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.
9 * Contributions after 2012-01-13 are licensed under the terms of the
10 * GNU GPL, version 2 or (at your option) any later version.
13 #include "qemu/osdep.h"
16 #include "migration/vmstate.h"
17 #include "ui/console.h"
18 #include "hw/arm/pxa.h"
19 #include "ui/pixel_ops.h"
20 /* FIXME: For graphic_rotate. Should probably be done in common code. */
21 #include "sysemu/sysemu.h"
22 #include "framebuffer.h"
27 uint8_t palette
[1024];
28 uint8_t pbuffer
[1024];
29 void (*redraw
)(PXA2xxLCDState
*s
, hwaddr addr
,
30 int *miny
, int *maxy
);
38 struct PXA2xxLCDState
{
41 MemoryRegionSection fbsection
;
76 struct DMAChannel dma_ch
[7];
82 typedef struct QEMU_PACKED
{
89 #define LCCR0 0x000 /* LCD Controller Control register 0 */
90 #define LCCR1 0x004 /* LCD Controller Control register 1 */
91 #define LCCR2 0x008 /* LCD Controller Control register 2 */
92 #define LCCR3 0x00c /* LCD Controller Control register 3 */
93 #define LCCR4 0x010 /* LCD Controller Control register 4 */
94 #define LCCR5 0x014 /* LCD Controller Control register 5 */
96 #define FBR0 0x020 /* DMA Channel 0 Frame Branch register */
97 #define FBR1 0x024 /* DMA Channel 1 Frame Branch register */
98 #define FBR2 0x028 /* DMA Channel 2 Frame Branch register */
99 #define FBR3 0x02c /* DMA Channel 3 Frame Branch register */
100 #define FBR4 0x030 /* DMA Channel 4 Frame Branch register */
101 #define FBR5 0x110 /* DMA Channel 5 Frame Branch register */
102 #define FBR6 0x114 /* DMA Channel 6 Frame Branch register */
104 #define LCSR1 0x034 /* LCD Controller Status register 1 */
105 #define LCSR0 0x038 /* LCD Controller Status register 0 */
106 #define LIIDR 0x03c /* LCD Controller Interrupt ID register */
108 #define TRGBR 0x040 /* TMED RGB Seed register */
109 #define TCR 0x044 /* TMED Control register */
111 #define OVL1C1 0x050 /* Overlay 1 Control register 1 */
112 #define OVL1C2 0x060 /* Overlay 1 Control register 2 */
113 #define OVL2C1 0x070 /* Overlay 2 Control register 1 */
114 #define OVL2C2 0x080 /* Overlay 2 Control register 2 */
115 #define CCR 0x090 /* Cursor Control register */
117 #define CMDCR 0x100 /* Command Control register */
118 #define PRSR 0x104 /* Panel Read Status register */
120 #define PXA_LCDDMA_CHANS 7
121 #define DMA_FDADR 0x00 /* Frame Descriptor Address register */
122 #define DMA_FSADR 0x04 /* Frame Source Address register */
123 #define DMA_FIDR 0x08 /* Frame ID register */
124 #define DMA_LDCMD 0x0c /* Command register */
126 /* LCD Buffer Strength Control register */
127 #define BSCNTR 0x04000054
130 #define LCCR0_ENB (1 << 0)
131 #define LCCR0_CMS (1 << 1)
132 #define LCCR0_SDS (1 << 2)
133 #define LCCR0_LDM (1 << 3)
134 #define LCCR0_SOFM0 (1 << 4)
135 #define LCCR0_IUM (1 << 5)
136 #define LCCR0_EOFM0 (1 << 6)
137 #define LCCR0_PAS (1 << 7)
138 #define LCCR0_DPD (1 << 9)
139 #define LCCR0_DIS (1 << 10)
140 #define LCCR0_QDM (1 << 11)
141 #define LCCR0_PDD (0xff << 12)
142 #define LCCR0_BSM0 (1 << 20)
143 #define LCCR0_OUM (1 << 21)
144 #define LCCR0_LCDT (1 << 22)
145 #define LCCR0_RDSTM (1 << 23)
146 #define LCCR0_CMDIM (1 << 24)
147 #define LCCR0_OUC (1 << 25)
148 #define LCCR0_LDDALT (1 << 26)
149 #define LCCR1_PPL(x) ((x) & 0x3ff)
150 #define LCCR2_LPP(x) ((x) & 0x3ff)
151 #define LCCR3_API (15 << 16)
152 #define LCCR3_BPP(x) ((((x) >> 24) & 7) | (((x) >> 26) & 8))
153 #define LCCR3_PDFOR(x) (((x) >> 30) & 3)
154 #define LCCR4_K1(x) (((x) >> 0) & 7)
155 #define LCCR4_K2(x) (((x) >> 3) & 7)
156 #define LCCR4_K3(x) (((x) >> 6) & 7)
157 #define LCCR4_PALFOR(x) (((x) >> 15) & 3)
158 #define LCCR5_SOFM(ch) (1 << (ch - 1))
159 #define LCCR5_EOFM(ch) (1 << (ch + 7))
160 #define LCCR5_BSM(ch) (1 << (ch + 15))
161 #define LCCR5_IUM(ch) (1 << (ch + 23))
162 #define OVLC1_EN (1 << 31)
163 #define CCR_CEN (1 << 31)
164 #define FBR_BRA (1 << 0)
165 #define FBR_BINT (1 << 1)
166 #define FBR_SRCADDR (0xfffffff << 4)
167 #define LCSR0_LDD (1 << 0)
168 #define LCSR0_SOF0 (1 << 1)
169 #define LCSR0_BER (1 << 2)
170 #define LCSR0_ABC (1 << 3)
171 #define LCSR0_IU0 (1 << 4)
172 #define LCSR0_IU1 (1 << 5)
173 #define LCSR0_OU (1 << 6)
174 #define LCSR0_QD (1 << 7)
175 #define LCSR0_EOF0 (1 << 8)
176 #define LCSR0_BS0 (1 << 9)
177 #define LCSR0_SINT (1 << 10)
178 #define LCSR0_RDST (1 << 11)
179 #define LCSR0_CMDINT (1 << 12)
180 #define LCSR0_BERCH(x) (((x) & 7) << 28)
181 #define LCSR1_SOF(ch) (1 << (ch - 1))
182 #define LCSR1_EOF(ch) (1 << (ch + 7))
183 #define LCSR1_BS(ch) (1 << (ch + 15))
184 #define LCSR1_IU(ch) (1 << (ch + 23))
185 #define LDCMD_LENGTH(x) ((x) & 0x001ffffc)
186 #define LDCMD_EOFINT (1 << 21)
187 #define LDCMD_SOFINT (1 << 22)
188 #define LDCMD_PAL (1 << 26)
190 /* Route internal interrupt lines to the global IC */
191 static void pxa2xx_lcdc_int_update(PXA2xxLCDState
*s
)
194 level
|= (s
->status
[0] & LCSR0_LDD
) && !(s
->control
[0] & LCCR0_LDM
);
195 level
|= (s
->status
[0] & LCSR0_SOF0
) && !(s
->control
[0] & LCCR0_SOFM0
);
196 level
|= (s
->status
[0] & LCSR0_IU0
) && !(s
->control
[0] & LCCR0_IUM
);
197 level
|= (s
->status
[0] & LCSR0_IU1
) && !(s
->control
[5] & LCCR5_IUM(1));
198 level
|= (s
->status
[0] & LCSR0_OU
) && !(s
->control
[0] & LCCR0_OUM
);
199 level
|= (s
->status
[0] & LCSR0_QD
) && !(s
->control
[0] & LCCR0_QDM
);
200 level
|= (s
->status
[0] & LCSR0_EOF0
) && !(s
->control
[0] & LCCR0_EOFM0
);
201 level
|= (s
->status
[0] & LCSR0_BS0
) && !(s
->control
[0] & LCCR0_BSM0
);
202 level
|= (s
->status
[0] & LCSR0_RDST
) && !(s
->control
[0] & LCCR0_RDSTM
);
203 level
|= (s
->status
[0] & LCSR0_CMDINT
) && !(s
->control
[0] & LCCR0_CMDIM
);
204 level
|= (s
->status
[1] & ~s
->control
[5]);
206 qemu_set_irq(s
->irq
, !!level
);
210 /* Set Branch Status interrupt high and poke associated registers */
211 static inline void pxa2xx_dma_bs_set(PXA2xxLCDState
*s
, int ch
)
215 s
->status
[0] |= LCSR0_BS0
;
216 unmasked
= !(s
->control
[0] & LCCR0_BSM0
);
218 s
->status
[1] |= LCSR1_BS(ch
);
219 unmasked
= !(s
->control
[5] & LCCR5_BSM(ch
));
224 s
->status
[0] |= LCSR0_SINT
;
226 s
->liidr
= s
->dma_ch
[ch
].id
;
230 /* Set Start Of Frame Status interrupt high and poke associated registers */
231 static inline void pxa2xx_dma_sof_set(PXA2xxLCDState
*s
, int ch
)
234 if (!(s
->dma_ch
[ch
].command
& LDCMD_SOFINT
))
238 s
->status
[0] |= LCSR0_SOF0
;
239 unmasked
= !(s
->control
[0] & LCCR0_SOFM0
);
241 s
->status
[1] |= LCSR1_SOF(ch
);
242 unmasked
= !(s
->control
[5] & LCCR5_SOFM(ch
));
247 s
->status
[0] |= LCSR0_SINT
;
249 s
->liidr
= s
->dma_ch
[ch
].id
;
253 /* Set End Of Frame Status interrupt high and poke associated registers */
254 static inline void pxa2xx_dma_eof_set(PXA2xxLCDState
*s
, int ch
)
257 if (!(s
->dma_ch
[ch
].command
& LDCMD_EOFINT
))
261 s
->status
[0] |= LCSR0_EOF0
;
262 unmasked
= !(s
->control
[0] & LCCR0_EOFM0
);
264 s
->status
[1] |= LCSR1_EOF(ch
);
265 unmasked
= !(s
->control
[5] & LCCR5_EOFM(ch
));
270 s
->status
[0] |= LCSR0_SINT
;
272 s
->liidr
= s
->dma_ch
[ch
].id
;
276 /* Set Bus Error Status interrupt high and poke associated registers */
277 static inline void pxa2xx_dma_ber_set(PXA2xxLCDState
*s
, int ch
)
279 s
->status
[0] |= LCSR0_BERCH(ch
) | LCSR0_BER
;
281 s
->status
[0] |= LCSR0_SINT
;
283 s
->liidr
= s
->dma_ch
[ch
].id
;
286 /* Load new Frame Descriptors from DMA */
287 static void pxa2xx_descriptor_load(PXA2xxLCDState
*s
)
289 PXAFrameDescriptor desc
;
293 for (i
= 0; i
< PXA_LCDDMA_CHANS
; i
++) {
294 s
->dma_ch
[i
].source
= 0;
296 if (!s
->dma_ch
[i
].up
)
299 if (s
->dma_ch
[i
].branch
& FBR_BRA
) {
300 descptr
= s
->dma_ch
[i
].branch
& FBR_SRCADDR
;
301 if (s
->dma_ch
[i
].branch
& FBR_BINT
)
302 pxa2xx_dma_bs_set(s
, i
);
303 s
->dma_ch
[i
].branch
&= ~FBR_BRA
;
305 descptr
= s
->dma_ch
[i
].descriptor
;
307 if (!((descptr
>= PXA2XX_SDRAM_BASE
&& descptr
+
308 sizeof(desc
) <= PXA2XX_SDRAM_BASE
+ ram_size
) ||
309 (descptr
>= PXA2XX_INTERNAL_BASE
&& descptr
+ sizeof(desc
) <=
310 PXA2XX_INTERNAL_BASE
+ PXA2XX_INTERNAL_SIZE
))) {
314 cpu_physical_memory_read(descptr
, &desc
, sizeof(desc
));
315 s
->dma_ch
[i
].descriptor
= le32_to_cpu(desc
.fdaddr
);
316 s
->dma_ch
[i
].source
= le32_to_cpu(desc
.fsaddr
);
317 s
->dma_ch
[i
].id
= le32_to_cpu(desc
.fidr
);
318 s
->dma_ch
[i
].command
= le32_to_cpu(desc
.ldcmd
);
322 static uint64_t pxa2xx_lcdc_read(void *opaque
, hwaddr offset
,
325 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
330 return s
->control
[0];
332 return s
->control
[1];
334 return s
->control
[2];
336 return s
->control
[3];
338 return s
->control
[4];
340 return s
->control
[5];
362 case 0x200 ... 0x1000: /* DMA per-channel registers */
363 ch
= (offset
- 0x200) >> 4;
364 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
367 switch (offset
& 0xf) {
369 return s
->dma_ch
[ch
].descriptor
;
371 return s
->dma_ch
[ch
].source
;
373 return s
->dma_ch
[ch
].id
;
375 return s
->dma_ch
[ch
].command
;
381 return s
->dma_ch
[0].branch
;
383 return s
->dma_ch
[1].branch
;
385 return s
->dma_ch
[2].branch
;
387 return s
->dma_ch
[3].branch
;
389 return s
->dma_ch
[4].branch
;
391 return s
->dma_ch
[5].branch
;
393 return s
->dma_ch
[6].branch
;
410 qemu_log_mask(LOG_GUEST_ERROR
, "%s: Bad offset 0x%" HWADDR_PRIX
"\n",
417 static void pxa2xx_lcdc_write(void *opaque
, hwaddr offset
,
418 uint64_t value
, unsigned size
)
420 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
425 /* ACK Quick Disable done */
426 if ((s
->control
[0] & LCCR0_ENB
) && !(value
& LCCR0_ENB
))
427 s
->status
[0] |= LCSR0_QD
;
429 if (!(s
->control
[0] & LCCR0_LCDT
) && (value
& LCCR0_LCDT
)) {
430 qemu_log_mask(LOG_UNIMP
,
431 "%s: internal frame buffer unsupported\n", __func__
);
433 if ((s
->control
[3] & LCCR3_API
) &&
434 (value
& LCCR0_ENB
) && !(value
& LCCR0_LCDT
))
435 s
->status
[0] |= LCSR0_ABC
;
437 s
->control
[0] = value
& 0x07ffffff;
438 pxa2xx_lcdc_int_update(s
);
440 s
->dma_ch
[0].up
= !!(value
& LCCR0_ENB
);
441 s
->dma_ch
[1].up
= (s
->ovl1c
[0] & OVLC1_EN
) || (value
& LCCR0_SDS
);
445 s
->control
[1] = value
;
449 s
->control
[2] = value
;
453 s
->control
[3] = value
& 0xefffffff;
454 s
->bpp
= LCCR3_BPP(value
);
458 s
->control
[4] = value
& 0x83ff81ff;
462 s
->control
[5] = value
& 0x3f3f3f3f;
466 if (!(s
->ovl1c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
)) {
467 qemu_log_mask(LOG_UNIMP
, "%s: Overlay 1 not supported\n", __func__
);
469 s
->ovl1c
[0] = value
& 0x80ffffff;
470 s
->dma_ch
[1].up
= (value
& OVLC1_EN
) || (s
->control
[0] & LCCR0_SDS
);
474 s
->ovl1c
[1] = value
& 0x000fffff;
478 if (!(s
->ovl2c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
)) {
479 qemu_log_mask(LOG_UNIMP
, "%s: Overlay 2 not supported\n", __func__
);
481 s
->ovl2c
[0] = value
& 0x80ffffff;
482 s
->dma_ch
[2].up
= !!(value
& OVLC1_EN
);
483 s
->dma_ch
[3].up
= !!(value
& OVLC1_EN
);
484 s
->dma_ch
[4].up
= !!(value
& OVLC1_EN
);
488 s
->ovl2c
[1] = value
& 0x007fffff;
492 if (!(s
->ccr
& CCR_CEN
) && (value
& CCR_CEN
)) {
493 qemu_log_mask(LOG_UNIMP
,
494 "%s: Hardware cursor unimplemented\n", __func__
);
496 s
->ccr
= value
& 0x81ffffe7;
497 s
->dma_ch
[5].up
= !!(value
& CCR_CEN
);
501 s
->cmdcr
= value
& 0xff;
505 s
->trgbr
= value
& 0x00ffffff;
509 s
->tcr
= value
& 0x7fff;
512 case 0x200 ... 0x1000: /* DMA per-channel registers */
513 ch
= (offset
- 0x200) >> 4;
514 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
517 switch (offset
& 0xf) {
519 s
->dma_ch
[ch
].descriptor
= value
& 0xfffffff0;
528 s
->dma_ch
[0].branch
= value
& 0xfffffff3;
531 s
->dma_ch
[1].branch
= value
& 0xfffffff3;
534 s
->dma_ch
[2].branch
= value
& 0xfffffff3;
537 s
->dma_ch
[3].branch
= value
& 0xfffffff3;
540 s
->dma_ch
[4].branch
= value
& 0xfffffff3;
543 s
->dma_ch
[5].branch
= value
& 0xfffffff3;
546 s
->dma_ch
[6].branch
= value
& 0xfffffff3;
550 s
->bscntr
= value
& 0xf;
557 s
->status
[0] &= ~(value
& 0xfff);
558 if (value
& LCSR0_BER
)
559 s
->status
[0] &= ~LCSR0_BERCH(7);
563 s
->status
[1] &= ~(value
& 0x3e3f3f);
568 qemu_log_mask(LOG_GUEST_ERROR
, "%s: Bad offset 0x%" HWADDR_PRIX
"\n",
573 static const MemoryRegionOps pxa2xx_lcdc_ops
= {
574 .read
= pxa2xx_lcdc_read
,
575 .write
= pxa2xx_lcdc_write
,
576 .endianness
= DEVICE_NATIVE_ENDIAN
,
579 /* Load new palette for a given DMA channel, convert to internal format */
580 static void pxa2xx_palette_parse(PXA2xxLCDState
*s
, int ch
, int bpp
)
582 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
583 int i
, n
, format
, r
, g
, b
, alpha
;
586 s
->pal_for
= LCCR4_PALFOR(s
->control
[4]);
603 src
= (uint8_t *) s
->dma_ch
[ch
].pbuffer
;
604 dest
= (uint32_t *) s
->dma_ch
[ch
].palette
;
605 alpha
= r
= g
= b
= 0;
607 for (i
= 0; i
< n
; i
++) {
609 case 0: /* 16 bpp, no transparency */
611 if (s
->control
[0] & LCCR0_CMS
) {
612 r
= g
= b
= *(uint16_t *) src
& 0xff;
615 r
= (*(uint16_t *) src
& 0xf800) >> 8;
616 g
= (*(uint16_t *) src
& 0x07e0) >> 3;
617 b
= (*(uint16_t *) src
& 0x001f) << 3;
621 case 1: /* 16 bpp plus transparency */
622 alpha
= *(uint32_t *) src
& (1 << 24);
623 if (s
->control
[0] & LCCR0_CMS
)
624 r
= g
= b
= *(uint32_t *) src
& 0xff;
626 r
= (*(uint32_t *) src
& 0xf80000) >> 16;
627 g
= (*(uint32_t *) src
& 0x00fc00) >> 8;
628 b
= (*(uint32_t *) src
& 0x0000f8);
632 case 2: /* 18 bpp plus transparency */
633 alpha
= *(uint32_t *) src
& (1 << 24);
634 if (s
->control
[0] & LCCR0_CMS
)
635 r
= g
= b
= *(uint32_t *) src
& 0xff;
637 r
= (*(uint32_t *) src
& 0xfc0000) >> 16;
638 g
= (*(uint32_t *) src
& 0x00fc00) >> 8;
639 b
= (*(uint32_t *) src
& 0x0000fc);
643 case 3: /* 24 bpp plus transparency */
644 alpha
= *(uint32_t *) src
& (1 << 24);
645 if (s
->control
[0] & LCCR0_CMS
)
646 r
= g
= b
= *(uint32_t *) src
& 0xff;
648 r
= (*(uint32_t *) src
& 0xff0000) >> 16;
649 g
= (*(uint32_t *) src
& 0x00ff00) >> 8;
650 b
= (*(uint32_t *) src
& 0x0000ff);
655 switch (surface_bits_per_pixel(surface
)) {
657 *dest
= rgb_to_pixel8(r
, g
, b
) | alpha
;
660 *dest
= rgb_to_pixel15(r
, g
, b
) | alpha
;
663 *dest
= rgb_to_pixel16(r
, g
, b
) | alpha
;
666 *dest
= rgb_to_pixel24(r
, g
, b
) | alpha
;
669 *dest
= rgb_to_pixel32(r
, g
, b
) | alpha
;
676 static void pxa2xx_lcdc_dma0_redraw_rot0(PXA2xxLCDState
*s
,
677 hwaddr addr
, int *miny
, int *maxy
)
679 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
680 int src_width
, dest_width
;
683 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
687 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
688 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
690 else if (s
->bpp
> pxa_lcdc_16bpp
)
692 else if (s
->bpp
> pxa_lcdc_8bpp
)
695 dest_width
= s
->xres
* s
->dest_width
;
697 if (s
->invalidated
) {
698 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
699 addr
, s
->yres
, src_width
);
701 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
702 src_width
, dest_width
, s
->dest_width
,
704 fn
, s
->dma_ch
[0].palette
, miny
, maxy
);
707 static void pxa2xx_lcdc_dma0_redraw_rot90(PXA2xxLCDState
*s
,
708 hwaddr addr
, int *miny
, int *maxy
)
710 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
711 int src_width
, dest_width
;
714 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
718 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
719 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
721 else if (s
->bpp
> pxa_lcdc_16bpp
)
723 else if (s
->bpp
> pxa_lcdc_8bpp
)
726 dest_width
= s
->yres
* s
->dest_width
;
728 if (s
->invalidated
) {
729 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
730 addr
, s
->yres
, src_width
);
732 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
733 src_width
, s
->dest_width
, -dest_width
,
735 fn
, s
->dma_ch
[0].palette
,
739 static void pxa2xx_lcdc_dma0_redraw_rot180(PXA2xxLCDState
*s
,
740 hwaddr addr
, int *miny
, int *maxy
)
742 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
743 int src_width
, dest_width
;
746 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
752 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
753 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
) {
755 } else if (s
->bpp
> pxa_lcdc_16bpp
) {
757 } else if (s
->bpp
> pxa_lcdc_8bpp
) {
761 dest_width
= s
->xres
* s
->dest_width
;
763 if (s
->invalidated
) {
764 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
765 addr
, s
->yres
, src_width
);
767 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
768 src_width
, -dest_width
, -s
->dest_width
,
770 fn
, s
->dma_ch
[0].palette
, miny
, maxy
);
773 static void pxa2xx_lcdc_dma0_redraw_rot270(PXA2xxLCDState
*s
,
774 hwaddr addr
, int *miny
, int *maxy
)
776 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
777 int src_width
, dest_width
;
780 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
786 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
787 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
) {
789 } else if (s
->bpp
> pxa_lcdc_16bpp
) {
791 } else if (s
->bpp
> pxa_lcdc_8bpp
) {
795 dest_width
= s
->yres
* s
->dest_width
;
797 if (s
->invalidated
) {
798 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
799 addr
, s
->yres
, src_width
);
801 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
802 src_width
, -s
->dest_width
, dest_width
,
804 fn
, s
->dma_ch
[0].palette
,
808 static void pxa2xx_lcdc_resize(PXA2xxLCDState
*s
)
811 if (!(s
->control
[0] & LCCR0_ENB
))
814 width
= LCCR1_PPL(s
->control
[1]) + 1;
815 height
= LCCR2_LPP(s
->control
[2]) + 1;
817 if (width
!= s
->xres
|| height
!= s
->yres
) {
818 if (s
->orientation
== 90 || s
->orientation
== 270) {
819 qemu_console_resize(s
->con
, height
, width
);
821 qemu_console_resize(s
->con
, width
, height
);
829 static void pxa2xx_update_display(void *opaque
)
831 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
835 if (!(s
->control
[0] & LCCR0_ENB
))
838 pxa2xx_descriptor_load(s
);
840 pxa2xx_lcdc_resize(s
);
843 s
->transp
= s
->dma_ch
[2].up
|| s
->dma_ch
[3].up
;
844 /* Note: With overlay planes the order depends on LCCR0 bit 25. */
845 for (ch
= 0; ch
< PXA_LCDDMA_CHANS
; ch
++)
846 if (s
->dma_ch
[ch
].up
) {
847 if (!s
->dma_ch
[ch
].source
) {
848 pxa2xx_dma_ber_set(s
, ch
);
851 fbptr
= s
->dma_ch
[ch
].source
;
852 if (!((fbptr
>= PXA2XX_SDRAM_BASE
&&
853 fbptr
<= PXA2XX_SDRAM_BASE
+ ram_size
) ||
854 (fbptr
>= PXA2XX_INTERNAL_BASE
&&
855 fbptr
<= PXA2XX_INTERNAL_BASE
+ PXA2XX_INTERNAL_SIZE
))) {
856 pxa2xx_dma_ber_set(s
, ch
);
860 if (s
->dma_ch
[ch
].command
& LDCMD_PAL
) {
861 cpu_physical_memory_read(fbptr
, s
->dma_ch
[ch
].pbuffer
,
862 MAX(LDCMD_LENGTH(s
->dma_ch
[ch
].command
),
863 sizeof(s
->dma_ch
[ch
].pbuffer
)));
864 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
866 /* Do we need to reparse palette */
867 if (LCCR4_PALFOR(s
->control
[4]) != s
->pal_for
)
868 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
870 /* ACK frame start */
871 pxa2xx_dma_sof_set(s
, ch
);
873 s
->dma_ch
[ch
].redraw(s
, fbptr
, &miny
, &maxy
);
876 /* ACK frame completed */
877 pxa2xx_dma_eof_set(s
, ch
);
881 if (s
->control
[0] & LCCR0_DIS
) {
882 /* ACK last frame completed */
883 s
->control
[0] &= ~LCCR0_ENB
;
884 s
->status
[0] |= LCSR0_LDD
;
888 switch (s
->orientation
) {
890 dpy_gfx_update(s
->con
, 0, miny
, s
->xres
, maxy
- miny
+ 1);
893 dpy_gfx_update(s
->con
, miny
, 0, maxy
- miny
+ 1, s
->xres
);
896 maxy
= s
->yres
- maxy
- 1;
897 miny
= s
->yres
- miny
- 1;
898 dpy_gfx_update(s
->con
, 0, maxy
, s
->xres
, miny
- maxy
+ 1);
901 maxy
= s
->yres
- maxy
- 1;
902 miny
= s
->yres
- miny
- 1;
903 dpy_gfx_update(s
->con
, maxy
, 0, miny
- maxy
+ 1, s
->xres
);
907 pxa2xx_lcdc_int_update(s
);
909 qemu_irq_raise(s
->vsync_cb
);
912 static void pxa2xx_invalidate_display(void *opaque
)
914 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
918 static void pxa2xx_lcdc_orientation(void *opaque
, int angle
)
920 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
924 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot0
;
927 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot90
;
930 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot180
;
933 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot270
;
937 s
->orientation
= angle
;
938 s
->xres
= s
->yres
= -1;
939 pxa2xx_lcdc_resize(s
);
942 static const VMStateDescription vmstate_dma_channel
= {
943 .name
= "dma_channel",
945 .minimum_version_id
= 0,
946 .fields
= (VMStateField
[]) {
947 VMSTATE_UINT32(branch
, struct DMAChannel
),
948 VMSTATE_UINT8(up
, struct DMAChannel
),
949 VMSTATE_BUFFER(pbuffer
, struct DMAChannel
),
950 VMSTATE_UINT32(descriptor
, struct DMAChannel
),
951 VMSTATE_UINT32(source
, struct DMAChannel
),
952 VMSTATE_UINT32(id
, struct DMAChannel
),
953 VMSTATE_UINT32(command
, struct DMAChannel
),
954 VMSTATE_END_OF_LIST()
958 static int pxa2xx_lcdc_post_load(void *opaque
, int version_id
)
960 PXA2xxLCDState
*s
= opaque
;
962 s
->bpp
= LCCR3_BPP(s
->control
[3]);
963 s
->xres
= s
->yres
= s
->pal_for
= -1;
968 static const VMStateDescription vmstate_pxa2xx_lcdc
= {
969 .name
= "pxa2xx_lcdc",
971 .minimum_version_id
= 0,
972 .post_load
= pxa2xx_lcdc_post_load
,
973 .fields
= (VMStateField
[]) {
974 VMSTATE_INT32(irqlevel
, PXA2xxLCDState
),
975 VMSTATE_INT32(transp
, PXA2xxLCDState
),
976 VMSTATE_UINT32_ARRAY(control
, PXA2xxLCDState
, 6),
977 VMSTATE_UINT32_ARRAY(status
, PXA2xxLCDState
, 2),
978 VMSTATE_UINT32_ARRAY(ovl1c
, PXA2xxLCDState
, 2),
979 VMSTATE_UINT32_ARRAY(ovl2c
, PXA2xxLCDState
, 2),
980 VMSTATE_UINT32(ccr
, PXA2xxLCDState
),
981 VMSTATE_UINT32(cmdcr
, PXA2xxLCDState
),
982 VMSTATE_UINT32(trgbr
, PXA2xxLCDState
),
983 VMSTATE_UINT32(tcr
, PXA2xxLCDState
),
984 VMSTATE_UINT32(liidr
, PXA2xxLCDState
),
985 VMSTATE_UINT8(bscntr
, PXA2xxLCDState
),
986 VMSTATE_STRUCT_ARRAY(dma_ch
, PXA2xxLCDState
, 7, 0,
987 vmstate_dma_channel
, struct DMAChannel
),
988 VMSTATE_END_OF_LIST()
993 #include "pxa2xx_template.h"
995 #include "pxa2xx_template.h"
997 #include "pxa2xx_template.h"
999 #include "pxa2xx_template.h"
1001 #include "pxa2xx_template.h"
1003 static const GraphicHwOps pxa2xx_ops
= {
1004 .invalidate
= pxa2xx_invalidate_display
,
1005 .gfx_update
= pxa2xx_update_display
,
1008 PXA2xxLCDState
*pxa2xx_lcdc_init(MemoryRegion
*sysmem
,
1009 hwaddr base
, qemu_irq irq
)
1012 DisplaySurface
*surface
;
1014 s
= (PXA2xxLCDState
*) g_malloc0(sizeof(PXA2xxLCDState
));
1019 pxa2xx_lcdc_orientation(s
, graphic_rotate
);
1021 memory_region_init_io(&s
->iomem
, NULL
, &pxa2xx_lcdc_ops
, s
,
1022 "pxa2xx-lcd-controller", 0x00100000);
1023 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
1025 s
->con
= graphic_console_init(NULL
, 0, &pxa2xx_ops
, s
);
1026 surface
= qemu_console_surface(s
->con
);
1028 switch (surface_bits_per_pixel(surface
)) {
1033 s
->line_fn
[0] = pxa2xx_draw_fn_8
;
1034 s
->line_fn
[1] = pxa2xx_draw_fn_8t
;
1038 s
->line_fn
[0] = pxa2xx_draw_fn_15
;
1039 s
->line_fn
[1] = pxa2xx_draw_fn_15t
;
1043 s
->line_fn
[0] = pxa2xx_draw_fn_16
;
1044 s
->line_fn
[1] = pxa2xx_draw_fn_16t
;
1048 s
->line_fn
[0] = pxa2xx_draw_fn_24
;
1049 s
->line_fn
[1] = pxa2xx_draw_fn_24t
;
1053 s
->line_fn
[0] = pxa2xx_draw_fn_32
;
1054 s
->line_fn
[1] = pxa2xx_draw_fn_32t
;
1058 fprintf(stderr
, "%s: Bad color depth\n", __func__
);
1062 vmstate_register(NULL
, 0, &vmstate_pxa2xx_lcdc
, s
);
1067 void pxa2xx_lcd_vsync_notifier(PXA2xxLCDState
*s
, qemu_irq handler
)
1069 s
->vsync_cb
= handler
;