2 * Intel XScale PXA255/270 LCDC emulation.
4 * Copyright (c) 2006 Openedhand Ltd.
7 * This code is licensed under the GPLv2.
12 typedef void (*drawfn)(uint32_t *, uint8_t *, const uint8_t *, int, int);
14 struct pxa2xx_lcdc_s {
15 target_phys_addr_t base;
51 target_phys_addr_t branch;
53 uint8_t palette[1024];
54 uint8_t pbuffer[1024];
55 void (*redraw)(struct pxa2xx_lcdc_s *s, uint8_t *fb,
56 int *miny, int *maxy);
58 target_phys_addr_t descriptor;
59 target_phys_addr_t source;
64 void (*vsync_cb)(void *opaque);
69 struct __attribute__ ((__packed__)) pxa_frame_descriptor_s {
76 #define LCCR0 0x000 /* LCD Controller Control register 0 */
77 #define LCCR1 0x004 /* LCD Controller Control register 1 */
78 #define LCCR2 0x008 /* LCD Controller Control register 2 */
79 #define LCCR3 0x00c /* LCD Controller Control register 3 */
80 #define LCCR4 0x010 /* LCD Controller Control register 4 */
81 #define LCCR5 0x014 /* LCD Controller Control register 5 */
83 #define FBR0 0x020 /* DMA Channel 0 Frame Branch register */
84 #define FBR1 0x024 /* DMA Channel 1 Frame Branch register */
85 #define FBR2 0x028 /* DMA Channel 2 Frame Branch register */
86 #define FBR3 0x02c /* DMA Channel 3 Frame Branch register */
87 #define FBR4 0x030 /* DMA Channel 4 Frame Branch register */
88 #define FBR5 0x110 /* DMA Channel 5 Frame Branch register */
89 #define FBR6 0x114 /* DMA Channel 6 Frame Branch register */
91 #define LCSR1 0x034 /* LCD Controller Status register 1 */
92 #define LCSR0 0x038 /* LCD Controller Status register 0 */
93 #define LIIDR 0x03c /* LCD Controller Interrupt ID register */
95 #define TRGBR 0x040 /* TMED RGB Seed register */
96 #define TCR 0x044 /* TMED Control register */
98 #define OVL1C1 0x050 /* Overlay 1 Control register 1 */
99 #define OVL1C2 0x060 /* Overlay 1 Control register 2 */
100 #define OVL2C1 0x070 /* Overlay 2 Control register 1 */
101 #define OVL2C2 0x080 /* Overlay 2 Control register 2 */
102 #define CCR 0x090 /* Cursor Control register */
104 #define CMDCR 0x100 /* Command Control register */
105 #define PRSR 0x104 /* Panel Read Status register */
107 #define PXA_LCDDMA_CHANS 7
108 #define DMA_FDADR 0x00 /* Frame Descriptor Address register */
109 #define DMA_FSADR 0x04 /* Frame Source Address register */
110 #define DMA_FIDR 0x08 /* Frame ID register */
111 #define DMA_LDCMD 0x0c /* Command register */
113 /* LCD Buffer Strength Control register */
114 #define BSCNTR 0x04000054
117 #define LCCR0_ENB (1 << 0)
118 #define LCCR0_CMS (1 << 1)
119 #define LCCR0_SDS (1 << 2)
120 #define LCCR0_LDM (1 << 3)
121 #define LCCR0_SOFM0 (1 << 4)
122 #define LCCR0_IUM (1 << 5)
123 #define LCCR0_EOFM0 (1 << 6)
124 #define LCCR0_PAS (1 << 7)
125 #define LCCR0_DPD (1 << 9)
126 #define LCCR0_DIS (1 << 10)
127 #define LCCR0_QDM (1 << 11)
128 #define LCCR0_PDD (0xff << 12)
129 #define LCCR0_BSM0 (1 << 20)
130 #define LCCR0_OUM (1 << 21)
131 #define LCCR0_LCDT (1 << 22)
132 #define LCCR0_RDSTM (1 << 23)
133 #define LCCR0_CMDIM (1 << 24)
134 #define LCCR0_OUC (1 << 25)
135 #define LCCR0_LDDALT (1 << 26)
136 #define LCCR1_PPL(x) ((x) & 0x3ff)
137 #define LCCR2_LPP(x) ((x) & 0x3ff)
138 #define LCCR3_API (15 << 16)
139 #define LCCR3_BPP(x) ((((x) >> 24) & 7) | (((x) >> 26) & 8))
140 #define LCCR3_PDFOR(x) (((x) >> 30) & 3)
141 #define LCCR4_K1(x) (((x) >> 0) & 7)
142 #define LCCR4_K2(x) (((x) >> 3) & 7)
143 #define LCCR4_K3(x) (((x) >> 6) & 7)
144 #define LCCR4_PALFOR(x) (((x) >> 15) & 3)
145 #define LCCR5_SOFM(ch) (1 << (ch - 1))
146 #define LCCR5_EOFM(ch) (1 << (ch + 7))
147 #define LCCR5_BSM(ch) (1 << (ch + 15))
148 #define LCCR5_IUM(ch) (1 << (ch + 23))
149 #define OVLC1_EN (1 << 31)
150 #define CCR_CEN (1 << 31)
151 #define FBR_BRA (1 << 0)
152 #define FBR_BINT (1 << 1)
153 #define FBR_SRCADDR (0xfffffff << 4)
154 #define LCSR0_LDD (1 << 0)
155 #define LCSR0_SOF0 (1 << 1)
156 #define LCSR0_BER (1 << 2)
157 #define LCSR0_ABC (1 << 3)
158 #define LCSR0_IU0 (1 << 4)
159 #define LCSR0_IU1 (1 << 5)
160 #define LCSR0_OU (1 << 6)
161 #define LCSR0_QD (1 << 7)
162 #define LCSR0_EOF0 (1 << 8)
163 #define LCSR0_BS0 (1 << 9)
164 #define LCSR0_SINT (1 << 10)
165 #define LCSR0_RDST (1 << 11)
166 #define LCSR0_CMDINT (1 << 12)
167 #define LCSR0_BERCH(x) (((x) & 7) << 28)
168 #define LCSR1_SOF(ch) (1 << (ch - 1))
169 #define LCSR1_EOF(ch) (1 << (ch + 7))
170 #define LCSR1_BS(ch) (1 << (ch + 15))
171 #define LCSR1_IU(ch) (1 << (ch + 23))
172 #define LDCMD_LENGTH(x) ((x) & 0x001ffffc)
173 #define LDCMD_EOFINT (1 << 21)
174 #define LDCMD_SOFINT (1 << 22)
175 #define LDCMD_PAL (1 << 26)
177 /* Route internal interrupt lines to the global IC */
178 static void pxa2xx_lcdc_int_update(struct pxa2xx_lcdc_s *s)
181 level |= (s->status[0] & LCSR0_LDD) && !(s->control[0] & LCCR0_LDM);
182 level |= (s->status[0] & LCSR0_SOF0) && !(s->control[0] & LCCR0_SOFM0);
183 level |= (s->status[0] & LCSR0_IU0) && !(s->control[0] & LCCR0_IUM);
184 level |= (s->status[0] & LCSR0_IU1) && !(s->control[5] & LCCR5_IUM(1));
185 level |= (s->status[0] & LCSR0_OU) && !(s->control[0] & LCCR0_OUM);
186 level |= (s->status[0] & LCSR0_QD) && !(s->control[0] & LCCR0_QDM);
187 level |= (s->status[0] & LCSR0_EOF0) && !(s->control[0] & LCCR0_EOFM0);
188 level |= (s->status[0] & LCSR0_BS0) && !(s->control[0] & LCCR0_BSM0);
189 level |= (s->status[0] & LCSR0_RDST) && !(s->control[0] & LCCR0_RDSTM);
190 level |= (s->status[0] & LCSR0_CMDINT) && !(s->control[0] & LCCR0_CMDIM);
191 level |= (s->status[1] & ~s->control[5]);
193 qemu_set_irq(s->irq, !!level);
197 /* Set Branch Status interrupt high and poke associated registers */
198 static inline void pxa2xx_dma_bs_set(struct pxa2xx_lcdc_s *s, int ch)
202 s->status[0] |= LCSR0_BS0;
203 unmasked = !(s->control[0] & LCCR0_BSM0);
205 s->status[1] |= LCSR1_BS(ch);
206 unmasked = !(s->control[5] & LCCR5_BSM(ch));
211 s->status[0] |= LCSR0_SINT;
213 s->liidr = s->dma_ch[ch].id;
217 /* Set Start Of Frame Status interrupt high and poke associated registers */
218 static inline void pxa2xx_dma_sof_set(struct pxa2xx_lcdc_s *s, int ch)
221 if (!(s->dma_ch[ch].command & LDCMD_SOFINT))
225 s->status[0] |= LCSR0_SOF0;
226 unmasked = !(s->control[0] & LCCR0_SOFM0);
228 s->status[1] |= LCSR1_SOF(ch);
229 unmasked = !(s->control[5] & LCCR5_SOFM(ch));
234 s->status[0] |= LCSR0_SINT;
236 s->liidr = s->dma_ch[ch].id;
240 /* Set End Of Frame Status interrupt high and poke associated registers */
241 static inline void pxa2xx_dma_eof_set(struct pxa2xx_lcdc_s *s, int ch)
244 if (!(s->dma_ch[ch].command & LDCMD_EOFINT))
248 s->status[0] |= LCSR0_EOF0;
249 unmasked = !(s->control[0] & LCCR0_EOFM0);
251 s->status[1] |= LCSR1_EOF(ch);
252 unmasked = !(s->control[5] & LCCR5_EOFM(ch));
257 s->status[0] |= LCSR0_SINT;
259 s->liidr = s->dma_ch[ch].id;
263 /* Set Bus Error Status interrupt high and poke associated registers */
264 static inline void pxa2xx_dma_ber_set(struct pxa2xx_lcdc_s *s, int ch)
266 s->status[0] |= LCSR0_BERCH(ch) | LCSR0_BER;
268 s->status[0] |= LCSR0_SINT;
270 s->liidr = s->dma_ch[ch].id;
273 /* Set Read Status interrupt high and poke associated registers */
274 static inline void pxa2xx_dma_rdst_set(struct pxa2xx_lcdc_s *s)
276 s->status[0] |= LCSR0_RDST;
277 if (s->irqlevel && !(s->control[0] & LCCR0_RDSTM))
278 s->status[0] |= LCSR0_SINT;
281 /* Load new Frame Descriptors from DMA */
282 static void pxa2xx_descriptor_load(struct pxa2xx_lcdc_s *s)
284 struct pxa_frame_descriptor_s *desc[PXA_LCDDMA_CHANS];
285 target_phys_addr_t descptr;
288 for (i = 0; i < PXA_LCDDMA_CHANS; i ++) {
290 s->dma_ch[i].source = 0;
292 if (!s->dma_ch[i].up)
295 if (s->dma_ch[i].branch & FBR_BRA) {
296 descptr = s->dma_ch[i].branch & FBR_SRCADDR;
297 if (s->dma_ch[i].branch & FBR_BINT)
298 pxa2xx_dma_bs_set(s, i);
299 s->dma_ch[i].branch &= ~FBR_BRA;
301 descptr = s->dma_ch[i].descriptor;
303 if (!(descptr >= PXA2XX_SDRAM_BASE && descptr +
304 sizeof(*desc[i]) <= PXA2XX_SDRAM_BASE + phys_ram_size))
307 descptr -= PXA2XX_SDRAM_BASE;
308 desc[i] = (struct pxa_frame_descriptor_s *) (phys_ram_base + descptr);
309 s->dma_ch[i].descriptor = desc[i]->fdaddr;
310 s->dma_ch[i].source = desc[i]->fsaddr;
311 s->dma_ch[i].id = desc[i]->fidr;
312 s->dma_ch[i].command = desc[i]->ldcmd;
316 static uint32_t pxa2xx_lcdc_read(void *opaque, target_phys_addr_t offset)
318 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
324 return s->control[0];
326 return s->control[1];
328 return s->control[2];
330 return s->control[3];
332 return s->control[4];
334 return s->control[5];
356 case 0x200 ... 0x1000: /* DMA per-channel registers */
357 ch = (offset - 0x200) >> 4;
358 if (!(ch >= 0 && ch < PXA_LCDDMA_CHANS))
361 switch (offset & 0xf) {
363 return s->dma_ch[ch].descriptor;
365 return s->dma_ch[ch].source;
367 return s->dma_ch[ch].id;
369 return s->dma_ch[ch].command;
375 return s->dma_ch[0].branch;
377 return s->dma_ch[1].branch;
379 return s->dma_ch[2].branch;
381 return s->dma_ch[3].branch;
383 return s->dma_ch[4].branch;
385 return s->dma_ch[5].branch;
387 return s->dma_ch[6].branch;
404 cpu_abort(cpu_single_env,
405 "%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
411 static void pxa2xx_lcdc_write(void *opaque,
412 target_phys_addr_t offset, uint32_t value)
414 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
420 /* ACK Quick Disable done */
421 if ((s->control[0] & LCCR0_ENB) && !(value & LCCR0_ENB))
422 s->status[0] |= LCSR0_QD;
424 if (!(s->control[0] & LCCR0_LCDT) && (value & LCCR0_LCDT))
425 printf("%s: internal frame buffer unsupported\n", __FUNCTION__);
427 if ((s->control[3] & LCCR3_API) &&
428 (value & LCCR0_ENB) && !(value & LCCR0_LCDT))
429 s->status[0] |= LCSR0_ABC;
431 s->control[0] = value & 0x07ffffff;
432 pxa2xx_lcdc_int_update(s);
434 s->dma_ch[0].up = !!(value & LCCR0_ENB);
435 s->dma_ch[1].up = (s->ovl1c[0] & OVLC1_EN) || (value & LCCR0_SDS);
439 s->control[1] = value;
443 s->control[2] = value;
447 s->control[3] = value & 0xefffffff;
448 s->bpp = LCCR3_BPP(value);
452 s->control[4] = value & 0x83ff81ff;
456 s->control[5] = value & 0x3f3f3f3f;
460 if (!(s->ovl1c[0] & OVLC1_EN) && (value & OVLC1_EN))
461 printf("%s: Overlay 1 not supported\n", __FUNCTION__);
463 s->ovl1c[0] = value & 0x80ffffff;
464 s->dma_ch[1].up = (value & OVLC1_EN) || (s->control[0] & LCCR0_SDS);
468 s->ovl1c[1] = value & 0x000fffff;
472 if (!(s->ovl2c[0] & OVLC1_EN) && (value & OVLC1_EN))
473 printf("%s: Overlay 2 not supported\n", __FUNCTION__);
475 s->ovl2c[0] = value & 0x80ffffff;
476 s->dma_ch[2].up = !!(value & OVLC1_EN);
477 s->dma_ch[3].up = !!(value & OVLC1_EN);
478 s->dma_ch[4].up = !!(value & OVLC1_EN);
482 s->ovl2c[1] = value & 0x007fffff;
486 if (!(s->ccr & CCR_CEN) && (value & CCR_CEN))
487 printf("%s: Hardware cursor unimplemented\n", __FUNCTION__);
489 s->ccr = value & 0x81ffffe7;
490 s->dma_ch[5].up = !!(value & CCR_CEN);
494 s->cmdcr = value & 0xff;
498 s->trgbr = value & 0x00ffffff;
502 s->tcr = value & 0x7fff;
505 case 0x200 ... 0x1000: /* DMA per-channel registers */
506 ch = (offset - 0x200) >> 4;
507 if (!(ch >= 0 && ch < PXA_LCDDMA_CHANS))
510 switch (offset & 0xf) {
512 s->dma_ch[ch].descriptor = value & 0xfffffff0;
521 s->dma_ch[0].branch = value & 0xfffffff3;
524 s->dma_ch[1].branch = value & 0xfffffff3;
527 s->dma_ch[2].branch = value & 0xfffffff3;
530 s->dma_ch[3].branch = value & 0xfffffff3;
533 s->dma_ch[4].branch = value & 0xfffffff3;
536 s->dma_ch[5].branch = value & 0xfffffff3;
539 s->dma_ch[6].branch = value & 0xfffffff3;
543 s->bscntr = value & 0xf;
550 s->status[0] &= ~(value & 0xfff);
551 if (value & LCSR0_BER)
552 s->status[0] &= ~LCSR0_BERCH(7);
556 s->status[1] &= ~(value & 0x3e3f3f);
561 cpu_abort(cpu_single_env,
562 "%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
566 static CPUReadMemoryFunc *pxa2xx_lcdc_readfn[] = {
572 static CPUWriteMemoryFunc *pxa2xx_lcdc_writefn[] = {
579 uint32_t rgb_to_pixel8(unsigned int r, unsigned int g, unsigned b)
581 return ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
585 uint32_t rgb_to_pixel15(unsigned int r, unsigned int g, unsigned b)
587 return ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
591 uint32_t rgb_to_pixel16(unsigned int r, unsigned int g, unsigned b)
593 return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
597 uint32_t rgb_to_pixel24(unsigned int r, unsigned int g, unsigned b)
599 return (r << 16) | (g << 8) | b;
603 uint32_t rgb_to_pixel32(unsigned int r, unsigned int g, unsigned b)
605 return (r << 16) | (g << 8) | b;
608 /* Load new palette for a given DMA channel, convert to internal format */
609 static void pxa2xx_palette_parse(struct pxa2xx_lcdc_s *s, int ch, int bpp)
611 int i, n, format, r, g, b, alpha;
612 uint32_t *dest, *src;
613 s->pal_for = LCCR4_PALFOR(s->control[4]);
631 src = (uint32_t *) s->dma_ch[ch].pbuffer;
632 dest = (uint32_t *) s->dma_ch[ch].palette;
633 alpha = r = g = b = 0;
635 for (i = 0; i < n; i ++) {
637 case 0: /* 16 bpp, no transparency */
639 if (s->control[0] & LCCR0_CMS)
640 r = g = b = *src & 0xff;
642 r = (*src & 0xf800) >> 8;
643 g = (*src & 0x07e0) >> 3;
644 b = (*src & 0x001f) << 3;
647 case 1: /* 16 bpp plus transparency */
648 alpha = *src & (1 << 24);
649 if (s->control[0] & LCCR0_CMS)
650 r = g = b = *src & 0xff;
652 r = (*src & 0xf800) >> 8;
653 g = (*src & 0x07e0) >> 3;
654 b = (*src & 0x001f) << 3;
657 case 2: /* 18 bpp plus transparency */
658 alpha = *src & (1 << 24);
659 if (s->control[0] & LCCR0_CMS)
660 r = g = b = *src & 0xff;
662 r = (*src & 0xf80000) >> 16;
663 g = (*src & 0x00fc00) >> 8;
664 b = (*src & 0x0000f8);
667 case 3: /* 24 bpp plus transparency */
668 alpha = *src & (1 << 24);
669 if (s->control[0] & LCCR0_CMS)
670 r = g = b = *src & 0xff;
672 r = (*src & 0xff0000) >> 16;
673 g = (*src & 0x00ff00) >> 8;
674 b = (*src & 0x0000ff);
678 switch (s->ds->depth) {
680 *dest = rgb_to_pixel8(r, g, b) | alpha;
683 *dest = rgb_to_pixel15(r, g, b) | alpha;
686 *dest = rgb_to_pixel16(r, g, b) | alpha;
689 *dest = rgb_to_pixel24(r, g, b) | alpha;
692 *dest = rgb_to_pixel32(r, g, b) | alpha;
700 static void pxa2xx_lcdc_dma0_redraw_horiz(struct pxa2xx_lcdc_s *s,
701 uint8_t *fb, int *miny, int *maxy)
703 int y, src_width, dest_width, dirty[2];
705 ram_addr_t x, addr, new_addr, start, end;
708 fn = s->line_fn[s->transp][s->bpp];
713 src_width = (s->xres + 3) & ~3; /* Pad to a 4 pixels multiple */
714 if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp)
716 else if (s->bpp > pxa_lcdc_16bpp)
718 else if (s->bpp > pxa_lcdc_8bpp)
722 dest_width = s->xres * s->dest_width;
724 addr = (ram_addr_t) (fb - phys_ram_base);
725 start = addr + s->yres * src_width;
727 dirty[0] = dirty[1] = cpu_physical_memory_get_dirty(start, VGA_DIRTY_FLAG);
728 for (y = 0; y < s->yres; y ++) {
729 new_addr = addr + src_width;
730 for (x = addr + TARGET_PAGE_SIZE; x < new_addr;
731 x += TARGET_PAGE_SIZE) {
732 dirty[1] = cpu_physical_memory_get_dirty(x, VGA_DIRTY_FLAG);
733 dirty[0] |= dirty[1];
735 if (dirty[0] || s->invalidated) {
736 fn((uint32_t *) s->dma_ch[0].palette,
737 dest, src, s->xres, s->dest_width);
753 cpu_physical_memory_reset_dirty(start, end, VGA_DIRTY_FLAG);
756 static void pxa2xx_lcdc_dma0_redraw_vert(struct pxa2xx_lcdc_s *s,
757 uint8_t *fb, int *miny, int *maxy)
759 int y, src_width, dest_width, dirty[2];
761 ram_addr_t x, addr, new_addr, start, end;
764 fn = s->line_fn[s->transp][s->bpp];
769 src_width = (s->xres + 3) & ~3; /* Pad to a 4 pixels multiple */
770 if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp)
772 else if (s->bpp > pxa_lcdc_16bpp)
774 else if (s->bpp > pxa_lcdc_8bpp)
777 dest_width = s->yres * s->dest_width;
778 dest = s->ds->data + dest_width * (s->xres - 1);
780 addr = (ram_addr_t) (fb - phys_ram_base);
781 start = addr + s->yres * src_width;
783 dirty[0] = dirty[1] = cpu_physical_memory_get_dirty(start, VGA_DIRTY_FLAG);
784 for (y = 0; y < s->yres; y ++) {
785 new_addr = addr + src_width;
786 for (x = addr + TARGET_PAGE_SIZE; x < new_addr;
787 x += TARGET_PAGE_SIZE) {
788 dirty[1] = cpu_physical_memory_get_dirty(x, VGA_DIRTY_FLAG);
789 dirty[0] |= dirty[1];
791 if (dirty[0] || s->invalidated) {
792 fn((uint32_t *) s->dma_ch[0].palette,
793 dest, src, s->xres, -dest_width);
805 dest += s->dest_width;
809 cpu_physical_memory_reset_dirty(start, end, VGA_DIRTY_FLAG);
812 static void pxa2xx_lcdc_resize(struct pxa2xx_lcdc_s *s)
815 if (!(s->control[0] & LCCR0_ENB))
818 width = LCCR1_PPL(s->control[1]) + 1;
819 height = LCCR2_LPP(s->control[2]) + 1;
821 if (width != s->xres || height != s->yres) {
823 dpy_resize(s->ds, height, width);
825 dpy_resize(s->ds, width, height);
832 static void pxa2xx_update_display(void *opaque)
834 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
836 target_phys_addr_t fbptr;
839 if (!(s->control[0] & LCCR0_ENB))
842 pxa2xx_descriptor_load(s);
844 pxa2xx_lcdc_resize(s);
847 s->transp = s->dma_ch[2].up || s->dma_ch[3].up;
848 /* Note: With overlay planes the order depends on LCCR0 bit 25. */
849 for (ch = 0; ch < PXA_LCDDMA_CHANS; ch ++)
850 if (s->dma_ch[ch].up) {
851 if (!s->dma_ch[ch].source) {
852 pxa2xx_dma_ber_set(s, ch);
855 fbptr = s->dma_ch[ch].source;
856 if (!(fbptr >= PXA2XX_SDRAM_BASE &&
857 fbptr <= PXA2XX_SDRAM_BASE + phys_ram_size)) {
858 pxa2xx_dma_ber_set(s, ch);
861 fbptr -= PXA2XX_SDRAM_BASE;
862 fb = phys_ram_base + fbptr;
864 if (s->dma_ch[ch].command & LDCMD_PAL) {
865 memcpy(s->dma_ch[ch].pbuffer, fb,
866 MAX(LDCMD_LENGTH(s->dma_ch[ch].command),
867 sizeof(s->dma_ch[ch].pbuffer)));
868 pxa2xx_palette_parse(s, ch, s->bpp);
870 /* Do we need to reparse palette */
871 if (LCCR4_PALFOR(s->control[4]) != s->pal_for)
872 pxa2xx_palette_parse(s, ch, s->bpp);
874 /* ACK frame start */
875 pxa2xx_dma_sof_set(s, ch);
877 s->dma_ch[ch].redraw(s, fb, &miny, &maxy);
880 /* ACK frame completed */
881 pxa2xx_dma_eof_set(s, ch);
885 if (s->control[0] & LCCR0_DIS) {
886 /* ACK last frame completed */
887 s->control[0] &= ~LCCR0_ENB;
888 s->status[0] |= LCSR0_LDD;
892 dpy_update(s->ds, miny, 0, maxy, s->xres);
894 dpy_update(s->ds, 0, miny, s->xres, maxy);
895 pxa2xx_lcdc_int_update(s);
898 s->vsync_cb(s->opaque);
901 static void pxa2xx_invalidate_display(void *opaque)
903 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
907 static void pxa2xx_screen_dump(void *opaque, const char *filename)
912 void pxa2xx_lcdc_orientation(void *opaque, int angle)
914 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
917 s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_vert;
919 s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_horiz;
922 s->orientation = angle;
923 s->xres = s->yres = -1;
924 pxa2xx_lcdc_resize(s);
928 #include "pxa2xx_template.h"
930 #include "pxa2xx_template.h"
932 #include "pxa2xx_template.h"
934 #include "pxa2xx_template.h"
936 #include "pxa2xx_template.h"
938 struct pxa2xx_lcdc_s *pxa2xx_lcdc_init(target_phys_addr_t base, qemu_irq irq,
942 struct pxa2xx_lcdc_s *s;
944 s = (struct pxa2xx_lcdc_s *) qemu_mallocz(sizeof(struct pxa2xx_lcdc_s));
950 pxa2xx_lcdc_orientation(s, graphic_rotate);
952 iomemtype = cpu_register_io_memory(0, pxa2xx_lcdc_readfn,
953 pxa2xx_lcdc_writefn, s);
954 cpu_register_physical_memory(base, 0x000fffff, iomemtype);
956 graphic_console_init(ds, pxa2xx_update_display,
957 pxa2xx_invalidate_display, pxa2xx_screen_dump, s);
959 switch (s->ds->depth) {
964 s->line_fn[0] = pxa2xx_draw_fn_8;
965 s->line_fn[1] = pxa2xx_draw_fn_8t;
969 s->line_fn[0] = pxa2xx_draw_fn_15;
970 s->line_fn[1] = pxa2xx_draw_fn_15t;
974 s->line_fn[0] = pxa2xx_draw_fn_16;
975 s->line_fn[1] = pxa2xx_draw_fn_16t;
979 s->line_fn[0] = pxa2xx_draw_fn_24;
980 s->line_fn[1] = pxa2xx_draw_fn_24t;
984 s->line_fn[0] = pxa2xx_draw_fn_32;
985 s->line_fn[1] = pxa2xx_draw_fn_32t;
989 fprintf(stderr, "%s: Bad color depth\n", __FUNCTION__);
995 void pxa2xx_lcd_vsync_cb(struct pxa2xx_lcdc_s *s,
996 void (*cb)(void *opaque), void *opaque) {