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