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. */
17 typedef void (*drawfn
)(uint32_t *, uint8_t *, const uint8_t *, int, int);
19 struct pxa2xx_lcdc_s
{
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
;
327 return s
->control
[0];
329 return s
->control
[1];
331 return s
->control
[2];
333 return s
->control
[3];
335 return s
->control
[4];
337 return s
->control
[5];
359 case 0x200 ... 0x1000: /* DMA per-channel registers */
360 ch
= (offset
- 0x200) >> 4;
361 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
364 switch (offset
& 0xf) {
366 return s
->dma_ch
[ch
].descriptor
;
368 return s
->dma_ch
[ch
].source
;
370 return s
->dma_ch
[ch
].id
;
372 return s
->dma_ch
[ch
].command
;
378 return s
->dma_ch
[0].branch
;
380 return s
->dma_ch
[1].branch
;
382 return s
->dma_ch
[2].branch
;
384 return s
->dma_ch
[3].branch
;
386 return s
->dma_ch
[4].branch
;
388 return s
->dma_ch
[5].branch
;
390 return s
->dma_ch
[6].branch
;
407 cpu_abort(cpu_single_env
,
408 "%s: Bad offset " REG_FMT
"\n", __FUNCTION__
, offset
);
414 static void pxa2xx_lcdc_write(void *opaque
,
415 target_phys_addr_t offset
, uint32_t value
)
417 struct pxa2xx_lcdc_s
*s
= (struct pxa2xx_lcdc_s
*) opaque
;
422 /* ACK Quick Disable done */
423 if ((s
->control
[0] & LCCR0_ENB
) && !(value
& LCCR0_ENB
))
424 s
->status
[0] |= LCSR0_QD
;
426 if (!(s
->control
[0] & LCCR0_LCDT
) && (value
& LCCR0_LCDT
))
427 printf("%s: internal frame buffer unsupported\n", __FUNCTION__
);
429 if ((s
->control
[3] & LCCR3_API
) &&
430 (value
& LCCR0_ENB
) && !(value
& LCCR0_LCDT
))
431 s
->status
[0] |= LCSR0_ABC
;
433 s
->control
[0] = value
& 0x07ffffff;
434 pxa2xx_lcdc_int_update(s
);
436 s
->dma_ch
[0].up
= !!(value
& LCCR0_ENB
);
437 s
->dma_ch
[1].up
= (s
->ovl1c
[0] & OVLC1_EN
) || (value
& LCCR0_SDS
);
441 s
->control
[1] = value
;
445 s
->control
[2] = value
;
449 s
->control
[3] = value
& 0xefffffff;
450 s
->bpp
= LCCR3_BPP(value
);
454 s
->control
[4] = value
& 0x83ff81ff;
458 s
->control
[5] = value
& 0x3f3f3f3f;
462 if (!(s
->ovl1c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
))
463 printf("%s: Overlay 1 not supported\n", __FUNCTION__
);
465 s
->ovl1c
[0] = value
& 0x80ffffff;
466 s
->dma_ch
[1].up
= (value
& OVLC1_EN
) || (s
->control
[0] & LCCR0_SDS
);
470 s
->ovl1c
[1] = value
& 0x000fffff;
474 if (!(s
->ovl2c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
))
475 printf("%s: Overlay 2 not supported\n", __FUNCTION__
);
477 s
->ovl2c
[0] = value
& 0x80ffffff;
478 s
->dma_ch
[2].up
= !!(value
& OVLC1_EN
);
479 s
->dma_ch
[3].up
= !!(value
& OVLC1_EN
);
480 s
->dma_ch
[4].up
= !!(value
& OVLC1_EN
);
484 s
->ovl2c
[1] = value
& 0x007fffff;
488 if (!(s
->ccr
& CCR_CEN
) && (value
& CCR_CEN
))
489 printf("%s: Hardware cursor unimplemented\n", __FUNCTION__
);
491 s
->ccr
= value
& 0x81ffffe7;
492 s
->dma_ch
[5].up
= !!(value
& CCR_CEN
);
496 s
->cmdcr
= value
& 0xff;
500 s
->trgbr
= value
& 0x00ffffff;
504 s
->tcr
= value
& 0x7fff;
507 case 0x200 ... 0x1000: /* DMA per-channel registers */
508 ch
= (offset
- 0x200) >> 4;
509 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
512 switch (offset
& 0xf) {
514 s
->dma_ch
[ch
].descriptor
= value
& 0xfffffff0;
523 s
->dma_ch
[0].branch
= value
& 0xfffffff3;
526 s
->dma_ch
[1].branch
= value
& 0xfffffff3;
529 s
->dma_ch
[2].branch
= value
& 0xfffffff3;
532 s
->dma_ch
[3].branch
= value
& 0xfffffff3;
535 s
->dma_ch
[4].branch
= value
& 0xfffffff3;
538 s
->dma_ch
[5].branch
= value
& 0xfffffff3;
541 s
->dma_ch
[6].branch
= value
& 0xfffffff3;
545 s
->bscntr
= value
& 0xf;
552 s
->status
[0] &= ~(value
& 0xfff);
553 if (value
& LCSR0_BER
)
554 s
->status
[0] &= ~LCSR0_BERCH(7);
558 s
->status
[1] &= ~(value
& 0x3e3f3f);
563 cpu_abort(cpu_single_env
,
564 "%s: Bad offset " REG_FMT
"\n", __FUNCTION__
, offset
);
568 static CPUReadMemoryFunc
*pxa2xx_lcdc_readfn
[] = {
574 static CPUWriteMemoryFunc
*pxa2xx_lcdc_writefn
[] = {
580 /* Load new palette for a given DMA channel, convert to internal format */
581 static void pxa2xx_palette_parse(struct pxa2xx_lcdc_s
*s
, int ch
, int bpp
)
583 int i
, n
, format
, r
, g
, b
, alpha
;
584 uint32_t *dest
, *src
;
585 s
->pal_for
= LCCR4_PALFOR(s
->control
[4]);
603 src
= (uint32_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
= *src
& 0xff;
614 r
= (*src
& 0xf800) >> 8;
615 g
= (*src
& 0x07e0) >> 3;
616 b
= (*src
& 0x001f) << 3;
619 case 1: /* 16 bpp plus transparency */
620 alpha
= *src
& (1 << 24);
621 if (s
->control
[0] & LCCR0_CMS
)
622 r
= g
= b
= *src
& 0xff;
624 r
= (*src
& 0xf800) >> 8;
625 g
= (*src
& 0x07e0) >> 3;
626 b
= (*src
& 0x001f) << 3;
629 case 2: /* 18 bpp plus transparency */
630 alpha
= *src
& (1 << 24);
631 if (s
->control
[0] & LCCR0_CMS
)
632 r
= g
= b
= *src
& 0xff;
634 r
= (*src
& 0xf80000) >> 16;
635 g
= (*src
& 0x00fc00) >> 8;
636 b
= (*src
& 0x0000f8);
639 case 3: /* 24 bpp plus transparency */
640 alpha
= *src
& (1 << 24);
641 if (s
->control
[0] & LCCR0_CMS
)
642 r
= g
= b
= *src
& 0xff;
644 r
= (*src
& 0xff0000) >> 16;
645 g
= (*src
& 0x00ff00) >> 8;
646 b
= (*src
& 0x0000ff);
650 switch (ds_get_bits_per_pixel(s
->ds
)) {
652 *dest
= rgb_to_pixel8(r
, g
, b
) | alpha
;
655 *dest
= rgb_to_pixel15(r
, g
, b
) | alpha
;
658 *dest
= rgb_to_pixel16(r
, g
, b
) | alpha
;
661 *dest
= rgb_to_pixel24(r
, g
, b
) | alpha
;
664 *dest
= rgb_to_pixel32(r
, g
, b
) | alpha
;
672 static void pxa2xx_lcdc_dma0_redraw_horiz(struct pxa2xx_lcdc_s
*s
,
673 uint8_t *fb
, int *miny
, int *maxy
)
675 int y
, src_width
, dest_width
, dirty
[2];
677 ram_addr_t x
, addr
, new_addr
, start
, end
;
680 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
685 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
686 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
688 else if (s
->bpp
> pxa_lcdc_16bpp
)
690 else if (s
->bpp
> pxa_lcdc_8bpp
)
693 dest
= ds_get_data(s
->ds
);
694 dest_width
= s
->xres
* s
->dest_width
;
696 addr
= (ram_addr_t
) (fb
- phys_ram_base
);
697 start
= addr
+ s
->yres
* src_width
;
699 dirty
[0] = dirty
[1] = cpu_physical_memory_get_dirty(start
, VGA_DIRTY_FLAG
);
700 for (y
= 0; y
< s
->yres
; y
++) {
701 new_addr
= addr
+ src_width
;
702 for (x
= addr
+ TARGET_PAGE_SIZE
; x
< new_addr
;
703 x
+= TARGET_PAGE_SIZE
) {
704 dirty
[1] = cpu_physical_memory_get_dirty(x
, VGA_DIRTY_FLAG
);
705 dirty
[0] |= dirty
[1];
707 if (dirty
[0] || s
->invalidated
) {
708 fn((uint32_t *) s
->dma_ch
[0].palette
,
709 dest
, src
, s
->xres
, s
->dest_width
);
725 cpu_physical_memory_reset_dirty(start
, end
, VGA_DIRTY_FLAG
);
728 static void pxa2xx_lcdc_dma0_redraw_vert(struct pxa2xx_lcdc_s
*s
,
729 uint8_t *fb
, int *miny
, int *maxy
)
731 int y
, src_width
, dest_width
, dirty
[2];
733 ram_addr_t x
, addr
, new_addr
, start
, end
;
736 fn
= s
->line_fn
[s
->transp
][s
->bpp
];
741 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
742 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
744 else if (s
->bpp
> pxa_lcdc_16bpp
)
746 else if (s
->bpp
> pxa_lcdc_8bpp
)
749 dest_width
= s
->yres
* s
->dest_width
;
750 dest
= ds_get_data(s
->ds
) + dest_width
* (s
->xres
- 1);
752 addr
= (ram_addr_t
) (fb
- phys_ram_base
);
753 start
= addr
+ s
->yres
* src_width
;
755 dirty
[0] = dirty
[1] = cpu_physical_memory_get_dirty(start
, VGA_DIRTY_FLAG
);
756 for (y
= 0; y
< s
->yres
; y
++) {
757 new_addr
= addr
+ src_width
;
758 for (x
= addr
+ TARGET_PAGE_SIZE
; x
< new_addr
;
759 x
+= TARGET_PAGE_SIZE
) {
760 dirty
[1] = cpu_physical_memory_get_dirty(x
, VGA_DIRTY_FLAG
);
761 dirty
[0] |= dirty
[1];
763 if (dirty
[0] || s
->invalidated
) {
764 fn((uint32_t *) s
->dma_ch
[0].palette
,
765 dest
, src
, s
->xres
, -dest_width
);
777 dest
+= s
->dest_width
;
781 cpu_physical_memory_reset_dirty(start
, end
, VGA_DIRTY_FLAG
);
784 static void pxa2xx_lcdc_resize(struct pxa2xx_lcdc_s
*s
)
787 if (!(s
->control
[0] & LCCR0_ENB
))
790 width
= LCCR1_PPL(s
->control
[1]) + 1;
791 height
= LCCR2_LPP(s
->control
[2]) + 1;
793 if (width
!= s
->xres
|| height
!= s
->yres
) {
795 qemu_console_resize(s
->console
, height
, width
);
797 qemu_console_resize(s
->console
, width
, height
);
804 static void pxa2xx_update_display(void *opaque
)
806 struct pxa2xx_lcdc_s
*s
= (struct pxa2xx_lcdc_s
*) opaque
;
808 target_phys_addr_t fbptr
;
811 if (!(s
->control
[0] & LCCR0_ENB
))
814 pxa2xx_descriptor_load(s
);
816 pxa2xx_lcdc_resize(s
);
819 s
->transp
= s
->dma_ch
[2].up
|| s
->dma_ch
[3].up
;
820 /* Note: With overlay planes the order depends on LCCR0 bit 25. */
821 for (ch
= 0; ch
< PXA_LCDDMA_CHANS
; ch
++)
822 if (s
->dma_ch
[ch
].up
) {
823 if (!s
->dma_ch
[ch
].source
) {
824 pxa2xx_dma_ber_set(s
, ch
);
827 fbptr
= s
->dma_ch
[ch
].source
;
828 if (!(fbptr
>= PXA2XX_SDRAM_BASE
&&
829 fbptr
<= PXA2XX_SDRAM_BASE
+ phys_ram_size
)) {
830 pxa2xx_dma_ber_set(s
, ch
);
833 fbptr
-= PXA2XX_SDRAM_BASE
;
834 fb
= phys_ram_base
+ fbptr
;
836 if (s
->dma_ch
[ch
].command
& LDCMD_PAL
) {
837 memcpy(s
->dma_ch
[ch
].pbuffer
, fb
,
838 MAX(LDCMD_LENGTH(s
->dma_ch
[ch
].command
),
839 sizeof(s
->dma_ch
[ch
].pbuffer
)));
840 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
842 /* Do we need to reparse palette */
843 if (LCCR4_PALFOR(s
->control
[4]) != s
->pal_for
)
844 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
846 /* ACK frame start */
847 pxa2xx_dma_sof_set(s
, ch
);
849 s
->dma_ch
[ch
].redraw(s
, fb
, &miny
, &maxy
);
852 /* ACK frame completed */
853 pxa2xx_dma_eof_set(s
, ch
);
857 if (s
->control
[0] & LCCR0_DIS
) {
858 /* ACK last frame completed */
859 s
->control
[0] &= ~LCCR0_ENB
;
860 s
->status
[0] |= LCSR0_LDD
;
864 dpy_update(s
->ds
, miny
, 0, maxy
, s
->xres
);
866 dpy_update(s
->ds
, 0, miny
, s
->xres
, maxy
);
867 pxa2xx_lcdc_int_update(s
);
869 qemu_irq_raise(s
->vsync_cb
);
872 static void pxa2xx_invalidate_display(void *opaque
)
874 struct pxa2xx_lcdc_s
*s
= (struct pxa2xx_lcdc_s
*) opaque
;
878 static void pxa2xx_screen_dump(void *opaque
, const char *filename
)
883 static void pxa2xx_lcdc_orientation(void *opaque
, int angle
)
885 struct pxa2xx_lcdc_s
*s
= (struct pxa2xx_lcdc_s
*) opaque
;
888 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_vert
;
890 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_horiz
;
893 s
->orientation
= angle
;
894 s
->xres
= s
->yres
= -1;
895 pxa2xx_lcdc_resize(s
);
898 static void pxa2xx_lcdc_save(QEMUFile
*f
, void *opaque
)
900 struct pxa2xx_lcdc_s
*s
= (struct pxa2xx_lcdc_s
*) opaque
;
903 qemu_put_be32(f
, s
->irqlevel
);
904 qemu_put_be32(f
, s
->transp
);
906 for (i
= 0; i
< 6; i
++)
907 qemu_put_be32s(f
, &s
->control
[i
]);
908 for (i
= 0; i
< 2; i
++)
909 qemu_put_be32s(f
, &s
->status
[i
]);
910 for (i
= 0; i
< 2; i
++)
911 qemu_put_be32s(f
, &s
->ovl1c
[i
]);
912 for (i
= 0; i
< 2; i
++)
913 qemu_put_be32s(f
, &s
->ovl2c
[i
]);
914 qemu_put_be32s(f
, &s
->ccr
);
915 qemu_put_be32s(f
, &s
->cmdcr
);
916 qemu_put_be32s(f
, &s
->trgbr
);
917 qemu_put_be32s(f
, &s
->tcr
);
918 qemu_put_be32s(f
, &s
->liidr
);
919 qemu_put_8s(f
, &s
->bscntr
);
921 for (i
= 0; i
< 7; i
++) {
922 qemu_put_betl(f
, s
->dma_ch
[i
].branch
);
923 qemu_put_byte(f
, s
->dma_ch
[i
].up
);
924 qemu_put_buffer(f
, s
->dma_ch
[i
].pbuffer
, sizeof(s
->dma_ch
[i
].pbuffer
));
926 qemu_put_betl(f
, s
->dma_ch
[i
].descriptor
);
927 qemu_put_betl(f
, s
->dma_ch
[i
].source
);
928 qemu_put_be32s(f
, &s
->dma_ch
[i
].id
);
929 qemu_put_be32s(f
, &s
->dma_ch
[i
].command
);
933 static int pxa2xx_lcdc_load(QEMUFile
*f
, void *opaque
, int version_id
)
935 struct pxa2xx_lcdc_s
*s
= (struct pxa2xx_lcdc_s
*) opaque
;
938 s
->irqlevel
= qemu_get_be32(f
);
939 s
->transp
= qemu_get_be32(f
);
941 for (i
= 0; i
< 6; i
++)
942 qemu_get_be32s(f
, &s
->control
[i
]);
943 for (i
= 0; i
< 2; i
++)
944 qemu_get_be32s(f
, &s
->status
[i
]);
945 for (i
= 0; i
< 2; i
++)
946 qemu_get_be32s(f
, &s
->ovl1c
[i
]);
947 for (i
= 0; i
< 2; i
++)
948 qemu_get_be32s(f
, &s
->ovl2c
[i
]);
949 qemu_get_be32s(f
, &s
->ccr
);
950 qemu_get_be32s(f
, &s
->cmdcr
);
951 qemu_get_be32s(f
, &s
->trgbr
);
952 qemu_get_be32s(f
, &s
->tcr
);
953 qemu_get_be32s(f
, &s
->liidr
);
954 qemu_get_8s(f
, &s
->bscntr
);
956 for (i
= 0; i
< 7; i
++) {
957 s
->dma_ch
[i
].branch
= qemu_get_betl(f
);
958 s
->dma_ch
[i
].up
= qemu_get_byte(f
);
959 qemu_get_buffer(f
, s
->dma_ch
[i
].pbuffer
, sizeof(s
->dma_ch
[i
].pbuffer
));
961 s
->dma_ch
[i
].descriptor
= qemu_get_betl(f
);
962 s
->dma_ch
[i
].source
= qemu_get_betl(f
);
963 qemu_get_be32s(f
, &s
->dma_ch
[i
].id
);
964 qemu_get_be32s(f
, &s
->dma_ch
[i
].command
);
967 s
->bpp
= LCCR3_BPP(s
->control
[3]);
968 s
->xres
= s
->yres
= s
->pal_for
= -1;
974 #include "pxa2xx_template.h"
976 #include "pxa2xx_template.h"
978 #include "pxa2xx_template.h"
980 #include "pxa2xx_template.h"
982 #include "pxa2xx_template.h"
984 struct pxa2xx_lcdc_s
*pxa2xx_lcdc_init(target_phys_addr_t base
, qemu_irq irq
,
988 struct pxa2xx_lcdc_s
*s
;
990 s
= (struct pxa2xx_lcdc_s
*) qemu_mallocz(sizeof(struct pxa2xx_lcdc_s
));
995 pxa2xx_lcdc_orientation(s
, graphic_rotate
);
997 iomemtype
= cpu_register_io_memory(0, pxa2xx_lcdc_readfn
,
998 pxa2xx_lcdc_writefn
, s
);
999 cpu_register_physical_memory(base
, 0x00100000, iomemtype
);
1001 s
->console
= graphic_console_init(ds
, pxa2xx_update_display
,
1002 pxa2xx_invalidate_display
,
1003 pxa2xx_screen_dump
, NULL
, s
);
1005 switch (ds_get_bits_per_pixel(s
->ds
)) {
1010 s
->line_fn
[0] = pxa2xx_draw_fn_8
;
1011 s
->line_fn
[1] = pxa2xx_draw_fn_8t
;
1015 s
->line_fn
[0] = pxa2xx_draw_fn_15
;
1016 s
->line_fn
[1] = pxa2xx_draw_fn_15t
;
1020 s
->line_fn
[0] = pxa2xx_draw_fn_16
;
1021 s
->line_fn
[1] = pxa2xx_draw_fn_16t
;
1025 s
->line_fn
[0] = pxa2xx_draw_fn_24
;
1026 s
->line_fn
[1] = pxa2xx_draw_fn_24t
;
1030 s
->line_fn
[0] = pxa2xx_draw_fn_32
;
1031 s
->line_fn
[1] = pxa2xx_draw_fn_32t
;
1035 fprintf(stderr
, "%s: Bad color depth\n", __FUNCTION__
);
1039 register_savevm("pxa2xx_lcdc", 0, 0,
1040 pxa2xx_lcdc_save
, pxa2xx_lcdc_load
, s
);
1045 void pxa2xx_lcd_vsync_notifier(struct pxa2xx_lcdc_s
*s
, qemu_irq handler
)
1047 s
->vsync_cb
= handler
;