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/>.
19 #include "qemu/osdep.h"
21 #include "ui/console.h"
22 #include "hw/arm/omap.h"
23 #include "framebuffer.h"
24 #include "ui/pixel_ops.h"
26 struct omap_lcd_panel_s
{
29 MemoryRegionSection fbsection
;
44 struct omap_dma_lcd_channel_s
*dma
;
45 uint16_t palette
[256];
52 static void omap_lcd_interrupts(struct omap_lcd_panel_s
*s
)
54 if (s
->frame_done
&& (s
->interrupts
& 1)) {
55 qemu_irq_raise(s
->irq
);
59 if (s
->palette_done
&& (s
->interrupts
& 2)) {
60 qemu_irq_raise(s
->irq
);
65 qemu_irq_raise(s
->irq
);
69 qemu_irq_lower(s
->irq
);
72 #define draw_line_func drawfn
75 #include "omap_lcd_template.h"
77 #include "omap_lcd_template.h"
79 #include "omap_lcd_template.h"
81 #include "omap_lcd_template.h"
83 static draw_line_func draw_line_table2
[33] = {
89 }, draw_line_table4
[33] = {
95 }, draw_line_table8
[33] = {
100 [32] = draw_line8_32
,
101 }, draw_line_table12
[33] = {
104 [15] = draw_line12_15
,
105 [16] = draw_line12_16
,
106 [32] = draw_line12_32
,
107 }, draw_line_table16
[33] = {
110 [15] = draw_line16_15
,
111 [16] = draw_line16_16
,
112 [32] = draw_line16_32
,
115 static void omap_update_display(void *opaque
)
117 struct omap_lcd_panel_s
*omap_lcd
= (struct omap_lcd_panel_s
*) opaque
;
118 DisplaySurface
*surface
= qemu_console_surface(omap_lcd
->con
);
119 draw_line_func draw_line
;
120 int size
, height
, first
, last
;
121 int width
, linesize
, step
, bpp
, frame_offset
;
124 if (!omap_lcd
|| omap_lcd
->plm
== 1 || !omap_lcd
->enable
||
125 !surface_bits_per_pixel(surface
)) {
130 if (omap_lcd
->plm
!= 2) {
131 cpu_physical_memory_read(omap_lcd
->dma
->phys_framebuffer
[
132 omap_lcd
->dma
->current_frame
],
133 (void *)omap_lcd
->palette
, 0x200);
134 switch (omap_lcd
->palette
[0] >> 12 & 7) {
136 frame_offset
+= 0x200;
139 frame_offset
+= 0x20;
144 switch ((omap_lcd
->palette
[0] >> 12) & 7) {
146 draw_line
= draw_line_table2
[surface_bits_per_pixel(surface
)];
151 draw_line
= draw_line_table4
[surface_bits_per_pixel(surface
)];
156 draw_line
= draw_line_table8
[surface_bits_per_pixel(surface
)];
162 draw_line
= draw_line_table12
[surface_bits_per_pixel(surface
)];
164 draw_line
= draw_line_table16
[surface_bits_per_pixel(surface
)];
169 /* Unsupported at the moment. */
174 width
= omap_lcd
->width
;
175 if (width
!= surface_width(surface
) ||
176 omap_lcd
->height
!= surface_height(surface
)) {
177 qemu_console_resize(omap_lcd
->con
,
178 omap_lcd
->width
, omap_lcd
->height
);
179 surface
= qemu_console_surface(omap_lcd
->con
);
180 omap_lcd
->invalidate
= 1;
183 if (omap_lcd
->dma
->current_frame
== 0)
184 size
= omap_lcd
->dma
->src_f1_bottom
- omap_lcd
->dma
->src_f1_top
;
186 size
= omap_lcd
->dma
->src_f2_bottom
- omap_lcd
->dma
->src_f2_top
;
188 if (frame_offset
+ ((width
* omap_lcd
->height
* bpp
) >> 3) > size
+ 2) {
189 omap_lcd
->sync_error
= 1;
190 omap_lcd_interrupts(omap_lcd
);
191 omap_lcd
->enable
= 0;
196 frame_base
= omap_lcd
->dma
->phys_framebuffer
[
197 omap_lcd
->dma
->current_frame
] + frame_offset
;
198 omap_lcd
->dma
->condition
|= 1 << omap_lcd
->dma
->current_frame
;
199 if (omap_lcd
->dma
->interrupts
& 1)
200 qemu_irq_raise(omap_lcd
->dma
->irq
);
201 if (omap_lcd
->dma
->dual
)
202 omap_lcd
->dma
->current_frame
^= 1;
204 if (!surface_bits_per_pixel(surface
)) {
209 height
= omap_lcd
->height
;
210 if (omap_lcd
->subpanel
& (1 << 31)) {
211 if (omap_lcd
->subpanel
& (1 << 29))
212 first
= (omap_lcd
->subpanel
>> 16) & 0x3ff;
214 height
= (omap_lcd
->subpanel
>> 16) & 0x3ff;
215 /* TODO: fill the rest of the panel with DPD */
218 step
= width
* bpp
>> 3;
219 linesize
= surface_stride(surface
);
220 if (omap_lcd
->invalidate
) {
221 framebuffer_update_memory_section(&omap_lcd
->fbsection
,
222 omap_lcd
->sysmem
, frame_base
,
226 framebuffer_update_display(surface
, &omap_lcd
->fbsection
,
229 omap_lcd
->invalidate
,
230 draw_line
, omap_lcd
->palette
,
234 dpy_gfx_update(omap_lcd
->con
, 0, first
, width
, last
- first
+ 1);
236 omap_lcd
->invalidate
= 0;
239 static void omap_invalidate_display(void *opaque
) {
240 struct omap_lcd_panel_s
*omap_lcd
= opaque
;
241 omap_lcd
->invalidate
= 1;
244 static void omap_lcd_update(struct omap_lcd_panel_s
*s
) {
246 s
->dma
->current_frame
= -1;
250 omap_lcd_interrupts(s
);
254 if (s
->dma
->current_frame
== -1) {
257 s
->dma
->current_frame
= 0;
260 if (!s
->dma
->mpu
->port
[s
->dma
->src
].addr_valid(s
->dma
->mpu
,
261 s
->dma
->src_f1_top
) ||
263 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
264 s
->dma
->src_f1_bottom
) ||
267 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
268 s
->dma
->src_f2_top
) ||
270 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
271 s
->dma
->src_f2_bottom
)))) {
272 s
->dma
->condition
|= 1 << 2;
273 if (s
->dma
->interrupts
& (1 << 1))
274 qemu_irq_raise(s
->dma
->irq
);
279 s
->dma
->phys_framebuffer
[0] = s
->dma
->src_f1_top
;
280 s
->dma
->phys_framebuffer
[1] = s
->dma
->src_f2_top
;
282 if (s
->plm
!= 2 && !s
->palette_done
) {
283 cpu_physical_memory_read(
284 s
->dma
->phys_framebuffer
[s
->dma
->current_frame
],
285 (void *)s
->palette
, 0x200);
287 omap_lcd_interrupts(s
);
291 static uint64_t omap_lcdc_read(void *opaque
, hwaddr addr
,
294 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*) opaque
;
297 case 0x00: /* LCD_CONTROL */
298 return (s
->tft
<< 23) | (s
->plm
<< 20) |
299 (s
->tft
<< 7) | (s
->interrupts
<< 3) |
300 (s
->mono
<< 1) | s
->enable
| s
->ctrl
| 0xfe000c34;
302 case 0x04: /* LCD_TIMING0 */
303 return (s
->timing
[0] << 10) | (s
->width
- 1) | 0x0000000f;
305 case 0x08: /* LCD_TIMING1 */
306 return (s
->timing
[1] << 10) | (s
->height
- 1);
308 case 0x0c: /* LCD_TIMING2 */
309 return s
->timing
[2] | 0xfc000000;
311 case 0x10: /* LCD_STATUS */
312 return (s
->palette_done
<< 6) | (s
->sync_error
<< 2) | s
->frame_done
;
314 case 0x14: /* LCD_SUBPANEL */
324 static void omap_lcdc_write(void *opaque
, hwaddr addr
,
325 uint64_t value
, unsigned size
)
327 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*) opaque
;
330 case 0x00: /* LCD_CONTROL */
331 s
->plm
= (value
>> 20) & 3;
332 s
->tft
= (value
>> 7) & 1;
333 s
->interrupts
= (value
>> 3) & 3;
334 s
->mono
= (value
>> 1) & 1;
335 s
->ctrl
= value
& 0x01cff300;
336 if (s
->enable
!= (value
& 1)) {
337 s
->enable
= value
& 1;
342 case 0x04: /* LCD_TIMING0 */
343 s
->timing
[0] = value
>> 10;
344 s
->width
= (value
& 0x3ff) + 1;
347 case 0x08: /* LCD_TIMING1 */
348 s
->timing
[1] = value
>> 10;
349 s
->height
= (value
& 0x3ff) + 1;
352 case 0x0c: /* LCD_TIMING2 */
353 s
->timing
[2] = value
;
356 case 0x10: /* LCD_STATUS */
359 case 0x14: /* LCD_SUBPANEL */
360 s
->subpanel
= value
& 0xa1ffffff;
368 static const MemoryRegionOps omap_lcdc_ops
= {
369 .read
= omap_lcdc_read
,
370 .write
= omap_lcdc_write
,
371 .endianness
= DEVICE_NATIVE_ENDIAN
,
374 void omap_lcdc_reset(struct omap_lcd_panel_s
*s
)
376 s
->dma
->current_frame
= -1;
396 static const GraphicHwOps omap_ops
= {
397 .invalidate
= omap_invalidate_display
,
398 .gfx_update
= omap_update_display
,
401 struct omap_lcd_panel_s
*omap_lcdc_init(MemoryRegion
*sysmem
,
404 struct omap_dma_lcd_channel_s
*dma
,
407 struct omap_lcd_panel_s
*s
= g_new0(struct omap_lcd_panel_s
, 1);
414 memory_region_init_io(&s
->iomem
, NULL
, &omap_lcdc_ops
, s
, "omap.lcdc", 0x100);
415 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
417 s
->con
= graphic_console_init(NULL
, 0, &omap_ops
, s
);