root / hw / pxa2xx_timer.c @ 8034ce7d
History | View | Annotate | Download (14.1 kB)
1 | a171fe39 | balrog | /*
|
---|---|---|---|
2 | a171fe39 | balrog | * Intel XScale PXA255/270 OS Timers.
|
3 | a171fe39 | balrog | *
|
4 | a171fe39 | balrog | * Copyright (c) 2006 Openedhand Ltd.
|
5 | a171fe39 | balrog | * Copyright (c) 2006 Thorsten Zitterell
|
6 | a171fe39 | balrog | *
|
7 | a171fe39 | balrog | * This code is licenced under the GPL.
|
8 | a171fe39 | balrog | */
|
9 | a171fe39 | balrog | |
10 | 87ecb68b | pbrook | #include "hw.h" |
11 | 87ecb68b | pbrook | #include "qemu-timer.h" |
12 | 87ecb68b | pbrook | #include "sysemu.h" |
13 | 87ecb68b | pbrook | #include "pxa.h" |
14 | 797e9542 | Dmitry Eremin-Solenikov | #include "sysbus.h" |
15 | a171fe39 | balrog | |
16 | a171fe39 | balrog | #define OSMR0 0x00 |
17 | a171fe39 | balrog | #define OSMR1 0x04 |
18 | a171fe39 | balrog | #define OSMR2 0x08 |
19 | a171fe39 | balrog | #define OSMR3 0x0c |
20 | a171fe39 | balrog | #define OSMR4 0x80 |
21 | a171fe39 | balrog | #define OSMR5 0x84 |
22 | a171fe39 | balrog | #define OSMR6 0x88 |
23 | a171fe39 | balrog | #define OSMR7 0x8c |
24 | a171fe39 | balrog | #define OSMR8 0x90 |
25 | a171fe39 | balrog | #define OSMR9 0x94 |
26 | a171fe39 | balrog | #define OSMR10 0x98 |
27 | a171fe39 | balrog | #define OSMR11 0x9c |
28 | a171fe39 | balrog | #define OSCR 0x10 /* OS Timer Count */ |
29 | a171fe39 | balrog | #define OSCR4 0x40 |
30 | a171fe39 | balrog | #define OSCR5 0x44 |
31 | a171fe39 | balrog | #define OSCR6 0x48 |
32 | a171fe39 | balrog | #define OSCR7 0x4c |
33 | a171fe39 | balrog | #define OSCR8 0x50 |
34 | a171fe39 | balrog | #define OSCR9 0x54 |
35 | a171fe39 | balrog | #define OSCR10 0x58 |
36 | a171fe39 | balrog | #define OSCR11 0x5c |
37 | a171fe39 | balrog | #define OSSR 0x14 /* Timer status register */ |
38 | a171fe39 | balrog | #define OWER 0x18 |
39 | a171fe39 | balrog | #define OIER 0x1c /* Interrupt enable register 3-0 to E3-E0 */ |
40 | a171fe39 | balrog | #define OMCR4 0xc0 /* OS Match Control registers */ |
41 | a171fe39 | balrog | #define OMCR5 0xc4 |
42 | a171fe39 | balrog | #define OMCR6 0xc8 |
43 | a171fe39 | balrog | #define OMCR7 0xcc |
44 | a171fe39 | balrog | #define OMCR8 0xd0 |
45 | a171fe39 | balrog | #define OMCR9 0xd4 |
46 | a171fe39 | balrog | #define OMCR10 0xd8 |
47 | a171fe39 | balrog | #define OMCR11 0xdc |
48 | a171fe39 | balrog | #define OSNR 0x20 |
49 | a171fe39 | balrog | |
50 | a171fe39 | balrog | #define PXA25X_FREQ 3686400 /* 3.6864 MHz */ |
51 | a171fe39 | balrog | #define PXA27X_FREQ 3250000 /* 3.25 MHz */ |
52 | a171fe39 | balrog | |
53 | a171fe39 | balrog | static int pxa2xx_timer4_freq[8] = { |
54 | a171fe39 | balrog | [0] = 0, |
55 | a171fe39 | balrog | [1] = 32768, |
56 | a171fe39 | balrog | [2] = 1000, |
57 | a171fe39 | balrog | [3] = 1, |
58 | a171fe39 | balrog | [4] = 1000000, |
59 | a171fe39 | balrog | /* [5] is the "Externally supplied clock". Assign if necessary. */
|
60 | a171fe39 | balrog | [5 ... 7] = 0, |
61 | a171fe39 | balrog | }; |
62 | a171fe39 | balrog | |
63 | 797e9542 | Dmitry Eremin-Solenikov | typedef struct PXA2xxTimerInfo PXA2xxTimerInfo; |
64 | 797e9542 | Dmitry Eremin-Solenikov | |
65 | bc24a225 | Paul Brook | typedef struct { |
66 | a171fe39 | balrog | uint32_t value; |
67 | 5251d196 | Andrzej Zaborowski | qemu_irq irq; |
68 | a171fe39 | balrog | QEMUTimer *qtimer; |
69 | a171fe39 | balrog | int num;
|
70 | 797e9542 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *info; |
71 | bc24a225 | Paul Brook | } PXA2xxTimer0; |
72 | a171fe39 | balrog | |
73 | bc24a225 | Paul Brook | typedef struct { |
74 | bc24a225 | Paul Brook | PXA2xxTimer0 tm; |
75 | a171fe39 | balrog | int32_t oldclock; |
76 | a171fe39 | balrog | int32_t clock; |
77 | a171fe39 | balrog | uint64_t lastload; |
78 | a171fe39 | balrog | uint32_t freq; |
79 | a171fe39 | balrog | uint32_t control; |
80 | bc24a225 | Paul Brook | } PXA2xxTimer4; |
81 | a171fe39 | balrog | |
82 | 797e9542 | Dmitry Eremin-Solenikov | struct PXA2xxTimerInfo {
|
83 | 797e9542 | Dmitry Eremin-Solenikov | SysBusDevice busdev; |
84 | 797e9542 | Dmitry Eremin-Solenikov | uint32_t flags; |
85 | 797e9542 | Dmitry Eremin-Solenikov | |
86 | a171fe39 | balrog | int32_t clock; |
87 | a171fe39 | balrog | int32_t oldclock; |
88 | a171fe39 | balrog | uint64_t lastload; |
89 | a171fe39 | balrog | uint32_t freq; |
90 | bc24a225 | Paul Brook | PXA2xxTimer0 timer[4];
|
91 | a171fe39 | balrog | uint32_t events; |
92 | a171fe39 | balrog | uint32_t irq_enabled; |
93 | a171fe39 | balrog | uint32_t reset3; |
94 | a171fe39 | balrog | uint32_t snapshot; |
95 | 797e9542 | Dmitry Eremin-Solenikov | |
96 | 4ff927cc | Dmitry Eremin-Solenikov | qemu_irq irq4; |
97 | 797e9542 | Dmitry Eremin-Solenikov | PXA2xxTimer4 tm4[8];
|
98 | 797e9542 | Dmitry Eremin-Solenikov | }; |
99 | 797e9542 | Dmitry Eremin-Solenikov | |
100 | 797e9542 | Dmitry Eremin-Solenikov | #define PXA2XX_TIMER_HAVE_TM4 0 |
101 | 797e9542 | Dmitry Eremin-Solenikov | |
102 | 797e9542 | Dmitry Eremin-Solenikov | static inline int pxa2xx_timer_has_tm4(PXA2xxTimerInfo *s) |
103 | 797e9542 | Dmitry Eremin-Solenikov | { |
104 | 797e9542 | Dmitry Eremin-Solenikov | return s->flags & (1 << PXA2XX_TIMER_HAVE_TM4); |
105 | 797e9542 | Dmitry Eremin-Solenikov | } |
106 | a171fe39 | balrog | |
107 | a171fe39 | balrog | static void pxa2xx_timer_update(void *opaque, uint64_t now_qemu) |
108 | a171fe39 | balrog | { |
109 | d353eb43 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque; |
110 | a171fe39 | balrog | int i;
|
111 | a171fe39 | balrog | uint32_t now_vm; |
112 | a171fe39 | balrog | uint64_t new_qemu; |
113 | a171fe39 | balrog | |
114 | a171fe39 | balrog | now_vm = s->clock + |
115 | 6ee093c9 | Juan Quintela | muldiv64(now_qemu - s->lastload, s->freq, get_ticks_per_sec()); |
116 | a171fe39 | balrog | |
117 | a171fe39 | balrog | for (i = 0; i < 4; i ++) { |
118 | a171fe39 | balrog | new_qemu = now_qemu + muldiv64((uint32_t) (s->timer[i].value - now_vm), |
119 | 6ee093c9 | Juan Quintela | get_ticks_per_sec(), s->freq); |
120 | a171fe39 | balrog | qemu_mod_timer(s->timer[i].qtimer, new_qemu); |
121 | a171fe39 | balrog | } |
122 | a171fe39 | balrog | } |
123 | a171fe39 | balrog | |
124 | a171fe39 | balrog | static void pxa2xx_timer_update4(void *opaque, uint64_t now_qemu, int n) |
125 | a171fe39 | balrog | { |
126 | d353eb43 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque; |
127 | a171fe39 | balrog | uint32_t now_vm; |
128 | a171fe39 | balrog | uint64_t new_qemu; |
129 | a171fe39 | balrog | static const int counters[8] = { 0, 0, 0, 0, 4, 4, 6, 6 }; |
130 | a171fe39 | balrog | int counter;
|
131 | a171fe39 | balrog | |
132 | a171fe39 | balrog | if (s->tm4[n].control & (1 << 7)) |
133 | a171fe39 | balrog | counter = n; |
134 | a171fe39 | balrog | else
|
135 | a171fe39 | balrog | counter = counters[n]; |
136 | a171fe39 | balrog | |
137 | a171fe39 | balrog | if (!s->tm4[counter].freq) {
|
138 | 3f582262 | balrog | qemu_del_timer(s->tm4[n].tm.qtimer); |
139 | a171fe39 | balrog | return;
|
140 | a171fe39 | balrog | } |
141 | a171fe39 | balrog | |
142 | a171fe39 | balrog | now_vm = s->tm4[counter].clock + muldiv64(now_qemu - |
143 | a171fe39 | balrog | s->tm4[counter].lastload, |
144 | 6ee093c9 | Juan Quintela | s->tm4[counter].freq, get_ticks_per_sec()); |
145 | a171fe39 | balrog | |
146 | 3bdd58a4 | balrog | new_qemu = now_qemu + muldiv64((uint32_t) (s->tm4[n].tm.value - now_vm), |
147 | 6ee093c9 | Juan Quintela | get_ticks_per_sec(), s->tm4[counter].freq); |
148 | 3f582262 | balrog | qemu_mod_timer(s->tm4[n].tm.qtimer, new_qemu); |
149 | a171fe39 | balrog | } |
150 | a171fe39 | balrog | |
151 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_timer_read(void *opaque, target_phys_addr_t offset) |
152 | a171fe39 | balrog | { |
153 | d353eb43 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque; |
154 | a171fe39 | balrog | int tm = 0; |
155 | a171fe39 | balrog | |
156 | a171fe39 | balrog | switch (offset) {
|
157 | a171fe39 | balrog | case OSMR3: tm ++;
|
158 | a171fe39 | balrog | case OSMR2: tm ++;
|
159 | a171fe39 | balrog | case OSMR1: tm ++;
|
160 | a171fe39 | balrog | case OSMR0:
|
161 | a171fe39 | balrog | return s->timer[tm].value;
|
162 | a171fe39 | balrog | case OSMR11: tm ++;
|
163 | a171fe39 | balrog | case OSMR10: tm ++;
|
164 | a171fe39 | balrog | case OSMR9: tm ++;
|
165 | a171fe39 | balrog | case OSMR8: tm ++;
|
166 | a171fe39 | balrog | case OSMR7: tm ++;
|
167 | a171fe39 | balrog | case OSMR6: tm ++;
|
168 | a171fe39 | balrog | case OSMR5: tm ++;
|
169 | a171fe39 | balrog | case OSMR4:
|
170 | 797e9542 | Dmitry Eremin-Solenikov | if (!pxa2xx_timer_has_tm4(s))
|
171 | a171fe39 | balrog | goto badreg;
|
172 | 3bdd58a4 | balrog | return s->tm4[tm].tm.value;
|
173 | a171fe39 | balrog | case OSCR:
|
174 | a171fe39 | balrog | return s->clock + muldiv64(qemu_get_clock(vm_clock) -
|
175 | 6ee093c9 | Juan Quintela | s->lastload, s->freq, get_ticks_per_sec()); |
176 | a171fe39 | balrog | case OSCR11: tm ++;
|
177 | a171fe39 | balrog | case OSCR10: tm ++;
|
178 | a171fe39 | balrog | case OSCR9: tm ++;
|
179 | a171fe39 | balrog | case OSCR8: tm ++;
|
180 | a171fe39 | balrog | case OSCR7: tm ++;
|
181 | a171fe39 | balrog | case OSCR6: tm ++;
|
182 | a171fe39 | balrog | case OSCR5: tm ++;
|
183 | a171fe39 | balrog | case OSCR4:
|
184 | 797e9542 | Dmitry Eremin-Solenikov | if (!pxa2xx_timer_has_tm4(s))
|
185 | a171fe39 | balrog | goto badreg;
|
186 | a171fe39 | balrog | |
187 | a171fe39 | balrog | if ((tm == 9 - 4 || tm == 11 - 4) && (s->tm4[tm].control & (1 << 9))) { |
188 | a171fe39 | balrog | if (s->tm4[tm - 1].freq) |
189 | a171fe39 | balrog | s->snapshot = s->tm4[tm - 1].clock + muldiv64(
|
190 | a171fe39 | balrog | qemu_get_clock(vm_clock) - |
191 | a171fe39 | balrog | s->tm4[tm - 1].lastload,
|
192 | 6ee093c9 | Juan Quintela | s->tm4[tm - 1].freq, get_ticks_per_sec());
|
193 | a171fe39 | balrog | else
|
194 | a171fe39 | balrog | s->snapshot = s->tm4[tm - 1].clock;
|
195 | a171fe39 | balrog | } |
196 | a171fe39 | balrog | |
197 | a171fe39 | balrog | if (!s->tm4[tm].freq)
|
198 | a171fe39 | balrog | return s->tm4[tm].clock;
|
199 | a171fe39 | balrog | return s->tm4[tm].clock + muldiv64(qemu_get_clock(vm_clock) -
|
200 | 6ee093c9 | Juan Quintela | s->tm4[tm].lastload, s->tm4[tm].freq, get_ticks_per_sec()); |
201 | a171fe39 | balrog | case OIER:
|
202 | a171fe39 | balrog | return s->irq_enabled;
|
203 | a171fe39 | balrog | case OSSR: /* Status register */ |
204 | a171fe39 | balrog | return s->events;
|
205 | a171fe39 | balrog | case OWER:
|
206 | a171fe39 | balrog | return s->reset3;
|
207 | a171fe39 | balrog | case OMCR11: tm ++;
|
208 | a171fe39 | balrog | case OMCR10: tm ++;
|
209 | a171fe39 | balrog | case OMCR9: tm ++;
|
210 | a171fe39 | balrog | case OMCR8: tm ++;
|
211 | a171fe39 | balrog | case OMCR7: tm ++;
|
212 | a171fe39 | balrog | case OMCR6: tm ++;
|
213 | a171fe39 | balrog | case OMCR5: tm ++;
|
214 | a171fe39 | balrog | case OMCR4:
|
215 | 797e9542 | Dmitry Eremin-Solenikov | if (!pxa2xx_timer_has_tm4(s))
|
216 | a171fe39 | balrog | goto badreg;
|
217 | a171fe39 | balrog | return s->tm4[tm].control;
|
218 | a171fe39 | balrog | case OSNR:
|
219 | a171fe39 | balrog | return s->snapshot;
|
220 | a171fe39 | balrog | default:
|
221 | a171fe39 | balrog | badreg:
|
222 | 2ac71179 | Paul Brook | hw_error("pxa2xx_timer_read: Bad offset " REG_FMT "\n", offset); |
223 | a171fe39 | balrog | } |
224 | a171fe39 | balrog | |
225 | a171fe39 | balrog | return 0; |
226 | a171fe39 | balrog | } |
227 | a171fe39 | balrog | |
228 | c227f099 | Anthony Liguori | static void pxa2xx_timer_write(void *opaque, target_phys_addr_t offset, |
229 | a171fe39 | balrog | uint32_t value) |
230 | a171fe39 | balrog | { |
231 | a171fe39 | balrog | int i, tm = 0; |
232 | d353eb43 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque; |
233 | a171fe39 | balrog | |
234 | a171fe39 | balrog | switch (offset) {
|
235 | a171fe39 | balrog | case OSMR3: tm ++;
|
236 | a171fe39 | balrog | case OSMR2: tm ++;
|
237 | a171fe39 | balrog | case OSMR1: tm ++;
|
238 | a171fe39 | balrog | case OSMR0:
|
239 | a171fe39 | balrog | s->timer[tm].value = value; |
240 | a171fe39 | balrog | pxa2xx_timer_update(s, qemu_get_clock(vm_clock)); |
241 | a171fe39 | balrog | break;
|
242 | a171fe39 | balrog | case OSMR11: tm ++;
|
243 | a171fe39 | balrog | case OSMR10: tm ++;
|
244 | a171fe39 | balrog | case OSMR9: tm ++;
|
245 | a171fe39 | balrog | case OSMR8: tm ++;
|
246 | a171fe39 | balrog | case OSMR7: tm ++;
|
247 | a171fe39 | balrog | case OSMR6: tm ++;
|
248 | a171fe39 | balrog | case OSMR5: tm ++;
|
249 | a171fe39 | balrog | case OSMR4:
|
250 | 797e9542 | Dmitry Eremin-Solenikov | if (!pxa2xx_timer_has_tm4(s))
|
251 | a171fe39 | balrog | goto badreg;
|
252 | 3bdd58a4 | balrog | s->tm4[tm].tm.value = value; |
253 | a171fe39 | balrog | pxa2xx_timer_update4(s, qemu_get_clock(vm_clock), tm); |
254 | a171fe39 | balrog | break;
|
255 | a171fe39 | balrog | case OSCR:
|
256 | a171fe39 | balrog | s->oldclock = s->clock; |
257 | a171fe39 | balrog | s->lastload = qemu_get_clock(vm_clock); |
258 | a171fe39 | balrog | s->clock = value; |
259 | a171fe39 | balrog | pxa2xx_timer_update(s, s->lastload); |
260 | a171fe39 | balrog | break;
|
261 | a171fe39 | balrog | case OSCR11: tm ++;
|
262 | a171fe39 | balrog | case OSCR10: tm ++;
|
263 | a171fe39 | balrog | case OSCR9: tm ++;
|
264 | a171fe39 | balrog | case OSCR8: tm ++;
|
265 | a171fe39 | balrog | case OSCR7: tm ++;
|
266 | a171fe39 | balrog | case OSCR6: tm ++;
|
267 | a171fe39 | balrog | case OSCR5: tm ++;
|
268 | a171fe39 | balrog | case OSCR4:
|
269 | 797e9542 | Dmitry Eremin-Solenikov | if (!pxa2xx_timer_has_tm4(s))
|
270 | a171fe39 | balrog | goto badreg;
|
271 | a171fe39 | balrog | s->tm4[tm].oldclock = s->tm4[tm].clock; |
272 | a171fe39 | balrog | s->tm4[tm].lastload = qemu_get_clock(vm_clock); |
273 | a171fe39 | balrog | s->tm4[tm].clock = value; |
274 | a171fe39 | balrog | pxa2xx_timer_update4(s, s->tm4[tm].lastload, tm); |
275 | a171fe39 | balrog | break;
|
276 | a171fe39 | balrog | case OIER:
|
277 | a171fe39 | balrog | s->irq_enabled = value & 0xfff;
|
278 | a171fe39 | balrog | break;
|
279 | a171fe39 | balrog | case OSSR: /* Status register */ |
280 | 8034ce7d | Andrzej Zaborowski | value &= s->events; |
281 | a171fe39 | balrog | s->events &= ~value; |
282 | 8034ce7d | Andrzej Zaborowski | for (i = 0; i < 4; i ++, value >>= 1) |
283 | 8034ce7d | Andrzej Zaborowski | if (value & 1) |
284 | 5251d196 | Andrzej Zaborowski | qemu_irq_lower(s->timer[i].irq); |
285 | 8034ce7d | Andrzej Zaborowski | if (pxa2xx_timer_has_tm4(s) && !(s->events & 0xff0) && value) |
286 | 8034ce7d | Andrzej Zaborowski | qemu_irq_lower(s->irq4); |
287 | a171fe39 | balrog | break;
|
288 | a171fe39 | balrog | case OWER: /* XXX: Reset on OSMR3 match? */ |
289 | a171fe39 | balrog | s->reset3 = value; |
290 | a171fe39 | balrog | break;
|
291 | a171fe39 | balrog | case OMCR7: tm ++;
|
292 | a171fe39 | balrog | case OMCR6: tm ++;
|
293 | a171fe39 | balrog | case OMCR5: tm ++;
|
294 | a171fe39 | balrog | case OMCR4:
|
295 | 797e9542 | Dmitry Eremin-Solenikov | if (!pxa2xx_timer_has_tm4(s))
|
296 | a171fe39 | balrog | goto badreg;
|
297 | a171fe39 | balrog | s->tm4[tm].control = value & 0x0ff;
|
298 | a171fe39 | balrog | /* XXX Stop if running (shouldn't happen) */
|
299 | a171fe39 | balrog | if ((value & (1 << 7)) || tm == 0) |
300 | a171fe39 | balrog | s->tm4[tm].freq = pxa2xx_timer4_freq[value & 7];
|
301 | a171fe39 | balrog | else {
|
302 | a171fe39 | balrog | s->tm4[tm].freq = 0;
|
303 | a171fe39 | balrog | pxa2xx_timer_update4(s, qemu_get_clock(vm_clock), tm); |
304 | a171fe39 | balrog | } |
305 | a171fe39 | balrog | break;
|
306 | a171fe39 | balrog | case OMCR11: tm ++;
|
307 | a171fe39 | balrog | case OMCR10: tm ++;
|
308 | a171fe39 | balrog | case OMCR9: tm ++;
|
309 | a171fe39 | balrog | case OMCR8: tm += 4; |
310 | 797e9542 | Dmitry Eremin-Solenikov | if (!pxa2xx_timer_has_tm4(s))
|
311 | a171fe39 | balrog | goto badreg;
|
312 | a171fe39 | balrog | s->tm4[tm].control = value & 0x3ff;
|
313 | a171fe39 | balrog | /* XXX Stop if running (shouldn't happen) */
|
314 | a171fe39 | balrog | if ((value & (1 << 7)) || !(tm & 1)) |
315 | a171fe39 | balrog | s->tm4[tm].freq = |
316 | a171fe39 | balrog | pxa2xx_timer4_freq[(value & (1 << 8)) ? 0 : (value & 7)]; |
317 | a171fe39 | balrog | else {
|
318 | a171fe39 | balrog | s->tm4[tm].freq = 0;
|
319 | a171fe39 | balrog | pxa2xx_timer_update4(s, qemu_get_clock(vm_clock), tm); |
320 | a171fe39 | balrog | } |
321 | a171fe39 | balrog | break;
|
322 | a171fe39 | balrog | default:
|
323 | a171fe39 | balrog | badreg:
|
324 | 2ac71179 | Paul Brook | hw_error("pxa2xx_timer_write: Bad offset " REG_FMT "\n", offset); |
325 | a171fe39 | balrog | } |
326 | a171fe39 | balrog | } |
327 | a171fe39 | balrog | |
328 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_timer_readfn[] = { |
329 | a171fe39 | balrog | pxa2xx_timer_read, |
330 | a171fe39 | balrog | pxa2xx_timer_read, |
331 | a171fe39 | balrog | pxa2xx_timer_read, |
332 | a171fe39 | balrog | }; |
333 | a171fe39 | balrog | |
334 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_timer_writefn[] = { |
335 | a171fe39 | balrog | pxa2xx_timer_write, |
336 | a171fe39 | balrog | pxa2xx_timer_write, |
337 | a171fe39 | balrog | pxa2xx_timer_write, |
338 | a171fe39 | balrog | }; |
339 | a171fe39 | balrog | |
340 | a171fe39 | balrog | static void pxa2xx_timer_tick(void *opaque) |
341 | a171fe39 | balrog | { |
342 | bc24a225 | Paul Brook | PXA2xxTimer0 *t = (PXA2xxTimer0 *) opaque; |
343 | 797e9542 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *i = t->info; |
344 | a171fe39 | balrog | |
345 | a171fe39 | balrog | if (i->irq_enabled & (1 << t->num)) { |
346 | a171fe39 | balrog | i->events |= 1 << t->num;
|
347 | 5251d196 | Andrzej Zaborowski | qemu_irq_raise(t->irq); |
348 | a171fe39 | balrog | } |
349 | a171fe39 | balrog | |
350 | a171fe39 | balrog | if (t->num == 3) |
351 | a171fe39 | balrog | if (i->reset3 & 1) { |
352 | a171fe39 | balrog | i->reset3 = 0;
|
353 | 3f582262 | balrog | qemu_system_reset_request(); |
354 | a171fe39 | balrog | } |
355 | a171fe39 | balrog | } |
356 | a171fe39 | balrog | |
357 | a171fe39 | balrog | static void pxa2xx_timer_tick4(void *opaque) |
358 | a171fe39 | balrog | { |
359 | bc24a225 | Paul Brook | PXA2xxTimer4 *t = (PXA2xxTimer4 *) opaque; |
360 | d353eb43 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *i = (PXA2xxTimerInfo *) t->tm.info; |
361 | a171fe39 | balrog | |
362 | 3bdd58a4 | balrog | pxa2xx_timer_tick(&t->tm); |
363 | a171fe39 | balrog | if (t->control & (1 << 3)) |
364 | a171fe39 | balrog | t->clock = 0;
|
365 | a171fe39 | balrog | if (t->control & (1 << 6)) |
366 | 3bdd58a4 | balrog | pxa2xx_timer_update4(i, qemu_get_clock(vm_clock), t->tm.num - 4);
|
367 | 4ff927cc | Dmitry Eremin-Solenikov | if (i->events & 0xff0) |
368 | 4ff927cc | Dmitry Eremin-Solenikov | qemu_irq_raise(i->irq4); |
369 | a171fe39 | balrog | } |
370 | a171fe39 | balrog | |
371 | 797e9542 | Dmitry Eremin-Solenikov | static int pxa25x_timer_post_load(void *opaque, int version_id) |
372 | aa941b94 | balrog | { |
373 | d353eb43 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque; |
374 | aa941b94 | balrog | int64_t now; |
375 | aa941b94 | balrog | int i;
|
376 | aa941b94 | balrog | |
377 | aa941b94 | balrog | now = qemu_get_clock(vm_clock); |
378 | aa941b94 | balrog | pxa2xx_timer_update(s, now); |
379 | aa941b94 | balrog | |
380 | 797e9542 | Dmitry Eremin-Solenikov | if (pxa2xx_timer_has_tm4(s))
|
381 | 797e9542 | Dmitry Eremin-Solenikov | for (i = 0; i < 8; i ++) |
382 | aa941b94 | balrog | pxa2xx_timer_update4(s, now, i); |
383 | aa941b94 | balrog | |
384 | aa941b94 | balrog | return 0; |
385 | aa941b94 | balrog | } |
386 | aa941b94 | balrog | |
387 | 797e9542 | Dmitry Eremin-Solenikov | static int pxa2xx_timer_init(SysBusDevice *dev) |
388 | a171fe39 | balrog | { |
389 | a171fe39 | balrog | int i;
|
390 | a171fe39 | balrog | int iomemtype;
|
391 | d353eb43 | Dmitry Eremin-Solenikov | PXA2xxTimerInfo *s; |
392 | a171fe39 | balrog | |
393 | 797e9542 | Dmitry Eremin-Solenikov | s = FROM_SYSBUS(PXA2xxTimerInfo, dev); |
394 | a171fe39 | balrog | s->irq_enabled = 0;
|
395 | a171fe39 | balrog | s->oldclock = 0;
|
396 | a171fe39 | balrog | s->clock = 0;
|
397 | a171fe39 | balrog | s->lastload = qemu_get_clock(vm_clock); |
398 | a171fe39 | balrog | s->reset3 = 0;
|
399 | a171fe39 | balrog | |
400 | a171fe39 | balrog | for (i = 0; i < 4; i ++) { |
401 | a171fe39 | balrog | s->timer[i].value = 0;
|
402 | 5251d196 | Andrzej Zaborowski | sysbus_init_irq(dev, &s->timer[i].irq); |
403 | a171fe39 | balrog | s->timer[i].info = s; |
404 | a171fe39 | balrog | s->timer[i].num = i; |
405 | a171fe39 | balrog | s->timer[i].qtimer = qemu_new_timer(vm_clock, |
406 | a171fe39 | balrog | pxa2xx_timer_tick, &s->timer[i]); |
407 | a171fe39 | balrog | } |
408 | 797e9542 | Dmitry Eremin-Solenikov | if (s->flags & (1 << PXA2XX_TIMER_HAVE_TM4)) { |
409 | 4ff927cc | Dmitry Eremin-Solenikov | sysbus_init_irq(dev, &s->irq4); |
410 | 797e9542 | Dmitry Eremin-Solenikov | |
411 | 797e9542 | Dmitry Eremin-Solenikov | for (i = 0; i < 8; i ++) { |
412 | 797e9542 | Dmitry Eremin-Solenikov | s->tm4[i].tm.value = 0;
|
413 | 797e9542 | Dmitry Eremin-Solenikov | s->tm4[i].tm.info = s; |
414 | 797e9542 | Dmitry Eremin-Solenikov | s->tm4[i].tm.num = i + 4;
|
415 | 797e9542 | Dmitry Eremin-Solenikov | s->tm4[i].freq = 0;
|
416 | 797e9542 | Dmitry Eremin-Solenikov | s->tm4[i].control = 0x0;
|
417 | 797e9542 | Dmitry Eremin-Solenikov | s->tm4[i].tm.qtimer = qemu_new_timer(vm_clock, |
418 | 797e9542 | Dmitry Eremin-Solenikov | pxa2xx_timer_tick4, &s->tm4[i]); |
419 | 797e9542 | Dmitry Eremin-Solenikov | } |
420 | 797e9542 | Dmitry Eremin-Solenikov | } |
421 | a171fe39 | balrog | |
422 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_timer_readfn, |
423 | 2507c12a | Alexander Graf | pxa2xx_timer_writefn, s, DEVICE_NATIVE_ENDIAN); |
424 | 797e9542 | Dmitry Eremin-Solenikov | sysbus_init_mmio(dev, 0x00001000, iomemtype);
|
425 | aa941b94 | balrog | |
426 | 797e9542 | Dmitry Eremin-Solenikov | return 0; |
427 | a171fe39 | balrog | } |
428 | a171fe39 | balrog | |
429 | 797e9542 | Dmitry Eremin-Solenikov | static const VMStateDescription vmstate_pxa2xx_timer0_regs = { |
430 | 797e9542 | Dmitry Eremin-Solenikov | .name = "pxa2xx_timer0",
|
431 | 8034ce7d | Andrzej Zaborowski | .version_id = 2,
|
432 | 8034ce7d | Andrzej Zaborowski | .minimum_version_id = 2,
|
433 | 8034ce7d | Andrzej Zaborowski | .minimum_version_id_old = 2,
|
434 | 797e9542 | Dmitry Eremin-Solenikov | .fields = (VMStateField[]) { |
435 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT32(value, PXA2xxTimer0), |
436 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_END_OF_LIST(), |
437 | 797e9542 | Dmitry Eremin-Solenikov | }, |
438 | 797e9542 | Dmitry Eremin-Solenikov | }; |
439 | 797e9542 | Dmitry Eremin-Solenikov | |
440 | 797e9542 | Dmitry Eremin-Solenikov | static const VMStateDescription vmstate_pxa2xx_timer4_regs = { |
441 | 797e9542 | Dmitry Eremin-Solenikov | .name = "pxa2xx_timer4",
|
442 | 797e9542 | Dmitry Eremin-Solenikov | .version_id = 1,
|
443 | 797e9542 | Dmitry Eremin-Solenikov | .minimum_version_id = 1,
|
444 | 797e9542 | Dmitry Eremin-Solenikov | .minimum_version_id_old = 1,
|
445 | 797e9542 | Dmitry Eremin-Solenikov | .fields = (VMStateField[]) { |
446 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_STRUCT(tm, PXA2xxTimer4, 1,
|
447 | 797e9542 | Dmitry Eremin-Solenikov | vmstate_pxa2xx_timer0_regs, PXA2xxTimer0), |
448 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_INT32(oldclock, PXA2xxTimer4), |
449 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_INT32(clock, PXA2xxTimer4), |
450 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT64(lastload, PXA2xxTimer4), |
451 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT32(freq, PXA2xxTimer4), |
452 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT32(control, PXA2xxTimer4), |
453 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_END_OF_LIST(), |
454 | 797e9542 | Dmitry Eremin-Solenikov | }, |
455 | 797e9542 | Dmitry Eremin-Solenikov | }; |
456 | 797e9542 | Dmitry Eremin-Solenikov | |
457 | 797e9542 | Dmitry Eremin-Solenikov | static bool pxa2xx_timer_has_tm4_test(void *opaque, int version_id) |
458 | a171fe39 | balrog | { |
459 | 797e9542 | Dmitry Eremin-Solenikov | return pxa2xx_timer_has_tm4(opaque);
|
460 | a171fe39 | balrog | } |
461 | a171fe39 | balrog | |
462 | 797e9542 | Dmitry Eremin-Solenikov | static const VMStateDescription vmstate_pxa2xx_timer_regs = { |
463 | 797e9542 | Dmitry Eremin-Solenikov | .name = "pxa2xx_timer",
|
464 | 797e9542 | Dmitry Eremin-Solenikov | .version_id = 1,
|
465 | 797e9542 | Dmitry Eremin-Solenikov | .minimum_version_id = 1,
|
466 | 797e9542 | Dmitry Eremin-Solenikov | .minimum_version_id_old = 1,
|
467 | 797e9542 | Dmitry Eremin-Solenikov | .post_load = pxa25x_timer_post_load, |
468 | 797e9542 | Dmitry Eremin-Solenikov | .fields = (VMStateField[]) { |
469 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_INT32(clock, PXA2xxTimerInfo), |
470 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_INT32(oldclock, PXA2xxTimerInfo), |
471 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT64(lastload, PXA2xxTimerInfo), |
472 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_STRUCT_ARRAY(timer, PXA2xxTimerInfo, 4, 1, |
473 | 797e9542 | Dmitry Eremin-Solenikov | vmstate_pxa2xx_timer0_regs, PXA2xxTimer0), |
474 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT32(events, PXA2xxTimerInfo), |
475 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT32(irq_enabled, PXA2xxTimerInfo), |
476 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT32(reset3, PXA2xxTimerInfo), |
477 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_UINT32(snapshot, PXA2xxTimerInfo), |
478 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_STRUCT_ARRAY_TEST(tm4, PXA2xxTimerInfo, 8,
|
479 | 797e9542 | Dmitry Eremin-Solenikov | pxa2xx_timer_has_tm4_test, 0,
|
480 | 797e9542 | Dmitry Eremin-Solenikov | vmstate_pxa2xx_timer4_regs, PXA2xxTimer4), |
481 | 797e9542 | Dmitry Eremin-Solenikov | VMSTATE_END_OF_LIST(), |
482 | a171fe39 | balrog | } |
483 | 797e9542 | Dmitry Eremin-Solenikov | }; |
484 | 797e9542 | Dmitry Eremin-Solenikov | |
485 | 797e9542 | Dmitry Eremin-Solenikov | static SysBusDeviceInfo pxa25x_timer_dev_info = {
|
486 | 797e9542 | Dmitry Eremin-Solenikov | .init = pxa2xx_timer_init, |
487 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.name = "pxa25x-timer",
|
488 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.desc = "PXA25x timer",
|
489 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.size = sizeof(PXA2xxTimerInfo),
|
490 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.vmsd = &vmstate_pxa2xx_timer_regs, |
491 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.props = (Property[]) { |
492 | 797e9542 | Dmitry Eremin-Solenikov | DEFINE_PROP_UINT32("freq", PXA2xxTimerInfo, freq, PXA25X_FREQ),
|
493 | 797e9542 | Dmitry Eremin-Solenikov | DEFINE_PROP_BIT("tm4", PXA2xxTimerInfo, flags,
|
494 | 797e9542 | Dmitry Eremin-Solenikov | PXA2XX_TIMER_HAVE_TM4, false),
|
495 | 797e9542 | Dmitry Eremin-Solenikov | DEFINE_PROP_END_OF_LIST(), |
496 | 797e9542 | Dmitry Eremin-Solenikov | }, |
497 | 797e9542 | Dmitry Eremin-Solenikov | }; |
498 | 797e9542 | Dmitry Eremin-Solenikov | |
499 | 797e9542 | Dmitry Eremin-Solenikov | static SysBusDeviceInfo pxa27x_timer_dev_info = {
|
500 | 797e9542 | Dmitry Eremin-Solenikov | .init = pxa2xx_timer_init, |
501 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.name = "pxa27x-timer",
|
502 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.desc = "PXA27x timer",
|
503 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.size = sizeof(PXA2xxTimerInfo),
|
504 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.vmsd = &vmstate_pxa2xx_timer_regs, |
505 | 797e9542 | Dmitry Eremin-Solenikov | .qdev.props = (Property[]) { |
506 | 797e9542 | Dmitry Eremin-Solenikov | DEFINE_PROP_UINT32("freq", PXA2xxTimerInfo, freq, PXA27X_FREQ),
|
507 | 797e9542 | Dmitry Eremin-Solenikov | DEFINE_PROP_BIT("tm4", PXA2xxTimerInfo, flags,
|
508 | 797e9542 | Dmitry Eremin-Solenikov | PXA2XX_TIMER_HAVE_TM4, true),
|
509 | 797e9542 | Dmitry Eremin-Solenikov | DEFINE_PROP_END_OF_LIST(), |
510 | 797e9542 | Dmitry Eremin-Solenikov | }, |
511 | 797e9542 | Dmitry Eremin-Solenikov | }; |
512 | 797e9542 | Dmitry Eremin-Solenikov | |
513 | 797e9542 | Dmitry Eremin-Solenikov | static void pxa2xx_timer_register(void) |
514 | 797e9542 | Dmitry Eremin-Solenikov | { |
515 | 797e9542 | Dmitry Eremin-Solenikov | sysbus_register_withprop(&pxa25x_timer_dev_info); |
516 | 797e9542 | Dmitry Eremin-Solenikov | sysbus_register_withprop(&pxa27x_timer_dev_info); |
517 | 797e9542 | Dmitry Eremin-Solenikov | }; |
518 | 797e9542 | Dmitry Eremin-Solenikov | device_init(pxa2xx_timer_register); |