2 * Arm PrimeCell PL110 Color LCD Controller
4 * Copyright (c) 2005-2009 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GNU LGPL
12 #include "framebuffer.h"
14 #define PL110_CR_EN 0x001
15 #define PL110_CR_BGR 0x100
16 #define PL110_CR_BEBO 0x200
17 #define PL110_CR_BEPO 0x400
18 #define PL110_CR_PWR 0x800
34 /* The Versatile/PB uses a slightly modified PL110 controller. */
44 enum pl110_bppmode bpp
;
46 uint32_t pallette
[256];
47 uint32_t raw_pallette
[128];
51 static const VMStateDescription vmstate_pl110
= {
54 .minimum_version_id
= 1,
55 .fields
= (VMStateField
[]) {
56 VMSTATE_INT32(versatile
, pl110_state
),
57 VMSTATE_UINT32_ARRAY(timing
, pl110_state
, 4),
58 VMSTATE_UINT32(cr
, pl110_state
),
59 VMSTATE_UINT32(upbase
, pl110_state
),
60 VMSTATE_UINT32(lpbase
, pl110_state
),
61 VMSTATE_UINT32(int_status
, pl110_state
),
62 VMSTATE_UINT32(int_mask
, pl110_state
),
63 VMSTATE_INT32(cols
, pl110_state
),
64 VMSTATE_INT32(rows
, pl110_state
),
65 VMSTATE_UINT32(bpp
, pl110_state
),
66 VMSTATE_INT32(invalidate
, pl110_state
),
67 VMSTATE_UINT32_ARRAY(pallette
, pl110_state
, 256),
68 VMSTATE_UINT32_ARRAY(raw_pallette
, pl110_state
, 128),
73 static const unsigned char pl110_id
[] =
74 { 0x10, 0x11, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
76 /* The Arm documentation (DDI0224C) says the CLDC on the Versatile board
77 has a different ID. However Linux only looks for the normal ID. */
79 static const unsigned char pl110_versatile_id
[] =
80 { 0x93, 0x10, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
82 #define pl110_versatile_id pl110_id
85 #include "pixel_ops.h"
88 #include "pl110_template.h"
90 #include "pl110_template.h"
92 #include "pl110_template.h"
94 #include "pl110_template.h"
96 #include "pl110_template.h"
98 static int pl110_enabled(pl110_state
*s
)
100 return (s
->cr
& PL110_CR_EN
) && (s
->cr
& PL110_CR_PWR
);
103 static void pl110_update_display(void *opaque
)
105 pl110_state
*s
= (pl110_state
*)opaque
;
114 if (!pl110_enabled(s
))
117 switch (ds_get_bits_per_pixel(s
->ds
)) {
121 fntable
= pl110_draw_fn_8
;
125 fntable
= pl110_draw_fn_15
;
129 fntable
= pl110_draw_fn_16
;
133 fntable
= pl110_draw_fn_24
;
137 fntable
= pl110_draw_fn_32
;
141 fprintf(stderr
, "pl110: Bad color depth\n");
144 if (s
->cr
& PL110_CR_BGR
)
149 if (s
->cr
& PL110_CR_BEBO
)
150 fn
= fntable
[s
->bpp
+ 6 + bpp_offset
];
151 else if (s
->cr
& PL110_CR_BEPO
)
152 fn
= fntable
[s
->bpp
+ 12 + bpp_offset
];
154 fn
= fntable
[s
->bpp
+ bpp_offset
];
176 dest_width
*= s
->cols
;
178 framebuffer_update_display(s
->ds
,
179 s
->upbase
, s
->cols
, s
->rows
,
180 src_width
, dest_width
, 0,
185 dpy_update(s
->ds
, 0, first
, s
->cols
, last
- first
+ 1);
190 static void pl110_invalidate_display(void * opaque
)
192 pl110_state
*s
= (pl110_state
*)opaque
;
194 if (pl110_enabled(s
)) {
195 qemu_console_resize(s
->ds
, s
->cols
, s
->rows
);
199 static void pl110_update_pallette(pl110_state
*s
, int n
)
203 unsigned int r
, g
, b
;
205 raw
= s
->raw_pallette
[n
];
207 for (i
= 0; i
< 2; i
++) {
208 r
= (raw
& 0x1f) << 3;
210 g
= (raw
& 0x1f) << 3;
212 b
= (raw
& 0x1f) << 3;
213 /* The I bit is ignored. */
215 switch (ds_get_bits_per_pixel(s
->ds
)) {
217 s
->pallette
[n
] = rgb_to_pixel8(r
, g
, b
);
220 s
->pallette
[n
] = rgb_to_pixel15(r
, g
, b
);
223 s
->pallette
[n
] = rgb_to_pixel16(r
, g
, b
);
227 s
->pallette
[n
] = rgb_to_pixel32(r
, g
, b
);
234 static void pl110_resize(pl110_state
*s
, int width
, int height
)
236 if (width
!= s
->cols
|| height
!= s
->rows
) {
237 if (pl110_enabled(s
)) {
238 qemu_console_resize(s
->ds
, width
, height
);
245 /* Update interrupts. */
246 static void pl110_update(pl110_state
*s
)
248 /* TODO: Implement interrupts. */
251 static uint32_t pl110_read(void *opaque
, target_phys_addr_t offset
)
253 pl110_state
*s
= (pl110_state
*)opaque
;
255 if (offset
>= 0xfe0 && offset
< 0x1000) {
257 return pl110_versatile_id
[(offset
- 0xfe0) >> 2];
259 return pl110_id
[(offset
- 0xfe0) >> 2];
261 if (offset
>= 0x200 && offset
< 0x400) {
262 return s
->raw_pallette
[(offset
- 0x200) >> 2];
264 switch (offset
>> 2) {
265 case 0: /* LCDTiming0 */
267 case 1: /* LCDTiming1 */
269 case 2: /* LCDTiming2 */
271 case 3: /* LCDTiming3 */
273 case 4: /* LCDUPBASE */
275 case 5: /* LCDLPBASE */
277 case 6: /* LCDIMSC */
281 case 7: /* LCDControl */
286 return s
->int_status
;
288 return s
->int_status
& s
->int_mask
;
289 case 11: /* LCDUPCURR */
290 /* TODO: Implement vertical refresh. */
292 case 12: /* LCDLPCURR */
295 hw_error("pl110_read: Bad offset %x\n", (int)offset
);
300 static void pl110_write(void *opaque
, target_phys_addr_t offset
,
303 pl110_state
*s
= (pl110_state
*)opaque
;
306 /* For simplicity invalidate the display whenever a control register
309 if (offset
>= 0x200 && offset
< 0x400) {
311 n
= (offset
- 0x200) >> 2;
312 s
->raw_pallette
[(offset
- 0x200) >> 2] = val
;
313 pl110_update_pallette(s
, n
);
316 switch (offset
>> 2) {
317 case 0: /* LCDTiming0 */
319 n
= ((val
& 0xfc) + 4) * 4;
320 pl110_resize(s
, n
, s
->rows
);
322 case 1: /* LCDTiming1 */
324 n
= (val
& 0x3ff) + 1;
325 pl110_resize(s
, s
->cols
, n
);
327 case 2: /* LCDTiming2 */
330 case 3: /* LCDTiming3 */
333 case 4: /* LCDUPBASE */
336 case 5: /* LCDLPBASE */
339 case 6: /* LCDIMSC */
346 case 7: /* LCDControl */
351 s
->bpp
= (val
>> 1) & 7;
352 if (pl110_enabled(s
)) {
353 qemu_console_resize(s
->ds
, s
->cols
, s
->rows
);
356 case 10: /* LCDICR */
357 s
->int_status
&= ~val
;
361 hw_error("pl110_write: Bad offset %x\n", (int)offset
);
365 static CPUReadMemoryFunc
* const pl110_readfn
[] = {
371 static CPUWriteMemoryFunc
* const pl110_writefn
[] = {
377 static int pl110_init(SysBusDevice
*dev
)
379 pl110_state
*s
= FROM_SYSBUS(pl110_state
, dev
);
382 iomemtype
= cpu_register_io_memory(pl110_readfn
,
384 DEVICE_NATIVE_ENDIAN
);
385 sysbus_init_mmio(dev
, 0x1000, iomemtype
);
386 sysbus_init_irq(dev
, &s
->irq
);
387 s
->ds
= graphic_console_init(pl110_update_display
,
388 pl110_invalidate_display
,
393 static int pl110_versatile_init(SysBusDevice
*dev
)
395 pl110_state
*s
= FROM_SYSBUS(pl110_state
, dev
);
397 return pl110_init(dev
);
400 static SysBusDeviceInfo pl110_info
= {
402 .qdev
.name
= "pl110",
403 .qdev
.size
= sizeof(pl110_state
),
404 .qdev
.vmsd
= &vmstate_pl110
,
408 static SysBusDeviceInfo pl110_versatile_info
= {
409 .init
= pl110_versatile_init
,
410 .qdev
.name
= "pl110_versatile",
411 .qdev
.size
= sizeof(pl110_state
),
412 .qdev
.vmsd
= &vmstate_pl110
,
416 static void pl110_register_devices(void)
418 sysbus_register_withprop(&pl110_info
);
419 sysbus_register_withprop(&pl110_versatile_info
);
422 device_init(pl110_register_devices
)