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