root / hw / pxa2xx.c @ 783f04e1
History | View | Annotate | Download (64.8 kB)
1 | c1713132 | balrog | /*
|
---|---|---|---|
2 | c1713132 | balrog | * Intel XScale PXA255/270 processor support.
|
3 | c1713132 | balrog | *
|
4 | c1713132 | balrog | * Copyright (c) 2006 Openedhand Ltd.
|
5 | c1713132 | balrog | * Written by Andrzej Zaborowski <balrog@zabor.org>
|
6 | c1713132 | balrog | *
|
7 | c1713132 | balrog | * This code is licenced under the GPL.
|
8 | c1713132 | balrog | */
|
9 | c1713132 | balrog | |
10 | a984a69e | Paul Brook | #include "sysbus.h" |
11 | 87ecb68b | pbrook | #include "pxa.h" |
12 | 87ecb68b | pbrook | #include "sysemu.h" |
13 | 87ecb68b | pbrook | #include "pc.h" |
14 | 87ecb68b | pbrook | #include "i2c.h" |
15 | a984a69e | Paul Brook | #include "ssi.h" |
16 | 87ecb68b | pbrook | #include "qemu-timer.h" |
17 | 87ecb68b | pbrook | #include "qemu-char.h" |
18 | 2446333c | Blue Swirl | #include "blockdev.h" |
19 | c1713132 | balrog | |
20 | c1713132 | balrog | static struct { |
21 | c227f099 | Anthony Liguori | target_phys_addr_t io_base; |
22 | c1713132 | balrog | int irqn;
|
23 | c1713132 | balrog | } pxa255_serial[] = { |
24 | c1713132 | balrog | { 0x40100000, PXA2XX_PIC_FFUART },
|
25 | c1713132 | balrog | { 0x40200000, PXA2XX_PIC_BTUART },
|
26 | c1713132 | balrog | { 0x40700000, PXA2XX_PIC_STUART },
|
27 | c1713132 | balrog | { 0x41600000, PXA25X_PIC_HWUART },
|
28 | c1713132 | balrog | { 0, 0 } |
29 | c1713132 | balrog | }, pxa270_serial[] = { |
30 | c1713132 | balrog | { 0x40100000, PXA2XX_PIC_FFUART },
|
31 | c1713132 | balrog | { 0x40200000, PXA2XX_PIC_BTUART },
|
32 | c1713132 | balrog | { 0x40700000, PXA2XX_PIC_STUART },
|
33 | c1713132 | balrog | { 0, 0 } |
34 | c1713132 | balrog | }; |
35 | c1713132 | balrog | |
36 | fa58c156 | bellard | typedef struct PXASSPDef { |
37 | c227f099 | Anthony Liguori | target_phys_addr_t io_base; |
38 | c1713132 | balrog | int irqn;
|
39 | fa58c156 | bellard | } PXASSPDef; |
40 | fa58c156 | bellard | |
41 | fa58c156 | bellard | #if 0
|
42 | fa58c156 | bellard | static PXASSPDef pxa250_ssp[] = {
|
43 | c1713132 | balrog | { 0x41000000, PXA2XX_PIC_SSP },
|
44 | c1713132 | balrog | { 0, 0 }
|
45 | fa58c156 | bellard | };
|
46 | fa58c156 | bellard | #endif
|
47 | fa58c156 | bellard | |
48 | fa58c156 | bellard | static PXASSPDef pxa255_ssp[] = {
|
49 | c1713132 | balrog | { 0x41000000, PXA2XX_PIC_SSP },
|
50 | c1713132 | balrog | { 0x41400000, PXA25X_PIC_NSSP },
|
51 | c1713132 | balrog | { 0, 0 } |
52 | fa58c156 | bellard | }; |
53 | fa58c156 | bellard | |
54 | fa58c156 | bellard | #if 0
|
55 | fa58c156 | bellard | static PXASSPDef pxa26x_ssp[] = {
|
56 | c1713132 | balrog | { 0x41000000, PXA2XX_PIC_SSP },
|
57 | c1713132 | balrog | { 0x41400000, PXA25X_PIC_NSSP },
|
58 | c1713132 | balrog | { 0x41500000, PXA26X_PIC_ASSP },
|
59 | c1713132 | balrog | { 0, 0 }
|
60 | fa58c156 | bellard | };
|
61 | fa58c156 | bellard | #endif
|
62 | fa58c156 | bellard | |
63 | fa58c156 | bellard | static PXASSPDef pxa27x_ssp[] = {
|
64 | c1713132 | balrog | { 0x41000000, PXA2XX_PIC_SSP },
|
65 | c1713132 | balrog | { 0x41700000, PXA27X_PIC_SSP2 },
|
66 | c1713132 | balrog | { 0x41900000, PXA2XX_PIC_SSP3 },
|
67 | c1713132 | balrog | { 0, 0 } |
68 | c1713132 | balrog | }; |
69 | c1713132 | balrog | |
70 | c1713132 | balrog | #define PMCR 0x00 /* Power Manager Control register */ |
71 | c1713132 | balrog | #define PSSR 0x04 /* Power Manager Sleep Status register */ |
72 | c1713132 | balrog | #define PSPR 0x08 /* Power Manager Scratch-Pad register */ |
73 | c1713132 | balrog | #define PWER 0x0c /* Power Manager Wake-Up Enable register */ |
74 | c1713132 | balrog | #define PRER 0x10 /* Power Manager Rising-Edge Detect Enable register */ |
75 | c1713132 | balrog | #define PFER 0x14 /* Power Manager Falling-Edge Detect Enable register */ |
76 | c1713132 | balrog | #define PEDR 0x18 /* Power Manager Edge-Detect Status register */ |
77 | c1713132 | balrog | #define PCFR 0x1c /* Power Manager General Configuration register */ |
78 | c1713132 | balrog | #define PGSR0 0x20 /* Power Manager GPIO Sleep-State register 0 */ |
79 | c1713132 | balrog | #define PGSR1 0x24 /* Power Manager GPIO Sleep-State register 1 */ |
80 | c1713132 | balrog | #define PGSR2 0x28 /* Power Manager GPIO Sleep-State register 2 */ |
81 | c1713132 | balrog | #define PGSR3 0x2c /* Power Manager GPIO Sleep-State register 3 */ |
82 | c1713132 | balrog | #define RCSR 0x30 /* Reset Controller Status register */ |
83 | c1713132 | balrog | #define PSLR 0x34 /* Power Manager Sleep Configuration register */ |
84 | c1713132 | balrog | #define PTSR 0x38 /* Power Manager Standby Configuration register */ |
85 | c1713132 | balrog | #define PVCR 0x40 /* Power Manager Voltage Change Control register */ |
86 | c1713132 | balrog | #define PUCR 0x4c /* Power Manager USIM Card Control/Status register */ |
87 | c1713132 | balrog | #define PKWR 0x50 /* Power Manager Keyboard Wake-Up Enable register */ |
88 | c1713132 | balrog | #define PKSR 0x54 /* Power Manager Keyboard Level-Detect Status */ |
89 | c1713132 | balrog | #define PCMD0 0x80 /* Power Manager I2C Command register File 0 */ |
90 | c1713132 | balrog | #define PCMD31 0xfc /* Power Manager I2C Command register File 31 */ |
91 | c1713132 | balrog | |
92 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_pm_read(void *opaque, target_phys_addr_t addr) |
93 | c1713132 | balrog | { |
94 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
95 | c1713132 | balrog | |
96 | c1713132 | balrog | switch (addr) {
|
97 | c1713132 | balrog | case PMCR ... PCMD31:
|
98 | c1713132 | balrog | if (addr & 3) |
99 | c1713132 | balrog | goto fail;
|
100 | c1713132 | balrog | |
101 | c1713132 | balrog | return s->pm_regs[addr >> 2]; |
102 | c1713132 | balrog | default:
|
103 | c1713132 | balrog | fail:
|
104 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
105 | c1713132 | balrog | break;
|
106 | c1713132 | balrog | } |
107 | c1713132 | balrog | return 0; |
108 | c1713132 | balrog | } |
109 | c1713132 | balrog | |
110 | c227f099 | Anthony Liguori | static void pxa2xx_pm_write(void *opaque, target_phys_addr_t addr, |
111 | c1713132 | balrog | uint32_t value) |
112 | c1713132 | balrog | { |
113 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
114 | c1713132 | balrog | |
115 | c1713132 | balrog | switch (addr) {
|
116 | c1713132 | balrog | case PMCR:
|
117 | c1713132 | balrog | s->pm_regs[addr >> 2] &= 0x15 & ~(value & 0x2a); |
118 | c1713132 | balrog | s->pm_regs[addr >> 2] |= value & 0x15; |
119 | c1713132 | balrog | break;
|
120 | c1713132 | balrog | |
121 | c1713132 | balrog | case PSSR: /* Read-clean registers */ |
122 | c1713132 | balrog | case RCSR:
|
123 | c1713132 | balrog | case PKSR:
|
124 | c1713132 | balrog | s->pm_regs[addr >> 2] &= ~value;
|
125 | c1713132 | balrog | break;
|
126 | c1713132 | balrog | |
127 | c1713132 | balrog | default: /* Read-write registers */ |
128 | c1713132 | balrog | if (addr >= PMCR && addr <= PCMD31 && !(addr & 3)) { |
129 | c1713132 | balrog | s->pm_regs[addr >> 2] = value;
|
130 | c1713132 | balrog | break;
|
131 | c1713132 | balrog | } |
132 | c1713132 | balrog | |
133 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
134 | c1713132 | balrog | break;
|
135 | c1713132 | balrog | } |
136 | c1713132 | balrog | } |
137 | c1713132 | balrog | |
138 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_pm_readfn[] = { |
139 | c1713132 | balrog | pxa2xx_pm_read, |
140 | c1713132 | balrog | pxa2xx_pm_read, |
141 | c1713132 | balrog | pxa2xx_pm_read, |
142 | c1713132 | balrog | }; |
143 | c1713132 | balrog | |
144 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_pm_writefn[] = { |
145 | c1713132 | balrog | pxa2xx_pm_write, |
146 | c1713132 | balrog | pxa2xx_pm_write, |
147 | c1713132 | balrog | pxa2xx_pm_write, |
148 | c1713132 | balrog | }; |
149 | c1713132 | balrog | |
150 | aa941b94 | balrog | static void pxa2xx_pm_save(QEMUFile *f, void *opaque) |
151 | aa941b94 | balrog | { |
152 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
153 | aa941b94 | balrog | int i;
|
154 | aa941b94 | balrog | |
155 | aa941b94 | balrog | for (i = 0; i < 0x40; i ++) |
156 | aa941b94 | balrog | qemu_put_be32s(f, &s->pm_regs[i]); |
157 | aa941b94 | balrog | } |
158 | aa941b94 | balrog | |
159 | aa941b94 | balrog | static int pxa2xx_pm_load(QEMUFile *f, void *opaque, int version_id) |
160 | aa941b94 | balrog | { |
161 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
162 | aa941b94 | balrog | int i;
|
163 | aa941b94 | balrog | |
164 | aa941b94 | balrog | for (i = 0; i < 0x40; i ++) |
165 | aa941b94 | balrog | qemu_get_be32s(f, &s->pm_regs[i]); |
166 | aa941b94 | balrog | |
167 | aa941b94 | balrog | return 0; |
168 | aa941b94 | balrog | } |
169 | aa941b94 | balrog | |
170 | c1713132 | balrog | #define CCCR 0x00 /* Core Clock Configuration register */ |
171 | c1713132 | balrog | #define CKEN 0x04 /* Clock Enable register */ |
172 | c1713132 | balrog | #define OSCC 0x08 /* Oscillator Configuration register */ |
173 | c1713132 | balrog | #define CCSR 0x0c /* Core Clock Status register */ |
174 | c1713132 | balrog | |
175 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_cm_read(void *opaque, target_phys_addr_t addr) |
176 | c1713132 | balrog | { |
177 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
178 | c1713132 | balrog | |
179 | c1713132 | balrog | switch (addr) {
|
180 | c1713132 | balrog | case CCCR:
|
181 | c1713132 | balrog | case CKEN:
|
182 | c1713132 | balrog | case OSCC:
|
183 | c1713132 | balrog | return s->cm_regs[addr >> 2]; |
184 | c1713132 | balrog | |
185 | c1713132 | balrog | case CCSR:
|
186 | c1713132 | balrog | return s->cm_regs[CCCR >> 2] | (3 << 28); |
187 | c1713132 | balrog | |
188 | c1713132 | balrog | default:
|
189 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
190 | c1713132 | balrog | break;
|
191 | c1713132 | balrog | } |
192 | c1713132 | balrog | return 0; |
193 | c1713132 | balrog | } |
194 | c1713132 | balrog | |
195 | c227f099 | Anthony Liguori | static void pxa2xx_cm_write(void *opaque, target_phys_addr_t addr, |
196 | c1713132 | balrog | uint32_t value) |
197 | c1713132 | balrog | { |
198 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
199 | c1713132 | balrog | |
200 | c1713132 | balrog | switch (addr) {
|
201 | c1713132 | balrog | case CCCR:
|
202 | c1713132 | balrog | case CKEN:
|
203 | c1713132 | balrog | s->cm_regs[addr >> 2] = value;
|
204 | c1713132 | balrog | break;
|
205 | c1713132 | balrog | |
206 | c1713132 | balrog | case OSCC:
|
207 | 565d2895 | balrog | s->cm_regs[addr >> 2] &= ~0x6c; |
208 | c1713132 | balrog | s->cm_regs[addr >> 2] |= value & 0x6e; |
209 | 565d2895 | balrog | if ((value >> 1) & 1) /* OON */ |
210 | 565d2895 | balrog | s->cm_regs[addr >> 2] |= 1 << 0; /* Oscillator is now stable */ |
211 | c1713132 | balrog | break;
|
212 | c1713132 | balrog | |
213 | c1713132 | balrog | default:
|
214 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
215 | c1713132 | balrog | break;
|
216 | c1713132 | balrog | } |
217 | c1713132 | balrog | } |
218 | c1713132 | balrog | |
219 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_cm_readfn[] = { |
220 | c1713132 | balrog | pxa2xx_cm_read, |
221 | c1713132 | balrog | pxa2xx_cm_read, |
222 | c1713132 | balrog | pxa2xx_cm_read, |
223 | c1713132 | balrog | }; |
224 | c1713132 | balrog | |
225 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_cm_writefn[] = { |
226 | c1713132 | balrog | pxa2xx_cm_write, |
227 | c1713132 | balrog | pxa2xx_cm_write, |
228 | c1713132 | balrog | pxa2xx_cm_write, |
229 | c1713132 | balrog | }; |
230 | c1713132 | balrog | |
231 | aa941b94 | balrog | static void pxa2xx_cm_save(QEMUFile *f, void *opaque) |
232 | aa941b94 | balrog | { |
233 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
234 | aa941b94 | balrog | int i;
|
235 | aa941b94 | balrog | |
236 | aa941b94 | balrog | for (i = 0; i < 4; i ++) |
237 | aa941b94 | balrog | qemu_put_be32s(f, &s->cm_regs[i]); |
238 | aa941b94 | balrog | qemu_put_be32s(f, &s->clkcfg); |
239 | aa941b94 | balrog | qemu_put_be32s(f, &s->pmnc); |
240 | aa941b94 | balrog | } |
241 | aa941b94 | balrog | |
242 | aa941b94 | balrog | static int pxa2xx_cm_load(QEMUFile *f, void *opaque, int version_id) |
243 | aa941b94 | balrog | { |
244 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
245 | aa941b94 | balrog | int i;
|
246 | aa941b94 | balrog | |
247 | aa941b94 | balrog | for (i = 0; i < 4; i ++) |
248 | aa941b94 | balrog | qemu_get_be32s(f, &s->cm_regs[i]); |
249 | aa941b94 | balrog | qemu_get_be32s(f, &s->clkcfg); |
250 | aa941b94 | balrog | qemu_get_be32s(f, &s->pmnc); |
251 | aa941b94 | balrog | |
252 | aa941b94 | balrog | return 0; |
253 | aa941b94 | balrog | } |
254 | aa941b94 | balrog | |
255 | c1713132 | balrog | static uint32_t pxa2xx_clkpwr_read(void *opaque, int op2, int reg, int crm) |
256 | c1713132 | balrog | { |
257 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
258 | c1713132 | balrog | |
259 | c1713132 | balrog | switch (reg) {
|
260 | c1713132 | balrog | case 6: /* Clock Configuration register */ |
261 | c1713132 | balrog | return s->clkcfg;
|
262 | c1713132 | balrog | |
263 | c1713132 | balrog | case 7: /* Power Mode register */ |
264 | c1713132 | balrog | return 0; |
265 | c1713132 | balrog | |
266 | c1713132 | balrog | default:
|
267 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
268 | c1713132 | balrog | break;
|
269 | c1713132 | balrog | } |
270 | c1713132 | balrog | return 0; |
271 | c1713132 | balrog | } |
272 | c1713132 | balrog | |
273 | c1713132 | balrog | static void pxa2xx_clkpwr_write(void *opaque, int op2, int reg, int crm, |
274 | c1713132 | balrog | uint32_t value) |
275 | c1713132 | balrog | { |
276 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
277 | c1713132 | balrog | static const char *pwrmode[8] = { |
278 | c1713132 | balrog | "Normal", "Idle", "Deep-idle", "Standby", |
279 | c1713132 | balrog | "Sleep", "reserved (!)", "reserved (!)", "Deep-sleep", |
280 | c1713132 | balrog | }; |
281 | c1713132 | balrog | |
282 | c1713132 | balrog | switch (reg) {
|
283 | c1713132 | balrog | case 6: /* Clock Configuration register */ |
284 | c1713132 | balrog | s->clkcfg = value & 0xf;
|
285 | c1713132 | balrog | if (value & 2) |
286 | c1713132 | balrog | printf("%s: CPU frequency change attempt\n", __FUNCTION__);
|
287 | c1713132 | balrog | break;
|
288 | c1713132 | balrog | |
289 | c1713132 | balrog | case 7: /* Power Mode register */ |
290 | c1713132 | balrog | if (value & 8) |
291 | c1713132 | balrog | printf("%s: CPU voltage change attempt\n", __FUNCTION__);
|
292 | c1713132 | balrog | switch (value & 7) { |
293 | c1713132 | balrog | case 0: |
294 | c1713132 | balrog | /* Do nothing */
|
295 | c1713132 | balrog | break;
|
296 | c1713132 | balrog | |
297 | c1713132 | balrog | case 1: |
298 | c1713132 | balrog | /* Idle */
|
299 | 82d17978 | balrog | if (!(s->cm_regs[CCCR >> 2] & (1 << 31))) { /* CPDIS */ |
300 | c1713132 | balrog | cpu_interrupt(s->env, CPU_INTERRUPT_HALT); |
301 | c1713132 | balrog | break;
|
302 | c1713132 | balrog | } |
303 | c1713132 | balrog | /* Fall through. */
|
304 | c1713132 | balrog | |
305 | c1713132 | balrog | case 2: |
306 | c1713132 | balrog | /* Deep-Idle */
|
307 | c1713132 | balrog | cpu_interrupt(s->env, CPU_INTERRUPT_HALT); |
308 | c1713132 | balrog | s->pm_regs[RCSR >> 2] |= 0x8; /* Set GPR */ |
309 | c1713132 | balrog | goto message;
|
310 | c1713132 | balrog | |
311 | c1713132 | balrog | case 3: |
312 | a90b7318 | balrog | s->env->uncached_cpsr = |
313 | a90b7318 | balrog | ARM_CPU_MODE_SVC | CPSR_A | CPSR_F | CPSR_I; |
314 | c1713132 | balrog | s->env->cp15.c1_sys = 0;
|
315 | c1713132 | balrog | s->env->cp15.c1_coproc = 0;
|
316 | 9ee6e8bb | pbrook | s->env->cp15.c2_base0 = 0;
|
317 | c1713132 | balrog | s->env->cp15.c3 = 0;
|
318 | c1713132 | balrog | s->pm_regs[PSSR >> 2] |= 0x8; /* Set STS */ |
319 | c1713132 | balrog | s->pm_regs[RCSR >> 2] |= 0x8; /* Set GPR */ |
320 | c1713132 | balrog | |
321 | c1713132 | balrog | /*
|
322 | c1713132 | balrog | * The scratch-pad register is almost universally used
|
323 | c1713132 | balrog | * for storing the return address on suspend. For the
|
324 | c1713132 | balrog | * lack of a resuming bootloader, perform a jump
|
325 | c1713132 | balrog | * directly to that address.
|
326 | c1713132 | balrog | */
|
327 | c1713132 | balrog | memset(s->env->regs, 0, 4 * 15); |
328 | c1713132 | balrog | s->env->regs[15] = s->pm_regs[PSPR >> 2]; |
329 | c1713132 | balrog | |
330 | c1713132 | balrog | #if 0
|
331 | c1713132 | balrog | buffer = 0xe59ff000; /* ldr pc, [pc, #0] */
|
332 | c1713132 | balrog | cpu_physical_memory_write(0, &buffer, 4);
|
333 | c1713132 | balrog | buffer = s->pm_regs[PSPR >> 2];
|
334 | c1713132 | balrog | cpu_physical_memory_write(8, &buffer, 4);
|
335 | c1713132 | balrog | #endif
|
336 | c1713132 | balrog | |
337 | c1713132 | balrog | /* Suspend */
|
338 | c1713132 | balrog | cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT); |
339 | c1713132 | balrog | |
340 | c1713132 | balrog | goto message;
|
341 | c1713132 | balrog | |
342 | c1713132 | balrog | default:
|
343 | c1713132 | balrog | message:
|
344 | c1713132 | balrog | printf("%s: machine entered %s mode\n", __FUNCTION__,
|
345 | c1713132 | balrog | pwrmode[value & 7]);
|
346 | c1713132 | balrog | } |
347 | c1713132 | balrog | break;
|
348 | c1713132 | balrog | |
349 | c1713132 | balrog | default:
|
350 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
351 | c1713132 | balrog | break;
|
352 | c1713132 | balrog | } |
353 | c1713132 | balrog | } |
354 | c1713132 | balrog | |
355 | c1713132 | balrog | /* Performace Monitoring Registers */
|
356 | c1713132 | balrog | #define CPPMNC 0 /* Performance Monitor Control register */ |
357 | c1713132 | balrog | #define CPCCNT 1 /* Clock Counter register */ |
358 | c1713132 | balrog | #define CPINTEN 4 /* Interrupt Enable register */ |
359 | c1713132 | balrog | #define CPFLAG 5 /* Overflow Flag register */ |
360 | c1713132 | balrog | #define CPEVTSEL 8 /* Event Selection register */ |
361 | c1713132 | balrog | |
362 | c1713132 | balrog | #define CPPMN0 0 /* Performance Count register 0 */ |
363 | c1713132 | balrog | #define CPPMN1 1 /* Performance Count register 1 */ |
364 | c1713132 | balrog | #define CPPMN2 2 /* Performance Count register 2 */ |
365 | c1713132 | balrog | #define CPPMN3 3 /* Performance Count register 3 */ |
366 | c1713132 | balrog | |
367 | c1713132 | balrog | static uint32_t pxa2xx_perf_read(void *opaque, int op2, int reg, int crm) |
368 | c1713132 | balrog | { |
369 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
370 | c1713132 | balrog | |
371 | c1713132 | balrog | switch (reg) {
|
372 | c1713132 | balrog | case CPPMNC:
|
373 | c1713132 | balrog | return s->pmnc;
|
374 | c1713132 | balrog | case CPCCNT:
|
375 | c1713132 | balrog | if (s->pmnc & 1) |
376 | c1713132 | balrog | return qemu_get_clock(vm_clock);
|
377 | c1713132 | balrog | else
|
378 | c1713132 | balrog | return 0; |
379 | c1713132 | balrog | case CPINTEN:
|
380 | c1713132 | balrog | case CPFLAG:
|
381 | c1713132 | balrog | case CPEVTSEL:
|
382 | c1713132 | balrog | return 0; |
383 | c1713132 | balrog | |
384 | c1713132 | balrog | default:
|
385 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
386 | c1713132 | balrog | break;
|
387 | c1713132 | balrog | } |
388 | c1713132 | balrog | return 0; |
389 | c1713132 | balrog | } |
390 | c1713132 | balrog | |
391 | c1713132 | balrog | static void pxa2xx_perf_write(void *opaque, int op2, int reg, int crm, |
392 | c1713132 | balrog | uint32_t value) |
393 | c1713132 | balrog | { |
394 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
395 | c1713132 | balrog | |
396 | c1713132 | balrog | switch (reg) {
|
397 | c1713132 | balrog | case CPPMNC:
|
398 | c1713132 | balrog | s->pmnc = value; |
399 | c1713132 | balrog | break;
|
400 | c1713132 | balrog | |
401 | c1713132 | balrog | case CPCCNT:
|
402 | c1713132 | balrog | case CPINTEN:
|
403 | c1713132 | balrog | case CPFLAG:
|
404 | c1713132 | balrog | case CPEVTSEL:
|
405 | c1713132 | balrog | break;
|
406 | c1713132 | balrog | |
407 | c1713132 | balrog | default:
|
408 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
409 | c1713132 | balrog | break;
|
410 | c1713132 | balrog | } |
411 | c1713132 | balrog | } |
412 | c1713132 | balrog | |
413 | c1713132 | balrog | static uint32_t pxa2xx_cp14_read(void *opaque, int op2, int reg, int crm) |
414 | c1713132 | balrog | { |
415 | c1713132 | balrog | switch (crm) {
|
416 | c1713132 | balrog | case 0: |
417 | c1713132 | balrog | return pxa2xx_clkpwr_read(opaque, op2, reg, crm);
|
418 | c1713132 | balrog | case 1: |
419 | c1713132 | balrog | return pxa2xx_perf_read(opaque, op2, reg, crm);
|
420 | c1713132 | balrog | case 2: |
421 | c1713132 | balrog | switch (reg) {
|
422 | c1713132 | balrog | case CPPMN0:
|
423 | c1713132 | balrog | case CPPMN1:
|
424 | c1713132 | balrog | case CPPMN2:
|
425 | c1713132 | balrog | case CPPMN3:
|
426 | c1713132 | balrog | return 0; |
427 | c1713132 | balrog | } |
428 | c1713132 | balrog | /* Fall through */
|
429 | c1713132 | balrog | default:
|
430 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
431 | c1713132 | balrog | break;
|
432 | c1713132 | balrog | } |
433 | c1713132 | balrog | return 0; |
434 | c1713132 | balrog | } |
435 | c1713132 | balrog | |
436 | c1713132 | balrog | static void pxa2xx_cp14_write(void *opaque, int op2, int reg, int crm, |
437 | c1713132 | balrog | uint32_t value) |
438 | c1713132 | balrog | { |
439 | c1713132 | balrog | switch (crm) {
|
440 | c1713132 | balrog | case 0: |
441 | c1713132 | balrog | pxa2xx_clkpwr_write(opaque, op2, reg, crm, value); |
442 | c1713132 | balrog | break;
|
443 | c1713132 | balrog | case 1: |
444 | c1713132 | balrog | pxa2xx_perf_write(opaque, op2, reg, crm, value); |
445 | c1713132 | balrog | break;
|
446 | c1713132 | balrog | case 2: |
447 | c1713132 | balrog | switch (reg) {
|
448 | c1713132 | balrog | case CPPMN0:
|
449 | c1713132 | balrog | case CPPMN1:
|
450 | c1713132 | balrog | case CPPMN2:
|
451 | c1713132 | balrog | case CPPMN3:
|
452 | c1713132 | balrog | return;
|
453 | c1713132 | balrog | } |
454 | c1713132 | balrog | /* Fall through */
|
455 | c1713132 | balrog | default:
|
456 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
457 | c1713132 | balrog | break;
|
458 | c1713132 | balrog | } |
459 | c1713132 | balrog | } |
460 | c1713132 | balrog | |
461 | c1713132 | balrog | #define MDCNFG 0x00 /* SDRAM Configuration register */ |
462 | c1713132 | balrog | #define MDREFR 0x04 /* SDRAM Refresh Control register */ |
463 | c1713132 | balrog | #define MSC0 0x08 /* Static Memory Control register 0 */ |
464 | c1713132 | balrog | #define MSC1 0x0c /* Static Memory Control register 1 */ |
465 | c1713132 | balrog | #define MSC2 0x10 /* Static Memory Control register 2 */ |
466 | c1713132 | balrog | #define MECR 0x14 /* Expansion Memory Bus Config register */ |
467 | c1713132 | balrog | #define SXCNFG 0x1c /* Synchronous Static Memory Config register */ |
468 | c1713132 | balrog | #define MCMEM0 0x28 /* PC Card Memory Socket 0 Timing register */ |
469 | c1713132 | balrog | #define MCMEM1 0x2c /* PC Card Memory Socket 1 Timing register */ |
470 | c1713132 | balrog | #define MCATT0 0x30 /* PC Card Attribute Socket 0 register */ |
471 | c1713132 | balrog | #define MCATT1 0x34 /* PC Card Attribute Socket 1 register */ |
472 | c1713132 | balrog | #define MCIO0 0x38 /* PC Card I/O Socket 0 Timing register */ |
473 | c1713132 | balrog | #define MCIO1 0x3c /* PC Card I/O Socket 1 Timing register */ |
474 | c1713132 | balrog | #define MDMRS 0x40 /* SDRAM Mode Register Set Config register */ |
475 | c1713132 | balrog | #define BOOT_DEF 0x44 /* Boot-time Default Configuration register */ |
476 | c1713132 | balrog | #define ARB_CNTL 0x48 /* Arbiter Control register */ |
477 | c1713132 | balrog | #define BSCNTR0 0x4c /* Memory Buffer Strength Control register 0 */ |
478 | c1713132 | balrog | #define BSCNTR1 0x50 /* Memory Buffer Strength Control register 1 */ |
479 | c1713132 | balrog | #define LCDBSCNTR 0x54 /* LCD Buffer Strength Control register */ |
480 | c1713132 | balrog | #define MDMRSLP 0x58 /* Low Power SDRAM Mode Set Config register */ |
481 | c1713132 | balrog | #define BSCNTR2 0x5c /* Memory Buffer Strength Control register 2 */ |
482 | c1713132 | balrog | #define BSCNTR3 0x60 /* Memory Buffer Strength Control register 3 */ |
483 | c1713132 | balrog | #define SA1110 0x64 /* SA-1110 Memory Compatibility register */ |
484 | c1713132 | balrog | |
485 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_mm_read(void *opaque, target_phys_addr_t addr) |
486 | c1713132 | balrog | { |
487 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
488 | c1713132 | balrog | |
489 | c1713132 | balrog | switch (addr) {
|
490 | c1713132 | balrog | case MDCNFG ... SA1110:
|
491 | c1713132 | balrog | if ((addr & 3) == 0) |
492 | c1713132 | balrog | return s->mm_regs[addr >> 2]; |
493 | c1713132 | balrog | |
494 | c1713132 | balrog | default:
|
495 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
496 | c1713132 | balrog | break;
|
497 | c1713132 | balrog | } |
498 | c1713132 | balrog | return 0; |
499 | c1713132 | balrog | } |
500 | c1713132 | balrog | |
501 | c227f099 | Anthony Liguori | static void pxa2xx_mm_write(void *opaque, target_phys_addr_t addr, |
502 | c1713132 | balrog | uint32_t value) |
503 | c1713132 | balrog | { |
504 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
505 | c1713132 | balrog | |
506 | c1713132 | balrog | switch (addr) {
|
507 | c1713132 | balrog | case MDCNFG ... SA1110:
|
508 | c1713132 | balrog | if ((addr & 3) == 0) { |
509 | c1713132 | balrog | s->mm_regs[addr >> 2] = value;
|
510 | c1713132 | balrog | break;
|
511 | c1713132 | balrog | } |
512 | c1713132 | balrog | |
513 | c1713132 | balrog | default:
|
514 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
515 | c1713132 | balrog | break;
|
516 | c1713132 | balrog | } |
517 | c1713132 | balrog | } |
518 | c1713132 | balrog | |
519 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_mm_readfn[] = { |
520 | c1713132 | balrog | pxa2xx_mm_read, |
521 | c1713132 | balrog | pxa2xx_mm_read, |
522 | c1713132 | balrog | pxa2xx_mm_read, |
523 | c1713132 | balrog | }; |
524 | c1713132 | balrog | |
525 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_mm_writefn[] = { |
526 | c1713132 | balrog | pxa2xx_mm_write, |
527 | c1713132 | balrog | pxa2xx_mm_write, |
528 | c1713132 | balrog | pxa2xx_mm_write, |
529 | c1713132 | balrog | }; |
530 | c1713132 | balrog | |
531 | aa941b94 | balrog | static void pxa2xx_mm_save(QEMUFile *f, void *opaque) |
532 | aa941b94 | balrog | { |
533 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
534 | aa941b94 | balrog | int i;
|
535 | aa941b94 | balrog | |
536 | aa941b94 | balrog | for (i = 0; i < 0x1a; i ++) |
537 | aa941b94 | balrog | qemu_put_be32s(f, &s->mm_regs[i]); |
538 | aa941b94 | balrog | } |
539 | aa941b94 | balrog | |
540 | aa941b94 | balrog | static int pxa2xx_mm_load(QEMUFile *f, void *opaque, int version_id) |
541 | aa941b94 | balrog | { |
542 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
543 | aa941b94 | balrog | int i;
|
544 | aa941b94 | balrog | |
545 | aa941b94 | balrog | for (i = 0; i < 0x1a; i ++) |
546 | aa941b94 | balrog | qemu_get_be32s(f, &s->mm_regs[i]); |
547 | aa941b94 | balrog | |
548 | aa941b94 | balrog | return 0; |
549 | aa941b94 | balrog | } |
550 | aa941b94 | balrog | |
551 | c1713132 | balrog | /* Synchronous Serial Ports */
|
552 | a984a69e | Paul Brook | typedef struct { |
553 | a984a69e | Paul Brook | SysBusDevice busdev; |
554 | c1713132 | balrog | qemu_irq irq; |
555 | c1713132 | balrog | int enable;
|
556 | a984a69e | Paul Brook | SSIBus *bus; |
557 | c1713132 | balrog | |
558 | c1713132 | balrog | uint32_t sscr[2];
|
559 | c1713132 | balrog | uint32_t sspsp; |
560 | c1713132 | balrog | uint32_t ssto; |
561 | c1713132 | balrog | uint32_t ssitr; |
562 | c1713132 | balrog | uint32_t sssr; |
563 | c1713132 | balrog | uint8_t sstsa; |
564 | c1713132 | balrog | uint8_t ssrsa; |
565 | c1713132 | balrog | uint8_t ssacd; |
566 | c1713132 | balrog | |
567 | c1713132 | balrog | uint32_t rx_fifo[16];
|
568 | c1713132 | balrog | int rx_level;
|
569 | c1713132 | balrog | int rx_start;
|
570 | a984a69e | Paul Brook | } PXA2xxSSPState; |
571 | c1713132 | balrog | |
572 | c1713132 | balrog | #define SSCR0 0x00 /* SSP Control register 0 */ |
573 | c1713132 | balrog | #define SSCR1 0x04 /* SSP Control register 1 */ |
574 | c1713132 | balrog | #define SSSR 0x08 /* SSP Status register */ |
575 | c1713132 | balrog | #define SSITR 0x0c /* SSP Interrupt Test register */ |
576 | c1713132 | balrog | #define SSDR 0x10 /* SSP Data register */ |
577 | c1713132 | balrog | #define SSTO 0x28 /* SSP Time-Out register */ |
578 | c1713132 | balrog | #define SSPSP 0x2c /* SSP Programmable Serial Protocol register */ |
579 | c1713132 | balrog | #define SSTSA 0x30 /* SSP TX Time Slot Active register */ |
580 | c1713132 | balrog | #define SSRSA 0x34 /* SSP RX Time Slot Active register */ |
581 | c1713132 | balrog | #define SSTSS 0x38 /* SSP Time Slot Status register */ |
582 | c1713132 | balrog | #define SSACD 0x3c /* SSP Audio Clock Divider register */ |
583 | c1713132 | balrog | |
584 | c1713132 | balrog | /* Bitfields for above registers */
|
585 | c1713132 | balrog | #define SSCR0_SPI(x) (((x) & 0x30) == 0x00) |
586 | c1713132 | balrog | #define SSCR0_SSP(x) (((x) & 0x30) == 0x10) |
587 | c1713132 | balrog | #define SSCR0_UWIRE(x) (((x) & 0x30) == 0x20) |
588 | c1713132 | balrog | #define SSCR0_PSP(x) (((x) & 0x30) == 0x30) |
589 | c1713132 | balrog | #define SSCR0_SSE (1 << 7) |
590 | c1713132 | balrog | #define SSCR0_RIM (1 << 22) |
591 | c1713132 | balrog | #define SSCR0_TIM (1 << 23) |
592 | c1713132 | balrog | #define SSCR0_MOD (1 << 31) |
593 | c1713132 | balrog | #define SSCR0_DSS(x) (((((x) >> 16) & 0x10) | ((x) & 0xf)) + 1) |
594 | c1713132 | balrog | #define SSCR1_RIE (1 << 0) |
595 | c1713132 | balrog | #define SSCR1_TIE (1 << 1) |
596 | c1713132 | balrog | #define SSCR1_LBM (1 << 2) |
597 | c1713132 | balrog | #define SSCR1_MWDS (1 << 5) |
598 | c1713132 | balrog | #define SSCR1_TFT(x) ((((x) >> 6) & 0xf) + 1) |
599 | c1713132 | balrog | #define SSCR1_RFT(x) ((((x) >> 10) & 0xf) + 1) |
600 | c1713132 | balrog | #define SSCR1_EFWR (1 << 14) |
601 | c1713132 | balrog | #define SSCR1_PINTE (1 << 18) |
602 | c1713132 | balrog | #define SSCR1_TINTE (1 << 19) |
603 | c1713132 | balrog | #define SSCR1_RSRE (1 << 20) |
604 | c1713132 | balrog | #define SSCR1_TSRE (1 << 21) |
605 | c1713132 | balrog | #define SSCR1_EBCEI (1 << 29) |
606 | c1713132 | balrog | #define SSITR_INT (7 << 5) |
607 | c1713132 | balrog | #define SSSR_TNF (1 << 2) |
608 | c1713132 | balrog | #define SSSR_RNE (1 << 3) |
609 | c1713132 | balrog | #define SSSR_TFS (1 << 5) |
610 | c1713132 | balrog | #define SSSR_RFS (1 << 6) |
611 | c1713132 | balrog | #define SSSR_ROR (1 << 7) |
612 | c1713132 | balrog | #define SSSR_PINT (1 << 18) |
613 | c1713132 | balrog | #define SSSR_TINT (1 << 19) |
614 | c1713132 | balrog | #define SSSR_EOC (1 << 20) |
615 | c1713132 | balrog | #define SSSR_TUR (1 << 21) |
616 | c1713132 | balrog | #define SSSR_BCE (1 << 23) |
617 | c1713132 | balrog | #define SSSR_RW 0x00bc0080 |
618 | c1713132 | balrog | |
619 | bc24a225 | Paul Brook | static void pxa2xx_ssp_int_update(PXA2xxSSPState *s) |
620 | c1713132 | balrog | { |
621 | c1713132 | balrog | int level = 0; |
622 | c1713132 | balrog | |
623 | c1713132 | balrog | level |= s->ssitr & SSITR_INT; |
624 | c1713132 | balrog | level |= (s->sssr & SSSR_BCE) && (s->sscr[1] & SSCR1_EBCEI);
|
625 | c1713132 | balrog | level |= (s->sssr & SSSR_TUR) && !(s->sscr[0] & SSCR0_TIM);
|
626 | c1713132 | balrog | level |= (s->sssr & SSSR_EOC) && (s->sssr & (SSSR_TINT | SSSR_PINT)); |
627 | c1713132 | balrog | level |= (s->sssr & SSSR_TINT) && (s->sscr[1] & SSCR1_TINTE);
|
628 | c1713132 | balrog | level |= (s->sssr & SSSR_PINT) && (s->sscr[1] & SSCR1_PINTE);
|
629 | c1713132 | balrog | level |= (s->sssr & SSSR_ROR) && !(s->sscr[0] & SSCR0_RIM);
|
630 | c1713132 | balrog | level |= (s->sssr & SSSR_RFS) && (s->sscr[1] & SSCR1_RIE);
|
631 | c1713132 | balrog | level |= (s->sssr & SSSR_TFS) && (s->sscr[1] & SSCR1_TIE);
|
632 | c1713132 | balrog | qemu_set_irq(s->irq, !!level); |
633 | c1713132 | balrog | } |
634 | c1713132 | balrog | |
635 | bc24a225 | Paul Brook | static void pxa2xx_ssp_fifo_update(PXA2xxSSPState *s) |
636 | c1713132 | balrog | { |
637 | c1713132 | balrog | s->sssr &= ~(0xf << 12); /* Clear RFL */ |
638 | c1713132 | balrog | s->sssr &= ~(0xf << 8); /* Clear TFL */ |
639 | c1713132 | balrog | s->sssr &= ~SSSR_TNF; |
640 | c1713132 | balrog | if (s->enable) {
|
641 | c1713132 | balrog | s->sssr |= ((s->rx_level - 1) & 0xf) << 12; |
642 | c1713132 | balrog | if (s->rx_level >= SSCR1_RFT(s->sscr[1])) |
643 | c1713132 | balrog | s->sssr |= SSSR_RFS; |
644 | c1713132 | balrog | else
|
645 | c1713132 | balrog | s->sssr &= ~SSSR_RFS; |
646 | c1713132 | balrog | if (0 <= SSCR1_TFT(s->sscr[1])) |
647 | c1713132 | balrog | s->sssr |= SSSR_TFS; |
648 | c1713132 | balrog | else
|
649 | c1713132 | balrog | s->sssr &= ~SSSR_TFS; |
650 | c1713132 | balrog | if (s->rx_level)
|
651 | c1713132 | balrog | s->sssr |= SSSR_RNE; |
652 | c1713132 | balrog | else
|
653 | c1713132 | balrog | s->sssr &= ~SSSR_RNE; |
654 | c1713132 | balrog | s->sssr |= SSSR_TNF; |
655 | c1713132 | balrog | } |
656 | c1713132 | balrog | |
657 | c1713132 | balrog | pxa2xx_ssp_int_update(s); |
658 | c1713132 | balrog | } |
659 | c1713132 | balrog | |
660 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_ssp_read(void *opaque, target_phys_addr_t addr) |
661 | c1713132 | balrog | { |
662 | bc24a225 | Paul Brook | PXA2xxSSPState *s = (PXA2xxSSPState *) opaque; |
663 | c1713132 | balrog | uint32_t retval; |
664 | c1713132 | balrog | |
665 | c1713132 | balrog | switch (addr) {
|
666 | c1713132 | balrog | case SSCR0:
|
667 | c1713132 | balrog | return s->sscr[0]; |
668 | c1713132 | balrog | case SSCR1:
|
669 | c1713132 | balrog | return s->sscr[1]; |
670 | c1713132 | balrog | case SSPSP:
|
671 | c1713132 | balrog | return s->sspsp;
|
672 | c1713132 | balrog | case SSTO:
|
673 | c1713132 | balrog | return s->ssto;
|
674 | c1713132 | balrog | case SSITR:
|
675 | c1713132 | balrog | return s->ssitr;
|
676 | c1713132 | balrog | case SSSR:
|
677 | c1713132 | balrog | return s->sssr | s->ssitr;
|
678 | c1713132 | balrog | case SSDR:
|
679 | c1713132 | balrog | if (!s->enable)
|
680 | c1713132 | balrog | return 0xffffffff; |
681 | c1713132 | balrog | if (s->rx_level < 1) { |
682 | c1713132 | balrog | printf("%s: SSP Rx Underrun\n", __FUNCTION__);
|
683 | c1713132 | balrog | return 0xffffffff; |
684 | c1713132 | balrog | } |
685 | c1713132 | balrog | s->rx_level --; |
686 | c1713132 | balrog | retval = s->rx_fifo[s->rx_start ++]; |
687 | c1713132 | balrog | s->rx_start &= 0xf;
|
688 | c1713132 | balrog | pxa2xx_ssp_fifo_update(s); |
689 | c1713132 | balrog | return retval;
|
690 | c1713132 | balrog | case SSTSA:
|
691 | c1713132 | balrog | return s->sstsa;
|
692 | c1713132 | balrog | case SSRSA:
|
693 | c1713132 | balrog | return s->ssrsa;
|
694 | c1713132 | balrog | case SSTSS:
|
695 | c1713132 | balrog | return 0; |
696 | c1713132 | balrog | case SSACD:
|
697 | c1713132 | balrog | return s->ssacd;
|
698 | c1713132 | balrog | default:
|
699 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
700 | c1713132 | balrog | break;
|
701 | c1713132 | balrog | } |
702 | c1713132 | balrog | return 0; |
703 | c1713132 | balrog | } |
704 | c1713132 | balrog | |
705 | c227f099 | Anthony Liguori | static void pxa2xx_ssp_write(void *opaque, target_phys_addr_t addr, |
706 | c1713132 | balrog | uint32_t value) |
707 | c1713132 | balrog | { |
708 | bc24a225 | Paul Brook | PXA2xxSSPState *s = (PXA2xxSSPState *) opaque; |
709 | c1713132 | balrog | |
710 | c1713132 | balrog | switch (addr) {
|
711 | c1713132 | balrog | case SSCR0:
|
712 | c1713132 | balrog | s->sscr[0] = value & 0xc7ffffff; |
713 | c1713132 | balrog | s->enable = value & SSCR0_SSE; |
714 | c1713132 | balrog | if (value & SSCR0_MOD)
|
715 | c1713132 | balrog | printf("%s: Attempt to use network mode\n", __FUNCTION__);
|
716 | c1713132 | balrog | if (s->enable && SSCR0_DSS(value) < 4) |
717 | c1713132 | balrog | printf("%s: Wrong data size: %i bits\n", __FUNCTION__,
|
718 | c1713132 | balrog | SSCR0_DSS(value)); |
719 | c1713132 | balrog | if (!(value & SSCR0_SSE)) {
|
720 | c1713132 | balrog | s->sssr = 0;
|
721 | c1713132 | balrog | s->ssitr = 0;
|
722 | c1713132 | balrog | s->rx_level = 0;
|
723 | c1713132 | balrog | } |
724 | c1713132 | balrog | pxa2xx_ssp_fifo_update(s); |
725 | c1713132 | balrog | break;
|
726 | c1713132 | balrog | |
727 | c1713132 | balrog | case SSCR1:
|
728 | c1713132 | balrog | s->sscr[1] = value;
|
729 | c1713132 | balrog | if (value & (SSCR1_LBM | SSCR1_EFWR))
|
730 | c1713132 | balrog | printf("%s: Attempt to use SSP test mode\n", __FUNCTION__);
|
731 | c1713132 | balrog | pxa2xx_ssp_fifo_update(s); |
732 | c1713132 | balrog | break;
|
733 | c1713132 | balrog | |
734 | c1713132 | balrog | case SSPSP:
|
735 | c1713132 | balrog | s->sspsp = value; |
736 | c1713132 | balrog | break;
|
737 | c1713132 | balrog | |
738 | c1713132 | balrog | case SSTO:
|
739 | c1713132 | balrog | s->ssto = value; |
740 | c1713132 | balrog | break;
|
741 | c1713132 | balrog | |
742 | c1713132 | balrog | case SSITR:
|
743 | c1713132 | balrog | s->ssitr = value & SSITR_INT; |
744 | c1713132 | balrog | pxa2xx_ssp_int_update(s); |
745 | c1713132 | balrog | break;
|
746 | c1713132 | balrog | |
747 | c1713132 | balrog | case SSSR:
|
748 | c1713132 | balrog | s->sssr &= ~(value & SSSR_RW); |
749 | c1713132 | balrog | pxa2xx_ssp_int_update(s); |
750 | c1713132 | balrog | break;
|
751 | c1713132 | balrog | |
752 | c1713132 | balrog | case SSDR:
|
753 | c1713132 | balrog | if (SSCR0_UWIRE(s->sscr[0])) { |
754 | c1713132 | balrog | if (s->sscr[1] & SSCR1_MWDS) |
755 | c1713132 | balrog | value &= 0xffff;
|
756 | c1713132 | balrog | else
|
757 | c1713132 | balrog | value &= 0xff;
|
758 | c1713132 | balrog | } else
|
759 | c1713132 | balrog | /* Note how 32bits overflow does no harm here */
|
760 | c1713132 | balrog | value &= (1 << SSCR0_DSS(s->sscr[0])) - 1; |
761 | c1713132 | balrog | |
762 | c1713132 | balrog | /* Data goes from here to the Tx FIFO and is shifted out from
|
763 | c1713132 | balrog | * there directly to the slave, no need to buffer it.
|
764 | c1713132 | balrog | */
|
765 | c1713132 | balrog | if (s->enable) {
|
766 | a984a69e | Paul Brook | uint32_t readval; |
767 | a984a69e | Paul Brook | readval = ssi_transfer(s->bus, value); |
768 | c1713132 | balrog | if (s->rx_level < 0x10) { |
769 | a984a69e | Paul Brook | s->rx_fifo[(s->rx_start + s->rx_level ++) & 0xf] = readval;
|
770 | a984a69e | Paul Brook | } else {
|
771 | c1713132 | balrog | s->sssr |= SSSR_ROR; |
772 | a984a69e | Paul Brook | } |
773 | c1713132 | balrog | } |
774 | c1713132 | balrog | pxa2xx_ssp_fifo_update(s); |
775 | c1713132 | balrog | break;
|
776 | c1713132 | balrog | |
777 | c1713132 | balrog | case SSTSA:
|
778 | c1713132 | balrog | s->sstsa = value; |
779 | c1713132 | balrog | break;
|
780 | c1713132 | balrog | |
781 | c1713132 | balrog | case SSRSA:
|
782 | c1713132 | balrog | s->ssrsa = value; |
783 | c1713132 | balrog | break;
|
784 | c1713132 | balrog | |
785 | c1713132 | balrog | case SSACD:
|
786 | c1713132 | balrog | s->ssacd = value; |
787 | c1713132 | balrog | break;
|
788 | c1713132 | balrog | |
789 | c1713132 | balrog | default:
|
790 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
791 | c1713132 | balrog | break;
|
792 | c1713132 | balrog | } |
793 | c1713132 | balrog | } |
794 | c1713132 | balrog | |
795 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_ssp_readfn[] = { |
796 | c1713132 | balrog | pxa2xx_ssp_read, |
797 | c1713132 | balrog | pxa2xx_ssp_read, |
798 | c1713132 | balrog | pxa2xx_ssp_read, |
799 | c1713132 | balrog | }; |
800 | c1713132 | balrog | |
801 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_ssp_writefn[] = { |
802 | c1713132 | balrog | pxa2xx_ssp_write, |
803 | c1713132 | balrog | pxa2xx_ssp_write, |
804 | c1713132 | balrog | pxa2xx_ssp_write, |
805 | c1713132 | balrog | }; |
806 | c1713132 | balrog | |
807 | aa941b94 | balrog | static void pxa2xx_ssp_save(QEMUFile *f, void *opaque) |
808 | aa941b94 | balrog | { |
809 | bc24a225 | Paul Brook | PXA2xxSSPState *s = (PXA2xxSSPState *) opaque; |
810 | aa941b94 | balrog | int i;
|
811 | aa941b94 | balrog | |
812 | aa941b94 | balrog | qemu_put_be32(f, s->enable); |
813 | aa941b94 | balrog | |
814 | aa941b94 | balrog | qemu_put_be32s(f, &s->sscr[0]);
|
815 | aa941b94 | balrog | qemu_put_be32s(f, &s->sscr[1]);
|
816 | aa941b94 | balrog | qemu_put_be32s(f, &s->sspsp); |
817 | aa941b94 | balrog | qemu_put_be32s(f, &s->ssto); |
818 | aa941b94 | balrog | qemu_put_be32s(f, &s->ssitr); |
819 | aa941b94 | balrog | qemu_put_be32s(f, &s->sssr); |
820 | aa941b94 | balrog | qemu_put_8s(f, &s->sstsa); |
821 | aa941b94 | balrog | qemu_put_8s(f, &s->ssrsa); |
822 | aa941b94 | balrog | qemu_put_8s(f, &s->ssacd); |
823 | aa941b94 | balrog | |
824 | aa941b94 | balrog | qemu_put_byte(f, s->rx_level); |
825 | aa941b94 | balrog | for (i = 0; i < s->rx_level; i ++) |
826 | aa941b94 | balrog | qemu_put_byte(f, s->rx_fifo[(s->rx_start + i) & 0xf]);
|
827 | aa941b94 | balrog | } |
828 | aa941b94 | balrog | |
829 | aa941b94 | balrog | static int pxa2xx_ssp_load(QEMUFile *f, void *opaque, int version_id) |
830 | aa941b94 | balrog | { |
831 | bc24a225 | Paul Brook | PXA2xxSSPState *s = (PXA2xxSSPState *) opaque; |
832 | aa941b94 | balrog | int i;
|
833 | aa941b94 | balrog | |
834 | aa941b94 | balrog | s->enable = qemu_get_be32(f); |
835 | aa941b94 | balrog | |
836 | aa941b94 | balrog | qemu_get_be32s(f, &s->sscr[0]);
|
837 | aa941b94 | balrog | qemu_get_be32s(f, &s->sscr[1]);
|
838 | aa941b94 | balrog | qemu_get_be32s(f, &s->sspsp); |
839 | aa941b94 | balrog | qemu_get_be32s(f, &s->ssto); |
840 | aa941b94 | balrog | qemu_get_be32s(f, &s->ssitr); |
841 | aa941b94 | balrog | qemu_get_be32s(f, &s->sssr); |
842 | aa941b94 | balrog | qemu_get_8s(f, &s->sstsa); |
843 | aa941b94 | balrog | qemu_get_8s(f, &s->ssrsa); |
844 | aa941b94 | balrog | qemu_get_8s(f, &s->ssacd); |
845 | aa941b94 | balrog | |
846 | aa941b94 | balrog | s->rx_level = qemu_get_byte(f); |
847 | aa941b94 | balrog | s->rx_start = 0;
|
848 | aa941b94 | balrog | for (i = 0; i < s->rx_level; i ++) |
849 | aa941b94 | balrog | s->rx_fifo[i] = qemu_get_byte(f); |
850 | aa941b94 | balrog | |
851 | aa941b94 | balrog | return 0; |
852 | aa941b94 | balrog | } |
853 | aa941b94 | balrog | |
854 | 81a322d4 | Gerd Hoffmann | static int pxa2xx_ssp_init(SysBusDevice *dev) |
855 | a984a69e | Paul Brook | { |
856 | a984a69e | Paul Brook | int iomemtype;
|
857 | a984a69e | Paul Brook | PXA2xxSSPState *s = FROM_SYSBUS(PXA2xxSSPState, dev); |
858 | a984a69e | Paul Brook | |
859 | a984a69e | Paul Brook | sysbus_init_irq(dev, &s->irq); |
860 | a984a69e | Paul Brook | |
861 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_ssp_readfn, |
862 | a984a69e | Paul Brook | pxa2xx_ssp_writefn, s); |
863 | a984a69e | Paul Brook | sysbus_init_mmio(dev, 0x1000, iomemtype);
|
864 | 0be71e32 | Alex Williamson | register_savevm(&dev->qdev, "pxa2xx_ssp", -1, 0, |
865 | a984a69e | Paul Brook | pxa2xx_ssp_save, pxa2xx_ssp_load, s); |
866 | a984a69e | Paul Brook | |
867 | 02e2da45 | Paul Brook | s->bus = ssi_create_bus(&dev->qdev, "ssi");
|
868 | 81a322d4 | Gerd Hoffmann | return 0; |
869 | a984a69e | Paul Brook | } |
870 | a984a69e | Paul Brook | |
871 | c1713132 | balrog | /* Real-Time Clock */
|
872 | c1713132 | balrog | #define RCNR 0x00 /* RTC Counter register */ |
873 | c1713132 | balrog | #define RTAR 0x04 /* RTC Alarm register */ |
874 | c1713132 | balrog | #define RTSR 0x08 /* RTC Status register */ |
875 | c1713132 | balrog | #define RTTR 0x0c /* RTC Timer Trim register */ |
876 | c1713132 | balrog | #define RDCR 0x10 /* RTC Day Counter register */ |
877 | c1713132 | balrog | #define RYCR 0x14 /* RTC Year Counter register */ |
878 | c1713132 | balrog | #define RDAR1 0x18 /* RTC Wristwatch Day Alarm register 1 */ |
879 | c1713132 | balrog | #define RYAR1 0x1c /* RTC Wristwatch Year Alarm register 1 */ |
880 | c1713132 | balrog | #define RDAR2 0x20 /* RTC Wristwatch Day Alarm register 2 */ |
881 | c1713132 | balrog | #define RYAR2 0x24 /* RTC Wristwatch Year Alarm register 2 */ |
882 | c1713132 | balrog | #define SWCR 0x28 /* RTC Stopwatch Counter register */ |
883 | c1713132 | balrog | #define SWAR1 0x2c /* RTC Stopwatch Alarm register 1 */ |
884 | c1713132 | balrog | #define SWAR2 0x30 /* RTC Stopwatch Alarm register 2 */ |
885 | c1713132 | balrog | #define RTCPICR 0x34 /* RTC Periodic Interrupt Counter register */ |
886 | c1713132 | balrog | #define PIAR 0x38 /* RTC Periodic Interrupt Alarm register */ |
887 | c1713132 | balrog | |
888 | bc24a225 | Paul Brook | static inline void pxa2xx_rtc_int_update(PXA2xxState *s) |
889 | c1713132 | balrog | { |
890 | c1713132 | balrog | qemu_set_irq(s->pic[PXA2XX_PIC_RTCALARM], !!(s->rtsr & 0x2553));
|
891 | c1713132 | balrog | } |
892 | c1713132 | balrog | |
893 | bc24a225 | Paul Brook | static void pxa2xx_rtc_hzupdate(PXA2xxState *s) |
894 | c1713132 | balrog | { |
895 | c1713132 | balrog | int64_t rt = qemu_get_clock(rt_clock); |
896 | c1713132 | balrog | s->last_rcnr += ((rt - s->last_hz) << 15) /
|
897 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
898 | c1713132 | balrog | s->last_rdcr += ((rt - s->last_hz) << 15) /
|
899 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
900 | c1713132 | balrog | s->last_hz = rt; |
901 | c1713132 | balrog | } |
902 | c1713132 | balrog | |
903 | bc24a225 | Paul Brook | static void pxa2xx_rtc_swupdate(PXA2xxState *s) |
904 | c1713132 | balrog | { |
905 | c1713132 | balrog | int64_t rt = qemu_get_clock(rt_clock); |
906 | c1713132 | balrog | if (s->rtsr & (1 << 12)) |
907 | c1713132 | balrog | s->last_swcr += (rt - s->last_sw) / 10;
|
908 | c1713132 | balrog | s->last_sw = rt; |
909 | c1713132 | balrog | } |
910 | c1713132 | balrog | |
911 | bc24a225 | Paul Brook | static void pxa2xx_rtc_piupdate(PXA2xxState *s) |
912 | c1713132 | balrog | { |
913 | c1713132 | balrog | int64_t rt = qemu_get_clock(rt_clock); |
914 | c1713132 | balrog | if (s->rtsr & (1 << 15)) |
915 | c1713132 | balrog | s->last_swcr += rt - s->last_pi; |
916 | c1713132 | balrog | s->last_pi = rt; |
917 | c1713132 | balrog | } |
918 | c1713132 | balrog | |
919 | bc24a225 | Paul Brook | static inline void pxa2xx_rtc_alarm_update(PXA2xxState *s, |
920 | c1713132 | balrog | uint32_t rtsr) |
921 | c1713132 | balrog | { |
922 | c1713132 | balrog | if ((rtsr & (1 << 2)) && !(rtsr & (1 << 0))) |
923 | c1713132 | balrog | qemu_mod_timer(s->rtc_hz, s->last_hz + |
924 | c1713132 | balrog | (((s->rtar - s->last_rcnr) * 1000 *
|
925 | c1713132 | balrog | ((s->rttr & 0xffff) + 1)) >> 15)); |
926 | c1713132 | balrog | else
|
927 | c1713132 | balrog | qemu_del_timer(s->rtc_hz); |
928 | c1713132 | balrog | |
929 | c1713132 | balrog | if ((rtsr & (1 << 5)) && !(rtsr & (1 << 4))) |
930 | c1713132 | balrog | qemu_mod_timer(s->rtc_rdal1, s->last_hz + |
931 | c1713132 | balrog | (((s->rdar1 - s->last_rdcr) * 1000 *
|
932 | c1713132 | balrog | ((s->rttr & 0xffff) + 1)) >> 15)); /* TODO: fixup */ |
933 | c1713132 | balrog | else
|
934 | c1713132 | balrog | qemu_del_timer(s->rtc_rdal1); |
935 | c1713132 | balrog | |
936 | c1713132 | balrog | if ((rtsr & (1 << 7)) && !(rtsr & (1 << 6))) |
937 | c1713132 | balrog | qemu_mod_timer(s->rtc_rdal2, s->last_hz + |
938 | c1713132 | balrog | (((s->rdar2 - s->last_rdcr) * 1000 *
|
939 | c1713132 | balrog | ((s->rttr & 0xffff) + 1)) >> 15)); /* TODO: fixup */ |
940 | c1713132 | balrog | else
|
941 | c1713132 | balrog | qemu_del_timer(s->rtc_rdal2); |
942 | c1713132 | balrog | |
943 | c1713132 | balrog | if ((rtsr & 0x1200) == 0x1200 && !(rtsr & (1 << 8))) |
944 | c1713132 | balrog | qemu_mod_timer(s->rtc_swal1, s->last_sw + |
945 | c1713132 | balrog | (s->swar1 - s->last_swcr) * 10); /* TODO: fixup */ |
946 | c1713132 | balrog | else
|
947 | c1713132 | balrog | qemu_del_timer(s->rtc_swal1); |
948 | c1713132 | balrog | |
949 | c1713132 | balrog | if ((rtsr & 0x1800) == 0x1800 && !(rtsr & (1 << 10))) |
950 | c1713132 | balrog | qemu_mod_timer(s->rtc_swal2, s->last_sw + |
951 | c1713132 | balrog | (s->swar2 - s->last_swcr) * 10); /* TODO: fixup */ |
952 | c1713132 | balrog | else
|
953 | c1713132 | balrog | qemu_del_timer(s->rtc_swal2); |
954 | c1713132 | balrog | |
955 | c1713132 | balrog | if ((rtsr & 0xc000) == 0xc000 && !(rtsr & (1 << 13))) |
956 | c1713132 | balrog | qemu_mod_timer(s->rtc_pi, s->last_pi + |
957 | c1713132 | balrog | (s->piar & 0xffff) - s->last_rtcpicr);
|
958 | c1713132 | balrog | else
|
959 | c1713132 | balrog | qemu_del_timer(s->rtc_pi); |
960 | c1713132 | balrog | } |
961 | c1713132 | balrog | |
962 | c1713132 | balrog | static inline void pxa2xx_rtc_hz_tick(void *opaque) |
963 | c1713132 | balrog | { |
964 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
965 | c1713132 | balrog | s->rtsr |= (1 << 0); |
966 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
967 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
968 | c1713132 | balrog | } |
969 | c1713132 | balrog | |
970 | c1713132 | balrog | static inline void pxa2xx_rtc_rdal1_tick(void *opaque) |
971 | c1713132 | balrog | { |
972 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
973 | c1713132 | balrog | s->rtsr |= (1 << 4); |
974 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
975 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
976 | c1713132 | balrog | } |
977 | c1713132 | balrog | |
978 | c1713132 | balrog | static inline void pxa2xx_rtc_rdal2_tick(void *opaque) |
979 | c1713132 | balrog | { |
980 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
981 | c1713132 | balrog | s->rtsr |= (1 << 6); |
982 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
983 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
984 | c1713132 | balrog | } |
985 | c1713132 | balrog | |
986 | c1713132 | balrog | static inline void pxa2xx_rtc_swal1_tick(void *opaque) |
987 | c1713132 | balrog | { |
988 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
989 | c1713132 | balrog | s->rtsr |= (1 << 8); |
990 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
991 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
992 | c1713132 | balrog | } |
993 | c1713132 | balrog | |
994 | c1713132 | balrog | static inline void pxa2xx_rtc_swal2_tick(void *opaque) |
995 | c1713132 | balrog | { |
996 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
997 | c1713132 | balrog | s->rtsr |= (1 << 10); |
998 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
999 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
1000 | c1713132 | balrog | } |
1001 | c1713132 | balrog | |
1002 | c1713132 | balrog | static inline void pxa2xx_rtc_pi_tick(void *opaque) |
1003 | c1713132 | balrog | { |
1004 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1005 | c1713132 | balrog | s->rtsr |= (1 << 13); |
1006 | c1713132 | balrog | pxa2xx_rtc_piupdate(s); |
1007 | c1713132 | balrog | s->last_rtcpicr = 0;
|
1008 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1009 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
1010 | c1713132 | balrog | } |
1011 | c1713132 | balrog | |
1012 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_rtc_read(void *opaque, target_phys_addr_t addr) |
1013 | c1713132 | balrog | { |
1014 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1015 | c1713132 | balrog | |
1016 | c1713132 | balrog | switch (addr) {
|
1017 | c1713132 | balrog | case RTTR:
|
1018 | c1713132 | balrog | return s->rttr;
|
1019 | c1713132 | balrog | case RTSR:
|
1020 | c1713132 | balrog | return s->rtsr;
|
1021 | c1713132 | balrog | case RTAR:
|
1022 | c1713132 | balrog | return s->rtar;
|
1023 | c1713132 | balrog | case RDAR1:
|
1024 | c1713132 | balrog | return s->rdar1;
|
1025 | c1713132 | balrog | case RDAR2:
|
1026 | c1713132 | balrog | return s->rdar2;
|
1027 | c1713132 | balrog | case RYAR1:
|
1028 | c1713132 | balrog | return s->ryar1;
|
1029 | c1713132 | balrog | case RYAR2:
|
1030 | c1713132 | balrog | return s->ryar2;
|
1031 | c1713132 | balrog | case SWAR1:
|
1032 | c1713132 | balrog | return s->swar1;
|
1033 | c1713132 | balrog | case SWAR2:
|
1034 | c1713132 | balrog | return s->swar2;
|
1035 | c1713132 | balrog | case PIAR:
|
1036 | c1713132 | balrog | return s->piar;
|
1037 | c1713132 | balrog | case RCNR:
|
1038 | c1713132 | balrog | return s->last_rcnr + ((qemu_get_clock(rt_clock) - s->last_hz) << 15) / |
1039 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
1040 | c1713132 | balrog | case RDCR:
|
1041 | c1713132 | balrog | return s->last_rdcr + ((qemu_get_clock(rt_clock) - s->last_hz) << 15) / |
1042 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
1043 | c1713132 | balrog | case RYCR:
|
1044 | c1713132 | balrog | return s->last_rycr;
|
1045 | c1713132 | balrog | case SWCR:
|
1046 | c1713132 | balrog | if (s->rtsr & (1 << 12)) |
1047 | c1713132 | balrog | return s->last_swcr + (qemu_get_clock(rt_clock) - s->last_sw) / 10; |
1048 | c1713132 | balrog | else
|
1049 | c1713132 | balrog | return s->last_swcr;
|
1050 | c1713132 | balrog | default:
|
1051 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1052 | c1713132 | balrog | break;
|
1053 | c1713132 | balrog | } |
1054 | c1713132 | balrog | return 0; |
1055 | c1713132 | balrog | } |
1056 | c1713132 | balrog | |
1057 | c227f099 | Anthony Liguori | static void pxa2xx_rtc_write(void *opaque, target_phys_addr_t addr, |
1058 | c1713132 | balrog | uint32_t value) |
1059 | c1713132 | balrog | { |
1060 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1061 | c1713132 | balrog | |
1062 | c1713132 | balrog | switch (addr) {
|
1063 | c1713132 | balrog | case RTTR:
|
1064 | c1713132 | balrog | if (!(s->rttr & (1 << 31))) { |
1065 | c1713132 | balrog | pxa2xx_rtc_hzupdate(s); |
1066 | c1713132 | balrog | s->rttr = value; |
1067 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1068 | c1713132 | balrog | } |
1069 | c1713132 | balrog | break;
|
1070 | c1713132 | balrog | |
1071 | c1713132 | balrog | case RTSR:
|
1072 | c1713132 | balrog | if ((s->rtsr ^ value) & (1 << 15)) |
1073 | c1713132 | balrog | pxa2xx_rtc_piupdate(s); |
1074 | c1713132 | balrog | |
1075 | c1713132 | balrog | if ((s->rtsr ^ value) & (1 << 12)) |
1076 | c1713132 | balrog | pxa2xx_rtc_swupdate(s); |
1077 | c1713132 | balrog | |
1078 | c1713132 | balrog | if (((s->rtsr ^ value) & 0x4aac) | (value & ~0xdaac)) |
1079 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, value); |
1080 | c1713132 | balrog | |
1081 | c1713132 | balrog | s->rtsr = (value & 0xdaac) | (s->rtsr & ~(value & ~0xdaac)); |
1082 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
1083 | c1713132 | balrog | break;
|
1084 | c1713132 | balrog | |
1085 | c1713132 | balrog | case RTAR:
|
1086 | c1713132 | balrog | s->rtar = value; |
1087 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1088 | c1713132 | balrog | break;
|
1089 | c1713132 | balrog | |
1090 | c1713132 | balrog | case RDAR1:
|
1091 | c1713132 | balrog | s->rdar1 = value; |
1092 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1093 | c1713132 | balrog | break;
|
1094 | c1713132 | balrog | |
1095 | c1713132 | balrog | case RDAR2:
|
1096 | c1713132 | balrog | s->rdar2 = value; |
1097 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1098 | c1713132 | balrog | break;
|
1099 | c1713132 | balrog | |
1100 | c1713132 | balrog | case RYAR1:
|
1101 | c1713132 | balrog | s->ryar1 = value; |
1102 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1103 | c1713132 | balrog | break;
|
1104 | c1713132 | balrog | |
1105 | c1713132 | balrog | case RYAR2:
|
1106 | c1713132 | balrog | s->ryar2 = value; |
1107 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1108 | c1713132 | balrog | break;
|
1109 | c1713132 | balrog | |
1110 | c1713132 | balrog | case SWAR1:
|
1111 | c1713132 | balrog | pxa2xx_rtc_swupdate(s); |
1112 | c1713132 | balrog | s->swar1 = value; |
1113 | c1713132 | balrog | s->last_swcr = 0;
|
1114 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1115 | c1713132 | balrog | break;
|
1116 | c1713132 | balrog | |
1117 | c1713132 | balrog | case SWAR2:
|
1118 | c1713132 | balrog | s->swar2 = value; |
1119 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1120 | c1713132 | balrog | break;
|
1121 | c1713132 | balrog | |
1122 | c1713132 | balrog | case PIAR:
|
1123 | c1713132 | balrog | s->piar = value; |
1124 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1125 | c1713132 | balrog | break;
|
1126 | c1713132 | balrog | |
1127 | c1713132 | balrog | case RCNR:
|
1128 | c1713132 | balrog | pxa2xx_rtc_hzupdate(s); |
1129 | c1713132 | balrog | s->last_rcnr = value; |
1130 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1131 | c1713132 | balrog | break;
|
1132 | c1713132 | balrog | |
1133 | c1713132 | balrog | case RDCR:
|
1134 | c1713132 | balrog | pxa2xx_rtc_hzupdate(s); |
1135 | c1713132 | balrog | s->last_rdcr = value; |
1136 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1137 | c1713132 | balrog | break;
|
1138 | c1713132 | balrog | |
1139 | c1713132 | balrog | case RYCR:
|
1140 | c1713132 | balrog | s->last_rycr = value; |
1141 | c1713132 | balrog | break;
|
1142 | c1713132 | balrog | |
1143 | c1713132 | balrog | case SWCR:
|
1144 | c1713132 | balrog | pxa2xx_rtc_swupdate(s); |
1145 | c1713132 | balrog | s->last_swcr = value; |
1146 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1147 | c1713132 | balrog | break;
|
1148 | c1713132 | balrog | |
1149 | c1713132 | balrog | case RTCPICR:
|
1150 | c1713132 | balrog | pxa2xx_rtc_piupdate(s); |
1151 | c1713132 | balrog | s->last_rtcpicr = value & 0xffff;
|
1152 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1153 | c1713132 | balrog | break;
|
1154 | c1713132 | balrog | |
1155 | c1713132 | balrog | default:
|
1156 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1157 | c1713132 | balrog | } |
1158 | c1713132 | balrog | } |
1159 | c1713132 | balrog | |
1160 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_rtc_readfn[] = { |
1161 | aa941b94 | balrog | pxa2xx_rtc_read, |
1162 | aa941b94 | balrog | pxa2xx_rtc_read, |
1163 | aa941b94 | balrog | pxa2xx_rtc_read, |
1164 | aa941b94 | balrog | }; |
1165 | aa941b94 | balrog | |
1166 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_rtc_writefn[] = { |
1167 | aa941b94 | balrog | pxa2xx_rtc_write, |
1168 | aa941b94 | balrog | pxa2xx_rtc_write, |
1169 | aa941b94 | balrog | pxa2xx_rtc_write, |
1170 | aa941b94 | balrog | }; |
1171 | aa941b94 | balrog | |
1172 | bc24a225 | Paul Brook | static void pxa2xx_rtc_init(PXA2xxState *s) |
1173 | c1713132 | balrog | { |
1174 | f6503059 | balrog | struct tm tm;
|
1175 | c1713132 | balrog | int wom;
|
1176 | c1713132 | balrog | |
1177 | c1713132 | balrog | s->rttr = 0x7fff;
|
1178 | c1713132 | balrog | s->rtsr = 0;
|
1179 | c1713132 | balrog | |
1180 | f6503059 | balrog | qemu_get_timedate(&tm, 0);
|
1181 | f6503059 | balrog | wom = ((tm.tm_mday - 1) / 7) + 1; |
1182 | f6503059 | balrog | |
1183 | 0cd2df75 | aurel32 | s->last_rcnr = (uint32_t) mktimegm(&tm); |
1184 | f6503059 | balrog | s->last_rdcr = (wom << 20) | ((tm.tm_wday + 1) << 17) | |
1185 | f6503059 | balrog | (tm.tm_hour << 12) | (tm.tm_min << 6) | tm.tm_sec; |
1186 | f6503059 | balrog | s->last_rycr = ((tm.tm_year + 1900) << 9) | |
1187 | f6503059 | balrog | ((tm.tm_mon + 1) << 5) | tm.tm_mday; |
1188 | f6503059 | balrog | s->last_swcr = (tm.tm_hour << 19) |
|
1189 | f6503059 | balrog | (tm.tm_min << 13) | (tm.tm_sec << 7); |
1190 | c1713132 | balrog | s->last_rtcpicr = 0;
|
1191 | c1713132 | balrog | s->last_hz = s->last_sw = s->last_pi = qemu_get_clock(rt_clock); |
1192 | c1713132 | balrog | |
1193 | c1713132 | balrog | s->rtc_hz = qemu_new_timer(rt_clock, pxa2xx_rtc_hz_tick, s); |
1194 | c1713132 | balrog | s->rtc_rdal1 = qemu_new_timer(rt_clock, pxa2xx_rtc_rdal1_tick, s); |
1195 | c1713132 | balrog | s->rtc_rdal2 = qemu_new_timer(rt_clock, pxa2xx_rtc_rdal2_tick, s); |
1196 | c1713132 | balrog | s->rtc_swal1 = qemu_new_timer(rt_clock, pxa2xx_rtc_swal1_tick, s); |
1197 | c1713132 | balrog | s->rtc_swal2 = qemu_new_timer(rt_clock, pxa2xx_rtc_swal2_tick, s); |
1198 | c1713132 | balrog | s->rtc_pi = qemu_new_timer(rt_clock, pxa2xx_rtc_pi_tick, s); |
1199 | c1713132 | balrog | } |
1200 | c1713132 | balrog | |
1201 | aa941b94 | balrog | static void pxa2xx_rtc_save(QEMUFile *f, void *opaque) |
1202 | aa941b94 | balrog | { |
1203 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1204 | c1713132 | balrog | |
1205 | aa941b94 | balrog | pxa2xx_rtc_hzupdate(s); |
1206 | aa941b94 | balrog | pxa2xx_rtc_piupdate(s); |
1207 | aa941b94 | balrog | pxa2xx_rtc_swupdate(s); |
1208 | aa941b94 | balrog | |
1209 | aa941b94 | balrog | qemu_put_be32s(f, &s->rttr); |
1210 | aa941b94 | balrog | qemu_put_be32s(f, &s->rtsr); |
1211 | aa941b94 | balrog | qemu_put_be32s(f, &s->rtar); |
1212 | aa941b94 | balrog | qemu_put_be32s(f, &s->rdar1); |
1213 | aa941b94 | balrog | qemu_put_be32s(f, &s->rdar2); |
1214 | aa941b94 | balrog | qemu_put_be32s(f, &s->ryar1); |
1215 | aa941b94 | balrog | qemu_put_be32s(f, &s->ryar2); |
1216 | aa941b94 | balrog | qemu_put_be32s(f, &s->swar1); |
1217 | aa941b94 | balrog | qemu_put_be32s(f, &s->swar2); |
1218 | aa941b94 | balrog | qemu_put_be32s(f, &s->piar); |
1219 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rcnr); |
1220 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rdcr); |
1221 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rycr); |
1222 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_swcr); |
1223 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rtcpicr); |
1224 | b6c4f71f | blueswir1 | qemu_put_sbe64s(f, &s->last_hz); |
1225 | b6c4f71f | blueswir1 | qemu_put_sbe64s(f, &s->last_sw); |
1226 | b6c4f71f | blueswir1 | qemu_put_sbe64s(f, &s->last_pi); |
1227 | aa941b94 | balrog | } |
1228 | aa941b94 | balrog | |
1229 | aa941b94 | balrog | static int pxa2xx_rtc_load(QEMUFile *f, void *opaque, int version_id) |
1230 | aa941b94 | balrog | { |
1231 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1232 | aa941b94 | balrog | |
1233 | aa941b94 | balrog | qemu_get_be32s(f, &s->rttr); |
1234 | aa941b94 | balrog | qemu_get_be32s(f, &s->rtsr); |
1235 | aa941b94 | balrog | qemu_get_be32s(f, &s->rtar); |
1236 | aa941b94 | balrog | qemu_get_be32s(f, &s->rdar1); |
1237 | aa941b94 | balrog | qemu_get_be32s(f, &s->rdar2); |
1238 | aa941b94 | balrog | qemu_get_be32s(f, &s->ryar1); |
1239 | aa941b94 | balrog | qemu_get_be32s(f, &s->ryar2); |
1240 | aa941b94 | balrog | qemu_get_be32s(f, &s->swar1); |
1241 | aa941b94 | balrog | qemu_get_be32s(f, &s->swar2); |
1242 | aa941b94 | balrog | qemu_get_be32s(f, &s->piar); |
1243 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rcnr); |
1244 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rdcr); |
1245 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rycr); |
1246 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_swcr); |
1247 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rtcpicr); |
1248 | b6c4f71f | blueswir1 | qemu_get_sbe64s(f, &s->last_hz); |
1249 | b6c4f71f | blueswir1 | qemu_get_sbe64s(f, &s->last_sw); |
1250 | b6c4f71f | blueswir1 | qemu_get_sbe64s(f, &s->last_pi); |
1251 | aa941b94 | balrog | |
1252 | aa941b94 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1253 | aa941b94 | balrog | |
1254 | aa941b94 | balrog | return 0; |
1255 | aa941b94 | balrog | } |
1256 | c1713132 | balrog | |
1257 | 3f582262 | balrog | /* I2C Interface */
|
1258 | e3b42536 | Paul Brook | typedef struct { |
1259 | e3b42536 | Paul Brook | i2c_slave i2c; |
1260 | e3b42536 | Paul Brook | PXA2xxI2CState *host; |
1261 | e3b42536 | Paul Brook | } PXA2xxI2CSlaveState; |
1262 | e3b42536 | Paul Brook | |
1263 | bc24a225 | Paul Brook | struct PXA2xxI2CState {
|
1264 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave; |
1265 | 3f582262 | balrog | i2c_bus *bus; |
1266 | 3f582262 | balrog | qemu_irq irq; |
1267 | c227f099 | Anthony Liguori | target_phys_addr_t offset; |
1268 | 3f582262 | balrog | |
1269 | 3f582262 | balrog | uint16_t control; |
1270 | 3f582262 | balrog | uint16_t status; |
1271 | 3f582262 | balrog | uint8_t ibmr; |
1272 | 3f582262 | balrog | uint8_t data; |
1273 | 3f582262 | balrog | }; |
1274 | 3f582262 | balrog | |
1275 | 3f582262 | balrog | #define IBMR 0x80 /* I2C Bus Monitor register */ |
1276 | 3f582262 | balrog | #define IDBR 0x88 /* I2C Data Buffer register */ |
1277 | 3f582262 | balrog | #define ICR 0x90 /* I2C Control register */ |
1278 | 3f582262 | balrog | #define ISR 0x98 /* I2C Status register */ |
1279 | 3f582262 | balrog | #define ISAR 0xa0 /* I2C Slave Address register */ |
1280 | 3f582262 | balrog | |
1281 | bc24a225 | Paul Brook | static void pxa2xx_i2c_update(PXA2xxI2CState *s) |
1282 | 3f582262 | balrog | { |
1283 | 3f582262 | balrog | uint16_t level = 0;
|
1284 | 3f582262 | balrog | level |= s->status & s->control & (1 << 10); /* BED */ |
1285 | 3f582262 | balrog | level |= (s->status & (1 << 7)) && (s->control & (1 << 9)); /* IRF */ |
1286 | 3f582262 | balrog | level |= (s->status & (1 << 6)) && (s->control & (1 << 8)); /* ITE */ |
1287 | 3f582262 | balrog | level |= s->status & (1 << 9); /* SAD */ |
1288 | 3f582262 | balrog | qemu_set_irq(s->irq, !!level); |
1289 | 3f582262 | balrog | } |
1290 | 3f582262 | balrog | |
1291 | 3f582262 | balrog | /* These are only stubs now. */
|
1292 | 3f582262 | balrog | static void pxa2xx_i2c_event(i2c_slave *i2c, enum i2c_event event) |
1293 | 3f582262 | balrog | { |
1294 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c); |
1295 | e3b42536 | Paul Brook | PXA2xxI2CState *s = slave->host; |
1296 | 3f582262 | balrog | |
1297 | 3f582262 | balrog | switch (event) {
|
1298 | 3f582262 | balrog | case I2C_START_SEND:
|
1299 | 3f582262 | balrog | s->status |= (1 << 9); /* set SAD */ |
1300 | 3f582262 | balrog | s->status &= ~(1 << 0); /* clear RWM */ |
1301 | 3f582262 | balrog | break;
|
1302 | 3f582262 | balrog | case I2C_START_RECV:
|
1303 | 3f582262 | balrog | s->status |= (1 << 9); /* set SAD */ |
1304 | 3f582262 | balrog | s->status |= 1 << 0; /* set RWM */ |
1305 | 3f582262 | balrog | break;
|
1306 | 3f582262 | balrog | case I2C_FINISH:
|
1307 | 3f582262 | balrog | s->status |= (1 << 4); /* set SSD */ |
1308 | 3f582262 | balrog | break;
|
1309 | 3f582262 | balrog | case I2C_NACK:
|
1310 | 3f582262 | balrog | s->status |= 1 << 1; /* set ACKNAK */ |
1311 | 3f582262 | balrog | break;
|
1312 | 3f582262 | balrog | } |
1313 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1314 | 3f582262 | balrog | } |
1315 | 3f582262 | balrog | |
1316 | 3f582262 | balrog | static int pxa2xx_i2c_rx(i2c_slave *i2c) |
1317 | 3f582262 | balrog | { |
1318 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c); |
1319 | e3b42536 | Paul Brook | PXA2xxI2CState *s = slave->host; |
1320 | 3f582262 | balrog | if ((s->control & (1 << 14)) || !(s->control & (1 << 6))) |
1321 | 3f582262 | balrog | return 0; |
1322 | 3f582262 | balrog | |
1323 | 3f582262 | balrog | if (s->status & (1 << 0)) { /* RWM */ |
1324 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1325 | 3f582262 | balrog | } |
1326 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1327 | 3f582262 | balrog | |
1328 | 3f582262 | balrog | return s->data;
|
1329 | 3f582262 | balrog | } |
1330 | 3f582262 | balrog | |
1331 | 3f582262 | balrog | static int pxa2xx_i2c_tx(i2c_slave *i2c, uint8_t data) |
1332 | 3f582262 | balrog | { |
1333 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c); |
1334 | e3b42536 | Paul Brook | PXA2xxI2CState *s = slave->host; |
1335 | 3f582262 | balrog | if ((s->control & (1 << 14)) || !(s->control & (1 << 6))) |
1336 | 3f582262 | balrog | return 1; |
1337 | 3f582262 | balrog | |
1338 | 3f582262 | balrog | if (!(s->status & (1 << 0))) { /* RWM */ |
1339 | 3f582262 | balrog | s->status |= 1 << 7; /* set IRF */ |
1340 | 3f582262 | balrog | s->data = data; |
1341 | 3f582262 | balrog | } |
1342 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1343 | 3f582262 | balrog | |
1344 | 3f582262 | balrog | return 1; |
1345 | 3f582262 | balrog | } |
1346 | 3f582262 | balrog | |
1347 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_i2c_read(void *opaque, target_phys_addr_t addr) |
1348 | 3f582262 | balrog | { |
1349 | bc24a225 | Paul Brook | PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; |
1350 | 3f582262 | balrog | |
1351 | ed005253 | balrog | addr -= s->offset; |
1352 | 3f582262 | balrog | switch (addr) {
|
1353 | 3f582262 | balrog | case ICR:
|
1354 | 3f582262 | balrog | return s->control;
|
1355 | 3f582262 | balrog | case ISR:
|
1356 | 3f582262 | balrog | return s->status | (i2c_bus_busy(s->bus) << 2); |
1357 | 3f582262 | balrog | case ISAR:
|
1358 | e3b42536 | Paul Brook | return s->slave->i2c.address;
|
1359 | 3f582262 | balrog | case IDBR:
|
1360 | 3f582262 | balrog | return s->data;
|
1361 | 3f582262 | balrog | case IBMR:
|
1362 | 3f582262 | balrog | if (s->status & (1 << 2)) |
1363 | 3f582262 | balrog | s->ibmr ^= 3; /* Fake SCL and SDA pin changes */ |
1364 | 3f582262 | balrog | else
|
1365 | 3f582262 | balrog | s->ibmr = 0;
|
1366 | 3f582262 | balrog | return s->ibmr;
|
1367 | 3f582262 | balrog | default:
|
1368 | 3f582262 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1369 | 3f582262 | balrog | break;
|
1370 | 3f582262 | balrog | } |
1371 | 3f582262 | balrog | return 0; |
1372 | 3f582262 | balrog | } |
1373 | 3f582262 | balrog | |
1374 | c227f099 | Anthony Liguori | static void pxa2xx_i2c_write(void *opaque, target_phys_addr_t addr, |
1375 | 3f582262 | balrog | uint32_t value) |
1376 | 3f582262 | balrog | { |
1377 | bc24a225 | Paul Brook | PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; |
1378 | 3f582262 | balrog | int ack;
|
1379 | 3f582262 | balrog | |
1380 | ed005253 | balrog | addr -= s->offset; |
1381 | 3f582262 | balrog | switch (addr) {
|
1382 | 3f582262 | balrog | case ICR:
|
1383 | 3f582262 | balrog | s->control = value & 0xfff7;
|
1384 | 3f582262 | balrog | if ((value & (1 << 3)) && (value & (1 << 6))) { /* TB and IUE */ |
1385 | 3f582262 | balrog | /* TODO: slave mode */
|
1386 | 3f582262 | balrog | if (value & (1 << 0)) { /* START condition */ |
1387 | 3f582262 | balrog | if (s->data & 1) |
1388 | 3f582262 | balrog | s->status |= 1 << 0; /* set RWM */ |
1389 | 3f582262 | balrog | else
|
1390 | 3f582262 | balrog | s->status &= ~(1 << 0); /* clear RWM */ |
1391 | 3f582262 | balrog | ack = !i2c_start_transfer(s->bus, s->data >> 1, s->data & 1); |
1392 | 3f582262 | balrog | } else {
|
1393 | 3f582262 | balrog | if (s->status & (1 << 0)) { /* RWM */ |
1394 | 3f582262 | balrog | s->data = i2c_recv(s->bus); |
1395 | 3f582262 | balrog | if (value & (1 << 2)) /* ACKNAK */ |
1396 | 3f582262 | balrog | i2c_nack(s->bus); |
1397 | 3f582262 | balrog | ack = 1;
|
1398 | 3f582262 | balrog | } else
|
1399 | 3f582262 | balrog | ack = !i2c_send(s->bus, s->data); |
1400 | 3f582262 | balrog | } |
1401 | 3f582262 | balrog | |
1402 | 3f582262 | balrog | if (value & (1 << 1)) /* STOP condition */ |
1403 | 3f582262 | balrog | i2c_end_transfer(s->bus); |
1404 | 3f582262 | balrog | |
1405 | 3f582262 | balrog | if (ack) {
|
1406 | 3f582262 | balrog | if (value & (1 << 0)) /* START condition */ |
1407 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1408 | 3f582262 | balrog | else
|
1409 | 3f582262 | balrog | if (s->status & (1 << 0)) /* RWM */ |
1410 | 3f582262 | balrog | s->status |= 1 << 7; /* set IRF */ |
1411 | 3f582262 | balrog | else
|
1412 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1413 | 3f582262 | balrog | s->status &= ~(1 << 1); /* clear ACKNAK */ |
1414 | 3f582262 | balrog | } else {
|
1415 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1416 | 3f582262 | balrog | s->status |= 1 << 10; /* set BED */ |
1417 | 3f582262 | balrog | s->status |= 1 << 1; /* set ACKNAK */ |
1418 | 3f582262 | balrog | } |
1419 | 3f582262 | balrog | } |
1420 | 3f582262 | balrog | if (!(value & (1 << 3)) && (value & (1 << 6))) /* !TB and IUE */ |
1421 | 3f582262 | balrog | if (value & (1 << 4)) /* MA */ |
1422 | 3f582262 | balrog | i2c_end_transfer(s->bus); |
1423 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1424 | 3f582262 | balrog | break;
|
1425 | 3f582262 | balrog | |
1426 | 3f582262 | balrog | case ISR:
|
1427 | 3f582262 | balrog | s->status &= ~(value & 0x07f0);
|
1428 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1429 | 3f582262 | balrog | break;
|
1430 | 3f582262 | balrog | |
1431 | 3f582262 | balrog | case ISAR:
|
1432 | e3b42536 | Paul Brook | i2c_set_slave_address(&s->slave->i2c, value & 0x7f);
|
1433 | 3f582262 | balrog | break;
|
1434 | 3f582262 | balrog | |
1435 | 3f582262 | balrog | case IDBR:
|
1436 | 3f582262 | balrog | s->data = value & 0xff;
|
1437 | 3f582262 | balrog | break;
|
1438 | 3f582262 | balrog | |
1439 | 3f582262 | balrog | default:
|
1440 | 3f582262 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1441 | 3f582262 | balrog | } |
1442 | 3f582262 | balrog | } |
1443 | 3f582262 | balrog | |
1444 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_i2c_readfn[] = { |
1445 | 3f582262 | balrog | pxa2xx_i2c_read, |
1446 | 3f582262 | balrog | pxa2xx_i2c_read, |
1447 | 3f582262 | balrog | pxa2xx_i2c_read, |
1448 | 3f582262 | balrog | }; |
1449 | 3f582262 | balrog | |
1450 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_i2c_writefn[] = { |
1451 | 3f582262 | balrog | pxa2xx_i2c_write, |
1452 | 3f582262 | balrog | pxa2xx_i2c_write, |
1453 | 3f582262 | balrog | pxa2xx_i2c_write, |
1454 | 3f582262 | balrog | }; |
1455 | 3f582262 | balrog | |
1456 | 0211364d | Juan Quintela | static const VMStateDescription vmstate_pxa2xx_i2c_slave = { |
1457 | 0211364d | Juan Quintela | .name = "pxa2xx_i2c_slave",
|
1458 | 0211364d | Juan Quintela | .version_id = 1,
|
1459 | 0211364d | Juan Quintela | .minimum_version_id = 1,
|
1460 | 0211364d | Juan Quintela | .minimum_version_id_old = 1,
|
1461 | 0211364d | Juan Quintela | .fields = (VMStateField []) { |
1462 | 0211364d | Juan Quintela | VMSTATE_I2C_SLAVE(i2c, PXA2xxI2CSlaveState), |
1463 | 0211364d | Juan Quintela | VMSTATE_END_OF_LIST() |
1464 | 0211364d | Juan Quintela | } |
1465 | 0211364d | Juan Quintela | }; |
1466 | aa941b94 | balrog | |
1467 | 0211364d | Juan Quintela | static const VMStateDescription vmstate_pxa2xx_i2c = { |
1468 | 0211364d | Juan Quintela | .name = "pxa2xx_i2c",
|
1469 | 0211364d | Juan Quintela | .version_id = 1,
|
1470 | 0211364d | Juan Quintela | .minimum_version_id = 1,
|
1471 | 0211364d | Juan Quintela | .minimum_version_id_old = 1,
|
1472 | 0211364d | Juan Quintela | .fields = (VMStateField []) { |
1473 | 0211364d | Juan Quintela | VMSTATE_UINT16(control, PXA2xxI2CState), |
1474 | 0211364d | Juan Quintela | VMSTATE_UINT16(status, PXA2xxI2CState), |
1475 | 0211364d | Juan Quintela | VMSTATE_UINT8(ibmr, PXA2xxI2CState), |
1476 | 0211364d | Juan Quintela | VMSTATE_UINT8(data, PXA2xxI2CState), |
1477 | 0211364d | Juan Quintela | VMSTATE_STRUCT_POINTER(slave, PXA2xxI2CState, |
1478 | 0211364d | Juan Quintela | vmstate_pxa2xx_i2c, PXA2xxI2CSlaveState *), |
1479 | 0211364d | Juan Quintela | VMSTATE_END_OF_LIST() |
1480 | 0211364d | Juan Quintela | } |
1481 | 0211364d | Juan Quintela | }; |
1482 | aa941b94 | balrog | |
1483 | 81a322d4 | Gerd Hoffmann | static int pxa2xx_i2c_slave_init(i2c_slave *i2c) |
1484 | e3b42536 | Paul Brook | { |
1485 | e3b42536 | Paul Brook | /* Nothing to do. */
|
1486 | 81a322d4 | Gerd Hoffmann | return 0; |
1487 | e3b42536 | Paul Brook | } |
1488 | e3b42536 | Paul Brook | |
1489 | e3b42536 | Paul Brook | static I2CSlaveInfo pxa2xx_i2c_slave_info = {
|
1490 | 074f2fff | Gerd Hoffmann | .qdev.name = "pxa2xx-i2c-slave",
|
1491 | 074f2fff | Gerd Hoffmann | .qdev.size = sizeof(PXA2xxI2CSlaveState),
|
1492 | e3b42536 | Paul Brook | .init = pxa2xx_i2c_slave_init, |
1493 | e3b42536 | Paul Brook | .event = pxa2xx_i2c_event, |
1494 | e3b42536 | Paul Brook | .recv = pxa2xx_i2c_rx, |
1495 | e3b42536 | Paul Brook | .send = pxa2xx_i2c_tx |
1496 | e3b42536 | Paul Brook | }; |
1497 | e3b42536 | Paul Brook | |
1498 | c227f099 | Anthony Liguori | PXA2xxI2CState *pxa2xx_i2c_init(target_phys_addr_t base, |
1499 | ed005253 | balrog | qemu_irq irq, uint32_t region_size) |
1500 | 3f582262 | balrog | { |
1501 | 3f582262 | balrog | int iomemtype;
|
1502 | e3b42536 | Paul Brook | DeviceState *dev; |
1503 | e3b42536 | Paul Brook | PXA2xxI2CState *s = qemu_mallocz(sizeof(PXA2xxI2CState));
|
1504 | e3b42536 | Paul Brook | |
1505 | c701b35b | pbrook | /* FIXME: Should the slave device really be on a separate bus? */
|
1506 | 02e2da45 | Paul Brook | dev = i2c_create_slave(i2c_init_bus(NULL, "dummy"), "pxa2xx-i2c-slave", 0); |
1507 | e3b42536 | Paul Brook | s->slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, I2C_SLAVE_FROM_QDEV(dev)); |
1508 | e3b42536 | Paul Brook | s->slave->host = s; |
1509 | 3f582262 | balrog | |
1510 | 3f582262 | balrog | s->irq = irq; |
1511 | 02e2da45 | Paul Brook | s->bus = i2c_init_bus(NULL, "i2c"); |
1512 | dc23e260 | balrog | s->offset = base - (base & (~region_size) & TARGET_PAGE_MASK); |
1513 | 3f582262 | balrog | |
1514 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_i2c_readfn, |
1515 | 2a163929 | balrog | pxa2xx_i2c_writefn, s); |
1516 | ed005253 | balrog | cpu_register_physical_memory(base & ~region_size, |
1517 | ed005253 | balrog | region_size + 1, iomemtype);
|
1518 | 3f582262 | balrog | |
1519 | 0be71e32 | Alex Williamson | vmstate_register(NULL, base, &vmstate_pxa2xx_i2c, s);
|
1520 | aa941b94 | balrog | |
1521 | 3f582262 | balrog | return s;
|
1522 | 3f582262 | balrog | } |
1523 | 3f582262 | balrog | |
1524 | bc24a225 | Paul Brook | i2c_bus *pxa2xx_i2c_bus(PXA2xxI2CState *s) |
1525 | 3f582262 | balrog | { |
1526 | 3f582262 | balrog | return s->bus;
|
1527 | 3f582262 | balrog | } |
1528 | 3f582262 | balrog | |
1529 | c1713132 | balrog | /* PXA Inter-IC Sound Controller */
|
1530 | bc24a225 | Paul Brook | static void pxa2xx_i2s_reset(PXA2xxI2SState *i2s) |
1531 | c1713132 | balrog | { |
1532 | c1713132 | balrog | i2s->rx_len = 0;
|
1533 | c1713132 | balrog | i2s->tx_len = 0;
|
1534 | c1713132 | balrog | i2s->fifo_len = 0;
|
1535 | c1713132 | balrog | i2s->clk = 0x1a;
|
1536 | c1713132 | balrog | i2s->control[0] = 0x00; |
1537 | c1713132 | balrog | i2s->control[1] = 0x00; |
1538 | c1713132 | balrog | i2s->status = 0x00;
|
1539 | c1713132 | balrog | i2s->mask = 0x00;
|
1540 | c1713132 | balrog | } |
1541 | c1713132 | balrog | |
1542 | c1713132 | balrog | #define SACR_TFTH(val) ((val >> 8) & 0xf) |
1543 | c1713132 | balrog | #define SACR_RFTH(val) ((val >> 12) & 0xf) |
1544 | c1713132 | balrog | #define SACR_DREC(val) (val & (1 << 3)) |
1545 | c1713132 | balrog | #define SACR_DPRL(val) (val & (1 << 4)) |
1546 | c1713132 | balrog | |
1547 | bc24a225 | Paul Brook | static inline void pxa2xx_i2s_update(PXA2xxI2SState *i2s) |
1548 | c1713132 | balrog | { |
1549 | c1713132 | balrog | int rfs, tfs;
|
1550 | c1713132 | balrog | rfs = SACR_RFTH(i2s->control[0]) < i2s->rx_len &&
|
1551 | c1713132 | balrog | !SACR_DREC(i2s->control[1]);
|
1552 | c1713132 | balrog | tfs = (i2s->tx_len || i2s->fifo_len < SACR_TFTH(i2s->control[0])) &&
|
1553 | c1713132 | balrog | i2s->enable && !SACR_DPRL(i2s->control[1]);
|
1554 | c1713132 | balrog | |
1555 | c1713132 | balrog | pxa2xx_dma_request(i2s->dma, PXA2XX_RX_RQ_I2S, rfs); |
1556 | c1713132 | balrog | pxa2xx_dma_request(i2s->dma, PXA2XX_TX_RQ_I2S, tfs); |
1557 | c1713132 | balrog | |
1558 | c1713132 | balrog | i2s->status &= 0xe0;
|
1559 | 59c0149b | balrog | if (i2s->fifo_len < 16 || !i2s->enable) |
1560 | 59c0149b | balrog | i2s->status |= 1 << 0; /* TNF */ |
1561 | c1713132 | balrog | if (i2s->rx_len)
|
1562 | c1713132 | balrog | i2s->status |= 1 << 1; /* RNE */ |
1563 | c1713132 | balrog | if (i2s->enable)
|
1564 | c1713132 | balrog | i2s->status |= 1 << 2; /* BSY */ |
1565 | c1713132 | balrog | if (tfs)
|
1566 | c1713132 | balrog | i2s->status |= 1 << 3; /* TFS */ |
1567 | c1713132 | balrog | if (rfs)
|
1568 | c1713132 | balrog | i2s->status |= 1 << 4; /* RFS */ |
1569 | c1713132 | balrog | if (!(i2s->tx_len && i2s->enable))
|
1570 | c1713132 | balrog | i2s->status |= i2s->fifo_len << 8; /* TFL */ |
1571 | c1713132 | balrog | i2s->status |= MAX(i2s->rx_len, 0xf) << 12; /* RFL */ |
1572 | c1713132 | balrog | |
1573 | c1713132 | balrog | qemu_set_irq(i2s->irq, i2s->status & i2s->mask); |
1574 | c1713132 | balrog | } |
1575 | c1713132 | balrog | |
1576 | c1713132 | balrog | #define SACR0 0x00 /* Serial Audio Global Control register */ |
1577 | c1713132 | balrog | #define SACR1 0x04 /* Serial Audio I2S/MSB-Justified Control register */ |
1578 | c1713132 | balrog | #define SASR0 0x0c /* Serial Audio Interface and FIFO Status register */ |
1579 | c1713132 | balrog | #define SAIMR 0x14 /* Serial Audio Interrupt Mask register */ |
1580 | c1713132 | balrog | #define SAICR 0x18 /* Serial Audio Interrupt Clear register */ |
1581 | c1713132 | balrog | #define SADIV 0x60 /* Serial Audio Clock Divider register */ |
1582 | c1713132 | balrog | #define SADR 0x80 /* Serial Audio Data register */ |
1583 | c1713132 | balrog | |
1584 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_i2s_read(void *opaque, target_phys_addr_t addr) |
1585 | c1713132 | balrog | { |
1586 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1587 | c1713132 | balrog | |
1588 | c1713132 | balrog | switch (addr) {
|
1589 | c1713132 | balrog | case SACR0:
|
1590 | c1713132 | balrog | return s->control[0]; |
1591 | c1713132 | balrog | case SACR1:
|
1592 | c1713132 | balrog | return s->control[1]; |
1593 | c1713132 | balrog | case SASR0:
|
1594 | c1713132 | balrog | return s->status;
|
1595 | c1713132 | balrog | case SAIMR:
|
1596 | c1713132 | balrog | return s->mask;
|
1597 | c1713132 | balrog | case SAICR:
|
1598 | c1713132 | balrog | return 0; |
1599 | c1713132 | balrog | case SADIV:
|
1600 | c1713132 | balrog | return s->clk;
|
1601 | c1713132 | balrog | case SADR:
|
1602 | c1713132 | balrog | if (s->rx_len > 0) { |
1603 | c1713132 | balrog | s->rx_len --; |
1604 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1605 | c1713132 | balrog | return s->codec_in(s->opaque);
|
1606 | c1713132 | balrog | } |
1607 | c1713132 | balrog | return 0; |
1608 | c1713132 | balrog | default:
|
1609 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1610 | c1713132 | balrog | break;
|
1611 | c1713132 | balrog | } |
1612 | c1713132 | balrog | return 0; |
1613 | c1713132 | balrog | } |
1614 | c1713132 | balrog | |
1615 | c227f099 | Anthony Liguori | static void pxa2xx_i2s_write(void *opaque, target_phys_addr_t addr, |
1616 | c1713132 | balrog | uint32_t value) |
1617 | c1713132 | balrog | { |
1618 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1619 | c1713132 | balrog | uint32_t *sample; |
1620 | c1713132 | balrog | |
1621 | c1713132 | balrog | switch (addr) {
|
1622 | c1713132 | balrog | case SACR0:
|
1623 | c1713132 | balrog | if (value & (1 << 3)) /* RST */ |
1624 | c1713132 | balrog | pxa2xx_i2s_reset(s); |
1625 | c1713132 | balrog | s->control[0] = value & 0xff3d; |
1626 | c1713132 | balrog | if (!s->enable && (value & 1) && s->tx_len) { /* ENB */ |
1627 | c1713132 | balrog | for (sample = s->fifo; s->fifo_len > 0; s->fifo_len --, sample ++) |
1628 | c1713132 | balrog | s->codec_out(s->opaque, *sample); |
1629 | c1713132 | balrog | s->status &= ~(1 << 7); /* I2SOFF */ |
1630 | c1713132 | balrog | } |
1631 | c1713132 | balrog | if (value & (1 << 4)) /* EFWR */ |
1632 | c1713132 | balrog | printf("%s: Attempt to use special function\n", __FUNCTION__);
|
1633 | c1713132 | balrog | s->enable = ((value ^ 4) & 5) == 5; /* ENB && !RST*/ |
1634 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1635 | c1713132 | balrog | break;
|
1636 | c1713132 | balrog | case SACR1:
|
1637 | c1713132 | balrog | s->control[1] = value & 0x0039; |
1638 | c1713132 | balrog | if (value & (1 << 5)) /* ENLBF */ |
1639 | c1713132 | balrog | printf("%s: Attempt to use loopback function\n", __FUNCTION__);
|
1640 | c1713132 | balrog | if (value & (1 << 4)) /* DPRL */ |
1641 | c1713132 | balrog | s->fifo_len = 0;
|
1642 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1643 | c1713132 | balrog | break;
|
1644 | c1713132 | balrog | case SAIMR:
|
1645 | c1713132 | balrog | s->mask = value & 0x0078;
|
1646 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1647 | c1713132 | balrog | break;
|
1648 | c1713132 | balrog | case SAICR:
|
1649 | c1713132 | balrog | s->status &= ~(value & (3 << 5)); |
1650 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1651 | c1713132 | balrog | break;
|
1652 | c1713132 | balrog | case SADIV:
|
1653 | c1713132 | balrog | s->clk = value & 0x007f;
|
1654 | c1713132 | balrog | break;
|
1655 | c1713132 | balrog | case SADR:
|
1656 | c1713132 | balrog | if (s->tx_len && s->enable) {
|
1657 | c1713132 | balrog | s->tx_len --; |
1658 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1659 | c1713132 | balrog | s->codec_out(s->opaque, value); |
1660 | c1713132 | balrog | } else if (s->fifo_len < 16) { |
1661 | c1713132 | balrog | s->fifo[s->fifo_len ++] = value; |
1662 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1663 | c1713132 | balrog | } |
1664 | c1713132 | balrog | break;
|
1665 | c1713132 | balrog | default:
|
1666 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1667 | c1713132 | balrog | } |
1668 | c1713132 | balrog | } |
1669 | c1713132 | balrog | |
1670 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_i2s_readfn[] = { |
1671 | c1713132 | balrog | pxa2xx_i2s_read, |
1672 | c1713132 | balrog | pxa2xx_i2s_read, |
1673 | c1713132 | balrog | pxa2xx_i2s_read, |
1674 | c1713132 | balrog | }; |
1675 | c1713132 | balrog | |
1676 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_i2s_writefn[] = { |
1677 | c1713132 | balrog | pxa2xx_i2s_write, |
1678 | c1713132 | balrog | pxa2xx_i2s_write, |
1679 | c1713132 | balrog | pxa2xx_i2s_write, |
1680 | c1713132 | balrog | }; |
1681 | c1713132 | balrog | |
1682 | aa941b94 | balrog | static void pxa2xx_i2s_save(QEMUFile *f, void *opaque) |
1683 | aa941b94 | balrog | { |
1684 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1685 | aa941b94 | balrog | |
1686 | aa941b94 | balrog | qemu_put_be32s(f, &s->control[0]);
|
1687 | aa941b94 | balrog | qemu_put_be32s(f, &s->control[1]);
|
1688 | aa941b94 | balrog | qemu_put_be32s(f, &s->status); |
1689 | aa941b94 | balrog | qemu_put_be32s(f, &s->mask); |
1690 | aa941b94 | balrog | qemu_put_be32s(f, &s->clk); |
1691 | aa941b94 | balrog | |
1692 | aa941b94 | balrog | qemu_put_be32(f, s->enable); |
1693 | aa941b94 | balrog | qemu_put_be32(f, s->rx_len); |
1694 | aa941b94 | balrog | qemu_put_be32(f, s->tx_len); |
1695 | aa941b94 | balrog | qemu_put_be32(f, s->fifo_len); |
1696 | aa941b94 | balrog | } |
1697 | aa941b94 | balrog | |
1698 | aa941b94 | balrog | static int pxa2xx_i2s_load(QEMUFile *f, void *opaque, int version_id) |
1699 | aa941b94 | balrog | { |
1700 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1701 | aa941b94 | balrog | |
1702 | aa941b94 | balrog | qemu_get_be32s(f, &s->control[0]);
|
1703 | aa941b94 | balrog | qemu_get_be32s(f, &s->control[1]);
|
1704 | aa941b94 | balrog | qemu_get_be32s(f, &s->status); |
1705 | aa941b94 | balrog | qemu_get_be32s(f, &s->mask); |
1706 | aa941b94 | balrog | qemu_get_be32s(f, &s->clk); |
1707 | aa941b94 | balrog | |
1708 | aa941b94 | balrog | s->enable = qemu_get_be32(f); |
1709 | aa941b94 | balrog | s->rx_len = qemu_get_be32(f); |
1710 | aa941b94 | balrog | s->tx_len = qemu_get_be32(f); |
1711 | aa941b94 | balrog | s->fifo_len = qemu_get_be32(f); |
1712 | aa941b94 | balrog | |
1713 | aa941b94 | balrog | return 0; |
1714 | aa941b94 | balrog | } |
1715 | aa941b94 | balrog | |
1716 | c1713132 | balrog | static void pxa2xx_i2s_data_req(void *opaque, int tx, int rx) |
1717 | c1713132 | balrog | { |
1718 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1719 | c1713132 | balrog | uint32_t *sample; |
1720 | c1713132 | balrog | |
1721 | c1713132 | balrog | /* Signal FIFO errors */
|
1722 | c1713132 | balrog | if (s->enable && s->tx_len)
|
1723 | c1713132 | balrog | s->status |= 1 << 5; /* TUR */ |
1724 | c1713132 | balrog | if (s->enable && s->rx_len)
|
1725 | c1713132 | balrog | s->status |= 1 << 6; /* ROR */ |
1726 | c1713132 | balrog | |
1727 | c1713132 | balrog | /* Should be tx - MIN(tx, s->fifo_len) but we don't really need to
|
1728 | c1713132 | balrog | * handle the cases where it makes a difference. */
|
1729 | c1713132 | balrog | s->tx_len = tx - s->fifo_len; |
1730 | c1713132 | balrog | s->rx_len = rx; |
1731 | c1713132 | balrog | /* Note that is s->codec_out wasn't set, we wouldn't get called. */
|
1732 | c1713132 | balrog | if (s->enable)
|
1733 | c1713132 | balrog | for (sample = s->fifo; s->fifo_len; s->fifo_len --, sample ++)
|
1734 | c1713132 | balrog | s->codec_out(s->opaque, *sample); |
1735 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1736 | c1713132 | balrog | } |
1737 | c1713132 | balrog | |
1738 | c227f099 | Anthony Liguori | static PXA2xxI2SState *pxa2xx_i2s_init(target_phys_addr_t base,
|
1739 | bc24a225 | Paul Brook | qemu_irq irq, PXA2xxDMAState *dma) |
1740 | c1713132 | balrog | { |
1741 | c1713132 | balrog | int iomemtype;
|
1742 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) |
1743 | bc24a225 | Paul Brook | qemu_mallocz(sizeof(PXA2xxI2SState));
|
1744 | c1713132 | balrog | |
1745 | c1713132 | balrog | s->irq = irq; |
1746 | c1713132 | balrog | s->dma = dma; |
1747 | c1713132 | balrog | s->data_req = pxa2xx_i2s_data_req; |
1748 | c1713132 | balrog | |
1749 | c1713132 | balrog | pxa2xx_i2s_reset(s); |
1750 | c1713132 | balrog | |
1751 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_i2s_readfn, |
1752 | c1713132 | balrog | pxa2xx_i2s_writefn, s); |
1753 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100000, iomemtype);
|
1754 | c1713132 | balrog | |
1755 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_i2s", base, 0, |
1756 | aa941b94 | balrog | pxa2xx_i2s_save, pxa2xx_i2s_load, s); |
1757 | aa941b94 | balrog | |
1758 | c1713132 | balrog | return s;
|
1759 | c1713132 | balrog | } |
1760 | c1713132 | balrog | |
1761 | c1713132 | balrog | /* PXA Fast Infra-red Communications Port */
|
1762 | bc24a225 | Paul Brook | struct PXA2xxFIrState {
|
1763 | c1713132 | balrog | qemu_irq irq; |
1764 | bc24a225 | Paul Brook | PXA2xxDMAState *dma; |
1765 | c1713132 | balrog | int enable;
|
1766 | c1713132 | balrog | CharDriverState *chr; |
1767 | c1713132 | balrog | |
1768 | c1713132 | balrog | uint8_t control[3];
|
1769 | c1713132 | balrog | uint8_t status[2];
|
1770 | c1713132 | balrog | |
1771 | c1713132 | balrog | int rx_len;
|
1772 | c1713132 | balrog | int rx_start;
|
1773 | c1713132 | balrog | uint8_t rx_fifo[64];
|
1774 | c1713132 | balrog | }; |
1775 | c1713132 | balrog | |
1776 | bc24a225 | Paul Brook | static void pxa2xx_fir_reset(PXA2xxFIrState *s) |
1777 | c1713132 | balrog | { |
1778 | c1713132 | balrog | s->control[0] = 0x00; |
1779 | c1713132 | balrog | s->control[1] = 0x00; |
1780 | c1713132 | balrog | s->control[2] = 0x00; |
1781 | c1713132 | balrog | s->status[0] = 0x00; |
1782 | c1713132 | balrog | s->status[1] = 0x00; |
1783 | c1713132 | balrog | s->enable = 0;
|
1784 | c1713132 | balrog | } |
1785 | c1713132 | balrog | |
1786 | bc24a225 | Paul Brook | static inline void pxa2xx_fir_update(PXA2xxFIrState *s) |
1787 | c1713132 | balrog | { |
1788 | c1713132 | balrog | static const int tresh[4] = { 8, 16, 32, 0 }; |
1789 | c1713132 | balrog | int intr = 0; |
1790 | c1713132 | balrog | if ((s->control[0] & (1 << 4)) && /* RXE */ |
1791 | c1713132 | balrog | s->rx_len >= tresh[s->control[2] & 3]) /* TRIG */ |
1792 | c1713132 | balrog | s->status[0] |= 1 << 4; /* RFS */ |
1793 | c1713132 | balrog | else
|
1794 | c1713132 | balrog | s->status[0] &= ~(1 << 4); /* RFS */ |
1795 | c1713132 | balrog | if (s->control[0] & (1 << 3)) /* TXE */ |
1796 | c1713132 | balrog | s->status[0] |= 1 << 3; /* TFS */ |
1797 | c1713132 | balrog | else
|
1798 | c1713132 | balrog | s->status[0] &= ~(1 << 3); /* TFS */ |
1799 | c1713132 | balrog | if (s->rx_len)
|
1800 | c1713132 | balrog | s->status[1] |= 1 << 2; /* RNE */ |
1801 | c1713132 | balrog | else
|
1802 | c1713132 | balrog | s->status[1] &= ~(1 << 2); /* RNE */ |
1803 | c1713132 | balrog | if (s->control[0] & (1 << 4)) /* RXE */ |
1804 | c1713132 | balrog | s->status[1] |= 1 << 0; /* RSY */ |
1805 | c1713132 | balrog | else
|
1806 | c1713132 | balrog | s->status[1] &= ~(1 << 0); /* RSY */ |
1807 | c1713132 | balrog | |
1808 | c1713132 | balrog | intr |= (s->control[0] & (1 << 5)) && /* RIE */ |
1809 | c1713132 | balrog | (s->status[0] & (1 << 4)); /* RFS */ |
1810 | c1713132 | balrog | intr |= (s->control[0] & (1 << 6)) && /* TIE */ |
1811 | c1713132 | balrog | (s->status[0] & (1 << 3)); /* TFS */ |
1812 | c1713132 | balrog | intr |= (s->control[2] & (1 << 4)) && /* TRAIL */ |
1813 | c1713132 | balrog | (s->status[0] & (1 << 6)); /* EOC */ |
1814 | c1713132 | balrog | intr |= (s->control[0] & (1 << 2)) && /* TUS */ |
1815 | c1713132 | balrog | (s->status[0] & (1 << 1)); /* TUR */ |
1816 | c1713132 | balrog | intr |= s->status[0] & 0x25; /* FRE, RAB, EIF */ |
1817 | c1713132 | balrog | |
1818 | c1713132 | balrog | pxa2xx_dma_request(s->dma, PXA2XX_RX_RQ_ICP, (s->status[0] >> 4) & 1); |
1819 | c1713132 | balrog | pxa2xx_dma_request(s->dma, PXA2XX_TX_RQ_ICP, (s->status[0] >> 3) & 1); |
1820 | c1713132 | balrog | |
1821 | c1713132 | balrog | qemu_set_irq(s->irq, intr && s->enable); |
1822 | c1713132 | balrog | } |
1823 | c1713132 | balrog | |
1824 | c1713132 | balrog | #define ICCR0 0x00 /* FICP Control register 0 */ |
1825 | c1713132 | balrog | #define ICCR1 0x04 /* FICP Control register 1 */ |
1826 | c1713132 | balrog | #define ICCR2 0x08 /* FICP Control register 2 */ |
1827 | c1713132 | balrog | #define ICDR 0x0c /* FICP Data register */ |
1828 | c1713132 | balrog | #define ICSR0 0x14 /* FICP Status register 0 */ |
1829 | c1713132 | balrog | #define ICSR1 0x18 /* FICP Status register 1 */ |
1830 | c1713132 | balrog | #define ICFOR 0x1c /* FICP FIFO Occupancy Status register */ |
1831 | c1713132 | balrog | |
1832 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_fir_read(void *opaque, target_phys_addr_t addr) |
1833 | c1713132 | balrog | { |
1834 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1835 | c1713132 | balrog | uint8_t ret; |
1836 | c1713132 | balrog | |
1837 | c1713132 | balrog | switch (addr) {
|
1838 | c1713132 | balrog | case ICCR0:
|
1839 | c1713132 | balrog | return s->control[0]; |
1840 | c1713132 | balrog | case ICCR1:
|
1841 | c1713132 | balrog | return s->control[1]; |
1842 | c1713132 | balrog | case ICCR2:
|
1843 | c1713132 | balrog | return s->control[2]; |
1844 | c1713132 | balrog | case ICDR:
|
1845 | c1713132 | balrog | s->status[0] &= ~0x01; |
1846 | c1713132 | balrog | s->status[1] &= ~0x72; |
1847 | c1713132 | balrog | if (s->rx_len) {
|
1848 | c1713132 | balrog | s->rx_len --; |
1849 | c1713132 | balrog | ret = s->rx_fifo[s->rx_start ++]; |
1850 | c1713132 | balrog | s->rx_start &= 63;
|
1851 | c1713132 | balrog | pxa2xx_fir_update(s); |
1852 | c1713132 | balrog | return ret;
|
1853 | c1713132 | balrog | } |
1854 | c1713132 | balrog | printf("%s: Rx FIFO underrun.\n", __FUNCTION__);
|
1855 | c1713132 | balrog | break;
|
1856 | c1713132 | balrog | case ICSR0:
|
1857 | c1713132 | balrog | return s->status[0]; |
1858 | c1713132 | balrog | case ICSR1:
|
1859 | c1713132 | balrog | return s->status[1] | (1 << 3); /* TNF */ |
1860 | c1713132 | balrog | case ICFOR:
|
1861 | c1713132 | balrog | return s->rx_len;
|
1862 | c1713132 | balrog | default:
|
1863 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1864 | c1713132 | balrog | break;
|
1865 | c1713132 | balrog | } |
1866 | c1713132 | balrog | return 0; |
1867 | c1713132 | balrog | } |
1868 | c1713132 | balrog | |
1869 | c227f099 | Anthony Liguori | static void pxa2xx_fir_write(void *opaque, target_phys_addr_t addr, |
1870 | c1713132 | balrog | uint32_t value) |
1871 | c1713132 | balrog | { |
1872 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1873 | c1713132 | balrog | uint8_t ch; |
1874 | c1713132 | balrog | |
1875 | c1713132 | balrog | switch (addr) {
|
1876 | c1713132 | balrog | case ICCR0:
|
1877 | c1713132 | balrog | s->control[0] = value;
|
1878 | c1713132 | balrog | if (!(value & (1 << 4))) /* RXE */ |
1879 | c1713132 | balrog | s->rx_len = s->rx_start = 0;
|
1880 | c1713132 | balrog | if (!(value & (1 << 3))) /* TXE */ |
1881 | c1713132 | balrog | /* Nop */;
|
1882 | c1713132 | balrog | s->enable = value & 1; /* ITR */ |
1883 | c1713132 | balrog | if (!s->enable)
|
1884 | c1713132 | balrog | s->status[0] = 0; |
1885 | c1713132 | balrog | pxa2xx_fir_update(s); |
1886 | c1713132 | balrog | break;
|
1887 | c1713132 | balrog | case ICCR1:
|
1888 | c1713132 | balrog | s->control[1] = value;
|
1889 | c1713132 | balrog | break;
|
1890 | c1713132 | balrog | case ICCR2:
|
1891 | c1713132 | balrog | s->control[2] = value & 0x3f; |
1892 | c1713132 | balrog | pxa2xx_fir_update(s); |
1893 | c1713132 | balrog | break;
|
1894 | c1713132 | balrog | case ICDR:
|
1895 | c1713132 | balrog | if (s->control[2] & (1 << 2)) /* TXP */ |
1896 | c1713132 | balrog | ch = value; |
1897 | c1713132 | balrog | else
|
1898 | c1713132 | balrog | ch = ~value; |
1899 | c1713132 | balrog | if (s->chr && s->enable && (s->control[0] & (1 << 3))) /* TXE */ |
1900 | c1713132 | balrog | qemu_chr_write(s->chr, &ch, 1);
|
1901 | c1713132 | balrog | break;
|
1902 | c1713132 | balrog | case ICSR0:
|
1903 | c1713132 | balrog | s->status[0] &= ~(value & 0x66); |
1904 | c1713132 | balrog | pxa2xx_fir_update(s); |
1905 | c1713132 | balrog | break;
|
1906 | c1713132 | balrog | case ICFOR:
|
1907 | c1713132 | balrog | break;
|
1908 | c1713132 | balrog | default:
|
1909 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1910 | c1713132 | balrog | } |
1911 | c1713132 | balrog | } |
1912 | c1713132 | balrog | |
1913 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_fir_readfn[] = { |
1914 | c1713132 | balrog | pxa2xx_fir_read, |
1915 | c1713132 | balrog | pxa2xx_fir_read, |
1916 | c1713132 | balrog | pxa2xx_fir_read, |
1917 | c1713132 | balrog | }; |
1918 | c1713132 | balrog | |
1919 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_fir_writefn[] = { |
1920 | c1713132 | balrog | pxa2xx_fir_write, |
1921 | c1713132 | balrog | pxa2xx_fir_write, |
1922 | c1713132 | balrog | pxa2xx_fir_write, |
1923 | c1713132 | balrog | }; |
1924 | c1713132 | balrog | |
1925 | c1713132 | balrog | static int pxa2xx_fir_is_empty(void *opaque) |
1926 | c1713132 | balrog | { |
1927 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1928 | c1713132 | balrog | return (s->rx_len < 64); |
1929 | c1713132 | balrog | } |
1930 | c1713132 | balrog | |
1931 | c1713132 | balrog | static void pxa2xx_fir_rx(void *opaque, const uint8_t *buf, int size) |
1932 | c1713132 | balrog | { |
1933 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1934 | c1713132 | balrog | if (!(s->control[0] & (1 << 4))) /* RXE */ |
1935 | c1713132 | balrog | return;
|
1936 | c1713132 | balrog | |
1937 | c1713132 | balrog | while (size --) {
|
1938 | c1713132 | balrog | s->status[1] |= 1 << 4; /* EOF */ |
1939 | c1713132 | balrog | if (s->rx_len >= 64) { |
1940 | c1713132 | balrog | s->status[1] |= 1 << 6; /* ROR */ |
1941 | c1713132 | balrog | break;
|
1942 | c1713132 | balrog | } |
1943 | c1713132 | balrog | |
1944 | c1713132 | balrog | if (s->control[2] & (1 << 3)) /* RXP */ |
1945 | c1713132 | balrog | s->rx_fifo[(s->rx_start + s->rx_len ++) & 63] = *(buf ++);
|
1946 | c1713132 | balrog | else
|
1947 | c1713132 | balrog | s->rx_fifo[(s->rx_start + s->rx_len ++) & 63] = ~*(buf ++);
|
1948 | c1713132 | balrog | } |
1949 | c1713132 | balrog | |
1950 | c1713132 | balrog | pxa2xx_fir_update(s); |
1951 | c1713132 | balrog | } |
1952 | c1713132 | balrog | |
1953 | c1713132 | balrog | static void pxa2xx_fir_event(void *opaque, int event) |
1954 | c1713132 | balrog | { |
1955 | c1713132 | balrog | } |
1956 | c1713132 | balrog | |
1957 | aa941b94 | balrog | static void pxa2xx_fir_save(QEMUFile *f, void *opaque) |
1958 | aa941b94 | balrog | { |
1959 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1960 | aa941b94 | balrog | int i;
|
1961 | aa941b94 | balrog | |
1962 | aa941b94 | balrog | qemu_put_be32(f, s->enable); |
1963 | aa941b94 | balrog | |
1964 | aa941b94 | balrog | qemu_put_8s(f, &s->control[0]);
|
1965 | aa941b94 | balrog | qemu_put_8s(f, &s->control[1]);
|
1966 | aa941b94 | balrog | qemu_put_8s(f, &s->control[2]);
|
1967 | aa941b94 | balrog | qemu_put_8s(f, &s->status[0]);
|
1968 | aa941b94 | balrog | qemu_put_8s(f, &s->status[1]);
|
1969 | aa941b94 | balrog | |
1970 | aa941b94 | balrog | qemu_put_byte(f, s->rx_len); |
1971 | aa941b94 | balrog | for (i = 0; i < s->rx_len; i ++) |
1972 | aa941b94 | balrog | qemu_put_byte(f, s->rx_fifo[(s->rx_start + i) & 63]);
|
1973 | aa941b94 | balrog | } |
1974 | aa941b94 | balrog | |
1975 | aa941b94 | balrog | static int pxa2xx_fir_load(QEMUFile *f, void *opaque, int version_id) |
1976 | aa941b94 | balrog | { |
1977 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1978 | aa941b94 | balrog | int i;
|
1979 | aa941b94 | balrog | |
1980 | aa941b94 | balrog | s->enable = qemu_get_be32(f); |
1981 | aa941b94 | balrog | |
1982 | aa941b94 | balrog | qemu_get_8s(f, &s->control[0]);
|
1983 | aa941b94 | balrog | qemu_get_8s(f, &s->control[1]);
|
1984 | aa941b94 | balrog | qemu_get_8s(f, &s->control[2]);
|
1985 | aa941b94 | balrog | qemu_get_8s(f, &s->status[0]);
|
1986 | aa941b94 | balrog | qemu_get_8s(f, &s->status[1]);
|
1987 | aa941b94 | balrog | |
1988 | aa941b94 | balrog | s->rx_len = qemu_get_byte(f); |
1989 | aa941b94 | balrog | s->rx_start = 0;
|
1990 | aa941b94 | balrog | for (i = 0; i < s->rx_len; i ++) |
1991 | aa941b94 | balrog | s->rx_fifo[i] = qemu_get_byte(f); |
1992 | aa941b94 | balrog | |
1993 | aa941b94 | balrog | return 0; |
1994 | aa941b94 | balrog | } |
1995 | aa941b94 | balrog | |
1996 | c227f099 | Anthony Liguori | static PXA2xxFIrState *pxa2xx_fir_init(target_phys_addr_t base,
|
1997 | bc24a225 | Paul Brook | qemu_irq irq, PXA2xxDMAState *dma, |
1998 | c1713132 | balrog | CharDriverState *chr) |
1999 | c1713132 | balrog | { |
2000 | c1713132 | balrog | int iomemtype;
|
2001 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) |
2002 | bc24a225 | Paul Brook | qemu_mallocz(sizeof(PXA2xxFIrState));
|
2003 | c1713132 | balrog | |
2004 | c1713132 | balrog | s->irq = irq; |
2005 | c1713132 | balrog | s->dma = dma; |
2006 | c1713132 | balrog | s->chr = chr; |
2007 | c1713132 | balrog | |
2008 | c1713132 | balrog | pxa2xx_fir_reset(s); |
2009 | c1713132 | balrog | |
2010 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_fir_readfn, |
2011 | c1713132 | balrog | pxa2xx_fir_writefn, s); |
2012 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x1000, iomemtype);
|
2013 | c1713132 | balrog | |
2014 | c1713132 | balrog | if (chr)
|
2015 | c1713132 | balrog | qemu_chr_add_handlers(chr, pxa2xx_fir_is_empty, |
2016 | c1713132 | balrog | pxa2xx_fir_rx, pxa2xx_fir_event, s); |
2017 | c1713132 | balrog | |
2018 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_fir", 0, 0, pxa2xx_fir_save, |
2019 | 0be71e32 | Alex Williamson | pxa2xx_fir_load, s); |
2020 | aa941b94 | balrog | |
2021 | c1713132 | balrog | return s;
|
2022 | c1713132 | balrog | } |
2023 | c1713132 | balrog | |
2024 | 38641a52 | balrog | static void pxa2xx_reset(void *opaque, int line, int level) |
2025 | c1713132 | balrog | { |
2026 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
2027 | 38641a52 | balrog | |
2028 | c1713132 | balrog | if (level && (s->pm_regs[PCFR >> 2] & 0x10)) { /* GPR_EN */ |
2029 | c1713132 | balrog | cpu_reset(s->env); |
2030 | c1713132 | balrog | /* TODO: reset peripherals */
|
2031 | c1713132 | balrog | } |
2032 | c1713132 | balrog | } |
2033 | c1713132 | balrog | |
2034 | c1713132 | balrog | /* Initialise a PXA270 integrated chip (ARM based core). */
|
2035 | bc24a225 | Paul Brook | PXA2xxState *pxa270_init(unsigned int sdram_size, const char *revision) |
2036 | c1713132 | balrog | { |
2037 | bc24a225 | Paul Brook | PXA2xxState *s; |
2038 | c1713132 | balrog | int iomemtype, i;
|
2039 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
2040 | bc24a225 | Paul Brook | s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState));
|
2041 | c1713132 | balrog | |
2042 | 4207117c | balrog | if (revision && strncmp(revision, "pxa27", 5)) { |
2043 | 4207117c | balrog | fprintf(stderr, "Machine requires a PXA27x processor.\n");
|
2044 | 4207117c | balrog | exit(1);
|
2045 | 4207117c | balrog | } |
2046 | aaed909a | bellard | if (!revision)
|
2047 | aaed909a | bellard | revision = "pxa270";
|
2048 | aaed909a | bellard | |
2049 | aaed909a | bellard | s->env = cpu_init(revision); |
2050 | aaed909a | bellard | if (!s->env) {
|
2051 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
2052 | aaed909a | bellard | exit(1);
|
2053 | aaed909a | bellard | } |
2054 | 38641a52 | balrog | s->reset = qemu_allocate_irqs(pxa2xx_reset, s, 1)[0]; |
2055 | 38641a52 | balrog | |
2056 | d95b2f8d | balrog | /* SDRAM & Internal Memory Storage */
|
2057 | d95b2f8d | balrog | cpu_register_physical_memory(PXA2XX_SDRAM_BASE, |
2058 | 1724f049 | Alex Williamson | sdram_size, qemu_ram_alloc(NULL, "pxa270.sdram", |
2059 | 1724f049 | Alex Williamson | sdram_size) | IO_MEM_RAM); |
2060 | d95b2f8d | balrog | cpu_register_physical_memory(PXA2XX_INTERNAL_BASE, |
2061 | 1724f049 | Alex Williamson | 0x40000, qemu_ram_alloc(NULL, "pxa270.internal", |
2062 | 1724f049 | Alex Williamson | 0x40000) | IO_MEM_RAM);
|
2063 | d95b2f8d | balrog | |
2064 | c1713132 | balrog | s->pic = pxa2xx_pic_init(0x40d00000, s->env);
|
2065 | c1713132 | balrog | |
2066 | c1713132 | balrog | s->dma = pxa27x_dma_init(0x40000000, s->pic[PXA2XX_PIC_DMA]);
|
2067 | c1713132 | balrog | |
2068 | a171fe39 | balrog | pxa27x_timer_init(0x40a00000, &s->pic[PXA2XX_PIC_OST_0],
|
2069 | 3f582262 | balrog | s->pic[PXA27X_PIC_OST_4_11]); |
2070 | a171fe39 | balrog | |
2071 | c1713132 | balrog | s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 121); |
2072 | c1713132 | balrog | |
2073 | 751c6a17 | Gerd Hoffmann | dinfo = drive_get(IF_SD, 0, 0); |
2074 | 751c6a17 | Gerd Hoffmann | if (!dinfo) {
|
2075 | e4bcb14c | ths | fprintf(stderr, "qemu: missing SecureDigital device\n");
|
2076 | e4bcb14c | ths | exit(1);
|
2077 | e4bcb14c | ths | } |
2078 | 751c6a17 | Gerd Hoffmann | s->mmc = pxa2xx_mmci_init(0x41100000, dinfo->bdrv,
|
2079 | e4bcb14c | ths | s->pic[PXA2XX_PIC_MMC], s->dma); |
2080 | a171fe39 | balrog | |
2081 | c1713132 | balrog | for (i = 0; pxa270_serial[i].io_base; i ++) |
2082 | c1713132 | balrog | if (serial_hds[i])
|
2083 | 2d48377a | Blue Swirl | #ifdef TARGET_WORDS_BIGENDIAN
|
2084 | c1713132 | balrog | serial_mm_init(pxa270_serial[i].io_base, 2,
|
2085 | b6cd0ea1 | aurel32 | s->pic[pxa270_serial[i].irqn], 14857000/16, |
2086 | 2d48377a | Blue Swirl | serial_hds[i], 1, 1); |
2087 | 2d48377a | Blue Swirl | #else
|
2088 | 2d48377a | Blue Swirl | serial_mm_init(pxa270_serial[i].io_base, 2,
|
2089 | 2d48377a | Blue Swirl | s->pic[pxa270_serial[i].irqn], 14857000/16, |
2090 | 6725f3fa | Lars Munch | serial_hds[i], 1, 0); |
2091 | 2d48377a | Blue Swirl | #endif
|
2092 | c1713132 | balrog | else
|
2093 | c1713132 | balrog | break;
|
2094 | c1713132 | balrog | if (serial_hds[i])
|
2095 | c1713132 | balrog | s->fir = pxa2xx_fir_init(0x40800000, s->pic[PXA2XX_PIC_ICP],
|
2096 | c1713132 | balrog | s->dma, serial_hds[i]); |
2097 | c1713132 | balrog | |
2098 | 3023f332 | aliguori | s->lcd = pxa2xx_lcdc_init(0x44000000, s->pic[PXA2XX_PIC_LCD]);
|
2099 | a171fe39 | balrog | |
2100 | c1713132 | balrog | s->cm_base = 0x41300000;
|
2101 | 82d17978 | balrog | s->cm_regs[CCCR >> 2] = 0x02000210; /* 416.0 MHz */ |
2102 | c1713132 | balrog | s->clkcfg = 0x00000009; /* Turbo mode active */ |
2103 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_cm_readfn, |
2104 | c1713132 | balrog | pxa2xx_cm_writefn, s); |
2105 | 187337f8 | pbrook | cpu_register_physical_memory(s->cm_base, 0x1000, iomemtype);
|
2106 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_cm", 0, 0, pxa2xx_cm_save, pxa2xx_cm_load, s); |
2107 | c1713132 | balrog | |
2108 | c1713132 | balrog | cpu_arm_set_cp_io(s->env, 14, pxa2xx_cp14_read, pxa2xx_cp14_write, s);
|
2109 | c1713132 | balrog | |
2110 | c1713132 | balrog | s->mm_base = 0x48000000;
|
2111 | c1713132 | balrog | s->mm_regs[MDMRS >> 2] = 0x00020002; |
2112 | c1713132 | balrog | s->mm_regs[MDREFR >> 2] = 0x03ca4000; |
2113 | c1713132 | balrog | s->mm_regs[MECR >> 2] = 0x00000001; /* Two PC Card sockets */ |
2114 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_mm_readfn, |
2115 | c1713132 | balrog | pxa2xx_mm_writefn, s); |
2116 | 187337f8 | pbrook | cpu_register_physical_memory(s->mm_base, 0x1000, iomemtype);
|
2117 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_mm", 0, 0, pxa2xx_mm_save, pxa2xx_mm_load, s); |
2118 | c1713132 | balrog | |
2119 | 2a163929 | balrog | s->pm_base = 0x40f00000;
|
2120 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_pm_readfn, |
2121 | 2a163929 | balrog | pxa2xx_pm_writefn, s); |
2122 | 187337f8 | pbrook | cpu_register_physical_memory(s->pm_base, 0x100, iomemtype);
|
2123 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_pm", 0, 0, pxa2xx_pm_save, pxa2xx_pm_load, s); |
2124 | 2a163929 | balrog | |
2125 | c1713132 | balrog | for (i = 0; pxa27x_ssp[i].io_base; i ++); |
2126 | a984a69e | Paul Brook | s->ssp = (SSIBus **)qemu_mallocz(sizeof(SSIBus *) * i);
|
2127 | c1713132 | balrog | for (i = 0; pxa27x_ssp[i].io_base; i ++) { |
2128 | a984a69e | Paul Brook | DeviceState *dev; |
2129 | a984a69e | Paul Brook | dev = sysbus_create_simple("pxa2xx-ssp", pxa27x_ssp[i].io_base,
|
2130 | a984a69e | Paul Brook | s->pic[pxa27x_ssp[i].irqn]); |
2131 | 02e2da45 | Paul Brook | s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
|
2132 | c1713132 | balrog | } |
2133 | c1713132 | balrog | |
2134 | a171fe39 | balrog | if (usb_enabled) {
|
2135 | 61d3cf93 | Paul Brook | sysbus_create_simple("sysbus-ohci", 0x4c000000, |
2136 | 61d3cf93 | Paul Brook | s->pic[PXA2XX_PIC_USBH1]); |
2137 | a171fe39 | balrog | } |
2138 | a171fe39 | balrog | |
2139 | a171fe39 | balrog | s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000); |
2140 | a171fe39 | balrog | s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000); |
2141 | a171fe39 | balrog | |
2142 | c1713132 | balrog | s->rtc_base = 0x40900000;
|
2143 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_rtc_readfn, |
2144 | c1713132 | balrog | pxa2xx_rtc_writefn, s); |
2145 | 187337f8 | pbrook | cpu_register_physical_memory(s->rtc_base, 0x1000, iomemtype);
|
2146 | aa941b94 | balrog | pxa2xx_rtc_init(s); |
2147 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_rtc", 0, 0, pxa2xx_rtc_save, |
2148 | 0be71e32 | Alex Williamson | pxa2xx_rtc_load, s); |
2149 | c1713132 | balrog | |
2150 | 2a163929 | balrog | s->i2c[0] = pxa2xx_i2c_init(0x40301600, s->pic[PXA2XX_PIC_I2C], 0xffff); |
2151 | 2a163929 | balrog | s->i2c[1] = pxa2xx_i2c_init(0x40f00100, s->pic[PXA2XX_PIC_PWRI2C], 0xff); |
2152 | c1713132 | balrog | |
2153 | c1713132 | balrog | s->i2s = pxa2xx_i2s_init(0x40400000, s->pic[PXA2XX_PIC_I2S], s->dma);
|
2154 | c1713132 | balrog | |
2155 | 31b87f2e | balrog | s->kp = pxa27x_keypad_init(0x41500000, s->pic[PXA2XX_PIC_KEYPAD]);
|
2156 | 31b87f2e | balrog | |
2157 | c1713132 | balrog | /* GPIO1 resets the processor */
|
2158 | fe8f096b | ths | /* The handler can be overridden by board-specific code */
|
2159 | 38641a52 | balrog | pxa2xx_gpio_out_set(s->gpio, 1, s->reset);
|
2160 | c1713132 | balrog | return s;
|
2161 | c1713132 | balrog | } |
2162 | c1713132 | balrog | |
2163 | c1713132 | balrog | /* Initialise a PXA255 integrated chip (ARM based core). */
|
2164 | bc24a225 | Paul Brook | PXA2xxState *pxa255_init(unsigned int sdram_size) |
2165 | c1713132 | balrog | { |
2166 | bc24a225 | Paul Brook | PXA2xxState *s; |
2167 | c1713132 | balrog | int iomemtype, i;
|
2168 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
2169 | aaed909a | bellard | |
2170 | bc24a225 | Paul Brook | s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState));
|
2171 | c1713132 | balrog | |
2172 | aaed909a | bellard | s->env = cpu_init("pxa255");
|
2173 | aaed909a | bellard | if (!s->env) {
|
2174 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
2175 | aaed909a | bellard | exit(1);
|
2176 | aaed909a | bellard | } |
2177 | 38641a52 | balrog | s->reset = qemu_allocate_irqs(pxa2xx_reset, s, 1)[0]; |
2178 | 38641a52 | balrog | |
2179 | d95b2f8d | balrog | /* SDRAM & Internal Memory Storage */
|
2180 | a07dec22 | balrog | cpu_register_physical_memory(PXA2XX_SDRAM_BASE, sdram_size, |
2181 | 1724f049 | Alex Williamson | qemu_ram_alloc(NULL, "pxa255.sdram", |
2182 | 1724f049 | Alex Williamson | sdram_size) | IO_MEM_RAM); |
2183 | a07dec22 | balrog | cpu_register_physical_memory(PXA2XX_INTERNAL_BASE, PXA2XX_INTERNAL_SIZE, |
2184 | 1724f049 | Alex Williamson | qemu_ram_alloc(NULL, "pxa255.internal", |
2185 | 1724f049 | Alex Williamson | PXA2XX_INTERNAL_SIZE) | IO_MEM_RAM); |
2186 | d95b2f8d | balrog | |
2187 | c1713132 | balrog | s->pic = pxa2xx_pic_init(0x40d00000, s->env);
|
2188 | c1713132 | balrog | |
2189 | c1713132 | balrog | s->dma = pxa255_dma_init(0x40000000, s->pic[PXA2XX_PIC_DMA]);
|
2190 | c1713132 | balrog | |
2191 | 3f582262 | balrog | pxa25x_timer_init(0x40a00000, &s->pic[PXA2XX_PIC_OST_0]);
|
2192 | a171fe39 | balrog | |
2193 | 3bdd58a4 | balrog | s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 85); |
2194 | c1713132 | balrog | |
2195 | 751c6a17 | Gerd Hoffmann | dinfo = drive_get(IF_SD, 0, 0); |
2196 | 751c6a17 | Gerd Hoffmann | if (!dinfo) {
|
2197 | e4bcb14c | ths | fprintf(stderr, "qemu: missing SecureDigital device\n");
|
2198 | e4bcb14c | ths | exit(1);
|
2199 | e4bcb14c | ths | } |
2200 | 751c6a17 | Gerd Hoffmann | s->mmc = pxa2xx_mmci_init(0x41100000, dinfo->bdrv,
|
2201 | e4bcb14c | ths | s->pic[PXA2XX_PIC_MMC], s->dma); |
2202 | a171fe39 | balrog | |
2203 | c1713132 | balrog | for (i = 0; pxa255_serial[i].io_base; i ++) |
2204 | 2d48377a | Blue Swirl | if (serial_hds[i]) {
|
2205 | 2d48377a | Blue Swirl | #ifdef TARGET_WORDS_BIGENDIAN
|
2206 | c1713132 | balrog | serial_mm_init(pxa255_serial[i].io_base, 2,
|
2207 | b6cd0ea1 | aurel32 | s->pic[pxa255_serial[i].irqn], 14745600/16, |
2208 | 2d48377a | Blue Swirl | serial_hds[i], 1, 1); |
2209 | 2d48377a | Blue Swirl | #else
|
2210 | 2d48377a | Blue Swirl | serial_mm_init(pxa255_serial[i].io_base, 2,
|
2211 | 2d48377a | Blue Swirl | s->pic[pxa255_serial[i].irqn], 14745600/16, |
2212 | 2d48377a | Blue Swirl | serial_hds[i], 1, 0); |
2213 | 2d48377a | Blue Swirl | #endif
|
2214 | 2d48377a | Blue Swirl | } else {
|
2215 | c1713132 | balrog | break;
|
2216 | 2d48377a | Blue Swirl | } |
2217 | c1713132 | balrog | if (serial_hds[i])
|
2218 | c1713132 | balrog | s->fir = pxa2xx_fir_init(0x40800000, s->pic[PXA2XX_PIC_ICP],
|
2219 | c1713132 | balrog | s->dma, serial_hds[i]); |
2220 | c1713132 | balrog | |
2221 | 3023f332 | aliguori | s->lcd = pxa2xx_lcdc_init(0x44000000, s->pic[PXA2XX_PIC_LCD]);
|
2222 | a171fe39 | balrog | |
2223 | c1713132 | balrog | s->cm_base = 0x41300000;
|
2224 | 82d17978 | balrog | s->cm_regs[CCCR >> 2] = 0x02000210; /* 416.0 MHz */ |
2225 | c1713132 | balrog | s->clkcfg = 0x00000009; /* Turbo mode active */ |
2226 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_cm_readfn, |
2227 | c1713132 | balrog | pxa2xx_cm_writefn, s); |
2228 | 187337f8 | pbrook | cpu_register_physical_memory(s->cm_base, 0x1000, iomemtype);
|
2229 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_cm", 0, 0, pxa2xx_cm_save, pxa2xx_cm_load, s); |
2230 | c1713132 | balrog | |
2231 | c1713132 | balrog | cpu_arm_set_cp_io(s->env, 14, pxa2xx_cp14_read, pxa2xx_cp14_write, s);
|
2232 | c1713132 | balrog | |
2233 | c1713132 | balrog | s->mm_base = 0x48000000;
|
2234 | c1713132 | balrog | s->mm_regs[MDMRS >> 2] = 0x00020002; |
2235 | c1713132 | balrog | s->mm_regs[MDREFR >> 2] = 0x03ca4000; |
2236 | c1713132 | balrog | s->mm_regs[MECR >> 2] = 0x00000001; /* Two PC Card sockets */ |
2237 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_mm_readfn, |
2238 | c1713132 | balrog | pxa2xx_mm_writefn, s); |
2239 | 187337f8 | pbrook | cpu_register_physical_memory(s->mm_base, 0x1000, iomemtype);
|
2240 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_mm", 0, 0, pxa2xx_mm_save, pxa2xx_mm_load, s); |
2241 | c1713132 | balrog | |
2242 | 2a163929 | balrog | s->pm_base = 0x40f00000;
|
2243 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_pm_readfn, |
2244 | 2a163929 | balrog | pxa2xx_pm_writefn, s); |
2245 | 187337f8 | pbrook | cpu_register_physical_memory(s->pm_base, 0x100, iomemtype);
|
2246 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_pm", 0, 0, pxa2xx_pm_save, pxa2xx_pm_load, s); |
2247 | 2a163929 | balrog | |
2248 | c1713132 | balrog | for (i = 0; pxa255_ssp[i].io_base; i ++); |
2249 | a984a69e | Paul Brook | s->ssp = (SSIBus **)qemu_mallocz(sizeof(SSIBus *) * i);
|
2250 | c1713132 | balrog | for (i = 0; pxa255_ssp[i].io_base; i ++) { |
2251 | a984a69e | Paul Brook | DeviceState *dev; |
2252 | a984a69e | Paul Brook | dev = sysbus_create_simple("pxa2xx-ssp", pxa255_ssp[i].io_base,
|
2253 | a984a69e | Paul Brook | s->pic[pxa255_ssp[i].irqn]); |
2254 | 02e2da45 | Paul Brook | s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
|
2255 | c1713132 | balrog | } |
2256 | c1713132 | balrog | |
2257 | a171fe39 | balrog | if (usb_enabled) {
|
2258 | 61d3cf93 | Paul Brook | sysbus_create_simple("sysbus-ohci", 0x4c000000, |
2259 | 61d3cf93 | Paul Brook | s->pic[PXA2XX_PIC_USBH1]); |
2260 | a171fe39 | balrog | } |
2261 | a171fe39 | balrog | |
2262 | a171fe39 | balrog | s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000); |
2263 | a171fe39 | balrog | s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000); |
2264 | a171fe39 | balrog | |
2265 | c1713132 | balrog | s->rtc_base = 0x40900000;
|
2266 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_rtc_readfn, |
2267 | c1713132 | balrog | pxa2xx_rtc_writefn, s); |
2268 | 187337f8 | pbrook | cpu_register_physical_memory(s->rtc_base, 0x1000, iomemtype);
|
2269 | aa941b94 | balrog | pxa2xx_rtc_init(s); |
2270 | 0be71e32 | Alex Williamson | register_savevm(NULL, "pxa2xx_rtc", 0, 0, pxa2xx_rtc_save, |
2271 | 0be71e32 | Alex Williamson | pxa2xx_rtc_load, s); |
2272 | c1713132 | balrog | |
2273 | 2a163929 | balrog | s->i2c[0] = pxa2xx_i2c_init(0x40301600, s->pic[PXA2XX_PIC_I2C], 0xffff); |
2274 | 2a163929 | balrog | s->i2c[1] = pxa2xx_i2c_init(0x40f00100, s->pic[PXA2XX_PIC_PWRI2C], 0xff); |
2275 | c1713132 | balrog | |
2276 | c1713132 | balrog | s->i2s = pxa2xx_i2s_init(0x40400000, s->pic[PXA2XX_PIC_I2S], s->dma);
|
2277 | c1713132 | balrog | |
2278 | c1713132 | balrog | /* GPIO1 resets the processor */
|
2279 | fe8f096b | ths | /* The handler can be overridden by board-specific code */
|
2280 | 38641a52 | balrog | pxa2xx_gpio_out_set(s->gpio, 1, s->reset);
|
2281 | c1713132 | balrog | return s;
|
2282 | c1713132 | balrog | } |
2283 | e3b42536 | Paul Brook | |
2284 | e3b42536 | Paul Brook | static void pxa2xx_register_devices(void) |
2285 | e3b42536 | Paul Brook | { |
2286 | 074f2fff | Gerd Hoffmann | i2c_register_slave(&pxa2xx_i2c_slave_info); |
2287 | a984a69e | Paul Brook | sysbus_register_dev("pxa2xx-ssp", sizeof(PXA2xxSSPState), pxa2xx_ssp_init); |
2288 | e3b42536 | Paul Brook | } |
2289 | e3b42536 | Paul Brook | |
2290 | e3b42536 | Paul Brook | device_init(pxa2xx_register_devices) |