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.
16 #include "pixel_ops.h"
17 /* FIXME: For graphic_rotate. Should probably be done in common code. */
19 #include "framebuffer.h"
22 target_phys_addr_t branch
;
24 uint8_t palette
[1024];
25 uint8_t pbuffer
[1024];
26 void (*redraw
)(PXA2xxLCDState
*s
, target_phys_addr_t addr
,
27 int *miny
, int *maxy
);
29 target_phys_addr_t descriptor
;
30 target_phys_addr_t source
;
35 struct PXA2xxLCDState
{
72 struct DMAChannel dma_ch
[7];
78 typedef struct QEMU_PACKED
{
85 #define LCCR0 0x000 /* LCD Controller Control register 0 */
86 #define LCCR1 0x004 /* LCD Controller Control register 1 */
87 #define LCCR2 0x008 /* LCD Controller Control register 2 */
88 #define LCCR3 0x00c /* LCD Controller Control register 3 */
89 #define LCCR4 0x010 /* LCD Controller Control register 4 */
90 #define LCCR5 0x014 /* LCD Controller Control register 5 */
92 #define FBR0 0x020 /* DMA Channel 0 Frame Branch register */
93 #define FBR1 0x024 /* DMA Channel 1 Frame Branch register */
94 #define FBR2 0x028 /* DMA Channel 2 Frame Branch register */
95 #define FBR3 0x02c /* DMA Channel 3 Frame Branch register */
96 #define FBR4 0x030 /* DMA Channel 4 Frame Branch register */
97 #define FBR5 0x110 /* DMA Channel 5 Frame Branch register */
98 #define FBR6 0x114 /* DMA Channel 6 Frame Branch register */
100 #define LCSR1 0x034 /* LCD Controller Status register 1 */
101 #define LCSR0 0x038 /* LCD Controller Status register 0 */
102 #define LIIDR 0x03c /* LCD Controller Interrupt ID register */
104 #define TRGBR 0x040 /* TMED RGB Seed register */
105 #define TCR 0x044 /* TMED Control register */
107 #define OVL1C1 0x050 /* Overlay 1 Control register 1 */
108 #define OVL1C2 0x060 /* Overlay 1 Control register 2 */
109 #define OVL2C1 0x070 /* Overlay 2 Control register 1 */
110 #define OVL2C2 0x080 /* Overlay 2 Control register 2 */
111 #define CCR 0x090 /* Cursor Control register */
113 #define CMDCR 0x100 /* Command Control register */
114 #define PRSR 0x104 /* Panel Read Status register */
116 #define PXA_LCDDMA_CHANS 7
117 #define DMA_FDADR 0x00 /* Frame Descriptor Address register */
118 #define DMA_FSADR 0x04 /* Frame Source Address register */
119 #define DMA_FIDR 0x08 /* Frame ID register */
120 #define DMA_LDCMD 0x0c /* Command register */
122 /* LCD Buffer Strength Control register */
123 #define BSCNTR 0x04000054
126 #define LCCR0_ENB (1 << 0)
127 #define LCCR0_CMS (1 << 1)
128 #define LCCR0_SDS (1 << 2)
129 #define LCCR0_LDM (1 << 3)
130 #define LCCR0_SOFM0 (1 << 4)
131 #define LCCR0_IUM (1 << 5)
132 #define LCCR0_EOFM0 (1 << 6)
133 #define LCCR0_PAS (1 << 7)
134 #define LCCR0_DPD (1 << 9)
135 #define LCCR0_DIS (1 << 10)
136 #define LCCR0_QDM (1 << 11)
137 #define LCCR0_PDD (0xff << 12)
138 #define LCCR0_BSM0 (1 << 20)
139 #define LCCR0_OUM (1 << 21)
140 #define LCCR0_LCDT (1 << 22)
141 #define LCCR0_RDSTM (1 << 23)
142 #define LCCR0_CMDIM (1 << 24)
143 #define LCCR0_OUC (1 << 25)
144 #define LCCR0_LDDALT (1 << 26)
145 #define LCCR1_PPL(x) ((x) & 0x3ff)
146 #define LCCR2_LPP(x) ((x) & 0x3ff)
147 #define LCCR3_API (15 << 16)
148 #define LCCR3_BPP(x) ((((x) >> 24) & 7) | (((x) >> 26) & 8))
149 #define LCCR3_PDFOR(x) (((x) >> 30) & 3)
150 #define LCCR4_K1(x) (((x) >> 0) & 7)
151 #define LCCR4_K2(x) (((x) >> 3) & 7)
152 #define LCCR4_K3(x) (((x) >> 6) & 7)
153 #define LCCR4_PALFOR(x) (((x) >> 15) & 3)
154 #define LCCR5_SOFM(ch) (1 << (ch - 1))
155 #define LCCR5_EOFM(ch) (1 << (ch + 7))
156 #define LCCR5_BSM(ch) (1 << (ch + 15))
157 #define LCCR5_IUM(ch) (1 << (ch + 23))
158 #define OVLC1_EN (1 << 31)
159 #define CCR_CEN (1 << 31)
160 #define FBR_BRA (1 << 0)
161 #define FBR_BINT (1 << 1)
162 #define FBR_SRCADDR (0xfffffff << 4)
163 #define LCSR0_LDD (1 << 0)
164 #define LCSR0_SOF0 (1 << 1)
165 #define LCSR0_BER (1 << 2)
166 #define LCSR0_ABC (1 << 3)
167 #define LCSR0_IU0 (1 << 4)
168 #define LCSR0_IU1 (1 << 5)
169 #define LCSR0_OU (1 << 6)
170 #define LCSR0_QD (1 << 7)
171 #define LCSR0_EOF0 (1 << 8)
172 #define LCSR0_BS0 (1 << 9)
173 #define LCSR0_SINT (1 << 10)
174 #define LCSR0_RDST (1 << 11)
175 #define LCSR0_CMDINT (1 << 12)
176 #define LCSR0_BERCH(x) (((x) & 7) << 28)
177 #define LCSR1_SOF(ch) (1 << (ch - 1))
178 #define LCSR1_EOF(ch) (1 << (ch + 7))
179 #define LCSR1_BS(ch) (1 << (ch + 15))
180 #define LCSR1_IU(ch) (1 << (ch + 23))
181 #define LDCMD_LENGTH(x) ((x) & 0x001ffffc)
182 #define LDCMD_EOFINT (1 << 21)
183 #define LDCMD_SOFINT (1 << 22)
184 #define LDCMD_PAL (1 << 26)
186 /* Route internal interrupt lines to the global IC */
187 static void pxa2xx_lcdc_int_update(PXA2xxLCDState
*s
)
190 level
|= (s
->status
[0] & LCSR0_LDD
) && !(s
->control
[0] & LCCR0_LDM
);
191 level
|= (s
->status
[0] & LCSR0_SOF0
) && !(s
->control
[0] & LCCR0_SOFM0
);
192 level
|= (s
->status
[0] & LCSR0_IU0
) && !(s
->control
[0] & LCCR0_IUM
);
193 level
|= (s
->status
[0] & LCSR0_IU1
) && !(s
->control
[5] & LCCR5_IUM(1));
194 level
|= (s
->status
[0] & LCSR0_OU
) && !(s
->control
[0] & LCCR0_OUM
);
195 level
|= (s
->status
[0] & LCSR0_QD
) && !(s
->control
[0] & LCCR0_QDM
);
196 level
|= (s
->status
[0] & LCSR0_EOF0
) && !(s
->control
[0] & LCCR0_EOFM0
);
197 level
|= (s
->status
[0] & LCSR0_BS0
) && !(s
->control
[0] & LCCR0_BSM0
);
198 level
|= (s
->status
[0] & LCSR0_RDST
) && !(s
->control
[0] & LCCR0_RDSTM
);
199 level
|= (s
->status
[0] & LCSR0_CMDINT
) && !(s
->control
[0] & LCCR0_CMDIM
);
200 level
|= (s
->status
[1] & ~s
->control
[5]);
202 qemu_set_irq(s
->irq
, !!level
);
206 /* Set Branch Status interrupt high and poke associated registers */
207 static inline void pxa2xx_dma_bs_set(PXA2xxLCDState
*s
, int ch
)
211 s
->status
[0] |= LCSR0_BS0
;
212 unmasked
= !(s
->control
[0] & LCCR0_BSM0
);
214 s
->status
[1] |= LCSR1_BS(ch
);
215 unmasked
= !(s
->control
[5] & LCCR5_BSM(ch
));
220 s
->status
[0] |= LCSR0_SINT
;
222 s
->liidr
= s
->dma_ch
[ch
].id
;
226 /* Set Start Of Frame Status interrupt high and poke associated registers */
227 static inline void pxa2xx_dma_sof_set(PXA2xxLCDState
*s
, int ch
)
230 if (!(s
->dma_ch
[ch
].command
& LDCMD_SOFINT
))
234 s
->status
[0] |= LCSR0_SOF0
;
235 unmasked
= !(s
->control
[0] & LCCR0_SOFM0
);
237 s
->status
[1] |= LCSR1_SOF(ch
);
238 unmasked
= !(s
->control
[5] & LCCR5_SOFM(ch
));
243 s
->status
[0] |= LCSR0_SINT
;
245 s
->liidr
= s
->dma_ch
[ch
].id
;
249 /* Set End Of Frame Status interrupt high and poke associated registers */
250 static inline void pxa2xx_dma_eof_set(PXA2xxLCDState
*s
, int ch
)
253 if (!(s
->dma_ch
[ch
].command
& LDCMD_EOFINT
))
257 s
->status
[0] |= LCSR0_EOF0
;
258 unmasked
= !(s
->control
[0] & LCCR0_EOFM0
);
260 s
->status
[1] |= LCSR1_EOF(ch
);
261 unmasked
= !(s
->control
[5] & LCCR5_EOFM(ch
));
266 s
->status
[0] |= LCSR0_SINT
;
268 s
->liidr
= s
->dma_ch
[ch
].id
;
272 /* Set Bus Error Status interrupt high and poke associated registers */
273 static inline void pxa2xx_dma_ber_set(PXA2xxLCDState
*s
, int ch
)
275 s
->status
[0] |= LCSR0_BERCH(ch
) | LCSR0_BER
;
277 s
->status
[0] |= LCSR0_SINT
;
279 s
->liidr
= s
->dma_ch
[ch
].id
;
282 /* Set Read Status interrupt high and poke associated registers */
283 static inline void pxa2xx_dma_rdst_set(PXA2xxLCDState
*s
)
285 s
->status
[0] |= LCSR0_RDST
;
286 if (s
->irqlevel
&& !(s
->control
[0] & LCCR0_RDSTM
))
287 s
->status
[0] |= LCSR0_SINT
;
290 /* Load new Frame Descriptors from DMA */
291 static void pxa2xx_descriptor_load(PXA2xxLCDState
*s
)
293 PXAFrameDescriptor desc
;
294 target_phys_addr_t descptr
;
297 for (i
= 0; i
< PXA_LCDDMA_CHANS
; i
++) {
298 s
->dma_ch
[i
].source
= 0;
300 if (!s
->dma_ch
[i
].up
)
303 if (s
->dma_ch
[i
].branch
& FBR_BRA
) {
304 descptr
= s
->dma_ch
[i
].branch
& FBR_SRCADDR
;
305 if (s
->dma_ch
[i
].branch
& FBR_BINT
)
306 pxa2xx_dma_bs_set(s
, i
);
307 s
->dma_ch
[i
].branch
&= ~FBR_BRA
;
309 descptr
= s
->dma_ch
[i
].descriptor
;
311 if (!(descptr
>= PXA2XX_SDRAM_BASE
&& descptr
+
312 sizeof(desc
) <= PXA2XX_SDRAM_BASE
+ ram_size
))
315 cpu_physical_memory_read(descptr
, (void *)&desc
, sizeof(desc
));
316 s
->dma_ch
[i
].descriptor
= tswap32(desc
.fdaddr
);
317 s
->dma_ch
[i
].source
= tswap32(desc
.fsaddr
);
318 s
->dma_ch
[i
].id
= tswap32(desc
.fidr
);
319 s
->dma_ch
[i
].command
= tswap32(desc
.ldcmd
);
323 static uint64_t pxa2xx_lcdc_read(void *opaque
, target_phys_addr_t offset
,
326 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
331 return s
->control
[0];
333 return s
->control
[1];
335 return s
->control
[2];
337 return s
->control
[3];
339 return s
->control
[4];
341 return s
->control
[5];
363 case 0x200 ... 0x1000: /* DMA per-channel registers */
364 ch
= (offset
- 0x200) >> 4;
365 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
368 switch (offset
& 0xf) {
370 return s
->dma_ch
[ch
].descriptor
;
372 return s
->dma_ch
[ch
].source
;
374 return s
->dma_ch
[ch
].id
;
376 return s
->dma_ch
[ch
].command
;
382 return s
->dma_ch
[0].branch
;
384 return s
->dma_ch
[1].branch
;
386 return s
->dma_ch
[2].branch
;
388 return s
->dma_ch
[3].branch
;
390 return s
->dma_ch
[4].branch
;
392 return s
->dma_ch
[5].branch
;
394 return s
->dma_ch
[6].branch
;
411 hw_error("%s: Bad offset " REG_FMT
"\n", __FUNCTION__
, offset
);
417 static void pxa2xx_lcdc_write(void *opaque
, target_phys_addr_t 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 printf("%s: internal frame buffer unsupported\n", __FUNCTION__
);
432 if ((s
->control
[3] & LCCR3_API
) &&
433 (value
& LCCR0_ENB
) && !(value
& LCCR0_LCDT
))
434 s
->status
[0] |= LCSR0_ABC
;
436 s
->control
[0] = value
& 0x07ffffff;
437 pxa2xx_lcdc_int_update(s
);
439 s
->dma_ch
[0].up
= !!(value
& LCCR0_ENB
);
440 s
->dma_ch
[1].up
= (s
->ovl1c
[0] & OVLC1_EN
) || (value
& LCCR0_SDS
);
444 s
->control
[1] = value
;
448 s
->control
[2] = value
;
452 s
->control
[3] = value
& 0xefffffff;
453 s
->bpp
= LCCR3_BPP(value
);
457 s
->control
[4] = value
& 0x83ff81ff;
461 s
->control
[5] = value
& 0x3f3f3f3f;
465 if (!(s
->ovl1c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
))
466 printf("%s: Overlay 1 not supported\n", __FUNCTION__
);
468 s
->ovl1c
[0] = value
& 0x80ffffff;
469 s
->dma_ch
[1].up
= (value
& OVLC1_EN
) || (s
->control
[0] & LCCR0_SDS
);
473 s
->ovl1c
[1] = value
& 0x000fffff;
477 if (!(s
->ovl2c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
))
478 printf("%s: Overlay 2 not supported\n", __FUNCTION__
);
480 s
->ovl2c
[0] = value
& 0x80ffffff;
481 s
->dma_ch
[2].up
= !!(value
& OVLC1_EN
);
482 s
->dma_ch
[3].up
= !!(value
& OVLC1_EN
);
483 s
->dma_ch
[4].up
= !!(value
& OVLC1_EN
);
487 s
->ovl2c
[1] = value
& 0x007fffff;
491 if (!(s
->ccr
& CCR_CEN
) && (value
& CCR_CEN
))
492 printf("%s: Hardware cursor unimplemented\n", __FUNCTION__
);
494 s
->ccr
= value
& 0x81ffffe7;
495 s
->dma_ch
[5].up
= !!(value
& CCR_CEN
);
499 s
->cmdcr
= value
& 0xff;
503 s
->trgbr
= value
& 0x00ffffff;
507 s
->tcr
= value
& 0x7fff;
510 case 0x200 ... 0x1000: /* DMA per-channel registers */
511 ch
= (offset
- 0x200) >> 4;
512 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
515 switch (offset
& 0xf) {
517 s
->dma_ch
[ch
].descriptor
= value
& 0xfffffff0;
526 s
->dma_ch
[0].branch
= value
& 0xfffffff3;
529 s
->dma_ch
[1].branch
= value
& 0xfffffff3;
532 s
->dma_ch
[2].branch
= value
& 0xfffffff3;
535 s
->dma_ch
[3].branch
= value
& 0xfffffff3;
538 s
->dma_ch
[4].branch
= value
& 0xfffffff3;
541 s
->dma_ch
[5].branch
= value
& 0xfffffff3;
544 s
->dma_ch
[6].branch
= value
& 0xfffffff3;
548 s
->bscntr
= value
& 0xf;
555 s
->status
[0] &= ~(value
& 0xfff);
556 if (value
& LCSR0_BER
)
557 s
->status
[0] &= ~LCSR0_BERCH(7);
561 s
->status
[1] &= ~(value
& 0x3e3f3f);
566 hw_error("%s: Bad offset " REG_FMT
"\n", __FUNCTION__
, offset
);
570 static const MemoryRegionOps pxa2xx_lcdc_ops
= {
571 .read
= pxa2xx_lcdc_read
,
572 .write
= pxa2xx_lcdc_write
,
573 .endianness
= DEVICE_NATIVE_ENDIAN
,
576 /* Load new palette for a given DMA channel, convert to internal format */
577 static void pxa2xx_palette_parse(PXA2xxLCDState
*s
, int ch
, int bpp
)
579 int i
, n
, format
, r
, g
, b
, alpha
;
582 s
->pal_for
= LCCR4_PALFOR(s
->control
[4]);
600 src
= (uint8_t *) s
->dma_ch
[ch
].pbuffer
;
601 dest
= (uint32_t *) s
->dma_ch
[ch
].palette
;
602 alpha
= r
= g
= b
= 0;
604 for (i
= 0; i
< n
; i
++) {
606 case 0: /* 16 bpp, no transparency */
608 if (s
->control
[0] & LCCR0_CMS
) {
609 r
= g
= b
= *(uint16_t *) src
& 0xff;
612 r
= (*(uint16_t *) src
& 0xf800) >> 8;
613 g
= (*(uint16_t *) src
& 0x07e0) >> 3;
614 b
= (*(uint16_t *) src
& 0x001f) << 3;
618 case 1: /* 16 bpp plus transparency */
619 alpha
= *(uint16_t *) src
& (1 << 24);
620 if (s
->control
[0] & LCCR0_CMS
)
621 r
= g
= b
= *(uint16_t *) src
& 0xff;
623 r
= (*(uint16_t *) src
& 0xf800) >> 8;
624 g
= (*(uint16_t *) src
& 0x07e0) >> 3;
625 b
= (*(uint16_t *) src
& 0x001f) << 3;
629 case 2: /* 18 bpp plus transparency */
630 alpha
= *(uint32_t *) src
& (1 << 24);
631 if (s
->control
[0] & LCCR0_CMS
)
632 r
= g
= b
= *(uint32_t *) src
& 0xff;
634 r
= (*(uint32_t *) src
& 0xf80000) >> 16;
635 g
= (*(uint32_t *) src
& 0x00fc00) >> 8;
636 b
= (*(uint32_t *) src
& 0x0000f8);
640 case 3: /* 24 bpp plus transparency */
641 alpha
= *(uint32_t *) src
& (1 << 24);
642 if (s
->control
[0] & LCCR0_CMS
)
643 r
= g
= b
= *(uint32_t *) src
& 0xff;
645 r
= (*(uint32_t *) src
& 0xff0000) >> 16;
646 g
= (*(uint32_t *) src
& 0x00ff00) >> 8;
647 b
= (*(uint32_t *) src
& 0x0000ff);
652 switch (ds_get_bits_per_pixel(s
->ds
)) {
654 *dest
= rgb_to_pixel8(r
, g
, b
) | alpha
;
657 *dest
= rgb_to_pixel15(r
, g
, b
) | alpha
;
660 *dest
= rgb_to_pixel16(r
, g
, b
) | alpha
;
663 *dest
= rgb_to_pixel24(r
, g
, b
) | alpha
;
666 *dest
= rgb_to_pixel32(r
, g
, b
) | alpha
;
673 static void pxa2xx_lcdc_dma0_redraw_rot0(PXA2xxLCDState
*s
,
674 target_phys_addr_t addr
, int *miny
, int *maxy
)
676 int src_width
, dest_width
;
679 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
683 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
684 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
686 else if (s
->bpp
> pxa_lcdc_16bpp
)
688 else if (s
->bpp
> pxa_lcdc_8bpp
)
691 dest_width
= s
->xres
* s
->dest_width
;
693 framebuffer_update_display(s
->ds
, s
->sysmem
,
694 addr
, s
->xres
, s
->yres
,
695 src_width
, dest_width
, s
->dest_width
,
697 fn
, s
->dma_ch
[0].palette
, miny
, maxy
);
700 static void pxa2xx_lcdc_dma0_redraw_rot90(PXA2xxLCDState
*s
,
701 target_phys_addr_t addr
, int *miny
, int *maxy
)
703 int src_width
, dest_width
;
706 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
710 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
711 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
713 else if (s
->bpp
> pxa_lcdc_16bpp
)
715 else if (s
->bpp
> pxa_lcdc_8bpp
)
718 dest_width
= s
->yres
* s
->dest_width
;
720 framebuffer_update_display(s
->ds
, s
->sysmem
,
721 addr
, s
->xres
, s
->yres
,
722 src_width
, s
->dest_width
, -dest_width
,
724 fn
, s
->dma_ch
[0].palette
,
728 static void pxa2xx_lcdc_dma0_redraw_rot180(PXA2xxLCDState
*s
,
729 target_phys_addr_t addr
, int *miny
, int *maxy
)
731 int src_width
, dest_width
;
734 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
740 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
741 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
) {
743 } else if (s
->bpp
> pxa_lcdc_16bpp
) {
745 } else if (s
->bpp
> pxa_lcdc_8bpp
) {
749 dest_width
= s
->xres
* s
->dest_width
;
751 framebuffer_update_display(s
->ds
, s
->sysmem
,
752 addr
, s
->xres
, s
->yres
,
753 src_width
, -dest_width
, -s
->dest_width
,
755 fn
, s
->dma_ch
[0].palette
, miny
, maxy
);
758 static void pxa2xx_lcdc_dma0_redraw_rot270(PXA2xxLCDState
*s
,
759 target_phys_addr_t addr
, int *miny
, int *maxy
)
761 int src_width
, dest_width
;
764 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
770 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
771 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
) {
773 } else if (s
->bpp
> pxa_lcdc_16bpp
) {
775 } else if (s
->bpp
> pxa_lcdc_8bpp
) {
779 dest_width
= s
->yres
* s
->dest_width
;
781 framebuffer_update_display(s
->ds
, s
->sysmem
,
782 addr
, s
->xres
, s
->yres
,
783 src_width
, -s
->dest_width
, dest_width
,
785 fn
, s
->dma_ch
[0].palette
,
789 static void pxa2xx_lcdc_resize(PXA2xxLCDState
*s
)
792 if (!(s
->control
[0] & LCCR0_ENB
))
795 width
= LCCR1_PPL(s
->control
[1]) + 1;
796 height
= LCCR2_LPP(s
->control
[2]) + 1;
798 if (width
!= s
->xres
|| height
!= s
->yres
) {
799 if (s
->orientation
== 90 || s
->orientation
== 270) {
800 qemu_console_resize(s
->ds
, height
, width
);
802 qemu_console_resize(s
->ds
, width
, height
);
810 static void pxa2xx_update_display(void *opaque
)
812 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
813 target_phys_addr_t fbptr
;
816 if (!(s
->control
[0] & LCCR0_ENB
))
819 pxa2xx_descriptor_load(s
);
821 pxa2xx_lcdc_resize(s
);
824 s
->transp
= s
->dma_ch
[2].up
|| s
->dma_ch
[3].up
;
825 /* Note: With overlay planes the order depends on LCCR0 bit 25. */
826 for (ch
= 0; ch
< PXA_LCDDMA_CHANS
; ch
++)
827 if (s
->dma_ch
[ch
].up
) {
828 if (!s
->dma_ch
[ch
].source
) {
829 pxa2xx_dma_ber_set(s
, ch
);
832 fbptr
= s
->dma_ch
[ch
].source
;
833 if (!(fbptr
>= PXA2XX_SDRAM_BASE
&&
834 fbptr
<= PXA2XX_SDRAM_BASE
+ ram_size
)) {
835 pxa2xx_dma_ber_set(s
, ch
);
839 if (s
->dma_ch
[ch
].command
& LDCMD_PAL
) {
840 cpu_physical_memory_read(fbptr
, s
->dma_ch
[ch
].pbuffer
,
841 MAX(LDCMD_LENGTH(s
->dma_ch
[ch
].command
),
842 sizeof(s
->dma_ch
[ch
].pbuffer
)));
843 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
845 /* Do we need to reparse palette */
846 if (LCCR4_PALFOR(s
->control
[4]) != s
->pal_for
)
847 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
849 /* ACK frame start */
850 pxa2xx_dma_sof_set(s
, ch
);
852 s
->dma_ch
[ch
].redraw(s
, fbptr
, &miny
, &maxy
);
855 /* ACK frame completed */
856 pxa2xx_dma_eof_set(s
, ch
);
860 if (s
->control
[0] & LCCR0_DIS
) {
861 /* ACK last frame completed */
862 s
->control
[0] &= ~LCCR0_ENB
;
863 s
->status
[0] |= LCSR0_LDD
;
867 switch (s
->orientation
) {
869 dpy_update(s
->ds
, 0, miny
, s
->xres
, maxy
- miny
+ 1);
872 dpy_update(s
->ds
, miny
, 0, maxy
- miny
+ 1, s
->xres
);
875 maxy
= s
->yres
- maxy
- 1;
876 miny
= s
->yres
- miny
- 1;
877 dpy_update(s
->ds
, 0, maxy
, s
->xres
, miny
- maxy
+ 1);
880 maxy
= s
->yres
- maxy
- 1;
881 miny
= s
->yres
- miny
- 1;
882 dpy_update(s
->ds
, maxy
, 0, miny
- maxy
+ 1, s
->xres
);
886 pxa2xx_lcdc_int_update(s
);
888 qemu_irq_raise(s
->vsync_cb
);
891 static void pxa2xx_invalidate_display(void *opaque
)
893 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
897 static void pxa2xx_screen_dump(void *opaque
, const char *filename
)
902 static void pxa2xx_lcdc_orientation(void *opaque
, int angle
)
904 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
908 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot0
;
911 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot90
;
914 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot180
;
917 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot270
;
921 s
->orientation
= angle
;
922 s
->xres
= s
->yres
= -1;
923 pxa2xx_lcdc_resize(s
);
926 static const VMStateDescription vmstate_dma_channel
= {
927 .name
= "dma_channel",
929 .minimum_version_id
= 0,
930 .minimum_version_id_old
= 0,
931 .fields
= (VMStateField
[]) {
932 VMSTATE_UINTTL(branch
, struct DMAChannel
),
933 VMSTATE_UINT8(up
, struct DMAChannel
),
934 VMSTATE_BUFFER(pbuffer
, struct DMAChannel
),
935 VMSTATE_UINTTL(descriptor
, struct DMAChannel
),
936 VMSTATE_UINTTL(source
, struct DMAChannel
),
937 VMSTATE_UINT32(id
, struct DMAChannel
),
938 VMSTATE_UINT32(command
, struct DMAChannel
),
939 VMSTATE_END_OF_LIST()
943 static int pxa2xx_lcdc_post_load(void *opaque
, int version_id
)
945 PXA2xxLCDState
*s
= opaque
;
947 s
->bpp
= LCCR3_BPP(s
->control
[3]);
948 s
->xres
= s
->yres
= s
->pal_for
= -1;
953 static const VMStateDescription vmstate_pxa2xx_lcdc
= {
954 .name
= "pxa2xx_lcdc",
956 .minimum_version_id
= 0,
957 .minimum_version_id_old
= 0,
958 .post_load
= pxa2xx_lcdc_post_load
,
959 .fields
= (VMStateField
[]) {
960 VMSTATE_INT32(irqlevel
, PXA2xxLCDState
),
961 VMSTATE_INT32(transp
, PXA2xxLCDState
),
962 VMSTATE_UINT32_ARRAY(control
, PXA2xxLCDState
, 6),
963 VMSTATE_UINT32_ARRAY(status
, PXA2xxLCDState
, 2),
964 VMSTATE_UINT32_ARRAY(ovl1c
, PXA2xxLCDState
, 2),
965 VMSTATE_UINT32_ARRAY(ovl2c
, PXA2xxLCDState
, 2),
966 VMSTATE_UINT32(ccr
, PXA2xxLCDState
),
967 VMSTATE_UINT32(cmdcr
, PXA2xxLCDState
),
968 VMSTATE_UINT32(trgbr
, PXA2xxLCDState
),
969 VMSTATE_UINT32(tcr
, PXA2xxLCDState
),
970 VMSTATE_UINT32(liidr
, PXA2xxLCDState
),
971 VMSTATE_UINT8(bscntr
, PXA2xxLCDState
),
972 VMSTATE_STRUCT_ARRAY(dma_ch
, PXA2xxLCDState
, 7, 0,
973 vmstate_dma_channel
, struct DMAChannel
),
974 VMSTATE_END_OF_LIST()
979 #include "pxa2xx_template.h"
981 #include "pxa2xx_template.h"
983 #include "pxa2xx_template.h"
985 #include "pxa2xx_template.h"
987 #include "pxa2xx_template.h"
989 PXA2xxLCDState
*pxa2xx_lcdc_init(MemoryRegion
*sysmem
,
990 target_phys_addr_t base
, qemu_irq irq
)
994 s
= (PXA2xxLCDState
*) g_malloc0(sizeof(PXA2xxLCDState
));
999 pxa2xx_lcdc_orientation(s
, graphic_rotate
);
1001 memory_region_init_io(&s
->iomem
, &pxa2xx_lcdc_ops
, s
,
1002 "pxa2xx-lcd-controller", 0x00100000);
1003 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
1005 s
->ds
= graphic_console_init(pxa2xx_update_display
,
1006 pxa2xx_invalidate_display
,
1007 pxa2xx_screen_dump
, NULL
, s
);
1009 switch (ds_get_bits_per_pixel(s
->ds
)) {
1014 s
->line_fn
[0] = pxa2xx_draw_fn_8
;
1015 s
->line_fn
[1] = pxa2xx_draw_fn_8t
;
1019 s
->line_fn
[0] = pxa2xx_draw_fn_15
;
1020 s
->line_fn
[1] = pxa2xx_draw_fn_15t
;
1024 s
->line_fn
[0] = pxa2xx_draw_fn_16
;
1025 s
->line_fn
[1] = pxa2xx_draw_fn_16t
;
1029 s
->line_fn
[0] = pxa2xx_draw_fn_24
;
1030 s
->line_fn
[1] = pxa2xx_draw_fn_24t
;
1034 s
->line_fn
[0] = pxa2xx_draw_fn_32
;
1035 s
->line_fn
[1] = pxa2xx_draw_fn_32t
;
1039 fprintf(stderr
, "%s: Bad color depth\n", __FUNCTION__
);
1043 vmstate_register(NULL
, 0, &vmstate_pxa2xx_lcdc
, s
);
1048 void pxa2xx_lcd_vsync_notifier(PXA2xxLCDState
*s
, qemu_irq handler
)
1050 s
->vsync_cb
= handler
;