4 * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "ui/console.h"
21 #include "hw/arm/omap.h"
22 #include "framebuffer.h"
23 #include "ui/pixel_ops.h"
25 struct omap_lcd_panel_s
{
42 struct omap_dma_lcd_channel_s
*dma
;
43 uint16_t palette
[256];
50 static void omap_lcd_interrupts(struct omap_lcd_panel_s
*s
)
52 if (s
->frame_done
&& (s
->interrupts
& 1)) {
53 qemu_irq_raise(s
->irq
);
57 if (s
->palette_done
&& (s
->interrupts
& 2)) {
58 qemu_irq_raise(s
->irq
);
63 qemu_irq_raise(s
->irq
);
67 qemu_irq_lower(s
->irq
);
70 #define draw_line_func drawfn
73 #include "omap_lcd_template.h"
75 #include "omap_lcd_template.h"
77 #include "omap_lcd_template.h"
79 #include "omap_lcd_template.h"
81 static draw_line_func draw_line_table2
[33] = {
87 }, draw_line_table4
[33] = {
93 }, draw_line_table8
[33] = {
99 }, draw_line_table12
[33] = {
102 [15] = draw_line12_15
,
103 [16] = draw_line12_16
,
104 [32] = draw_line12_32
,
105 }, draw_line_table16
[33] = {
108 [15] = draw_line16_15
,
109 [16] = draw_line16_16
,
110 [32] = draw_line16_32
,
113 static void omap_update_display(void *opaque
)
115 struct omap_lcd_panel_s
*omap_lcd
= (struct omap_lcd_panel_s
*) opaque
;
116 DisplaySurface
*surface
= qemu_console_surface(omap_lcd
->con
);
117 draw_line_func draw_line
;
118 int size
, height
, first
, last
;
119 int width
, linesize
, step
, bpp
, frame_offset
;
122 if (!omap_lcd
|| omap_lcd
->plm
== 1 || !omap_lcd
->enable
||
123 !surface_bits_per_pixel(surface
)) {
128 if (omap_lcd
->plm
!= 2) {
129 cpu_physical_memory_read(omap_lcd
->dma
->phys_framebuffer
[
130 omap_lcd
->dma
->current_frame
],
131 (void *)omap_lcd
->palette
, 0x200);
132 switch (omap_lcd
->palette
[0] >> 12 & 7) {
134 frame_offset
+= 0x200;
137 frame_offset
+= 0x20;
142 switch ((omap_lcd
->palette
[0] >> 12) & 7) {
144 draw_line
= draw_line_table2
[surface_bits_per_pixel(surface
)];
149 draw_line
= draw_line_table4
[surface_bits_per_pixel(surface
)];
154 draw_line
= draw_line_table8
[surface_bits_per_pixel(surface
)];
160 draw_line
= draw_line_table12
[surface_bits_per_pixel(surface
)];
162 draw_line
= draw_line_table16
[surface_bits_per_pixel(surface
)];
167 /* Unsupported at the moment. */
172 width
= omap_lcd
->width
;
173 if (width
!= surface_width(surface
) ||
174 omap_lcd
->height
!= surface_height(surface
)) {
175 qemu_console_resize(omap_lcd
->con
,
176 omap_lcd
->width
, omap_lcd
->height
);
177 surface
= qemu_console_surface(omap_lcd
->con
);
178 omap_lcd
->invalidate
= 1;
181 if (omap_lcd
->dma
->current_frame
== 0)
182 size
= omap_lcd
->dma
->src_f1_bottom
- omap_lcd
->dma
->src_f1_top
;
184 size
= omap_lcd
->dma
->src_f2_bottom
- omap_lcd
->dma
->src_f2_top
;
186 if (frame_offset
+ ((width
* omap_lcd
->height
* bpp
) >> 3) > size
+ 2) {
187 omap_lcd
->sync_error
= 1;
188 omap_lcd_interrupts(omap_lcd
);
189 omap_lcd
->enable
= 0;
194 frame_base
= omap_lcd
->dma
->phys_framebuffer
[
195 omap_lcd
->dma
->current_frame
] + frame_offset
;
196 omap_lcd
->dma
->condition
|= 1 << omap_lcd
->dma
->current_frame
;
197 if (omap_lcd
->dma
->interrupts
& 1)
198 qemu_irq_raise(omap_lcd
->dma
->irq
);
199 if (omap_lcd
->dma
->dual
)
200 omap_lcd
->dma
->current_frame
^= 1;
202 if (!surface_bits_per_pixel(surface
)) {
207 height
= omap_lcd
->height
;
208 if (omap_lcd
->subpanel
& (1 << 31)) {
209 if (omap_lcd
->subpanel
& (1 << 29))
210 first
= (omap_lcd
->subpanel
>> 16) & 0x3ff;
212 height
= (omap_lcd
->subpanel
>> 16) & 0x3ff;
213 /* TODO: fill the rest of the panel with DPD */
216 step
= width
* bpp
>> 3;
217 linesize
= surface_stride(surface
);
218 framebuffer_update_display(surface
, omap_lcd
->sysmem
,
219 frame_base
, width
, height
,
221 omap_lcd
->invalidate
,
222 draw_line
, omap_lcd
->palette
,
225 dpy_gfx_update(omap_lcd
->con
, 0, first
, width
, last
- first
+ 1);
227 omap_lcd
->invalidate
= 0;
230 static void omap_invalidate_display(void *opaque
) {
231 struct omap_lcd_panel_s
*omap_lcd
= opaque
;
232 omap_lcd
->invalidate
= 1;
235 static void omap_lcd_update(struct omap_lcd_panel_s
*s
) {
237 s
->dma
->current_frame
= -1;
241 omap_lcd_interrupts(s
);
245 if (s
->dma
->current_frame
== -1) {
248 s
->dma
->current_frame
= 0;
251 if (!s
->dma
->mpu
->port
[s
->dma
->src
].addr_valid(s
->dma
->mpu
,
252 s
->dma
->src_f1_top
) ||
254 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
255 s
->dma
->src_f1_bottom
) ||
258 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
259 s
->dma
->src_f2_top
) ||
261 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
262 s
->dma
->src_f2_bottom
)))) {
263 s
->dma
->condition
|= 1 << 2;
264 if (s
->dma
->interrupts
& (1 << 1))
265 qemu_irq_raise(s
->dma
->irq
);
270 s
->dma
->phys_framebuffer
[0] = s
->dma
->src_f1_top
;
271 s
->dma
->phys_framebuffer
[1] = s
->dma
->src_f2_top
;
273 if (s
->plm
!= 2 && !s
->palette_done
) {
274 cpu_physical_memory_read(
275 s
->dma
->phys_framebuffer
[s
->dma
->current_frame
],
276 (void *)s
->palette
, 0x200);
278 omap_lcd_interrupts(s
);
282 static uint64_t omap_lcdc_read(void *opaque
, hwaddr addr
,
285 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*) opaque
;
288 case 0x00: /* LCD_CONTROL */
289 return (s
->tft
<< 23) | (s
->plm
<< 20) |
290 (s
->tft
<< 7) | (s
->interrupts
<< 3) |
291 (s
->mono
<< 1) | s
->enable
| s
->ctrl
| 0xfe000c34;
293 case 0x04: /* LCD_TIMING0 */
294 return (s
->timing
[0] << 10) | (s
->width
- 1) | 0x0000000f;
296 case 0x08: /* LCD_TIMING1 */
297 return (s
->timing
[1] << 10) | (s
->height
- 1);
299 case 0x0c: /* LCD_TIMING2 */
300 return s
->timing
[2] | 0xfc000000;
302 case 0x10: /* LCD_STATUS */
303 return (s
->palette_done
<< 6) | (s
->sync_error
<< 2) | s
->frame_done
;
305 case 0x14: /* LCD_SUBPANEL */
315 static void omap_lcdc_write(void *opaque
, hwaddr addr
,
316 uint64_t value
, unsigned size
)
318 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*) opaque
;
321 case 0x00: /* LCD_CONTROL */
322 s
->plm
= (value
>> 20) & 3;
323 s
->tft
= (value
>> 7) & 1;
324 s
->interrupts
= (value
>> 3) & 3;
325 s
->mono
= (value
>> 1) & 1;
326 s
->ctrl
= value
& 0x01cff300;
327 if (s
->enable
!= (value
& 1)) {
328 s
->enable
= value
& 1;
333 case 0x04: /* LCD_TIMING0 */
334 s
->timing
[0] = value
>> 10;
335 s
->width
= (value
& 0x3ff) + 1;
338 case 0x08: /* LCD_TIMING1 */
339 s
->timing
[1] = value
>> 10;
340 s
->height
= (value
& 0x3ff) + 1;
343 case 0x0c: /* LCD_TIMING2 */
344 s
->timing
[2] = value
;
347 case 0x10: /* LCD_STATUS */
350 case 0x14: /* LCD_SUBPANEL */
351 s
->subpanel
= value
& 0xa1ffffff;
359 static const MemoryRegionOps omap_lcdc_ops
= {
360 .read
= omap_lcdc_read
,
361 .write
= omap_lcdc_write
,
362 .endianness
= DEVICE_NATIVE_ENDIAN
,
365 void omap_lcdc_reset(struct omap_lcd_panel_s
*s
)
367 s
->dma
->current_frame
= -1;
387 static const GraphicHwOps omap_ops
= {
388 .invalidate
= omap_invalidate_display
,
389 .gfx_update
= omap_update_display
,
392 struct omap_lcd_panel_s
*omap_lcdc_init(MemoryRegion
*sysmem
,
395 struct omap_dma_lcd_channel_s
*dma
,
398 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*)
399 g_malloc0(sizeof(struct omap_lcd_panel_s
));
406 memory_region_init_io(&s
->iomem
, NULL
, &omap_lcdc_ops
, s
, "omap.lcdc", 0x100);
407 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
409 s
->con
= graphic_console_init(NULL
, 0, &omap_ops
, s
);