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
;
678 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
680 uint64_t distance
= qemu_get_clock(vm_clock
) - timer
->time
;
682 if (timer
->st
&& timer
->enable
&& timer
->rate
)
683 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
684 timer
->rate
, ticks_per_sec
);
689 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
691 timer
->val
= omap_timer_read(timer
);
692 timer
->time
= qemu_get_clock(vm_clock
);
695 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
699 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
700 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
701 expires
= muldiv64((uint64_t) timer
->val
<< (timer
->ptv
+ 1),
702 ticks_per_sec
, timer
->rate
);
704 /* If timer expiry would be sooner than in about 1 ms and
705 * auto-reload isn't set, then fire immediately. This is a hack
706 * to make systems like PalmOS run in acceptable time. PalmOS
707 * sets the interval to a very low value and polls the status bit
708 * in a busy loop when it wants to sleep just a couple of CPU
710 if (expires
> (ticks_per_sec
>> 10) || timer
->ar
)
711 qemu_mod_timer(timer
->timer
, timer
->time
+ expires
);
713 qemu_bh_schedule(timer
->tick
);
715 qemu_del_timer(timer
->timer
);
718 static void omap_timer_fire(void *opaque
)
720 struct omap_mpu_timer_s
*timer
= opaque
;
728 /* Edge-triggered irq */
729 qemu_irq_pulse(timer
->irq
);
732 static void omap_timer_tick(void *opaque
)
734 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
736 omap_timer_sync(timer
);
737 omap_timer_fire(timer
);
738 omap_timer_update(timer
);
741 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
743 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
745 omap_timer_sync(timer
);
746 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
747 omap_timer_update(timer
);
750 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
752 omap_clk_adduser(timer
->clk
,
753 qemu_allocate_irqs(omap_timer_clk_update
, timer
, 1)[0]);
754 timer
->rate
= omap_clk_getrate(timer
->clk
);
757 static uint32_t omap_mpu_timer_read(void *opaque
, target_phys_addr_t addr
)
759 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
760 int offset
= addr
- s
->base
;
763 case 0x00: /* CNTL_TIMER */
764 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
766 case 0x04: /* LOAD_TIM */
769 case 0x08: /* READ_TIM */
770 return omap_timer_read(s
);
777 static void omap_mpu_timer_write(void *opaque
, target_phys_addr_t addr
,
780 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
781 int offset
= addr
- s
->base
;
784 case 0x00: /* CNTL_TIMER */
786 s
->enable
= (value
>> 5) & 1;
787 s
->ptv
= (value
>> 2) & 7;
788 s
->ar
= (value
>> 1) & 1;
790 omap_timer_update(s
);
793 case 0x04: /* LOAD_TIM */
794 s
->reset_val
= value
;
797 case 0x08: /* READ_TIM */
806 static CPUReadMemoryFunc
*omap_mpu_timer_readfn
[] = {
807 omap_badwidth_read32
,
808 omap_badwidth_read32
,
812 static CPUWriteMemoryFunc
*omap_mpu_timer_writefn
[] = {
813 omap_badwidth_write32
,
814 omap_badwidth_write32
,
815 omap_mpu_timer_write
,
818 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
820 qemu_del_timer(s
->timer
);
822 s
->reset_val
= 31337;
830 struct omap_mpu_timer_s
*omap_mpu_timer_init(target_phys_addr_t base
,
831 qemu_irq irq
, omap_clk clk
)
834 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*)
835 qemu_mallocz(sizeof(struct omap_mpu_timer_s
));
840 s
->timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, s
);
841 s
->tick
= qemu_bh_new(omap_timer_fire
, s
);
842 omap_mpu_timer_reset(s
);
843 omap_timer_clk_setup(s
);
845 iomemtype
= cpu_register_io_memory(0, omap_mpu_timer_readfn
,
846 omap_mpu_timer_writefn
, s
);
847 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
853 struct omap_watchdog_timer_s
{
854 struct omap_mpu_timer_s timer
;
861 static uint32_t omap_wd_timer_read(void *opaque
, target_phys_addr_t addr
)
863 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
864 int offset
= addr
- s
->timer
.base
;
867 case 0x00: /* CNTL_TIMER */
868 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
869 (s
->timer
.st
<< 7) | (s
->free
<< 1);
871 case 0x04: /* READ_TIMER */
872 return omap_timer_read(&s
->timer
);
874 case 0x08: /* TIMER_MODE */
875 return s
->mode
<< 15;
882 static void omap_wd_timer_write(void *opaque
, target_phys_addr_t addr
,
885 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
886 int offset
= addr
- s
->timer
.base
;
889 case 0x00: /* CNTL_TIMER */
890 omap_timer_sync(&s
->timer
);
891 s
->timer
.ptv
= (value
>> 9) & 7;
892 s
->timer
.ar
= (value
>> 8) & 1;
893 s
->timer
.st
= (value
>> 7) & 1;
894 s
->free
= (value
>> 1) & 1;
895 omap_timer_update(&s
->timer
);
898 case 0x04: /* LOAD_TIMER */
899 s
->timer
.reset_val
= value
& 0xffff;
902 case 0x08: /* TIMER_MODE */
903 if (!s
->mode
&& ((value
>> 15) & 1))
904 omap_clk_get(s
->timer
.clk
);
905 s
->mode
|= (value
>> 15) & 1;
906 if (s
->last_wr
== 0xf5) {
907 if ((value
& 0xff) == 0xa0) {
910 omap_clk_put(s
->timer
.clk
);
913 /* XXX: on T|E hardware somehow this has no effect,
914 * on Zire 71 it works as specified. */
916 qemu_system_reset_request();
919 s
->last_wr
= value
& 0xff;
927 static CPUReadMemoryFunc
*omap_wd_timer_readfn
[] = {
928 omap_badwidth_read16
,
930 omap_badwidth_read16
,
933 static CPUWriteMemoryFunc
*omap_wd_timer_writefn
[] = {
934 omap_badwidth_write16
,
936 omap_badwidth_write16
,
939 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
941 qemu_del_timer(s
->timer
.timer
);
943 omap_clk_get(s
->timer
.clk
);
949 s
->timer
.reset_val
= 0xffff;
954 omap_timer_update(&s
->timer
);
957 struct omap_watchdog_timer_s
*omap_wd_timer_init(target_phys_addr_t base
,
958 qemu_irq irq
, omap_clk clk
)
961 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*)
962 qemu_mallocz(sizeof(struct omap_watchdog_timer_s
));
966 s
->timer
.base
= base
;
967 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
968 omap_wd_timer_reset(s
);
969 omap_timer_clk_setup(&s
->timer
);
971 iomemtype
= cpu_register_io_memory(0, omap_wd_timer_readfn
,
972 omap_wd_timer_writefn
, s
);
973 cpu_register_physical_memory(s
->timer
.base
, 0x100, iomemtype
);
979 struct omap_32khz_timer_s
{
980 struct omap_mpu_timer_s timer
;
983 static uint32_t omap_os_timer_read(void *opaque
, target_phys_addr_t addr
)
985 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
986 int offset
= addr
& OMAP_MPUI_REG_MASK
;
990 return s
->timer
.reset_val
;
993 return omap_timer_read(&s
->timer
);
996 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
1005 static void omap_os_timer_write(void *opaque
, target_phys_addr_t addr
,
1008 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
1009 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1012 case 0x00: /* TVR */
1013 s
->timer
.reset_val
= value
& 0x00ffffff;
1016 case 0x04: /* TCR */
1021 s
->timer
.ar
= (value
>> 3) & 1;
1022 s
->timer
.it_ena
= (value
>> 2) & 1;
1023 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
1024 omap_timer_sync(&s
->timer
);
1025 s
->timer
.enable
= value
& 1;
1026 s
->timer
.st
= value
& 1;
1027 omap_timer_update(&s
->timer
);
1036 static CPUReadMemoryFunc
*omap_os_timer_readfn
[] = {
1037 omap_badwidth_read32
,
1038 omap_badwidth_read32
,
1042 static CPUWriteMemoryFunc
*omap_os_timer_writefn
[] = {
1043 omap_badwidth_write32
,
1044 omap_badwidth_write32
,
1045 omap_os_timer_write
,
1048 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
1050 qemu_del_timer(s
->timer
.timer
);
1051 s
->timer
.enable
= 0;
1052 s
->timer
.it_ena
= 0;
1053 s
->timer
.reset_val
= 0x00ffffff;
1060 struct omap_32khz_timer_s
*omap_os_timer_init(target_phys_addr_t base
,
1061 qemu_irq irq
, omap_clk clk
)
1064 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*)
1065 qemu_mallocz(sizeof(struct omap_32khz_timer_s
));
1069 s
->timer
.base
= base
;
1070 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
1071 omap_os_timer_reset(s
);
1072 omap_timer_clk_setup(&s
->timer
);
1074 iomemtype
= cpu_register_io_memory(0, omap_os_timer_readfn
,
1075 omap_os_timer_writefn
, s
);
1076 cpu_register_physical_memory(s
->timer
.base
, 0x800, iomemtype
);
1081 /* Ultra Low-Power Device Module */
1082 static uint32_t omap_ulpd_pm_read(void *opaque
, target_phys_addr_t addr
)
1084 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1085 int offset
= addr
- s
->ulpd_pm_base
;
1089 case 0x14: /* IT_STATUS */
1090 ret
= s
->ulpd_pm_regs
[offset
>> 2];
1091 s
->ulpd_pm_regs
[offset
>> 2] = 0;
1092 qemu_irq_lower(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1095 case 0x18: /* Reserved */
1096 case 0x1c: /* Reserved */
1097 case 0x20: /* Reserved */
1098 case 0x28: /* Reserved */
1099 case 0x2c: /* Reserved */
1101 case 0x00: /* COUNTER_32_LSB */
1102 case 0x04: /* COUNTER_32_MSB */
1103 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1104 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1105 case 0x10: /* GAUGING_CTRL */
1106 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1107 case 0x30: /* CLOCK_CTRL */
1108 case 0x34: /* SOFT_REQ */
1109 case 0x38: /* COUNTER_32_FIQ */
1110 case 0x3c: /* DPLL_CTRL */
1111 case 0x40: /* STATUS_REQ */
1112 /* XXX: check clk::usecount state for every clock */
1113 case 0x48: /* LOCL_TIME */
1114 case 0x4c: /* APLL_CTRL */
1115 case 0x50: /* POWER_CTRL */
1116 return s
->ulpd_pm_regs
[offset
>> 2];
1123 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
1124 uint16_t diff
, uint16_t value
)
1126 if (diff
& (1 << 4)) /* USB_MCLK_EN */
1127 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
1128 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
1129 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
1132 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
1133 uint16_t diff
, uint16_t value
)
1135 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
1136 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
1137 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
1138 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
1139 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
1140 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
1141 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
1142 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
1145 static void omap_ulpd_pm_write(void *opaque
, target_phys_addr_t addr
,
1148 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1149 int offset
= addr
- s
->ulpd_pm_base
;
1152 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1156 case 0x00: /* COUNTER_32_LSB */
1157 case 0x04: /* COUNTER_32_MSB */
1158 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1159 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1160 case 0x14: /* IT_STATUS */
1161 case 0x40: /* STATUS_REQ */
1165 case 0x10: /* GAUGING_CTRL */
1166 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
1167 if ((s
->ulpd_pm_regs
[offset
>> 2] ^ value
) & 1) {
1168 now
= qemu_get_clock(vm_clock
);
1171 s
->ulpd_gauge_start
= now
;
1173 now
-= s
->ulpd_gauge_start
;
1176 ticks
= muldiv64(now
, 32768, ticks_per_sec
);
1177 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
1178 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
1179 if (ticks
>> 32) /* OVERFLOW_32K */
1180 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
1182 /* High frequency ticks */
1183 ticks
= muldiv64(now
, 12000000, ticks_per_sec
);
1184 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
1185 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
1186 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
1187 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
1189 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
1190 qemu_irq_raise(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1193 s
->ulpd_pm_regs
[offset
>> 2] = value
;
1196 case 0x18: /* Reserved */
1197 case 0x1c: /* Reserved */
1198 case 0x20: /* Reserved */
1199 case 0x28: /* Reserved */
1200 case 0x2c: /* Reserved */
1202 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1203 case 0x38: /* COUNTER_32_FIQ */
1204 case 0x48: /* LOCL_TIME */
1205 case 0x50: /* POWER_CTRL */
1206 s
->ulpd_pm_regs
[offset
>> 2] = value
;
1209 case 0x30: /* CLOCK_CTRL */
1210 diff
= s
->ulpd_pm_regs
[offset
>> 2] ^ value
;
1211 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x3f;
1212 omap_ulpd_clk_update(s
, diff
, value
);
1215 case 0x34: /* SOFT_REQ */
1216 diff
= s
->ulpd_pm_regs
[offset
>> 2] ^ value
;
1217 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x1f;
1218 omap_ulpd_req_update(s
, diff
, value
);
1221 case 0x3c: /* DPLL_CTRL */
1222 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
1223 * omitted altogether, probably a typo. */
1224 /* This register has identical semantics with DPLL(1:3) control
1225 * registers, see omap_dpll_write() */
1226 diff
= s
->ulpd_pm_regs
[offset
>> 2] & value
;
1227 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x2fff;
1228 if (diff
& (0x3ff << 2)) {
1229 if (value
& (1 << 4)) { /* PLL_ENABLE */
1230 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1231 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1233 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1236 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
1239 /* Enter the desired mode. */
1240 s
->ulpd_pm_regs
[offset
>> 2] =
1241 (s
->ulpd_pm_regs
[offset
>> 2] & 0xfffe) |
1242 ((s
->ulpd_pm_regs
[offset
>> 2] >> 4) & 1);
1244 /* Act as if the lock is restored. */
1245 s
->ulpd_pm_regs
[offset
>> 2] |= 2;
1248 case 0x4c: /* APLL_CTRL */
1249 diff
= s
->ulpd_pm_regs
[offset
>> 2] & value
;
1250 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0xf;
1251 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
1252 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
1253 (value
& (1 << 0)) ? "apll" : "dpll4"));
1261 static CPUReadMemoryFunc
*omap_ulpd_pm_readfn
[] = {
1262 omap_badwidth_read16
,
1264 omap_badwidth_read16
,
1267 static CPUWriteMemoryFunc
*omap_ulpd_pm_writefn
[] = {
1268 omap_badwidth_write16
,
1270 omap_badwidth_write16
,
1273 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
1275 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
1276 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
1277 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
1278 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
1279 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
1280 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
1281 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
1282 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
1283 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
1284 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
1285 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
1286 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
1287 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
1288 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
1289 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
1290 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
1291 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
1292 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
1293 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
1294 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
1295 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
1296 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
1297 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
1300 static void omap_ulpd_pm_init(target_phys_addr_t base
,
1301 struct omap_mpu_state_s
*mpu
)
1303 int iomemtype
= cpu_register_io_memory(0, omap_ulpd_pm_readfn
,
1304 omap_ulpd_pm_writefn
, mpu
);
1306 mpu
->ulpd_pm_base
= base
;
1307 cpu_register_physical_memory(mpu
->ulpd_pm_base
, 0x800, iomemtype
);
1308 omap_ulpd_pm_reset(mpu
);
1311 /* OMAP Pin Configuration */
1312 static uint32_t omap_pin_cfg_read(void *opaque
, target_phys_addr_t addr
)
1314 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1315 int offset
= addr
- s
->pin_cfg_base
;
1318 case 0x00: /* FUNC_MUX_CTRL_0 */
1319 case 0x04: /* FUNC_MUX_CTRL_1 */
1320 case 0x08: /* FUNC_MUX_CTRL_2 */
1321 return s
->func_mux_ctrl
[offset
>> 2];
1323 case 0x0c: /* COMP_MODE_CTRL_0 */
1324 return s
->comp_mode_ctrl
[0];
1326 case 0x10: /* FUNC_MUX_CTRL_3 */
1327 case 0x14: /* FUNC_MUX_CTRL_4 */
1328 case 0x18: /* FUNC_MUX_CTRL_5 */
1329 case 0x1c: /* FUNC_MUX_CTRL_6 */
1330 case 0x20: /* FUNC_MUX_CTRL_7 */
1331 case 0x24: /* FUNC_MUX_CTRL_8 */
1332 case 0x28: /* FUNC_MUX_CTRL_9 */
1333 case 0x2c: /* FUNC_MUX_CTRL_A */
1334 case 0x30: /* FUNC_MUX_CTRL_B */
1335 case 0x34: /* FUNC_MUX_CTRL_C */
1336 case 0x38: /* FUNC_MUX_CTRL_D */
1337 return s
->func_mux_ctrl
[(offset
>> 2) - 1];
1339 case 0x40: /* PULL_DWN_CTRL_0 */
1340 case 0x44: /* PULL_DWN_CTRL_1 */
1341 case 0x48: /* PULL_DWN_CTRL_2 */
1342 case 0x4c: /* PULL_DWN_CTRL_3 */
1343 return s
->pull_dwn_ctrl
[(offset
& 0xf) >> 2];
1345 case 0x50: /* GATE_INH_CTRL_0 */
1346 return s
->gate_inh_ctrl
[0];
1348 case 0x60: /* VOLTAGE_CTRL_0 */
1349 return s
->voltage_ctrl
[0];
1351 case 0x70: /* TEST_DBG_CTRL_0 */
1352 return s
->test_dbg_ctrl
[0];
1354 case 0x80: /* MOD_CONF_CTRL_0 */
1355 return s
->mod_conf_ctrl
[0];
1362 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
1363 uint32_t diff
, uint32_t value
)
1365 if (s
->compat1509
) {
1366 if (diff
& (1 << 9)) /* BLUETOOTH */
1367 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
1369 if (diff
& (1 << 7)) /* USB.CLKO */
1370 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
1375 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
1376 uint32_t diff
, uint32_t value
)
1378 if (s
->compat1509
) {
1379 if (diff
& (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
1380 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"),
1382 if (diff
& (1 << 1)) /* CLK32K */
1383 omap_clk_onoff(omap_findclk(s
, "clk32k_out"),
1388 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
1389 uint32_t diff
, uint32_t value
)
1391 if (diff
& (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
1392 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
1393 omap_findclk(s
, ((value
>> 31) & 1) ?
1394 "ck_48m" : "armper_ck"));
1395 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
1396 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
1397 omap_findclk(s
, ((value
>> 30) & 1) ?
1398 "ck_48m" : "armper_ck"));
1399 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
1400 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
1401 omap_findclk(s
, ((value
>> 29) & 1) ?
1402 "ck_48m" : "armper_ck"));
1403 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
1404 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
1405 omap_findclk(s
, ((value
>> 23) & 1) ?
1406 "ck_48m" : "armper_ck"));
1407 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
1408 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
1409 omap_findclk(s
, ((value
>> 12) & 1) ?
1410 "ck_48m" : "armper_ck"));
1411 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
1412 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
1415 static void omap_pin_cfg_write(void *opaque
, target_phys_addr_t addr
,
1418 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1419 int offset
= addr
- s
->pin_cfg_base
;
1423 case 0x00: /* FUNC_MUX_CTRL_0 */
1424 diff
= s
->func_mux_ctrl
[offset
>> 2] ^ value
;
1425 s
->func_mux_ctrl
[offset
>> 2] = value
;
1426 omap_pin_funcmux0_update(s
, diff
, value
);
1429 case 0x04: /* FUNC_MUX_CTRL_1 */
1430 diff
= s
->func_mux_ctrl
[offset
>> 2] ^ value
;
1431 s
->func_mux_ctrl
[offset
>> 2] = value
;
1432 omap_pin_funcmux1_update(s
, diff
, value
);
1435 case 0x08: /* FUNC_MUX_CTRL_2 */
1436 s
->func_mux_ctrl
[offset
>> 2] = value
;
1439 case 0x0c: /* COMP_MODE_CTRL_0 */
1440 s
->comp_mode_ctrl
[0] = value
;
1441 s
->compat1509
= (value
!= 0x0000eaef);
1442 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
1443 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
1446 case 0x10: /* FUNC_MUX_CTRL_3 */
1447 case 0x14: /* FUNC_MUX_CTRL_4 */
1448 case 0x18: /* FUNC_MUX_CTRL_5 */
1449 case 0x1c: /* FUNC_MUX_CTRL_6 */
1450 case 0x20: /* FUNC_MUX_CTRL_7 */
1451 case 0x24: /* FUNC_MUX_CTRL_8 */
1452 case 0x28: /* FUNC_MUX_CTRL_9 */
1453 case 0x2c: /* FUNC_MUX_CTRL_A */
1454 case 0x30: /* FUNC_MUX_CTRL_B */
1455 case 0x34: /* FUNC_MUX_CTRL_C */
1456 case 0x38: /* FUNC_MUX_CTRL_D */
1457 s
->func_mux_ctrl
[(offset
>> 2) - 1] = value
;
1460 case 0x40: /* PULL_DWN_CTRL_0 */
1461 case 0x44: /* PULL_DWN_CTRL_1 */
1462 case 0x48: /* PULL_DWN_CTRL_2 */
1463 case 0x4c: /* PULL_DWN_CTRL_3 */
1464 s
->pull_dwn_ctrl
[(offset
& 0xf) >> 2] = value
;
1467 case 0x50: /* GATE_INH_CTRL_0 */
1468 s
->gate_inh_ctrl
[0] = value
;
1471 case 0x60: /* VOLTAGE_CTRL_0 */
1472 s
->voltage_ctrl
[0] = value
;
1475 case 0x70: /* TEST_DBG_CTRL_0 */
1476 s
->test_dbg_ctrl
[0] = value
;
1479 case 0x80: /* MOD_CONF_CTRL_0 */
1480 diff
= s
->mod_conf_ctrl
[0] ^ value
;
1481 s
->mod_conf_ctrl
[0] = value
;
1482 omap_pin_modconf1_update(s
, diff
, value
);
1490 static CPUReadMemoryFunc
*omap_pin_cfg_readfn
[] = {
1491 omap_badwidth_read32
,
1492 omap_badwidth_read32
,
1496 static CPUWriteMemoryFunc
*omap_pin_cfg_writefn
[] = {
1497 omap_badwidth_write32
,
1498 omap_badwidth_write32
,
1502 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
1504 /* Start in Compatibility Mode. */
1505 mpu
->compat1509
= 1;
1506 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
1507 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
1508 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
1509 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
1510 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
1511 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
1512 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
1513 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
1514 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
1515 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
1518 static void omap_pin_cfg_init(target_phys_addr_t base
,
1519 struct omap_mpu_state_s
*mpu
)
1521 int iomemtype
= cpu_register_io_memory(0, omap_pin_cfg_readfn
,
1522 omap_pin_cfg_writefn
, mpu
);
1524 mpu
->pin_cfg_base
= base
;
1525 cpu_register_physical_memory(mpu
->pin_cfg_base
, 0x800, iomemtype
);
1526 omap_pin_cfg_reset(mpu
);
1529 /* Device Identification, Die Identification */
1530 static uint32_t omap_id_read(void *opaque
, target_phys_addr_t addr
)
1532 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1535 case 0xfffe1800: /* DIE_ID_LSB */
1537 case 0xfffe1804: /* DIE_ID_MSB */
1540 case 0xfffe2000: /* PRODUCT_ID_LSB */
1542 case 0xfffe2004: /* PRODUCT_ID_MSB */
1545 case 0xfffed400: /* JTAG_ID_LSB */
1546 switch (s
->mpu_model
) {
1552 cpu_abort(cpu_single_env
, "%s: bad mpu model\n", __FUNCTION__
);
1556 case 0xfffed404: /* JTAG_ID_MSB */
1557 switch (s
->mpu_model
) {
1563 cpu_abort(cpu_single_env
, "%s: bad mpu model\n", __FUNCTION__
);
1572 static void omap_id_write(void *opaque
, target_phys_addr_t addr
,
1578 static CPUReadMemoryFunc
*omap_id_readfn
[] = {
1579 omap_badwidth_read32
,
1580 omap_badwidth_read32
,
1584 static CPUWriteMemoryFunc
*omap_id_writefn
[] = {
1585 omap_badwidth_write32
,
1586 omap_badwidth_write32
,
1590 static void omap_id_init(struct omap_mpu_state_s
*mpu
)
1592 int iomemtype
= cpu_register_io_memory(0, omap_id_readfn
,
1593 omap_id_writefn
, mpu
);
1594 cpu_register_physical_memory(0xfffe1800, 0x800, iomemtype
);
1595 cpu_register_physical_memory(0xfffed400, 0x100, iomemtype
);
1596 if (!cpu_is_omap15xx(mpu
))
1597 cpu_register_physical_memory(0xfffe2000, 0x800, iomemtype
);
1600 /* MPUI Control (Dummy) */
1601 static uint32_t omap_mpui_read(void *opaque
, target_phys_addr_t addr
)
1603 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1604 int offset
= addr
- s
->mpui_base
;
1607 case 0x00: /* CTRL */
1608 return s
->mpui_ctrl
;
1609 case 0x04: /* DEBUG_ADDR */
1611 case 0x08: /* DEBUG_DATA */
1613 case 0x0c: /* DEBUG_FLAG */
1615 case 0x10: /* STATUS */
1618 /* Not in OMAP310 */
1619 case 0x14: /* DSP_STATUS */
1620 case 0x18: /* DSP_BOOT_CONFIG */
1622 case 0x1c: /* DSP_MPUI_CONFIG */
1630 static void omap_mpui_write(void *opaque
, target_phys_addr_t addr
,
1633 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1634 int offset
= addr
- s
->mpui_base
;
1637 case 0x00: /* CTRL */
1638 s
->mpui_ctrl
= value
& 0x007fffff;
1641 case 0x04: /* DEBUG_ADDR */
1642 case 0x08: /* DEBUG_DATA */
1643 case 0x0c: /* DEBUG_FLAG */
1644 case 0x10: /* STATUS */
1645 /* Not in OMAP310 */
1646 case 0x14: /* DSP_STATUS */
1648 case 0x18: /* DSP_BOOT_CONFIG */
1649 case 0x1c: /* DSP_MPUI_CONFIG */
1657 static CPUReadMemoryFunc
*omap_mpui_readfn
[] = {
1658 omap_badwidth_read32
,
1659 omap_badwidth_read32
,
1663 static CPUWriteMemoryFunc
*omap_mpui_writefn
[] = {
1664 omap_badwidth_write32
,
1665 omap_badwidth_write32
,
1669 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1671 s
->mpui_ctrl
= 0x0003ff1b;
1674 static void omap_mpui_init(target_phys_addr_t base
,
1675 struct omap_mpu_state_s
*mpu
)
1677 int iomemtype
= cpu_register_io_memory(0, omap_mpui_readfn
,
1678 omap_mpui_writefn
, mpu
);
1680 mpu
->mpui_base
= base
;
1681 cpu_register_physical_memory(mpu
->mpui_base
, 0x100, iomemtype
);
1683 omap_mpui_reset(mpu
);
1687 struct omap_tipb_bridge_s
{
1688 target_phys_addr_t base
;
1695 uint16_t enh_control
;
1698 static uint32_t omap_tipb_bridge_read(void *opaque
, target_phys_addr_t addr
)
1700 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1701 int offset
= addr
- s
->base
;
1704 case 0x00: /* TIPB_CNTL */
1706 case 0x04: /* TIPB_BUS_ALLOC */
1708 case 0x08: /* MPU_TIPB_CNTL */
1710 case 0x0c: /* ENHANCED_TIPB_CNTL */
1711 return s
->enh_control
;
1712 case 0x10: /* ADDRESS_DBG */
1713 case 0x14: /* DATA_DEBUG_LOW */
1714 case 0x18: /* DATA_DEBUG_HIGH */
1716 case 0x1c: /* DEBUG_CNTR_SIG */
1724 static void omap_tipb_bridge_write(void *opaque
, target_phys_addr_t addr
,
1727 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1728 int offset
= addr
- s
->base
;
1731 case 0x00: /* TIPB_CNTL */
1732 s
->control
= value
& 0xffff;
1735 case 0x04: /* TIPB_BUS_ALLOC */
1736 s
->alloc
= value
& 0x003f;
1739 case 0x08: /* MPU_TIPB_CNTL */
1740 s
->buffer
= value
& 0x0003;
1743 case 0x0c: /* ENHANCED_TIPB_CNTL */
1744 s
->width_intr
= !(value
& 2);
1745 s
->enh_control
= value
& 0x000f;
1748 case 0x10: /* ADDRESS_DBG */
1749 case 0x14: /* DATA_DEBUG_LOW */
1750 case 0x18: /* DATA_DEBUG_HIGH */
1751 case 0x1c: /* DEBUG_CNTR_SIG */
1760 static CPUReadMemoryFunc
*omap_tipb_bridge_readfn
[] = {
1761 omap_badwidth_read16
,
1762 omap_tipb_bridge_read
,
1763 omap_tipb_bridge_read
,
1766 static CPUWriteMemoryFunc
*omap_tipb_bridge_writefn
[] = {
1767 omap_badwidth_write16
,
1768 omap_tipb_bridge_write
,
1769 omap_tipb_bridge_write
,
1772 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1774 s
->control
= 0xffff;
1777 s
->enh_control
= 0x000f;
1780 struct omap_tipb_bridge_s
*omap_tipb_bridge_init(target_phys_addr_t base
,
1781 qemu_irq abort_irq
, omap_clk clk
)
1784 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*)
1785 qemu_mallocz(sizeof(struct omap_tipb_bridge_s
));
1787 s
->abort
= abort_irq
;
1789 omap_tipb_bridge_reset(s
);
1791 iomemtype
= cpu_register_io_memory(0, omap_tipb_bridge_readfn
,
1792 omap_tipb_bridge_writefn
, s
);
1793 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
1798 /* Dummy Traffic Controller's Memory Interface */
1799 static uint32_t omap_tcmi_read(void *opaque
, target_phys_addr_t addr
)
1801 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1802 int offset
= addr
- s
->tcmi_base
;
1806 case 0x00: /* IMIF_PRIO */
1807 case 0x04: /* EMIFS_PRIO */
1808 case 0x08: /* EMIFF_PRIO */
1809 case 0x0c: /* EMIFS_CONFIG */
1810 case 0x10: /* EMIFS_CS0_CONFIG */
1811 case 0x14: /* EMIFS_CS1_CONFIG */
1812 case 0x18: /* EMIFS_CS2_CONFIG */
1813 case 0x1c: /* EMIFS_CS3_CONFIG */
1814 case 0x24: /* EMIFF_MRS */
1815 case 0x28: /* TIMEOUT1 */
1816 case 0x2c: /* TIMEOUT2 */
1817 case 0x30: /* TIMEOUT3 */
1818 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1819 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1820 return s
->tcmi_regs
[offset
>> 2];
1822 case 0x20: /* EMIFF_SDRAM_CONFIG */
1823 ret
= s
->tcmi_regs
[offset
>> 2];
1824 s
->tcmi_regs
[offset
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1825 /* XXX: We can try using the VGA_DIRTY flag for this */
1833 static void omap_tcmi_write(void *opaque
, target_phys_addr_t addr
,
1836 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1837 int offset
= addr
- s
->tcmi_base
;
1840 case 0x00: /* IMIF_PRIO */
1841 case 0x04: /* EMIFS_PRIO */
1842 case 0x08: /* EMIFF_PRIO */
1843 case 0x10: /* EMIFS_CS0_CONFIG */
1844 case 0x14: /* EMIFS_CS1_CONFIG */
1845 case 0x18: /* EMIFS_CS2_CONFIG */
1846 case 0x1c: /* EMIFS_CS3_CONFIG */
1847 case 0x20: /* EMIFF_SDRAM_CONFIG */
1848 case 0x24: /* EMIFF_MRS */
1849 case 0x28: /* TIMEOUT1 */
1850 case 0x2c: /* TIMEOUT2 */
1851 case 0x30: /* TIMEOUT3 */
1852 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1853 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1854 s
->tcmi_regs
[offset
>> 2] = value
;
1856 case 0x0c: /* EMIFS_CONFIG */
1857 s
->tcmi_regs
[offset
>> 2] = (value
& 0xf) | (1 << 4);
1865 static CPUReadMemoryFunc
*omap_tcmi_readfn
[] = {
1866 omap_badwidth_read32
,
1867 omap_badwidth_read32
,
1871 static CPUWriteMemoryFunc
*omap_tcmi_writefn
[] = {
1872 omap_badwidth_write32
,
1873 omap_badwidth_write32
,
1877 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1879 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1880 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1881 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1882 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1883 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1884 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1885 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1886 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1887 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1888 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1889 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1890 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1891 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1892 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1893 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1896 static void omap_tcmi_init(target_phys_addr_t base
,
1897 struct omap_mpu_state_s
*mpu
)
1899 int iomemtype
= cpu_register_io_memory(0, omap_tcmi_readfn
,
1900 omap_tcmi_writefn
, mpu
);
1902 mpu
->tcmi_base
= base
;
1903 cpu_register_physical_memory(mpu
->tcmi_base
, 0x100, iomemtype
);
1904 omap_tcmi_reset(mpu
);
1907 /* Digital phase-locked loops control */
1908 static uint32_t omap_dpll_read(void *opaque
, target_phys_addr_t addr
)
1910 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1911 int offset
= addr
- s
->base
;
1913 if (offset
== 0x00) /* CTL_REG */
1920 static void omap_dpll_write(void *opaque
, target_phys_addr_t addr
,
1923 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1925 int offset
= addr
- s
->base
;
1926 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1929 if (offset
== 0x00) { /* CTL_REG */
1930 /* See omap_ulpd_pm_write() too */
1931 diff
= s
->mode
& value
;
1932 s
->mode
= value
& 0x2fff;
1933 if (diff
& (0x3ff << 2)) {
1934 if (value
& (1 << 4)) { /* PLL_ENABLE */
1935 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1936 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1938 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1941 omap_clk_setrate(s
->dpll
, div
, mult
);
1944 /* Enter the desired mode. */
1945 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1947 /* Act as if the lock is restored. */
1954 static CPUReadMemoryFunc
*omap_dpll_readfn
[] = {
1955 omap_badwidth_read16
,
1957 omap_badwidth_read16
,
1960 static CPUWriteMemoryFunc
*omap_dpll_writefn
[] = {
1961 omap_badwidth_write16
,
1963 omap_badwidth_write16
,
1966 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1969 omap_clk_setrate(s
->dpll
, 1, 1);
1972 static void omap_dpll_init(struct dpll_ctl_s
*s
, target_phys_addr_t base
,
1975 int iomemtype
= cpu_register_io_memory(0, omap_dpll_readfn
,
1976 omap_dpll_writefn
, s
);
1982 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
1986 struct omap_uart_s
{
1987 SerialState
*serial
; /* TODO */
1988 struct omap_target_agent_s
*ta
;
1989 target_phys_addr_t base
;
2001 void omap_uart_reset(struct omap_uart_s
*s
)
2009 struct omap_uart_s
*omap_uart_init(target_phys_addr_t base
,
2010 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
2011 qemu_irq txdma
, qemu_irq rxdma
, CharDriverState
*chr
)
2013 struct omap_uart_s
*s
= (struct omap_uart_s
*)
2014 qemu_mallocz(sizeof(struct omap_uart_s
));
2019 s
->serial
= serial_mm_init(base
, 2, irq
, omap_clk_getrate(fclk
)/16,
2020 chr
?: qemu_chr_open("null"), 1);
2025 static uint32_t omap_uart_read(void *opaque
, target_phys_addr_t addr
)
2027 struct omap_uart_s
*s
= (struct omap_uart_s
*) opaque
;
2028 int offset
= addr
- s
->base
;
2031 case 0x20: /* MDR1 */
2033 case 0x24: /* MDR2 */
2035 case 0x40: /* SCR */
2037 case 0x44: /* SSR */
2039 case 0x48: /* EBLR */
2041 case 0x50: /* MVR */
2043 case 0x54: /* SYSC */
2044 return s
->syscontrol
;
2045 case 0x58: /* SYSS */
2047 case 0x5c: /* WER */
2049 case 0x60: /* CFPS */
2057 static void omap_uart_write(void *opaque
, target_phys_addr_t addr
,
2060 struct omap_uart_s
*s
= (struct omap_uart_s
*) opaque
;
2061 int offset
= addr
- s
->base
;
2064 case 0x20: /* MDR1 */
2065 s
->mdr
[0] = value
& 0x7f;
2067 case 0x24: /* MDR2 */
2068 s
->mdr
[1] = value
& 0xff;
2070 case 0x40: /* SCR */
2071 s
->scr
= value
& 0xff;
2073 case 0x48: /* EBLR */
2074 s
->eblr
= value
& 0xff;
2076 case 0x44: /* SSR */
2077 case 0x50: /* MVR */
2078 case 0x58: /* SYSS */
2081 case 0x54: /* SYSC */
2082 s
->syscontrol
= value
& 0x1d;
2086 case 0x5c: /* WER */
2087 s
->wkup
= value
& 0x7f;
2089 case 0x60: /* CFPS */
2090 s
->cfps
= value
& 0xff;
2097 static CPUReadMemoryFunc
*omap_uart_readfn
[] = {
2100 omap_badwidth_read8
,
2103 static CPUWriteMemoryFunc
*omap_uart_writefn
[] = {
2106 omap_badwidth_write8
,
2109 struct omap_uart_s
*omap2_uart_init(struct omap_target_agent_s
*ta
,
2110 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
2111 qemu_irq txdma
, qemu_irq rxdma
, CharDriverState
*chr
)
2113 target_phys_addr_t base
= omap_l4_attach(ta
, 0, 0);
2114 struct omap_uart_s
*s
= omap_uart_init(base
, irq
,
2115 fclk
, iclk
, txdma
, rxdma
, chr
);
2116 int iomemtype
= cpu_register_io_memory(0, omap_uart_readfn
,
2117 omap_uart_writefn
, s
);
2121 cpu_register_physical_memory(s
->base
+ 0x20, 0x100, iomemtype
);
2126 void omap_uart_attach(struct omap_uart_s
*s
, CharDriverState
*chr
)
2128 /* TODO: Should reuse or destroy current s->serial */
2129 s
->serial
= serial_mm_init(s
->base
, 2, s
->irq
,
2130 omap_clk_getrate(s
->fclk
) / 16,
2131 chr
?: qemu_chr_open("null"), 1);
2134 /* MPU Clock/Reset/Power Mode Control */
2135 static uint32_t omap_clkm_read(void *opaque
, target_phys_addr_t addr
)
2137 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2138 int offset
= addr
- s
->clkm
.mpu_base
;
2141 case 0x00: /* ARM_CKCTL */
2142 return s
->clkm
.arm_ckctl
;
2144 case 0x04: /* ARM_IDLECT1 */
2145 return s
->clkm
.arm_idlect1
;
2147 case 0x08: /* ARM_IDLECT2 */
2148 return s
->clkm
.arm_idlect2
;
2150 case 0x0c: /* ARM_EWUPCT */
2151 return s
->clkm
.arm_ewupct
;
2153 case 0x10: /* ARM_RSTCT1 */
2154 return s
->clkm
.arm_rstct1
;
2156 case 0x14: /* ARM_RSTCT2 */
2157 return s
->clkm
.arm_rstct2
;
2159 case 0x18: /* ARM_SYSST */
2160 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
2162 case 0x1c: /* ARM_CKOUT1 */
2163 return s
->clkm
.arm_ckout1
;
2165 case 0x20: /* ARM_CKOUT2 */
2173 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
2174 uint16_t diff
, uint16_t value
)
2178 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
2179 if (value
& (1 << 14))
2182 clk
= omap_findclk(s
, "arminth_ck");
2183 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2186 if (diff
& (1 << 12)) { /* ARM_TIMXO */
2187 clk
= omap_findclk(s
, "armtim_ck");
2188 if (value
& (1 << 12))
2189 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
2191 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2194 if (diff
& (3 << 10)) { /* DSPMMUDIV */
2195 clk
= omap_findclk(s
, "dspmmu_ck");
2196 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
2198 if (diff
& (3 << 8)) { /* TCDIV */
2199 clk
= omap_findclk(s
, "tc_ck");
2200 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
2202 if (diff
& (3 << 6)) { /* DSPDIV */
2203 clk
= omap_findclk(s
, "dsp_ck");
2204 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
2206 if (diff
& (3 << 4)) { /* ARMDIV */
2207 clk
= omap_findclk(s
, "arm_ck");
2208 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
2210 if (diff
& (3 << 2)) { /* LCDDIV */
2211 clk
= omap_findclk(s
, "lcd_ck");
2212 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
2214 if (diff
& (3 << 0)) { /* PERDIV */
2215 clk
= omap_findclk(s
, "armper_ck");
2216 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
2220 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
2221 uint16_t diff
, uint16_t value
)
2225 if (value
& (1 << 11)) /* SETARM_IDLE */
2226 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
2227 if (!(value
& (1 << 10))) /* WKUP_MODE */
2228 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
2230 #define SET_CANIDLE(clock, bit) \
2231 if (diff & (1 << bit)) { \
2232 clk = omap_findclk(s, clock); \
2233 omap_clk_canidle(clk, (value >> bit) & 1); \
2235 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
2236 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
2237 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
2238 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
2239 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
2240 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
2241 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
2242 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
2243 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
2244 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
2245 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
2246 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
2247 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
2248 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
2251 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
2252 uint16_t diff
, uint16_t value
)
2256 #define SET_ONOFF(clock, bit) \
2257 if (diff & (1 << bit)) { \
2258 clk = omap_findclk(s, clock); \
2259 omap_clk_onoff(clk, (value >> bit) & 1); \
2261 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
2262 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
2263 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
2264 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
2265 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
2266 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
2267 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
2268 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
2269 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
2270 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
2271 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
2274 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
2275 uint16_t diff
, uint16_t value
)
2279 if (diff
& (3 << 4)) { /* TCLKOUT */
2280 clk
= omap_findclk(s
, "tclk_out");
2281 switch ((value
>> 4) & 3) {
2283 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
2284 omap_clk_onoff(clk
, 1);
2287 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2288 omap_clk_onoff(clk
, 1);
2291 omap_clk_onoff(clk
, 0);
2294 if (diff
& (3 << 2)) { /* DCLKOUT */
2295 clk
= omap_findclk(s
, "dclk_out");
2296 switch ((value
>> 2) & 3) {
2298 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
2301 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
2304 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
2307 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2311 if (diff
& (3 << 0)) { /* ACLKOUT */
2312 clk
= omap_findclk(s
, "aclk_out");
2313 switch ((value
>> 0) & 3) {
2315 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2316 omap_clk_onoff(clk
, 1);
2319 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
2320 omap_clk_onoff(clk
, 1);
2323 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2324 omap_clk_onoff(clk
, 1);
2327 omap_clk_onoff(clk
, 0);
2332 static void omap_clkm_write(void *opaque
, target_phys_addr_t addr
,
2335 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2336 int offset
= addr
- s
->clkm
.mpu_base
;
2339 static const char *clkschemename
[8] = {
2340 "fully synchronous", "fully asynchronous", "synchronous scalable",
2341 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
2345 case 0x00: /* ARM_CKCTL */
2346 diff
= s
->clkm
.arm_ckctl
^ value
;
2347 s
->clkm
.arm_ckctl
= value
& 0x7fff;
2348 omap_clkm_ckctl_update(s
, diff
, value
);
2351 case 0x04: /* ARM_IDLECT1 */
2352 diff
= s
->clkm
.arm_idlect1
^ value
;
2353 s
->clkm
.arm_idlect1
= value
& 0x0fff;
2354 omap_clkm_idlect1_update(s
, diff
, value
);
2357 case 0x08: /* ARM_IDLECT2 */
2358 diff
= s
->clkm
.arm_idlect2
^ value
;
2359 s
->clkm
.arm_idlect2
= value
& 0x07ff;
2360 omap_clkm_idlect2_update(s
, diff
, value
);
2363 case 0x0c: /* ARM_EWUPCT */
2364 diff
= s
->clkm
.arm_ewupct
^ value
;
2365 s
->clkm
.arm_ewupct
= value
& 0x003f;
2368 case 0x10: /* ARM_RSTCT1 */
2369 diff
= s
->clkm
.arm_rstct1
^ value
;
2370 s
->clkm
.arm_rstct1
= value
& 0x0007;
2372 qemu_system_reset_request();
2373 s
->clkm
.cold_start
= 0xa;
2375 if (diff
& ~value
& 4) { /* DSP_RST */
2377 omap_tipb_bridge_reset(s
->private_tipb
);
2378 omap_tipb_bridge_reset(s
->public_tipb
);
2380 if (diff
& 2) { /* DSP_EN */
2381 clk
= omap_findclk(s
, "dsp_ck");
2382 omap_clk_canidle(clk
, (~value
>> 1) & 1);
2386 case 0x14: /* ARM_RSTCT2 */
2387 s
->clkm
.arm_rstct2
= value
& 0x0001;
2390 case 0x18: /* ARM_SYSST */
2391 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
2392 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
2393 printf("%s: clocking scheme set to %s\n", __FUNCTION__
,
2394 clkschemename
[s
->clkm
.clocking_scheme
]);
2396 s
->clkm
.cold_start
&= value
& 0x3f;
2399 case 0x1c: /* ARM_CKOUT1 */
2400 diff
= s
->clkm
.arm_ckout1
^ value
;
2401 s
->clkm
.arm_ckout1
= value
& 0x003f;
2402 omap_clkm_ckout1_update(s
, diff
, value
);
2405 case 0x20: /* ARM_CKOUT2 */
2411 static CPUReadMemoryFunc
*omap_clkm_readfn
[] = {
2412 omap_badwidth_read16
,
2414 omap_badwidth_read16
,
2417 static CPUWriteMemoryFunc
*omap_clkm_writefn
[] = {
2418 omap_badwidth_write16
,
2420 omap_badwidth_write16
,
2423 static uint32_t omap_clkdsp_read(void *opaque
, target_phys_addr_t addr
)
2425 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2426 int offset
= addr
- s
->clkm
.dsp_base
;
2429 case 0x04: /* DSP_IDLECT1 */
2430 return s
->clkm
.dsp_idlect1
;
2432 case 0x08: /* DSP_IDLECT2 */
2433 return s
->clkm
.dsp_idlect2
;
2435 case 0x14: /* DSP_RSTCT2 */
2436 return s
->clkm
.dsp_rstct2
;
2438 case 0x18: /* DSP_SYSST */
2439 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
2440 (s
->env
->halted
<< 6); /* Quite useless... */
2447 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
2448 uint16_t diff
, uint16_t value
)
2452 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
2455 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
2456 uint16_t diff
, uint16_t value
)
2460 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
2463 static void omap_clkdsp_write(void *opaque
, target_phys_addr_t addr
,
2466 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2467 int offset
= addr
- s
->clkm
.dsp_base
;
2471 case 0x04: /* DSP_IDLECT1 */
2472 diff
= s
->clkm
.dsp_idlect1
^ value
;
2473 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
2474 omap_clkdsp_idlect1_update(s
, diff
, value
);
2477 case 0x08: /* DSP_IDLECT2 */
2478 s
->clkm
.dsp_idlect2
= value
& 0x0037;
2479 diff
= s
->clkm
.dsp_idlect1
^ value
;
2480 omap_clkdsp_idlect2_update(s
, diff
, value
);
2483 case 0x14: /* DSP_RSTCT2 */
2484 s
->clkm
.dsp_rstct2
= value
& 0x0001;
2487 case 0x18: /* DSP_SYSST */
2488 s
->clkm
.cold_start
&= value
& 0x3f;
2496 static CPUReadMemoryFunc
*omap_clkdsp_readfn
[] = {
2497 omap_badwidth_read16
,
2499 omap_badwidth_read16
,
2502 static CPUWriteMemoryFunc
*omap_clkdsp_writefn
[] = {
2503 omap_badwidth_write16
,
2505 omap_badwidth_write16
,
2508 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
2510 if (s
->wdt
&& s
->wdt
->reset
)
2511 s
->clkm
.cold_start
= 0x6;
2512 s
->clkm
.clocking_scheme
= 0;
2513 omap_clkm_ckctl_update(s
, ~0, 0x3000);
2514 s
->clkm
.arm_ckctl
= 0x3000;
2515 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
2516 s
->clkm
.arm_idlect1
= 0x0400;
2517 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
2518 s
->clkm
.arm_idlect2
= 0x0100;
2519 s
->clkm
.arm_ewupct
= 0x003f;
2520 s
->clkm
.arm_rstct1
= 0x0000;
2521 s
->clkm
.arm_rstct2
= 0x0000;
2522 s
->clkm
.arm_ckout1
= 0x0015;
2523 s
->clkm
.dpll1_mode
= 0x2002;
2524 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
2525 s
->clkm
.dsp_idlect1
= 0x0040;
2526 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
2527 s
->clkm
.dsp_idlect2
= 0x0000;
2528 s
->clkm
.dsp_rstct2
= 0x0000;
2531 static void omap_clkm_init(target_phys_addr_t mpu_base
,
2532 target_phys_addr_t dsp_base
, struct omap_mpu_state_s
*s
)
2534 int iomemtype
[2] = {
2535 cpu_register_io_memory(0, omap_clkm_readfn
, omap_clkm_writefn
, s
),
2536 cpu_register_io_memory(0, omap_clkdsp_readfn
, omap_clkdsp_writefn
, s
),
2539 s
->clkm
.mpu_base
= mpu_base
;
2540 s
->clkm
.dsp_base
= dsp_base
;
2541 s
->clkm
.arm_idlect1
= 0x03ff;
2542 s
->clkm
.arm_idlect2
= 0x0100;
2543 s
->clkm
.dsp_idlect1
= 0x0002;
2545 s
->clkm
.cold_start
= 0x3a;
2547 cpu_register_physical_memory(s
->clkm
.mpu_base
, 0x100, iomemtype
[0]);
2548 cpu_register_physical_memory(s
->clkm
.dsp_base
, 0x1000, iomemtype
[1]);
2552 struct omap_mpuio_s
{
2553 target_phys_addr_t base
;
2557 qemu_irq handler
[16];
2578 static void omap_mpuio_set(void *opaque
, int line
, int level
)
2580 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2581 uint16_t prev
= s
->inputs
;
2584 s
->inputs
|= 1 << line
;
2586 s
->inputs
&= ~(1 << line
);
2588 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
2589 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
2590 s
->ints
|= 1 << line
;
2591 qemu_irq_raise(s
->irq
);
2594 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
2595 (s
->event
>> 1) == line
) /* PIN_SELECT */
2596 s
->latch
= s
->inputs
;
2600 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
2603 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
2605 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
2609 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
2610 s
->row_latch
= ~rows
;
2613 static uint32_t omap_mpuio_read(void *opaque
, target_phys_addr_t addr
)
2615 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2616 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2620 case 0x00: /* INPUT_LATCH */
2623 case 0x04: /* OUTPUT_REG */
2626 case 0x08: /* IO_CNTL */
2629 case 0x10: /* KBR_LATCH */
2630 return s
->row_latch
;
2632 case 0x14: /* KBC_REG */
2635 case 0x18: /* GPIO_EVENT_MODE_REG */
2638 case 0x1c: /* GPIO_INT_EDGE_REG */
2641 case 0x20: /* KBD_INT */
2642 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
2644 case 0x24: /* GPIO_INT */
2648 qemu_irq_lower(s
->irq
);
2651 case 0x28: /* KBD_MASKIT */
2654 case 0x2c: /* GPIO_MASKIT */
2657 case 0x30: /* GPIO_DEBOUNCING_REG */
2660 case 0x34: /* GPIO_LATCH_REG */
2668 static void omap_mpuio_write(void *opaque
, target_phys_addr_t addr
,
2671 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2672 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2677 case 0x04: /* OUTPUT_REG */
2678 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2680 while ((ln
= ffs(diff
))) {
2683 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2688 case 0x08: /* IO_CNTL */
2689 diff
= s
->outputs
& (s
->dir
^ value
);
2692 value
= s
->outputs
& ~s
->dir
;
2693 while ((ln
= ffs(diff
))) {
2696 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2701 case 0x14: /* KBC_REG */
2703 omap_mpuio_kbd_update(s
);
2706 case 0x18: /* GPIO_EVENT_MODE_REG */
2707 s
->event
= value
& 0x1f;
2710 case 0x1c: /* GPIO_INT_EDGE_REG */
2714 case 0x28: /* KBD_MASKIT */
2715 s
->kbd_mask
= value
& 1;
2716 omap_mpuio_kbd_update(s
);
2719 case 0x2c: /* GPIO_MASKIT */
2723 case 0x30: /* GPIO_DEBOUNCING_REG */
2724 s
->debounce
= value
& 0x1ff;
2727 case 0x00: /* INPUT_LATCH */
2728 case 0x10: /* KBR_LATCH */
2729 case 0x20: /* KBD_INT */
2730 case 0x24: /* GPIO_INT */
2731 case 0x34: /* GPIO_LATCH_REG */
2741 static CPUReadMemoryFunc
*omap_mpuio_readfn
[] = {
2742 omap_badwidth_read16
,
2744 omap_badwidth_read16
,
2747 static CPUWriteMemoryFunc
*omap_mpuio_writefn
[] = {
2748 omap_badwidth_write16
,
2750 omap_badwidth_write16
,
2753 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2765 s
->row_latch
= 0x1f;
2769 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2771 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2775 omap_mpuio_kbd_update(s
);
2778 struct omap_mpuio_s
*omap_mpuio_init(target_phys_addr_t base
,
2779 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2783 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*)
2784 qemu_mallocz(sizeof(struct omap_mpuio_s
));
2788 s
->kbd_irq
= kbd_int
;
2790 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2791 omap_mpuio_reset(s
);
2793 iomemtype
= cpu_register_io_memory(0, omap_mpuio_readfn
,
2794 omap_mpuio_writefn
, s
);
2795 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
2797 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_mpuio_onoff
, s
, 1)[0]);
2802 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2807 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2809 if (line
>= 16 || line
< 0)
2810 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
2811 s
->handler
[line
] = handler
;
2814 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2816 if (row
>= 5 || row
< 0)
2817 cpu_abort(cpu_single_env
, "%s: No key %i-%i\n",
2818 __FUNCTION__
, col
, row
);
2821 s
->buttons
[row
] |= 1 << col
;
2823 s
->buttons
[row
] &= ~(1 << col
);
2825 omap_mpuio_kbd_update(s
);
2828 /* General-Purpose I/O */
2829 struct omap_gpio_s
{
2830 target_phys_addr_t base
;
2833 qemu_irq handler
[16];
2844 static void omap_gpio_set(void *opaque
, int line
, int level
)
2846 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2847 uint16_t prev
= s
->inputs
;
2850 s
->inputs
|= 1 << line
;
2852 s
->inputs
&= ~(1 << line
);
2854 if (((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) &
2855 (1 << line
) & s
->dir
& ~s
->mask
) {
2856 s
->ints
|= 1 << line
;
2857 qemu_irq_raise(s
->irq
);
2861 static uint32_t omap_gpio_read(void *opaque
, target_phys_addr_t addr
)
2863 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2864 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2867 case 0x00: /* DATA_INPUT */
2868 return s
->inputs
& s
->pins
;
2870 case 0x04: /* DATA_OUTPUT */
2873 case 0x08: /* DIRECTION_CONTROL */
2876 case 0x0c: /* INTERRUPT_CONTROL */
2879 case 0x10: /* INTERRUPT_MASK */
2882 case 0x14: /* INTERRUPT_STATUS */
2885 case 0x18: /* PIN_CONTROL (not in OMAP310) */
2894 static void omap_gpio_write(void *opaque
, target_phys_addr_t addr
,
2897 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2898 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2903 case 0x00: /* DATA_INPUT */
2907 case 0x04: /* DATA_OUTPUT */
2908 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2910 while ((ln
= ffs(diff
))) {
2913 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2918 case 0x08: /* DIRECTION_CONTROL */
2919 diff
= s
->outputs
& (s
->dir
^ value
);
2922 value
= s
->outputs
& ~s
->dir
;
2923 while ((ln
= ffs(diff
))) {
2926 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2931 case 0x0c: /* INTERRUPT_CONTROL */
2935 case 0x10: /* INTERRUPT_MASK */
2939 case 0x14: /* INTERRUPT_STATUS */
2942 qemu_irq_lower(s
->irq
);
2945 case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */
2956 /* *Some* sources say the memory region is 32-bit. */
2957 static CPUReadMemoryFunc
*omap_gpio_readfn
[] = {
2958 omap_badwidth_read16
,
2960 omap_badwidth_read16
,
2963 static CPUWriteMemoryFunc
*omap_gpio_writefn
[] = {
2964 omap_badwidth_write16
,
2966 omap_badwidth_write16
,
2969 static void omap_gpio_reset(struct omap_gpio_s
*s
)
2980 struct omap_gpio_s
*omap_gpio_init(target_phys_addr_t base
,
2981 qemu_irq irq
, omap_clk clk
)
2984 struct omap_gpio_s
*s
= (struct omap_gpio_s
*)
2985 qemu_mallocz(sizeof(struct omap_gpio_s
));
2989 s
->in
= qemu_allocate_irqs(omap_gpio_set
, s
, 16);
2992 iomemtype
= cpu_register_io_memory(0, omap_gpio_readfn
,
2993 omap_gpio_writefn
, s
);
2994 cpu_register_physical_memory(s
->base
, 0x1000, iomemtype
);
2999 qemu_irq
*omap_gpio_in_get(struct omap_gpio_s
*s
)
3004 void omap_gpio_out_set(struct omap_gpio_s
*s
, int line
, qemu_irq handler
)
3006 if (line
>= 16 || line
< 0)
3007 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
3008 s
->handler
[line
] = handler
;
3011 /* MicroWire Interface */
3012 struct omap_uwire_s
{
3013 target_phys_addr_t base
;
3023 struct uwire_slave_s
*chip
[4];
3026 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
3028 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
3029 struct uwire_slave_s
*slave
= s
->chip
[chipselect
];
3031 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
3032 if (s
->control
& (1 << 12)) /* CS_CMD */
3033 if (slave
&& slave
->send
)
3034 slave
->send(slave
->opaque
,
3035 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
3036 s
->control
&= ~(1 << 14); /* CSRB */
3037 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3038 * a DRQ. When is the level IRQ supposed to be reset? */
3041 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
3042 if (s
->control
& (1 << 12)) /* CS_CMD */
3043 if (slave
&& slave
->receive
)
3044 s
->rxbuf
= slave
->receive(slave
->opaque
);
3045 s
->control
|= 1 << 15; /* RDRB */
3046 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3047 * a DRQ. When is the level IRQ supposed to be reset? */
3051 static uint32_t omap_uwire_read(void *opaque
, target_phys_addr_t addr
)
3053 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3054 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3057 case 0x00: /* RDR */
3058 s
->control
&= ~(1 << 15); /* RDRB */
3061 case 0x04: /* CSR */
3064 case 0x08: /* SR1 */
3066 case 0x0c: /* SR2 */
3068 case 0x10: /* SR3 */
3070 case 0x14: /* SR4 */
3072 case 0x18: /* SR5 */
3080 static void omap_uwire_write(void *opaque
, target_phys_addr_t addr
,
3083 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3084 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3087 case 0x00: /* TDR */
3088 s
->txbuf
= value
; /* TD */
3089 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
3090 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
3091 (s
->control
& (1 << 12)))) { /* CS_CMD */
3092 s
->control
|= 1 << 14; /* CSRB */
3093 omap_uwire_transfer_start(s
);
3097 case 0x04: /* CSR */
3098 s
->control
= value
& 0x1fff;
3099 if (value
& (1 << 13)) /* START */
3100 omap_uwire_transfer_start(s
);
3103 case 0x08: /* SR1 */
3104 s
->setup
[0] = value
& 0x003f;
3107 case 0x0c: /* SR2 */
3108 s
->setup
[1] = value
& 0x0fc0;
3111 case 0x10: /* SR3 */
3112 s
->setup
[2] = value
& 0x0003;
3115 case 0x14: /* SR4 */
3116 s
->setup
[3] = value
& 0x0001;
3119 case 0x18: /* SR5 */
3120 s
->setup
[4] = value
& 0x000f;
3129 static CPUReadMemoryFunc
*omap_uwire_readfn
[] = {
3130 omap_badwidth_read16
,
3132 omap_badwidth_read16
,
3135 static CPUWriteMemoryFunc
*omap_uwire_writefn
[] = {
3136 omap_badwidth_write16
,
3138 omap_badwidth_write16
,
3141 static void omap_uwire_reset(struct omap_uwire_s
*s
)
3151 struct omap_uwire_s
*omap_uwire_init(target_phys_addr_t base
,
3152 qemu_irq
*irq
, qemu_irq dma
, omap_clk clk
)
3155 struct omap_uwire_s
*s
= (struct omap_uwire_s
*)
3156 qemu_mallocz(sizeof(struct omap_uwire_s
));
3162 omap_uwire_reset(s
);
3164 iomemtype
= cpu_register_io_memory(0, omap_uwire_readfn
,
3165 omap_uwire_writefn
, s
);
3166 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
3171 void omap_uwire_attach(struct omap_uwire_s
*s
,
3172 struct uwire_slave_s
*slave
, int chipselect
)
3174 if (chipselect
< 0 || chipselect
> 3) {
3175 fprintf(stderr
, "%s: Bad chipselect %i\n", __FUNCTION__
, chipselect
);
3179 s
->chip
[chipselect
] = slave
;
3182 /* Pseudonoise Pulse-Width Light Modulator */
3183 static void omap_pwl_update(struct omap_mpu_state_s
*s
)
3185 int output
= (s
->pwl
.clk
&& s
->pwl
.enable
) ? s
->pwl
.level
: 0;
3187 if (output
!= s
->pwl
.output
) {
3188 s
->pwl
.output
= output
;
3189 printf("%s: Backlight now at %i/256\n", __FUNCTION__
, output
);
3193 static uint32_t omap_pwl_read(void *opaque
, target_phys_addr_t addr
)
3195 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3196 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3199 case 0x00: /* PWL_LEVEL */
3200 return s
->pwl
.level
;
3201 case 0x04: /* PWL_CTRL */
3202 return s
->pwl
.enable
;
3208 static void omap_pwl_write(void *opaque
, target_phys_addr_t addr
,
3211 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3212 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3215 case 0x00: /* PWL_LEVEL */
3216 s
->pwl
.level
= value
;
3219 case 0x04: /* PWL_CTRL */
3220 s
->pwl
.enable
= value
& 1;
3229 static CPUReadMemoryFunc
*omap_pwl_readfn
[] = {
3231 omap_badwidth_read8
,
3232 omap_badwidth_read8
,
3235 static CPUWriteMemoryFunc
*omap_pwl_writefn
[] = {
3237 omap_badwidth_write8
,
3238 omap_badwidth_write8
,
3241 static void omap_pwl_reset(struct omap_mpu_state_s
*s
)
3250 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
3252 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3258 static void omap_pwl_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3265 iomemtype
= cpu_register_io_memory(0, omap_pwl_readfn
,
3266 omap_pwl_writefn
, s
);
3267 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3269 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_pwl_clk_update
, s
, 1)[0]);
3272 /* Pulse-Width Tone module */
3273 static uint32_t omap_pwt_read(void *opaque
, target_phys_addr_t addr
)
3275 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3276 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3279 case 0x00: /* FRC */
3281 case 0x04: /* VCR */
3283 case 0x08: /* GCR */
3290 static void omap_pwt_write(void *opaque
, target_phys_addr_t addr
,
3293 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3294 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3297 case 0x00: /* FRC */
3298 s
->pwt
.frc
= value
& 0x3f;
3300 case 0x04: /* VRC */
3301 if ((value
^ s
->pwt
.vrc
) & 1) {
3303 printf("%s: %iHz buzz on\n", __FUNCTION__
, (int)
3304 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
3305 ((omap_clk_getrate(s
->pwt
.clk
) >> 3) /
3306 /* Pre-multiplexer divider */
3307 ((s
->pwt
.gcr
& 2) ? 1 : 154) /
3308 /* Octave multiplexer */
3309 (2 << (value
& 3)) *
3310 /* 101/107 divider */
3311 ((value
& (1 << 2)) ? 101 : 107) *
3313 ((value
& (1 << 3)) ? 49 : 55) *
3315 ((value
& (1 << 4)) ? 50 : 63) *
3316 /* 80/127 divider */
3317 ((value
& (1 << 5)) ? 80 : 127) /
3318 (107 * 55 * 63 * 127)));
3320 printf("%s: silence!\n", __FUNCTION__
);
3322 s
->pwt
.vrc
= value
& 0x7f;
3324 case 0x08: /* GCR */
3325 s
->pwt
.gcr
= value
& 3;
3333 static CPUReadMemoryFunc
*omap_pwt_readfn
[] = {
3335 omap_badwidth_read8
,
3336 omap_badwidth_read8
,
3339 static CPUWriteMemoryFunc
*omap_pwt_writefn
[] = {
3341 omap_badwidth_write8
,
3342 omap_badwidth_write8
,
3345 static void omap_pwt_reset(struct omap_mpu_state_s
*s
)
3352 static void omap_pwt_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3360 iomemtype
= cpu_register_io_memory(0, omap_pwt_readfn
,
3361 omap_pwt_writefn
, s
);
3362 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3365 /* Real-time Clock module */
3367 target_phys_addr_t base
;
3382 struct tm current_tm
;
3387 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
3389 /* s->alarm is level-triggered */
3390 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
3393 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
3395 s
->alarm_ti
= mktime(&s
->alarm_tm
);
3396 if (s
->alarm_ti
== -1)
3397 printf("%s: conversion failed\n", __FUNCTION__
);
3400 static inline uint8_t omap_rtc_bcd(int num
)
3402 return ((num
/ 10) << 4) | (num
% 10);
3405 static inline int omap_rtc_bin(uint8_t num
)
3407 return (num
& 15) + 10 * (num
>> 4);
3410 static uint32_t omap_rtc_read(void *opaque
, target_phys_addr_t addr
)
3412 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3413 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3417 case 0x00: /* SECONDS_REG */
3418 return omap_rtc_bcd(s
->current_tm
.tm_sec
);
3420 case 0x04: /* MINUTES_REG */
3421 return omap_rtc_bcd(s
->current_tm
.tm_min
);
3423 case 0x08: /* HOURS_REG */
3425 return ((s
->current_tm
.tm_hour
> 11) << 7) |
3426 omap_rtc_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
3428 return omap_rtc_bcd(s
->current_tm
.tm_hour
);
3430 case 0x0c: /* DAYS_REG */
3431 return omap_rtc_bcd(s
->current_tm
.tm_mday
);
3433 case 0x10: /* MONTHS_REG */
3434 return omap_rtc_bcd(s
->current_tm
.tm_mon
+ 1);
3436 case 0x14: /* YEARS_REG */
3437 return omap_rtc_bcd(s
->current_tm
.tm_year
% 100);
3439 case 0x18: /* WEEK_REG */
3440 return s
->current_tm
.tm_wday
;
3442 case 0x20: /* ALARM_SECONDS_REG */
3443 return omap_rtc_bcd(s
->alarm_tm
.tm_sec
);
3445 case 0x24: /* ALARM_MINUTES_REG */
3446 return omap_rtc_bcd(s
->alarm_tm
.tm_min
);
3448 case 0x28: /* ALARM_HOURS_REG */
3450 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
3451 omap_rtc_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
3453 return omap_rtc_bcd(s
->alarm_tm
.tm_hour
);
3455 case 0x2c: /* ALARM_DAYS_REG */
3456 return omap_rtc_bcd(s
->alarm_tm
.tm_mday
);
3458 case 0x30: /* ALARM_MONTHS_REG */
3459 return omap_rtc_bcd(s
->alarm_tm
.tm_mon
+ 1);
3461 case 0x34: /* ALARM_YEARS_REG */
3462 return omap_rtc_bcd(s
->alarm_tm
.tm_year
% 100);
3464 case 0x40: /* RTC_CTRL_REG */
3465 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
3466 (s
->round
<< 1) | s
->running
;
3468 case 0x44: /* RTC_STATUS_REG */
3473 case 0x48: /* RTC_INTERRUPTS_REG */
3474 return s
->interrupts
;
3476 case 0x4c: /* RTC_COMP_LSB_REG */
3477 return ((uint16_t) s
->comp_reg
) & 0xff;
3479 case 0x50: /* RTC_COMP_MSB_REG */
3480 return ((uint16_t) s
->comp_reg
) >> 8;
3487 static void omap_rtc_write(void *opaque
, target_phys_addr_t addr
,
3490 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3491 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3496 case 0x00: /* SECONDS_REG */
3498 printf("RTC SEC_REG <-- %02x\n", value
);
3500 s
->ti
-= s
->current_tm
.tm_sec
;
3501 s
->ti
+= omap_rtc_bin(value
);
3504 case 0x04: /* MINUTES_REG */
3506 printf("RTC MIN_REG <-- %02x\n", value
);
3508 s
->ti
-= s
->current_tm
.tm_min
* 60;
3509 s
->ti
+= omap_rtc_bin(value
) * 60;
3512 case 0x08: /* HOURS_REG */
3514 printf("RTC HRS_REG <-- %02x\n", value
);
3516 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
3518 s
->ti
+= (omap_rtc_bin(value
& 0x3f) & 12) * 3600;
3519 s
->ti
+= ((value
>> 7) & 1) * 43200;
3521 s
->ti
+= omap_rtc_bin(value
& 0x3f) * 3600;
3524 case 0x0c: /* DAYS_REG */
3526 printf("RTC DAY_REG <-- %02x\n", value
);
3528 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
3529 s
->ti
+= omap_rtc_bin(value
) * 86400;
3532 case 0x10: /* MONTHS_REG */
3534 printf("RTC MTH_REG <-- %02x\n", value
);
3536 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3537 new_tm
.tm_mon
= omap_rtc_bin(value
);
3538 ti
[0] = mktime(&s
->current_tm
);
3539 ti
[1] = mktime(&new_tm
);
3541 if (ti
[0] != -1 && ti
[1] != -1) {
3545 /* A less accurate version */
3546 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
3547 s
->ti
+= omap_rtc_bin(value
) * 2592000;
3551 case 0x14: /* YEARS_REG */
3553 printf("RTC YRS_REG <-- %02x\n", value
);
3555 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3556 new_tm
.tm_year
+= omap_rtc_bin(value
) - (new_tm
.tm_year
% 100);
3557 ti
[0] = mktime(&s
->current_tm
);
3558 ti
[1] = mktime(&new_tm
);
3560 if (ti
[0] != -1 && ti
[1] != -1) {
3564 /* A less accurate version */
3565 s
->ti
-= (s
->current_tm
.tm_year
% 100) * 31536000;
3566 s
->ti
+= omap_rtc_bin(value
) * 31536000;
3570 case 0x18: /* WEEK_REG */
3571 return; /* Ignored */
3573 case 0x20: /* ALARM_SECONDS_REG */
3575 printf("ALM SEC_REG <-- %02x\n", value
);
3577 s
->alarm_tm
.tm_sec
= omap_rtc_bin(value
);
3578 omap_rtc_alarm_update(s
);
3581 case 0x24: /* ALARM_MINUTES_REG */
3583 printf("ALM MIN_REG <-- %02x\n", value
);
3585 s
->alarm_tm
.tm_min
= omap_rtc_bin(value
);
3586 omap_rtc_alarm_update(s
);
3589 case 0x28: /* ALARM_HOURS_REG */
3591 printf("ALM HRS_REG <-- %02x\n", value
);
3594 s
->alarm_tm
.tm_hour
=
3595 ((omap_rtc_bin(value
& 0x3f)) % 12) +
3596 ((value
>> 7) & 1) * 12;
3598 s
->alarm_tm
.tm_hour
= omap_rtc_bin(value
);
3599 omap_rtc_alarm_update(s
);
3602 case 0x2c: /* ALARM_DAYS_REG */
3604 printf("ALM DAY_REG <-- %02x\n", value
);
3606 s
->alarm_tm
.tm_mday
= omap_rtc_bin(value
);
3607 omap_rtc_alarm_update(s
);
3610 case 0x30: /* ALARM_MONTHS_REG */
3612 printf("ALM MON_REG <-- %02x\n", value
);
3614 s
->alarm_tm
.tm_mon
= omap_rtc_bin(value
);
3615 omap_rtc_alarm_update(s
);
3618 case 0x34: /* ALARM_YEARS_REG */
3620 printf("ALM YRS_REG <-- %02x\n", value
);
3622 s
->alarm_tm
.tm_year
= omap_rtc_bin(value
);
3623 omap_rtc_alarm_update(s
);
3626 case 0x40: /* RTC_CTRL_REG */
3628 printf("RTC CONTROL <-- %02x\n", value
);
3630 s
->pm_am
= (value
>> 3) & 1;
3631 s
->auto_comp
= (value
>> 2) & 1;
3632 s
->round
= (value
>> 1) & 1;
3633 s
->running
= value
& 1;
3635 s
->status
|= s
->running
<< 1;
3638 case 0x44: /* RTC_STATUS_REG */
3640 printf("RTC STATUSL <-- %02x\n", value
);
3642 s
->status
&= ~((value
& 0xc0) ^ 0x80);
3643 omap_rtc_interrupts_update(s
);
3646 case 0x48: /* RTC_INTERRUPTS_REG */
3648 printf("RTC INTRS <-- %02x\n", value
);
3650 s
->interrupts
= value
;
3653 case 0x4c: /* RTC_COMP_LSB_REG */
3655 printf("RTC COMPLSB <-- %02x\n", value
);
3657 s
->comp_reg
&= 0xff00;
3658 s
->comp_reg
|= 0x00ff & value
;
3661 case 0x50: /* RTC_COMP_MSB_REG */
3663 printf("RTC COMPMSB <-- %02x\n", value
);
3665 s
->comp_reg
&= 0x00ff;
3666 s
->comp_reg
|= 0xff00 & (value
<< 8);
3675 static CPUReadMemoryFunc
*omap_rtc_readfn
[] = {
3677 omap_badwidth_read8
,
3678 omap_badwidth_read8
,
3681 static CPUWriteMemoryFunc
*omap_rtc_writefn
[] = {
3683 omap_badwidth_write8
,
3684 omap_badwidth_write8
,
3687 static void omap_rtc_tick(void *opaque
)
3689 struct omap_rtc_s
*s
= opaque
;
3692 /* Round to nearest full minute. */
3693 if (s
->current_tm
.tm_sec
< 30)
3694 s
->ti
-= s
->current_tm
.tm_sec
;
3696 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
3701 memcpy(&s
->current_tm
, localtime(&s
->ti
), sizeof(s
->current_tm
));
3703 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
3705 omap_rtc_interrupts_update(s
);
3708 if (s
->interrupts
& 0x04)
3709 switch (s
->interrupts
& 3) {
3712 qemu_irq_pulse(s
->irq
);
3715 if (s
->current_tm
.tm_sec
)
3718 qemu_irq_pulse(s
->irq
);
3721 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
3724 qemu_irq_pulse(s
->irq
);
3727 if (s
->current_tm
.tm_sec
||
3728 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
3731 qemu_irq_pulse(s
->irq
);
3741 * Every full hour add a rough approximation of the compensation
3742 * register to the 32kHz Timer (which drives the RTC) value.
3744 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
3745 s
->tick
+= s
->comp_reg
* 1000 / 32768;
3747 qemu_mod_timer(s
->clk
, s
->tick
);
3750 static void omap_rtc_reset(struct omap_rtc_s
*s
)
3760 s
->tick
= qemu_get_clock(rt_clock
);
3761 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
3762 s
->alarm_tm
.tm_mday
= 0x01;
3764 qemu_get_timedate(&tm
, 0);
3765 s
->ti
= mktime(&tm
);
3767 omap_rtc_alarm_update(s
);
3771 struct omap_rtc_s
*omap_rtc_init(target_phys_addr_t base
,
3772 qemu_irq
*irq
, omap_clk clk
)
3775 struct omap_rtc_s
*s
= (struct omap_rtc_s
*)
3776 qemu_mallocz(sizeof(struct omap_rtc_s
));
3781 s
->clk
= qemu_new_timer(rt_clock
, omap_rtc_tick
, s
);
3785 iomemtype
= cpu_register_io_memory(0, omap_rtc_readfn
,
3786 omap_rtc_writefn
, s
);
3787 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
3792 /* Multi-channel Buffered Serial Port interfaces */
3793 struct omap_mcbsp_s
{
3794 target_phys_addr_t base
;
3813 struct i2s_codec_s
*codec
;
3814 QEMUTimer
*source_timer
;
3815 QEMUTimer
*sink_timer
;
3818 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
3822 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
3824 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
3827 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
3835 qemu_irq_pulse(s
->rxirq
);
3837 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
3839 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
3842 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
3850 qemu_irq_pulse(s
->txirq
);
3853 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
3855 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
3856 s
->spcr
[0] |= 1 << 2; /* RFULL */
3857 s
->spcr
[0] |= 1 << 1; /* RRDY */
3858 qemu_irq_raise(s
->rxdrq
);
3859 omap_mcbsp_intr_update(s
);
3862 static void omap_mcbsp_source_tick(void *opaque
)
3864 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3865 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3870 printf("%s: Rx FIFO overrun\n", __FUNCTION__
);
3872 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
3874 omap_mcbsp_rx_newdata(s
);
3875 qemu_mod_timer(s
->source_timer
, qemu_get_clock(vm_clock
) + ticks_per_sec
);
3878 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
3880 if (!s
->codec
|| !s
->codec
->rts
)
3881 omap_mcbsp_source_tick(s
);
3882 else if (s
->codec
->in
.len
) {
3883 s
->rx_req
= s
->codec
->in
.len
;
3884 omap_mcbsp_rx_newdata(s
);
3888 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
3890 qemu_del_timer(s
->source_timer
);
3893 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
3895 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
3896 qemu_irq_lower(s
->rxdrq
);
3897 omap_mcbsp_intr_update(s
);
3900 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
3902 s
->spcr
[1] |= 1 << 1; /* XRDY */
3903 qemu_irq_raise(s
->txdrq
);
3904 omap_mcbsp_intr_update(s
);
3907 static void omap_mcbsp_sink_tick(void *opaque
)
3909 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3910 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3915 printf("%s: Tx FIFO underrun\n", __FUNCTION__
);
3917 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
3919 omap_mcbsp_tx_newdata(s
);
3920 qemu_mod_timer(s
->sink_timer
, qemu_get_clock(vm_clock
) + ticks_per_sec
);
3923 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
3925 if (!s
->codec
|| !s
->codec
->cts
)
3926 omap_mcbsp_sink_tick(s
);
3927 else if (s
->codec
->out
.size
) {
3928 s
->tx_req
= s
->codec
->out
.size
;
3929 omap_mcbsp_tx_newdata(s
);
3933 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
3935 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
3936 qemu_irq_lower(s
->txdrq
);
3937 omap_mcbsp_intr_update(s
);
3938 if (s
->codec
&& s
->codec
->cts
)
3939 s
->codec
->tx_swallow(s
->codec
->opaque
);
3942 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
3945 omap_mcbsp_tx_done(s
);
3946 qemu_del_timer(s
->sink_timer
);
3949 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
3951 int prev_rx_rate
, prev_tx_rate
;
3952 int rx_rate
= 0, tx_rate
= 0;
3953 int cpu_rate
= 1500000; /* XXX */
3955 /* TODO: check CLKSTP bit */
3956 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3957 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3958 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3959 (s
->pcr
& (1 << 8))) { /* CLKRM */
3960 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3961 rx_rate
= cpu_rate
/
3962 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3965 rx_rate
= s
->codec
->rx_rate
;
3968 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3969 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3970 (s
->pcr
& (1 << 9))) { /* CLKXM */
3971 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3972 tx_rate
= cpu_rate
/
3973 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3976 tx_rate
= s
->codec
->tx_rate
;
3979 prev_tx_rate
= s
->tx_rate
;
3980 prev_rx_rate
= s
->rx_rate
;
3981 s
->tx_rate
= tx_rate
;
3982 s
->rx_rate
= rx_rate
;
3985 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3987 if (!prev_tx_rate
&& tx_rate
)
3988 omap_mcbsp_tx_start(s
);
3989 else if (s
->tx_rate
&& !tx_rate
)
3990 omap_mcbsp_tx_stop(s
);
3992 if (!prev_rx_rate
&& rx_rate
)
3993 omap_mcbsp_rx_start(s
);
3994 else if (prev_tx_rate
&& !tx_rate
)
3995 omap_mcbsp_rx_stop(s
);
3998 static uint32_t omap_mcbsp_read(void *opaque
, target_phys_addr_t addr
)
4000 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4001 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4005 case 0x00: /* DRR2 */
4006 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
4009 case 0x02: /* DRR1 */
4010 if (s
->rx_req
< 2) {
4011 printf("%s: Rx FIFO underrun\n", __FUNCTION__
);
4012 omap_mcbsp_rx_done(s
);
4015 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
4016 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
4017 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
4018 s
->codec
->in
.len
-= 2;
4022 omap_mcbsp_rx_done(s
);
4027 case 0x04: /* DXR2 */
4028 case 0x06: /* DXR1 */
4031 case 0x08: /* SPCR2 */
4033 case 0x0a: /* SPCR1 */
4035 case 0x0c: /* RCR2 */
4037 case 0x0e: /* RCR1 */
4039 case 0x10: /* XCR2 */
4041 case 0x12: /* XCR1 */
4043 case 0x14: /* SRGR2 */
4045 case 0x16: /* SRGR1 */
4047 case 0x18: /* MCR2 */
4049 case 0x1a: /* MCR1 */
4051 case 0x1c: /* RCERA */
4053 case 0x1e: /* RCERB */
4055 case 0x20: /* XCERA */
4057 case 0x22: /* XCERB */
4059 case 0x24: /* PCR0 */
4061 case 0x26: /* RCERC */
4063 case 0x28: /* RCERD */
4065 case 0x2a: /* XCERC */
4067 case 0x2c: /* XCERD */
4069 case 0x2e: /* RCERE */
4071 case 0x30: /* RCERF */
4073 case 0x32: /* XCERE */
4075 case 0x34: /* XCERF */
4077 case 0x36: /* RCERG */
4079 case 0x38: /* RCERH */
4081 case 0x3a: /* XCERG */
4083 case 0x3c: /* XCERH */
4091 static void omap_mcbsp_writeh(void *opaque
, target_phys_addr_t addr
,
4094 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4095 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4098 case 0x00: /* DRR2 */
4099 case 0x02: /* DRR1 */
4103 case 0x04: /* DXR2 */
4104 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
4107 case 0x06: /* DXR1 */
4108 if (s
->tx_req
> 1) {
4110 if (s
->codec
&& s
->codec
->cts
) {
4111 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
4112 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
4115 omap_mcbsp_tx_done(s
);
4117 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4120 case 0x08: /* SPCR2 */
4121 s
->spcr
[1] &= 0x0002;
4122 s
->spcr
[1] |= 0x03f9 & value
;
4123 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
4124 if (~value
& 1) /* XRST */
4126 omap_mcbsp_req_update(s
);
4128 case 0x0a: /* SPCR1 */
4129 s
->spcr
[0] &= 0x0006;
4130 s
->spcr
[0] |= 0xf8f9 & value
;
4131 if (value
& (1 << 15)) /* DLB */
4132 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__
);
4133 if (~value
& 1) { /* RRST */
4136 omap_mcbsp_rx_done(s
);
4138 omap_mcbsp_req_update(s
);
4141 case 0x0c: /* RCR2 */
4142 s
->rcr
[1] = value
& 0xffff;
4144 case 0x0e: /* RCR1 */
4145 s
->rcr
[0] = value
& 0x7fe0;
4147 case 0x10: /* XCR2 */
4148 s
->xcr
[1] = value
& 0xffff;
4150 case 0x12: /* XCR1 */
4151 s
->xcr
[0] = value
& 0x7fe0;
4153 case 0x14: /* SRGR2 */
4154 s
->srgr
[1] = value
& 0xffff;
4155 omap_mcbsp_req_update(s
);
4157 case 0x16: /* SRGR1 */
4158 s
->srgr
[0] = value
& 0xffff;
4159 omap_mcbsp_req_update(s
);
4161 case 0x18: /* MCR2 */
4162 s
->mcr
[1] = value
& 0x03e3;
4163 if (value
& 3) /* XMCM */
4164 printf("%s: Tx channel selection mode enable attempt\n",
4167 case 0x1a: /* MCR1 */
4168 s
->mcr
[0] = value
& 0x03e1;
4169 if (value
& 1) /* RMCM */
4170 printf("%s: Rx channel selection mode enable attempt\n",
4173 case 0x1c: /* RCERA */
4174 s
->rcer
[0] = value
& 0xffff;
4176 case 0x1e: /* RCERB */
4177 s
->rcer
[1] = value
& 0xffff;
4179 case 0x20: /* XCERA */
4180 s
->xcer
[0] = value
& 0xffff;
4182 case 0x22: /* XCERB */
4183 s
->xcer
[1] = value
& 0xffff;
4185 case 0x24: /* PCR0 */
4186 s
->pcr
= value
& 0x7faf;
4188 case 0x26: /* RCERC */
4189 s
->rcer
[2] = value
& 0xffff;
4191 case 0x28: /* RCERD */
4192 s
->rcer
[3] = value
& 0xffff;
4194 case 0x2a: /* XCERC */
4195 s
->xcer
[2] = value
& 0xffff;
4197 case 0x2c: /* XCERD */
4198 s
->xcer
[3] = value
& 0xffff;
4200 case 0x2e: /* RCERE */
4201 s
->rcer
[4] = value
& 0xffff;
4203 case 0x30: /* RCERF */
4204 s
->rcer
[5] = value
& 0xffff;
4206 case 0x32: /* XCERE */
4207 s
->xcer
[4] = value
& 0xffff;
4209 case 0x34: /* XCERF */
4210 s
->xcer
[5] = value
& 0xffff;
4212 case 0x36: /* RCERG */
4213 s
->rcer
[6] = value
& 0xffff;
4215 case 0x38: /* RCERH */
4216 s
->rcer
[7] = value
& 0xffff;
4218 case 0x3a: /* XCERG */
4219 s
->xcer
[6] = value
& 0xffff;
4221 case 0x3c: /* XCERH */
4222 s
->xcer
[7] = value
& 0xffff;
4229 static void omap_mcbsp_writew(void *opaque
, target_phys_addr_t addr
,
4232 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4233 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4235 if (offset
== 0x04) { /* DXR */
4236 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
4238 if (s
->tx_req
> 3) {
4240 if (s
->codec
&& s
->codec
->cts
) {
4241 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4242 (value
>> 24) & 0xff;
4243 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4244 (value
>> 16) & 0xff;
4245 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4246 (value
>> 8) & 0xff;
4247 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4248 (value
>> 0) & 0xff;
4251 omap_mcbsp_tx_done(s
);
4253 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4257 omap_badwidth_write16(opaque
, addr
, value
);
4260 static CPUReadMemoryFunc
*omap_mcbsp_readfn
[] = {
4261 omap_badwidth_read16
,
4263 omap_badwidth_read16
,
4266 static CPUWriteMemoryFunc
*omap_mcbsp_writefn
[] = {
4267 omap_badwidth_write16
,
4272 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
4274 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
4275 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
4276 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
4277 s
->srgr
[0] = 0x0001;
4278 s
->srgr
[1] = 0x2000;
4279 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
4280 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
4281 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
4282 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
4287 qemu_del_timer(s
->source_timer
);
4288 qemu_del_timer(s
->sink_timer
);
4291 struct omap_mcbsp_s
*omap_mcbsp_init(target_phys_addr_t base
,
4292 qemu_irq
*irq
, qemu_irq
*dma
, omap_clk clk
)
4295 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*)
4296 qemu_mallocz(sizeof(struct omap_mcbsp_s
));
4303 s
->sink_timer
= qemu_new_timer(vm_clock
, omap_mcbsp_sink_tick
, s
);
4304 s
->source_timer
= qemu_new_timer(vm_clock
, omap_mcbsp_source_tick
, s
);
4305 omap_mcbsp_reset(s
);
4307 iomemtype
= cpu_register_io_memory(0, omap_mcbsp_readfn
,
4308 omap_mcbsp_writefn
, s
);
4309 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
4314 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
4316 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4319 s
->rx_req
= s
->codec
->in
.len
;
4320 omap_mcbsp_rx_newdata(s
);
4324 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
4326 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4329 s
->tx_req
= s
->codec
->out
.size
;
4330 omap_mcbsp_tx_newdata(s
);
4334 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, struct i2s_codec_s
*slave
)
4337 slave
->rx_swallow
= qemu_allocate_irqs(omap_mcbsp_i2s_swallow
, s
, 1)[0];
4338 slave
->tx_start
= qemu_allocate_irqs(omap_mcbsp_i2s_start
, s
, 1)[0];
4341 /* LED Pulse Generators */
4343 target_phys_addr_t base
;
4354 static void omap_lpg_tick(void *opaque
)
4356 struct omap_lpg_s
*s
= opaque
;
4359 qemu_mod_timer(s
->tm
, qemu_get_clock(rt_clock
) + s
->period
- s
->on
);
4361 qemu_mod_timer(s
->tm
, qemu_get_clock(rt_clock
) + s
->on
);
4363 s
->cycle
= !s
->cycle
;
4364 printf("%s: LED is %s\n", __FUNCTION__
, s
->cycle
? "on" : "off");
4367 static void omap_lpg_update(struct omap_lpg_s
*s
)
4369 int64_t on
, period
= 1, ticks
= 1000;
4370 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
4372 if (~s
->control
& (1 << 6)) /* LPGRES */
4374 else if (s
->control
& (1 << 7)) /* PERM_ON */
4377 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
4379 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
4380 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
4383 qemu_del_timer(s
->tm
);
4384 if (on
== period
&& s
->on
< s
->period
)
4385 printf("%s: LED is on\n", __FUNCTION__
);
4386 else if (on
== 0 && s
->on
)
4387 printf("%s: LED is off\n", __FUNCTION__
);
4388 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
4400 static void omap_lpg_reset(struct omap_lpg_s
*s
)
4408 static uint32_t omap_lpg_read(void *opaque
, target_phys_addr_t addr
)
4410 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4411 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4414 case 0x00: /* LCR */
4417 case 0x04: /* PMR */
4425 static void omap_lpg_write(void *opaque
, target_phys_addr_t addr
,
4428 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4429 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4432 case 0x00: /* LCR */
4433 if (~value
& (1 << 6)) /* LPGRES */
4435 s
->control
= value
& 0xff;
4439 case 0x04: /* PMR */
4440 s
->power
= value
& 0x01;
4450 static CPUReadMemoryFunc
*omap_lpg_readfn
[] = {
4452 omap_badwidth_read8
,
4453 omap_badwidth_read8
,
4456 static CPUWriteMemoryFunc
*omap_lpg_writefn
[] = {
4458 omap_badwidth_write8
,
4459 omap_badwidth_write8
,
4462 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
4464 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4470 struct omap_lpg_s
*omap_lpg_init(target_phys_addr_t base
, omap_clk clk
)
4473 struct omap_lpg_s
*s
= (struct omap_lpg_s
*)
4474 qemu_mallocz(sizeof(struct omap_lpg_s
));
4477 s
->tm
= qemu_new_timer(rt_clock
, omap_lpg_tick
, s
);
4481 iomemtype
= cpu_register_io_memory(0, omap_lpg_readfn
,
4482 omap_lpg_writefn
, s
);
4483 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
4485 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_lpg_clk_update
, s
, 1)[0]);
4490 /* MPUI Peripheral Bridge configuration */
4491 static uint32_t omap_mpui_io_read(void *opaque
, target_phys_addr_t addr
)
4493 if (addr
== OMAP_MPUI_BASE
) /* CMR */
4500 static CPUReadMemoryFunc
*omap_mpui_io_readfn
[] = {
4501 omap_badwidth_read16
,
4503 omap_badwidth_read16
,
4506 static CPUWriteMemoryFunc
*omap_mpui_io_writefn
[] = {
4507 omap_badwidth_write16
,
4508 omap_badwidth_write16
,
4509 omap_badwidth_write16
,
4512 static void omap_setup_mpui_io(struct omap_mpu_state_s
*mpu
)
4514 int iomemtype
= cpu_register_io_memory(0, omap_mpui_io_readfn
,
4515 omap_mpui_io_writefn
, mpu
);
4516 cpu_register_physical_memory(OMAP_MPUI_BASE
, 0x7fff, iomemtype
);
4519 /* General chip reset */
4520 static void omap1_mpu_reset(void *opaque
)
4522 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4524 omap_inth_reset(mpu
->ih
[0]);
4525 omap_inth_reset(mpu
->ih
[1]);
4526 omap_dma_reset(mpu
->dma
);
4527 omap_mpu_timer_reset(mpu
->timer
[0]);
4528 omap_mpu_timer_reset(mpu
->timer
[1]);
4529 omap_mpu_timer_reset(mpu
->timer
[2]);
4530 omap_wd_timer_reset(mpu
->wdt
);
4531 omap_os_timer_reset(mpu
->os_timer
);
4532 omap_lcdc_reset(mpu
->lcd
);
4533 omap_ulpd_pm_reset(mpu
);
4534 omap_pin_cfg_reset(mpu
);
4535 omap_mpui_reset(mpu
);
4536 omap_tipb_bridge_reset(mpu
->private_tipb
);
4537 omap_tipb_bridge_reset(mpu
->public_tipb
);
4538 omap_dpll_reset(&mpu
->dpll
[0]);
4539 omap_dpll_reset(&mpu
->dpll
[1]);
4540 omap_dpll_reset(&mpu
->dpll
[2]);
4541 omap_uart_reset(mpu
->uart
[0]);
4542 omap_uart_reset(mpu
->uart
[1]);
4543 omap_uart_reset(mpu
->uart
[2]);
4544 omap_mmc_reset(mpu
->mmc
);
4545 omap_mpuio_reset(mpu
->mpuio
);
4546 omap_gpio_reset(mpu
->gpio
);
4547 omap_uwire_reset(mpu
->microwire
);
4548 omap_pwl_reset(mpu
);
4549 omap_pwt_reset(mpu
);
4550 omap_i2c_reset(mpu
->i2c
[0]);
4551 omap_rtc_reset(mpu
->rtc
);
4552 omap_mcbsp_reset(mpu
->mcbsp1
);
4553 omap_mcbsp_reset(mpu
->mcbsp2
);
4554 omap_mcbsp_reset(mpu
->mcbsp3
);
4555 omap_lpg_reset(mpu
->led
[0]);
4556 omap_lpg_reset(mpu
->led
[1]);
4557 omap_clkm_reset(mpu
);
4558 cpu_reset(mpu
->env
);
4561 static const struct omap_map_s
{
4562 target_phys_addr_t phys_dsp
;
4563 target_phys_addr_t phys_mpu
;
4566 } omap15xx_dsp_mm
[] = {
4568 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
4569 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
4570 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
4571 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
4572 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
4573 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
4574 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
4575 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
4576 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
4577 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
4578 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
4579 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
4580 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
4581 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
4582 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
4583 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
4584 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
4586 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
4591 static void omap_setup_dsp_mapping(const struct omap_map_s
*map
)
4595 for (; map
->phys_dsp
; map
++) {
4596 io
= cpu_get_physical_page_desc(map
->phys_mpu
);
4598 cpu_register_physical_memory(map
->phys_dsp
, map
->size
, io
);
4602 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
4604 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4606 if (mpu
->env
->halted
)
4607 cpu_interrupt(mpu
->env
, CPU_INTERRUPT_EXITTB
);
4610 static const struct dma_irq_map omap1_dma_irq_map
[] = {
4611 { 0, OMAP_INT_DMA_CH0_6
},
4612 { 0, OMAP_INT_DMA_CH1_7
},
4613 { 0, OMAP_INT_DMA_CH2_8
},
4614 { 0, OMAP_INT_DMA_CH3
},
4615 { 0, OMAP_INT_DMA_CH4
},
4616 { 0, OMAP_INT_DMA_CH5
},
4617 { 1, OMAP_INT_1610_DMA_CH6
},
4618 { 1, OMAP_INT_1610_DMA_CH7
},
4619 { 1, OMAP_INT_1610_DMA_CH8
},
4620 { 1, OMAP_INT_1610_DMA_CH9
},
4621 { 1, OMAP_INT_1610_DMA_CH10
},
4622 { 1, OMAP_INT_1610_DMA_CH11
},
4623 { 1, OMAP_INT_1610_DMA_CH12
},
4624 { 1, OMAP_INT_1610_DMA_CH13
},
4625 { 1, OMAP_INT_1610_DMA_CH14
},
4626 { 1, OMAP_INT_1610_DMA_CH15
}
4629 /* DMA ports for OMAP1 */
4630 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
4631 target_phys_addr_t addr
)
4633 return addr
>= OMAP_EMIFF_BASE
&& addr
< OMAP_EMIFF_BASE
+ s
->sdram_size
;
4636 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
4637 target_phys_addr_t addr
)
4639 return addr
>= OMAP_EMIFS_BASE
&& addr
< OMAP_EMIFF_BASE
;
4642 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
4643 target_phys_addr_t addr
)
4645 return addr
>= OMAP_IMIF_BASE
&& addr
< OMAP_IMIF_BASE
+ s
->sram_size
;
4648 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
4649 target_phys_addr_t addr
)
4651 return addr
>= 0xfffb0000 && addr
< 0xffff0000;
4654 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
4655 target_phys_addr_t addr
)
4657 return addr
>= OMAP_LOCALBUS_BASE
&& addr
< OMAP_LOCALBUS_BASE
+ 0x1000000;
4660 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
4661 target_phys_addr_t addr
)
4663 return addr
>= 0xe1010000 && addr
< 0xe1020004;
4666 struct omap_mpu_state_s
*omap310_mpu_init(unsigned long sdram_size
,
4667 DisplayState
*ds
, const char *core
)
4670 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*)
4671 qemu_mallocz(sizeof(struct omap_mpu_state_s
));
4672 ram_addr_t imif_base
, emiff_base
;
4674 qemu_irq dma_irqs
[6];
4681 s
->mpu_model
= omap310
;
4682 s
->env
= cpu_init(core
);
4684 fprintf(stderr
, "Unable to find CPU definition\n");
4687 s
->sdram_size
= sdram_size
;
4688 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
4690 s
->wakeup
= qemu_allocate_irqs(omap_mpu_wakeup
, s
, 1)[0];
4695 /* Memory-mapped stuff */
4696 cpu_register_physical_memory(OMAP_EMIFF_BASE
, s
->sdram_size
,
4697 (emiff_base
= qemu_ram_alloc(s
->sdram_size
)) | IO_MEM_RAM
);
4698 cpu_register_physical_memory(OMAP_IMIF_BASE
, s
->sram_size
,
4699 (imif_base
= qemu_ram_alloc(s
->sram_size
)) | IO_MEM_RAM
);
4701 omap_clkm_init(0xfffece00, 0xe1008000, s
);
4703 cpu_irq
= arm_pic_init_cpu(s
->env
);
4704 s
->ih
[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s
->irq
[0],
4705 cpu_irq
[ARM_PIC_CPU_IRQ
], cpu_irq
[ARM_PIC_CPU_FIQ
],
4706 omap_findclk(s
, "arminth_ck"));
4707 s
->ih
[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s
->irq
[1],
4708 s
->ih
[0]->pins
[OMAP_INT_15XX_IH2_IRQ
], NULL
,
4709 omap_findclk(s
, "arminth_ck"));
4711 for (i
= 0; i
< 6; i
++)
4713 s
->irq
[omap1_dma_irq_map
[i
].ih
][omap1_dma_irq_map
[i
].intr
];
4714 s
->dma
= omap_dma_init(0xfffed800, dma_irqs
, s
->irq
[0][OMAP_INT_DMA_LCD
],
4715 s
, omap_findclk(s
, "dma_ck"), omap_dma_3_1
);
4717 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
4718 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
4719 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
4720 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
4721 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
4722 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
4724 /* Register SDRAM and SRAM DMA ports for fast transfers. */
4725 soc_dma_port_add_mem_ram(s
->dma
,
4726 emiff_base
, OMAP_EMIFF_BASE
, s
->sdram_size
);
4727 soc_dma_port_add_mem_ram(s
->dma
,
4728 imif_base
, OMAP_IMIF_BASE
, s
->sram_size
);
4730 s
->timer
[0] = omap_mpu_timer_init(0xfffec500,
4731 s
->irq
[0][OMAP_INT_TIMER1
],
4732 omap_findclk(s
, "mputim_ck"));
4733 s
->timer
[1] = omap_mpu_timer_init(0xfffec600,
4734 s
->irq
[0][OMAP_INT_TIMER2
],
4735 omap_findclk(s
, "mputim_ck"));
4736 s
->timer
[2] = omap_mpu_timer_init(0xfffec700,
4737 s
->irq
[0][OMAP_INT_TIMER3
],
4738 omap_findclk(s
, "mputim_ck"));
4740 s
->wdt
= omap_wd_timer_init(0xfffec800,
4741 s
->irq
[0][OMAP_INT_WD_TIMER
],
4742 omap_findclk(s
, "armwdt_ck"));
4744 s
->os_timer
= omap_os_timer_init(0xfffb9000,
4745 s
->irq
[1][OMAP_INT_OS_TIMER
],
4746 omap_findclk(s
, "clk32-kHz"));
4748 s
->lcd
= omap_lcdc_init(0xfffec000, s
->irq
[0][OMAP_INT_LCD_CTRL
],
4749 omap_dma_get_lcdch(s
->dma
), ds
, imif_base
, emiff_base
,
4750 omap_findclk(s
, "lcd_ck"));
4752 omap_ulpd_pm_init(0xfffe0800, s
);
4753 omap_pin_cfg_init(0xfffe1000, s
);
4756 omap_mpui_init(0xfffec900, s
);
4758 s
->private_tipb
= omap_tipb_bridge_init(0xfffeca00,
4759 s
->irq
[0][OMAP_INT_BRIDGE_PRIV
],
4760 omap_findclk(s
, "tipb_ck"));
4761 s
->public_tipb
= omap_tipb_bridge_init(0xfffed300,
4762 s
->irq
[0][OMAP_INT_BRIDGE_PUB
],
4763 omap_findclk(s
, "tipb_ck"));
4765 omap_tcmi_init(0xfffecc00, s
);
4767 s
->uart
[0] = omap_uart_init(0xfffb0000, s
->irq
[1][OMAP_INT_UART1
],
4768 omap_findclk(s
, "uart1_ck"),
4769 omap_findclk(s
, "uart1_ck"),
4770 s
->drq
[OMAP_DMA_UART1_TX
], s
->drq
[OMAP_DMA_UART1_RX
],
4772 s
->uart
[1] = omap_uart_init(0xfffb0800, s
->irq
[1][OMAP_INT_UART2
],
4773 omap_findclk(s
, "uart2_ck"),
4774 omap_findclk(s
, "uart2_ck"),
4775 s
->drq
[OMAP_DMA_UART2_TX
], s
->drq
[OMAP_DMA_UART2_RX
],
4776 serial_hds
[0] ? serial_hds
[1] : 0);
4777 s
->uart
[2] = omap_uart_init(0xe1019800, s
->irq
[0][OMAP_INT_UART3
],
4778 omap_findclk(s
, "uart3_ck"),
4779 omap_findclk(s
, "uart3_ck"),
4780 s
->drq
[OMAP_DMA_UART3_TX
], s
->drq
[OMAP_DMA_UART3_RX
],
4781 serial_hds
[0] && serial_hds
[1] ? serial_hds
[2] : 0);
4783 omap_dpll_init(&s
->dpll
[0], 0xfffecf00, omap_findclk(s
, "dpll1"));
4784 omap_dpll_init(&s
->dpll
[1], 0xfffed000, omap_findclk(s
, "dpll2"));
4785 omap_dpll_init(&s
->dpll
[2], 0xfffed100, omap_findclk(s
, "dpll3"));
4787 sdindex
= drive_get_index(IF_SD
, 0, 0);
4788 if (sdindex
== -1) {
4789 fprintf(stderr
, "qemu: missing SecureDigital device\n");
4792 s
->mmc
= omap_mmc_init(0xfffb7800, drives_table
[sdindex
].bdrv
,
4793 s
->irq
[1][OMAP_INT_OQN
], &s
->drq
[OMAP_DMA_MMC_TX
],
4794 omap_findclk(s
, "mmc_ck"));
4796 s
->mpuio
= omap_mpuio_init(0xfffb5000,
4797 s
->irq
[1][OMAP_INT_KEYBOARD
], s
->irq
[1][OMAP_INT_MPUIO
],
4798 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
4800 s
->gpio
= omap_gpio_init(0xfffce000, s
->irq
[0][OMAP_INT_GPIO_BANK1
],
4801 omap_findclk(s
, "arm_gpio_ck"));
4803 s
->microwire
= omap_uwire_init(0xfffb3000, &s
->irq
[1][OMAP_INT_uWireTX
],
4804 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
4806 omap_pwl_init(0xfffb5800, s
, omap_findclk(s
, "armxor_ck"));
4807 omap_pwt_init(0xfffb6000, s
, omap_findclk(s
, "armxor_ck"));
4809 s
->i2c
[0] = omap_i2c_init(0xfffb3800, s
->irq
[1][OMAP_INT_I2C
],
4810 &s
->drq
[OMAP_DMA_I2C_RX
], omap_findclk(s
, "mpuper_ck"));
4812 s
->rtc
= omap_rtc_init(0xfffb4800, &s
->irq
[1][OMAP_INT_RTC_TIMER
],
4813 omap_findclk(s
, "clk32-kHz"));
4815 s
->mcbsp1
= omap_mcbsp_init(0xfffb1800, &s
->irq
[1][OMAP_INT_McBSP1TX
],
4816 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
4817 s
->mcbsp2
= omap_mcbsp_init(0xfffb1000, &s
->irq
[0][OMAP_INT_310_McBSP2_TX
],
4818 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
4819 s
->mcbsp3
= omap_mcbsp_init(0xfffb7000, &s
->irq
[1][OMAP_INT_McBSP3TX
],
4820 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
4822 s
->led
[0] = omap_lpg_init(0xfffbd000, omap_findclk(s
, "clk32-kHz"));
4823 s
->led
[1] = omap_lpg_init(0xfffbd800, omap_findclk(s
, "clk32-kHz"));
4825 /* Register mappings not currenlty implemented:
4826 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4827 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4828 * USB W2FC fffb4000 - fffb47ff
4829 * Camera Interface fffb6800 - fffb6fff
4830 * USB Host fffba000 - fffba7ff
4831 * FAC fffba800 - fffbafff
4832 * HDQ/1-Wire fffbc000 - fffbc7ff
4833 * TIPB switches fffbc800 - fffbcfff
4834 * Mailbox fffcf000 - fffcf7ff
4835 * Local bus IF fffec100 - fffec1ff
4836 * Local bus MMU fffec200 - fffec2ff
4837 * DSP MMU fffed200 - fffed2ff
4840 omap_setup_dsp_mapping(omap15xx_dsp_mm
);
4841 omap_setup_mpui_io(s
);
4843 qemu_register_reset(omap1_mpu_reset
, s
);