2 * Intel XScale PXA255/270 LCDC emulation.
4 * Copyright (c) 2006 Openedhand Ltd.
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. */
17 typedef void (*drawfn)(uint32_t *, uint8_t *, const uint8_t *, int, int);
19 struct pxa2xx_lcdc_s {
20 target_phys_addr_t base;
56 target_phys_addr_t branch;
58 uint8_t palette[1024];
59 uint8_t pbuffer[1024];
60 void (*redraw)(struct pxa2xx_lcdc_s *s, uint8_t *fb,
61 int *miny, int *maxy);
63 target_phys_addr_t descriptor;
64 target_phys_addr_t source;
73 struct __attribute__ ((__packed__)) pxa_frame_descriptor_s {
80 #define LCCR0 0x000 /* LCD Controller Control register 0 */
81 #define LCCR1 0x004 /* LCD Controller Control register 1 */
82 #define LCCR2 0x008 /* LCD Controller Control register 2 */
83 #define LCCR3 0x00c /* LCD Controller Control register 3 */
84 #define LCCR4 0x010 /* LCD Controller Control register 4 */
85 #define LCCR5 0x014 /* LCD Controller Control register 5 */
87 #define FBR0 0x020 /* DMA Channel 0 Frame Branch register */
88 #define FBR1 0x024 /* DMA Channel 1 Frame Branch register */
89 #define FBR2 0x028 /* DMA Channel 2 Frame Branch register */
90 #define FBR3 0x02c /* DMA Channel 3 Frame Branch register */
91 #define FBR4 0x030 /* DMA Channel 4 Frame Branch register */
92 #define FBR5 0x110 /* DMA Channel 5 Frame Branch register */
93 #define FBR6 0x114 /* DMA Channel 6 Frame Branch register */
95 #define LCSR1 0x034 /* LCD Controller Status register 1 */
96 #define LCSR0 0x038 /* LCD Controller Status register 0 */
97 #define LIIDR 0x03c /* LCD Controller Interrupt ID register */
99 #define TRGBR 0x040 /* TMED RGB Seed register */
100 #define TCR 0x044 /* TMED Control register */
102 #define OVL1C1 0x050 /* Overlay 1 Control register 1 */
103 #define OVL1C2 0x060 /* Overlay 1 Control register 2 */
104 #define OVL2C1 0x070 /* Overlay 2 Control register 1 */
105 #define OVL2C2 0x080 /* Overlay 2 Control register 2 */
106 #define CCR 0x090 /* Cursor Control register */
108 #define CMDCR 0x100 /* Command Control register */
109 #define PRSR 0x104 /* Panel Read Status register */
111 #define PXA_LCDDMA_CHANS 7
112 #define DMA_FDADR 0x00 /* Frame Descriptor Address register */
113 #define DMA_FSADR 0x04 /* Frame Source Address register */
114 #define DMA_FIDR 0x08 /* Frame ID register */
115 #define DMA_LDCMD 0x0c /* Command register */
117 /* LCD Buffer Strength Control register */
118 #define BSCNTR 0x04000054
121 #define LCCR0_ENB (1 << 0)
122 #define LCCR0_CMS (1 << 1)
123 #define LCCR0_SDS (1 << 2)
124 #define LCCR0_LDM (1 << 3)
125 #define LCCR0_SOFM0 (1 << 4)
126 #define LCCR0_IUM (1 << 5)
127 #define LCCR0_EOFM0 (1 << 6)
128 #define LCCR0_PAS (1 << 7)
129 #define LCCR0_DPD (1 << 9)
130 #define LCCR0_DIS (1 << 10)
131 #define LCCR0_QDM (1 << 11)
132 #define LCCR0_PDD (0xff << 12)
133 #define LCCR0_BSM0 (1 << 20)
134 #define LCCR0_OUM (1 << 21)
135 #define LCCR0_LCDT (1 << 22)
136 #define LCCR0_RDSTM (1 << 23)
137 #define LCCR0_CMDIM (1 << 24)
138 #define LCCR0_OUC (1 << 25)
139 #define LCCR0_LDDALT (1 << 26)
140 #define LCCR1_PPL(x) ((x) & 0x3ff)
141 #define LCCR2_LPP(x) ((x) & 0x3ff)
142 #define LCCR3_API (15 << 16)
143 #define LCCR3_BPP(x) ((((x) >> 24) & 7) | (((x) >> 26) & 8))
144 #define LCCR3_PDFOR(x) (((x) >> 30) & 3)
145 #define LCCR4_K1(x) (((x) >> 0) & 7)
146 #define LCCR4_K2(x) (((x) >> 3) & 7)
147 #define LCCR4_K3(x) (((x) >> 6) & 7)
148 #define LCCR4_PALFOR(x) (((x) >> 15) & 3)
149 #define LCCR5_SOFM(ch) (1 << (ch - 1))
150 #define LCCR5_EOFM(ch) (1 << (ch + 7))
151 #define LCCR5_BSM(ch) (1 << (ch + 15))
152 #define LCCR5_IUM(ch) (1 << (ch + 23))
153 #define OVLC1_EN (1 << 31)
154 #define CCR_CEN (1 << 31)
155 #define FBR_BRA (1 << 0)
156 #define FBR_BINT (1 << 1)
157 #define FBR_SRCADDR (0xfffffff << 4)
158 #define LCSR0_LDD (1 << 0)
159 #define LCSR0_SOF0 (1 << 1)
160 #define LCSR0_BER (1 << 2)
161 #define LCSR0_ABC (1 << 3)
162 #define LCSR0_IU0 (1 << 4)
163 #define LCSR0_IU1 (1 << 5)
164 #define LCSR0_OU (1 << 6)
165 #define LCSR0_QD (1 << 7)
166 #define LCSR0_EOF0 (1 << 8)
167 #define LCSR0_BS0 (1 << 9)
168 #define LCSR0_SINT (1 << 10)
169 #define LCSR0_RDST (1 << 11)
170 #define LCSR0_CMDINT (1 << 12)
171 #define LCSR0_BERCH(x) (((x) & 7) << 28)
172 #define LCSR1_SOF(ch) (1 << (ch - 1))
173 #define LCSR1_EOF(ch) (1 << (ch + 7))
174 #define LCSR1_BS(ch) (1 << (ch + 15))
175 #define LCSR1_IU(ch) (1 << (ch + 23))
176 #define LDCMD_LENGTH(x) ((x) & 0x001ffffc)
177 #define LDCMD_EOFINT (1 << 21)
178 #define LDCMD_SOFINT (1 << 22)
179 #define LDCMD_PAL (1 << 26)
181 /* Route internal interrupt lines to the global IC */
182 static void pxa2xx_lcdc_int_update(struct pxa2xx_lcdc_s *s)
185 level |= (s->status[0] & LCSR0_LDD) && !(s->control[0] & LCCR0_LDM);
186 level |= (s->status[0] & LCSR0_SOF0) && !(s->control[0] & LCCR0_SOFM0);
187 level |= (s->status[0] & LCSR0_IU0) && !(s->control[0] & LCCR0_IUM);
188 level |= (s->status[0] & LCSR0_IU1) && !(s->control[5] & LCCR5_IUM(1));
189 level |= (s->status[0] & LCSR0_OU) && !(s->control[0] & LCCR0_OUM);
190 level |= (s->status[0] & LCSR0_QD) && !(s->control[0] & LCCR0_QDM);
191 level |= (s->status[0] & LCSR0_EOF0) && !(s->control[0] & LCCR0_EOFM0);
192 level |= (s->status[0] & LCSR0_BS0) && !(s->control[0] & LCCR0_BSM0);
193 level |= (s->status[0] & LCSR0_RDST) && !(s->control[0] & LCCR0_RDSTM);
194 level |= (s->status[0] & LCSR0_CMDINT) && !(s->control[0] & LCCR0_CMDIM);
195 level |= (s->status[1] & ~s->control[5]);
197 qemu_set_irq(s->irq, !!level);
201 /* Set Branch Status interrupt high and poke associated registers */
202 static inline void pxa2xx_dma_bs_set(struct pxa2xx_lcdc_s *s, int ch)
206 s->status[0] |= LCSR0_BS0;
207 unmasked = !(s->control[0] & LCCR0_BSM0);
209 s->status[1] |= LCSR1_BS(ch);
210 unmasked = !(s->control[5] & LCCR5_BSM(ch));
215 s->status[0] |= LCSR0_SINT;
217 s->liidr = s->dma_ch[ch].id;
221 /* Set Start Of Frame Status interrupt high and poke associated registers */
222 static inline void pxa2xx_dma_sof_set(struct pxa2xx_lcdc_s *s, int ch)
225 if (!(s->dma_ch[ch].command & LDCMD_SOFINT))
229 s->status[0] |= LCSR0_SOF0;
230 unmasked = !(s->control[0] & LCCR0_SOFM0);
232 s->status[1] |= LCSR1_SOF(ch);
233 unmasked = !(s->control[5] & LCCR5_SOFM(ch));
238 s->status[0] |= LCSR0_SINT;
240 s->liidr = s->dma_ch[ch].id;
244 /* Set End Of Frame Status interrupt high and poke associated registers */
245 static inline void pxa2xx_dma_eof_set(struct pxa2xx_lcdc_s *s, int ch)
248 if (!(s->dma_ch[ch].command & LDCMD_EOFINT))
252 s->status[0] |= LCSR0_EOF0;
253 unmasked = !(s->control[0] & LCCR0_EOFM0);
255 s->status[1] |= LCSR1_EOF(ch);
256 unmasked = !(s->control[5] & LCCR5_EOFM(ch));
261 s->status[0] |= LCSR0_SINT;
263 s->liidr = s->dma_ch[ch].id;
267 /* Set Bus Error Status interrupt high and poke associated registers */
268 static inline void pxa2xx_dma_ber_set(struct pxa2xx_lcdc_s *s, int ch)
270 s->status[0] |= LCSR0_BERCH(ch) | LCSR0_BER;
272 s->status[0] |= LCSR0_SINT;
274 s->liidr = s->dma_ch[ch].id;
277 /* Set Read Status interrupt high and poke associated registers */
278 static inline void pxa2xx_dma_rdst_set(struct pxa2xx_lcdc_s *s)
280 s->status[0] |= LCSR0_RDST;
281 if (s->irqlevel && !(s->control[0] & LCCR0_RDSTM))
282 s->status[0] |= LCSR0_SINT;
285 /* Load new Frame Descriptors from DMA */
286 static void pxa2xx_descriptor_load(struct pxa2xx_lcdc_s *s)
288 struct pxa_frame_descriptor_s *desc[PXA_LCDDMA_CHANS];
289 target_phys_addr_t descptr;
292 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[i]) <= PXA2XX_SDRAM_BASE + phys_ram_size))
311 descptr -= PXA2XX_SDRAM_BASE;
312 desc[i] = (struct pxa_frame_descriptor_s *) (phys_ram_base + descptr);
313 s->dma_ch[i].descriptor = desc[i]->fdaddr;
314 s->dma_ch[i].source = desc[i]->fsaddr;
315 s->dma_ch[i].id = desc[i]->fidr;
316 s->dma_ch[i].command = desc[i]->ldcmd;
320 static uint32_t pxa2xx_lcdc_read(void *opaque, target_phys_addr_t offset)
322 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
328 return s->control[0];
330 return s->control[1];
332 return s->control[2];
334 return s->control[3];
336 return s->control[4];
338 return s->control[5];
360 case 0x200 ... 0x1000: /* DMA per-channel registers */
361 ch = (offset - 0x200) >> 4;
362 if (!(ch >= 0 && ch < PXA_LCDDMA_CHANS))
365 switch (offset & 0xf) {
367 return s->dma_ch[ch].descriptor;
369 return s->dma_ch[ch].source;
371 return s->dma_ch[ch].id;
373 return s->dma_ch[ch].command;
379 return s->dma_ch[0].branch;
381 return s->dma_ch[1].branch;
383 return s->dma_ch[2].branch;
385 return s->dma_ch[3].branch;
387 return s->dma_ch[4].branch;
389 return s->dma_ch[5].branch;
391 return s->dma_ch[6].branch;
408 cpu_abort(cpu_single_env,
409 "%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
415 static void pxa2xx_lcdc_write(void *opaque,
416 target_phys_addr_t offset, uint32_t value)
418 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
424 /* ACK Quick Disable done */
425 if ((s->control[0] & LCCR0_ENB) && !(value & LCCR0_ENB))
426 s->status[0] |= LCSR0_QD;
428 if (!(s->control[0] & LCCR0_LCDT) && (value & LCCR0_LCDT))
429 printf("%s: internal frame buffer unsupported\n", __FUNCTION__);
431 if ((s->control[3] & LCCR3_API) &&
432 (value & LCCR0_ENB) && !(value & LCCR0_LCDT))
433 s->status[0] |= LCSR0_ABC;
435 s->control[0] = value & 0x07ffffff;
436 pxa2xx_lcdc_int_update(s);
438 s->dma_ch[0].up = !!(value & LCCR0_ENB);
439 s->dma_ch[1].up = (s->ovl1c[0] & OVLC1_EN) || (value & LCCR0_SDS);
443 s->control[1] = value;
447 s->control[2] = value;
451 s->control[3] = value & 0xefffffff;
452 s->bpp = LCCR3_BPP(value);
456 s->control[4] = value & 0x83ff81ff;
460 s->control[5] = value & 0x3f3f3f3f;
464 if (!(s->ovl1c[0] & OVLC1_EN) && (value & OVLC1_EN))
465 printf("%s: Overlay 1 not supported\n", __FUNCTION__);
467 s->ovl1c[0] = value & 0x80ffffff;
468 s->dma_ch[1].up = (value & OVLC1_EN) || (s->control[0] & LCCR0_SDS);
472 s->ovl1c[1] = value & 0x000fffff;
476 if (!(s->ovl2c[0] & OVLC1_EN) && (value & OVLC1_EN))
477 printf("%s: Overlay 2 not supported\n", __FUNCTION__);
479 s->ovl2c[0] = value & 0x80ffffff;
480 s->dma_ch[2].up = !!(value & OVLC1_EN);
481 s->dma_ch[3].up = !!(value & OVLC1_EN);
482 s->dma_ch[4].up = !!(value & OVLC1_EN);
486 s->ovl2c[1] = value & 0x007fffff;
490 if (!(s->ccr & CCR_CEN) && (value & CCR_CEN))
491 printf("%s: Hardware cursor unimplemented\n", __FUNCTION__);
493 s->ccr = value & 0x81ffffe7;
494 s->dma_ch[5].up = !!(value & CCR_CEN);
498 s->cmdcr = value & 0xff;
502 s->trgbr = value & 0x00ffffff;
506 s->tcr = value & 0x7fff;
509 case 0x200 ... 0x1000: /* DMA per-channel registers */
510 ch = (offset - 0x200) >> 4;
511 if (!(ch >= 0 && ch < PXA_LCDDMA_CHANS))
514 switch (offset & 0xf) {
516 s->dma_ch[ch].descriptor = value & 0xfffffff0;
525 s->dma_ch[0].branch = value & 0xfffffff3;
528 s->dma_ch[1].branch = value & 0xfffffff3;
531 s->dma_ch[2].branch = value & 0xfffffff3;
534 s->dma_ch[3].branch = value & 0xfffffff3;
537 s->dma_ch[4].branch = value & 0xfffffff3;
540 s->dma_ch[5].branch = value & 0xfffffff3;
543 s->dma_ch[6].branch = value & 0xfffffff3;
547 s->bscntr = value & 0xf;
554 s->status[0] &= ~(value & 0xfff);
555 if (value & LCSR0_BER)
556 s->status[0] &= ~LCSR0_BERCH(7);
560 s->status[1] &= ~(value & 0x3e3f3f);
565 cpu_abort(cpu_single_env,
566 "%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
570 static CPUReadMemoryFunc *pxa2xx_lcdc_readfn[] = {
576 static CPUWriteMemoryFunc *pxa2xx_lcdc_writefn[] = {
582 /* Load new palette for a given DMA channel, convert to internal format */
583 static void pxa2xx_palette_parse(struct pxa2xx_lcdc_s *s, int ch, int bpp)
585 int i, n, format, r, g, b, alpha;
586 uint32_t *dest, *src;
587 s->pal_for = LCCR4_PALFOR(s->control[4]);
605 src = (uint32_t *) s->dma_ch[ch].pbuffer;
606 dest = (uint32_t *) s->dma_ch[ch].palette;
607 alpha = r = g = b = 0;
609 for (i = 0; i < n; i ++) {
611 case 0: /* 16 bpp, no transparency */
613 if (s->control[0] & LCCR0_CMS)
614 r = g = b = *src & 0xff;
616 r = (*src & 0xf800) >> 8;
617 g = (*src & 0x07e0) >> 3;
618 b = (*src & 0x001f) << 3;
621 case 1: /* 16 bpp plus transparency */
622 alpha = *src & (1 << 24);
623 if (s->control[0] & LCCR0_CMS)
624 r = g = b = *src & 0xff;
626 r = (*src & 0xf800) >> 8;
627 g = (*src & 0x07e0) >> 3;
628 b = (*src & 0x001f) << 3;
631 case 2: /* 18 bpp plus transparency */
632 alpha = *src & (1 << 24);
633 if (s->control[0] & LCCR0_CMS)
634 r = g = b = *src & 0xff;
636 r = (*src & 0xf80000) >> 16;
637 g = (*src & 0x00fc00) >> 8;
638 b = (*src & 0x0000f8);
641 case 3: /* 24 bpp plus transparency */
642 alpha = *src & (1 << 24);
643 if (s->control[0] & LCCR0_CMS)
644 r = g = b = *src & 0xff;
646 r = (*src & 0xff0000) >> 16;
647 g = (*src & 0x00ff00) >> 8;
648 b = (*src & 0x0000ff);
652 switch (s->ds->depth) {
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;
674 static void pxa2xx_lcdc_dma0_redraw_horiz(struct pxa2xx_lcdc_s *s,
675 uint8_t *fb, int *miny, int *maxy)
677 int y, src_width, dest_width, dirty[2];
679 ram_addr_t x, addr, new_addr, start, end;
682 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)
696 dest_width = s->xres * s->dest_width;
698 addr = (ram_addr_t) (fb - phys_ram_base);
699 start = addr + s->yres * src_width;
701 dirty[0] = dirty[1] = cpu_physical_memory_get_dirty(start, VGA_DIRTY_FLAG);
702 for (y = 0; y < s->yres; y ++) {
703 new_addr = addr + src_width;
704 for (x = addr + TARGET_PAGE_SIZE; x < new_addr;
705 x += TARGET_PAGE_SIZE) {
706 dirty[1] = cpu_physical_memory_get_dirty(x, VGA_DIRTY_FLAG);
707 dirty[0] |= dirty[1];
709 if (dirty[0] || s->invalidated) {
710 fn((uint32_t *) s->dma_ch[0].palette,
711 dest, src, s->xres, s->dest_width);
727 cpu_physical_memory_reset_dirty(start, end, VGA_DIRTY_FLAG);
730 static void pxa2xx_lcdc_dma0_redraw_vert(struct pxa2xx_lcdc_s *s,
731 uint8_t *fb, int *miny, int *maxy)
733 int y, src_width, dest_width, dirty[2];
735 ram_addr_t x, addr, new_addr, start, end;
738 fn = s->line_fn[s->transp][s->bpp];
743 src_width = (s->xres + 3) & ~3; /* Pad to a 4 pixels multiple */
744 if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp)
746 else if (s->bpp > pxa_lcdc_16bpp)
748 else if (s->bpp > pxa_lcdc_8bpp)
751 dest_width = s->yres * s->dest_width;
752 dest = s->ds->data + dest_width * (s->xres - 1);
754 addr = (ram_addr_t) (fb - phys_ram_base);
755 start = addr + s->yres * src_width;
757 dirty[0] = dirty[1] = cpu_physical_memory_get_dirty(start, VGA_DIRTY_FLAG);
758 for (y = 0; y < s->yres; y ++) {
759 new_addr = addr + src_width;
760 for (x = addr + TARGET_PAGE_SIZE; x < new_addr;
761 x += TARGET_PAGE_SIZE) {
762 dirty[1] = cpu_physical_memory_get_dirty(x, VGA_DIRTY_FLAG);
763 dirty[0] |= dirty[1];
765 if (dirty[0] || s->invalidated) {
766 fn((uint32_t *) s->dma_ch[0].palette,
767 dest, src, s->xres, -dest_width);
779 dest += s->dest_width;
783 cpu_physical_memory_reset_dirty(start, end, VGA_DIRTY_FLAG);
786 static void pxa2xx_lcdc_resize(struct pxa2xx_lcdc_s *s)
789 if (!(s->control[0] & LCCR0_ENB))
792 width = LCCR1_PPL(s->control[1]) + 1;
793 height = LCCR2_LPP(s->control[2]) + 1;
795 if (width != s->xres || height != s->yres) {
797 dpy_resize(s->ds, height, width);
799 dpy_resize(s->ds, width, height);
806 static void pxa2xx_update_display(void *opaque)
808 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
810 target_phys_addr_t fbptr;
813 if (!(s->control[0] & LCCR0_ENB))
816 pxa2xx_descriptor_load(s);
818 pxa2xx_lcdc_resize(s);
821 s->transp = s->dma_ch[2].up || s->dma_ch[3].up;
822 /* Note: With overlay planes the order depends on LCCR0 bit 25. */
823 for (ch = 0; ch < PXA_LCDDMA_CHANS; ch ++)
824 if (s->dma_ch[ch].up) {
825 if (!s->dma_ch[ch].source) {
826 pxa2xx_dma_ber_set(s, ch);
829 fbptr = s->dma_ch[ch].source;
830 if (!(fbptr >= PXA2XX_SDRAM_BASE &&
831 fbptr <= PXA2XX_SDRAM_BASE + phys_ram_size)) {
832 pxa2xx_dma_ber_set(s, ch);
835 fbptr -= PXA2XX_SDRAM_BASE;
836 fb = phys_ram_base + fbptr;
838 if (s->dma_ch[ch].command & LDCMD_PAL) {
839 memcpy(s->dma_ch[ch].pbuffer, fb,
840 MAX(LDCMD_LENGTH(s->dma_ch[ch].command),
841 sizeof(s->dma_ch[ch].pbuffer)));
842 pxa2xx_palette_parse(s, ch, s->bpp);
844 /* Do we need to reparse palette */
845 if (LCCR4_PALFOR(s->control[4]) != s->pal_for)
846 pxa2xx_palette_parse(s, ch, s->bpp);
848 /* ACK frame start */
849 pxa2xx_dma_sof_set(s, ch);
851 s->dma_ch[ch].redraw(s, fb, &miny, &maxy);
854 /* ACK frame completed */
855 pxa2xx_dma_eof_set(s, ch);
859 if (s->control[0] & LCCR0_DIS) {
860 /* ACK last frame completed */
861 s->control[0] &= ~LCCR0_ENB;
862 s->status[0] |= LCSR0_LDD;
866 dpy_update(s->ds, miny, 0, maxy, s->xres);
868 dpy_update(s->ds, 0, miny, s->xres, maxy);
869 pxa2xx_lcdc_int_update(s);
871 qemu_irq_raise(s->vsync_cb);
874 static void pxa2xx_invalidate_display(void *opaque)
876 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
880 static void pxa2xx_screen_dump(void *opaque, const char *filename)
885 static void pxa2xx_lcdc_orientation(void *opaque, int angle)
887 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
890 s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_vert;
892 s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_horiz;
895 s->orientation = angle;
896 s->xres = s->yres = -1;
897 pxa2xx_lcdc_resize(s);
900 static void pxa2xx_lcdc_save(QEMUFile *f, void *opaque)
902 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
905 qemu_put_be32(f, s->irqlevel);
906 qemu_put_be32(f, s->transp);
908 for (i = 0; i < 6; i ++)
909 qemu_put_be32s(f, &s->control[i]);
910 for (i = 0; i < 2; i ++)
911 qemu_put_be32s(f, &s->status[i]);
912 for (i = 0; i < 2; i ++)
913 qemu_put_be32s(f, &s->ovl1c[i]);
914 for (i = 0; i < 2; i ++)
915 qemu_put_be32s(f, &s->ovl2c[i]);
916 qemu_put_be32s(f, &s->ccr);
917 qemu_put_be32s(f, &s->cmdcr);
918 qemu_put_be32s(f, &s->trgbr);
919 qemu_put_be32s(f, &s->tcr);
920 qemu_put_be32s(f, &s->liidr);
921 qemu_put_8s(f, &s->bscntr);
923 for (i = 0; i < 7; i ++) {
924 qemu_put_betl(f, s->dma_ch[i].branch);
925 qemu_put_byte(f, s->dma_ch[i].up);
926 qemu_put_buffer(f, s->dma_ch[i].pbuffer, sizeof(s->dma_ch[i].pbuffer));
928 qemu_put_betl(f, s->dma_ch[i].descriptor);
929 qemu_put_betl(f, s->dma_ch[i].source);
930 qemu_put_be32s(f, &s->dma_ch[i].id);
931 qemu_put_be32s(f, &s->dma_ch[i].command);
935 static int pxa2xx_lcdc_load(QEMUFile *f, void *opaque, int version_id)
937 struct pxa2xx_lcdc_s *s = (struct pxa2xx_lcdc_s *) opaque;
940 s->irqlevel = qemu_get_be32(f);
941 s->transp = qemu_get_be32(f);
943 for (i = 0; i < 6; i ++)
944 qemu_get_be32s(f, &s->control[i]);
945 for (i = 0; i < 2; i ++)
946 qemu_get_be32s(f, &s->status[i]);
947 for (i = 0; i < 2; i ++)
948 qemu_get_be32s(f, &s->ovl1c[i]);
949 for (i = 0; i < 2; i ++)
950 qemu_get_be32s(f, &s->ovl2c[i]);
951 qemu_get_be32s(f, &s->ccr);
952 qemu_get_be32s(f, &s->cmdcr);
953 qemu_get_be32s(f, &s->trgbr);
954 qemu_get_be32s(f, &s->tcr);
955 qemu_get_be32s(f, &s->liidr);
956 qemu_get_8s(f, &s->bscntr);
958 for (i = 0; i < 7; i ++) {
959 s->dma_ch[i].branch = qemu_get_betl(f);
960 s->dma_ch[i].up = qemu_get_byte(f);
961 qemu_get_buffer(f, s->dma_ch[i].pbuffer, sizeof(s->dma_ch[i].pbuffer));
963 s->dma_ch[i].descriptor = qemu_get_betl(f);
964 s->dma_ch[i].source = qemu_get_betl(f);
965 qemu_get_be32s(f, &s->dma_ch[i].id);
966 qemu_get_be32s(f, &s->dma_ch[i].command);
969 s->bpp = LCCR3_BPP(s->control[3]);
970 s->xres = s->yres = s->pal_for = -1;
976 #include "pxa2xx_template.h"
978 #include "pxa2xx_template.h"
980 #include "pxa2xx_template.h"
982 #include "pxa2xx_template.h"
984 #include "pxa2xx_template.h"
986 struct pxa2xx_lcdc_s *pxa2xx_lcdc_init(target_phys_addr_t base, qemu_irq irq,
990 struct pxa2xx_lcdc_s *s;
992 s = (struct pxa2xx_lcdc_s *) qemu_mallocz(sizeof(struct pxa2xx_lcdc_s));
998 pxa2xx_lcdc_orientation(s, graphic_rotate);
1000 iomemtype = cpu_register_io_memory(0, pxa2xx_lcdc_readfn,
1001 pxa2xx_lcdc_writefn, s);
1002 cpu_register_physical_memory(base, 0x00100000, iomemtype);
1004 graphic_console_init(ds, pxa2xx_update_display,
1005 pxa2xx_invalidate_display, pxa2xx_screen_dump, s);
1007 switch (s->ds->depth) {
1012 s->line_fn[0] = pxa2xx_draw_fn_8;
1013 s->line_fn[1] = pxa2xx_draw_fn_8t;
1017 s->line_fn[0] = pxa2xx_draw_fn_15;
1018 s->line_fn[1] = pxa2xx_draw_fn_15t;
1022 s->line_fn[0] = pxa2xx_draw_fn_16;
1023 s->line_fn[1] = pxa2xx_draw_fn_16t;
1027 s->line_fn[0] = pxa2xx_draw_fn_24;
1028 s->line_fn[1] = pxa2xx_draw_fn_24t;
1032 s->line_fn[0] = pxa2xx_draw_fn_32;
1033 s->line_fn[1] = pxa2xx_draw_fn_32t;
1037 fprintf(stderr, "%s: Bad color depth\n", __FUNCTION__);
1041 register_savevm("pxa2xx_lcdc", 0, 0,
1042 pxa2xx_lcdc_save, pxa2xx_lcdc_load, s);
1047 void pxa2xx_lcd_vsync_notifier(struct pxa2xx_lcdc_s *s, qemu_irq handler)
1049 s->vsync_cb = handler;