2 * Intel XScale PXA255/270 LCDC emulation.
4 * Copyright (c) 2006 Openedhand Ltd.
5 * Written by Andrzej Zaborowski <balrog@zabor.org>
7 * This code is licensed under the GPLv2.
13 #include "pixel_ops.h"
14 /* FIXME: For graphic_rotate. Should probably be done in common code. */
16 #include "framebuffer.h"
18 struct PXA2xxLCDState
{
54 target_phys_addr_t branch
;
56 uint8_t palette
[1024];
57 uint8_t pbuffer
[1024];
58 void (*redraw
)(PXA2xxLCDState
*s
, target_phys_addr_t addr
,
59 int *miny
, int *maxy
);
61 target_phys_addr_t descriptor
;
62 target_phys_addr_t source
;
71 typedef struct __attribute__ ((__packed__
)) {
78 #define LCCR0 0x000 /* LCD Controller Control register 0 */
79 #define LCCR1 0x004 /* LCD Controller Control register 1 */
80 #define LCCR2 0x008 /* LCD Controller Control register 2 */
81 #define LCCR3 0x00c /* LCD Controller Control register 3 */
82 #define LCCR4 0x010 /* LCD Controller Control register 4 */
83 #define LCCR5 0x014 /* LCD Controller Control register 5 */
85 #define FBR0 0x020 /* DMA Channel 0 Frame Branch register */
86 #define FBR1 0x024 /* DMA Channel 1 Frame Branch register */
87 #define FBR2 0x028 /* DMA Channel 2 Frame Branch register */
88 #define FBR3 0x02c /* DMA Channel 3 Frame Branch register */
89 #define FBR4 0x030 /* DMA Channel 4 Frame Branch register */
90 #define FBR5 0x110 /* DMA Channel 5 Frame Branch register */
91 #define FBR6 0x114 /* DMA Channel 6 Frame Branch register */
93 #define LCSR1 0x034 /* LCD Controller Status register 1 */
94 #define LCSR0 0x038 /* LCD Controller Status register 0 */
95 #define LIIDR 0x03c /* LCD Controller Interrupt ID register */
97 #define TRGBR 0x040 /* TMED RGB Seed register */
98 #define TCR 0x044 /* TMED Control register */
100 #define OVL1C1 0x050 /* Overlay 1 Control register 1 */
101 #define OVL1C2 0x060 /* Overlay 1 Control register 2 */
102 #define OVL2C1 0x070 /* Overlay 2 Control register 1 */
103 #define OVL2C2 0x080 /* Overlay 2 Control register 2 */
104 #define CCR 0x090 /* Cursor Control register */
106 #define CMDCR 0x100 /* Command Control register */
107 #define PRSR 0x104 /* Panel Read Status register */
109 #define PXA_LCDDMA_CHANS 7
110 #define DMA_FDADR 0x00 /* Frame Descriptor Address register */
111 #define DMA_FSADR 0x04 /* Frame Source Address register */
112 #define DMA_FIDR 0x08 /* Frame ID register */
113 #define DMA_LDCMD 0x0c /* Command register */
115 /* LCD Buffer Strength Control register */
116 #define BSCNTR 0x04000054
119 #define LCCR0_ENB (1 << 0)
120 #define LCCR0_CMS (1 << 1)
121 #define LCCR0_SDS (1 << 2)
122 #define LCCR0_LDM (1 << 3)
123 #define LCCR0_SOFM0 (1 << 4)
124 #define LCCR0_IUM (1 << 5)
125 #define LCCR0_EOFM0 (1 << 6)
126 #define LCCR0_PAS (1 << 7)
127 #define LCCR0_DPD (1 << 9)
128 #define LCCR0_DIS (1 << 10)
129 #define LCCR0_QDM (1 << 11)
130 #define LCCR0_PDD (0xff << 12)
131 #define LCCR0_BSM0 (1 << 20)
132 #define LCCR0_OUM (1 << 21)
133 #define LCCR0_LCDT (1 << 22)
134 #define LCCR0_RDSTM (1 << 23)
135 #define LCCR0_CMDIM (1 << 24)
136 #define LCCR0_OUC (1 << 25)
137 #define LCCR0_LDDALT (1 << 26)
138 #define LCCR1_PPL(x) ((x) & 0x3ff)
139 #define LCCR2_LPP(x) ((x) & 0x3ff)
140 #define LCCR3_API (15 << 16)
141 #define LCCR3_BPP(x) ((((x) >> 24) & 7) | (((x) >> 26) & 8))
142 #define LCCR3_PDFOR(x) (((x) >> 30) & 3)
143 #define LCCR4_K1(x) (((x) >> 0) & 7)
144 #define LCCR4_K2(x) (((x) >> 3) & 7)
145 #define LCCR4_K3(x) (((x) >> 6) & 7)
146 #define LCCR4_PALFOR(x) (((x) >> 15) & 3)
147 #define LCCR5_SOFM(ch) (1 << (ch - 1))
148 #define LCCR5_EOFM(ch) (1 << (ch + 7))
149 #define LCCR5_BSM(ch) (1 << (ch + 15))
150 #define LCCR5_IUM(ch) (1 << (ch + 23))
151 #define OVLC1_EN (1 << 31)
152 #define CCR_CEN (1 << 31)
153 #define FBR_BRA (1 << 0)
154 #define FBR_BINT (1 << 1)
155 #define FBR_SRCADDR (0xfffffff << 4)
156 #define LCSR0_LDD (1 << 0)
157 #define LCSR0_SOF0 (1 << 1)
158 #define LCSR0_BER (1 << 2)
159 #define LCSR0_ABC (1 << 3)
160 #define LCSR0_IU0 (1 << 4)
161 #define LCSR0_IU1 (1 << 5)
162 #define LCSR0_OU (1 << 6)
163 #define LCSR0_QD (1 << 7)
164 #define LCSR0_EOF0 (1 << 8)
165 #define LCSR0_BS0 (1 << 9)
166 #define LCSR0_SINT (1 << 10)
167 #define LCSR0_RDST (1 << 11)
168 #define LCSR0_CMDINT (1 << 12)
169 #define LCSR0_BERCH(x) (((x) & 7) << 28)
170 #define LCSR1_SOF(ch) (1 << (ch - 1))
171 #define LCSR1_EOF(ch) (1 << (ch + 7))
172 #define LCSR1_BS(ch) (1 << (ch + 15))
173 #define LCSR1_IU(ch) (1 << (ch + 23))
174 #define LDCMD_LENGTH(x) ((x) & 0x001ffffc)
175 #define LDCMD_EOFINT (1 << 21)
176 #define LDCMD_SOFINT (1 << 22)
177 #define LDCMD_PAL (1 << 26)
179 /* Route internal interrupt lines to the global IC */
180 static void pxa2xx_lcdc_int_update(PXA2xxLCDState
*s
)
183 level
|= (s
->status
[0] & LCSR0_LDD
) && !(s
->control
[0] & LCCR0_LDM
);
184 level
|= (s
->status
[0] & LCSR0_SOF0
) && !(s
->control
[0] & LCCR0_SOFM0
);
185 level
|= (s
->status
[0] & LCSR0_IU0
) && !(s
->control
[0] & LCCR0_IUM
);
186 level
|= (s
->status
[0] & LCSR0_IU1
) && !(s
->control
[5] & LCCR5_IUM(1));
187 level
|= (s
->status
[0] & LCSR0_OU
) && !(s
->control
[0] & LCCR0_OUM
);
188 level
|= (s
->status
[0] & LCSR0_QD
) && !(s
->control
[0] & LCCR0_QDM
);
189 level
|= (s
->status
[0] & LCSR0_EOF0
) && !(s
->control
[0] & LCCR0_EOFM0
);
190 level
|= (s
->status
[0] & LCSR0_BS0
) && !(s
->control
[0] & LCCR0_BSM0
);
191 level
|= (s
->status
[0] & LCSR0_RDST
) && !(s
->control
[0] & LCCR0_RDSTM
);
192 level
|= (s
->status
[0] & LCSR0_CMDINT
) && !(s
->control
[0] & LCCR0_CMDIM
);
193 level
|= (s
->status
[1] & ~s
->control
[5]);
195 qemu_set_irq(s
->irq
, !!level
);
199 /* Set Branch Status interrupt high and poke associated registers */
200 static inline void pxa2xx_dma_bs_set(PXA2xxLCDState
*s
, int ch
)
204 s
->status
[0] |= LCSR0_BS0
;
205 unmasked
= !(s
->control
[0] & LCCR0_BSM0
);
207 s
->status
[1] |= LCSR1_BS(ch
);
208 unmasked
= !(s
->control
[5] & LCCR5_BSM(ch
));
213 s
->status
[0] |= LCSR0_SINT
;
215 s
->liidr
= s
->dma_ch
[ch
].id
;
219 /* Set Start Of Frame Status interrupt high and poke associated registers */
220 static inline void pxa2xx_dma_sof_set(PXA2xxLCDState
*s
, int ch
)
223 if (!(s
->dma_ch
[ch
].command
& LDCMD_SOFINT
))
227 s
->status
[0] |= LCSR0_SOF0
;
228 unmasked
= !(s
->control
[0] & LCCR0_SOFM0
);
230 s
->status
[1] |= LCSR1_SOF(ch
);
231 unmasked
= !(s
->control
[5] & LCCR5_SOFM(ch
));
236 s
->status
[0] |= LCSR0_SINT
;
238 s
->liidr
= s
->dma_ch
[ch
].id
;
242 /* Set End Of Frame Status interrupt high and poke associated registers */
243 static inline void pxa2xx_dma_eof_set(PXA2xxLCDState
*s
, int ch
)
246 if (!(s
->dma_ch
[ch
].command
& LDCMD_EOFINT
))
250 s
->status
[0] |= LCSR0_EOF0
;
251 unmasked
= !(s
->control
[0] & LCCR0_EOFM0
);
253 s
->status
[1] |= LCSR1_EOF(ch
);
254 unmasked
= !(s
->control
[5] & LCCR5_EOFM(ch
));
259 s
->status
[0] |= LCSR0_SINT
;
261 s
->liidr
= s
->dma_ch
[ch
].id
;
265 /* Set Bus Error Status interrupt high and poke associated registers */
266 static inline void pxa2xx_dma_ber_set(PXA2xxLCDState
*s
, int ch
)
268 s
->status
[0] |= LCSR0_BERCH(ch
) | LCSR0_BER
;
270 s
->status
[0] |= LCSR0_SINT
;
272 s
->liidr
= s
->dma_ch
[ch
].id
;
275 /* Set Read Status interrupt high and poke associated registers */
276 static inline void pxa2xx_dma_rdst_set(PXA2xxLCDState
*s
)
278 s
->status
[0] |= LCSR0_RDST
;
279 if (s
->irqlevel
&& !(s
->control
[0] & LCCR0_RDSTM
))
280 s
->status
[0] |= LCSR0_SINT
;
283 /* Load new Frame Descriptors from DMA */
284 static void pxa2xx_descriptor_load(PXA2xxLCDState
*s
)
286 PXAFrameDescriptor desc
;
287 target_phys_addr_t descptr
;
290 for (i
= 0; i
< PXA_LCDDMA_CHANS
; i
++) {
291 s
->dma_ch
[i
].source
= 0;
293 if (!s
->dma_ch
[i
].up
)
296 if (s
->dma_ch
[i
].branch
& FBR_BRA
) {
297 descptr
= s
->dma_ch
[i
].branch
& FBR_SRCADDR
;
298 if (s
->dma_ch
[i
].branch
& FBR_BINT
)
299 pxa2xx_dma_bs_set(s
, i
);
300 s
->dma_ch
[i
].branch
&= ~FBR_BRA
;
302 descptr
= s
->dma_ch
[i
].descriptor
;
304 if (!(descptr
>= PXA2XX_SDRAM_BASE
&& descptr
+
305 sizeof(desc
) <= PXA2XX_SDRAM_BASE
+ ram_size
))
308 cpu_physical_memory_read(descptr
, (void *)&desc
, sizeof(desc
));
309 s
->dma_ch
[i
].descriptor
= tswap32(desc
.fdaddr
);
310 s
->dma_ch
[i
].source
= tswap32(desc
.fsaddr
);
311 s
->dma_ch
[i
].id
= tswap32(desc
.fidr
);
312 s
->dma_ch
[i
].command
= tswap32(desc
.ldcmd
);
316 static uint32_t pxa2xx_lcdc_read(void *opaque
, target_phys_addr_t offset
)
318 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
323 return s
->control
[0];
325 return s
->control
[1];
327 return s
->control
[2];
329 return s
->control
[3];
331 return s
->control
[4];
333 return s
->control
[5];
355 case 0x200 ... 0x1000: /* DMA per-channel registers */
356 ch
= (offset
- 0x200) >> 4;
357 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
360 switch (offset
& 0xf) {
362 return s
->dma_ch
[ch
].descriptor
;
364 return s
->dma_ch
[ch
].source
;
366 return s
->dma_ch
[ch
].id
;
368 return s
->dma_ch
[ch
].command
;
374 return s
->dma_ch
[0].branch
;
376 return s
->dma_ch
[1].branch
;
378 return s
->dma_ch
[2].branch
;
380 return s
->dma_ch
[3].branch
;
382 return s
->dma_ch
[4].branch
;
384 return s
->dma_ch
[5].branch
;
386 return s
->dma_ch
[6].branch
;
403 hw_error("%s: Bad offset " REG_FMT
"\n", __FUNCTION__
, offset
);
409 static void pxa2xx_lcdc_write(void *opaque
,
410 target_phys_addr_t offset
, uint32_t value
)
412 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
417 /* ACK Quick Disable done */
418 if ((s
->control
[0] & LCCR0_ENB
) && !(value
& LCCR0_ENB
))
419 s
->status
[0] |= LCSR0_QD
;
421 if (!(s
->control
[0] & LCCR0_LCDT
) && (value
& LCCR0_LCDT
))
422 printf("%s: internal frame buffer unsupported\n", __FUNCTION__
);
424 if ((s
->control
[3] & LCCR3_API
) &&
425 (value
& LCCR0_ENB
) && !(value
& LCCR0_LCDT
))
426 s
->status
[0] |= LCSR0_ABC
;
428 s
->control
[0] = value
& 0x07ffffff;
429 pxa2xx_lcdc_int_update(s
);
431 s
->dma_ch
[0].up
= !!(value
& LCCR0_ENB
);
432 s
->dma_ch
[1].up
= (s
->ovl1c
[0] & OVLC1_EN
) || (value
& LCCR0_SDS
);
436 s
->control
[1] = value
;
440 s
->control
[2] = value
;
444 s
->control
[3] = value
& 0xefffffff;
445 s
->bpp
= LCCR3_BPP(value
);
449 s
->control
[4] = value
& 0x83ff81ff;
453 s
->control
[5] = value
& 0x3f3f3f3f;
457 if (!(s
->ovl1c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
))
458 printf("%s: Overlay 1 not supported\n", __FUNCTION__
);
460 s
->ovl1c
[0] = value
& 0x80ffffff;
461 s
->dma_ch
[1].up
= (value
& OVLC1_EN
) || (s
->control
[0] & LCCR0_SDS
);
465 s
->ovl1c
[1] = value
& 0x000fffff;
469 if (!(s
->ovl2c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
))
470 printf("%s: Overlay 2 not supported\n", __FUNCTION__
);
472 s
->ovl2c
[0] = value
& 0x80ffffff;
473 s
->dma_ch
[2].up
= !!(value
& OVLC1_EN
);
474 s
->dma_ch
[3].up
= !!(value
& OVLC1_EN
);
475 s
->dma_ch
[4].up
= !!(value
& OVLC1_EN
);
479 s
->ovl2c
[1] = value
& 0x007fffff;
483 if (!(s
->ccr
& CCR_CEN
) && (value
& CCR_CEN
))
484 printf("%s: Hardware cursor unimplemented\n", __FUNCTION__
);
486 s
->ccr
= value
& 0x81ffffe7;
487 s
->dma_ch
[5].up
= !!(value
& CCR_CEN
);
491 s
->cmdcr
= value
& 0xff;
495 s
->trgbr
= value
& 0x00ffffff;
499 s
->tcr
= value
& 0x7fff;
502 case 0x200 ... 0x1000: /* DMA per-channel registers */
503 ch
= (offset
- 0x200) >> 4;
504 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
507 switch (offset
& 0xf) {
509 s
->dma_ch
[ch
].descriptor
= value
& 0xfffffff0;
518 s
->dma_ch
[0].branch
= value
& 0xfffffff3;
521 s
->dma_ch
[1].branch
= value
& 0xfffffff3;
524 s
->dma_ch
[2].branch
= value
& 0xfffffff3;
527 s
->dma_ch
[3].branch
= value
& 0xfffffff3;
530 s
->dma_ch
[4].branch
= value
& 0xfffffff3;
533 s
->dma_ch
[5].branch
= value
& 0xfffffff3;
536 s
->dma_ch
[6].branch
= value
& 0xfffffff3;
540 s
->bscntr
= value
& 0xf;
547 s
->status
[0] &= ~(value
& 0xfff);
548 if (value
& LCSR0_BER
)
549 s
->status
[0] &= ~LCSR0_BERCH(7);
553 s
->status
[1] &= ~(value
& 0x3e3f3f);
558 hw_error("%s: Bad offset " REG_FMT
"\n", __FUNCTION__
, offset
);
562 static CPUReadMemoryFunc
* const pxa2xx_lcdc_readfn
[] = {
568 static CPUWriteMemoryFunc
* const pxa2xx_lcdc_writefn
[] = {
574 /* Load new palette for a given DMA channel, convert to internal format */
575 static void pxa2xx_palette_parse(PXA2xxLCDState
*s
, int ch
, int bpp
)
577 int i
, n
, format
, r
, g
, b
, alpha
;
578 uint32_t *dest
, *src
;
579 s
->pal_for
= LCCR4_PALFOR(s
->control
[4]);
597 src
= (uint32_t *) s
->dma_ch
[ch
].pbuffer
;
598 dest
= (uint32_t *) s
->dma_ch
[ch
].palette
;
599 alpha
= r
= g
= b
= 0;
601 for (i
= 0; i
< n
; i
++) {
603 case 0: /* 16 bpp, no transparency */
605 if (s
->control
[0] & LCCR0_CMS
)
606 r
= g
= b
= *src
& 0xff;
608 r
= (*src
& 0xf800) >> 8;
609 g
= (*src
& 0x07e0) >> 3;
610 b
= (*src
& 0x001f) << 3;
613 case 1: /* 16 bpp plus transparency */
614 alpha
= *src
& (1 << 24);
615 if (s
->control
[0] & LCCR0_CMS
)
616 r
= g
= b
= *src
& 0xff;
618 r
= (*src
& 0xf800) >> 8;
619 g
= (*src
& 0x07e0) >> 3;
620 b
= (*src
& 0x001f) << 3;
623 case 2: /* 18 bpp plus transparency */
624 alpha
= *src
& (1 << 24);
625 if (s
->control
[0] & LCCR0_CMS
)
626 r
= g
= b
= *src
& 0xff;
628 r
= (*src
& 0xf80000) >> 16;
629 g
= (*src
& 0x00fc00) >> 8;
630 b
= (*src
& 0x0000f8);
633 case 3: /* 24 bpp plus transparency */
634 alpha
= *src
& (1 << 24);
635 if (s
->control
[0] & LCCR0_CMS
)
636 r
= g
= b
= *src
& 0xff;
638 r
= (*src
& 0xff0000) >> 16;
639 g
= (*src
& 0x00ff00) >> 8;
640 b
= (*src
& 0x0000ff);
644 switch (ds_get_bits_per_pixel(s
->ds
)) {
646 *dest
= rgb_to_pixel8(r
, g
, b
) | alpha
;
649 *dest
= rgb_to_pixel15(r
, g
, b
) | alpha
;
652 *dest
= rgb_to_pixel16(r
, g
, b
) | alpha
;
655 *dest
= rgb_to_pixel24(r
, g
, b
) | alpha
;
658 *dest
= rgb_to_pixel32(r
, g
, b
) | alpha
;
666 static void pxa2xx_lcdc_dma0_redraw_horiz(PXA2xxLCDState
*s
,
667 target_phys_addr_t addr
, int *miny
, int *maxy
)
669 int src_width
, dest_width
;
672 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
676 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
677 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
679 else if (s
->bpp
> pxa_lcdc_16bpp
)
681 else if (s
->bpp
> pxa_lcdc_8bpp
)
684 dest_width
= s
->xres
* s
->dest_width
;
686 framebuffer_update_display(s
->ds
,
687 addr
, s
->xres
, s
->yres
,
688 src_width
, dest_width
, s
->dest_width
,
690 fn
, s
->dma_ch
[0].palette
, miny
, maxy
);
693 static void pxa2xx_lcdc_dma0_redraw_vert(PXA2xxLCDState
*s
,
694 target_phys_addr_t addr
, int *miny
, int *maxy
)
696 int src_width
, dest_width
;
699 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
703 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
704 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
706 else if (s
->bpp
> pxa_lcdc_16bpp
)
708 else if (s
->bpp
> pxa_lcdc_8bpp
)
711 dest_width
= s
->yres
* s
->dest_width
;
713 framebuffer_update_display(s
->ds
,
714 addr
, s
->xres
, s
->yres
,
715 src_width
, s
->dest_width
, -dest_width
,
717 fn
, s
->dma_ch
[0].palette
,
721 static void pxa2xx_lcdc_resize(PXA2xxLCDState
*s
)
724 if (!(s
->control
[0] & LCCR0_ENB
))
727 width
= LCCR1_PPL(s
->control
[1]) + 1;
728 height
= LCCR2_LPP(s
->control
[2]) + 1;
730 if (width
!= s
->xres
|| height
!= s
->yres
) {
732 qemu_console_resize(s
->ds
, height
, width
);
734 qemu_console_resize(s
->ds
, width
, height
);
741 static void pxa2xx_update_display(void *opaque
)
743 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
744 target_phys_addr_t fbptr
;
747 if (!(s
->control
[0] & LCCR0_ENB
))
750 pxa2xx_descriptor_load(s
);
752 pxa2xx_lcdc_resize(s
);
755 s
->transp
= s
->dma_ch
[2].up
|| s
->dma_ch
[3].up
;
756 /* Note: With overlay planes the order depends on LCCR0 bit 25. */
757 for (ch
= 0; ch
< PXA_LCDDMA_CHANS
; ch
++)
758 if (s
->dma_ch
[ch
].up
) {
759 if (!s
->dma_ch
[ch
].source
) {
760 pxa2xx_dma_ber_set(s
, ch
);
763 fbptr
= s
->dma_ch
[ch
].source
;
764 if (!(fbptr
>= PXA2XX_SDRAM_BASE
&&
765 fbptr
<= PXA2XX_SDRAM_BASE
+ ram_size
)) {
766 pxa2xx_dma_ber_set(s
, ch
);
770 if (s
->dma_ch
[ch
].command
& LDCMD_PAL
) {
771 cpu_physical_memory_read(fbptr
, s
->dma_ch
[ch
].pbuffer
,
772 MAX(LDCMD_LENGTH(s
->dma_ch
[ch
].command
),
773 sizeof(s
->dma_ch
[ch
].pbuffer
)));
774 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
776 /* Do we need to reparse palette */
777 if (LCCR4_PALFOR(s
->control
[4]) != s
->pal_for
)
778 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
780 /* ACK frame start */
781 pxa2xx_dma_sof_set(s
, ch
);
783 s
->dma_ch
[ch
].redraw(s
, fbptr
, &miny
, &maxy
);
786 /* ACK frame completed */
787 pxa2xx_dma_eof_set(s
, ch
);
791 if (s
->control
[0] & LCCR0_DIS
) {
792 /* ACK last frame completed */
793 s
->control
[0] &= ~LCCR0_ENB
;
794 s
->status
[0] |= LCSR0_LDD
;
799 dpy_update(s
->ds
, miny
, 0, maxy
, s
->xres
);
801 dpy_update(s
->ds
, 0, miny
, s
->xres
, maxy
);
803 pxa2xx_lcdc_int_update(s
);
805 qemu_irq_raise(s
->vsync_cb
);
808 static void pxa2xx_invalidate_display(void *opaque
)
810 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
814 static void pxa2xx_screen_dump(void *opaque
, const char *filename
)
819 static void pxa2xx_lcdc_orientation(void *opaque
, int angle
)
821 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
824 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_vert
;
826 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_horiz
;
829 s
->orientation
= angle
;
830 s
->xres
= s
->yres
= -1;
831 pxa2xx_lcdc_resize(s
);
834 static void pxa2xx_lcdc_save(QEMUFile
*f
, void *opaque
)
836 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
839 qemu_put_be32(f
, s
->irqlevel
);
840 qemu_put_be32(f
, s
->transp
);
842 for (i
= 0; i
< 6; i
++)
843 qemu_put_be32s(f
, &s
->control
[i
]);
844 for (i
= 0; i
< 2; i
++)
845 qemu_put_be32s(f
, &s
->status
[i
]);
846 for (i
= 0; i
< 2; i
++)
847 qemu_put_be32s(f
, &s
->ovl1c
[i
]);
848 for (i
= 0; i
< 2; i
++)
849 qemu_put_be32s(f
, &s
->ovl2c
[i
]);
850 qemu_put_be32s(f
, &s
->ccr
);
851 qemu_put_be32s(f
, &s
->cmdcr
);
852 qemu_put_be32s(f
, &s
->trgbr
);
853 qemu_put_be32s(f
, &s
->tcr
);
854 qemu_put_be32s(f
, &s
->liidr
);
855 qemu_put_8s(f
, &s
->bscntr
);
857 for (i
= 0; i
< 7; i
++) {
858 qemu_put_betl(f
, s
->dma_ch
[i
].branch
);
859 qemu_put_byte(f
, s
->dma_ch
[i
].up
);
860 qemu_put_buffer(f
, s
->dma_ch
[i
].pbuffer
, sizeof(s
->dma_ch
[i
].pbuffer
));
862 qemu_put_betl(f
, s
->dma_ch
[i
].descriptor
);
863 qemu_put_betl(f
, s
->dma_ch
[i
].source
);
864 qemu_put_be32s(f
, &s
->dma_ch
[i
].id
);
865 qemu_put_be32s(f
, &s
->dma_ch
[i
].command
);
869 static int pxa2xx_lcdc_load(QEMUFile
*f
, void *opaque
, int version_id
)
871 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
874 s
->irqlevel
= qemu_get_be32(f
);
875 s
->transp
= qemu_get_be32(f
);
877 for (i
= 0; i
< 6; i
++)
878 qemu_get_be32s(f
, &s
->control
[i
]);
879 for (i
= 0; i
< 2; i
++)
880 qemu_get_be32s(f
, &s
->status
[i
]);
881 for (i
= 0; i
< 2; i
++)
882 qemu_get_be32s(f
, &s
->ovl1c
[i
]);
883 for (i
= 0; i
< 2; i
++)
884 qemu_get_be32s(f
, &s
->ovl2c
[i
]);
885 qemu_get_be32s(f
, &s
->ccr
);
886 qemu_get_be32s(f
, &s
->cmdcr
);
887 qemu_get_be32s(f
, &s
->trgbr
);
888 qemu_get_be32s(f
, &s
->tcr
);
889 qemu_get_be32s(f
, &s
->liidr
);
890 qemu_get_8s(f
, &s
->bscntr
);
892 for (i
= 0; i
< 7; i
++) {
893 s
->dma_ch
[i
].branch
= qemu_get_betl(f
);
894 s
->dma_ch
[i
].up
= qemu_get_byte(f
);
895 qemu_get_buffer(f
, s
->dma_ch
[i
].pbuffer
, sizeof(s
->dma_ch
[i
].pbuffer
));
897 s
->dma_ch
[i
].descriptor
= qemu_get_betl(f
);
898 s
->dma_ch
[i
].source
= qemu_get_betl(f
);
899 qemu_get_be32s(f
, &s
->dma_ch
[i
].id
);
900 qemu_get_be32s(f
, &s
->dma_ch
[i
].command
);
903 s
->bpp
= LCCR3_BPP(s
->control
[3]);
904 s
->xres
= s
->yres
= s
->pal_for
= -1;
910 #include "pxa2xx_template.h"
912 #include "pxa2xx_template.h"
914 #include "pxa2xx_template.h"
916 #include "pxa2xx_template.h"
918 #include "pxa2xx_template.h"
920 PXA2xxLCDState
*pxa2xx_lcdc_init(target_phys_addr_t base
, qemu_irq irq
)
925 s
= (PXA2xxLCDState
*) qemu_mallocz(sizeof(PXA2xxLCDState
));
929 pxa2xx_lcdc_orientation(s
, graphic_rotate
);
931 iomemtype
= cpu_register_io_memory(pxa2xx_lcdc_readfn
,
932 pxa2xx_lcdc_writefn
, s
);
933 cpu_register_physical_memory(base
, 0x00100000, iomemtype
);
935 s
->ds
= graphic_console_init(pxa2xx_update_display
,
936 pxa2xx_invalidate_display
,
937 pxa2xx_screen_dump
, NULL
, s
);
939 switch (ds_get_bits_per_pixel(s
->ds
)) {
944 s
->line_fn
[0] = pxa2xx_draw_fn_8
;
945 s
->line_fn
[1] = pxa2xx_draw_fn_8t
;
949 s
->line_fn
[0] = pxa2xx_draw_fn_15
;
950 s
->line_fn
[1] = pxa2xx_draw_fn_15t
;
954 s
->line_fn
[0] = pxa2xx_draw_fn_16
;
955 s
->line_fn
[1] = pxa2xx_draw_fn_16t
;
959 s
->line_fn
[0] = pxa2xx_draw_fn_24
;
960 s
->line_fn
[1] = pxa2xx_draw_fn_24t
;
964 s
->line_fn
[0] = pxa2xx_draw_fn_32
;
965 s
->line_fn
[1] = pxa2xx_draw_fn_32t
;
969 fprintf(stderr
, "%s: Bad color depth\n", __FUNCTION__
);
973 register_savevm("pxa2xx_lcdc", 0, 0,
974 pxa2xx_lcdc_save
, pxa2xx_lcdc_load
, s
);
979 void pxa2xx_lcd_vsync_notifier(PXA2xxLCDState
*s
, qemu_irq handler
)
981 s
->vsync_cb
= handler
;