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, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "framebuffer.h"
25 struct omap_lcd_panel_s
{
29 ram_addr_t emiff_base
;
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 #include "pixel_ops.h"
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 draw_line_func draw_line
;
119 int size
, height
, first
, last
;
120 int width
, linesize
, step
, bpp
, frame_offset
;
121 target_phys_addr_t frame_base
;
123 if (!omap_lcd
|| omap_lcd
->plm
== 1 ||
124 !omap_lcd
->enable
|| !ds_get_bits_per_pixel(omap_lcd
->state
))
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
[ds_get_bits_per_pixel(omap_lcd
->state
)];
149 draw_line
= draw_line_table4
[ds_get_bits_per_pixel(omap_lcd
->state
)];
154 draw_line
= draw_line_table8
[ds_get_bits_per_pixel(omap_lcd
->state
)];
160 draw_line
= draw_line_table12
[ds_get_bits_per_pixel(omap_lcd
->state
)];
162 draw_line
= draw_line_table16
[ds_get_bits_per_pixel(omap_lcd
->state
)];
167 /* Unsupported at the moment. */
172 width
= omap_lcd
->width
;
173 if (width
!= ds_get_width(omap_lcd
->state
) ||
174 omap_lcd
->height
!= ds_get_height(omap_lcd
->state
)) {
175 qemu_console_resize(omap_lcd
->state
,
176 omap_lcd
->width
, omap_lcd
->height
);
177 omap_lcd
->invalidate
= 1;
180 if (omap_lcd
->dma
->current_frame
== 0)
181 size
= omap_lcd
->dma
->src_f1_bottom
- omap_lcd
->dma
->src_f1_top
;
183 size
= omap_lcd
->dma
->src_f2_bottom
- omap_lcd
->dma
->src_f2_top
;
185 if (frame_offset
+ ((width
* omap_lcd
->height
* bpp
) >> 3) > size
+ 2) {
186 omap_lcd
->sync_error
= 1;
187 omap_lcd_interrupts(omap_lcd
);
188 omap_lcd
->enable
= 0;
193 frame_base
= omap_lcd
->dma
->phys_framebuffer
[
194 omap_lcd
->dma
->current_frame
] + frame_offset
;
195 omap_lcd
->dma
->condition
|= 1 << omap_lcd
->dma
->current_frame
;
196 if (omap_lcd
->dma
->interrupts
& 1)
197 qemu_irq_raise(omap_lcd
->dma
->irq
);
198 if (omap_lcd
->dma
->dual
)
199 omap_lcd
->dma
->current_frame
^= 1;
201 if (!ds_get_bits_per_pixel(omap_lcd
->state
))
205 height
= omap_lcd
->height
;
206 if (omap_lcd
->subpanel
& (1 << 31)) {
207 if (omap_lcd
->subpanel
& (1 << 29))
208 first
= (omap_lcd
->subpanel
>> 16) & 0x3ff;
210 height
= (omap_lcd
->subpanel
>> 16) & 0x3ff;
211 /* TODO: fill the rest of the panel with DPD */
214 step
= width
* bpp
>> 3;
215 linesize
= ds_get_linesize(omap_lcd
->state
);
216 framebuffer_update_display(omap_lcd
->state
,
217 frame_base
, width
, height
,
219 omap_lcd
->invalidate
,
220 draw_line
, omap_lcd
->palette
,
223 dpy_update(omap_lcd
->state
, 0, first
, width
, last
- first
+ 1);
225 omap_lcd
->invalidate
= 0;
228 static int ppm_save(const char *filename
, uint8_t *data
,
229 int w
, int h
, int linesize
)
236 f
= fopen(filename
, "wb");
239 fprintf(f
, "P6\n%d %d\n%d\n", w
, h
, 255);
242 for (y
= 0; y
< h
; y
++) {
244 for (x
= 0; x
< w
; x
++) {
248 fputc((v
>> 8) & 0xf8, f
);
249 fputc((v
>> 3) & 0xfc, f
);
250 fputc((v
<< 3) & 0xf8, f
);
255 fputc((v
>> 16) & 0xff, f
);
256 fputc((v
>> 8) & 0xff, f
);
257 fputc((v
) & 0xff, f
);
268 static void omap_screen_dump(void *opaque
, const char *filename
) {
269 struct omap_lcd_panel_s
*omap_lcd
= opaque
;
270 omap_update_display(opaque
);
271 if (omap_lcd
&& ds_get_data(omap_lcd
->state
))
272 ppm_save(filename
, ds_get_data(omap_lcd
->state
),
273 omap_lcd
->width
, omap_lcd
->height
,
274 ds_get_linesize(omap_lcd
->state
));
277 static void omap_invalidate_display(void *opaque
) {
278 struct omap_lcd_panel_s
*omap_lcd
= opaque
;
279 omap_lcd
->invalidate
= 1;
282 static void omap_lcd_update(struct omap_lcd_panel_s
*s
) {
284 s
->dma
->current_frame
= -1;
288 omap_lcd_interrupts(s
);
292 if (s
->dma
->current_frame
== -1) {
295 s
->dma
->current_frame
= 0;
298 if (!s
->dma
->mpu
->port
[s
->dma
->src
].addr_valid(s
->dma
->mpu
,
299 s
->dma
->src_f1_top
) ||
301 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
302 s
->dma
->src_f1_bottom
) ||
305 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
306 s
->dma
->src_f2_top
) ||
308 s
->dma
->src
].addr_valid(s
->dma
->mpu
,
309 s
->dma
->src_f2_bottom
)))) {
310 s
->dma
->condition
|= 1 << 2;
311 if (s
->dma
->interrupts
& (1 << 1))
312 qemu_irq_raise(s
->dma
->irq
);
317 s
->dma
->phys_framebuffer
[0] = s
->dma
->src_f1_top
;
318 s
->dma
->phys_framebuffer
[1] = s
->dma
->src_f2_top
;
320 if (s
->plm
!= 2 && !s
->palette_done
) {
321 cpu_physical_memory_read(
322 s
->dma
->phys_framebuffer
[s
->dma
->current_frame
],
323 (void *)s
->palette
, 0x200);
325 omap_lcd_interrupts(s
);
329 static uint32_t omap_lcdc_read(void *opaque
, target_phys_addr_t addr
)
331 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*) opaque
;
334 case 0x00: /* LCD_CONTROL */
335 return (s
->tft
<< 23) | (s
->plm
<< 20) |
336 (s
->tft
<< 7) | (s
->interrupts
<< 3) |
337 (s
->mono
<< 1) | s
->enable
| s
->ctrl
| 0xfe000c34;
339 case 0x04: /* LCD_TIMING0 */
340 return (s
->timing
[0] << 10) | (s
->width
- 1) | 0x0000000f;
342 case 0x08: /* LCD_TIMING1 */
343 return (s
->timing
[1] << 10) | (s
->height
- 1);
345 case 0x0c: /* LCD_TIMING2 */
346 return s
->timing
[2] | 0xfc000000;
348 case 0x10: /* LCD_STATUS */
349 return (s
->palette_done
<< 6) | (s
->sync_error
<< 2) | s
->frame_done
;
351 case 0x14: /* LCD_SUBPANEL */
361 static void omap_lcdc_write(void *opaque
, target_phys_addr_t addr
,
364 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*) opaque
;
367 case 0x00: /* LCD_CONTROL */
368 s
->plm
= (value
>> 20) & 3;
369 s
->tft
= (value
>> 7) & 1;
370 s
->interrupts
= (value
>> 3) & 3;
371 s
->mono
= (value
>> 1) & 1;
372 s
->ctrl
= value
& 0x01cff300;
373 if (s
->enable
!= (value
& 1)) {
374 s
->enable
= value
& 1;
379 case 0x04: /* LCD_TIMING0 */
380 s
->timing
[0] = value
>> 10;
381 s
->width
= (value
& 0x3ff) + 1;
384 case 0x08: /* LCD_TIMING1 */
385 s
->timing
[1] = value
>> 10;
386 s
->height
= (value
& 0x3ff) + 1;
389 case 0x0c: /* LCD_TIMING2 */
390 s
->timing
[2] = value
;
393 case 0x10: /* LCD_STATUS */
396 case 0x14: /* LCD_SUBPANEL */
397 s
->subpanel
= value
& 0xa1ffffff;
405 static CPUReadMemoryFunc
*omap_lcdc_readfn
[] = {
411 static CPUWriteMemoryFunc
*omap_lcdc_writefn
[] = {
417 void omap_lcdc_reset(struct omap_lcd_panel_s
*s
)
419 s
->dma
->current_frame
= -1;
439 struct omap_lcd_panel_s
*omap_lcdc_init(target_phys_addr_t base
, qemu_irq irq
,
440 struct omap_dma_lcd_channel_s
*dma
,
441 ram_addr_t imif_base
, ram_addr_t emiff_base
, omap_clk clk
)
444 struct omap_lcd_panel_s
*s
= (struct omap_lcd_panel_s
*)
445 qemu_mallocz(sizeof(struct omap_lcd_panel_s
));
449 s
->imif_base
= imif_base
;
450 s
->emiff_base
= emiff_base
;
453 iomemtype
= cpu_register_io_memory(0, omap_lcdc_readfn
,
454 omap_lcdc_writefn
, s
);
455 cpu_register_physical_memory(base
, 0x100, iomemtype
);
457 s
->state
= graphic_console_init(omap_update_display
,
458 omap_invalidate_display
,
459 omap_screen_dump
, NULL
, s
);