2 * TI OMAP processors emulation.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include "qemu-timer.h"
26 #include "qemu-char.h"
28 /* We use pc-style serial ports. */
31 /* Should signal the TCMI/GPMC */
32 uint32_t omap_badwidth_read8(void *opaque
, target_phys_addr_t addr
)
37 cpu_physical_memory_read(addr
, (void *) &ret
, 1);
41 void omap_badwidth_write8(void *opaque
, target_phys_addr_t addr
,
47 cpu_physical_memory_write(addr
, (void *) &val8
, 1);
50 uint32_t omap_badwidth_read16(void *opaque
, target_phys_addr_t addr
)
55 cpu_physical_memory_read(addr
, (void *) &ret
, 2);
59 void omap_badwidth_write16(void *opaque
, target_phys_addr_t addr
,
62 uint16_t val16
= value
;
65 cpu_physical_memory_write(addr
, (void *) &val16
, 2);
68 uint32_t omap_badwidth_read32(void *opaque
, target_phys_addr_t addr
)
73 cpu_physical_memory_read(addr
, (void *) &ret
, 4);
77 void omap_badwidth_write32(void *opaque
, target_phys_addr_t addr
,
81 cpu_physical_memory_write(addr
, (void *) &value
, 4);
84 /* Interrupt Handlers */
85 struct omap_intr_handler_bank_s
{
92 unsigned char priority
[32];
95 struct omap_intr_handler_s
{
97 qemu_irq parent_intr
[2];
98 target_phys_addr_t base
;
107 struct omap_intr_handler_bank_s bank
[];
110 static void omap_inth_sir_update(struct omap_intr_handler_s
*s
, int is_fiq
)
112 int i
, j
, sir_intr
, p_intr
, p
, f
;
117 /* Find the interrupt line with the highest dynamic priority.
118 * Note: 0 denotes the hightest priority.
119 * If all interrupts have the same priority, the default order is IRQ_N,
120 * IRQ_N-1,...,IRQ_0. */
121 for (j
= 0; j
< s
->nbanks
; ++j
) {
122 level
= s
->bank
[j
].irqs
& ~s
->bank
[j
].mask
&
123 (is_fiq
? s
->bank
[j
].fiq
: ~s
->bank
[j
].fiq
);
124 for (f
= ffs(level
), i
= f
- 1, level
>>= f
- 1; f
; i
+= f
,
126 p
= s
->bank
[j
].priority
[i
];
129 sir_intr
= 32 * j
+ i
;
134 s
->sir_intr
[is_fiq
] = sir_intr
;
137 static inline void omap_inth_update(struct omap_intr_handler_s
*s
, int is_fiq
)
140 uint32_t has_intr
= 0;
142 for (i
= 0; i
< s
->nbanks
; ++i
)
143 has_intr
|= s
->bank
[i
].irqs
& ~s
->bank
[i
].mask
&
144 (is_fiq
? s
->bank
[i
].fiq
: ~s
->bank
[i
].fiq
);
146 if (s
->new_agr
[is_fiq
] & has_intr
& s
->mask
) {
147 s
->new_agr
[is_fiq
] = 0;
148 omap_inth_sir_update(s
, is_fiq
);
149 qemu_set_irq(s
->parent_intr
[is_fiq
], 1);
153 #define INT_FALLING_EDGE 0
154 #define INT_LOW_LEVEL 1
156 static void omap_set_intr(void *opaque
, int irq
, int req
)
158 struct omap_intr_handler_s
*ih
= (struct omap_intr_handler_s
*) opaque
;
161 struct omap_intr_handler_bank_s
*bank
= &ih
->bank
[irq
>> 5];
165 rise
= ~bank
->irqs
& (1 << n
);
166 if (~bank
->sens_edge
& (1 << n
))
167 rise
&= ~bank
->inputs
;
169 bank
->inputs
|= (1 << n
);
172 omap_inth_update(ih
, 0);
173 omap_inth_update(ih
, 1);
176 rise
= bank
->sens_edge
& bank
->irqs
& (1 << n
);
178 bank
->inputs
&= ~(1 << n
);
182 /* Simplified version with no edge detection */
183 static void omap_set_intr_noedge(void *opaque
, int irq
, int req
)
185 struct omap_intr_handler_s
*ih
= (struct omap_intr_handler_s
*) opaque
;
188 struct omap_intr_handler_bank_s
*bank
= &ih
->bank
[irq
>> 5];
192 rise
= ~bank
->inputs
& (1 << n
);
194 bank
->irqs
|= bank
->inputs
|= rise
;
195 omap_inth_update(ih
, 0);
196 omap_inth_update(ih
, 1);
199 bank
->irqs
= (bank
->inputs
&= ~(1 << n
)) | bank
->swi
;
202 static uint32_t omap_inth_read(void *opaque
, target_phys_addr_t addr
)
204 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
205 int i
, offset
= addr
- s
->base
;
206 int bank_no
= offset
>> 8;
208 struct omap_intr_handler_bank_s
*bank
= &s
->bank
[bank_no
];
218 case 0x10: /* SIR_IRQ_CODE */
219 case 0x14: /* SIR_FIQ_CODE */
222 line_no
= s
->sir_intr
[(offset
- 0x10) >> 2];
223 bank
= &s
->bank
[line_no
>> 5];
225 if (((bank
->sens_edge
>> i
) & 1) == INT_FALLING_EDGE
)
226 bank
->irqs
&= ~(1 << i
);
229 case 0x18: /* CONTROL_REG */
234 case 0x1c: /* ILR0 */
235 case 0x20: /* ILR1 */
236 case 0x24: /* ILR2 */
237 case 0x28: /* ILR3 */
238 case 0x2c: /* ILR4 */
239 case 0x30: /* ILR5 */
240 case 0x34: /* ILR6 */
241 case 0x38: /* ILR7 */
242 case 0x3c: /* ILR8 */
243 case 0x40: /* ILR9 */
244 case 0x44: /* ILR10 */
245 case 0x48: /* ILR11 */
246 case 0x4c: /* ILR12 */
247 case 0x50: /* ILR13 */
248 case 0x54: /* ILR14 */
249 case 0x58: /* ILR15 */
250 case 0x5c: /* ILR16 */
251 case 0x60: /* ILR17 */
252 case 0x64: /* ILR18 */
253 case 0x68: /* ILR19 */
254 case 0x6c: /* ILR20 */
255 case 0x70: /* ILR21 */
256 case 0x74: /* ILR22 */
257 case 0x78: /* ILR23 */
258 case 0x7c: /* ILR24 */
259 case 0x80: /* ILR25 */
260 case 0x84: /* ILR26 */
261 case 0x88: /* ILR27 */
262 case 0x8c: /* ILR28 */
263 case 0x90: /* ILR29 */
264 case 0x94: /* ILR30 */
265 case 0x98: /* ILR31 */
266 i
= (offset
- 0x1c) >> 2;
267 return (bank
->priority
[i
] << 2) |
268 (((bank
->sens_edge
>> i
) & 1) << 1) |
269 ((bank
->fiq
>> i
) & 1);
279 static void omap_inth_write(void *opaque
, target_phys_addr_t addr
,
282 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
283 int i
, offset
= addr
- s
->base
;
284 int bank_no
= offset
>> 8;
285 struct omap_intr_handler_bank_s
*bank
= &s
->bank
[bank_no
];
290 /* Important: ignore the clearing if the IRQ is level-triggered and
291 the input bit is 1 */
292 bank
->irqs
&= value
| (bank
->inputs
& bank
->sens_edge
);
297 omap_inth_update(s
, 0);
298 omap_inth_update(s
, 1);
301 case 0x10: /* SIR_IRQ_CODE */
302 case 0x14: /* SIR_FIQ_CODE */
306 case 0x18: /* CONTROL_REG */
310 qemu_set_irq(s
->parent_intr
[1], 0);
312 omap_inth_update(s
, 1);
315 qemu_set_irq(s
->parent_intr
[0], 0);
317 omap_inth_update(s
, 0);
321 case 0x1c: /* ILR0 */
322 case 0x20: /* ILR1 */
323 case 0x24: /* ILR2 */
324 case 0x28: /* ILR3 */
325 case 0x2c: /* ILR4 */
326 case 0x30: /* ILR5 */
327 case 0x34: /* ILR6 */
328 case 0x38: /* ILR7 */
329 case 0x3c: /* ILR8 */
330 case 0x40: /* ILR9 */
331 case 0x44: /* ILR10 */
332 case 0x48: /* ILR11 */
333 case 0x4c: /* ILR12 */
334 case 0x50: /* ILR13 */
335 case 0x54: /* ILR14 */
336 case 0x58: /* ILR15 */
337 case 0x5c: /* ILR16 */
338 case 0x60: /* ILR17 */
339 case 0x64: /* ILR18 */
340 case 0x68: /* ILR19 */
341 case 0x6c: /* ILR20 */
342 case 0x70: /* ILR21 */
343 case 0x74: /* ILR22 */
344 case 0x78: /* ILR23 */
345 case 0x7c: /* ILR24 */
346 case 0x80: /* ILR25 */
347 case 0x84: /* ILR26 */
348 case 0x88: /* ILR27 */
349 case 0x8c: /* ILR28 */
350 case 0x90: /* ILR29 */
351 case 0x94: /* ILR30 */
352 case 0x98: /* ILR31 */
353 i
= (offset
- 0x1c) >> 2;
354 bank
->priority
[i
] = (value
>> 2) & 0x1f;
355 bank
->sens_edge
&= ~(1 << i
);
356 bank
->sens_edge
|= ((value
>> 1) & 1) << i
;
357 bank
->fiq
&= ~(1 << i
);
358 bank
->fiq
|= (value
& 1) << i
;
362 for (i
= 0; i
< 32; i
++)
363 if (value
& (1 << i
)) {
364 omap_set_intr(s
, 32 * bank_no
+ i
, 1);
372 static CPUReadMemoryFunc
*omap_inth_readfn
[] = {
373 omap_badwidth_read32
,
374 omap_badwidth_read32
,
378 static CPUWriteMemoryFunc
*omap_inth_writefn
[] = {
384 void omap_inth_reset(struct omap_intr_handler_s
*s
)
388 for (i
= 0; i
< s
->nbanks
; ++i
){
389 s
->bank
[i
].irqs
= 0x00000000;
390 s
->bank
[i
].mask
= 0xffffffff;
391 s
->bank
[i
].sens_edge
= 0x00000000;
392 s
->bank
[i
].fiq
= 0x00000000;
393 s
->bank
[i
].inputs
= 0x00000000;
394 s
->bank
[i
].swi
= 0x00000000;
395 memset(s
->bank
[i
].priority
, 0, sizeof(s
->bank
[i
].priority
));
398 s
->bank
[i
].sens_edge
= 0xffffffff;
408 qemu_set_irq(s
->parent_intr
[0], 0);
409 qemu_set_irq(s
->parent_intr
[1], 0);
412 struct omap_intr_handler_s
*omap_inth_init(target_phys_addr_t base
,
413 unsigned long size
, unsigned char nbanks
, qemu_irq
**pins
,
414 qemu_irq parent_irq
, qemu_irq parent_fiq
, omap_clk clk
)
417 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*)
418 qemu_mallocz(sizeof(struct omap_intr_handler_s
) +
419 sizeof(struct omap_intr_handler_bank_s
) * nbanks
);
421 s
->parent_intr
[0] = parent_irq
;
422 s
->parent_intr
[1] = parent_fiq
;
425 s
->pins
= qemu_allocate_irqs(omap_set_intr
, s
, nbanks
* 32);
431 iomemtype
= cpu_register_io_memory(0, omap_inth_readfn
,
432 omap_inth_writefn
, s
);
433 cpu_register_physical_memory(s
->base
, size
, iomemtype
);
438 static uint32_t omap2_inth_read(void *opaque
, target_phys_addr_t addr
)
440 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
441 int offset
= addr
- s
->base
;
442 int bank_no
, line_no
;
443 struct omap_intr_handler_bank_s
*bank
= 0;
445 if ((offset
& 0xf80) == 0x80) {
446 bank_no
= (offset
& 0x60) >> 5;
447 if (bank_no
< s
->nbanks
) {
449 bank
= &s
->bank
[bank_no
];
454 case 0x00: /* INTC_REVISION */
457 case 0x10: /* INTC_SYSCONFIG */
458 return (s
->autoidle
>> 2) & 1;
460 case 0x14: /* INTC_SYSSTATUS */
461 return 1; /* RESETDONE */
463 case 0x40: /* INTC_SIR_IRQ */
464 return s
->sir_intr
[0];
466 case 0x44: /* INTC_SIR_FIQ */
467 return s
->sir_intr
[1];
469 case 0x48: /* INTC_CONTROL */
470 return (!s
->mask
) << 2; /* GLOBALMASK */
472 case 0x4c: /* INTC_PROTECTION */
475 case 0x50: /* INTC_IDLE */
476 return s
->autoidle
& 3;
478 /* Per-bank registers */
479 case 0x80: /* INTC_ITR */
482 case 0x84: /* INTC_MIR */
485 case 0x88: /* INTC_MIR_CLEAR */
486 case 0x8c: /* INTC_MIR_SET */
489 case 0x90: /* INTC_ISR_SET */
492 case 0x94: /* INTC_ISR_CLEAR */
495 case 0x98: /* INTC_PENDING_IRQ */
496 return bank
->irqs
& ~bank
->mask
& ~bank
->fiq
;
498 case 0x9c: /* INTC_PENDING_FIQ */
499 return bank
->irqs
& ~bank
->mask
& bank
->fiq
;
501 /* Per-line registers */
502 case 0x100 ... 0x300: /* INTC_ILR */
503 bank_no
= (offset
- 0x100) >> 7;
504 if (bank_no
> s
->nbanks
)
506 bank
= &s
->bank
[bank_no
];
507 line_no
= (offset
& 0x7f) >> 2;
508 return (bank
->priority
[line_no
] << 2) |
509 ((bank
->fiq
>> line_no
) & 1);
515 static void omap2_inth_write(void *opaque
, target_phys_addr_t addr
,
518 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
519 int offset
= addr
- s
->base
;
520 int bank_no
, line_no
;
521 struct omap_intr_handler_bank_s
*bank
= 0;
523 if ((offset
& 0xf80) == 0x80) {
524 bank_no
= (offset
& 0x60) >> 5;
525 if (bank_no
< s
->nbanks
) {
527 bank
= &s
->bank
[bank_no
];
532 case 0x10: /* INTC_SYSCONFIG */
534 s
->autoidle
|= (value
& 1) << 2;
535 if (value
& 2) /* SOFTRESET */
539 case 0x48: /* INTC_CONTROL */
540 s
->mask
= (value
& 4) ? 0 : ~0; /* GLOBALMASK */
541 if (value
& 2) { /* NEWFIQAGR */
542 qemu_set_irq(s
->parent_intr
[1], 0);
544 omap_inth_update(s
, 1);
546 if (value
& 1) { /* NEWIRQAGR */
547 qemu_set_irq(s
->parent_intr
[0], 0);
549 omap_inth_update(s
, 0);
553 case 0x4c: /* INTC_PROTECTION */
554 /* TODO: Make a bitmap (or sizeof(char)map) of access privileges
555 * for every register, see Chapter 3 and 4 for privileged mode. */
557 fprintf(stderr
, "%s: protection mode enable attempt\n",
561 case 0x50: /* INTC_IDLE */
563 s
->autoidle
|= value
& 3;
566 /* Per-bank registers */
567 case 0x84: /* INTC_MIR */
569 omap_inth_update(s
, 0);
570 omap_inth_update(s
, 1);
573 case 0x88: /* INTC_MIR_CLEAR */
574 bank
->mask
&= ~value
;
575 omap_inth_update(s
, 0);
576 omap_inth_update(s
, 1);
579 case 0x8c: /* INTC_MIR_SET */
583 case 0x90: /* INTC_ISR_SET */
584 bank
->irqs
|= bank
->swi
|= value
;
585 omap_inth_update(s
, 0);
586 omap_inth_update(s
, 1);
589 case 0x94: /* INTC_ISR_CLEAR */
591 bank
->irqs
= bank
->swi
& bank
->inputs
;
594 /* Per-line registers */
595 case 0x100 ... 0x300: /* INTC_ILR */
596 bank_no
= (offset
- 0x100) >> 7;
597 if (bank_no
> s
->nbanks
)
599 bank
= &s
->bank
[bank_no
];
600 line_no
= (offset
& 0x7f) >> 2;
601 bank
->priority
[line_no
] = (value
>> 2) & 0x3f;
602 bank
->fiq
&= ~(1 << line_no
);
603 bank
->fiq
|= (value
& 1) << line_no
;
606 case 0x00: /* INTC_REVISION */
607 case 0x14: /* INTC_SYSSTATUS */
608 case 0x40: /* INTC_SIR_IRQ */
609 case 0x44: /* INTC_SIR_FIQ */
610 case 0x80: /* INTC_ITR */
611 case 0x98: /* INTC_PENDING_IRQ */
612 case 0x9c: /* INTC_PENDING_FIQ */
619 static CPUReadMemoryFunc
*omap2_inth_readfn
[] = {
620 omap_badwidth_read32
,
621 omap_badwidth_read32
,
625 static CPUWriteMemoryFunc
*omap2_inth_writefn
[] = {
631 struct omap_intr_handler_s
*omap2_inth_init(target_phys_addr_t base
,
632 int size
, int nbanks
, qemu_irq
**pins
,
633 qemu_irq parent_irq
, qemu_irq parent_fiq
,
634 omap_clk fclk
, omap_clk iclk
)
637 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*)
638 qemu_mallocz(sizeof(struct omap_intr_handler_s
) +
639 sizeof(struct omap_intr_handler_bank_s
) * nbanks
);
641 s
->parent_intr
[0] = parent_irq
;
642 s
->parent_intr
[1] = parent_fiq
;
646 s
->pins
= qemu_allocate_irqs(omap_set_intr_noedge
, s
, nbanks
* 32);
652 iomemtype
= cpu_register_io_memory(0, omap2_inth_readfn
,
653 omap2_inth_writefn
, s
);
654 cpu_register_physical_memory(s
->base
, size
, iomemtype
);
660 struct omap_mpu_timer_s
{
663 target_phys_addr_t base
;
677 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
679 uint64_t distance
= qemu_get_clock(vm_clock
) - timer
->time
;
681 if (timer
->st
&& timer
->enable
&& timer
->rate
)
682 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
683 timer
->rate
, ticks_per_sec
);
688 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
690 timer
->val
= omap_timer_read(timer
);
691 timer
->time
= qemu_get_clock(vm_clock
);
694 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
698 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
699 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
700 expires
= muldiv64((uint64_t) timer
->val
<< (timer
->ptv
+ 1),
701 ticks_per_sec
, timer
->rate
);
703 /* If timer expiry would be sooner than in about 1 ms and
704 * auto-reload isn't set, then fire immediately. This is a hack
705 * to make systems like PalmOS run in acceptable time. PalmOS
706 * sets the interval to a very low value and polls the status bit
707 * in a busy loop when it wants to sleep just a couple of CPU
709 if (expires
> (ticks_per_sec
>> 10) || timer
->ar
)
710 qemu_mod_timer(timer
->timer
, timer
->time
+ expires
);
715 /* Edge-triggered irq */
716 qemu_irq_pulse(timer
->irq
);
719 qemu_del_timer(timer
->timer
);
722 static void omap_timer_tick(void *opaque
)
724 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
725 omap_timer_sync(timer
);
733 /* Edge-triggered irq */
734 qemu_irq_pulse(timer
->irq
);
735 omap_timer_update(timer
);
738 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
740 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
742 omap_timer_sync(timer
);
743 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
744 omap_timer_update(timer
);
747 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
749 omap_clk_adduser(timer
->clk
,
750 qemu_allocate_irqs(omap_timer_clk_update
, timer
, 1)[0]);
751 timer
->rate
= omap_clk_getrate(timer
->clk
);
754 static uint32_t omap_mpu_timer_read(void *opaque
, target_phys_addr_t addr
)
756 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
757 int offset
= addr
- s
->base
;
760 case 0x00: /* CNTL_TIMER */
761 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
763 case 0x04: /* LOAD_TIM */
766 case 0x08: /* READ_TIM */
767 return omap_timer_read(s
);
774 static void omap_mpu_timer_write(void *opaque
, target_phys_addr_t addr
,
777 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
778 int offset
= addr
- s
->base
;
781 case 0x00: /* CNTL_TIMER */
783 s
->enable
= (value
>> 5) & 1;
784 s
->ptv
= (value
>> 2) & 7;
785 s
->ar
= (value
>> 1) & 1;
787 omap_timer_update(s
);
790 case 0x04: /* LOAD_TIM */
791 s
->reset_val
= value
;
794 case 0x08: /* READ_TIM */
803 static CPUReadMemoryFunc
*omap_mpu_timer_readfn
[] = {
804 omap_badwidth_read32
,
805 omap_badwidth_read32
,
809 static CPUWriteMemoryFunc
*omap_mpu_timer_writefn
[] = {
810 omap_badwidth_write32
,
811 omap_badwidth_write32
,
812 omap_mpu_timer_write
,
815 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
817 qemu_del_timer(s
->timer
);
819 s
->reset_val
= 31337;
827 struct omap_mpu_timer_s
*omap_mpu_timer_init(target_phys_addr_t base
,
828 qemu_irq irq
, omap_clk clk
)
831 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*)
832 qemu_mallocz(sizeof(struct omap_mpu_timer_s
));
837 s
->timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, s
);
838 omap_mpu_timer_reset(s
);
839 omap_timer_clk_setup(s
);
841 iomemtype
= cpu_register_io_memory(0, omap_mpu_timer_readfn
,
842 omap_mpu_timer_writefn
, s
);
843 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
849 struct omap_watchdog_timer_s
{
850 struct omap_mpu_timer_s timer
;
857 static uint32_t omap_wd_timer_read(void *opaque
, target_phys_addr_t addr
)
859 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
860 int offset
= addr
- s
->timer
.base
;
863 case 0x00: /* CNTL_TIMER */
864 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
865 (s
->timer
.st
<< 7) | (s
->free
<< 1);
867 case 0x04: /* READ_TIMER */
868 return omap_timer_read(&s
->timer
);
870 case 0x08: /* TIMER_MODE */
871 return s
->mode
<< 15;
878 static void omap_wd_timer_write(void *opaque
, target_phys_addr_t addr
,
881 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
882 int offset
= addr
- s
->timer
.base
;
885 case 0x00: /* CNTL_TIMER */
886 omap_timer_sync(&s
->timer
);
887 s
->timer
.ptv
= (value
>> 9) & 7;
888 s
->timer
.ar
= (value
>> 8) & 1;
889 s
->timer
.st
= (value
>> 7) & 1;
890 s
->free
= (value
>> 1) & 1;
891 omap_timer_update(&s
->timer
);
894 case 0x04: /* LOAD_TIMER */
895 s
->timer
.reset_val
= value
& 0xffff;
898 case 0x08: /* TIMER_MODE */
899 if (!s
->mode
&& ((value
>> 15) & 1))
900 omap_clk_get(s
->timer
.clk
);
901 s
->mode
|= (value
>> 15) & 1;
902 if (s
->last_wr
== 0xf5) {
903 if ((value
& 0xff) == 0xa0) {
906 omap_clk_put(s
->timer
.clk
);
909 /* XXX: on T|E hardware somehow this has no effect,
910 * on Zire 71 it works as specified. */
912 qemu_system_reset_request();
915 s
->last_wr
= value
& 0xff;
923 static CPUReadMemoryFunc
*omap_wd_timer_readfn
[] = {
924 omap_badwidth_read16
,
926 omap_badwidth_read16
,
929 static CPUWriteMemoryFunc
*omap_wd_timer_writefn
[] = {
930 omap_badwidth_write16
,
932 omap_badwidth_write16
,
935 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
937 qemu_del_timer(s
->timer
.timer
);
939 omap_clk_get(s
->timer
.clk
);
945 s
->timer
.reset_val
= 0xffff;
950 omap_timer_update(&s
->timer
);
953 struct omap_watchdog_timer_s
*omap_wd_timer_init(target_phys_addr_t base
,
954 qemu_irq irq
, omap_clk clk
)
957 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*)
958 qemu_mallocz(sizeof(struct omap_watchdog_timer_s
));
962 s
->timer
.base
= base
;
963 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
964 omap_wd_timer_reset(s
);
965 omap_timer_clk_setup(&s
->timer
);
967 iomemtype
= cpu_register_io_memory(0, omap_wd_timer_readfn
,
968 omap_wd_timer_writefn
, s
);
969 cpu_register_physical_memory(s
->timer
.base
, 0x100, iomemtype
);
975 struct omap_32khz_timer_s
{
976 struct omap_mpu_timer_s timer
;
979 static uint32_t omap_os_timer_read(void *opaque
, target_phys_addr_t addr
)
981 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
982 int offset
= addr
& OMAP_MPUI_REG_MASK
;
986 return s
->timer
.reset_val
;
989 return omap_timer_read(&s
->timer
);
992 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
1001 static void omap_os_timer_write(void *opaque
, target_phys_addr_t addr
,
1004 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
1005 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1008 case 0x00: /* TVR */
1009 s
->timer
.reset_val
= value
& 0x00ffffff;
1012 case 0x04: /* TCR */
1017 s
->timer
.ar
= (value
>> 3) & 1;
1018 s
->timer
.it_ena
= (value
>> 2) & 1;
1019 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
1020 omap_timer_sync(&s
->timer
);
1021 s
->timer
.enable
= value
& 1;
1022 s
->timer
.st
= value
& 1;
1023 omap_timer_update(&s
->timer
);
1032 static CPUReadMemoryFunc
*omap_os_timer_readfn
[] = {
1033 omap_badwidth_read32
,
1034 omap_badwidth_read32
,
1038 static CPUWriteMemoryFunc
*omap_os_timer_writefn
[] = {
1039 omap_badwidth_write32
,
1040 omap_badwidth_write32
,
1041 omap_os_timer_write
,
1044 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
1046 qemu_del_timer(s
->timer
.timer
);
1047 s
->timer
.enable
= 0;
1048 s
->timer
.it_ena
= 0;
1049 s
->timer
.reset_val
= 0x00ffffff;
1056 struct omap_32khz_timer_s
*omap_os_timer_init(target_phys_addr_t base
,
1057 qemu_irq irq
, omap_clk clk
)
1060 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*)
1061 qemu_mallocz(sizeof(struct omap_32khz_timer_s
));
1065 s
->timer
.base
= base
;
1066 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
1067 omap_os_timer_reset(s
);
1068 omap_timer_clk_setup(&s
->timer
);
1070 iomemtype
= cpu_register_io_memory(0, omap_os_timer_readfn
,
1071 omap_os_timer_writefn
, s
);
1072 cpu_register_physical_memory(s
->timer
.base
, 0x800, iomemtype
);
1077 /* Ultra Low-Power Device Module */
1078 static uint32_t omap_ulpd_pm_read(void *opaque
, target_phys_addr_t addr
)
1080 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1081 int offset
= addr
- s
->ulpd_pm_base
;
1085 case 0x14: /* IT_STATUS */
1086 ret
= s
->ulpd_pm_regs
[offset
>> 2];
1087 s
->ulpd_pm_regs
[offset
>> 2] = 0;
1088 qemu_irq_lower(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1091 case 0x18: /* Reserved */
1092 case 0x1c: /* Reserved */
1093 case 0x20: /* Reserved */
1094 case 0x28: /* Reserved */
1095 case 0x2c: /* Reserved */
1097 case 0x00: /* COUNTER_32_LSB */
1098 case 0x04: /* COUNTER_32_MSB */
1099 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1100 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1101 case 0x10: /* GAUGING_CTRL */
1102 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1103 case 0x30: /* CLOCK_CTRL */
1104 case 0x34: /* SOFT_REQ */
1105 case 0x38: /* COUNTER_32_FIQ */
1106 case 0x3c: /* DPLL_CTRL */
1107 case 0x40: /* STATUS_REQ */
1108 /* XXX: check clk::usecount state for every clock */
1109 case 0x48: /* LOCL_TIME */
1110 case 0x4c: /* APLL_CTRL */
1111 case 0x50: /* POWER_CTRL */
1112 return s
->ulpd_pm_regs
[offset
>> 2];
1119 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
1120 uint16_t diff
, uint16_t value
)
1122 if (diff
& (1 << 4)) /* USB_MCLK_EN */
1123 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
1124 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
1125 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
1128 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
1129 uint16_t diff
, uint16_t value
)
1131 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
1132 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
1133 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
1134 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
1135 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
1136 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
1137 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
1138 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
1141 static void omap_ulpd_pm_write(void *opaque
, target_phys_addr_t addr
,
1144 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1145 int offset
= addr
- s
->ulpd_pm_base
;
1148 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1152 case 0x00: /* COUNTER_32_LSB */
1153 case 0x04: /* COUNTER_32_MSB */
1154 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1155 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1156 case 0x14: /* IT_STATUS */
1157 case 0x40: /* STATUS_REQ */
1161 case 0x10: /* GAUGING_CTRL */
1162 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
1163 if ((s
->ulpd_pm_regs
[offset
>> 2] ^ value
) & 1) {
1164 now
= qemu_get_clock(vm_clock
);
1167 s
->ulpd_gauge_start
= now
;
1169 now
-= s
->ulpd_gauge_start
;
1172 ticks
= muldiv64(now
, 32768, ticks_per_sec
);
1173 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
1174 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
1175 if (ticks
>> 32) /* OVERFLOW_32K */
1176 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
1178 /* High frequency ticks */
1179 ticks
= muldiv64(now
, 12000000, ticks_per_sec
);
1180 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
1181 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
1182 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
1183 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
1185 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
1186 qemu_irq_raise(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1189 s
->ulpd_pm_regs
[offset
>> 2] = value
;
1192 case 0x18: /* Reserved */
1193 case 0x1c: /* Reserved */
1194 case 0x20: /* Reserved */
1195 case 0x28: /* Reserved */
1196 case 0x2c: /* Reserved */
1198 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1199 case 0x38: /* COUNTER_32_FIQ */
1200 case 0x48: /* LOCL_TIME */
1201 case 0x50: /* POWER_CTRL */
1202 s
->ulpd_pm_regs
[offset
>> 2] = value
;
1205 case 0x30: /* CLOCK_CTRL */
1206 diff
= s
->ulpd_pm_regs
[offset
>> 2] ^ value
;
1207 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x3f;
1208 omap_ulpd_clk_update(s
, diff
, value
);
1211 case 0x34: /* SOFT_REQ */
1212 diff
= s
->ulpd_pm_regs
[offset
>> 2] ^ value
;
1213 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x1f;
1214 omap_ulpd_req_update(s
, diff
, value
);
1217 case 0x3c: /* DPLL_CTRL */
1218 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
1219 * omitted altogether, probably a typo. */
1220 /* This register has identical semantics with DPLL(1:3) control
1221 * registers, see omap_dpll_write() */
1222 diff
= s
->ulpd_pm_regs
[offset
>> 2] & value
;
1223 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x2fff;
1224 if (diff
& (0x3ff << 2)) {
1225 if (value
& (1 << 4)) { /* PLL_ENABLE */
1226 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1227 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1229 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1232 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
1235 /* Enter the desired mode. */
1236 s
->ulpd_pm_regs
[offset
>> 2] =
1237 (s
->ulpd_pm_regs
[offset
>> 2] & 0xfffe) |
1238 ((s
->ulpd_pm_regs
[offset
>> 2] >> 4) & 1);
1240 /* Act as if the lock is restored. */
1241 s
->ulpd_pm_regs
[offset
>> 2] |= 2;
1244 case 0x4c: /* APLL_CTRL */
1245 diff
= s
->ulpd_pm_regs
[offset
>> 2] & value
;
1246 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0xf;
1247 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
1248 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
1249 (value
& (1 << 0)) ? "apll" : "dpll4"));
1257 static CPUReadMemoryFunc
*omap_ulpd_pm_readfn
[] = {
1258 omap_badwidth_read16
,
1260 omap_badwidth_read16
,
1263 static CPUWriteMemoryFunc
*omap_ulpd_pm_writefn
[] = {
1264 omap_badwidth_write16
,
1266 omap_badwidth_write16
,
1269 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
1271 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
1272 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
1273 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
1274 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
1275 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
1276 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
1277 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
1278 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
1279 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
1280 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
1281 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
1282 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
1283 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
1284 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
1285 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
1286 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
1287 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
1288 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
1289 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
1290 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
1291 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
1292 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
1293 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
1296 static void omap_ulpd_pm_init(target_phys_addr_t base
,
1297 struct omap_mpu_state_s
*mpu
)
1299 int iomemtype
= cpu_register_io_memory(0, omap_ulpd_pm_readfn
,
1300 omap_ulpd_pm_writefn
, mpu
);
1302 mpu
->ulpd_pm_base
= base
;
1303 cpu_register_physical_memory(mpu
->ulpd_pm_base
, 0x800, iomemtype
);
1304 omap_ulpd_pm_reset(mpu
);
1307 /* OMAP Pin Configuration */
1308 static uint32_t omap_pin_cfg_read(void *opaque
, target_phys_addr_t addr
)
1310 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1311 int offset
= addr
- s
->pin_cfg_base
;
1314 case 0x00: /* FUNC_MUX_CTRL_0 */
1315 case 0x04: /* FUNC_MUX_CTRL_1 */
1316 case 0x08: /* FUNC_MUX_CTRL_2 */
1317 return s
->func_mux_ctrl
[offset
>> 2];
1319 case 0x0c: /* COMP_MODE_CTRL_0 */
1320 return s
->comp_mode_ctrl
[0];
1322 case 0x10: /* FUNC_MUX_CTRL_3 */
1323 case 0x14: /* FUNC_MUX_CTRL_4 */
1324 case 0x18: /* FUNC_MUX_CTRL_5 */
1325 case 0x1c: /* FUNC_MUX_CTRL_6 */
1326 case 0x20: /* FUNC_MUX_CTRL_7 */
1327 case 0x24: /* FUNC_MUX_CTRL_8 */
1328 case 0x28: /* FUNC_MUX_CTRL_9 */
1329 case 0x2c: /* FUNC_MUX_CTRL_A */
1330 case 0x30: /* FUNC_MUX_CTRL_B */
1331 case 0x34: /* FUNC_MUX_CTRL_C */
1332 case 0x38: /* FUNC_MUX_CTRL_D */
1333 return s
->func_mux_ctrl
[(offset
>> 2) - 1];
1335 case 0x40: /* PULL_DWN_CTRL_0 */
1336 case 0x44: /* PULL_DWN_CTRL_1 */
1337 case 0x48: /* PULL_DWN_CTRL_2 */
1338 case 0x4c: /* PULL_DWN_CTRL_3 */
1339 return s
->pull_dwn_ctrl
[(offset
& 0xf) >> 2];
1341 case 0x50: /* GATE_INH_CTRL_0 */
1342 return s
->gate_inh_ctrl
[0];
1344 case 0x60: /* VOLTAGE_CTRL_0 */
1345 return s
->voltage_ctrl
[0];
1347 case 0x70: /* TEST_DBG_CTRL_0 */
1348 return s
->test_dbg_ctrl
[0];
1350 case 0x80: /* MOD_CONF_CTRL_0 */
1351 return s
->mod_conf_ctrl
[0];
1358 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
1359 uint32_t diff
, uint32_t value
)
1361 if (s
->compat1509
) {
1362 if (diff
& (1 << 9)) /* BLUETOOTH */
1363 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
1365 if (diff
& (1 << 7)) /* USB.CLKO */
1366 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
1371 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
1372 uint32_t diff
, uint32_t value
)
1374 if (s
->compat1509
) {
1375 if (diff
& (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
1376 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"),
1378 if (diff
& (1 << 1)) /* CLK32K */
1379 omap_clk_onoff(omap_findclk(s
, "clk32k_out"),
1384 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
1385 uint32_t diff
, uint32_t value
)
1387 if (diff
& (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
1388 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
1389 omap_findclk(s
, ((value
>> 31) & 1) ?
1390 "ck_48m" : "armper_ck"));
1391 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
1392 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
1393 omap_findclk(s
, ((value
>> 30) & 1) ?
1394 "ck_48m" : "armper_ck"));
1395 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
1396 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
1397 omap_findclk(s
, ((value
>> 29) & 1) ?
1398 "ck_48m" : "armper_ck"));
1399 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
1400 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
1401 omap_findclk(s
, ((value
>> 23) & 1) ?
1402 "ck_48m" : "armper_ck"));
1403 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
1404 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
1405 omap_findclk(s
, ((value
>> 12) & 1) ?
1406 "ck_48m" : "armper_ck"));
1407 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
1408 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
1411 static void omap_pin_cfg_write(void *opaque
, target_phys_addr_t addr
,
1414 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1415 int offset
= addr
- s
->pin_cfg_base
;
1419 case 0x00: /* FUNC_MUX_CTRL_0 */
1420 diff
= s
->func_mux_ctrl
[offset
>> 2] ^ value
;
1421 s
->func_mux_ctrl
[offset
>> 2] = value
;
1422 omap_pin_funcmux0_update(s
, diff
, value
);
1425 case 0x04: /* FUNC_MUX_CTRL_1 */
1426 diff
= s
->func_mux_ctrl
[offset
>> 2] ^ value
;
1427 s
->func_mux_ctrl
[offset
>> 2] = value
;
1428 omap_pin_funcmux1_update(s
, diff
, value
);
1431 case 0x08: /* FUNC_MUX_CTRL_2 */
1432 s
->func_mux_ctrl
[offset
>> 2] = value
;
1435 case 0x0c: /* COMP_MODE_CTRL_0 */
1436 s
->comp_mode_ctrl
[0] = value
;
1437 s
->compat1509
= (value
!= 0x0000eaef);
1438 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
1439 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
1442 case 0x10: /* FUNC_MUX_CTRL_3 */
1443 case 0x14: /* FUNC_MUX_CTRL_4 */
1444 case 0x18: /* FUNC_MUX_CTRL_5 */
1445 case 0x1c: /* FUNC_MUX_CTRL_6 */
1446 case 0x20: /* FUNC_MUX_CTRL_7 */
1447 case 0x24: /* FUNC_MUX_CTRL_8 */
1448 case 0x28: /* FUNC_MUX_CTRL_9 */
1449 case 0x2c: /* FUNC_MUX_CTRL_A */
1450 case 0x30: /* FUNC_MUX_CTRL_B */
1451 case 0x34: /* FUNC_MUX_CTRL_C */
1452 case 0x38: /* FUNC_MUX_CTRL_D */
1453 s
->func_mux_ctrl
[(offset
>> 2) - 1] = value
;
1456 case 0x40: /* PULL_DWN_CTRL_0 */
1457 case 0x44: /* PULL_DWN_CTRL_1 */
1458 case 0x48: /* PULL_DWN_CTRL_2 */
1459 case 0x4c: /* PULL_DWN_CTRL_3 */
1460 s
->pull_dwn_ctrl
[(offset
& 0xf) >> 2] = value
;
1463 case 0x50: /* GATE_INH_CTRL_0 */
1464 s
->gate_inh_ctrl
[0] = value
;
1467 case 0x60: /* VOLTAGE_CTRL_0 */
1468 s
->voltage_ctrl
[0] = value
;
1471 case 0x70: /* TEST_DBG_CTRL_0 */
1472 s
->test_dbg_ctrl
[0] = value
;
1475 case 0x80: /* MOD_CONF_CTRL_0 */
1476 diff
= s
->mod_conf_ctrl
[0] ^ value
;
1477 s
->mod_conf_ctrl
[0] = value
;
1478 omap_pin_modconf1_update(s
, diff
, value
);
1486 static CPUReadMemoryFunc
*omap_pin_cfg_readfn
[] = {
1487 omap_badwidth_read32
,
1488 omap_badwidth_read32
,
1492 static CPUWriteMemoryFunc
*omap_pin_cfg_writefn
[] = {
1493 omap_badwidth_write32
,
1494 omap_badwidth_write32
,
1498 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
1500 /* Start in Compatibility Mode. */
1501 mpu
->compat1509
= 1;
1502 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
1503 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
1504 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
1505 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
1506 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
1507 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
1508 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
1509 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
1510 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
1511 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
1514 static void omap_pin_cfg_init(target_phys_addr_t base
,
1515 struct omap_mpu_state_s
*mpu
)
1517 int iomemtype
= cpu_register_io_memory(0, omap_pin_cfg_readfn
,
1518 omap_pin_cfg_writefn
, mpu
);
1520 mpu
->pin_cfg_base
= base
;
1521 cpu_register_physical_memory(mpu
->pin_cfg_base
, 0x800, iomemtype
);
1522 omap_pin_cfg_reset(mpu
);
1525 /* Device Identification, Die Identification */
1526 static uint32_t omap_id_read(void *opaque
, target_phys_addr_t addr
)
1528 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1531 case 0xfffe1800: /* DIE_ID_LSB */
1533 case 0xfffe1804: /* DIE_ID_MSB */
1536 case 0xfffe2000: /* PRODUCT_ID_LSB */
1538 case 0xfffe2004: /* PRODUCT_ID_MSB */
1541 case 0xfffed400: /* JTAG_ID_LSB */
1542 switch (s
->mpu_model
) {
1548 cpu_abort(cpu_single_env
, "%s: bad mpu model\n", __FUNCTION__
);
1552 case 0xfffed404: /* JTAG_ID_MSB */
1553 switch (s
->mpu_model
) {
1559 cpu_abort(cpu_single_env
, "%s: bad mpu model\n", __FUNCTION__
);
1568 static void omap_id_write(void *opaque
, target_phys_addr_t addr
,
1574 static CPUReadMemoryFunc
*omap_id_readfn
[] = {
1575 omap_badwidth_read32
,
1576 omap_badwidth_read32
,
1580 static CPUWriteMemoryFunc
*omap_id_writefn
[] = {
1581 omap_badwidth_write32
,
1582 omap_badwidth_write32
,
1586 static void omap_id_init(struct omap_mpu_state_s
*mpu
)
1588 int iomemtype
= cpu_register_io_memory(0, omap_id_readfn
,
1589 omap_id_writefn
, mpu
);
1590 cpu_register_physical_memory(0xfffe1800, 0x800, iomemtype
);
1591 cpu_register_physical_memory(0xfffed400, 0x100, iomemtype
);
1592 if (!cpu_is_omap15xx(mpu
))
1593 cpu_register_physical_memory(0xfffe2000, 0x800, iomemtype
);
1596 /* MPUI Control (Dummy) */
1597 static uint32_t omap_mpui_read(void *opaque
, target_phys_addr_t addr
)
1599 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1600 int offset
= addr
- s
->mpui_base
;
1603 case 0x00: /* CTRL */
1604 return s
->mpui_ctrl
;
1605 case 0x04: /* DEBUG_ADDR */
1607 case 0x08: /* DEBUG_DATA */
1609 case 0x0c: /* DEBUG_FLAG */
1611 case 0x10: /* STATUS */
1614 /* Not in OMAP310 */
1615 case 0x14: /* DSP_STATUS */
1616 case 0x18: /* DSP_BOOT_CONFIG */
1618 case 0x1c: /* DSP_MPUI_CONFIG */
1626 static void omap_mpui_write(void *opaque
, target_phys_addr_t addr
,
1629 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1630 int offset
= addr
- s
->mpui_base
;
1633 case 0x00: /* CTRL */
1634 s
->mpui_ctrl
= value
& 0x007fffff;
1637 case 0x04: /* DEBUG_ADDR */
1638 case 0x08: /* DEBUG_DATA */
1639 case 0x0c: /* DEBUG_FLAG */
1640 case 0x10: /* STATUS */
1641 /* Not in OMAP310 */
1642 case 0x14: /* DSP_STATUS */
1644 case 0x18: /* DSP_BOOT_CONFIG */
1645 case 0x1c: /* DSP_MPUI_CONFIG */
1653 static CPUReadMemoryFunc
*omap_mpui_readfn
[] = {
1654 omap_badwidth_read32
,
1655 omap_badwidth_read32
,
1659 static CPUWriteMemoryFunc
*omap_mpui_writefn
[] = {
1660 omap_badwidth_write32
,
1661 omap_badwidth_write32
,
1665 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1667 s
->mpui_ctrl
= 0x0003ff1b;
1670 static void omap_mpui_init(target_phys_addr_t base
,
1671 struct omap_mpu_state_s
*mpu
)
1673 int iomemtype
= cpu_register_io_memory(0, omap_mpui_readfn
,
1674 omap_mpui_writefn
, mpu
);
1676 mpu
->mpui_base
= base
;
1677 cpu_register_physical_memory(mpu
->mpui_base
, 0x100, iomemtype
);
1679 omap_mpui_reset(mpu
);
1683 struct omap_tipb_bridge_s
{
1684 target_phys_addr_t base
;
1691 uint16_t enh_control
;
1694 static uint32_t omap_tipb_bridge_read(void *opaque
, target_phys_addr_t addr
)
1696 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1697 int offset
= addr
- s
->base
;
1700 case 0x00: /* TIPB_CNTL */
1702 case 0x04: /* TIPB_BUS_ALLOC */
1704 case 0x08: /* MPU_TIPB_CNTL */
1706 case 0x0c: /* ENHANCED_TIPB_CNTL */
1707 return s
->enh_control
;
1708 case 0x10: /* ADDRESS_DBG */
1709 case 0x14: /* DATA_DEBUG_LOW */
1710 case 0x18: /* DATA_DEBUG_HIGH */
1712 case 0x1c: /* DEBUG_CNTR_SIG */
1720 static void omap_tipb_bridge_write(void *opaque
, target_phys_addr_t addr
,
1723 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1724 int offset
= addr
- s
->base
;
1727 case 0x00: /* TIPB_CNTL */
1728 s
->control
= value
& 0xffff;
1731 case 0x04: /* TIPB_BUS_ALLOC */
1732 s
->alloc
= value
& 0x003f;
1735 case 0x08: /* MPU_TIPB_CNTL */
1736 s
->buffer
= value
& 0x0003;
1739 case 0x0c: /* ENHANCED_TIPB_CNTL */
1740 s
->width_intr
= !(value
& 2);
1741 s
->enh_control
= value
& 0x000f;
1744 case 0x10: /* ADDRESS_DBG */
1745 case 0x14: /* DATA_DEBUG_LOW */
1746 case 0x18: /* DATA_DEBUG_HIGH */
1747 case 0x1c: /* DEBUG_CNTR_SIG */
1756 static CPUReadMemoryFunc
*omap_tipb_bridge_readfn
[] = {
1757 omap_badwidth_read16
,
1758 omap_tipb_bridge_read
,
1759 omap_tipb_bridge_read
,
1762 static CPUWriteMemoryFunc
*omap_tipb_bridge_writefn
[] = {
1763 omap_badwidth_write16
,
1764 omap_tipb_bridge_write
,
1765 omap_tipb_bridge_write
,
1768 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1770 s
->control
= 0xffff;
1773 s
->enh_control
= 0x000f;
1776 struct omap_tipb_bridge_s
*omap_tipb_bridge_init(target_phys_addr_t base
,
1777 qemu_irq abort_irq
, omap_clk clk
)
1780 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*)
1781 qemu_mallocz(sizeof(struct omap_tipb_bridge_s
));
1783 s
->abort
= abort_irq
;
1785 omap_tipb_bridge_reset(s
);
1787 iomemtype
= cpu_register_io_memory(0, omap_tipb_bridge_readfn
,
1788 omap_tipb_bridge_writefn
, s
);
1789 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
1794 /* Dummy Traffic Controller's Memory Interface */
1795 static uint32_t omap_tcmi_read(void *opaque
, target_phys_addr_t addr
)
1797 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1798 int offset
= addr
- s
->tcmi_base
;
1802 case 0x00: /* IMIF_PRIO */
1803 case 0x04: /* EMIFS_PRIO */
1804 case 0x08: /* EMIFF_PRIO */
1805 case 0x0c: /* EMIFS_CONFIG */
1806 case 0x10: /* EMIFS_CS0_CONFIG */
1807 case 0x14: /* EMIFS_CS1_CONFIG */
1808 case 0x18: /* EMIFS_CS2_CONFIG */
1809 case 0x1c: /* EMIFS_CS3_CONFIG */
1810 case 0x24: /* EMIFF_MRS */
1811 case 0x28: /* TIMEOUT1 */
1812 case 0x2c: /* TIMEOUT2 */
1813 case 0x30: /* TIMEOUT3 */
1814 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1815 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1816 return s
->tcmi_regs
[offset
>> 2];
1818 case 0x20: /* EMIFF_SDRAM_CONFIG */
1819 ret
= s
->tcmi_regs
[offset
>> 2];
1820 s
->tcmi_regs
[offset
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1821 /* XXX: We can try using the VGA_DIRTY flag for this */
1829 static void omap_tcmi_write(void *opaque
, target_phys_addr_t addr
,
1832 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1833 int offset
= addr
- s
->tcmi_base
;
1836 case 0x00: /* IMIF_PRIO */
1837 case 0x04: /* EMIFS_PRIO */
1838 case 0x08: /* EMIFF_PRIO */
1839 case 0x10: /* EMIFS_CS0_CONFIG */
1840 case 0x14: /* EMIFS_CS1_CONFIG */
1841 case 0x18: /* EMIFS_CS2_CONFIG */
1842 case 0x1c: /* EMIFS_CS3_CONFIG */
1843 case 0x20: /* EMIFF_SDRAM_CONFIG */
1844 case 0x24: /* EMIFF_MRS */
1845 case 0x28: /* TIMEOUT1 */
1846 case 0x2c: /* TIMEOUT2 */
1847 case 0x30: /* TIMEOUT3 */
1848 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1849 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1850 s
->tcmi_regs
[offset
>> 2] = value
;
1852 case 0x0c: /* EMIFS_CONFIG */
1853 s
->tcmi_regs
[offset
>> 2] = (value
& 0xf) | (1 << 4);
1861 static CPUReadMemoryFunc
*omap_tcmi_readfn
[] = {
1862 omap_badwidth_read32
,
1863 omap_badwidth_read32
,
1867 static CPUWriteMemoryFunc
*omap_tcmi_writefn
[] = {
1868 omap_badwidth_write32
,
1869 omap_badwidth_write32
,
1873 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1875 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1876 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1877 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1878 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1879 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1880 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1881 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1882 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1883 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1884 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1885 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1886 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1887 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1888 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1889 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1892 static void omap_tcmi_init(target_phys_addr_t base
,
1893 struct omap_mpu_state_s
*mpu
)
1895 int iomemtype
= cpu_register_io_memory(0, omap_tcmi_readfn
,
1896 omap_tcmi_writefn
, mpu
);
1898 mpu
->tcmi_base
= base
;
1899 cpu_register_physical_memory(mpu
->tcmi_base
, 0x100, iomemtype
);
1900 omap_tcmi_reset(mpu
);
1903 /* Digital phase-locked loops control */
1904 static uint32_t omap_dpll_read(void *opaque
, target_phys_addr_t addr
)
1906 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1907 int offset
= addr
- s
->base
;
1909 if (offset
== 0x00) /* CTL_REG */
1916 static void omap_dpll_write(void *opaque
, target_phys_addr_t addr
,
1919 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1921 int offset
= addr
- s
->base
;
1922 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1925 if (offset
== 0x00) { /* CTL_REG */
1926 /* See omap_ulpd_pm_write() too */
1927 diff
= s
->mode
& value
;
1928 s
->mode
= value
& 0x2fff;
1929 if (diff
& (0x3ff << 2)) {
1930 if (value
& (1 << 4)) { /* PLL_ENABLE */
1931 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1932 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1934 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1937 omap_clk_setrate(s
->dpll
, div
, mult
);
1940 /* Enter the desired mode. */
1941 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1943 /* Act as if the lock is restored. */
1950 static CPUReadMemoryFunc
*omap_dpll_readfn
[] = {
1951 omap_badwidth_read16
,
1953 omap_badwidth_read16
,
1956 static CPUWriteMemoryFunc
*omap_dpll_writefn
[] = {
1957 omap_badwidth_write16
,
1959 omap_badwidth_write16
,
1962 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1965 omap_clk_setrate(s
->dpll
, 1, 1);
1968 static void omap_dpll_init(struct dpll_ctl_s
*s
, target_phys_addr_t base
,
1971 int iomemtype
= cpu_register_io_memory(0, omap_dpll_readfn
,
1972 omap_dpll_writefn
, s
);
1978 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
1982 struct omap_uart_s
{
1983 SerialState
*serial
; /* TODO */
1984 struct omap_target_agent_s
*ta
;
1985 target_phys_addr_t base
;
1997 void omap_uart_reset(struct omap_uart_s
*s
)
2005 struct omap_uart_s
*omap_uart_init(target_phys_addr_t base
,
2006 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
2007 qemu_irq txdma
, qemu_irq rxdma
, CharDriverState
*chr
)
2009 struct omap_uart_s
*s
= (struct omap_uart_s
*)
2010 qemu_mallocz(sizeof(struct omap_uart_s
));
2015 s
->serial
= serial_mm_init(base
, 2, irq
, omap_clk_getrate(fclk
)/16,
2016 chr
?: qemu_chr_open("null"), 1);
2021 static uint32_t omap_uart_read(void *opaque
, target_phys_addr_t addr
)
2023 struct omap_uart_s
*s
= (struct omap_uart_s
*) opaque
;
2024 int offset
= addr
- s
->base
;
2027 case 0x20: /* MDR1 */
2029 case 0x24: /* MDR2 */
2031 case 0x40: /* SCR */
2033 case 0x44: /* SSR */
2035 case 0x48: /* EBLR */
2037 case 0x50: /* MVR */
2039 case 0x54: /* SYSC */
2040 return s
->syscontrol
;
2041 case 0x58: /* SYSS */
2043 case 0x5c: /* WER */
2045 case 0x60: /* CFPS */
2053 static void omap_uart_write(void *opaque
, target_phys_addr_t addr
,
2056 struct omap_uart_s
*s
= (struct omap_uart_s
*) opaque
;
2057 int offset
= addr
- s
->base
;
2060 case 0x20: /* MDR1 */
2061 s
->mdr
[0] = value
& 0x7f;
2063 case 0x24: /* MDR2 */
2064 s
->mdr
[1] = value
& 0xff;
2066 case 0x40: /* SCR */
2067 s
->scr
= value
& 0xff;
2069 case 0x48: /* EBLR */
2070 s
->eblr
= value
& 0xff;
2072 case 0x44: /* SSR */
2073 case 0x50: /* MVR */
2074 case 0x58: /* SYSS */
2077 case 0x54: /* SYSC */
2078 s
->syscontrol
= value
& 0x1d;
2082 case 0x5c: /* WER */
2083 s
->wkup
= value
& 0x7f;
2085 case 0x60: /* CFPS */
2086 s
->cfps
= value
& 0xff;
2093 static CPUReadMemoryFunc
*omap_uart_readfn
[] = {
2096 omap_badwidth_read8
,
2099 static CPUWriteMemoryFunc
*omap_uart_writefn
[] = {
2102 omap_badwidth_write8
,
2105 struct omap_uart_s
*omap2_uart_init(struct omap_target_agent_s
*ta
,
2106 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
2107 qemu_irq txdma
, qemu_irq rxdma
, CharDriverState
*chr
)
2109 target_phys_addr_t base
= omap_l4_attach(ta
, 0, 0);
2110 struct omap_uart_s
*s
= omap_uart_init(base
, irq
,
2111 fclk
, iclk
, txdma
, rxdma
, chr
);
2112 int iomemtype
= cpu_register_io_memory(0, omap_uart_readfn
,
2113 omap_uart_writefn
, s
);
2117 cpu_register_physical_memory(s
->base
+ 0x20, 0x100, iomemtype
);
2122 void omap_uart_attach(struct omap_uart_s
*s
, CharDriverState
*chr
)
2124 /* TODO: Should reuse or destroy current s->serial */
2125 s
->serial
= serial_mm_init(s
->base
, 2, s
->irq
,
2126 omap_clk_getrate(s
->fclk
) / 16,
2127 chr
?: qemu_chr_open("null"), 1);
2130 /* MPU Clock/Reset/Power Mode Control */
2131 static uint32_t omap_clkm_read(void *opaque
, target_phys_addr_t addr
)
2133 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2134 int offset
= addr
- s
->clkm
.mpu_base
;
2137 case 0x00: /* ARM_CKCTL */
2138 return s
->clkm
.arm_ckctl
;
2140 case 0x04: /* ARM_IDLECT1 */
2141 return s
->clkm
.arm_idlect1
;
2143 case 0x08: /* ARM_IDLECT2 */
2144 return s
->clkm
.arm_idlect2
;
2146 case 0x0c: /* ARM_EWUPCT */
2147 return s
->clkm
.arm_ewupct
;
2149 case 0x10: /* ARM_RSTCT1 */
2150 return s
->clkm
.arm_rstct1
;
2152 case 0x14: /* ARM_RSTCT2 */
2153 return s
->clkm
.arm_rstct2
;
2155 case 0x18: /* ARM_SYSST */
2156 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
2158 case 0x1c: /* ARM_CKOUT1 */
2159 return s
->clkm
.arm_ckout1
;
2161 case 0x20: /* ARM_CKOUT2 */
2169 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
2170 uint16_t diff
, uint16_t value
)
2174 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
2175 if (value
& (1 << 14))
2178 clk
= omap_findclk(s
, "arminth_ck");
2179 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2182 if (diff
& (1 << 12)) { /* ARM_TIMXO */
2183 clk
= omap_findclk(s
, "armtim_ck");
2184 if (value
& (1 << 12))
2185 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
2187 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2190 if (diff
& (3 << 10)) { /* DSPMMUDIV */
2191 clk
= omap_findclk(s
, "dspmmu_ck");
2192 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
2194 if (diff
& (3 << 8)) { /* TCDIV */
2195 clk
= omap_findclk(s
, "tc_ck");
2196 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
2198 if (diff
& (3 << 6)) { /* DSPDIV */
2199 clk
= omap_findclk(s
, "dsp_ck");
2200 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
2202 if (diff
& (3 << 4)) { /* ARMDIV */
2203 clk
= omap_findclk(s
, "arm_ck");
2204 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
2206 if (diff
& (3 << 2)) { /* LCDDIV */
2207 clk
= omap_findclk(s
, "lcd_ck");
2208 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
2210 if (diff
& (3 << 0)) { /* PERDIV */
2211 clk
= omap_findclk(s
, "armper_ck");
2212 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
2216 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
2217 uint16_t diff
, uint16_t value
)
2221 if (value
& (1 << 11)) /* SETARM_IDLE */
2222 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
2223 if (!(value
& (1 << 10))) /* WKUP_MODE */
2224 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
2226 #define SET_CANIDLE(clock, bit) \
2227 if (diff & (1 << bit)) { \
2228 clk = omap_findclk(s, clock); \
2229 omap_clk_canidle(clk, (value >> bit) & 1); \
2231 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
2232 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
2233 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
2234 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
2235 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
2236 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
2237 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
2238 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
2239 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
2240 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
2241 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
2242 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
2243 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
2244 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
2247 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
2248 uint16_t diff
, uint16_t value
)
2252 #define SET_ONOFF(clock, bit) \
2253 if (diff & (1 << bit)) { \
2254 clk = omap_findclk(s, clock); \
2255 omap_clk_onoff(clk, (value >> bit) & 1); \
2257 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
2258 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
2259 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
2260 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
2261 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
2262 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
2263 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
2264 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
2265 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
2266 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
2267 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
2270 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
2271 uint16_t diff
, uint16_t value
)
2275 if (diff
& (3 << 4)) { /* TCLKOUT */
2276 clk
= omap_findclk(s
, "tclk_out");
2277 switch ((value
>> 4) & 3) {
2279 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
2280 omap_clk_onoff(clk
, 1);
2283 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2284 omap_clk_onoff(clk
, 1);
2287 omap_clk_onoff(clk
, 0);
2290 if (diff
& (3 << 2)) { /* DCLKOUT */
2291 clk
= omap_findclk(s
, "dclk_out");
2292 switch ((value
>> 2) & 3) {
2294 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
2297 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
2300 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
2303 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2307 if (diff
& (3 << 0)) { /* ACLKOUT */
2308 clk
= omap_findclk(s
, "aclk_out");
2309 switch ((value
>> 0) & 3) {
2311 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2312 omap_clk_onoff(clk
, 1);
2315 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
2316 omap_clk_onoff(clk
, 1);
2319 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2320 omap_clk_onoff(clk
, 1);
2323 omap_clk_onoff(clk
, 0);
2328 static void omap_clkm_write(void *opaque
, target_phys_addr_t addr
,
2331 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2332 int offset
= addr
- s
->clkm
.mpu_base
;
2335 static const char *clkschemename
[8] = {
2336 "fully synchronous", "fully asynchronous", "synchronous scalable",
2337 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
2341 case 0x00: /* ARM_CKCTL */
2342 diff
= s
->clkm
.arm_ckctl
^ value
;
2343 s
->clkm
.arm_ckctl
= value
& 0x7fff;
2344 omap_clkm_ckctl_update(s
, diff
, value
);
2347 case 0x04: /* ARM_IDLECT1 */
2348 diff
= s
->clkm
.arm_idlect1
^ value
;
2349 s
->clkm
.arm_idlect1
= value
& 0x0fff;
2350 omap_clkm_idlect1_update(s
, diff
, value
);
2353 case 0x08: /* ARM_IDLECT2 */
2354 diff
= s
->clkm
.arm_idlect2
^ value
;
2355 s
->clkm
.arm_idlect2
= value
& 0x07ff;
2356 omap_clkm_idlect2_update(s
, diff
, value
);
2359 case 0x0c: /* ARM_EWUPCT */
2360 diff
= s
->clkm
.arm_ewupct
^ value
;
2361 s
->clkm
.arm_ewupct
= value
& 0x003f;
2364 case 0x10: /* ARM_RSTCT1 */
2365 diff
= s
->clkm
.arm_rstct1
^ value
;
2366 s
->clkm
.arm_rstct1
= value
& 0x0007;
2368 qemu_system_reset_request();
2369 s
->clkm
.cold_start
= 0xa;
2371 if (diff
& ~value
& 4) { /* DSP_RST */
2373 omap_tipb_bridge_reset(s
->private_tipb
);
2374 omap_tipb_bridge_reset(s
->public_tipb
);
2376 if (diff
& 2) { /* DSP_EN */
2377 clk
= omap_findclk(s
, "dsp_ck");
2378 omap_clk_canidle(clk
, (~value
>> 1) & 1);
2382 case 0x14: /* ARM_RSTCT2 */
2383 s
->clkm
.arm_rstct2
= value
& 0x0001;
2386 case 0x18: /* ARM_SYSST */
2387 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
2388 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
2389 printf("%s: clocking scheme set to %s\n", __FUNCTION__
,
2390 clkschemename
[s
->clkm
.clocking_scheme
]);
2392 s
->clkm
.cold_start
&= value
& 0x3f;
2395 case 0x1c: /* ARM_CKOUT1 */
2396 diff
= s
->clkm
.arm_ckout1
^ value
;
2397 s
->clkm
.arm_ckout1
= value
& 0x003f;
2398 omap_clkm_ckout1_update(s
, diff
, value
);
2401 case 0x20: /* ARM_CKOUT2 */
2407 static CPUReadMemoryFunc
*omap_clkm_readfn
[] = {
2408 omap_badwidth_read16
,
2410 omap_badwidth_read16
,
2413 static CPUWriteMemoryFunc
*omap_clkm_writefn
[] = {
2414 omap_badwidth_write16
,
2416 omap_badwidth_write16
,
2419 static uint32_t omap_clkdsp_read(void *opaque
, target_phys_addr_t addr
)
2421 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2422 int offset
= addr
- s
->clkm
.dsp_base
;
2425 case 0x04: /* DSP_IDLECT1 */
2426 return s
->clkm
.dsp_idlect1
;
2428 case 0x08: /* DSP_IDLECT2 */
2429 return s
->clkm
.dsp_idlect2
;
2431 case 0x14: /* DSP_RSTCT2 */
2432 return s
->clkm
.dsp_rstct2
;
2434 case 0x18: /* DSP_SYSST */
2435 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
2436 (s
->env
->halted
<< 6); /* Quite useless... */
2443 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
2444 uint16_t diff
, uint16_t value
)
2448 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
2451 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
2452 uint16_t diff
, uint16_t value
)
2456 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
2459 static void omap_clkdsp_write(void *opaque
, target_phys_addr_t addr
,
2462 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2463 int offset
= addr
- s
->clkm
.dsp_base
;
2467 case 0x04: /* DSP_IDLECT1 */
2468 diff
= s
->clkm
.dsp_idlect1
^ value
;
2469 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
2470 omap_clkdsp_idlect1_update(s
, diff
, value
);
2473 case 0x08: /* DSP_IDLECT2 */
2474 s
->clkm
.dsp_idlect2
= value
& 0x0037;
2475 diff
= s
->clkm
.dsp_idlect1
^ value
;
2476 omap_clkdsp_idlect2_update(s
, diff
, value
);
2479 case 0x14: /* DSP_RSTCT2 */
2480 s
->clkm
.dsp_rstct2
= value
& 0x0001;
2483 case 0x18: /* DSP_SYSST */
2484 s
->clkm
.cold_start
&= value
& 0x3f;
2492 static CPUReadMemoryFunc
*omap_clkdsp_readfn
[] = {
2493 omap_badwidth_read16
,
2495 omap_badwidth_read16
,
2498 static CPUWriteMemoryFunc
*omap_clkdsp_writefn
[] = {
2499 omap_badwidth_write16
,
2501 omap_badwidth_write16
,
2504 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
2506 if (s
->wdt
&& s
->wdt
->reset
)
2507 s
->clkm
.cold_start
= 0x6;
2508 s
->clkm
.clocking_scheme
= 0;
2509 omap_clkm_ckctl_update(s
, ~0, 0x3000);
2510 s
->clkm
.arm_ckctl
= 0x3000;
2511 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
2512 s
->clkm
.arm_idlect1
= 0x0400;
2513 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
2514 s
->clkm
.arm_idlect2
= 0x0100;
2515 s
->clkm
.arm_ewupct
= 0x003f;
2516 s
->clkm
.arm_rstct1
= 0x0000;
2517 s
->clkm
.arm_rstct2
= 0x0000;
2518 s
->clkm
.arm_ckout1
= 0x0015;
2519 s
->clkm
.dpll1_mode
= 0x2002;
2520 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
2521 s
->clkm
.dsp_idlect1
= 0x0040;
2522 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
2523 s
->clkm
.dsp_idlect2
= 0x0000;
2524 s
->clkm
.dsp_rstct2
= 0x0000;
2527 static void omap_clkm_init(target_phys_addr_t mpu_base
,
2528 target_phys_addr_t dsp_base
, struct omap_mpu_state_s
*s
)
2530 int iomemtype
[2] = {
2531 cpu_register_io_memory(0, omap_clkm_readfn
, omap_clkm_writefn
, s
),
2532 cpu_register_io_memory(0, omap_clkdsp_readfn
, omap_clkdsp_writefn
, s
),
2535 s
->clkm
.mpu_base
= mpu_base
;
2536 s
->clkm
.dsp_base
= dsp_base
;
2537 s
->clkm
.arm_idlect1
= 0x03ff;
2538 s
->clkm
.arm_idlect2
= 0x0100;
2539 s
->clkm
.dsp_idlect1
= 0x0002;
2541 s
->clkm
.cold_start
= 0x3a;
2543 cpu_register_physical_memory(s
->clkm
.mpu_base
, 0x100, iomemtype
[0]);
2544 cpu_register_physical_memory(s
->clkm
.dsp_base
, 0x1000, iomemtype
[1]);
2548 struct omap_mpuio_s
{
2549 target_phys_addr_t base
;
2553 qemu_irq handler
[16];
2574 static void omap_mpuio_set(void *opaque
, int line
, int level
)
2576 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2577 uint16_t prev
= s
->inputs
;
2580 s
->inputs
|= 1 << line
;
2582 s
->inputs
&= ~(1 << line
);
2584 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
2585 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
2586 s
->ints
|= 1 << line
;
2587 qemu_irq_raise(s
->irq
);
2590 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
2591 (s
->event
>> 1) == line
) /* PIN_SELECT */
2592 s
->latch
= s
->inputs
;
2596 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
2599 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
2601 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
2605 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
2606 s
->row_latch
= ~rows
;
2609 static uint32_t omap_mpuio_read(void *opaque
, target_phys_addr_t addr
)
2611 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2612 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2616 case 0x00: /* INPUT_LATCH */
2619 case 0x04: /* OUTPUT_REG */
2622 case 0x08: /* IO_CNTL */
2625 case 0x10: /* KBR_LATCH */
2626 return s
->row_latch
;
2628 case 0x14: /* KBC_REG */
2631 case 0x18: /* GPIO_EVENT_MODE_REG */
2634 case 0x1c: /* GPIO_INT_EDGE_REG */
2637 case 0x20: /* KBD_INT */
2638 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
2640 case 0x24: /* GPIO_INT */
2644 qemu_irq_lower(s
->irq
);
2647 case 0x28: /* KBD_MASKIT */
2650 case 0x2c: /* GPIO_MASKIT */
2653 case 0x30: /* GPIO_DEBOUNCING_REG */
2656 case 0x34: /* GPIO_LATCH_REG */
2664 static void omap_mpuio_write(void *opaque
, target_phys_addr_t addr
,
2667 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2668 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2673 case 0x04: /* OUTPUT_REG */
2674 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2676 while ((ln
= ffs(diff
))) {
2679 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2684 case 0x08: /* IO_CNTL */
2685 diff
= s
->outputs
& (s
->dir
^ value
);
2688 value
= s
->outputs
& ~s
->dir
;
2689 while ((ln
= ffs(diff
))) {
2692 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2697 case 0x14: /* KBC_REG */
2699 omap_mpuio_kbd_update(s
);
2702 case 0x18: /* GPIO_EVENT_MODE_REG */
2703 s
->event
= value
& 0x1f;
2706 case 0x1c: /* GPIO_INT_EDGE_REG */
2710 case 0x28: /* KBD_MASKIT */
2711 s
->kbd_mask
= value
& 1;
2712 omap_mpuio_kbd_update(s
);
2715 case 0x2c: /* GPIO_MASKIT */
2719 case 0x30: /* GPIO_DEBOUNCING_REG */
2720 s
->debounce
= value
& 0x1ff;
2723 case 0x00: /* INPUT_LATCH */
2724 case 0x10: /* KBR_LATCH */
2725 case 0x20: /* KBD_INT */
2726 case 0x24: /* GPIO_INT */
2727 case 0x34: /* GPIO_LATCH_REG */
2737 static CPUReadMemoryFunc
*omap_mpuio_readfn
[] = {
2738 omap_badwidth_read16
,
2740 omap_badwidth_read16
,
2743 static CPUWriteMemoryFunc
*omap_mpuio_writefn
[] = {
2744 omap_badwidth_write16
,
2746 omap_badwidth_write16
,
2749 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2761 s
->row_latch
= 0x1f;
2765 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2767 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2771 omap_mpuio_kbd_update(s
);
2774 struct omap_mpuio_s
*omap_mpuio_init(target_phys_addr_t base
,
2775 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2779 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*)
2780 qemu_mallocz(sizeof(struct omap_mpuio_s
));
2784 s
->kbd_irq
= kbd_int
;
2786 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2787 omap_mpuio_reset(s
);
2789 iomemtype
= cpu_register_io_memory(0, omap_mpuio_readfn
,
2790 omap_mpuio_writefn
, s
);
2791 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
2793 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_mpuio_onoff
, s
, 1)[0]);
2798 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2803 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2805 if (line
>= 16 || line
< 0)
2806 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
2807 s
->handler
[line
] = handler
;
2810 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2812 if (row
>= 5 || row
< 0)
2813 cpu_abort(cpu_single_env
, "%s: No key %i-%i\n",
2814 __FUNCTION__
, col
, row
);
2817 s
->buttons
[row
] |= 1 << col
;
2819 s
->buttons
[row
] &= ~(1 << col
);
2821 omap_mpuio_kbd_update(s
);
2824 /* General-Purpose I/O */
2825 struct omap_gpio_s
{
2826 target_phys_addr_t base
;
2829 qemu_irq handler
[16];
2840 static void omap_gpio_set(void *opaque
, int line
, int level
)
2842 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2843 uint16_t prev
= s
->inputs
;
2846 s
->inputs
|= 1 << line
;
2848 s
->inputs
&= ~(1 << line
);
2850 if (((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) &
2851 (1 << line
) & s
->dir
& ~s
->mask
) {
2852 s
->ints
|= 1 << line
;
2853 qemu_irq_raise(s
->irq
);
2857 static uint32_t omap_gpio_read(void *opaque
, target_phys_addr_t addr
)
2859 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2860 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2863 case 0x00: /* DATA_INPUT */
2864 return s
->inputs
& s
->pins
;
2866 case 0x04: /* DATA_OUTPUT */
2869 case 0x08: /* DIRECTION_CONTROL */
2872 case 0x0c: /* INTERRUPT_CONTROL */
2875 case 0x10: /* INTERRUPT_MASK */
2878 case 0x14: /* INTERRUPT_STATUS */
2881 case 0x18: /* PIN_CONTROL (not in OMAP310) */
2890 static void omap_gpio_write(void *opaque
, target_phys_addr_t addr
,
2893 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2894 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2899 case 0x00: /* DATA_INPUT */
2903 case 0x04: /* DATA_OUTPUT */
2904 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2906 while ((ln
= ffs(diff
))) {
2909 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2914 case 0x08: /* DIRECTION_CONTROL */
2915 diff
= s
->outputs
& (s
->dir
^ value
);
2918 value
= s
->outputs
& ~s
->dir
;
2919 while ((ln
= ffs(diff
))) {
2922 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2927 case 0x0c: /* INTERRUPT_CONTROL */
2931 case 0x10: /* INTERRUPT_MASK */
2935 case 0x14: /* INTERRUPT_STATUS */
2938 qemu_irq_lower(s
->irq
);
2941 case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */
2952 /* *Some* sources say the memory region is 32-bit. */
2953 static CPUReadMemoryFunc
*omap_gpio_readfn
[] = {
2954 omap_badwidth_read16
,
2956 omap_badwidth_read16
,
2959 static CPUWriteMemoryFunc
*omap_gpio_writefn
[] = {
2960 omap_badwidth_write16
,
2962 omap_badwidth_write16
,
2965 static void omap_gpio_reset(struct omap_gpio_s
*s
)
2976 struct omap_gpio_s
*omap_gpio_init(target_phys_addr_t base
,
2977 qemu_irq irq
, omap_clk clk
)
2980 struct omap_gpio_s
*s
= (struct omap_gpio_s
*)
2981 qemu_mallocz(sizeof(struct omap_gpio_s
));
2985 s
->in
= qemu_allocate_irqs(omap_gpio_set
, s
, 16);
2988 iomemtype
= cpu_register_io_memory(0, omap_gpio_readfn
,
2989 omap_gpio_writefn
, s
);
2990 cpu_register_physical_memory(s
->base
, 0x1000, iomemtype
);
2995 qemu_irq
*omap_gpio_in_get(struct omap_gpio_s
*s
)
3000 void omap_gpio_out_set(struct omap_gpio_s
*s
, int line
, qemu_irq handler
)
3002 if (line
>= 16 || line
< 0)
3003 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
3004 s
->handler
[line
] = handler
;
3007 /* MicroWire Interface */
3008 struct omap_uwire_s
{
3009 target_phys_addr_t base
;
3019 struct uwire_slave_s
*chip
[4];
3022 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
3024 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
3025 struct uwire_slave_s
*slave
= s
->chip
[chipselect
];
3027 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
3028 if (s
->control
& (1 << 12)) /* CS_CMD */
3029 if (slave
&& slave
->send
)
3030 slave
->send(slave
->opaque
,
3031 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
3032 s
->control
&= ~(1 << 14); /* CSRB */
3033 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3034 * a DRQ. When is the level IRQ supposed to be reset? */
3037 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
3038 if (s
->control
& (1 << 12)) /* CS_CMD */
3039 if (slave
&& slave
->receive
)
3040 s
->rxbuf
= slave
->receive(slave
->opaque
);
3041 s
->control
|= 1 << 15; /* RDRB */
3042 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3043 * a DRQ. When is the level IRQ supposed to be reset? */
3047 static uint32_t omap_uwire_read(void *opaque
, target_phys_addr_t addr
)
3049 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3050 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3053 case 0x00: /* RDR */
3054 s
->control
&= ~(1 << 15); /* RDRB */
3057 case 0x04: /* CSR */
3060 case 0x08: /* SR1 */
3062 case 0x0c: /* SR2 */
3064 case 0x10: /* SR3 */
3066 case 0x14: /* SR4 */
3068 case 0x18: /* SR5 */
3076 static void omap_uwire_write(void *opaque
, target_phys_addr_t addr
,
3079 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3080 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3083 case 0x00: /* TDR */
3084 s
->txbuf
= value
; /* TD */
3085 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
3086 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
3087 (s
->control
& (1 << 12)))) { /* CS_CMD */
3088 s
->control
|= 1 << 14; /* CSRB */
3089 omap_uwire_transfer_start(s
);
3093 case 0x04: /* CSR */
3094 s
->control
= value
& 0x1fff;
3095 if (value
& (1 << 13)) /* START */
3096 omap_uwire_transfer_start(s
);
3099 case 0x08: /* SR1 */
3100 s
->setup
[0] = value
& 0x003f;
3103 case 0x0c: /* SR2 */
3104 s
->setup
[1] = value
& 0x0fc0;
3107 case 0x10: /* SR3 */
3108 s
->setup
[2] = value
& 0x0003;
3111 case 0x14: /* SR4 */
3112 s
->setup
[3] = value
& 0x0001;
3115 case 0x18: /* SR5 */
3116 s
->setup
[4] = value
& 0x000f;
3125 static CPUReadMemoryFunc
*omap_uwire_readfn
[] = {
3126 omap_badwidth_read16
,
3128 omap_badwidth_read16
,
3131 static CPUWriteMemoryFunc
*omap_uwire_writefn
[] = {
3132 omap_badwidth_write16
,
3134 omap_badwidth_write16
,
3137 static void omap_uwire_reset(struct omap_uwire_s
*s
)
3147 struct omap_uwire_s
*omap_uwire_init(target_phys_addr_t base
,
3148 qemu_irq
*irq
, qemu_irq dma
, omap_clk clk
)
3151 struct omap_uwire_s
*s
= (struct omap_uwire_s
*)
3152 qemu_mallocz(sizeof(struct omap_uwire_s
));
3158 omap_uwire_reset(s
);
3160 iomemtype
= cpu_register_io_memory(0, omap_uwire_readfn
,
3161 omap_uwire_writefn
, s
);
3162 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
3167 void omap_uwire_attach(struct omap_uwire_s
*s
,
3168 struct uwire_slave_s
*slave
, int chipselect
)
3170 if (chipselect
< 0 || chipselect
> 3) {
3171 fprintf(stderr
, "%s: Bad chipselect %i\n", __FUNCTION__
, chipselect
);
3175 s
->chip
[chipselect
] = slave
;
3178 /* Pseudonoise Pulse-Width Light Modulator */
3179 static void omap_pwl_update(struct omap_mpu_state_s
*s
)
3181 int output
= (s
->pwl
.clk
&& s
->pwl
.enable
) ? s
->pwl
.level
: 0;
3183 if (output
!= s
->pwl
.output
) {
3184 s
->pwl
.output
= output
;
3185 printf("%s: Backlight now at %i/256\n", __FUNCTION__
, output
);
3189 static uint32_t omap_pwl_read(void *opaque
, target_phys_addr_t addr
)
3191 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3192 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3195 case 0x00: /* PWL_LEVEL */
3196 return s
->pwl
.level
;
3197 case 0x04: /* PWL_CTRL */
3198 return s
->pwl
.enable
;
3204 static void omap_pwl_write(void *opaque
, target_phys_addr_t addr
,
3207 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3208 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3211 case 0x00: /* PWL_LEVEL */
3212 s
->pwl
.level
= value
;
3215 case 0x04: /* PWL_CTRL */
3216 s
->pwl
.enable
= value
& 1;
3225 static CPUReadMemoryFunc
*omap_pwl_readfn
[] = {
3227 omap_badwidth_read8
,
3228 omap_badwidth_read8
,
3231 static CPUWriteMemoryFunc
*omap_pwl_writefn
[] = {
3233 omap_badwidth_write8
,
3234 omap_badwidth_write8
,
3237 static void omap_pwl_reset(struct omap_mpu_state_s
*s
)
3246 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
3248 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3254 static void omap_pwl_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3261 iomemtype
= cpu_register_io_memory(0, omap_pwl_readfn
,
3262 omap_pwl_writefn
, s
);
3263 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3265 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_pwl_clk_update
, s
, 1)[0]);
3268 /* Pulse-Width Tone module */
3269 static uint32_t omap_pwt_read(void *opaque
, target_phys_addr_t addr
)
3271 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3272 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3275 case 0x00: /* FRC */
3277 case 0x04: /* VCR */
3279 case 0x08: /* GCR */
3286 static void omap_pwt_write(void *opaque
, target_phys_addr_t addr
,
3289 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3290 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3293 case 0x00: /* FRC */
3294 s
->pwt
.frc
= value
& 0x3f;
3296 case 0x04: /* VRC */
3297 if ((value
^ s
->pwt
.vrc
) & 1) {
3299 printf("%s: %iHz buzz on\n", __FUNCTION__
, (int)
3300 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
3301 ((omap_clk_getrate(s
->pwt
.clk
) >> 3) /
3302 /* Pre-multiplexer divider */
3303 ((s
->pwt
.gcr
& 2) ? 1 : 154) /
3304 /* Octave multiplexer */
3305 (2 << (value
& 3)) *
3306 /* 101/107 divider */
3307 ((value
& (1 << 2)) ? 101 : 107) *
3309 ((value
& (1 << 3)) ? 49 : 55) *
3311 ((value
& (1 << 4)) ? 50 : 63) *
3312 /* 80/127 divider */
3313 ((value
& (1 << 5)) ? 80 : 127) /
3314 (107 * 55 * 63 * 127)));
3316 printf("%s: silence!\n", __FUNCTION__
);
3318 s
->pwt
.vrc
= value
& 0x7f;
3320 case 0x08: /* GCR */
3321 s
->pwt
.gcr
= value
& 3;
3329 static CPUReadMemoryFunc
*omap_pwt_readfn
[] = {
3331 omap_badwidth_read8
,
3332 omap_badwidth_read8
,
3335 static CPUWriteMemoryFunc
*omap_pwt_writefn
[] = {
3337 omap_badwidth_write8
,
3338 omap_badwidth_write8
,
3341 static void omap_pwt_reset(struct omap_mpu_state_s
*s
)
3348 static void omap_pwt_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3356 iomemtype
= cpu_register_io_memory(0, omap_pwt_readfn
,
3357 omap_pwt_writefn
, s
);
3358 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3361 /* Real-time Clock module */
3363 target_phys_addr_t base
;
3378 struct tm current_tm
;
3383 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
3385 /* s->alarm is level-triggered */
3386 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
3389 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
3391 s
->alarm_ti
= mktime(&s
->alarm_tm
);
3392 if (s
->alarm_ti
== -1)
3393 printf("%s: conversion failed\n", __FUNCTION__
);
3396 static inline uint8_t omap_rtc_bcd(int num
)
3398 return ((num
/ 10) << 4) | (num
% 10);
3401 static inline int omap_rtc_bin(uint8_t num
)
3403 return (num
& 15) + 10 * (num
>> 4);
3406 static uint32_t omap_rtc_read(void *opaque
, target_phys_addr_t addr
)
3408 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3409 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3413 case 0x00: /* SECONDS_REG */
3414 return omap_rtc_bcd(s
->current_tm
.tm_sec
);
3416 case 0x04: /* MINUTES_REG */
3417 return omap_rtc_bcd(s
->current_tm
.tm_min
);
3419 case 0x08: /* HOURS_REG */
3421 return ((s
->current_tm
.tm_hour
> 11) << 7) |
3422 omap_rtc_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
3424 return omap_rtc_bcd(s
->current_tm
.tm_hour
);
3426 case 0x0c: /* DAYS_REG */
3427 return omap_rtc_bcd(s
->current_tm
.tm_mday
);
3429 case 0x10: /* MONTHS_REG */
3430 return omap_rtc_bcd(s
->current_tm
.tm_mon
+ 1);
3432 case 0x14: /* YEARS_REG */
3433 return omap_rtc_bcd(s
->current_tm
.tm_year
% 100);
3435 case 0x18: /* WEEK_REG */
3436 return s
->current_tm
.tm_wday
;
3438 case 0x20: /* ALARM_SECONDS_REG */
3439 return omap_rtc_bcd(s
->alarm_tm
.tm_sec
);
3441 case 0x24: /* ALARM_MINUTES_REG */
3442 return omap_rtc_bcd(s
->alarm_tm
.tm_min
);
3444 case 0x28: /* ALARM_HOURS_REG */
3446 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
3447 omap_rtc_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
3449 return omap_rtc_bcd(s
->alarm_tm
.tm_hour
);
3451 case 0x2c: /* ALARM_DAYS_REG */
3452 return omap_rtc_bcd(s
->alarm_tm
.tm_mday
);
3454 case 0x30: /* ALARM_MONTHS_REG */
3455 return omap_rtc_bcd(s
->alarm_tm
.tm_mon
+ 1);
3457 case 0x34: /* ALARM_YEARS_REG */
3458 return omap_rtc_bcd(s
->alarm_tm
.tm_year
% 100);
3460 case 0x40: /* RTC_CTRL_REG */
3461 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
3462 (s
->round
<< 1) | s
->running
;
3464 case 0x44: /* RTC_STATUS_REG */
3469 case 0x48: /* RTC_INTERRUPTS_REG */
3470 return s
->interrupts
;
3472 case 0x4c: /* RTC_COMP_LSB_REG */
3473 return ((uint16_t) s
->comp_reg
) & 0xff;
3475 case 0x50: /* RTC_COMP_MSB_REG */
3476 return ((uint16_t) s
->comp_reg
) >> 8;
3483 static void omap_rtc_write(void *opaque
, target_phys_addr_t addr
,
3486 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3487 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3492 case 0x00: /* SECONDS_REG */
3494 printf("RTC SEC_REG <-- %02x\n", value
);
3496 s
->ti
-= s
->current_tm
.tm_sec
;
3497 s
->ti
+= omap_rtc_bin(value
);
3500 case 0x04: /* MINUTES_REG */
3502 printf("RTC MIN_REG <-- %02x\n", value
);
3504 s
->ti
-= s
->current_tm
.tm_min
* 60;
3505 s
->ti
+= omap_rtc_bin(value
) * 60;
3508 case 0x08: /* HOURS_REG */
3510 printf("RTC HRS_REG <-- %02x\n", value
);
3512 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
3514 s
->ti
+= (omap_rtc_bin(value
& 0x3f) & 12) * 3600;
3515 s
->ti
+= ((value
>> 7) & 1) * 43200;
3517 s
->ti
+= omap_rtc_bin(value
& 0x3f) * 3600;
3520 case 0x0c: /* DAYS_REG */
3522 printf("RTC DAY_REG <-- %02x\n", value
);
3524 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
3525 s
->ti
+= omap_rtc_bin(value
) * 86400;
3528 case 0x10: /* MONTHS_REG */
3530 printf("RTC MTH_REG <-- %02x\n", value
);
3532 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3533 new_tm
.tm_mon
= omap_rtc_bin(value
);
3534 ti
[0] = mktime(&s
->current_tm
);
3535 ti
[1] = mktime(&new_tm
);
3537 if (ti
[0] != -1 && ti
[1] != -1) {
3541 /* A less accurate version */
3542 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
3543 s
->ti
+= omap_rtc_bin(value
) * 2592000;
3547 case 0x14: /* YEARS_REG */
3549 printf("RTC YRS_REG <-- %02x\n", value
);
3551 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3552 new_tm
.tm_year
+= omap_rtc_bin(value
) - (new_tm
.tm_year
% 100);
3553 ti
[0] = mktime(&s
->current_tm
);
3554 ti
[1] = mktime(&new_tm
);
3556 if (ti
[0] != -1 && ti
[1] != -1) {
3560 /* A less accurate version */
3561 s
->ti
-= (s
->current_tm
.tm_year
% 100) * 31536000;
3562 s
->ti
+= omap_rtc_bin(value
) * 31536000;
3566 case 0x18: /* WEEK_REG */
3567 return; /* Ignored */
3569 case 0x20: /* ALARM_SECONDS_REG */
3571 printf("ALM SEC_REG <-- %02x\n", value
);
3573 s
->alarm_tm
.tm_sec
= omap_rtc_bin(value
);
3574 omap_rtc_alarm_update(s
);
3577 case 0x24: /* ALARM_MINUTES_REG */
3579 printf("ALM MIN_REG <-- %02x\n", value
);
3581 s
->alarm_tm
.tm_min
= omap_rtc_bin(value
);
3582 omap_rtc_alarm_update(s
);
3585 case 0x28: /* ALARM_HOURS_REG */
3587 printf("ALM HRS_REG <-- %02x\n", value
);
3590 s
->alarm_tm
.tm_hour
=
3591 ((omap_rtc_bin(value
& 0x3f)) % 12) +
3592 ((value
>> 7) & 1) * 12;
3594 s
->alarm_tm
.tm_hour
= omap_rtc_bin(value
);
3595 omap_rtc_alarm_update(s
);
3598 case 0x2c: /* ALARM_DAYS_REG */
3600 printf("ALM DAY_REG <-- %02x\n", value
);
3602 s
->alarm_tm
.tm_mday
= omap_rtc_bin(value
);
3603 omap_rtc_alarm_update(s
);
3606 case 0x30: /* ALARM_MONTHS_REG */
3608 printf("ALM MON_REG <-- %02x\n", value
);
3610 s
->alarm_tm
.tm_mon
= omap_rtc_bin(value
);
3611 omap_rtc_alarm_update(s
);
3614 case 0x34: /* ALARM_YEARS_REG */
3616 printf("ALM YRS_REG <-- %02x\n", value
);
3618 s
->alarm_tm
.tm_year
= omap_rtc_bin(value
);
3619 omap_rtc_alarm_update(s
);
3622 case 0x40: /* RTC_CTRL_REG */
3624 printf("RTC CONTROL <-- %02x\n", value
);
3626 s
->pm_am
= (value
>> 3) & 1;
3627 s
->auto_comp
= (value
>> 2) & 1;
3628 s
->round
= (value
>> 1) & 1;
3629 s
->running
= value
& 1;
3631 s
->status
|= s
->running
<< 1;
3634 case 0x44: /* RTC_STATUS_REG */
3636 printf("RTC STATUSL <-- %02x\n", value
);
3638 s
->status
&= ~((value
& 0xc0) ^ 0x80);
3639 omap_rtc_interrupts_update(s
);
3642 case 0x48: /* RTC_INTERRUPTS_REG */
3644 printf("RTC INTRS <-- %02x\n", value
);
3646 s
->interrupts
= value
;
3649 case 0x4c: /* RTC_COMP_LSB_REG */
3651 printf("RTC COMPLSB <-- %02x\n", value
);
3653 s
->comp_reg
&= 0xff00;
3654 s
->comp_reg
|= 0x00ff & value
;
3657 case 0x50: /* RTC_COMP_MSB_REG */
3659 printf("RTC COMPMSB <-- %02x\n", value
);
3661 s
->comp_reg
&= 0x00ff;
3662 s
->comp_reg
|= 0xff00 & (value
<< 8);
3671 static CPUReadMemoryFunc
*omap_rtc_readfn
[] = {
3673 omap_badwidth_read8
,
3674 omap_badwidth_read8
,
3677 static CPUWriteMemoryFunc
*omap_rtc_writefn
[] = {
3679 omap_badwidth_write8
,
3680 omap_badwidth_write8
,
3683 static void omap_rtc_tick(void *opaque
)
3685 struct omap_rtc_s
*s
= opaque
;
3688 /* Round to nearest full minute. */
3689 if (s
->current_tm
.tm_sec
< 30)
3690 s
->ti
-= s
->current_tm
.tm_sec
;
3692 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
3697 memcpy(&s
->current_tm
, localtime(&s
->ti
), sizeof(s
->current_tm
));
3699 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
3701 omap_rtc_interrupts_update(s
);
3704 if (s
->interrupts
& 0x04)
3705 switch (s
->interrupts
& 3) {
3708 qemu_irq_pulse(s
->irq
);
3711 if (s
->current_tm
.tm_sec
)
3714 qemu_irq_pulse(s
->irq
);
3717 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
3720 qemu_irq_pulse(s
->irq
);
3723 if (s
->current_tm
.tm_sec
||
3724 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
3727 qemu_irq_pulse(s
->irq
);
3737 * Every full hour add a rough approximation of the compensation
3738 * register to the 32kHz Timer (which drives the RTC) value.
3740 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
3741 s
->tick
+= s
->comp_reg
* 1000 / 32768;
3743 qemu_mod_timer(s
->clk
, s
->tick
);
3746 static void omap_rtc_reset(struct omap_rtc_s
*s
)
3756 s
->tick
= qemu_get_clock(rt_clock
);
3757 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
3758 s
->alarm_tm
.tm_mday
= 0x01;
3760 qemu_get_timedate(&tm
, 0);
3761 s
->ti
= mktime(&tm
);
3763 omap_rtc_alarm_update(s
);
3767 struct omap_rtc_s
*omap_rtc_init(target_phys_addr_t base
,
3768 qemu_irq
*irq
, omap_clk clk
)
3771 struct omap_rtc_s
*s
= (struct omap_rtc_s
*)
3772 qemu_mallocz(sizeof(struct omap_rtc_s
));
3777 s
->clk
= qemu_new_timer(rt_clock
, omap_rtc_tick
, s
);
3781 iomemtype
= cpu_register_io_memory(0, omap_rtc_readfn
,
3782 omap_rtc_writefn
, s
);
3783 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
3788 /* Multi-channel Buffered Serial Port interfaces */
3789 struct omap_mcbsp_s
{
3790 target_phys_addr_t base
;
3809 struct i2s_codec_s
*codec
;
3810 QEMUTimer
*source_timer
;
3811 QEMUTimer
*sink_timer
;
3814 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
3818 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
3820 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
3823 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
3831 qemu_irq_pulse(s
->rxirq
);
3833 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
3835 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
3838 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
3846 qemu_irq_pulse(s
->txirq
);
3849 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
3851 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
3852 s
->spcr
[0] |= 1 << 2; /* RFULL */
3853 s
->spcr
[0] |= 1 << 1; /* RRDY */
3854 qemu_irq_raise(s
->rxdrq
);
3855 omap_mcbsp_intr_update(s
);
3858 static void omap_mcbsp_source_tick(void *opaque
)
3860 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3861 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3866 printf("%s: Rx FIFO overrun\n", __FUNCTION__
);
3868 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
3870 omap_mcbsp_rx_newdata(s
);
3871 qemu_mod_timer(s
->source_timer
, qemu_get_clock(vm_clock
) + ticks_per_sec
);
3874 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
3876 if (!s
->codec
|| !s
->codec
->rts
)
3877 omap_mcbsp_source_tick(s
);
3878 else if (s
->codec
->in
.len
) {
3879 s
->rx_req
= s
->codec
->in
.len
;
3880 omap_mcbsp_rx_newdata(s
);
3884 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
3886 qemu_del_timer(s
->source_timer
);
3889 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
3891 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
3892 qemu_irq_lower(s
->rxdrq
);
3893 omap_mcbsp_intr_update(s
);
3896 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
3898 s
->spcr
[1] |= 1 << 1; /* XRDY */
3899 qemu_irq_raise(s
->txdrq
);
3900 omap_mcbsp_intr_update(s
);
3903 static void omap_mcbsp_sink_tick(void *opaque
)
3905 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3906 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3911 printf("%s: Tx FIFO underrun\n", __FUNCTION__
);
3913 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
3915 omap_mcbsp_tx_newdata(s
);
3916 qemu_mod_timer(s
->sink_timer
, qemu_get_clock(vm_clock
) + ticks_per_sec
);
3919 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
3921 if (!s
->codec
|| !s
->codec
->cts
)
3922 omap_mcbsp_sink_tick(s
);
3923 else if (s
->codec
->out
.size
) {
3924 s
->tx_req
= s
->codec
->out
.size
;
3925 omap_mcbsp_tx_newdata(s
);
3929 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
3931 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
3932 qemu_irq_lower(s
->txdrq
);
3933 omap_mcbsp_intr_update(s
);
3934 if (s
->codec
&& s
->codec
->cts
)
3935 s
->codec
->tx_swallow(s
->codec
->opaque
);
3938 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
3941 omap_mcbsp_tx_done(s
);
3942 qemu_del_timer(s
->sink_timer
);
3945 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
3947 int prev_rx_rate
, prev_tx_rate
;
3948 int rx_rate
= 0, tx_rate
= 0;
3949 int cpu_rate
= 1500000; /* XXX */
3951 /* TODO: check CLKSTP bit */
3952 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3953 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3954 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3955 (s
->pcr
& (1 << 8))) { /* CLKRM */
3956 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3957 rx_rate
= cpu_rate
/
3958 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3961 rx_rate
= s
->codec
->rx_rate
;
3964 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3965 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3966 (s
->pcr
& (1 << 9))) { /* CLKXM */
3967 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3968 tx_rate
= cpu_rate
/
3969 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3972 tx_rate
= s
->codec
->tx_rate
;
3975 prev_tx_rate
= s
->tx_rate
;
3976 prev_rx_rate
= s
->rx_rate
;
3977 s
->tx_rate
= tx_rate
;
3978 s
->rx_rate
= rx_rate
;
3981 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3983 if (!prev_tx_rate
&& tx_rate
)
3984 omap_mcbsp_tx_start(s
);
3985 else if (s
->tx_rate
&& !tx_rate
)
3986 omap_mcbsp_tx_stop(s
);
3988 if (!prev_rx_rate
&& rx_rate
)
3989 omap_mcbsp_rx_start(s
);
3990 else if (prev_tx_rate
&& !tx_rate
)
3991 omap_mcbsp_rx_stop(s
);
3994 static uint32_t omap_mcbsp_read(void *opaque
, target_phys_addr_t addr
)
3996 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3997 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4001 case 0x00: /* DRR2 */
4002 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
4005 case 0x02: /* DRR1 */
4006 if (s
->rx_req
< 2) {
4007 printf("%s: Rx FIFO underrun\n", __FUNCTION__
);
4008 omap_mcbsp_rx_done(s
);
4011 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
4012 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
4013 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
4014 s
->codec
->in
.len
-= 2;
4018 omap_mcbsp_rx_done(s
);
4023 case 0x04: /* DXR2 */
4024 case 0x06: /* DXR1 */
4027 case 0x08: /* SPCR2 */
4029 case 0x0a: /* SPCR1 */
4031 case 0x0c: /* RCR2 */
4033 case 0x0e: /* RCR1 */
4035 case 0x10: /* XCR2 */
4037 case 0x12: /* XCR1 */
4039 case 0x14: /* SRGR2 */
4041 case 0x16: /* SRGR1 */
4043 case 0x18: /* MCR2 */
4045 case 0x1a: /* MCR1 */
4047 case 0x1c: /* RCERA */
4049 case 0x1e: /* RCERB */
4051 case 0x20: /* XCERA */
4053 case 0x22: /* XCERB */
4055 case 0x24: /* PCR0 */
4057 case 0x26: /* RCERC */
4059 case 0x28: /* RCERD */
4061 case 0x2a: /* XCERC */
4063 case 0x2c: /* XCERD */
4065 case 0x2e: /* RCERE */
4067 case 0x30: /* RCERF */
4069 case 0x32: /* XCERE */
4071 case 0x34: /* XCERF */
4073 case 0x36: /* RCERG */
4075 case 0x38: /* RCERH */
4077 case 0x3a: /* XCERG */
4079 case 0x3c: /* XCERH */
4087 static void omap_mcbsp_writeh(void *opaque
, target_phys_addr_t addr
,
4090 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4091 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4094 case 0x00: /* DRR2 */
4095 case 0x02: /* DRR1 */
4099 case 0x04: /* DXR2 */
4100 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
4103 case 0x06: /* DXR1 */
4104 if (s
->tx_req
> 1) {
4106 if (s
->codec
&& s
->codec
->cts
) {
4107 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
4108 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
4111 omap_mcbsp_tx_done(s
);
4113 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4116 case 0x08: /* SPCR2 */
4117 s
->spcr
[1] &= 0x0002;
4118 s
->spcr
[1] |= 0x03f9 & value
;
4119 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
4120 if (~value
& 1) /* XRST */
4122 omap_mcbsp_req_update(s
);
4124 case 0x0a: /* SPCR1 */
4125 s
->spcr
[0] &= 0x0006;
4126 s
->spcr
[0] |= 0xf8f9 & value
;
4127 if (value
& (1 << 15)) /* DLB */
4128 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__
);
4129 if (~value
& 1) { /* RRST */
4132 omap_mcbsp_rx_done(s
);
4134 omap_mcbsp_req_update(s
);
4137 case 0x0c: /* RCR2 */
4138 s
->rcr
[1] = value
& 0xffff;
4140 case 0x0e: /* RCR1 */
4141 s
->rcr
[0] = value
& 0x7fe0;
4143 case 0x10: /* XCR2 */
4144 s
->xcr
[1] = value
& 0xffff;
4146 case 0x12: /* XCR1 */
4147 s
->xcr
[0] = value
& 0x7fe0;
4149 case 0x14: /* SRGR2 */
4150 s
->srgr
[1] = value
& 0xffff;
4151 omap_mcbsp_req_update(s
);
4153 case 0x16: /* SRGR1 */
4154 s
->srgr
[0] = value
& 0xffff;
4155 omap_mcbsp_req_update(s
);
4157 case 0x18: /* MCR2 */
4158 s
->mcr
[1] = value
& 0x03e3;
4159 if (value
& 3) /* XMCM */
4160 printf("%s: Tx channel selection mode enable attempt\n",
4163 case 0x1a: /* MCR1 */
4164 s
->mcr
[0] = value
& 0x03e1;
4165 if (value
& 1) /* RMCM */
4166 printf("%s: Rx channel selection mode enable attempt\n",
4169 case 0x1c: /* RCERA */
4170 s
->rcer
[0] = value
& 0xffff;
4172 case 0x1e: /* RCERB */
4173 s
->rcer
[1] = value
& 0xffff;
4175 case 0x20: /* XCERA */
4176 s
->xcer
[0] = value
& 0xffff;
4178 case 0x22: /* XCERB */
4179 s
->xcer
[1] = value
& 0xffff;
4181 case 0x24: /* PCR0 */
4182 s
->pcr
= value
& 0x7faf;
4184 case 0x26: /* RCERC */
4185 s
->rcer
[2] = value
& 0xffff;
4187 case 0x28: /* RCERD */
4188 s
->rcer
[3] = value
& 0xffff;
4190 case 0x2a: /* XCERC */
4191 s
->xcer
[2] = value
& 0xffff;
4193 case 0x2c: /* XCERD */
4194 s
->xcer
[3] = value
& 0xffff;
4196 case 0x2e: /* RCERE */
4197 s
->rcer
[4] = value
& 0xffff;
4199 case 0x30: /* RCERF */
4200 s
->rcer
[5] = value
& 0xffff;
4202 case 0x32: /* XCERE */
4203 s
->xcer
[4] = value
& 0xffff;
4205 case 0x34: /* XCERF */
4206 s
->xcer
[5] = value
& 0xffff;
4208 case 0x36: /* RCERG */
4209 s
->rcer
[6] = value
& 0xffff;
4211 case 0x38: /* RCERH */
4212 s
->rcer
[7] = value
& 0xffff;
4214 case 0x3a: /* XCERG */
4215 s
->xcer
[6] = value
& 0xffff;
4217 case 0x3c: /* XCERH */
4218 s
->xcer
[7] = value
& 0xffff;
4225 static void omap_mcbsp_writew(void *opaque
, target_phys_addr_t addr
,
4228 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4229 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4231 if (offset
== 0x04) { /* DXR */
4232 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
4234 if (s
->tx_req
> 3) {
4236 if (s
->codec
&& s
->codec
->cts
) {
4237 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4238 (value
>> 24) & 0xff;
4239 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4240 (value
>> 16) & 0xff;
4241 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4242 (value
>> 8) & 0xff;
4243 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4244 (value
>> 0) & 0xff;
4247 omap_mcbsp_tx_done(s
);
4249 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4253 omap_badwidth_write16(opaque
, addr
, value
);
4256 static CPUReadMemoryFunc
*omap_mcbsp_readfn
[] = {
4257 omap_badwidth_read16
,
4259 omap_badwidth_read16
,
4262 static CPUWriteMemoryFunc
*omap_mcbsp_writefn
[] = {
4263 omap_badwidth_write16
,
4268 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
4270 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
4271 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
4272 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
4273 s
->srgr
[0] = 0x0001;
4274 s
->srgr
[1] = 0x2000;
4275 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
4276 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
4277 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
4278 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
4283 qemu_del_timer(s
->source_timer
);
4284 qemu_del_timer(s
->sink_timer
);
4287 struct omap_mcbsp_s
*omap_mcbsp_init(target_phys_addr_t base
,
4288 qemu_irq
*irq
, qemu_irq
*dma
, omap_clk clk
)
4291 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*)
4292 qemu_mallocz(sizeof(struct omap_mcbsp_s
));
4299 s
->sink_timer
= qemu_new_timer(vm_clock
, omap_mcbsp_sink_tick
, s
);
4300 s
->source_timer
= qemu_new_timer(vm_clock
, omap_mcbsp_source_tick
, s
);
4301 omap_mcbsp_reset(s
);
4303 iomemtype
= cpu_register_io_memory(0, omap_mcbsp_readfn
,
4304 omap_mcbsp_writefn
, s
);
4305 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
4310 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
4312 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4315 s
->rx_req
= s
->codec
->in
.len
;
4316 omap_mcbsp_rx_newdata(s
);
4320 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
4322 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4325 s
->tx_req
= s
->codec
->out
.size
;
4326 omap_mcbsp_tx_newdata(s
);
4330 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, struct i2s_codec_s
*slave
)
4333 slave
->rx_swallow
= qemu_allocate_irqs(omap_mcbsp_i2s_swallow
, s
, 1)[0];
4334 slave
->tx_start
= qemu_allocate_irqs(omap_mcbsp_i2s_start
, s
, 1)[0];
4337 /* LED Pulse Generators */
4339 target_phys_addr_t base
;
4350 static void omap_lpg_tick(void *opaque
)
4352 struct omap_lpg_s
*s
= opaque
;
4355 qemu_mod_timer(s
->tm
, qemu_get_clock(rt_clock
) + s
->period
- s
->on
);
4357 qemu_mod_timer(s
->tm
, qemu_get_clock(rt_clock
) + s
->on
);
4359 s
->cycle
= !s
->cycle
;
4360 printf("%s: LED is %s\n", __FUNCTION__
, s
->cycle
? "on" : "off");
4363 static void omap_lpg_update(struct omap_lpg_s
*s
)
4365 int64_t on
, period
= 1, ticks
= 1000;
4366 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
4368 if (~s
->control
& (1 << 6)) /* LPGRES */
4370 else if (s
->control
& (1 << 7)) /* PERM_ON */
4373 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
4375 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
4376 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
4379 qemu_del_timer(s
->tm
);
4380 if (on
== period
&& s
->on
< s
->period
)
4381 printf("%s: LED is on\n", __FUNCTION__
);
4382 else if (on
== 0 && s
->on
)
4383 printf("%s: LED is off\n", __FUNCTION__
);
4384 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
4396 static void omap_lpg_reset(struct omap_lpg_s
*s
)
4404 static uint32_t omap_lpg_read(void *opaque
, target_phys_addr_t addr
)
4406 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4407 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4410 case 0x00: /* LCR */
4413 case 0x04: /* PMR */
4421 static void omap_lpg_write(void *opaque
, target_phys_addr_t addr
,
4424 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4425 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4428 case 0x00: /* LCR */
4429 if (~value
& (1 << 6)) /* LPGRES */
4431 s
->control
= value
& 0xff;
4435 case 0x04: /* PMR */
4436 s
->power
= value
& 0x01;
4446 static CPUReadMemoryFunc
*omap_lpg_readfn
[] = {
4448 omap_badwidth_read8
,
4449 omap_badwidth_read8
,
4452 static CPUWriteMemoryFunc
*omap_lpg_writefn
[] = {
4454 omap_badwidth_write8
,
4455 omap_badwidth_write8
,
4458 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
4460 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4466 struct omap_lpg_s
*omap_lpg_init(target_phys_addr_t base
, omap_clk clk
)
4469 struct omap_lpg_s
*s
= (struct omap_lpg_s
*)
4470 qemu_mallocz(sizeof(struct omap_lpg_s
));
4473 s
->tm
= qemu_new_timer(rt_clock
, omap_lpg_tick
, s
);
4477 iomemtype
= cpu_register_io_memory(0, omap_lpg_readfn
,
4478 omap_lpg_writefn
, s
);
4479 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
4481 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_lpg_clk_update
, s
, 1)[0]);
4486 /* MPUI Peripheral Bridge configuration */
4487 static uint32_t omap_mpui_io_read(void *opaque
, target_phys_addr_t addr
)
4489 if (addr
== OMAP_MPUI_BASE
) /* CMR */
4496 static CPUReadMemoryFunc
*omap_mpui_io_readfn
[] = {
4497 omap_badwidth_read16
,
4499 omap_badwidth_read16
,
4502 static CPUWriteMemoryFunc
*omap_mpui_io_writefn
[] = {
4503 omap_badwidth_write16
,
4504 omap_badwidth_write16
,
4505 omap_badwidth_write16
,
4508 static void omap_setup_mpui_io(struct omap_mpu_state_s
*mpu
)
4510 int iomemtype
= cpu_register_io_memory(0, omap_mpui_io_readfn
,
4511 omap_mpui_io_writefn
, mpu
);
4512 cpu_register_physical_memory(OMAP_MPUI_BASE
, 0x7fff, iomemtype
);
4515 /* General chip reset */
4516 static void omap1_mpu_reset(void *opaque
)
4518 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4520 omap_inth_reset(mpu
->ih
[0]);
4521 omap_inth_reset(mpu
->ih
[1]);
4522 omap_dma_reset(mpu
->dma
);
4523 omap_mpu_timer_reset(mpu
->timer
[0]);
4524 omap_mpu_timer_reset(mpu
->timer
[1]);
4525 omap_mpu_timer_reset(mpu
->timer
[2]);
4526 omap_wd_timer_reset(mpu
->wdt
);
4527 omap_os_timer_reset(mpu
->os_timer
);
4528 omap_lcdc_reset(mpu
->lcd
);
4529 omap_ulpd_pm_reset(mpu
);
4530 omap_pin_cfg_reset(mpu
);
4531 omap_mpui_reset(mpu
);
4532 omap_tipb_bridge_reset(mpu
->private_tipb
);
4533 omap_tipb_bridge_reset(mpu
->public_tipb
);
4534 omap_dpll_reset(&mpu
->dpll
[0]);
4535 omap_dpll_reset(&mpu
->dpll
[1]);
4536 omap_dpll_reset(&mpu
->dpll
[2]);
4537 omap_uart_reset(mpu
->uart
[0]);
4538 omap_uart_reset(mpu
->uart
[1]);
4539 omap_uart_reset(mpu
->uart
[2]);
4540 omap_mmc_reset(mpu
->mmc
);
4541 omap_mpuio_reset(mpu
->mpuio
);
4542 omap_gpio_reset(mpu
->gpio
);
4543 omap_uwire_reset(mpu
->microwire
);
4544 omap_pwl_reset(mpu
);
4545 omap_pwt_reset(mpu
);
4546 omap_i2c_reset(mpu
->i2c
[0]);
4547 omap_rtc_reset(mpu
->rtc
);
4548 omap_mcbsp_reset(mpu
->mcbsp1
);
4549 omap_mcbsp_reset(mpu
->mcbsp2
);
4550 omap_mcbsp_reset(mpu
->mcbsp3
);
4551 omap_lpg_reset(mpu
->led
[0]);
4552 omap_lpg_reset(mpu
->led
[1]);
4553 omap_clkm_reset(mpu
);
4554 cpu_reset(mpu
->env
);
4557 static const struct omap_map_s
{
4558 target_phys_addr_t phys_dsp
;
4559 target_phys_addr_t phys_mpu
;
4562 } omap15xx_dsp_mm
[] = {
4564 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
4565 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
4566 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
4567 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
4568 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
4569 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
4570 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
4571 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
4572 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
4573 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
4574 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
4575 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
4576 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
4577 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
4578 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
4579 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
4580 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
4582 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
4587 static void omap_setup_dsp_mapping(const struct omap_map_s
*map
)
4591 for (; map
->phys_dsp
; map
++) {
4592 io
= cpu_get_physical_page_desc(map
->phys_mpu
);
4594 cpu_register_physical_memory(map
->phys_dsp
, map
->size
, io
);
4598 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
4600 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4602 if (mpu
->env
->halted
)
4603 cpu_interrupt(mpu
->env
, CPU_INTERRUPT_EXITTB
);
4606 static const struct dma_irq_map omap1_dma_irq_map
[] = {
4607 { 0, OMAP_INT_DMA_CH0_6
},
4608 { 0, OMAP_INT_DMA_CH1_7
},
4609 { 0, OMAP_INT_DMA_CH2_8
},
4610 { 0, OMAP_INT_DMA_CH3
},
4611 { 0, OMAP_INT_DMA_CH4
},
4612 { 0, OMAP_INT_DMA_CH5
},
4613 { 1, OMAP_INT_1610_DMA_CH6
},
4614 { 1, OMAP_INT_1610_DMA_CH7
},
4615 { 1, OMAP_INT_1610_DMA_CH8
},
4616 { 1, OMAP_INT_1610_DMA_CH9
},
4617 { 1, OMAP_INT_1610_DMA_CH10
},
4618 { 1, OMAP_INT_1610_DMA_CH11
},
4619 { 1, OMAP_INT_1610_DMA_CH12
},
4620 { 1, OMAP_INT_1610_DMA_CH13
},
4621 { 1, OMAP_INT_1610_DMA_CH14
},
4622 { 1, OMAP_INT_1610_DMA_CH15
}
4625 /* DMA ports for OMAP1 */
4626 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
4627 target_phys_addr_t addr
)
4629 return addr
>= OMAP_EMIFF_BASE
&& addr
< OMAP_EMIFF_BASE
+ s
->sdram_size
;
4632 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
4633 target_phys_addr_t addr
)
4635 return addr
>= OMAP_EMIFS_BASE
&& addr
< OMAP_EMIFF_BASE
;
4638 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
4639 target_phys_addr_t addr
)
4641 return addr
>= OMAP_IMIF_BASE
&& addr
< OMAP_IMIF_BASE
+ s
->sram_size
;
4644 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
4645 target_phys_addr_t addr
)
4647 return addr
>= 0xfffb0000 && addr
< 0xffff0000;
4650 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
4651 target_phys_addr_t addr
)
4653 return addr
>= OMAP_LOCALBUS_BASE
&& addr
< OMAP_LOCALBUS_BASE
+ 0x1000000;
4656 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
4657 target_phys_addr_t addr
)
4659 return addr
>= 0xe1010000 && addr
< 0xe1020004;
4662 struct omap_mpu_state_s
*omap310_mpu_init(unsigned long sdram_size
,
4663 DisplayState
*ds
, const char *core
)
4666 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*)
4667 qemu_mallocz(sizeof(struct omap_mpu_state_s
));
4668 ram_addr_t imif_base
, emiff_base
;
4670 qemu_irq dma_irqs
[6];
4677 s
->mpu_model
= omap310
;
4678 s
->env
= cpu_init(core
);
4680 fprintf(stderr
, "Unable to find CPU definition\n");
4683 s
->sdram_size
= sdram_size
;
4684 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
4686 s
->wakeup
= qemu_allocate_irqs(omap_mpu_wakeup
, s
, 1)[0];
4691 /* Memory-mapped stuff */
4692 cpu_register_physical_memory(OMAP_EMIFF_BASE
, s
->sdram_size
,
4693 (emiff_base
= qemu_ram_alloc(s
->sdram_size
)) | IO_MEM_RAM
);
4694 cpu_register_physical_memory(OMAP_IMIF_BASE
, s
->sram_size
,
4695 (imif_base
= qemu_ram_alloc(s
->sram_size
)) | IO_MEM_RAM
);
4697 omap_clkm_init(0xfffece00, 0xe1008000, s
);
4699 cpu_irq
= arm_pic_init_cpu(s
->env
);
4700 s
->ih
[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s
->irq
[0],
4701 cpu_irq
[ARM_PIC_CPU_IRQ
], cpu_irq
[ARM_PIC_CPU_FIQ
],
4702 omap_findclk(s
, "arminth_ck"));
4703 s
->ih
[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s
->irq
[1],
4704 s
->ih
[0]->pins
[OMAP_INT_15XX_IH2_IRQ
], NULL
,
4705 omap_findclk(s
, "arminth_ck"));
4707 for (i
= 0; i
< 6; i
++)
4709 s
->irq
[omap1_dma_irq_map
[i
].ih
][omap1_dma_irq_map
[i
].intr
];
4710 s
->dma
= omap_dma_init(0xfffed800, dma_irqs
, s
->irq
[0][OMAP_INT_DMA_LCD
],
4711 s
, omap_findclk(s
, "dma_ck"), omap_dma_3_1
);
4713 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
4714 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
4715 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
4716 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
4717 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
4718 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
4720 /* Register SDRAM and SRAM DMA ports for fast transfers. */
4721 soc_dma_port_add_mem_ram(s
->dma
,
4722 emiff_base
, OMAP_EMIFF_BASE
, s
->sdram_size
);
4723 soc_dma_port_add_mem_ram(s
->dma
,
4724 imif_base
, OMAP_IMIF_BASE
, s
->sram_size
);
4726 s
->timer
[0] = omap_mpu_timer_init(0xfffec500,
4727 s
->irq
[0][OMAP_INT_TIMER1
],
4728 omap_findclk(s
, "mputim_ck"));
4729 s
->timer
[1] = omap_mpu_timer_init(0xfffec600,
4730 s
->irq
[0][OMAP_INT_TIMER2
],
4731 omap_findclk(s
, "mputim_ck"));
4732 s
->timer
[2] = omap_mpu_timer_init(0xfffec700,
4733 s
->irq
[0][OMAP_INT_TIMER3
],
4734 omap_findclk(s
, "mputim_ck"));
4736 s
->wdt
= omap_wd_timer_init(0xfffec800,
4737 s
->irq
[0][OMAP_INT_WD_TIMER
],
4738 omap_findclk(s
, "armwdt_ck"));
4740 s
->os_timer
= omap_os_timer_init(0xfffb9000,
4741 s
->irq
[1][OMAP_INT_OS_TIMER
],
4742 omap_findclk(s
, "clk32-kHz"));
4744 s
->lcd
= omap_lcdc_init(0xfffec000, s
->irq
[0][OMAP_INT_LCD_CTRL
],
4745 omap_dma_get_lcdch(s
->dma
), ds
, imif_base
, emiff_base
,
4746 omap_findclk(s
, "lcd_ck"));
4748 omap_ulpd_pm_init(0xfffe0800, s
);
4749 omap_pin_cfg_init(0xfffe1000, s
);
4752 omap_mpui_init(0xfffec900, s
);
4754 s
->private_tipb
= omap_tipb_bridge_init(0xfffeca00,
4755 s
->irq
[0][OMAP_INT_BRIDGE_PRIV
],
4756 omap_findclk(s
, "tipb_ck"));
4757 s
->public_tipb
= omap_tipb_bridge_init(0xfffed300,
4758 s
->irq
[0][OMAP_INT_BRIDGE_PUB
],
4759 omap_findclk(s
, "tipb_ck"));
4761 omap_tcmi_init(0xfffecc00, s
);
4763 s
->uart
[0] = omap_uart_init(0xfffb0000, s
->irq
[1][OMAP_INT_UART1
],
4764 omap_findclk(s
, "uart1_ck"),
4765 omap_findclk(s
, "uart1_ck"),
4766 s
->drq
[OMAP_DMA_UART1_TX
], s
->drq
[OMAP_DMA_UART1_RX
],
4768 s
->uart
[1] = omap_uart_init(0xfffb0800, s
->irq
[1][OMAP_INT_UART2
],
4769 omap_findclk(s
, "uart2_ck"),
4770 omap_findclk(s
, "uart2_ck"),
4771 s
->drq
[OMAP_DMA_UART2_TX
], s
->drq
[OMAP_DMA_UART2_RX
],
4772 serial_hds
[0] ? serial_hds
[1] : 0);
4773 s
->uart
[2] = omap_uart_init(0xe1019800, s
->irq
[0][OMAP_INT_UART3
],
4774 omap_findclk(s
, "uart3_ck"),
4775 omap_findclk(s
, "uart3_ck"),
4776 s
->drq
[OMAP_DMA_UART3_TX
], s
->drq
[OMAP_DMA_UART3_RX
],
4777 serial_hds
[0] && serial_hds
[1] ? serial_hds
[2] : 0);
4779 omap_dpll_init(&s
->dpll
[0], 0xfffecf00, omap_findclk(s
, "dpll1"));
4780 omap_dpll_init(&s
->dpll
[1], 0xfffed000, omap_findclk(s
, "dpll2"));
4781 omap_dpll_init(&s
->dpll
[2], 0xfffed100, omap_findclk(s
, "dpll3"));
4783 sdindex
= drive_get_index(IF_SD
, 0, 0);
4784 if (sdindex
== -1) {
4785 fprintf(stderr
, "qemu: missing SecureDigital device\n");
4788 s
->mmc
= omap_mmc_init(0xfffb7800, drives_table
[sdindex
].bdrv
,
4789 s
->irq
[1][OMAP_INT_OQN
], &s
->drq
[OMAP_DMA_MMC_TX
],
4790 omap_findclk(s
, "mmc_ck"));
4792 s
->mpuio
= omap_mpuio_init(0xfffb5000,
4793 s
->irq
[1][OMAP_INT_KEYBOARD
], s
->irq
[1][OMAP_INT_MPUIO
],
4794 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
4796 s
->gpio
= omap_gpio_init(0xfffce000, s
->irq
[0][OMAP_INT_GPIO_BANK1
],
4797 omap_findclk(s
, "arm_gpio_ck"));
4799 s
->microwire
= omap_uwire_init(0xfffb3000, &s
->irq
[1][OMAP_INT_uWireTX
],
4800 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
4802 omap_pwl_init(0xfffb5800, s
, omap_findclk(s
, "armxor_ck"));
4803 omap_pwt_init(0xfffb6000, s
, omap_findclk(s
, "armxor_ck"));
4805 s
->i2c
[0] = omap_i2c_init(0xfffb3800, s
->irq
[1][OMAP_INT_I2C
],
4806 &s
->drq
[OMAP_DMA_I2C_RX
], omap_findclk(s
, "mpuper_ck"));
4808 s
->rtc
= omap_rtc_init(0xfffb4800, &s
->irq
[1][OMAP_INT_RTC_TIMER
],
4809 omap_findclk(s
, "clk32-kHz"));
4811 s
->mcbsp1
= omap_mcbsp_init(0xfffb1800, &s
->irq
[1][OMAP_INT_McBSP1TX
],
4812 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
4813 s
->mcbsp2
= omap_mcbsp_init(0xfffb1000, &s
->irq
[0][OMAP_INT_310_McBSP2_TX
],
4814 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
4815 s
->mcbsp3
= omap_mcbsp_init(0xfffb7000, &s
->irq
[1][OMAP_INT_McBSP3TX
],
4816 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
4818 s
->led
[0] = omap_lpg_init(0xfffbd000, omap_findclk(s
, "clk32-kHz"));
4819 s
->led
[1] = omap_lpg_init(0xfffbd800, omap_findclk(s
, "clk32-kHz"));
4821 /* Register mappings not currenlty implemented:
4822 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4823 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4824 * USB W2FC fffb4000 - fffb47ff
4825 * Camera Interface fffb6800 - fffb6fff
4826 * USB Host fffba000 - fffba7ff
4827 * FAC fffba800 - fffbafff
4828 * HDQ/1-Wire fffbc000 - fffbc7ff
4829 * TIPB switches fffbc800 - fffbcfff
4830 * Mailbox fffcf000 - fffcf7ff
4831 * Local bus IF fffec100 - fffec1ff
4832 * Local bus MMU fffec200 - fffec2ff
4833 * DSP MMU fffed200 - fffed2ff
4836 omap_setup_dsp_mapping(omap15xx_dsp_mm
);
4837 omap_setup_mpui_io(s
);
4839 qemu_register_reset(omap1_mpu_reset
, s
);