root / hw / pxa2xx.c @ 8a637d44
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 | a984a69e | Paul Brook | iomemtype = cpu_register_io_memory(0, 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 | a984a69e | Paul Brook | s->bus = ssi_create_bus(); |
867 | a984a69e | Paul Brook | qdev_attach_child_bus(&dev->qdev, "ssi", s->bus);
|
868 | a984a69e | Paul Brook | } |
869 | a984a69e | Paul Brook | |
870 | c1713132 | balrog | /* Real-Time Clock */
|
871 | c1713132 | balrog | #define RCNR 0x00 /* RTC Counter register */ |
872 | c1713132 | balrog | #define RTAR 0x04 /* RTC Alarm register */ |
873 | c1713132 | balrog | #define RTSR 0x08 /* RTC Status register */ |
874 | c1713132 | balrog | #define RTTR 0x0c /* RTC Timer Trim register */ |
875 | c1713132 | balrog | #define RDCR 0x10 /* RTC Day Counter register */ |
876 | c1713132 | balrog | #define RYCR 0x14 /* RTC Year Counter register */ |
877 | c1713132 | balrog | #define RDAR1 0x18 /* RTC Wristwatch Day Alarm register 1 */ |
878 | c1713132 | balrog | #define RYAR1 0x1c /* RTC Wristwatch Year Alarm register 1 */ |
879 | c1713132 | balrog | #define RDAR2 0x20 /* RTC Wristwatch Day Alarm register 2 */ |
880 | c1713132 | balrog | #define RYAR2 0x24 /* RTC Wristwatch Year Alarm register 2 */ |
881 | c1713132 | balrog | #define SWCR 0x28 /* RTC Stopwatch Counter register */ |
882 | c1713132 | balrog | #define SWAR1 0x2c /* RTC Stopwatch Alarm register 1 */ |
883 | c1713132 | balrog | #define SWAR2 0x30 /* RTC Stopwatch Alarm register 2 */ |
884 | c1713132 | balrog | #define RTCPICR 0x34 /* RTC Periodic Interrupt Counter register */ |
885 | c1713132 | balrog | #define PIAR 0x38 /* RTC Periodic Interrupt Alarm register */ |
886 | c1713132 | balrog | |
887 | bc24a225 | Paul Brook | static inline void pxa2xx_rtc_int_update(PXA2xxState *s) |
888 | c1713132 | balrog | { |
889 | c1713132 | balrog | qemu_set_irq(s->pic[PXA2XX_PIC_RTCALARM], !!(s->rtsr & 0x2553));
|
890 | c1713132 | balrog | } |
891 | c1713132 | balrog | |
892 | bc24a225 | Paul Brook | static void pxa2xx_rtc_hzupdate(PXA2xxState *s) |
893 | c1713132 | balrog | { |
894 | c1713132 | balrog | int64_t rt = qemu_get_clock(rt_clock); |
895 | c1713132 | balrog | s->last_rcnr += ((rt - s->last_hz) << 15) /
|
896 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
897 | c1713132 | balrog | s->last_rdcr += ((rt - s->last_hz) << 15) /
|
898 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
899 | c1713132 | balrog | s->last_hz = rt; |
900 | c1713132 | balrog | } |
901 | c1713132 | balrog | |
902 | bc24a225 | Paul Brook | static void pxa2xx_rtc_swupdate(PXA2xxState *s) |
903 | c1713132 | balrog | { |
904 | c1713132 | balrog | int64_t rt = qemu_get_clock(rt_clock); |
905 | c1713132 | balrog | if (s->rtsr & (1 << 12)) |
906 | c1713132 | balrog | s->last_swcr += (rt - s->last_sw) / 10;
|
907 | c1713132 | balrog | s->last_sw = rt; |
908 | c1713132 | balrog | } |
909 | c1713132 | balrog | |
910 | bc24a225 | Paul Brook | static void pxa2xx_rtc_piupdate(PXA2xxState *s) |
911 | c1713132 | balrog | { |
912 | c1713132 | balrog | int64_t rt = qemu_get_clock(rt_clock); |
913 | c1713132 | balrog | if (s->rtsr & (1 << 15)) |
914 | c1713132 | balrog | s->last_swcr += rt - s->last_pi; |
915 | c1713132 | balrog | s->last_pi = rt; |
916 | c1713132 | balrog | } |
917 | c1713132 | balrog | |
918 | bc24a225 | Paul Brook | static inline void pxa2xx_rtc_alarm_update(PXA2xxState *s, |
919 | c1713132 | balrog | uint32_t rtsr) |
920 | c1713132 | balrog | { |
921 | c1713132 | balrog | if ((rtsr & (1 << 2)) && !(rtsr & (1 << 0))) |
922 | c1713132 | balrog | qemu_mod_timer(s->rtc_hz, s->last_hz + |
923 | c1713132 | balrog | (((s->rtar - s->last_rcnr) * 1000 *
|
924 | c1713132 | balrog | ((s->rttr & 0xffff) + 1)) >> 15)); |
925 | c1713132 | balrog | else
|
926 | c1713132 | balrog | qemu_del_timer(s->rtc_hz); |
927 | c1713132 | balrog | |
928 | c1713132 | balrog | if ((rtsr & (1 << 5)) && !(rtsr & (1 << 4))) |
929 | c1713132 | balrog | qemu_mod_timer(s->rtc_rdal1, s->last_hz + |
930 | c1713132 | balrog | (((s->rdar1 - s->last_rdcr) * 1000 *
|
931 | c1713132 | balrog | ((s->rttr & 0xffff) + 1)) >> 15)); /* TODO: fixup */ |
932 | c1713132 | balrog | else
|
933 | c1713132 | balrog | qemu_del_timer(s->rtc_rdal1); |
934 | c1713132 | balrog | |
935 | c1713132 | balrog | if ((rtsr & (1 << 7)) && !(rtsr & (1 << 6))) |
936 | c1713132 | balrog | qemu_mod_timer(s->rtc_rdal2, s->last_hz + |
937 | c1713132 | balrog | (((s->rdar2 - s->last_rdcr) * 1000 *
|
938 | c1713132 | balrog | ((s->rttr & 0xffff) + 1)) >> 15)); /* TODO: fixup */ |
939 | c1713132 | balrog | else
|
940 | c1713132 | balrog | qemu_del_timer(s->rtc_rdal2); |
941 | c1713132 | balrog | |
942 | c1713132 | balrog | if ((rtsr & 0x1200) == 0x1200 && !(rtsr & (1 << 8))) |
943 | c1713132 | balrog | qemu_mod_timer(s->rtc_swal1, s->last_sw + |
944 | c1713132 | balrog | (s->swar1 - s->last_swcr) * 10); /* TODO: fixup */ |
945 | c1713132 | balrog | else
|
946 | c1713132 | balrog | qemu_del_timer(s->rtc_swal1); |
947 | c1713132 | balrog | |
948 | c1713132 | balrog | if ((rtsr & 0x1800) == 0x1800 && !(rtsr & (1 << 10))) |
949 | c1713132 | balrog | qemu_mod_timer(s->rtc_swal2, s->last_sw + |
950 | c1713132 | balrog | (s->swar2 - s->last_swcr) * 10); /* TODO: fixup */ |
951 | c1713132 | balrog | else
|
952 | c1713132 | balrog | qemu_del_timer(s->rtc_swal2); |
953 | c1713132 | balrog | |
954 | c1713132 | balrog | if ((rtsr & 0xc000) == 0xc000 && !(rtsr & (1 << 13))) |
955 | c1713132 | balrog | qemu_mod_timer(s->rtc_pi, s->last_pi + |
956 | c1713132 | balrog | (s->piar & 0xffff) - s->last_rtcpicr);
|
957 | c1713132 | balrog | else
|
958 | c1713132 | balrog | qemu_del_timer(s->rtc_pi); |
959 | c1713132 | balrog | } |
960 | c1713132 | balrog | |
961 | c1713132 | balrog | static inline void pxa2xx_rtc_hz_tick(void *opaque) |
962 | c1713132 | balrog | { |
963 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
964 | c1713132 | balrog | s->rtsr |= (1 << 0); |
965 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
966 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
967 | c1713132 | balrog | } |
968 | c1713132 | balrog | |
969 | c1713132 | balrog | static inline void pxa2xx_rtc_rdal1_tick(void *opaque) |
970 | c1713132 | balrog | { |
971 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
972 | c1713132 | balrog | s->rtsr |= (1 << 4); |
973 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
974 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
975 | c1713132 | balrog | } |
976 | c1713132 | balrog | |
977 | c1713132 | balrog | static inline void pxa2xx_rtc_rdal2_tick(void *opaque) |
978 | c1713132 | balrog | { |
979 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
980 | c1713132 | balrog | s->rtsr |= (1 << 6); |
981 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
982 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
983 | c1713132 | balrog | } |
984 | c1713132 | balrog | |
985 | c1713132 | balrog | static inline void pxa2xx_rtc_swal1_tick(void *opaque) |
986 | c1713132 | balrog | { |
987 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
988 | c1713132 | balrog | s->rtsr |= (1 << 8); |
989 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
990 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
991 | c1713132 | balrog | } |
992 | c1713132 | balrog | |
993 | c1713132 | balrog | static inline void pxa2xx_rtc_swal2_tick(void *opaque) |
994 | c1713132 | balrog | { |
995 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
996 | c1713132 | balrog | s->rtsr |= (1 << 10); |
997 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
998 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
999 | c1713132 | balrog | } |
1000 | c1713132 | balrog | |
1001 | c1713132 | balrog | static inline void pxa2xx_rtc_pi_tick(void *opaque) |
1002 | c1713132 | balrog | { |
1003 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1004 | c1713132 | balrog | s->rtsr |= (1 << 13); |
1005 | c1713132 | balrog | pxa2xx_rtc_piupdate(s); |
1006 | c1713132 | balrog | s->last_rtcpicr = 0;
|
1007 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1008 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
1009 | c1713132 | balrog | } |
1010 | c1713132 | balrog | |
1011 | c1713132 | balrog | static uint32_t pxa2xx_rtc_read(void *opaque, target_phys_addr_t addr) |
1012 | c1713132 | balrog | { |
1013 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1014 | c1713132 | balrog | |
1015 | c1713132 | balrog | switch (addr) {
|
1016 | c1713132 | balrog | case RTTR:
|
1017 | c1713132 | balrog | return s->rttr;
|
1018 | c1713132 | balrog | case RTSR:
|
1019 | c1713132 | balrog | return s->rtsr;
|
1020 | c1713132 | balrog | case RTAR:
|
1021 | c1713132 | balrog | return s->rtar;
|
1022 | c1713132 | balrog | case RDAR1:
|
1023 | c1713132 | balrog | return s->rdar1;
|
1024 | c1713132 | balrog | case RDAR2:
|
1025 | c1713132 | balrog | return s->rdar2;
|
1026 | c1713132 | balrog | case RYAR1:
|
1027 | c1713132 | balrog | return s->ryar1;
|
1028 | c1713132 | balrog | case RYAR2:
|
1029 | c1713132 | balrog | return s->ryar2;
|
1030 | c1713132 | balrog | case SWAR1:
|
1031 | c1713132 | balrog | return s->swar1;
|
1032 | c1713132 | balrog | case SWAR2:
|
1033 | c1713132 | balrog | return s->swar2;
|
1034 | c1713132 | balrog | case PIAR:
|
1035 | c1713132 | balrog | return s->piar;
|
1036 | c1713132 | balrog | case RCNR:
|
1037 | c1713132 | balrog | return s->last_rcnr + ((qemu_get_clock(rt_clock) - s->last_hz) << 15) / |
1038 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
1039 | c1713132 | balrog | case RDCR:
|
1040 | c1713132 | balrog | return s->last_rdcr + ((qemu_get_clock(rt_clock) - s->last_hz) << 15) / |
1041 | c1713132 | balrog | (1000 * ((s->rttr & 0xffff) + 1)); |
1042 | c1713132 | balrog | case RYCR:
|
1043 | c1713132 | balrog | return s->last_rycr;
|
1044 | c1713132 | balrog | case SWCR:
|
1045 | c1713132 | balrog | if (s->rtsr & (1 << 12)) |
1046 | c1713132 | balrog | return s->last_swcr + (qemu_get_clock(rt_clock) - s->last_sw) / 10; |
1047 | c1713132 | balrog | else
|
1048 | c1713132 | balrog | return s->last_swcr;
|
1049 | c1713132 | balrog | default:
|
1050 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1051 | c1713132 | balrog | break;
|
1052 | c1713132 | balrog | } |
1053 | c1713132 | balrog | return 0; |
1054 | c1713132 | balrog | } |
1055 | c1713132 | balrog | |
1056 | c1713132 | balrog | static void pxa2xx_rtc_write(void *opaque, target_phys_addr_t addr, |
1057 | c1713132 | balrog | uint32_t value) |
1058 | c1713132 | balrog | { |
1059 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1060 | c1713132 | balrog | |
1061 | c1713132 | balrog | switch (addr) {
|
1062 | c1713132 | balrog | case RTTR:
|
1063 | c1713132 | balrog | if (!(s->rttr & (1 << 31))) { |
1064 | c1713132 | balrog | pxa2xx_rtc_hzupdate(s); |
1065 | c1713132 | balrog | s->rttr = value; |
1066 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1067 | c1713132 | balrog | } |
1068 | c1713132 | balrog | break;
|
1069 | c1713132 | balrog | |
1070 | c1713132 | balrog | case RTSR:
|
1071 | c1713132 | balrog | if ((s->rtsr ^ value) & (1 << 15)) |
1072 | c1713132 | balrog | pxa2xx_rtc_piupdate(s); |
1073 | c1713132 | balrog | |
1074 | c1713132 | balrog | if ((s->rtsr ^ value) & (1 << 12)) |
1075 | c1713132 | balrog | pxa2xx_rtc_swupdate(s); |
1076 | c1713132 | balrog | |
1077 | c1713132 | balrog | if (((s->rtsr ^ value) & 0x4aac) | (value & ~0xdaac)) |
1078 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, value); |
1079 | c1713132 | balrog | |
1080 | c1713132 | balrog | s->rtsr = (value & 0xdaac) | (s->rtsr & ~(value & ~0xdaac)); |
1081 | c1713132 | balrog | pxa2xx_rtc_int_update(s); |
1082 | c1713132 | balrog | break;
|
1083 | c1713132 | balrog | |
1084 | c1713132 | balrog | case RTAR:
|
1085 | c1713132 | balrog | s->rtar = value; |
1086 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1087 | c1713132 | balrog | break;
|
1088 | c1713132 | balrog | |
1089 | c1713132 | balrog | case RDAR1:
|
1090 | c1713132 | balrog | s->rdar1 = value; |
1091 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1092 | c1713132 | balrog | break;
|
1093 | c1713132 | balrog | |
1094 | c1713132 | balrog | case RDAR2:
|
1095 | c1713132 | balrog | s->rdar2 = value; |
1096 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1097 | c1713132 | balrog | break;
|
1098 | c1713132 | balrog | |
1099 | c1713132 | balrog | case RYAR1:
|
1100 | c1713132 | balrog | s->ryar1 = value; |
1101 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1102 | c1713132 | balrog | break;
|
1103 | c1713132 | balrog | |
1104 | c1713132 | balrog | case RYAR2:
|
1105 | c1713132 | balrog | s->ryar2 = value; |
1106 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1107 | c1713132 | balrog | break;
|
1108 | c1713132 | balrog | |
1109 | c1713132 | balrog | case SWAR1:
|
1110 | c1713132 | balrog | pxa2xx_rtc_swupdate(s); |
1111 | c1713132 | balrog | s->swar1 = value; |
1112 | c1713132 | balrog | s->last_swcr = 0;
|
1113 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1114 | c1713132 | balrog | break;
|
1115 | c1713132 | balrog | |
1116 | c1713132 | balrog | case SWAR2:
|
1117 | c1713132 | balrog | s->swar2 = value; |
1118 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1119 | c1713132 | balrog | break;
|
1120 | c1713132 | balrog | |
1121 | c1713132 | balrog | case PIAR:
|
1122 | c1713132 | balrog | s->piar = value; |
1123 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1124 | c1713132 | balrog | break;
|
1125 | c1713132 | balrog | |
1126 | c1713132 | balrog | case RCNR:
|
1127 | c1713132 | balrog | pxa2xx_rtc_hzupdate(s); |
1128 | c1713132 | balrog | s->last_rcnr = value; |
1129 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1130 | c1713132 | balrog | break;
|
1131 | c1713132 | balrog | |
1132 | c1713132 | balrog | case RDCR:
|
1133 | c1713132 | balrog | pxa2xx_rtc_hzupdate(s); |
1134 | c1713132 | balrog | s->last_rdcr = value; |
1135 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1136 | c1713132 | balrog | break;
|
1137 | c1713132 | balrog | |
1138 | c1713132 | balrog | case RYCR:
|
1139 | c1713132 | balrog | s->last_rycr = value; |
1140 | c1713132 | balrog | break;
|
1141 | c1713132 | balrog | |
1142 | c1713132 | balrog | case SWCR:
|
1143 | c1713132 | balrog | pxa2xx_rtc_swupdate(s); |
1144 | c1713132 | balrog | s->last_swcr = value; |
1145 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1146 | c1713132 | balrog | break;
|
1147 | c1713132 | balrog | |
1148 | c1713132 | balrog | case RTCPICR:
|
1149 | c1713132 | balrog | pxa2xx_rtc_piupdate(s); |
1150 | c1713132 | balrog | s->last_rtcpicr = value & 0xffff;
|
1151 | c1713132 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1152 | c1713132 | balrog | break;
|
1153 | c1713132 | balrog | |
1154 | c1713132 | balrog | default:
|
1155 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1156 | c1713132 | balrog | } |
1157 | c1713132 | balrog | } |
1158 | c1713132 | balrog | |
1159 | aa941b94 | balrog | static CPUReadMemoryFunc *pxa2xx_rtc_readfn[] = {
|
1160 | aa941b94 | balrog | pxa2xx_rtc_read, |
1161 | aa941b94 | balrog | pxa2xx_rtc_read, |
1162 | aa941b94 | balrog | pxa2xx_rtc_read, |
1163 | aa941b94 | balrog | }; |
1164 | aa941b94 | balrog | |
1165 | aa941b94 | balrog | static CPUWriteMemoryFunc *pxa2xx_rtc_writefn[] = {
|
1166 | aa941b94 | balrog | pxa2xx_rtc_write, |
1167 | aa941b94 | balrog | pxa2xx_rtc_write, |
1168 | aa941b94 | balrog | pxa2xx_rtc_write, |
1169 | aa941b94 | balrog | }; |
1170 | aa941b94 | balrog | |
1171 | bc24a225 | Paul Brook | static void pxa2xx_rtc_init(PXA2xxState *s) |
1172 | c1713132 | balrog | { |
1173 | f6503059 | balrog | struct tm tm;
|
1174 | c1713132 | balrog | int wom;
|
1175 | c1713132 | balrog | |
1176 | c1713132 | balrog | s->rttr = 0x7fff;
|
1177 | c1713132 | balrog | s->rtsr = 0;
|
1178 | c1713132 | balrog | |
1179 | f6503059 | balrog | qemu_get_timedate(&tm, 0);
|
1180 | f6503059 | balrog | wom = ((tm.tm_mday - 1) / 7) + 1; |
1181 | f6503059 | balrog | |
1182 | 0cd2df75 | aurel32 | s->last_rcnr = (uint32_t) mktimegm(&tm); |
1183 | f6503059 | balrog | s->last_rdcr = (wom << 20) | ((tm.tm_wday + 1) << 17) | |
1184 | f6503059 | balrog | (tm.tm_hour << 12) | (tm.tm_min << 6) | tm.tm_sec; |
1185 | f6503059 | balrog | s->last_rycr = ((tm.tm_year + 1900) << 9) | |
1186 | f6503059 | balrog | ((tm.tm_mon + 1) << 5) | tm.tm_mday; |
1187 | f6503059 | balrog | s->last_swcr = (tm.tm_hour << 19) |
|
1188 | f6503059 | balrog | (tm.tm_min << 13) | (tm.tm_sec << 7); |
1189 | c1713132 | balrog | s->last_rtcpicr = 0;
|
1190 | c1713132 | balrog | s->last_hz = s->last_sw = s->last_pi = qemu_get_clock(rt_clock); |
1191 | c1713132 | balrog | |
1192 | c1713132 | balrog | s->rtc_hz = qemu_new_timer(rt_clock, pxa2xx_rtc_hz_tick, s); |
1193 | c1713132 | balrog | s->rtc_rdal1 = qemu_new_timer(rt_clock, pxa2xx_rtc_rdal1_tick, s); |
1194 | c1713132 | balrog | s->rtc_rdal2 = qemu_new_timer(rt_clock, pxa2xx_rtc_rdal2_tick, s); |
1195 | c1713132 | balrog | s->rtc_swal1 = qemu_new_timer(rt_clock, pxa2xx_rtc_swal1_tick, s); |
1196 | c1713132 | balrog | s->rtc_swal2 = qemu_new_timer(rt_clock, pxa2xx_rtc_swal2_tick, s); |
1197 | c1713132 | balrog | s->rtc_pi = qemu_new_timer(rt_clock, pxa2xx_rtc_pi_tick, s); |
1198 | c1713132 | balrog | } |
1199 | c1713132 | balrog | |
1200 | aa941b94 | balrog | static void pxa2xx_rtc_save(QEMUFile *f, void *opaque) |
1201 | aa941b94 | balrog | { |
1202 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1203 | c1713132 | balrog | |
1204 | aa941b94 | balrog | pxa2xx_rtc_hzupdate(s); |
1205 | aa941b94 | balrog | pxa2xx_rtc_piupdate(s); |
1206 | aa941b94 | balrog | pxa2xx_rtc_swupdate(s); |
1207 | aa941b94 | balrog | |
1208 | aa941b94 | balrog | qemu_put_be32s(f, &s->rttr); |
1209 | aa941b94 | balrog | qemu_put_be32s(f, &s->rtsr); |
1210 | aa941b94 | balrog | qemu_put_be32s(f, &s->rtar); |
1211 | aa941b94 | balrog | qemu_put_be32s(f, &s->rdar1); |
1212 | aa941b94 | balrog | qemu_put_be32s(f, &s->rdar2); |
1213 | aa941b94 | balrog | qemu_put_be32s(f, &s->ryar1); |
1214 | aa941b94 | balrog | qemu_put_be32s(f, &s->ryar2); |
1215 | aa941b94 | balrog | qemu_put_be32s(f, &s->swar1); |
1216 | aa941b94 | balrog | qemu_put_be32s(f, &s->swar2); |
1217 | aa941b94 | balrog | qemu_put_be32s(f, &s->piar); |
1218 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rcnr); |
1219 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rdcr); |
1220 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rycr); |
1221 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_swcr); |
1222 | aa941b94 | balrog | qemu_put_be32s(f, &s->last_rtcpicr); |
1223 | b6c4f71f | blueswir1 | qemu_put_sbe64s(f, &s->last_hz); |
1224 | b6c4f71f | blueswir1 | qemu_put_sbe64s(f, &s->last_sw); |
1225 | b6c4f71f | blueswir1 | qemu_put_sbe64s(f, &s->last_pi); |
1226 | aa941b94 | balrog | } |
1227 | aa941b94 | balrog | |
1228 | aa941b94 | balrog | static int pxa2xx_rtc_load(QEMUFile *f, void *opaque, int version_id) |
1229 | aa941b94 | balrog | { |
1230 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
1231 | aa941b94 | balrog | |
1232 | aa941b94 | balrog | qemu_get_be32s(f, &s->rttr); |
1233 | aa941b94 | balrog | qemu_get_be32s(f, &s->rtsr); |
1234 | aa941b94 | balrog | qemu_get_be32s(f, &s->rtar); |
1235 | aa941b94 | balrog | qemu_get_be32s(f, &s->rdar1); |
1236 | aa941b94 | balrog | qemu_get_be32s(f, &s->rdar2); |
1237 | aa941b94 | balrog | qemu_get_be32s(f, &s->ryar1); |
1238 | aa941b94 | balrog | qemu_get_be32s(f, &s->ryar2); |
1239 | aa941b94 | balrog | qemu_get_be32s(f, &s->swar1); |
1240 | aa941b94 | balrog | qemu_get_be32s(f, &s->swar2); |
1241 | aa941b94 | balrog | qemu_get_be32s(f, &s->piar); |
1242 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rcnr); |
1243 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rdcr); |
1244 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rycr); |
1245 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_swcr); |
1246 | aa941b94 | balrog | qemu_get_be32s(f, &s->last_rtcpicr); |
1247 | b6c4f71f | blueswir1 | qemu_get_sbe64s(f, &s->last_hz); |
1248 | b6c4f71f | blueswir1 | qemu_get_sbe64s(f, &s->last_sw); |
1249 | b6c4f71f | blueswir1 | qemu_get_sbe64s(f, &s->last_pi); |
1250 | aa941b94 | balrog | |
1251 | aa941b94 | balrog | pxa2xx_rtc_alarm_update(s, s->rtsr); |
1252 | aa941b94 | balrog | |
1253 | aa941b94 | balrog | return 0; |
1254 | aa941b94 | balrog | } |
1255 | c1713132 | balrog | |
1256 | 3f582262 | balrog | /* I2C Interface */
|
1257 | e3b42536 | Paul Brook | typedef struct { |
1258 | e3b42536 | Paul Brook | i2c_slave i2c; |
1259 | e3b42536 | Paul Brook | PXA2xxI2CState *host; |
1260 | e3b42536 | Paul Brook | } PXA2xxI2CSlaveState; |
1261 | e3b42536 | Paul Brook | |
1262 | bc24a225 | Paul Brook | struct PXA2xxI2CState {
|
1263 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave; |
1264 | 3f582262 | balrog | i2c_bus *bus; |
1265 | 3f582262 | balrog | qemu_irq irq; |
1266 | ed005253 | balrog | target_phys_addr_t offset; |
1267 | 3f582262 | balrog | |
1268 | 3f582262 | balrog | uint16_t control; |
1269 | 3f582262 | balrog | uint16_t status; |
1270 | 3f582262 | balrog | uint8_t ibmr; |
1271 | 3f582262 | balrog | uint8_t data; |
1272 | 3f582262 | balrog | }; |
1273 | 3f582262 | balrog | |
1274 | 3f582262 | balrog | #define IBMR 0x80 /* I2C Bus Monitor register */ |
1275 | 3f582262 | balrog | #define IDBR 0x88 /* I2C Data Buffer register */ |
1276 | 3f582262 | balrog | #define ICR 0x90 /* I2C Control register */ |
1277 | 3f582262 | balrog | #define ISR 0x98 /* I2C Status register */ |
1278 | 3f582262 | balrog | #define ISAR 0xa0 /* I2C Slave Address register */ |
1279 | 3f582262 | balrog | |
1280 | bc24a225 | Paul Brook | static void pxa2xx_i2c_update(PXA2xxI2CState *s) |
1281 | 3f582262 | balrog | { |
1282 | 3f582262 | balrog | uint16_t level = 0;
|
1283 | 3f582262 | balrog | level |= s->status & s->control & (1 << 10); /* BED */ |
1284 | 3f582262 | balrog | level |= (s->status & (1 << 7)) && (s->control & (1 << 9)); /* IRF */ |
1285 | 3f582262 | balrog | level |= (s->status & (1 << 6)) && (s->control & (1 << 8)); /* ITE */ |
1286 | 3f582262 | balrog | level |= s->status & (1 << 9); /* SAD */ |
1287 | 3f582262 | balrog | qemu_set_irq(s->irq, !!level); |
1288 | 3f582262 | balrog | } |
1289 | 3f582262 | balrog | |
1290 | 3f582262 | balrog | /* These are only stubs now. */
|
1291 | 3f582262 | balrog | static void pxa2xx_i2c_event(i2c_slave *i2c, enum i2c_event event) |
1292 | 3f582262 | balrog | { |
1293 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c); |
1294 | e3b42536 | Paul Brook | PXA2xxI2CState *s = slave->host; |
1295 | 3f582262 | balrog | |
1296 | 3f582262 | balrog | switch (event) {
|
1297 | 3f582262 | balrog | case I2C_START_SEND:
|
1298 | 3f582262 | balrog | s->status |= (1 << 9); /* set SAD */ |
1299 | 3f582262 | balrog | s->status &= ~(1 << 0); /* clear RWM */ |
1300 | 3f582262 | balrog | break;
|
1301 | 3f582262 | balrog | case I2C_START_RECV:
|
1302 | 3f582262 | balrog | s->status |= (1 << 9); /* set SAD */ |
1303 | 3f582262 | balrog | s->status |= 1 << 0; /* set RWM */ |
1304 | 3f582262 | balrog | break;
|
1305 | 3f582262 | balrog | case I2C_FINISH:
|
1306 | 3f582262 | balrog | s->status |= (1 << 4); /* set SSD */ |
1307 | 3f582262 | balrog | break;
|
1308 | 3f582262 | balrog | case I2C_NACK:
|
1309 | 3f582262 | balrog | s->status |= 1 << 1; /* set ACKNAK */ |
1310 | 3f582262 | balrog | break;
|
1311 | 3f582262 | balrog | } |
1312 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1313 | 3f582262 | balrog | } |
1314 | 3f582262 | balrog | |
1315 | 3f582262 | balrog | static int pxa2xx_i2c_rx(i2c_slave *i2c) |
1316 | 3f582262 | balrog | { |
1317 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c); |
1318 | e3b42536 | Paul Brook | PXA2xxI2CState *s = slave->host; |
1319 | 3f582262 | balrog | if ((s->control & (1 << 14)) || !(s->control & (1 << 6))) |
1320 | 3f582262 | balrog | return 0; |
1321 | 3f582262 | balrog | |
1322 | 3f582262 | balrog | if (s->status & (1 << 0)) { /* RWM */ |
1323 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1324 | 3f582262 | balrog | } |
1325 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1326 | 3f582262 | balrog | |
1327 | 3f582262 | balrog | return s->data;
|
1328 | 3f582262 | balrog | } |
1329 | 3f582262 | balrog | |
1330 | 3f582262 | balrog | static int pxa2xx_i2c_tx(i2c_slave *i2c, uint8_t data) |
1331 | 3f582262 | balrog | { |
1332 | e3b42536 | Paul Brook | PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c); |
1333 | e3b42536 | Paul Brook | PXA2xxI2CState *s = slave->host; |
1334 | 3f582262 | balrog | if ((s->control & (1 << 14)) || !(s->control & (1 << 6))) |
1335 | 3f582262 | balrog | return 1; |
1336 | 3f582262 | balrog | |
1337 | 3f582262 | balrog | if (!(s->status & (1 << 0))) { /* RWM */ |
1338 | 3f582262 | balrog | s->status |= 1 << 7; /* set IRF */ |
1339 | 3f582262 | balrog | s->data = data; |
1340 | 3f582262 | balrog | } |
1341 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1342 | 3f582262 | balrog | |
1343 | 3f582262 | balrog | return 1; |
1344 | 3f582262 | balrog | } |
1345 | 3f582262 | balrog | |
1346 | 3f582262 | balrog | static uint32_t pxa2xx_i2c_read(void *opaque, target_phys_addr_t addr) |
1347 | 3f582262 | balrog | { |
1348 | bc24a225 | Paul Brook | PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; |
1349 | 3f582262 | balrog | |
1350 | ed005253 | balrog | addr -= s->offset; |
1351 | 3f582262 | balrog | switch (addr) {
|
1352 | 3f582262 | balrog | case ICR:
|
1353 | 3f582262 | balrog | return s->control;
|
1354 | 3f582262 | balrog | case ISR:
|
1355 | 3f582262 | balrog | return s->status | (i2c_bus_busy(s->bus) << 2); |
1356 | 3f582262 | balrog | case ISAR:
|
1357 | e3b42536 | Paul Brook | return s->slave->i2c.address;
|
1358 | 3f582262 | balrog | case IDBR:
|
1359 | 3f582262 | balrog | return s->data;
|
1360 | 3f582262 | balrog | case IBMR:
|
1361 | 3f582262 | balrog | if (s->status & (1 << 2)) |
1362 | 3f582262 | balrog | s->ibmr ^= 3; /* Fake SCL and SDA pin changes */ |
1363 | 3f582262 | balrog | else
|
1364 | 3f582262 | balrog | s->ibmr = 0;
|
1365 | 3f582262 | balrog | return s->ibmr;
|
1366 | 3f582262 | balrog | default:
|
1367 | 3f582262 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1368 | 3f582262 | balrog | break;
|
1369 | 3f582262 | balrog | } |
1370 | 3f582262 | balrog | return 0; |
1371 | 3f582262 | balrog | } |
1372 | 3f582262 | balrog | |
1373 | 3f582262 | balrog | static void pxa2xx_i2c_write(void *opaque, target_phys_addr_t addr, |
1374 | 3f582262 | balrog | uint32_t value) |
1375 | 3f582262 | balrog | { |
1376 | bc24a225 | Paul Brook | PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; |
1377 | 3f582262 | balrog | int ack;
|
1378 | 3f582262 | balrog | |
1379 | ed005253 | balrog | addr -= s->offset; |
1380 | 3f582262 | balrog | switch (addr) {
|
1381 | 3f582262 | balrog | case ICR:
|
1382 | 3f582262 | balrog | s->control = value & 0xfff7;
|
1383 | 3f582262 | balrog | if ((value & (1 << 3)) && (value & (1 << 6))) { /* TB and IUE */ |
1384 | 3f582262 | balrog | /* TODO: slave mode */
|
1385 | 3f582262 | balrog | if (value & (1 << 0)) { /* START condition */ |
1386 | 3f582262 | balrog | if (s->data & 1) |
1387 | 3f582262 | balrog | s->status |= 1 << 0; /* set RWM */ |
1388 | 3f582262 | balrog | else
|
1389 | 3f582262 | balrog | s->status &= ~(1 << 0); /* clear RWM */ |
1390 | 3f582262 | balrog | ack = !i2c_start_transfer(s->bus, s->data >> 1, s->data & 1); |
1391 | 3f582262 | balrog | } else {
|
1392 | 3f582262 | balrog | if (s->status & (1 << 0)) { /* RWM */ |
1393 | 3f582262 | balrog | s->data = i2c_recv(s->bus); |
1394 | 3f582262 | balrog | if (value & (1 << 2)) /* ACKNAK */ |
1395 | 3f582262 | balrog | i2c_nack(s->bus); |
1396 | 3f582262 | balrog | ack = 1;
|
1397 | 3f582262 | balrog | } else
|
1398 | 3f582262 | balrog | ack = !i2c_send(s->bus, s->data); |
1399 | 3f582262 | balrog | } |
1400 | 3f582262 | balrog | |
1401 | 3f582262 | balrog | if (value & (1 << 1)) /* STOP condition */ |
1402 | 3f582262 | balrog | i2c_end_transfer(s->bus); |
1403 | 3f582262 | balrog | |
1404 | 3f582262 | balrog | if (ack) {
|
1405 | 3f582262 | balrog | if (value & (1 << 0)) /* START condition */ |
1406 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1407 | 3f582262 | balrog | else
|
1408 | 3f582262 | balrog | if (s->status & (1 << 0)) /* RWM */ |
1409 | 3f582262 | balrog | s->status |= 1 << 7; /* set IRF */ |
1410 | 3f582262 | balrog | else
|
1411 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1412 | 3f582262 | balrog | s->status &= ~(1 << 1); /* clear ACKNAK */ |
1413 | 3f582262 | balrog | } else {
|
1414 | 3f582262 | balrog | s->status |= 1 << 6; /* set ITE */ |
1415 | 3f582262 | balrog | s->status |= 1 << 10; /* set BED */ |
1416 | 3f582262 | balrog | s->status |= 1 << 1; /* set ACKNAK */ |
1417 | 3f582262 | balrog | } |
1418 | 3f582262 | balrog | } |
1419 | 3f582262 | balrog | if (!(value & (1 << 3)) && (value & (1 << 6))) /* !TB and IUE */ |
1420 | 3f582262 | balrog | if (value & (1 << 4)) /* MA */ |
1421 | 3f582262 | balrog | i2c_end_transfer(s->bus); |
1422 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1423 | 3f582262 | balrog | break;
|
1424 | 3f582262 | balrog | |
1425 | 3f582262 | balrog | case ISR:
|
1426 | 3f582262 | balrog | s->status &= ~(value & 0x07f0);
|
1427 | 3f582262 | balrog | pxa2xx_i2c_update(s); |
1428 | 3f582262 | balrog | break;
|
1429 | 3f582262 | balrog | |
1430 | 3f582262 | balrog | case ISAR:
|
1431 | e3b42536 | Paul Brook | i2c_set_slave_address(&s->slave->i2c, value & 0x7f);
|
1432 | 3f582262 | balrog | break;
|
1433 | 3f582262 | balrog | |
1434 | 3f582262 | balrog | case IDBR:
|
1435 | 3f582262 | balrog | s->data = value & 0xff;
|
1436 | 3f582262 | balrog | break;
|
1437 | 3f582262 | balrog | |
1438 | 3f582262 | balrog | default:
|
1439 | 3f582262 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1440 | 3f582262 | balrog | } |
1441 | 3f582262 | balrog | } |
1442 | 3f582262 | balrog | |
1443 | 3f582262 | balrog | static CPUReadMemoryFunc *pxa2xx_i2c_readfn[] = {
|
1444 | 3f582262 | balrog | pxa2xx_i2c_read, |
1445 | 3f582262 | balrog | pxa2xx_i2c_read, |
1446 | 3f582262 | balrog | pxa2xx_i2c_read, |
1447 | 3f582262 | balrog | }; |
1448 | 3f582262 | balrog | |
1449 | 3f582262 | balrog | static CPUWriteMemoryFunc *pxa2xx_i2c_writefn[] = {
|
1450 | 3f582262 | balrog | pxa2xx_i2c_write, |
1451 | 3f582262 | balrog | pxa2xx_i2c_write, |
1452 | 3f582262 | balrog | pxa2xx_i2c_write, |
1453 | 3f582262 | balrog | }; |
1454 | 3f582262 | balrog | |
1455 | aa941b94 | balrog | static void pxa2xx_i2c_save(QEMUFile *f, void *opaque) |
1456 | aa941b94 | balrog | { |
1457 | bc24a225 | Paul Brook | PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; |
1458 | aa941b94 | balrog | |
1459 | aa941b94 | balrog | qemu_put_be16s(f, &s->control); |
1460 | aa941b94 | balrog | qemu_put_be16s(f, &s->status); |
1461 | aa941b94 | balrog | qemu_put_8s(f, &s->ibmr); |
1462 | aa941b94 | balrog | qemu_put_8s(f, &s->data); |
1463 | aa941b94 | balrog | |
1464 | e3b42536 | Paul Brook | i2c_slave_save(f, &s->slave->i2c); |
1465 | aa941b94 | balrog | } |
1466 | aa941b94 | balrog | |
1467 | aa941b94 | balrog | static int pxa2xx_i2c_load(QEMUFile *f, void *opaque, int version_id) |
1468 | aa941b94 | balrog | { |
1469 | bc24a225 | Paul Brook | PXA2xxI2CState *s = (PXA2xxI2CState *) opaque; |
1470 | aa941b94 | balrog | |
1471 | c701b35b | pbrook | if (version_id != 1) |
1472 | c701b35b | pbrook | return -EINVAL;
|
1473 | c701b35b | pbrook | |
1474 | aa941b94 | balrog | qemu_get_be16s(f, &s->control); |
1475 | aa941b94 | balrog | qemu_get_be16s(f, &s->status); |
1476 | aa941b94 | balrog | qemu_get_8s(f, &s->ibmr); |
1477 | aa941b94 | balrog | qemu_get_8s(f, &s->data); |
1478 | aa941b94 | balrog | |
1479 | e3b42536 | Paul Brook | i2c_slave_load(f, &s->slave->i2c); |
1480 | aa941b94 | balrog | return 0; |
1481 | aa941b94 | balrog | } |
1482 | aa941b94 | balrog | |
1483 | e3b42536 | Paul Brook | static void pxa2xx_i2c_slave_init(i2c_slave *i2c) |
1484 | e3b42536 | Paul Brook | { |
1485 | e3b42536 | Paul Brook | /* Nothing to do. */
|
1486 | e3b42536 | Paul Brook | } |
1487 | e3b42536 | Paul Brook | |
1488 | e3b42536 | Paul Brook | static I2CSlaveInfo pxa2xx_i2c_slave_info = {
|
1489 | e3b42536 | Paul Brook | .init = pxa2xx_i2c_slave_init, |
1490 | e3b42536 | Paul Brook | .event = pxa2xx_i2c_event, |
1491 | e3b42536 | Paul Brook | .recv = pxa2xx_i2c_rx, |
1492 | e3b42536 | Paul Brook | .send = pxa2xx_i2c_tx |
1493 | e3b42536 | Paul Brook | }; |
1494 | e3b42536 | Paul Brook | |
1495 | bc24a225 | Paul Brook | PXA2xxI2CState *pxa2xx_i2c_init(target_phys_addr_t base, |
1496 | ed005253 | balrog | qemu_irq irq, uint32_t region_size) |
1497 | 3f582262 | balrog | { |
1498 | 3f582262 | balrog | int iomemtype;
|
1499 | e3b42536 | Paul Brook | DeviceState *dev; |
1500 | e3b42536 | Paul Brook | PXA2xxI2CState *s = qemu_mallocz(sizeof(PXA2xxI2CState));
|
1501 | e3b42536 | Paul Brook | |
1502 | c701b35b | pbrook | /* FIXME: Should the slave device really be on a separate bus? */
|
1503 | e3b42536 | Paul Brook | dev = i2c_create_slave(i2c_init_bus(), "pxa2xx-i2c-slave", 0); |
1504 | e3b42536 | Paul Brook | s->slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, I2C_SLAVE_FROM_QDEV(dev)); |
1505 | e3b42536 | Paul Brook | s->slave->host = s; |
1506 | 3f582262 | balrog | |
1507 | 3f582262 | balrog | s->irq = irq; |
1508 | 3f582262 | balrog | s->bus = i2c_init_bus(); |
1509 | dc23e260 | balrog | s->offset = base - (base & (~region_size) & TARGET_PAGE_MASK); |
1510 | 3f582262 | balrog | |
1511 | 2a163929 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_i2c_readfn,
|
1512 | 2a163929 | balrog | pxa2xx_i2c_writefn, s); |
1513 | ed005253 | balrog | cpu_register_physical_memory(base & ~region_size, |
1514 | ed005253 | balrog | region_size + 1, iomemtype);
|
1515 | 3f582262 | balrog | |
1516 | c701b35b | pbrook | register_savevm("pxa2xx_i2c", base, 1, |
1517 | aa941b94 | balrog | pxa2xx_i2c_save, pxa2xx_i2c_load, s); |
1518 | aa941b94 | balrog | |
1519 | 3f582262 | balrog | return s;
|
1520 | 3f582262 | balrog | } |
1521 | 3f582262 | balrog | |
1522 | bc24a225 | Paul Brook | i2c_bus *pxa2xx_i2c_bus(PXA2xxI2CState *s) |
1523 | 3f582262 | balrog | { |
1524 | 3f582262 | balrog | return s->bus;
|
1525 | 3f582262 | balrog | } |
1526 | 3f582262 | balrog | |
1527 | c1713132 | balrog | /* PXA Inter-IC Sound Controller */
|
1528 | bc24a225 | Paul Brook | static void pxa2xx_i2s_reset(PXA2xxI2SState *i2s) |
1529 | c1713132 | balrog | { |
1530 | c1713132 | balrog | i2s->rx_len = 0;
|
1531 | c1713132 | balrog | i2s->tx_len = 0;
|
1532 | c1713132 | balrog | i2s->fifo_len = 0;
|
1533 | c1713132 | balrog | i2s->clk = 0x1a;
|
1534 | c1713132 | balrog | i2s->control[0] = 0x00; |
1535 | c1713132 | balrog | i2s->control[1] = 0x00; |
1536 | c1713132 | balrog | i2s->status = 0x00;
|
1537 | c1713132 | balrog | i2s->mask = 0x00;
|
1538 | c1713132 | balrog | } |
1539 | c1713132 | balrog | |
1540 | c1713132 | balrog | #define SACR_TFTH(val) ((val >> 8) & 0xf) |
1541 | c1713132 | balrog | #define SACR_RFTH(val) ((val >> 12) & 0xf) |
1542 | c1713132 | balrog | #define SACR_DREC(val) (val & (1 << 3)) |
1543 | c1713132 | balrog | #define SACR_DPRL(val) (val & (1 << 4)) |
1544 | c1713132 | balrog | |
1545 | bc24a225 | Paul Brook | static inline void pxa2xx_i2s_update(PXA2xxI2SState *i2s) |
1546 | c1713132 | balrog | { |
1547 | c1713132 | balrog | int rfs, tfs;
|
1548 | c1713132 | balrog | rfs = SACR_RFTH(i2s->control[0]) < i2s->rx_len &&
|
1549 | c1713132 | balrog | !SACR_DREC(i2s->control[1]);
|
1550 | c1713132 | balrog | tfs = (i2s->tx_len || i2s->fifo_len < SACR_TFTH(i2s->control[0])) &&
|
1551 | c1713132 | balrog | i2s->enable && !SACR_DPRL(i2s->control[1]);
|
1552 | c1713132 | balrog | |
1553 | c1713132 | balrog | pxa2xx_dma_request(i2s->dma, PXA2XX_RX_RQ_I2S, rfs); |
1554 | c1713132 | balrog | pxa2xx_dma_request(i2s->dma, PXA2XX_TX_RQ_I2S, tfs); |
1555 | c1713132 | balrog | |
1556 | c1713132 | balrog | i2s->status &= 0xe0;
|
1557 | 59c0149b | balrog | if (i2s->fifo_len < 16 || !i2s->enable) |
1558 | 59c0149b | balrog | i2s->status |= 1 << 0; /* TNF */ |
1559 | c1713132 | balrog | if (i2s->rx_len)
|
1560 | c1713132 | balrog | i2s->status |= 1 << 1; /* RNE */ |
1561 | c1713132 | balrog | if (i2s->enable)
|
1562 | c1713132 | balrog | i2s->status |= 1 << 2; /* BSY */ |
1563 | c1713132 | balrog | if (tfs)
|
1564 | c1713132 | balrog | i2s->status |= 1 << 3; /* TFS */ |
1565 | c1713132 | balrog | if (rfs)
|
1566 | c1713132 | balrog | i2s->status |= 1 << 4; /* RFS */ |
1567 | c1713132 | balrog | if (!(i2s->tx_len && i2s->enable))
|
1568 | c1713132 | balrog | i2s->status |= i2s->fifo_len << 8; /* TFL */ |
1569 | c1713132 | balrog | i2s->status |= MAX(i2s->rx_len, 0xf) << 12; /* RFL */ |
1570 | c1713132 | balrog | |
1571 | c1713132 | balrog | qemu_set_irq(i2s->irq, i2s->status & i2s->mask); |
1572 | c1713132 | balrog | } |
1573 | c1713132 | balrog | |
1574 | c1713132 | balrog | #define SACR0 0x00 /* Serial Audio Global Control register */ |
1575 | c1713132 | balrog | #define SACR1 0x04 /* Serial Audio I2S/MSB-Justified Control register */ |
1576 | c1713132 | balrog | #define SASR0 0x0c /* Serial Audio Interface and FIFO Status register */ |
1577 | c1713132 | balrog | #define SAIMR 0x14 /* Serial Audio Interrupt Mask register */ |
1578 | c1713132 | balrog | #define SAICR 0x18 /* Serial Audio Interrupt Clear register */ |
1579 | c1713132 | balrog | #define SADIV 0x60 /* Serial Audio Clock Divider register */ |
1580 | c1713132 | balrog | #define SADR 0x80 /* Serial Audio Data register */ |
1581 | c1713132 | balrog | |
1582 | c1713132 | balrog | static uint32_t pxa2xx_i2s_read(void *opaque, target_phys_addr_t addr) |
1583 | c1713132 | balrog | { |
1584 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1585 | c1713132 | balrog | |
1586 | c1713132 | balrog | switch (addr) {
|
1587 | c1713132 | balrog | case SACR0:
|
1588 | c1713132 | balrog | return s->control[0]; |
1589 | c1713132 | balrog | case SACR1:
|
1590 | c1713132 | balrog | return s->control[1]; |
1591 | c1713132 | balrog | case SASR0:
|
1592 | c1713132 | balrog | return s->status;
|
1593 | c1713132 | balrog | case SAIMR:
|
1594 | c1713132 | balrog | return s->mask;
|
1595 | c1713132 | balrog | case SAICR:
|
1596 | c1713132 | balrog | return 0; |
1597 | c1713132 | balrog | case SADIV:
|
1598 | c1713132 | balrog | return s->clk;
|
1599 | c1713132 | balrog | case SADR:
|
1600 | c1713132 | balrog | if (s->rx_len > 0) { |
1601 | c1713132 | balrog | s->rx_len --; |
1602 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1603 | c1713132 | balrog | return s->codec_in(s->opaque);
|
1604 | c1713132 | balrog | } |
1605 | c1713132 | balrog | return 0; |
1606 | c1713132 | balrog | default:
|
1607 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1608 | c1713132 | balrog | break;
|
1609 | c1713132 | balrog | } |
1610 | c1713132 | balrog | return 0; |
1611 | c1713132 | balrog | } |
1612 | c1713132 | balrog | |
1613 | c1713132 | balrog | static void pxa2xx_i2s_write(void *opaque, target_phys_addr_t addr, |
1614 | c1713132 | balrog | uint32_t value) |
1615 | c1713132 | balrog | { |
1616 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1617 | c1713132 | balrog | uint32_t *sample; |
1618 | c1713132 | balrog | |
1619 | c1713132 | balrog | switch (addr) {
|
1620 | c1713132 | balrog | case SACR0:
|
1621 | c1713132 | balrog | if (value & (1 << 3)) /* RST */ |
1622 | c1713132 | balrog | pxa2xx_i2s_reset(s); |
1623 | c1713132 | balrog | s->control[0] = value & 0xff3d; |
1624 | c1713132 | balrog | if (!s->enable && (value & 1) && s->tx_len) { /* ENB */ |
1625 | c1713132 | balrog | for (sample = s->fifo; s->fifo_len > 0; s->fifo_len --, sample ++) |
1626 | c1713132 | balrog | s->codec_out(s->opaque, *sample); |
1627 | c1713132 | balrog | s->status &= ~(1 << 7); /* I2SOFF */ |
1628 | c1713132 | balrog | } |
1629 | c1713132 | balrog | if (value & (1 << 4)) /* EFWR */ |
1630 | c1713132 | balrog | printf("%s: Attempt to use special function\n", __FUNCTION__);
|
1631 | c1713132 | balrog | s->enable = ((value ^ 4) & 5) == 5; /* ENB && !RST*/ |
1632 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1633 | c1713132 | balrog | break;
|
1634 | c1713132 | balrog | case SACR1:
|
1635 | c1713132 | balrog | s->control[1] = value & 0x0039; |
1636 | c1713132 | balrog | if (value & (1 << 5)) /* ENLBF */ |
1637 | c1713132 | balrog | printf("%s: Attempt to use loopback function\n", __FUNCTION__);
|
1638 | c1713132 | balrog | if (value & (1 << 4)) /* DPRL */ |
1639 | c1713132 | balrog | s->fifo_len = 0;
|
1640 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1641 | c1713132 | balrog | break;
|
1642 | c1713132 | balrog | case SAIMR:
|
1643 | c1713132 | balrog | s->mask = value & 0x0078;
|
1644 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1645 | c1713132 | balrog | break;
|
1646 | c1713132 | balrog | case SAICR:
|
1647 | c1713132 | balrog | s->status &= ~(value & (3 << 5)); |
1648 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1649 | c1713132 | balrog | break;
|
1650 | c1713132 | balrog | case SADIV:
|
1651 | c1713132 | balrog | s->clk = value & 0x007f;
|
1652 | c1713132 | balrog | break;
|
1653 | c1713132 | balrog | case SADR:
|
1654 | c1713132 | balrog | if (s->tx_len && s->enable) {
|
1655 | c1713132 | balrog | s->tx_len --; |
1656 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1657 | c1713132 | balrog | s->codec_out(s->opaque, value); |
1658 | c1713132 | balrog | } else if (s->fifo_len < 16) { |
1659 | c1713132 | balrog | s->fifo[s->fifo_len ++] = value; |
1660 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1661 | c1713132 | balrog | } |
1662 | c1713132 | balrog | break;
|
1663 | c1713132 | balrog | default:
|
1664 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1665 | c1713132 | balrog | } |
1666 | c1713132 | balrog | } |
1667 | c1713132 | balrog | |
1668 | c1713132 | balrog | static CPUReadMemoryFunc *pxa2xx_i2s_readfn[] = {
|
1669 | c1713132 | balrog | pxa2xx_i2s_read, |
1670 | c1713132 | balrog | pxa2xx_i2s_read, |
1671 | c1713132 | balrog | pxa2xx_i2s_read, |
1672 | c1713132 | balrog | }; |
1673 | c1713132 | balrog | |
1674 | c1713132 | balrog | static CPUWriteMemoryFunc *pxa2xx_i2s_writefn[] = {
|
1675 | c1713132 | balrog | pxa2xx_i2s_write, |
1676 | c1713132 | balrog | pxa2xx_i2s_write, |
1677 | c1713132 | balrog | pxa2xx_i2s_write, |
1678 | c1713132 | balrog | }; |
1679 | c1713132 | balrog | |
1680 | aa941b94 | balrog | static void pxa2xx_i2s_save(QEMUFile *f, void *opaque) |
1681 | aa941b94 | balrog | { |
1682 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1683 | aa941b94 | balrog | |
1684 | aa941b94 | balrog | qemu_put_be32s(f, &s->control[0]);
|
1685 | aa941b94 | balrog | qemu_put_be32s(f, &s->control[1]);
|
1686 | aa941b94 | balrog | qemu_put_be32s(f, &s->status); |
1687 | aa941b94 | balrog | qemu_put_be32s(f, &s->mask); |
1688 | aa941b94 | balrog | qemu_put_be32s(f, &s->clk); |
1689 | aa941b94 | balrog | |
1690 | aa941b94 | balrog | qemu_put_be32(f, s->enable); |
1691 | aa941b94 | balrog | qemu_put_be32(f, s->rx_len); |
1692 | aa941b94 | balrog | qemu_put_be32(f, s->tx_len); |
1693 | aa941b94 | balrog | qemu_put_be32(f, s->fifo_len); |
1694 | aa941b94 | balrog | } |
1695 | aa941b94 | balrog | |
1696 | aa941b94 | balrog | static int pxa2xx_i2s_load(QEMUFile *f, void *opaque, int version_id) |
1697 | aa941b94 | balrog | { |
1698 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1699 | aa941b94 | balrog | |
1700 | aa941b94 | balrog | qemu_get_be32s(f, &s->control[0]);
|
1701 | aa941b94 | balrog | qemu_get_be32s(f, &s->control[1]);
|
1702 | aa941b94 | balrog | qemu_get_be32s(f, &s->status); |
1703 | aa941b94 | balrog | qemu_get_be32s(f, &s->mask); |
1704 | aa941b94 | balrog | qemu_get_be32s(f, &s->clk); |
1705 | aa941b94 | balrog | |
1706 | aa941b94 | balrog | s->enable = qemu_get_be32(f); |
1707 | aa941b94 | balrog | s->rx_len = qemu_get_be32(f); |
1708 | aa941b94 | balrog | s->tx_len = qemu_get_be32(f); |
1709 | aa941b94 | balrog | s->fifo_len = qemu_get_be32(f); |
1710 | aa941b94 | balrog | |
1711 | aa941b94 | balrog | return 0; |
1712 | aa941b94 | balrog | } |
1713 | aa941b94 | balrog | |
1714 | c1713132 | balrog | static void pxa2xx_i2s_data_req(void *opaque, int tx, int rx) |
1715 | c1713132 | balrog | { |
1716 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) opaque; |
1717 | c1713132 | balrog | uint32_t *sample; |
1718 | c1713132 | balrog | |
1719 | c1713132 | balrog | /* Signal FIFO errors */
|
1720 | c1713132 | balrog | if (s->enable && s->tx_len)
|
1721 | c1713132 | balrog | s->status |= 1 << 5; /* TUR */ |
1722 | c1713132 | balrog | if (s->enable && s->rx_len)
|
1723 | c1713132 | balrog | s->status |= 1 << 6; /* ROR */ |
1724 | c1713132 | balrog | |
1725 | c1713132 | balrog | /* Should be tx - MIN(tx, s->fifo_len) but we don't really need to
|
1726 | c1713132 | balrog | * handle the cases where it makes a difference. */
|
1727 | c1713132 | balrog | s->tx_len = tx - s->fifo_len; |
1728 | c1713132 | balrog | s->rx_len = rx; |
1729 | c1713132 | balrog | /* Note that is s->codec_out wasn't set, we wouldn't get called. */
|
1730 | c1713132 | balrog | if (s->enable)
|
1731 | c1713132 | balrog | for (sample = s->fifo; s->fifo_len; s->fifo_len --, sample ++)
|
1732 | c1713132 | balrog | s->codec_out(s->opaque, *sample); |
1733 | c1713132 | balrog | pxa2xx_i2s_update(s); |
1734 | c1713132 | balrog | } |
1735 | c1713132 | balrog | |
1736 | bc24a225 | Paul Brook | static PXA2xxI2SState *pxa2xx_i2s_init(target_phys_addr_t base,
|
1737 | bc24a225 | Paul Brook | qemu_irq irq, PXA2xxDMAState *dma) |
1738 | c1713132 | balrog | { |
1739 | c1713132 | balrog | int iomemtype;
|
1740 | bc24a225 | Paul Brook | PXA2xxI2SState *s = (PXA2xxI2SState *) |
1741 | bc24a225 | Paul Brook | qemu_mallocz(sizeof(PXA2xxI2SState));
|
1742 | c1713132 | balrog | |
1743 | c1713132 | balrog | s->irq = irq; |
1744 | c1713132 | balrog | s->dma = dma; |
1745 | c1713132 | balrog | s->data_req = pxa2xx_i2s_data_req; |
1746 | c1713132 | balrog | |
1747 | c1713132 | balrog | pxa2xx_i2s_reset(s); |
1748 | c1713132 | balrog | |
1749 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_i2s_readfn,
|
1750 | c1713132 | balrog | pxa2xx_i2s_writefn, s); |
1751 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100000, iomemtype);
|
1752 | c1713132 | balrog | |
1753 | aa941b94 | balrog | register_savevm("pxa2xx_i2s", base, 0, |
1754 | aa941b94 | balrog | pxa2xx_i2s_save, pxa2xx_i2s_load, s); |
1755 | aa941b94 | balrog | |
1756 | c1713132 | balrog | return s;
|
1757 | c1713132 | balrog | } |
1758 | c1713132 | balrog | |
1759 | c1713132 | balrog | /* PXA Fast Infra-red Communications Port */
|
1760 | bc24a225 | Paul Brook | struct PXA2xxFIrState {
|
1761 | c1713132 | balrog | qemu_irq irq; |
1762 | bc24a225 | Paul Brook | PXA2xxDMAState *dma; |
1763 | c1713132 | balrog | int enable;
|
1764 | c1713132 | balrog | CharDriverState *chr; |
1765 | c1713132 | balrog | |
1766 | c1713132 | balrog | uint8_t control[3];
|
1767 | c1713132 | balrog | uint8_t status[2];
|
1768 | c1713132 | balrog | |
1769 | c1713132 | balrog | int rx_len;
|
1770 | c1713132 | balrog | int rx_start;
|
1771 | c1713132 | balrog | uint8_t rx_fifo[64];
|
1772 | c1713132 | balrog | }; |
1773 | c1713132 | balrog | |
1774 | bc24a225 | Paul Brook | static void pxa2xx_fir_reset(PXA2xxFIrState *s) |
1775 | c1713132 | balrog | { |
1776 | c1713132 | balrog | s->control[0] = 0x00; |
1777 | c1713132 | balrog | s->control[1] = 0x00; |
1778 | c1713132 | balrog | s->control[2] = 0x00; |
1779 | c1713132 | balrog | s->status[0] = 0x00; |
1780 | c1713132 | balrog | s->status[1] = 0x00; |
1781 | c1713132 | balrog | s->enable = 0;
|
1782 | c1713132 | balrog | } |
1783 | c1713132 | balrog | |
1784 | bc24a225 | Paul Brook | static inline void pxa2xx_fir_update(PXA2xxFIrState *s) |
1785 | c1713132 | balrog | { |
1786 | c1713132 | balrog | static const int tresh[4] = { 8, 16, 32, 0 }; |
1787 | c1713132 | balrog | int intr = 0; |
1788 | c1713132 | balrog | if ((s->control[0] & (1 << 4)) && /* RXE */ |
1789 | c1713132 | balrog | s->rx_len >= tresh[s->control[2] & 3]) /* TRIG */ |
1790 | c1713132 | balrog | s->status[0] |= 1 << 4; /* RFS */ |
1791 | c1713132 | balrog | else
|
1792 | c1713132 | balrog | s->status[0] &= ~(1 << 4); /* RFS */ |
1793 | c1713132 | balrog | if (s->control[0] & (1 << 3)) /* TXE */ |
1794 | c1713132 | balrog | s->status[0] |= 1 << 3; /* TFS */ |
1795 | c1713132 | balrog | else
|
1796 | c1713132 | balrog | s->status[0] &= ~(1 << 3); /* TFS */ |
1797 | c1713132 | balrog | if (s->rx_len)
|
1798 | c1713132 | balrog | s->status[1] |= 1 << 2; /* RNE */ |
1799 | c1713132 | balrog | else
|
1800 | c1713132 | balrog | s->status[1] &= ~(1 << 2); /* RNE */ |
1801 | c1713132 | balrog | if (s->control[0] & (1 << 4)) /* RXE */ |
1802 | c1713132 | balrog | s->status[1] |= 1 << 0; /* RSY */ |
1803 | c1713132 | balrog | else
|
1804 | c1713132 | balrog | s->status[1] &= ~(1 << 0); /* RSY */ |
1805 | c1713132 | balrog | |
1806 | c1713132 | balrog | intr |= (s->control[0] & (1 << 5)) && /* RIE */ |
1807 | c1713132 | balrog | (s->status[0] & (1 << 4)); /* RFS */ |
1808 | c1713132 | balrog | intr |= (s->control[0] & (1 << 6)) && /* TIE */ |
1809 | c1713132 | balrog | (s->status[0] & (1 << 3)); /* TFS */ |
1810 | c1713132 | balrog | intr |= (s->control[2] & (1 << 4)) && /* TRAIL */ |
1811 | c1713132 | balrog | (s->status[0] & (1 << 6)); /* EOC */ |
1812 | c1713132 | balrog | intr |= (s->control[0] & (1 << 2)) && /* TUS */ |
1813 | c1713132 | balrog | (s->status[0] & (1 << 1)); /* TUR */ |
1814 | c1713132 | balrog | intr |= s->status[0] & 0x25; /* FRE, RAB, EIF */ |
1815 | c1713132 | balrog | |
1816 | c1713132 | balrog | pxa2xx_dma_request(s->dma, PXA2XX_RX_RQ_ICP, (s->status[0] >> 4) & 1); |
1817 | c1713132 | balrog | pxa2xx_dma_request(s->dma, PXA2XX_TX_RQ_ICP, (s->status[0] >> 3) & 1); |
1818 | c1713132 | balrog | |
1819 | c1713132 | balrog | qemu_set_irq(s->irq, intr && s->enable); |
1820 | c1713132 | balrog | } |
1821 | c1713132 | balrog | |
1822 | c1713132 | balrog | #define ICCR0 0x00 /* FICP Control register 0 */ |
1823 | c1713132 | balrog | #define ICCR1 0x04 /* FICP Control register 1 */ |
1824 | c1713132 | balrog | #define ICCR2 0x08 /* FICP Control register 2 */ |
1825 | c1713132 | balrog | #define ICDR 0x0c /* FICP Data register */ |
1826 | c1713132 | balrog | #define ICSR0 0x14 /* FICP Status register 0 */ |
1827 | c1713132 | balrog | #define ICSR1 0x18 /* FICP Status register 1 */ |
1828 | c1713132 | balrog | #define ICFOR 0x1c /* FICP FIFO Occupancy Status register */ |
1829 | c1713132 | balrog | |
1830 | c1713132 | balrog | static uint32_t pxa2xx_fir_read(void *opaque, target_phys_addr_t addr) |
1831 | c1713132 | balrog | { |
1832 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1833 | c1713132 | balrog | uint8_t ret; |
1834 | c1713132 | balrog | |
1835 | c1713132 | balrog | switch (addr) {
|
1836 | c1713132 | balrog | case ICCR0:
|
1837 | c1713132 | balrog | return s->control[0]; |
1838 | c1713132 | balrog | case ICCR1:
|
1839 | c1713132 | balrog | return s->control[1]; |
1840 | c1713132 | balrog | case ICCR2:
|
1841 | c1713132 | balrog | return s->control[2]; |
1842 | c1713132 | balrog | case ICDR:
|
1843 | c1713132 | balrog | s->status[0] &= ~0x01; |
1844 | c1713132 | balrog | s->status[1] &= ~0x72; |
1845 | c1713132 | balrog | if (s->rx_len) {
|
1846 | c1713132 | balrog | s->rx_len --; |
1847 | c1713132 | balrog | ret = s->rx_fifo[s->rx_start ++]; |
1848 | c1713132 | balrog | s->rx_start &= 63;
|
1849 | c1713132 | balrog | pxa2xx_fir_update(s); |
1850 | c1713132 | balrog | return ret;
|
1851 | c1713132 | balrog | } |
1852 | c1713132 | balrog | printf("%s: Rx FIFO underrun.\n", __FUNCTION__);
|
1853 | c1713132 | balrog | break;
|
1854 | c1713132 | balrog | case ICSR0:
|
1855 | c1713132 | balrog | return s->status[0]; |
1856 | c1713132 | balrog | case ICSR1:
|
1857 | c1713132 | balrog | return s->status[1] | (1 << 3); /* TNF */ |
1858 | c1713132 | balrog | case ICFOR:
|
1859 | c1713132 | balrog | return s->rx_len;
|
1860 | c1713132 | balrog | default:
|
1861 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1862 | c1713132 | balrog | break;
|
1863 | c1713132 | balrog | } |
1864 | c1713132 | balrog | return 0; |
1865 | c1713132 | balrog | } |
1866 | c1713132 | balrog | |
1867 | c1713132 | balrog | static void pxa2xx_fir_write(void *opaque, target_phys_addr_t addr, |
1868 | c1713132 | balrog | uint32_t value) |
1869 | c1713132 | balrog | { |
1870 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1871 | c1713132 | balrog | uint8_t ch; |
1872 | c1713132 | balrog | |
1873 | c1713132 | balrog | switch (addr) {
|
1874 | c1713132 | balrog | case ICCR0:
|
1875 | c1713132 | balrog | s->control[0] = value;
|
1876 | c1713132 | balrog | if (!(value & (1 << 4))) /* RXE */ |
1877 | c1713132 | balrog | s->rx_len = s->rx_start = 0;
|
1878 | c1713132 | balrog | if (!(value & (1 << 3))) /* TXE */ |
1879 | c1713132 | balrog | /* Nop */;
|
1880 | c1713132 | balrog | s->enable = value & 1; /* ITR */ |
1881 | c1713132 | balrog | if (!s->enable)
|
1882 | c1713132 | balrog | s->status[0] = 0; |
1883 | c1713132 | balrog | pxa2xx_fir_update(s); |
1884 | c1713132 | balrog | break;
|
1885 | c1713132 | balrog | case ICCR1:
|
1886 | c1713132 | balrog | s->control[1] = value;
|
1887 | c1713132 | balrog | break;
|
1888 | c1713132 | balrog | case ICCR2:
|
1889 | c1713132 | balrog | s->control[2] = value & 0x3f; |
1890 | c1713132 | balrog | pxa2xx_fir_update(s); |
1891 | c1713132 | balrog | break;
|
1892 | c1713132 | balrog | case ICDR:
|
1893 | c1713132 | balrog | if (s->control[2] & (1 << 2)) /* TXP */ |
1894 | c1713132 | balrog | ch = value; |
1895 | c1713132 | balrog | else
|
1896 | c1713132 | balrog | ch = ~value; |
1897 | c1713132 | balrog | if (s->chr && s->enable && (s->control[0] & (1 << 3))) /* TXE */ |
1898 | c1713132 | balrog | qemu_chr_write(s->chr, &ch, 1);
|
1899 | c1713132 | balrog | break;
|
1900 | c1713132 | balrog | case ICSR0:
|
1901 | c1713132 | balrog | s->status[0] &= ~(value & 0x66); |
1902 | c1713132 | balrog | pxa2xx_fir_update(s); |
1903 | c1713132 | balrog | break;
|
1904 | c1713132 | balrog | case ICFOR:
|
1905 | c1713132 | balrog | break;
|
1906 | c1713132 | balrog | default:
|
1907 | c1713132 | balrog | printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); |
1908 | c1713132 | balrog | } |
1909 | c1713132 | balrog | } |
1910 | c1713132 | balrog | |
1911 | c1713132 | balrog | static CPUReadMemoryFunc *pxa2xx_fir_readfn[] = {
|
1912 | c1713132 | balrog | pxa2xx_fir_read, |
1913 | c1713132 | balrog | pxa2xx_fir_read, |
1914 | c1713132 | balrog | pxa2xx_fir_read, |
1915 | c1713132 | balrog | }; |
1916 | c1713132 | balrog | |
1917 | c1713132 | balrog | static CPUWriteMemoryFunc *pxa2xx_fir_writefn[] = {
|
1918 | c1713132 | balrog | pxa2xx_fir_write, |
1919 | c1713132 | balrog | pxa2xx_fir_write, |
1920 | c1713132 | balrog | pxa2xx_fir_write, |
1921 | c1713132 | balrog | }; |
1922 | c1713132 | balrog | |
1923 | c1713132 | balrog | static int pxa2xx_fir_is_empty(void *opaque) |
1924 | c1713132 | balrog | { |
1925 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1926 | c1713132 | balrog | return (s->rx_len < 64); |
1927 | c1713132 | balrog | } |
1928 | c1713132 | balrog | |
1929 | c1713132 | balrog | static void pxa2xx_fir_rx(void *opaque, const uint8_t *buf, int size) |
1930 | c1713132 | balrog | { |
1931 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1932 | c1713132 | balrog | if (!(s->control[0] & (1 << 4))) /* RXE */ |
1933 | c1713132 | balrog | return;
|
1934 | c1713132 | balrog | |
1935 | c1713132 | balrog | while (size --) {
|
1936 | c1713132 | balrog | s->status[1] |= 1 << 4; /* EOF */ |
1937 | c1713132 | balrog | if (s->rx_len >= 64) { |
1938 | c1713132 | balrog | s->status[1] |= 1 << 6; /* ROR */ |
1939 | c1713132 | balrog | break;
|
1940 | c1713132 | balrog | } |
1941 | c1713132 | balrog | |
1942 | c1713132 | balrog | if (s->control[2] & (1 << 3)) /* RXP */ |
1943 | c1713132 | balrog | s->rx_fifo[(s->rx_start + s->rx_len ++) & 63] = *(buf ++);
|
1944 | c1713132 | balrog | else
|
1945 | c1713132 | balrog | s->rx_fifo[(s->rx_start + s->rx_len ++) & 63] = ~*(buf ++);
|
1946 | c1713132 | balrog | } |
1947 | c1713132 | balrog | |
1948 | c1713132 | balrog | pxa2xx_fir_update(s); |
1949 | c1713132 | balrog | } |
1950 | c1713132 | balrog | |
1951 | c1713132 | balrog | static void pxa2xx_fir_event(void *opaque, int event) |
1952 | c1713132 | balrog | { |
1953 | c1713132 | balrog | } |
1954 | c1713132 | balrog | |
1955 | aa941b94 | balrog | static void pxa2xx_fir_save(QEMUFile *f, void *opaque) |
1956 | aa941b94 | balrog | { |
1957 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1958 | aa941b94 | balrog | int i;
|
1959 | aa941b94 | balrog | |
1960 | aa941b94 | balrog | qemu_put_be32(f, s->enable); |
1961 | aa941b94 | balrog | |
1962 | aa941b94 | balrog | qemu_put_8s(f, &s->control[0]);
|
1963 | aa941b94 | balrog | qemu_put_8s(f, &s->control[1]);
|
1964 | aa941b94 | balrog | qemu_put_8s(f, &s->control[2]);
|
1965 | aa941b94 | balrog | qemu_put_8s(f, &s->status[0]);
|
1966 | aa941b94 | balrog | qemu_put_8s(f, &s->status[1]);
|
1967 | aa941b94 | balrog | |
1968 | aa941b94 | balrog | qemu_put_byte(f, s->rx_len); |
1969 | aa941b94 | balrog | for (i = 0; i < s->rx_len; i ++) |
1970 | aa941b94 | balrog | qemu_put_byte(f, s->rx_fifo[(s->rx_start + i) & 63]);
|
1971 | aa941b94 | balrog | } |
1972 | aa941b94 | balrog | |
1973 | aa941b94 | balrog | static int pxa2xx_fir_load(QEMUFile *f, void *opaque, int version_id) |
1974 | aa941b94 | balrog | { |
1975 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) opaque; |
1976 | aa941b94 | balrog | int i;
|
1977 | aa941b94 | balrog | |
1978 | aa941b94 | balrog | s->enable = qemu_get_be32(f); |
1979 | aa941b94 | balrog | |
1980 | aa941b94 | balrog | qemu_get_8s(f, &s->control[0]);
|
1981 | aa941b94 | balrog | qemu_get_8s(f, &s->control[1]);
|
1982 | aa941b94 | balrog | qemu_get_8s(f, &s->control[2]);
|
1983 | aa941b94 | balrog | qemu_get_8s(f, &s->status[0]);
|
1984 | aa941b94 | balrog | qemu_get_8s(f, &s->status[1]);
|
1985 | aa941b94 | balrog | |
1986 | aa941b94 | balrog | s->rx_len = qemu_get_byte(f); |
1987 | aa941b94 | balrog | s->rx_start = 0;
|
1988 | aa941b94 | balrog | for (i = 0; i < s->rx_len; i ++) |
1989 | aa941b94 | balrog | s->rx_fifo[i] = qemu_get_byte(f); |
1990 | aa941b94 | balrog | |
1991 | aa941b94 | balrog | return 0; |
1992 | aa941b94 | balrog | } |
1993 | aa941b94 | balrog | |
1994 | bc24a225 | Paul Brook | static PXA2xxFIrState *pxa2xx_fir_init(target_phys_addr_t base,
|
1995 | bc24a225 | Paul Brook | qemu_irq irq, PXA2xxDMAState *dma, |
1996 | c1713132 | balrog | CharDriverState *chr) |
1997 | c1713132 | balrog | { |
1998 | c1713132 | balrog | int iomemtype;
|
1999 | bc24a225 | Paul Brook | PXA2xxFIrState *s = (PXA2xxFIrState *) |
2000 | bc24a225 | Paul Brook | qemu_mallocz(sizeof(PXA2xxFIrState));
|
2001 | c1713132 | balrog | |
2002 | c1713132 | balrog | s->irq = irq; |
2003 | c1713132 | balrog | s->dma = dma; |
2004 | c1713132 | balrog | s->chr = chr; |
2005 | c1713132 | balrog | |
2006 | c1713132 | balrog | pxa2xx_fir_reset(s); |
2007 | c1713132 | balrog | |
2008 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_fir_readfn,
|
2009 | c1713132 | balrog | pxa2xx_fir_writefn, s); |
2010 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x1000, iomemtype);
|
2011 | c1713132 | balrog | |
2012 | c1713132 | balrog | if (chr)
|
2013 | c1713132 | balrog | qemu_chr_add_handlers(chr, pxa2xx_fir_is_empty, |
2014 | c1713132 | balrog | pxa2xx_fir_rx, pxa2xx_fir_event, s); |
2015 | c1713132 | balrog | |
2016 | aa941b94 | balrog | register_savevm("pxa2xx_fir", 0, 0, pxa2xx_fir_save, pxa2xx_fir_load, s); |
2017 | aa941b94 | balrog | |
2018 | c1713132 | balrog | return s;
|
2019 | c1713132 | balrog | } |
2020 | c1713132 | balrog | |
2021 | 38641a52 | balrog | static void pxa2xx_reset(void *opaque, int line, int level) |
2022 | c1713132 | balrog | { |
2023 | bc24a225 | Paul Brook | PXA2xxState *s = (PXA2xxState *) opaque; |
2024 | 38641a52 | balrog | |
2025 | c1713132 | balrog | if (level && (s->pm_regs[PCFR >> 2] & 0x10)) { /* GPR_EN */ |
2026 | c1713132 | balrog | cpu_reset(s->env); |
2027 | c1713132 | balrog | /* TODO: reset peripherals */
|
2028 | c1713132 | balrog | } |
2029 | c1713132 | balrog | } |
2030 | c1713132 | balrog | |
2031 | c1713132 | balrog | /* Initialise a PXA270 integrated chip (ARM based core). */
|
2032 | bc24a225 | Paul Brook | PXA2xxState *pxa270_init(unsigned int sdram_size, const char *revision) |
2033 | c1713132 | balrog | { |
2034 | bc24a225 | Paul Brook | PXA2xxState *s; |
2035 | c1713132 | balrog | int iomemtype, i;
|
2036 | e4bcb14c | ths | int index;
|
2037 | bc24a225 | Paul Brook | s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState));
|
2038 | c1713132 | balrog | |
2039 | 4207117c | balrog | if (revision && strncmp(revision, "pxa27", 5)) { |
2040 | 4207117c | balrog | fprintf(stderr, "Machine requires a PXA27x processor.\n");
|
2041 | 4207117c | balrog | exit(1);
|
2042 | 4207117c | balrog | } |
2043 | aaed909a | bellard | if (!revision)
|
2044 | aaed909a | bellard | revision = "pxa270";
|
2045 | aaed909a | bellard | |
2046 | aaed909a | bellard | s->env = cpu_init(revision); |
2047 | aaed909a | bellard | if (!s->env) {
|
2048 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
2049 | aaed909a | bellard | exit(1);
|
2050 | aaed909a | bellard | } |
2051 | 38641a52 | balrog | s->reset = qemu_allocate_irqs(pxa2xx_reset, s, 1)[0]; |
2052 | 38641a52 | balrog | |
2053 | d95b2f8d | balrog | /* SDRAM & Internal Memory Storage */
|
2054 | d95b2f8d | balrog | cpu_register_physical_memory(PXA2XX_SDRAM_BASE, |
2055 | d95b2f8d | balrog | sdram_size, qemu_ram_alloc(sdram_size) | IO_MEM_RAM); |
2056 | d95b2f8d | balrog | cpu_register_physical_memory(PXA2XX_INTERNAL_BASE, |
2057 | d95b2f8d | balrog | 0x40000, qemu_ram_alloc(0x40000) | IO_MEM_RAM); |
2058 | d95b2f8d | balrog | |
2059 | c1713132 | balrog | s->pic = pxa2xx_pic_init(0x40d00000, s->env);
|
2060 | c1713132 | balrog | |
2061 | c1713132 | balrog | s->dma = pxa27x_dma_init(0x40000000, s->pic[PXA2XX_PIC_DMA]);
|
2062 | c1713132 | balrog | |
2063 | a171fe39 | balrog | pxa27x_timer_init(0x40a00000, &s->pic[PXA2XX_PIC_OST_0],
|
2064 | 3f582262 | balrog | s->pic[PXA27X_PIC_OST_4_11]); |
2065 | a171fe39 | balrog | |
2066 | c1713132 | balrog | s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 121); |
2067 | c1713132 | balrog | |
2068 | e4bcb14c | ths | index = drive_get_index(IF_SD, 0, 0); |
2069 | e4bcb14c | ths | if (index == -1) { |
2070 | e4bcb14c | ths | fprintf(stderr, "qemu: missing SecureDigital device\n");
|
2071 | e4bcb14c | ths | exit(1);
|
2072 | e4bcb14c | ths | } |
2073 | e4bcb14c | ths | s->mmc = pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv,
|
2074 | e4bcb14c | ths | s->pic[PXA2XX_PIC_MMC], s->dma); |
2075 | a171fe39 | balrog | |
2076 | c1713132 | balrog | for (i = 0; pxa270_serial[i].io_base; i ++) |
2077 | c1713132 | balrog | if (serial_hds[i])
|
2078 | c1713132 | balrog | serial_mm_init(pxa270_serial[i].io_base, 2,
|
2079 | b6cd0ea1 | aurel32 | s->pic[pxa270_serial[i].irqn], 14857000/16, |
2080 | b6cd0ea1 | aurel32 | serial_hds[i], 1);
|
2081 | c1713132 | balrog | else
|
2082 | c1713132 | balrog | break;
|
2083 | c1713132 | balrog | if (serial_hds[i])
|
2084 | c1713132 | balrog | s->fir = pxa2xx_fir_init(0x40800000, s->pic[PXA2XX_PIC_ICP],
|
2085 | c1713132 | balrog | s->dma, serial_hds[i]); |
2086 | c1713132 | balrog | |
2087 | 3023f332 | aliguori | s->lcd = pxa2xx_lcdc_init(0x44000000, s->pic[PXA2XX_PIC_LCD]);
|
2088 | a171fe39 | balrog | |
2089 | c1713132 | balrog | s->cm_base = 0x41300000;
|
2090 | 82d17978 | balrog | s->cm_regs[CCCR >> 2] = 0x02000210; /* 416.0 MHz */ |
2091 | c1713132 | balrog | s->clkcfg = 0x00000009; /* Turbo mode active */ |
2092 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_cm_readfn,
|
2093 | c1713132 | balrog | pxa2xx_cm_writefn, s); |
2094 | 187337f8 | pbrook | cpu_register_physical_memory(s->cm_base, 0x1000, iomemtype);
|
2095 | aa941b94 | balrog | register_savevm("pxa2xx_cm", 0, 0, pxa2xx_cm_save, pxa2xx_cm_load, s); |
2096 | c1713132 | balrog | |
2097 | c1713132 | balrog | cpu_arm_set_cp_io(s->env, 14, pxa2xx_cp14_read, pxa2xx_cp14_write, s);
|
2098 | c1713132 | balrog | |
2099 | c1713132 | balrog | s->mm_base = 0x48000000;
|
2100 | c1713132 | balrog | s->mm_regs[MDMRS >> 2] = 0x00020002; |
2101 | c1713132 | balrog | s->mm_regs[MDREFR >> 2] = 0x03ca4000; |
2102 | c1713132 | balrog | s->mm_regs[MECR >> 2] = 0x00000001; /* Two PC Card sockets */ |
2103 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_mm_readfn,
|
2104 | c1713132 | balrog | pxa2xx_mm_writefn, s); |
2105 | 187337f8 | pbrook | cpu_register_physical_memory(s->mm_base, 0x1000, iomemtype);
|
2106 | aa941b94 | balrog | register_savevm("pxa2xx_mm", 0, 0, pxa2xx_mm_save, pxa2xx_mm_load, s); |
2107 | c1713132 | balrog | |
2108 | 2a163929 | balrog | s->pm_base = 0x40f00000;
|
2109 | 2a163929 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_pm_readfn,
|
2110 | 2a163929 | balrog | pxa2xx_pm_writefn, s); |
2111 | 187337f8 | pbrook | cpu_register_physical_memory(s->pm_base, 0x100, iomemtype);
|
2112 | 2a163929 | balrog | register_savevm("pxa2xx_pm", 0, 0, pxa2xx_pm_save, pxa2xx_pm_load, s); |
2113 | 2a163929 | balrog | |
2114 | c1713132 | balrog | for (i = 0; pxa27x_ssp[i].io_base; i ++); |
2115 | a984a69e | Paul Brook | s->ssp = (SSIBus **)qemu_mallocz(sizeof(SSIBus *) * i);
|
2116 | c1713132 | balrog | for (i = 0; pxa27x_ssp[i].io_base; i ++) { |
2117 | a984a69e | Paul Brook | DeviceState *dev; |
2118 | a984a69e | Paul Brook | dev = sysbus_create_simple("pxa2xx-ssp", pxa27x_ssp[i].io_base,
|
2119 | a984a69e | Paul Brook | s->pic[pxa27x_ssp[i].irqn]); |
2120 | a984a69e | Paul Brook | s->ssp[i] = qdev_get_child_bus(dev, "ssi");
|
2121 | c1713132 | balrog | } |
2122 | c1713132 | balrog | |
2123 | a171fe39 | balrog | if (usb_enabled) {
|
2124 | a171fe39 | balrog | usb_ohci_init_pxa(0x4c000000, 3, -1, s->pic[PXA2XX_PIC_USBH1]); |
2125 | a171fe39 | balrog | } |
2126 | a171fe39 | balrog | |
2127 | a171fe39 | balrog | s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000); |
2128 | a171fe39 | balrog | s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000); |
2129 | a171fe39 | balrog | |
2130 | c1713132 | balrog | s->rtc_base = 0x40900000;
|
2131 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_rtc_readfn,
|
2132 | c1713132 | balrog | pxa2xx_rtc_writefn, s); |
2133 | 187337f8 | pbrook | cpu_register_physical_memory(s->rtc_base, 0x1000, iomemtype);
|
2134 | aa941b94 | balrog | pxa2xx_rtc_init(s); |
2135 | aa941b94 | balrog | register_savevm("pxa2xx_rtc", 0, 0, pxa2xx_rtc_save, pxa2xx_rtc_load, s); |
2136 | c1713132 | balrog | |
2137 | 2a163929 | balrog | s->i2c[0] = pxa2xx_i2c_init(0x40301600, s->pic[PXA2XX_PIC_I2C], 0xffff); |
2138 | 2a163929 | balrog | s->i2c[1] = pxa2xx_i2c_init(0x40f00100, s->pic[PXA2XX_PIC_PWRI2C], 0xff); |
2139 | c1713132 | balrog | |
2140 | c1713132 | balrog | s->i2s = pxa2xx_i2s_init(0x40400000, s->pic[PXA2XX_PIC_I2S], s->dma);
|
2141 | c1713132 | balrog | |
2142 | 31b87f2e | balrog | s->kp = pxa27x_keypad_init(0x41500000, s->pic[PXA2XX_PIC_KEYPAD]);
|
2143 | 31b87f2e | balrog | |
2144 | c1713132 | balrog | /* GPIO1 resets the processor */
|
2145 | fe8f096b | ths | /* The handler can be overridden by board-specific code */
|
2146 | 38641a52 | balrog | pxa2xx_gpio_out_set(s->gpio, 1, s->reset);
|
2147 | c1713132 | balrog | return s;
|
2148 | c1713132 | balrog | } |
2149 | c1713132 | balrog | |
2150 | c1713132 | balrog | /* Initialise a PXA255 integrated chip (ARM based core). */
|
2151 | bc24a225 | Paul Brook | PXA2xxState *pxa255_init(unsigned int sdram_size) |
2152 | c1713132 | balrog | { |
2153 | bc24a225 | Paul Brook | PXA2xxState *s; |
2154 | c1713132 | balrog | int iomemtype, i;
|
2155 | e4bcb14c | ths | int index;
|
2156 | aaed909a | bellard | |
2157 | bc24a225 | Paul Brook | s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState));
|
2158 | c1713132 | balrog | |
2159 | aaed909a | bellard | s->env = cpu_init("pxa255");
|
2160 | aaed909a | bellard | if (!s->env) {
|
2161 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
2162 | aaed909a | bellard | exit(1);
|
2163 | aaed909a | bellard | } |
2164 | 38641a52 | balrog | s->reset = qemu_allocate_irqs(pxa2xx_reset, s, 1)[0]; |
2165 | 38641a52 | balrog | |
2166 | d95b2f8d | balrog | /* SDRAM & Internal Memory Storage */
|
2167 | a07dec22 | balrog | cpu_register_physical_memory(PXA2XX_SDRAM_BASE, sdram_size, |
2168 | a07dec22 | balrog | qemu_ram_alloc(sdram_size) | IO_MEM_RAM); |
2169 | a07dec22 | balrog | cpu_register_physical_memory(PXA2XX_INTERNAL_BASE, PXA2XX_INTERNAL_SIZE, |
2170 | a07dec22 | balrog | qemu_ram_alloc(PXA2XX_INTERNAL_SIZE) | IO_MEM_RAM); |
2171 | d95b2f8d | balrog | |
2172 | c1713132 | balrog | s->pic = pxa2xx_pic_init(0x40d00000, s->env);
|
2173 | c1713132 | balrog | |
2174 | c1713132 | balrog | s->dma = pxa255_dma_init(0x40000000, s->pic[PXA2XX_PIC_DMA]);
|
2175 | c1713132 | balrog | |
2176 | 3f582262 | balrog | pxa25x_timer_init(0x40a00000, &s->pic[PXA2XX_PIC_OST_0]);
|
2177 | a171fe39 | balrog | |
2178 | 3bdd58a4 | balrog | s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 85); |
2179 | c1713132 | balrog | |
2180 | e4bcb14c | ths | index = drive_get_index(IF_SD, 0, 0); |
2181 | e4bcb14c | ths | if (index == -1) { |
2182 | e4bcb14c | ths | fprintf(stderr, "qemu: missing SecureDigital device\n");
|
2183 | e4bcb14c | ths | exit(1);
|
2184 | e4bcb14c | ths | } |
2185 | e4bcb14c | ths | s->mmc = pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv,
|
2186 | e4bcb14c | ths | s->pic[PXA2XX_PIC_MMC], s->dma); |
2187 | a171fe39 | balrog | |
2188 | c1713132 | balrog | for (i = 0; pxa255_serial[i].io_base; i ++) |
2189 | c1713132 | balrog | if (serial_hds[i])
|
2190 | c1713132 | balrog | serial_mm_init(pxa255_serial[i].io_base, 2,
|
2191 | b6cd0ea1 | aurel32 | s->pic[pxa255_serial[i].irqn], 14745600/16, |
2192 | b6cd0ea1 | aurel32 | serial_hds[i], 1);
|
2193 | c1713132 | balrog | else
|
2194 | c1713132 | balrog | break;
|
2195 | c1713132 | balrog | if (serial_hds[i])
|
2196 | c1713132 | balrog | s->fir = pxa2xx_fir_init(0x40800000, s->pic[PXA2XX_PIC_ICP],
|
2197 | c1713132 | balrog | s->dma, serial_hds[i]); |
2198 | c1713132 | balrog | |
2199 | 3023f332 | aliguori | s->lcd = pxa2xx_lcdc_init(0x44000000, s->pic[PXA2XX_PIC_LCD]);
|
2200 | a171fe39 | balrog | |
2201 | c1713132 | balrog | s->cm_base = 0x41300000;
|
2202 | 82d17978 | balrog | s->cm_regs[CCCR >> 2] = 0x02000210; /* 416.0 MHz */ |
2203 | c1713132 | balrog | s->clkcfg = 0x00000009; /* Turbo mode active */ |
2204 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_cm_readfn,
|
2205 | c1713132 | balrog | pxa2xx_cm_writefn, s); |
2206 | 187337f8 | pbrook | cpu_register_physical_memory(s->cm_base, 0x1000, iomemtype);
|
2207 | aa941b94 | balrog | register_savevm("pxa2xx_cm", 0, 0, pxa2xx_cm_save, pxa2xx_cm_load, s); |
2208 | c1713132 | balrog | |
2209 | c1713132 | balrog | cpu_arm_set_cp_io(s->env, 14, pxa2xx_cp14_read, pxa2xx_cp14_write, s);
|
2210 | c1713132 | balrog | |
2211 | c1713132 | balrog | s->mm_base = 0x48000000;
|
2212 | c1713132 | balrog | s->mm_regs[MDMRS >> 2] = 0x00020002; |
2213 | c1713132 | balrog | s->mm_regs[MDREFR >> 2] = 0x03ca4000; |
2214 | c1713132 | balrog | s->mm_regs[MECR >> 2] = 0x00000001; /* Two PC Card sockets */ |
2215 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_mm_readfn,
|
2216 | c1713132 | balrog | pxa2xx_mm_writefn, s); |
2217 | 187337f8 | pbrook | cpu_register_physical_memory(s->mm_base, 0x1000, iomemtype);
|
2218 | aa941b94 | balrog | register_savevm("pxa2xx_mm", 0, 0, pxa2xx_mm_save, pxa2xx_mm_load, s); |
2219 | c1713132 | balrog | |
2220 | 2a163929 | balrog | s->pm_base = 0x40f00000;
|
2221 | 2a163929 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_pm_readfn,
|
2222 | 2a163929 | balrog | pxa2xx_pm_writefn, s); |
2223 | 187337f8 | pbrook | cpu_register_physical_memory(s->pm_base, 0x100, iomemtype);
|
2224 | 2a163929 | balrog | register_savevm("pxa2xx_pm", 0, 0, pxa2xx_pm_save, pxa2xx_pm_load, s); |
2225 | 2a163929 | balrog | |
2226 | c1713132 | balrog | for (i = 0; pxa255_ssp[i].io_base; i ++); |
2227 | a984a69e | Paul Brook | s->ssp = (SSIBus **)qemu_mallocz(sizeof(SSIBus *) * i);
|
2228 | c1713132 | balrog | for (i = 0; pxa255_ssp[i].io_base; i ++) { |
2229 | a984a69e | Paul Brook | DeviceState *dev; |
2230 | a984a69e | Paul Brook | dev = sysbus_create_simple("pxa2xx-ssp", pxa255_ssp[i].io_base,
|
2231 | a984a69e | Paul Brook | s->pic[pxa255_ssp[i].irqn]); |
2232 | a984a69e | Paul Brook | s->ssp[i] = qdev_get_child_bus(dev, "ssi");
|
2233 | c1713132 | balrog | } |
2234 | c1713132 | balrog | |
2235 | a171fe39 | balrog | if (usb_enabled) {
|
2236 | a171fe39 | balrog | usb_ohci_init_pxa(0x4c000000, 3, -1, s->pic[PXA2XX_PIC_USBH1]); |
2237 | a171fe39 | balrog | } |
2238 | a171fe39 | balrog | |
2239 | a171fe39 | balrog | s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000); |
2240 | a171fe39 | balrog | s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000); |
2241 | a171fe39 | balrog | |
2242 | c1713132 | balrog | s->rtc_base = 0x40900000;
|
2243 | c1713132 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_rtc_readfn,
|
2244 | c1713132 | balrog | pxa2xx_rtc_writefn, s); |
2245 | 187337f8 | pbrook | cpu_register_physical_memory(s->rtc_base, 0x1000, iomemtype);
|
2246 | aa941b94 | balrog | pxa2xx_rtc_init(s); |
2247 | aa941b94 | balrog | register_savevm("pxa2xx_rtc", 0, 0, pxa2xx_rtc_save, pxa2xx_rtc_load, s); |
2248 | c1713132 | balrog | |
2249 | 2a163929 | balrog | s->i2c[0] = pxa2xx_i2c_init(0x40301600, s->pic[PXA2XX_PIC_I2C], 0xffff); |
2250 | 2a163929 | balrog | s->i2c[1] = pxa2xx_i2c_init(0x40f00100, s->pic[PXA2XX_PIC_PWRI2C], 0xff); |
2251 | c1713132 | balrog | |
2252 | c1713132 | balrog | s->i2s = pxa2xx_i2s_init(0x40400000, s->pic[PXA2XX_PIC_I2S], s->dma);
|
2253 | c1713132 | balrog | |
2254 | c1713132 | balrog | /* GPIO1 resets the processor */
|
2255 | fe8f096b | ths | /* The handler can be overridden by board-specific code */
|
2256 | 38641a52 | balrog | pxa2xx_gpio_out_set(s->gpio, 1, s->reset);
|
2257 | c1713132 | balrog | return s;
|
2258 | c1713132 | balrog | } |
2259 | e3b42536 | Paul Brook | |
2260 | e3b42536 | Paul Brook | static void pxa2xx_register_devices(void) |
2261 | e3b42536 | Paul Brook | { |
2262 | e3b42536 | Paul Brook | i2c_register_slave("pxa2xx-i2c-slave", sizeof(PXA2xxI2CSlaveState), |
2263 | e3b42536 | Paul Brook | &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) |