root / hw / omap.c @ 66450b15
History | View | Annotate | Download (101.3 kB)
1 | c3d2689d | balrog | /*
|
---|---|---|---|
2 | c3d2689d | balrog | * TI OMAP processors emulation.
|
3 | c3d2689d | balrog | *
|
4 | c3d2689d | balrog | * Copyright (C) 2006-2007 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 | c3d2689d | balrog | * published by the Free Software Foundation; either version 2 of
|
9 | c3d2689d | balrog | * the License, or (at your option) any later version.
|
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 | c3d2689d | balrog | * You should have received a copy of the GNU General Public License
|
17 | c3d2689d | balrog | * along with this program; if not, write to the Free Software
|
18 | c3d2689d | balrog | * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
19 | c3d2689d | balrog | * MA 02111-1307 USA
|
20 | c3d2689d | balrog | */
|
21 | c3d2689d | balrog | #include "vl.h" |
22 | c3d2689d | balrog | #include "arm_pic.h" |
23 | c3d2689d | balrog | |
24 | c3d2689d | balrog | /* Should signal the TCMI */
|
25 | 66450b15 | balrog | uint32_t omap_badwidth_read8(void *opaque, target_phys_addr_t addr)
|
26 | 66450b15 | balrog | { |
27 | 66450b15 | balrog | OMAP_8B_REG(addr); |
28 | 66450b15 | balrog | return 0; |
29 | 66450b15 | balrog | } |
30 | 66450b15 | balrog | |
31 | 66450b15 | balrog | void omap_badwidth_write8(void *opaque, target_phys_addr_t addr, |
32 | 66450b15 | balrog | uint32_t value) |
33 | 66450b15 | balrog | { |
34 | 66450b15 | balrog | OMAP_8B_REG(addr); |
35 | 66450b15 | balrog | } |
36 | 66450b15 | balrog | |
37 | b30bb3a2 | balrog | uint32_t omap_badwidth_read16(void *opaque, target_phys_addr_t addr)
|
38 | c3d2689d | balrog | { |
39 | c3d2689d | balrog | OMAP_16B_REG(addr); |
40 | c3d2689d | balrog | return 0; |
41 | c3d2689d | balrog | } |
42 | c3d2689d | balrog | |
43 | b30bb3a2 | balrog | void omap_badwidth_write16(void *opaque, target_phys_addr_t addr, |
44 | c3d2689d | balrog | uint32_t value) |
45 | c3d2689d | balrog | { |
46 | c3d2689d | balrog | OMAP_16B_REG(addr); |
47 | c3d2689d | balrog | } |
48 | c3d2689d | balrog | |
49 | b30bb3a2 | balrog | uint32_t omap_badwidth_read32(void *opaque, target_phys_addr_t addr)
|
50 | c3d2689d | balrog | { |
51 | c3d2689d | balrog | OMAP_32B_REG(addr); |
52 | c3d2689d | balrog | return 0; |
53 | c3d2689d | balrog | } |
54 | c3d2689d | balrog | |
55 | b30bb3a2 | balrog | void omap_badwidth_write32(void *opaque, target_phys_addr_t addr, |
56 | c3d2689d | balrog | uint32_t value) |
57 | c3d2689d | balrog | { |
58 | c3d2689d | balrog | OMAP_32B_REG(addr); |
59 | c3d2689d | balrog | } |
60 | c3d2689d | balrog | |
61 | c3d2689d | balrog | /* Interrupt Handlers */
|
62 | c3d2689d | balrog | struct omap_intr_handler_s {
|
63 | c3d2689d | balrog | qemu_irq *pins; |
64 | c3d2689d | balrog | qemu_irq *parent_pic; |
65 | c3d2689d | balrog | target_phys_addr_t base; |
66 | c3d2689d | balrog | |
67 | c3d2689d | balrog | /* state */
|
68 | c3d2689d | balrog | uint32_t irqs; |
69 | c3d2689d | balrog | uint32_t mask; |
70 | c3d2689d | balrog | uint32_t sens_edge; |
71 | c3d2689d | balrog | uint32_t fiq; |
72 | c3d2689d | balrog | int priority[32]; |
73 | c3d2689d | balrog | uint32_t new_irq_agr; |
74 | c3d2689d | balrog | uint32_t new_fiq_agr; |
75 | c3d2689d | balrog | int sir_irq;
|
76 | c3d2689d | balrog | int sir_fiq;
|
77 | c3d2689d | balrog | int stats[32]; |
78 | c3d2689d | balrog | }; |
79 | c3d2689d | balrog | |
80 | c3d2689d | balrog | static void omap_inth_update(struct omap_intr_handler_s *s) |
81 | c3d2689d | balrog | { |
82 | cfa0b71d | balrog | uint32_t irq = s->irqs & ~s->mask & ~s->fiq; |
83 | cfa0b71d | balrog | uint32_t fiq = s->irqs & ~s->mask & s->fiq; |
84 | c3d2689d | balrog | |
85 | cfa0b71d | balrog | if (s->new_irq_agr || !irq) {
|
86 | cfa0b71d | balrog | qemu_set_irq(s->parent_pic[ARM_PIC_CPU_IRQ], irq); |
87 | cfa0b71d | balrog | if (irq)
|
88 | cfa0b71d | balrog | s->new_irq_agr = 0;
|
89 | cfa0b71d | balrog | } |
90 | c3d2689d | balrog | |
91 | cfa0b71d | balrog | if (s->new_fiq_agr || !irq) {
|
92 | cfa0b71d | balrog | qemu_set_irq(s->parent_pic[ARM_PIC_CPU_FIQ], fiq); |
93 | cfa0b71d | balrog | if (fiq)
|
94 | cfa0b71d | balrog | s->new_fiq_agr = 0;
|
95 | cfa0b71d | balrog | } |
96 | c3d2689d | balrog | } |
97 | c3d2689d | balrog | |
98 | c3d2689d | balrog | static void omap_inth_sir_update(struct omap_intr_handler_s *s) |
99 | c3d2689d | balrog | { |
100 | c3d2689d | balrog | int i, intr_irq, intr_fiq, p_irq, p_fiq, p, f;
|
101 | c3d2689d | balrog | uint32_t level = s->irqs & ~s->mask; |
102 | c3d2689d | balrog | |
103 | c3d2689d | balrog | intr_irq = 0;
|
104 | c3d2689d | balrog | intr_fiq = 0;
|
105 | c3d2689d | balrog | p_irq = -1;
|
106 | c3d2689d | balrog | p_fiq = -1;
|
107 | c3d2689d | balrog | /* Find the interrupt line with the highest dynamic priority */
|
108 | c3d2689d | balrog | for (f = ffs(level), i = f - 1, level >>= f - 1; f; i += f, level >>= f) { |
109 | c3d2689d | balrog | p = s->priority[i]; |
110 | c3d2689d | balrog | if (s->fiq & (1 << i)) { |
111 | c3d2689d | balrog | if (p > p_fiq) {
|
112 | c3d2689d | balrog | p_fiq = p; |
113 | c3d2689d | balrog | intr_fiq = i; |
114 | c3d2689d | balrog | } |
115 | c3d2689d | balrog | } else {
|
116 | c3d2689d | balrog | if (p > p_irq) {
|
117 | c3d2689d | balrog | p_irq = p; |
118 | c3d2689d | balrog | intr_irq = i; |
119 | c3d2689d | balrog | } |
120 | c3d2689d | balrog | } |
121 | c3d2689d | balrog | |
122 | c3d2689d | balrog | f = ffs(level >> 1);
|
123 | c3d2689d | balrog | } |
124 | c3d2689d | balrog | |
125 | c3d2689d | balrog | s->sir_irq = intr_irq; |
126 | c3d2689d | balrog | s->sir_fiq = intr_fiq; |
127 | c3d2689d | balrog | } |
128 | c3d2689d | balrog | |
129 | c3d2689d | balrog | #define INT_FALLING_EDGE 0 |
130 | c3d2689d | balrog | #define INT_LOW_LEVEL 1 |
131 | c3d2689d | balrog | |
132 | c3d2689d | balrog | static void omap_set_intr(void *opaque, int irq, int req) |
133 | c3d2689d | balrog | { |
134 | c3d2689d | balrog | struct omap_intr_handler_s *ih = (struct omap_intr_handler_s *) opaque; |
135 | c3d2689d | balrog | uint32_t rise; |
136 | c3d2689d | balrog | |
137 | c3d2689d | balrog | if (req) {
|
138 | c3d2689d | balrog | rise = ~ih->irqs & (1 << irq);
|
139 | c3d2689d | balrog | ih->irqs |= rise; |
140 | cfa0b71d | balrog | ih->stats[irq] += !!rise; |
141 | c3d2689d | balrog | } else {
|
142 | c3d2689d | balrog | rise = ih->sens_edge & ih->irqs & (1 << irq);
|
143 | c3d2689d | balrog | ih->irqs &= ~rise; |
144 | c3d2689d | balrog | } |
145 | c3d2689d | balrog | |
146 | c3d2689d | balrog | if (rise & ~ih->mask) {
|
147 | c3d2689d | balrog | omap_inth_sir_update(ih); |
148 | c3d2689d | balrog | |
149 | c3d2689d | balrog | omap_inth_update(ih); |
150 | c3d2689d | balrog | } |
151 | c3d2689d | balrog | } |
152 | c3d2689d | balrog | |
153 | c3d2689d | balrog | static uint32_t omap_inth_read(void *opaque, target_phys_addr_t addr) |
154 | c3d2689d | balrog | { |
155 | c3d2689d | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque; |
156 | c3d2689d | balrog | int i, offset = addr - s->base;
|
157 | c3d2689d | balrog | |
158 | c3d2689d | balrog | switch (offset) {
|
159 | c3d2689d | balrog | case 0x00: /* ITR */ |
160 | c3d2689d | balrog | return s->irqs;
|
161 | c3d2689d | balrog | |
162 | c3d2689d | balrog | case 0x04: /* MIR */ |
163 | c3d2689d | balrog | return s->mask;
|
164 | c3d2689d | balrog | |
165 | c3d2689d | balrog | case 0x10: /* SIR_IRQ_CODE */ |
166 | c3d2689d | balrog | i = s->sir_irq; |
167 | c3d2689d | balrog | if (((s->sens_edge >> i) & 1) == INT_FALLING_EDGE && i) { |
168 | c3d2689d | balrog | s->irqs &= ~(1 << i);
|
169 | c3d2689d | balrog | omap_inth_sir_update(s); |
170 | c3d2689d | balrog | omap_inth_update(s); |
171 | c3d2689d | balrog | } |
172 | c3d2689d | balrog | return i;
|
173 | c3d2689d | balrog | |
174 | c3d2689d | balrog | case 0x14: /* SIR_FIQ_CODE */ |
175 | c3d2689d | balrog | i = s->sir_fiq; |
176 | c3d2689d | balrog | if (((s->sens_edge >> i) & 1) == INT_FALLING_EDGE && i) { |
177 | c3d2689d | balrog | s->irqs &= ~(1 << i);
|
178 | c3d2689d | balrog | omap_inth_sir_update(s); |
179 | c3d2689d | balrog | omap_inth_update(s); |
180 | c3d2689d | balrog | } |
181 | c3d2689d | balrog | return i;
|
182 | c3d2689d | balrog | |
183 | c3d2689d | balrog | case 0x18: /* CONTROL_REG */ |
184 | c3d2689d | balrog | return 0; |
185 | c3d2689d | balrog | |
186 | c3d2689d | balrog | case 0x1c: /* ILR0 */ |
187 | c3d2689d | balrog | case 0x20: /* ILR1 */ |
188 | c3d2689d | balrog | case 0x24: /* ILR2 */ |
189 | c3d2689d | balrog | case 0x28: /* ILR3 */ |
190 | c3d2689d | balrog | case 0x2c: /* ILR4 */ |
191 | c3d2689d | balrog | case 0x30: /* ILR5 */ |
192 | c3d2689d | balrog | case 0x34: /* ILR6 */ |
193 | c3d2689d | balrog | case 0x38: /* ILR7 */ |
194 | c3d2689d | balrog | case 0x3c: /* ILR8 */ |
195 | c3d2689d | balrog | case 0x40: /* ILR9 */ |
196 | c3d2689d | balrog | case 0x44: /* ILR10 */ |
197 | c3d2689d | balrog | case 0x48: /* ILR11 */ |
198 | c3d2689d | balrog | case 0x4c: /* ILR12 */ |
199 | c3d2689d | balrog | case 0x50: /* ILR13 */ |
200 | c3d2689d | balrog | case 0x54: /* ILR14 */ |
201 | c3d2689d | balrog | case 0x58: /* ILR15 */ |
202 | c3d2689d | balrog | case 0x5c: /* ILR16 */ |
203 | c3d2689d | balrog | case 0x60: /* ILR17 */ |
204 | c3d2689d | balrog | case 0x64: /* ILR18 */ |
205 | c3d2689d | balrog | case 0x68: /* ILR19 */ |
206 | c3d2689d | balrog | case 0x6c: /* ILR20 */ |
207 | c3d2689d | balrog | case 0x70: /* ILR21 */ |
208 | c3d2689d | balrog | case 0x74: /* ILR22 */ |
209 | c3d2689d | balrog | case 0x78: /* ILR23 */ |
210 | c3d2689d | balrog | case 0x7c: /* ILR24 */ |
211 | c3d2689d | balrog | case 0x80: /* ILR25 */ |
212 | c3d2689d | balrog | case 0x84: /* ILR26 */ |
213 | c3d2689d | balrog | case 0x88: /* ILR27 */ |
214 | c3d2689d | balrog | case 0x8c: /* ILR28 */ |
215 | c3d2689d | balrog | case 0x90: /* ILR29 */ |
216 | c3d2689d | balrog | case 0x94: /* ILR30 */ |
217 | c3d2689d | balrog | case 0x98: /* ILR31 */ |
218 | c3d2689d | balrog | i = (offset - 0x1c) >> 2; |
219 | c3d2689d | balrog | return (s->priority[i] << 2) | |
220 | c3d2689d | balrog | (((s->sens_edge >> i) & 1) << 1) | |
221 | c3d2689d | balrog | ((s->fiq >> i) & 1);
|
222 | c3d2689d | balrog | |
223 | c3d2689d | balrog | case 0x9c: /* ISR */ |
224 | c3d2689d | balrog | return 0x00000000; |
225 | c3d2689d | balrog | |
226 | c3d2689d | balrog | default:
|
227 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
228 | c3d2689d | balrog | break;
|
229 | c3d2689d | balrog | } |
230 | c3d2689d | balrog | return 0; |
231 | c3d2689d | balrog | } |
232 | c3d2689d | balrog | |
233 | c3d2689d | balrog | static void omap_inth_write(void *opaque, target_phys_addr_t addr, |
234 | c3d2689d | balrog | uint32_t value) |
235 | c3d2689d | balrog | { |
236 | c3d2689d | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque; |
237 | c3d2689d | balrog | int i, offset = addr - s->base;
|
238 | c3d2689d | balrog | |
239 | c3d2689d | balrog | switch (offset) {
|
240 | c3d2689d | balrog | case 0x00: /* ITR */ |
241 | c3d2689d | balrog | s->irqs &= value; |
242 | c3d2689d | balrog | omap_inth_sir_update(s); |
243 | c3d2689d | balrog | omap_inth_update(s); |
244 | c3d2689d | balrog | return;
|
245 | c3d2689d | balrog | |
246 | c3d2689d | balrog | case 0x04: /* MIR */ |
247 | c3d2689d | balrog | s->mask = value; |
248 | c3d2689d | balrog | omap_inth_sir_update(s); |
249 | c3d2689d | balrog | omap_inth_update(s); |
250 | c3d2689d | balrog | return;
|
251 | c3d2689d | balrog | |
252 | c3d2689d | balrog | case 0x10: /* SIR_IRQ_CODE */ |
253 | c3d2689d | balrog | case 0x14: /* SIR_FIQ_CODE */ |
254 | c3d2689d | balrog | OMAP_RO_REG(addr); |
255 | c3d2689d | balrog | break;
|
256 | c3d2689d | balrog | |
257 | c3d2689d | balrog | case 0x18: /* CONTROL_REG */ |
258 | c3d2689d | balrog | if (value & 2) |
259 | c3d2689d | balrog | s->new_fiq_agr = ~0;
|
260 | c3d2689d | balrog | if (value & 1) |
261 | c3d2689d | balrog | s->new_irq_agr = ~0;
|
262 | c3d2689d | balrog | omap_inth_update(s); |
263 | c3d2689d | balrog | return;
|
264 | c3d2689d | balrog | |
265 | c3d2689d | balrog | case 0x1c: /* ILR0 */ |
266 | c3d2689d | balrog | case 0x20: /* ILR1 */ |
267 | c3d2689d | balrog | case 0x24: /* ILR2 */ |
268 | c3d2689d | balrog | case 0x28: /* ILR3 */ |
269 | c3d2689d | balrog | case 0x2c: /* ILR4 */ |
270 | c3d2689d | balrog | case 0x30: /* ILR5 */ |
271 | c3d2689d | balrog | case 0x34: /* ILR6 */ |
272 | c3d2689d | balrog | case 0x38: /* ILR7 */ |
273 | c3d2689d | balrog | case 0x3c: /* ILR8 */ |
274 | c3d2689d | balrog | case 0x40: /* ILR9 */ |
275 | c3d2689d | balrog | case 0x44: /* ILR10 */ |
276 | c3d2689d | balrog | case 0x48: /* ILR11 */ |
277 | c3d2689d | balrog | case 0x4c: /* ILR12 */ |
278 | c3d2689d | balrog | case 0x50: /* ILR13 */ |
279 | c3d2689d | balrog | case 0x54: /* ILR14 */ |
280 | c3d2689d | balrog | case 0x58: /* ILR15 */ |
281 | c3d2689d | balrog | case 0x5c: /* ILR16 */ |
282 | c3d2689d | balrog | case 0x60: /* ILR17 */ |
283 | c3d2689d | balrog | case 0x64: /* ILR18 */ |
284 | c3d2689d | balrog | case 0x68: /* ILR19 */ |
285 | c3d2689d | balrog | case 0x6c: /* ILR20 */ |
286 | c3d2689d | balrog | case 0x70: /* ILR21 */ |
287 | c3d2689d | balrog | case 0x74: /* ILR22 */ |
288 | c3d2689d | balrog | case 0x78: /* ILR23 */ |
289 | c3d2689d | balrog | case 0x7c: /* ILR24 */ |
290 | c3d2689d | balrog | case 0x80: /* ILR25 */ |
291 | c3d2689d | balrog | case 0x84: /* ILR26 */ |
292 | c3d2689d | balrog | case 0x88: /* ILR27 */ |
293 | c3d2689d | balrog | case 0x8c: /* ILR28 */ |
294 | c3d2689d | balrog | case 0x90: /* ILR29 */ |
295 | c3d2689d | balrog | case 0x94: /* ILR30 */ |
296 | c3d2689d | balrog | case 0x98: /* ILR31 */ |
297 | c3d2689d | balrog | i = (offset - 0x1c) >> 2; |
298 | c3d2689d | balrog | s->priority[i] = (value >> 2) & 0x1f; |
299 | c3d2689d | balrog | s->sens_edge &= ~(1 << i);
|
300 | c3d2689d | balrog | s->sens_edge |= ((value >> 1) & 1) << i; |
301 | c3d2689d | balrog | s->fiq &= ~(1 << i);
|
302 | c3d2689d | balrog | s->fiq |= (value & 1) << i;
|
303 | c3d2689d | balrog | return;
|
304 | c3d2689d | balrog | |
305 | c3d2689d | balrog | case 0x9c: /* ISR */ |
306 | c3d2689d | balrog | for (i = 0; i < 32; i ++) |
307 | c3d2689d | balrog | if (value & (1 << i)) { |
308 | c3d2689d | balrog | omap_set_intr(s, i, 1);
|
309 | c3d2689d | balrog | return;
|
310 | c3d2689d | balrog | } |
311 | c3d2689d | balrog | return;
|
312 | c3d2689d | balrog | |
313 | c3d2689d | balrog | default:
|
314 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
315 | c3d2689d | balrog | } |
316 | c3d2689d | balrog | } |
317 | c3d2689d | balrog | |
318 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_inth_readfn[] = {
|
319 | c3d2689d | balrog | omap_badwidth_read32, |
320 | c3d2689d | balrog | omap_badwidth_read32, |
321 | c3d2689d | balrog | omap_inth_read, |
322 | c3d2689d | balrog | }; |
323 | c3d2689d | balrog | |
324 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_inth_writefn[] = {
|
325 | c3d2689d | balrog | omap_inth_write, |
326 | c3d2689d | balrog | omap_inth_write, |
327 | c3d2689d | balrog | omap_inth_write, |
328 | c3d2689d | balrog | }; |
329 | c3d2689d | balrog | |
330 | c3d2689d | balrog | static void omap_inth_reset(struct omap_intr_handler_s *s) |
331 | c3d2689d | balrog | { |
332 | c3d2689d | balrog | s->irqs = 0x00000000;
|
333 | c3d2689d | balrog | s->mask = 0xffffffff;
|
334 | c3d2689d | balrog | s->sens_edge = 0x00000000;
|
335 | c3d2689d | balrog | s->fiq = 0x00000000;
|
336 | c3d2689d | balrog | memset(s->priority, 0, sizeof(s->priority)); |
337 | c3d2689d | balrog | s->new_irq_agr = ~0;
|
338 | c3d2689d | balrog | s->new_fiq_agr = ~0;
|
339 | c3d2689d | balrog | s->sir_irq = 0;
|
340 | c3d2689d | balrog | s->sir_fiq = 0;
|
341 | c3d2689d | balrog | |
342 | c3d2689d | balrog | omap_inth_update(s); |
343 | c3d2689d | balrog | } |
344 | c3d2689d | balrog | |
345 | c3d2689d | balrog | struct omap_intr_handler_s *omap_inth_init(target_phys_addr_t base,
|
346 | c3d2689d | balrog | unsigned long size, qemu_irq parent[2], omap_clk clk) |
347 | c3d2689d | balrog | { |
348 | c3d2689d | balrog | int iomemtype;
|
349 | c3d2689d | balrog | struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) |
350 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_intr_handler_s)); |
351 | c3d2689d | balrog | |
352 | c3d2689d | balrog | s->parent_pic = parent; |
353 | c3d2689d | balrog | s->base = base; |
354 | c3d2689d | balrog | s->pins = qemu_allocate_irqs(omap_set_intr, s, 32);
|
355 | c3d2689d | balrog | omap_inth_reset(s); |
356 | c3d2689d | balrog | |
357 | c3d2689d | balrog | iomemtype = cpu_register_io_memory(0, omap_inth_readfn,
|
358 | c3d2689d | balrog | omap_inth_writefn, s); |
359 | c3d2689d | balrog | cpu_register_physical_memory(s->base, size, iomemtype); |
360 | c3d2689d | balrog | |
361 | c3d2689d | balrog | return s;
|
362 | c3d2689d | balrog | } |
363 | c3d2689d | balrog | |
364 | c3d2689d | balrog | /* OMAP1 DMA module */
|
365 | c3d2689d | balrog | typedef enum { |
366 | c3d2689d | balrog | constant = 0,
|
367 | c3d2689d | balrog | post_incremented, |
368 | c3d2689d | balrog | single_index, |
369 | c3d2689d | balrog | double_index, |
370 | c3d2689d | balrog | } omap_dma_addressing_t; |
371 | c3d2689d | balrog | |
372 | c3d2689d | balrog | struct omap_dma_channel_s {
|
373 | c3d2689d | balrog | int burst[2]; |
374 | c3d2689d | balrog | int pack[2]; |
375 | c3d2689d | balrog | enum omap_dma_port port[2]; |
376 | c3d2689d | balrog | target_phys_addr_t addr[2];
|
377 | c3d2689d | balrog | omap_dma_addressing_t mode[2];
|
378 | c3d2689d | balrog | int data_type;
|
379 | c3d2689d | balrog | int end_prog;
|
380 | c3d2689d | balrog | int repeat;
|
381 | c3d2689d | balrog | int auto_init;
|
382 | c3d2689d | balrog | int priority;
|
383 | c3d2689d | balrog | int fs;
|
384 | c3d2689d | balrog | int sync;
|
385 | c3d2689d | balrog | int running;
|
386 | c3d2689d | balrog | int interrupts;
|
387 | c3d2689d | balrog | int status;
|
388 | c3d2689d | balrog | int signalled;
|
389 | c3d2689d | balrog | int post_sync;
|
390 | c3d2689d | balrog | int transfer;
|
391 | c3d2689d | balrog | uint16_t elements; |
392 | c3d2689d | balrog | uint16_t frames; |
393 | c3d2689d | balrog | uint16_t frame_index; |
394 | c3d2689d | balrog | uint16_t element_index; |
395 | c3d2689d | balrog | uint16_t cpc; |
396 | c3d2689d | balrog | |
397 | c3d2689d | balrog | struct omap_dma_reg_set_s {
|
398 | c3d2689d | balrog | target_phys_addr_t src, dest; |
399 | c3d2689d | balrog | int frame;
|
400 | c3d2689d | balrog | int element;
|
401 | c3d2689d | balrog | int frame_delta[2]; |
402 | c3d2689d | balrog | int elem_delta[2]; |
403 | c3d2689d | balrog | int frames;
|
404 | c3d2689d | balrog | int elements;
|
405 | c3d2689d | balrog | } active_set; |
406 | c3d2689d | balrog | }; |
407 | c3d2689d | balrog | |
408 | c3d2689d | balrog | struct omap_dma_s {
|
409 | c3d2689d | balrog | qemu_irq *ih; |
410 | c3d2689d | balrog | QEMUTimer *tm; |
411 | c3d2689d | balrog | struct omap_mpu_state_s *mpu;
|
412 | c3d2689d | balrog | target_phys_addr_t base; |
413 | c3d2689d | balrog | omap_clk clk; |
414 | c3d2689d | balrog | int64_t delay; |
415 | 1af2b62d | balrog | uint32_t drq; |
416 | c3d2689d | balrog | |
417 | c3d2689d | balrog | uint16_t gcr; |
418 | c3d2689d | balrog | int run_count;
|
419 | c3d2689d | balrog | |
420 | c3d2689d | balrog | int chans;
|
421 | c3d2689d | balrog | struct omap_dma_channel_s ch[16]; |
422 | c3d2689d | balrog | struct omap_dma_lcd_channel_s lcd_ch;
|
423 | c3d2689d | balrog | }; |
424 | c3d2689d | balrog | |
425 | c3d2689d | balrog | static void omap_dma_interrupts_update(struct omap_dma_s *s) |
426 | c3d2689d | balrog | { |
427 | c3d2689d | balrog | /* First three interrupts are shared between two channels each. */
|
428 | c3d2689d | balrog | qemu_set_irq(s->ih[OMAP_INT_DMA_CH0_6], |
429 | c3d2689d | balrog | (s->ch[0].status | s->ch[6].status) & 0x3f); |
430 | c3d2689d | balrog | qemu_set_irq(s->ih[OMAP_INT_DMA_CH1_7], |
431 | c3d2689d | balrog | (s->ch[1].status | s->ch[7].status) & 0x3f); |
432 | c3d2689d | balrog | qemu_set_irq(s->ih[OMAP_INT_DMA_CH2_8], |
433 | c3d2689d | balrog | (s->ch[2].status | s->ch[8].status) & 0x3f); |
434 | c3d2689d | balrog | qemu_set_irq(s->ih[OMAP_INT_DMA_CH3], |
435 | c3d2689d | balrog | (s->ch[3].status) & 0x3f); |
436 | c3d2689d | balrog | qemu_set_irq(s->ih[OMAP_INT_DMA_CH4], |
437 | c3d2689d | balrog | (s->ch[4].status) & 0x3f); |
438 | c3d2689d | balrog | qemu_set_irq(s->ih[OMAP_INT_DMA_CH5], |
439 | c3d2689d | balrog | (s->ch[5].status) & 0x3f); |
440 | c3d2689d | balrog | } |
441 | c3d2689d | balrog | |
442 | c3d2689d | balrog | static void omap_dma_channel_load(struct omap_dma_s *s, int ch) |
443 | c3d2689d | balrog | { |
444 | c3d2689d | balrog | struct omap_dma_reg_set_s *a = &s->ch[ch].active_set;
|
445 | c3d2689d | balrog | int i;
|
446 | c3d2689d | balrog | |
447 | c3d2689d | balrog | /*
|
448 | c3d2689d | balrog | * TODO: verify address ranges and alignment
|
449 | c3d2689d | balrog | * TODO: port endianness
|
450 | c3d2689d | balrog | */
|
451 | c3d2689d | balrog | |
452 | c3d2689d | balrog | a->src = s->ch[ch].addr[0];
|
453 | c3d2689d | balrog | a->dest = s->ch[ch].addr[1];
|
454 | c3d2689d | balrog | a->frames = s->ch[ch].frames; |
455 | c3d2689d | balrog | a->elements = s->ch[ch].elements; |
456 | c3d2689d | balrog | a->frame = 0;
|
457 | c3d2689d | balrog | a->element = 0;
|
458 | c3d2689d | balrog | |
459 | c3d2689d | balrog | if (unlikely(!s->ch[ch].elements || !s->ch[ch].frames)) {
|
460 | c3d2689d | balrog | printf("%s: bad DMA request\n", __FUNCTION__);
|
461 | c3d2689d | balrog | return;
|
462 | c3d2689d | balrog | } |
463 | c3d2689d | balrog | |
464 | c3d2689d | balrog | for (i = 0; i < 2; i ++) |
465 | c3d2689d | balrog | switch (s->ch[ch].mode[i]) {
|
466 | c3d2689d | balrog | case constant:
|
467 | c3d2689d | balrog | a->elem_delta[i] = 0;
|
468 | c3d2689d | balrog | a->frame_delta[i] = 0;
|
469 | c3d2689d | balrog | break;
|
470 | c3d2689d | balrog | case post_incremented:
|
471 | c3d2689d | balrog | a->elem_delta[i] = s->ch[ch].data_type; |
472 | c3d2689d | balrog | a->frame_delta[i] = 0;
|
473 | c3d2689d | balrog | break;
|
474 | c3d2689d | balrog | case single_index:
|
475 | c3d2689d | balrog | a->elem_delta[i] = s->ch[ch].data_type + |
476 | c3d2689d | balrog | s->ch[ch].element_index - 1;
|
477 | c3d2689d | balrog | if (s->ch[ch].element_index > 0x7fff) |
478 | c3d2689d | balrog | a->elem_delta[i] -= 0x10000;
|
479 | c3d2689d | balrog | a->frame_delta[i] = 0;
|
480 | c3d2689d | balrog | break;
|
481 | c3d2689d | balrog | case double_index:
|
482 | c3d2689d | balrog | a->elem_delta[i] = s->ch[ch].data_type + |
483 | c3d2689d | balrog | s->ch[ch].element_index - 1;
|
484 | c3d2689d | balrog | if (s->ch[ch].element_index > 0x7fff) |
485 | c3d2689d | balrog | a->elem_delta[i] -= 0x10000;
|
486 | c3d2689d | balrog | a->frame_delta[i] = s->ch[ch].frame_index - |
487 | c3d2689d | balrog | s->ch[ch].element_index; |
488 | c3d2689d | balrog | if (s->ch[ch].frame_index > 0x7fff) |
489 | c3d2689d | balrog | a->frame_delta[i] -= 0x10000;
|
490 | c3d2689d | balrog | break;
|
491 | c3d2689d | balrog | default:
|
492 | c3d2689d | balrog | break;
|
493 | c3d2689d | balrog | } |
494 | c3d2689d | balrog | } |
495 | c3d2689d | balrog | |
496 | c3d2689d | balrog | static inline void omap_dma_request_run(struct omap_dma_s *s, |
497 | c3d2689d | balrog | int channel, int request) |
498 | c3d2689d | balrog | { |
499 | c3d2689d | balrog | next_channel:
|
500 | c3d2689d | balrog | if (request > 0) |
501 | c3d2689d | balrog | for (; channel < 9; channel ++) |
502 | c3d2689d | balrog | if (s->ch[channel].sync == request && s->ch[channel].running)
|
503 | c3d2689d | balrog | break;
|
504 | c3d2689d | balrog | if (channel >= 9) |
505 | c3d2689d | balrog | return;
|
506 | c3d2689d | balrog | |
507 | c3d2689d | balrog | if (s->ch[channel].transfer) {
|
508 | c3d2689d | balrog | if (request > 0) { |
509 | c3d2689d | balrog | s->ch[channel ++].post_sync = request; |
510 | c3d2689d | balrog | goto next_channel;
|
511 | c3d2689d | balrog | } |
512 | c3d2689d | balrog | s->ch[channel].status |= 0x02; /* Synchronisation drop */ |
513 | c3d2689d | balrog | omap_dma_interrupts_update(s); |
514 | c3d2689d | balrog | return;
|
515 | c3d2689d | balrog | } |
516 | c3d2689d | balrog | |
517 | c3d2689d | balrog | if (!s->ch[channel].signalled)
|
518 | c3d2689d | balrog | s->run_count ++; |
519 | c3d2689d | balrog | s->ch[channel].signalled = 1;
|
520 | c3d2689d | balrog | |
521 | c3d2689d | balrog | if (request > 0) |
522 | c3d2689d | balrog | s->ch[channel].status |= 0x40; /* External request */ |
523 | c3d2689d | balrog | |
524 | 1af2b62d | balrog | if (s->delay && !qemu_timer_pending(s->tm))
|
525 | c3d2689d | balrog | qemu_mod_timer(s->tm, qemu_get_clock(vm_clock) + s->delay); |
526 | c3d2689d | balrog | |
527 | c3d2689d | balrog | if (request > 0) { |
528 | c3d2689d | balrog | channel ++; |
529 | c3d2689d | balrog | goto next_channel;
|
530 | c3d2689d | balrog | } |
531 | c3d2689d | balrog | } |
532 | c3d2689d | balrog | |
533 | c3d2689d | balrog | static inline void omap_dma_request_stop(struct omap_dma_s *s, int channel) |
534 | c3d2689d | balrog | { |
535 | c3d2689d | balrog | if (s->ch[channel].signalled)
|
536 | c3d2689d | balrog | s->run_count --; |
537 | c3d2689d | balrog | s->ch[channel].signalled = 0;
|
538 | c3d2689d | balrog | |
539 | c3d2689d | balrog | if (!s->run_count)
|
540 | c3d2689d | balrog | qemu_del_timer(s->tm); |
541 | c3d2689d | balrog | } |
542 | c3d2689d | balrog | |
543 | c3d2689d | balrog | static void omap_dma_channel_run(struct omap_dma_s *s) |
544 | c3d2689d | balrog | { |
545 | c3d2689d | balrog | int ch;
|
546 | c3d2689d | balrog | uint16_t status; |
547 | c3d2689d | balrog | uint8_t value[4];
|
548 | c3d2689d | balrog | struct omap_dma_port_if_s *src_p, *dest_p;
|
549 | c3d2689d | balrog | struct omap_dma_reg_set_s *a;
|
550 | c3d2689d | balrog | |
551 | c3d2689d | balrog | for (ch = 0; ch < 9; ch ++) { |
552 | c3d2689d | balrog | a = &s->ch[ch].active_set; |
553 | c3d2689d | balrog | |
554 | c3d2689d | balrog | src_p = &s->mpu->port[s->ch[ch].port[0]];
|
555 | c3d2689d | balrog | dest_p = &s->mpu->port[s->ch[ch].port[1]];
|
556 | c3d2689d | balrog | if (s->ch[ch].signalled && (!src_p->addr_valid(s->mpu, a->src) ||
|
557 | c3d2689d | balrog | !dest_p->addr_valid(s->mpu, a->dest))) { |
558 | c3d2689d | balrog | #if 0
|
559 | c3d2689d | balrog | /* Bus time-out */
|
560 | c3d2689d | balrog | if (s->ch[ch].interrupts & 0x01)
|
561 | c3d2689d | balrog | s->ch[ch].status |= 0x01;
|
562 | c3d2689d | balrog | omap_dma_request_stop(s, ch);
|
563 | c3d2689d | balrog | continue;
|
564 | c3d2689d | balrog | #endif
|
565 | c3d2689d | balrog | printf("%s: Bus time-out in DMA%i operation\n", __FUNCTION__, ch);
|
566 | c3d2689d | balrog | } |
567 | c3d2689d | balrog | |
568 | c3d2689d | balrog | status = s->ch[ch].status; |
569 | c3d2689d | balrog | while (status == s->ch[ch].status && s->ch[ch].signalled) {
|
570 | c3d2689d | balrog | /* Transfer a single element */
|
571 | c3d2689d | balrog | s->ch[ch].transfer = 1;
|
572 | c3d2689d | balrog | cpu_physical_memory_read(a->src, value, s->ch[ch].data_type); |
573 | c3d2689d | balrog | cpu_physical_memory_write(a->dest, value, s->ch[ch].data_type); |
574 | c3d2689d | balrog | s->ch[ch].transfer = 0;
|
575 | c3d2689d | balrog | |
576 | c3d2689d | balrog | a->src += a->elem_delta[0];
|
577 | c3d2689d | balrog | a->dest += a->elem_delta[1];
|
578 | c3d2689d | balrog | a->element ++; |
579 | c3d2689d | balrog | |
580 | c3d2689d | balrog | /* Check interrupt conditions */
|
581 | c3d2689d | balrog | if (a->element == a->elements) {
|
582 | c3d2689d | balrog | a->element = 0;
|
583 | c3d2689d | balrog | a->src += a->frame_delta[0];
|
584 | c3d2689d | balrog | a->dest += a->frame_delta[1];
|
585 | c3d2689d | balrog | a->frame ++; |
586 | c3d2689d | balrog | |
587 | c3d2689d | balrog | if (a->frame == a->frames) {
|
588 | c3d2689d | balrog | if (!s->ch[ch].repeat || !s->ch[ch].auto_init)
|
589 | c3d2689d | balrog | s->ch[ch].running = 0;
|
590 | c3d2689d | balrog | |
591 | c3d2689d | balrog | if (s->ch[ch].auto_init &&
|
592 | c3d2689d | balrog | (s->ch[ch].repeat || |
593 | c3d2689d | balrog | s->ch[ch].end_prog)) |
594 | c3d2689d | balrog | omap_dma_channel_load(s, ch); |
595 | c3d2689d | balrog | |
596 | c3d2689d | balrog | if (s->ch[ch].interrupts & 0x20) |
597 | c3d2689d | balrog | s->ch[ch].status |= 0x20;
|
598 | c3d2689d | balrog | |
599 | c3d2689d | balrog | if (!s->ch[ch].sync)
|
600 | c3d2689d | balrog | omap_dma_request_stop(s, ch); |
601 | c3d2689d | balrog | } |
602 | c3d2689d | balrog | |
603 | c3d2689d | balrog | if (s->ch[ch].interrupts & 0x08) |
604 | c3d2689d | balrog | s->ch[ch].status |= 0x08;
|
605 | c3d2689d | balrog | |
606 | 1af2b62d | balrog | if (s->ch[ch].sync && s->ch[ch].fs &&
|
607 | 1af2b62d | balrog | !(s->drq & (1 << s->ch[ch].sync))) {
|
608 | c3d2689d | balrog | s->ch[ch].status &= ~0x40;
|
609 | c3d2689d | balrog | omap_dma_request_stop(s, ch); |
610 | c3d2689d | balrog | } |
611 | c3d2689d | balrog | } |
612 | c3d2689d | balrog | |
613 | c3d2689d | balrog | if (a->element == 1 && a->frame == a->frames - 1) |
614 | c3d2689d | balrog | if (s->ch[ch].interrupts & 0x10) |
615 | c3d2689d | balrog | s->ch[ch].status |= 0x10;
|
616 | c3d2689d | balrog | |
617 | c3d2689d | balrog | if (a->element == (a->elements >> 1)) |
618 | c3d2689d | balrog | if (s->ch[ch].interrupts & 0x04) |
619 | c3d2689d | balrog | s->ch[ch].status |= 0x04;
|
620 | c3d2689d | balrog | |
621 | 1af2b62d | balrog | if (s->ch[ch].sync && !s->ch[ch].fs &&
|
622 | 1af2b62d | balrog | !(s->drq & (1 << s->ch[ch].sync))) {
|
623 | c3d2689d | balrog | s->ch[ch].status &= ~0x40;
|
624 | c3d2689d | balrog | omap_dma_request_stop(s, ch); |
625 | c3d2689d | balrog | } |
626 | c3d2689d | balrog | |
627 | c3d2689d | balrog | /*
|
628 | c3d2689d | balrog | * Process requests made while the element was
|
629 | c3d2689d | balrog | * being transferred.
|
630 | c3d2689d | balrog | */
|
631 | c3d2689d | balrog | if (s->ch[ch].post_sync) {
|
632 | c3d2689d | balrog | omap_dma_request_run(s, 0, s->ch[ch].post_sync);
|
633 | c3d2689d | balrog | s->ch[ch].post_sync = 0;
|
634 | c3d2689d | balrog | } |
635 | c3d2689d | balrog | |
636 | c3d2689d | balrog | #if 0
|
637 | c3d2689d | balrog | break;
|
638 | c3d2689d | balrog | #endif
|
639 | c3d2689d | balrog | } |
640 | c3d2689d | balrog | |
641 | c3d2689d | balrog | s->ch[ch].cpc = a->dest & 0x0000ffff;
|
642 | c3d2689d | balrog | } |
643 | c3d2689d | balrog | |
644 | c3d2689d | balrog | omap_dma_interrupts_update(s); |
645 | c3d2689d | balrog | if (s->run_count && s->delay)
|
646 | c3d2689d | balrog | qemu_mod_timer(s->tm, qemu_get_clock(vm_clock) + s->delay); |
647 | c3d2689d | balrog | } |
648 | c3d2689d | balrog | |
649 | c3d2689d | balrog | static int omap_dma_ch_reg_read(struct omap_dma_s *s, |
650 | c3d2689d | balrog | int ch, int reg, uint16_t *value) { |
651 | c3d2689d | balrog | switch (reg) {
|
652 | c3d2689d | balrog | case 0x00: /* SYS_DMA_CSDP_CH0 */ |
653 | c3d2689d | balrog | *value = (s->ch[ch].burst[1] << 14) | |
654 | c3d2689d | balrog | (s->ch[ch].pack[1] << 13) | |
655 | c3d2689d | balrog | (s->ch[ch].port[1] << 9) | |
656 | c3d2689d | balrog | (s->ch[ch].burst[0] << 7) | |
657 | c3d2689d | balrog | (s->ch[ch].pack[0] << 6) | |
658 | c3d2689d | balrog | (s->ch[ch].port[0] << 2) | |
659 | c3d2689d | balrog | (s->ch[ch].data_type >> 1);
|
660 | c3d2689d | balrog | break;
|
661 | c3d2689d | balrog | |
662 | c3d2689d | balrog | case 0x02: /* SYS_DMA_CCR_CH0 */ |
663 | c3d2689d | balrog | *value = (s->ch[ch].mode[1] << 14) | |
664 | c3d2689d | balrog | (s->ch[ch].mode[0] << 12) | |
665 | c3d2689d | balrog | (s->ch[ch].end_prog << 11) |
|
666 | c3d2689d | balrog | (s->ch[ch].repeat << 9) |
|
667 | c3d2689d | balrog | (s->ch[ch].auto_init << 8) |
|
668 | c3d2689d | balrog | (s->ch[ch].running << 7) |
|
669 | c3d2689d | balrog | (s->ch[ch].priority << 6) |
|
670 | c3d2689d | balrog | (s->ch[ch].fs << 5) | s->ch[ch].sync;
|
671 | c3d2689d | balrog | break;
|
672 | c3d2689d | balrog | |
673 | c3d2689d | balrog | case 0x04: /* SYS_DMA_CICR_CH0 */ |
674 | c3d2689d | balrog | *value = s->ch[ch].interrupts; |
675 | c3d2689d | balrog | break;
|
676 | c3d2689d | balrog | |
677 | c3d2689d | balrog | case 0x06: /* SYS_DMA_CSR_CH0 */ |
678 | c3d2689d | balrog | /* FIXME: shared CSR for channels sharing the interrupts */
|
679 | c3d2689d | balrog | *value = s->ch[ch].status; |
680 | c3d2689d | balrog | s->ch[ch].status &= 0x40;
|
681 | c3d2689d | balrog | omap_dma_interrupts_update(s); |
682 | c3d2689d | balrog | break;
|
683 | c3d2689d | balrog | |
684 | c3d2689d | balrog | case 0x08: /* SYS_DMA_CSSA_L_CH0 */ |
685 | c3d2689d | balrog | *value = s->ch[ch].addr[0] & 0x0000ffff; |
686 | c3d2689d | balrog | break;
|
687 | c3d2689d | balrog | |
688 | c3d2689d | balrog | case 0x0a: /* SYS_DMA_CSSA_U_CH0 */ |
689 | c3d2689d | balrog | *value = s->ch[ch].addr[0] >> 16; |
690 | c3d2689d | balrog | break;
|
691 | c3d2689d | balrog | |
692 | c3d2689d | balrog | case 0x0c: /* SYS_DMA_CDSA_L_CH0 */ |
693 | c3d2689d | balrog | *value = s->ch[ch].addr[1] & 0x0000ffff; |
694 | c3d2689d | balrog | break;
|
695 | c3d2689d | balrog | |
696 | c3d2689d | balrog | case 0x0e: /* SYS_DMA_CDSA_U_CH0 */ |
697 | c3d2689d | balrog | *value = s->ch[ch].addr[1] >> 16; |
698 | c3d2689d | balrog | break;
|
699 | c3d2689d | balrog | |
700 | c3d2689d | balrog | case 0x10: /* SYS_DMA_CEN_CH0 */ |
701 | c3d2689d | balrog | *value = s->ch[ch].elements; |
702 | c3d2689d | balrog | break;
|
703 | c3d2689d | balrog | |
704 | c3d2689d | balrog | case 0x12: /* SYS_DMA_CFN_CH0 */ |
705 | c3d2689d | balrog | *value = s->ch[ch].frames; |
706 | c3d2689d | balrog | break;
|
707 | c3d2689d | balrog | |
708 | c3d2689d | balrog | case 0x14: /* SYS_DMA_CFI_CH0 */ |
709 | c3d2689d | balrog | *value = s->ch[ch].frame_index; |
710 | c3d2689d | balrog | break;
|
711 | c3d2689d | balrog | |
712 | c3d2689d | balrog | case 0x16: /* SYS_DMA_CEI_CH0 */ |
713 | c3d2689d | balrog | *value = s->ch[ch].element_index; |
714 | c3d2689d | balrog | break;
|
715 | c3d2689d | balrog | |
716 | c3d2689d | balrog | case 0x18: /* SYS_DMA_CPC_CH0 */ |
717 | c3d2689d | balrog | *value = s->ch[ch].cpc; |
718 | c3d2689d | balrog | break;
|
719 | c3d2689d | balrog | |
720 | c3d2689d | balrog | default:
|
721 | c3d2689d | balrog | return 1; |
722 | c3d2689d | balrog | } |
723 | c3d2689d | balrog | return 0; |
724 | c3d2689d | balrog | } |
725 | c3d2689d | balrog | |
726 | c3d2689d | balrog | static int omap_dma_ch_reg_write(struct omap_dma_s *s, |
727 | c3d2689d | balrog | int ch, int reg, uint16_t value) { |
728 | c3d2689d | balrog | switch (reg) {
|
729 | c3d2689d | balrog | case 0x00: /* SYS_DMA_CSDP_CH0 */ |
730 | c3d2689d | balrog | s->ch[ch].burst[1] = (value & 0xc000) >> 14; |
731 | c3d2689d | balrog | s->ch[ch].pack[1] = (value & 0x2000) >> 13; |
732 | c3d2689d | balrog | s->ch[ch].port[1] = (enum omap_dma_port) ((value & 0x1e00) >> 9); |
733 | c3d2689d | balrog | s->ch[ch].burst[0] = (value & 0x0180) >> 7; |
734 | c3d2689d | balrog | s->ch[ch].pack[0] = (value & 0x0040) >> 6; |
735 | c3d2689d | balrog | s->ch[ch].port[0] = (enum omap_dma_port) ((value & 0x003c) >> 2); |
736 | c3d2689d | balrog | s->ch[ch].data_type = (1 << (value & 3)); |
737 | c3d2689d | balrog | if (s->ch[ch].port[0] >= omap_dma_port_last) |
738 | c3d2689d | balrog | printf("%s: invalid DMA port %i\n", __FUNCTION__,
|
739 | c3d2689d | balrog | s->ch[ch].port[0]);
|
740 | c3d2689d | balrog | if (s->ch[ch].port[1] >= omap_dma_port_last) |
741 | c3d2689d | balrog | printf("%s: invalid DMA port %i\n", __FUNCTION__,
|
742 | c3d2689d | balrog | s->ch[ch].port[1]);
|
743 | c3d2689d | balrog | if ((value & 3) == 3) |
744 | c3d2689d | balrog | printf("%s: bad data_type for DMA channel %i\n", __FUNCTION__, ch);
|
745 | c3d2689d | balrog | break;
|
746 | c3d2689d | balrog | |
747 | c3d2689d | balrog | case 0x02: /* SYS_DMA_CCR_CH0 */ |
748 | c3d2689d | balrog | s->ch[ch].mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14); |
749 | c3d2689d | balrog | s->ch[ch].mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12); |
750 | c3d2689d | balrog | s->ch[ch].end_prog = (value & 0x0800) >> 11; |
751 | c3d2689d | balrog | s->ch[ch].repeat = (value & 0x0200) >> 9; |
752 | c3d2689d | balrog | s->ch[ch].auto_init = (value & 0x0100) >> 8; |
753 | c3d2689d | balrog | s->ch[ch].priority = (value & 0x0040) >> 6; |
754 | c3d2689d | balrog | s->ch[ch].fs = (value & 0x0020) >> 5; |
755 | c3d2689d | balrog | s->ch[ch].sync = value & 0x001f;
|
756 | c3d2689d | balrog | if (value & 0x0080) { |
757 | c3d2689d | balrog | if (s->ch[ch].running) {
|
758 | c3d2689d | balrog | if (!s->ch[ch].signalled &&
|
759 | c3d2689d | balrog | s->ch[ch].auto_init && s->ch[ch].end_prog) |
760 | c3d2689d | balrog | omap_dma_channel_load(s, ch); |
761 | c3d2689d | balrog | } else {
|
762 | c3d2689d | balrog | s->ch[ch].running = 1;
|
763 | c3d2689d | balrog | omap_dma_channel_load(s, ch); |
764 | c3d2689d | balrog | } |
765 | 1af2b62d | balrog | if (!s->ch[ch].sync || (s->drq & (1 << s->ch[ch].sync))) |
766 | c3d2689d | balrog | omap_dma_request_run(s, ch, 0);
|
767 | c3d2689d | balrog | } else {
|
768 | c3d2689d | balrog | s->ch[ch].running = 0;
|
769 | c3d2689d | balrog | omap_dma_request_stop(s, ch); |
770 | c3d2689d | balrog | } |
771 | c3d2689d | balrog | break;
|
772 | c3d2689d | balrog | |
773 | c3d2689d | balrog | case 0x04: /* SYS_DMA_CICR_CH0 */ |
774 | c3d2689d | balrog | s->ch[ch].interrupts = value & 0x003f;
|
775 | c3d2689d | balrog | break;
|
776 | c3d2689d | balrog | |
777 | c3d2689d | balrog | case 0x06: /* SYS_DMA_CSR_CH0 */ |
778 | c3d2689d | balrog | return 1; |
779 | c3d2689d | balrog | |
780 | c3d2689d | balrog | case 0x08: /* SYS_DMA_CSSA_L_CH0 */ |
781 | c3d2689d | balrog | s->ch[ch].addr[0] &= 0xffff0000; |
782 | c3d2689d | balrog | s->ch[ch].addr[0] |= value;
|
783 | c3d2689d | balrog | break;
|
784 | c3d2689d | balrog | |
785 | c3d2689d | balrog | case 0x0a: /* SYS_DMA_CSSA_U_CH0 */ |
786 | c3d2689d | balrog | s->ch[ch].addr[0] &= 0x0000ffff; |
787 | c3d2689d | balrog | s->ch[ch].addr[0] |= value << 16; |
788 | c3d2689d | balrog | break;
|
789 | c3d2689d | balrog | |
790 | c3d2689d | balrog | case 0x0c: /* SYS_DMA_CDSA_L_CH0 */ |
791 | c3d2689d | balrog | s->ch[ch].addr[1] &= 0xffff0000; |
792 | c3d2689d | balrog | s->ch[ch].addr[1] |= value;
|
793 | c3d2689d | balrog | break;
|
794 | c3d2689d | balrog | |
795 | c3d2689d | balrog | case 0x0e: /* SYS_DMA_CDSA_U_CH0 */ |
796 | c3d2689d | balrog | s->ch[ch].addr[1] &= 0x0000ffff; |
797 | c3d2689d | balrog | s->ch[ch].addr[1] |= value << 16; |
798 | c3d2689d | balrog | break;
|
799 | c3d2689d | balrog | |
800 | c3d2689d | balrog | case 0x10: /* SYS_DMA_CEN_CH0 */ |
801 | c3d2689d | balrog | s->ch[ch].elements = value & 0xffff;
|
802 | c3d2689d | balrog | break;
|
803 | c3d2689d | balrog | |
804 | c3d2689d | balrog | case 0x12: /* SYS_DMA_CFN_CH0 */ |
805 | c3d2689d | balrog | s->ch[ch].frames = value & 0xffff;
|
806 | c3d2689d | balrog | break;
|
807 | c3d2689d | balrog | |
808 | c3d2689d | balrog | case 0x14: /* SYS_DMA_CFI_CH0 */ |
809 | c3d2689d | balrog | s->ch[ch].frame_index = value & 0xffff;
|
810 | c3d2689d | balrog | break;
|
811 | c3d2689d | balrog | |
812 | c3d2689d | balrog | case 0x16: /* SYS_DMA_CEI_CH0 */ |
813 | c3d2689d | balrog | s->ch[ch].element_index = value & 0xffff;
|
814 | c3d2689d | balrog | break;
|
815 | c3d2689d | balrog | |
816 | c3d2689d | balrog | case 0x18: /* SYS_DMA_CPC_CH0 */ |
817 | c3d2689d | balrog | return 1; |
818 | c3d2689d | balrog | |
819 | c3d2689d | balrog | default:
|
820 | c3d2689d | balrog | OMAP_BAD_REG((unsigned long) reg); |
821 | c3d2689d | balrog | } |
822 | c3d2689d | balrog | return 0; |
823 | c3d2689d | balrog | } |
824 | c3d2689d | balrog | |
825 | c3d2689d | balrog | static uint32_t omap_dma_read(void *opaque, target_phys_addr_t addr) |
826 | c3d2689d | balrog | { |
827 | c3d2689d | balrog | struct omap_dma_s *s = (struct omap_dma_s *) opaque; |
828 | c3d2689d | balrog | int i, reg, ch, offset = addr - s->base;
|
829 | c3d2689d | balrog | uint16_t ret; |
830 | c3d2689d | balrog | |
831 | c3d2689d | balrog | switch (offset) {
|
832 | c3d2689d | balrog | case 0x000 ... 0x2fe: |
833 | c3d2689d | balrog | reg = offset & 0x3f;
|
834 | c3d2689d | balrog | ch = (offset >> 6) & 0x0f; |
835 | c3d2689d | balrog | if (omap_dma_ch_reg_read(s, ch, reg, &ret))
|
836 | c3d2689d | balrog | break;
|
837 | c3d2689d | balrog | return ret;
|
838 | c3d2689d | balrog | |
839 | c3d2689d | balrog | case 0x300: /* SYS_DMA_LCD_CTRL */ |
840 | c3d2689d | balrog | i = s->lcd_ch.condition; |
841 | c3d2689d | balrog | s->lcd_ch.condition = 0;
|
842 | c3d2689d | balrog | qemu_irq_lower(s->lcd_ch.irq); |
843 | c3d2689d | balrog | return ((s->lcd_ch.src == imif) << 6) | (i << 3) | |
844 | c3d2689d | balrog | (s->lcd_ch.interrupts << 1) | s->lcd_ch.dual;
|
845 | c3d2689d | balrog | |
846 | c3d2689d | balrog | case 0x302: /* SYS_DMA_LCD_TOP_F1_L */ |
847 | c3d2689d | balrog | return s->lcd_ch.src_f1_top & 0xffff; |
848 | c3d2689d | balrog | |
849 | c3d2689d | balrog | case 0x304: /* SYS_DMA_LCD_TOP_F1_U */ |
850 | c3d2689d | balrog | return s->lcd_ch.src_f1_top >> 16; |
851 | c3d2689d | balrog | |
852 | c3d2689d | balrog | case 0x306: /* SYS_DMA_LCD_BOT_F1_L */ |
853 | c3d2689d | balrog | return s->lcd_ch.src_f1_bottom & 0xffff; |
854 | c3d2689d | balrog | |
855 | c3d2689d | balrog | case 0x308: /* SYS_DMA_LCD_BOT_F1_U */ |
856 | c3d2689d | balrog | return s->lcd_ch.src_f1_bottom >> 16; |
857 | c3d2689d | balrog | |
858 | c3d2689d | balrog | case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */ |
859 | c3d2689d | balrog | return s->lcd_ch.src_f2_top & 0xffff; |
860 | c3d2689d | balrog | |
861 | c3d2689d | balrog | case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */ |
862 | c3d2689d | balrog | return s->lcd_ch.src_f2_top >> 16; |
863 | c3d2689d | balrog | |
864 | c3d2689d | balrog | case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */ |
865 | c3d2689d | balrog | return s->lcd_ch.src_f2_bottom & 0xffff; |
866 | c3d2689d | balrog | |
867 | c3d2689d | balrog | case 0x310: /* SYS_DMA_LCD_BOT_F2_U */ |
868 | c3d2689d | balrog | return s->lcd_ch.src_f2_bottom >> 16; |
869 | c3d2689d | balrog | |
870 | c3d2689d | balrog | case 0x400: /* SYS_DMA_GCR */ |
871 | c3d2689d | balrog | return s->gcr;
|
872 | c3d2689d | balrog | } |
873 | c3d2689d | balrog | |
874 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
875 | c3d2689d | balrog | return 0; |
876 | c3d2689d | balrog | } |
877 | c3d2689d | balrog | |
878 | c3d2689d | balrog | static void omap_dma_write(void *opaque, target_phys_addr_t addr, |
879 | c3d2689d | balrog | uint32_t value) |
880 | c3d2689d | balrog | { |
881 | c3d2689d | balrog | struct omap_dma_s *s = (struct omap_dma_s *) opaque; |
882 | c3d2689d | balrog | int reg, ch, offset = addr - s->base;
|
883 | c3d2689d | balrog | |
884 | c3d2689d | balrog | switch (offset) {
|
885 | c3d2689d | balrog | case 0x000 ... 0x2fe: |
886 | c3d2689d | balrog | reg = offset & 0x3f;
|
887 | c3d2689d | balrog | ch = (offset >> 6) & 0x0f; |
888 | c3d2689d | balrog | if (omap_dma_ch_reg_write(s, ch, reg, value))
|
889 | c3d2689d | balrog | OMAP_RO_REG(addr); |
890 | c3d2689d | balrog | break;
|
891 | c3d2689d | balrog | |
892 | c3d2689d | balrog | case 0x300: /* SYS_DMA_LCD_CTRL */ |
893 | c3d2689d | balrog | s->lcd_ch.src = (value & 0x40) ? imif : emiff;
|
894 | c3d2689d | balrog | s->lcd_ch.condition = 0;
|
895 | c3d2689d | balrog | /* Assume no bus errors and thus no BUS_ERROR irq bits. */
|
896 | c3d2689d | balrog | s->lcd_ch.interrupts = (value >> 1) & 1; |
897 | c3d2689d | balrog | s->lcd_ch.dual = value & 1;
|
898 | c3d2689d | balrog | break;
|
899 | c3d2689d | balrog | |
900 | c3d2689d | balrog | case 0x302: /* SYS_DMA_LCD_TOP_F1_L */ |
901 | c3d2689d | balrog | s->lcd_ch.src_f1_top &= 0xffff0000;
|
902 | c3d2689d | balrog | s->lcd_ch.src_f1_top |= 0x0000ffff & value;
|
903 | c3d2689d | balrog | break;
|
904 | c3d2689d | balrog | |
905 | c3d2689d | balrog | case 0x304: /* SYS_DMA_LCD_TOP_F1_U */ |
906 | c3d2689d | balrog | s->lcd_ch.src_f1_top &= 0x0000ffff;
|
907 | c3d2689d | balrog | s->lcd_ch.src_f1_top |= value << 16;
|
908 | c3d2689d | balrog | break;
|
909 | c3d2689d | balrog | |
910 | c3d2689d | balrog | case 0x306: /* SYS_DMA_LCD_BOT_F1_L */ |
911 | c3d2689d | balrog | s->lcd_ch.src_f1_bottom &= 0xffff0000;
|
912 | c3d2689d | balrog | s->lcd_ch.src_f1_bottom |= 0x0000ffff & value;
|
913 | c3d2689d | balrog | break;
|
914 | c3d2689d | balrog | |
915 | c3d2689d | balrog | case 0x308: /* SYS_DMA_LCD_BOT_F1_U */ |
916 | c3d2689d | balrog | s->lcd_ch.src_f1_bottom &= 0x0000ffff;
|
917 | c3d2689d | balrog | s->lcd_ch.src_f1_bottom |= value << 16;
|
918 | c3d2689d | balrog | break;
|
919 | c3d2689d | balrog | |
920 | c3d2689d | balrog | case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */ |
921 | c3d2689d | balrog | s->lcd_ch.src_f2_top &= 0xffff0000;
|
922 | c3d2689d | balrog | s->lcd_ch.src_f2_top |= 0x0000ffff & value;
|
923 | c3d2689d | balrog | break;
|
924 | c3d2689d | balrog | |
925 | c3d2689d | balrog | case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */ |
926 | c3d2689d | balrog | s->lcd_ch.src_f2_top &= 0x0000ffff;
|
927 | c3d2689d | balrog | s->lcd_ch.src_f2_top |= value << 16;
|
928 | c3d2689d | balrog | break;
|
929 | c3d2689d | balrog | |
930 | c3d2689d | balrog | case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */ |
931 | c3d2689d | balrog | s->lcd_ch.src_f2_bottom &= 0xffff0000;
|
932 | c3d2689d | balrog | s->lcd_ch.src_f2_bottom |= 0x0000ffff & value;
|
933 | c3d2689d | balrog | break;
|
934 | c3d2689d | balrog | |
935 | c3d2689d | balrog | case 0x310: /* SYS_DMA_LCD_BOT_F2_U */ |
936 | c3d2689d | balrog | s->lcd_ch.src_f2_bottom &= 0x0000ffff;
|
937 | c3d2689d | balrog | s->lcd_ch.src_f2_bottom |= value << 16;
|
938 | c3d2689d | balrog | break;
|
939 | c3d2689d | balrog | |
940 | c3d2689d | balrog | case 0x400: /* SYS_DMA_GCR */ |
941 | c3d2689d | balrog | s->gcr = value & 0x000c;
|
942 | c3d2689d | balrog | break;
|
943 | c3d2689d | balrog | |
944 | c3d2689d | balrog | default:
|
945 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
946 | c3d2689d | balrog | } |
947 | c3d2689d | balrog | } |
948 | c3d2689d | balrog | |
949 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_dma_readfn[] = {
|
950 | c3d2689d | balrog | omap_badwidth_read16, |
951 | c3d2689d | balrog | omap_dma_read, |
952 | c3d2689d | balrog | omap_badwidth_read16, |
953 | c3d2689d | balrog | }; |
954 | c3d2689d | balrog | |
955 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_dma_writefn[] = {
|
956 | c3d2689d | balrog | omap_badwidth_write16, |
957 | c3d2689d | balrog | omap_dma_write, |
958 | c3d2689d | balrog | omap_badwidth_write16, |
959 | c3d2689d | balrog | }; |
960 | c3d2689d | balrog | |
961 | c3d2689d | balrog | static void omap_dma_request(void *opaque, int drq, int req) |
962 | c3d2689d | balrog | { |
963 | c3d2689d | balrog | struct omap_dma_s *s = (struct omap_dma_s *) opaque; |
964 | 1af2b62d | balrog | /* The request pins are level triggered. */
|
965 | 1af2b62d | balrog | if (req) {
|
966 | 1af2b62d | balrog | if (~s->drq & (1 << drq)) { |
967 | 1af2b62d | balrog | s->drq |= 1 << drq;
|
968 | 1af2b62d | balrog | omap_dma_request_run(s, 0, drq);
|
969 | 1af2b62d | balrog | } |
970 | 1af2b62d | balrog | } else
|
971 | 1af2b62d | balrog | s->drq &= ~(1 << drq);
|
972 | c3d2689d | balrog | } |
973 | c3d2689d | balrog | |
974 | c3d2689d | balrog | static void omap_dma_clk_update(void *opaque, int line, int on) |
975 | c3d2689d | balrog | { |
976 | c3d2689d | balrog | struct omap_dma_s *s = (struct omap_dma_s *) opaque; |
977 | c3d2689d | balrog | |
978 | c3d2689d | balrog | if (on) {
|
979 | c3d2689d | balrog | s->delay = ticks_per_sec >> 5;
|
980 | c3d2689d | balrog | if (s->run_count)
|
981 | c3d2689d | balrog | qemu_mod_timer(s->tm, qemu_get_clock(vm_clock) + s->delay); |
982 | c3d2689d | balrog | } else {
|
983 | c3d2689d | balrog | s->delay = 0;
|
984 | c3d2689d | balrog | qemu_del_timer(s->tm); |
985 | c3d2689d | balrog | } |
986 | c3d2689d | balrog | } |
987 | c3d2689d | balrog | |
988 | c3d2689d | balrog | static void omap_dma_reset(struct omap_dma_s *s) |
989 | c3d2689d | balrog | { |
990 | c3d2689d | balrog | int i;
|
991 | c3d2689d | balrog | |
992 | c3d2689d | balrog | qemu_del_timer(s->tm); |
993 | c3d2689d | balrog | s->gcr = 0x0004;
|
994 | 1af2b62d | balrog | s->drq = 0x00000000;
|
995 | c3d2689d | balrog | s->run_count = 0;
|
996 | c3d2689d | balrog | s->lcd_ch.src = emiff; |
997 | c3d2689d | balrog | s->lcd_ch.condition = 0;
|
998 | c3d2689d | balrog | s->lcd_ch.interrupts = 0;
|
999 | c3d2689d | balrog | s->lcd_ch.dual = 0;
|
1000 | c3d2689d | balrog | memset(s->ch, 0, sizeof(s->ch)); |
1001 | c3d2689d | balrog | for (i = 0; i < s->chans; i ++) |
1002 | c3d2689d | balrog | s->ch[i].interrupts = 0x0003;
|
1003 | c3d2689d | balrog | } |
1004 | c3d2689d | balrog | |
1005 | c3d2689d | balrog | struct omap_dma_s *omap_dma_init(target_phys_addr_t base,
|
1006 | c3d2689d | balrog | qemu_irq pic[], struct omap_mpu_state_s *mpu, omap_clk clk)
|
1007 | c3d2689d | balrog | { |
1008 | c3d2689d | balrog | int iomemtype;
|
1009 | c3d2689d | balrog | struct omap_dma_s *s = (struct omap_dma_s *) |
1010 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_dma_s)); |
1011 | c3d2689d | balrog | |
1012 | c3d2689d | balrog | s->ih = pic; |
1013 | c3d2689d | balrog | s->base = base; |
1014 | c3d2689d | balrog | s->chans = 9;
|
1015 | c3d2689d | balrog | s->mpu = mpu; |
1016 | c3d2689d | balrog | s->clk = clk; |
1017 | c3d2689d | balrog | s->lcd_ch.irq = pic[OMAP_INT_DMA_LCD]; |
1018 | c3d2689d | balrog | s->lcd_ch.mpu = mpu; |
1019 | c3d2689d | balrog | s->tm = qemu_new_timer(vm_clock, (QEMUTimerCB *) omap_dma_channel_run, s); |
1020 | c3d2689d | balrog | omap_clk_adduser(s->clk, qemu_allocate_irqs(omap_dma_clk_update, s, 1)[0]); |
1021 | c3d2689d | balrog | mpu->drq = qemu_allocate_irqs(omap_dma_request, s, 32);
|
1022 | c3d2689d | balrog | omap_dma_reset(s); |
1023 | 1af2b62d | balrog | omap_dma_clk_update(s, 0, 1); |
1024 | c3d2689d | balrog | |
1025 | c3d2689d | balrog | iomemtype = cpu_register_io_memory(0, omap_dma_readfn,
|
1026 | c3d2689d | balrog | omap_dma_writefn, s); |
1027 | c3d2689d | balrog | cpu_register_physical_memory(s->base, 0x800, iomemtype);
|
1028 | c3d2689d | balrog | |
1029 | c3d2689d | balrog | return s;
|
1030 | c3d2689d | balrog | } |
1031 | c3d2689d | balrog | |
1032 | c3d2689d | balrog | /* DMA ports */
|
1033 | c3d2689d | balrog | int omap_validate_emiff_addr(struct omap_mpu_state_s *s, |
1034 | c3d2689d | balrog | target_phys_addr_t addr) |
1035 | c3d2689d | balrog | { |
1036 | c3d2689d | balrog | return addr >= OMAP_EMIFF_BASE && addr < OMAP_EMIFF_BASE + s->sdram_size;
|
1037 | c3d2689d | balrog | } |
1038 | c3d2689d | balrog | |
1039 | c3d2689d | balrog | int omap_validate_emifs_addr(struct omap_mpu_state_s *s, |
1040 | c3d2689d | balrog | target_phys_addr_t addr) |
1041 | c3d2689d | balrog | { |
1042 | c3d2689d | balrog | return addr >= OMAP_EMIFS_BASE && addr < OMAP_EMIFF_BASE;
|
1043 | c3d2689d | balrog | } |
1044 | c3d2689d | balrog | |
1045 | c3d2689d | balrog | int omap_validate_imif_addr(struct omap_mpu_state_s *s, |
1046 | c3d2689d | balrog | target_phys_addr_t addr) |
1047 | c3d2689d | balrog | { |
1048 | c3d2689d | balrog | return addr >= OMAP_IMIF_BASE && addr < OMAP_IMIF_BASE + s->sram_size;
|
1049 | c3d2689d | balrog | } |
1050 | c3d2689d | balrog | |
1051 | c3d2689d | balrog | int omap_validate_tipb_addr(struct omap_mpu_state_s *s, |
1052 | c3d2689d | balrog | target_phys_addr_t addr) |
1053 | c3d2689d | balrog | { |
1054 | c3d2689d | balrog | return addr >= 0xfffb0000 && addr < 0xffff0000; |
1055 | c3d2689d | balrog | } |
1056 | c3d2689d | balrog | |
1057 | c3d2689d | balrog | int omap_validate_local_addr(struct omap_mpu_state_s *s, |
1058 | c3d2689d | balrog | target_phys_addr_t addr) |
1059 | c3d2689d | balrog | { |
1060 | c3d2689d | balrog | return addr >= OMAP_LOCALBUS_BASE && addr < OMAP_LOCALBUS_BASE + 0x1000000; |
1061 | c3d2689d | balrog | } |
1062 | c3d2689d | balrog | |
1063 | c3d2689d | balrog | int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s *s, |
1064 | c3d2689d | balrog | target_phys_addr_t addr) |
1065 | c3d2689d | balrog | { |
1066 | c3d2689d | balrog | return addr >= 0xe1010000 && addr < 0xe1020004; |
1067 | c3d2689d | balrog | } |
1068 | c3d2689d | balrog | |
1069 | c3d2689d | balrog | /* MPU OS timers */
|
1070 | c3d2689d | balrog | struct omap_mpu_timer_s {
|
1071 | c3d2689d | balrog | qemu_irq irq; |
1072 | c3d2689d | balrog | omap_clk clk; |
1073 | c3d2689d | balrog | target_phys_addr_t base; |
1074 | c3d2689d | balrog | uint32_t val; |
1075 | c3d2689d | balrog | int64_t time; |
1076 | c3d2689d | balrog | QEMUTimer *timer; |
1077 | c3d2689d | balrog | int64_t rate; |
1078 | c3d2689d | balrog | int it_ena;
|
1079 | c3d2689d | balrog | |
1080 | c3d2689d | balrog | int enable;
|
1081 | c3d2689d | balrog | int ptv;
|
1082 | c3d2689d | balrog | int ar;
|
1083 | c3d2689d | balrog | int st;
|
1084 | c3d2689d | balrog | uint32_t reset_val; |
1085 | c3d2689d | balrog | }; |
1086 | c3d2689d | balrog | |
1087 | c3d2689d | balrog | static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer) |
1088 | c3d2689d | balrog | { |
1089 | c3d2689d | balrog | uint64_t distance = qemu_get_clock(vm_clock) - timer->time; |
1090 | c3d2689d | balrog | |
1091 | c3d2689d | balrog | if (timer->st && timer->enable && timer->rate)
|
1092 | c3d2689d | balrog | return timer->val - muldiv64(distance >> (timer->ptv + 1), |
1093 | c3d2689d | balrog | timer->rate, ticks_per_sec); |
1094 | c3d2689d | balrog | else
|
1095 | c3d2689d | balrog | return timer->val;
|
1096 | c3d2689d | balrog | } |
1097 | c3d2689d | balrog | |
1098 | c3d2689d | balrog | static inline void omap_timer_sync(struct omap_mpu_timer_s *timer) |
1099 | c3d2689d | balrog | { |
1100 | c3d2689d | balrog | timer->val = omap_timer_read(timer); |
1101 | c3d2689d | balrog | timer->time = qemu_get_clock(vm_clock); |
1102 | c3d2689d | balrog | } |
1103 | c3d2689d | balrog | |
1104 | c3d2689d | balrog | static inline void omap_timer_update(struct omap_mpu_timer_s *timer) |
1105 | c3d2689d | balrog | { |
1106 | c3d2689d | balrog | int64_t expires; |
1107 | c3d2689d | balrog | |
1108 | c3d2689d | balrog | if (timer->enable && timer->st && timer->rate) {
|
1109 | c3d2689d | balrog | timer->val = timer->reset_val; /* Should skip this on clk enable */
|
1110 | c3d2689d | balrog | expires = timer->time + muldiv64(timer->val << (timer->ptv + 1),
|
1111 | c3d2689d | balrog | ticks_per_sec, timer->rate); |
1112 | c3d2689d | balrog | qemu_mod_timer(timer->timer, expires); |
1113 | c3d2689d | balrog | } else
|
1114 | c3d2689d | balrog | qemu_del_timer(timer->timer); |
1115 | c3d2689d | balrog | } |
1116 | c3d2689d | balrog | |
1117 | c3d2689d | balrog | static void omap_timer_tick(void *opaque) |
1118 | c3d2689d | balrog | { |
1119 | c3d2689d | balrog | struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque; |
1120 | c3d2689d | balrog | omap_timer_sync(timer); |
1121 | c3d2689d | balrog | |
1122 | c3d2689d | balrog | if (!timer->ar) {
|
1123 | c3d2689d | balrog | timer->val = 0;
|
1124 | c3d2689d | balrog | timer->st = 0;
|
1125 | c3d2689d | balrog | } |
1126 | c3d2689d | balrog | |
1127 | c3d2689d | balrog | if (timer->it_ena)
|
1128 | c3d2689d | balrog | qemu_irq_raise(timer->irq); |
1129 | c3d2689d | balrog | omap_timer_update(timer); |
1130 | c3d2689d | balrog | } |
1131 | c3d2689d | balrog | |
1132 | c3d2689d | balrog | static void omap_timer_clk_update(void *opaque, int line, int on) |
1133 | c3d2689d | balrog | { |
1134 | c3d2689d | balrog | struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque; |
1135 | c3d2689d | balrog | |
1136 | c3d2689d | balrog | omap_timer_sync(timer); |
1137 | c3d2689d | balrog | timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
|
1138 | c3d2689d | balrog | omap_timer_update(timer); |
1139 | c3d2689d | balrog | } |
1140 | c3d2689d | balrog | |
1141 | c3d2689d | balrog | static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer) |
1142 | c3d2689d | balrog | { |
1143 | c3d2689d | balrog | omap_clk_adduser(timer->clk, |
1144 | c3d2689d | balrog | qemu_allocate_irqs(omap_timer_clk_update, timer, 1)[0]); |
1145 | c3d2689d | balrog | timer->rate = omap_clk_getrate(timer->clk); |
1146 | c3d2689d | balrog | } |
1147 | c3d2689d | balrog | |
1148 | c3d2689d | balrog | static uint32_t omap_mpu_timer_read(void *opaque, target_phys_addr_t addr) |
1149 | c3d2689d | balrog | { |
1150 | c3d2689d | balrog | struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque; |
1151 | c3d2689d | balrog | int offset = addr - s->base;
|
1152 | c3d2689d | balrog | |
1153 | c3d2689d | balrog | switch (offset) {
|
1154 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
1155 | c3d2689d | balrog | return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st; |
1156 | c3d2689d | balrog | |
1157 | c3d2689d | balrog | case 0x04: /* LOAD_TIM */ |
1158 | c3d2689d | balrog | break;
|
1159 | c3d2689d | balrog | |
1160 | c3d2689d | balrog | case 0x08: /* READ_TIM */ |
1161 | c3d2689d | balrog | return omap_timer_read(s);
|
1162 | c3d2689d | balrog | } |
1163 | c3d2689d | balrog | |
1164 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1165 | c3d2689d | balrog | return 0; |
1166 | c3d2689d | balrog | } |
1167 | c3d2689d | balrog | |
1168 | c3d2689d | balrog | static void omap_mpu_timer_write(void *opaque, target_phys_addr_t addr, |
1169 | c3d2689d | balrog | uint32_t value) |
1170 | c3d2689d | balrog | { |
1171 | c3d2689d | balrog | struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque; |
1172 | c3d2689d | balrog | int offset = addr - s->base;
|
1173 | c3d2689d | balrog | |
1174 | c3d2689d | balrog | switch (offset) {
|
1175 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
1176 | c3d2689d | balrog | omap_timer_sync(s); |
1177 | c3d2689d | balrog | s->enable = (value >> 5) & 1; |
1178 | c3d2689d | balrog | s->ptv = (value >> 2) & 7; |
1179 | c3d2689d | balrog | s->ar = (value >> 1) & 1; |
1180 | c3d2689d | balrog | s->st = value & 1;
|
1181 | c3d2689d | balrog | omap_timer_update(s); |
1182 | c3d2689d | balrog | return;
|
1183 | c3d2689d | balrog | |
1184 | c3d2689d | balrog | case 0x04: /* LOAD_TIM */ |
1185 | c3d2689d | balrog | s->reset_val = value; |
1186 | c3d2689d | balrog | return;
|
1187 | c3d2689d | balrog | |
1188 | c3d2689d | balrog | case 0x08: /* READ_TIM */ |
1189 | c3d2689d | balrog | OMAP_RO_REG(addr); |
1190 | c3d2689d | balrog | break;
|
1191 | c3d2689d | balrog | |
1192 | c3d2689d | balrog | default:
|
1193 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1194 | c3d2689d | balrog | } |
1195 | c3d2689d | balrog | } |
1196 | c3d2689d | balrog | |
1197 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_mpu_timer_readfn[] = {
|
1198 | c3d2689d | balrog | omap_badwidth_read32, |
1199 | c3d2689d | balrog | omap_badwidth_read32, |
1200 | c3d2689d | balrog | omap_mpu_timer_read, |
1201 | c3d2689d | balrog | }; |
1202 | c3d2689d | balrog | |
1203 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_mpu_timer_writefn[] = {
|
1204 | c3d2689d | balrog | omap_badwidth_write32, |
1205 | c3d2689d | balrog | omap_badwidth_write32, |
1206 | c3d2689d | balrog | omap_mpu_timer_write, |
1207 | c3d2689d | balrog | }; |
1208 | c3d2689d | balrog | |
1209 | c3d2689d | balrog | static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s) |
1210 | c3d2689d | balrog | { |
1211 | c3d2689d | balrog | qemu_del_timer(s->timer); |
1212 | c3d2689d | balrog | s->enable = 0;
|
1213 | c3d2689d | balrog | s->reset_val = 31337;
|
1214 | c3d2689d | balrog | s->val = 0;
|
1215 | c3d2689d | balrog | s->ptv = 0;
|
1216 | c3d2689d | balrog | s->ar = 0;
|
1217 | c3d2689d | balrog | s->st = 0;
|
1218 | c3d2689d | balrog | s->it_ena = 1;
|
1219 | c3d2689d | balrog | } |
1220 | c3d2689d | balrog | |
1221 | c3d2689d | balrog | struct omap_mpu_timer_s *omap_mpu_timer_init(target_phys_addr_t base,
|
1222 | c3d2689d | balrog | qemu_irq irq, omap_clk clk) |
1223 | c3d2689d | balrog | { |
1224 | c3d2689d | balrog | int iomemtype;
|
1225 | c3d2689d | balrog | struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) |
1226 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_mpu_timer_s)); |
1227 | c3d2689d | balrog | |
1228 | c3d2689d | balrog | s->irq = irq; |
1229 | c3d2689d | balrog | s->clk = clk; |
1230 | c3d2689d | balrog | s->base = base; |
1231 | c3d2689d | balrog | s->timer = qemu_new_timer(vm_clock, omap_timer_tick, s); |
1232 | c3d2689d | balrog | omap_mpu_timer_reset(s); |
1233 | c3d2689d | balrog | omap_timer_clk_setup(s); |
1234 | c3d2689d | balrog | |
1235 | c3d2689d | balrog | iomemtype = cpu_register_io_memory(0, omap_mpu_timer_readfn,
|
1236 | c3d2689d | balrog | omap_mpu_timer_writefn, s); |
1237 | c3d2689d | balrog | cpu_register_physical_memory(s->base, 0x100, iomemtype);
|
1238 | c3d2689d | balrog | |
1239 | c3d2689d | balrog | return s;
|
1240 | c3d2689d | balrog | } |
1241 | c3d2689d | balrog | |
1242 | c3d2689d | balrog | /* Watchdog timer */
|
1243 | c3d2689d | balrog | struct omap_watchdog_timer_s {
|
1244 | c3d2689d | balrog | struct omap_mpu_timer_s timer;
|
1245 | c3d2689d | balrog | uint8_t last_wr; |
1246 | c3d2689d | balrog | int mode;
|
1247 | c3d2689d | balrog | int free;
|
1248 | c3d2689d | balrog | int reset;
|
1249 | c3d2689d | balrog | }; |
1250 | c3d2689d | balrog | |
1251 | c3d2689d | balrog | static uint32_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr) |
1252 | c3d2689d | balrog | { |
1253 | c3d2689d | balrog | struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque; |
1254 | c3d2689d | balrog | int offset = addr - s->timer.base;
|
1255 | c3d2689d | balrog | |
1256 | c3d2689d | balrog | switch (offset) {
|
1257 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
1258 | c3d2689d | balrog | return (s->timer.ptv << 9) | (s->timer.ar << 8) | |
1259 | c3d2689d | balrog | (s->timer.st << 7) | (s->free << 1); |
1260 | c3d2689d | balrog | |
1261 | c3d2689d | balrog | case 0x04: /* READ_TIMER */ |
1262 | c3d2689d | balrog | return omap_timer_read(&s->timer);
|
1263 | c3d2689d | balrog | |
1264 | c3d2689d | balrog | case 0x08: /* TIMER_MODE */ |
1265 | c3d2689d | balrog | return s->mode << 15; |
1266 | c3d2689d | balrog | } |
1267 | c3d2689d | balrog | |
1268 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1269 | c3d2689d | balrog | return 0; |
1270 | c3d2689d | balrog | } |
1271 | c3d2689d | balrog | |
1272 | c3d2689d | balrog | static void omap_wd_timer_write(void *opaque, target_phys_addr_t addr, |
1273 | c3d2689d | balrog | uint32_t value) |
1274 | c3d2689d | balrog | { |
1275 | c3d2689d | balrog | struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque; |
1276 | c3d2689d | balrog | int offset = addr - s->timer.base;
|
1277 | c3d2689d | balrog | |
1278 | c3d2689d | balrog | switch (offset) {
|
1279 | c3d2689d | balrog | case 0x00: /* CNTL_TIMER */ |
1280 | c3d2689d | balrog | omap_timer_sync(&s->timer); |
1281 | c3d2689d | balrog | s->timer.ptv = (value >> 9) & 7; |
1282 | c3d2689d | balrog | s->timer.ar = (value >> 8) & 1; |
1283 | c3d2689d | balrog | s->timer.st = (value >> 7) & 1; |
1284 | c3d2689d | balrog | s->free = (value >> 1) & 1; |
1285 | c3d2689d | balrog | omap_timer_update(&s->timer); |
1286 | c3d2689d | balrog | break;
|
1287 | c3d2689d | balrog | |
1288 | c3d2689d | balrog | case 0x04: /* LOAD_TIMER */ |
1289 | c3d2689d | balrog | s->timer.reset_val = value & 0xffff;
|
1290 | c3d2689d | balrog | break;
|
1291 | c3d2689d | balrog | |
1292 | c3d2689d | balrog | case 0x08: /* TIMER_MODE */ |
1293 | c3d2689d | balrog | if (!s->mode && ((value >> 15) & 1)) |
1294 | c3d2689d | balrog | omap_clk_get(s->timer.clk); |
1295 | c3d2689d | balrog | s->mode |= (value >> 15) & 1; |
1296 | c3d2689d | balrog | if (s->last_wr == 0xf5) { |
1297 | c3d2689d | balrog | if ((value & 0xff) == 0xa0) { |
1298 | c3d2689d | balrog | s->mode = 0;
|
1299 | c3d2689d | balrog | omap_clk_put(s->timer.clk); |
1300 | c3d2689d | balrog | } else {
|
1301 | c3d2689d | balrog | /* XXX: on T|E hardware somehow this has no effect,
|
1302 | c3d2689d | balrog | * on Zire 71 it works as specified. */
|
1303 | c3d2689d | balrog | s->reset = 1;
|
1304 | c3d2689d | balrog | qemu_system_reset_request(); |
1305 | c3d2689d | balrog | } |
1306 | c3d2689d | balrog | } |
1307 | c3d2689d | balrog | s->last_wr = value & 0xff;
|
1308 | c3d2689d | balrog | break;
|
1309 | c3d2689d | balrog | |
1310 | c3d2689d | balrog | default:
|
1311 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1312 | c3d2689d | balrog | } |
1313 | c3d2689d | balrog | } |
1314 | c3d2689d | balrog | |
1315 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_wd_timer_readfn[] = {
|
1316 | c3d2689d | balrog | omap_badwidth_read16, |
1317 | c3d2689d | balrog | omap_wd_timer_read, |
1318 | c3d2689d | balrog | omap_badwidth_read16, |
1319 | c3d2689d | balrog | }; |
1320 | c3d2689d | balrog | |
1321 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_wd_timer_writefn[] = {
|
1322 | c3d2689d | balrog | omap_badwidth_write16, |
1323 | c3d2689d | balrog | omap_wd_timer_write, |
1324 | c3d2689d | balrog | omap_badwidth_write16, |
1325 | c3d2689d | balrog | }; |
1326 | c3d2689d | balrog | |
1327 | c3d2689d | balrog | static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s) |
1328 | c3d2689d | balrog | { |
1329 | c3d2689d | balrog | qemu_del_timer(s->timer.timer); |
1330 | c3d2689d | balrog | if (!s->mode)
|
1331 | c3d2689d | balrog | omap_clk_get(s->timer.clk); |
1332 | c3d2689d | balrog | s->mode = 1;
|
1333 | c3d2689d | balrog | s->free = 1;
|
1334 | c3d2689d | balrog | s->reset = 0;
|
1335 | c3d2689d | balrog | s->timer.enable = 1;
|
1336 | c3d2689d | balrog | s->timer.it_ena = 1;
|
1337 | c3d2689d | balrog | s->timer.reset_val = 0xffff;
|
1338 | c3d2689d | balrog | s->timer.val = 0;
|
1339 | c3d2689d | balrog | s->timer.st = 0;
|
1340 | c3d2689d | balrog | s->timer.ptv = 0;
|
1341 | c3d2689d | balrog | s->timer.ar = 0;
|
1342 | c3d2689d | balrog | omap_timer_update(&s->timer); |
1343 | c3d2689d | balrog | } |
1344 | c3d2689d | balrog | |
1345 | c3d2689d | balrog | struct omap_watchdog_timer_s *omap_wd_timer_init(target_phys_addr_t base,
|
1346 | c3d2689d | balrog | qemu_irq irq, omap_clk clk) |
1347 | c3d2689d | balrog | { |
1348 | c3d2689d | balrog | int iomemtype;
|
1349 | c3d2689d | balrog | struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) |
1350 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_watchdog_timer_s)); |
1351 | c3d2689d | balrog | |
1352 | c3d2689d | balrog | s->timer.irq = irq; |
1353 | c3d2689d | balrog | s->timer.clk = clk; |
1354 | c3d2689d | balrog | s->timer.base = base; |
1355 | c3d2689d | balrog | s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer); |
1356 | c3d2689d | balrog | omap_wd_timer_reset(s); |
1357 | c3d2689d | balrog | omap_timer_clk_setup(&s->timer); |
1358 | c3d2689d | balrog | |
1359 | c3d2689d | balrog | iomemtype = cpu_register_io_memory(0, omap_wd_timer_readfn,
|
1360 | c3d2689d | balrog | omap_wd_timer_writefn, s); |
1361 | c3d2689d | balrog | cpu_register_physical_memory(s->timer.base, 0x100, iomemtype);
|
1362 | c3d2689d | balrog | |
1363 | c3d2689d | balrog | return s;
|
1364 | c3d2689d | balrog | } |
1365 | c3d2689d | balrog | |
1366 | c3d2689d | balrog | /* 32-kHz timer */
|
1367 | c3d2689d | balrog | struct omap_32khz_timer_s {
|
1368 | c3d2689d | balrog | struct omap_mpu_timer_s timer;
|
1369 | c3d2689d | balrog | }; |
1370 | c3d2689d | balrog | |
1371 | c3d2689d | balrog | static uint32_t omap_os_timer_read(void *opaque, target_phys_addr_t addr) |
1372 | c3d2689d | balrog | { |
1373 | c3d2689d | balrog | struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque; |
1374 | c3d2689d | balrog | int offset = addr - s->timer.base;
|
1375 | c3d2689d | balrog | |
1376 | c3d2689d | balrog | switch (offset) {
|
1377 | c3d2689d | balrog | case 0x00: /* TVR */ |
1378 | c3d2689d | balrog | return s->timer.reset_val;
|
1379 | c3d2689d | balrog | |
1380 | c3d2689d | balrog | case 0x04: /* TCR */ |
1381 | c3d2689d | balrog | return omap_timer_read(&s->timer);
|
1382 | c3d2689d | balrog | |
1383 | c3d2689d | balrog | case 0x08: /* CR */ |
1384 | c3d2689d | balrog | return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st; |
1385 | c3d2689d | balrog | |
1386 | c3d2689d | balrog | default:
|
1387 | c3d2689d | balrog | break;
|
1388 | c3d2689d | balrog | } |
1389 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1390 | c3d2689d | balrog | return 0; |
1391 | c3d2689d | balrog | } |
1392 | c3d2689d | balrog | |
1393 | c3d2689d | balrog | static void omap_os_timer_write(void *opaque, target_phys_addr_t addr, |
1394 | c3d2689d | balrog | uint32_t value) |
1395 | c3d2689d | balrog | { |
1396 | c3d2689d | balrog | struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque; |
1397 | c3d2689d | balrog | int offset = addr - s->timer.base;
|
1398 | c3d2689d | balrog | |
1399 | c3d2689d | balrog | switch (offset) {
|
1400 | c3d2689d | balrog | case 0x00: /* TVR */ |
1401 | c3d2689d | balrog | s->timer.reset_val = value & 0x00ffffff;
|
1402 | c3d2689d | balrog | break;
|
1403 | c3d2689d | balrog | |
1404 | c3d2689d | balrog | case 0x04: /* TCR */ |
1405 | c3d2689d | balrog | OMAP_RO_REG(addr); |
1406 | c3d2689d | balrog | break;
|
1407 | c3d2689d | balrog | |
1408 | c3d2689d | balrog | case 0x08: /* CR */ |
1409 | c3d2689d | balrog | s->timer.ar = (value >> 3) & 1; |
1410 | c3d2689d | balrog | s->timer.it_ena = (value >> 2) & 1; |
1411 | c3d2689d | balrog | if (s->timer.st != (value & 1) || (value & 2)) { |
1412 | c3d2689d | balrog | omap_timer_sync(&s->timer); |
1413 | c3d2689d | balrog | s->timer.enable = value & 1;
|
1414 | c3d2689d | balrog | s->timer.st = value & 1;
|
1415 | c3d2689d | balrog | omap_timer_update(&s->timer); |
1416 | c3d2689d | balrog | } |
1417 | c3d2689d | balrog | break;
|
1418 | c3d2689d | balrog | |
1419 | c3d2689d | balrog | default:
|
1420 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1421 | c3d2689d | balrog | } |
1422 | c3d2689d | balrog | } |
1423 | c3d2689d | balrog | |
1424 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_os_timer_readfn[] = {
|
1425 | c3d2689d | balrog | omap_badwidth_read32, |
1426 | c3d2689d | balrog | omap_badwidth_read32, |
1427 | c3d2689d | balrog | omap_os_timer_read, |
1428 | c3d2689d | balrog | }; |
1429 | c3d2689d | balrog | |
1430 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_os_timer_writefn[] = {
|
1431 | c3d2689d | balrog | omap_badwidth_write32, |
1432 | c3d2689d | balrog | omap_badwidth_write32, |
1433 | c3d2689d | balrog | omap_os_timer_write, |
1434 | c3d2689d | balrog | }; |
1435 | c3d2689d | balrog | |
1436 | c3d2689d | balrog | static void omap_os_timer_reset(struct omap_32khz_timer_s *s) |
1437 | c3d2689d | balrog | { |
1438 | c3d2689d | balrog | qemu_del_timer(s->timer.timer); |
1439 | c3d2689d | balrog | s->timer.enable = 0;
|
1440 | c3d2689d | balrog | s->timer.it_ena = 0;
|
1441 | c3d2689d | balrog | s->timer.reset_val = 0x00ffffff;
|
1442 | c3d2689d | balrog | s->timer.val = 0;
|
1443 | c3d2689d | balrog | s->timer.st = 0;
|
1444 | c3d2689d | balrog | s->timer.ptv = 0;
|
1445 | c3d2689d | balrog | s->timer.ar = 1;
|
1446 | c3d2689d | balrog | } |
1447 | c3d2689d | balrog | |
1448 | c3d2689d | balrog | struct omap_32khz_timer_s *omap_os_timer_init(target_phys_addr_t base,
|
1449 | c3d2689d | balrog | qemu_irq irq, omap_clk clk) |
1450 | c3d2689d | balrog | { |
1451 | c3d2689d | balrog | int iomemtype;
|
1452 | c3d2689d | balrog | struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) |
1453 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_32khz_timer_s)); |
1454 | c3d2689d | balrog | |
1455 | c3d2689d | balrog | s->timer.irq = irq; |
1456 | c3d2689d | balrog | s->timer.clk = clk; |
1457 | c3d2689d | balrog | s->timer.base = base; |
1458 | c3d2689d | balrog | s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer); |
1459 | c3d2689d | balrog | omap_os_timer_reset(s); |
1460 | c3d2689d | balrog | omap_timer_clk_setup(&s->timer); |
1461 | c3d2689d | balrog | |
1462 | c3d2689d | balrog | iomemtype = cpu_register_io_memory(0, omap_os_timer_readfn,
|
1463 | c3d2689d | balrog | omap_os_timer_writefn, s); |
1464 | c3d2689d | balrog | cpu_register_physical_memory(s->timer.base, 0x800, iomemtype);
|
1465 | c3d2689d | balrog | |
1466 | c3d2689d | balrog | return s;
|
1467 | c3d2689d | balrog | } |
1468 | c3d2689d | balrog | |
1469 | c3d2689d | balrog | /* Ultra Low-Power Device Module */
|
1470 | c3d2689d | balrog | static uint32_t omap_ulpd_pm_read(void *opaque, target_phys_addr_t addr) |
1471 | c3d2689d | balrog | { |
1472 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1473 | c3d2689d | balrog | int offset = addr - s->ulpd_pm_base;
|
1474 | c3d2689d | balrog | uint16_t ret; |
1475 | c3d2689d | balrog | |
1476 | c3d2689d | balrog | switch (offset) {
|
1477 | c3d2689d | balrog | case 0x14: /* IT_STATUS */ |
1478 | c3d2689d | balrog | ret = s->ulpd_pm_regs[offset >> 2];
|
1479 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] = 0; |
1480 | c3d2689d | balrog | qemu_irq_lower(s->irq[1][OMAP_INT_GAUGE_32K]);
|
1481 | c3d2689d | balrog | return ret;
|
1482 | c3d2689d | balrog | |
1483 | c3d2689d | balrog | case 0x18: /* Reserved */ |
1484 | c3d2689d | balrog | case 0x1c: /* Reserved */ |
1485 | c3d2689d | balrog | case 0x20: /* Reserved */ |
1486 | c3d2689d | balrog | case 0x28: /* Reserved */ |
1487 | c3d2689d | balrog | case 0x2c: /* Reserved */ |
1488 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1489 | c3d2689d | balrog | case 0x00: /* COUNTER_32_LSB */ |
1490 | c3d2689d | balrog | case 0x04: /* COUNTER_32_MSB */ |
1491 | c3d2689d | balrog | case 0x08: /* COUNTER_HIGH_FREQ_LSB */ |
1492 | c3d2689d | balrog | case 0x0c: /* COUNTER_HIGH_FREQ_MSB */ |
1493 | c3d2689d | balrog | case 0x10: /* GAUGING_CTRL */ |
1494 | c3d2689d | balrog | case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */ |
1495 | c3d2689d | balrog | case 0x30: /* CLOCK_CTRL */ |
1496 | c3d2689d | balrog | case 0x34: /* SOFT_REQ */ |
1497 | c3d2689d | balrog | case 0x38: /* COUNTER_32_FIQ */ |
1498 | c3d2689d | balrog | case 0x3c: /* DPLL_CTRL */ |
1499 | c3d2689d | balrog | case 0x40: /* STATUS_REQ */ |
1500 | c3d2689d | balrog | /* XXX: check clk::usecount state for every clock */
|
1501 | c3d2689d | balrog | case 0x48: /* LOCL_TIME */ |
1502 | c3d2689d | balrog | case 0x4c: /* APLL_CTRL */ |
1503 | c3d2689d | balrog | case 0x50: /* POWER_CTRL */ |
1504 | c3d2689d | balrog | return s->ulpd_pm_regs[offset >> 2]; |
1505 | c3d2689d | balrog | } |
1506 | c3d2689d | balrog | |
1507 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1508 | c3d2689d | balrog | return 0; |
1509 | c3d2689d | balrog | } |
1510 | c3d2689d | balrog | |
1511 | c3d2689d | balrog | static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s, |
1512 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
1513 | c3d2689d | balrog | { |
1514 | c3d2689d | balrog | if (diff & (1 << 4)) /* USB_MCLK_EN */ |
1515 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1); |
1516 | c3d2689d | balrog | if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */ |
1517 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1); |
1518 | c3d2689d | balrog | } |
1519 | c3d2689d | balrog | |
1520 | c3d2689d | balrog | static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s, |
1521 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
1522 | c3d2689d | balrog | { |
1523 | c3d2689d | balrog | if (diff & (1 << 0)) /* SOFT_DPLL_REQ */ |
1524 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1); |
1525 | c3d2689d | balrog | if (diff & (1 << 1)) /* SOFT_COM_REQ */ |
1526 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1); |
1527 | c3d2689d | balrog | if (diff & (1 << 2)) /* SOFT_SDW_REQ */ |
1528 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1); |
1529 | c3d2689d | balrog | if (diff & (1 << 3)) /* SOFT_USB_REQ */ |
1530 | c3d2689d | balrog | omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1); |
1531 | c3d2689d | balrog | } |
1532 | c3d2689d | balrog | |
1533 | c3d2689d | balrog | static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr, |
1534 | c3d2689d | balrog | uint32_t value) |
1535 | c3d2689d | balrog | { |
1536 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1537 | c3d2689d | balrog | int offset = addr - s->ulpd_pm_base;
|
1538 | c3d2689d | balrog | int64_t now, ticks; |
1539 | c3d2689d | balrog | int div, mult;
|
1540 | c3d2689d | balrog | static const int bypass_div[4] = { 1, 2, 4, 4 }; |
1541 | c3d2689d | balrog | uint16_t diff; |
1542 | c3d2689d | balrog | |
1543 | c3d2689d | balrog | switch (offset) {
|
1544 | c3d2689d | balrog | case 0x00: /* COUNTER_32_LSB */ |
1545 | c3d2689d | balrog | case 0x04: /* COUNTER_32_MSB */ |
1546 | c3d2689d | balrog | case 0x08: /* COUNTER_HIGH_FREQ_LSB */ |
1547 | c3d2689d | balrog | case 0x0c: /* COUNTER_HIGH_FREQ_MSB */ |
1548 | c3d2689d | balrog | case 0x14: /* IT_STATUS */ |
1549 | c3d2689d | balrog | case 0x40: /* STATUS_REQ */ |
1550 | c3d2689d | balrog | OMAP_RO_REG(addr); |
1551 | c3d2689d | balrog | break;
|
1552 | c3d2689d | balrog | |
1553 | c3d2689d | balrog | case 0x10: /* GAUGING_CTRL */ |
1554 | c3d2689d | balrog | /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
|
1555 | c3d2689d | balrog | if ((s->ulpd_pm_regs[offset >> 2] ^ value) & 1) { |
1556 | c3d2689d | balrog | now = qemu_get_clock(vm_clock); |
1557 | c3d2689d | balrog | |
1558 | c3d2689d | balrog | if (value & 1) |
1559 | c3d2689d | balrog | s->ulpd_gauge_start = now; |
1560 | c3d2689d | balrog | else {
|
1561 | c3d2689d | balrog | now -= s->ulpd_gauge_start; |
1562 | c3d2689d | balrog | |
1563 | c3d2689d | balrog | /* 32-kHz ticks */
|
1564 | c3d2689d | balrog | ticks = muldiv64(now, 32768, ticks_per_sec);
|
1565 | c3d2689d | balrog | s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff; |
1566 | c3d2689d | balrog | s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff; |
1567 | c3d2689d | balrog | if (ticks >> 32) /* OVERFLOW_32K */ |
1568 | c3d2689d | balrog | s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2; |
1569 | c3d2689d | balrog | |
1570 | c3d2689d | balrog | /* High frequency ticks */
|
1571 | c3d2689d | balrog | ticks = muldiv64(now, 12000000, ticks_per_sec);
|
1572 | c3d2689d | balrog | s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff; |
1573 | c3d2689d | balrog | s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff; |
1574 | c3d2689d | balrog | if (ticks >> 32) /* OVERFLOW_HI_FREQ */ |
1575 | c3d2689d | balrog | s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1; |
1576 | c3d2689d | balrog | |
1577 | c3d2689d | balrog | s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */ |
1578 | c3d2689d | balrog | qemu_irq_raise(s->irq[1][OMAP_INT_GAUGE_32K]);
|
1579 | c3d2689d | balrog | } |
1580 | c3d2689d | balrog | } |
1581 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] = value;
|
1582 | c3d2689d | balrog | break;
|
1583 | c3d2689d | balrog | |
1584 | c3d2689d | balrog | case 0x18: /* Reserved */ |
1585 | c3d2689d | balrog | case 0x1c: /* Reserved */ |
1586 | c3d2689d | balrog | case 0x20: /* Reserved */ |
1587 | c3d2689d | balrog | case 0x28: /* Reserved */ |
1588 | c3d2689d | balrog | case 0x2c: /* Reserved */ |
1589 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1590 | c3d2689d | balrog | case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */ |
1591 | c3d2689d | balrog | case 0x38: /* COUNTER_32_FIQ */ |
1592 | c3d2689d | balrog | case 0x48: /* LOCL_TIME */ |
1593 | c3d2689d | balrog | case 0x50: /* POWER_CTRL */ |
1594 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] = value;
|
1595 | c3d2689d | balrog | break;
|
1596 | c3d2689d | balrog | |
1597 | c3d2689d | balrog | case 0x30: /* CLOCK_CTRL */ |
1598 | c3d2689d | balrog | diff = s->ulpd_pm_regs[offset >> 2] ^ value;
|
1599 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] = value & 0x3f; |
1600 | c3d2689d | balrog | omap_ulpd_clk_update(s, diff, value); |
1601 | c3d2689d | balrog | break;
|
1602 | c3d2689d | balrog | |
1603 | c3d2689d | balrog | case 0x34: /* SOFT_REQ */ |
1604 | c3d2689d | balrog | diff = s->ulpd_pm_regs[offset >> 2] ^ value;
|
1605 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] = value & 0x1f; |
1606 | c3d2689d | balrog | omap_ulpd_req_update(s, diff, value); |
1607 | c3d2689d | balrog | break;
|
1608 | c3d2689d | balrog | |
1609 | c3d2689d | balrog | case 0x3c: /* DPLL_CTRL */ |
1610 | c3d2689d | balrog | /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
|
1611 | c3d2689d | balrog | * omitted altogether, probably a typo. */
|
1612 | c3d2689d | balrog | /* This register has identical semantics with DPLL(1:3) control
|
1613 | c3d2689d | balrog | * registers, see omap_dpll_write() */
|
1614 | c3d2689d | balrog | diff = s->ulpd_pm_regs[offset >> 2] & value;
|
1615 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] = value & 0x2fff; |
1616 | c3d2689d | balrog | if (diff & (0x3ff << 2)) { |
1617 | c3d2689d | balrog | if (value & (1 << 4)) { /* PLL_ENABLE */ |
1618 | c3d2689d | balrog | div = ((value >> 5) & 3) + 1; /* PLL_DIV */ |
1619 | c3d2689d | balrog | mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */ |
1620 | c3d2689d | balrog | } else {
|
1621 | c3d2689d | balrog | div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */ |
1622 | c3d2689d | balrog | mult = 1;
|
1623 | c3d2689d | balrog | } |
1624 | c3d2689d | balrog | omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
|
1625 | c3d2689d | balrog | } |
1626 | c3d2689d | balrog | |
1627 | c3d2689d | balrog | /* Enter the desired mode. */
|
1628 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] =
|
1629 | c3d2689d | balrog | (s->ulpd_pm_regs[offset >> 2] & 0xfffe) | |
1630 | c3d2689d | balrog | ((s->ulpd_pm_regs[offset >> 2] >> 4) & 1); |
1631 | c3d2689d | balrog | |
1632 | c3d2689d | balrog | /* Act as if the lock is restored. */
|
1633 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] |= 2; |
1634 | c3d2689d | balrog | break;
|
1635 | c3d2689d | balrog | |
1636 | c3d2689d | balrog | case 0x4c: /* APLL_CTRL */ |
1637 | c3d2689d | balrog | diff = s->ulpd_pm_regs[offset >> 2] & value;
|
1638 | c3d2689d | balrog | s->ulpd_pm_regs[offset >> 2] = value & 0xf; |
1639 | c3d2689d | balrog | if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */ |
1640 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
|
1641 | c3d2689d | balrog | (value & (1 << 0)) ? "apll" : "dpll4")); |
1642 | c3d2689d | balrog | break;
|
1643 | c3d2689d | balrog | |
1644 | c3d2689d | balrog | default:
|
1645 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1646 | c3d2689d | balrog | } |
1647 | c3d2689d | balrog | } |
1648 | c3d2689d | balrog | |
1649 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_ulpd_pm_readfn[] = {
|
1650 | c3d2689d | balrog | omap_badwidth_read16, |
1651 | c3d2689d | balrog | omap_ulpd_pm_read, |
1652 | c3d2689d | balrog | omap_badwidth_read16, |
1653 | c3d2689d | balrog | }; |
1654 | c3d2689d | balrog | |
1655 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_ulpd_pm_writefn[] = {
|
1656 | c3d2689d | balrog | omap_badwidth_write16, |
1657 | c3d2689d | balrog | omap_ulpd_pm_write, |
1658 | c3d2689d | balrog | omap_badwidth_write16, |
1659 | c3d2689d | balrog | }; |
1660 | c3d2689d | balrog | |
1661 | c3d2689d | balrog | static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu) |
1662 | c3d2689d | balrog | { |
1663 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001; |
1664 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000; |
1665 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001; |
1666 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000; |
1667 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000; |
1668 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x18 >> 2] = 0x01; |
1669 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x1c >> 2] = 0x01; |
1670 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x20 >> 2] = 0x01; |
1671 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff; |
1672 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x28 >> 2] = 0x01; |
1673 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x2c >> 2] = 0x01; |
1674 | c3d2689d | balrog | omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000); |
1675 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000; |
1676 | c3d2689d | balrog | omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000); |
1677 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000; |
1678 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001; |
1679 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211; |
1680 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */ |
1681 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x48 >> 2] = 0x960; |
1682 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x4c >> 2] = 0x08; |
1683 | c3d2689d | balrog | mpu->ulpd_pm_regs[0x50 >> 2] = 0x08; |
1684 | c3d2689d | balrog | omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4); |
1685 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4")); |
1686 | c3d2689d | balrog | } |
1687 | c3d2689d | balrog | |
1688 | c3d2689d | balrog | static void omap_ulpd_pm_init(target_phys_addr_t base, |
1689 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
1690 | c3d2689d | balrog | { |
1691 | c3d2689d | balrog | int iomemtype = cpu_register_io_memory(0, omap_ulpd_pm_readfn, |
1692 | c3d2689d | balrog | omap_ulpd_pm_writefn, mpu); |
1693 | c3d2689d | balrog | |
1694 | c3d2689d | balrog | mpu->ulpd_pm_base = base; |
1695 | c3d2689d | balrog | cpu_register_physical_memory(mpu->ulpd_pm_base, 0x800, iomemtype);
|
1696 | c3d2689d | balrog | omap_ulpd_pm_reset(mpu); |
1697 | c3d2689d | balrog | } |
1698 | c3d2689d | balrog | |
1699 | c3d2689d | balrog | /* OMAP Pin Configuration */
|
1700 | c3d2689d | balrog | static uint32_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr) |
1701 | c3d2689d | balrog | { |
1702 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1703 | c3d2689d | balrog | int offset = addr - s->pin_cfg_base;
|
1704 | c3d2689d | balrog | |
1705 | c3d2689d | balrog | switch (offset) {
|
1706 | c3d2689d | balrog | case 0x00: /* FUNC_MUX_CTRL_0 */ |
1707 | c3d2689d | balrog | case 0x04: /* FUNC_MUX_CTRL_1 */ |
1708 | c3d2689d | balrog | case 0x08: /* FUNC_MUX_CTRL_2 */ |
1709 | c3d2689d | balrog | return s->func_mux_ctrl[offset >> 2]; |
1710 | c3d2689d | balrog | |
1711 | c3d2689d | balrog | case 0x0c: /* COMP_MODE_CTRL_0 */ |
1712 | c3d2689d | balrog | return s->comp_mode_ctrl[0]; |
1713 | c3d2689d | balrog | |
1714 | c3d2689d | balrog | case 0x10: /* FUNC_MUX_CTRL_3 */ |
1715 | c3d2689d | balrog | case 0x14: /* FUNC_MUX_CTRL_4 */ |
1716 | c3d2689d | balrog | case 0x18: /* FUNC_MUX_CTRL_5 */ |
1717 | c3d2689d | balrog | case 0x1c: /* FUNC_MUX_CTRL_6 */ |
1718 | c3d2689d | balrog | case 0x20: /* FUNC_MUX_CTRL_7 */ |
1719 | c3d2689d | balrog | case 0x24: /* FUNC_MUX_CTRL_8 */ |
1720 | c3d2689d | balrog | case 0x28: /* FUNC_MUX_CTRL_9 */ |
1721 | c3d2689d | balrog | case 0x2c: /* FUNC_MUX_CTRL_A */ |
1722 | c3d2689d | balrog | case 0x30: /* FUNC_MUX_CTRL_B */ |
1723 | c3d2689d | balrog | case 0x34: /* FUNC_MUX_CTRL_C */ |
1724 | c3d2689d | balrog | case 0x38: /* FUNC_MUX_CTRL_D */ |
1725 | c3d2689d | balrog | return s->func_mux_ctrl[(offset >> 2) - 1]; |
1726 | c3d2689d | balrog | |
1727 | c3d2689d | balrog | case 0x40: /* PULL_DWN_CTRL_0 */ |
1728 | c3d2689d | balrog | case 0x44: /* PULL_DWN_CTRL_1 */ |
1729 | c3d2689d | balrog | case 0x48: /* PULL_DWN_CTRL_2 */ |
1730 | c3d2689d | balrog | case 0x4c: /* PULL_DWN_CTRL_3 */ |
1731 | c3d2689d | balrog | return s->pull_dwn_ctrl[(offset & 0xf) >> 2]; |
1732 | c3d2689d | balrog | |
1733 | c3d2689d | balrog | case 0x50: /* GATE_INH_CTRL_0 */ |
1734 | c3d2689d | balrog | return s->gate_inh_ctrl[0]; |
1735 | c3d2689d | balrog | |
1736 | c3d2689d | balrog | case 0x60: /* VOLTAGE_CTRL_0 */ |
1737 | c3d2689d | balrog | return s->voltage_ctrl[0]; |
1738 | c3d2689d | balrog | |
1739 | c3d2689d | balrog | case 0x70: /* TEST_DBG_CTRL_0 */ |
1740 | c3d2689d | balrog | return s->test_dbg_ctrl[0]; |
1741 | c3d2689d | balrog | |
1742 | c3d2689d | balrog | case 0x80: /* MOD_CONF_CTRL_0 */ |
1743 | c3d2689d | balrog | return s->mod_conf_ctrl[0]; |
1744 | c3d2689d | balrog | } |
1745 | c3d2689d | balrog | |
1746 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1747 | c3d2689d | balrog | return 0; |
1748 | c3d2689d | balrog | } |
1749 | c3d2689d | balrog | |
1750 | c3d2689d | balrog | static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s, |
1751 | c3d2689d | balrog | uint32_t diff, uint32_t value) |
1752 | c3d2689d | balrog | { |
1753 | c3d2689d | balrog | if (s->compat1509) {
|
1754 | c3d2689d | balrog | if (diff & (1 << 9)) /* BLUETOOTH */ |
1755 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
|
1756 | c3d2689d | balrog | (~value >> 9) & 1); |
1757 | c3d2689d | balrog | if (diff & (1 << 7)) /* USB.CLKO */ |
1758 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb.clko"),
|
1759 | c3d2689d | balrog | (value >> 7) & 1); |
1760 | c3d2689d | balrog | } |
1761 | c3d2689d | balrog | } |
1762 | c3d2689d | balrog | |
1763 | c3d2689d | balrog | static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s, |
1764 | c3d2689d | balrog | uint32_t diff, uint32_t value) |
1765 | c3d2689d | balrog | { |
1766 | c3d2689d | balrog | if (s->compat1509) {
|
1767 | c3d2689d | balrog | if (diff & (1 << 31)) /* MCBSP3_CLK_HIZ_DI */ |
1768 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"),
|
1769 | c3d2689d | balrog | (value >> 31) & 1); |
1770 | c3d2689d | balrog | if (diff & (1 << 1)) /* CLK32K */ |
1771 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "clk32k_out"),
|
1772 | c3d2689d | balrog | (~value >> 1) & 1); |
1773 | c3d2689d | balrog | } |
1774 | c3d2689d | balrog | } |
1775 | c3d2689d | balrog | |
1776 | c3d2689d | balrog | static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s, |
1777 | c3d2689d | balrog | uint32_t diff, uint32_t value) |
1778 | c3d2689d | balrog | { |
1779 | c3d2689d | balrog | if (diff & (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */ |
1780 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "uart3_ck"),
|
1781 | c3d2689d | balrog | omap_findclk(s, ((value >> 31) & 1) ? |
1782 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1783 | c3d2689d | balrog | if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */ |
1784 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "uart2_ck"),
|
1785 | c3d2689d | balrog | omap_findclk(s, ((value >> 30) & 1) ? |
1786 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1787 | c3d2689d | balrog | if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */ |
1788 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "uart1_ck"),
|
1789 | c3d2689d | balrog | omap_findclk(s, ((value >> 29) & 1) ? |
1790 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1791 | c3d2689d | balrog | if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */ |
1792 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "mmc_ck"),
|
1793 | c3d2689d | balrog | omap_findclk(s, ((value >> 23) & 1) ? |
1794 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1795 | c3d2689d | balrog | if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */ |
1796 | c3d2689d | balrog | omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
|
1797 | c3d2689d | balrog | omap_findclk(s, ((value >> 12) & 1) ? |
1798 | c3d2689d | balrog | "ck_48m" : "armper_ck")); |
1799 | c3d2689d | balrog | if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */ |
1800 | c3d2689d | balrog | omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1); |
1801 | c3d2689d | balrog | } |
1802 | c3d2689d | balrog | |
1803 | c3d2689d | balrog | static void omap_pin_cfg_write(void *opaque, target_phys_addr_t addr, |
1804 | c3d2689d | balrog | uint32_t value) |
1805 | c3d2689d | balrog | { |
1806 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1807 | c3d2689d | balrog | int offset = addr - s->pin_cfg_base;
|
1808 | c3d2689d | balrog | uint32_t diff; |
1809 | c3d2689d | balrog | |
1810 | c3d2689d | balrog | switch (offset) {
|
1811 | c3d2689d | balrog | case 0x00: /* FUNC_MUX_CTRL_0 */ |
1812 | c3d2689d | balrog | diff = s->func_mux_ctrl[offset >> 2] ^ value;
|
1813 | c3d2689d | balrog | s->func_mux_ctrl[offset >> 2] = value;
|
1814 | c3d2689d | balrog | omap_pin_funcmux0_update(s, diff, value); |
1815 | c3d2689d | balrog | return;
|
1816 | c3d2689d | balrog | |
1817 | c3d2689d | balrog | case 0x04: /* FUNC_MUX_CTRL_1 */ |
1818 | c3d2689d | balrog | diff = s->func_mux_ctrl[offset >> 2] ^ value;
|
1819 | c3d2689d | balrog | s->func_mux_ctrl[offset >> 2] = value;
|
1820 | c3d2689d | balrog | omap_pin_funcmux1_update(s, diff, value); |
1821 | c3d2689d | balrog | return;
|
1822 | c3d2689d | balrog | |
1823 | c3d2689d | balrog | case 0x08: /* FUNC_MUX_CTRL_2 */ |
1824 | c3d2689d | balrog | s->func_mux_ctrl[offset >> 2] = value;
|
1825 | c3d2689d | balrog | return;
|
1826 | c3d2689d | balrog | |
1827 | c3d2689d | balrog | case 0x0c: /* COMP_MODE_CTRL_0 */ |
1828 | c3d2689d | balrog | s->comp_mode_ctrl[0] = value;
|
1829 | c3d2689d | balrog | s->compat1509 = (value != 0x0000eaef);
|
1830 | c3d2689d | balrog | omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]); |
1831 | c3d2689d | balrog | omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]); |
1832 | c3d2689d | balrog | return;
|
1833 | c3d2689d | balrog | |
1834 | c3d2689d | balrog | case 0x10: /* FUNC_MUX_CTRL_3 */ |
1835 | c3d2689d | balrog | case 0x14: /* FUNC_MUX_CTRL_4 */ |
1836 | c3d2689d | balrog | case 0x18: /* FUNC_MUX_CTRL_5 */ |
1837 | c3d2689d | balrog | case 0x1c: /* FUNC_MUX_CTRL_6 */ |
1838 | c3d2689d | balrog | case 0x20: /* FUNC_MUX_CTRL_7 */ |
1839 | c3d2689d | balrog | case 0x24: /* FUNC_MUX_CTRL_8 */ |
1840 | c3d2689d | balrog | case 0x28: /* FUNC_MUX_CTRL_9 */ |
1841 | c3d2689d | balrog | case 0x2c: /* FUNC_MUX_CTRL_A */ |
1842 | c3d2689d | balrog | case 0x30: /* FUNC_MUX_CTRL_B */ |
1843 | c3d2689d | balrog | case 0x34: /* FUNC_MUX_CTRL_C */ |
1844 | c3d2689d | balrog | case 0x38: /* FUNC_MUX_CTRL_D */ |
1845 | c3d2689d | balrog | s->func_mux_ctrl[(offset >> 2) - 1] = value; |
1846 | c3d2689d | balrog | return;
|
1847 | c3d2689d | balrog | |
1848 | c3d2689d | balrog | case 0x40: /* PULL_DWN_CTRL_0 */ |
1849 | c3d2689d | balrog | case 0x44: /* PULL_DWN_CTRL_1 */ |
1850 | c3d2689d | balrog | case 0x48: /* PULL_DWN_CTRL_2 */ |
1851 | c3d2689d | balrog | case 0x4c: /* PULL_DWN_CTRL_3 */ |
1852 | c3d2689d | balrog | s->pull_dwn_ctrl[(offset & 0xf) >> 2] = value; |
1853 | c3d2689d | balrog | return;
|
1854 | c3d2689d | balrog | |
1855 | c3d2689d | balrog | case 0x50: /* GATE_INH_CTRL_0 */ |
1856 | c3d2689d | balrog | s->gate_inh_ctrl[0] = value;
|
1857 | c3d2689d | balrog | return;
|
1858 | c3d2689d | balrog | |
1859 | c3d2689d | balrog | case 0x60: /* VOLTAGE_CTRL_0 */ |
1860 | c3d2689d | balrog | s->voltage_ctrl[0] = value;
|
1861 | c3d2689d | balrog | return;
|
1862 | c3d2689d | balrog | |
1863 | c3d2689d | balrog | case 0x70: /* TEST_DBG_CTRL_0 */ |
1864 | c3d2689d | balrog | s->test_dbg_ctrl[0] = value;
|
1865 | c3d2689d | balrog | return;
|
1866 | c3d2689d | balrog | |
1867 | c3d2689d | balrog | case 0x80: /* MOD_CONF_CTRL_0 */ |
1868 | c3d2689d | balrog | diff = s->mod_conf_ctrl[0] ^ value;
|
1869 | c3d2689d | balrog | s->mod_conf_ctrl[0] = value;
|
1870 | c3d2689d | balrog | omap_pin_modconf1_update(s, diff, value); |
1871 | c3d2689d | balrog | return;
|
1872 | c3d2689d | balrog | |
1873 | c3d2689d | balrog | default:
|
1874 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1875 | c3d2689d | balrog | } |
1876 | c3d2689d | balrog | } |
1877 | c3d2689d | balrog | |
1878 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_pin_cfg_readfn[] = {
|
1879 | c3d2689d | balrog | omap_badwidth_read32, |
1880 | c3d2689d | balrog | omap_badwidth_read32, |
1881 | c3d2689d | balrog | omap_pin_cfg_read, |
1882 | c3d2689d | balrog | }; |
1883 | c3d2689d | balrog | |
1884 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_pin_cfg_writefn[] = {
|
1885 | c3d2689d | balrog | omap_badwidth_write32, |
1886 | c3d2689d | balrog | omap_badwidth_write32, |
1887 | c3d2689d | balrog | omap_pin_cfg_write, |
1888 | c3d2689d | balrog | }; |
1889 | c3d2689d | balrog | |
1890 | c3d2689d | balrog | static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu) |
1891 | c3d2689d | balrog | { |
1892 | c3d2689d | balrog | /* Start in Compatibility Mode. */
|
1893 | c3d2689d | balrog | mpu->compat1509 = 1;
|
1894 | c3d2689d | balrog | omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0); |
1895 | c3d2689d | balrog | omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0); |
1896 | c3d2689d | balrog | omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0); |
1897 | c3d2689d | balrog | memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl)); |
1898 | c3d2689d | balrog | memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl)); |
1899 | c3d2689d | balrog | memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl)); |
1900 | c3d2689d | balrog | memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl)); |
1901 | c3d2689d | balrog | memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl)); |
1902 | c3d2689d | balrog | memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl)); |
1903 | c3d2689d | balrog | memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl)); |
1904 | c3d2689d | balrog | } |
1905 | c3d2689d | balrog | |
1906 | c3d2689d | balrog | static void omap_pin_cfg_init(target_phys_addr_t base, |
1907 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
1908 | c3d2689d | balrog | { |
1909 | c3d2689d | balrog | int iomemtype = cpu_register_io_memory(0, omap_pin_cfg_readfn, |
1910 | c3d2689d | balrog | omap_pin_cfg_writefn, mpu); |
1911 | c3d2689d | balrog | |
1912 | c3d2689d | balrog | mpu->pin_cfg_base = base; |
1913 | c3d2689d | balrog | cpu_register_physical_memory(mpu->pin_cfg_base, 0x800, iomemtype);
|
1914 | c3d2689d | balrog | omap_pin_cfg_reset(mpu); |
1915 | c3d2689d | balrog | } |
1916 | c3d2689d | balrog | |
1917 | c3d2689d | balrog | /* Device Identification, Die Identification */
|
1918 | c3d2689d | balrog | static uint32_t omap_id_read(void *opaque, target_phys_addr_t addr) |
1919 | c3d2689d | balrog | { |
1920 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1921 | c3d2689d | balrog | |
1922 | c3d2689d | balrog | switch (addr) {
|
1923 | c3d2689d | balrog | case 0xfffe1800: /* DIE_ID_LSB */ |
1924 | c3d2689d | balrog | return 0xc9581f0e; |
1925 | c3d2689d | balrog | case 0xfffe1804: /* DIE_ID_MSB */ |
1926 | c3d2689d | balrog | return 0xa8858bfa; |
1927 | c3d2689d | balrog | |
1928 | c3d2689d | balrog | case 0xfffe2000: /* PRODUCT_ID_LSB */ |
1929 | c3d2689d | balrog | return 0x00aaaafc; |
1930 | c3d2689d | balrog | case 0xfffe2004: /* PRODUCT_ID_MSB */ |
1931 | c3d2689d | balrog | return 0xcafeb574; |
1932 | c3d2689d | balrog | |
1933 | c3d2689d | balrog | case 0xfffed400: /* JTAG_ID_LSB */ |
1934 | c3d2689d | balrog | switch (s->mpu_model) {
|
1935 | c3d2689d | balrog | case omap310:
|
1936 | c3d2689d | balrog | return 0x03310315; |
1937 | c3d2689d | balrog | case omap1510:
|
1938 | c3d2689d | balrog | return 0x03310115; |
1939 | c3d2689d | balrog | } |
1940 | c3d2689d | balrog | break;
|
1941 | c3d2689d | balrog | |
1942 | c3d2689d | balrog | case 0xfffed404: /* JTAG_ID_MSB */ |
1943 | c3d2689d | balrog | switch (s->mpu_model) {
|
1944 | c3d2689d | balrog | case omap310:
|
1945 | c3d2689d | balrog | return 0xfb57402f; |
1946 | c3d2689d | balrog | case omap1510:
|
1947 | c3d2689d | balrog | return 0xfb47002f; |
1948 | c3d2689d | balrog | } |
1949 | c3d2689d | balrog | break;
|
1950 | c3d2689d | balrog | } |
1951 | c3d2689d | balrog | |
1952 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1953 | c3d2689d | balrog | return 0; |
1954 | c3d2689d | balrog | } |
1955 | c3d2689d | balrog | |
1956 | c3d2689d | balrog | static void omap_id_write(void *opaque, target_phys_addr_t addr, |
1957 | c3d2689d | balrog | uint32_t value) |
1958 | c3d2689d | balrog | { |
1959 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
1960 | c3d2689d | balrog | } |
1961 | c3d2689d | balrog | |
1962 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_id_readfn[] = {
|
1963 | c3d2689d | balrog | omap_badwidth_read32, |
1964 | c3d2689d | balrog | omap_badwidth_read32, |
1965 | c3d2689d | balrog | omap_id_read, |
1966 | c3d2689d | balrog | }; |
1967 | c3d2689d | balrog | |
1968 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_id_writefn[] = {
|
1969 | c3d2689d | balrog | omap_badwidth_write32, |
1970 | c3d2689d | balrog | omap_badwidth_write32, |
1971 | c3d2689d | balrog | omap_id_write, |
1972 | c3d2689d | balrog | }; |
1973 | c3d2689d | balrog | |
1974 | c3d2689d | balrog | static void omap_id_init(struct omap_mpu_state_s *mpu) |
1975 | c3d2689d | balrog | { |
1976 | c3d2689d | balrog | int iomemtype = cpu_register_io_memory(0, omap_id_readfn, |
1977 | c3d2689d | balrog | omap_id_writefn, mpu); |
1978 | c3d2689d | balrog | cpu_register_physical_memory(0xfffe1800, 0x800, iomemtype); |
1979 | c3d2689d | balrog | cpu_register_physical_memory(0xfffed400, 0x100, iomemtype); |
1980 | c3d2689d | balrog | if (!cpu_is_omap15xx(mpu))
|
1981 | c3d2689d | balrog | cpu_register_physical_memory(0xfffe2000, 0x800, iomemtype); |
1982 | c3d2689d | balrog | } |
1983 | c3d2689d | balrog | |
1984 | c3d2689d | balrog | /* MPUI Control (Dummy) */
|
1985 | c3d2689d | balrog | static uint32_t omap_mpui_read(void *opaque, target_phys_addr_t addr) |
1986 | c3d2689d | balrog | { |
1987 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
1988 | c3d2689d | balrog | int offset = addr - s->mpui_base;
|
1989 | c3d2689d | balrog | |
1990 | c3d2689d | balrog | switch (offset) {
|
1991 | c3d2689d | balrog | case 0x00: /* CTRL */ |
1992 | c3d2689d | balrog | return s->mpui_ctrl;
|
1993 | c3d2689d | balrog | case 0x04: /* DEBUG_ADDR */ |
1994 | c3d2689d | balrog | return 0x01ffffff; |
1995 | c3d2689d | balrog | case 0x08: /* DEBUG_DATA */ |
1996 | c3d2689d | balrog | return 0xffffffff; |
1997 | c3d2689d | balrog | case 0x0c: /* DEBUG_FLAG */ |
1998 | c3d2689d | balrog | return 0x00000800; |
1999 | c3d2689d | balrog | case 0x10: /* STATUS */ |
2000 | c3d2689d | balrog | return 0x00000000; |
2001 | c3d2689d | balrog | |
2002 | c3d2689d | balrog | /* Not in OMAP310 */
|
2003 | c3d2689d | balrog | case 0x14: /* DSP_STATUS */ |
2004 | c3d2689d | balrog | case 0x18: /* DSP_BOOT_CONFIG */ |
2005 | c3d2689d | balrog | return 0x00000000; |
2006 | c3d2689d | balrog | case 0x1c: /* DSP_MPUI_CONFIG */ |
2007 | c3d2689d | balrog | return 0x0000ffff; |
2008 | c3d2689d | balrog | } |
2009 | c3d2689d | balrog | |
2010 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2011 | c3d2689d | balrog | return 0; |
2012 | c3d2689d | balrog | } |
2013 | c3d2689d | balrog | |
2014 | c3d2689d | balrog | static void omap_mpui_write(void *opaque, target_phys_addr_t addr, |
2015 | c3d2689d | balrog | uint32_t value) |
2016 | c3d2689d | balrog | { |
2017 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2018 | c3d2689d | balrog | int offset = addr - s->mpui_base;
|
2019 | c3d2689d | balrog | |
2020 | c3d2689d | balrog | switch (offset) {
|
2021 | c3d2689d | balrog | case 0x00: /* CTRL */ |
2022 | c3d2689d | balrog | s->mpui_ctrl = value & 0x007fffff;
|
2023 | c3d2689d | balrog | break;
|
2024 | c3d2689d | balrog | |
2025 | c3d2689d | balrog | case 0x04: /* DEBUG_ADDR */ |
2026 | c3d2689d | balrog | case 0x08: /* DEBUG_DATA */ |
2027 | c3d2689d | balrog | case 0x0c: /* DEBUG_FLAG */ |
2028 | c3d2689d | balrog | case 0x10: /* STATUS */ |
2029 | c3d2689d | balrog | /* Not in OMAP310 */
|
2030 | c3d2689d | balrog | case 0x14: /* DSP_STATUS */ |
2031 | c3d2689d | balrog | OMAP_RO_REG(addr); |
2032 | c3d2689d | balrog | case 0x18: /* DSP_BOOT_CONFIG */ |
2033 | c3d2689d | balrog | case 0x1c: /* DSP_MPUI_CONFIG */ |
2034 | c3d2689d | balrog | break;
|
2035 | c3d2689d | balrog | |
2036 | c3d2689d | balrog | default:
|
2037 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2038 | c3d2689d | balrog | } |
2039 | c3d2689d | balrog | } |
2040 | c3d2689d | balrog | |
2041 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_mpui_readfn[] = {
|
2042 | c3d2689d | balrog | omap_badwidth_read32, |
2043 | c3d2689d | balrog | omap_badwidth_read32, |
2044 | c3d2689d | balrog | omap_mpui_read, |
2045 | c3d2689d | balrog | }; |
2046 | c3d2689d | balrog | |
2047 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_mpui_writefn[] = {
|
2048 | c3d2689d | balrog | omap_badwidth_write32, |
2049 | c3d2689d | balrog | omap_badwidth_write32, |
2050 | c3d2689d | balrog | omap_mpui_write, |
2051 | c3d2689d | balrog | }; |
2052 | c3d2689d | balrog | |
2053 | c3d2689d | balrog | static void omap_mpui_reset(struct omap_mpu_state_s *s) |
2054 | c3d2689d | balrog | { |
2055 | c3d2689d | balrog | s->mpui_ctrl = 0x0003ff1b;
|
2056 | c3d2689d | balrog | } |
2057 | c3d2689d | balrog | |
2058 | c3d2689d | balrog | static void omap_mpui_init(target_phys_addr_t base, |
2059 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
2060 | c3d2689d | balrog | { |
2061 | c3d2689d | balrog | int iomemtype = cpu_register_io_memory(0, omap_mpui_readfn, |
2062 | c3d2689d | balrog | omap_mpui_writefn, mpu); |
2063 | c3d2689d | balrog | |
2064 | c3d2689d | balrog | mpu->mpui_base = base; |
2065 | c3d2689d | balrog | cpu_register_physical_memory(mpu->mpui_base, 0x100, iomemtype);
|
2066 | c3d2689d | balrog | |
2067 | c3d2689d | balrog | omap_mpui_reset(mpu); |
2068 | c3d2689d | balrog | } |
2069 | c3d2689d | balrog | |
2070 | c3d2689d | balrog | /* TIPB Bridges */
|
2071 | c3d2689d | balrog | struct omap_tipb_bridge_s {
|
2072 | c3d2689d | balrog | target_phys_addr_t base; |
2073 | c3d2689d | balrog | qemu_irq abort; |
2074 | c3d2689d | balrog | |
2075 | c3d2689d | balrog | int width_intr;
|
2076 | c3d2689d | balrog | uint16_t control; |
2077 | c3d2689d | balrog | uint16_t alloc; |
2078 | c3d2689d | balrog | uint16_t buffer; |
2079 | c3d2689d | balrog | uint16_t enh_control; |
2080 | c3d2689d | balrog | }; |
2081 | c3d2689d | balrog | |
2082 | c3d2689d | balrog | static uint32_t omap_tipb_bridge_read(void *opaque, target_phys_addr_t addr) |
2083 | c3d2689d | balrog | { |
2084 | c3d2689d | balrog | struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque; |
2085 | c3d2689d | balrog | int offset = addr - s->base;
|
2086 | c3d2689d | balrog | |
2087 | c3d2689d | balrog | switch (offset) {
|
2088 | c3d2689d | balrog | case 0x00: /* TIPB_CNTL */ |
2089 | c3d2689d | balrog | return s->control;
|
2090 | c3d2689d | balrog | case 0x04: /* TIPB_BUS_ALLOC */ |
2091 | c3d2689d | balrog | return s->alloc;
|
2092 | c3d2689d | balrog | case 0x08: /* MPU_TIPB_CNTL */ |
2093 | c3d2689d | balrog | return s->buffer;
|
2094 | c3d2689d | balrog | case 0x0c: /* ENHANCED_TIPB_CNTL */ |
2095 | c3d2689d | balrog | return s->enh_control;
|
2096 | c3d2689d | balrog | case 0x10: /* ADDRESS_DBG */ |
2097 | c3d2689d | balrog | case 0x14: /* DATA_DEBUG_LOW */ |
2098 | c3d2689d | balrog | case 0x18: /* DATA_DEBUG_HIGH */ |
2099 | c3d2689d | balrog | return 0xffff; |
2100 | c3d2689d | balrog | case 0x1c: /* DEBUG_CNTR_SIG */ |
2101 | c3d2689d | balrog | return 0x00f8; |
2102 | c3d2689d | balrog | } |
2103 | c3d2689d | balrog | |
2104 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2105 | c3d2689d | balrog | return 0; |
2106 | c3d2689d | balrog | } |
2107 | c3d2689d | balrog | |
2108 | c3d2689d | balrog | static void omap_tipb_bridge_write(void *opaque, target_phys_addr_t addr, |
2109 | c3d2689d | balrog | uint32_t value) |
2110 | c3d2689d | balrog | { |
2111 | c3d2689d | balrog | struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque; |
2112 | c3d2689d | balrog | int offset = addr - s->base;
|
2113 | c3d2689d | balrog | |
2114 | c3d2689d | balrog | switch (offset) {
|
2115 | c3d2689d | balrog | case 0x00: /* TIPB_CNTL */ |
2116 | c3d2689d | balrog | s->control = value & 0xffff;
|
2117 | c3d2689d | balrog | break;
|
2118 | c3d2689d | balrog | |
2119 | c3d2689d | balrog | case 0x04: /* TIPB_BUS_ALLOC */ |
2120 | c3d2689d | balrog | s->alloc = value & 0x003f;
|
2121 | c3d2689d | balrog | break;
|
2122 | c3d2689d | balrog | |
2123 | c3d2689d | balrog | case 0x08: /* MPU_TIPB_CNTL */ |
2124 | c3d2689d | balrog | s->buffer = value & 0x0003;
|
2125 | c3d2689d | balrog | break;
|
2126 | c3d2689d | balrog | |
2127 | c3d2689d | balrog | case 0x0c: /* ENHANCED_TIPB_CNTL */ |
2128 | c3d2689d | balrog | s->width_intr = !(value & 2);
|
2129 | c3d2689d | balrog | s->enh_control = value & 0x000f;
|
2130 | c3d2689d | balrog | break;
|
2131 | c3d2689d | balrog | |
2132 | c3d2689d | balrog | case 0x10: /* ADDRESS_DBG */ |
2133 | c3d2689d | balrog | case 0x14: /* DATA_DEBUG_LOW */ |
2134 | c3d2689d | balrog | case 0x18: /* DATA_DEBUG_HIGH */ |
2135 | c3d2689d | balrog | case 0x1c: /* DEBUG_CNTR_SIG */ |
2136 | c3d2689d | balrog | OMAP_RO_REG(addr); |
2137 | c3d2689d | balrog | break;
|
2138 | c3d2689d | balrog | |
2139 | c3d2689d | balrog | default:
|
2140 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2141 | c3d2689d | balrog | } |
2142 | c3d2689d | balrog | } |
2143 | c3d2689d | balrog | |
2144 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_tipb_bridge_readfn[] = {
|
2145 | c3d2689d | balrog | omap_badwidth_read16, |
2146 | c3d2689d | balrog | omap_tipb_bridge_read, |
2147 | c3d2689d | balrog | omap_tipb_bridge_read, |
2148 | c3d2689d | balrog | }; |
2149 | c3d2689d | balrog | |
2150 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_tipb_bridge_writefn[] = {
|
2151 | c3d2689d | balrog | omap_badwidth_write16, |
2152 | c3d2689d | balrog | omap_tipb_bridge_write, |
2153 | c3d2689d | balrog | omap_tipb_bridge_write, |
2154 | c3d2689d | balrog | }; |
2155 | c3d2689d | balrog | |
2156 | c3d2689d | balrog | static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s) |
2157 | c3d2689d | balrog | { |
2158 | c3d2689d | balrog | s->control = 0xffff;
|
2159 | c3d2689d | balrog | s->alloc = 0x0009;
|
2160 | c3d2689d | balrog | s->buffer = 0x0000;
|
2161 | c3d2689d | balrog | s->enh_control = 0x000f;
|
2162 | c3d2689d | balrog | } |
2163 | c3d2689d | balrog | |
2164 | c3d2689d | balrog | struct omap_tipb_bridge_s *omap_tipb_bridge_init(target_phys_addr_t base,
|
2165 | c3d2689d | balrog | qemu_irq abort_irq, omap_clk clk) |
2166 | c3d2689d | balrog | { |
2167 | c3d2689d | balrog | int iomemtype;
|
2168 | c3d2689d | balrog | struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) |
2169 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_tipb_bridge_s)); |
2170 | c3d2689d | balrog | |
2171 | c3d2689d | balrog | s->abort = abort_irq; |
2172 | c3d2689d | balrog | s->base = base; |
2173 | c3d2689d | balrog | omap_tipb_bridge_reset(s); |
2174 | c3d2689d | balrog | |
2175 | c3d2689d | balrog | iomemtype = cpu_register_io_memory(0, omap_tipb_bridge_readfn,
|
2176 | c3d2689d | balrog | omap_tipb_bridge_writefn, s); |
2177 | c3d2689d | balrog | cpu_register_physical_memory(s->base, 0x100, iomemtype);
|
2178 | c3d2689d | balrog | |
2179 | c3d2689d | balrog | return s;
|
2180 | c3d2689d | balrog | } |
2181 | c3d2689d | balrog | |
2182 | c3d2689d | balrog | /* Dummy Traffic Controller's Memory Interface */
|
2183 | c3d2689d | balrog | static uint32_t omap_tcmi_read(void *opaque, target_phys_addr_t addr) |
2184 | c3d2689d | balrog | { |
2185 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2186 | c3d2689d | balrog | int offset = addr - s->tcmi_base;
|
2187 | c3d2689d | balrog | uint32_t ret; |
2188 | c3d2689d | balrog | |
2189 | c3d2689d | balrog | switch (offset) {
|
2190 | c3d2689d | balrog | case 0xfffecc00: /* IMIF_PRIO */ |
2191 | c3d2689d | balrog | case 0xfffecc04: /* EMIFS_PRIO */ |
2192 | c3d2689d | balrog | case 0xfffecc08: /* EMIFF_PRIO */ |
2193 | c3d2689d | balrog | case 0xfffecc0c: /* EMIFS_CONFIG */ |
2194 | c3d2689d | balrog | case 0xfffecc10: /* EMIFS_CS0_CONFIG */ |
2195 | c3d2689d | balrog | case 0xfffecc14: /* EMIFS_CS1_CONFIG */ |
2196 | c3d2689d | balrog | case 0xfffecc18: /* EMIFS_CS2_CONFIG */ |
2197 | c3d2689d | balrog | case 0xfffecc1c: /* EMIFS_CS3_CONFIG */ |
2198 | c3d2689d | balrog | case 0xfffecc24: /* EMIFF_MRS */ |
2199 | c3d2689d | balrog | case 0xfffecc28: /* TIMEOUT1 */ |
2200 | c3d2689d | balrog | case 0xfffecc2c: /* TIMEOUT2 */ |
2201 | c3d2689d | balrog | case 0xfffecc30: /* TIMEOUT3 */ |
2202 | c3d2689d | balrog | case 0xfffecc3c: /* EMIFF_SDRAM_CONFIG_2 */ |
2203 | c3d2689d | balrog | case 0xfffecc40: /* EMIFS_CFG_DYN_WAIT */ |
2204 | c3d2689d | balrog | return s->tcmi_regs[offset >> 2]; |
2205 | c3d2689d | balrog | |
2206 | c3d2689d | balrog | case 0xfffecc20: /* EMIFF_SDRAM_CONFIG */ |
2207 | c3d2689d | balrog | ret = s->tcmi_regs[offset >> 2];
|
2208 | c3d2689d | balrog | s->tcmi_regs[offset >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */ |
2209 | c3d2689d | balrog | /* XXX: We can try using the VGA_DIRTY flag for this */
|
2210 | c3d2689d | balrog | return ret;
|
2211 | c3d2689d | balrog | } |
2212 | c3d2689d | balrog | |
2213 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2214 | c3d2689d | balrog | return 0; |
2215 | c3d2689d | balrog | } |
2216 | c3d2689d | balrog | |
2217 | c3d2689d | balrog | static void omap_tcmi_write(void *opaque, target_phys_addr_t addr, |
2218 | c3d2689d | balrog | uint32_t value) |
2219 | c3d2689d | balrog | { |
2220 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2221 | c3d2689d | balrog | int offset = addr - s->tcmi_base;
|
2222 | c3d2689d | balrog | |
2223 | c3d2689d | balrog | switch (offset) {
|
2224 | c3d2689d | balrog | case 0xfffecc00: /* IMIF_PRIO */ |
2225 | c3d2689d | balrog | case 0xfffecc04: /* EMIFS_PRIO */ |
2226 | c3d2689d | balrog | case 0xfffecc08: /* EMIFF_PRIO */ |
2227 | c3d2689d | balrog | case 0xfffecc10: /* EMIFS_CS0_CONFIG */ |
2228 | c3d2689d | balrog | case 0xfffecc14: /* EMIFS_CS1_CONFIG */ |
2229 | c3d2689d | balrog | case 0xfffecc18: /* EMIFS_CS2_CONFIG */ |
2230 | c3d2689d | balrog | case 0xfffecc1c: /* EMIFS_CS3_CONFIG */ |
2231 | c3d2689d | balrog | case 0xfffecc20: /* EMIFF_SDRAM_CONFIG */ |
2232 | c3d2689d | balrog | case 0xfffecc24: /* EMIFF_MRS */ |
2233 | c3d2689d | balrog | case 0xfffecc28: /* TIMEOUT1 */ |
2234 | c3d2689d | balrog | case 0xfffecc2c: /* TIMEOUT2 */ |
2235 | c3d2689d | balrog | case 0xfffecc30: /* TIMEOUT3 */ |
2236 | c3d2689d | balrog | case 0xfffecc3c: /* EMIFF_SDRAM_CONFIG_2 */ |
2237 | c3d2689d | balrog | case 0xfffecc40: /* EMIFS_CFG_DYN_WAIT */ |
2238 | c3d2689d | balrog | s->tcmi_regs[offset >> 2] = value;
|
2239 | c3d2689d | balrog | break;
|
2240 | c3d2689d | balrog | case 0xfffecc0c: /* EMIFS_CONFIG */ |
2241 | c3d2689d | balrog | s->tcmi_regs[offset >> 2] = (value & 0xf) | (1 << 4); |
2242 | c3d2689d | balrog | break;
|
2243 | c3d2689d | balrog | |
2244 | c3d2689d | balrog | default:
|
2245 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2246 | c3d2689d | balrog | } |
2247 | c3d2689d | balrog | } |
2248 | c3d2689d | balrog | |
2249 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_tcmi_readfn[] = {
|
2250 | c3d2689d | balrog | omap_badwidth_read32, |
2251 | c3d2689d | balrog | omap_badwidth_read32, |
2252 | c3d2689d | balrog | omap_tcmi_read, |
2253 | c3d2689d | balrog | }; |
2254 | c3d2689d | balrog | |
2255 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_tcmi_writefn[] = {
|
2256 | c3d2689d | balrog | omap_badwidth_write32, |
2257 | c3d2689d | balrog | omap_badwidth_write32, |
2258 | c3d2689d | balrog | omap_tcmi_write, |
2259 | c3d2689d | balrog | }; |
2260 | c3d2689d | balrog | |
2261 | c3d2689d | balrog | static void omap_tcmi_reset(struct omap_mpu_state_s *mpu) |
2262 | c3d2689d | balrog | { |
2263 | c3d2689d | balrog | mpu->tcmi_regs[0x00 >> 2] = 0x00000000; |
2264 | c3d2689d | balrog | mpu->tcmi_regs[0x04 >> 2] = 0x00000000; |
2265 | c3d2689d | balrog | mpu->tcmi_regs[0x08 >> 2] = 0x00000000; |
2266 | c3d2689d | balrog | mpu->tcmi_regs[0x0c >> 2] = 0x00000010; |
2267 | c3d2689d | balrog | mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb; |
2268 | c3d2689d | balrog | mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb; |
2269 | c3d2689d | balrog | mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb; |
2270 | c3d2689d | balrog | mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb; |
2271 | c3d2689d | balrog | mpu->tcmi_regs[0x20 >> 2] = 0x00618800; |
2272 | c3d2689d | balrog | mpu->tcmi_regs[0x24 >> 2] = 0x00000037; |
2273 | c3d2689d | balrog | mpu->tcmi_regs[0x28 >> 2] = 0x00000000; |
2274 | c3d2689d | balrog | mpu->tcmi_regs[0x2c >> 2] = 0x00000000; |
2275 | c3d2689d | balrog | mpu->tcmi_regs[0x30 >> 2] = 0x00000000; |
2276 | c3d2689d | balrog | mpu->tcmi_regs[0x3c >> 2] = 0x00000003; |
2277 | c3d2689d | balrog | mpu->tcmi_regs[0x40 >> 2] = 0x00000000; |
2278 | c3d2689d | balrog | } |
2279 | c3d2689d | balrog | |
2280 | c3d2689d | balrog | static void omap_tcmi_init(target_phys_addr_t base, |
2281 | c3d2689d | balrog | struct omap_mpu_state_s *mpu)
|
2282 | c3d2689d | balrog | { |
2283 | c3d2689d | balrog | int iomemtype = cpu_register_io_memory(0, omap_tcmi_readfn, |
2284 | c3d2689d | balrog | omap_tcmi_writefn, mpu); |
2285 | c3d2689d | balrog | |
2286 | c3d2689d | balrog | mpu->tcmi_base = base; |
2287 | c3d2689d | balrog | cpu_register_physical_memory(mpu->tcmi_base, 0x100, iomemtype);
|
2288 | c3d2689d | balrog | omap_tcmi_reset(mpu); |
2289 | c3d2689d | balrog | } |
2290 | c3d2689d | balrog | |
2291 | c3d2689d | balrog | /* Digital phase-locked loops control */
|
2292 | c3d2689d | balrog | static uint32_t omap_dpll_read(void *opaque, target_phys_addr_t addr) |
2293 | c3d2689d | balrog | { |
2294 | c3d2689d | balrog | struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque; |
2295 | c3d2689d | balrog | int offset = addr - s->base;
|
2296 | c3d2689d | balrog | |
2297 | c3d2689d | balrog | if (offset == 0x00) /* CTL_REG */ |
2298 | c3d2689d | balrog | return s->mode;
|
2299 | c3d2689d | balrog | |
2300 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2301 | c3d2689d | balrog | return 0; |
2302 | c3d2689d | balrog | } |
2303 | c3d2689d | balrog | |
2304 | c3d2689d | balrog | static void omap_dpll_write(void *opaque, target_phys_addr_t addr, |
2305 | c3d2689d | balrog | uint32_t value) |
2306 | c3d2689d | balrog | { |
2307 | c3d2689d | balrog | struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque; |
2308 | c3d2689d | balrog | uint16_t diff; |
2309 | c3d2689d | balrog | int offset = addr - s->base;
|
2310 | c3d2689d | balrog | static const int bypass_div[4] = { 1, 2, 4, 4 }; |
2311 | c3d2689d | balrog | int div, mult;
|
2312 | c3d2689d | balrog | |
2313 | c3d2689d | balrog | if (offset == 0x00) { /* CTL_REG */ |
2314 | c3d2689d | balrog | /* See omap_ulpd_pm_write() too */
|
2315 | c3d2689d | balrog | diff = s->mode & value; |
2316 | c3d2689d | balrog | s->mode = value & 0x2fff;
|
2317 | c3d2689d | balrog | if (diff & (0x3ff << 2)) { |
2318 | c3d2689d | balrog | if (value & (1 << 4)) { /* PLL_ENABLE */ |
2319 | c3d2689d | balrog | div = ((value >> 5) & 3) + 1; /* PLL_DIV */ |
2320 | c3d2689d | balrog | mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */ |
2321 | c3d2689d | balrog | } else {
|
2322 | c3d2689d | balrog | div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */ |
2323 | c3d2689d | balrog | mult = 1;
|
2324 | c3d2689d | balrog | } |
2325 | c3d2689d | balrog | omap_clk_setrate(s->dpll, div, mult); |
2326 | c3d2689d | balrog | } |
2327 | c3d2689d | balrog | |
2328 | c3d2689d | balrog | /* Enter the desired mode. */
|
2329 | c3d2689d | balrog | s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1); |
2330 | c3d2689d | balrog | |
2331 | c3d2689d | balrog | /* Act as if the lock is restored. */
|
2332 | c3d2689d | balrog | s->mode |= 2;
|
2333 | c3d2689d | balrog | } else {
|
2334 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2335 | c3d2689d | balrog | } |
2336 | c3d2689d | balrog | } |
2337 | c3d2689d | balrog | |
2338 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_dpll_readfn[] = {
|
2339 | c3d2689d | balrog | omap_badwidth_read16, |
2340 | c3d2689d | balrog | omap_dpll_read, |
2341 | c3d2689d | balrog | omap_badwidth_read16, |
2342 | c3d2689d | balrog | }; |
2343 | c3d2689d | balrog | |
2344 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_dpll_writefn[] = {
|
2345 | c3d2689d | balrog | omap_badwidth_write16, |
2346 | c3d2689d | balrog | omap_dpll_write, |
2347 | c3d2689d | balrog | omap_badwidth_write16, |
2348 | c3d2689d | balrog | }; |
2349 | c3d2689d | balrog | |
2350 | c3d2689d | balrog | static void omap_dpll_reset(struct dpll_ctl_s *s) |
2351 | c3d2689d | balrog | { |
2352 | c3d2689d | balrog | s->mode = 0x2002;
|
2353 | c3d2689d | balrog | omap_clk_setrate(s->dpll, 1, 1); |
2354 | c3d2689d | balrog | } |
2355 | c3d2689d | balrog | |
2356 | c3d2689d | balrog | static void omap_dpll_init(struct dpll_ctl_s *s, target_phys_addr_t base, |
2357 | c3d2689d | balrog | omap_clk clk) |
2358 | c3d2689d | balrog | { |
2359 | c3d2689d | balrog | int iomemtype = cpu_register_io_memory(0, omap_dpll_readfn, |
2360 | c3d2689d | balrog | omap_dpll_writefn, s); |
2361 | c3d2689d | balrog | |
2362 | c3d2689d | balrog | s->base = base; |
2363 | c3d2689d | balrog | s->dpll = clk; |
2364 | c3d2689d | balrog | omap_dpll_reset(s); |
2365 | c3d2689d | balrog | |
2366 | c3d2689d | balrog | cpu_register_physical_memory(s->base, 0x100, iomemtype);
|
2367 | c3d2689d | balrog | } |
2368 | c3d2689d | balrog | |
2369 | c3d2689d | balrog | /* UARTs */
|
2370 | c3d2689d | balrog | struct omap_uart_s {
|
2371 | c3d2689d | balrog | SerialState *serial; /* TODO */
|
2372 | c3d2689d | balrog | }; |
2373 | c3d2689d | balrog | |
2374 | c3d2689d | balrog | static void omap_uart_reset(struct omap_uart_s *s) |
2375 | c3d2689d | balrog | { |
2376 | c3d2689d | balrog | } |
2377 | c3d2689d | balrog | |
2378 | c3d2689d | balrog | struct omap_uart_s *omap_uart_init(target_phys_addr_t base,
|
2379 | c3d2689d | balrog | qemu_irq irq, omap_clk clk, CharDriverState *chr) |
2380 | c3d2689d | balrog | { |
2381 | c3d2689d | balrog | struct omap_uart_s *s = (struct omap_uart_s *) |
2382 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_uart_s)); |
2383 | c3d2689d | balrog | if (chr)
|
2384 | c3d2689d | balrog | s->serial = serial_mm_init(base, 2, irq, chr, 1); |
2385 | c3d2689d | balrog | return s;
|
2386 | c3d2689d | balrog | } |
2387 | c3d2689d | balrog | |
2388 | c3d2689d | balrog | /* MPU Clock/Reset/Power Mode Control */
|
2389 | c3d2689d | balrog | static uint32_t omap_clkm_read(void *opaque, target_phys_addr_t addr) |
2390 | c3d2689d | balrog | { |
2391 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2392 | c3d2689d | balrog | int offset = addr - s->clkm.mpu_base;
|
2393 | c3d2689d | balrog | |
2394 | c3d2689d | balrog | switch (offset) {
|
2395 | c3d2689d | balrog | case 0x00: /* ARM_CKCTL */ |
2396 | c3d2689d | balrog | return s->clkm.arm_ckctl;
|
2397 | c3d2689d | balrog | |
2398 | c3d2689d | balrog | case 0x04: /* ARM_IDLECT1 */ |
2399 | c3d2689d | balrog | return s->clkm.arm_idlect1;
|
2400 | c3d2689d | balrog | |
2401 | c3d2689d | balrog | case 0x08: /* ARM_IDLECT2 */ |
2402 | c3d2689d | balrog | return s->clkm.arm_idlect2;
|
2403 | c3d2689d | balrog | |
2404 | c3d2689d | balrog | case 0x0c: /* ARM_EWUPCT */ |
2405 | c3d2689d | balrog | return s->clkm.arm_ewupct;
|
2406 | c3d2689d | balrog | |
2407 | c3d2689d | balrog | case 0x10: /* ARM_RSTCT1 */ |
2408 | c3d2689d | balrog | return s->clkm.arm_rstct1;
|
2409 | c3d2689d | balrog | |
2410 | c3d2689d | balrog | case 0x14: /* ARM_RSTCT2 */ |
2411 | c3d2689d | balrog | return s->clkm.arm_rstct2;
|
2412 | c3d2689d | balrog | |
2413 | c3d2689d | balrog | case 0x18: /* ARM_SYSST */ |
2414 | c3d2689d | balrog | return (s->clkm.clocking_scheme < 11) | s->clkm.cold_start; |
2415 | c3d2689d | balrog | |
2416 | c3d2689d | balrog | case 0x1c: /* ARM_CKOUT1 */ |
2417 | c3d2689d | balrog | return s->clkm.arm_ckout1;
|
2418 | c3d2689d | balrog | |
2419 | c3d2689d | balrog | case 0x20: /* ARM_CKOUT2 */ |
2420 | c3d2689d | balrog | break;
|
2421 | c3d2689d | balrog | } |
2422 | c3d2689d | balrog | |
2423 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2424 | c3d2689d | balrog | return 0; |
2425 | c3d2689d | balrog | } |
2426 | c3d2689d | balrog | |
2427 | c3d2689d | balrog | static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s, |
2428 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2429 | c3d2689d | balrog | { |
2430 | c3d2689d | balrog | omap_clk clk; |
2431 | c3d2689d | balrog | |
2432 | c3d2689d | balrog | if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */ |
2433 | c3d2689d | balrog | if (value & (1 << 14)) |
2434 | c3d2689d | balrog | /* Reserved */;
|
2435 | c3d2689d | balrog | else {
|
2436 | c3d2689d | balrog | clk = omap_findclk(s, "arminth_ck");
|
2437 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
|
2438 | c3d2689d | balrog | } |
2439 | c3d2689d | balrog | } |
2440 | c3d2689d | balrog | if (diff & (1 << 12)) { /* ARM_TIMXO */ |
2441 | c3d2689d | balrog | clk = omap_findclk(s, "armtim_ck");
|
2442 | c3d2689d | balrog | if (value & (1 << 12)) |
2443 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "clkin"));
|
2444 | c3d2689d | balrog | else
|
2445 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
|
2446 | c3d2689d | balrog | } |
2447 | c3d2689d | balrog | /* XXX: en_dspck */
|
2448 | c3d2689d | balrog | if (diff & (3 << 10)) { /* DSPMMUDIV */ |
2449 | c3d2689d | balrog | clk = omap_findclk(s, "dspmmu_ck");
|
2450 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1); |
2451 | c3d2689d | balrog | } |
2452 | c3d2689d | balrog | if (diff & (3 << 8)) { /* TCDIV */ |
2453 | c3d2689d | balrog | clk = omap_findclk(s, "tc_ck");
|
2454 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1); |
2455 | c3d2689d | balrog | } |
2456 | c3d2689d | balrog | if (diff & (3 << 6)) { /* DSPDIV */ |
2457 | c3d2689d | balrog | clk = omap_findclk(s, "dsp_ck");
|
2458 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1); |
2459 | c3d2689d | balrog | } |
2460 | c3d2689d | balrog | if (diff & (3 << 4)) { /* ARMDIV */ |
2461 | c3d2689d | balrog | clk = omap_findclk(s, "arm_ck");
|
2462 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1); |
2463 | c3d2689d | balrog | } |
2464 | c3d2689d | balrog | if (diff & (3 << 2)) { /* LCDDIV */ |
2465 | c3d2689d | balrog | clk = omap_findclk(s, "lcd_ck");
|
2466 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1); |
2467 | c3d2689d | balrog | } |
2468 | c3d2689d | balrog | if (diff & (3 << 0)) { /* PERDIV */ |
2469 | c3d2689d | balrog | clk = omap_findclk(s, "armper_ck");
|
2470 | c3d2689d | balrog | omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1); |
2471 | c3d2689d | balrog | } |
2472 | c3d2689d | balrog | } |
2473 | c3d2689d | balrog | |
2474 | c3d2689d | balrog | static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s, |
2475 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2476 | c3d2689d | balrog | { |
2477 | c3d2689d | balrog | omap_clk clk; |
2478 | c3d2689d | balrog | |
2479 | c3d2689d | balrog | if (value & (1 << 11)) /* SETARM_IDLE */ |
2480 | c3d2689d | balrog | cpu_interrupt(s->env, CPU_INTERRUPT_HALT); |
2481 | c3d2689d | balrog | if (!(value & (1 << 10))) /* WKUP_MODE */ |
2482 | c3d2689d | balrog | qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
|
2483 | c3d2689d | balrog | |
2484 | c3d2689d | balrog | #define SET_CANIDLE(clock, bit) \
|
2485 | c3d2689d | balrog | if (diff & (1 << bit)) { \ |
2486 | c3d2689d | balrog | clk = omap_findclk(s, clock); \ |
2487 | c3d2689d | balrog | omap_clk_canidle(clk, (value >> bit) & 1); \
|
2488 | c3d2689d | balrog | } |
2489 | c3d2689d | balrog | SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */ |
2490 | c3d2689d | balrog | SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */ |
2491 | c3d2689d | balrog | SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */ |
2492 | c3d2689d | balrog | SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */ |
2493 | c3d2689d | balrog | SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */ |
2494 | c3d2689d | balrog | SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */ |
2495 | c3d2689d | balrog | SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */ |
2496 | c3d2689d | balrog | SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */ |
2497 | c3d2689d | balrog | SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */ |
2498 | c3d2689d | balrog | SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */ |
2499 | c3d2689d | balrog | SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */ |
2500 | c3d2689d | balrog | SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */ |
2501 | c3d2689d | balrog | SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */ |
2502 | c3d2689d | balrog | SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */ |
2503 | c3d2689d | balrog | } |
2504 | c3d2689d | balrog | |
2505 | c3d2689d | balrog | static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s, |
2506 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2507 | c3d2689d | balrog | { |
2508 | c3d2689d | balrog | omap_clk clk; |
2509 | c3d2689d | balrog | |
2510 | c3d2689d | balrog | #define SET_ONOFF(clock, bit) \
|
2511 | c3d2689d | balrog | if (diff & (1 << bit)) { \ |
2512 | c3d2689d | balrog | clk = omap_findclk(s, clock); \ |
2513 | c3d2689d | balrog | omap_clk_onoff(clk, (value >> bit) & 1); \
|
2514 | c3d2689d | balrog | } |
2515 | c3d2689d | balrog | SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */ |
2516 | c3d2689d | balrog | SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */ |
2517 | c3d2689d | balrog | SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */ |
2518 | c3d2689d | balrog | SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */ |
2519 | c3d2689d | balrog | SET_ONOFF("lb_ck", 4) /* EN_LBCK */ |
2520 | c3d2689d | balrog | SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */ |
2521 | c3d2689d | balrog | SET_ONOFF("mpui_ck", 6) /* EN_APICK */ |
2522 | c3d2689d | balrog | SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */ |
2523 | c3d2689d | balrog | SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */ |
2524 | c3d2689d | balrog | SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */ |
2525 | c3d2689d | balrog | SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */ |
2526 | c3d2689d | balrog | } |
2527 | c3d2689d | balrog | |
2528 | c3d2689d | balrog | static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s, |
2529 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2530 | c3d2689d | balrog | { |
2531 | c3d2689d | balrog | omap_clk clk; |
2532 | c3d2689d | balrog | |
2533 | c3d2689d | balrog | if (diff & (3 << 4)) { /* TCLKOUT */ |
2534 | c3d2689d | balrog | clk = omap_findclk(s, "tclk_out");
|
2535 | c3d2689d | balrog | switch ((value >> 4) & 3) { |
2536 | c3d2689d | balrog | case 1: |
2537 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
|
2538 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2539 | c3d2689d | balrog | break;
|
2540 | c3d2689d | balrog | case 2: |
2541 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
|
2542 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2543 | c3d2689d | balrog | break;
|
2544 | c3d2689d | balrog | default:
|
2545 | c3d2689d | balrog | omap_clk_onoff(clk, 0);
|
2546 | c3d2689d | balrog | } |
2547 | c3d2689d | balrog | } |
2548 | c3d2689d | balrog | if (diff & (3 << 2)) { /* DCLKOUT */ |
2549 | c3d2689d | balrog | clk = omap_findclk(s, "dclk_out");
|
2550 | c3d2689d | balrog | switch ((value >> 2) & 3) { |
2551 | c3d2689d | balrog | case 0: |
2552 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
|
2553 | c3d2689d | balrog | break;
|
2554 | c3d2689d | balrog | case 1: |
2555 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
|
2556 | c3d2689d | balrog | break;
|
2557 | c3d2689d | balrog | case 2: |
2558 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
|
2559 | c3d2689d | balrog | break;
|
2560 | c3d2689d | balrog | case 3: |
2561 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
|
2562 | c3d2689d | balrog | break;
|
2563 | c3d2689d | balrog | } |
2564 | c3d2689d | balrog | } |
2565 | c3d2689d | balrog | if (diff & (3 << 0)) { /* ACLKOUT */ |
2566 | c3d2689d | balrog | clk = omap_findclk(s, "aclk_out");
|
2567 | c3d2689d | balrog | switch ((value >> 0) & 3) { |
2568 | c3d2689d | balrog | case 1: |
2569 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
|
2570 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2571 | c3d2689d | balrog | break;
|
2572 | c3d2689d | balrog | case 2: |
2573 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
|
2574 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2575 | c3d2689d | balrog | break;
|
2576 | c3d2689d | balrog | case 3: |
2577 | c3d2689d | balrog | omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
|
2578 | c3d2689d | balrog | omap_clk_onoff(clk, 1);
|
2579 | c3d2689d | balrog | break;
|
2580 | c3d2689d | balrog | default:
|
2581 | c3d2689d | balrog | omap_clk_onoff(clk, 0);
|
2582 | c3d2689d | balrog | } |
2583 | c3d2689d | balrog | } |
2584 | c3d2689d | balrog | } |
2585 | c3d2689d | balrog | |
2586 | c3d2689d | balrog | static void omap_clkm_write(void *opaque, target_phys_addr_t addr, |
2587 | c3d2689d | balrog | uint32_t value) |
2588 | c3d2689d | balrog | { |
2589 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2590 | c3d2689d | balrog | int offset = addr - s->clkm.mpu_base;
|
2591 | c3d2689d | balrog | uint16_t diff; |
2592 | c3d2689d | balrog | omap_clk clk; |
2593 | c3d2689d | balrog | static const char *clkschemename[8] = { |
2594 | c3d2689d | balrog | "fully synchronous", "fully asynchronous", "synchronous scalable", |
2595 | c3d2689d | balrog | "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4", |
2596 | c3d2689d | balrog | }; |
2597 | c3d2689d | balrog | |
2598 | c3d2689d | balrog | switch (offset) {
|
2599 | c3d2689d | balrog | case 0x00: /* ARM_CKCTL */ |
2600 | c3d2689d | balrog | diff = s->clkm.arm_ckctl ^ value; |
2601 | c3d2689d | balrog | s->clkm.arm_ckctl = value & 0x7fff;
|
2602 | c3d2689d | balrog | omap_clkm_ckctl_update(s, diff, value); |
2603 | c3d2689d | balrog | return;
|
2604 | c3d2689d | balrog | |
2605 | c3d2689d | balrog | case 0x04: /* ARM_IDLECT1 */ |
2606 | c3d2689d | balrog | diff = s->clkm.arm_idlect1 ^ value; |
2607 | c3d2689d | balrog | s->clkm.arm_idlect1 = value & 0x0fff;
|
2608 | c3d2689d | balrog | omap_clkm_idlect1_update(s, diff, value); |
2609 | c3d2689d | balrog | return;
|
2610 | c3d2689d | balrog | |
2611 | c3d2689d | balrog | case 0x08: /* ARM_IDLECT2 */ |
2612 | c3d2689d | balrog | diff = s->clkm.arm_idlect2 ^ value; |
2613 | c3d2689d | balrog | s->clkm.arm_idlect2 = value & 0x07ff;
|
2614 | c3d2689d | balrog | omap_clkm_idlect2_update(s, diff, value); |
2615 | c3d2689d | balrog | return;
|
2616 | c3d2689d | balrog | |
2617 | c3d2689d | balrog | case 0x0c: /* ARM_EWUPCT */ |
2618 | c3d2689d | balrog | diff = s->clkm.arm_ewupct ^ value; |
2619 | c3d2689d | balrog | s->clkm.arm_ewupct = value & 0x003f;
|
2620 | c3d2689d | balrog | return;
|
2621 | c3d2689d | balrog | |
2622 | c3d2689d | balrog | case 0x10: /* ARM_RSTCT1 */ |
2623 | c3d2689d | balrog | diff = s->clkm.arm_rstct1 ^ value; |
2624 | c3d2689d | balrog | s->clkm.arm_rstct1 = value & 0x0007;
|
2625 | c3d2689d | balrog | if (value & 9) { |
2626 | c3d2689d | balrog | qemu_system_reset_request(); |
2627 | c3d2689d | balrog | s->clkm.cold_start = 0xa;
|
2628 | c3d2689d | balrog | } |
2629 | c3d2689d | balrog | if (diff & ~value & 4) { /* DSP_RST */ |
2630 | c3d2689d | balrog | omap_mpui_reset(s); |
2631 | c3d2689d | balrog | omap_tipb_bridge_reset(s->private_tipb); |
2632 | c3d2689d | balrog | omap_tipb_bridge_reset(s->public_tipb); |
2633 | c3d2689d | balrog | } |
2634 | c3d2689d | balrog | if (diff & 2) { /* DSP_EN */ |
2635 | c3d2689d | balrog | clk = omap_findclk(s, "dsp_ck");
|
2636 | c3d2689d | balrog | omap_clk_canidle(clk, (~value >> 1) & 1); |
2637 | c3d2689d | balrog | } |
2638 | c3d2689d | balrog | return;
|
2639 | c3d2689d | balrog | |
2640 | c3d2689d | balrog | case 0x14: /* ARM_RSTCT2 */ |
2641 | c3d2689d | balrog | s->clkm.arm_rstct2 = value & 0x0001;
|
2642 | c3d2689d | balrog | return;
|
2643 | c3d2689d | balrog | |
2644 | c3d2689d | balrog | case 0x18: /* ARM_SYSST */ |
2645 | c3d2689d | balrog | if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) { |
2646 | c3d2689d | balrog | s->clkm.clocking_scheme = (value >> 11) & 7; |
2647 | c3d2689d | balrog | printf("%s: clocking scheme set to %s\n", __FUNCTION__,
|
2648 | c3d2689d | balrog | clkschemename[s->clkm.clocking_scheme]); |
2649 | c3d2689d | balrog | } |
2650 | c3d2689d | balrog | s->clkm.cold_start &= value & 0x3f;
|
2651 | c3d2689d | balrog | return;
|
2652 | c3d2689d | balrog | |
2653 | c3d2689d | balrog | case 0x1c: /* ARM_CKOUT1 */ |
2654 | c3d2689d | balrog | diff = s->clkm.arm_ckout1 ^ value; |
2655 | c3d2689d | balrog | s->clkm.arm_ckout1 = value & 0x003f;
|
2656 | c3d2689d | balrog | omap_clkm_ckout1_update(s, diff, value); |
2657 | c3d2689d | balrog | return;
|
2658 | c3d2689d | balrog | |
2659 | c3d2689d | balrog | case 0x20: /* ARM_CKOUT2 */ |
2660 | c3d2689d | balrog | default:
|
2661 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2662 | c3d2689d | balrog | } |
2663 | c3d2689d | balrog | } |
2664 | c3d2689d | balrog | |
2665 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_clkm_readfn[] = {
|
2666 | c3d2689d | balrog | omap_badwidth_read16, |
2667 | c3d2689d | balrog | omap_clkm_read, |
2668 | c3d2689d | balrog | omap_badwidth_read16, |
2669 | c3d2689d | balrog | }; |
2670 | c3d2689d | balrog | |
2671 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_clkm_writefn[] = {
|
2672 | c3d2689d | balrog | omap_badwidth_write16, |
2673 | c3d2689d | balrog | omap_clkm_write, |
2674 | c3d2689d | balrog | omap_badwidth_write16, |
2675 | c3d2689d | balrog | }; |
2676 | c3d2689d | balrog | |
2677 | c3d2689d | balrog | static uint32_t omap_clkdsp_read(void *opaque, target_phys_addr_t addr) |
2678 | c3d2689d | balrog | { |
2679 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2680 | c3d2689d | balrog | int offset = addr - s->clkm.dsp_base;
|
2681 | c3d2689d | balrog | |
2682 | c3d2689d | balrog | switch (offset) {
|
2683 | c3d2689d | balrog | case 0x04: /* DSP_IDLECT1 */ |
2684 | c3d2689d | balrog | return s->clkm.dsp_idlect1;
|
2685 | c3d2689d | balrog | |
2686 | c3d2689d | balrog | case 0x08: /* DSP_IDLECT2 */ |
2687 | c3d2689d | balrog | return s->clkm.dsp_idlect2;
|
2688 | c3d2689d | balrog | |
2689 | c3d2689d | balrog | case 0x14: /* DSP_RSTCT2 */ |
2690 | c3d2689d | balrog | return s->clkm.dsp_rstct2;
|
2691 | c3d2689d | balrog | |
2692 | c3d2689d | balrog | case 0x18: /* DSP_SYSST */ |
2693 | c3d2689d | balrog | return (s->clkm.clocking_scheme < 11) | s->clkm.cold_start | |
2694 | c3d2689d | balrog | (s->env->halted << 6); /* Quite useless... */ |
2695 | c3d2689d | balrog | } |
2696 | c3d2689d | balrog | |
2697 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2698 | c3d2689d | balrog | return 0; |
2699 | c3d2689d | balrog | } |
2700 | c3d2689d | balrog | |
2701 | c3d2689d | balrog | static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s, |
2702 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2703 | c3d2689d | balrog | { |
2704 | c3d2689d | balrog | omap_clk clk; |
2705 | c3d2689d | balrog | |
2706 | c3d2689d | balrog | SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */ |
2707 | c3d2689d | balrog | } |
2708 | c3d2689d | balrog | |
2709 | c3d2689d | balrog | static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s, |
2710 | c3d2689d | balrog | uint16_t diff, uint16_t value) |
2711 | c3d2689d | balrog | { |
2712 | c3d2689d | balrog | omap_clk clk; |
2713 | c3d2689d | balrog | |
2714 | c3d2689d | balrog | SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */ |
2715 | c3d2689d | balrog | } |
2716 | c3d2689d | balrog | |
2717 | c3d2689d | balrog | static void omap_clkdsp_write(void *opaque, target_phys_addr_t addr, |
2718 | c3d2689d | balrog | uint32_t value) |
2719 | c3d2689d | balrog | { |
2720 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
2721 | c3d2689d | balrog | int offset = addr - s->clkm.dsp_base;
|
2722 | c3d2689d | balrog | uint16_t diff; |
2723 | c3d2689d | balrog | |
2724 | c3d2689d | balrog | switch (offset) {
|
2725 | c3d2689d | balrog | case 0x04: /* DSP_IDLECT1 */ |
2726 | c3d2689d | balrog | diff = s->clkm.dsp_idlect1 ^ value; |
2727 | c3d2689d | balrog | s->clkm.dsp_idlect1 = value & 0x01f7;
|
2728 | c3d2689d | balrog | omap_clkdsp_idlect1_update(s, diff, value); |
2729 | c3d2689d | balrog | break;
|
2730 | c3d2689d | balrog | |
2731 | c3d2689d | balrog | case 0x08: /* DSP_IDLECT2 */ |
2732 | c3d2689d | balrog | s->clkm.dsp_idlect2 = value & 0x0037;
|
2733 | c3d2689d | balrog | diff = s->clkm.dsp_idlect1 ^ value; |
2734 | c3d2689d | balrog | omap_clkdsp_idlect2_update(s, diff, value); |
2735 | c3d2689d | balrog | break;
|
2736 | c3d2689d | balrog | |
2737 | c3d2689d | balrog | case 0x14: /* DSP_RSTCT2 */ |
2738 | c3d2689d | balrog | s->clkm.dsp_rstct2 = value & 0x0001;
|
2739 | c3d2689d | balrog | break;
|
2740 | c3d2689d | balrog | |
2741 | c3d2689d | balrog | case 0x18: /* DSP_SYSST */ |
2742 | c3d2689d | balrog | s->clkm.cold_start &= value & 0x3f;
|
2743 | c3d2689d | balrog | break;
|
2744 | c3d2689d | balrog | |
2745 | c3d2689d | balrog | default:
|
2746 | c3d2689d | balrog | OMAP_BAD_REG(addr); |
2747 | c3d2689d | balrog | } |
2748 | c3d2689d | balrog | } |
2749 | c3d2689d | balrog | |
2750 | c3d2689d | balrog | static CPUReadMemoryFunc *omap_clkdsp_readfn[] = {
|
2751 | c3d2689d | balrog | omap_badwidth_read16, |
2752 | c3d2689d | balrog | omap_clkdsp_read, |
2753 | c3d2689d | balrog | omap_badwidth_read16, |
2754 | c3d2689d | balrog | }; |
2755 | c3d2689d | balrog | |
2756 | c3d2689d | balrog | static CPUWriteMemoryFunc *omap_clkdsp_writefn[] = {
|
2757 | c3d2689d | balrog | omap_badwidth_write16, |
2758 | c3d2689d | balrog | omap_clkdsp_write, |
2759 | c3d2689d | balrog | omap_badwidth_write16, |
2760 | c3d2689d | balrog | }; |
2761 | c3d2689d | balrog | |
2762 | c3d2689d | balrog | static void omap_clkm_reset(struct omap_mpu_state_s *s) |
2763 | c3d2689d | balrog | { |
2764 | c3d2689d | balrog | if (s->wdt && s->wdt->reset)
|
2765 | c3d2689d | balrog | s->clkm.cold_start = 0x6;
|
2766 | c3d2689d | balrog | s->clkm.clocking_scheme = 0;
|
2767 | c3d2689d | balrog | omap_clkm_ckctl_update(s, ~0, 0x3000); |
2768 | c3d2689d | balrog | s->clkm.arm_ckctl = 0x3000;
|
2769 | c3d2689d | balrog | omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 & 0x0400, 0x0400); |
2770 | c3d2689d | balrog | s->clkm.arm_idlect1 = 0x0400;
|
2771 | c3d2689d | balrog | omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 & 0x0100, 0x0100); |
2772 | c3d2689d | balrog | s->clkm.arm_idlect2 = 0x0100;
|
2773 | c3d2689d | balrog | s->clkm.arm_ewupct = 0x003f;
|
2774 | c3d2689d | balrog | s->clkm.arm_rstct1 = 0x0000;
|
2775 | c3d2689d | balrog | s->clkm.arm_rstct2 = 0x0000;
|
2776 | c3d2689d | balrog | s->clkm.arm_ckout1 = 0x0015;
|
2777 | c3d2689d | balrog | s->clkm.dpll1_mode = 0x2002;
|
2778 | c3d2689d | balrog | omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040); |
2779 | c3d2689d | balrog | s->clkm.dsp_idlect1 = 0x0040;
|
2780 | c3d2689d | balrog | omap_clkdsp_idlect2_update(s, ~0, 0x0000); |
2781 | c3d2689d | balrog | s->clkm.dsp_idlect2 = 0x0000;
|
2782 | c3d2689d | balrog | s->clkm.dsp_rstct2 = 0x0000;
|
2783 | c3d2689d | balrog | } |
2784 | c3d2689d | balrog | |
2785 | c3d2689d | balrog | static void omap_clkm_init(target_phys_addr_t mpu_base, |
2786 | c3d2689d | balrog | target_phys_addr_t dsp_base, struct omap_mpu_state_s *s)
|
2787 | c3d2689d | balrog | { |
2788 | c3d2689d | balrog | int iomemtype[2] = { |
2789 | c3d2689d | balrog | cpu_register_io_memory(0, omap_clkm_readfn, omap_clkm_writefn, s),
|
2790 | c3d2689d | balrog | cpu_register_io_memory(0, omap_clkdsp_readfn, omap_clkdsp_writefn, s),
|
2791 | c3d2689d | balrog | }; |
2792 | c3d2689d | balrog | |
2793 | c3d2689d | balrog | s->clkm.mpu_base = mpu_base; |
2794 | c3d2689d | balrog | s->clkm.dsp_base = dsp_base; |
2795 | c3d2689d | balrog | s->clkm.cold_start = 0x3a;
|
2796 | c3d2689d | balrog | omap_clkm_reset(s); |
2797 | c3d2689d | balrog | |
2798 | c3d2689d | balrog | cpu_register_physical_memory(s->clkm.mpu_base, 0x100, iomemtype[0]); |
2799 | c3d2689d | balrog | cpu_register_physical_memory(s->clkm.dsp_base, 0x1000, iomemtype[1]); |
2800 | c3d2689d | balrog | } |
2801 | c3d2689d | balrog | |
2802 | fe71e81a | balrog | /* MPU I/O */
|
2803 | fe71e81a | balrog | struct omap_mpuio_s {
|
2804 | fe71e81a | balrog | target_phys_addr_t base; |
2805 | fe71e81a | balrog | qemu_irq irq; |
2806 | fe71e81a | balrog | qemu_irq kbd_irq; |
2807 | fe71e81a | balrog | qemu_irq *in; |
2808 | fe71e81a | balrog | qemu_irq handler[16];
|
2809 | fe71e81a | balrog | qemu_irq wakeup; |
2810 | fe71e81a | balrog | |
2811 | fe71e81a | balrog | uint16_t inputs; |
2812 | fe71e81a | balrog | uint16_t outputs; |
2813 | fe71e81a | balrog | uint16_t dir; |
2814 | fe71e81a | balrog | uint16_t edge; |
2815 | fe71e81a | balrog | uint16_t mask; |
2816 | fe71e81a | balrog | uint16_t ints; |
2817 | fe71e81a | balrog | |
2818 | fe71e81a | balrog | uint16_t debounce; |
2819 | fe71e81a | balrog | uint16_t latch; |
2820 | fe71e81a | balrog | uint8_t event; |
2821 | fe71e81a | balrog | |
2822 | fe71e81a | balrog | uint8_t buttons[5];
|
2823 | fe71e81a | balrog | uint8_t row_latch; |
2824 | fe71e81a | balrog | uint8_t cols; |
2825 | fe71e81a | balrog | int kbd_mask;
|
2826 | fe71e81a | balrog | int clk;
|
2827 | fe71e81a | balrog | }; |
2828 | fe71e81a | balrog | |
2829 | fe71e81a | balrog | static void omap_mpuio_set(void *opaque, int line, int level) |
2830 | fe71e81a | balrog | { |
2831 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
2832 | fe71e81a | balrog | uint16_t prev = s->inputs; |
2833 | fe71e81a | balrog | |
2834 | fe71e81a | balrog | if (level)
|
2835 | fe71e81a | balrog | s->inputs |= 1 << line;
|
2836 | fe71e81a | balrog | else
|
2837 | fe71e81a | balrog | s->inputs &= ~(1 << line);
|
2838 | fe71e81a | balrog | |
2839 | fe71e81a | balrog | if (((1 << line) & s->dir & ~s->mask) && s->clk) { |
2840 | fe71e81a | balrog | if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
|
2841 | fe71e81a | balrog | s->ints |= 1 << line;
|
2842 | fe71e81a | balrog | qemu_irq_raise(s->irq); |
2843 | fe71e81a | balrog | /* TODO: wakeup */
|
2844 | fe71e81a | balrog | } |
2845 | fe71e81a | balrog | if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */ |
2846 | fe71e81a | balrog | (s->event >> 1) == line) /* PIN_SELECT */ |
2847 | fe71e81a | balrog | s->latch = s->inputs; |
2848 | fe71e81a | balrog | } |
2849 | fe71e81a | balrog | } |
2850 | fe71e81a | balrog | |
2851 | fe71e81a | balrog | static void omap_mpuio_kbd_update(struct omap_mpuio_s *s) |
2852 | fe71e81a | balrog | { |
2853 | fe71e81a | balrog | int i;
|
2854 | fe71e81a | balrog | uint8_t *row, rows = 0, cols = ~s->cols;
|
2855 | fe71e81a | balrog | |
2856 | 38a34e1d | balrog | for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1) |
2857 | fe71e81a | balrog | if (*row & cols)
|
2858 | 38a34e1d | balrog | rows |= i; |
2859 | fe71e81a | balrog | |
2860 | 38a34e1d | balrog | qemu_set_irq(s->kbd_irq, rows && ~s->kbd_mask && s->clk); |
2861 | fe71e81a | balrog | s->row_latch = rows ^ 0x1f;
|
2862 | fe71e81a | balrog | } |
2863 | fe71e81a | balrog | |
2864 | fe71e81a | balrog | static uint32_t omap_mpuio_read(void *opaque, target_phys_addr_t addr) |
2865 | fe71e81a | balrog | { |
2866 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
2867 | fe71e81a | balrog | int offset = addr - s->base;
|
2868 | fe71e81a | balrog | uint16_t ret; |
2869 | fe71e81a | balrog | |
2870 | fe71e81a | balrog | switch (offset) {
|
2871 | fe71e81a | balrog | case 0x00: /* INPUT_LATCH */ |
2872 | fe71e81a | balrog | return s->inputs;
|
2873 | fe71e81a | balrog | |
2874 | fe71e81a | balrog | case 0x04: /* OUTPUT_REG */ |
2875 | fe71e81a | balrog | return s->outputs;
|
2876 | fe71e81a | balrog | |
2877 | fe71e81a | balrog | case 0x08: /* IO_CNTL */ |
2878 | fe71e81a | balrog | return s->dir;
|
2879 | fe71e81a | balrog | |
2880 | fe71e81a | balrog | case 0x10: /* KBR_LATCH */ |
2881 | fe71e81a | balrog | return s->row_latch;
|
2882 | fe71e81a | balrog | |
2883 | fe71e81a | balrog | case 0x14: /* KBC_REG */ |
2884 | fe71e81a | balrog | return s->cols;
|
2885 | fe71e81a | balrog | |
2886 | fe71e81a | balrog | case 0x18: /* GPIO_EVENT_MODE_REG */ |
2887 | fe71e81a | balrog | return s->event;
|
2888 | fe71e81a | balrog | |
2889 | fe71e81a | balrog | case 0x1c: /* GPIO_INT_EDGE_REG */ |
2890 | fe71e81a | balrog | return s->edge;
|
2891 | fe71e81a | balrog | |
2892 | fe71e81a | balrog | case 0x20: /* KBD_INT */ |
2893 | fe71e81a | balrog | return (s->row_latch != 0x1f) && !s->kbd_mask; |
2894 | fe71e81a | balrog | |
2895 | fe71e81a | balrog | case 0x24: /* GPIO_INT */ |
2896 | fe71e81a | balrog | ret = s->ints; |
2897 | 8e129e07 | balrog | s->ints &= s->mask; |
2898 | 8e129e07 | balrog | if (ret)
|
2899 | 8e129e07 | balrog | qemu_irq_lower(s->irq); |
2900 | fe71e81a | balrog | return ret;
|
2901 | fe71e81a | balrog | |
2902 | fe71e81a | balrog | case 0x28: /* KBD_MASKIT */ |
2903 | fe71e81a | balrog | return s->kbd_mask;
|
2904 | fe71e81a | balrog | |
2905 | fe71e81a | balrog | case 0x2c: /* GPIO_MASKIT */ |
2906 | fe71e81a | balrog | return s->mask;
|
2907 | fe71e81a | balrog | |
2908 | fe71e81a | balrog | case 0x30: /* GPIO_DEBOUNCING_REG */ |
2909 | fe71e81a | balrog | return s->debounce;
|
2910 | fe71e81a | balrog | |
2911 | fe71e81a | balrog | case 0x34: /* GPIO_LATCH_REG */ |
2912 | fe71e81a | balrog | return s->latch;
|
2913 | fe71e81a | balrog | } |
2914 | fe71e81a | balrog | |
2915 | fe71e81a | balrog | OMAP_BAD_REG(addr); |
2916 | fe71e81a | balrog | return 0; |
2917 | fe71e81a | balrog | } |
2918 | fe71e81a | balrog | |
2919 | fe71e81a | balrog | static void omap_mpuio_write(void *opaque, target_phys_addr_t addr, |
2920 | fe71e81a | balrog | uint32_t value) |
2921 | fe71e81a | balrog | { |
2922 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
2923 | fe71e81a | balrog | int offset = addr - s->base;
|
2924 | fe71e81a | balrog | uint16_t diff; |
2925 | fe71e81a | balrog | int ln;
|
2926 | fe71e81a | balrog | |
2927 | fe71e81a | balrog | switch (offset) {
|
2928 | fe71e81a | balrog | case 0x04: /* OUTPUT_REG */ |
2929 | fe71e81a | balrog | diff = s->outputs ^ (value & ~s->dir); |
2930 | fe71e81a | balrog | s->outputs = value; |
2931 | fe71e81a | balrog | value &= ~s->dir; |
2932 | fe71e81a | balrog | while ((ln = ffs(diff))) {
|
2933 | fe71e81a | balrog | ln --; |
2934 | fe71e81a | balrog | if (s->handler[ln])
|
2935 | fe71e81a | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
2936 | fe71e81a | balrog | diff &= ~(1 << ln);
|
2937 | fe71e81a | balrog | } |
2938 | fe71e81a | balrog | break;
|
2939 | fe71e81a | balrog | |
2940 | fe71e81a | balrog | case 0x08: /* IO_CNTL */ |
2941 | fe71e81a | balrog | diff = s->outputs & (s->dir ^ value); |
2942 | fe71e81a | balrog | s->dir = value; |
2943 | fe71e81a | balrog | |
2944 | fe71e81a | balrog | value = s->outputs & ~s->dir; |
2945 | fe71e81a | balrog | while ((ln = ffs(diff))) {
|
2946 | fe71e81a | balrog | ln --; |
2947 | fe71e81a | balrog | if (s->handler[ln])
|
2948 | fe71e81a | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
2949 | fe71e81a | balrog | diff &= ~(1 << ln);
|
2950 | fe71e81a | balrog | } |
2951 | fe71e81a | balrog | break;
|
2952 | fe71e81a | balrog | |
2953 | fe71e81a | balrog | case 0x14: /* KBC_REG */ |
2954 | fe71e81a | balrog | s->cols = value; |
2955 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
2956 | fe71e81a | balrog | break;
|
2957 | fe71e81a | balrog | |
2958 | fe71e81a | balrog | case 0x18: /* GPIO_EVENT_MODE_REG */ |
2959 | fe71e81a | balrog | s->event = value & 0x1f;
|
2960 | fe71e81a | balrog | break;
|
2961 | fe71e81a | balrog | |
2962 | fe71e81a | balrog | case 0x1c: /* GPIO_INT_EDGE_REG */ |
2963 | fe71e81a | balrog | s->edge = value; |
2964 | fe71e81a | balrog | break;
|
2965 | fe71e81a | balrog | |
2966 | fe71e81a | balrog | case 0x28: /* KBD_MASKIT */ |
2967 | fe71e81a | balrog | s->kbd_mask = value & 1;
|
2968 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
2969 | fe71e81a | balrog | break;
|
2970 | fe71e81a | balrog | |
2971 | fe71e81a | balrog | case 0x2c: /* GPIO_MASKIT */ |
2972 | fe71e81a | balrog | s->mask = value; |
2973 | fe71e81a | balrog | break;
|
2974 | fe71e81a | balrog | |
2975 | fe71e81a | balrog | case 0x30: /* GPIO_DEBOUNCING_REG */ |
2976 | fe71e81a | balrog | s->debounce = value & 0x1ff;
|
2977 | fe71e81a | balrog | break;
|
2978 | fe71e81a | balrog | |
2979 | fe71e81a | balrog | case 0x00: /* INPUT_LATCH */ |
2980 | fe71e81a | balrog | case 0x10: /* KBR_LATCH */ |
2981 | fe71e81a | balrog | case 0x20: /* KBD_INT */ |
2982 | fe71e81a | balrog | case 0x24: /* GPIO_INT */ |
2983 | fe71e81a | balrog | case 0x34: /* GPIO_LATCH_REG */ |
2984 | fe71e81a | balrog | OMAP_RO_REG(addr); |
2985 | fe71e81a | balrog | return;
|
2986 | fe71e81a | balrog | |
2987 | fe71e81a | balrog | default:
|
2988 | fe71e81a | balrog | OMAP_BAD_REG(addr); |
2989 | fe71e81a | balrog | return;
|
2990 | fe71e81a | balrog | } |
2991 | fe71e81a | balrog | } |
2992 | fe71e81a | balrog | |
2993 | fe71e81a | balrog | static CPUReadMemoryFunc *omap_mpuio_readfn[] = {
|
2994 | fe71e81a | balrog | omap_badwidth_read16, |
2995 | fe71e81a | balrog | omap_mpuio_read, |
2996 | fe71e81a | balrog | omap_badwidth_read16, |
2997 | fe71e81a | balrog | }; |
2998 | fe71e81a | balrog | |
2999 | fe71e81a | balrog | static CPUWriteMemoryFunc *omap_mpuio_writefn[] = {
|
3000 | fe71e81a | balrog | omap_badwidth_write16, |
3001 | fe71e81a | balrog | omap_mpuio_write, |
3002 | fe71e81a | balrog | omap_badwidth_write16, |
3003 | fe71e81a | balrog | }; |
3004 | fe71e81a | balrog | |
3005 | fe71e81a | balrog | void omap_mpuio_reset(struct omap_mpuio_s *s) |
3006 | fe71e81a | balrog | { |
3007 | fe71e81a | balrog | s->inputs = 0;
|
3008 | fe71e81a | balrog | s->outputs = 0;
|
3009 | fe71e81a | balrog | s->dir = ~0;
|
3010 | fe71e81a | balrog | s->event = 0;
|
3011 | fe71e81a | balrog | s->edge = 0;
|
3012 | fe71e81a | balrog | s->kbd_mask = 0;
|
3013 | fe71e81a | balrog | s->mask = 0;
|
3014 | fe71e81a | balrog | s->debounce = 0;
|
3015 | fe71e81a | balrog | s->latch = 0;
|
3016 | fe71e81a | balrog | s->ints = 0;
|
3017 | fe71e81a | balrog | s->row_latch = 0x1f;
|
3018 | 38a34e1d | balrog | s->clk = 1;
|
3019 | fe71e81a | balrog | } |
3020 | fe71e81a | balrog | |
3021 | fe71e81a | balrog | static void omap_mpuio_onoff(void *opaque, int line, int on) |
3022 | fe71e81a | balrog | { |
3023 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque; |
3024 | fe71e81a | balrog | |
3025 | fe71e81a | balrog | s->clk = on; |
3026 | fe71e81a | balrog | if (on)
|
3027 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
3028 | fe71e81a | balrog | } |
3029 | fe71e81a | balrog | |
3030 | fe71e81a | balrog | struct omap_mpuio_s *omap_mpuio_init(target_phys_addr_t base,
|
3031 | fe71e81a | balrog | qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup, |
3032 | fe71e81a | balrog | omap_clk clk) |
3033 | fe71e81a | balrog | { |
3034 | fe71e81a | balrog | int iomemtype;
|
3035 | fe71e81a | balrog | struct omap_mpuio_s *s = (struct omap_mpuio_s *) |
3036 | fe71e81a | balrog | qemu_mallocz(sizeof(struct omap_mpuio_s)); |
3037 | fe71e81a | balrog | |
3038 | fe71e81a | balrog | s->base = base; |
3039 | fe71e81a | balrog | s->irq = gpio_int; |
3040 | fe71e81a | balrog | s->kbd_irq = kbd_int; |
3041 | fe71e81a | balrog | s->wakeup = wakeup; |
3042 | fe71e81a | balrog | s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
|
3043 | fe71e81a | balrog | omap_mpuio_reset(s); |
3044 | fe71e81a | balrog | |
3045 | fe71e81a | balrog | iomemtype = cpu_register_io_memory(0, omap_mpuio_readfn,
|
3046 | fe71e81a | balrog | omap_mpuio_writefn, s); |
3047 | fe71e81a | balrog | cpu_register_physical_memory(s->base, 0x800, iomemtype);
|
3048 | fe71e81a | balrog | |
3049 | fe71e81a | balrog | omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]); |
3050 | fe71e81a | balrog | |
3051 | fe71e81a | balrog | return s;
|
3052 | fe71e81a | balrog | } |
3053 | fe71e81a | balrog | |
3054 | fe71e81a | balrog | qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
|
3055 | fe71e81a | balrog | { |
3056 | fe71e81a | balrog | return s->in;
|
3057 | fe71e81a | balrog | } |
3058 | fe71e81a | balrog | |
3059 | fe71e81a | balrog | void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler) |
3060 | fe71e81a | balrog | { |
3061 | fe71e81a | balrog | if (line >= 16 || line < 0) |
3062 | fe71e81a | balrog | cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
|
3063 | fe71e81a | balrog | s->handler[line] = handler; |
3064 | fe71e81a | balrog | } |
3065 | fe71e81a | balrog | |
3066 | fe71e81a | balrog | void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down) |
3067 | fe71e81a | balrog | { |
3068 | fe71e81a | balrog | if (row >= 5 || row < 0) |
3069 | fe71e81a | balrog | cpu_abort(cpu_single_env, "%s: No key %i-%i\n",
|
3070 | fe71e81a | balrog | __FUNCTION__, col, row); |
3071 | fe71e81a | balrog | |
3072 | fe71e81a | balrog | if (down)
|
3073 | 38a34e1d | balrog | s->buttons[row] |= 1 << col;
|
3074 | fe71e81a | balrog | else
|
3075 | 38a34e1d | balrog | s->buttons[row] &= ~(1 << col);
|
3076 | fe71e81a | balrog | |
3077 | fe71e81a | balrog | omap_mpuio_kbd_update(s); |
3078 | fe71e81a | balrog | } |
3079 | fe71e81a | balrog | |
3080 | 64330148 | balrog | /* General-Purpose I/O */
|
3081 | 64330148 | balrog | struct omap_gpio_s {
|
3082 | 64330148 | balrog | target_phys_addr_t base; |
3083 | 64330148 | balrog | qemu_irq irq; |
3084 | 64330148 | balrog | qemu_irq *in; |
3085 | 64330148 | balrog | qemu_irq handler[16];
|
3086 | 64330148 | balrog | |
3087 | 64330148 | balrog | uint16_t inputs; |
3088 | 64330148 | balrog | uint16_t outputs; |
3089 | 64330148 | balrog | uint16_t dir; |
3090 | 64330148 | balrog | uint16_t edge; |
3091 | 64330148 | balrog | uint16_t mask; |
3092 | 64330148 | balrog | uint16_t ints; |
3093 | 64330148 | balrog | }; |
3094 | 64330148 | balrog | |
3095 | 64330148 | balrog | static void omap_gpio_set(void *opaque, int line, int level) |
3096 | 64330148 | balrog | { |
3097 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; |
3098 | 64330148 | balrog | uint16_t prev = s->inputs; |
3099 | 64330148 | balrog | |
3100 | 64330148 | balrog | if (level)
|
3101 | 64330148 | balrog | s->inputs |= 1 << line;
|
3102 | 64330148 | balrog | else
|
3103 | 64330148 | balrog | s->inputs &= ~(1 << line);
|
3104 | 64330148 | balrog | |
3105 | 64330148 | balrog | if (((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) &
|
3106 | 64330148 | balrog | (1 << line) & s->dir & ~s->mask) {
|
3107 | 64330148 | balrog | s->ints |= 1 << line;
|
3108 | 64330148 | balrog | qemu_irq_raise(s->irq); |
3109 | 64330148 | balrog | } |
3110 | 64330148 | balrog | } |
3111 | 64330148 | balrog | |
3112 | 64330148 | balrog | static uint32_t omap_gpio_read(void *opaque, target_phys_addr_t addr) |
3113 | 64330148 | balrog | { |
3114 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; |
3115 | 64330148 | balrog | int offset = addr - s->base;
|
3116 | 64330148 | balrog | |
3117 | 64330148 | balrog | switch (offset) {
|
3118 | 64330148 | balrog | case 0x00: /* DATA_INPUT */ |
3119 | 64330148 | balrog | return s->inputs;
|
3120 | 64330148 | balrog | |
3121 | 64330148 | balrog | case 0x04: /* DATA_OUTPUT */ |
3122 | 64330148 | balrog | return s->outputs;
|
3123 | 64330148 | balrog | |
3124 | 64330148 | balrog | case 0x08: /* DIRECTION_CONTROL */ |
3125 | 64330148 | balrog | return s->dir;
|
3126 | 64330148 | balrog | |
3127 | 64330148 | balrog | case 0x0c: /* INTERRUPT_CONTROL */ |
3128 | 64330148 | balrog | return s->edge;
|
3129 | 64330148 | balrog | |
3130 | 64330148 | balrog | case 0x10: /* INTERRUPT_MASK */ |
3131 | 64330148 | balrog | return s->mask;
|
3132 | 64330148 | balrog | |
3133 | 64330148 | balrog | case 0x14: /* INTERRUPT_STATUS */ |
3134 | 64330148 | balrog | return s->ints;
|
3135 | 64330148 | balrog | } |
3136 | 64330148 | balrog | |
3137 | 64330148 | balrog | OMAP_BAD_REG(addr); |
3138 | 64330148 | balrog | return 0; |
3139 | 64330148 | balrog | } |
3140 | 64330148 | balrog | |
3141 | 64330148 | balrog | static void omap_gpio_write(void *opaque, target_phys_addr_t addr, |
3142 | 64330148 | balrog | uint32_t value) |
3143 | 64330148 | balrog | { |
3144 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; |
3145 | 64330148 | balrog | int offset = addr - s->base;
|
3146 | 64330148 | balrog | uint16_t diff; |
3147 | 64330148 | balrog | int ln;
|
3148 | 64330148 | balrog | |
3149 | 64330148 | balrog | switch (offset) {
|
3150 | 64330148 | balrog | case 0x00: /* DATA_INPUT */ |
3151 | 64330148 | balrog | OMAP_RO_REG(addr); |
3152 | 64330148 | balrog | return;
|
3153 | 64330148 | balrog | |
3154 | 64330148 | balrog | case 0x04: /* DATA_OUTPUT */ |
3155 | 66450b15 | balrog | diff = (s->outputs ^ value) & ~s->dir; |
3156 | 64330148 | balrog | s->outputs = value; |
3157 | 64330148 | balrog | while ((ln = ffs(diff))) {
|
3158 | 64330148 | balrog | ln --; |
3159 | 64330148 | balrog | if (s->handler[ln])
|
3160 | 64330148 | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
3161 | 64330148 | balrog | diff &= ~(1 << ln);
|
3162 | 64330148 | balrog | } |
3163 | 64330148 | balrog | break;
|
3164 | 64330148 | balrog | |
3165 | 64330148 | balrog | case 0x08: /* DIRECTION_CONTROL */ |
3166 | 64330148 | balrog | diff = s->outputs & (s->dir ^ value); |
3167 | 64330148 | balrog | s->dir = value; |
3168 | 64330148 | balrog | |
3169 | 64330148 | balrog | value = s->outputs & ~s->dir; |
3170 | 64330148 | balrog | while ((ln = ffs(diff))) {
|
3171 | 64330148 | balrog | ln --; |
3172 | 64330148 | balrog | if (s->handler[ln])
|
3173 | 64330148 | balrog | qemu_set_irq(s->handler[ln], (value >> ln) & 1);
|
3174 | 64330148 | balrog | diff &= ~(1 << ln);
|
3175 | 64330148 | balrog | } |
3176 | 64330148 | balrog | break;
|
3177 | 64330148 | balrog | |
3178 | 64330148 | balrog | case 0x0c: /* INTERRUPT_CONTROL */ |
3179 | 64330148 | balrog | s->edge = value; |
3180 | 64330148 | balrog | break;
|
3181 | 64330148 | balrog | |
3182 | 64330148 | balrog | case 0x10: /* INTERRUPT_MASK */ |
3183 | 64330148 | balrog | s->mask = value; |
3184 | 64330148 | balrog | break;
|
3185 | 64330148 | balrog | |
3186 | 64330148 | balrog | case 0x14: /* INTERRUPT_STATUS */ |
3187 | 64330148 | balrog | s->ints &= ~value; |
3188 | 64330148 | balrog | if (!s->ints)
|
3189 | 64330148 | balrog | qemu_irq_lower(s->irq); |
3190 | 64330148 | balrog | break;
|
3191 | 64330148 | balrog | |
3192 | 64330148 | balrog | default:
|
3193 | 64330148 | balrog | OMAP_BAD_REG(addr); |
3194 | 64330148 | balrog | return;
|
3195 | 64330148 | balrog | } |
3196 | 64330148 | balrog | } |
3197 | 64330148 | balrog | |
3198 | 3efda49d | balrog | /* *Some* sources say the memory region is 32-bit. */
|
3199 | 64330148 | balrog | static CPUReadMemoryFunc *omap_gpio_readfn[] = {
|
3200 | 3efda49d | balrog | omap_badwidth_read16, |
3201 | 64330148 | balrog | omap_gpio_read, |
3202 | 3efda49d | balrog | omap_badwidth_read16, |
3203 | 64330148 | balrog | }; |
3204 | 64330148 | balrog | |
3205 | 64330148 | balrog | static CPUWriteMemoryFunc *omap_gpio_writefn[] = {
|
3206 | 3efda49d | balrog | omap_badwidth_write16, |
3207 | 64330148 | balrog | omap_gpio_write, |
3208 | 3efda49d | balrog | omap_badwidth_write16, |
3209 | 64330148 | balrog | }; |
3210 | 64330148 | balrog | |
3211 | 64330148 | balrog | void omap_gpio_reset(struct omap_gpio_s *s) |
3212 | 64330148 | balrog | { |
3213 | 64330148 | balrog | s->inputs = 0;
|
3214 | 64330148 | balrog | s->outputs = ~0;
|
3215 | 64330148 | balrog | s->dir = ~0;
|
3216 | 64330148 | balrog | s->edge = ~0;
|
3217 | 64330148 | balrog | s->mask = ~0;
|
3218 | 64330148 | balrog | s->ints = 0;
|
3219 | 64330148 | balrog | } |
3220 | 64330148 | balrog | |
3221 | 64330148 | balrog | struct omap_gpio_s *omap_gpio_init(target_phys_addr_t base,
|
3222 | 64330148 | balrog | qemu_irq irq, omap_clk clk) |
3223 | 64330148 | balrog | { |
3224 | 64330148 | balrog | int iomemtype;
|
3225 | 64330148 | balrog | struct omap_gpio_s *s = (struct omap_gpio_s *) |
3226 | 64330148 | balrog | qemu_mallocz(sizeof(struct omap_gpio_s)); |
3227 | 64330148 | balrog | |
3228 | 64330148 | balrog | s->base = base; |
3229 | 64330148 | balrog | s->irq = irq; |
3230 | 64330148 | balrog | s->in = qemu_allocate_irqs(omap_gpio_set, s, 16);
|
3231 | 64330148 | balrog | omap_gpio_reset(s); |
3232 | 64330148 | balrog | |
3233 | 64330148 | balrog | iomemtype = cpu_register_io_memory(0, omap_gpio_readfn,
|
3234 | 64330148 | balrog | omap_gpio_writefn, s); |
3235 | 64330148 | balrog | cpu_register_physical_memory(s->base, 0x1000, iomemtype);
|
3236 | 64330148 | balrog | |
3237 | 64330148 | balrog | return s;
|
3238 | 64330148 | balrog | } |
3239 | 64330148 | balrog | |
3240 | 64330148 | balrog | qemu_irq *omap_gpio_in_get(struct omap_gpio_s *s)
|
3241 | 64330148 | balrog | { |
3242 | 64330148 | balrog | return s->in;
|
3243 | 64330148 | balrog | } |
3244 | 64330148 | balrog | |
3245 | 64330148 | balrog | void omap_gpio_out_set(struct omap_gpio_s *s, int line, qemu_irq handler) |
3246 | 64330148 | balrog | { |
3247 | 64330148 | balrog | if (line >= 16 || line < 0) |
3248 | 64330148 | balrog | cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
|
3249 | 64330148 | balrog | s->handler[line] = handler; |
3250 | 64330148 | balrog | } |
3251 | 64330148 | balrog | |
3252 | d951f6ff | balrog | /* MicroWire Interface */
|
3253 | d951f6ff | balrog | struct omap_uwire_s {
|
3254 | d951f6ff | balrog | target_phys_addr_t base; |
3255 | d951f6ff | balrog | qemu_irq txirq; |
3256 | d951f6ff | balrog | qemu_irq rxirq; |
3257 | d951f6ff | balrog | qemu_irq txdrq; |
3258 | d951f6ff | balrog | |
3259 | d951f6ff | balrog | uint16_t txbuf; |
3260 | d951f6ff | balrog | uint16_t rxbuf; |
3261 | d951f6ff | balrog | uint16_t control; |
3262 | d951f6ff | balrog | uint16_t setup[5];
|
3263 | d951f6ff | balrog | |
3264 | d951f6ff | balrog | struct uwire_slave_s *chip[4]; |
3265 | d951f6ff | balrog | }; |
3266 | d951f6ff | balrog | |
3267 | d951f6ff | balrog | static void omap_uwire_transfer_start(struct omap_uwire_s *s) |
3268 | d951f6ff | balrog | { |
3269 | d951f6ff | balrog | int chipselect = (s->control >> 10) & 3; /* INDEX */ |
3270 | d951f6ff | balrog | struct uwire_slave_s *slave = s->chip[chipselect];
|
3271 | d951f6ff | balrog | |
3272 | d951f6ff | balrog | if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */ |
3273 | d951f6ff | balrog | if (s->control & (1 << 12)) /* CS_CMD */ |
3274 | d951f6ff | balrog | if (slave && slave->send)
|
3275 | d951f6ff | balrog | slave->send(slave->opaque, |
3276 | d951f6ff | balrog | s->txbuf >> (16 - ((s->control >> 5) & 0x1f))); |
3277 | d951f6ff | balrog | s->control &= ~(1 << 14); /* CSRB */ |
3278 | d951f6ff | balrog | /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
|
3279 | d951f6ff | balrog | * a DRQ. When is the level IRQ supposed to be reset? */
|
3280 | d951f6ff | balrog | } |
3281 | d951f6ff | balrog | |
3282 | d951f6ff | balrog | if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */ |
3283 | d951f6ff | balrog | if (s->control & (1 << 12)) /* CS_CMD */ |
3284 | d951f6ff | balrog | if (slave && slave->receive)
|
3285 | d951f6ff | balrog | s->rxbuf = slave->receive(slave->opaque); |
3286 | d951f6ff | balrog | s->control |= 1 << 15; /* RDRB */ |
3287 | d951f6ff | balrog | /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
|
3288 | d951f6ff | balrog | * a DRQ. When is the level IRQ supposed to be reset? */
|
3289 | d951f6ff | balrog | } |
3290 | d951f6ff | balrog | } |
3291 | d951f6ff | balrog | |
3292 | d951f6ff | balrog | static uint32_t omap_uwire_read(void *opaque, target_phys_addr_t addr) |
3293 | d951f6ff | balrog | { |
3294 | d951f6ff | balrog | struct omap_uwire_s *s = (struct omap_uwire_s *) opaque; |
3295 | d951f6ff | balrog | int offset = addr - s->base;
|
3296 | d951f6ff | balrog | |
3297 | d951f6ff | balrog | switch (offset) {
|
3298 | d951f6ff | balrog | case 0x00: /* RDR */ |
3299 | d951f6ff | balrog | s->control &= ~(1 << 15); /* RDRB */ |
3300 | d951f6ff | balrog | return s->rxbuf;
|
3301 | d951f6ff | balrog | |
3302 | d951f6ff | balrog | case 0x04: /* CSR */ |
3303 | d951f6ff | balrog | return s->control;
|
3304 | d951f6ff | balrog | |
3305 | d951f6ff | balrog | case 0x08: /* SR1 */ |
3306 | d951f6ff | balrog | return s->setup[0]; |
3307 | d951f6ff | balrog | case 0x0c: /* SR2 */ |
3308 | d951f6ff | balrog | return s->setup[1]; |
3309 | d951f6ff | balrog | case 0x10: /* SR3 */ |
3310 | d951f6ff | balrog | return s->setup[2]; |
3311 | d951f6ff | balrog | case 0x14: /* SR4 */ |
3312 | d951f6ff | balrog | return s->setup[3]; |
3313 | d951f6ff | balrog | case 0x18: /* SR5 */ |
3314 | d951f6ff | balrog | return s->setup[4]; |
3315 | d951f6ff | balrog | } |
3316 | d951f6ff | balrog | |
3317 | d951f6ff | balrog | OMAP_BAD_REG(addr); |
3318 | d951f6ff | balrog | return 0; |
3319 | d951f6ff | balrog | } |
3320 | d951f6ff | balrog | |
3321 | d951f6ff | balrog | static void omap_uwire_write(void *opaque, target_phys_addr_t addr, |
3322 | d951f6ff | balrog | uint32_t value) |
3323 | d951f6ff | balrog | { |
3324 | d951f6ff | balrog | struct omap_uwire_s *s = (struct omap_uwire_s *) opaque; |
3325 | d951f6ff | balrog | int offset = addr - s->base;
|
3326 | d951f6ff | balrog | |
3327 | d951f6ff | balrog | switch (offset) {
|
3328 | d951f6ff | balrog | case 0x00: /* TDR */ |
3329 | d951f6ff | balrog | s->txbuf = value; /* TD */
|
3330 | d951f6ff | balrog | s->control |= 1 << 14; /* CSRB */ |
3331 | d951f6ff | balrog | if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */ |
3332 | d951f6ff | balrog | ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */ |
3333 | d951f6ff | balrog | (s->control & (1 << 12)))) /* CS_CMD */ |
3334 | d951f6ff | balrog | omap_uwire_transfer_start(s); |
3335 | d951f6ff | balrog | break;
|
3336 | d951f6ff | balrog | |
3337 | d951f6ff | balrog | case 0x04: /* CSR */ |
3338 | d951f6ff | balrog | s->control = value & 0x1fff;
|
3339 | d951f6ff | balrog | if (value & (1 << 13)) /* START */ |
3340 | d951f6ff | balrog | omap_uwire_transfer_start(s); |
3341 | d951f6ff | balrog | break;
|
3342 | d951f6ff | balrog | |
3343 | d951f6ff | balrog | case 0x08: /* SR1 */ |
3344 | d951f6ff | balrog | s->setup[0] = value & 0x003f; |
3345 | d951f6ff | balrog | break;
|
3346 | d951f6ff | balrog | |
3347 | d951f6ff | balrog | case 0x0c: /* SR2 */ |
3348 | d951f6ff | balrog | s->setup[1] = value & 0x0fc0; |
3349 | d951f6ff | balrog | break;
|
3350 | d951f6ff | balrog | |
3351 | d951f6ff | balrog | case 0x10: /* SR3 */ |
3352 | d951f6ff | balrog | s->setup[2] = value & 0x0003; |
3353 | d951f6ff | balrog | break;
|
3354 | d951f6ff | balrog | |
3355 | d951f6ff | balrog | case 0x14: /* SR4 */ |
3356 | d951f6ff | balrog | s->setup[3] = value & 0x0001; |
3357 | d951f6ff | balrog | break;
|
3358 | d951f6ff | balrog | |
3359 | d951f6ff | balrog | case 0x18: /* SR5 */ |
3360 | d951f6ff | balrog | s->setup[4] = value & 0x000f; |
3361 | d951f6ff | balrog | break;
|
3362 | d951f6ff | balrog | |
3363 | d951f6ff | balrog | default:
|
3364 | d951f6ff | balrog | OMAP_BAD_REG(addr); |
3365 | d951f6ff | balrog | return;
|
3366 | d951f6ff | balrog | } |
3367 | d951f6ff | balrog | } |
3368 | d951f6ff | balrog | |
3369 | d951f6ff | balrog | static CPUReadMemoryFunc *omap_uwire_readfn[] = {
|
3370 | d951f6ff | balrog | omap_badwidth_read16, |
3371 | d951f6ff | balrog | omap_uwire_read, |
3372 | d951f6ff | balrog | omap_badwidth_read16, |
3373 | d951f6ff | balrog | }; |
3374 | d951f6ff | balrog | |
3375 | d951f6ff | balrog | static CPUWriteMemoryFunc *omap_uwire_writefn[] = {
|
3376 | d951f6ff | balrog | omap_badwidth_write16, |
3377 | d951f6ff | balrog | omap_uwire_write, |
3378 | d951f6ff | balrog | omap_badwidth_write16, |
3379 | d951f6ff | balrog | }; |
3380 | d951f6ff | balrog | |
3381 | d951f6ff | balrog | void omap_uwire_reset(struct omap_uwire_s *s) |
3382 | d951f6ff | balrog | { |
3383 | 66450b15 | balrog | s->control = 0;
|
3384 | d951f6ff | balrog | s->setup[0] = 0; |
3385 | d951f6ff | balrog | s->setup[1] = 0; |
3386 | d951f6ff | balrog | s->setup[2] = 0; |
3387 | d951f6ff | balrog | s->setup[3] = 0; |
3388 | d951f6ff | balrog | s->setup[4] = 0; |
3389 | d951f6ff | balrog | } |
3390 | d951f6ff | balrog | |
3391 | d951f6ff | balrog | struct omap_uwire_s *omap_uwire_init(target_phys_addr_t base,
|
3392 | d951f6ff | balrog | qemu_irq *irq, qemu_irq dma, omap_clk clk) |
3393 | d951f6ff | balrog | { |
3394 | d951f6ff | balrog | int iomemtype;
|
3395 | d951f6ff | balrog | struct omap_uwire_s *s = (struct omap_uwire_s *) |
3396 | d951f6ff | balrog | qemu_mallocz(sizeof(struct omap_uwire_s)); |
3397 | d951f6ff | balrog | |
3398 | d951f6ff | balrog | s->base = base; |
3399 | d951f6ff | balrog | s->txirq = irq[0];
|
3400 | d951f6ff | balrog | s->rxirq = irq[1];
|
3401 | d951f6ff | balrog | s->txdrq = dma; |
3402 | d951f6ff | balrog | omap_uwire_reset(s); |
3403 | d951f6ff | balrog | |
3404 | d951f6ff | balrog | iomemtype = cpu_register_io_memory(0, omap_uwire_readfn,
|
3405 | d951f6ff | balrog | omap_uwire_writefn, s); |
3406 | d951f6ff | balrog | cpu_register_physical_memory(s->base, 0x800, iomemtype);
|
3407 | d951f6ff | balrog | |
3408 | d951f6ff | balrog | return s;
|
3409 | d951f6ff | balrog | } |
3410 | d951f6ff | balrog | |
3411 | d951f6ff | balrog | void omap_uwire_attach(struct omap_uwire_s *s, |
3412 | d951f6ff | balrog | struct uwire_slave_s *slave, int chipselect) |
3413 | d951f6ff | balrog | { |
3414 | d951f6ff | balrog | if (chipselect < 0 || chipselect > 3) |
3415 | d951f6ff | balrog | cpu_abort(cpu_single_env, "%s: Bad chipselect %i\n", __FUNCTION__,
|
3416 | d951f6ff | balrog | chipselect); |
3417 | d951f6ff | balrog | |
3418 | d951f6ff | balrog | s->chip[chipselect] = slave; |
3419 | d951f6ff | balrog | } |
3420 | d951f6ff | balrog | |
3421 | 66450b15 | balrog | /* Pseudonoise Pulse-Width Light Modulator */
|
3422 | 66450b15 | balrog | void omap_pwl_update(struct omap_mpu_state_s *s) |
3423 | 66450b15 | balrog | { |
3424 | 66450b15 | balrog | int output = (s->pwl.clk && s->pwl.enable) ? s->pwl.level : 0; |
3425 | 66450b15 | balrog | |
3426 | 66450b15 | balrog | if (output != s->pwl.output) {
|
3427 | 66450b15 | balrog | s->pwl.output = output; |
3428 | 66450b15 | balrog | printf("%s: Backlight now at %i/256\n", __FUNCTION__, output);
|
3429 | 66450b15 | balrog | } |
3430 | 66450b15 | balrog | } |
3431 | 66450b15 | balrog | |
3432 | 66450b15 | balrog | static uint32_t omap_pwl_read(void *opaque, target_phys_addr_t addr) |
3433 | 66450b15 | balrog | { |
3434 | 66450b15 | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3435 | 66450b15 | balrog | int offset = addr - s->pwl.base;
|
3436 | 66450b15 | balrog | |
3437 | 66450b15 | balrog | switch (offset) {
|
3438 | 66450b15 | balrog | case 0x00: /* PWL_LEVEL */ |
3439 | 66450b15 | balrog | return s->pwl.level;
|
3440 | 66450b15 | balrog | case 0x04: /* PWL_CTRL */ |
3441 | 66450b15 | balrog | return s->pwl.enable;
|
3442 | 66450b15 | balrog | } |
3443 | 66450b15 | balrog | OMAP_BAD_REG(addr); |
3444 | 66450b15 | balrog | return 0; |
3445 | 66450b15 | balrog | } |
3446 | 66450b15 | balrog | |
3447 | 66450b15 | balrog | static void omap_pwl_write(void *opaque, target_phys_addr_t addr, |
3448 | 66450b15 | balrog | uint32_t value) |
3449 | 66450b15 | balrog | { |
3450 | 66450b15 | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3451 | 66450b15 | balrog | int offset = addr - s->pwl.base;
|
3452 | 66450b15 | balrog | |
3453 | 66450b15 | balrog | switch (offset) {
|
3454 | 66450b15 | balrog | case 0x00: /* PWL_LEVEL */ |
3455 | 66450b15 | balrog | s->pwl.level = value; |
3456 | 66450b15 | balrog | omap_pwl_update(s); |
3457 | 66450b15 | balrog | break;
|
3458 | 66450b15 | balrog | case 0x04: /* PWL_CTRL */ |
3459 | 66450b15 | balrog | s->pwl.enable = value & 1;
|
3460 | 66450b15 | balrog | omap_pwl_update(s); |
3461 | 66450b15 | balrog | break;
|
3462 | 66450b15 | balrog | default:
|
3463 | 66450b15 | balrog | OMAP_BAD_REG(addr); |
3464 | 66450b15 | balrog | return;
|
3465 | 66450b15 | balrog | } |
3466 | 66450b15 | balrog | } |
3467 | 66450b15 | balrog | |
3468 | 66450b15 | balrog | static CPUReadMemoryFunc *omap_pwl_readfn[] = {
|
3469 | 66450b15 | balrog | omap_badwidth_read8, |
3470 | 66450b15 | balrog | omap_badwidth_read8, |
3471 | 66450b15 | balrog | omap_pwl_read, |
3472 | 66450b15 | balrog | }; |
3473 | 66450b15 | balrog | |
3474 | 66450b15 | balrog | static CPUWriteMemoryFunc *omap_pwl_writefn[] = {
|
3475 | 66450b15 | balrog | omap_badwidth_write8, |
3476 | 66450b15 | balrog | omap_badwidth_write8, |
3477 | 66450b15 | balrog | omap_pwl_write, |
3478 | 66450b15 | balrog | }; |
3479 | 66450b15 | balrog | |
3480 | 66450b15 | balrog | void omap_pwl_reset(struct omap_mpu_state_s *s) |
3481 | 66450b15 | balrog | { |
3482 | 66450b15 | balrog | s->pwl.output = 0;
|
3483 | 66450b15 | balrog | s->pwl.level = 0;
|
3484 | 66450b15 | balrog | s->pwl.enable = 0;
|
3485 | 66450b15 | balrog | s->pwl.clk = 1;
|
3486 | 66450b15 | balrog | omap_pwl_update(s); |
3487 | 66450b15 | balrog | } |
3488 | 66450b15 | balrog | |
3489 | 66450b15 | balrog | static void omap_pwl_clk_update(void *opaque, int line, int on) |
3490 | 66450b15 | balrog | { |
3491 | 66450b15 | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; |
3492 | 66450b15 | balrog | |
3493 | 66450b15 | balrog | s->pwl.clk = on; |
3494 | 66450b15 | balrog | omap_pwl_update(s); |
3495 | 66450b15 | balrog | } |
3496 | 66450b15 | balrog | |
3497 | 66450b15 | balrog | static void omap_pwl_init(target_phys_addr_t base, struct omap_mpu_state_s *s, |
3498 | 66450b15 | balrog | omap_clk clk) |
3499 | 66450b15 | balrog | { |
3500 | 66450b15 | balrog | int iomemtype;
|
3501 | 66450b15 | balrog | |
3502 | 66450b15 | balrog | s->pwl.base = base; |
3503 | 66450b15 | balrog | omap_pwl_reset(s); |
3504 | 66450b15 | balrog | |
3505 | 66450b15 | balrog | iomemtype = cpu_register_io_memory(0, omap_pwl_readfn,
|
3506 | 66450b15 | balrog | omap_pwl_writefn, s); |
3507 | 66450b15 | balrog | cpu_register_physical_memory(s->pwl.base, 0x800, iomemtype);
|
3508 | 66450b15 | balrog | |
3509 | 66450b15 | balrog | omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]); |
3510 | 66450b15 | balrog | } |
3511 | 66450b15 | balrog | |
3512 | c3d2689d | balrog | /* General chip reset */
|
3513 | c3d2689d | balrog | static void omap_mpu_reset(void *opaque) |
3514 | c3d2689d | balrog | { |
3515 | c3d2689d | balrog | struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque; |
3516 | c3d2689d | balrog | |
3517 | c3d2689d | balrog | omap_clkm_reset(mpu); |
3518 | c3d2689d | balrog | omap_inth_reset(mpu->ih[0]);
|
3519 | c3d2689d | balrog | omap_inth_reset(mpu->ih[1]);
|
3520 | c3d2689d | balrog | omap_dma_reset(mpu->dma); |
3521 | c3d2689d | balrog | omap_mpu_timer_reset(mpu->timer[0]);
|
3522 | c3d2689d | balrog | omap_mpu_timer_reset(mpu->timer[1]);
|
3523 | c3d2689d | balrog | omap_mpu_timer_reset(mpu->timer[2]);
|
3524 | c3d2689d | balrog | omap_wd_timer_reset(mpu->wdt); |
3525 | c3d2689d | balrog | omap_os_timer_reset(mpu->os_timer); |
3526 | c3d2689d | balrog | omap_lcdc_reset(mpu->lcd); |
3527 | c3d2689d | balrog | omap_ulpd_pm_reset(mpu); |
3528 | c3d2689d | balrog | omap_pin_cfg_reset(mpu); |
3529 | c3d2689d | balrog | omap_mpui_reset(mpu); |
3530 | c3d2689d | balrog | omap_tipb_bridge_reset(mpu->private_tipb); |
3531 | c3d2689d | balrog | omap_tipb_bridge_reset(mpu->public_tipb); |
3532 | c3d2689d | balrog | omap_dpll_reset(&mpu->dpll[0]);
|
3533 | c3d2689d | balrog | omap_dpll_reset(&mpu->dpll[1]);
|
3534 | c3d2689d | balrog | omap_dpll_reset(&mpu->dpll[2]);
|
3535 | d951f6ff | balrog | omap_uart_reset(mpu->uart[0]);
|
3536 | d951f6ff | balrog | omap_uart_reset(mpu->uart[1]);
|
3537 | d951f6ff | balrog | omap_uart_reset(mpu->uart[2]);
|
3538 | b30bb3a2 | balrog | omap_mmc_reset(mpu->mmc); |
3539 | fe71e81a | balrog | omap_mpuio_reset(mpu->mpuio); |
3540 | 64330148 | balrog | omap_gpio_reset(mpu->gpio); |
3541 | d951f6ff | balrog | omap_uwire_reset(mpu->microwire); |
3542 | 66450b15 | balrog | omap_pwl_reset(mpu); |
3543 | c3d2689d | balrog | cpu_reset(mpu->env); |
3544 | c3d2689d | balrog | } |
3545 | c3d2689d | balrog | |
3546 | c3d2689d | balrog | static void omap_mpu_wakeup(void *opaque, int irq, int req) |
3547 | c3d2689d | balrog | { |
3548 | c3d2689d | balrog | struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque; |
3549 | c3d2689d | balrog | |
3550 | fe71e81a | balrog | if (mpu->env->halted)
|
3551 | fe71e81a | balrog | cpu_interrupt(mpu->env, CPU_INTERRUPT_EXITTB); |
3552 | c3d2689d | balrog | } |
3553 | c3d2689d | balrog | |
3554 | c3d2689d | balrog | struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size, |
3555 | c3d2689d | balrog | DisplayState *ds, const char *core) |
3556 | c3d2689d | balrog | { |
3557 | c3d2689d | balrog | struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) |
3558 | c3d2689d | balrog | qemu_mallocz(sizeof(struct omap_mpu_state_s)); |
3559 | c3d2689d | balrog | ram_addr_t imif_base, emiff_base; |
3560 | c3d2689d | balrog | |
3561 | c3d2689d | balrog | /* Core */
|
3562 | c3d2689d | balrog | s->mpu_model = omap310; |
3563 | c3d2689d | balrog | s->env = cpu_init(); |
3564 | c3d2689d | balrog | s->sdram_size = sdram_size; |
3565 | c3d2689d | balrog | s->sram_size = OMAP15XX_SRAM_SIZE; |
3566 | c3d2689d | balrog | |
3567 | c3d2689d | balrog | cpu_arm_set_model(s->env, core ?: "ti925t");
|
3568 | c3d2689d | balrog | |
3569 | fe71e81a | balrog | s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0]; |
3570 | fe71e81a | balrog | |
3571 | c3d2689d | balrog | /* Clocks */
|
3572 | c3d2689d | balrog | omap_clk_init(s); |
3573 | c3d2689d | balrog | |
3574 | c3d2689d | balrog | /* Memory-mapped stuff */
|
3575 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_EMIFF_BASE, s->sdram_size, |
3576 | c3d2689d | balrog | (emiff_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM); |
3577 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_IMIF_BASE, s->sram_size, |
3578 | c3d2689d | balrog | (imif_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM); |
3579 | c3d2689d | balrog | |
3580 | c3d2689d | balrog | omap_clkm_init(0xfffece00, 0xe1008000, s); |
3581 | c3d2689d | balrog | |
3582 | c3d2689d | balrog | s->ih[0] = omap_inth_init(0xfffecb00, 0x100, |
3583 | c3d2689d | balrog | arm_pic_init_cpu(s->env), |
3584 | c3d2689d | balrog | omap_findclk(s, "arminth_ck"));
|
3585 | c3d2689d | balrog | s->ih[1] = omap_inth_init(0xfffe0000, 0x800, |
3586 | c3d2689d | balrog | &s->ih[0]->pins[OMAP_INT_15XX_IH2_IRQ],
|
3587 | c3d2689d | balrog | omap_findclk(s, "arminth_ck"));
|
3588 | c3d2689d | balrog | s->irq[0] = s->ih[0]->pins; |
3589 | c3d2689d | balrog | s->irq[1] = s->ih[1]->pins; |
3590 | c3d2689d | balrog | |
3591 | c3d2689d | balrog | s->dma = omap_dma_init(0xfffed800, s->irq[0], s, |
3592 | c3d2689d | balrog | omap_findclk(s, "dma_ck"));
|
3593 | c3d2689d | balrog | s->port[emiff ].addr_valid = omap_validate_emiff_addr; |
3594 | c3d2689d | balrog | s->port[emifs ].addr_valid = omap_validate_emifs_addr; |
3595 | c3d2689d | balrog | s->port[imif ].addr_valid = omap_validate_imif_addr; |
3596 | c3d2689d | balrog | s->port[tipb ].addr_valid = omap_validate_tipb_addr; |
3597 | c3d2689d | balrog | s->port[local ].addr_valid = omap_validate_local_addr; |
3598 | c3d2689d | balrog | s->port[tipb_mpui].addr_valid = omap_validate_tipb_mpui_addr; |
3599 | c3d2689d | balrog | |
3600 | c3d2689d | balrog | s->timer[0] = omap_mpu_timer_init(0xfffec500, |
3601 | c3d2689d | balrog | s->irq[0][OMAP_INT_TIMER1],
|
3602 | c3d2689d | balrog | omap_findclk(s, "mputim_ck"));
|
3603 | c3d2689d | balrog | s->timer[1] = omap_mpu_timer_init(0xfffec600, |
3604 | c3d2689d | balrog | s->irq[0][OMAP_INT_TIMER2],
|
3605 | c3d2689d | balrog | omap_findclk(s, "mputim_ck"));
|
3606 | c3d2689d | balrog | s->timer[2] = omap_mpu_timer_init(0xfffec700, |
3607 | c3d2689d | balrog | s->irq[0][OMAP_INT_TIMER3],
|
3608 | c3d2689d | balrog | omap_findclk(s, "mputim_ck"));
|
3609 | c3d2689d | balrog | |
3610 | c3d2689d | balrog | s->wdt = omap_wd_timer_init(0xfffec800,
|
3611 | c3d2689d | balrog | s->irq[0][OMAP_INT_WD_TIMER],
|
3612 | c3d2689d | balrog | omap_findclk(s, "armwdt_ck"));
|
3613 | c3d2689d | balrog | |
3614 | c3d2689d | balrog | s->os_timer = omap_os_timer_init(0xfffb9000,
|
3615 | c3d2689d | balrog | s->irq[1][OMAP_INT_OS_TIMER],
|
3616 | c3d2689d | balrog | omap_findclk(s, "clk32-kHz"));
|
3617 | c3d2689d | balrog | |
3618 | c3d2689d | balrog | s->lcd = omap_lcdc_init(0xfffec000, s->irq[0][OMAP_INT_LCD_CTRL], |
3619 | c3d2689d | balrog | &s->dma->lcd_ch, ds, imif_base, emiff_base, |
3620 | c3d2689d | balrog | omap_findclk(s, "lcd_ck"));
|
3621 | c3d2689d | balrog | |
3622 | c3d2689d | balrog | omap_ulpd_pm_init(0xfffe0800, s);
|
3623 | c3d2689d | balrog | omap_pin_cfg_init(0xfffe1000, s);
|
3624 | c3d2689d | balrog | omap_id_init(s); |
3625 | c3d2689d | balrog | |
3626 | c3d2689d | balrog | omap_mpui_init(0xfffec900, s);
|
3627 | c3d2689d | balrog | |
3628 | c3d2689d | balrog | s->private_tipb = omap_tipb_bridge_init(0xfffeca00,
|
3629 | c3d2689d | balrog | s->irq[0][OMAP_INT_BRIDGE_PRIV],
|
3630 | c3d2689d | balrog | omap_findclk(s, "tipb_ck"));
|
3631 | c3d2689d | balrog | s->public_tipb = omap_tipb_bridge_init(0xfffed300,
|
3632 | c3d2689d | balrog | s->irq[0][OMAP_INT_BRIDGE_PUB],
|
3633 | c3d2689d | balrog | omap_findclk(s, "tipb_ck"));
|
3634 | c3d2689d | balrog | |
3635 | c3d2689d | balrog | omap_tcmi_init(0xfffecc00, s);
|
3636 | c3d2689d | balrog | |
3637 | d951f6ff | balrog | s->uart[0] = omap_uart_init(0xfffb0000, s->irq[1][OMAP_INT_UART1], |
3638 | c3d2689d | balrog | omap_findclk(s, "uart1_ck"),
|
3639 | c3d2689d | balrog | serial_hds[0]);
|
3640 | d951f6ff | balrog | s->uart[1] = omap_uart_init(0xfffb0800, s->irq[1][OMAP_INT_UART2], |
3641 | c3d2689d | balrog | omap_findclk(s, "uart2_ck"),
|
3642 | c3d2689d | balrog | serial_hds[0] ? serial_hds[1] : 0); |
3643 | d951f6ff | balrog | s->uart[2] = omap_uart_init(0xe1019800, s->irq[0][OMAP_INT_UART3], |
3644 | c3d2689d | balrog | omap_findclk(s, "uart3_ck"),
|
3645 | c3d2689d | balrog | serial_hds[0] && serial_hds[1] ? serial_hds[2] : 0); |
3646 | c3d2689d | balrog | |
3647 | c3d2689d | balrog | omap_dpll_init(&s->dpll[0], 0xfffecf00, omap_findclk(s, "dpll1")); |
3648 | c3d2689d | balrog | omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2")); |
3649 | c3d2689d | balrog | omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3")); |
3650 | c3d2689d | balrog | |
3651 | b30bb3a2 | balrog | s->mmc = omap_mmc_init(0xfffb7800, s->irq[1][OMAP_INT_OQN], |
3652 | b30bb3a2 | balrog | &s->drq[OMAP_DMA_MMC_TX], omap_findclk(s, "mmc_ck"));
|
3653 | b30bb3a2 | balrog | |
3654 | fe71e81a | balrog | s->mpuio = omap_mpuio_init(0xfffb5000,
|
3655 | fe71e81a | balrog | s->irq[1][OMAP_INT_KEYBOARD], s->irq[1][OMAP_INT_MPUIO], |
3656 | fe71e81a | balrog | s->wakeup, omap_findclk(s, "clk32-kHz"));
|
3657 | fe71e81a | balrog | |
3658 | 3efda49d | balrog | s->gpio = omap_gpio_init(0xfffce000, s->irq[0][OMAP_INT_GPIO_BANK1], |
3659 | 66450b15 | balrog | omap_findclk(s, "arm_gpio_ck"));
|
3660 | 64330148 | balrog | |
3661 | d951f6ff | balrog | s->microwire = omap_uwire_init(0xfffb3000, &s->irq[1][OMAP_INT_uWireTX], |
3662 | d951f6ff | balrog | s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
|
3663 | d951f6ff | balrog | |
3664 | 66450b15 | balrog | omap_pwl_init(0xfffb5800, s, omap_findclk(s, "clk32-kHz")); |
3665 | 66450b15 | balrog | |
3666 | c3d2689d | balrog | qemu_register_reset(omap_mpu_reset, s); |
3667 | c3d2689d | balrog | |
3668 | c3d2689d | balrog | return s;
|
3669 | c3d2689d | balrog | } |