root / hw / omap1.c @ 9ef5c4bf
History | View | Annotate | Download (131.6 kB)
1 | c3d2689d | balrog | /*
|
---|---|---|---|
2 | c3d2689d | balrog | * TI OMAP processors emulation.
|
3 | c3d2689d | balrog | *
|
4 | b4e3104b | balrog | * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
|
5 | c3d2689d | balrog | *
|
6 | c3d2689d | balrog | * This program is free software; you can redistribute it and/or
|
7 | c3d2689d | balrog | * modify it under the terms of the GNU General Public License as
|
8 | 827df9f3 | balrog | * published by the Free Software Foundation; either version 2 or
|
9 | 827df9f3 | balrog | * (at your option) version 3 of the License.
|
10 | c3d2689d | balrog | *
|
11 | c3d2689d | balrog | * This program is distributed in the hope that it will be useful,
|
12 | c3d2689d | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | c3d2689d | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | c3d2689d | balrog | * GNU General Public License for more details.
|
15 | c3d2689d | balrog | *
|
16 | fad6cb1a | aurel32 | * You should have received a copy of the GNU General Public License along
|
17 | 8167ee88 | Blue Swirl | * with this program; if not, see <http://www.gnu.org/licenses/>.
|
18 | c3d2689d | balrog | */
|
19 | 87ecb68b | pbrook | #include "hw.h" |
20 | 87ecb68b | pbrook | #include "arm-misc.h" |
21 | 87ecb68b | pbrook | #include "omap.h" |
22 | 87ecb68b | pbrook | #include "sysemu.h" |
23 | 87ecb68b | pbrook | #include "qemu-timer.h" |
24 | 827df9f3 | balrog | #include "qemu-char.h" |
25 | afbb5194 | balrog | #include "soc_dma.h" |
26 | 87ecb68b | pbrook | /* We use pc-style serial ports. */
|
27 | 87ecb68b | pbrook | #include "pc.h" |
28 | c3d2689d | balrog | |
29 | 827df9f3 | balrog | /* Should signal the TCMI/GPMC */
|
30 | c227f099 | Anthony Liguori | uint32_t omap_badwidth_read8(void *opaque, target_phys_addr_t addr)
|
31 | 66450b15 | balrog | { |
32 | 02645926 | balrog | uint8_t ret; |
33 | 02645926 | balrog | |
34 | 66450b15 | balrog | OMAP_8B_REG(addr); |
35 | b854bc19 | balrog | cpu_physical_memory_read(addr, (void *) &ret, 1); |
36 | 02645926 | balrog | return ret;
|
37 | 66450b15 | balrog | } |
38 | 66450b15 | balrog | |
39 | c227f099 | Anthony Liguori | void omap_badwidth_write8(void *opaque, target_phys_addr_t addr, |
40 | 66450b15 | balrog | uint32_t value) |
41 | 66450b15 | balrog | { |
42 | b854bc19 | balrog | uint8_t val8 = value; |
43 | b854bc19 | balrog | |
44 | 66450b15 | balrog | OMAP_8B_REG(addr); |
45 | b854bc19 | balrog | cpu_physical_memory_write(addr, (void *) &val8, 1); |
46 | 66450b15 | balrog | } |
47 | 66450b15 | balrog | |
48 | c227f099 | Anthony Liguori | uint32_t omap_badwidth_read16(void *opaque, target_phys_addr_t addr)
|
49 | c3d2689d | balrog | { |
50 | b854bc19 | balrog | uint16_t ret; |
51 | b854bc19 | balrog | |
52 | c3d2689d | balrog | OMAP_16B_REG(addr); |
53 | b854bc19 | balrog | cpu_physical_memory_read(addr, (void *) &ret, 2); |
54 | b854bc19 | balrog | return ret;
|
55 | c3d2689d | balrog | } |
56 | c3d2689d | balrog | |
57 | c227f099 | Anthony Liguori | void omap_badwidth_write16(void *opaque, target_phys_addr_t addr, |
58 | c3d2689d | balrog | uint32_t value) |
59 | c3d2689d | balrog | { |
60 | b854bc19 | balrog | uint16_t val16 = value; |
61 | b854bc19 | balrog | |
62 | c3d2689d | balrog | OMAP_16B_REG(addr); |
63 | b854bc19 | balrog | cpu_physical_memory_write(addr, (void *) &val16, 2); |
64 | c3d2689d | balrog | } |
65 | c3d2689d | balrog | |
66 | c227f099 | Anthony Liguori | uint32_t omap_badwidth_read32(void *opaque, target_phys_addr_t addr)
|
67 | c3d2689d | balrog | { |
68 | b854bc19 | balrog | uint32_t ret; |
69 | b854bc19 | balrog | |
70 | c3d2689d | balrog | OMAP_32B_REG(addr); |
71 | b854bc19 | balrog | cpu_physical_memory_read(addr, (void *) &ret, 4); |
72 | b854bc19 | balrog | return ret;
|
73 | c3d2689d | balrog | } |
74 | c3d2689d | balrog | |
75 | c227f099 | Anthony Liguori | void omap_badwidth_write32(void *opaque, target_phys_addr_t addr, |
76 | c3d2689d | balrog | uint32_t value) |
77 | c3d2689d | balrog | { |
78 | c3d2689d | balrog | OMAP_32B_REG(addr); |
79 | b854bc19 | balrog | cpu_physical_memory_write(addr, (void *) &value, 4); |
80 | c3d2689d | balrog | } |
81 | c3d2689d | balrog | |
82 | c3d2689d | balrog | /* Interrupt Handlers */
|
83 | 106627d0 | balrog | struct omap_intr_handler_bank_s {
|
84 | c3d2689d | balrog | uint32_t irqs; |
85 | 106627d0 | balrog | uint32_t inputs; |
86 | c3d2689d | balrog | uint32_t mask; |
87 | c3d2689d | balrog | uint32_t fiq; |
88 | 106627d0 | balrog | uint32_t sens_edge; |
89 | 827df9f3 | balrog | uint32_t swi; |
90 | 106627d0 | balrog | unsigned char priority[32]; |
91 | c3d2689d | balrog | }; |
92 | c3d2689d | balrog | |
93 | 106627d0 | balrog | struct omap_intr_handler_s {
|
94 | 106627d0 | balrog | qemu_irq *pins; |
95 | 106627d0 | balrog | qemu_irq parent_intr[2];
|
96 | 106627d0 | balrog | unsigned char nbanks; |
97 | 827df9f3 | balrog | int level_only;
|
98 | c3d2689d | balrog | |
99 | 106627d0 | balrog | /* state */
|
100 | 106627d0 | balrog | uint32_t new_agr[2];
|
101 | 106627d0 | balrog | int sir_intr[2]; |
102 | 827df9f3 | balrog | int autoidle;
|
103 | 827df9f3 | balrog | uint32_t mask; |
104 | 827df9f3 | balrog | struct omap_intr_handler_bank_s bank[];
|
105 | 106627d0 | balrog | }; |
106 | c3d2689d | balrog | |
107 | 106627d0 | balrog | static void omap_inth_sir_update(struct omap_intr_handler_s *s, int is_fiq) |
108 | 106627d0 | balrog | { |
109 | 106627d0 | balrog | int i, j, sir_intr, p_intr, p, f;
|
110 | 106627d0 | balrog | uint32_t level; |
111 | 106627d0 | balrog | sir_intr = 0;
|
112 | 106627d0 | balrog | p_intr = 255;
|
113 | 106627d0 | balrog | |
114 | 106627d0 | balrog | /* Find the interrupt line with the highest dynamic priority.
|
115 | 106627d0 | balrog | * Note: 0 denotes the hightest priority.
|
116 | 106627d0 | balrog | * If all interrupts have the same priority, the default order is IRQ_N,
|
117 | 106627d0 | balrog | * IRQ_N-1,...,IRQ_0. */
|
118 | 106627d0 | balrog | for (j = 0; j < s->nbanks; ++j) { |
119 | 827df9f3 | balrog | level = s->bank[j].irqs & ~s->bank[j].mask & |
120 | 827df9f3 | balrog | (is_fiq ? s->bank[j].fiq : ~s->bank[j].fiq); |
121 | 106627d0 | balrog | for (f = ffs(level), i = f - 1, level >>= f - 1; f; i += f, |
122 | 106627d0 | balrog | level >>= f) { |
123 | 827df9f3 | balrog | p = s->bank[j].priority[i]; |
124 | 106627d0 | balrog | if (p <= p_intr) {
|
125 | 106627d0 | balrog | p_intr = p; |
126 | 106627d0 | balrog | sir_intr = 32 * j + i;
|
127 | 106627d0 | balrog | } |
128 | 106627d0 | balrog | f = ffs(level >> 1);
|
129 | 106627d0 | balrog | } |
130 | cfa0b71d | balrog | } |
131 | 106627d0 | balrog | s->sir_intr[is_fiq] = sir_intr; |
132 | c3d2689d | balrog | } |
133 | c3d2689d | balrog | |
134 | 106627d0 | balrog | static inline void omap_inth_update(struct omap_intr_handler_s *s, int is_fiq) |
135 | c3d2689d | balrog | { |
136 | 106627d0 | balrog | int i;
|
137 | 106627d0 | balrog | uint32_t has_intr = 0;
|
138 | c3d2689d | balrog | |
139 | 106627d0 | balrog | for (i = 0; i < s->nbanks; ++i) |
140 | 827df9f3 | balrog | has_intr |= s->bank[i].irqs & ~s->bank[i].mask & |
141 | 827df9f3 | balrog | (is_fiq ? s->bank[i].fiq : ~s->bank[i].fiq); |
142 | c3d2689d | balrog | |
143 | 827df9f3 | balrog | if (s->new_agr[is_fiq] & has_intr & s->mask) {
|
144 | 106627d0 | balrog | s->new_agr[is_fiq] = 0;
|
145 | 106627d0 | balrog | omap_inth_sir_update(s, is_fiq); |
146 | 106627d0 | balrog | qemu_set_irq(s->parent_intr[is_fiq], 1);
|
147 | c3d2689d | balrog | } |
148 | c3d2689d | balrog | } |
149 | c3d2689d | balrog | |
150 | c3d2689d | balrog | #define INT_FALLING_EDGE 0 |
151 | c3d2689d | balrog | #define INT_LOW_LEVEL 1 |
152 | c3d2689d | balrog | |
153 | c3d2689d | balrog | static void omap_set_intr(void *opaque, int irq, int req) |
154 | c3d2689d | balrog | { |
155 | c3d2689d | balrog | struct omap_intr_handler_s *ih = (struct omap_intr_handler_s *) opaque; |
156 | c3d2689d | balrog | uint32_t rise; |
157 | c3d2689d | balrog | |
158 | 827df9f3 | balrog | struct omap_intr_handler_bank_s *bank = &ih->bank[irq >> 5]; |
159 | 106627d0 | balrog | int n = irq & 31; |
160 | 106627d0 | balrog | |
161 | c3d2689d | balrog | if (req) {
|
162 | 106627d0 | balrog | rise = ~bank->irqs & (1 << n);
|
163 | 106627d0 | balrog | if (~bank->sens_edge & (1 << n)) |
164 | 827df9f3 | balrog | rise &= ~bank->inputs; |
165 | 106627d0 | balrog | |
166 | 106627d0 | balrog | bank->inputs |= (1 << n);
|
167 | 106627d0 | balrog | if (rise) {
|
168 | 106627d0 | balrog | bank->irqs |= rise; |
169 | 106627d0 | balrog | omap_inth_update(ih, 0);
|
170 | 106627d0 | balrog | omap_inth_update(ih, 1);
|
171 | 106627d0 | balrog | } |
172 | c3d2689d | balrog | } else {
|
173 | 106627d0 | balrog | rise = bank->sens_edge & bank->irqs & (1 << n);
|
174 | 106627d0 | balrog | bank->irqs &= ~rise; |
175 | 106627d0 | balrog | bank->inputs &= ~(1 << n);
|
176 | c3d2689d | balrog | } |
177 | c3d2689d | balrog | } |
178 | c3d2689d | balrog | |
179 | 827df9f3 | balrog | /* Simplified version with no edge detection */
|
180 | 827df9f3 | balrog | static void omap_set_intr_noedge(void *opaque, int irq, int req) |
181 | 827df9f3 | balrog | { |
182 | 827df9f3 | balrog | struct omap_intr_handler_s *ih = (struct omap_intr_handler_s *) opaque; |
183 | 827df9f3 | balrog | uint32_t rise; |
184 | 827df9f3 | balrog | |
185 | 827df9f3 | balrog | struct omap_intr_handler_bank_s *bank = &ih->bank[irq >> 5]; |
186 | 827df9f3 | balrog | int n = irq & 31; |
187 | 827df9f3 | balrog | |
188 | 827df9f3 | balrog | if (req) {
|
189 | 827df9f3 | balrog | rise = ~bank->inputs & (1 << n);
|
190 | 827df9f3 | balrog | if (rise) {
|
191 | 827df9f3 | balrog | bank->irqs |= bank->inputs |= rise; |
192 | 827df9f3 | balrog | omap_inth_update(ih, 0);
|
193 | 827df9f3 | balrog | omap_inth_update(ih, 1);
|
194 | 827df9f3 | balrog | } |
195 | 827df9f3 | balrog | } else
|
196 | 827df9f3 | balrog | bank->irqs = (bank->inputs &= ~(1 << n)) | bank->swi;
|
197 | 827df9f3 | balrog | } |
198 | 827df9f3 | balrog | |
199 | c227f099 | Anthony Liguori | static uint32_t omap_inth_read(void *opaque, target_phys_addr_t addr) |
200 | c3d2689d | balrog | { |
201 | c3d2689d | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque; |
202 | 8da3ff18 | pbrook | int i, offset = addr;
|
203 | 106627d0 | balrog | int bank_no = offset >> 8; |
204 | 106627d0 | balrog | int line_no;
|
205 | 827df9f3 | balrog | struct omap_intr_handler_bank_s *bank = &s->bank[bank_no];
|
206 | 106627d0 | balrog | offset &= 0xff;
|
207 | c3d2689d | balrog | |
208 | c3d2689d | balrog | switch (offset) {
|
209 | c3d2689d | balrog | case 0x00: /* ITR */ |
210 | 106627d0 | balrog | return bank->irqs;
|
211 | c3d2689d | balrog | |
212 | c3d2689d | balrog | case 0x04: /* MIR */ |
213 | 106627d0 | balrog | return bank->mask;
|
214 | c3d2689d | balrog | |
215 | c3d2689d | balrog | case 0x10: /* SIR_IRQ_CODE */ |
216 | 106627d0 | balrog | case 0x14: /* SIR_FIQ_CODE */ |
217 | 106627d0 | balrog | if (bank_no != 0) |
218 | 106627d0 | balrog | break;
|
219 | 106627d0 | balrog | line_no = s->sir_intr[(offset - 0x10) >> 2]; |
220 | 827df9f3 | balrog | bank = &s->bank[line_no >> 5];
|
221 | 106627d0 | balrog | i = line_no & 31;
|
222 | 106627d0 | balrog | if (((bank->sens_edge >> i) & 1) == INT_FALLING_EDGE) |
223 | 106627d0 | balrog | bank->irqs &= ~(1 << i);
|
224 | f2df5260 | balrog | return line_no;
|
225 | c3d2689d | balrog | |
226 | c3d2689d | balrog | case 0x18: /* CONTROL_REG */ |
227 | 106627d0 | balrog | if (bank_no != 0) |
228 | 106627d0 | balrog | break;
|
229 | c3d2689d | balrog | return 0; |
230 | c3d2689d | balrog | |
231 | c3d2689d | balrog | case 0x1c: /* ILR0 */ |
232 | c3d2689d | balrog | case 0x20: /* ILR1 */ |
233 | c3d2689d | balrog | case 0x24: /* ILR2 */ |
234 | c3d2689d | balrog | case 0x28: /* ILR3 */ |
235 | c3d2689d | balrog | case 0x2c: /* ILR4 */ |
236 | c3d2689d | balrog | case 0x30: /* ILR5 */ |
237 | c3d2689d | balrog | case 0x34: /* ILR6 */ |
238 | c3d2689d | balrog | case 0x38: /* ILR7 */ |
239 | c3d2689d | balrog | case 0x3c: /* ILR8 */ |
240 | c3d2689d | balrog | case 0x40: /* ILR9 */ |
241 | c3d2689d | balrog | case 0x44: /* ILR10 */ |
242 | c3d2689d | balrog | case 0x48: /* ILR11 */ |
243 | c3d2689d | balrog | case 0x4c: /* ILR12 */ |
244 | c3d2689d | balrog | case 0x50: /* ILR13 */ |
245 | c3d2689d | balrog | case 0x54: /* ILR14 */ |
246 | c3d2689d | balrog | case 0x58: /* ILR15 */ |
247 | c3d2689d | balrog | case 0x5c: /* ILR16 */ |
248 | c3d2689d | balrog | case 0x60: /* ILR17 */ |
249 | c3d2689d | balrog | case 0x64: /* ILR18 */ |
250 | c3d2689d | balrog | case 0x68: /* ILR19 */ |
251 | c3d2689d | balrog | case 0x6c: /* ILR20 */ |
252 | c3d2689d | balrog | case 0x70: /* ILR21 */ |
253 | c3d2689d | balrog | case 0x74: /* ILR22 */ |
254 | c3d2689d | balrog | case 0x78: /* ILR23 */ |
255 | c3d2689d | balrog | case 0x7c: /* ILR24 */ |
256 | c3d2689d | balrog | case 0x80: /* ILR25 */ |
257 | c3d2689d | balrog | case 0x84: /* ILR26 */ |
258 | c3d2689d | balrog | case 0x88: /* ILR27 */ |
259 | c3d2689d | balrog | case 0x8c: /* ILR28 */ |
260 | c3d2689d | balrog | case 0x90: /* ILR29 */ |
261 | c3d2689d | balrog | case 0x94: /* ILR30 */ |
262 | c3d2689d | balrog | case 0x98: /* ILR31 */ |
263 | c3d2689d | balrog | i = (offset - 0x1c) >> 2; |
264 | 106627d0 | balrog | return (bank->priority[i] << 2) | |
265 | 106627d0 | balrog | (((bank->sens_edge >> i) & 1) << 1) | |
266 | 106627d0 | balrog | ((bank->fiq >> i) & 1);
|
267 | c3d2689d | balrog | |
268 | c3d2689d | balrog | case 0x9c: /* ISR */ |
269 | c3d2689d | balrog | return 0x00000000; |
270 | c3d2689d | balrog | |
271 | c3d2689d | balrog | } |
272 | 106627d0 | balrog | OMAP_BAD_REG(addr); |
273 | c3d2689d | balrog | return 0; |
274 | c3d2689d | balrog | } |
275 | c3d2689d | balrog | |
276 | c227f099 | Anthony Liguori | static void omap_inth_write(void *opaque, target_phys_addr_t addr, |
277 | c3d2689d | balrog | uint32_t value) |
278 | c3d2689d | balrog | { |
279 | c3d2689d | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque; |
280 | 8da3ff18 | pbrook | int i, offset = addr;
|
281 | 106627d0 | balrog | int bank_no = offset >> 8; |
282 | 827df9f3 | balrog | struct omap_intr_handler_bank_s *bank = &s->bank[bank_no];
|
283 | 106627d0 | balrog | offset &= 0xff;
|
284 | c3d2689d | balrog | |
285 | c3d2689d | balrog | switch (offset) {
|
286 | c3d2689d | balrog | case 0x00: /* ITR */ |
287 | 106627d0 | balrog | /* Important: ignore the clearing if the IRQ is level-triggered and
|
288 | 106627d0 | balrog | the input bit is 1 */
|
289 | 106627d0 | balrog | bank->irqs &= value | (bank->inputs & bank->sens_edge); |
290 | c3d2689d | balrog | return;
|
291 | c3d2689d | balrog | |
292 | c3d2689d | balrog | case 0x04: /* MIR */ |
293 | 106627d0 | balrog | bank->mask = value; |
294 | 106627d0 | balrog | omap_inth_update(s, 0);
|
295 | 106627d0 | balrog | omap_inth_update(s, 1);
|
296 | c3d2689d | balrog | return;
|
297 | c3d2689d | balrog | |
298 | c3d2689d | balrog | case 0x10: /* SIR_IRQ_CODE */ |
299 | c3d2689d | balrog | case 0x14: /* SIR_FIQ_CODE */ |
300 | c3d2689d | balrog | OMAP_RO_REG(addr); |
301 | c3d2689d | balrog | break;
|
302 | c3d2689d | balrog | |
303 | c3d2689d | balrog | case 0x18: /* CONTROL_REG */ |
304 | 106627d0 | balrog | if (bank_no != 0) |
305 | 106627d0 | balrog | break;
|
306 | 106627d0 | balrog | if (value & 2) { |
307 | 106627d0 | balrog | qemu_set_irq(s->parent_intr[1], 0); |
308 | 106627d0 | balrog | s->new_agr[1] = ~0; |
309 | 106627d0 | balrog | omap_inth_update(s, 1);
|
310 | 106627d0 | balrog | } |
311 | 106627d0 | balrog | if (value & 1) { |
312 | 106627d0 | balrog | qemu_set_irq(s->parent_intr[0], 0); |
313 | 106627d0 | balrog | s->new_agr[0] = ~0; |
314 | 106627d0 | balrog | omap_inth_update(s, 0);
|
315 | 106627d0 | balrog | } |
316 | c3d2689d | balrog | return;
|
317 | c3d2689d | balrog | |
318 | c3d2689d | balrog | case 0x1c: /* ILR0 */ |
319 | c3d2689d | balrog | case 0x20: /* ILR1 */ |
320 | c3d2689d | balrog | case 0x24: /* ILR2 */ |
321 | c3d2689d | balrog | case 0x28: /* ILR3 */ |
322 | c3d2689d | balrog | case 0x2c: /* ILR4 */ |
323 | c3d2689d | balrog | case 0x30: /* ILR5 */ |
324 | c3d2689d | balrog | case 0x34: /* ILR6 */ |
325 | c3d2689d | balrog | case 0x38: /* ILR7 */ |
326 | c3d2689d | balrog | case 0x3c: /* ILR8 */ |
327 | c3d2689d | balrog | case 0x40: /* ILR9 */ |
328 | c3d2689d | balrog | case 0x44: /* ILR10 */ |
329 | c3d2689d | balrog | case 0x48: /* ILR11 */ |
330 | c3d2689d | balrog | case 0x4c: /* ILR12 */ |
331 | c3d2689d | balrog | case 0x50: /* ILR13 */ |
332 | c3d2689d | balrog | case 0x54: /* ILR14 */ |
333 | c3d2689d | balrog | case 0x58: /* ILR15 */ |
334 | c3d2689d | balrog | case 0x5c: /* ILR16 */ |
335 | c3d2689d | balrog | case 0x60: /* ILR17 */ |
336 | c3d2689d | balrog | case 0x64: /* ILR18 */ |
337 | c3d2689d | balrog | case 0x68: /* ILR19 */ |
338 | c3d2689d | balrog | case 0x6c: /* ILR20 */ |
339 | c3d2689d | balrog | case 0x70: /* ILR21 */ |
340 | c3d2689d | balrog | case 0x74: /* ILR22 */ |
341 | c3d2689d | balrog | case 0x78: /* ILR23 */ |
342 | c3d2689d | balrog | case 0x7c: /* ILR24 */ |
343 | c3d2689d | balrog | case 0x80: /* ILR25 */ |
344 | c3d2689d | balrog | case 0x84: /* ILR26 */ |
345 | c3d2689d | balrog | case 0x88: /* ILR27 */ |
346 | c3d2689d | balrog | case 0x8c: /* ILR28 */ |
347 | c3d2689d | balrog | case 0x90: /* ILR29 */ |
348 | c3d2689d | balrog | case 0x94: /* ILR30 */ |
349 | c3d2689d | balrog | case 0x98: /* ILR31 */ |
350 | c3d2689d | balrog | i = (offset - 0x1c) >> 2; |
351 | 106627d0 | balrog | bank->priority[i] = (value >> 2) & 0x1f; |
352 | 106627d0 | balrog | bank->sens_edge &= ~(1 << i);
|
353 | 106627d0 | balrog | bank->sens_edge |= ((value >> 1) & 1) << i; |
354 | 106627d0 | balrog | bank->fiq &= ~(1 << i);
|
355 | 106627d0 | balrog | bank->fiq |= (value & 1) << i;
|
356 | c3d2689d | balrog | return;
|
357 | c3d2689d | balrog | |
358 | c3d2689d | balrog | case 0x9c: /* ISR */ |
359 | c3d2689d | balrog | for (i = 0; i < 32; i ++) |
360 | c3d2689d | balrog | if (value & (1 << i)) { |
361 | 106627d0 | balrog | omap_set_intr(s, 32 * bank_no + i, 1); |
362 | c3d2689d | balrog | return;
|
363 | c3d2689d | balrog | } |
364 | c3d2689d | balrog | return;
|
365 | c3d2689d | balrog | } |
366 | 106627d0 | balrog | OMAP_BAD_REG(addr); |
367 | c3d2689d | balrog | } |
368 | c3d2689d | balrog | |
369 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_inth_readfn[] = { |
370 | c3d2689d | balrog | omap_badwidth_read32, |
371 | c3d2689d | balrog | omap_badwidth_read32, |
372 | c3d2689d | balrog | omap_inth_read, |
373 | c3d2689d | balrog | }; |
374 | c3d2689d | balrog | |
375 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_inth_writefn[] = { |
376 | c3d2689d | balrog | omap_inth_write, |
377 | c3d2689d | balrog | omap_inth_write, |
378 | c3d2689d | balrog | omap_inth_write, |
379 | c3d2689d | balrog | }; |
380 | c3d2689d | balrog | |
381 | 106627d0 | balrog | void omap_inth_reset(struct omap_intr_handler_s *s) |
382 | c3d2689d | balrog | { |
383 | 106627d0 | balrog | int i;
|
384 | 106627d0 | balrog | |
385 | 106627d0 | balrog | for (i = 0; i < s->nbanks; ++i){ |
386 | 827df9f3 | balrog | s->bank[i].irqs = 0x00000000;
|
387 | 827df9f3 | balrog | s->bank[i].mask = 0xffffffff;
|
388 | 827df9f3 | balrog | s->bank[i].sens_edge = 0x00000000;
|
389 | 827df9f3 | balrog | s->bank[i].fiq = 0x00000000;
|
390 | 827df9f3 | balrog | s->bank[i].inputs = 0x00000000;
|
391 | 827df9f3 | balrog | s->bank[i].swi = 0x00000000;
|
392 | 827df9f3 | balrog | memset(s->bank[i].priority, 0, sizeof(s->bank[i].priority)); |
393 | 827df9f3 | balrog | |
394 | 827df9f3 | balrog | if (s->level_only)
|
395 | 827df9f3 | balrog | s->bank[i].sens_edge = 0xffffffff;
|
396 | 106627d0 | balrog | } |
397 | c3d2689d | balrog | |
398 | 106627d0 | balrog | s->new_agr[0] = ~0; |
399 | 106627d0 | balrog | s->new_agr[1] = ~0; |
400 | 106627d0 | balrog | s->sir_intr[0] = 0; |
401 | 106627d0 | balrog | s->sir_intr[1] = 0; |
402 | 827df9f3 | balrog | s->autoidle = 0;
|
403 | 827df9f3 | balrog | s->mask = ~0;
|
404 | 106627d0 | balrog | |
405 | 106627d0 | balrog | qemu_set_irq(s->parent_intr[0], 0); |
406 | 106627d0 | balrog | qemu_set_irq(s->parent_intr[1], 0); |
407 | c3d2689d | balrog | } |
408 | c3d2689d | balrog | |
409 | c227f099 | Anthony Liguori | struct omap_intr_handler_s *omap_inth_init(target_phys_addr_t base,
|
410 | 827df9f3 | balrog | unsigned long size, unsigned char nbanks, qemu_irq **pins, |
411 | 106627d0 | balrog | qemu_irq parent_irq, qemu_irq parent_fiq, omap_clk clk) |
412 | c3d2689d | balrog | { |
413 | c3d2689d | balrog | int iomemtype;
|
414 | c3d2689d | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) |
415 | 106627d0 | balrog | qemu_mallocz(sizeof(struct omap_intr_handler_s) + |
416 | 106627d0 | balrog | sizeof(struct omap_intr_handler_bank_s) * nbanks); |
417 | c3d2689d | balrog | |
418 | 106627d0 | balrog | s->parent_intr[0] = parent_irq;
|
419 | 106627d0 | balrog | s->parent_intr[1] = parent_fiq;
|
420 | 106627d0 | balrog | s->nbanks = nbanks; |
421 | 106627d0 | balrog | s->pins = qemu_allocate_irqs(omap_set_intr, s, nbanks * 32);
|
422 | 827df9f3 | balrog | if (pins)
|
423 | 827df9f3 | balrog | *pins = s->pins; |
424 | 106627d0 | balrog | |
425 | c3d2689d | balrog | omap_inth_reset(s); |
426 | c3d2689d | balrog | |
427 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_inth_readfn, |
428 | c3d2689d | balrog | omap_inth_writefn, s); |
429 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, size, iomemtype); |
430 | c3d2689d | balrog | |
431 | c3d2689d | balrog | return s;
|
432 | c3d2689d | balrog | } |
433 | c3d2689d | balrog | |
434 | c227f099 | Anthony Liguori | static uint32_t omap2_inth_read(void *opaque, target_phys_addr_t addr) |
435 | 827df9f3 | balrog | { |
436 | 827df9f3 | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque; |
437 | 8da3ff18 | pbrook | int offset = addr;
|
438 | 827df9f3 | balrog | int bank_no, line_no;
|
439 | b9d38e95 | Blue Swirl | struct omap_intr_handler_bank_s *bank = NULL; |
440 | 827df9f3 | balrog | |
441 | 827df9f3 | balrog | if ((offset & 0xf80) == 0x80) { |
442 | 827df9f3 | balrog | bank_no = (offset & 0x60) >> 5; |
443 | 827df9f3 | balrog | if (bank_no < s->nbanks) {
|
444 | 827df9f3 | balrog | offset &= ~0x60;
|
445 | 827df9f3 | balrog | bank = &s->bank[bank_no]; |
446 | 827df9f3 | balrog | } |
447 | 827df9f3 | balrog | } |
448 | 827df9f3 | balrog | |
449 | 827df9f3 | balrog | switch (offset) {
|
450 | 827df9f3 | balrog | case 0x00: /* INTC_REVISION */ |
451 | 827df9f3 | balrog | return 0x21; |
452 | 827df9f3 | balrog | |
453 | 827df9f3 | balrog | case 0x10: /* INTC_SYSCONFIG */ |
454 | 827df9f3 | balrog | return (s->autoidle >> 2) & 1; |
455 | 827df9f3 | balrog | |
456 | 827df9f3 | balrog | case 0x14: /* INTC_SYSSTATUS */ |
457 | 827df9f3 | balrog | return 1; /* RESETDONE */ |
458 | 827df9f3 | balrog | |
459 | 827df9f3 | balrog | case 0x40: /* INTC_SIR_IRQ */ |
460 | 827df9f3 | balrog | return s->sir_intr[0]; |
461 | 827df9f3 | balrog | |
462 | 827df9f3 | balrog | case 0x44: /* INTC_SIR_FIQ */ |
463 | 827df9f3 | balrog | return s->sir_intr[1]; |
464 | 827df9f3 | balrog | |
465 | 827df9f3 | balrog | case 0x48: /* INTC_CONTROL */ |
466 | 827df9f3 | balrog | return (!s->mask) << 2; /* GLOBALMASK */ |
467 | 827df9f3 | balrog | |
468 | 827df9f3 | balrog | case 0x4c: /* INTC_PROTECTION */ |
469 | 827df9f3 | balrog | return 0; |
470 | 827df9f3 | balrog | |
471 | 827df9f3 | balrog | case 0x50: /* INTC_IDLE */ |
472 | 827df9f3 | balrog | return s->autoidle & 3; |
473 | 827df9f3 | balrog | |
474 | 827df9f3 | balrog | /* Per-bank registers */
|
475 | 827df9f3 | balrog | case 0x80: /* INTC_ITR */ |
476 | 827df9f3 | balrog | return bank->inputs;
|
477 | 827df9f3 | balrog | |
478 | 827df9f3 | balrog | case 0x84: /* INTC_MIR */ |
479 | 827df9f3 | balrog | return bank->mask;
|
480 | 827df9f3 | balrog | |
481 | 827df9f3 | balrog | case 0x88: /* INTC_MIR_CLEAR */ |
482 | 827df9f3 | balrog | case 0x8c: /* INTC_MIR_SET */ |
483 | 827df9f3 | balrog | return 0; |
484 | 827df9f3 | balrog | |
485 | 827df9f3 | balrog | case 0x90: /* INTC_ISR_SET */ |
486 | 827df9f3 | balrog | return bank->swi;
|
487 | 827df9f3 | balrog | |
488 | 827df9f3 | balrog | case 0x94: /* INTC_ISR_CLEAR */ |
489 | 827df9f3 | balrog | return 0; |
490 | 827df9f3 | balrog | |
491 | 827df9f3 | balrog | case 0x98: /* INTC_PENDING_IRQ */ |
492 | 827df9f3 | balrog | return bank->irqs & ~bank->mask & ~bank->fiq;
|
493 | 827df9f3 | balrog | |
494 | 827df9f3 | balrog | case 0x9c: /* INTC_PENDING_FIQ */ |
495 | 827df9f3 | balrog | return bank->irqs & ~bank->mask & bank->fiq;
|
496 | 827df9f3 | balrog | |
497 | 827df9f3 | balrog | /* Per-line registers */
|
498 | 827df9f3 | balrog | case 0x100 ... 0x300: /* INTC_ILR */ |
499 | 827df9f3 | balrog | bank_no = (offset - 0x100) >> 7; |
500 | 827df9f3 | balrog | if (bank_no > s->nbanks)
|
501 | 827df9f3 | balrog | break;
|
502 | 827df9f3 | balrog | bank = &s->bank[bank_no]; |
503 | 827df9f3 | balrog | line_no = (offset & 0x7f) >> 2; |
504 | 827df9f3 | balrog | return (bank->priority[line_no] << 2) | |
505 | 827df9f3 | balrog | ((bank->fiq >> line_no) & 1);
|
506 | 827df9f3 | balrog | } |
507 | 827df9f3 | balrog | OMAP_BAD_REG(addr); |
508 | 827df9f3 | balrog | return 0; |
509 | 827df9f3 | balrog | } |
510 | 827df9f3 | balrog | |
511 | c227f099 | Anthony Liguori | static void omap2_inth_write(void *opaque, target_phys_addr_t addr, |
512 | 827df9f3 | balrog | uint32_t value) |
513 | 827df9f3 | balrog | { |
514 | 827df9f3 | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque; |
515 | 8da3ff18 | pbrook | int offset = addr;
|
516 | 827df9f3 | balrog | int bank_no, line_no;
|
517 | b9d38e95 | Blue Swirl | struct omap_intr_handler_bank_s *bank = NULL; |
518 | 827df9f3 | balrog | |
519 | 827df9f3 | balrog | if ((offset & 0xf80) == 0x80) { |
520 | 827df9f3 | balrog | bank_no = (offset & 0x60) >> 5; |
521 | 827df9f3 | balrog | if (bank_no < s->nbanks) {
|
522 | 827df9f3 | balrog | offset &= ~0x60;
|
523 | 827df9f3 | balrog | bank = &s->bank[bank_no]; |
524 | 827df9f3 | balrog | } |
525 | 827df9f3 | balrog | } |
526 | 827df9f3 | balrog | |
527 | 827df9f3 | balrog | switch (offset) {
|
528 | 827df9f3 | balrog | case 0x10: /* INTC_SYSCONFIG */ |
529 | 827df9f3 | balrog | s->autoidle &= 4;
|
530 | 827df9f3 | balrog | s->autoidle |= (value & 1) << 2; |
531 | 827df9f3 | balrog | if (value & 2) /* SOFTRESET */ |
532 | 827df9f3 | balrog | omap_inth_reset(s); |
533 | 827df9f3 | balrog | return;
|
534 | 827df9f3 | balrog | |
535 | 827df9f3 | balrog | case 0x48: /* INTC_CONTROL */ |
536 | 827df9f3 | balrog | s->mask = (value & 4) ? 0 : ~0; /* GLOBALMASK */ |
537 | 827df9f3 | balrog | if (value & 2) { /* NEWFIQAGR */ |
538 | 827df9f3 | balrog | qemu_set_irq(s->parent_intr[1], 0); |
539 | 827df9f3 | balrog | s->new_agr[1] = ~0; |
540 | 827df9f3 | balrog | omap_inth_update(s, 1);
|
541 | 827df9f3 | balrog | } |
542 | 827df9f3 | balrog | if (value & 1) { /* NEWIRQAGR */ |
543 | 827df9f3 | balrog | qemu_set_irq(s->parent_intr[0], 0); |
544 | 827df9f3 | balrog | s->new_agr[0] = ~0; |
545 | 827df9f3 | balrog | omap_inth_update(s, 0);
|
546 | 827df9f3 | balrog | } |
547 | 827df9f3 | balrog | return;
|
548 | 827df9f3 | balrog | |
549 | 827df9f3 | balrog | case 0x4c: /* INTC_PROTECTION */ |
550 | 827df9f3 | balrog | /* TODO: Make a bitmap (or sizeof(char)map) of access privileges
|
551 | 827df9f3 | balrog | * for every register, see Chapter 3 and 4 for privileged mode. */
|
552 | 827df9f3 | balrog | if (value & 1) |
553 | 827df9f3 | balrog | fprintf(stderr, "%s: protection mode enable attempt\n",
|
554 | 827df9f3 | balrog | __FUNCTION__); |
555 | 827df9f3 | balrog | return;
|
556 | 827df9f3 | balrog | |
557 | 827df9f3 | balrog | case 0x50: /* INTC_IDLE */ |
558 | 827df9f3 | balrog | s->autoidle &= ~3;
|
559 | 827df9f3 | balrog | s->autoidle |= value & 3;
|
560 | 827df9f3 | balrog | return;
|
561 | 827df9f3 | balrog | |
562 | 827df9f3 | balrog | /* Per-bank registers */
|
563 | 827df9f3 | balrog | case 0x84: /* INTC_MIR */ |
564 | 827df9f3 | balrog | bank->mask = value; |
565 | 827df9f3 | balrog | omap_inth_update(s, 0);
|
566 | 827df9f3 | balrog | omap_inth_update(s, 1);
|
567 | 827df9f3 | balrog | return;
|
568 | 827df9f3 | balrog | |
569 | 827df9f3 | balrog | case 0x88: /* INTC_MIR_CLEAR */ |
570 | 827df9f3 | balrog | bank->mask &= ~value; |
571 | 827df9f3 | balrog | omap_inth_update(s, 0);
|
572 | 827df9f3 | balrog | omap_inth_update(s, 1);
|
573 | 827df9f3 | balrog | return;
|
574 | 827df9f3 | balrog | |
575 | 827df9f3 | balrog | case 0x8c: /* INTC_MIR_SET */ |
576 | 827df9f3 | balrog | bank->mask |= value; |
577 | 827df9f3 | balrog | return;
|
578 | 827df9f3 | balrog | |
579 | 827df9f3 | balrog | case 0x90: /* INTC_ISR_SET */ |
580 | 827df9f3 | balrog | bank->irqs |= bank->swi |= value; |
581 | 827df9f3 | balrog | omap_inth_update(s, 0);
|
582 | 827df9f3 | balrog | omap_inth_update(s, 1);
|
583 | 827df9f3 | balrog | return;
|
584 | 827df9f3 | balrog | |
585 | 827df9f3 | balrog | case 0x94: /* INTC_ISR_CLEAR */ |
586 | 827df9f3 | balrog | bank->swi &= ~value; |
587 | 827df9f3 | balrog | bank->irqs = bank->swi & bank->inputs; |
588 | 827df9f3 | balrog | return;
|
589 | 827df9f3 | balrog | |
590 | 827df9f3 | balrog | /* Per-line registers */
|
591 | 827df9f3 | balrog | case 0x100 ... 0x300: /* INTC_ILR */ |
592 | 827df9f3 | balrog | bank_no = (offset - 0x100) >> 7; |
593 | 827df9f3 | balrog | if (bank_no > s->nbanks)
|
594 | 827df9f3 | balrog | break;
|
595 | 827df9f3 | balrog | bank = &s->bank[bank_no]; |
596 | 827df9f3 | balrog | line_no = (offset & 0x7f) >> 2; |
597 | 827df9f3 | balrog | bank->priority[line_no] = (value >> 2) & 0x3f; |
598 | 827df9f3 | balrog | bank->fiq &= ~(1 << line_no);
|
599 | 827df9f3 | balrog | bank->fiq |= (value & 1) << line_no;
|
600 | 827df9f3 | balrog | return;
|
601 | 827df9f3 | balrog | |
602 | 827df9f3 | balrog | case 0x00: /* INTC_REVISION */ |
603 | 827df9f3 | balrog | case 0x14: /* INTC_SYSSTATUS */ |
604 | 827df9f3 | balrog | case 0x40: /* INTC_SIR_IRQ */ |
605 | 827df9f3 | balrog | case 0x44: /* INTC_SIR_FIQ */ |
606 | 827df9f3 | balrog | case 0x80: /* INTC_ITR */ |
607 | 827df9f3 | balrog | case 0x98: /* INTC_PENDING_IRQ */ |
608 | 827df9f3 | balrog | case 0x9c: /* INTC_PENDING_FIQ */ |
609 | 827df9f3 | balrog | OMAP_RO_REG(addr); |
610 | 827df9f3 | balrog | return;
|
611 | 827df9f3 | balrog | } |
612 | 827df9f3 | balrog | OMAP_BAD_REG(addr); |
613 | 827df9f3 | balrog | } |
614 | 827df9f3 | balrog | |
615 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap2_inth_readfn[] = { |
616 | 827df9f3 | balrog | omap_badwidth_read32, |
617 | 827df9f3 | balrog | omap_badwidth_read32, |
618 | 827df9f3 | balrog | omap2_inth_read, |
619 | 827df9f3 | balrog | }; |
620 | 827df9f3 | balrog | |
621 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap2_inth_writefn[] = { |
622 | 827df9f3 | balrog | omap2_inth_write, |
623 | 827df9f3 | balrog | omap2_inth_write, |
624 | 827df9f3 | balrog | omap2_inth_write, |
625 | 827df9f3 | balrog | }; |
626 | 827df9f3 | balrog | |
627 | c227f099 | Anthony Liguori | struct omap_intr_handler_s *omap2_inth_init(target_phys_addr_t base,
|
628 | 827df9f3 | balrog | int size, int nbanks, qemu_irq **pins, |
629 | 827df9f3 | balrog | qemu_irq parent_irq, qemu_irq parent_fiq, |
630 | 827df9f3 | balrog | omap_clk fclk, omap_clk iclk) |
631 | 827df9f3 | balrog | { |
632 | 827df9f3 | balrog | int iomemtype;
|
633 | 827df9f3 | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) |
634 | 827df9f3 | balrog | qemu_mallocz(sizeof(struct omap_intr_handler_s) + |
635 | 827df9f3 | balrog | sizeof(struct omap_intr_handler_bank_s) * nbanks); |
636 | 827df9f3 | balrog | |
637 | 827df9f3 | balrog | s->parent_intr[0] = parent_irq;
|
638 | 827df9f3 | balrog | s->parent_intr[1] = parent_fiq;
|
639 | 827df9f3 | balrog | s->nbanks = nbanks; |
640 | 827df9f3 | balrog | s->level_only = 1;
|
641 | 827df9f3 | balrog | s->pins = qemu_allocate_irqs(omap_set_intr_noedge, s, nbanks * 32);
|
642 | 827df9f3 | balrog | if (pins)
|
643 | 827df9f3 | balrog | *pins = s->pins; |
644 | 827df9f3 | balrog | |
645 | 827df9f3 | balrog | omap_inth_reset(s); |
646 | 827df9f3 | balrog | |
647 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap2_inth_readfn, |
648 | 827df9f3 | balrog | omap2_inth_writefn, s); |
649 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, size, iomemtype); |
650 | 827df9f3 | balrog | |
651 | 827df9f3 | balrog | return s;
|
652 | 827df9f3 | balrog | } |
653 | 827df9f3 | balrog | |
654 | c3d2689d | balrog | /* MPU OS timers */
|
655 | c3d2689d | balrog | struct omap_mpu_timer_s {
|
656 | c3d2689d | balrog | qemu_irq irq; |
657 | c3d2689d | balrog | omap_clk clk; |
658 | c3d2689d | balrog | uint32_t val; |
659 | c3d2689d | balrog | int64_t time; |
660 | c3d2689d | balrog | QEMUTimer *timer; |
661 | e856f2ad | balrog | QEMUBH *tick; |
662 | c3d2689d | balrog | int64_t rate; |
663 | c3d2689d | balrog | int it_ena;
|
664 | c3d2689d | balrog | |
665 | c3d2689d | balrog | int enable;
|
666 | c3d2689d | balrog | int ptv;
|
667 | c3d2689d | balrog | int ar;
|
668 | c3d2689d | balrog | int st;
|
669 | c3d2689d | balrog | uint32_t reset_val; |
670 | c3d2689d | balrog | }; |
671 | c3d2689d | balrog | |
672 | c3d2689d | balrog | static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer) |
673 | c3d2689d | balrog | { |
674 | c3d2689d | balrog | uint64_t distance = qemu_get_clock(vm_clock) - timer->time; |
675 | c3d2689d | balrog | |
676 | c3d2689d | balrog | if (timer->st && timer->enable && timer->rate)
|
677 | c3d2689d | balrog | return timer->val - muldiv64(distance >> (timer->ptv + 1), |
678 | 6ee093c9 | Juan Quintela | timer->rate, get_ticks_per_sec()); |
679 | c3d2689d | balrog | else
|
680 | c3d2689d | balrog | return timer->val;
|
681 | c3d2689d | balrog | } |
682 | c3d2689d | balrog | |
683 | c3d2689d | balrog | static inline void omap_timer_sync(struct omap_mpu_timer_s *timer) |
684 | c3d2689d | balrog | { |
685 | c3d2689d | balrog | timer->val = omap_timer_read(timer); |
686 | c3d2689d | balrog | timer->time = qemu_get_clock(vm_clock); |
687 | c3d2689d | balrog | } |
688 | c3d2689d | balrog | |
689 | c3d2689d | balrog | static inline void omap_timer_update(struct omap_mpu_timer_s *timer) |
690 | c3d2689d | balrog | { |
691 | c3d2689d | balrog | int64_t expires; |
692 | c3d2689d | balrog | |
693 | c3d2689d | balrog | if (timer->enable && timer->st && timer->rate) {
|
694 | c3d2689d | balrog | timer->val = timer->reset_val; /* Should skip this on clk enable */
|
695 | b8b137d6 | balrog | expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
|
696 | 6ee093c9 | Juan Quintela | get_ticks_per_sec(), timer->rate); |
697 | b854bc19 | balrog | |
698 | b854bc19 | balrog | /* If timer expiry would be sooner than in about 1 ms and
|
699 | b854bc19 | balrog | * auto-reload isn't set, then fire immediately. This is a hack
|
700 | b854bc19 | balrog | * to make systems like PalmOS run in acceptable time. PalmOS
|
701 | b854bc19 | balrog | * sets the interval to a very low value and polls the status bit
|
702 | b854bc19 | balrog | * in a busy loop when it wants to sleep just a couple of CPU
|
703 | b854bc19 | balrog | * ticks. */
|
704 | 6ee093c9 | Juan Quintela | if (expires > (get_ticks_per_sec() >> 10) || timer->ar) |
705 | b854bc19 | balrog | qemu_mod_timer(timer->timer, timer->time + expires); |
706 | e856f2ad | balrog | else
|
707 | e856f2ad | balrog | qemu_bh_schedule(timer->tick); |
708 | c3d2689d | balrog | } else
|
709 | c3d2689d | balrog | qemu_del_timer(timer->timer); |
710 | c3d2689d | balrog | } |
711 | c3d2689d | balrog | |
712 | e856f2ad | balrog | static void omap_timer_fire(void *opaque) |
713 | c3d2689d | balrog | { |
714 | e856f2ad | balrog | struct omap_mpu_timer_s *timer = opaque;
|
715 | c3d2689d | balrog | |
716 | c3d2689d | balrog | if (!timer->ar) {
|
717 | c3d2689d | balrog | timer->val = 0;
|
718 | c3d2689d | balrog | timer->st = 0;
|
719 | c3d2689d | balrog | } |
720 | c3d2689d | balrog | |
721 | c3d2689d | balrog | if (timer->it_ena)
|
722 | 106627d0 | balrog | /* Edge-triggered irq */
|
723 | 106627d0 | balrog | qemu_irq_pulse(timer->irq); |
724 | e856f2ad | balrog | } |
725 | e856f2ad | balrog | |
726 | e856f2ad | balrog | static void omap_timer_tick(void *opaque) |
727 | e856f2ad | balrog | { |
728 | e856f2ad | balrog | struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque; |
729 | e856f2ad | balrog | |
730 | e856f2ad | balrog | omap_timer_sync(timer); |
731 | e856f2ad | balrog | omap_timer_fire(timer); |
732 | c3d2689d | balrog | omap_timer_update(timer); |
733 | c3d2689d | balrog | } |
734 | c3d2689d | balrog | |
735 | c3d2689d | balrog | static void omap_timer_clk_update(void *opaque, int line, int on) |
736 | c3d2689d | balrog | { |
737 | c3d2689d | balrog | struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque; |
738 | c3d2689d | balrog | |
739 | c3d2689d | balrog | omap_timer_sync(timer); |
740 | c3d2689d | balrog | timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
|
741 | c3d2689d | balrog | omap_timer_update(timer); |
742 | c3d2689d | balrog | } |
743 | c3d2689d | balrog | |
744 | c3d2689d | balrog | static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer) |
745 | c3d2689d | balrog | { |
746 | c3d2689d | balrog | omap_clk_adduser(timer->clk, |
747 | c3d2689d | balrog | qemu_allocate_irqs(omap_timer_clk_update, timer, 1)[0]); |
748 | c3d2689d | balrog | timer->rate = omap_clk_getrate(timer->clk); |
749 | c3d2689d | balrog | } |
750 | c3d2689d | balrog | |
751 | c227f099 | Anthony Liguori | static uint32_t omap_mpu_timer_read(void *opaque, target_phys_addr_t addr) |
752 | c3d2689d | balrog | { |
753 | c3d2689d | balrog | struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque; |
754 | c3d2689d | balrog | |
755 | 8da3ff18 | pbrook | switch (addr) {
|
756 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
757 | c3d2689d | balrog | return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st; |
758 | c3d2689d | balrog | |
759 | c3d2689d | balrog | case 0x04: /* LOAD_TIM */ |
760 | c3d2689d | balrog | break;
|
761 | c3d2689d | balrog | |
762 | c3d2689d | balrog | case 0x08: /* READ_TIM */ |
763 | c3d2689d | balrog | return omap_timer_read(s);
|
764 | c3d2689d | balrog | } |
765 | c3d2689d | balrog | |
766 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
767 | c3d2689d | balrog | return 0; |
768 | c3d2689d | balrog | } |
769 | c3d2689d | balrog | |
770 | c227f099 | Anthony Liguori | static void omap_mpu_timer_write(void *opaque, target_phys_addr_t addr, |
771 | c3d2689d | balrog | uint32_t value) |
772 | c3d2689d | balrog | { |
773 | c3d2689d | balrog | struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque; |
774 | c3d2689d | balrog | |
775 | 8da3ff18 | pbrook | switch (addr) {
|
776 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
777 | c3d2689d | balrog | omap_timer_sync(s); |
778 | c3d2689d | balrog | s->enable = (value >> 5) & 1; |
779 | c3d2689d | balrog | s->ptv = (value >> 2) & 7; |
780 | c3d2689d | balrog | s->ar = (value >> 1) & 1; |
781 | c3d2689d | balrog | s->st = value & 1;
|
782 | c3d2689d | balrog | omap_timer_update(s); |
783 | c3d2689d | balrog | return;
|
784 | c3d2689d | balrog | |
785 | c3d2689d | balrog | case 0x04: /* LOAD_TIM */ |
786 | c3d2689d | balrog | s->reset_val = value; |
787 | c3d2689d | balrog | return;
|
788 | c3d2689d | balrog | |
789 | c3d2689d | balrog | case 0x08: /* READ_TIM */ |
790 | c3d2689d | balrog | OMAP_RO_REG(addr); |
791 | c3d2689d | balrog | break;
|
792 | c3d2689d | balrog | |
793 | c3d2689d | balrog | default:
|
794 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
795 | c3d2689d | balrog | } |
796 | c3d2689d | balrog | } |
797 | c3d2689d | balrog | |
798 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_mpu_timer_readfn[] = { |
799 | c3d2689d | balrog | omap_badwidth_read32, |
800 | c3d2689d | balrog | omap_badwidth_read32, |
801 | c3d2689d | balrog | omap_mpu_timer_read, |
802 | c3d2689d | balrog | }; |
803 | c3d2689d | balrog | |
804 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_mpu_timer_writefn[] = { |
805 | c3d2689d | balrog | omap_badwidth_write32, |
806 | c3d2689d | balrog | omap_badwidth_write32, |
807 | c3d2689d | balrog | omap_mpu_timer_write, |
808 | c3d2689d | balrog | }; |
809 | c3d2689d | balrog | |
810 | c3d2689d | balrog | static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s) |
811 | c3d2689d | balrog | { |
812 | c3d2689d | balrog | qemu_del_timer(s->timer); |
813 | c3d2689d | balrog | s->enable = 0;
|
814 | c3d2689d | balrog | s->reset_val = 31337;
|
815 | c3d2689d | balrog | s->val = 0;
|
816 | c3d2689d | balrog | s->ptv = 0;
|
817 | c3d2689d | balrog | s->ar = 0;
|
818 | c3d2689d | balrog | s->st = 0;
|
819 | c3d2689d | balrog | s->it_ena = 1;
|
820 | c3d2689d | balrog | } |
821 | c3d2689d | balrog | |
822 | c227f099 | Anthony Liguori | struct omap_mpu_timer_s *omap_mpu_timer_init(target_phys_addr_t base,
|
823 | c3d2689d | balrog | qemu_irq irq, omap_clk clk) |
824 | c3d2689d | balrog | { |
825 | c3d2689d | balrog | int iomemtype;
|
826 | c3d2689d | balrog | struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) |
827 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_mpu_timer_s)); |
828 | c3d2689d | balrog | |
829 | c3d2689d | balrog | s->irq = irq; |
830 | c3d2689d | balrog | s->clk = clk; |
831 | c3d2689d | balrog | s->timer = qemu_new_timer(vm_clock, omap_timer_tick, s); |
832 | e856f2ad | balrog | s->tick = qemu_bh_new(omap_timer_fire, s); |
833 | c3d2689d | balrog | omap_mpu_timer_reset(s); |
834 | c3d2689d | balrog | omap_timer_clk_setup(s); |
835 | c3d2689d | balrog | |
836 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_mpu_timer_readfn, |
837 | c3d2689d | balrog | omap_mpu_timer_writefn, s); |
838 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100, iomemtype);
|
839 | c3d2689d | balrog | |
840 | c3d2689d | balrog | return s;
|
841 | c3d2689d | balrog | } |
842 | c3d2689d | balrog | |
843 | c3d2689d | balrog | /* Watchdog timer */
|
844 | c3d2689d | balrog | struct omap_watchdog_timer_s {
|
845 | c3d2689d | balrog | struct omap_mpu_timer_s timer;
|
846 | c3d2689d | balrog | uint8_t last_wr; |
847 | c3d2689d | balrog | int mode;
|
848 | c3d2689d | balrog | int free;
|
849 | c3d2689d | balrog | int reset;
|
850 | c3d2689d | balrog | }; |
851 | c3d2689d | balrog | |
852 | c227f099 | Anthony Liguori | static uint32_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr) |
853 | c3d2689d | balrog | { |
854 | c3d2689d | balrog | struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque; |
855 | c3d2689d | balrog | |
856 | 8da3ff18 | pbrook | switch (addr) {
|
857 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
858 | c3d2689d | balrog | return (s->timer.ptv << 9) | (s->timer.ar << 8) | |
859 | c3d2689d | balrog | (s->timer.st << 7) | (s->free << 1); |
860 | c3d2689d | balrog | |
861 | c3d2689d | balrog | case 0x04: /* READ_TIMER */ |
862 | c3d2689d | balrog | return omap_timer_read(&s->timer);
|
863 | c3d2689d | balrog | |
864 | c3d2689d | balrog | case 0x08: /* TIMER_MODE */ |
865 | c3d2689d | balrog | return s->mode << 15; |
866 | c3d2689d | balrog | } |
867 | c3d2689d | balrog | |
868 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
869 | c3d2689d | balrog | return 0; |
870 | c3d2689d | balrog | } |
871 | c3d2689d | balrog | |
872 | c227f099 | Anthony Liguori | static void omap_wd_timer_write(void *opaque, target_phys_addr_t addr, |
873 | c3d2689d | balrog | uint32_t value) |
874 | c3d2689d | balrog | { |
875 | c3d2689d | balrog | struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque; |
876 | c3d2689d | balrog | |
877 | 8da3ff18 | pbrook | switch (addr) {
|
878 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
879 | c3d2689d | balrog | omap_timer_sync(&s->timer); |
880 | c3d2689d | balrog | s->timer.ptv = (value >> 9) & 7; |
881 | c3d2689d | balrog | s->timer.ar = (value >> 8) & 1; |
882 | c3d2689d | balrog | s->timer.st = (value >> 7) & 1; |
883 | c3d2689d | balrog | s->free = (value >> 1) & 1; |
884 | c3d2689d | balrog | omap_timer_update(&s->timer); |
885 | c3d2689d | balrog | break;
|
886 | c3d2689d | balrog | |
887 | c3d2689d | balrog | case 0x04: /* LOAD_TIMER */ |
888 | c3d2689d | balrog | s->timer.reset_val = value & 0xffff;
|
889 | c3d2689d | balrog | break;
|
890 | c3d2689d | balrog | |
891 | c3d2689d | balrog | case 0x08: /* TIMER_MODE */ |
892 | c3d2689d | balrog | if (!s->mode && ((value >> 15) & 1)) |
893 | c3d2689d | balrog | omap_clk_get(s->timer.clk); |
894 | c3d2689d | balrog | s->mode |= (value >> 15) & 1; |
895 | c3d2689d | balrog | if (s->last_wr == 0xf5) { |
896 | c3d2689d | balrog | if ((value & 0xff) == 0xa0) { |
897 | d8f699cb | balrog | if (s->mode) {
|
898 | d8f699cb | balrog | s->mode = 0;
|
899 | d8f699cb | balrog | omap_clk_put(s->timer.clk); |
900 | d8f699cb | balrog | } |
901 | c3d2689d | balrog | } else {
|
902 | c3d2689d | balrog | /* XXX: on T|E hardware somehow this has no effect,
|
903 | c3d2689d | balrog | * on Zire 71 it works as specified. */
|
904 | c3d2689d | balrog | s->reset = 1;
|
905 | c3d2689d | balrog | qemu_system_reset_request(); |
906 | c3d2689d | balrog | } |
907 | c3d2689d | balrog | } |
908 | c3d2689d | balrog | s->last_wr = value & 0xff;
|
909 | c3d2689d | balrog | break;
|
910 | c3d2689d | balrog | |
911 | c3d2689d | balrog | default:
|
912 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
913 | c3d2689d | balrog | } |
914 | c3d2689d | balrog | } |
915 | c3d2689d | balrog | |
916 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_wd_timer_readfn[] = { |
917 | c3d2689d | balrog | omap_badwidth_read16, |
918 | c3d2689d | balrog | omap_wd_timer_read, |
919 | c3d2689d | balrog | omap_badwidth_read16, |
920 | c3d2689d | balrog | }; |
921 | c3d2689d | balrog | |
922 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_wd_timer_writefn[] = { |
923 | c3d2689d | balrog | omap_badwidth_write16, |
924 | c3d2689d | balrog | omap_wd_timer_write, |
925 | c3d2689d | balrog | omap_badwidth_write16, |
926 | c3d2689d | balrog | }; |
927 | c3d2689d | balrog | |
928 | c3d2689d | balrog | static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s) |
929 | c3d2689d | balrog | { |
930 | c3d2689d | balrog | qemu_del_timer(s->timer.timer); |
931 | c3d2689d | balrog | if (!s->mode)
|
932 | c3d2689d | balrog | omap_clk_get(s->timer.clk); |
933 | c3d2689d | balrog | s->mode = 1;
|
934 | c3d2689d | balrog | s->free = 1;
|
935 | c3d2689d | balrog | s->reset = 0;
|
936 | c3d2689d | balrog | s->timer.enable = 1;
|
937 | c3d2689d | balrog | s->timer.it_ena = 1;
|
938 | c3d2689d | balrog | s->timer.reset_val = 0xffff;
|
939 | c3d2689d | balrog | s->timer.val = 0;
|
940 | c3d2689d | balrog | s->timer.st = 0;
|
941 | c3d2689d | balrog | s->timer.ptv = 0;
|
942 | c3d2689d | balrog | s->timer.ar = 0;
|
943 | c3d2689d | balrog | omap_timer_update(&s->timer); |
944 | c3d2689d | balrog | } |
945 | c3d2689d | balrog | |
946 | c227f099 | Anthony Liguori | struct omap_watchdog_timer_s *omap_wd_timer_init(target_phys_addr_t base,
|
947 | c3d2689d | balrog | qemu_irq irq, omap_clk clk) |
948 | c3d2689d | balrog | { |
949 | c3d2689d | balrog | int iomemtype;
|
950 | c3d2689d | balrog | struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) |
951 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_watchdog_timer_s)); |
952 | c3d2689d | balrog | |
953 | c3d2689d | balrog | s->timer.irq = irq; |
954 | c3d2689d | balrog | s->timer.clk = clk; |
955 | c3d2689d | balrog | s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer); |
956 | c3d2689d | balrog | omap_wd_timer_reset(s); |
957 | c3d2689d | balrog | omap_timer_clk_setup(&s->timer); |
958 | c3d2689d | balrog | |
959 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_wd_timer_readfn, |
960 | c3d2689d | balrog | omap_wd_timer_writefn, s); |
961 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100, iomemtype);
|
962 | c3d2689d | balrog | |
963 | c3d2689d | balrog | return s;
|
964 | c3d2689d | balrog | } |
965 | c3d2689d | balrog | |
966 | c3d2689d | balrog | /* 32-kHz timer */
|
967 | c3d2689d | balrog | struct omap_32khz_timer_s {
|
968 | c3d2689d | balrog | struct omap_mpu_timer_s timer;
|
969 | c3d2689d | balrog | }; |
970 | c3d2689d | balrog | |
971 | c227f099 | Anthony Liguori | static uint32_t omap_os_timer_read(void *opaque, target_phys_addr_t addr) |
972 | c3d2689d | balrog | { |
973 | c3d2689d | balrog | struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque; |
974 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
975 | c3d2689d | balrog | |
976 | c3d2689d | balrog | switch (offset) {
|
977 | c3d2689d | balrog | case 0x00: /* TVR */ |
978 | c3d2689d | balrog | return s->timer.reset_val;
|
979 | c3d2689d | balrog | |
980 | c3d2689d | balrog | case 0x04: /* TCR */ |
981 | c3d2689d | balrog | return omap_timer_read(&s->timer);
|
982 | c3d2689d | balrog | |
983 | c3d2689d | balrog | case 0x08: /* CR */ |
984 | c3d2689d | balrog | return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st; |
985 | c3d2689d | balrog | |
986 | c3d2689d | balrog | default:
|
987 | c3d2689d | balrog | break;
|
988 | c3d2689d | balrog | } |
989 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
990 | c3d2689d | balrog | return 0; |
991 | c3d2689d | balrog | } |
992 | c3d2689d | balrog | |
993 | c227f099 | Anthony Liguori | static void omap_os_timer_write(void *opaque, target_phys_addr_t addr, |
994 | c3d2689d | balrog | uint32_t value) |
995 | c3d2689d | balrog | { |
996 | c3d2689d | balrog | struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque; |
997 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
998 | c3d2689d | balrog | |
999 | c3d2689d | balrog | switch (offset) {
|
1000 | c3d2689d | balrog | case 0x00: /* TVR */ |
1001 | c3d2689d | balrog | s->timer.reset_val = value & 0x00ffffff;
|
1002 | c3d2689d | balrog | break;
|
1003 | c3d2689d | balrog | |
1004 | c3d2689d | balrog | case 0x04: /* TCR */ |
1005 | c3d2689d | balrog | OMAP_RO_REG(addr); |
1006 | c3d2689d | balrog | break;
|
1007 | c3d2689d | balrog | |
1008 | c3d2689d | balrog | case 0x08: /* CR */ |
1009 | c3d2689d | balrog | s->timer.ar = (value >> 3) & 1; |
1010 | c3d2689d | balrog | s->timer.it_ena = (value >> 2) & 1; |
1011 | c3d2689d | balrog | if (s->timer.st != (value & 1) || (value & 2)) { |
1012 | c3d2689d | balrog | omap_timer_sync(&s->timer); |
1013 | c3d2689d | balrog | s->timer.enable = value & 1;
|
1014 | c3d2689d | balrog | s->timer.st = value & 1;
|
1015 | c3d2689d | balrog | omap_timer_update(&s->timer); |
1016 | c3d2689d | balrog | } |
1017 | c3d2689d | balrog | break;
|
1018 | c3d2689d | balrog | |
1019 | c3d2689d | balrog | default:
|
1020 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1021 | c3d2689d | balrog | } |
1022 | c3d2689d | balrog | } |
1023 | c3d2689d | balrog | |
1024 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_os_timer_readfn[] = { |
1025 | c3d2689d | balrog | omap_badwidth_read32, |
1026 | c3d2689d | balrog | omap_badwidth_read32, |
1027 | c3d2689d | balrog | omap_os_timer_read, |
1028 | c3d2689d | balrog | }; |
1029 | c3d2689d | balrog | |
1030 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_os_timer_writefn[] = { |
1031 | c3d2689d | balrog | omap_badwidth_write32, |
1032 | c3d2689d | balrog | omap_badwidth_write32, |
1033 | c3d2689d | balrog | omap_os_timer_write, |
1034 | c3d2689d | balrog | }; |
1035 | c3d2689d | balrog | |
1036 | c3d2689d | balrog | static void omap_os_timer_reset(struct omap_32khz_timer_s *s) |
1037 | c3d2689d | balrog | { |
1038 | c3d2689d | balrog | qemu_del_timer(s->timer.timer); |
1039 | c3d2689d | balrog | s->timer.enable = 0;
|
1040 | c3d2689d | balrog | s->timer.it_ena = 0;
|
1041 | c3d2689d | balrog | s->timer.reset_val = 0x00ffffff;
|
1042 | c3d2689d | balrog | s->timer.val = 0;
|
1043 | c3d2689d | balrog | s->timer.st = 0;
|
1044 | c3d2689d | balrog | s->timer.ptv = 0;
|
1045 | c3d2689d | balrog | s->timer.ar = 1;
|
1046 | c3d2689d | balrog | } |
1047 | c3d2689d | balrog | |
1048 | c227f099 | Anthony Liguori | struct omap_32khz_timer_s *omap_os_timer_init(target_phys_addr_t base,
|
1049 | c3d2689d | balrog | qemu_irq irq, omap_clk clk) |
1050 | c3d2689d | balrog | { |
1051 | c3d2689d | balrog | int iomemtype;
|
1052 | c3d2689d | balrog | struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) |
1053 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_32khz_timer_s)); |
1054 | c3d2689d | balrog | |
1055 | c3d2689d | balrog | s->timer.irq = irq; |
1056 | c3d2689d | balrog | s->timer.clk = clk; |
1057 | c3d2689d | balrog | s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer); |
1058 | c3d2689d | balrog | omap_os_timer_reset(s); |
1059 | c3d2689d | balrog | omap_timer_clk_setup(&s->timer); |
1060 | c3d2689d | balrog | |
1061 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_os_timer_readfn, |
1062 | c3d2689d | balrog | omap_os_timer_writefn, s); |
1063 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
1064 | c3d2689d | balrog | |
1065 | c3d2689d | balrog | return s;
|
1066 | c3d2689d | balrog | } |
1067 | c3d2689d | balrog | |
1068 | c3d2689d | balrog | /* Ultra Low-Power Device Module */
|
1069 | c227f099 | Anthony Liguori | static uint32_t omap_ulpd_pm_read(void *opaque, target_phys_addr_t addr) |
1070 | c3d2689d | balrog | { |
1071 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1072 | c3d2689d | balrog | uint16_t ret; |
1073 | c3d2689d | balrog | |
1074 | 8da3ff18 | pbrook | switch (addr) {
|
1075 | c3d2689d | balrog | case 0x14: /* IT_STATUS */ |
1076 | 8da3ff18 | pbrook | ret = s->ulpd_pm_regs[addr >> 2];
|
1077 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] = 0; |
1078 | c3d2689d | balrog | qemu_irq_lower(s->irq[1][OMAP_INT_GAUGE_32K]);
|
1079 | c3d2689d | balrog | return ret;
|
1080 | c3d2689d | balrog | |
1081 | c3d2689d | balrog | case 0x18: /* Reserved */ |
1082 | c3d2689d | balrog | case 0x1c: /* Reserved */ |
1083 | c3d2689d | balrog | case 0x20: /* Reserved */ |
1084 | c3d2689d | balrog | case 0x28: /* Reserved */ |
1085 | c3d2689d | balrog | case 0x2c: /* Reserved */ |
1086 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1087 | c3d2689d | balrog | case 0x00: /* COUNTER_32_LSB */ |
1088 | c3d2689d | balrog | case 0x04: /* COUNTER_32_MSB */ |
1089 | c3d2689d | balrog | case 0x08: /* COUNTER_HIGH_FREQ_LSB */ |
1090 | c3d2689d | balrog | case 0x0c: /* COUNTER_HIGH_FREQ_MSB */ |
1091 | c3d2689d | balrog | case 0x10: /* GAUGING_CTRL */ |
1092 | c3d2689d | balrog | case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */ |
1093 | c3d2689d | balrog | case 0x30: /* CLOCK_CTRL */ |
1094 | c3d2689d | balrog | case 0x34: /* SOFT_REQ */ |
1095 | c3d2689d | balrog | case 0x38: /* COUNTER_32_FIQ */ |
1096 | c3d2689d | balrog | case 0x3c: /* DPLL_CTRL */ |
1097 | c3d2689d | balrog | case 0x40: /* STATUS_REQ */ |
1098 | c3d2689d | balrog | /* XXX: check clk::usecount state for every clock */
|
1099 | c3d2689d | balrog | case 0x48: /* LOCL_TIME */ |
1100 | c3d2689d | balrog | case 0x4c: /* APLL_CTRL */ |
1101 | c3d2689d | balrog | case 0x50: /* POWER_CTRL */ |
1102 | 8da3ff18 | pbrook | return s->ulpd_pm_regs[addr >> 2]; |
1103 | c3d2689d | balrog | } |
1104 | c3d2689d | balrog | |
1105 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1106 | c3d2689d | balrog | return 0; |
1107 | c3d2689d | balrog | } |
1108 | c3d2689d | balrog | |
1109 | c3d2689d | balrog | static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s, |
1110 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
1111 | c3d2689d | balrog | { |
1112 | c3d2689d | balrog | if (diff & (1 << 4)) /* USB_MCLK_EN */ |
1113 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1); |
1114 | c3d2689d | balrog | if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */ |
1115 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1); |
1116 | c3d2689d | balrog | } |
1117 | c3d2689d | balrog | |
1118 | c3d2689d | balrog | static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s, |
1119 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
1120 | c3d2689d | balrog | { |
1121 | c3d2689d | balrog | if (diff & (1 << 0)) /* SOFT_DPLL_REQ */ |
1122 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1); |
1123 | c3d2689d | balrog | if (diff & (1 << 1)) /* SOFT_COM_REQ */ |
1124 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1); |
1125 | c3d2689d | balrog | if (diff & (1 << 2)) /* SOFT_SDW_REQ */ |
1126 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1); |
1127 | c3d2689d | balrog | if (diff & (1 << 3)) /* SOFT_USB_REQ */ |
1128 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1); |
1129 | c3d2689d | balrog | } |
1130 | c3d2689d | balrog | |
1131 | c227f099 | Anthony Liguori | static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr, |
1132 | c3d2689d | balrog | uint32_t value) |
1133 | c3d2689d | balrog | { |
1134 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1135 | c3d2689d | balrog | int64_t now, ticks; |
1136 | c3d2689d | balrog | int div, mult;
|
1137 | c3d2689d | balrog | static const int bypass_div[4] = { 1, 2, 4, 4 }; |
1138 | c3d2689d | balrog | uint16_t diff; |
1139 | c3d2689d | balrog | |
1140 | 8da3ff18 | pbrook | switch (addr) {
|
1141 | c3d2689d | balrog | case 0x00: /* COUNTER_32_LSB */ |
1142 | c3d2689d | balrog | case 0x04: /* COUNTER_32_MSB */ |
1143 | c3d2689d | balrog | case 0x08: /* COUNTER_HIGH_FREQ_LSB */ |
1144 | c3d2689d | balrog | case 0x0c: /* COUNTER_HIGH_FREQ_MSB */ |
1145 | c3d2689d | balrog | case 0x14: /* IT_STATUS */ |
1146 | c3d2689d | balrog | case 0x40: /* STATUS_REQ */ |
1147 | c3d2689d | balrog | OMAP_RO_REG(addr); |
1148 | c3d2689d | balrog | break;
|
1149 | c3d2689d | balrog | |
1150 | c3d2689d | balrog | case 0x10: /* GAUGING_CTRL */ |
1151 | c3d2689d | balrog | /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
|
1152 | 8da3ff18 | pbrook | if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) { |
1153 | c3d2689d | balrog | now = qemu_get_clock(vm_clock); |
1154 | c3d2689d | balrog | |
1155 | c3d2689d | balrog | if (value & 1) |
1156 | c3d2689d | balrog | s->ulpd_gauge_start = now; |
1157 | c3d2689d | balrog | else {
|
1158 | c3d2689d | balrog | now -= s->ulpd_gauge_start; |
1159 | c3d2689d | balrog | |
1160 | c3d2689d | balrog | /* 32-kHz ticks */
|
1161 | 6ee093c9 | Juan Quintela | ticks = muldiv64(now, 32768, get_ticks_per_sec());
|
1162 | c3d2689d | balrog | s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff; |
1163 | c3d2689d | balrog | s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff; |
1164 | c3d2689d | balrog | if (ticks >> 32) /* OVERFLOW_32K */ |
1165 | c3d2689d | balrog | s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2; |
1166 | c3d2689d | balrog | |
1167 | c3d2689d | balrog | /* High frequency ticks */
|
1168 | 6ee093c9 | Juan Quintela | ticks = muldiv64(now, 12000000, get_ticks_per_sec());
|
1169 | c3d2689d | balrog | s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff; |
1170 | c3d2689d | balrog | s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff; |
1171 | c3d2689d | balrog | if (ticks >> 32) /* OVERFLOW_HI_FREQ */ |
1172 | c3d2689d | balrog | s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1; |
1173 | c3d2689d | balrog | |
1174 | c3d2689d | balrog | s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */ |
1175 | c3d2689d | balrog | qemu_irq_raise(s->irq[1][OMAP_INT_GAUGE_32K]);
|
1176 | c3d2689d | balrog | } |
1177 | c3d2689d | balrog | } |
1178 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] = value;
|
1179 | c3d2689d | balrog | break;
|
1180 | c3d2689d | balrog | |
1181 | c3d2689d | balrog | case 0x18: /* Reserved */ |
1182 | c3d2689d | balrog | case 0x1c: /* Reserved */ |
1183 | c3d2689d | balrog | case 0x20: /* Reserved */ |
1184 | c3d2689d | balrog | case 0x28: /* Reserved */ |
1185 | c3d2689d | balrog | case 0x2c: /* Reserved */ |
1186 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1187 | c3d2689d | balrog | case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */ |
1188 | c3d2689d | balrog | case 0x38: /* COUNTER_32_FIQ */ |
1189 | c3d2689d | balrog | case 0x48: /* LOCL_TIME */ |
1190 | c3d2689d | balrog | case 0x50: /* POWER_CTRL */ |
1191 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] = value;
|
1192 | c3d2689d | balrog | break;
|
1193 | c3d2689d | balrog | |
1194 | c3d2689d | balrog | case 0x30: /* CLOCK_CTRL */ |
1195 | 8da3ff18 | pbrook | diff = s->ulpd_pm_regs[addr >> 2] ^ value;
|
1196 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] = value & 0x3f; |
1197 | c3d2689d | balrog | omap_ulpd_clk_update(s, diff, value); |
1198 | c3d2689d | balrog | break;
|
1199 | c3d2689d | balrog | |
1200 | c3d2689d | balrog | case 0x34: /* SOFT_REQ */ |
1201 | 8da3ff18 | pbrook | diff = s->ulpd_pm_regs[addr >> 2] ^ value;
|
1202 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] = value & 0x1f; |
1203 | c3d2689d | balrog | omap_ulpd_req_update(s, diff, value); |
1204 | c3d2689d | balrog | break;
|
1205 | c3d2689d | balrog | |
1206 | c3d2689d | balrog | case 0x3c: /* DPLL_CTRL */ |
1207 | c3d2689d | balrog | /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
|
1208 | c3d2689d | balrog | * omitted altogether, probably a typo. */
|
1209 | c3d2689d | balrog | /* This register has identical semantics with DPLL(1:3) control
|
1210 | c3d2689d | balrog | * registers, see omap_dpll_write() */
|
1211 | 8da3ff18 | pbrook | diff = s->ulpd_pm_regs[addr >> 2] & value;
|
1212 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] = value & 0x2fff; |
1213 | c3d2689d | balrog | if (diff & (0x3ff << 2)) { |
1214 | c3d2689d | balrog | if (value & (1 << 4)) { /* PLL_ENABLE */ |
1215 | c3d2689d | balrog | div = ((value >> 5) & 3) + 1; /* PLL_DIV */ |
1216 | c3d2689d | balrog | mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */ |
1217 | c3d2689d | balrog | } else {
|
1218 | c3d2689d | balrog | div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */ |
1219 | c3d2689d | balrog | mult = 1;
|
1220 | c3d2689d | balrog | } |
1221 | c3d2689d | balrog | omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
|
1222 | c3d2689d | balrog | } |
1223 | c3d2689d | balrog | |
1224 | c3d2689d | balrog | /* Enter the desired mode. */
|
1225 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] =
|
1226 | 8da3ff18 | pbrook | (s->ulpd_pm_regs[addr >> 2] & 0xfffe) | |
1227 | 8da3ff18 | pbrook | ((s->ulpd_pm_regs[addr >> 2] >> 4) & 1); |
1228 | c3d2689d | balrog | |
1229 | c3d2689d | balrog | /* Act as if the lock is restored. */
|
1230 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] |= 2; |
1231 | c3d2689d | balrog | break;
|
1232 | c3d2689d | balrog | |
1233 | c3d2689d | balrog | case 0x4c: /* APLL_CTRL */ |
1234 | 8da3ff18 | pbrook | diff = s->ulpd_pm_regs[addr >> 2] & value;
|
1235 | 8da3ff18 | pbrook | s->ulpd_pm_regs[addr >> 2] = value & 0xf; |
1236 | c3d2689d | balrog | if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */ |
1237 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
|
1238 | c3d2689d | balrog | (value & (1 << 0)) ? "apll" : "dpll4")); |
1239 | c3d2689d | balrog | break;
|
1240 | c3d2689d | balrog | |
1241 | c3d2689d | balrog | default:
|
1242 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1243 | c3d2689d | balrog | } |
1244 | c3d2689d | balrog | } |
1245 | c3d2689d | balrog | |
1246 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_ulpd_pm_readfn[] = { |
1247 | c3d2689d | balrog | omap_badwidth_read16, |
1248 | c3d2689d | balrog | omap_ulpd_pm_read, |
1249 | c3d2689d | balrog | omap_badwidth_read16, |
1250 | c3d2689d | balrog | }; |
1251 | c3d2689d | balrog | |
1252 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_ulpd_pm_writefn[] = { |
1253 | c3d2689d | balrog | omap_badwidth_write16, |
1254 | c3d2689d | balrog | omap_ulpd_pm_write, |
1255 | c3d2689d | balrog | omap_badwidth_write16, |
1256 | c3d2689d | balrog | }; |
1257 | c3d2689d | balrog | |
1258 | c3d2689d | balrog | static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu) |
1259 | c3d2689d | balrog | { |
1260 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001; |
1261 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000; |
1262 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001; |
1263 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000; |
1264 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000; |
1265 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x18 >> 2] = 0x01; |
1266 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x1c >> 2] = 0x01; |
1267 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x20 >> 2] = 0x01; |
1268 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff; |
1269 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x28 >> 2] = 0x01; |
1270 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x2c >> 2] = 0x01; |
1271 | c3d2689d | balrog | omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000); |
1272 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000; |
1273 | c3d2689d | balrog | omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000); |
1274 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000; |
1275 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001; |
1276 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211; |
1277 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */ |
1278 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x48 >> 2] = 0x960; |
1279 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x4c >> 2] = 0x08; |
1280 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x50 >> 2] = 0x08; |
1281 | c3d2689d | balrog | omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4); |
1282 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4")); |
1283 | c3d2689d | balrog | } |
1284 | c3d2689d | balrog | |
1285 | c227f099 | Anthony Liguori | static void omap_ulpd_pm_init(target_phys_addr_t base, |
1286 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
1287 | c3d2689d | balrog | { |
1288 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_ulpd_pm_readfn,
|
1289 | c3d2689d | balrog | omap_ulpd_pm_writefn, mpu); |
1290 | c3d2689d | balrog | |
1291 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
1292 | c3d2689d | balrog | omap_ulpd_pm_reset(mpu); |
1293 | c3d2689d | balrog | } |
1294 | c3d2689d | balrog | |
1295 | c3d2689d | balrog | /* OMAP Pin Configuration */
|
1296 | c227f099 | Anthony Liguori | static uint32_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr) |
1297 | c3d2689d | balrog | { |
1298 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1299 | c3d2689d | balrog | |
1300 | 8da3ff18 | pbrook | switch (addr) {
|
1301 | c3d2689d | balrog | case 0x00: /* FUNC_MUX_CTRL_0 */ |
1302 | c3d2689d | balrog | case 0x04: /* FUNC_MUX_CTRL_1 */ |
1303 | c3d2689d | balrog | case 0x08: /* FUNC_MUX_CTRL_2 */ |
1304 | 8da3ff18 | pbrook | return s->func_mux_ctrl[addr >> 2]; |
1305 | c3d2689d | balrog | |
1306 | c3d2689d | balrog | case 0x0c: /* COMP_MODE_CTRL_0 */ |
1307 | c3d2689d | balrog | return s->comp_mode_ctrl[0]; |
1308 | c3d2689d | balrog | |
1309 | c3d2689d | balrog | case 0x10: /* FUNC_MUX_CTRL_3 */ |
1310 | c3d2689d | balrog | case 0x14: /* FUNC_MUX_CTRL_4 */ |
1311 | c3d2689d | balrog | case 0x18: /* FUNC_MUX_CTRL_5 */ |
1312 | c3d2689d | balrog | case 0x1c: /* FUNC_MUX_CTRL_6 */ |
1313 | c3d2689d | balrog | case 0x20: /* FUNC_MUX_CTRL_7 */ |
1314 | c3d2689d | balrog | case 0x24: /* FUNC_MUX_CTRL_8 */ |
1315 | c3d2689d | balrog | case 0x28: /* FUNC_MUX_CTRL_9 */ |
1316 | c3d2689d | balrog | case 0x2c: /* FUNC_MUX_CTRL_A */ |
1317 | c3d2689d | balrog | case 0x30: /* FUNC_MUX_CTRL_B */ |
1318 | c3d2689d | balrog | case 0x34: /* FUNC_MUX_CTRL_C */ |
1319 | c3d2689d | balrog | case 0x38: /* FUNC_MUX_CTRL_D */ |
1320 | 8da3ff18 | pbrook | return s->func_mux_ctrl[(addr >> 2) - 1]; |
1321 | c3d2689d | balrog | |
1322 | c3d2689d | balrog | case 0x40: /* PULL_DWN_CTRL_0 */ |
1323 | c3d2689d | balrog | case 0x44: /* PULL_DWN_CTRL_1 */ |
1324 | c3d2689d | balrog | case 0x48: /* PULL_DWN_CTRL_2 */ |
1325 | c3d2689d | balrog | case 0x4c: /* PULL_DWN_CTRL_3 */ |
1326 | 8da3ff18 | pbrook | return s->pull_dwn_ctrl[(addr & 0xf) >> 2]; |
1327 | c3d2689d | balrog | |
1328 | c3d2689d | balrog | case 0x50: /* GATE_INH_CTRL_0 */ |
1329 | c3d2689d | balrog | return s->gate_inh_ctrl[0]; |
1330 | c3d2689d | balrog | |
1331 | c3d2689d | balrog | case 0x60: /* VOLTAGE_CTRL_0 */ |
1332 | c3d2689d | balrog | return s->voltage_ctrl[0]; |
1333 | c3d2689d | balrog | |
1334 | c3d2689d | balrog | case 0x70: /* TEST_DBG_CTRL_0 */ |
1335 | c3d2689d | balrog | return s->test_dbg_ctrl[0]; |
1336 | c3d2689d | balrog | |
1337 | c3d2689d | balrog | case 0x80: /* MOD_CONF_CTRL_0 */ |
1338 | c3d2689d | balrog | return s->mod_conf_ctrl[0]; |
1339 | c3d2689d | balrog | } |
1340 | c3d2689d | balrog | |
1341 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1342 | c3d2689d | balrog | return 0; |
1343 | c3d2689d | balrog | } |
1344 | c3d2689d | balrog | |
1345 | c3d2689d | balrog | static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s, |
1346 | c3d2689d | balrog | uint32_t diff, uint32_t value) |
1347 | c3d2689d | balrog | { |
1348 | c3d2689d | balrog | if (s->compat1509) {
|
1349 | c3d2689d | balrog | if (diff & (1 << 9)) /* BLUETOOTH */ |
1350 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
|
1351 | c3d2689d | balrog | (~value >> 9) & 1); |
1352 | c3d2689d | balrog | if (diff & (1 << 7)) /* USB.CLKO */ |
1353 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb.clko"),
|
1354 | c3d2689d | balrog | (value >> 7) & 1); |
1355 | c3d2689d | balrog | } |
1356 | c3d2689d | balrog | } |
1357 | c3d2689d | balrog | |
1358 | c3d2689d | balrog | static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s, |
1359 | c3d2689d | balrog | uint32_t diff, uint32_t value) |
1360 | c3d2689d | balrog | { |
1361 | c3d2689d | balrog | if (s->compat1509) {
|
1362 | c3d2689d | balrog | if (diff & (1 << 31)) /* MCBSP3_CLK_HIZ_DI */ |
1363 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"),
|
1364 | c3d2689d | balrog | (value >> 31) & 1); |
1365 | c3d2689d | balrog | if (diff & (1 << 1)) /* CLK32K */ |
1366 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "clk32k_out"),
|
1367 | c3d2689d | balrog | (~value >> 1) & 1); |
1368 | c3d2689d | balrog | } |
1369 | c3d2689d | balrog | } |
1370 | c3d2689d | balrog | |
1371 | c3d2689d | balrog | static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s, |
1372 | c3d2689d | balrog | uint32_t diff, uint32_t value) |
1373 | c3d2689d | balrog | { |
1374 | c3d2689d | balrog | if (diff & (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */ |
1375 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "uart3_ck"),
|
1376 | c3d2689d | balrog | omap_findclk(s, ((value >> 31) & 1) ? |
1377 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1378 | c3d2689d | balrog | if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */ |
1379 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "uart2_ck"),
|
1380 | c3d2689d | balrog | omap_findclk(s, ((value >> 30) & 1) ? |
1381 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1382 | c3d2689d | balrog | if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */ |
1383 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "uart1_ck"),
|
1384 | c3d2689d | balrog | omap_findclk(s, ((value >> 29) & 1) ? |
1385 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1386 | c3d2689d | balrog | if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */ |
1387 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "mmc_ck"),
|
1388 | c3d2689d | balrog | omap_findclk(s, ((value >> 23) & 1) ? |
1389 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1390 | c3d2689d | balrog | if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */ |
1391 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
|
1392 | c3d2689d | balrog | omap_findclk(s, ((value >> 12) & 1) ? |
1393 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1394 | c3d2689d | balrog | if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */ |
1395 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1); |
1396 | c3d2689d | balrog | } |
1397 | c3d2689d | balrog | |
1398 | c227f099 | Anthony Liguori | static void omap_pin_cfg_write(void *opaque, target_phys_addr_t addr, |
1399 | c3d2689d | balrog | uint32_t value) |
1400 | c3d2689d | balrog | { |
1401 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1402 | c3d2689d | balrog | uint32_t diff; |
1403 | c3d2689d | balrog | |
1404 | 8da3ff18 | pbrook | switch (addr) {
|
1405 | c3d2689d | balrog | case 0x00: /* FUNC_MUX_CTRL_0 */ |
1406 | 8da3ff18 | pbrook | diff = s->func_mux_ctrl[addr >> 2] ^ value;
|
1407 | 8da3ff18 | pbrook | s->func_mux_ctrl[addr >> 2] = value;
|
1408 | c3d2689d | balrog | omap_pin_funcmux0_update(s, diff, value); |
1409 | c3d2689d | balrog | return;
|
1410 | c3d2689d | balrog | |
1411 | c3d2689d | balrog | case 0x04: /* FUNC_MUX_CTRL_1 */ |
1412 | 8da3ff18 | pbrook | diff = s->func_mux_ctrl[addr >> 2] ^ value;
|
1413 | 8da3ff18 | pbrook | s->func_mux_ctrl[addr >> 2] = value;
|
1414 | c3d2689d | balrog | omap_pin_funcmux1_update(s, diff, value); |
1415 | c3d2689d | balrog | return;
|
1416 | c3d2689d | balrog | |
1417 | c3d2689d | balrog | case 0x08: /* FUNC_MUX_CTRL_2 */ |
1418 | 8da3ff18 | pbrook | s->func_mux_ctrl[addr >> 2] = value;
|
1419 | c3d2689d | balrog | return;
|
1420 | c3d2689d | balrog | |
1421 | c3d2689d | balrog | case 0x0c: /* COMP_MODE_CTRL_0 */ |
1422 | c3d2689d | balrog | s->comp_mode_ctrl[0] = value;
|
1423 | c3d2689d | balrog | s->compat1509 = (value != 0x0000eaef);
|
1424 | c3d2689d | balrog | omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]); |
1425 | c3d2689d | balrog | omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]); |
1426 | c3d2689d | balrog | return;
|
1427 | c3d2689d | balrog | |
1428 | c3d2689d | balrog | case 0x10: /* FUNC_MUX_CTRL_3 */ |
1429 | c3d2689d | balrog | case 0x14: /* FUNC_MUX_CTRL_4 */ |
1430 | c3d2689d | balrog | case 0x18: /* FUNC_MUX_CTRL_5 */ |
1431 | c3d2689d | balrog | case 0x1c: /* FUNC_MUX_CTRL_6 */ |
1432 | c3d2689d | balrog | case 0x20: /* FUNC_MUX_CTRL_7 */ |
1433 | c3d2689d | balrog | case 0x24: /* FUNC_MUX_CTRL_8 */ |
1434 | c3d2689d | balrog | case 0x28: /* FUNC_MUX_CTRL_9 */ |
1435 | c3d2689d | balrog | case 0x2c: /* FUNC_MUX_CTRL_A */ |
1436 | c3d2689d | balrog | case 0x30: /* FUNC_MUX_CTRL_B */ |
1437 | c3d2689d | balrog | case 0x34: /* FUNC_MUX_CTRL_C */ |
1438 | c3d2689d | balrog | case 0x38: /* FUNC_MUX_CTRL_D */ |
1439 | 8da3ff18 | pbrook | s->func_mux_ctrl[(addr >> 2) - 1] = value; |
1440 | c3d2689d | balrog | return;
|
1441 | c3d2689d | balrog | |
1442 | c3d2689d | balrog | case 0x40: /* PULL_DWN_CTRL_0 */ |
1443 | c3d2689d | balrog | case 0x44: /* PULL_DWN_CTRL_1 */ |
1444 | c3d2689d | balrog | case 0x48: /* PULL_DWN_CTRL_2 */ |
1445 | c3d2689d | balrog | case 0x4c: /* PULL_DWN_CTRL_3 */ |
1446 | 8da3ff18 | pbrook | s->pull_dwn_ctrl[(addr & 0xf) >> 2] = value; |
1447 | c3d2689d | balrog | return;
|
1448 | c3d2689d | balrog | |
1449 | c3d2689d | balrog | case 0x50: /* GATE_INH_CTRL_0 */ |
1450 | c3d2689d | balrog | s->gate_inh_ctrl[0] = value;
|
1451 | c3d2689d | balrog | return;
|
1452 | c3d2689d | balrog | |
1453 | c3d2689d | balrog | case 0x60: /* VOLTAGE_CTRL_0 */ |
1454 | c3d2689d | balrog | s->voltage_ctrl[0] = value;
|
1455 | c3d2689d | balrog | return;
|
1456 | c3d2689d | balrog | |
1457 | c3d2689d | balrog | case 0x70: /* TEST_DBG_CTRL_0 */ |
1458 | c3d2689d | balrog | s->test_dbg_ctrl[0] = value;
|
1459 | c3d2689d | balrog | return;
|
1460 | c3d2689d | balrog | |
1461 | c3d2689d | balrog | case 0x80: /* MOD_CONF_CTRL_0 */ |
1462 | c3d2689d | balrog | diff = s->mod_conf_ctrl[0] ^ value;
|
1463 | c3d2689d | balrog | s->mod_conf_ctrl[0] = value;
|
1464 | c3d2689d | balrog | omap_pin_modconf1_update(s, diff, value); |
1465 | c3d2689d | balrog | return;
|
1466 | c3d2689d | balrog | |
1467 | c3d2689d | balrog | default:
|
1468 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1469 | c3d2689d | balrog | } |
1470 | c3d2689d | balrog | } |
1471 | c3d2689d | balrog | |
1472 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_pin_cfg_readfn[] = { |
1473 | c3d2689d | balrog | omap_badwidth_read32, |
1474 | c3d2689d | balrog | omap_badwidth_read32, |
1475 | c3d2689d | balrog | omap_pin_cfg_read, |
1476 | c3d2689d | balrog | }; |
1477 | c3d2689d | balrog | |
1478 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_pin_cfg_writefn[] = { |
1479 | c3d2689d | balrog | omap_badwidth_write32, |
1480 | c3d2689d | balrog | omap_badwidth_write32, |
1481 | c3d2689d | balrog | omap_pin_cfg_write, |
1482 | c3d2689d | balrog | }; |
1483 | c3d2689d | balrog | |
1484 | c3d2689d | balrog | static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu) |
1485 | c3d2689d | balrog | { |
1486 | c3d2689d | balrog | /* Start in Compatibility Mode. */
|
1487 | c3d2689d | balrog | mpu->compat1509 = 1;
|
1488 | c3d2689d | balrog | omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0); |
1489 | c3d2689d | balrog | omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0); |
1490 | c3d2689d | balrog | omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0); |
1491 | c3d2689d | balrog | memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl)); |
1492 | c3d2689d | balrog | memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl)); |
1493 | c3d2689d | balrog | memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl)); |
1494 | c3d2689d | balrog | memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl)); |
1495 | c3d2689d | balrog | memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl)); |
1496 | c3d2689d | balrog | memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl)); |
1497 | c3d2689d | balrog | memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl)); |
1498 | c3d2689d | balrog | } |
1499 | c3d2689d | balrog | |
1500 | c227f099 | Anthony Liguori | static void omap_pin_cfg_init(target_phys_addr_t base, |
1501 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
1502 | c3d2689d | balrog | { |
1503 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_pin_cfg_readfn,
|
1504 | c3d2689d | balrog | omap_pin_cfg_writefn, mpu); |
1505 | c3d2689d | balrog | |
1506 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
1507 | c3d2689d | balrog | omap_pin_cfg_reset(mpu); |
1508 | c3d2689d | balrog | } |
1509 | c3d2689d | balrog | |
1510 | c3d2689d | balrog | /* Device Identification, Die Identification */
|
1511 | c227f099 | Anthony Liguori | static uint32_t omap_id_read(void *opaque, target_phys_addr_t addr) |
1512 | c3d2689d | balrog | { |
1513 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1514 | c3d2689d | balrog | |
1515 | c3d2689d | balrog | switch (addr) {
|
1516 | c3d2689d | balrog | case 0xfffe1800: /* DIE_ID_LSB */ |
1517 | c3d2689d | balrog | return 0xc9581f0e; |
1518 | c3d2689d | balrog | case 0xfffe1804: /* DIE_ID_MSB */ |
1519 | c3d2689d | balrog | return 0xa8858bfa; |
1520 | c3d2689d | balrog | |
1521 | c3d2689d | balrog | case 0xfffe2000: /* PRODUCT_ID_LSB */ |
1522 | c3d2689d | balrog | return 0x00aaaafc; |
1523 | c3d2689d | balrog | case 0xfffe2004: /* PRODUCT_ID_MSB */ |
1524 | c3d2689d | balrog | return 0xcafeb574; |
1525 | c3d2689d | balrog | |
1526 | c3d2689d | balrog | case 0xfffed400: /* JTAG_ID_LSB */ |
1527 | c3d2689d | balrog | switch (s->mpu_model) {
|
1528 | c3d2689d | balrog | case omap310:
|
1529 | c3d2689d | balrog | return 0x03310315; |
1530 | c3d2689d | balrog | case omap1510:
|
1531 | c3d2689d | balrog | return 0x03310115; |
1532 | 827df9f3 | balrog | default:
|
1533 | 2ac71179 | Paul Brook | hw_error("%s: bad mpu model\n", __FUNCTION__);
|
1534 | c3d2689d | balrog | } |
1535 | c3d2689d | balrog | break;
|
1536 | c3d2689d | balrog | |
1537 | c3d2689d | balrog | case 0xfffed404: /* JTAG_ID_MSB */ |
1538 | c3d2689d | balrog | switch (s->mpu_model) {
|
1539 | c3d2689d | balrog | case omap310:
|
1540 | c3d2689d | balrog | return 0xfb57402f; |
1541 | c3d2689d | balrog | case omap1510:
|
1542 | c3d2689d | balrog | return 0xfb47002f; |
1543 | 827df9f3 | balrog | default:
|
1544 | 2ac71179 | Paul Brook | hw_error("%s: bad mpu model\n", __FUNCTION__);
|
1545 | c3d2689d | balrog | } |
1546 | c3d2689d | balrog | break;
|
1547 | c3d2689d | balrog | } |
1548 | c3d2689d | balrog | |
1549 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1550 | c3d2689d | balrog | return 0; |
1551 | c3d2689d | balrog | } |
1552 | c3d2689d | balrog | |
1553 | c227f099 | Anthony Liguori | static void omap_id_write(void *opaque, target_phys_addr_t addr, |
1554 | c3d2689d | balrog | uint32_t value) |
1555 | c3d2689d | balrog | { |
1556 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1557 | c3d2689d | balrog | } |
1558 | c3d2689d | balrog | |
1559 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_id_readfn[] = { |
1560 | c3d2689d | balrog | omap_badwidth_read32, |
1561 | c3d2689d | balrog | omap_badwidth_read32, |
1562 | c3d2689d | balrog | omap_id_read, |
1563 | c3d2689d | balrog | }; |
1564 | c3d2689d | balrog | |
1565 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_id_writefn[] = { |
1566 | c3d2689d | balrog | omap_badwidth_write32, |
1567 | c3d2689d | balrog | omap_badwidth_write32, |
1568 | c3d2689d | balrog | omap_id_write, |
1569 | c3d2689d | balrog | }; |
1570 | c3d2689d | balrog | |
1571 | c3d2689d | balrog | static void omap_id_init(struct omap_mpu_state_s *mpu) |
1572 | c3d2689d | balrog | { |
1573 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_id_readfn,
|
1574 | c3d2689d | balrog | omap_id_writefn, mpu); |
1575 | 8da3ff18 | pbrook | cpu_register_physical_memory_offset(0xfffe1800, 0x800, iomemtype, 0xfffe1800); |
1576 | 8da3ff18 | pbrook | cpu_register_physical_memory_offset(0xfffed400, 0x100, iomemtype, 0xfffed400); |
1577 | c3d2689d | balrog | if (!cpu_is_omap15xx(mpu))
|
1578 | 8da3ff18 | pbrook | cpu_register_physical_memory_offset(0xfffe2000, 0x800, iomemtype, 0xfffe2000); |
1579 | c3d2689d | balrog | } |
1580 | c3d2689d | balrog | |
1581 | c3d2689d | balrog | /* MPUI Control (Dummy) */
|
1582 | c227f099 | Anthony Liguori | static uint32_t omap_mpui_read(void *opaque, target_phys_addr_t addr) |
1583 | c3d2689d | balrog | { |
1584 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1585 | c3d2689d | balrog | |
1586 | 8da3ff18 | pbrook | switch (addr) {
|
1587 | c3d2689d | balrog | case 0x00: /* CTRL */ |
1588 | c3d2689d | balrog | return s->mpui_ctrl;
|
1589 | c3d2689d | balrog | case 0x04: /* DEBUG_ADDR */ |
1590 | c3d2689d | balrog | return 0x01ffffff; |
1591 | c3d2689d | balrog | case 0x08: /* DEBUG_DATA */ |
1592 | c3d2689d | balrog | return 0xffffffff; |
1593 | c3d2689d | balrog | case 0x0c: /* DEBUG_FLAG */ |
1594 | c3d2689d | balrog | return 0x00000800; |
1595 | c3d2689d | balrog | case 0x10: /* STATUS */ |
1596 | c3d2689d | balrog | return 0x00000000; |
1597 | c3d2689d | balrog | |
1598 | c3d2689d | balrog | /* Not in OMAP310 */
|
1599 | c3d2689d | balrog | case 0x14: /* DSP_STATUS */ |
1600 | c3d2689d | balrog | case 0x18: /* DSP_BOOT_CONFIG */ |
1601 | c3d2689d | balrog | return 0x00000000; |
1602 | c3d2689d | balrog | case 0x1c: /* DSP_MPUI_CONFIG */ |
1603 | c3d2689d | balrog | return 0x0000ffff; |
1604 | c3d2689d | balrog | } |
1605 | c3d2689d | balrog | |
1606 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1607 | c3d2689d | balrog | return 0; |
1608 | c3d2689d | balrog | } |
1609 | c3d2689d | balrog | |
1610 | c227f099 | Anthony Liguori | static void omap_mpui_write(void *opaque, target_phys_addr_t addr, |
1611 | c3d2689d | balrog | uint32_t value) |
1612 | c3d2689d | balrog | { |
1613 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1614 | c3d2689d | balrog | |
1615 | 8da3ff18 | pbrook | switch (addr) {
|
1616 | c3d2689d | balrog | case 0x00: /* CTRL */ |
1617 | c3d2689d | balrog | s->mpui_ctrl = value & 0x007fffff;
|
1618 | c3d2689d | balrog | break;
|
1619 | c3d2689d | balrog | |
1620 | c3d2689d | balrog | case 0x04: /* DEBUG_ADDR */ |
1621 | c3d2689d | balrog | case 0x08: /* DEBUG_DATA */ |
1622 | c3d2689d | balrog | case 0x0c: /* DEBUG_FLAG */ |
1623 | c3d2689d | balrog | case 0x10: /* STATUS */ |
1624 | c3d2689d | balrog | /* Not in OMAP310 */
|
1625 | c3d2689d | balrog | case 0x14: /* DSP_STATUS */ |
1626 | c3d2689d | balrog | OMAP_RO_REG(addr); |
1627 | c3d2689d | balrog | case 0x18: /* DSP_BOOT_CONFIG */ |
1628 | c3d2689d | balrog | case 0x1c: /* DSP_MPUI_CONFIG */ |
1629 | c3d2689d | balrog | break;
|
1630 | c3d2689d | balrog | |
1631 | c3d2689d | balrog | default:
|
1632 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1633 | c3d2689d | balrog | } |
1634 | c3d2689d | balrog | } |
1635 | c3d2689d | balrog | |
1636 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_mpui_readfn[] = { |
1637 | c3d2689d | balrog | omap_badwidth_read32, |
1638 | c3d2689d | balrog | omap_badwidth_read32, |
1639 | c3d2689d | balrog | omap_mpui_read, |
1640 | c3d2689d | balrog | }; |
1641 | c3d2689d | balrog | |
1642 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_mpui_writefn[] = { |
1643 | c3d2689d | balrog | omap_badwidth_write32, |
1644 | c3d2689d | balrog | omap_badwidth_write32, |
1645 | c3d2689d | balrog | omap_mpui_write, |
1646 | c3d2689d | balrog | }; |
1647 | c3d2689d | balrog | |
1648 | c3d2689d | balrog | static void omap_mpui_reset(struct omap_mpu_state_s *s) |
1649 | c3d2689d | balrog | { |
1650 | c3d2689d | balrog | s->mpui_ctrl = 0x0003ff1b;
|
1651 | c3d2689d | balrog | } |
1652 | c3d2689d | balrog | |
1653 | c227f099 | Anthony Liguori | static void omap_mpui_init(target_phys_addr_t base, |
1654 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
1655 | c3d2689d | balrog | { |
1656 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_mpui_readfn,
|
1657 | c3d2689d | balrog | omap_mpui_writefn, mpu); |
1658 | c3d2689d | balrog | |
1659 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100, iomemtype);
|
1660 | c3d2689d | balrog | |
1661 | c3d2689d | balrog | omap_mpui_reset(mpu); |
1662 | c3d2689d | balrog | } |
1663 | c3d2689d | balrog | |
1664 | c3d2689d | balrog | /* TIPB Bridges */
|
1665 | c3d2689d | balrog | struct omap_tipb_bridge_s {
|
1666 | c3d2689d | balrog | qemu_irq abort; |
1667 | c3d2689d | balrog | |
1668 | c3d2689d | balrog | int width_intr;
|
1669 | c3d2689d | balrog | uint16_t control; |
1670 | c3d2689d | balrog | uint16_t alloc; |
1671 | c3d2689d | balrog | uint16_t buffer; |
1672 | c3d2689d | balrog | uint16_t enh_control; |
1673 | c3d2689d | balrog | }; |
1674 | c3d2689d | balrog | |
1675 | c227f099 | Anthony Liguori | static uint32_t omap_tipb_bridge_read(void *opaque, target_phys_addr_t addr) |
1676 | c3d2689d | balrog | { |
1677 | c3d2689d | balrog | struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque; |
1678 | c3d2689d | balrog | |
1679 | 8da3ff18 | pbrook | switch (addr) {
|
1680 | c3d2689d | balrog | case 0x00: /* TIPB_CNTL */ |
1681 | c3d2689d | balrog | return s->control;
|
1682 | c3d2689d | balrog | case 0x04: /* TIPB_BUS_ALLOC */ |
1683 | c3d2689d | balrog | return s->alloc;
|
1684 | c3d2689d | balrog | case 0x08: /* MPU_TIPB_CNTL */ |
1685 | c3d2689d | balrog | return s->buffer;
|
1686 | c3d2689d | balrog | case 0x0c: /* ENHANCED_TIPB_CNTL */ |
1687 | c3d2689d | balrog | return s->enh_control;
|
1688 | c3d2689d | balrog | case 0x10: /* ADDRESS_DBG */ |
1689 | c3d2689d | balrog | case 0x14: /* DATA_DEBUG_LOW */ |
1690 | c3d2689d | balrog | case 0x18: /* DATA_DEBUG_HIGH */ |
1691 | c3d2689d | balrog | return 0xffff; |
1692 | c3d2689d | balrog | case 0x1c: /* DEBUG_CNTR_SIG */ |
1693 | c3d2689d | balrog | return 0x00f8; |
1694 | c3d2689d | balrog | } |
1695 | c3d2689d | balrog | |
1696 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1697 | c3d2689d | balrog | return 0; |
1698 | c3d2689d | balrog | } |
1699 | c3d2689d | balrog | |
1700 | c227f099 | Anthony Liguori | static void omap_tipb_bridge_write(void *opaque, target_phys_addr_t addr, |
1701 | c3d2689d | balrog | uint32_t value) |
1702 | c3d2689d | balrog | { |
1703 | c3d2689d | balrog | struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque; |
1704 | c3d2689d | balrog | |
1705 | 8da3ff18 | pbrook | switch (addr) {
|
1706 | c3d2689d | balrog | case 0x00: /* TIPB_CNTL */ |
1707 | c3d2689d | balrog | s->control = value & 0xffff;
|
1708 | c3d2689d | balrog | break;
|
1709 | c3d2689d | balrog | |
1710 | c3d2689d | balrog | case 0x04: /* TIPB_BUS_ALLOC */ |
1711 | c3d2689d | balrog | s->alloc = value & 0x003f;
|
1712 | c3d2689d | balrog | break;
|
1713 | c3d2689d | balrog | |
1714 | c3d2689d | balrog | case 0x08: /* MPU_TIPB_CNTL */ |
1715 | c3d2689d | balrog | s->buffer = value & 0x0003;
|
1716 | c3d2689d | balrog | break;
|
1717 | c3d2689d | balrog | |
1718 | c3d2689d | balrog | case 0x0c: /* ENHANCED_TIPB_CNTL */ |
1719 | c3d2689d | balrog | s->width_intr = !(value & 2);
|
1720 | c3d2689d | balrog | s->enh_control = value & 0x000f;
|
1721 | c3d2689d | balrog | break;
|
1722 | c3d2689d | balrog | |
1723 | c3d2689d | balrog | case 0x10: /* ADDRESS_DBG */ |
1724 | c3d2689d | balrog | case 0x14: /* DATA_DEBUG_LOW */ |
1725 | c3d2689d | balrog | case 0x18: /* DATA_DEBUG_HIGH */ |
1726 | c3d2689d | balrog | case 0x1c: /* DEBUG_CNTR_SIG */ |
1727 | c3d2689d | balrog | OMAP_RO_REG(addr); |
1728 | c3d2689d | balrog | break;
|
1729 | c3d2689d | balrog | |
1730 | c3d2689d | balrog | default:
|
1731 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1732 | c3d2689d | balrog | } |
1733 | c3d2689d | balrog | } |
1734 | c3d2689d | balrog | |
1735 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_tipb_bridge_readfn[] = { |
1736 | c3d2689d | balrog | omap_badwidth_read16, |
1737 | c3d2689d | balrog | omap_tipb_bridge_read, |
1738 | c3d2689d | balrog | omap_tipb_bridge_read, |
1739 | c3d2689d | balrog | }; |
1740 | c3d2689d | balrog | |
1741 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_tipb_bridge_writefn[] = { |
1742 | c3d2689d | balrog | omap_badwidth_write16, |
1743 | c3d2689d | balrog | omap_tipb_bridge_write, |
1744 | c3d2689d | balrog | omap_tipb_bridge_write, |
1745 | c3d2689d | balrog | }; |
1746 | c3d2689d | balrog | |
1747 | c3d2689d | balrog | static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s) |
1748 | c3d2689d | balrog | { |
1749 | c3d2689d | balrog | s->control = 0xffff;
|
1750 | c3d2689d | balrog | s->alloc = 0x0009;
|
1751 | c3d2689d | balrog | s->buffer = 0x0000;
|
1752 | c3d2689d | balrog | s->enh_control = 0x000f;
|
1753 | c3d2689d | balrog | } |
1754 | c3d2689d | balrog | |
1755 | c227f099 | Anthony Liguori | struct omap_tipb_bridge_s *omap_tipb_bridge_init(target_phys_addr_t base,
|
1756 | c3d2689d | balrog | qemu_irq abort_irq, omap_clk clk) |
1757 | c3d2689d | balrog | { |
1758 | c3d2689d | balrog | int iomemtype;
|
1759 | c3d2689d | balrog | struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) |
1760 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_tipb_bridge_s)); |
1761 | c3d2689d | balrog | |
1762 | c3d2689d | balrog | s->abort = abort_irq; |
1763 | c3d2689d | balrog | omap_tipb_bridge_reset(s); |
1764 | c3d2689d | balrog | |
1765 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_tipb_bridge_readfn, |
1766 | c3d2689d | balrog | omap_tipb_bridge_writefn, s); |
1767 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100, iomemtype);
|
1768 | c3d2689d | balrog | |
1769 | c3d2689d | balrog | return s;
|
1770 | c3d2689d | balrog | } |
1771 | c3d2689d | balrog | |
1772 | c3d2689d | balrog | /* Dummy Traffic Controller's Memory Interface */
|
1773 | c227f099 | Anthony Liguori | static uint32_t omap_tcmi_read(void *opaque, target_phys_addr_t addr) |
1774 | c3d2689d | balrog | { |
1775 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1776 | c3d2689d | balrog | uint32_t ret; |
1777 | c3d2689d | balrog | |
1778 | 8da3ff18 | pbrook | switch (addr) {
|
1779 | d8f699cb | balrog | case 0x00: /* IMIF_PRIO */ |
1780 | d8f699cb | balrog | case 0x04: /* EMIFS_PRIO */ |
1781 | d8f699cb | balrog | case 0x08: /* EMIFF_PRIO */ |
1782 | d8f699cb | balrog | case 0x0c: /* EMIFS_CONFIG */ |
1783 | d8f699cb | balrog | case 0x10: /* EMIFS_CS0_CONFIG */ |
1784 | d8f699cb | balrog | case 0x14: /* EMIFS_CS1_CONFIG */ |
1785 | d8f699cb | balrog | case 0x18: /* EMIFS_CS2_CONFIG */ |
1786 | d8f699cb | balrog | case 0x1c: /* EMIFS_CS3_CONFIG */ |
1787 | d8f699cb | balrog | case 0x24: /* EMIFF_MRS */ |
1788 | d8f699cb | balrog | case 0x28: /* TIMEOUT1 */ |
1789 | d8f699cb | balrog | case 0x2c: /* TIMEOUT2 */ |
1790 | d8f699cb | balrog | case 0x30: /* TIMEOUT3 */ |
1791 | d8f699cb | balrog | case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */ |
1792 | d8f699cb | balrog | case 0x40: /* EMIFS_CFG_DYN_WAIT */ |
1793 | 8da3ff18 | pbrook | return s->tcmi_regs[addr >> 2]; |
1794 | c3d2689d | balrog | |
1795 | d8f699cb | balrog | case 0x20: /* EMIFF_SDRAM_CONFIG */ |
1796 | 8da3ff18 | pbrook | ret = s->tcmi_regs[addr >> 2];
|
1797 | 8da3ff18 | pbrook | s->tcmi_regs[addr >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */ |
1798 | c3d2689d | balrog | /* XXX: We can try using the VGA_DIRTY flag for this */
|
1799 | c3d2689d | balrog | return ret;
|
1800 | c3d2689d | balrog | } |
1801 | c3d2689d | balrog | |
1802 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1803 | c3d2689d | balrog | return 0; |
1804 | c3d2689d | balrog | } |
1805 | c3d2689d | balrog | |
1806 | c227f099 | Anthony Liguori | static void omap_tcmi_write(void *opaque, target_phys_addr_t addr, |
1807 | c3d2689d | balrog | uint32_t value) |
1808 | c3d2689d | balrog | { |
1809 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1810 | c3d2689d | balrog | |
1811 | 8da3ff18 | pbrook | switch (addr) {
|
1812 | d8f699cb | balrog | case 0x00: /* IMIF_PRIO */ |
1813 | d8f699cb | balrog | case 0x04: /* EMIFS_PRIO */ |
1814 | d8f699cb | balrog | case 0x08: /* EMIFF_PRIO */ |
1815 | d8f699cb | balrog | case 0x10: /* EMIFS_CS0_CONFIG */ |
1816 | d8f699cb | balrog | case 0x14: /* EMIFS_CS1_CONFIG */ |
1817 | d8f699cb | balrog | case 0x18: /* EMIFS_CS2_CONFIG */ |
1818 | d8f699cb | balrog | case 0x1c: /* EMIFS_CS3_CONFIG */ |
1819 | d8f699cb | balrog | case 0x20: /* EMIFF_SDRAM_CONFIG */ |
1820 | d8f699cb | balrog | case 0x24: /* EMIFF_MRS */ |
1821 | d8f699cb | balrog | case 0x28: /* TIMEOUT1 */ |
1822 | d8f699cb | balrog | case 0x2c: /* TIMEOUT2 */ |
1823 | d8f699cb | balrog | case 0x30: /* TIMEOUT3 */ |
1824 | d8f699cb | balrog | case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */ |
1825 | d8f699cb | balrog | case 0x40: /* EMIFS_CFG_DYN_WAIT */ |
1826 | 8da3ff18 | pbrook | s->tcmi_regs[addr >> 2] = value;
|
1827 | c3d2689d | balrog | break;
|
1828 | d8f699cb | balrog | case 0x0c: /* EMIFS_CONFIG */ |
1829 | 8da3ff18 | pbrook | s->tcmi_regs[addr >> 2] = (value & 0xf) | (1 << 4); |
1830 | c3d2689d | balrog | break;
|
1831 | c3d2689d | balrog | |
1832 | c3d2689d | balrog | default:
|
1833 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1834 | c3d2689d | balrog | } |
1835 | c3d2689d | balrog | } |
1836 | c3d2689d | balrog | |
1837 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_tcmi_readfn[] = { |
1838 | c3d2689d | balrog | omap_badwidth_read32, |
1839 | c3d2689d | balrog | omap_badwidth_read32, |
1840 | c3d2689d | balrog | omap_tcmi_read, |
1841 | c3d2689d | balrog | }; |
1842 | c3d2689d | balrog | |
1843 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_tcmi_writefn[] = { |
1844 | c3d2689d | balrog | omap_badwidth_write32, |
1845 | c3d2689d | balrog | omap_badwidth_write32, |
1846 | c3d2689d | balrog | omap_tcmi_write, |
1847 | c3d2689d | balrog | }; |
1848 | c3d2689d | balrog | |
1849 | c3d2689d | balrog | static void omap_tcmi_reset(struct omap_mpu_state_s *mpu) |
1850 | c3d2689d | balrog | { |
1851 | c3d2689d | balrog | mpu->tcmi_regs[0x00 >> 2] = 0x00000000; |
1852 | c3d2689d | balrog | mpu->tcmi_regs[0x04 >> 2] = 0x00000000; |
1853 | c3d2689d | balrog | mpu->tcmi_regs[0x08 >> 2] = 0x00000000; |
1854 | c3d2689d | balrog | mpu->tcmi_regs[0x0c >> 2] = 0x00000010; |
1855 | c3d2689d | balrog | mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb; |
1856 | c3d2689d | balrog | mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb; |
1857 | c3d2689d | balrog | mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb; |
1858 | c3d2689d | balrog | mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb; |
1859 | c3d2689d | balrog | mpu->tcmi_regs[0x20 >> 2] = 0x00618800; |
1860 | c3d2689d | balrog | mpu->tcmi_regs[0x24 >> 2] = 0x00000037; |
1861 | c3d2689d | balrog | mpu->tcmi_regs[0x28 >> 2] = 0x00000000; |
1862 | c3d2689d | balrog | mpu->tcmi_regs[0x2c >> 2] = 0x00000000; |
1863 | c3d2689d | balrog | mpu->tcmi_regs[0x30 >> 2] = 0x00000000; |
1864 | c3d2689d | balrog | mpu->tcmi_regs[0x3c >> 2] = 0x00000003; |
1865 | c3d2689d | balrog | mpu->tcmi_regs[0x40 >> 2] = 0x00000000; |
1866 | c3d2689d | balrog | } |
1867 | c3d2689d | balrog | |
1868 | c227f099 | Anthony Liguori | static void omap_tcmi_init(target_phys_addr_t base, |
1869 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
1870 | c3d2689d | balrog | { |
1871 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_tcmi_readfn,
|
1872 | c3d2689d | balrog | omap_tcmi_writefn, mpu); |
1873 | c3d2689d | balrog | |
1874 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100, iomemtype);
|
1875 | c3d2689d | balrog | omap_tcmi_reset(mpu); |
1876 | c3d2689d | balrog | } |
1877 | c3d2689d | balrog | |
1878 | c3d2689d | balrog | /* Digital phase-locked loops control */
|
1879 | c227f099 | Anthony Liguori | static uint32_t omap_dpll_read(void *opaque, target_phys_addr_t addr) |
1880 | c3d2689d | balrog | { |
1881 | c3d2689d | balrog | struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque; |
1882 | c3d2689d | balrog | |
1883 | 8da3ff18 | pbrook | if (addr == 0x00) /* CTL_REG */ |
1884 | c3d2689d | balrog | return s->mode;
|
1885 | c3d2689d | balrog | |
1886 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1887 | c3d2689d | balrog | return 0; |
1888 | c3d2689d | balrog | } |
1889 | c3d2689d | balrog | |
1890 | c227f099 | Anthony Liguori | static void omap_dpll_write(void *opaque, target_phys_addr_t addr, |
1891 | c3d2689d | balrog | uint32_t value) |
1892 | c3d2689d | balrog | { |
1893 | c3d2689d | balrog | struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque; |
1894 | c3d2689d | balrog | uint16_t diff; |
1895 | c3d2689d | balrog | static const int bypass_div[4] = { 1, 2, 4, 4 }; |
1896 | c3d2689d | balrog | int div, mult;
|
1897 | c3d2689d | balrog | |
1898 | 8da3ff18 | pbrook | if (addr == 0x00) { /* CTL_REG */ |
1899 | c3d2689d | balrog | /* See omap_ulpd_pm_write() too */
|
1900 | c3d2689d | balrog | diff = s->mode & value; |
1901 | c3d2689d | balrog | s->mode = value & 0x2fff;
|
1902 | c3d2689d | balrog | if (diff & (0x3ff << 2)) { |
1903 | c3d2689d | balrog | if (value & (1 << 4)) { /* PLL_ENABLE */ |
1904 | c3d2689d | balrog | div = ((value >> 5) & 3) + 1; /* PLL_DIV */ |
1905 | c3d2689d | balrog | mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */ |
1906 | c3d2689d | balrog | } else {
|
1907 | c3d2689d | balrog | div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */ |
1908 | c3d2689d | balrog | mult = 1;
|
1909 | c3d2689d | balrog | } |
1910 | c3d2689d | balrog | omap_clk_setrate(s->dpll, div, mult); |
1911 | c3d2689d | balrog | } |
1912 | c3d2689d | balrog | |
1913 | c3d2689d | balrog | /* Enter the desired mode. */
|
1914 | c3d2689d | balrog | s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1); |
1915 | c3d2689d | balrog | |
1916 | c3d2689d | balrog | /* Act as if the lock is restored. */
|
1917 | c3d2689d | balrog | s->mode |= 2;
|
1918 | c3d2689d | balrog | } else {
|
1919 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1920 | c3d2689d | balrog | } |
1921 | c3d2689d | balrog | } |
1922 | c3d2689d | balrog | |
1923 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_dpll_readfn[] = { |
1924 | c3d2689d | balrog | omap_badwidth_read16, |
1925 | c3d2689d | balrog | omap_dpll_read, |
1926 | c3d2689d | balrog | omap_badwidth_read16, |
1927 | c3d2689d | balrog | }; |
1928 | c3d2689d | balrog | |
1929 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_dpll_writefn[] = { |
1930 | c3d2689d | balrog | omap_badwidth_write16, |
1931 | c3d2689d | balrog | omap_dpll_write, |
1932 | c3d2689d | balrog | omap_badwidth_write16, |
1933 | c3d2689d | balrog | }; |
1934 | c3d2689d | balrog | |
1935 | c3d2689d | balrog | static void omap_dpll_reset(struct dpll_ctl_s *s) |
1936 | c3d2689d | balrog | { |
1937 | c3d2689d | balrog | s->mode = 0x2002;
|
1938 | c3d2689d | balrog | omap_clk_setrate(s->dpll, 1, 1); |
1939 | c3d2689d | balrog | } |
1940 | c3d2689d | balrog | |
1941 | c227f099 | Anthony Liguori | static void omap_dpll_init(struct dpll_ctl_s *s, target_phys_addr_t base, |
1942 | c3d2689d | balrog | omap_clk clk) |
1943 | c3d2689d | balrog | { |
1944 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_dpll_readfn,
|
1945 | c3d2689d | balrog | omap_dpll_writefn, s); |
1946 | c3d2689d | balrog | |
1947 | c3d2689d | balrog | s->dpll = clk; |
1948 | c3d2689d | balrog | omap_dpll_reset(s); |
1949 | c3d2689d | balrog | |
1950 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x100, iomemtype);
|
1951 | c3d2689d | balrog | } |
1952 | c3d2689d | balrog | |
1953 | c3d2689d | balrog | /* UARTs */
|
1954 | c3d2689d | balrog | struct omap_uart_s {
|
1955 | c227f099 | Anthony Liguori | target_phys_addr_t base; |
1956 | c3d2689d | balrog | SerialState *serial; /* TODO */
|
1957 | 827df9f3 | balrog | struct omap_target_agent_s *ta;
|
1958 | 75554a3c | balrog | omap_clk fclk; |
1959 | 75554a3c | balrog | qemu_irq irq; |
1960 | 827df9f3 | balrog | |
1961 | 827df9f3 | balrog | uint8_t eblr; |
1962 | 827df9f3 | balrog | uint8_t syscontrol; |
1963 | 827df9f3 | balrog | uint8_t wkup; |
1964 | 827df9f3 | balrog | uint8_t cfps; |
1965 | 54585ffe | balrog | uint8_t mdr[2];
|
1966 | 54585ffe | balrog | uint8_t scr; |
1967 | c588de3d | balrog | uint8_t clksel; |
1968 | c3d2689d | balrog | }; |
1969 | c3d2689d | balrog | |
1970 | 827df9f3 | balrog | void omap_uart_reset(struct omap_uart_s *s) |
1971 | c3d2689d | balrog | { |
1972 | 827df9f3 | balrog | s->eblr = 0x00;
|
1973 | 827df9f3 | balrog | s->syscontrol = 0;
|
1974 | 827df9f3 | balrog | s->wkup = 0x3f;
|
1975 | 827df9f3 | balrog | s->cfps = 0x69;
|
1976 | c588de3d | balrog | s->clksel = 0;
|
1977 | c3d2689d | balrog | } |
1978 | c3d2689d | balrog | |
1979 | c227f099 | Anthony Liguori | struct omap_uart_s *omap_uart_init(target_phys_addr_t base,
|
1980 | 827df9f3 | balrog | qemu_irq irq, omap_clk fclk, omap_clk iclk, |
1981 | 827df9f3 | balrog | qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr) |
1982 | c3d2689d | balrog | { |
1983 | c3d2689d | balrog | struct omap_uart_s *s = (struct omap_uart_s *) |
1984 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_uart_s)); |
1985 | 827df9f3 | balrog | |
1986 | 75554a3c | balrog | s->base = base; |
1987 | 75554a3c | balrog | s->fclk = fclk; |
1988 | 75554a3c | balrog | s->irq = irq; |
1989 | b6cd0ea1 | aurel32 | s->serial = serial_mm_init(base, 2, irq, omap_clk_getrate(fclk)/16, |
1990 | ceecf1d1 | aurel32 | chr ?: qemu_chr_open("null", "null", NULL), 1); |
1991 | 827df9f3 | balrog | |
1992 | 827df9f3 | balrog | return s;
|
1993 | 827df9f3 | balrog | } |
1994 | 827df9f3 | balrog | |
1995 | c227f099 | Anthony Liguori | static uint32_t omap_uart_read(void *opaque, target_phys_addr_t addr) |
1996 | 827df9f3 | balrog | { |
1997 | 827df9f3 | balrog | struct omap_uart_s *s = (struct omap_uart_s *) opaque; |
1998 | 827df9f3 | balrog | |
1999 | 8da3ff18 | pbrook | addr &= 0xff;
|
2000 | 8da3ff18 | pbrook | switch (addr) {
|
2001 | 54585ffe | balrog | case 0x20: /* MDR1 */ |
2002 | 54585ffe | balrog | return s->mdr[0]; |
2003 | 54585ffe | balrog | case 0x24: /* MDR2 */ |
2004 | 54585ffe | balrog | return s->mdr[1]; |
2005 | 54585ffe | balrog | case 0x40: /* SCR */ |
2006 | 54585ffe | balrog | return s->scr;
|
2007 | 54585ffe | balrog | case 0x44: /* SSR */ |
2008 | 54585ffe | balrog | return 0x0; |
2009 | c588de3d | balrog | case 0x48: /* EBLR (OMAP2) */ |
2010 | 827df9f3 | balrog | return s->eblr;
|
2011 | c588de3d | balrog | case 0x4C: /* OSC_12M_SEL (OMAP1) */ |
2012 | c588de3d | balrog | return s->clksel;
|
2013 | 827df9f3 | balrog | case 0x50: /* MVR */ |
2014 | 827df9f3 | balrog | return 0x30; |
2015 | c588de3d | balrog | case 0x54: /* SYSC (OMAP2) */ |
2016 | 827df9f3 | balrog | return s->syscontrol;
|
2017 | c588de3d | balrog | case 0x58: /* SYSS (OMAP2) */ |
2018 | 827df9f3 | balrog | return 1; |
2019 | c588de3d | balrog | case 0x5c: /* WER (OMAP2) */ |
2020 | 827df9f3 | balrog | return s->wkup;
|
2021 | c588de3d | balrog | case 0x60: /* CFPS (OMAP2) */ |
2022 | 827df9f3 | balrog | return s->cfps;
|
2023 | 827df9f3 | balrog | } |
2024 | 827df9f3 | balrog | |
2025 | 827df9f3 | balrog | OMAP_BAD_REG(addr); |
2026 | 827df9f3 | balrog | return 0; |
2027 | 827df9f3 | balrog | } |
2028 | 827df9f3 | balrog | |
2029 | c227f099 | Anthony Liguori | static void omap_uart_write(void *opaque, target_phys_addr_t addr, |
2030 | 827df9f3 | balrog | uint32_t value) |
2031 | 827df9f3 | balrog | { |
2032 | 827df9f3 | balrog | struct omap_uart_s *s = (struct omap_uart_s *) opaque; |
2033 | 827df9f3 | balrog | |
2034 | 8da3ff18 | pbrook | addr &= 0xff;
|
2035 | 8da3ff18 | pbrook | switch (addr) {
|
2036 | 54585ffe | balrog | case 0x20: /* MDR1 */ |
2037 | 54585ffe | balrog | s->mdr[0] = value & 0x7f; |
2038 | 54585ffe | balrog | break;
|
2039 | 54585ffe | balrog | case 0x24: /* MDR2 */ |
2040 | 54585ffe | balrog | s->mdr[1] = value & 0xff; |
2041 | 54585ffe | balrog | break;
|
2042 | 54585ffe | balrog | case 0x40: /* SCR */ |
2043 | 54585ffe | balrog | s->scr = value & 0xff;
|
2044 | 54585ffe | balrog | break;
|
2045 | c588de3d | balrog | case 0x48: /* EBLR (OMAP2) */ |
2046 | 827df9f3 | balrog | s->eblr = value & 0xff;
|
2047 | 827df9f3 | balrog | break;
|
2048 | c588de3d | balrog | case 0x4C: /* OSC_12M_SEL (OMAP1) */ |
2049 | c588de3d | balrog | s->clksel = value & 1;
|
2050 | c588de3d | balrog | break;
|
2051 | 54585ffe | balrog | case 0x44: /* SSR */ |
2052 | 827df9f3 | balrog | case 0x50: /* MVR */ |
2053 | c588de3d | balrog | case 0x58: /* SYSS (OMAP2) */ |
2054 | 827df9f3 | balrog | OMAP_RO_REG(addr); |
2055 | 827df9f3 | balrog | break;
|
2056 | c588de3d | balrog | case 0x54: /* SYSC (OMAP2) */ |
2057 | 827df9f3 | balrog | s->syscontrol = value & 0x1d;
|
2058 | 827df9f3 | balrog | if (value & 2) |
2059 | 827df9f3 | balrog | omap_uart_reset(s); |
2060 | 827df9f3 | balrog | break;
|
2061 | c588de3d | balrog | case 0x5c: /* WER (OMAP2) */ |
2062 | 827df9f3 | balrog | s->wkup = value & 0x7f;
|
2063 | 827df9f3 | balrog | break;
|
2064 | c588de3d | balrog | case 0x60: /* CFPS (OMAP2) */ |
2065 | 827df9f3 | balrog | s->cfps = value & 0xff;
|
2066 | 827df9f3 | balrog | break;
|
2067 | 827df9f3 | balrog | default:
|
2068 | 827df9f3 | balrog | OMAP_BAD_REG(addr); |
2069 | 827df9f3 | balrog | } |
2070 | 827df9f3 | balrog | } |
2071 | 827df9f3 | balrog | |
2072 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_uart_readfn[] = { |
2073 | 827df9f3 | balrog | omap_uart_read, |
2074 | 827df9f3 | balrog | omap_uart_read, |
2075 | 827df9f3 | balrog | omap_badwidth_read8, |
2076 | 827df9f3 | balrog | }; |
2077 | 827df9f3 | balrog | |
2078 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_uart_writefn[] = { |
2079 | 827df9f3 | balrog | omap_uart_write, |
2080 | 827df9f3 | balrog | omap_uart_write, |
2081 | 827df9f3 | balrog | omap_badwidth_write8, |
2082 | 827df9f3 | balrog | }; |
2083 | 827df9f3 | balrog | |
2084 | 827df9f3 | balrog | struct omap_uart_s *omap2_uart_init(struct omap_target_agent_s *ta, |
2085 | 827df9f3 | balrog | qemu_irq irq, omap_clk fclk, omap_clk iclk, |
2086 | 827df9f3 | balrog | qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr) |
2087 | 827df9f3 | balrog | { |
2088 | c227f099 | Anthony Liguori | target_phys_addr_t base = omap_l4_attach(ta, 0, 0); |
2089 | 827df9f3 | balrog | struct omap_uart_s *s = omap_uart_init(base, irq,
|
2090 | 827df9f3 | balrog | fclk, iclk, txdma, rxdma, chr); |
2091 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_uart_readfn,
|
2092 | 827df9f3 | balrog | omap_uart_writefn, s); |
2093 | 827df9f3 | balrog | |
2094 | 827df9f3 | balrog | s->ta = ta; |
2095 | 827df9f3 | balrog | |
2096 | 8da3ff18 | pbrook | cpu_register_physical_memory(base + 0x20, 0x100, iomemtype); |
2097 | 827df9f3 | balrog | |
2098 | c3d2689d | balrog | return s;
|
2099 | c3d2689d | balrog | } |
2100 | c3d2689d | balrog | |
2101 | 75554a3c | balrog | void omap_uart_attach(struct omap_uart_s *s, CharDriverState *chr) |
2102 | 75554a3c | balrog | { |
2103 | 75554a3c | balrog | /* TODO: Should reuse or destroy current s->serial */
|
2104 | 75554a3c | balrog | s->serial = serial_mm_init(s->base, 2, s->irq,
|
2105 | 75554a3c | balrog | omap_clk_getrate(s->fclk) / 16,
|
2106 | ceecf1d1 | aurel32 | chr ?: qemu_chr_open("null", "null", NULL), 1); |
2107 | 75554a3c | balrog | } |
2108 | 75554a3c | balrog | |
2109 | c3d2689d | balrog | /* MPU Clock/Reset/Power Mode Control */
|
2110 | c227f099 | Anthony Liguori | static uint32_t omap_clkm_read(void *opaque, target_phys_addr_t addr) |
2111 | c3d2689d | balrog | { |
2112 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2113 | c3d2689d | balrog | |
2114 | 8da3ff18 | pbrook | switch (addr) {
|
2115 | c3d2689d | balrog | case 0x00: /* ARM_CKCTL */ |
2116 | c3d2689d | balrog | return s->clkm.arm_ckctl;
|
2117 | c3d2689d | balrog | |
2118 | c3d2689d | balrog | case 0x04: /* ARM_IDLECT1 */ |
2119 | c3d2689d | balrog | return s->clkm.arm_idlect1;
|
2120 | c3d2689d | balrog | |
2121 | c3d2689d | balrog | case 0x08: /* ARM_IDLECT2 */ |
2122 | c3d2689d | balrog | return s->clkm.arm_idlect2;
|
2123 | c3d2689d | balrog | |
2124 | c3d2689d | balrog | case 0x0c: /* ARM_EWUPCT */ |
2125 | c3d2689d | balrog | return s->clkm.arm_ewupct;
|
2126 | c3d2689d | balrog | |
2127 | c3d2689d | balrog | case 0x10: /* ARM_RSTCT1 */ |
2128 | c3d2689d | balrog | return s->clkm.arm_rstct1;
|
2129 | c3d2689d | balrog | |
2130 | c3d2689d | balrog | case 0x14: /* ARM_RSTCT2 */ |
2131 | c3d2689d | balrog | return s->clkm.arm_rstct2;
|
2132 | c3d2689d | balrog | |
2133 | c3d2689d | balrog | case 0x18: /* ARM_SYSST */ |
2134 | d8f699cb | balrog | return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start; |
2135 | c3d2689d | balrog | |
2136 | c3d2689d | balrog | case 0x1c: /* ARM_CKOUT1 */ |
2137 | c3d2689d | balrog | return s->clkm.arm_ckout1;
|
2138 | c3d2689d | balrog | |
2139 | c3d2689d | balrog | case 0x20: /* ARM_CKOUT2 */ |
2140 | c3d2689d | balrog | break;
|
2141 | c3d2689d | balrog | } |
2142 | c3d2689d | balrog | |
2143 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2144 | c3d2689d | balrog | return 0; |
2145 | c3d2689d | balrog | } |
2146 | c3d2689d | balrog | |
2147 | c3d2689d | balrog | static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s, |
2148 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2149 | c3d2689d | balrog | { |
2150 | c3d2689d | balrog | omap_clk clk; |
2151 | c3d2689d | balrog | |
2152 | c3d2689d | balrog | if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */ |
2153 | c3d2689d | balrog | if (value & (1 << 14)) |
2154 | c3d2689d | balrog | /* Reserved */;
|
2155 | c3d2689d | balrog | else {
|
2156 | c3d2689d | balrog | clk = omap_findclk(s, "arminth_ck");
|
2157 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
|
2158 | c3d2689d | balrog | } |
2159 | c3d2689d | balrog | } |
2160 | c3d2689d | balrog | if (diff & (1 << 12)) { /* ARM_TIMXO */ |
2161 | c3d2689d | balrog | clk = omap_findclk(s, "armtim_ck");
|
2162 | c3d2689d | balrog | if (value & (1 << 12)) |
2163 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "clkin"));
|
2164 | c3d2689d | balrog | else
|
2165 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
|
2166 | c3d2689d | balrog | } |
2167 | c3d2689d | balrog | /* XXX: en_dspck */
|
2168 | c3d2689d | balrog | if (diff & (3 << 10)) { /* DSPMMUDIV */ |
2169 | c3d2689d | balrog | clk = omap_findclk(s, "dspmmu_ck");
|
2170 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1); |
2171 | c3d2689d | balrog | } |
2172 | c3d2689d | balrog | if (diff & (3 << 8)) { /* TCDIV */ |
2173 | c3d2689d | balrog | clk = omap_findclk(s, "tc_ck");
|
2174 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1); |
2175 | c3d2689d | balrog | } |
2176 | c3d2689d | balrog | if (diff & (3 << 6)) { /* DSPDIV */ |
2177 | c3d2689d | balrog | clk = omap_findclk(s, "dsp_ck");
|
2178 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1); |
2179 | c3d2689d | balrog | } |
2180 | c3d2689d | balrog | if (diff & (3 << 4)) { /* ARMDIV */ |
2181 | c3d2689d | balrog | clk = omap_findclk(s, "arm_ck");
|
2182 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1); |
2183 | c3d2689d | balrog | } |
2184 | c3d2689d | balrog | if (diff & (3 << 2)) { /* LCDDIV */ |
2185 | c3d2689d | balrog | clk = omap_findclk(s, "lcd_ck");
|
2186 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1); |
2187 | c3d2689d | balrog | } |
2188 | c3d2689d | balrog | if (diff & (3 << 0)) { /* PERDIV */ |
2189 | c3d2689d | balrog | clk = omap_findclk(s, "armper_ck");
|
2190 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1); |
2191 | c3d2689d | balrog | } |
2192 | c3d2689d | balrog | } |
2193 | c3d2689d | balrog | |
2194 | c3d2689d | balrog | static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s, |
2195 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2196 | c3d2689d | balrog | { |
2197 | c3d2689d | balrog | omap_clk clk; |
2198 | c3d2689d | balrog | |
2199 | c3d2689d | balrog | if (value & (1 << 11)) /* SETARM_IDLE */ |
2200 | c3d2689d | balrog | cpu_interrupt(s->env, CPU_INTERRUPT_HALT); |
2201 | c3d2689d | balrog | if (!(value & (1 << 10))) /* WKUP_MODE */ |
2202 | c3d2689d | balrog | qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
|
2203 | c3d2689d | balrog | |
2204 | c3d2689d | balrog | #define SET_CANIDLE(clock, bit) \
|
2205 | c3d2689d | balrog | if (diff & (1 << bit)) { \ |
2206 | c3d2689d | balrog | clk = omap_findclk(s, clock); \ |
2207 | c3d2689d | balrog | omap_clk_canidle(clk, (value >> bit) & 1); \
|
2208 | c3d2689d | balrog | } |
2209 | c3d2689d | balrog | SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */ |
2210 | c3d2689d | balrog | SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */ |
2211 | c3d2689d | balrog | SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */ |
2212 | c3d2689d | balrog | SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */ |
2213 | c3d2689d | balrog | SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */ |
2214 | c3d2689d | balrog | SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */ |
2215 | c3d2689d | balrog | SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */ |
2216 | c3d2689d | balrog | SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */ |
2217 | c3d2689d | balrog | SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */ |
2218 | c3d2689d | balrog | SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */ |
2219 | c3d2689d | balrog | SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */ |
2220 | c3d2689d | balrog | SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */ |
2221 | c3d2689d | balrog | SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */ |
2222 | c3d2689d | balrog | SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */ |
2223 | c3d2689d | balrog | } |
2224 | c3d2689d | balrog | |
2225 | c3d2689d | balrog | static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s, |
2226 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2227 | c3d2689d | balrog | { |
2228 | c3d2689d | balrog | omap_clk clk; |
2229 | c3d2689d | balrog | |
2230 | c3d2689d | balrog | #define SET_ONOFF(clock, bit) \
|
2231 | c3d2689d | balrog | if (diff & (1 << bit)) { \ |
2232 | c3d2689d | balrog | clk = omap_findclk(s, clock); \ |
2233 | c3d2689d | balrog | omap_clk_onoff(clk, (value >> bit) & 1); \
|
2234 | c3d2689d | balrog | } |
2235 | c3d2689d | balrog | SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */ |
2236 | c3d2689d | balrog | SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */ |
2237 | c3d2689d | balrog | SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */ |
2238 | c3d2689d | balrog | SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */ |
2239 | c3d2689d | balrog | SET_ONOFF("lb_ck", 4) /* EN_LBCK */ |
2240 | c3d2689d | balrog | SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */ |
2241 | c3d2689d | balrog | SET_ONOFF("mpui_ck", 6) /* EN_APICK */ |
2242 | c3d2689d | balrog | SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */ |
2243 | c3d2689d | balrog | SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */ |
2244 | c3d2689d | balrog | SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */ |
2245 | c3d2689d | balrog | SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */ |
2246 | c3d2689d | balrog | } |
2247 | c3d2689d | balrog | |
2248 | c3d2689d | balrog | static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s, |
2249 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2250 | c3d2689d | balrog | { |
2251 | c3d2689d | balrog | omap_clk clk; |
2252 | c3d2689d | balrog | |
2253 | c3d2689d | balrog | if (diff & (3 << 4)) { /* TCLKOUT */ |
2254 | c3d2689d | balrog | clk = omap_findclk(s, "tclk_out");
|
2255 | c3d2689d | balrog | switch ((value >> 4) & 3) { |
2256 | c3d2689d | balrog | case 1: |
2257 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
|
2258 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2259 | c3d2689d | balrog | break;
|
2260 | c3d2689d | balrog | case 2: |
2261 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
|
2262 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2263 | c3d2689d | balrog | break;
|
2264 | c3d2689d | balrog | default:
|
2265 | c3d2689d | balrog | omap_clk_onoff(clk, 0);
|
2266 | c3d2689d | balrog | } |
2267 | c3d2689d | balrog | } |
2268 | c3d2689d | balrog | if (diff & (3 << 2)) { /* DCLKOUT */ |
2269 | c3d2689d | balrog | clk = omap_findclk(s, "dclk_out");
|
2270 | c3d2689d | balrog | switch ((value >> 2) & 3) { |
2271 | c3d2689d | balrog | case 0: |
2272 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
|
2273 | c3d2689d | balrog | break;
|
2274 | c3d2689d | balrog | case 1: |
2275 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
|
2276 | c3d2689d | balrog | break;
|
2277 | c3d2689d | balrog | case 2: |
2278 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
|
2279 | c3d2689d | balrog | break;
|
2280 | c3d2689d | balrog | case 3: |
2281 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
|
2282 | c3d2689d | balrog | break;
|
2283 | c3d2689d | balrog | } |
2284 | c3d2689d | balrog | } |
2285 | c3d2689d | balrog | if (diff & (3 << 0)) { /* ACLKOUT */ |
2286 | c3d2689d | balrog | clk = omap_findclk(s, "aclk_out");
|
2287 | c3d2689d | balrog | switch ((value >> 0) & 3) { |
2288 | c3d2689d | balrog | case 1: |
2289 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
|
2290 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2291 | c3d2689d | balrog | break;
|
2292 | c3d2689d | balrog | case 2: |
2293 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
|
2294 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2295 | c3d2689d | balrog | break;
|
2296 | c3d2689d | balrog | case 3: |
2297 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
|
2298 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2299 | c3d2689d | balrog | break;
|
2300 | c3d2689d | balrog | default:
|
2301 | c3d2689d | balrog | omap_clk_onoff(clk, 0);
|
2302 | c3d2689d | balrog | } |
2303 | c3d2689d | balrog | } |
2304 | c3d2689d | balrog | } |
2305 | c3d2689d | balrog | |
2306 | c227f099 | Anthony Liguori | static void omap_clkm_write(void *opaque, target_phys_addr_t addr, |
2307 | c3d2689d | balrog | uint32_t value) |
2308 | c3d2689d | balrog | { |
2309 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2310 | c3d2689d | balrog | uint16_t diff; |
2311 | c3d2689d | balrog | omap_clk clk; |
2312 | c3d2689d | balrog | static const char *clkschemename[8] = { |
2313 | c3d2689d | balrog | "fully synchronous", "fully asynchronous", "synchronous scalable", |
2314 | c3d2689d | balrog | "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4", |
2315 | c3d2689d | balrog | }; |
2316 | c3d2689d | balrog | |
2317 | 8da3ff18 | pbrook | switch (addr) {
|
2318 | c3d2689d | balrog | case 0x00: /* ARM_CKCTL */ |
2319 | c3d2689d | balrog | diff = s->clkm.arm_ckctl ^ value; |
2320 | c3d2689d | balrog | s->clkm.arm_ckctl = value & 0x7fff;
|
2321 | c3d2689d | balrog | omap_clkm_ckctl_update(s, diff, value); |
2322 | c3d2689d | balrog | return;
|
2323 | c3d2689d | balrog | |
2324 | c3d2689d | balrog | case 0x04: /* ARM_IDLECT1 */ |
2325 | c3d2689d | balrog | diff = s->clkm.arm_idlect1 ^ value; |
2326 | c3d2689d | balrog | s->clkm.arm_idlect1 = value & 0x0fff;
|
2327 | c3d2689d | balrog | omap_clkm_idlect1_update(s, diff, value); |
2328 | c3d2689d | balrog | return;
|
2329 | c3d2689d | balrog | |
2330 | c3d2689d | balrog | case 0x08: /* ARM_IDLECT2 */ |
2331 | c3d2689d | balrog | diff = s->clkm.arm_idlect2 ^ value; |
2332 | c3d2689d | balrog | s->clkm.arm_idlect2 = value & 0x07ff;
|
2333 | c3d2689d | balrog | omap_clkm_idlect2_update(s, diff, value); |
2334 | c3d2689d | balrog | return;
|
2335 | c3d2689d | balrog | |
2336 | c3d2689d | balrog | case 0x0c: /* ARM_EWUPCT */ |
2337 | c3d2689d | balrog | diff = s->clkm.arm_ewupct ^ value; |
2338 | c3d2689d | balrog | s->clkm.arm_ewupct = value & 0x003f;
|
2339 | c3d2689d | balrog | return;
|
2340 | c3d2689d | balrog | |
2341 | c3d2689d | balrog | case 0x10: /* ARM_RSTCT1 */ |
2342 | c3d2689d | balrog | diff = s->clkm.arm_rstct1 ^ value; |
2343 | c3d2689d | balrog | s->clkm.arm_rstct1 = value & 0x0007;
|
2344 | c3d2689d | balrog | if (value & 9) { |
2345 | c3d2689d | balrog | qemu_system_reset_request(); |
2346 | c3d2689d | balrog | s->clkm.cold_start = 0xa;
|
2347 | c3d2689d | balrog | } |
2348 | c3d2689d | balrog | if (diff & ~value & 4) { /* DSP_RST */ |
2349 | c3d2689d | balrog | omap_mpui_reset(s); |
2350 | c3d2689d | balrog | omap_tipb_bridge_reset(s->private_tipb); |
2351 | c3d2689d | balrog | omap_tipb_bridge_reset(s->public_tipb); |
2352 | c3d2689d | balrog | } |
2353 | c3d2689d | balrog | if (diff & 2) { /* DSP_EN */ |
2354 | c3d2689d | balrog | clk = omap_findclk(s, "dsp_ck");
|
2355 | c3d2689d | balrog | omap_clk_canidle(clk, (~value >> 1) & 1); |
2356 | c3d2689d | balrog | } |
2357 | c3d2689d | balrog | return;
|
2358 | c3d2689d | balrog | |
2359 | c3d2689d | balrog | case 0x14: /* ARM_RSTCT2 */ |
2360 | c3d2689d | balrog | s->clkm.arm_rstct2 = value & 0x0001;
|
2361 | c3d2689d | balrog | return;
|
2362 | c3d2689d | balrog | |
2363 | c3d2689d | balrog | case 0x18: /* ARM_SYSST */ |
2364 | c3d2689d | balrog | if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) { |
2365 | c3d2689d | balrog | s->clkm.clocking_scheme = (value >> 11) & 7; |
2366 | c3d2689d | balrog | printf("%s: clocking scheme set to %s\n", __FUNCTION__,
|
2367 | c3d2689d | balrog | clkschemename[s->clkm.clocking_scheme]); |
2368 | c3d2689d | balrog | } |
2369 | c3d2689d | balrog | s->clkm.cold_start &= value & 0x3f;
|
2370 | c3d2689d | balrog | return;
|
2371 | c3d2689d | balrog | |
2372 | c3d2689d | balrog | case 0x1c: /* ARM_CKOUT1 */ |
2373 | c3d2689d | balrog | diff = s->clkm.arm_ckout1 ^ value; |
2374 | c3d2689d | balrog | s->clkm.arm_ckout1 = value & 0x003f;
|
2375 | c3d2689d | balrog | omap_clkm_ckout1_update(s, diff, value); |
2376 | c3d2689d | balrog | return;
|
2377 | c3d2689d | balrog | |
2378 | c3d2689d | balrog | case 0x20: /* ARM_CKOUT2 */ |
2379 | c3d2689d | balrog | default:
|
2380 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2381 | c3d2689d | balrog | } |
2382 | c3d2689d | balrog | } |
2383 | c3d2689d | balrog | |
2384 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_clkm_readfn[] = { |
2385 | c3d2689d | balrog | omap_badwidth_read16, |
2386 | c3d2689d | balrog | omap_clkm_read, |
2387 | c3d2689d | balrog | omap_badwidth_read16, |
2388 | c3d2689d | balrog | }; |
2389 | c3d2689d | balrog | |
2390 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_clkm_writefn[] = { |
2391 | c3d2689d | balrog | omap_badwidth_write16, |
2392 | c3d2689d | balrog | omap_clkm_write, |
2393 | c3d2689d | balrog | omap_badwidth_write16, |
2394 | c3d2689d | balrog | }; |
2395 | c3d2689d | balrog | |
2396 | c227f099 | Anthony Liguori | static uint32_t omap_clkdsp_read(void *opaque, target_phys_addr_t addr) |
2397 | c3d2689d | balrog | { |
2398 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2399 | c3d2689d | balrog | |
2400 | 8da3ff18 | pbrook | switch (addr) {
|
2401 | c3d2689d | balrog | case 0x04: /* DSP_IDLECT1 */ |
2402 | c3d2689d | balrog | return s->clkm.dsp_idlect1;
|
2403 | c3d2689d | balrog | |
2404 | c3d2689d | balrog | case 0x08: /* DSP_IDLECT2 */ |
2405 | c3d2689d | balrog | return s->clkm.dsp_idlect2;
|
2406 | c3d2689d | balrog | |
2407 | c3d2689d | balrog | case 0x14: /* DSP_RSTCT2 */ |
2408 | c3d2689d | balrog | return s->clkm.dsp_rstct2;
|
2409 | c3d2689d | balrog | |
2410 | c3d2689d | balrog | case 0x18: /* DSP_SYSST */ |
2411 | d8f699cb | balrog | return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start | |
2412 | c3d2689d | balrog | (s->env->halted << 6); /* Quite useless... */ |
2413 | c3d2689d | balrog | } |
2414 | c3d2689d | balrog | |
2415 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2416 | c3d2689d | balrog | return 0; |
2417 | c3d2689d | balrog | } |
2418 | c3d2689d | balrog | |
2419 | c3d2689d | balrog | static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s, |
2420 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2421 | c3d2689d | balrog | { |
2422 | c3d2689d | balrog | omap_clk clk; |
2423 | c3d2689d | balrog | |
2424 | c3d2689d | balrog | SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */ |
2425 | c3d2689d | balrog | } |
2426 | c3d2689d | balrog | |
2427 | c3d2689d | balrog | static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s, |
2428 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2429 | c3d2689d | balrog | { |
2430 | c3d2689d | balrog | omap_clk clk; |
2431 | c3d2689d | balrog | |
2432 | c3d2689d | balrog | SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */ |
2433 | c3d2689d | balrog | } |
2434 | c3d2689d | balrog | |
2435 | c227f099 | Anthony Liguori | static void omap_clkdsp_write(void *opaque, target_phys_addr_t addr, |
2436 | c3d2689d | balrog | uint32_t value) |
2437 | c3d2689d | balrog | { |
2438 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2439 | c3d2689d | balrog | uint16_t diff; |
2440 | c3d2689d | balrog | |
2441 | 8da3ff18 | pbrook | switch (addr) {
|
2442 | c3d2689d | balrog | case 0x04: /* DSP_IDLECT1 */ |
2443 | c3d2689d | balrog | diff = s->clkm.dsp_idlect1 ^ value; |
2444 | c3d2689d | balrog | s->clkm.dsp_idlect1 = value & 0x01f7;
|
2445 | c3d2689d | balrog | omap_clkdsp_idlect1_update(s, diff, value); |
2446 | c3d2689d | balrog | break;
|
2447 | c3d2689d | balrog | |
2448 | c3d2689d | balrog | case 0x08: /* DSP_IDLECT2 */ |
2449 | c3d2689d | balrog | s->clkm.dsp_idlect2 = value & 0x0037;
|
2450 | c3d2689d | balrog | diff = s->clkm.dsp_idlect1 ^ value; |
2451 | c3d2689d | balrog | omap_clkdsp_idlect2_update(s, diff, value); |
2452 | c3d2689d | balrog | break;
|
2453 | c3d2689d | balrog | |
2454 | c3d2689d | balrog | case 0x14: /* DSP_RSTCT2 */ |
2455 | c3d2689d | balrog | s->clkm.dsp_rstct2 = value & 0x0001;
|
2456 | c3d2689d | balrog | break;
|
2457 | c3d2689d | balrog | |
2458 | c3d2689d | balrog | case 0x18: /* DSP_SYSST */ |
2459 | c3d2689d | balrog | s->clkm.cold_start &= value & 0x3f;
|
2460 | c3d2689d | balrog | break;
|
2461 | c3d2689d | balrog | |
2462 | c3d2689d | balrog | default:
|
2463 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2464 | c3d2689d | balrog | } |
2465 | c3d2689d | balrog | } |
2466 | c3d2689d | balrog | |
2467 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_clkdsp_readfn[] = { |
2468 | c3d2689d | balrog | omap_badwidth_read16, |
2469 | c3d2689d | balrog | omap_clkdsp_read, |
2470 | c3d2689d | balrog | omap_badwidth_read16, |
2471 | c3d2689d | balrog | }; |
2472 | c3d2689d | balrog | |
2473 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_clkdsp_writefn[] = { |
2474 | c3d2689d | balrog | omap_badwidth_write16, |
2475 | c3d2689d | balrog | omap_clkdsp_write, |
2476 | c3d2689d | balrog | omap_badwidth_write16, |
2477 | c3d2689d | balrog | }; |
2478 | c3d2689d | balrog | |
2479 | c3d2689d | balrog | static void omap_clkm_reset(struct omap_mpu_state_s *s) |
2480 | c3d2689d | balrog | { |
2481 | c3d2689d | balrog | if (s->wdt && s->wdt->reset)
|
2482 | c3d2689d | balrog | s->clkm.cold_start = 0x6;
|
2483 | c3d2689d | balrog | s->clkm.clocking_scheme = 0;
|
2484 | c3d2689d | balrog | omap_clkm_ckctl_update(s, ~0, 0x3000); |
2485 | c3d2689d | balrog | s->clkm.arm_ckctl = 0x3000;
|
2486 | d8f699cb | balrog | omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 ^ 0x0400, 0x0400); |
2487 | c3d2689d | balrog | s->clkm.arm_idlect1 = 0x0400;
|
2488 | d8f699cb | balrog | omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 ^ 0x0100, 0x0100); |
2489 | c3d2689d | balrog | s->clkm.arm_idlect2 = 0x0100;
|
2490 | c3d2689d | balrog | s->clkm.arm_ewupct = 0x003f;
|
2491 | c3d2689d | balrog | s->clkm.arm_rstct1 = 0x0000;
|
2492 | c3d2689d | balrog | s->clkm.arm_rstct2 = 0x0000;
|
2493 | c3d2689d | balrog | s->clkm.arm_ckout1 = 0x0015;
|
2494 | c3d2689d | balrog | s->clkm.dpll1_mode = 0x2002;
|
2495 | c3d2689d | balrog | omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040); |
2496 | c3d2689d | balrog | s->clkm.dsp_idlect1 = 0x0040;
|
2497 | c3d2689d | balrog | omap_clkdsp_idlect2_update(s, ~0, 0x0000); |
2498 | c3d2689d | balrog | s->clkm.dsp_idlect2 = 0x0000;
|
2499 | c3d2689d | balrog | s->clkm.dsp_rstct2 = 0x0000;
|
2500 | c3d2689d | balrog | } |
2501 | c3d2689d | balrog | |
2502 | c227f099 | Anthony Liguori | static void omap_clkm_init(target_phys_addr_t mpu_base, |
2503 | c227f099 | Anthony Liguori | target_phys_addr_t dsp_base, struct omap_mpu_state_s *s)
|
2504 | c3d2689d | balrog | { |
2505 | c3d2689d | balrog | int iomemtype[2] = { |
2506 | 1eed09cb | Avi Kivity | cpu_register_io_memory(omap_clkm_readfn, omap_clkm_writefn, s), |
2507 | 1eed09cb | Avi Kivity | cpu_register_io_memory(omap_clkdsp_readfn, omap_clkdsp_writefn, s), |
2508 | c3d2689d | balrog | }; |
2509 | c3d2689d | balrog | |
2510 | d8f699cb | balrog | s->clkm.arm_idlect1 = 0x03ff;
|
2511 | d8f699cb | balrog | s->clkm.arm_idlect2 = 0x0100;
|
2512 | d8f699cb | balrog | s->clkm.dsp_idlect1 = 0x0002;
|
2513 | c3d2689d | balrog | omap_clkm_reset(s); |
2514 | d8f699cb | balrog | s->clkm.cold_start = 0x3a;
|
2515 | c3d2689d | balrog | |
2516 | 8da3ff18 | pbrook | cpu_register_physical_memory(mpu_base, 0x100, iomemtype[0]); |
2517 | 8da3ff18 | pbrook | cpu_register_physical_memory(dsp_base, 0x1000, iomemtype[1]); |
2518 | c3d2689d | balrog | } |
2519 | c3d2689d | balrog | |
2520 | fe71e81a | balrog | /* MPU I/O */
|
2521 | fe71e81a | balrog | struct omap_mpuio_s {
|
2522 | fe71e81a | balrog | qemu_irq irq; |
2523 | fe71e81a | balrog | qemu_irq kbd_irq; |
2524 | fe71e81a | balrog | qemu_irq *in; |
2525 | fe71e81a | balrog | qemu_irq handler[16];
|
2526 | fe71e81a | balrog | qemu_irq wakeup; |
2527 | fe71e81a | balrog | |
2528 | fe71e81a | balrog | uint16_t inputs; |
2529 | fe71e81a | balrog | uint16_t outputs; |
2530 | fe71e81a | balrog | uint16_t dir; |
2531 | fe71e81a | balrog | uint16_t edge; |
2532 | fe71e81a | balrog | uint16_t mask; |
2533 | fe71e81a | balrog | uint16_t ints; |
2534 | fe71e81a | balrog | |
2535 | fe71e81a | balrog | uint16_t debounce; |
2536 | fe71e81a | balrog | uint16_t latch; |
2537 | fe71e81a | balrog | uint8_t event; |
2538 | fe71e81a | balrog | |
2539 | fe71e81a | balrog | uint8_t buttons[5];
|
2540 | fe71e81a | balrog | uint8_t row_latch; |
2541 | fe71e81a | balrog | uint8_t cols; |
2542 | fe71e81a | balrog | int kbd_mask;
|
2543 | fe71e81a | balrog | int clk;
|
2544 | fe71e81a | balrog | }; |
2545 | fe71e81a | balrog | |
2546 | fe71e81a | balrog | static void omap_mpuio_set(void *opaque, int line, int level) |
2547 | fe71e81a | balrog | { |
2548 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
2549 | fe71e81a | balrog | uint16_t prev = s->inputs; |
2550 | fe71e81a | balrog | |
2551 | fe71e81a | balrog | if (level)
|
2552 | fe71e81a | balrog | s->inputs |= 1 << line;
|
2553 | fe71e81a | balrog | else
|
2554 | fe71e81a | balrog | s->inputs &= ~(1 << line);
|
2555 | fe71e81a | balrog | |
2556 | fe71e81a | balrog | if (((1 << line) & s->dir & ~s->mask) && s->clk) { |
2557 | fe71e81a | balrog | if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
|
2558 | fe71e81a | balrog | s->ints |= 1 << line;
|
2559 | fe71e81a | balrog | qemu_irq_raise(s->irq); |
2560 | fe71e81a | balrog | /* TODO: wakeup */
|
2561 | fe71e81a | balrog | } |
2562 | fe71e81a | balrog | if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */ |
2563 | fe71e81a | balrog | (s->event >> 1) == line) /* PIN_SELECT */ |
2564 | fe71e81a | balrog | s->latch = s->inputs; |
2565 | fe71e81a | balrog | } |
2566 | fe71e81a | balrog | } |
2567 | fe71e81a | balrog | |
2568 | fe71e81a | balrog | static void omap_mpuio_kbd_update(struct omap_mpuio_s *s) |
2569 | fe71e81a | balrog | { |
2570 | fe71e81a | balrog | int i;
|
2571 | fe71e81a | balrog | uint8_t *row, rows = 0, cols = ~s->cols;
|
2572 | fe71e81a | balrog | |
2573 | 38a34e1d | balrog | for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1) |
2574 | fe71e81a | balrog | if (*row & cols)
|
2575 | 38a34e1d | balrog | rows |= i; |
2576 | fe71e81a | balrog | |
2577 | cf6d9118 | balrog | qemu_set_irq(s->kbd_irq, rows && !s->kbd_mask && s->clk); |
2578 | cf6d9118 | balrog | s->row_latch = ~rows; |
2579 | fe71e81a | balrog | } |
2580 | fe71e81a | balrog | |
2581 | c227f099 | Anthony Liguori | static uint32_t omap_mpuio_read(void *opaque, target_phys_addr_t addr) |
2582 | fe71e81a | balrog | { |
2583 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
2584 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
2585 | fe71e81a | balrog | uint16_t ret; |
2586 | fe71e81a | balrog | |
2587 | fe71e81a | balrog | switch (offset) {
|
2588 | fe71e81a | balrog | case 0x00: /* INPUT_LATCH */ |
2589 | fe71e81a | balrog | return s->inputs;
|
2590 | fe71e81a | balrog | |
2591 | fe71e81a | balrog | case 0x04: /* OUTPUT_REG */ |
2592 | fe71e81a | balrog | return s->outputs;
|
2593 | fe71e81a | balrog | |
2594 | fe71e81a | balrog | case 0x08: /* IO_CNTL */ |
2595 | fe71e81a | balrog | return s->dir;
|
2596 | fe71e81a | balrog | |
2597 | fe71e81a | balrog | case 0x10: /* KBR_LATCH */ |
2598 | fe71e81a | balrog | return s->row_latch;
|
2599 | fe71e81a | balrog | |
2600 | fe71e81a | balrog | case 0x14: /* KBC_REG */ |
2601 | fe71e81a | balrog | return s->cols;
|
2602 | fe71e81a | balrog | |
2603 | fe71e81a | balrog | case 0x18: /* GPIO_EVENT_MODE_REG */ |
2604 | fe71e81a | balrog | return s->event;
|
2605 | fe71e81a | balrog | |
2606 | fe71e81a | balrog | case 0x1c: /* GPIO_INT_EDGE_REG */ |
2607 | fe71e81a | balrog | return s->edge;
|
2608 | fe71e81a | balrog | |
2609 | fe71e81a | balrog | case 0x20: /* KBD_INT */ |
2610 | cf6d9118 | balrog | return (~s->row_latch & 0x1f) && !s->kbd_mask; |
2611 | fe71e81a | balrog | |
2612 | fe71e81a | balrog | case 0x24: /* GPIO_INT */ |
2613 | fe71e81a | balrog | ret = s->ints; |
2614 | 8e129e07 | balrog | s->ints &= s->mask; |
2615 | 8e129e07 | balrog | if (ret)
|
2616 | 8e129e07 | balrog | qemu_irq_lower(s->irq); |
2617 | fe71e81a | balrog | return ret;
|
2618 | fe71e81a | balrog | |
2619 | fe71e81a | balrog | case 0x28: /* KBD_MASKIT */ |
2620 | fe71e81a | balrog | return s->kbd_mask;
|
2621 | fe71e81a | balrog | |
2622 | fe71e81a | balrog | case 0x2c: /* GPIO_MASKIT */ |
2623 | fe71e81a | balrog | return s->mask;
|
2624 | fe71e81a | balrog | |
2625 | fe71e81a | balrog | case 0x30: /* GPIO_DEBOUNCING_REG */ |
2626 | fe71e81a | balrog | return s->debounce;
|
2627 | fe71e81a | balrog | |
2628 | fe71e81a | balrog | case 0x34: /* GPIO_LATCH_REG */ |
2629 | fe71e81a | balrog | return s->latch;
|
2630 | fe71e81a | balrog | } |
2631 | fe71e81a | balrog | |
2632 | fe71e81a | balrog | OMAP_BAD_REG(addr); |
2633 | fe71e81a | balrog | return 0; |
2634 | fe71e81a | balrog | } |
2635 | fe71e81a | balrog | |
2636 | c227f099 | Anthony Liguori | static void omap_mpuio_write(void *opaque, target_phys_addr_t addr, |
2637 | fe71e81a | balrog | uint32_t value) |
2638 | fe71e81a | balrog | { |
2639 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
2640 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
2641 | fe71e81a | balrog | uint16_t diff; |
2642 | fe71e81a | balrog | int ln;
|
2643 | fe71e81a | balrog | |
2644 | fe71e81a | balrog | switch (offset) {
|
2645 | fe71e81a | balrog | case 0x04: /* OUTPUT_REG */ |
2646 | d8f699cb | balrog | diff = (s->outputs ^ value) & ~s->dir; |
2647 | fe71e81a | balrog | s->outputs = value; |
2648 | fe71e81a | balrog | while ((ln = ffs(diff))) {
|
2649 | fe71e81a | balrog | ln --; |
2650 | fe71e81a | balrog | if (s->handler[ln])
|
2651 | fe71e81a | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
2652 | fe71e81a | balrog | diff &= ~(1 << ln);
|
2653 | fe71e81a | balrog | } |
2654 | fe71e81a | balrog | break;
|
2655 | fe71e81a | balrog | |
2656 | fe71e81a | balrog | case 0x08: /* IO_CNTL */ |
2657 | fe71e81a | balrog | diff = s->outputs & (s->dir ^ value); |
2658 | fe71e81a | balrog | s->dir = value; |
2659 | fe71e81a | balrog | |
2660 | fe71e81a | balrog | value = s->outputs & ~s->dir; |
2661 | fe71e81a | balrog | while ((ln = ffs(diff))) {
|
2662 | fe71e81a | balrog | ln --; |
2663 | fe71e81a | balrog | if (s->handler[ln])
|
2664 | fe71e81a | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
2665 | fe71e81a | balrog | diff &= ~(1 << ln);
|
2666 | fe71e81a | balrog | } |
2667 | fe71e81a | balrog | break;
|
2668 | fe71e81a | balrog | |
2669 | fe71e81a | balrog | case 0x14: /* KBC_REG */ |
2670 | fe71e81a | balrog | s->cols = value; |
2671 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
2672 | fe71e81a | balrog | break;
|
2673 | fe71e81a | balrog | |
2674 | fe71e81a | balrog | case 0x18: /* GPIO_EVENT_MODE_REG */ |
2675 | fe71e81a | balrog | s->event = value & 0x1f;
|
2676 | fe71e81a | balrog | break;
|
2677 | fe71e81a | balrog | |
2678 | fe71e81a | balrog | case 0x1c: /* GPIO_INT_EDGE_REG */ |
2679 | fe71e81a | balrog | s->edge = value; |
2680 | fe71e81a | balrog | break;
|
2681 | fe71e81a | balrog | |
2682 | fe71e81a | balrog | case 0x28: /* KBD_MASKIT */ |
2683 | fe71e81a | balrog | s->kbd_mask = value & 1;
|
2684 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
2685 | fe71e81a | balrog | break;
|
2686 | fe71e81a | balrog | |
2687 | fe71e81a | balrog | case 0x2c: /* GPIO_MASKIT */ |
2688 | fe71e81a | balrog | s->mask = value; |
2689 | fe71e81a | balrog | break;
|
2690 | fe71e81a | balrog | |
2691 | fe71e81a | balrog | case 0x30: /* GPIO_DEBOUNCING_REG */ |
2692 | fe71e81a | balrog | s->debounce = value & 0x1ff;
|
2693 | fe71e81a | balrog | break;
|
2694 | fe71e81a | balrog | |
2695 | fe71e81a | balrog | case 0x00: /* INPUT_LATCH */ |
2696 | fe71e81a | balrog | case 0x10: /* KBR_LATCH */ |
2697 | fe71e81a | balrog | case 0x20: /* KBD_INT */ |
2698 | fe71e81a | balrog | case 0x24: /* GPIO_INT */ |
2699 | fe71e81a | balrog | case 0x34: /* GPIO_LATCH_REG */ |
2700 | fe71e81a | balrog | OMAP_RO_REG(addr); |
2701 | fe71e81a | balrog | return;
|
2702 | fe71e81a | balrog | |
2703 | fe71e81a | balrog | default:
|
2704 | fe71e81a | balrog | OMAP_BAD_REG(addr); |
2705 | fe71e81a | balrog | return;
|
2706 | fe71e81a | balrog | } |
2707 | fe71e81a | balrog | } |
2708 | fe71e81a | balrog | |
2709 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_mpuio_readfn[] = { |
2710 | fe71e81a | balrog | omap_badwidth_read16, |
2711 | fe71e81a | balrog | omap_mpuio_read, |
2712 | fe71e81a | balrog | omap_badwidth_read16, |
2713 | fe71e81a | balrog | }; |
2714 | fe71e81a | balrog | |
2715 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_mpuio_writefn[] = { |
2716 | fe71e81a | balrog | omap_badwidth_write16, |
2717 | fe71e81a | balrog | omap_mpuio_write, |
2718 | fe71e81a | balrog | omap_badwidth_write16, |
2719 | fe71e81a | balrog | }; |
2720 | fe71e81a | balrog | |
2721 | 9596ebb7 | pbrook | static void omap_mpuio_reset(struct omap_mpuio_s *s) |
2722 | fe71e81a | balrog | { |
2723 | fe71e81a | balrog | s->inputs = 0;
|
2724 | fe71e81a | balrog | s->outputs = 0;
|
2725 | fe71e81a | balrog | s->dir = ~0;
|
2726 | fe71e81a | balrog | s->event = 0;
|
2727 | fe71e81a | balrog | s->edge = 0;
|
2728 | fe71e81a | balrog | s->kbd_mask = 0;
|
2729 | fe71e81a | balrog | s->mask = 0;
|
2730 | fe71e81a | balrog | s->debounce = 0;
|
2731 | fe71e81a | balrog | s->latch = 0;
|
2732 | fe71e81a | balrog | s->ints = 0;
|
2733 | fe71e81a | balrog | s->row_latch = 0x1f;
|
2734 | 38a34e1d | balrog | s->clk = 1;
|
2735 | fe71e81a | balrog | } |
2736 | fe71e81a | balrog | |
2737 | fe71e81a | balrog | static void omap_mpuio_onoff(void *opaque, int line, int on) |
2738 | fe71e81a | balrog | { |
2739 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
2740 | fe71e81a | balrog | |
2741 | fe71e81a | balrog | s->clk = on; |
2742 | fe71e81a | balrog | if (on)
|
2743 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
2744 | fe71e81a | balrog | } |
2745 | fe71e81a | balrog | |
2746 | c227f099 | Anthony Liguori | struct omap_mpuio_s *omap_mpuio_init(target_phys_addr_t base,
|
2747 | fe71e81a | balrog | qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup, |
2748 | fe71e81a | balrog | omap_clk clk) |
2749 | fe71e81a | balrog | { |
2750 | fe71e81a | balrog | int iomemtype;
|
2751 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) |
2752 | fe71e81a | balrog | qemu_mallocz(sizeof(struct omap_mpuio_s)); |
2753 | fe71e81a | balrog | |
2754 | fe71e81a | balrog | s->irq = gpio_int; |
2755 | fe71e81a | balrog | s->kbd_irq = kbd_int; |
2756 | fe71e81a | balrog | s->wakeup = wakeup; |
2757 | fe71e81a | balrog | s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
|
2758 | fe71e81a | balrog | omap_mpuio_reset(s); |
2759 | fe71e81a | balrog | |
2760 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_mpuio_readfn, |
2761 | fe71e81a | balrog | omap_mpuio_writefn, s); |
2762 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
2763 | fe71e81a | balrog | |
2764 | fe71e81a | balrog | omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]); |
2765 | fe71e81a | balrog | |
2766 | fe71e81a | balrog | return s;
|
2767 | fe71e81a | balrog | } |
2768 | fe71e81a | balrog | |
2769 | fe71e81a | balrog | qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
|
2770 | fe71e81a | balrog | { |
2771 | fe71e81a | balrog | return s->in;
|
2772 | fe71e81a | balrog | } |
2773 | fe71e81a | balrog | |
2774 | fe71e81a | balrog | void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler) |
2775 | fe71e81a | balrog | { |
2776 | fe71e81a | balrog | if (line >= 16 || line < 0) |
2777 | 2ac71179 | Paul Brook | hw_error("%s: No GPIO line %i\n", __FUNCTION__, line);
|
2778 | fe71e81a | balrog | s->handler[line] = handler; |
2779 | fe71e81a | balrog | } |
2780 | fe71e81a | balrog | |
2781 | fe71e81a | balrog | void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down) |
2782 | fe71e81a | balrog | { |
2783 | fe71e81a | balrog | if (row >= 5 || row < 0) |
2784 | 2ac71179 | Paul Brook | hw_error("%s: No key %i-%i\n", __FUNCTION__, col, row);
|
2785 | fe71e81a | balrog | |
2786 | fe71e81a | balrog | if (down)
|
2787 | 38a34e1d | balrog | s->buttons[row] |= 1 << col;
|
2788 | fe71e81a | balrog | else
|
2789 | 38a34e1d | balrog | s->buttons[row] &= ~(1 << col);
|
2790 | fe71e81a | balrog | |
2791 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
2792 | fe71e81a | balrog | } |
2793 | fe71e81a | balrog | |
2794 | 64330148 | balrog | /* General-Purpose I/O */
|
2795 | 64330148 | balrog | struct omap_gpio_s {
|
2796 | 64330148 | balrog | qemu_irq irq; |
2797 | 64330148 | balrog | qemu_irq *in; |
2798 | 64330148 | balrog | qemu_irq handler[16];
|
2799 | 64330148 | balrog | |
2800 | 64330148 | balrog | uint16_t inputs; |
2801 | 64330148 | balrog | uint16_t outputs; |
2802 | 64330148 | balrog | uint16_t dir; |
2803 | 64330148 | balrog | uint16_t edge; |
2804 | 64330148 | balrog | uint16_t mask; |
2805 | 64330148 | balrog | uint16_t ints; |
2806 | d8f699cb | balrog | uint16_t pins; |
2807 | 64330148 | balrog | }; |
2808 | 64330148 | balrog | |
2809 | 64330148 | balrog | static void omap_gpio_set(void *opaque, int line, int level) |
2810 | 64330148 | balrog | { |
2811 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; |
2812 | 64330148 | balrog | uint16_t prev = s->inputs; |
2813 | 64330148 | balrog | |
2814 | 64330148 | balrog | if (level)
|
2815 | 64330148 | balrog | s->inputs |= 1 << line;
|
2816 | 64330148 | balrog | else
|
2817 | 64330148 | balrog | s->inputs &= ~(1 << line);
|
2818 | 64330148 | balrog | |
2819 | 64330148 | balrog | if (((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) &
|
2820 | 64330148 | balrog | (1 << line) & s->dir & ~s->mask) {
|
2821 | 64330148 | balrog | s->ints |= 1 << line;
|
2822 | 64330148 | balrog | qemu_irq_raise(s->irq); |
2823 | 64330148 | balrog | } |
2824 | 64330148 | balrog | } |
2825 | 64330148 | balrog | |
2826 | c227f099 | Anthony Liguori | static uint32_t omap_gpio_read(void *opaque, target_phys_addr_t addr) |
2827 | 64330148 | balrog | { |
2828 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; |
2829 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
2830 | 64330148 | balrog | |
2831 | 64330148 | balrog | switch (offset) {
|
2832 | 64330148 | balrog | case 0x00: /* DATA_INPUT */ |
2833 | d8f699cb | balrog | return s->inputs & s->pins;
|
2834 | 64330148 | balrog | |
2835 | 64330148 | balrog | case 0x04: /* DATA_OUTPUT */ |
2836 | 64330148 | balrog | return s->outputs;
|
2837 | 64330148 | balrog | |
2838 | 64330148 | balrog | case 0x08: /* DIRECTION_CONTROL */ |
2839 | 64330148 | balrog | return s->dir;
|
2840 | 64330148 | balrog | |
2841 | 64330148 | balrog | case 0x0c: /* INTERRUPT_CONTROL */ |
2842 | 64330148 | balrog | return s->edge;
|
2843 | 64330148 | balrog | |
2844 | 64330148 | balrog | case 0x10: /* INTERRUPT_MASK */ |
2845 | 64330148 | balrog | return s->mask;
|
2846 | 64330148 | balrog | |
2847 | 64330148 | balrog | case 0x14: /* INTERRUPT_STATUS */ |
2848 | 64330148 | balrog | return s->ints;
|
2849 | d8f699cb | balrog | |
2850 | d8f699cb | balrog | case 0x18: /* PIN_CONTROL (not in OMAP310) */ |
2851 | d8f699cb | balrog | OMAP_BAD_REG(addr); |
2852 | d8f699cb | balrog | return s->pins;
|
2853 | 64330148 | balrog | } |
2854 | 64330148 | balrog | |
2855 | 64330148 | balrog | OMAP_BAD_REG(addr); |
2856 | 64330148 | balrog | return 0; |
2857 | 64330148 | balrog | } |
2858 | 64330148 | balrog | |
2859 | c227f099 | Anthony Liguori | static void omap_gpio_write(void *opaque, target_phys_addr_t addr, |
2860 | 64330148 | balrog | uint32_t value) |
2861 | 64330148 | balrog | { |
2862 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; |
2863 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
2864 | 64330148 | balrog | uint16_t diff; |
2865 | 64330148 | balrog | int ln;
|
2866 | 64330148 | balrog | |
2867 | 64330148 | balrog | switch (offset) {
|
2868 | 64330148 | balrog | case 0x00: /* DATA_INPUT */ |
2869 | 64330148 | balrog | OMAP_RO_REG(addr); |
2870 | 64330148 | balrog | return;
|
2871 | 64330148 | balrog | |
2872 | 64330148 | balrog | case 0x04: /* DATA_OUTPUT */ |
2873 | 66450b15 | balrog | diff = (s->outputs ^ value) & ~s->dir; |
2874 | 64330148 | balrog | s->outputs = value; |
2875 | 64330148 | balrog | while ((ln = ffs(diff))) {
|
2876 | 64330148 | balrog | ln --; |
2877 | 64330148 | balrog | if (s->handler[ln])
|
2878 | 64330148 | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
2879 | 64330148 | balrog | diff &= ~(1 << ln);
|
2880 | 64330148 | balrog | } |
2881 | 64330148 | balrog | break;
|
2882 | 64330148 | balrog | |
2883 | 64330148 | balrog | case 0x08: /* DIRECTION_CONTROL */ |
2884 | 64330148 | balrog | diff = s->outputs & (s->dir ^ value); |
2885 | 64330148 | balrog | s->dir = value; |
2886 | 64330148 | balrog | |
2887 | 64330148 | balrog | value = s->outputs & ~s->dir; |
2888 | 64330148 | balrog | while ((ln = ffs(diff))) {
|
2889 | 64330148 | balrog | ln --; |
2890 | 64330148 | balrog | if (s->handler[ln])
|
2891 | 64330148 | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
2892 | 64330148 | balrog | diff &= ~(1 << ln);
|
2893 | 64330148 | balrog | } |
2894 | 64330148 | balrog | break;
|
2895 | 64330148 | balrog | |
2896 | 64330148 | balrog | case 0x0c: /* INTERRUPT_CONTROL */ |
2897 | 64330148 | balrog | s->edge = value; |
2898 | 64330148 | balrog | break;
|
2899 | 64330148 | balrog | |
2900 | 64330148 | balrog | case 0x10: /* INTERRUPT_MASK */ |
2901 | 64330148 | balrog | s->mask = value; |
2902 | 64330148 | balrog | break;
|
2903 | 64330148 | balrog | |
2904 | 64330148 | balrog | case 0x14: /* INTERRUPT_STATUS */ |
2905 | 64330148 | balrog | s->ints &= ~value; |
2906 | 64330148 | balrog | if (!s->ints)
|
2907 | 64330148 | balrog | qemu_irq_lower(s->irq); |
2908 | 64330148 | balrog | break;
|
2909 | 64330148 | balrog | |
2910 | d8f699cb | balrog | case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */ |
2911 | d8f699cb | balrog | OMAP_BAD_REG(addr); |
2912 | d8f699cb | balrog | s->pins = value; |
2913 | d8f699cb | balrog | break;
|
2914 | d8f699cb | balrog | |
2915 | 64330148 | balrog | default:
|
2916 | 64330148 | balrog | OMAP_BAD_REG(addr); |
2917 | 64330148 | balrog | return;
|
2918 | 64330148 | balrog | } |
2919 | 64330148 | balrog | } |
2920 | 64330148 | balrog | |
2921 | 3efda49d | balrog | /* *Some* sources say the memory region is 32-bit. */
|
2922 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_gpio_readfn[] = { |
2923 | 3efda49d | balrog | omap_badwidth_read16, |
2924 | 64330148 | balrog | omap_gpio_read, |
2925 | 3efda49d | balrog | omap_badwidth_read16, |
2926 | 64330148 | balrog | }; |
2927 | 64330148 | balrog | |
2928 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_gpio_writefn[] = { |
2929 | 3efda49d | balrog | omap_badwidth_write16, |
2930 | 64330148 | balrog | omap_gpio_write, |
2931 | 3efda49d | balrog | omap_badwidth_write16, |
2932 | 64330148 | balrog | }; |
2933 | 64330148 | balrog | |
2934 | 9596ebb7 | pbrook | static void omap_gpio_reset(struct omap_gpio_s *s) |
2935 | 64330148 | balrog | { |
2936 | 64330148 | balrog | s->inputs = 0;
|
2937 | 64330148 | balrog | s->outputs = ~0;
|
2938 | 64330148 | balrog | s->dir = ~0;
|
2939 | 64330148 | balrog | s->edge = ~0;
|
2940 | 64330148 | balrog | s->mask = ~0;
|
2941 | 64330148 | balrog | s->ints = 0;
|
2942 | d8f699cb | balrog | s->pins = ~0;
|
2943 | 64330148 | balrog | } |
2944 | 64330148 | balrog | |
2945 | c227f099 | Anthony Liguori | struct omap_gpio_s *omap_gpio_init(target_phys_addr_t base,
|
2946 | 64330148 | balrog | qemu_irq irq, omap_clk clk) |
2947 | 64330148 | balrog | { |
2948 | 64330148 | balrog | int iomemtype;
|
2949 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) |
2950 | 64330148 | balrog | qemu_mallocz(sizeof(struct omap_gpio_s)); |
2951 | 64330148 | balrog | |
2952 | 64330148 | balrog | s->irq = irq; |
2953 | 64330148 | balrog | s->in = qemu_allocate_irqs(omap_gpio_set, s, 16);
|
2954 | 64330148 | balrog | omap_gpio_reset(s); |
2955 | 64330148 | balrog | |
2956 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_gpio_readfn, |
2957 | 64330148 | balrog | omap_gpio_writefn, s); |
2958 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x1000, iomemtype);
|
2959 | 64330148 | balrog | |
2960 | 64330148 | balrog | return s;
|
2961 | 64330148 | balrog | } |
2962 | 64330148 | balrog | |
2963 | 64330148 | balrog | qemu_irq *omap_gpio_in_get(struct omap_gpio_s *s)
|
2964 | 64330148 | balrog | { |
2965 | 64330148 | balrog | return s->in;
|
2966 | 64330148 | balrog | } |
2967 | 64330148 | balrog | |
2968 | 64330148 | balrog | void omap_gpio_out_set(struct omap_gpio_s *s, int line, qemu_irq handler) |
2969 | 64330148 | balrog | { |
2970 | 64330148 | balrog | if (line >= 16 || line < 0) |
2971 | 2ac71179 | Paul Brook | hw_error("%s: No GPIO line %i\n", __FUNCTION__, line);
|
2972 | 64330148 | balrog | s->handler[line] = handler; |
2973 | 64330148 | balrog | } |
2974 | 64330148 | balrog | |
2975 | d951f6ff | balrog | /* MicroWire Interface */
|
2976 | d951f6ff | balrog | struct omap_uwire_s {
|
2977 | d951f6ff | balrog | qemu_irq txirq; |
2978 | d951f6ff | balrog | qemu_irq rxirq; |
2979 | d951f6ff | balrog | qemu_irq txdrq; |
2980 | d951f6ff | balrog | |
2981 | d951f6ff | balrog | uint16_t txbuf; |
2982 | d951f6ff | balrog | uint16_t rxbuf; |
2983 | d951f6ff | balrog | uint16_t control; |
2984 | d951f6ff | balrog | uint16_t setup[5];
|
2985 | d951f6ff | balrog | |
2986 | bc24a225 | Paul Brook | uWireSlave *chip[4];
|
2987 | d951f6ff | balrog | }; |
2988 | d951f6ff | balrog | |
2989 | d951f6ff | balrog | static void omap_uwire_transfer_start(struct omap_uwire_s *s) |
2990 | d951f6ff | balrog | { |
2991 | d951f6ff | balrog | int chipselect = (s->control >> 10) & 3; /* INDEX */ |
2992 | bc24a225 | Paul Brook | uWireSlave *slave = s->chip[chipselect]; |
2993 | d951f6ff | balrog | |
2994 | d951f6ff | balrog | if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */ |
2995 | d951f6ff | balrog | if (s->control & (1 << 12)) /* CS_CMD */ |
2996 | d951f6ff | balrog | if (slave && slave->send)
|
2997 | d951f6ff | balrog | slave->send(slave->opaque, |
2998 | d951f6ff | balrog | s->txbuf >> (16 - ((s->control >> 5) & 0x1f))); |
2999 | d951f6ff | balrog | s->control &= ~(1 << 14); /* CSRB */ |
3000 | d951f6ff | balrog | /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
|
3001 | d951f6ff | balrog | * a DRQ. When is the level IRQ supposed to be reset? */
|
3002 | d951f6ff | balrog | } |
3003 | d951f6ff | balrog | |
3004 | d951f6ff | balrog | if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */ |
3005 | d951f6ff | balrog | if (s->control & (1 << 12)) /* CS_CMD */ |
3006 | d951f6ff | balrog | if (slave && slave->receive)
|
3007 | d951f6ff | balrog | s->rxbuf = slave->receive(slave->opaque); |
3008 | d951f6ff | balrog | s->control |= 1 << 15; /* RDRB */ |
3009 | d951f6ff | balrog | /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
|
3010 | d951f6ff | balrog | * a DRQ. When is the level IRQ supposed to be reset? */
|
3011 | d951f6ff | balrog | } |
3012 | d951f6ff | balrog | } |
3013 | d951f6ff | balrog | |
3014 | c227f099 | Anthony Liguori | static uint32_t omap_uwire_read(void *opaque, target_phys_addr_t addr) |
3015 | d951f6ff | balrog | { |
3016 | d951f6ff | balrog | struct omap_uwire_s *s = (struct omap_uwire_s *) opaque; |
3017 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3018 | d951f6ff | balrog | |
3019 | d951f6ff | balrog | switch (offset) {
|
3020 | d951f6ff | balrog | case 0x00: /* RDR */ |
3021 | d951f6ff | balrog | s->control &= ~(1 << 15); /* RDRB */ |
3022 | d951f6ff | balrog | return s->rxbuf;
|
3023 | d951f6ff | balrog | |
3024 | d951f6ff | balrog | case 0x04: /* CSR */ |
3025 | d951f6ff | balrog | return s->control;
|
3026 | d951f6ff | balrog | |
3027 | d951f6ff | balrog | case 0x08: /* SR1 */ |
3028 | d951f6ff | balrog | return s->setup[0]; |
3029 | d951f6ff | balrog | case 0x0c: /* SR2 */ |
3030 | d951f6ff | balrog | return s->setup[1]; |
3031 | d951f6ff | balrog | case 0x10: /* SR3 */ |
3032 | d951f6ff | balrog | return s->setup[2]; |
3033 | d951f6ff | balrog | case 0x14: /* SR4 */ |
3034 | d951f6ff | balrog | return s->setup[3]; |
3035 | d951f6ff | balrog | case 0x18: /* SR5 */ |
3036 | d951f6ff | balrog | return s->setup[4]; |
3037 | d951f6ff | balrog | } |
3038 | d951f6ff | balrog | |
3039 | d951f6ff | balrog | OMAP_BAD_REG(addr); |
3040 | d951f6ff | balrog | return 0; |
3041 | d951f6ff | balrog | } |
3042 | d951f6ff | balrog | |
3043 | c227f099 | Anthony Liguori | static void omap_uwire_write(void *opaque, target_phys_addr_t addr, |
3044 | d951f6ff | balrog | uint32_t value) |
3045 | d951f6ff | balrog | { |
3046 | d951f6ff | balrog | struct omap_uwire_s *s = (struct omap_uwire_s *) opaque; |
3047 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3048 | d951f6ff | balrog | |
3049 | d951f6ff | balrog | switch (offset) {
|
3050 | d951f6ff | balrog | case 0x00: /* TDR */ |
3051 | d951f6ff | balrog | s->txbuf = value; /* TD */
|
3052 | d951f6ff | balrog | if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */ |
3053 | d951f6ff | balrog | ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */ |
3054 | cf965d24 | balrog | (s->control & (1 << 12)))) { /* CS_CMD */ |
3055 | cf965d24 | balrog | s->control |= 1 << 14; /* CSRB */ |
3056 | d951f6ff | balrog | omap_uwire_transfer_start(s); |
3057 | cf965d24 | balrog | } |
3058 | d951f6ff | balrog | break;
|
3059 | d951f6ff | balrog | |
3060 | d951f6ff | balrog | case 0x04: /* CSR */ |
3061 | d951f6ff | balrog | s->control = value & 0x1fff;
|
3062 | d951f6ff | balrog | if (value & (1 << 13)) /* START */ |
3063 | d951f6ff | balrog | omap_uwire_transfer_start(s); |
3064 | d951f6ff | balrog | break;
|
3065 | d951f6ff | balrog | |
3066 | d951f6ff | balrog | case 0x08: /* SR1 */ |
3067 | d951f6ff | balrog | s->setup[0] = value & 0x003f; |
3068 | d951f6ff | balrog | break;
|
3069 | d951f6ff | balrog | |
3070 | d951f6ff | balrog | case 0x0c: /* SR2 */ |
3071 | d951f6ff | balrog | s->setup[1] = value & 0x0fc0; |
3072 | d951f6ff | balrog | break;
|
3073 | d951f6ff | balrog | |
3074 | d951f6ff | balrog | case 0x10: /* SR3 */ |
3075 | d951f6ff | balrog | s->setup[2] = value & 0x0003; |
3076 | d951f6ff | balrog | break;
|
3077 | d951f6ff | balrog | |
3078 | d951f6ff | balrog | case 0x14: /* SR4 */ |
3079 | d951f6ff | balrog | s->setup[3] = value & 0x0001; |
3080 | d951f6ff | balrog | break;
|
3081 | d951f6ff | balrog | |
3082 | d951f6ff | balrog | case 0x18: /* SR5 */ |
3083 | d951f6ff | balrog | s->setup[4] = value & 0x000f; |
3084 | d951f6ff | balrog | break;
|
3085 | d951f6ff | balrog | |
3086 | d951f6ff | balrog | default:
|
3087 | d951f6ff | balrog | OMAP_BAD_REG(addr); |
3088 | d951f6ff | balrog | return;
|
3089 | d951f6ff | balrog | } |
3090 | d951f6ff | balrog | } |
3091 | d951f6ff | balrog | |
3092 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_uwire_readfn[] = { |
3093 | d951f6ff | balrog | omap_badwidth_read16, |
3094 | d951f6ff | balrog | omap_uwire_read, |
3095 | d951f6ff | balrog | omap_badwidth_read16, |
3096 | d951f6ff | balrog | }; |
3097 | d951f6ff | balrog | |
3098 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_uwire_writefn[] = { |
3099 | d951f6ff | balrog | omap_badwidth_write16, |
3100 | d951f6ff | balrog | omap_uwire_write, |
3101 | d951f6ff | balrog | omap_badwidth_write16, |
3102 | d951f6ff | balrog | }; |
3103 | d951f6ff | balrog | |
3104 | 9596ebb7 | pbrook | static void omap_uwire_reset(struct omap_uwire_s *s) |
3105 | d951f6ff | balrog | { |
3106 | 66450b15 | balrog | s->control = 0;
|
3107 | d951f6ff | balrog | s->setup[0] = 0; |
3108 | d951f6ff | balrog | s->setup[1] = 0; |
3109 | d951f6ff | balrog | s->setup[2] = 0; |
3110 | d951f6ff | balrog | s->setup[3] = 0; |
3111 | d951f6ff | balrog | s->setup[4] = 0; |
3112 | d951f6ff | balrog | } |
3113 | d951f6ff | balrog | |
3114 | c227f099 | Anthony Liguori | struct omap_uwire_s *omap_uwire_init(target_phys_addr_t base,
|
3115 | d951f6ff | balrog | qemu_irq *irq, qemu_irq dma, omap_clk clk) |
3116 | d951f6ff | balrog | { |
3117 | d951f6ff | balrog | int iomemtype;
|
3118 | d951f6ff | balrog | struct omap_uwire_s *s = (struct omap_uwire_s *) |
3119 | d951f6ff | balrog | qemu_mallocz(sizeof(struct omap_uwire_s)); |
3120 | d951f6ff | balrog | |
3121 | d951f6ff | balrog | s->txirq = irq[0];
|
3122 | d951f6ff | balrog | s->rxirq = irq[1];
|
3123 | d951f6ff | balrog | s->txdrq = dma; |
3124 | d951f6ff | balrog | omap_uwire_reset(s); |
3125 | d951f6ff | balrog | |
3126 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_uwire_readfn, |
3127 | d951f6ff | balrog | omap_uwire_writefn, s); |
3128 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
3129 | d951f6ff | balrog | |
3130 | d951f6ff | balrog | return s;
|
3131 | d951f6ff | balrog | } |
3132 | d951f6ff | balrog | |
3133 | d951f6ff | balrog | void omap_uwire_attach(struct omap_uwire_s *s, |
3134 | bc24a225 | Paul Brook | uWireSlave *slave, int chipselect)
|
3135 | d951f6ff | balrog | { |
3136 | 827df9f3 | balrog | if (chipselect < 0 || chipselect > 3) { |
3137 | 827df9f3 | balrog | fprintf(stderr, "%s: Bad chipselect %i\n", __FUNCTION__, chipselect);
|
3138 | 827df9f3 | balrog | exit(-1);
|
3139 | 827df9f3 | balrog | } |
3140 | d951f6ff | balrog | |
3141 | d951f6ff | balrog | s->chip[chipselect] = slave; |
3142 | d951f6ff | balrog | } |
3143 | d951f6ff | balrog | |
3144 | 66450b15 | balrog | /* Pseudonoise Pulse-Width Light Modulator */
|
3145 | 9596ebb7 | pbrook | static void omap_pwl_update(struct omap_mpu_state_s *s) |
3146 | 66450b15 | balrog | { |
3147 | 66450b15 | balrog | int output = (s->pwl.clk && s->pwl.enable) ? s->pwl.level : 0; |
3148 | 66450b15 | balrog | |
3149 | 66450b15 | balrog | if (output != s->pwl.output) {
|
3150 | 66450b15 | balrog | s->pwl.output = output; |
3151 | 66450b15 | balrog | printf("%s: Backlight now at %i/256\n", __FUNCTION__, output);
|
3152 | 66450b15 | balrog | } |
3153 | 66450b15 | balrog | } |
3154 | 66450b15 | balrog | |
3155 | c227f099 | Anthony Liguori | static uint32_t omap_pwl_read(void *opaque, target_phys_addr_t addr) |
3156 | 66450b15 | balrog | { |
3157 | 66450b15 | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3158 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3159 | 66450b15 | balrog | |
3160 | 66450b15 | balrog | switch (offset) {
|
3161 | 66450b15 | balrog | case 0x00: /* PWL_LEVEL */ |
3162 | 66450b15 | balrog | return s->pwl.level;
|
3163 | 66450b15 | balrog | case 0x04: /* PWL_CTRL */ |
3164 | 66450b15 | balrog | return s->pwl.enable;
|
3165 | 66450b15 | balrog | } |
3166 | 66450b15 | balrog | OMAP_BAD_REG(addr); |
3167 | 66450b15 | balrog | return 0; |
3168 | 66450b15 | balrog | } |
3169 | 66450b15 | balrog | |
3170 | c227f099 | Anthony Liguori | static void omap_pwl_write(void *opaque, target_phys_addr_t addr, |
3171 | 66450b15 | balrog | uint32_t value) |
3172 | 66450b15 | balrog | { |
3173 | 66450b15 | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3174 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3175 | 66450b15 | balrog | |
3176 | 66450b15 | balrog | switch (offset) {
|
3177 | 66450b15 | balrog | case 0x00: /* PWL_LEVEL */ |
3178 | 66450b15 | balrog | s->pwl.level = value; |
3179 | 66450b15 | balrog | omap_pwl_update(s); |
3180 | 66450b15 | balrog | break;
|
3181 | 66450b15 | balrog | case 0x04: /* PWL_CTRL */ |
3182 | 66450b15 | balrog | s->pwl.enable = value & 1;
|
3183 | 66450b15 | balrog | omap_pwl_update(s); |
3184 | 66450b15 | balrog | break;
|
3185 | 66450b15 | balrog | default:
|
3186 | 66450b15 | balrog | OMAP_BAD_REG(addr); |
3187 | 66450b15 | balrog | return;
|
3188 | 66450b15 | balrog | } |
3189 | 66450b15 | balrog | } |
3190 | 66450b15 | balrog | |
3191 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_pwl_readfn[] = { |
3192 | 02645926 | balrog | omap_pwl_read, |
3193 | 66450b15 | balrog | omap_badwidth_read8, |
3194 | 66450b15 | balrog | omap_badwidth_read8, |
3195 | 66450b15 | balrog | }; |
3196 | 66450b15 | balrog | |
3197 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_pwl_writefn[] = { |
3198 | 02645926 | balrog | omap_pwl_write, |
3199 | 66450b15 | balrog | omap_badwidth_write8, |
3200 | 66450b15 | balrog | omap_badwidth_write8, |
3201 | 66450b15 | balrog | }; |
3202 | 66450b15 | balrog | |
3203 | 9596ebb7 | pbrook | static void omap_pwl_reset(struct omap_mpu_state_s *s) |
3204 | 66450b15 | balrog | { |
3205 | 66450b15 | balrog | s->pwl.output = 0;
|
3206 | 66450b15 | balrog | s->pwl.level = 0;
|
3207 | 66450b15 | balrog | s->pwl.enable = 0;
|
3208 | 66450b15 | balrog | s->pwl.clk = 1;
|
3209 | 66450b15 | balrog | omap_pwl_update(s); |
3210 | 66450b15 | balrog | } |
3211 | 66450b15 | balrog | |
3212 | 66450b15 | balrog | static void omap_pwl_clk_update(void *opaque, int line, int on) |
3213 | 66450b15 | balrog | { |
3214 | 66450b15 | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3215 | 66450b15 | balrog | |
3216 | 66450b15 | balrog | s->pwl.clk = on; |
3217 | 66450b15 | balrog | omap_pwl_update(s); |
3218 | 66450b15 | balrog | } |
3219 | 66450b15 | balrog | |
3220 | c227f099 | Anthony Liguori | static void omap_pwl_init(target_phys_addr_t base, struct omap_mpu_state_s *s, |
3221 | 66450b15 | balrog | omap_clk clk) |
3222 | 66450b15 | balrog | { |
3223 | 66450b15 | balrog | int iomemtype;
|
3224 | 66450b15 | balrog | |
3225 | 66450b15 | balrog | omap_pwl_reset(s); |
3226 | 66450b15 | balrog | |
3227 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_pwl_readfn, |
3228 | 66450b15 | balrog | omap_pwl_writefn, s); |
3229 | b854bc19 | balrog | cpu_register_physical_memory(base, 0x800, iomemtype);
|
3230 | 66450b15 | balrog | |
3231 | 66450b15 | balrog | omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]); |
3232 | 66450b15 | balrog | } |
3233 | 66450b15 | balrog | |
3234 | f34c417b | balrog | /* Pulse-Width Tone module */
|
3235 | c227f099 | Anthony Liguori | static uint32_t omap_pwt_read(void *opaque, target_phys_addr_t addr) |
3236 | f34c417b | balrog | { |
3237 | f34c417b | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3238 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3239 | f34c417b | balrog | |
3240 | f34c417b | balrog | switch (offset) {
|
3241 | f34c417b | balrog | case 0x00: /* FRC */ |
3242 | f34c417b | balrog | return s->pwt.frc;
|
3243 | f34c417b | balrog | case 0x04: /* VCR */ |
3244 | f34c417b | balrog | return s->pwt.vrc;
|
3245 | f34c417b | balrog | case 0x08: /* GCR */ |
3246 | f34c417b | balrog | return s->pwt.gcr;
|
3247 | f34c417b | balrog | } |
3248 | f34c417b | balrog | OMAP_BAD_REG(addr); |
3249 | f34c417b | balrog | return 0; |
3250 | f34c417b | balrog | } |
3251 | f34c417b | balrog | |
3252 | c227f099 | Anthony Liguori | static void omap_pwt_write(void *opaque, target_phys_addr_t addr, |
3253 | f34c417b | balrog | uint32_t value) |
3254 | f34c417b | balrog | { |
3255 | f34c417b | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3256 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3257 | f34c417b | balrog | |
3258 | f34c417b | balrog | switch (offset) {
|
3259 | f34c417b | balrog | case 0x00: /* FRC */ |
3260 | f34c417b | balrog | s->pwt.frc = value & 0x3f;
|
3261 | f34c417b | balrog | break;
|
3262 | f34c417b | balrog | case 0x04: /* VRC */ |
3263 | f34c417b | balrog | if ((value ^ s->pwt.vrc) & 1) { |
3264 | f34c417b | balrog | if (value & 1) |
3265 | f34c417b | balrog | printf("%s: %iHz buzz on\n", __FUNCTION__, (int) |
3266 | f34c417b | balrog | /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
|
3267 | f34c417b | balrog | ((omap_clk_getrate(s->pwt.clk) >> 3) /
|
3268 | f34c417b | balrog | /* Pre-multiplexer divider */
|
3269 | f34c417b | balrog | ((s->pwt.gcr & 2) ? 1 : 154) / |
3270 | f34c417b | balrog | /* Octave multiplexer */
|
3271 | f34c417b | balrog | (2 << (value & 3)) * |
3272 | f34c417b | balrog | /* 101/107 divider */
|
3273 | f34c417b | balrog | ((value & (1 << 2)) ? 101 : 107) * |
3274 | f34c417b | balrog | /* 49/55 divider */
|
3275 | f34c417b | balrog | ((value & (1 << 3)) ? 49 : 55) * |
3276 | f34c417b | balrog | /* 50/63 divider */
|
3277 | f34c417b | balrog | ((value & (1 << 4)) ? 50 : 63) * |
3278 | f34c417b | balrog | /* 80/127 divider */
|
3279 | f34c417b | balrog | ((value & (1 << 5)) ? 80 : 127) / |
3280 | f34c417b | balrog | (107 * 55 * 63 * 127))); |
3281 | f34c417b | balrog | else
|
3282 | f34c417b | balrog | printf("%s: silence!\n", __FUNCTION__);
|
3283 | f34c417b | balrog | } |
3284 | f34c417b | balrog | s->pwt.vrc = value & 0x7f;
|
3285 | f34c417b | balrog | break;
|
3286 | f34c417b | balrog | case 0x08: /* GCR */ |
3287 | f34c417b | balrog | s->pwt.gcr = value & 3;
|
3288 | f34c417b | balrog | break;
|
3289 | f34c417b | balrog | default:
|
3290 | f34c417b | balrog | OMAP_BAD_REG(addr); |
3291 | f34c417b | balrog | return;
|
3292 | f34c417b | balrog | } |
3293 | f34c417b | balrog | } |
3294 | f34c417b | balrog | |
3295 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_pwt_readfn[] = { |
3296 | 02645926 | balrog | omap_pwt_read, |
3297 | f34c417b | balrog | omap_badwidth_read8, |
3298 | f34c417b | balrog | omap_badwidth_read8, |
3299 | f34c417b | balrog | }; |
3300 | f34c417b | balrog | |
3301 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_pwt_writefn[] = { |
3302 | 02645926 | balrog | omap_pwt_write, |
3303 | f34c417b | balrog | omap_badwidth_write8, |
3304 | f34c417b | balrog | omap_badwidth_write8, |
3305 | f34c417b | balrog | }; |
3306 | f34c417b | balrog | |
3307 | 9596ebb7 | pbrook | static void omap_pwt_reset(struct omap_mpu_state_s *s) |
3308 | f34c417b | balrog | { |
3309 | f34c417b | balrog | s->pwt.frc = 0;
|
3310 | f34c417b | balrog | s->pwt.vrc = 0;
|
3311 | f34c417b | balrog | s->pwt.gcr = 0;
|
3312 | f34c417b | balrog | } |
3313 | f34c417b | balrog | |
3314 | c227f099 | Anthony Liguori | static void omap_pwt_init(target_phys_addr_t base, struct omap_mpu_state_s *s, |
3315 | f34c417b | balrog | omap_clk clk) |
3316 | f34c417b | balrog | { |
3317 | f34c417b | balrog | int iomemtype;
|
3318 | f34c417b | balrog | |
3319 | f34c417b | balrog | s->pwt.clk = clk; |
3320 | f34c417b | balrog | omap_pwt_reset(s); |
3321 | f34c417b | balrog | |
3322 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_pwt_readfn, |
3323 | f34c417b | balrog | omap_pwt_writefn, s); |
3324 | b854bc19 | balrog | cpu_register_physical_memory(base, 0x800, iomemtype);
|
3325 | f34c417b | balrog | } |
3326 | f34c417b | balrog | |
3327 | 5c1c390f | balrog | /* Real-time Clock module */
|
3328 | 5c1c390f | balrog | struct omap_rtc_s {
|
3329 | 5c1c390f | balrog | qemu_irq irq; |
3330 | 5c1c390f | balrog | qemu_irq alarm; |
3331 | 5c1c390f | balrog | QEMUTimer *clk; |
3332 | 5c1c390f | balrog | |
3333 | 5c1c390f | balrog | uint8_t interrupts; |
3334 | 5c1c390f | balrog | uint8_t status; |
3335 | 5c1c390f | balrog | int16_t comp_reg; |
3336 | 5c1c390f | balrog | int running;
|
3337 | 5c1c390f | balrog | int pm_am;
|
3338 | 5c1c390f | balrog | int auto_comp;
|
3339 | 5c1c390f | balrog | int round;
|
3340 | 5c1c390f | balrog | struct tm alarm_tm;
|
3341 | 5c1c390f | balrog | time_t alarm_ti; |
3342 | 5c1c390f | balrog | |
3343 | 5c1c390f | balrog | struct tm current_tm;
|
3344 | 5c1c390f | balrog | time_t ti; |
3345 | 5c1c390f | balrog | uint64_t tick; |
3346 | 5c1c390f | balrog | }; |
3347 | 5c1c390f | balrog | |
3348 | 5c1c390f | balrog | static void omap_rtc_interrupts_update(struct omap_rtc_s *s) |
3349 | 5c1c390f | balrog | { |
3350 | 106627d0 | balrog | /* s->alarm is level-triggered */
|
3351 | 5c1c390f | balrog | qemu_set_irq(s->alarm, (s->status >> 6) & 1); |
3352 | 5c1c390f | balrog | } |
3353 | 5c1c390f | balrog | |
3354 | 5c1c390f | balrog | static void omap_rtc_alarm_update(struct omap_rtc_s *s) |
3355 | 5c1c390f | balrog | { |
3356 | 0cd2df75 | aurel32 | s->alarm_ti = mktimegm(&s->alarm_tm); |
3357 | 5c1c390f | balrog | if (s->alarm_ti == -1) |
3358 | 5c1c390f | balrog | printf("%s: conversion failed\n", __FUNCTION__);
|
3359 | 5c1c390f | balrog | } |
3360 | 5c1c390f | balrog | |
3361 | c227f099 | Anthony Liguori | static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr) |
3362 | 5c1c390f | balrog | { |
3363 | 5c1c390f | balrog | struct omap_rtc_s *s = (struct omap_rtc_s *) opaque; |
3364 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3365 | 5c1c390f | balrog | uint8_t i; |
3366 | 5c1c390f | balrog | |
3367 | 5c1c390f | balrog | switch (offset) {
|
3368 | 5c1c390f | balrog | case 0x00: /* SECONDS_REG */ |
3369 | abd0c6bd | Paul Brook | return to_bcd(s->current_tm.tm_sec);
|
3370 | 5c1c390f | balrog | |
3371 | 5c1c390f | balrog | case 0x04: /* MINUTES_REG */ |
3372 | abd0c6bd | Paul Brook | return to_bcd(s->current_tm.tm_min);
|
3373 | 5c1c390f | balrog | |
3374 | 5c1c390f | balrog | case 0x08: /* HOURS_REG */ |
3375 | 5c1c390f | balrog | if (s->pm_am)
|
3376 | 5c1c390f | balrog | return ((s->current_tm.tm_hour > 11) << 7) | |
3377 | abd0c6bd | Paul Brook | to_bcd(((s->current_tm.tm_hour - 1) % 12) + 1); |
3378 | 5c1c390f | balrog | else
|
3379 | abd0c6bd | Paul Brook | return to_bcd(s->current_tm.tm_hour);
|
3380 | 5c1c390f | balrog | |
3381 | 5c1c390f | balrog | case 0x0c: /* DAYS_REG */ |
3382 | abd0c6bd | Paul Brook | return to_bcd(s->current_tm.tm_mday);
|
3383 | 5c1c390f | balrog | |
3384 | 5c1c390f | balrog | case 0x10: /* MONTHS_REG */ |
3385 | abd0c6bd | Paul Brook | return to_bcd(s->current_tm.tm_mon + 1); |
3386 | 5c1c390f | balrog | |
3387 | 5c1c390f | balrog | case 0x14: /* YEARS_REG */ |
3388 | abd0c6bd | Paul Brook | return to_bcd(s->current_tm.tm_year % 100); |
3389 | 5c1c390f | balrog | |
3390 | 5c1c390f | balrog | case 0x18: /* WEEK_REG */ |
3391 | 5c1c390f | balrog | return s->current_tm.tm_wday;
|
3392 | 5c1c390f | balrog | |
3393 | 5c1c390f | balrog | case 0x20: /* ALARM_SECONDS_REG */ |
3394 | abd0c6bd | Paul Brook | return to_bcd(s->alarm_tm.tm_sec);
|
3395 | 5c1c390f | balrog | |
3396 | 5c1c390f | balrog | case 0x24: /* ALARM_MINUTES_REG */ |
3397 | abd0c6bd | Paul Brook | return to_bcd(s->alarm_tm.tm_min);
|
3398 | 5c1c390f | balrog | |
3399 | 5c1c390f | balrog | case 0x28: /* ALARM_HOURS_REG */ |
3400 | 5c1c390f | balrog | if (s->pm_am)
|
3401 | 5c1c390f | balrog | return ((s->alarm_tm.tm_hour > 11) << 7) | |
3402 | abd0c6bd | Paul Brook | to_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1); |
3403 | 5c1c390f | balrog | else
|
3404 | abd0c6bd | Paul Brook | return to_bcd(s->alarm_tm.tm_hour);
|
3405 | 5c1c390f | balrog | |
3406 | 5c1c390f | balrog | case 0x2c: /* ALARM_DAYS_REG */ |
3407 | abd0c6bd | Paul Brook | return to_bcd(s->alarm_tm.tm_mday);
|
3408 | 5c1c390f | balrog | |
3409 | 5c1c390f | balrog | case 0x30: /* ALARM_MONTHS_REG */ |
3410 | abd0c6bd | Paul Brook | return to_bcd(s->alarm_tm.tm_mon + 1); |
3411 | 5c1c390f | balrog | |
3412 | 5c1c390f | balrog | case 0x34: /* ALARM_YEARS_REG */ |
3413 | abd0c6bd | Paul Brook | return to_bcd(s->alarm_tm.tm_year % 100); |
3414 | 5c1c390f | balrog | |
3415 | 5c1c390f | balrog | case 0x40: /* RTC_CTRL_REG */ |
3416 | 5c1c390f | balrog | return (s->pm_am << 3) | (s->auto_comp << 2) | |
3417 | 5c1c390f | balrog | (s->round << 1) | s->running;
|
3418 | 5c1c390f | balrog | |
3419 | 5c1c390f | balrog | case 0x44: /* RTC_STATUS_REG */ |
3420 | 5c1c390f | balrog | i = s->status; |
3421 | 5c1c390f | balrog | s->status &= ~0x3d;
|
3422 | 5c1c390f | balrog | return i;
|
3423 | 5c1c390f | balrog | |
3424 | 5c1c390f | balrog | case 0x48: /* RTC_INTERRUPTS_REG */ |
3425 | 5c1c390f | balrog | return s->interrupts;
|
3426 | 5c1c390f | balrog | |
3427 | 5c1c390f | balrog | case 0x4c: /* RTC_COMP_LSB_REG */ |
3428 | 5c1c390f | balrog | return ((uint16_t) s->comp_reg) & 0xff; |
3429 | 5c1c390f | balrog | |
3430 | 5c1c390f | balrog | case 0x50: /* RTC_COMP_MSB_REG */ |
3431 | 5c1c390f | balrog | return ((uint16_t) s->comp_reg) >> 8; |
3432 | 5c1c390f | balrog | } |
3433 | 5c1c390f | balrog | |
3434 | 5c1c390f | balrog | OMAP_BAD_REG(addr); |
3435 | 5c1c390f | balrog | return 0; |
3436 | 5c1c390f | balrog | } |
3437 | 5c1c390f | balrog | |
3438 | c227f099 | Anthony Liguori | static void omap_rtc_write(void *opaque, target_phys_addr_t addr, |
3439 | 5c1c390f | balrog | uint32_t value) |
3440 | 5c1c390f | balrog | { |
3441 | 5c1c390f | balrog | struct omap_rtc_s *s = (struct omap_rtc_s *) opaque; |
3442 | cf965d24 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3443 | 5c1c390f | balrog | struct tm new_tm;
|
3444 | 5c1c390f | balrog | time_t ti[2];
|
3445 | 5c1c390f | balrog | |
3446 | 5c1c390f | balrog | switch (offset) {
|
3447 | 5c1c390f | balrog | case 0x00: /* SECONDS_REG */ |
3448 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3449 | 5c1c390f | balrog | printf("RTC SEC_REG <-- %02x\n", value);
|
3450 | 5c1c390f | balrog | #endif
|
3451 | 5c1c390f | balrog | s->ti -= s->current_tm.tm_sec; |
3452 | abd0c6bd | Paul Brook | s->ti += from_bcd(value); |
3453 | 5c1c390f | balrog | return;
|
3454 | 5c1c390f | balrog | |
3455 | 5c1c390f | balrog | case 0x04: /* MINUTES_REG */ |
3456 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3457 | 5c1c390f | balrog | printf("RTC MIN_REG <-- %02x\n", value);
|
3458 | 5c1c390f | balrog | #endif
|
3459 | 5c1c390f | balrog | s->ti -= s->current_tm.tm_min * 60;
|
3460 | abd0c6bd | Paul Brook | s->ti += from_bcd(value) * 60;
|
3461 | 5c1c390f | balrog | return;
|
3462 | 5c1c390f | balrog | |
3463 | 5c1c390f | balrog | case 0x08: /* HOURS_REG */ |
3464 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3465 | 5c1c390f | balrog | printf("RTC HRS_REG <-- %02x\n", value);
|
3466 | 5c1c390f | balrog | #endif
|
3467 | 5c1c390f | balrog | s->ti -= s->current_tm.tm_hour * 3600;
|
3468 | 5c1c390f | balrog | if (s->pm_am) {
|
3469 | abd0c6bd | Paul Brook | s->ti += (from_bcd(value & 0x3f) & 12) * 3600; |
3470 | 5c1c390f | balrog | s->ti += ((value >> 7) & 1) * 43200; |
3471 | 5c1c390f | balrog | } else
|
3472 | abd0c6bd | Paul Brook | s->ti += from_bcd(value & 0x3f) * 3600; |
3473 | 5c1c390f | balrog | return;
|
3474 | 5c1c390f | balrog | |
3475 | 5c1c390f | balrog | case 0x0c: /* DAYS_REG */ |
3476 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3477 | 5c1c390f | balrog | printf("RTC DAY_REG <-- %02x\n", value);
|
3478 | 5c1c390f | balrog | #endif
|
3479 | 5c1c390f | balrog | s->ti -= s->current_tm.tm_mday * 86400;
|
3480 | abd0c6bd | Paul Brook | s->ti += from_bcd(value) * 86400;
|
3481 | 5c1c390f | balrog | return;
|
3482 | 5c1c390f | balrog | |
3483 | 5c1c390f | balrog | case 0x10: /* MONTHS_REG */ |
3484 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3485 | 5c1c390f | balrog | printf("RTC MTH_REG <-- %02x\n", value);
|
3486 | 5c1c390f | balrog | #endif
|
3487 | 5c1c390f | balrog | memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
|
3488 | abd0c6bd | Paul Brook | new_tm.tm_mon = from_bcd(value); |
3489 | 0cd2df75 | aurel32 | ti[0] = mktimegm(&s->current_tm);
|
3490 | 0cd2df75 | aurel32 | ti[1] = mktimegm(&new_tm);
|
3491 | 5c1c390f | balrog | |
3492 | 5c1c390f | balrog | if (ti[0] != -1 && ti[1] != -1) { |
3493 | 5c1c390f | balrog | s->ti -= ti[0];
|
3494 | 5c1c390f | balrog | s->ti += ti[1];
|
3495 | 5c1c390f | balrog | } else {
|
3496 | 5c1c390f | balrog | /* A less accurate version */
|
3497 | 5c1c390f | balrog | s->ti -= s->current_tm.tm_mon * 2592000;
|
3498 | abd0c6bd | Paul Brook | s->ti += from_bcd(value) * 2592000;
|
3499 | 5c1c390f | balrog | } |
3500 | 5c1c390f | balrog | return;
|
3501 | 5c1c390f | balrog | |
3502 | 5c1c390f | balrog | case 0x14: /* YEARS_REG */ |
3503 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3504 | 5c1c390f | balrog | printf("RTC YRS_REG <-- %02x\n", value);
|
3505 | 5c1c390f | balrog | #endif
|
3506 | 5c1c390f | balrog | memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
|
3507 | abd0c6bd | Paul Brook | new_tm.tm_year += from_bcd(value) - (new_tm.tm_year % 100);
|
3508 | 0cd2df75 | aurel32 | ti[0] = mktimegm(&s->current_tm);
|
3509 | 0cd2df75 | aurel32 | ti[1] = mktimegm(&new_tm);
|
3510 | 5c1c390f | balrog | |
3511 | 5c1c390f | balrog | if (ti[0] != -1 && ti[1] != -1) { |
3512 | 5c1c390f | balrog | s->ti -= ti[0];
|
3513 | 5c1c390f | balrog | s->ti += ti[1];
|
3514 | 5c1c390f | balrog | } else {
|
3515 | 5c1c390f | balrog | /* A less accurate version */
|
3516 | 5c1c390f | balrog | s->ti -= (s->current_tm.tm_year % 100) * 31536000; |
3517 | abd0c6bd | Paul Brook | s->ti += from_bcd(value) * 31536000;
|
3518 | 5c1c390f | balrog | } |
3519 | 5c1c390f | balrog | return;
|
3520 | 5c1c390f | balrog | |
3521 | 5c1c390f | balrog | case 0x18: /* WEEK_REG */ |
3522 | 5c1c390f | balrog | return; /* Ignored */ |
3523 | 5c1c390f | balrog | |
3524 | 5c1c390f | balrog | case 0x20: /* ALARM_SECONDS_REG */ |
3525 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3526 | 5c1c390f | balrog | printf("ALM SEC_REG <-- %02x\n", value);
|
3527 | 5c1c390f | balrog | #endif
|
3528 | abd0c6bd | Paul Brook | s->alarm_tm.tm_sec = from_bcd(value); |
3529 | 5c1c390f | balrog | omap_rtc_alarm_update(s); |
3530 | 5c1c390f | balrog | return;
|
3531 | 5c1c390f | balrog | |
3532 | 5c1c390f | balrog | case 0x24: /* ALARM_MINUTES_REG */ |
3533 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3534 | 5c1c390f | balrog | printf("ALM MIN_REG <-- %02x\n", value);
|
3535 | 5c1c390f | balrog | #endif
|
3536 | abd0c6bd | Paul Brook | s->alarm_tm.tm_min = from_bcd(value); |
3537 | 5c1c390f | balrog | omap_rtc_alarm_update(s); |
3538 | 5c1c390f | balrog | return;
|
3539 | 5c1c390f | balrog | |
3540 | 5c1c390f | balrog | case 0x28: /* ALARM_HOURS_REG */ |
3541 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3542 | 5c1c390f | balrog | printf("ALM HRS_REG <-- %02x\n", value);
|
3543 | 5c1c390f | balrog | #endif
|
3544 | 5c1c390f | balrog | if (s->pm_am)
|
3545 | 5c1c390f | balrog | s->alarm_tm.tm_hour = |
3546 | abd0c6bd | Paul Brook | ((from_bcd(value & 0x3f)) % 12) + |
3547 | 5c1c390f | balrog | ((value >> 7) & 1) * 12; |
3548 | 5c1c390f | balrog | else
|
3549 | abd0c6bd | Paul Brook | s->alarm_tm.tm_hour = from_bcd(value); |
3550 | 5c1c390f | balrog | omap_rtc_alarm_update(s); |
3551 | 5c1c390f | balrog | return;
|
3552 | 5c1c390f | balrog | |
3553 | 5c1c390f | balrog | case 0x2c: /* ALARM_DAYS_REG */ |
3554 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3555 | 5c1c390f | balrog | printf("ALM DAY_REG <-- %02x\n", value);
|
3556 | 5c1c390f | balrog | #endif
|
3557 | abd0c6bd | Paul Brook | s->alarm_tm.tm_mday = from_bcd(value); |
3558 | 5c1c390f | balrog | omap_rtc_alarm_update(s); |
3559 | 5c1c390f | balrog | return;
|
3560 | 5c1c390f | balrog | |
3561 | 5c1c390f | balrog | case 0x30: /* ALARM_MONTHS_REG */ |
3562 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3563 | 5c1c390f | balrog | printf("ALM MON_REG <-- %02x\n", value);
|
3564 | 5c1c390f | balrog | #endif
|
3565 | abd0c6bd | Paul Brook | s->alarm_tm.tm_mon = from_bcd(value); |
3566 | 5c1c390f | balrog | omap_rtc_alarm_update(s); |
3567 | 5c1c390f | balrog | return;
|
3568 | 5c1c390f | balrog | |
3569 | 5c1c390f | balrog | case 0x34: /* ALARM_YEARS_REG */ |
3570 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3571 | 5c1c390f | balrog | printf("ALM YRS_REG <-- %02x\n", value);
|
3572 | 5c1c390f | balrog | #endif
|
3573 | abd0c6bd | Paul Brook | s->alarm_tm.tm_year = from_bcd(value); |
3574 | 5c1c390f | balrog | omap_rtc_alarm_update(s); |
3575 | 5c1c390f | balrog | return;
|
3576 | 5c1c390f | balrog | |
3577 | 5c1c390f | balrog | case 0x40: /* RTC_CTRL_REG */ |
3578 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3579 | 5c1c390f | balrog | printf("RTC CONTROL <-- %02x\n", value);
|
3580 | 5c1c390f | balrog | #endif
|
3581 | 5c1c390f | balrog | s->pm_am = (value >> 3) & 1; |
3582 | 5c1c390f | balrog | s->auto_comp = (value >> 2) & 1; |
3583 | 5c1c390f | balrog | s->round = (value >> 1) & 1; |
3584 | 5c1c390f | balrog | s->running = value & 1;
|
3585 | 5c1c390f | balrog | s->status &= 0xfd;
|
3586 | 5c1c390f | balrog | s->status |= s->running << 1;
|
3587 | 5c1c390f | balrog | return;
|
3588 | 5c1c390f | balrog | |
3589 | 5c1c390f | balrog | case 0x44: /* RTC_STATUS_REG */ |
3590 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3591 | 5c1c390f | balrog | printf("RTC STATUSL <-- %02x\n", value);
|
3592 | 5c1c390f | balrog | #endif
|
3593 | 5c1c390f | balrog | s->status &= ~((value & 0xc0) ^ 0x80); |
3594 | 5c1c390f | balrog | omap_rtc_interrupts_update(s); |
3595 | 5c1c390f | balrog | return;
|
3596 | 5c1c390f | balrog | |
3597 | 5c1c390f | balrog | case 0x48: /* RTC_INTERRUPTS_REG */ |
3598 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3599 | 5c1c390f | balrog | printf("RTC INTRS <-- %02x\n", value);
|
3600 | 5c1c390f | balrog | #endif
|
3601 | 5c1c390f | balrog | s->interrupts = value; |
3602 | 5c1c390f | balrog | return;
|
3603 | 5c1c390f | balrog | |
3604 | 5c1c390f | balrog | case 0x4c: /* RTC_COMP_LSB_REG */ |
3605 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3606 | 5c1c390f | balrog | printf("RTC COMPLSB <-- %02x\n", value);
|
3607 | 5c1c390f | balrog | #endif
|
3608 | 5c1c390f | balrog | s->comp_reg &= 0xff00;
|
3609 | 5c1c390f | balrog | s->comp_reg |= 0x00ff & value;
|
3610 | 5c1c390f | balrog | return;
|
3611 | 5c1c390f | balrog | |
3612 | 5c1c390f | balrog | case 0x50: /* RTC_COMP_MSB_REG */ |
3613 | eb38c52c | blueswir1 | #ifdef ALMDEBUG
|
3614 | 5c1c390f | balrog | printf("RTC COMPMSB <-- %02x\n", value);
|
3615 | 5c1c390f | balrog | #endif
|
3616 | 5c1c390f | balrog | s->comp_reg &= 0x00ff;
|
3617 | 5c1c390f | balrog | s->comp_reg |= 0xff00 & (value << 8); |
3618 | 5c1c390f | balrog | return;
|
3619 | 5c1c390f | balrog | |
3620 | 5c1c390f | balrog | default:
|
3621 | 5c1c390f | balrog | OMAP_BAD_REG(addr); |
3622 | 5c1c390f | balrog | return;
|
3623 | 5c1c390f | balrog | } |
3624 | 5c1c390f | balrog | } |
3625 | 5c1c390f | balrog | |
3626 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_rtc_readfn[] = { |
3627 | 5c1c390f | balrog | omap_rtc_read, |
3628 | 5c1c390f | balrog | omap_badwidth_read8, |
3629 | 5c1c390f | balrog | omap_badwidth_read8, |
3630 | 5c1c390f | balrog | }; |
3631 | 5c1c390f | balrog | |
3632 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_rtc_writefn[] = { |
3633 | 5c1c390f | balrog | omap_rtc_write, |
3634 | 5c1c390f | balrog | omap_badwidth_write8, |
3635 | 5c1c390f | balrog | omap_badwidth_write8, |
3636 | 5c1c390f | balrog | }; |
3637 | 5c1c390f | balrog | |
3638 | 5c1c390f | balrog | static void omap_rtc_tick(void *opaque) |
3639 | 5c1c390f | balrog | { |
3640 | 5c1c390f | balrog | struct omap_rtc_s *s = opaque;
|
3641 | 5c1c390f | balrog | |
3642 | 5c1c390f | balrog | if (s->round) {
|
3643 | 5c1c390f | balrog | /* Round to nearest full minute. */
|
3644 | 5c1c390f | balrog | if (s->current_tm.tm_sec < 30) |
3645 | 5c1c390f | balrog | s->ti -= s->current_tm.tm_sec; |
3646 | 5c1c390f | balrog | else
|
3647 | 5c1c390f | balrog | s->ti += 60 - s->current_tm.tm_sec;
|
3648 | 5c1c390f | balrog | |
3649 | 5c1c390f | balrog | s->round = 0;
|
3650 | 5c1c390f | balrog | } |
3651 | 5c1c390f | balrog | |
3652 | f6503059 | balrog | memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm));
|
3653 | 5c1c390f | balrog | |
3654 | 5c1c390f | balrog | if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) { |
3655 | 5c1c390f | balrog | s->status |= 0x40;
|
3656 | 5c1c390f | balrog | omap_rtc_interrupts_update(s); |
3657 | 5c1c390f | balrog | } |
3658 | 5c1c390f | balrog | |
3659 | 5c1c390f | balrog | if (s->interrupts & 0x04) |
3660 | 5c1c390f | balrog | switch (s->interrupts & 3) { |
3661 | 5c1c390f | balrog | case 0: |
3662 | 5c1c390f | balrog | s->status |= 0x04;
|
3663 | 106627d0 | balrog | qemu_irq_pulse(s->irq); |
3664 | 5c1c390f | balrog | break;
|
3665 | 5c1c390f | balrog | case 1: |
3666 | 5c1c390f | balrog | if (s->current_tm.tm_sec)
|
3667 | 5c1c390f | balrog | break;
|
3668 | 5c1c390f | balrog | s->status |= 0x08;
|
3669 | 106627d0 | balrog | qemu_irq_pulse(s->irq); |
3670 | 5c1c390f | balrog | break;
|
3671 | 5c1c390f | balrog | case 2: |
3672 | 5c1c390f | balrog | if (s->current_tm.tm_sec || s->current_tm.tm_min)
|
3673 | 5c1c390f | balrog | break;
|
3674 | 5c1c390f | balrog | s->status |= 0x10;
|
3675 | 106627d0 | balrog | qemu_irq_pulse(s->irq); |
3676 | 5c1c390f | balrog | break;
|
3677 | 5c1c390f | balrog | case 3: |
3678 | 5c1c390f | balrog | if (s->current_tm.tm_sec ||
|
3679 | 5c1c390f | balrog | s->current_tm.tm_min || s->current_tm.tm_hour) |
3680 | 5c1c390f | balrog | break;
|
3681 | 5c1c390f | balrog | s->status |= 0x20;
|
3682 | 106627d0 | balrog | qemu_irq_pulse(s->irq); |
3683 | 5c1c390f | balrog | break;
|
3684 | 5c1c390f | balrog | } |
3685 | 5c1c390f | balrog | |
3686 | 5c1c390f | balrog | /* Move on */
|
3687 | 5c1c390f | balrog | if (s->running)
|
3688 | 5c1c390f | balrog | s->ti ++; |
3689 | 5c1c390f | balrog | s->tick += 1000;
|
3690 | 5c1c390f | balrog | |
3691 | 5c1c390f | balrog | /*
|
3692 | 5c1c390f | balrog | * Every full hour add a rough approximation of the compensation
|
3693 | 5c1c390f | balrog | * register to the 32kHz Timer (which drives the RTC) value.
|
3694 | 5c1c390f | balrog | */
|
3695 | 5c1c390f | balrog | if (s->auto_comp && !s->current_tm.tm_sec && !s->current_tm.tm_min)
|
3696 | 5c1c390f | balrog | s->tick += s->comp_reg * 1000 / 32768; |
3697 | 5c1c390f | balrog | |
3698 | 5c1c390f | balrog | qemu_mod_timer(s->clk, s->tick); |
3699 | 5c1c390f | balrog | } |
3700 | 5c1c390f | balrog | |
3701 | 9596ebb7 | pbrook | static void omap_rtc_reset(struct omap_rtc_s *s) |
3702 | 5c1c390f | balrog | { |
3703 | f6503059 | balrog | struct tm tm;
|
3704 | f6503059 | balrog | |
3705 | 5c1c390f | balrog | s->interrupts = 0;
|
3706 | 5c1c390f | balrog | s->comp_reg = 0;
|
3707 | 5c1c390f | balrog | s->running = 0;
|
3708 | 5c1c390f | balrog | s->pm_am = 0;
|
3709 | 5c1c390f | balrog | s->auto_comp = 0;
|
3710 | 5c1c390f | balrog | s->round = 0;
|
3711 | 5c1c390f | balrog | s->tick = qemu_get_clock(rt_clock); |
3712 | 5c1c390f | balrog | memset(&s->alarm_tm, 0, sizeof(s->alarm_tm)); |
3713 | 5c1c390f | balrog | s->alarm_tm.tm_mday = 0x01;
|
3714 | 5c1c390f | balrog | s->status = 1 << 7; |
3715 | f6503059 | balrog | qemu_get_timedate(&tm, 0);
|
3716 | 0cd2df75 | aurel32 | s->ti = mktimegm(&tm); |
3717 | 5c1c390f | balrog | |
3718 | 5c1c390f | balrog | omap_rtc_alarm_update(s); |
3719 | 5c1c390f | balrog | omap_rtc_tick(s); |
3720 | 5c1c390f | balrog | } |
3721 | 5c1c390f | balrog | |
3722 | c227f099 | Anthony Liguori | struct omap_rtc_s *omap_rtc_init(target_phys_addr_t base,
|
3723 | 5c1c390f | balrog | qemu_irq *irq, omap_clk clk) |
3724 | 5c1c390f | balrog | { |
3725 | 5c1c390f | balrog | int iomemtype;
|
3726 | 5c1c390f | balrog | struct omap_rtc_s *s = (struct omap_rtc_s *) |
3727 | 5c1c390f | balrog | qemu_mallocz(sizeof(struct omap_rtc_s)); |
3728 | 5c1c390f | balrog | |
3729 | 5c1c390f | balrog | s->irq = irq[0];
|
3730 | 5c1c390f | balrog | s->alarm = irq[1];
|
3731 | 5c1c390f | balrog | s->clk = qemu_new_timer(rt_clock, omap_rtc_tick, s); |
3732 | 5c1c390f | balrog | |
3733 | 5c1c390f | balrog | omap_rtc_reset(s); |
3734 | 5c1c390f | balrog | |
3735 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_rtc_readfn, |
3736 | 5c1c390f | balrog | omap_rtc_writefn, s); |
3737 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
3738 | 5c1c390f | balrog | |
3739 | 5c1c390f | balrog | return s;
|
3740 | 5c1c390f | balrog | } |
3741 | 5c1c390f | balrog | |
3742 | d8f699cb | balrog | /* Multi-channel Buffered Serial Port interfaces */
|
3743 | d8f699cb | balrog | struct omap_mcbsp_s {
|
3744 | d8f699cb | balrog | qemu_irq txirq; |
3745 | d8f699cb | balrog | qemu_irq rxirq; |
3746 | d8f699cb | balrog | qemu_irq txdrq; |
3747 | d8f699cb | balrog | qemu_irq rxdrq; |
3748 | d8f699cb | balrog | |
3749 | d8f699cb | balrog | uint16_t spcr[2];
|
3750 | d8f699cb | balrog | uint16_t rcr[2];
|
3751 | d8f699cb | balrog | uint16_t xcr[2];
|
3752 | d8f699cb | balrog | uint16_t srgr[2];
|
3753 | d8f699cb | balrog | uint16_t mcr[2];
|
3754 | d8f699cb | balrog | uint16_t pcr; |
3755 | d8f699cb | balrog | uint16_t rcer[8];
|
3756 | d8f699cb | balrog | uint16_t xcer[8];
|
3757 | d8f699cb | balrog | int tx_rate;
|
3758 | d8f699cb | balrog | int rx_rate;
|
3759 | d8f699cb | balrog | int tx_req;
|
3760 | 73560bc8 | balrog | int rx_req;
|
3761 | d8f699cb | balrog | |
3762 | bc24a225 | Paul Brook | I2SCodec *codec; |
3763 | 73560bc8 | balrog | QEMUTimer *source_timer; |
3764 | 73560bc8 | balrog | QEMUTimer *sink_timer; |
3765 | d8f699cb | balrog | }; |
3766 | d8f699cb | balrog | |
3767 | d8f699cb | balrog | static void omap_mcbsp_intr_update(struct omap_mcbsp_s *s) |
3768 | d8f699cb | balrog | { |
3769 | d8f699cb | balrog | int irq;
|
3770 | d8f699cb | balrog | |
3771 | d8f699cb | balrog | switch ((s->spcr[0] >> 4) & 3) { /* RINTM */ |
3772 | d8f699cb | balrog | case 0: |
3773 | d8f699cb | balrog | irq = (s->spcr[0] >> 1) & 1; /* RRDY */ |
3774 | d8f699cb | balrog | break;
|
3775 | d8f699cb | balrog | case 3: |
3776 | d8f699cb | balrog | irq = (s->spcr[0] >> 3) & 1; /* RSYNCERR */ |
3777 | d8f699cb | balrog | break;
|
3778 | d8f699cb | balrog | default:
|
3779 | d8f699cb | balrog | irq = 0;
|
3780 | d8f699cb | balrog | break;
|
3781 | d8f699cb | balrog | } |
3782 | d8f699cb | balrog | |
3783 | 106627d0 | balrog | if (irq)
|
3784 | 106627d0 | balrog | qemu_irq_pulse(s->rxirq); |
3785 | d8f699cb | balrog | |
3786 | d8f699cb | balrog | switch ((s->spcr[1] >> 4) & 3) { /* XINTM */ |
3787 | d8f699cb | balrog | case 0: |
3788 | d8f699cb | balrog | irq = (s->spcr[1] >> 1) & 1; /* XRDY */ |
3789 | d8f699cb | balrog | break;
|
3790 | d8f699cb | balrog | case 3: |
3791 | d8f699cb | balrog | irq = (s->spcr[1] >> 3) & 1; /* XSYNCERR */ |
3792 | d8f699cb | balrog | break;
|
3793 | d8f699cb | balrog | default:
|
3794 | d8f699cb | balrog | irq = 0;
|
3795 | d8f699cb | balrog | break;
|
3796 | d8f699cb | balrog | } |
3797 | d8f699cb | balrog | |
3798 | 106627d0 | balrog | if (irq)
|
3799 | 106627d0 | balrog | qemu_irq_pulse(s->txirq); |
3800 | d8f699cb | balrog | } |
3801 | d8f699cb | balrog | |
3802 | 73560bc8 | balrog | static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s *s) |
3803 | d8f699cb | balrog | { |
3804 | 73560bc8 | balrog | if ((s->spcr[0] >> 1) & 1) /* RRDY */ |
3805 | 73560bc8 | balrog | s->spcr[0] |= 1 << 2; /* RFULL */ |
3806 | 73560bc8 | balrog | s->spcr[0] |= 1 << 1; /* RRDY */ |
3807 | 73560bc8 | balrog | qemu_irq_raise(s->rxdrq); |
3808 | 73560bc8 | balrog | omap_mcbsp_intr_update(s); |
3809 | d8f699cb | balrog | } |
3810 | d8f699cb | balrog | |
3811 | 73560bc8 | balrog | static void omap_mcbsp_source_tick(void *opaque) |
3812 | d8f699cb | balrog | { |
3813 | 73560bc8 | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; |
3814 | 73560bc8 | balrog | static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 }; |
3815 | 73560bc8 | balrog | |
3816 | 73560bc8 | balrog | if (!s->rx_rate)
|
3817 | d8f699cb | balrog | return;
|
3818 | 73560bc8 | balrog | if (s->rx_req)
|
3819 | 73560bc8 | balrog | printf("%s: Rx FIFO overrun\n", __FUNCTION__);
|
3820 | d8f699cb | balrog | |
3821 | 73560bc8 | balrog | s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7]; |
3822 | d8f699cb | balrog | |
3823 | 73560bc8 | balrog | omap_mcbsp_rx_newdata(s); |
3824 | 6ee093c9 | Juan Quintela | qemu_mod_timer(s->source_timer, qemu_get_clock(vm_clock) + |
3825 | 6ee093c9 | Juan Quintela | get_ticks_per_sec()); |
3826 | d8f699cb | balrog | } |
3827 | d8f699cb | balrog | |
3828 | d8f699cb | balrog | static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s) |
3829 | d8f699cb | balrog | { |
3830 | 73560bc8 | balrog | if (!s->codec || !s->codec->rts)
|
3831 | 73560bc8 | balrog | omap_mcbsp_source_tick(s); |
3832 | 73560bc8 | balrog | else if (s->codec->in.len) { |
3833 | 73560bc8 | balrog | s->rx_req = s->codec->in.len; |
3834 | 73560bc8 | balrog | omap_mcbsp_rx_newdata(s); |
3835 | d8f699cb | balrog | } |
3836 | d8f699cb | balrog | } |
3837 | d8f699cb | balrog | |
3838 | d8f699cb | balrog | static void omap_mcbsp_rx_stop(struct omap_mcbsp_s *s) |
3839 | d8f699cb | balrog | { |
3840 | 73560bc8 | balrog | qemu_del_timer(s->source_timer); |
3841 | 73560bc8 | balrog | } |
3842 | 73560bc8 | balrog | |
3843 | 73560bc8 | balrog | static void omap_mcbsp_rx_done(struct omap_mcbsp_s *s) |
3844 | 73560bc8 | balrog | { |
3845 | d8f699cb | balrog | s->spcr[0] &= ~(1 << 1); /* RRDY */ |
3846 | d8f699cb | balrog | qemu_irq_lower(s->rxdrq); |
3847 | d8f699cb | balrog | omap_mcbsp_intr_update(s); |
3848 | d8f699cb | balrog | } |
3849 | d8f699cb | balrog | |
3850 | 73560bc8 | balrog | static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s *s) |
3851 | 73560bc8 | balrog | { |
3852 | 73560bc8 | balrog | s->spcr[1] |= 1 << 1; /* XRDY */ |
3853 | 73560bc8 | balrog | qemu_irq_raise(s->txdrq); |
3854 | 73560bc8 | balrog | omap_mcbsp_intr_update(s); |
3855 | 73560bc8 | balrog | } |
3856 | 73560bc8 | balrog | |
3857 | 73560bc8 | balrog | static void omap_mcbsp_sink_tick(void *opaque) |
3858 | d8f699cb | balrog | { |
3859 | 73560bc8 | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; |
3860 | 73560bc8 | balrog | static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 }; |
3861 | 73560bc8 | balrog | |
3862 | 73560bc8 | balrog | if (!s->tx_rate)
|
3863 | d8f699cb | balrog | return;
|
3864 | 73560bc8 | balrog | if (s->tx_req)
|
3865 | 73560bc8 | balrog | printf("%s: Tx FIFO underrun\n", __FUNCTION__);
|
3866 | 73560bc8 | balrog | |
3867 | 73560bc8 | balrog | s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7]; |
3868 | 73560bc8 | balrog | |
3869 | 73560bc8 | balrog | omap_mcbsp_tx_newdata(s); |
3870 | 6ee093c9 | Juan Quintela | qemu_mod_timer(s->sink_timer, qemu_get_clock(vm_clock) + |
3871 | 6ee093c9 | Juan Quintela | get_ticks_per_sec()); |
3872 | 73560bc8 | balrog | } |
3873 | 73560bc8 | balrog | |
3874 | 73560bc8 | balrog | static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s) |
3875 | 73560bc8 | balrog | { |
3876 | 73560bc8 | balrog | if (!s->codec || !s->codec->cts)
|
3877 | 73560bc8 | balrog | omap_mcbsp_sink_tick(s); |
3878 | 73560bc8 | balrog | else if (s->codec->out.size) { |
3879 | 73560bc8 | balrog | s->tx_req = s->codec->out.size; |
3880 | 73560bc8 | balrog | omap_mcbsp_tx_newdata(s); |
3881 | 73560bc8 | balrog | } |
3882 | 73560bc8 | balrog | } |
3883 | 73560bc8 | balrog | |
3884 | 73560bc8 | balrog | static void omap_mcbsp_tx_done(struct omap_mcbsp_s *s) |
3885 | 73560bc8 | balrog | { |
3886 | 73560bc8 | balrog | s->spcr[1] &= ~(1 << 1); /* XRDY */ |
3887 | 73560bc8 | balrog | qemu_irq_lower(s->txdrq); |
3888 | 73560bc8 | balrog | omap_mcbsp_intr_update(s); |
3889 | 73560bc8 | balrog | if (s->codec && s->codec->cts)
|
3890 | 73560bc8 | balrog | s->codec->tx_swallow(s->codec->opaque); |
3891 | d8f699cb | balrog | } |
3892 | d8f699cb | balrog | |
3893 | d8f699cb | balrog | static void omap_mcbsp_tx_stop(struct omap_mcbsp_s *s) |
3894 | d8f699cb | balrog | { |
3895 | 73560bc8 | balrog | s->tx_req = 0;
|
3896 | 73560bc8 | balrog | omap_mcbsp_tx_done(s); |
3897 | 73560bc8 | balrog | qemu_del_timer(s->sink_timer); |
3898 | 73560bc8 | balrog | } |
3899 | 73560bc8 | balrog | |
3900 | 73560bc8 | balrog | static void omap_mcbsp_req_update(struct omap_mcbsp_s *s) |
3901 | 73560bc8 | balrog | { |
3902 | 73560bc8 | balrog | int prev_rx_rate, prev_tx_rate;
|
3903 | 73560bc8 | balrog | int rx_rate = 0, tx_rate = 0; |
3904 | 73560bc8 | balrog | int cpu_rate = 1500000; /* XXX */ |
3905 | 73560bc8 | balrog | |
3906 | 73560bc8 | balrog | /* TODO: check CLKSTP bit */
|
3907 | 73560bc8 | balrog | if (s->spcr[1] & (1 << 6)) { /* GRST */ |
3908 | 73560bc8 | balrog | if (s->spcr[0] & (1 << 0)) { /* RRST */ |
3909 | 73560bc8 | balrog | if ((s->srgr[1] & (1 << 13)) && /* CLKSM */ |
3910 | 73560bc8 | balrog | (s->pcr & (1 << 8))) { /* CLKRM */ |
3911 | 73560bc8 | balrog | if (~s->pcr & (1 << 7)) /* SCLKME */ |
3912 | 73560bc8 | balrog | rx_rate = cpu_rate / |
3913 | 73560bc8 | balrog | ((s->srgr[0] & 0xff) + 1); /* CLKGDV */ |
3914 | 73560bc8 | balrog | } else
|
3915 | 73560bc8 | balrog | if (s->codec)
|
3916 | 73560bc8 | balrog | rx_rate = s->codec->rx_rate; |
3917 | 73560bc8 | balrog | } |
3918 | 73560bc8 | balrog | |
3919 | 73560bc8 | balrog | if (s->spcr[1] & (1 << 0)) { /* XRST */ |
3920 | 73560bc8 | balrog | if ((s->srgr[1] & (1 << 13)) && /* CLKSM */ |
3921 | 73560bc8 | balrog | (s->pcr & (1 << 9))) { /* CLKXM */ |
3922 | 73560bc8 | balrog | if (~s->pcr & (1 << 7)) /* SCLKME */ |
3923 | 73560bc8 | balrog | tx_rate = cpu_rate / |
3924 | 73560bc8 | balrog | ((s->srgr[0] & 0xff) + 1); /* CLKGDV */ |
3925 | 73560bc8 | balrog | } else
|
3926 | 73560bc8 | balrog | if (s->codec)
|
3927 | 73560bc8 | balrog | tx_rate = s->codec->tx_rate; |
3928 | 73560bc8 | balrog | } |
3929 | 73560bc8 | balrog | } |
3930 | 73560bc8 | balrog | prev_tx_rate = s->tx_rate; |
3931 | 73560bc8 | balrog | prev_rx_rate = s->rx_rate; |
3932 | 73560bc8 | balrog | s->tx_rate = tx_rate; |
3933 | 73560bc8 | balrog | s->rx_rate = rx_rate; |
3934 | 73560bc8 | balrog | |
3935 | 73560bc8 | balrog | if (s->codec)
|
3936 | 73560bc8 | balrog | s->codec->set_rate(s->codec->opaque, rx_rate, tx_rate); |
3937 | 73560bc8 | balrog | |
3938 | 73560bc8 | balrog | if (!prev_tx_rate && tx_rate)
|
3939 | 73560bc8 | balrog | omap_mcbsp_tx_start(s); |
3940 | 73560bc8 | balrog | else if (s->tx_rate && !tx_rate) |
3941 | 73560bc8 | balrog | omap_mcbsp_tx_stop(s); |
3942 | 73560bc8 | balrog | |
3943 | 73560bc8 | balrog | if (!prev_rx_rate && rx_rate)
|
3944 | 73560bc8 | balrog | omap_mcbsp_rx_start(s); |
3945 | 73560bc8 | balrog | else if (prev_tx_rate && !tx_rate) |
3946 | 73560bc8 | balrog | omap_mcbsp_rx_stop(s); |
3947 | d8f699cb | balrog | } |
3948 | d8f699cb | balrog | |
3949 | c227f099 | Anthony Liguori | static uint32_t omap_mcbsp_read(void *opaque, target_phys_addr_t addr) |
3950 | d8f699cb | balrog | { |
3951 | d8f699cb | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; |
3952 | d8f699cb | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
3953 | d8f699cb | balrog | uint16_t ret; |
3954 | d8f699cb | balrog | |
3955 | d8f699cb | balrog | switch (offset) {
|
3956 | d8f699cb | balrog | case 0x00: /* DRR2 */ |
3957 | d8f699cb | balrog | if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */ |
3958 | d8f699cb | balrog | return 0x0000; |
3959 | d8f699cb | balrog | /* Fall through. */
|
3960 | d8f699cb | balrog | case 0x02: /* DRR1 */ |
3961 | 73560bc8 | balrog | if (s->rx_req < 2) { |
3962 | d8f699cb | balrog | printf("%s: Rx FIFO underrun\n", __FUNCTION__);
|
3963 | 73560bc8 | balrog | omap_mcbsp_rx_done(s); |
3964 | d8f699cb | balrog | } else {
|
3965 | 73560bc8 | balrog | s->tx_req -= 2;
|
3966 | 73560bc8 | balrog | if (s->codec && s->codec->in.len >= 2) { |
3967 | 73560bc8 | balrog | ret = s->codec->in.fifo[s->codec->in.start ++] << 8;
|
3968 | 73560bc8 | balrog | ret |= s->codec->in.fifo[s->codec->in.start ++]; |
3969 | 73560bc8 | balrog | s->codec->in.len -= 2;
|
3970 | 73560bc8 | balrog | } else
|
3971 | 73560bc8 | balrog | ret = 0x0000;
|
3972 | 73560bc8 | balrog | if (!s->tx_req)
|
3973 | 73560bc8 | balrog | omap_mcbsp_rx_done(s); |
3974 | d8f699cb | balrog | return ret;
|
3975 | d8f699cb | balrog | } |
3976 | d8f699cb | balrog | return 0x0000; |
3977 | d8f699cb | balrog | |
3978 | d8f699cb | balrog | case 0x04: /* DXR2 */ |
3979 | d8f699cb | balrog | case 0x06: /* DXR1 */ |
3980 | d8f699cb | balrog | return 0x0000; |
3981 | d8f699cb | balrog | |
3982 | d8f699cb | balrog | case 0x08: /* SPCR2 */ |
3983 | d8f699cb | balrog | return s->spcr[1]; |
3984 | d8f699cb | balrog | case 0x0a: /* SPCR1 */ |
3985 | d8f699cb | balrog | return s->spcr[0]; |
3986 | d8f699cb | balrog | case 0x0c: /* RCR2 */ |
3987 | d8f699cb | balrog | return s->rcr[1]; |
3988 | d8f699cb | balrog | case 0x0e: /* RCR1 */ |
3989 | d8f699cb | balrog | return s->rcr[0]; |
3990 | d8f699cb | balrog | case 0x10: /* XCR2 */ |
3991 | d8f699cb | balrog | return s->xcr[1]; |
3992 | d8f699cb | balrog | case 0x12: /* XCR1 */ |
3993 | d8f699cb | balrog | return s->xcr[0]; |
3994 | d8f699cb | balrog | case 0x14: /* SRGR2 */ |
3995 | d8f699cb | balrog | return s->srgr[1]; |
3996 | d8f699cb | balrog | case 0x16: /* SRGR1 */ |
3997 | d8f699cb | balrog | return s->srgr[0]; |
3998 | d8f699cb | balrog | case 0x18: /* MCR2 */ |
3999 | d8f699cb | balrog | return s->mcr[1]; |
4000 | d8f699cb | balrog | case 0x1a: /* MCR1 */ |
4001 | d8f699cb | balrog | return s->mcr[0]; |
4002 | d8f699cb | balrog | case 0x1c: /* RCERA */ |
4003 | d8f699cb | balrog | return s->rcer[0]; |
4004 | d8f699cb | balrog | case 0x1e: /* RCERB */ |
4005 | d8f699cb | balrog | return s->rcer[1]; |
4006 | d8f699cb | balrog | case 0x20: /* XCERA */ |
4007 | d8f699cb | balrog | return s->xcer[0]; |
4008 | d8f699cb | balrog | case 0x22: /* XCERB */ |
4009 | d8f699cb | balrog | return s->xcer[1]; |
4010 | d8f699cb | balrog | case 0x24: /* PCR0 */ |
4011 | d8f699cb | balrog | return s->pcr;
|
4012 | d8f699cb | balrog | case 0x26: /* RCERC */ |
4013 | d8f699cb | balrog | return s->rcer[2]; |
4014 | d8f699cb | balrog | case 0x28: /* RCERD */ |
4015 | d8f699cb | balrog | return s->rcer[3]; |
4016 | d8f699cb | balrog | case 0x2a: /* XCERC */ |
4017 | d8f699cb | balrog | return s->xcer[2]; |
4018 | d8f699cb | balrog | case 0x2c: /* XCERD */ |
4019 | d8f699cb | balrog | return s->xcer[3]; |
4020 | d8f699cb | balrog | case 0x2e: /* RCERE */ |
4021 | d8f699cb | balrog | return s->rcer[4]; |
4022 | d8f699cb | balrog | case 0x30: /* RCERF */ |
4023 | d8f699cb | balrog | return s->rcer[5]; |
4024 | d8f699cb | balrog | case 0x32: /* XCERE */ |
4025 | d8f699cb | balrog | return s->xcer[4]; |
4026 | d8f699cb | balrog | case 0x34: /* XCERF */ |
4027 | d8f699cb | balrog | return s->xcer[5]; |
4028 | d8f699cb | balrog | case 0x36: /* RCERG */ |
4029 | d8f699cb | balrog | return s->rcer[6]; |
4030 | d8f699cb | balrog | case 0x38: /* RCERH */ |
4031 | d8f699cb | balrog | return s->rcer[7]; |
4032 | d8f699cb | balrog | case 0x3a: /* XCERG */ |
4033 | d8f699cb | balrog | return s->xcer[6]; |
4034 | d8f699cb | balrog | case 0x3c: /* XCERH */ |
4035 | d8f699cb | balrog | return s->xcer[7]; |
4036 | d8f699cb | balrog | } |
4037 | d8f699cb | balrog | |
4038 | d8f699cb | balrog | OMAP_BAD_REG(addr); |
4039 | d8f699cb | balrog | return 0; |
4040 | d8f699cb | balrog | } |
4041 | d8f699cb | balrog | |
4042 | c227f099 | Anthony Liguori | static void omap_mcbsp_writeh(void *opaque, target_phys_addr_t addr, |
4043 | d8f699cb | balrog | uint32_t value) |
4044 | d8f699cb | balrog | { |
4045 | d8f699cb | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; |
4046 | d8f699cb | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
4047 | d8f699cb | balrog | |
4048 | d8f699cb | balrog | switch (offset) {
|
4049 | d8f699cb | balrog | case 0x00: /* DRR2 */ |
4050 | d8f699cb | balrog | case 0x02: /* DRR1 */ |
4051 | d8f699cb | balrog | OMAP_RO_REG(addr); |
4052 | d8f699cb | balrog | return;
|
4053 | d8f699cb | balrog | |
4054 | d8f699cb | balrog | case 0x04: /* DXR2 */ |
4055 | d8f699cb | balrog | if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */ |
4056 | d8f699cb | balrog | return;
|
4057 | d8f699cb | balrog | /* Fall through. */
|
4058 | d8f699cb | balrog | case 0x06: /* DXR1 */ |
4059 | 73560bc8 | balrog | if (s->tx_req > 1) { |
4060 | 73560bc8 | balrog | s->tx_req -= 2;
|
4061 | 73560bc8 | balrog | if (s->codec && s->codec->cts) {
|
4062 | d8f699cb | balrog | s->codec->out.fifo[s->codec->out.len ++] = (value >> 8) & 0xff; |
4063 | d8f699cb | balrog | s->codec->out.fifo[s->codec->out.len ++] = (value >> 0) & 0xff; |
4064 | d8f699cb | balrog | } |
4065 | 73560bc8 | balrog | if (s->tx_req < 2) |
4066 | 73560bc8 | balrog | omap_mcbsp_tx_done(s); |
4067 | d8f699cb | balrog | } else
|
4068 | d8f699cb | balrog | printf("%s: Tx FIFO overrun\n", __FUNCTION__);
|
4069 | d8f699cb | balrog | return;
|
4070 | d8f699cb | balrog | |
4071 | d8f699cb | balrog | case 0x08: /* SPCR2 */ |
4072 | d8f699cb | balrog | s->spcr[1] &= 0x0002; |
4073 | d8f699cb | balrog | s->spcr[1] |= 0x03f9 & value; |
4074 | d8f699cb | balrog | s->spcr[1] |= 0x0004 & (value << 2); /* XEMPTY := XRST */ |
4075 | 73560bc8 | balrog | if (~value & 1) /* XRST */ |
4076 | d8f699cb | balrog | s->spcr[1] &= ~6; |
4077 | d8f699cb | balrog | omap_mcbsp_req_update(s); |
4078 | d8f699cb | balrog | return;
|
4079 | d8f699cb | balrog | case 0x0a: /* SPCR1 */ |
4080 | d8f699cb | balrog | s->spcr[0] &= 0x0006; |
4081 | d8f699cb | balrog | s->spcr[0] |= 0xf8f9 & value; |
4082 | d8f699cb | balrog | if (value & (1 << 15)) /* DLB */ |
4083 | d8f699cb | balrog | printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__);
|
4084 | d8f699cb | balrog | if (~value & 1) { /* RRST */ |
4085 | d8f699cb | balrog | s->spcr[0] &= ~6; |
4086 | 73560bc8 | balrog | s->rx_req = 0;
|
4087 | 73560bc8 | balrog | omap_mcbsp_rx_done(s); |
4088 | d8f699cb | balrog | } |
4089 | d8f699cb | balrog | omap_mcbsp_req_update(s); |
4090 | d8f699cb | balrog | return;
|
4091 | d8f699cb | balrog | |
4092 | d8f699cb | balrog | case 0x0c: /* RCR2 */ |
4093 | d8f699cb | balrog | s->rcr[1] = value & 0xffff; |
4094 | d8f699cb | balrog | return;
|
4095 | d8f699cb | balrog | case 0x0e: /* RCR1 */ |
4096 | d8f699cb | balrog | s->rcr[0] = value & 0x7fe0; |
4097 | d8f699cb | balrog | return;
|
4098 | d8f699cb | balrog | case 0x10: /* XCR2 */ |
4099 | d8f699cb | balrog | s->xcr[1] = value & 0xffff; |
4100 | d8f699cb | balrog | return;
|
4101 | d8f699cb | balrog | case 0x12: /* XCR1 */ |
4102 | d8f699cb | balrog | s->xcr[0] = value & 0x7fe0; |
4103 | d8f699cb | balrog | return;
|
4104 | d8f699cb | balrog | case 0x14: /* SRGR2 */ |
4105 | d8f699cb | balrog | s->srgr[1] = value & 0xffff; |
4106 | 73560bc8 | balrog | omap_mcbsp_req_update(s); |
4107 | d8f699cb | balrog | return;
|
4108 | d8f699cb | balrog | case 0x16: /* SRGR1 */ |
4109 | d8f699cb | balrog | s->srgr[0] = value & 0xffff; |
4110 | 73560bc8 | balrog | omap_mcbsp_req_update(s); |
4111 | d8f699cb | balrog | return;
|
4112 | d8f699cb | balrog | case 0x18: /* MCR2 */ |
4113 | d8f699cb | balrog | s->mcr[1] = value & 0x03e3; |
4114 | d8f699cb | balrog | if (value & 3) /* XMCM */ |
4115 | d8f699cb | balrog | printf("%s: Tx channel selection mode enable attempt\n",
|
4116 | d8f699cb | balrog | __FUNCTION__); |
4117 | d8f699cb | balrog | return;
|
4118 | d8f699cb | balrog | case 0x1a: /* MCR1 */ |
4119 | d8f699cb | balrog | s->mcr[0] = value & 0x03e1; |
4120 | d8f699cb | balrog | if (value & 1) /* RMCM */ |
4121 | d8f699cb | balrog | printf("%s: Rx channel selection mode enable attempt\n",
|
4122 | d8f699cb | balrog | __FUNCTION__); |
4123 | d8f699cb | balrog | return;
|
4124 | d8f699cb | balrog | case 0x1c: /* RCERA */ |
4125 | d8f699cb | balrog | s->rcer[0] = value & 0xffff; |
4126 | d8f699cb | balrog | return;
|
4127 | d8f699cb | balrog | case 0x1e: /* RCERB */ |
4128 | d8f699cb | balrog | s->rcer[1] = value & 0xffff; |
4129 | d8f699cb | balrog | return;
|
4130 | d8f699cb | balrog | case 0x20: /* XCERA */ |
4131 | d8f699cb | balrog | s->xcer[0] = value & 0xffff; |
4132 | d8f699cb | balrog | return;
|
4133 | d8f699cb | balrog | case 0x22: /* XCERB */ |
4134 | d8f699cb | balrog | s->xcer[1] = value & 0xffff; |
4135 | d8f699cb | balrog | return;
|
4136 | d8f699cb | balrog | case 0x24: /* PCR0 */ |
4137 | d8f699cb | balrog | s->pcr = value & 0x7faf;
|
4138 | d8f699cb | balrog | return;
|
4139 | d8f699cb | balrog | case 0x26: /* RCERC */ |
4140 | d8f699cb | balrog | s->rcer[2] = value & 0xffff; |
4141 | d8f699cb | balrog | return;
|
4142 | d8f699cb | balrog | case 0x28: /* RCERD */ |
4143 | d8f699cb | balrog | s->rcer[3] = value & 0xffff; |
4144 | d8f699cb | balrog | return;
|
4145 | d8f699cb | balrog | case 0x2a: /* XCERC */ |
4146 | d8f699cb | balrog | s->xcer[2] = value & 0xffff; |
4147 | d8f699cb | balrog | return;
|
4148 | d8f699cb | balrog | case 0x2c: /* XCERD */ |
4149 | d8f699cb | balrog | s->xcer[3] = value & 0xffff; |
4150 | d8f699cb | balrog | return;
|
4151 | d8f699cb | balrog | case 0x2e: /* RCERE */ |
4152 | d8f699cb | balrog | s->rcer[4] = value & 0xffff; |
4153 | d8f699cb | balrog | return;
|
4154 | d8f699cb | balrog | case 0x30: /* RCERF */ |
4155 | d8f699cb | balrog | s->rcer[5] = value & 0xffff; |
4156 | d8f699cb | balrog | return;
|
4157 | d8f699cb | balrog | case 0x32: /* XCERE */ |
4158 | d8f699cb | balrog | s->xcer[4] = value & 0xffff; |
4159 | d8f699cb | balrog | return;
|
4160 | d8f699cb | balrog | case 0x34: /* XCERF */ |
4161 | d8f699cb | balrog | s->xcer[5] = value & 0xffff; |
4162 | d8f699cb | balrog | return;
|
4163 | d8f699cb | balrog | case 0x36: /* RCERG */ |
4164 | d8f699cb | balrog | s->rcer[6] = value & 0xffff; |
4165 | d8f699cb | balrog | return;
|
4166 | d8f699cb | balrog | case 0x38: /* RCERH */ |
4167 | d8f699cb | balrog | s->rcer[7] = value & 0xffff; |
4168 | d8f699cb | balrog | return;
|
4169 | d8f699cb | balrog | case 0x3a: /* XCERG */ |
4170 | d8f699cb | balrog | s->xcer[6] = value & 0xffff; |
4171 | d8f699cb | balrog | return;
|
4172 | d8f699cb | balrog | case 0x3c: /* XCERH */ |
4173 | d8f699cb | balrog | s->xcer[7] = value & 0xffff; |
4174 | d8f699cb | balrog | return;
|
4175 | d8f699cb | balrog | } |
4176 | d8f699cb | balrog | |
4177 | d8f699cb | balrog | OMAP_BAD_REG(addr); |
4178 | d8f699cb | balrog | } |
4179 | d8f699cb | balrog | |
4180 | c227f099 | Anthony Liguori | static void omap_mcbsp_writew(void *opaque, target_phys_addr_t addr, |
4181 | 73560bc8 | balrog | uint32_t value) |
4182 | 73560bc8 | balrog | { |
4183 | 73560bc8 | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; |
4184 | 73560bc8 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
4185 | 73560bc8 | balrog | |
4186 | 73560bc8 | balrog | if (offset == 0x04) { /* DXR */ |
4187 | 73560bc8 | balrog | if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */ |
4188 | 73560bc8 | balrog | return;
|
4189 | 73560bc8 | balrog | if (s->tx_req > 3) { |
4190 | 73560bc8 | balrog | s->tx_req -= 4;
|
4191 | 73560bc8 | balrog | if (s->codec && s->codec->cts) {
|
4192 | 73560bc8 | balrog | s->codec->out.fifo[s->codec->out.len ++] = |
4193 | 73560bc8 | balrog | (value >> 24) & 0xff; |
4194 | 73560bc8 | balrog | s->codec->out.fifo[s->codec->out.len ++] = |
4195 | 73560bc8 | balrog | (value >> 16) & 0xff; |
4196 | 73560bc8 | balrog | s->codec->out.fifo[s->codec->out.len ++] = |
4197 | 73560bc8 | balrog | (value >> 8) & 0xff; |
4198 | 73560bc8 | balrog | s->codec->out.fifo[s->codec->out.len ++] = |
4199 | 73560bc8 | balrog | (value >> 0) & 0xff; |
4200 | 73560bc8 | balrog | } |
4201 | 73560bc8 | balrog | if (s->tx_req < 4) |
4202 | 73560bc8 | balrog | omap_mcbsp_tx_done(s); |
4203 | 73560bc8 | balrog | } else
|
4204 | 73560bc8 | balrog | printf("%s: Tx FIFO overrun\n", __FUNCTION__);
|
4205 | 73560bc8 | balrog | return;
|
4206 | 73560bc8 | balrog | } |
4207 | 73560bc8 | balrog | |
4208 | 73560bc8 | balrog | omap_badwidth_write16(opaque, addr, value); |
4209 | 73560bc8 | balrog | } |
4210 | 73560bc8 | balrog | |
4211 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_mcbsp_readfn[] = { |
4212 | d8f699cb | balrog | omap_badwidth_read16, |
4213 | d8f699cb | balrog | omap_mcbsp_read, |
4214 | d8f699cb | balrog | omap_badwidth_read16, |
4215 | d8f699cb | balrog | }; |
4216 | d8f699cb | balrog | |
4217 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_mcbsp_writefn[] = { |
4218 | d8f699cb | balrog | omap_badwidth_write16, |
4219 | 73560bc8 | balrog | omap_mcbsp_writeh, |
4220 | 73560bc8 | balrog | omap_mcbsp_writew, |
4221 | d8f699cb | balrog | }; |
4222 | d8f699cb | balrog | |
4223 | d8f699cb | balrog | static void omap_mcbsp_reset(struct omap_mcbsp_s *s) |
4224 | d8f699cb | balrog | { |
4225 | d8f699cb | balrog | memset(&s->spcr, 0, sizeof(s->spcr)); |
4226 | d8f699cb | balrog | memset(&s->rcr, 0, sizeof(s->rcr)); |
4227 | d8f699cb | balrog | memset(&s->xcr, 0, sizeof(s->xcr)); |
4228 | d8f699cb | balrog | s->srgr[0] = 0x0001; |
4229 | d8f699cb | balrog | s->srgr[1] = 0x2000; |
4230 | d8f699cb | balrog | memset(&s->mcr, 0, sizeof(s->mcr)); |
4231 | d8f699cb | balrog | memset(&s->pcr, 0, sizeof(s->pcr)); |
4232 | d8f699cb | balrog | memset(&s->rcer, 0, sizeof(s->rcer)); |
4233 | d8f699cb | balrog | memset(&s->xcer, 0, sizeof(s->xcer)); |
4234 | d8f699cb | balrog | s->tx_req = 0;
|
4235 | 73560bc8 | balrog | s->rx_req = 0;
|
4236 | d8f699cb | balrog | s->tx_rate = 0;
|
4237 | d8f699cb | balrog | s->rx_rate = 0;
|
4238 | 73560bc8 | balrog | qemu_del_timer(s->source_timer); |
4239 | 73560bc8 | balrog | qemu_del_timer(s->sink_timer); |
4240 | d8f699cb | balrog | } |
4241 | d8f699cb | balrog | |
4242 | c227f099 | Anthony Liguori | struct omap_mcbsp_s *omap_mcbsp_init(target_phys_addr_t base,
|
4243 | d8f699cb | balrog | qemu_irq *irq, qemu_irq *dma, omap_clk clk) |
4244 | d8f699cb | balrog | { |
4245 | d8f699cb | balrog | int iomemtype;
|
4246 | d8f699cb | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) |
4247 | d8f699cb | balrog | qemu_mallocz(sizeof(struct omap_mcbsp_s)); |
4248 | d8f699cb | balrog | |
4249 | d8f699cb | balrog | s->txirq = irq[0];
|
4250 | d8f699cb | balrog | s->rxirq = irq[1];
|
4251 | d8f699cb | balrog | s->txdrq = dma[0];
|
4252 | d8f699cb | balrog | s->rxdrq = dma[1];
|
4253 | 73560bc8 | balrog | s->sink_timer = qemu_new_timer(vm_clock, omap_mcbsp_sink_tick, s); |
4254 | 73560bc8 | balrog | s->source_timer = qemu_new_timer(vm_clock, omap_mcbsp_source_tick, s); |
4255 | d8f699cb | balrog | omap_mcbsp_reset(s); |
4256 | d8f699cb | balrog | |
4257 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_mcbsp_readfn, |
4258 | d8f699cb | balrog | omap_mcbsp_writefn, s); |
4259 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
4260 | d8f699cb | balrog | |
4261 | d8f699cb | balrog | return s;
|
4262 | d8f699cb | balrog | } |
4263 | d8f699cb | balrog | |
4264 | 9596ebb7 | pbrook | static void omap_mcbsp_i2s_swallow(void *opaque, int line, int level) |
4265 | d8f699cb | balrog | { |
4266 | d8f699cb | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; |
4267 | d8f699cb | balrog | |
4268 | 73560bc8 | balrog | if (s->rx_rate) {
|
4269 | 73560bc8 | balrog | s->rx_req = s->codec->in.len; |
4270 | 73560bc8 | balrog | omap_mcbsp_rx_newdata(s); |
4271 | 73560bc8 | balrog | } |
4272 | d8f699cb | balrog | } |
4273 | d8f699cb | balrog | |
4274 | 9596ebb7 | pbrook | static void omap_mcbsp_i2s_start(void *opaque, int line, int level) |
4275 | d8f699cb | balrog | { |
4276 | d8f699cb | balrog | struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; |
4277 | d8f699cb | balrog | |
4278 | 73560bc8 | balrog | if (s->tx_rate) {
|
4279 | 73560bc8 | balrog | s->tx_req = s->codec->out.size; |
4280 | 73560bc8 | balrog | omap_mcbsp_tx_newdata(s); |
4281 | 73560bc8 | balrog | } |
4282 | d8f699cb | balrog | } |
4283 | d8f699cb | balrog | |
4284 | bc24a225 | Paul Brook | void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, I2SCodec *slave) |
4285 | d8f699cb | balrog | { |
4286 | d8f699cb | balrog | s->codec = slave; |
4287 | d8f699cb | balrog | slave->rx_swallow = qemu_allocate_irqs(omap_mcbsp_i2s_swallow, s, 1)[0]; |
4288 | d8f699cb | balrog | slave->tx_start = qemu_allocate_irqs(omap_mcbsp_i2s_start, s, 1)[0]; |
4289 | d8f699cb | balrog | } |
4290 | d8f699cb | balrog | |
4291 | f9d43072 | balrog | /* LED Pulse Generators */
|
4292 | f9d43072 | balrog | struct omap_lpg_s {
|
4293 | f9d43072 | balrog | QEMUTimer *tm; |
4294 | f9d43072 | balrog | |
4295 | f9d43072 | balrog | uint8_t control; |
4296 | f9d43072 | balrog | uint8_t power; |
4297 | f9d43072 | balrog | int64_t on; |
4298 | f9d43072 | balrog | int64_t period; |
4299 | f9d43072 | balrog | int clk;
|
4300 | f9d43072 | balrog | int cycle;
|
4301 | f9d43072 | balrog | }; |
4302 | f9d43072 | balrog | |
4303 | f9d43072 | balrog | static void omap_lpg_tick(void *opaque) |
4304 | f9d43072 | balrog | { |
4305 | f9d43072 | balrog | struct omap_lpg_s *s = opaque;
|
4306 | f9d43072 | balrog | |
4307 | f9d43072 | balrog | if (s->cycle)
|
4308 | f9d43072 | balrog | qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->period - s->on); |
4309 | f9d43072 | balrog | else
|
4310 | f9d43072 | balrog | qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->on); |
4311 | f9d43072 | balrog | |
4312 | f9d43072 | balrog | s->cycle = !s->cycle; |
4313 | f9d43072 | balrog | printf("%s: LED is %s\n", __FUNCTION__, s->cycle ? "on" : "off"); |
4314 | f9d43072 | balrog | } |
4315 | f9d43072 | balrog | |
4316 | f9d43072 | balrog | static void omap_lpg_update(struct omap_lpg_s *s) |
4317 | f9d43072 | balrog | { |
4318 | f9d43072 | balrog | int64_t on, period = 1, ticks = 1000; |
4319 | f9d43072 | balrog | static const int per[8] = { 1, 2, 4, 8, 12, 16, 20, 24 }; |
4320 | f9d43072 | balrog | |
4321 | f9d43072 | balrog | if (~s->control & (1 << 6)) /* LPGRES */ |
4322 | f9d43072 | balrog | on = 0;
|
4323 | f9d43072 | balrog | else if (s->control & (1 << 7)) /* PERM_ON */ |
4324 | f9d43072 | balrog | on = period; |
4325 | f9d43072 | balrog | else {
|
4326 | f9d43072 | balrog | period = muldiv64(ticks, per[s->control & 7], /* PERCTRL */ |
4327 | f9d43072 | balrog | 256 / 32); |
4328 | f9d43072 | balrog | on = (s->clk && s->power) ? muldiv64(ticks, |
4329 | f9d43072 | balrog | per[(s->control >> 3) & 7], 256) : 0; /* ONCTRL */ |
4330 | f9d43072 | balrog | } |
4331 | f9d43072 | balrog | |
4332 | f9d43072 | balrog | qemu_del_timer(s->tm); |
4333 | f9d43072 | balrog | if (on == period && s->on < s->period)
|
4334 | f9d43072 | balrog | printf("%s: LED is on\n", __FUNCTION__);
|
4335 | f9d43072 | balrog | else if (on == 0 && s->on) |
4336 | f9d43072 | balrog | printf("%s: LED is off\n", __FUNCTION__);
|
4337 | f9d43072 | balrog | else if (on && (on != s->on || period != s->period)) { |
4338 | f9d43072 | balrog | s->cycle = 0;
|
4339 | f9d43072 | balrog | s->on = on; |
4340 | f9d43072 | balrog | s->period = period; |
4341 | f9d43072 | balrog | omap_lpg_tick(s); |
4342 | f9d43072 | balrog | return;
|
4343 | f9d43072 | balrog | } |
4344 | f9d43072 | balrog | |
4345 | f9d43072 | balrog | s->on = on; |
4346 | f9d43072 | balrog | s->period = period; |
4347 | f9d43072 | balrog | } |
4348 | f9d43072 | balrog | |
4349 | f9d43072 | balrog | static void omap_lpg_reset(struct omap_lpg_s *s) |
4350 | f9d43072 | balrog | { |
4351 | f9d43072 | balrog | s->control = 0x00;
|
4352 | f9d43072 | balrog | s->power = 0x00;
|
4353 | f9d43072 | balrog | s->clk = 1;
|
4354 | f9d43072 | balrog | omap_lpg_update(s); |
4355 | f9d43072 | balrog | } |
4356 | f9d43072 | balrog | |
4357 | c227f099 | Anthony Liguori | static uint32_t omap_lpg_read(void *opaque, target_phys_addr_t addr) |
4358 | f9d43072 | balrog | { |
4359 | f9d43072 | balrog | struct omap_lpg_s *s = (struct omap_lpg_s *) opaque; |
4360 | f9d43072 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
4361 | f9d43072 | balrog | |
4362 | f9d43072 | balrog | switch (offset) {
|
4363 | f9d43072 | balrog | case 0x00: /* LCR */ |
4364 | f9d43072 | balrog | return s->control;
|
4365 | f9d43072 | balrog | |
4366 | f9d43072 | balrog | case 0x04: /* PMR */ |
4367 | f9d43072 | balrog | return s->power;
|
4368 | f9d43072 | balrog | } |
4369 | f9d43072 | balrog | |
4370 | f9d43072 | balrog | OMAP_BAD_REG(addr); |
4371 | f9d43072 | balrog | return 0; |
4372 | f9d43072 | balrog | } |
4373 | f9d43072 | balrog | |
4374 | c227f099 | Anthony Liguori | static void omap_lpg_write(void *opaque, target_phys_addr_t addr, |
4375 | f9d43072 | balrog | uint32_t value) |
4376 | f9d43072 | balrog | { |
4377 | f9d43072 | balrog | struct omap_lpg_s *s = (struct omap_lpg_s *) opaque; |
4378 | f9d43072 | balrog | int offset = addr & OMAP_MPUI_REG_MASK;
|
4379 | f9d43072 | balrog | |
4380 | f9d43072 | balrog | switch (offset) {
|
4381 | f9d43072 | balrog | case 0x00: /* LCR */ |
4382 | f9d43072 | balrog | if (~value & (1 << 6)) /* LPGRES */ |
4383 | f9d43072 | balrog | omap_lpg_reset(s); |
4384 | f9d43072 | balrog | s->control = value & 0xff;
|
4385 | f9d43072 | balrog | omap_lpg_update(s); |
4386 | f9d43072 | balrog | return;
|
4387 | f9d43072 | balrog | |
4388 | f9d43072 | balrog | case 0x04: /* PMR */ |
4389 | f9d43072 | balrog | s->power = value & 0x01;
|
4390 | f9d43072 | balrog | omap_lpg_update(s); |
4391 | f9d43072 | balrog | return;
|
4392 | f9d43072 | balrog | |
4393 | f9d43072 | balrog | default:
|
4394 | f9d43072 | balrog | OMAP_BAD_REG(addr); |
4395 | f9d43072 | balrog | return;
|
4396 | f9d43072 | balrog | } |
4397 | f9d43072 | balrog | } |
4398 | f9d43072 | balrog | |
4399 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_lpg_readfn[] = { |
4400 | f9d43072 | balrog | omap_lpg_read, |
4401 | f9d43072 | balrog | omap_badwidth_read8, |
4402 | f9d43072 | balrog | omap_badwidth_read8, |
4403 | f9d43072 | balrog | }; |
4404 | f9d43072 | balrog | |
4405 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_lpg_writefn[] = { |
4406 | f9d43072 | balrog | omap_lpg_write, |
4407 | f9d43072 | balrog | omap_badwidth_write8, |
4408 | f9d43072 | balrog | omap_badwidth_write8, |
4409 | f9d43072 | balrog | }; |
4410 | f9d43072 | balrog | |
4411 | f9d43072 | balrog | static void omap_lpg_clk_update(void *opaque, int line, int on) |
4412 | f9d43072 | balrog | { |
4413 | f9d43072 | balrog | struct omap_lpg_s *s = (struct omap_lpg_s *) opaque; |
4414 | f9d43072 | balrog | |
4415 | f9d43072 | balrog | s->clk = on; |
4416 | f9d43072 | balrog | omap_lpg_update(s); |
4417 | f9d43072 | balrog | } |
4418 | f9d43072 | balrog | |
4419 | c227f099 | Anthony Liguori | struct omap_lpg_s *omap_lpg_init(target_phys_addr_t base, omap_clk clk)
|
4420 | f9d43072 | balrog | { |
4421 | f9d43072 | balrog | int iomemtype;
|
4422 | f9d43072 | balrog | struct omap_lpg_s *s = (struct omap_lpg_s *) |
4423 | f9d43072 | balrog | qemu_mallocz(sizeof(struct omap_lpg_s)); |
4424 | f9d43072 | balrog | |
4425 | f9d43072 | balrog | s->tm = qemu_new_timer(rt_clock, omap_lpg_tick, s); |
4426 | f9d43072 | balrog | |
4427 | f9d43072 | balrog | omap_lpg_reset(s); |
4428 | f9d43072 | balrog | |
4429 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(omap_lpg_readfn, |
4430 | f9d43072 | balrog | omap_lpg_writefn, s); |
4431 | 8da3ff18 | pbrook | cpu_register_physical_memory(base, 0x800, iomemtype);
|
4432 | f9d43072 | balrog | |
4433 | f9d43072 | balrog | omap_clk_adduser(clk, qemu_allocate_irqs(omap_lpg_clk_update, s, 1)[0]); |
4434 | f9d43072 | balrog | |
4435 | f9d43072 | balrog | return s;
|
4436 | f9d43072 | balrog | } |
4437 | f9d43072 | balrog | |
4438 | f9d43072 | balrog | /* MPUI Peripheral Bridge configuration */
|
4439 | c227f099 | Anthony Liguori | static uint32_t omap_mpui_io_read(void *opaque, target_phys_addr_t addr) |
4440 | f9d43072 | balrog | { |
4441 | f9d43072 | balrog | if (addr == OMAP_MPUI_BASE) /* CMR */ |
4442 | f9d43072 | balrog | return 0xfe4d; |
4443 | f9d43072 | balrog | |
4444 | f9d43072 | balrog | OMAP_BAD_REG(addr); |
4445 | f9d43072 | balrog | return 0; |
4446 | f9d43072 | balrog | } |
4447 | f9d43072 | balrog | |
4448 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const omap_mpui_io_readfn[] = { |
4449 | f9d43072 | balrog | omap_badwidth_read16, |
4450 | f9d43072 | balrog | omap_mpui_io_read, |
4451 | f9d43072 | balrog | omap_badwidth_read16, |
4452 | f9d43072 | balrog | }; |
4453 | f9d43072 | balrog | |
4454 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const omap_mpui_io_writefn[] = { |
4455 | f9d43072 | balrog | omap_badwidth_write16, |
4456 | f9d43072 | balrog | omap_badwidth_write16, |
4457 | f9d43072 | balrog | omap_badwidth_write16, |
4458 | f9d43072 | balrog | }; |
4459 | f9d43072 | balrog | |
4460 | f9d43072 | balrog | static void omap_setup_mpui_io(struct omap_mpu_state_s *mpu) |
4461 | f9d43072 | balrog | { |
4462 | 1eed09cb | Avi Kivity | int iomemtype = cpu_register_io_memory(omap_mpui_io_readfn,
|
4463 | f9d43072 | balrog | omap_mpui_io_writefn, mpu); |
4464 | f9d43072 | balrog | cpu_register_physical_memory(OMAP_MPUI_BASE, 0x7fff, iomemtype);
|
4465 | f9d43072 | balrog | } |
4466 | f9d43072 | balrog | |
4467 | c3d2689d | balrog | /* General chip reset */
|
4468 | 827df9f3 | balrog | static void omap1_mpu_reset(void *opaque) |
4469 | c3d2689d | balrog | { |
4470 | c3d2689d | balrog | struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque; |
4471 | c3d2689d | balrog | |
4472 | c3d2689d | balrog | omap_inth_reset(mpu->ih[0]);
|
4473 | c3d2689d | balrog | omap_inth_reset(mpu->ih[1]);
|
4474 | c3d2689d | balrog | omap_dma_reset(mpu->dma); |
4475 | c3d2689d | balrog | omap_mpu_timer_reset(mpu->timer[0]);
|
4476 | c3d2689d | balrog | omap_mpu_timer_reset(mpu->timer[1]);
|
4477 | c3d2689d | balrog | omap_mpu_timer_reset(mpu->timer[2]);
|
4478 | c3d2689d | balrog | omap_wd_timer_reset(mpu->wdt); |
4479 | c3d2689d | balrog | omap_os_timer_reset(mpu->os_timer); |
4480 | c3d2689d | balrog | omap_lcdc_reset(mpu->lcd); |
4481 | c3d2689d | balrog | omap_ulpd_pm_reset(mpu); |
4482 | c3d2689d | balrog | omap_pin_cfg_reset(mpu); |
4483 | c3d2689d | balrog | omap_mpui_reset(mpu); |
4484 | c3d2689d | balrog | omap_tipb_bridge_reset(mpu->private_tipb); |
4485 | c3d2689d | balrog | omap_tipb_bridge_reset(mpu->public_tipb); |
4486 | c3d2689d | balrog | omap_dpll_reset(&mpu->dpll[0]);
|
4487 | c3d2689d | balrog | omap_dpll_reset(&mpu->dpll[1]);
|
4488 | c3d2689d | balrog | omap_dpll_reset(&mpu->dpll[2]);
|
4489 | d951f6ff | balrog | omap_uart_reset(mpu->uart[0]);
|
4490 | d951f6ff | balrog | omap_uart_reset(mpu->uart[1]);
|
4491 | d951f6ff | balrog | omap_uart_reset(mpu->uart[2]);
|
4492 | b30bb3a2 | balrog | omap_mmc_reset(mpu->mmc); |
4493 | fe71e81a | balrog | omap_mpuio_reset(mpu->mpuio); |
4494 | 64330148 | balrog | omap_gpio_reset(mpu->gpio); |
4495 | d951f6ff | balrog | omap_uwire_reset(mpu->microwire); |
4496 | 66450b15 | balrog | omap_pwl_reset(mpu); |
4497 | 4a2c8ac2 | balrog | omap_pwt_reset(mpu); |
4498 | 827df9f3 | balrog | omap_i2c_reset(mpu->i2c[0]);
|
4499 | 5c1c390f | balrog | omap_rtc_reset(mpu->rtc); |
4500 | d8f699cb | balrog | omap_mcbsp_reset(mpu->mcbsp1); |
4501 | d8f699cb | balrog | omap_mcbsp_reset(mpu->mcbsp2); |
4502 | d8f699cb | balrog | omap_mcbsp_reset(mpu->mcbsp3); |
4503 | f9d43072 | balrog | omap_lpg_reset(mpu->led[0]);
|
4504 | f9d43072 | balrog | omap_lpg_reset(mpu->led[1]);
|
4505 | 8ef6367e | balrog | omap_clkm_reset(mpu); |
4506 | c3d2689d | balrog | cpu_reset(mpu->env); |
4507 | c3d2689d | balrog | } |
4508 | c3d2689d | balrog | |
4509 | cf965d24 | balrog | static const struct omap_map_s { |
4510 | c227f099 | Anthony Liguori | target_phys_addr_t phys_dsp; |
4511 | c227f099 | Anthony Liguori | target_phys_addr_t phys_mpu; |
4512 | cf965d24 | balrog | uint32_t size; |
4513 | cf965d24 | balrog | const char *name; |
4514 | cf965d24 | balrog | } omap15xx_dsp_mm[] = { |
4515 | cf965d24 | balrog | /* Strobe 0 */
|
4516 | cf965d24 | balrog | { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */ |
4517 | cf965d24 | balrog | { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */ |
4518 | cf965d24 | balrog | { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */ |
4519 | cf965d24 | balrog | { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */ |
4520 | cf965d24 | balrog | { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */ |
4521 | cf965d24 | balrog | { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */ |
4522 | cf965d24 | balrog | { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */ |
4523 | cf965d24 | balrog | { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */ |
4524 | cf965d24 | balrog | { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */ |
4525 | cf965d24 | balrog | { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */ |
4526 | cf965d24 | balrog | { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */ |
4527 | cf965d24 | balrog | { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */ |
4528 | cf965d24 | balrog | { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */ |
4529 | cf965d24 | balrog | { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */ |
4530 | cf965d24 | balrog | { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */ |
4531 | cf965d24 | balrog | { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */ |
4532 | cf965d24 | balrog | { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */ |
4533 | cf965d24 | balrog | /* Strobe 1 */
|
4534 | cf965d24 | balrog | { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */ |
4535 | cf965d24 | balrog | |
4536 | cf965d24 | balrog | { 0 }
|
4537 | cf965d24 | balrog | }; |
4538 | cf965d24 | balrog | |
4539 | cf965d24 | balrog | static void omap_setup_dsp_mapping(const struct omap_map_s *map) |
4540 | cf965d24 | balrog | { |
4541 | cf965d24 | balrog | int io;
|
4542 | cf965d24 | balrog | |
4543 | cf965d24 | balrog | for (; map->phys_dsp; map ++) {
|
4544 | cf965d24 | balrog | io = cpu_get_physical_page_desc(map->phys_mpu); |
4545 | cf965d24 | balrog | |
4546 | cf965d24 | balrog | cpu_register_physical_memory(map->phys_dsp, map->size, io); |
4547 | cf965d24 | balrog | } |
4548 | cf965d24 | balrog | } |
4549 | cf965d24 | balrog | |
4550 | 827df9f3 | balrog | void omap_mpu_wakeup(void *opaque, int irq, int req) |
4551 | c3d2689d | balrog | { |
4552 | c3d2689d | balrog | struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque; |
4553 | c3d2689d | balrog | |
4554 | fe71e81a | balrog | if (mpu->env->halted)
|
4555 | fe71e81a | balrog | cpu_interrupt(mpu->env, CPU_INTERRUPT_EXITTB); |
4556 | c3d2689d | balrog | } |
4557 | c3d2689d | balrog | |
4558 | 827df9f3 | balrog | static const struct dma_irq_map omap1_dma_irq_map[] = { |
4559 | 089b7c0a | balrog | { 0, OMAP_INT_DMA_CH0_6 },
|
4560 | 089b7c0a | balrog | { 0, OMAP_INT_DMA_CH1_7 },
|
4561 | 089b7c0a | balrog | { 0, OMAP_INT_DMA_CH2_8 },
|
4562 | 089b7c0a | balrog | { 0, OMAP_INT_DMA_CH3 },
|
4563 | 089b7c0a | balrog | { 0, OMAP_INT_DMA_CH4 },
|
4564 | 089b7c0a | balrog | { 0, OMAP_INT_DMA_CH5 },
|
4565 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH6 },
|
4566 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH7 },
|
4567 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH8 },
|
4568 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH9 },
|
4569 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH10 },
|
4570 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH11 },
|
4571 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH12 },
|
4572 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH13 },
|
4573 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH14 },
|
4574 | 089b7c0a | balrog | { 1, OMAP_INT_1610_DMA_CH15 }
|
4575 | 089b7c0a | balrog | }; |
4576 | 089b7c0a | balrog | |
4577 | b4e3104b | balrog | /* DMA ports for OMAP1 */
|
4578 | b4e3104b | balrog | static int omap_validate_emiff_addr(struct omap_mpu_state_s *s, |
4579 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
4580 | b4e3104b | balrog | { |
4581 | b4e3104b | balrog | return addr >= OMAP_EMIFF_BASE && addr < OMAP_EMIFF_BASE + s->sdram_size;
|
4582 | b4e3104b | balrog | } |
4583 | b4e3104b | balrog | |
4584 | b4e3104b | balrog | static int omap_validate_emifs_addr(struct omap_mpu_state_s *s, |
4585 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
4586 | b4e3104b | balrog | { |
4587 | b4e3104b | balrog | return addr >= OMAP_EMIFS_BASE && addr < OMAP_EMIFF_BASE;
|
4588 | b4e3104b | balrog | } |
4589 | b4e3104b | balrog | |
4590 | b4e3104b | balrog | static int omap_validate_imif_addr(struct omap_mpu_state_s *s, |
4591 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
4592 | b4e3104b | balrog | { |
4593 | b4e3104b | balrog | return addr >= OMAP_IMIF_BASE && addr < OMAP_IMIF_BASE + s->sram_size;
|
4594 | b4e3104b | balrog | } |
4595 | b4e3104b | balrog | |
4596 | b4e3104b | balrog | static int omap_validate_tipb_addr(struct omap_mpu_state_s *s, |
4597 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
4598 | b4e3104b | balrog | { |
4599 | b4e3104b | balrog | return addr >= 0xfffb0000 && addr < 0xffff0000; |
4600 | b4e3104b | balrog | } |
4601 | b4e3104b | balrog | |
4602 | b4e3104b | balrog | static int omap_validate_local_addr(struct omap_mpu_state_s *s, |
4603 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
4604 | b4e3104b | balrog | { |
4605 | b4e3104b | balrog | return addr >= OMAP_LOCALBUS_BASE && addr < OMAP_LOCALBUS_BASE + 0x1000000; |
4606 | b4e3104b | balrog | } |
4607 | b4e3104b | balrog | |
4608 | b4e3104b | balrog | static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s *s, |
4609 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
4610 | b4e3104b | balrog | { |
4611 | b4e3104b | balrog | return addr >= 0xe1010000 && addr < 0xe1020004; |
4612 | b4e3104b | balrog | } |
4613 | b4e3104b | balrog | |
4614 | c3d2689d | balrog | struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size, |
4615 | 3023f332 | aliguori | const char *core) |
4616 | c3d2689d | balrog | { |
4617 | 089b7c0a | balrog | int i;
|
4618 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) |
4619 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_mpu_state_s)); |
4620 | c227f099 | Anthony Liguori | ram_addr_t imif_base, emiff_base; |
4621 | 106627d0 | balrog | qemu_irq *cpu_irq; |
4622 | 089b7c0a | balrog | qemu_irq dma_irqs[6];
|
4623 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
4624 | 106627d0 | balrog | |
4625 | aaed909a | bellard | if (!core)
|
4626 | aaed909a | bellard | core = "ti925t";
|
4627 | c3d2689d | balrog | |
4628 | c3d2689d | balrog | /* Core */
|
4629 | c3d2689d | balrog | s->mpu_model = omap310; |
4630 | aaed909a | bellard | s->env = cpu_init(core); |
4631 | aaed909a | bellard | if (!s->env) {
|
4632 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
4633 | aaed909a | bellard | exit(1);
|
4634 | aaed909a | bellard | } |
4635 | c3d2689d | balrog | s->sdram_size = sdram_size; |
4636 | c3d2689d | balrog | s->sram_size = OMAP15XX_SRAM_SIZE; |
4637 | c3d2689d | balrog | |
4638 | fe71e81a | balrog | s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0]; |
4639 | fe71e81a | balrog | |
4640 | c3d2689d | balrog | /* Clocks */
|
4641 | c3d2689d | balrog | omap_clk_init(s); |
4642 | c3d2689d | balrog | |
4643 | c3d2689d | balrog | /* Memory-mapped stuff */
|
4644 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_EMIFF_BASE, s->sdram_size, |
4645 | c3d2689d | balrog | (emiff_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM); |
4646 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_IMIF_BASE, s->sram_size, |
4647 | c3d2689d | balrog | (imif_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM); |
4648 | c3d2689d | balrog | |
4649 | c3d2689d | balrog | omap_clkm_init(0xfffece00, 0xe1008000, s); |
4650 | c3d2689d | balrog | |
4651 | 106627d0 | balrog | cpu_irq = arm_pic_init_cpu(s->env); |
4652 | 827df9f3 | balrog | s->ih[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s->irq[0], |
4653 | 106627d0 | balrog | cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ], |
4654 | c3d2689d | balrog | omap_findclk(s, "arminth_ck"));
|
4655 | 827df9f3 | balrog | s->ih[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s->irq[1], |
4656 | 106627d0 | balrog | s->ih[0]->pins[OMAP_INT_15XX_IH2_IRQ], NULL, |
4657 | c3d2689d | balrog | omap_findclk(s, "arminth_ck"));
|
4658 | c3d2689d | balrog | |
4659 | 089b7c0a | balrog | for (i = 0; i < 6; i ++) |
4660 | 827df9f3 | balrog | dma_irqs[i] = |
4661 | 827df9f3 | balrog | s->irq[omap1_dma_irq_map[i].ih][omap1_dma_irq_map[i].intr]; |
4662 | 089b7c0a | balrog | s->dma = omap_dma_init(0xfffed800, dma_irqs, s->irq[0][OMAP_INT_DMA_LCD], |
4663 | 089b7c0a | balrog | s, omap_findclk(s, "dma_ck"), omap_dma_3_1);
|
4664 | 089b7c0a | balrog | |
4665 | c3d2689d | balrog | s->port[emiff ].addr_valid = omap_validate_emiff_addr; |
4666 | c3d2689d | balrog | s->port[emifs ].addr_valid = omap_validate_emifs_addr; |
4667 | c3d2689d | balrog | s->port[imif ].addr_valid = omap_validate_imif_addr; |
4668 | c3d2689d | balrog | s->port[tipb ].addr_valid = omap_validate_tipb_addr; |
4669 | c3d2689d | balrog | s->port[local ].addr_valid = omap_validate_local_addr; |
4670 | c3d2689d | balrog | s->port[tipb_mpui].addr_valid = omap_validate_tipb_mpui_addr; |
4671 | c3d2689d | balrog | |
4672 | afbb5194 | balrog | /* Register SDRAM and SRAM DMA ports for fast transfers. */
|
4673 | afbb5194 | balrog | soc_dma_port_add_mem_ram(s->dma, |
4674 | afbb5194 | balrog | emiff_base, OMAP_EMIFF_BASE, s->sdram_size); |
4675 | afbb5194 | balrog | soc_dma_port_add_mem_ram(s->dma, |
4676 | afbb5194 | balrog | imif_base, OMAP_IMIF_BASE, s->sram_size); |
4677 | afbb5194 | balrog | |
4678 | c3d2689d | balrog | s->timer[0] = omap_mpu_timer_init(0xfffec500, |
4679 | c3d2689d | balrog | s->irq[0][OMAP_INT_TIMER1],
|
4680 | c3d2689d | balrog | omap_findclk(s, "mputim_ck"));
|
4681 | c3d2689d | balrog | s->timer[1] = omap_mpu_timer_init(0xfffec600, |
4682 | c3d2689d | balrog | s->irq[0][OMAP_INT_TIMER2],
|
4683 | c3d2689d | balrog | omap_findclk(s, "mputim_ck"));
|
4684 | c3d2689d | balrog | s->timer[2] = omap_mpu_timer_init(0xfffec700, |
4685 | c3d2689d | balrog | s->irq[0][OMAP_INT_TIMER3],
|
4686 | c3d2689d | balrog | omap_findclk(s, "mputim_ck"));
|
4687 | c3d2689d | balrog | |
4688 | c3d2689d | balrog | s->wdt = omap_wd_timer_init(0xfffec800,
|
4689 | c3d2689d | balrog | s->irq[0][OMAP_INT_WD_TIMER],
|
4690 | c3d2689d | balrog | omap_findclk(s, "armwdt_ck"));
|
4691 | c3d2689d | balrog | |
4692 | c3d2689d | balrog | s->os_timer = omap_os_timer_init(0xfffb9000,
|
4693 | c3d2689d | balrog | s->irq[1][OMAP_INT_OS_TIMER],
|
4694 | c3d2689d | balrog | omap_findclk(s, "clk32-kHz"));
|
4695 | c3d2689d | balrog | |
4696 | c3d2689d | balrog | s->lcd = omap_lcdc_init(0xfffec000, s->irq[0][OMAP_INT_LCD_CTRL], |
4697 | 3023f332 | aliguori | omap_dma_get_lcdch(s->dma), imif_base, emiff_base, |
4698 | c3d2689d | balrog | omap_findclk(s, "lcd_ck"));
|
4699 | c3d2689d | balrog | |
4700 | c3d2689d | balrog | omap_ulpd_pm_init(0xfffe0800, s);
|
4701 | c3d2689d | balrog | omap_pin_cfg_init(0xfffe1000, s);
|
4702 | c3d2689d | balrog | omap_id_init(s); |
4703 | c3d2689d | balrog | |
4704 | c3d2689d | balrog | omap_mpui_init(0xfffec900, s);
|
4705 | c3d2689d | balrog | |
4706 | c3d2689d | balrog | s->private_tipb = omap_tipb_bridge_init(0xfffeca00,
|
4707 | c3d2689d | balrog | s->irq[0][OMAP_INT_BRIDGE_PRIV],
|
4708 | c3d2689d | balrog | omap_findclk(s, "tipb_ck"));
|
4709 | c3d2689d | balrog | s->public_tipb = omap_tipb_bridge_init(0xfffed300,
|
4710 | c3d2689d | balrog | s->irq[0][OMAP_INT_BRIDGE_PUB],
|
4711 | c3d2689d | balrog | omap_findclk(s, "tipb_ck"));
|
4712 | c3d2689d | balrog | |
4713 | c3d2689d | balrog | omap_tcmi_init(0xfffecc00, s);
|
4714 | c3d2689d | balrog | |
4715 | d951f6ff | balrog | s->uart[0] = omap_uart_init(0xfffb0000, s->irq[1][OMAP_INT_UART1], |
4716 | c3d2689d | balrog | omap_findclk(s, "uart1_ck"),
|
4717 | 827df9f3 | balrog | omap_findclk(s, "uart1_ck"),
|
4718 | 827df9f3 | balrog | s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX], |
4719 | c3d2689d | balrog | serial_hds[0]);
|
4720 | d951f6ff | balrog | s->uart[1] = omap_uart_init(0xfffb0800, s->irq[1][OMAP_INT_UART2], |
4721 | c3d2689d | balrog | omap_findclk(s, "uart2_ck"),
|
4722 | 827df9f3 | balrog | omap_findclk(s, "uart2_ck"),
|
4723 | 827df9f3 | balrog | s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX], |
4724 | b9d38e95 | Blue Swirl | serial_hds[0] ? serial_hds[1] : NULL); |
4725 | 13643323 | balrog | s->uart[2] = omap_uart_init(0xfffb9800, s->irq[0][OMAP_INT_UART3], |
4726 | c3d2689d | balrog | omap_findclk(s, "uart3_ck"),
|
4727 | 827df9f3 | balrog | omap_findclk(s, "uart3_ck"),
|
4728 | 827df9f3 | balrog | s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX], |
4729 | b9d38e95 | Blue Swirl | serial_hds[0] && serial_hds[1] ? serial_hds[2] : NULL); |
4730 | c3d2689d | balrog | |
4731 | c3d2689d | balrog | omap_dpll_init(&s->dpll[0], 0xfffecf00, omap_findclk(s, "dpll1")); |
4732 | c3d2689d | balrog | omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2")); |
4733 | c3d2689d | balrog | omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3")); |
4734 | c3d2689d | balrog | |
4735 | 751c6a17 | Gerd Hoffmann | dinfo = drive_get(IF_SD, 0, 0); |
4736 | 751c6a17 | Gerd Hoffmann | if (!dinfo) {
|
4737 | e4bcb14c | ths | fprintf(stderr, "qemu: missing SecureDigital device\n");
|
4738 | e4bcb14c | ths | exit(1);
|
4739 | e4bcb14c | ths | } |
4740 | 751c6a17 | Gerd Hoffmann | s->mmc = omap_mmc_init(0xfffb7800, dinfo->bdrv,
|
4741 | 9d413d1d | balrog | s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX],
|
4742 | 9d413d1d | balrog | omap_findclk(s, "mmc_ck"));
|
4743 | b30bb3a2 | balrog | |
4744 | fe71e81a | balrog | s->mpuio = omap_mpuio_init(0xfffb5000,
|
4745 | fe71e81a | balrog | s->irq[1][OMAP_INT_KEYBOARD], s->irq[1][OMAP_INT_MPUIO], |
4746 | fe71e81a | balrog | s->wakeup, omap_findclk(s, "clk32-kHz"));
|
4747 | fe71e81a | balrog | |
4748 | 3efda49d | balrog | s->gpio = omap_gpio_init(0xfffce000, s->irq[0][OMAP_INT_GPIO_BANK1], |
4749 | 66450b15 | balrog | omap_findclk(s, "arm_gpio_ck"));
|
4750 | 64330148 | balrog | |
4751 | d951f6ff | balrog | s->microwire = omap_uwire_init(0xfffb3000, &s->irq[1][OMAP_INT_uWireTX], |
4752 | d951f6ff | balrog | s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
|
4753 | d951f6ff | balrog | |
4754 | d8f699cb | balrog | omap_pwl_init(0xfffb5800, s, omap_findclk(s, "armxor_ck")); |
4755 | d8f699cb | balrog | omap_pwt_init(0xfffb6000, s, omap_findclk(s, "armxor_ck")); |
4756 | 66450b15 | balrog | |
4757 | 827df9f3 | balrog | s->i2c[0] = omap_i2c_init(0xfffb3800, s->irq[1][OMAP_INT_I2C], |
4758 | 4a2c8ac2 | balrog | &s->drq[OMAP_DMA_I2C_RX], omap_findclk(s, "mpuper_ck"));
|
4759 | 4a2c8ac2 | balrog | |
4760 | 5c1c390f | balrog | s->rtc = omap_rtc_init(0xfffb4800, &s->irq[1][OMAP_INT_RTC_TIMER], |
4761 | 5c1c390f | balrog | omap_findclk(s, "clk32-kHz"));
|
4762 | 02645926 | balrog | |
4763 | d8f699cb | balrog | s->mcbsp1 = omap_mcbsp_init(0xfffb1800, &s->irq[1][OMAP_INT_McBSP1TX], |
4764 | d8f699cb | balrog | &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
|
4765 | d8f699cb | balrog | s->mcbsp2 = omap_mcbsp_init(0xfffb1000, &s->irq[0][OMAP_INT_310_McBSP2_TX], |
4766 | d8f699cb | balrog | &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
|
4767 | d8f699cb | balrog | s->mcbsp3 = omap_mcbsp_init(0xfffb7000, &s->irq[1][OMAP_INT_McBSP3TX], |
4768 | d8f699cb | balrog | &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
|
4769 | d8f699cb | balrog | |
4770 | f9d43072 | balrog | s->led[0] = omap_lpg_init(0xfffbd000, omap_findclk(s, "clk32-kHz")); |
4771 | f9d43072 | balrog | s->led[1] = omap_lpg_init(0xfffbd800, omap_findclk(s, "clk32-kHz")); |
4772 | f9d43072 | balrog | |
4773 | 02645926 | balrog | /* Register mappings not currenlty implemented:
|
4774 | 02645926 | balrog | * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
|
4775 | 02645926 | balrog | * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
|
4776 | 02645926 | balrog | * USB W2FC fffb4000 - fffb47ff
|
4777 | 02645926 | balrog | * Camera Interface fffb6800 - fffb6fff
|
4778 | 02645926 | balrog | * USB Host fffba000 - fffba7ff
|
4779 | 02645926 | balrog | * FAC fffba800 - fffbafff
|
4780 | 02645926 | balrog | * HDQ/1-Wire fffbc000 - fffbc7ff
|
4781 | b854bc19 | balrog | * TIPB switches fffbc800 - fffbcfff
|
4782 | 02645926 | balrog | * Mailbox fffcf000 - fffcf7ff
|
4783 | 02645926 | balrog | * Local bus IF fffec100 - fffec1ff
|
4784 | 02645926 | balrog | * Local bus MMU fffec200 - fffec2ff
|
4785 | 02645926 | balrog | * DSP MMU fffed200 - fffed2ff
|
4786 | 02645926 | balrog | */
|
4787 | 02645926 | balrog | |
4788 | cf965d24 | balrog | omap_setup_dsp_mapping(omap15xx_dsp_mm); |
4789 | f9d43072 | balrog | omap_setup_mpui_io(s); |
4790 | cf965d24 | balrog | |
4791 | a08d4367 | Jan Kiszka | qemu_register_reset(omap1_mpu_reset, s); |
4792 | c3d2689d | balrog | |
4793 | c3d2689d | balrog | return s;
|
4794 | c3d2689d | balrog | } |