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