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