root / hw / pl110.c @ bc927e48
History | View | Annotate | Download (13.1 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | bdd5003a | pbrook | * Arm PrimeCell PL110 Color LCD Controller
|
3 | bdd5003a | pbrook | *
|
4 | 2e9bdce5 | Paul Brook | * Copyright (c) 2005-2009 CodeSourcery.
|
5 | bdd5003a | pbrook | * Written by Paul Brook
|
6 | bdd5003a | pbrook | *
|
7 | 8e31bf38 | Matthew Fernandez | * This code is licensed under the GNU LGPL
|
8 | bdd5003a | pbrook | */
|
9 | bdd5003a | pbrook | |
10 | 2e9bdce5 | Paul Brook | #include "sysbus.h" |
11 | 87ecb68b | pbrook | #include "console.h" |
12 | 714fa308 | pbrook | #include "framebuffer.h" |
13 | bdd5003a | pbrook | |
14 | bdd5003a | pbrook | #define PL110_CR_EN 0x001 |
15 | e9c05b42 | balrog | #define PL110_CR_BGR 0x100 |
16 | bdd5003a | pbrook | #define PL110_CR_BEBO 0x200 |
17 | bdd5003a | pbrook | #define PL110_CR_BEPO 0x400 |
18 | bdd5003a | pbrook | #define PL110_CR_PWR 0x800 |
19 | bdd5003a | pbrook | |
20 | bdd5003a | pbrook | enum pl110_bppmode
|
21 | bdd5003a | pbrook | { |
22 | bdd5003a | pbrook | BPP_1, |
23 | bdd5003a | pbrook | BPP_2, |
24 | bdd5003a | pbrook | BPP_4, |
25 | bdd5003a | pbrook | BPP_8, |
26 | bdd5003a | pbrook | BPP_16, |
27 | 4fbf5556 | Peter Maydell | BPP_32, |
28 | 4fbf5556 | Peter Maydell | BPP_16_565, /* PL111 only */
|
29 | 4fbf5556 | Peter Maydell | BPP_12 /* PL111 only */
|
30 | 4fbf5556 | Peter Maydell | }; |
31 | 4fbf5556 | Peter Maydell | |
32 | 4fbf5556 | Peter Maydell | |
33 | 4fbf5556 | Peter Maydell | /* The Versatile/PB uses a slightly modified PL110 controller. */
|
34 | 4fbf5556 | Peter Maydell | enum pl110_version
|
35 | 4fbf5556 | Peter Maydell | { |
36 | 4fbf5556 | Peter Maydell | PL110, |
37 | 4fbf5556 | Peter Maydell | PL110_VERSATILE, |
38 | 4fbf5556 | Peter Maydell | PL111 |
39 | bdd5003a | pbrook | }; |
40 | bdd5003a | pbrook | |
41 | bdd5003a | pbrook | typedef struct { |
42 | 2e9bdce5 | Paul Brook | SysBusDevice busdev; |
43 | 1a6b31ce | Avi Kivity | MemoryRegion iomem; |
44 | bdd5003a | pbrook | DisplayState *ds; |
45 | c60e08d9 | pbrook | |
46 | 4fbf5556 | Peter Maydell | int version;
|
47 | bdd5003a | pbrook | uint32_t timing[4];
|
48 | bdd5003a | pbrook | uint32_t cr; |
49 | bdd5003a | pbrook | uint32_t upbase; |
50 | bdd5003a | pbrook | uint32_t lpbase; |
51 | bdd5003a | pbrook | uint32_t int_status; |
52 | bdd5003a | pbrook | uint32_t int_mask; |
53 | bdd5003a | pbrook | int cols;
|
54 | bdd5003a | pbrook | int rows;
|
55 | bdd5003a | pbrook | enum pl110_bppmode bpp;
|
56 | bdd5003a | pbrook | int invalidate;
|
57 | 242ea2c6 | Peter Maydell | uint32_t mux_ctrl; |
58 | 6e4c0d1f | Peter Maydell | uint32_t palette[256];
|
59 | 6e4c0d1f | Peter Maydell | uint32_t raw_palette[128];
|
60 | d537cf6c | pbrook | qemu_irq irq; |
61 | bdd5003a | pbrook | } pl110_state; |
62 | bdd5003a | pbrook | |
63 | 128939a9 | Peter Maydell | static int vmstate_pl110_post_load(void *opaque, int version_id); |
64 | 128939a9 | Peter Maydell | |
65 | 8c60d065 | Peter Maydell | static const VMStateDescription vmstate_pl110 = { |
66 | 8c60d065 | Peter Maydell | .name = "pl110",
|
67 | 242ea2c6 | Peter Maydell | .version_id = 2,
|
68 | 8c60d065 | Peter Maydell | .minimum_version_id = 1,
|
69 | 128939a9 | Peter Maydell | .post_load = vmstate_pl110_post_load, |
70 | 8c60d065 | Peter Maydell | .fields = (VMStateField[]) { |
71 | 4fbf5556 | Peter Maydell | VMSTATE_INT32(version, pl110_state), |
72 | 8c60d065 | Peter Maydell | VMSTATE_UINT32_ARRAY(timing, pl110_state, 4),
|
73 | 8c60d065 | Peter Maydell | VMSTATE_UINT32(cr, pl110_state), |
74 | 8c60d065 | Peter Maydell | VMSTATE_UINT32(upbase, pl110_state), |
75 | 8c60d065 | Peter Maydell | VMSTATE_UINT32(lpbase, pl110_state), |
76 | 8c60d065 | Peter Maydell | VMSTATE_UINT32(int_status, pl110_state), |
77 | 8c60d065 | Peter Maydell | VMSTATE_UINT32(int_mask, pl110_state), |
78 | 8c60d065 | Peter Maydell | VMSTATE_INT32(cols, pl110_state), |
79 | 8c60d065 | Peter Maydell | VMSTATE_INT32(rows, pl110_state), |
80 | 8c60d065 | Peter Maydell | VMSTATE_UINT32(bpp, pl110_state), |
81 | 8c60d065 | Peter Maydell | VMSTATE_INT32(invalidate, pl110_state), |
82 | 6e4c0d1f | Peter Maydell | VMSTATE_UINT32_ARRAY(palette, pl110_state, 256),
|
83 | 6e4c0d1f | Peter Maydell | VMSTATE_UINT32_ARRAY(raw_palette, pl110_state, 128),
|
84 | 242ea2c6 | Peter Maydell | VMSTATE_UINT32_V(mux_ctrl, pl110_state, 2),
|
85 | 8c60d065 | Peter Maydell | VMSTATE_END_OF_LIST() |
86 | 8c60d065 | Peter Maydell | } |
87 | 8c60d065 | Peter Maydell | }; |
88 | 8c60d065 | Peter Maydell | |
89 | bdd5003a | pbrook | static const unsigned char pl110_id[] = |
90 | bdd5003a | pbrook | { 0x10, 0x11, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 }; |
91 | bdd5003a | pbrook | |
92 | cdbdb648 | pbrook | /* The Arm documentation (DDI0224C) says the CLDC on the Versatile board
|
93 | cdbdb648 | pbrook | has a different ID. However Linux only looks for the normal ID. */
|
94 | cdbdb648 | pbrook | #if 0
|
95 | cdbdb648 | pbrook | static const unsigned char pl110_versatile_id[] =
|
96 | cdbdb648 | pbrook | { 0x93, 0x10, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
|
97 | cdbdb648 | pbrook | #else
|
98 | cdbdb648 | pbrook | #define pl110_versatile_id pl110_id
|
99 | cdbdb648 | pbrook | #endif
|
100 | cdbdb648 | pbrook | |
101 | 4fbf5556 | Peter Maydell | static const unsigned char pl111_id[] = { |
102 | 4fbf5556 | Peter Maydell | 0x11, 0x11, 0x24, 0x00, 0x0d, 0xf0, 0x05, 0xb1 |
103 | 4fbf5556 | Peter Maydell | }; |
104 | 4fbf5556 | Peter Maydell | |
105 | 4fbf5556 | Peter Maydell | /* Indexed by pl110_version */
|
106 | 4fbf5556 | Peter Maydell | static const unsigned char *idregs[] = { |
107 | 4fbf5556 | Peter Maydell | pl110_id, |
108 | 4fbf5556 | Peter Maydell | pl110_versatile_id, |
109 | 4fbf5556 | Peter Maydell | pl111_id |
110 | 4fbf5556 | Peter Maydell | }; |
111 | 4fbf5556 | Peter Maydell | |
112 | 602dafcf | pbrook | #include "pixel_ops.h" |
113 | bdd5003a | pbrook | |
114 | bdd5003a | pbrook | #define BITS 8 |
115 | bdd5003a | pbrook | #include "pl110_template.h" |
116 | bdd5003a | pbrook | #define BITS 15 |
117 | bdd5003a | pbrook | #include "pl110_template.h" |
118 | bdd5003a | pbrook | #define BITS 16 |
119 | bdd5003a | pbrook | #include "pl110_template.h" |
120 | bdd5003a | pbrook | #define BITS 24 |
121 | bdd5003a | pbrook | #include "pl110_template.h" |
122 | bdd5003a | pbrook | #define BITS 32 |
123 | bdd5003a | pbrook | #include "pl110_template.h" |
124 | bdd5003a | pbrook | |
125 | bdd5003a | pbrook | static int pl110_enabled(pl110_state *s) |
126 | bdd5003a | pbrook | { |
127 | bdd5003a | pbrook | return (s->cr & PL110_CR_EN) && (s->cr & PL110_CR_PWR);
|
128 | bdd5003a | pbrook | } |
129 | bdd5003a | pbrook | |
130 | 95219897 | pbrook | static void pl110_update_display(void *opaque) |
131 | bdd5003a | pbrook | { |
132 | bdd5003a | pbrook | pl110_state *s = (pl110_state *)opaque; |
133 | bdd5003a | pbrook | drawfn* fntable; |
134 | bdd5003a | pbrook | drawfn fn; |
135 | bdd5003a | pbrook | int dest_width;
|
136 | bdd5003a | pbrook | int src_width;
|
137 | e9c05b42 | balrog | int bpp_offset;
|
138 | 714fa308 | pbrook | int first;
|
139 | 714fa308 | pbrook | int last;
|
140 | bdd5003a | pbrook | |
141 | bdd5003a | pbrook | if (!pl110_enabled(s))
|
142 | bdd5003a | pbrook | return;
|
143 | 3b46e624 | ths | |
144 | 0e1f5a0c | aliguori | switch (ds_get_bits_per_pixel(s->ds)) {
|
145 | af2f6733 | pbrook | case 0: |
146 | af2f6733 | pbrook | return;
|
147 | bdd5003a | pbrook | case 8: |
148 | bdd5003a | pbrook | fntable = pl110_draw_fn_8; |
149 | bdd5003a | pbrook | dest_width = 1;
|
150 | bdd5003a | pbrook | break;
|
151 | bdd5003a | pbrook | case 15: |
152 | bdd5003a | pbrook | fntable = pl110_draw_fn_15; |
153 | bdd5003a | pbrook | dest_width = 2;
|
154 | bdd5003a | pbrook | break;
|
155 | bdd5003a | pbrook | case 16: |
156 | bdd5003a | pbrook | fntable = pl110_draw_fn_16; |
157 | bdd5003a | pbrook | dest_width = 2;
|
158 | bdd5003a | pbrook | break;
|
159 | bdd5003a | pbrook | case 24: |
160 | bdd5003a | pbrook | fntable = pl110_draw_fn_24; |
161 | bdd5003a | pbrook | dest_width = 3;
|
162 | bdd5003a | pbrook | break;
|
163 | bdd5003a | pbrook | case 32: |
164 | bdd5003a | pbrook | fntable = pl110_draw_fn_32; |
165 | bdd5003a | pbrook | dest_width = 4;
|
166 | bdd5003a | pbrook | break;
|
167 | bdd5003a | pbrook | default:
|
168 | af2f6733 | pbrook | fprintf(stderr, "pl110: Bad color depth\n");
|
169 | bdd5003a | pbrook | exit(1);
|
170 | bdd5003a | pbrook | } |
171 | e9c05b42 | balrog | if (s->cr & PL110_CR_BGR)
|
172 | e9c05b42 | balrog | bpp_offset = 0;
|
173 | e9c05b42 | balrog | else
|
174 | 4fbf5556 | Peter Maydell | bpp_offset = 24;
|
175 | 4fbf5556 | Peter Maydell | |
176 | 4fbf5556 | Peter Maydell | if ((s->version != PL111) && (s->bpp == BPP_16)) {
|
177 | 4fbf5556 | Peter Maydell | /* The PL110's native 16 bit mode is 5551; however
|
178 | 4fbf5556 | Peter Maydell | * most boards with a PL110 implement an external
|
179 | 4fbf5556 | Peter Maydell | * mux which allows bits to be reshuffled to give
|
180 | 4fbf5556 | Peter Maydell | * 565 format. The mux is typically controlled by
|
181 | 4fbf5556 | Peter Maydell | * an external system register.
|
182 | 242ea2c6 | Peter Maydell | * This is controlled by a GPIO input pin
|
183 | 4fbf5556 | Peter Maydell | * so boards can wire it up to their register.
|
184 | 4fbf5556 | Peter Maydell | *
|
185 | 4fbf5556 | Peter Maydell | * The PL111 straightforwardly implements both
|
186 | 4fbf5556 | Peter Maydell | * 5551 and 565 under control of the bpp field
|
187 | 4fbf5556 | Peter Maydell | * in the LCDControl register.
|
188 | 4fbf5556 | Peter Maydell | */
|
189 | 242ea2c6 | Peter Maydell | switch (s->mux_ctrl) {
|
190 | 242ea2c6 | Peter Maydell | case 3: /* 565 BGR */ |
191 | 242ea2c6 | Peter Maydell | bpp_offset = (BPP_16_565 - BPP_16); |
192 | 242ea2c6 | Peter Maydell | break;
|
193 | 242ea2c6 | Peter Maydell | case 1: /* 5551 */ |
194 | 242ea2c6 | Peter Maydell | break;
|
195 | 242ea2c6 | Peter Maydell | case 0: /* 888; also if we have loaded vmstate from an old version */ |
196 | 242ea2c6 | Peter Maydell | case 2: /* 565 RGB */ |
197 | 242ea2c6 | Peter Maydell | default:
|
198 | 242ea2c6 | Peter Maydell | /* treat as 565 but honour BGR bit */
|
199 | 242ea2c6 | Peter Maydell | bpp_offset += (BPP_16_565 - BPP_16); |
200 | 242ea2c6 | Peter Maydell | break;
|
201 | 242ea2c6 | Peter Maydell | } |
202 | 4fbf5556 | Peter Maydell | } |
203 | e9c05b42 | balrog | |
204 | bdd5003a | pbrook | if (s->cr & PL110_CR_BEBO)
|
205 | 4fbf5556 | Peter Maydell | fn = fntable[s->bpp + 8 + bpp_offset];
|
206 | bdd5003a | pbrook | else if (s->cr & PL110_CR_BEPO) |
207 | 4fbf5556 | Peter Maydell | fn = fntable[s->bpp + 16 + bpp_offset];
|
208 | bdd5003a | pbrook | else
|
209 | e9c05b42 | balrog | fn = fntable[s->bpp + bpp_offset]; |
210 | 3b46e624 | ths | |
211 | bdd5003a | pbrook | src_width = s->cols; |
212 | bdd5003a | pbrook | switch (s->bpp) {
|
213 | bdd5003a | pbrook | case BPP_1:
|
214 | bdd5003a | pbrook | src_width >>= 3;
|
215 | bdd5003a | pbrook | break;
|
216 | bdd5003a | pbrook | case BPP_2:
|
217 | bdd5003a | pbrook | src_width >>= 2;
|
218 | bdd5003a | pbrook | break;
|
219 | bdd5003a | pbrook | case BPP_4:
|
220 | bdd5003a | pbrook | src_width >>= 1;
|
221 | bdd5003a | pbrook | break;
|
222 | bdd5003a | pbrook | case BPP_8:
|
223 | bdd5003a | pbrook | break;
|
224 | bdd5003a | pbrook | case BPP_16:
|
225 | 4fbf5556 | Peter Maydell | case BPP_16_565:
|
226 | 4fbf5556 | Peter Maydell | case BPP_12:
|
227 | bdd5003a | pbrook | src_width <<= 1;
|
228 | bdd5003a | pbrook | break;
|
229 | bdd5003a | pbrook | case BPP_32:
|
230 | bdd5003a | pbrook | src_width <<= 2;
|
231 | bdd5003a | pbrook | break;
|
232 | bdd5003a | pbrook | } |
233 | bdd5003a | pbrook | dest_width *= s->cols; |
234 | 714fa308 | pbrook | first = 0;
|
235 | 75c9d6c2 | Avi Kivity | framebuffer_update_display(s->ds, sysbus_address_space(&s->busdev), |
236 | 714fa308 | pbrook | s->upbase, s->cols, s->rows, |
237 | 714fa308 | pbrook | src_width, dest_width, 0,
|
238 | 714fa308 | pbrook | s->invalidate, |
239 | 6e4c0d1f | Peter Maydell | fn, s->palette, |
240 | 714fa308 | pbrook | &first, &last); |
241 | 714fa308 | pbrook | if (first >= 0) { |
242 | 714fa308 | pbrook | dpy_update(s->ds, 0, first, s->cols, last - first + 1); |
243 | bdd5003a | pbrook | } |
244 | bdd5003a | pbrook | s->invalidate = 0;
|
245 | bdd5003a | pbrook | } |
246 | bdd5003a | pbrook | |
247 | 95219897 | pbrook | static void pl110_invalidate_display(void * opaque) |
248 | bdd5003a | pbrook | { |
249 | bdd5003a | pbrook | pl110_state *s = (pl110_state *)opaque; |
250 | bdd5003a | pbrook | s->invalidate = 1;
|
251 | bfdb3629 | Blue Swirl | if (pl110_enabled(s)) {
|
252 | bfdb3629 | Blue Swirl | qemu_console_resize(s->ds, s->cols, s->rows); |
253 | bfdb3629 | Blue Swirl | } |
254 | bdd5003a | pbrook | } |
255 | bdd5003a | pbrook | |
256 | 6e4c0d1f | Peter Maydell | static void pl110_update_palette(pl110_state *s, int n) |
257 | bdd5003a | pbrook | { |
258 | bdd5003a | pbrook | int i;
|
259 | bdd5003a | pbrook | uint32_t raw; |
260 | bdd5003a | pbrook | unsigned int r, g, b; |
261 | bdd5003a | pbrook | |
262 | 6e4c0d1f | Peter Maydell | raw = s->raw_palette[n]; |
263 | bdd5003a | pbrook | n <<= 1;
|
264 | bdd5003a | pbrook | for (i = 0; i < 2; i++) { |
265 | bdd5003a | pbrook | r = (raw & 0x1f) << 3; |
266 | bdd5003a | pbrook | raw >>= 5;
|
267 | bdd5003a | pbrook | g = (raw & 0x1f) << 3; |
268 | bdd5003a | pbrook | raw >>= 5;
|
269 | bdd5003a | pbrook | b = (raw & 0x1f) << 3; |
270 | bdd5003a | pbrook | /* The I bit is ignored. */
|
271 | bdd5003a | pbrook | raw >>= 6;
|
272 | 0e1f5a0c | aliguori | switch (ds_get_bits_per_pixel(s->ds)) {
|
273 | bdd5003a | pbrook | case 8: |
274 | 6e4c0d1f | Peter Maydell | s->palette[n] = rgb_to_pixel8(r, g, b); |
275 | bdd5003a | pbrook | break;
|
276 | bdd5003a | pbrook | case 15: |
277 | 6e4c0d1f | Peter Maydell | s->palette[n] = rgb_to_pixel15(r, g, b); |
278 | bdd5003a | pbrook | break;
|
279 | bdd5003a | pbrook | case 16: |
280 | 6e4c0d1f | Peter Maydell | s->palette[n] = rgb_to_pixel16(r, g, b); |
281 | bdd5003a | pbrook | break;
|
282 | bdd5003a | pbrook | case 24: |
283 | bdd5003a | pbrook | case 32: |
284 | 6e4c0d1f | Peter Maydell | s->palette[n] = rgb_to_pixel32(r, g, b); |
285 | bdd5003a | pbrook | break;
|
286 | bdd5003a | pbrook | } |
287 | bdd5003a | pbrook | n++; |
288 | bdd5003a | pbrook | } |
289 | bdd5003a | pbrook | } |
290 | bdd5003a | pbrook | |
291 | bdd5003a | pbrook | static void pl110_resize(pl110_state *s, int width, int height) |
292 | bdd5003a | pbrook | { |
293 | bdd5003a | pbrook | if (width != s->cols || height != s->rows) {
|
294 | bdd5003a | pbrook | if (pl110_enabled(s)) {
|
295 | 3023f332 | aliguori | qemu_console_resize(s->ds, width, height); |
296 | bdd5003a | pbrook | } |
297 | bdd5003a | pbrook | } |
298 | bdd5003a | pbrook | s->cols = width; |
299 | bdd5003a | pbrook | s->rows = height; |
300 | bdd5003a | pbrook | } |
301 | bdd5003a | pbrook | |
302 | bdd5003a | pbrook | /* Update interrupts. */
|
303 | bdd5003a | pbrook | static void pl110_update(pl110_state *s) |
304 | bdd5003a | pbrook | { |
305 | bdd5003a | pbrook | /* TODO: Implement interrupts. */
|
306 | bdd5003a | pbrook | } |
307 | bdd5003a | pbrook | |
308 | a8170e5e | Avi Kivity | static uint64_t pl110_read(void *opaque, hwaddr offset, |
309 | 1a6b31ce | Avi Kivity | unsigned size)
|
310 | bdd5003a | pbrook | { |
311 | bdd5003a | pbrook | pl110_state *s = (pl110_state *)opaque; |
312 | bdd5003a | pbrook | |
313 | bdd5003a | pbrook | if (offset >= 0xfe0 && offset < 0x1000) { |
314 | 4fbf5556 | Peter Maydell | return idregs[s->version][(offset - 0xfe0) >> 2]; |
315 | bdd5003a | pbrook | } |
316 | bdd5003a | pbrook | if (offset >= 0x200 && offset < 0x400) { |
317 | 6e4c0d1f | Peter Maydell | return s->raw_palette[(offset - 0x200) >> 2]; |
318 | bdd5003a | pbrook | } |
319 | bdd5003a | pbrook | switch (offset >> 2) { |
320 | bdd5003a | pbrook | case 0: /* LCDTiming0 */ |
321 | bdd5003a | pbrook | return s->timing[0]; |
322 | bdd5003a | pbrook | case 1: /* LCDTiming1 */ |
323 | bdd5003a | pbrook | return s->timing[1]; |
324 | bdd5003a | pbrook | case 2: /* LCDTiming2 */ |
325 | bdd5003a | pbrook | return s->timing[2]; |
326 | bdd5003a | pbrook | case 3: /* LCDTiming3 */ |
327 | bdd5003a | pbrook | return s->timing[3]; |
328 | bdd5003a | pbrook | case 4: /* LCDUPBASE */ |
329 | bdd5003a | pbrook | return s->upbase;
|
330 | bdd5003a | pbrook | case 5: /* LCDLPBASE */ |
331 | bdd5003a | pbrook | return s->lpbase;
|
332 | bdd5003a | pbrook | case 6: /* LCDIMSC */ |
333 | 4fbf5556 | Peter Maydell | if (s->version != PL110) {
|
334 | 4fbf5556 | Peter Maydell | return s->cr;
|
335 | 4fbf5556 | Peter Maydell | } |
336 | bdd5003a | pbrook | return s->int_mask;
|
337 | bdd5003a | pbrook | case 7: /* LCDControl */ |
338 | 4fbf5556 | Peter Maydell | if (s->version != PL110) {
|
339 | 4fbf5556 | Peter Maydell | return s->int_mask;
|
340 | 4fbf5556 | Peter Maydell | } |
341 | bdd5003a | pbrook | return s->cr;
|
342 | bdd5003a | pbrook | case 8: /* LCDRIS */ |
343 | bdd5003a | pbrook | return s->int_status;
|
344 | bdd5003a | pbrook | case 9: /* LCDMIS */ |
345 | bdd5003a | pbrook | return s->int_status & s->int_mask;
|
346 | bdd5003a | pbrook | case 11: /* LCDUPCURR */ |
347 | bdd5003a | pbrook | /* TODO: Implement vertical refresh. */
|
348 | bdd5003a | pbrook | return s->upbase;
|
349 | bdd5003a | pbrook | case 12: /* LCDLPCURR */ |
350 | bdd5003a | pbrook | return s->lpbase;
|
351 | bdd5003a | pbrook | default:
|
352 | 2ac71179 | Paul Brook | hw_error("pl110_read: Bad offset %x\n", (int)offset); |
353 | bdd5003a | pbrook | return 0; |
354 | bdd5003a | pbrook | } |
355 | bdd5003a | pbrook | } |
356 | bdd5003a | pbrook | |
357 | a8170e5e | Avi Kivity | static void pl110_write(void *opaque, hwaddr offset, |
358 | 1a6b31ce | Avi Kivity | uint64_t val, unsigned size)
|
359 | bdd5003a | pbrook | { |
360 | bdd5003a | pbrook | pl110_state *s = (pl110_state *)opaque; |
361 | bdd5003a | pbrook | int n;
|
362 | bdd5003a | pbrook | |
363 | bdd5003a | pbrook | /* For simplicity invalidate the display whenever a control register
|
364 | 66a0a2cb | Dong Xu Wang | is written to. */
|
365 | bdd5003a | pbrook | s->invalidate = 1;
|
366 | bdd5003a | pbrook | if (offset >= 0x200 && offset < 0x400) { |
367 | 6e4c0d1f | Peter Maydell | /* Palette. */
|
368 | bdd5003a | pbrook | n = (offset - 0x200) >> 2; |
369 | 6e4c0d1f | Peter Maydell | s->raw_palette[(offset - 0x200) >> 2] = val; |
370 | 6e4c0d1f | Peter Maydell | pl110_update_palette(s, n); |
371 | e10c2bfb | pbrook | return;
|
372 | bdd5003a | pbrook | } |
373 | bdd5003a | pbrook | switch (offset >> 2) { |
374 | bdd5003a | pbrook | case 0: /* LCDTiming0 */ |
375 | bdd5003a | pbrook | s->timing[0] = val;
|
376 | bdd5003a | pbrook | n = ((val & 0xfc) + 4) * 4; |
377 | bdd5003a | pbrook | pl110_resize(s, n, s->rows); |
378 | bdd5003a | pbrook | break;
|
379 | bdd5003a | pbrook | case 1: /* LCDTiming1 */ |
380 | bdd5003a | pbrook | s->timing[1] = val;
|
381 | bdd5003a | pbrook | n = (val & 0x3ff) + 1; |
382 | bdd5003a | pbrook | pl110_resize(s, s->cols, n); |
383 | bdd5003a | pbrook | break;
|
384 | bdd5003a | pbrook | case 2: /* LCDTiming2 */ |
385 | bdd5003a | pbrook | s->timing[2] = val;
|
386 | bdd5003a | pbrook | break;
|
387 | bdd5003a | pbrook | case 3: /* LCDTiming3 */ |
388 | bdd5003a | pbrook | s->timing[3] = val;
|
389 | bdd5003a | pbrook | break;
|
390 | bdd5003a | pbrook | case 4: /* LCDUPBASE */ |
391 | bdd5003a | pbrook | s->upbase = val; |
392 | bdd5003a | pbrook | break;
|
393 | bdd5003a | pbrook | case 5: /* LCDLPBASE */ |
394 | bdd5003a | pbrook | s->lpbase = val; |
395 | bdd5003a | pbrook | break;
|
396 | bdd5003a | pbrook | case 6: /* LCDIMSC */ |
397 | 4fbf5556 | Peter Maydell | if (s->version != PL110) {
|
398 | cdbdb648 | pbrook | goto control;
|
399 | 4fbf5556 | Peter Maydell | } |
400 | cdbdb648 | pbrook | imsc:
|
401 | bdd5003a | pbrook | s->int_mask = val; |
402 | bdd5003a | pbrook | pl110_update(s); |
403 | bdd5003a | pbrook | break;
|
404 | bdd5003a | pbrook | case 7: /* LCDControl */ |
405 | 4fbf5556 | Peter Maydell | if (s->version != PL110) {
|
406 | cdbdb648 | pbrook | goto imsc;
|
407 | 4fbf5556 | Peter Maydell | } |
408 | cdbdb648 | pbrook | control:
|
409 | bdd5003a | pbrook | s->cr = val; |
410 | bdd5003a | pbrook | s->bpp = (val >> 1) & 7; |
411 | bdd5003a | pbrook | if (pl110_enabled(s)) {
|
412 | 3023f332 | aliguori | qemu_console_resize(s->ds, s->cols, s->rows); |
413 | bdd5003a | pbrook | } |
414 | bdd5003a | pbrook | break;
|
415 | bdd5003a | pbrook | case 10: /* LCDICR */ |
416 | bdd5003a | pbrook | s->int_status &= ~val; |
417 | bdd5003a | pbrook | pl110_update(s); |
418 | bdd5003a | pbrook | break;
|
419 | bdd5003a | pbrook | default:
|
420 | 2ac71179 | Paul Brook | hw_error("pl110_write: Bad offset %x\n", (int)offset); |
421 | bdd5003a | pbrook | } |
422 | bdd5003a | pbrook | } |
423 | bdd5003a | pbrook | |
424 | 1a6b31ce | Avi Kivity | static const MemoryRegionOps pl110_ops = { |
425 | 1a6b31ce | Avi Kivity | .read = pl110_read, |
426 | 1a6b31ce | Avi Kivity | .write = pl110_write, |
427 | 1a6b31ce | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
428 | bdd5003a | pbrook | }; |
429 | bdd5003a | pbrook | |
430 | 242ea2c6 | Peter Maydell | static void pl110_mux_ctrl_set(void *opaque, int line, int level) |
431 | 242ea2c6 | Peter Maydell | { |
432 | 242ea2c6 | Peter Maydell | pl110_state *s = (pl110_state *)opaque; |
433 | 242ea2c6 | Peter Maydell | s->mux_ctrl = level; |
434 | 242ea2c6 | Peter Maydell | } |
435 | 242ea2c6 | Peter Maydell | |
436 | 128939a9 | Peter Maydell | static int vmstate_pl110_post_load(void *opaque, int version_id) |
437 | 128939a9 | Peter Maydell | { |
438 | 128939a9 | Peter Maydell | pl110_state *s = opaque; |
439 | 128939a9 | Peter Maydell | /* Make sure we redraw, and at the right size */
|
440 | 128939a9 | Peter Maydell | pl110_invalidate_display(s); |
441 | 128939a9 | Peter Maydell | return 0; |
442 | 128939a9 | Peter Maydell | } |
443 | 128939a9 | Peter Maydell | |
444 | 81a322d4 | Gerd Hoffmann | static int pl110_init(SysBusDevice *dev) |
445 | bdd5003a | pbrook | { |
446 | 2e9bdce5 | Paul Brook | pl110_state *s = FROM_SYSBUS(pl110_state, dev); |
447 | bdd5003a | pbrook | |
448 | 1a6b31ce | Avi Kivity | memory_region_init_io(&s->iomem, &pl110_ops, s, "pl110", 0x1000); |
449 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->iomem); |
450 | 2e9bdce5 | Paul Brook | sysbus_init_irq(dev, &s->irq); |
451 | 242ea2c6 | Peter Maydell | qdev_init_gpio_in(&s->busdev.qdev, pl110_mux_ctrl_set, 1);
|
452 | 3023f332 | aliguori | s->ds = graphic_console_init(pl110_update_display, |
453 | 3023f332 | aliguori | pl110_invalidate_display, |
454 | 3023f332 | aliguori | NULL, NULL, s); |
455 | 81a322d4 | Gerd Hoffmann | return 0; |
456 | bdd5003a | pbrook | } |
457 | 2e9bdce5 | Paul Brook | |
458 | 81a322d4 | Gerd Hoffmann | static int pl110_versatile_init(SysBusDevice *dev) |
459 | 2e9bdce5 | Paul Brook | { |
460 | 2e9bdce5 | Paul Brook | pl110_state *s = FROM_SYSBUS(pl110_state, dev); |
461 | 4fbf5556 | Peter Maydell | s->version = PL110_VERSATILE; |
462 | 4fbf5556 | Peter Maydell | return pl110_init(dev);
|
463 | 4fbf5556 | Peter Maydell | } |
464 | 4fbf5556 | Peter Maydell | |
465 | 4fbf5556 | Peter Maydell | static int pl111_init(SysBusDevice *dev) |
466 | 4fbf5556 | Peter Maydell | { |
467 | 4fbf5556 | Peter Maydell | pl110_state *s = FROM_SYSBUS(pl110_state, dev); |
468 | 4fbf5556 | Peter Maydell | s->version = PL111; |
469 | 81a322d4 | Gerd Hoffmann | return pl110_init(dev);
|
470 | 2e9bdce5 | Paul Brook | } |
471 | 2e9bdce5 | Paul Brook | |
472 | 999e12bb | Anthony Liguori | static void pl110_class_init(ObjectClass *klass, void *data) |
473 | 999e12bb | Anthony Liguori | { |
474 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
475 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
476 | 999e12bb | Anthony Liguori | |
477 | 999e12bb | Anthony Liguori | k->init = pl110_init; |
478 | 39bffca2 | Anthony Liguori | dc->no_user = 1;
|
479 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_pl110; |
480 | 999e12bb | Anthony Liguori | } |
481 | 999e12bb | Anthony Liguori | |
482 | 39bffca2 | Anthony Liguori | static TypeInfo pl110_info = {
|
483 | 39bffca2 | Anthony Liguori | .name = "pl110",
|
484 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
485 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(pl110_state),
|
486 | 39bffca2 | Anthony Liguori | .class_init = pl110_class_init, |
487 | 8c60d065 | Peter Maydell | }; |
488 | 8c60d065 | Peter Maydell | |
489 | 999e12bb | Anthony Liguori | static void pl110_versatile_class_init(ObjectClass *klass, void *data) |
490 | 999e12bb | Anthony Liguori | { |
491 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
492 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
493 | 999e12bb | Anthony Liguori | |
494 | 999e12bb | Anthony Liguori | k->init = pl110_versatile_init; |
495 | 39bffca2 | Anthony Liguori | dc->no_user = 1;
|
496 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_pl110; |
497 | 999e12bb | Anthony Liguori | } |
498 | 999e12bb | Anthony Liguori | |
499 | 39bffca2 | Anthony Liguori | static TypeInfo pl110_versatile_info = {
|
500 | 39bffca2 | Anthony Liguori | .name = "pl110_versatile",
|
501 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
502 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(pl110_state),
|
503 | 39bffca2 | Anthony Liguori | .class_init = pl110_versatile_class_init, |
504 | 8c60d065 | Peter Maydell | }; |
505 | 8c60d065 | Peter Maydell | |
506 | 999e12bb | Anthony Liguori | static void pl111_class_init(ObjectClass *klass, void *data) |
507 | 999e12bb | Anthony Liguori | { |
508 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
509 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
510 | 999e12bb | Anthony Liguori | |
511 | 999e12bb | Anthony Liguori | k->init = pl111_init; |
512 | 39bffca2 | Anthony Liguori | dc->no_user = 1;
|
513 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_pl110; |
514 | 999e12bb | Anthony Liguori | } |
515 | 999e12bb | Anthony Liguori | |
516 | 39bffca2 | Anthony Liguori | static TypeInfo pl111_info = {
|
517 | 39bffca2 | Anthony Liguori | .name = "pl111",
|
518 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
519 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(pl110_state),
|
520 | 39bffca2 | Anthony Liguori | .class_init = pl111_class_init, |
521 | 4fbf5556 | Peter Maydell | }; |
522 | 4fbf5556 | Peter Maydell | |
523 | 83f7d43a | Andreas Färber | static void pl110_register_types(void) |
524 | 2e9bdce5 | Paul Brook | { |
525 | 39bffca2 | Anthony Liguori | type_register_static(&pl110_info); |
526 | 39bffca2 | Anthony Liguori | type_register_static(&pl110_versatile_info); |
527 | 39bffca2 | Anthony Liguori | type_register_static(&pl111_info); |
528 | 2e9bdce5 | Paul Brook | } |
529 | 2e9bdce5 | Paul Brook | |
530 | 83f7d43a | Andreas Färber | type_init(pl110_register_types) |