Statistics
| Branch: | Revision:

root / hw / pxa2xx_lcd.c @ ad2d30f7

History | View | Annotate | Download (26.4 kB)

1 a171fe39 balrog
/*
2 a171fe39 balrog
 * Intel XScale PXA255/270 LCDC emulation.
3 a171fe39 balrog
 *
4 a171fe39 balrog
 * Copyright (c) 2006 Openedhand Ltd.
5 a171fe39 balrog
 * Written by Andrzej Zaborowski <balrog@zabor.org>
6 a171fe39 balrog
 *
7 a171fe39 balrog
 * This code is licensed under the GPLv2.
8 a171fe39 balrog
 */
9 a171fe39 balrog
10 87ecb68b pbrook
#include "hw.h"
11 87ecb68b pbrook
#include "console.h"
12 87ecb68b pbrook
#include "pxa.h"
13 e27f01ef balrog
#include "pixel_ops.h"
14 87ecb68b pbrook
/* FIXME: For graphic_rotate. Should probably be done in common code.  */
15 87ecb68b pbrook
#include "sysemu.h"
16 714fa308 pbrook
#include "framebuffer.h"
17 a171fe39 balrog
18 2b7251e0 Juan Quintela
struct DMAChannel {
19 2b7251e0 Juan Quintela
    target_phys_addr_t branch;
20 46995409 Juan Quintela
    uint8_t up;
21 2b7251e0 Juan Quintela
    uint8_t palette[1024];
22 2b7251e0 Juan Quintela
    uint8_t pbuffer[1024];
23 2b7251e0 Juan Quintela
    void (*redraw)(PXA2xxLCDState *s, target_phys_addr_t addr,
24 2b7251e0 Juan Quintela
                   int *miny, int *maxy);
25 2b7251e0 Juan Quintela
26 2b7251e0 Juan Quintela
    target_phys_addr_t descriptor;
27 2b7251e0 Juan Quintela
    target_phys_addr_t source;
28 2b7251e0 Juan Quintela
    uint32_t id;
29 2b7251e0 Juan Quintela
    uint32_t command;
30 2b7251e0 Juan Quintela
};
31 2b7251e0 Juan Quintela
32 bc24a225 Paul Brook
struct PXA2xxLCDState {
33 a171fe39 balrog
    qemu_irq irq;
34 a171fe39 balrog
    int irqlevel;
35 a171fe39 balrog
36 a171fe39 balrog
    int invalidated;
37 a171fe39 balrog
    DisplayState *ds;
38 a171fe39 balrog
    drawfn *line_fn[2];
39 a171fe39 balrog
    int dest_width;
40 a171fe39 balrog
    int xres, yres;
41 a171fe39 balrog
    int pal_for;
42 a171fe39 balrog
    int transp;
43 a171fe39 balrog
    enum {
44 a171fe39 balrog
        pxa_lcdc_2bpp = 1,
45 a171fe39 balrog
        pxa_lcdc_4bpp = 2,
46 a171fe39 balrog
        pxa_lcdc_8bpp = 3,
47 a171fe39 balrog
        pxa_lcdc_16bpp = 4,
48 a171fe39 balrog
        pxa_lcdc_18bpp = 5,
49 a171fe39 balrog
        pxa_lcdc_18pbpp = 6,
50 a171fe39 balrog
        pxa_lcdc_19bpp = 7,
51 a171fe39 balrog
        pxa_lcdc_19pbpp = 8,
52 a171fe39 balrog
        pxa_lcdc_24bpp = 9,
53 a171fe39 balrog
        pxa_lcdc_25bpp = 10,
54 a171fe39 balrog
    } bpp;
55 a171fe39 balrog
56 a171fe39 balrog
    uint32_t control[6];
57 a171fe39 balrog
    uint32_t status[2];
58 a171fe39 balrog
    uint32_t ovl1c[2];
59 a171fe39 balrog
    uint32_t ovl2c[2];
60 a171fe39 balrog
    uint32_t ccr;
61 a171fe39 balrog
    uint32_t cmdcr;
62 a171fe39 balrog
    uint32_t trgbr;
63 a171fe39 balrog
    uint32_t tcr;
64 a171fe39 balrog
    uint32_t liidr;
65 a171fe39 balrog
    uint8_t bscntr;
66 a171fe39 balrog
67 2b7251e0 Juan Quintela
    struct DMAChannel dma_ch[7];
68 a171fe39 balrog
69 38641a52 balrog
    qemu_irq vsync_cb;
70 a171fe39 balrog
    int orientation;
71 a171fe39 balrog
};
72 a171fe39 balrog
73 bc24a225 Paul Brook
typedef struct __attribute__ ((__packed__)) {
74 a171fe39 balrog
    uint32_t fdaddr;
75 a171fe39 balrog
    uint32_t fsaddr;
76 a171fe39 balrog
    uint32_t fidr;
77 a171fe39 balrog
    uint32_t ldcmd;
78 bc24a225 Paul Brook
} PXAFrameDescriptor;
79 a171fe39 balrog
80 a171fe39 balrog
#define LCCR0        0x000        /* LCD Controller Control register 0 */
81 a171fe39 balrog
#define LCCR1        0x004        /* LCD Controller Control register 1 */
82 a171fe39 balrog
#define LCCR2        0x008        /* LCD Controller Control register 2 */
83 a171fe39 balrog
#define LCCR3        0x00c        /* LCD Controller Control register 3 */
84 a171fe39 balrog
#define LCCR4        0x010        /* LCD Controller Control register 4 */
85 a171fe39 balrog
#define LCCR5        0x014        /* LCD Controller Control register 5 */
86 a171fe39 balrog
87 a171fe39 balrog
#define FBR0        0x020        /* DMA Channel 0 Frame Branch register */
88 a171fe39 balrog
#define FBR1        0x024        /* DMA Channel 1 Frame Branch register */
89 a171fe39 balrog
#define FBR2        0x028        /* DMA Channel 2 Frame Branch register */
90 a171fe39 balrog
#define FBR3        0x02c        /* DMA Channel 3 Frame Branch register */
91 a171fe39 balrog
#define FBR4        0x030        /* DMA Channel 4 Frame Branch register */
92 a171fe39 balrog
#define FBR5        0x110        /* DMA Channel 5 Frame Branch register */
93 a171fe39 balrog
#define FBR6        0x114        /* DMA Channel 6 Frame Branch register */
94 a171fe39 balrog
95 a171fe39 balrog
#define LCSR1        0x034        /* LCD Controller Status register 1 */
96 a171fe39 balrog
#define LCSR0        0x038        /* LCD Controller Status register 0 */
97 a171fe39 balrog
#define LIIDR        0x03c        /* LCD Controller Interrupt ID register */
98 a171fe39 balrog
99 a171fe39 balrog
#define TRGBR        0x040        /* TMED RGB Seed register */
100 a171fe39 balrog
#define TCR        0x044        /* TMED Control register */
101 a171fe39 balrog
102 a171fe39 balrog
#define OVL1C1        0x050        /* Overlay 1 Control register 1 */
103 a171fe39 balrog
#define OVL1C2        0x060        /* Overlay 1 Control register 2 */
104 a171fe39 balrog
#define OVL2C1        0x070        /* Overlay 2 Control register 1 */
105 a171fe39 balrog
#define OVL2C2        0x080        /* Overlay 2 Control register 2 */
106 a171fe39 balrog
#define CCR        0x090        /* Cursor Control register */
107 a171fe39 balrog
108 a171fe39 balrog
#define CMDCR        0x100        /* Command Control register */
109 a171fe39 balrog
#define PRSR        0x104        /* Panel Read Status register */
110 a171fe39 balrog
111 a171fe39 balrog
#define PXA_LCDDMA_CHANS        7
112 a171fe39 balrog
#define DMA_FDADR                0x00        /* Frame Descriptor Address register */
113 a171fe39 balrog
#define DMA_FSADR                0x04        /* Frame Source Address register */
114 a171fe39 balrog
#define DMA_FIDR                0x08        /* Frame ID register */
115 a171fe39 balrog
#define DMA_LDCMD                0x0c        /* Command register */
116 a171fe39 balrog
117 a171fe39 balrog
/* LCD Buffer Strength Control register */
118 a171fe39 balrog
#define BSCNTR        0x04000054
119 a171fe39 balrog
120 a171fe39 balrog
/* Bitfield masks */
121 a171fe39 balrog
#define LCCR0_ENB        (1 << 0)
122 a171fe39 balrog
#define LCCR0_CMS        (1 << 1)
123 a171fe39 balrog
#define LCCR0_SDS        (1 << 2)
124 a171fe39 balrog
#define LCCR0_LDM        (1 << 3)
125 a171fe39 balrog
#define LCCR0_SOFM0        (1 << 4)
126 a171fe39 balrog
#define LCCR0_IUM        (1 << 5)
127 a171fe39 balrog
#define LCCR0_EOFM0        (1 << 6)
128 a171fe39 balrog
#define LCCR0_PAS        (1 << 7)
129 a171fe39 balrog
#define LCCR0_DPD        (1 << 9)
130 a171fe39 balrog
#define LCCR0_DIS        (1 << 10)
131 a171fe39 balrog
#define LCCR0_QDM        (1 << 11)
132 a171fe39 balrog
#define LCCR0_PDD        (0xff << 12)
133 a171fe39 balrog
#define LCCR0_BSM0        (1 << 20)
134 a171fe39 balrog
#define LCCR0_OUM        (1 << 21)
135 a171fe39 balrog
#define LCCR0_LCDT        (1 << 22)
136 a171fe39 balrog
#define LCCR0_RDSTM        (1 << 23)
137 a171fe39 balrog
#define LCCR0_CMDIM        (1 << 24)
138 a171fe39 balrog
#define LCCR0_OUC        (1 << 25)
139 a171fe39 balrog
#define LCCR0_LDDALT        (1 << 26)
140 a171fe39 balrog
#define LCCR1_PPL(x)        ((x) & 0x3ff)
141 a171fe39 balrog
#define LCCR2_LPP(x)        ((x) & 0x3ff)
142 a171fe39 balrog
#define LCCR3_API        (15 << 16)
143 a171fe39 balrog
#define LCCR3_BPP(x)        ((((x) >> 24) & 7) | (((x) >> 26) & 8))
144 a171fe39 balrog
#define LCCR3_PDFOR(x)        (((x) >> 30) & 3)
145 a171fe39 balrog
#define LCCR4_K1(x)        (((x) >> 0) & 7)
146 a171fe39 balrog
#define LCCR4_K2(x)        (((x) >> 3) & 7)
147 a171fe39 balrog
#define LCCR4_K3(x)        (((x) >> 6) & 7)
148 a171fe39 balrog
#define LCCR4_PALFOR(x)        (((x) >> 15) & 3)
149 a171fe39 balrog
#define LCCR5_SOFM(ch)        (1 << (ch - 1))
150 a171fe39 balrog
#define LCCR5_EOFM(ch)        (1 << (ch + 7))
151 a171fe39 balrog
#define LCCR5_BSM(ch)        (1 << (ch + 15))
152 a171fe39 balrog
#define LCCR5_IUM(ch)        (1 << (ch + 23))
153 a171fe39 balrog
#define OVLC1_EN        (1 << 31)
154 a171fe39 balrog
#define CCR_CEN                (1 << 31)
155 a171fe39 balrog
#define FBR_BRA                (1 << 0)
156 a171fe39 balrog
#define FBR_BINT        (1 << 1)
157 a171fe39 balrog
#define FBR_SRCADDR        (0xfffffff << 4)
158 a171fe39 balrog
#define LCSR0_LDD        (1 << 0)
159 a171fe39 balrog
#define LCSR0_SOF0        (1 << 1)
160 a171fe39 balrog
#define LCSR0_BER        (1 << 2)
161 a171fe39 balrog
#define LCSR0_ABC        (1 << 3)
162 a171fe39 balrog
#define LCSR0_IU0        (1 << 4)
163 a171fe39 balrog
#define LCSR0_IU1        (1 << 5)
164 a171fe39 balrog
#define LCSR0_OU        (1 << 6)
165 a171fe39 balrog
#define LCSR0_QD        (1 << 7)
166 a171fe39 balrog
#define LCSR0_EOF0        (1 << 8)
167 a171fe39 balrog
#define LCSR0_BS0        (1 << 9)
168 a171fe39 balrog
#define LCSR0_SINT        (1 << 10)
169 a171fe39 balrog
#define LCSR0_RDST        (1 << 11)
170 a171fe39 balrog
#define LCSR0_CMDINT        (1 << 12)
171 a171fe39 balrog
#define LCSR0_BERCH(x)        (((x) & 7) << 28)
172 a171fe39 balrog
#define LCSR1_SOF(ch)        (1 << (ch - 1))
173 a171fe39 balrog
#define LCSR1_EOF(ch)        (1 << (ch + 7))
174 a171fe39 balrog
#define LCSR1_BS(ch)        (1 << (ch + 15))
175 a171fe39 balrog
#define LCSR1_IU(ch)        (1 << (ch + 23))
176 a171fe39 balrog
#define LDCMD_LENGTH(x)        ((x) & 0x001ffffc)
177 a171fe39 balrog
#define LDCMD_EOFINT        (1 << 21)
178 a171fe39 balrog
#define LDCMD_SOFINT        (1 << 22)
179 a171fe39 balrog
#define LDCMD_PAL        (1 << 26)
180 a171fe39 balrog
181 a171fe39 balrog
/* Route internal interrupt lines to the global IC */
182 bc24a225 Paul Brook
static void pxa2xx_lcdc_int_update(PXA2xxLCDState *s)
183 a171fe39 balrog
{
184 a171fe39 balrog
    int level = 0;
185 a171fe39 balrog
    level |= (s->status[0] & LCSR0_LDD)    && !(s->control[0] & LCCR0_LDM);
186 a171fe39 balrog
    level |= (s->status[0] & LCSR0_SOF0)   && !(s->control[0] & LCCR0_SOFM0);
187 a171fe39 balrog
    level |= (s->status[0] & LCSR0_IU0)    && !(s->control[0] & LCCR0_IUM);
188 a171fe39 balrog
    level |= (s->status[0] & LCSR0_IU1)    && !(s->control[5] & LCCR5_IUM(1));
189 a171fe39 balrog
    level |= (s->status[0] & LCSR0_OU)     && !(s->control[0] & LCCR0_OUM);
190 a171fe39 balrog
    level |= (s->status[0] & LCSR0_QD)     && !(s->control[0] & LCCR0_QDM);
191 a171fe39 balrog
    level |= (s->status[0] & LCSR0_EOF0)   && !(s->control[0] & LCCR0_EOFM0);
192 a171fe39 balrog
    level |= (s->status[0] & LCSR0_BS0)    && !(s->control[0] & LCCR0_BSM0);
193 a171fe39 balrog
    level |= (s->status[0] & LCSR0_RDST)   && !(s->control[0] & LCCR0_RDSTM);
194 a171fe39 balrog
    level |= (s->status[0] & LCSR0_CMDINT) && !(s->control[0] & LCCR0_CMDIM);
195 a171fe39 balrog
    level |= (s->status[1] & ~s->control[5]);
196 a171fe39 balrog
197 a171fe39 balrog
    qemu_set_irq(s->irq, !!level);
198 a171fe39 balrog
    s->irqlevel = level;
199 a171fe39 balrog
}
200 a171fe39 balrog
201 a171fe39 balrog
/* Set Branch Status interrupt high and poke associated registers */
202 bc24a225 Paul Brook
static inline void pxa2xx_dma_bs_set(PXA2xxLCDState *s, int ch)
203 a171fe39 balrog
{
204 a171fe39 balrog
    int unmasked;
205 a171fe39 balrog
    if (ch == 0) {
206 a171fe39 balrog
        s->status[0] |= LCSR0_BS0;
207 a171fe39 balrog
        unmasked = !(s->control[0] & LCCR0_BSM0);
208 a171fe39 balrog
    } else {
209 a171fe39 balrog
        s->status[1] |= LCSR1_BS(ch);
210 a171fe39 balrog
        unmasked = !(s->control[5] & LCCR5_BSM(ch));
211 a171fe39 balrog
    }
212 a171fe39 balrog
213 a171fe39 balrog
    if (unmasked) {
214 a171fe39 balrog
        if (s->irqlevel)
215 a171fe39 balrog
            s->status[0] |= LCSR0_SINT;
216 a171fe39 balrog
        else
217 a171fe39 balrog
            s->liidr = s->dma_ch[ch].id;
218 a171fe39 balrog
    }
219 a171fe39 balrog
}
220 a171fe39 balrog
221 a171fe39 balrog
/* Set Start Of Frame Status interrupt high and poke associated registers */
222 bc24a225 Paul Brook
static inline void pxa2xx_dma_sof_set(PXA2xxLCDState *s, int ch)
223 a171fe39 balrog
{
224 a171fe39 balrog
    int unmasked;
225 a171fe39 balrog
    if (!(s->dma_ch[ch].command & LDCMD_SOFINT))
226 a171fe39 balrog
        return;
227 a171fe39 balrog
228 a171fe39 balrog
    if (ch == 0) {
229 a171fe39 balrog
        s->status[0] |= LCSR0_SOF0;
230 a171fe39 balrog
        unmasked = !(s->control[0] & LCCR0_SOFM0);
231 a171fe39 balrog
    } else {
232 a171fe39 balrog
        s->status[1] |= LCSR1_SOF(ch);
233 a171fe39 balrog
        unmasked = !(s->control[5] & LCCR5_SOFM(ch));
234 a171fe39 balrog
    }
235 a171fe39 balrog
236 a171fe39 balrog
    if (unmasked) {
237 a171fe39 balrog
        if (s->irqlevel)
238 a171fe39 balrog
            s->status[0] |= LCSR0_SINT;
239 a171fe39 balrog
        else
240 a171fe39 balrog
            s->liidr = s->dma_ch[ch].id;
241 a171fe39 balrog
    }
242 a171fe39 balrog
}
243 a171fe39 balrog
244 a171fe39 balrog
/* Set End Of Frame Status interrupt high and poke associated registers */
245 bc24a225 Paul Brook
static inline void pxa2xx_dma_eof_set(PXA2xxLCDState *s, int ch)
246 a171fe39 balrog
{
247 a171fe39 balrog
    int unmasked;
248 a171fe39 balrog
    if (!(s->dma_ch[ch].command & LDCMD_EOFINT))
249 a171fe39 balrog
        return;
250 a171fe39 balrog
251 a171fe39 balrog
    if (ch == 0) {
252 a171fe39 balrog
        s->status[0] |= LCSR0_EOF0;
253 a171fe39 balrog
        unmasked = !(s->control[0] & LCCR0_EOFM0);
254 a171fe39 balrog
    } else {
255 a171fe39 balrog
        s->status[1] |= LCSR1_EOF(ch);
256 a171fe39 balrog
        unmasked = !(s->control[5] & LCCR5_EOFM(ch));
257 a171fe39 balrog
    }
258 a171fe39 balrog
259 a171fe39 balrog
    if (unmasked) {
260 a171fe39 balrog
        if (s->irqlevel)
261 a171fe39 balrog
            s->status[0] |= LCSR0_SINT;
262 a171fe39 balrog
        else
263 a171fe39 balrog
            s->liidr = s->dma_ch[ch].id;
264 a171fe39 balrog
    }
265 a171fe39 balrog
}
266 a171fe39 balrog
267 a171fe39 balrog
/* Set Bus Error Status interrupt high and poke associated registers */
268 bc24a225 Paul Brook
static inline void pxa2xx_dma_ber_set(PXA2xxLCDState *s, int ch)
269 a171fe39 balrog
{
270 a171fe39 balrog
    s->status[0] |= LCSR0_BERCH(ch) | LCSR0_BER;
271 a171fe39 balrog
    if (s->irqlevel)
272 a171fe39 balrog
        s->status[0] |= LCSR0_SINT;
273 a171fe39 balrog
    else
274 a171fe39 balrog
        s->liidr = s->dma_ch[ch].id;
275 a171fe39 balrog
}
276 a171fe39 balrog
277 a171fe39 balrog
/* Set Read Status interrupt high and poke associated registers */
278 bc24a225 Paul Brook
static inline void pxa2xx_dma_rdst_set(PXA2xxLCDState *s)
279 a171fe39 balrog
{
280 a171fe39 balrog
    s->status[0] |= LCSR0_RDST;
281 a171fe39 balrog
    if (s->irqlevel && !(s->control[0] & LCCR0_RDSTM))
282 a171fe39 balrog
        s->status[0] |= LCSR0_SINT;
283 a171fe39 balrog
}
284 a171fe39 balrog
285 a171fe39 balrog
/* Load new Frame Descriptors from DMA */
286 bc24a225 Paul Brook
static void pxa2xx_descriptor_load(PXA2xxLCDState *s)
287 a171fe39 balrog
{
288 bc24a225 Paul Brook
    PXAFrameDescriptor desc;
289 c227f099 Anthony Liguori
    target_phys_addr_t descptr;
290 a171fe39 balrog
    int i;
291 a171fe39 balrog
292 a171fe39 balrog
    for (i = 0; i < PXA_LCDDMA_CHANS; i ++) {
293 a171fe39 balrog
        s->dma_ch[i].source = 0;
294 a171fe39 balrog
295 a171fe39 balrog
        if (!s->dma_ch[i].up)
296 a171fe39 balrog
            continue;
297 a171fe39 balrog
298 a171fe39 balrog
        if (s->dma_ch[i].branch & FBR_BRA) {
299 a171fe39 balrog
            descptr = s->dma_ch[i].branch & FBR_SRCADDR;
300 a171fe39 balrog
            if (s->dma_ch[i].branch & FBR_BINT)
301 a171fe39 balrog
                pxa2xx_dma_bs_set(s, i);
302 a171fe39 balrog
            s->dma_ch[i].branch &= ~FBR_BRA;
303 a171fe39 balrog
        } else
304 a171fe39 balrog
            descptr = s->dma_ch[i].descriptor;
305 a171fe39 balrog
306 d95b2f8d balrog
        if (!(descptr >= PXA2XX_SDRAM_BASE && descptr +
307 b0457b69 pbrook
                    sizeof(desc) <= PXA2XX_SDRAM_BASE + ram_size))
308 a171fe39 balrog
            continue;
309 a171fe39 balrog
310 d7585251 pbrook
        cpu_physical_memory_read(descptr, (void *)&desc, sizeof(desc));
311 d7585251 pbrook
        s->dma_ch[i].descriptor = tswap32(desc.fdaddr);
312 d7585251 pbrook
        s->dma_ch[i].source = tswap32(desc.fsaddr);
313 d7585251 pbrook
        s->dma_ch[i].id = tswap32(desc.fidr);
314 d7585251 pbrook
        s->dma_ch[i].command = tswap32(desc.ldcmd);
315 a171fe39 balrog
    }
316 a171fe39 balrog
}
317 a171fe39 balrog
318 c227f099 Anthony Liguori
static uint32_t pxa2xx_lcdc_read(void *opaque, target_phys_addr_t offset)
319 a171fe39 balrog
{
320 bc24a225 Paul Brook
    PXA2xxLCDState *s = (PXA2xxLCDState *) opaque;
321 a171fe39 balrog
    int ch;
322 a171fe39 balrog
323 a171fe39 balrog
    switch (offset) {
324 a171fe39 balrog
    case LCCR0:
325 a171fe39 balrog
        return s->control[0];
326 a171fe39 balrog
    case LCCR1:
327 a171fe39 balrog
        return s->control[1];
328 a171fe39 balrog
    case LCCR2:
329 a171fe39 balrog
        return s->control[2];
330 a171fe39 balrog
    case LCCR3:
331 a171fe39 balrog
        return s->control[3];
332 a171fe39 balrog
    case LCCR4:
333 a171fe39 balrog
        return s->control[4];
334 a171fe39 balrog
    case LCCR5:
335 a171fe39 balrog
        return s->control[5];
336 a171fe39 balrog
337 a171fe39 balrog
    case OVL1C1:
338 a171fe39 balrog
        return s->ovl1c[0];
339 a171fe39 balrog
    case OVL1C2:
340 a171fe39 balrog
        return s->ovl1c[1];
341 a171fe39 balrog
    case OVL2C1:
342 a171fe39 balrog
        return s->ovl2c[0];
343 a171fe39 balrog
    case OVL2C2:
344 a171fe39 balrog
        return s->ovl2c[1];
345 a171fe39 balrog
346 a171fe39 balrog
    case CCR:
347 a171fe39 balrog
        return s->ccr;
348 a171fe39 balrog
349 a171fe39 balrog
    case CMDCR:
350 a171fe39 balrog
        return s->cmdcr;
351 a171fe39 balrog
352 a171fe39 balrog
    case TRGBR:
353 a171fe39 balrog
        return s->trgbr;
354 a171fe39 balrog
    case TCR:
355 a171fe39 balrog
        return s->tcr;
356 a171fe39 balrog
357 a171fe39 balrog
    case 0x200 ... 0x1000:        /* DMA per-channel registers */
358 a171fe39 balrog
        ch = (offset - 0x200) >> 4;
359 a171fe39 balrog
        if (!(ch >= 0 && ch < PXA_LCDDMA_CHANS))
360 a171fe39 balrog
            goto fail;
361 a171fe39 balrog
362 a171fe39 balrog
        switch (offset & 0xf) {
363 a171fe39 balrog
        case DMA_FDADR:
364 a171fe39 balrog
            return s->dma_ch[ch].descriptor;
365 a171fe39 balrog
        case DMA_FSADR:
366 a171fe39 balrog
            return s->dma_ch[ch].source;
367 a171fe39 balrog
        case DMA_FIDR:
368 a171fe39 balrog
            return s->dma_ch[ch].id;
369 a171fe39 balrog
        case DMA_LDCMD:
370 a171fe39 balrog
            return s->dma_ch[ch].command;
371 a171fe39 balrog
        default:
372 a171fe39 balrog
            goto fail;
373 a171fe39 balrog
        }
374 a171fe39 balrog
375 a171fe39 balrog
    case FBR0:
376 a171fe39 balrog
        return s->dma_ch[0].branch;
377 a171fe39 balrog
    case FBR1:
378 a171fe39 balrog
        return s->dma_ch[1].branch;
379 a171fe39 balrog
    case FBR2:
380 a171fe39 balrog
        return s->dma_ch[2].branch;
381 a171fe39 balrog
    case FBR3:
382 a171fe39 balrog
        return s->dma_ch[3].branch;
383 a171fe39 balrog
    case FBR4:
384 a171fe39 balrog
        return s->dma_ch[4].branch;
385 a171fe39 balrog
    case FBR5:
386 a171fe39 balrog
        return s->dma_ch[5].branch;
387 a171fe39 balrog
    case FBR6:
388 a171fe39 balrog
        return s->dma_ch[6].branch;
389 a171fe39 balrog
390 a171fe39 balrog
    case BSCNTR:
391 a171fe39 balrog
        return s->bscntr;
392 a171fe39 balrog
393 a171fe39 balrog
    case PRSR:
394 a171fe39 balrog
        return 0;
395 a171fe39 balrog
396 a171fe39 balrog
    case LCSR0:
397 a171fe39 balrog
        return s->status[0];
398 a171fe39 balrog
    case LCSR1:
399 a171fe39 balrog
        return s->status[1];
400 a171fe39 balrog
    case LIIDR:
401 a171fe39 balrog
        return s->liidr;
402 a171fe39 balrog
403 a171fe39 balrog
    default:
404 a171fe39 balrog
    fail:
405 2ac71179 Paul Brook
        hw_error("%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
406 a171fe39 balrog
    }
407 a171fe39 balrog
408 a171fe39 balrog
    return 0;
409 a171fe39 balrog
}
410 a171fe39 balrog
411 a171fe39 balrog
static void pxa2xx_lcdc_write(void *opaque,
412 c227f099 Anthony Liguori
                target_phys_addr_t offset, uint32_t value)
413 a171fe39 balrog
{
414 bc24a225 Paul Brook
    PXA2xxLCDState *s = (PXA2xxLCDState *) opaque;
415 a171fe39 balrog
    int ch;
416 a171fe39 balrog
417 a171fe39 balrog
    switch (offset) {
418 a171fe39 balrog
    case LCCR0:
419 a171fe39 balrog
        /* ACK Quick Disable done */
420 a171fe39 balrog
        if ((s->control[0] & LCCR0_ENB) && !(value & LCCR0_ENB))
421 a171fe39 balrog
            s->status[0] |= LCSR0_QD;
422 a171fe39 balrog
423 a171fe39 balrog
        if (!(s->control[0] & LCCR0_LCDT) && (value & LCCR0_LCDT))
424 a171fe39 balrog
            printf("%s: internal frame buffer unsupported\n", __FUNCTION__);
425 a171fe39 balrog
426 a171fe39 balrog
        if ((s->control[3] & LCCR3_API) &&
427 a171fe39 balrog
                (value & LCCR0_ENB) && !(value & LCCR0_LCDT))
428 a171fe39 balrog
            s->status[0] |= LCSR0_ABC;
429 a171fe39 balrog
430 a171fe39 balrog
        s->control[0] = value & 0x07ffffff;
431 a171fe39 balrog
        pxa2xx_lcdc_int_update(s);
432 a171fe39 balrog
433 a171fe39 balrog
        s->dma_ch[0].up = !!(value & LCCR0_ENB);
434 a171fe39 balrog
        s->dma_ch[1].up = (s->ovl1c[0] & OVLC1_EN) || (value & LCCR0_SDS);
435 a171fe39 balrog
        break;
436 a171fe39 balrog
437 a171fe39 balrog
    case LCCR1:
438 a171fe39 balrog
        s->control[1] = value;
439 a171fe39 balrog
        break;
440 a171fe39 balrog
441 a171fe39 balrog
    case LCCR2:
442 a171fe39 balrog
        s->control[2] = value;
443 a171fe39 balrog
        break;
444 a171fe39 balrog
445 a171fe39 balrog
    case LCCR3:
446 a171fe39 balrog
        s->control[3] = value & 0xefffffff;
447 a171fe39 balrog
        s->bpp = LCCR3_BPP(value);
448 a171fe39 balrog
        break;
449 a171fe39 balrog
450 a171fe39 balrog
    case LCCR4:
451 a171fe39 balrog
        s->control[4] = value & 0x83ff81ff;
452 a171fe39 balrog
        break;
453 a171fe39 balrog
454 a171fe39 balrog
    case LCCR5:
455 a171fe39 balrog
        s->control[5] = value & 0x3f3f3f3f;
456 a171fe39 balrog
        break;
457 a171fe39 balrog
458 a171fe39 balrog
    case OVL1C1:
459 a171fe39 balrog
        if (!(s->ovl1c[0] & OVLC1_EN) && (value & OVLC1_EN))
460 a171fe39 balrog
            printf("%s: Overlay 1 not supported\n", __FUNCTION__);
461 a171fe39 balrog
462 a171fe39 balrog
        s->ovl1c[0] = value & 0x80ffffff;
463 a171fe39 balrog
        s->dma_ch[1].up = (value & OVLC1_EN) || (s->control[0] & LCCR0_SDS);
464 a171fe39 balrog
        break;
465 a171fe39 balrog
466 a171fe39 balrog
    case OVL1C2:
467 a171fe39 balrog
        s->ovl1c[1] = value & 0x000fffff;
468 a171fe39 balrog
        break;
469 a171fe39 balrog
470 a171fe39 balrog
    case OVL2C1:
471 a171fe39 balrog
        if (!(s->ovl2c[0] & OVLC1_EN) && (value & OVLC1_EN))
472 a171fe39 balrog
            printf("%s: Overlay 2 not supported\n", __FUNCTION__);
473 a171fe39 balrog
474 a171fe39 balrog
        s->ovl2c[0] = value & 0x80ffffff;
475 a171fe39 balrog
        s->dma_ch[2].up = !!(value & OVLC1_EN);
476 a171fe39 balrog
        s->dma_ch[3].up = !!(value & OVLC1_EN);
477 a171fe39 balrog
        s->dma_ch[4].up = !!(value & OVLC1_EN);
478 a171fe39 balrog
        break;
479 a171fe39 balrog
480 a171fe39 balrog
    case OVL2C2:
481 a171fe39 balrog
        s->ovl2c[1] = value & 0x007fffff;
482 a171fe39 balrog
        break;
483 a171fe39 balrog
484 a171fe39 balrog
    case CCR:
485 a171fe39 balrog
        if (!(s->ccr & CCR_CEN) && (value & CCR_CEN))
486 a171fe39 balrog
            printf("%s: Hardware cursor unimplemented\n", __FUNCTION__);
487 a171fe39 balrog
488 a171fe39 balrog
        s->ccr = value & 0x81ffffe7;
489 a171fe39 balrog
        s->dma_ch[5].up = !!(value & CCR_CEN);
490 a171fe39 balrog
        break;
491 a171fe39 balrog
492 a171fe39 balrog
    case CMDCR:
493 a171fe39 balrog
        s->cmdcr = value & 0xff;
494 a171fe39 balrog
        break;
495 a171fe39 balrog
496 a171fe39 balrog
    case TRGBR:
497 a171fe39 balrog
        s->trgbr = value & 0x00ffffff;
498 a171fe39 balrog
        break;
499 a171fe39 balrog
500 a171fe39 balrog
    case TCR:
501 a171fe39 balrog
        s->tcr = value & 0x7fff;
502 a171fe39 balrog
        break;
503 a171fe39 balrog
504 a171fe39 balrog
    case 0x200 ... 0x1000:        /* DMA per-channel registers */
505 a171fe39 balrog
        ch = (offset - 0x200) >> 4;
506 a171fe39 balrog
        if (!(ch >= 0 && ch < PXA_LCDDMA_CHANS))
507 a171fe39 balrog
            goto fail;
508 a171fe39 balrog
509 a171fe39 balrog
        switch (offset & 0xf) {
510 a171fe39 balrog
        case DMA_FDADR:
511 a171fe39 balrog
            s->dma_ch[ch].descriptor = value & 0xfffffff0;
512 a171fe39 balrog
            break;
513 a171fe39 balrog
514 a171fe39 balrog
        default:
515 a171fe39 balrog
            goto fail;
516 a171fe39 balrog
        }
517 a171fe39 balrog
        break;
518 a171fe39 balrog
519 a171fe39 balrog
    case FBR0:
520 a171fe39 balrog
        s->dma_ch[0].branch = value & 0xfffffff3;
521 a171fe39 balrog
        break;
522 a171fe39 balrog
    case FBR1:
523 a171fe39 balrog
        s->dma_ch[1].branch = value & 0xfffffff3;
524 a171fe39 balrog
        break;
525 a171fe39 balrog
    case FBR2:
526 a171fe39 balrog
        s->dma_ch[2].branch = value & 0xfffffff3;
527 a171fe39 balrog
        break;
528 a171fe39 balrog
    case FBR3:
529 a171fe39 balrog
        s->dma_ch[3].branch = value & 0xfffffff3;
530 a171fe39 balrog
        break;
531 a171fe39 balrog
    case FBR4:
532 a171fe39 balrog
        s->dma_ch[4].branch = value & 0xfffffff3;
533 a171fe39 balrog
        break;
534 a171fe39 balrog
    case FBR5:
535 a171fe39 balrog
        s->dma_ch[5].branch = value & 0xfffffff3;
536 a171fe39 balrog
        break;
537 a171fe39 balrog
    case FBR6:
538 a171fe39 balrog
        s->dma_ch[6].branch = value & 0xfffffff3;
539 a171fe39 balrog
        break;
540 a171fe39 balrog
541 a171fe39 balrog
    case BSCNTR:
542 a171fe39 balrog
        s->bscntr = value & 0xf;
543 a171fe39 balrog
        break;
544 a171fe39 balrog
545 a171fe39 balrog
    case PRSR:
546 a171fe39 balrog
        break;
547 a171fe39 balrog
548 a171fe39 balrog
    case LCSR0:
549 a171fe39 balrog
        s->status[0] &= ~(value & 0xfff);
550 a171fe39 balrog
        if (value & LCSR0_BER)
551 a171fe39 balrog
            s->status[0] &= ~LCSR0_BERCH(7);
552 a171fe39 balrog
        break;
553 a171fe39 balrog
554 a171fe39 balrog
    case LCSR1:
555 a171fe39 balrog
        s->status[1] &= ~(value & 0x3e3f3f);
556 a171fe39 balrog
        break;
557 a171fe39 balrog
558 a171fe39 balrog
    default:
559 a171fe39 balrog
    fail:
560 2ac71179 Paul Brook
        hw_error("%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
561 a171fe39 balrog
    }
562 a171fe39 balrog
}
563 a171fe39 balrog
564 d60efc6b Blue Swirl
static CPUReadMemoryFunc * const pxa2xx_lcdc_readfn[] = {
565 a171fe39 balrog
    pxa2xx_lcdc_read,
566 a171fe39 balrog
    pxa2xx_lcdc_read,
567 a171fe39 balrog
    pxa2xx_lcdc_read
568 a171fe39 balrog
};
569 a171fe39 balrog
570 d60efc6b Blue Swirl
static CPUWriteMemoryFunc * const pxa2xx_lcdc_writefn[] = {
571 a171fe39 balrog
    pxa2xx_lcdc_write,
572 a171fe39 balrog
    pxa2xx_lcdc_write,
573 a171fe39 balrog
    pxa2xx_lcdc_write
574 a171fe39 balrog
};
575 a171fe39 balrog
576 a171fe39 balrog
/* Load new palette for a given DMA channel, convert to internal format */
577 bc24a225 Paul Brook
static void pxa2xx_palette_parse(PXA2xxLCDState *s, int ch, int bpp)
578 a171fe39 balrog
{
579 a171fe39 balrog
    int i, n, format, r, g, b, alpha;
580 a171fe39 balrog
    uint32_t *dest, *src;
581 a171fe39 balrog
    s->pal_for = LCCR4_PALFOR(s->control[4]);
582 a171fe39 balrog
    format = s->pal_for;
583 a171fe39 balrog
584 a171fe39 balrog
    switch (bpp) {
585 a171fe39 balrog
    case pxa_lcdc_2bpp:
586 a171fe39 balrog
        n = 4;
587 a171fe39 balrog
        break;
588 a171fe39 balrog
    case pxa_lcdc_4bpp:
589 a171fe39 balrog
        n = 16;
590 a171fe39 balrog
        break;
591 a171fe39 balrog
    case pxa_lcdc_8bpp:
592 a171fe39 balrog
        n = 256;
593 a171fe39 balrog
        break;
594 a171fe39 balrog
    default:
595 a171fe39 balrog
        format = 0;
596 a171fe39 balrog
        return;
597 a171fe39 balrog
    }
598 a171fe39 balrog
599 a171fe39 balrog
    src = (uint32_t *) s->dma_ch[ch].pbuffer;
600 a171fe39 balrog
    dest = (uint32_t *) s->dma_ch[ch].palette;
601 a171fe39 balrog
    alpha = r = g = b = 0;
602 a171fe39 balrog
603 a171fe39 balrog
    for (i = 0; i < n; i ++) {
604 a171fe39 balrog
        switch (format) {
605 a171fe39 balrog
        case 0: /* 16 bpp, no transparency */
606 a171fe39 balrog
            alpha = 0;
607 a171fe39 balrog
            if (s->control[0] & LCCR0_CMS)
608 a171fe39 balrog
                r = g = b = *src & 0xff;
609 a171fe39 balrog
            else {
610 a171fe39 balrog
                r = (*src & 0xf800) >> 8;
611 a171fe39 balrog
                g = (*src & 0x07e0) >> 3;
612 a171fe39 balrog
                b = (*src & 0x001f) << 3;
613 a171fe39 balrog
            }
614 a171fe39 balrog
            break;
615 a171fe39 balrog
        case 1: /* 16 bpp plus transparency */
616 a171fe39 balrog
            alpha = *src & (1 << 24);
617 a171fe39 balrog
            if (s->control[0] & LCCR0_CMS)
618 a171fe39 balrog
                r = g = b = *src & 0xff;
619 a171fe39 balrog
            else {
620 a171fe39 balrog
                r = (*src & 0xf800) >> 8;
621 a171fe39 balrog
                g = (*src & 0x07e0) >> 3;
622 a171fe39 balrog
                b = (*src & 0x001f) << 3;
623 a171fe39 balrog
            }
624 a171fe39 balrog
            break;
625 a171fe39 balrog
        case 2: /* 18 bpp plus transparency */
626 a171fe39 balrog
            alpha = *src & (1 << 24);
627 a171fe39 balrog
            if (s->control[0] & LCCR0_CMS)
628 a171fe39 balrog
                r = g = b = *src & 0xff;
629 a171fe39 balrog
            else {
630 a171fe39 balrog
                r = (*src & 0xf80000) >> 16;
631 a171fe39 balrog
                g = (*src & 0x00fc00) >> 8;
632 a171fe39 balrog
                b = (*src & 0x0000f8);
633 a171fe39 balrog
            }
634 a171fe39 balrog
            break;
635 a171fe39 balrog
        case 3: /* 24 bpp plus transparency */
636 a171fe39 balrog
            alpha = *src & (1 << 24);
637 a171fe39 balrog
            if (s->control[0] & LCCR0_CMS)
638 a171fe39 balrog
                r = g = b = *src & 0xff;
639 a171fe39 balrog
            else {
640 a171fe39 balrog
                r = (*src & 0xff0000) >> 16;
641 a171fe39 balrog
                g = (*src & 0x00ff00) >> 8;
642 a171fe39 balrog
                b = (*src & 0x0000ff);
643 a171fe39 balrog
            }
644 a171fe39 balrog
            break;
645 a171fe39 balrog
        }
646 0e1f5a0c aliguori
        switch (ds_get_bits_per_pixel(s->ds)) {
647 a171fe39 balrog
        case 8:
648 a171fe39 balrog
            *dest = rgb_to_pixel8(r, g, b) | alpha;
649 a171fe39 balrog
            break;
650 a171fe39 balrog
        case 15:
651 a171fe39 balrog
            *dest = rgb_to_pixel15(r, g, b) | alpha;
652 a171fe39 balrog
            break;
653 a171fe39 balrog
        case 16:
654 a171fe39 balrog
            *dest = rgb_to_pixel16(r, g, b) | alpha;
655 a171fe39 balrog
            break;
656 a171fe39 balrog
        case 24:
657 a171fe39 balrog
            *dest = rgb_to_pixel24(r, g, b) | alpha;
658 a171fe39 balrog
            break;
659 a171fe39 balrog
        case 32:
660 a171fe39 balrog
            *dest = rgb_to_pixel32(r, g, b) | alpha;
661 a171fe39 balrog
            break;
662 a171fe39 balrog
        }
663 a171fe39 balrog
        src ++;
664 a171fe39 balrog
        dest ++;
665 a171fe39 balrog
    }
666 a171fe39 balrog
}
667 a171fe39 balrog
668 bc24a225 Paul Brook
static void pxa2xx_lcdc_dma0_redraw_horiz(PXA2xxLCDState *s,
669 c227f099 Anthony Liguori
                target_phys_addr_t addr, int *miny, int *maxy)
670 a171fe39 balrog
{
671 714fa308 pbrook
    int src_width, dest_width;
672 b9d38e95 Blue Swirl
    drawfn fn = NULL;
673 a171fe39 balrog
    if (s->dest_width)
674 a171fe39 balrog
        fn = s->line_fn[s->transp][s->bpp];
675 a171fe39 balrog
    if (!fn)
676 a171fe39 balrog
        return;
677 a171fe39 balrog
678 a171fe39 balrog
    src_width = (s->xres + 3) & ~3;     /* Pad to a 4 pixels multiple */
679 a171fe39 balrog
    if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp)
680 a171fe39 balrog
        src_width *= 3;
681 a171fe39 balrog
    else if (s->bpp > pxa_lcdc_16bpp)
682 a171fe39 balrog
        src_width *= 4;
683 a171fe39 balrog
    else if (s->bpp > pxa_lcdc_8bpp)
684 a171fe39 balrog
        src_width *= 2;
685 a171fe39 balrog
686 a171fe39 balrog
    dest_width = s->xres * s->dest_width;
687 714fa308 pbrook
    *miny = 0;
688 714fa308 pbrook
    framebuffer_update_display(s->ds,
689 714fa308 pbrook
                               addr, s->xres, s->yres,
690 714fa308 pbrook
                               src_width, dest_width, s->dest_width,
691 714fa308 pbrook
                               s->invalidated,
692 714fa308 pbrook
                               fn, s->dma_ch[0].palette, miny, maxy);
693 a171fe39 balrog
}
694 a171fe39 balrog
695 bc24a225 Paul Brook
static void pxa2xx_lcdc_dma0_redraw_vert(PXA2xxLCDState *s,
696 c227f099 Anthony Liguori
               target_phys_addr_t addr, int *miny, int *maxy)
697 a171fe39 balrog
{
698 714fa308 pbrook
    int src_width, dest_width;
699 b9d38e95 Blue Swirl
    drawfn fn = NULL;
700 a171fe39 balrog
    if (s->dest_width)
701 a171fe39 balrog
        fn = s->line_fn[s->transp][s->bpp];
702 a171fe39 balrog
    if (!fn)
703 a171fe39 balrog
        return;
704 a171fe39 balrog
705 a171fe39 balrog
    src_width = (s->xres + 3) & ~3;     /* Pad to a 4 pixels multiple */
706 a171fe39 balrog
    if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp)
707 a171fe39 balrog
        src_width *= 3;
708 a171fe39 balrog
    else if (s->bpp > pxa_lcdc_16bpp)
709 a171fe39 balrog
        src_width *= 4;
710 a171fe39 balrog
    else if (s->bpp > pxa_lcdc_8bpp)
711 a171fe39 balrog
        src_width *= 2;
712 a171fe39 balrog
713 a171fe39 balrog
    dest_width = s->yres * s->dest_width;
714 714fa308 pbrook
    *miny = 0;
715 714fa308 pbrook
    framebuffer_update_display(s->ds,
716 714fa308 pbrook
                               addr, s->xres, s->yres,
717 714fa308 pbrook
                               src_width, s->dest_width, -dest_width,
718 714fa308 pbrook
                               s->invalidated,
719 714fa308 pbrook
                               fn, s->dma_ch[0].palette,
720 714fa308 pbrook
                               miny, maxy);
721 a171fe39 balrog
}
722 a171fe39 balrog
723 bc24a225 Paul Brook
static void pxa2xx_lcdc_resize(PXA2xxLCDState *s)
724 a171fe39 balrog
{
725 a171fe39 balrog
    int width, height;
726 a171fe39 balrog
    if (!(s->control[0] & LCCR0_ENB))
727 a171fe39 balrog
        return;
728 a171fe39 balrog
729 a171fe39 balrog
    width = LCCR1_PPL(s->control[1]) + 1;
730 a171fe39 balrog
    height = LCCR2_LPP(s->control[2]) + 1;
731 a171fe39 balrog
732 a171fe39 balrog
    if (width != s->xres || height != s->yres) {
733 a171fe39 balrog
        if (s->orientation)
734 3023f332 aliguori
            qemu_console_resize(s->ds, height, width);
735 a171fe39 balrog
        else
736 3023f332 aliguori
            qemu_console_resize(s->ds, width, height);
737 a171fe39 balrog
        s->invalidated = 1;
738 a171fe39 balrog
        s->xres = width;
739 a171fe39 balrog
        s->yres = height;
740 a171fe39 balrog
    }
741 a171fe39 balrog
}
742 a171fe39 balrog
743 a171fe39 balrog
static void pxa2xx_update_display(void *opaque)
744 a171fe39 balrog
{
745 bc24a225 Paul Brook
    PXA2xxLCDState *s = (PXA2xxLCDState *) opaque;
746 c227f099 Anthony Liguori
    target_phys_addr_t fbptr;
747 a171fe39 balrog
    int miny, maxy;
748 a171fe39 balrog
    int ch;
749 a171fe39 balrog
    if (!(s->control[0] & LCCR0_ENB))
750 a171fe39 balrog
        return;
751 a171fe39 balrog
752 a171fe39 balrog
    pxa2xx_descriptor_load(s);
753 a171fe39 balrog
754 a171fe39 balrog
    pxa2xx_lcdc_resize(s);
755 a171fe39 balrog
    miny = s->yres;
756 a171fe39 balrog
    maxy = 0;
757 a171fe39 balrog
    s->transp = s->dma_ch[2].up || s->dma_ch[3].up;
758 a171fe39 balrog
    /* Note: With overlay planes the order depends on LCCR0 bit 25.  */
759 a171fe39 balrog
    for (ch = 0; ch < PXA_LCDDMA_CHANS; ch ++)
760 a171fe39 balrog
        if (s->dma_ch[ch].up) {
761 a171fe39 balrog
            if (!s->dma_ch[ch].source) {
762 a171fe39 balrog
                pxa2xx_dma_ber_set(s, ch);
763 a171fe39 balrog
                continue;
764 a171fe39 balrog
            }
765 a171fe39 balrog
            fbptr = s->dma_ch[ch].source;
766 d95b2f8d balrog
            if (!(fbptr >= PXA2XX_SDRAM_BASE &&
767 b0457b69 pbrook
                    fbptr <= PXA2XX_SDRAM_BASE + ram_size)) {
768 a171fe39 balrog
                pxa2xx_dma_ber_set(s, ch);
769 a171fe39 balrog
                continue;
770 a171fe39 balrog
            }
771 a171fe39 balrog
772 a171fe39 balrog
            if (s->dma_ch[ch].command & LDCMD_PAL) {
773 714fa308 pbrook
                cpu_physical_memory_read(fbptr, s->dma_ch[ch].pbuffer,
774 714fa308 pbrook
                    MAX(LDCMD_LENGTH(s->dma_ch[ch].command),
775 714fa308 pbrook
                        sizeof(s->dma_ch[ch].pbuffer)));
776 a171fe39 balrog
                pxa2xx_palette_parse(s, ch, s->bpp);
777 a171fe39 balrog
            } else {
778 a171fe39 balrog
                /* Do we need to reparse palette */
779 a171fe39 balrog
                if (LCCR4_PALFOR(s->control[4]) != s->pal_for)
780 a171fe39 balrog
                    pxa2xx_palette_parse(s, ch, s->bpp);
781 a171fe39 balrog
782 a171fe39 balrog
                /* ACK frame start */
783 a171fe39 balrog
                pxa2xx_dma_sof_set(s, ch);
784 a171fe39 balrog
785 714fa308 pbrook
                s->dma_ch[ch].redraw(s, fbptr, &miny, &maxy);
786 a171fe39 balrog
                s->invalidated = 0;
787 a171fe39 balrog
788 a171fe39 balrog
                /* ACK frame completed */
789 a171fe39 balrog
                pxa2xx_dma_eof_set(s, ch);
790 a171fe39 balrog
            }
791 a171fe39 balrog
        }
792 a171fe39 balrog
793 a171fe39 balrog
    if (s->control[0] & LCCR0_DIS) {
794 a171fe39 balrog
        /* ACK last frame completed */
795 a171fe39 balrog
        s->control[0] &= ~LCCR0_ENB;
796 a171fe39 balrog
        s->status[0] |= LCSR0_LDD;
797 a171fe39 balrog
    }
798 a171fe39 balrog
799 714fa308 pbrook
    if (miny >= 0) {
800 714fa308 pbrook
        if (s->orientation)
801 b2bf03a9 Dmitry Eremin-Solenikov
            dpy_update(s->ds, miny, 0, maxy - miny, s->xres);
802 714fa308 pbrook
        else
803 b2bf03a9 Dmitry Eremin-Solenikov
            dpy_update(s->ds, 0, miny, s->xres, maxy - miny);
804 714fa308 pbrook
    }
805 a171fe39 balrog
    pxa2xx_lcdc_int_update(s);
806 a171fe39 balrog
807 38641a52 balrog
    qemu_irq_raise(s->vsync_cb);
808 a171fe39 balrog
}
809 a171fe39 balrog
810 a171fe39 balrog
static void pxa2xx_invalidate_display(void *opaque)
811 a171fe39 balrog
{
812 bc24a225 Paul Brook
    PXA2xxLCDState *s = (PXA2xxLCDState *) opaque;
813 a171fe39 balrog
    s->invalidated = 1;
814 a171fe39 balrog
}
815 a171fe39 balrog
816 a171fe39 balrog
static void pxa2xx_screen_dump(void *opaque, const char *filename)
817 a171fe39 balrog
{
818 a171fe39 balrog
    /* TODO */
819 a171fe39 balrog
}
820 a171fe39 balrog
821 9596ebb7 pbrook
static void pxa2xx_lcdc_orientation(void *opaque, int angle)
822 a171fe39 balrog
{
823 bc24a225 Paul Brook
    PXA2xxLCDState *s = (PXA2xxLCDState *) opaque;
824 a171fe39 balrog
825 a171fe39 balrog
    if (angle) {
826 a171fe39 balrog
        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_vert;
827 a171fe39 balrog
    } else {
828 a171fe39 balrog
        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_horiz;
829 a171fe39 balrog
    }
830 a171fe39 balrog
831 a171fe39 balrog
    s->orientation = angle;
832 a171fe39 balrog
    s->xres = s->yres = -1;
833 a171fe39 balrog
    pxa2xx_lcdc_resize(s);
834 a171fe39 balrog
}
835 a171fe39 balrog
836 99838363 Juan Quintela
static const VMStateDescription vmstate_dma_channel = {
837 99838363 Juan Quintela
    .name = "dma_channel",
838 99838363 Juan Quintela
    .version_id = 0,
839 99838363 Juan Quintela
    .minimum_version_id = 0,
840 99838363 Juan Quintela
    .minimum_version_id_old = 0,
841 99838363 Juan Quintela
    .fields      = (VMStateField[]) {
842 99838363 Juan Quintela
        VMSTATE_UINTTL(branch, struct DMAChannel),
843 99838363 Juan Quintela
        VMSTATE_UINT8(up, struct DMAChannel),
844 99838363 Juan Quintela
        VMSTATE_BUFFER(pbuffer, struct DMAChannel),
845 99838363 Juan Quintela
        VMSTATE_UINTTL(descriptor, struct DMAChannel),
846 99838363 Juan Quintela
        VMSTATE_UINTTL(source, struct DMAChannel),
847 99838363 Juan Quintela
        VMSTATE_UINT32(id, struct DMAChannel),
848 99838363 Juan Quintela
        VMSTATE_UINT32(command, struct DMAChannel),
849 99838363 Juan Quintela
        VMSTATE_END_OF_LIST()
850 aa941b94 balrog
    }
851 99838363 Juan Quintela
};
852 aa941b94 balrog
853 99838363 Juan Quintela
static int pxa2xx_lcdc_post_load(void *opaque, int version_id)
854 aa941b94 balrog
{
855 99838363 Juan Quintela
    PXA2xxLCDState *s = opaque;
856 aa941b94 balrog
857 aa941b94 balrog
    s->bpp = LCCR3_BPP(s->control[3]);
858 aa941b94 balrog
    s->xres = s->yres = s->pal_for = -1;
859 aa941b94 balrog
860 aa941b94 balrog
    return 0;
861 aa941b94 balrog
}
862 aa941b94 balrog
863 99838363 Juan Quintela
static const VMStateDescription vmstate_pxa2xx_lcdc = {
864 99838363 Juan Quintela
    .name = "pxa2xx_lcdc",
865 99838363 Juan Quintela
    .version_id = 0,
866 99838363 Juan Quintela
    .minimum_version_id = 0,
867 99838363 Juan Quintela
    .minimum_version_id_old = 0,
868 99838363 Juan Quintela
    .post_load = pxa2xx_lcdc_post_load,
869 99838363 Juan Quintela
    .fields      = (VMStateField[]) {
870 99838363 Juan Quintela
        VMSTATE_INT32(irqlevel, PXA2xxLCDState),
871 99838363 Juan Quintela
        VMSTATE_INT32(transp, PXA2xxLCDState),
872 99838363 Juan Quintela
        VMSTATE_UINT32_ARRAY(control, PXA2xxLCDState, 6),
873 99838363 Juan Quintela
        VMSTATE_UINT32_ARRAY(status, PXA2xxLCDState, 2),
874 99838363 Juan Quintela
        VMSTATE_UINT32_ARRAY(ovl1c, PXA2xxLCDState, 2),
875 99838363 Juan Quintela
        VMSTATE_UINT32_ARRAY(ovl2c, PXA2xxLCDState, 2),
876 99838363 Juan Quintela
        VMSTATE_UINT32(ccr, PXA2xxLCDState),
877 99838363 Juan Quintela
        VMSTATE_UINT32(cmdcr, PXA2xxLCDState),
878 99838363 Juan Quintela
        VMSTATE_UINT32(trgbr, PXA2xxLCDState),
879 99838363 Juan Quintela
        VMSTATE_UINT32(tcr, PXA2xxLCDState),
880 99838363 Juan Quintela
        VMSTATE_UINT32(liidr, PXA2xxLCDState),
881 99838363 Juan Quintela
        VMSTATE_UINT8(bscntr, PXA2xxLCDState),
882 99838363 Juan Quintela
        VMSTATE_STRUCT_ARRAY(dma_ch, PXA2xxLCDState, 7, 0,
883 99838363 Juan Quintela
                             vmstate_dma_channel, struct DMAChannel),
884 99838363 Juan Quintela
        VMSTATE_END_OF_LIST()
885 99838363 Juan Quintela
    }
886 99838363 Juan Quintela
};
887 99838363 Juan Quintela
888 a171fe39 balrog
#define BITS 8
889 a171fe39 balrog
#include "pxa2xx_template.h"
890 a171fe39 balrog
#define BITS 15
891 a171fe39 balrog
#include "pxa2xx_template.h"
892 a171fe39 balrog
#define BITS 16
893 a171fe39 balrog
#include "pxa2xx_template.h"
894 a171fe39 balrog
#define BITS 24
895 a171fe39 balrog
#include "pxa2xx_template.h"
896 a171fe39 balrog
#define BITS 32
897 a171fe39 balrog
#include "pxa2xx_template.h"
898 a171fe39 balrog
899 c227f099 Anthony Liguori
PXA2xxLCDState *pxa2xx_lcdc_init(target_phys_addr_t base, qemu_irq irq)
900 a171fe39 balrog
{
901 a171fe39 balrog
    int iomemtype;
902 bc24a225 Paul Brook
    PXA2xxLCDState *s;
903 a171fe39 balrog
904 bc24a225 Paul Brook
    s = (PXA2xxLCDState *) qemu_mallocz(sizeof(PXA2xxLCDState));
905 a171fe39 balrog
    s->invalidated = 1;
906 a171fe39 balrog
    s->irq = irq;
907 a171fe39 balrog
908 a171fe39 balrog
    pxa2xx_lcdc_orientation(s, graphic_rotate);
909 a171fe39 balrog
910 1eed09cb Avi Kivity
    iomemtype = cpu_register_io_memory(pxa2xx_lcdc_readfn,
911 2507c12a Alexander Graf
                    pxa2xx_lcdc_writefn, s, DEVICE_NATIVE_ENDIAN);
912 187337f8 pbrook
    cpu_register_physical_memory(base, 0x00100000, iomemtype);
913 a171fe39 balrog
914 3023f332 aliguori
    s->ds = graphic_console_init(pxa2xx_update_display,
915 3023f332 aliguori
                                 pxa2xx_invalidate_display,
916 3023f332 aliguori
                                 pxa2xx_screen_dump, NULL, s);
917 a171fe39 balrog
918 0e1f5a0c aliguori
    switch (ds_get_bits_per_pixel(s->ds)) {
919 a171fe39 balrog
    case 0:
920 a171fe39 balrog
        s->dest_width = 0;
921 a171fe39 balrog
        break;
922 a171fe39 balrog
    case 8:
923 a171fe39 balrog
        s->line_fn[0] = pxa2xx_draw_fn_8;
924 a171fe39 balrog
        s->line_fn[1] = pxa2xx_draw_fn_8t;
925 a171fe39 balrog
        s->dest_width = 1;
926 a171fe39 balrog
        break;
927 a171fe39 balrog
    case 15:
928 a171fe39 balrog
        s->line_fn[0] = pxa2xx_draw_fn_15;
929 a171fe39 balrog
        s->line_fn[1] = pxa2xx_draw_fn_15t;
930 a171fe39 balrog
        s->dest_width = 2;
931 a171fe39 balrog
        break;
932 a171fe39 balrog
    case 16:
933 a171fe39 balrog
        s->line_fn[0] = pxa2xx_draw_fn_16;
934 a171fe39 balrog
        s->line_fn[1] = pxa2xx_draw_fn_16t;
935 a171fe39 balrog
        s->dest_width = 2;
936 a171fe39 balrog
        break;
937 a171fe39 balrog
    case 24:
938 a171fe39 balrog
        s->line_fn[0] = pxa2xx_draw_fn_24;
939 a171fe39 balrog
        s->line_fn[1] = pxa2xx_draw_fn_24t;
940 a171fe39 balrog
        s->dest_width = 3;
941 a171fe39 balrog
        break;
942 a171fe39 balrog
    case 32:
943 a171fe39 balrog
        s->line_fn[0] = pxa2xx_draw_fn_32;
944 a171fe39 balrog
        s->line_fn[1] = pxa2xx_draw_fn_32t;
945 a171fe39 balrog
        s->dest_width = 4;
946 a171fe39 balrog
        break;
947 a171fe39 balrog
    default:
948 a171fe39 balrog
        fprintf(stderr, "%s: Bad color depth\n", __FUNCTION__);
949 a171fe39 balrog
        exit(1);
950 a171fe39 balrog
    }
951 aa941b94 balrog
952 99838363 Juan Quintela
    vmstate_register(NULL, 0, &vmstate_pxa2xx_lcdc, s);
953 aa941b94 balrog
954 a171fe39 balrog
    return s;
955 a171fe39 balrog
}
956 a171fe39 balrog
957 bc24a225 Paul Brook
void pxa2xx_lcd_vsync_notifier(PXA2xxLCDState *s, qemu_irq handler)
958 38641a52 balrog
{
959 38641a52 balrog
    s->vsync_cb = handler;
960 a171fe39 balrog
}