2 * TI OMAP processors emulation.
4 * Copyright (C) 2006-2007 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 of
9 * the License, or (at your option) any later version.
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 /* We use pc-style serial ports. */
29 /* Should signal the TCMI */
30 uint32_t omap_badwidth_read8(void *opaque
, target_phys_addr_t addr
)
35 cpu_physical_memory_read(addr
, (void *) &ret
, 1);
39 void omap_badwidth_write8(void *opaque
, target_phys_addr_t addr
,
45 cpu_physical_memory_write(addr
, (void *) &val8
, 1);
48 uint32_t omap_badwidth_read16(void *opaque
, target_phys_addr_t addr
)
53 cpu_physical_memory_read(addr
, (void *) &ret
, 2);
57 void omap_badwidth_write16(void *opaque
, target_phys_addr_t addr
,
60 uint16_t val16
= value
;
63 cpu_physical_memory_write(addr
, (void *) &val16
, 2);
66 uint32_t omap_badwidth_read32(void *opaque
, target_phys_addr_t addr
)
71 cpu_physical_memory_read(addr
, (void *) &ret
, 4);
75 void omap_badwidth_write32(void *opaque
, target_phys_addr_t addr
,
79 cpu_physical_memory_write(addr
, (void *) &value
, 4);
82 /* Interrupt Handlers */
83 struct omap_intr_handler_s
{
86 target_phys_addr_t base
;
101 static void omap_inth_update(struct omap_intr_handler_s
*s
)
103 uint32_t irq
= s
->irqs
& ~s
->mask
& ~s
->fiq
;
104 uint32_t fiq
= s
->irqs
& ~s
->mask
& s
->fiq
;
106 if (s
->new_irq_agr
|| !irq
) {
107 qemu_set_irq(s
->parent_pic
[ARM_PIC_CPU_IRQ
], irq
);
112 if (s
->new_fiq_agr
|| !irq
) {
113 qemu_set_irq(s
->parent_pic
[ARM_PIC_CPU_FIQ
], fiq
);
119 static void omap_inth_sir_update(struct omap_intr_handler_s
*s
)
121 int i
, intr_irq
, intr_fiq
, p_irq
, p_fiq
, p
, f
;
122 uint32_t level
= s
->irqs
& ~s
->mask
;
128 /* Find the interrupt line with the highest dynamic priority */
129 for (f
= ffs(level
), i
= f
- 1, level
>>= f
- 1; f
; i
+= f
, level
>>= f
) {
131 if (s
->fiq
& (1 << i
)) {
146 s
->sir_irq
= intr_irq
;
147 s
->sir_fiq
= intr_fiq
;
150 #define INT_FALLING_EDGE 0
151 #define INT_LOW_LEVEL 1
153 static void omap_set_intr(void *opaque
, int irq
, int req
)
155 struct omap_intr_handler_s
*ih
= (struct omap_intr_handler_s
*) opaque
;
159 rise
= ~ih
->irqs
& (1 << irq
);
161 ih
->stats
[irq
] += !!rise
;
163 rise
= ih
->sens_edge
& ih
->irqs
& (1 << irq
);
167 if (rise
& ~ih
->mask
) {
168 omap_inth_sir_update(ih
);
170 omap_inth_update(ih
);
174 static uint32_t omap_inth_read(void *opaque
, target_phys_addr_t addr
)
176 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
177 int i
, offset
= addr
- s
->base
;
186 case 0x10: /* SIR_IRQ_CODE */
188 if (((s
->sens_edge
>> i
) & 1) == INT_FALLING_EDGE
&& i
) {
189 s
->irqs
&= ~(1 << i
);
190 omap_inth_sir_update(s
);
195 case 0x14: /* SIR_FIQ_CODE */
197 if (((s
->sens_edge
>> i
) & 1) == INT_FALLING_EDGE
&& i
) {
198 s
->irqs
&= ~(1 << i
);
199 omap_inth_sir_update(s
);
204 case 0x18: /* CONTROL_REG */
207 case 0x1c: /* ILR0 */
208 case 0x20: /* ILR1 */
209 case 0x24: /* ILR2 */
210 case 0x28: /* ILR3 */
211 case 0x2c: /* ILR4 */
212 case 0x30: /* ILR5 */
213 case 0x34: /* ILR6 */
214 case 0x38: /* ILR7 */
215 case 0x3c: /* ILR8 */
216 case 0x40: /* ILR9 */
217 case 0x44: /* ILR10 */
218 case 0x48: /* ILR11 */
219 case 0x4c: /* ILR12 */
220 case 0x50: /* ILR13 */
221 case 0x54: /* ILR14 */
222 case 0x58: /* ILR15 */
223 case 0x5c: /* ILR16 */
224 case 0x60: /* ILR17 */
225 case 0x64: /* ILR18 */
226 case 0x68: /* ILR19 */
227 case 0x6c: /* ILR20 */
228 case 0x70: /* ILR21 */
229 case 0x74: /* ILR22 */
230 case 0x78: /* ILR23 */
231 case 0x7c: /* ILR24 */
232 case 0x80: /* ILR25 */
233 case 0x84: /* ILR26 */
234 case 0x88: /* ILR27 */
235 case 0x8c: /* ILR28 */
236 case 0x90: /* ILR29 */
237 case 0x94: /* ILR30 */
238 case 0x98: /* ILR31 */
239 i
= (offset
- 0x1c) >> 2;
240 return (s
->priority
[i
] << 2) |
241 (((s
->sens_edge
>> i
) & 1) << 1) |
254 static void omap_inth_write(void *opaque
, target_phys_addr_t addr
,
257 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
258 int i
, offset
= addr
- s
->base
;
262 s
->irqs
&= value
| 1;
263 omap_inth_sir_update(s
);
269 omap_inth_sir_update(s
);
273 case 0x10: /* SIR_IRQ_CODE */
274 case 0x14: /* SIR_FIQ_CODE */
278 case 0x18: /* CONTROL_REG */
286 case 0x1c: /* ILR0 */
287 case 0x20: /* ILR1 */
288 case 0x24: /* ILR2 */
289 case 0x28: /* ILR3 */
290 case 0x2c: /* ILR4 */
291 case 0x30: /* ILR5 */
292 case 0x34: /* ILR6 */
293 case 0x38: /* ILR7 */
294 case 0x3c: /* ILR8 */
295 case 0x40: /* ILR9 */
296 case 0x44: /* ILR10 */
297 case 0x48: /* ILR11 */
298 case 0x4c: /* ILR12 */
299 case 0x50: /* ILR13 */
300 case 0x54: /* ILR14 */
301 case 0x58: /* ILR15 */
302 case 0x5c: /* ILR16 */
303 case 0x60: /* ILR17 */
304 case 0x64: /* ILR18 */
305 case 0x68: /* ILR19 */
306 case 0x6c: /* ILR20 */
307 case 0x70: /* ILR21 */
308 case 0x74: /* ILR22 */
309 case 0x78: /* ILR23 */
310 case 0x7c: /* ILR24 */
311 case 0x80: /* ILR25 */
312 case 0x84: /* ILR26 */
313 case 0x88: /* ILR27 */
314 case 0x8c: /* ILR28 */
315 case 0x90: /* ILR29 */
316 case 0x94: /* ILR30 */
317 case 0x98: /* ILR31 */
318 i
= (offset
- 0x1c) >> 2;
319 s
->priority
[i
] = (value
>> 2) & 0x1f;
320 s
->sens_edge
&= ~(1 << i
);
321 s
->sens_edge
|= ((value
>> 1) & 1) << i
;
323 s
->fiq
|= (value
& 1) << i
;
327 for (i
= 0; i
< 32; i
++)
328 if (value
& (1 << i
)) {
329 omap_set_intr(s
, i
, 1);
339 static CPUReadMemoryFunc
*omap_inth_readfn
[] = {
340 omap_badwidth_read32
,
341 omap_badwidth_read32
,
345 static CPUWriteMemoryFunc
*omap_inth_writefn
[] = {
351 static void omap_inth_reset(struct omap_intr_handler_s
*s
)
353 s
->irqs
= 0x00000000;
354 s
->mask
= 0xffffffff;
355 s
->sens_edge
= 0x00000000;
357 memset(s
->priority
, 0, sizeof(s
->priority
));
366 struct omap_intr_handler_s
*omap_inth_init(target_phys_addr_t base
,
367 unsigned long size
, qemu_irq parent
[2], omap_clk clk
)
370 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*)
371 qemu_mallocz(sizeof(struct omap_intr_handler_s
));
373 s
->parent_pic
= parent
;
375 s
->pins
= qemu_allocate_irqs(omap_set_intr
, s
, 32);
378 iomemtype
= cpu_register_io_memory(0, omap_inth_readfn
,
379 omap_inth_writefn
, s
);
380 cpu_register_physical_memory(s
->base
, size
, iomemtype
);
385 /* OMAP1 DMA module */
391 } omap_dma_addressing_t
;
393 struct omap_dma_channel_s
{
396 enum omap_dma_port port
[2];
397 target_phys_addr_t addr
[2];
398 omap_dma_addressing_t mode
[2];
414 uint16_t frame_index
;
415 uint16_t element_index
;
418 struct omap_dma_reg_set_s
{
419 target_phys_addr_t src
, dest
;
432 struct omap_mpu_state_s
*mpu
;
433 target_phys_addr_t base
;
442 struct omap_dma_channel_s ch
[16];
443 struct omap_dma_lcd_channel_s lcd_ch
;
446 static void omap_dma_interrupts_update(struct omap_dma_s
*s
)
448 /* First three interrupts are shared between two channels each. */
449 qemu_set_irq(s
->ih
[OMAP_INT_DMA_CH0_6
],
450 (s
->ch
[0].status
| s
->ch
[6].status
) & 0x3f);
451 qemu_set_irq(s
->ih
[OMAP_INT_DMA_CH1_7
],
452 (s
->ch
[1].status
| s
->ch
[7].status
) & 0x3f);
453 qemu_set_irq(s
->ih
[OMAP_INT_DMA_CH2_8
],
454 (s
->ch
[2].status
| s
->ch
[8].status
) & 0x3f);
455 qemu_set_irq(s
->ih
[OMAP_INT_DMA_CH3
],
456 (s
->ch
[3].status
) & 0x3f);
457 qemu_set_irq(s
->ih
[OMAP_INT_DMA_CH4
],
458 (s
->ch
[4].status
) & 0x3f);
459 qemu_set_irq(s
->ih
[OMAP_INT_DMA_CH5
],
460 (s
->ch
[5].status
) & 0x3f);
463 static void omap_dma_channel_load(struct omap_dma_s
*s
, int ch
)
465 struct omap_dma_reg_set_s
*a
= &s
->ch
[ch
].active_set
;
469 * TODO: verify address ranges and alignment
470 * TODO: port endianness
473 a
->src
= s
->ch
[ch
].addr
[0];
474 a
->dest
= s
->ch
[ch
].addr
[1];
475 a
->frames
= s
->ch
[ch
].frames
;
476 a
->elements
= s
->ch
[ch
].elements
;
480 if (unlikely(!s
->ch
[ch
].elements
|| !s
->ch
[ch
].frames
)) {
481 printf("%s: bad DMA request\n", __FUNCTION__
);
485 for (i
= 0; i
< 2; i
++)
486 switch (s
->ch
[ch
].mode
[i
]) {
488 a
->elem_delta
[i
] = 0;
489 a
->frame_delta
[i
] = 0;
491 case post_incremented
:
492 a
->elem_delta
[i
] = s
->ch
[ch
].data_type
;
493 a
->frame_delta
[i
] = 0;
496 a
->elem_delta
[i
] = s
->ch
[ch
].data_type
+
497 s
->ch
[ch
].element_index
- 1;
498 if (s
->ch
[ch
].element_index
> 0x7fff)
499 a
->elem_delta
[i
] -= 0x10000;
500 a
->frame_delta
[i
] = 0;
503 a
->elem_delta
[i
] = s
->ch
[ch
].data_type
+
504 s
->ch
[ch
].element_index
- 1;
505 if (s
->ch
[ch
].element_index
> 0x7fff)
506 a
->elem_delta
[i
] -= 0x10000;
507 a
->frame_delta
[i
] = s
->ch
[ch
].frame_index
-
508 s
->ch
[ch
].element_index
;
509 if (s
->ch
[ch
].frame_index
> 0x7fff)
510 a
->frame_delta
[i
] -= 0x10000;
517 static inline void omap_dma_request_run(struct omap_dma_s
*s
,
518 int channel
, int request
)
522 for (; channel
< 9; channel
++)
523 if (s
->ch
[channel
].sync
== request
&& s
->ch
[channel
].running
)
528 if (s
->ch
[channel
].transfer
) {
530 s
->ch
[channel
++].post_sync
= request
;
533 s
->ch
[channel
].status
|= 0x02; /* Synchronisation drop */
534 omap_dma_interrupts_update(s
);
538 if (!s
->ch
[channel
].signalled
)
540 s
->ch
[channel
].signalled
= 1;
543 s
->ch
[channel
].status
|= 0x40; /* External request */
545 if (s
->delay
&& !qemu_timer_pending(s
->tm
))
546 qemu_mod_timer(s
->tm
, qemu_get_clock(vm_clock
) + s
->delay
);
554 static inline void omap_dma_request_stop(struct omap_dma_s
*s
, int channel
)
556 if (s
->ch
[channel
].signalled
)
558 s
->ch
[channel
].signalled
= 0;
561 qemu_del_timer(s
->tm
);
564 static void omap_dma_channel_run(struct omap_dma_s
*s
)
569 struct omap_dma_port_if_s
*src_p
, *dest_p
;
570 struct omap_dma_reg_set_s
*a
;
572 for (ch
= 0; ch
< 9; ch
++) {
573 a
= &s
->ch
[ch
].active_set
;
575 src_p
= &s
->mpu
->port
[s
->ch
[ch
].port
[0]];
576 dest_p
= &s
->mpu
->port
[s
->ch
[ch
].port
[1]];
577 if (s
->ch
[ch
].signalled
&& (!src_p
->addr_valid(s
->mpu
, a
->src
) ||
578 !dest_p
->addr_valid(s
->mpu
, a
->dest
))) {
581 if (s
->ch
[ch
].interrupts
& 0x01)
582 s
->ch
[ch
].status
|= 0x01;
583 omap_dma_request_stop(s
, ch
);
586 printf("%s: Bus time-out in DMA%i operation\n", __FUNCTION__
, ch
);
589 status
= s
->ch
[ch
].status
;
590 while (status
== s
->ch
[ch
].status
&& s
->ch
[ch
].signalled
) {
591 /* Transfer a single element */
592 s
->ch
[ch
].transfer
= 1;
593 cpu_physical_memory_read(a
->src
, value
, s
->ch
[ch
].data_type
);
594 cpu_physical_memory_write(a
->dest
, value
, s
->ch
[ch
].data_type
);
595 s
->ch
[ch
].transfer
= 0;
597 a
->src
+= a
->elem_delta
[0];
598 a
->dest
+= a
->elem_delta
[1];
601 /* Check interrupt conditions */
602 if (a
->element
== a
->elements
) {
604 a
->src
+= a
->frame_delta
[0];
605 a
->dest
+= a
->frame_delta
[1];
608 if (a
->frame
== a
->frames
) {
609 if (!s
->ch
[ch
].repeat
|| !s
->ch
[ch
].auto_init
)
610 s
->ch
[ch
].running
= 0;
612 if (s
->ch
[ch
].auto_init
&&
615 omap_dma_channel_load(s
, ch
);
617 if (s
->ch
[ch
].interrupts
& 0x20)
618 s
->ch
[ch
].status
|= 0x20;
621 omap_dma_request_stop(s
, ch
);
624 if (s
->ch
[ch
].interrupts
& 0x08)
625 s
->ch
[ch
].status
|= 0x08;
627 if (s
->ch
[ch
].sync
&& s
->ch
[ch
].fs
&&
628 !(s
->drq
& (1 << s
->ch
[ch
].sync
))) {
629 s
->ch
[ch
].status
&= ~0x40;
630 omap_dma_request_stop(s
, ch
);
634 if (a
->element
== 1 && a
->frame
== a
->frames
- 1)
635 if (s
->ch
[ch
].interrupts
& 0x10)
636 s
->ch
[ch
].status
|= 0x10;
638 if (a
->element
== (a
->elements
>> 1))
639 if (s
->ch
[ch
].interrupts
& 0x04)
640 s
->ch
[ch
].status
|= 0x04;
642 if (s
->ch
[ch
].sync
&& !s
->ch
[ch
].fs
&&
643 !(s
->drq
& (1 << s
->ch
[ch
].sync
))) {
644 s
->ch
[ch
].status
&= ~0x40;
645 omap_dma_request_stop(s
, ch
);
649 * Process requests made while the element was
652 if (s
->ch
[ch
].post_sync
) {
653 omap_dma_request_run(s
, 0, s
->ch
[ch
].post_sync
);
654 s
->ch
[ch
].post_sync
= 0;
662 s
->ch
[ch
].cpc
= a
->dest
& 0x0000ffff;
665 omap_dma_interrupts_update(s
);
666 if (s
->run_count
&& s
->delay
)
667 qemu_mod_timer(s
->tm
, qemu_get_clock(vm_clock
) + s
->delay
);
670 static int omap_dma_ch_reg_read(struct omap_dma_s
*s
,
671 int ch
, int reg
, uint16_t *value
) {
673 case 0x00: /* SYS_DMA_CSDP_CH0 */
674 *value
= (s
->ch
[ch
].burst
[1] << 14) |
675 (s
->ch
[ch
].pack
[1] << 13) |
676 (s
->ch
[ch
].port
[1] << 9) |
677 (s
->ch
[ch
].burst
[0] << 7) |
678 (s
->ch
[ch
].pack
[0] << 6) |
679 (s
->ch
[ch
].port
[0] << 2) |
680 (s
->ch
[ch
].data_type
>> 1);
683 case 0x02: /* SYS_DMA_CCR_CH0 */
684 *value
= (s
->ch
[ch
].mode
[1] << 14) |
685 (s
->ch
[ch
].mode
[0] << 12) |
686 (s
->ch
[ch
].end_prog
<< 11) |
687 (s
->ch
[ch
].repeat
<< 9) |
688 (s
->ch
[ch
].auto_init
<< 8) |
689 (s
->ch
[ch
].running
<< 7) |
690 (s
->ch
[ch
].priority
<< 6) |
691 (s
->ch
[ch
].fs
<< 5) | s
->ch
[ch
].sync
;
694 case 0x04: /* SYS_DMA_CICR_CH0 */
695 *value
= s
->ch
[ch
].interrupts
;
698 case 0x06: /* SYS_DMA_CSR_CH0 */
699 /* FIXME: shared CSR for channels sharing the interrupts */
700 *value
= s
->ch
[ch
].status
;
701 s
->ch
[ch
].status
&= 0x40;
702 omap_dma_interrupts_update(s
);
705 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
706 *value
= s
->ch
[ch
].addr
[0] & 0x0000ffff;
709 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
710 *value
= s
->ch
[ch
].addr
[0] >> 16;
713 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
714 *value
= s
->ch
[ch
].addr
[1] & 0x0000ffff;
717 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
718 *value
= s
->ch
[ch
].addr
[1] >> 16;
721 case 0x10: /* SYS_DMA_CEN_CH0 */
722 *value
= s
->ch
[ch
].elements
;
725 case 0x12: /* SYS_DMA_CFN_CH0 */
726 *value
= s
->ch
[ch
].frames
;
729 case 0x14: /* SYS_DMA_CFI_CH0 */
730 *value
= s
->ch
[ch
].frame_index
;
733 case 0x16: /* SYS_DMA_CEI_CH0 */
734 *value
= s
->ch
[ch
].element_index
;
737 case 0x18: /* SYS_DMA_CPC_CH0 */
738 *value
= s
->ch
[ch
].cpc
;
747 static int omap_dma_ch_reg_write(struct omap_dma_s
*s
,
748 int ch
, int reg
, uint16_t value
) {
750 case 0x00: /* SYS_DMA_CSDP_CH0 */
751 s
->ch
[ch
].burst
[1] = (value
& 0xc000) >> 14;
752 s
->ch
[ch
].pack
[1] = (value
& 0x2000) >> 13;
753 s
->ch
[ch
].port
[1] = (enum omap_dma_port
) ((value
& 0x1e00) >> 9);
754 s
->ch
[ch
].burst
[0] = (value
& 0x0180) >> 7;
755 s
->ch
[ch
].pack
[0] = (value
& 0x0040) >> 6;
756 s
->ch
[ch
].port
[0] = (enum omap_dma_port
) ((value
& 0x003c) >> 2);
757 s
->ch
[ch
].data_type
= (1 << (value
& 3));
758 if (s
->ch
[ch
].port
[0] >= omap_dma_port_last
)
759 printf("%s: invalid DMA port %i\n", __FUNCTION__
,
761 if (s
->ch
[ch
].port
[1] >= omap_dma_port_last
)
762 printf("%s: invalid DMA port %i\n", __FUNCTION__
,
764 if ((value
& 3) == 3)
765 printf("%s: bad data_type for DMA channel %i\n", __FUNCTION__
, ch
);
768 case 0x02: /* SYS_DMA_CCR_CH0 */
769 s
->ch
[ch
].mode
[1] = (omap_dma_addressing_t
) ((value
& 0xc000) >> 14);
770 s
->ch
[ch
].mode
[0] = (omap_dma_addressing_t
) ((value
& 0x3000) >> 12);
771 s
->ch
[ch
].end_prog
= (value
& 0x0800) >> 11;
772 s
->ch
[ch
].repeat
= (value
& 0x0200) >> 9;
773 s
->ch
[ch
].auto_init
= (value
& 0x0100) >> 8;
774 s
->ch
[ch
].priority
= (value
& 0x0040) >> 6;
775 s
->ch
[ch
].fs
= (value
& 0x0020) >> 5;
776 s
->ch
[ch
].sync
= value
& 0x001f;
777 if (value
& 0x0080) {
778 if (s
->ch
[ch
].running
) {
779 if (!s
->ch
[ch
].signalled
&&
780 s
->ch
[ch
].auto_init
&& s
->ch
[ch
].end_prog
)
781 omap_dma_channel_load(s
, ch
);
783 s
->ch
[ch
].running
= 1;
784 omap_dma_channel_load(s
, ch
);
786 if (!s
->ch
[ch
].sync
|| (s
->drq
& (1 << s
->ch
[ch
].sync
)))
787 omap_dma_request_run(s
, ch
, 0);
789 s
->ch
[ch
].running
= 0;
790 omap_dma_request_stop(s
, ch
);
794 case 0x04: /* SYS_DMA_CICR_CH0 */
795 s
->ch
[ch
].interrupts
= value
& 0x003f;
798 case 0x06: /* SYS_DMA_CSR_CH0 */
801 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
802 s
->ch
[ch
].addr
[0] &= 0xffff0000;
803 s
->ch
[ch
].addr
[0] |= value
;
806 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
807 s
->ch
[ch
].addr
[0] &= 0x0000ffff;
808 s
->ch
[ch
].addr
[0] |= (uint32_t) value
<< 16;
811 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
812 s
->ch
[ch
].addr
[1] &= 0xffff0000;
813 s
->ch
[ch
].addr
[1] |= value
;
816 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
817 s
->ch
[ch
].addr
[1] &= 0x0000ffff;
818 s
->ch
[ch
].addr
[1] |= (uint32_t) value
<< 16;
821 case 0x10: /* SYS_DMA_CEN_CH0 */
822 s
->ch
[ch
].elements
= value
& 0xffff;
825 case 0x12: /* SYS_DMA_CFN_CH0 */
826 s
->ch
[ch
].frames
= value
& 0xffff;
829 case 0x14: /* SYS_DMA_CFI_CH0 */
830 s
->ch
[ch
].frame_index
= value
& 0xffff;
833 case 0x16: /* SYS_DMA_CEI_CH0 */
834 s
->ch
[ch
].element_index
= value
& 0xffff;
837 case 0x18: /* SYS_DMA_CPC_CH0 */
841 OMAP_BAD_REG((target_phys_addr_t
) reg
);
846 static uint32_t omap_dma_read(void *opaque
, target_phys_addr_t addr
)
848 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
849 int i
, reg
, ch
, offset
= addr
- s
->base
;
853 case 0x000 ... 0x2fe:
855 ch
= (offset
>> 6) & 0x0f;
856 if (omap_dma_ch_reg_read(s
, ch
, reg
, &ret
))
860 case 0x300: /* SYS_DMA_LCD_CTRL */
861 i
= s
->lcd_ch
.condition
;
862 s
->lcd_ch
.condition
= 0;
863 qemu_irq_lower(s
->lcd_ch
.irq
);
864 return ((s
->lcd_ch
.src
== imif
) << 6) | (i
<< 3) |
865 (s
->lcd_ch
.interrupts
<< 1) | s
->lcd_ch
.dual
;
867 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
868 return s
->lcd_ch
.src_f1_top
& 0xffff;
870 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
871 return s
->lcd_ch
.src_f1_top
>> 16;
873 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
874 return s
->lcd_ch
.src_f1_bottom
& 0xffff;
876 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
877 return s
->lcd_ch
.src_f1_bottom
>> 16;
879 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
880 return s
->lcd_ch
.src_f2_top
& 0xffff;
882 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
883 return s
->lcd_ch
.src_f2_top
>> 16;
885 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
886 return s
->lcd_ch
.src_f2_bottom
& 0xffff;
888 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
889 return s
->lcd_ch
.src_f2_bottom
>> 16;
891 case 0x400: /* SYS_DMA_GCR */
899 static void omap_dma_write(void *opaque
, target_phys_addr_t addr
,
902 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
903 int reg
, ch
, offset
= addr
- s
->base
;
906 case 0x000 ... 0x2fe:
908 ch
= (offset
>> 6) & 0x0f;
909 if (omap_dma_ch_reg_write(s
, ch
, reg
, value
))
913 case 0x300: /* SYS_DMA_LCD_CTRL */
914 s
->lcd_ch
.src
= (value
& 0x40) ? imif
: emiff
;
915 s
->lcd_ch
.condition
= 0;
916 /* Assume no bus errors and thus no BUS_ERROR irq bits. */
917 s
->lcd_ch
.interrupts
= (value
>> 1) & 1;
918 s
->lcd_ch
.dual
= value
& 1;
921 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
922 s
->lcd_ch
.src_f1_top
&= 0xffff0000;
923 s
->lcd_ch
.src_f1_top
|= 0x0000ffff & value
;
926 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
927 s
->lcd_ch
.src_f1_top
&= 0x0000ffff;
928 s
->lcd_ch
.src_f1_top
|= value
<< 16;
931 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
932 s
->lcd_ch
.src_f1_bottom
&= 0xffff0000;
933 s
->lcd_ch
.src_f1_bottom
|= 0x0000ffff & value
;
936 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
937 s
->lcd_ch
.src_f1_bottom
&= 0x0000ffff;
938 s
->lcd_ch
.src_f1_bottom
|= value
<< 16;
941 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
942 s
->lcd_ch
.src_f2_top
&= 0xffff0000;
943 s
->lcd_ch
.src_f2_top
|= 0x0000ffff & value
;
946 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
947 s
->lcd_ch
.src_f2_top
&= 0x0000ffff;
948 s
->lcd_ch
.src_f2_top
|= value
<< 16;
951 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
952 s
->lcd_ch
.src_f2_bottom
&= 0xffff0000;
953 s
->lcd_ch
.src_f2_bottom
|= 0x0000ffff & value
;
956 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
957 s
->lcd_ch
.src_f2_bottom
&= 0x0000ffff;
958 s
->lcd_ch
.src_f2_bottom
|= value
<< 16;
961 case 0x400: /* SYS_DMA_GCR */
962 s
->gcr
= value
& 0x000c;
970 static CPUReadMemoryFunc
*omap_dma_readfn
[] = {
971 omap_badwidth_read16
,
973 omap_badwidth_read16
,
976 static CPUWriteMemoryFunc
*omap_dma_writefn
[] = {
977 omap_badwidth_write16
,
979 omap_badwidth_write16
,
982 static void omap_dma_request(void *opaque
, int drq
, int req
)
984 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
985 /* The request pins are level triggered. */
987 if (~s
->drq
& (1 << drq
)) {
989 omap_dma_request_run(s
, 0, drq
);
992 s
->drq
&= ~(1 << drq
);
995 static void omap_dma_clk_update(void *opaque
, int line
, int on
)
997 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1000 s
->delay
= ticks_per_sec
>> 7;
1002 qemu_mod_timer(s
->tm
, qemu_get_clock(vm_clock
) + s
->delay
);
1005 qemu_del_timer(s
->tm
);
1009 static void omap_dma_reset(struct omap_dma_s
*s
)
1013 qemu_del_timer(s
->tm
);
1015 s
->drq
= 0x00000000;
1017 s
->lcd_ch
.src
= emiff
;
1018 s
->lcd_ch
.condition
= 0;
1019 s
->lcd_ch
.interrupts
= 0;
1021 memset(s
->ch
, 0, sizeof(s
->ch
));
1022 for (i
= 0; i
< s
->chans
; i
++)
1023 s
->ch
[i
].interrupts
= 0x0003;
1026 struct omap_dma_s
*omap_dma_init(target_phys_addr_t base
,
1027 qemu_irq pic
[], struct omap_mpu_state_s
*mpu
, omap_clk clk
)
1030 struct omap_dma_s
*s
= (struct omap_dma_s
*)
1031 qemu_mallocz(sizeof(struct omap_dma_s
));
1038 s
->lcd_ch
.irq
= pic
[OMAP_INT_DMA_LCD
];
1039 s
->lcd_ch
.mpu
= mpu
;
1040 s
->tm
= qemu_new_timer(vm_clock
, (QEMUTimerCB
*) omap_dma_channel_run
, s
);
1041 omap_clk_adduser(s
->clk
, qemu_allocate_irqs(omap_dma_clk_update
, s
, 1)[0]);
1042 mpu
->drq
= qemu_allocate_irqs(omap_dma_request
, s
, 32);
1044 omap_dma_clk_update(s
, 0, 1);
1046 iomemtype
= cpu_register_io_memory(0, omap_dma_readfn
,
1047 omap_dma_writefn
, s
);
1048 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
1054 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
1055 target_phys_addr_t addr
)
1057 return addr
>= OMAP_EMIFF_BASE
&& addr
< OMAP_EMIFF_BASE
+ s
->sdram_size
;
1060 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
1061 target_phys_addr_t addr
)
1063 return addr
>= OMAP_EMIFS_BASE
&& addr
< OMAP_EMIFF_BASE
;
1066 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
1067 target_phys_addr_t addr
)
1069 return addr
>= OMAP_IMIF_BASE
&& addr
< OMAP_IMIF_BASE
+ s
->sram_size
;
1072 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
1073 target_phys_addr_t addr
)
1075 return addr
>= 0xfffb0000 && addr
< 0xffff0000;
1078 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
1079 target_phys_addr_t addr
)
1081 return addr
>= OMAP_LOCALBUS_BASE
&& addr
< OMAP_LOCALBUS_BASE
+ 0x1000000;
1084 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
1085 target_phys_addr_t addr
)
1087 return addr
>= 0xe1010000 && addr
< 0xe1020004;
1091 struct omap_mpu_timer_s
{
1094 target_phys_addr_t base
;
1108 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
1110 uint64_t distance
= qemu_get_clock(vm_clock
) - timer
->time
;
1112 if (timer
->st
&& timer
->enable
&& timer
->rate
)
1113 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
1114 timer
->rate
, ticks_per_sec
);
1119 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
1121 timer
->val
= omap_timer_read(timer
);
1122 timer
->time
= qemu_get_clock(vm_clock
);
1125 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
1129 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
1130 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
1131 expires
= muldiv64(timer
->val
<< (timer
->ptv
+ 1),
1132 ticks_per_sec
, timer
->rate
);
1134 /* If timer expiry would be sooner than in about 1 ms and
1135 * auto-reload isn't set, then fire immediately. This is a hack
1136 * to make systems like PalmOS run in acceptable time. PalmOS
1137 * sets the interval to a very low value and polls the status bit
1138 * in a busy loop when it wants to sleep just a couple of CPU
1140 if (expires
> (ticks_per_sec
>> 10) || timer
->ar
)
1141 qemu_mod_timer(timer
->timer
, timer
->time
+ expires
);
1146 qemu_irq_raise(timer
->irq
);
1149 qemu_del_timer(timer
->timer
);
1152 static void omap_timer_tick(void *opaque
)
1154 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
1155 omap_timer_sync(timer
);
1163 qemu_irq_raise(timer
->irq
);
1164 omap_timer_update(timer
);
1167 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
1169 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
1171 omap_timer_sync(timer
);
1172 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
1173 omap_timer_update(timer
);
1176 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
1178 omap_clk_adduser(timer
->clk
,
1179 qemu_allocate_irqs(omap_timer_clk_update
, timer
, 1)[0]);
1180 timer
->rate
= omap_clk_getrate(timer
->clk
);
1183 static uint32_t omap_mpu_timer_read(void *opaque
, target_phys_addr_t addr
)
1185 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
1186 int offset
= addr
- s
->base
;
1189 case 0x00: /* CNTL_TIMER */
1190 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
1192 case 0x04: /* LOAD_TIM */
1195 case 0x08: /* READ_TIM */
1196 return omap_timer_read(s
);
1203 static void omap_mpu_timer_write(void *opaque
, target_phys_addr_t addr
,
1206 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
1207 int offset
= addr
- s
->base
;
1210 case 0x00: /* CNTL_TIMER */
1212 s
->enable
= (value
>> 5) & 1;
1213 s
->ptv
= (value
>> 2) & 7;
1214 s
->ar
= (value
>> 1) & 1;
1216 omap_timer_update(s
);
1219 case 0x04: /* LOAD_TIM */
1220 s
->reset_val
= value
;
1223 case 0x08: /* READ_TIM */
1232 static CPUReadMemoryFunc
*omap_mpu_timer_readfn
[] = {
1233 omap_badwidth_read32
,
1234 omap_badwidth_read32
,
1235 omap_mpu_timer_read
,
1238 static CPUWriteMemoryFunc
*omap_mpu_timer_writefn
[] = {
1239 omap_badwidth_write32
,
1240 omap_badwidth_write32
,
1241 omap_mpu_timer_write
,
1244 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
1246 qemu_del_timer(s
->timer
);
1248 s
->reset_val
= 31337;
1256 struct omap_mpu_timer_s
*omap_mpu_timer_init(target_phys_addr_t base
,
1257 qemu_irq irq
, omap_clk clk
)
1260 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*)
1261 qemu_mallocz(sizeof(struct omap_mpu_timer_s
));
1266 s
->timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, s
);
1267 omap_mpu_timer_reset(s
);
1268 omap_timer_clk_setup(s
);
1270 iomemtype
= cpu_register_io_memory(0, omap_mpu_timer_readfn
,
1271 omap_mpu_timer_writefn
, s
);
1272 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
1277 /* Watchdog timer */
1278 struct omap_watchdog_timer_s
{
1279 struct omap_mpu_timer_s timer
;
1286 static uint32_t omap_wd_timer_read(void *opaque
, target_phys_addr_t addr
)
1288 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
1289 int offset
= addr
- s
->timer
.base
;
1292 case 0x00: /* CNTL_TIMER */
1293 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
1294 (s
->timer
.st
<< 7) | (s
->free
<< 1);
1296 case 0x04: /* READ_TIMER */
1297 return omap_timer_read(&s
->timer
);
1299 case 0x08: /* TIMER_MODE */
1300 return s
->mode
<< 15;
1307 static void omap_wd_timer_write(void *opaque
, target_phys_addr_t addr
,
1310 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
1311 int offset
= addr
- s
->timer
.base
;
1314 case 0x00: /* CNTL_TIMER */
1315 omap_timer_sync(&s
->timer
);
1316 s
->timer
.ptv
= (value
>> 9) & 7;
1317 s
->timer
.ar
= (value
>> 8) & 1;
1318 s
->timer
.st
= (value
>> 7) & 1;
1319 s
->free
= (value
>> 1) & 1;
1320 omap_timer_update(&s
->timer
);
1323 case 0x04: /* LOAD_TIMER */
1324 s
->timer
.reset_val
= value
& 0xffff;
1327 case 0x08: /* TIMER_MODE */
1328 if (!s
->mode
&& ((value
>> 15) & 1))
1329 omap_clk_get(s
->timer
.clk
);
1330 s
->mode
|= (value
>> 15) & 1;
1331 if (s
->last_wr
== 0xf5) {
1332 if ((value
& 0xff) == 0xa0) {
1335 omap_clk_put(s
->timer
.clk
);
1338 /* XXX: on T|E hardware somehow this has no effect,
1339 * on Zire 71 it works as specified. */
1341 qemu_system_reset_request();
1344 s
->last_wr
= value
& 0xff;
1352 static CPUReadMemoryFunc
*omap_wd_timer_readfn
[] = {
1353 omap_badwidth_read16
,
1355 omap_badwidth_read16
,
1358 static CPUWriteMemoryFunc
*omap_wd_timer_writefn
[] = {
1359 omap_badwidth_write16
,
1360 omap_wd_timer_write
,
1361 omap_badwidth_write16
,
1364 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
1366 qemu_del_timer(s
->timer
.timer
);
1368 omap_clk_get(s
->timer
.clk
);
1372 s
->timer
.enable
= 1;
1373 s
->timer
.it_ena
= 1;
1374 s
->timer
.reset_val
= 0xffff;
1379 omap_timer_update(&s
->timer
);
1382 struct omap_watchdog_timer_s
*omap_wd_timer_init(target_phys_addr_t base
,
1383 qemu_irq irq
, omap_clk clk
)
1386 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*)
1387 qemu_mallocz(sizeof(struct omap_watchdog_timer_s
));
1391 s
->timer
.base
= base
;
1392 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
1393 omap_wd_timer_reset(s
);
1394 omap_timer_clk_setup(&s
->timer
);
1396 iomemtype
= cpu_register_io_memory(0, omap_wd_timer_readfn
,
1397 omap_wd_timer_writefn
, s
);
1398 cpu_register_physical_memory(s
->timer
.base
, 0x100, iomemtype
);
1404 struct omap_32khz_timer_s
{
1405 struct omap_mpu_timer_s timer
;
1408 static uint32_t omap_os_timer_read(void *opaque
, target_phys_addr_t addr
)
1410 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
1411 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1414 case 0x00: /* TVR */
1415 return s
->timer
.reset_val
;
1417 case 0x04: /* TCR */
1418 return omap_timer_read(&s
->timer
);
1421 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
1430 static void omap_os_timer_write(void *opaque
, target_phys_addr_t addr
,
1433 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
1434 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1437 case 0x00: /* TVR */
1438 s
->timer
.reset_val
= value
& 0x00ffffff;
1441 case 0x04: /* TCR */
1446 s
->timer
.ar
= (value
>> 3) & 1;
1447 s
->timer
.it_ena
= (value
>> 2) & 1;
1448 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
1449 omap_timer_sync(&s
->timer
);
1450 s
->timer
.enable
= value
& 1;
1451 s
->timer
.st
= value
& 1;
1452 omap_timer_update(&s
->timer
);
1461 static CPUReadMemoryFunc
*omap_os_timer_readfn
[] = {
1462 omap_badwidth_read32
,
1463 omap_badwidth_read32
,
1467 static CPUWriteMemoryFunc
*omap_os_timer_writefn
[] = {
1468 omap_badwidth_write32
,
1469 omap_badwidth_write32
,
1470 omap_os_timer_write
,
1473 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
1475 qemu_del_timer(s
->timer
.timer
);
1476 s
->timer
.enable
= 0;
1477 s
->timer
.it_ena
= 0;
1478 s
->timer
.reset_val
= 0x00ffffff;
1485 struct omap_32khz_timer_s
*omap_os_timer_init(target_phys_addr_t base
,
1486 qemu_irq irq
, omap_clk clk
)
1489 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*)
1490 qemu_mallocz(sizeof(struct omap_32khz_timer_s
));
1494 s
->timer
.base
= base
;
1495 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
1496 omap_os_timer_reset(s
);
1497 omap_timer_clk_setup(&s
->timer
);
1499 iomemtype
= cpu_register_io_memory(0, omap_os_timer_readfn
,
1500 omap_os_timer_writefn
, s
);
1501 cpu_register_physical_memory(s
->timer
.base
, 0x800, iomemtype
);
1506 /* Ultra Low-Power Device Module */
1507 static uint32_t omap_ulpd_pm_read(void *opaque
, target_phys_addr_t addr
)
1509 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1510 int offset
= addr
- s
->ulpd_pm_base
;
1514 case 0x14: /* IT_STATUS */
1515 ret
= s
->ulpd_pm_regs
[offset
>> 2];
1516 s
->ulpd_pm_regs
[offset
>> 2] = 0;
1517 qemu_irq_lower(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1520 case 0x18: /* Reserved */
1521 case 0x1c: /* Reserved */
1522 case 0x20: /* Reserved */
1523 case 0x28: /* Reserved */
1524 case 0x2c: /* Reserved */
1526 case 0x00: /* COUNTER_32_LSB */
1527 case 0x04: /* COUNTER_32_MSB */
1528 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1529 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1530 case 0x10: /* GAUGING_CTRL */
1531 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1532 case 0x30: /* CLOCK_CTRL */
1533 case 0x34: /* SOFT_REQ */
1534 case 0x38: /* COUNTER_32_FIQ */
1535 case 0x3c: /* DPLL_CTRL */
1536 case 0x40: /* STATUS_REQ */
1537 /* XXX: check clk::usecount state for every clock */
1538 case 0x48: /* LOCL_TIME */
1539 case 0x4c: /* APLL_CTRL */
1540 case 0x50: /* POWER_CTRL */
1541 return s
->ulpd_pm_regs
[offset
>> 2];
1548 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
1549 uint16_t diff
, uint16_t value
)
1551 if (diff
& (1 << 4)) /* USB_MCLK_EN */
1552 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
1553 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
1554 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
1557 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
1558 uint16_t diff
, uint16_t value
)
1560 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
1561 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
1562 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
1563 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
1564 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
1565 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
1566 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
1567 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
1570 static void omap_ulpd_pm_write(void *opaque
, target_phys_addr_t addr
,
1573 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1574 int offset
= addr
- s
->ulpd_pm_base
;
1577 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1581 case 0x00: /* COUNTER_32_LSB */
1582 case 0x04: /* COUNTER_32_MSB */
1583 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1584 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1585 case 0x14: /* IT_STATUS */
1586 case 0x40: /* STATUS_REQ */
1590 case 0x10: /* GAUGING_CTRL */
1591 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
1592 if ((s
->ulpd_pm_regs
[offset
>> 2] ^ value
) & 1) {
1593 now
= qemu_get_clock(vm_clock
);
1596 s
->ulpd_gauge_start
= now
;
1598 now
-= s
->ulpd_gauge_start
;
1601 ticks
= muldiv64(now
, 32768, ticks_per_sec
);
1602 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
1603 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
1604 if (ticks
>> 32) /* OVERFLOW_32K */
1605 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
1607 /* High frequency ticks */
1608 ticks
= muldiv64(now
, 12000000, ticks_per_sec
);
1609 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
1610 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
1611 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
1612 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
1614 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
1615 qemu_irq_raise(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1618 s
->ulpd_pm_regs
[offset
>> 2] = value
;
1621 case 0x18: /* Reserved */
1622 case 0x1c: /* Reserved */
1623 case 0x20: /* Reserved */
1624 case 0x28: /* Reserved */
1625 case 0x2c: /* Reserved */
1627 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1628 case 0x38: /* COUNTER_32_FIQ */
1629 case 0x48: /* LOCL_TIME */
1630 case 0x50: /* POWER_CTRL */
1631 s
->ulpd_pm_regs
[offset
>> 2] = value
;
1634 case 0x30: /* CLOCK_CTRL */
1635 diff
= s
->ulpd_pm_regs
[offset
>> 2] ^ value
;
1636 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x3f;
1637 omap_ulpd_clk_update(s
, diff
, value
);
1640 case 0x34: /* SOFT_REQ */
1641 diff
= s
->ulpd_pm_regs
[offset
>> 2] ^ value
;
1642 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x1f;
1643 omap_ulpd_req_update(s
, diff
, value
);
1646 case 0x3c: /* DPLL_CTRL */
1647 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
1648 * omitted altogether, probably a typo. */
1649 /* This register has identical semantics with DPLL(1:3) control
1650 * registers, see omap_dpll_write() */
1651 diff
= s
->ulpd_pm_regs
[offset
>> 2] & value
;
1652 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0x2fff;
1653 if (diff
& (0x3ff << 2)) {
1654 if (value
& (1 << 4)) { /* PLL_ENABLE */
1655 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1656 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1658 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1661 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
1664 /* Enter the desired mode. */
1665 s
->ulpd_pm_regs
[offset
>> 2] =
1666 (s
->ulpd_pm_regs
[offset
>> 2] & 0xfffe) |
1667 ((s
->ulpd_pm_regs
[offset
>> 2] >> 4) & 1);
1669 /* Act as if the lock is restored. */
1670 s
->ulpd_pm_regs
[offset
>> 2] |= 2;
1673 case 0x4c: /* APLL_CTRL */
1674 diff
= s
->ulpd_pm_regs
[offset
>> 2] & value
;
1675 s
->ulpd_pm_regs
[offset
>> 2] = value
& 0xf;
1676 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
1677 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
1678 (value
& (1 << 0)) ? "apll" : "dpll4"));
1686 static CPUReadMemoryFunc
*omap_ulpd_pm_readfn
[] = {
1687 omap_badwidth_read16
,
1689 omap_badwidth_read16
,
1692 static CPUWriteMemoryFunc
*omap_ulpd_pm_writefn
[] = {
1693 omap_badwidth_write16
,
1695 omap_badwidth_write16
,
1698 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
1700 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
1701 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
1702 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
1703 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
1704 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
1705 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
1706 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
1707 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
1708 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
1709 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
1710 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
1711 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
1712 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
1713 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
1714 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
1715 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
1716 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
1717 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
1718 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
1719 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
1720 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
1721 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
1722 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
1725 static void omap_ulpd_pm_init(target_phys_addr_t base
,
1726 struct omap_mpu_state_s
*mpu
)
1728 int iomemtype
= cpu_register_io_memory(0, omap_ulpd_pm_readfn
,
1729 omap_ulpd_pm_writefn
, mpu
);
1731 mpu
->ulpd_pm_base
= base
;
1732 cpu_register_physical_memory(mpu
->ulpd_pm_base
, 0x800, iomemtype
);
1733 omap_ulpd_pm_reset(mpu
);
1736 /* OMAP Pin Configuration */
1737 static uint32_t omap_pin_cfg_read(void *opaque
, target_phys_addr_t addr
)
1739 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1740 int offset
= addr
- s
->pin_cfg_base
;
1743 case 0x00: /* FUNC_MUX_CTRL_0 */
1744 case 0x04: /* FUNC_MUX_CTRL_1 */
1745 case 0x08: /* FUNC_MUX_CTRL_2 */
1746 return s
->func_mux_ctrl
[offset
>> 2];
1748 case 0x0c: /* COMP_MODE_CTRL_0 */
1749 return s
->comp_mode_ctrl
[0];
1751 case 0x10: /* FUNC_MUX_CTRL_3 */
1752 case 0x14: /* FUNC_MUX_CTRL_4 */
1753 case 0x18: /* FUNC_MUX_CTRL_5 */
1754 case 0x1c: /* FUNC_MUX_CTRL_6 */
1755 case 0x20: /* FUNC_MUX_CTRL_7 */
1756 case 0x24: /* FUNC_MUX_CTRL_8 */
1757 case 0x28: /* FUNC_MUX_CTRL_9 */
1758 case 0x2c: /* FUNC_MUX_CTRL_A */
1759 case 0x30: /* FUNC_MUX_CTRL_B */
1760 case 0x34: /* FUNC_MUX_CTRL_C */
1761 case 0x38: /* FUNC_MUX_CTRL_D */
1762 return s
->func_mux_ctrl
[(offset
>> 2) - 1];
1764 case 0x40: /* PULL_DWN_CTRL_0 */
1765 case 0x44: /* PULL_DWN_CTRL_1 */
1766 case 0x48: /* PULL_DWN_CTRL_2 */
1767 case 0x4c: /* PULL_DWN_CTRL_3 */
1768 return s
->pull_dwn_ctrl
[(offset
& 0xf) >> 2];
1770 case 0x50: /* GATE_INH_CTRL_0 */
1771 return s
->gate_inh_ctrl
[0];
1773 case 0x60: /* VOLTAGE_CTRL_0 */
1774 return s
->voltage_ctrl
[0];
1776 case 0x70: /* TEST_DBG_CTRL_0 */
1777 return s
->test_dbg_ctrl
[0];
1779 case 0x80: /* MOD_CONF_CTRL_0 */
1780 return s
->mod_conf_ctrl
[0];
1787 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
1788 uint32_t diff
, uint32_t value
)
1790 if (s
->compat1509
) {
1791 if (diff
& (1 << 9)) /* BLUETOOTH */
1792 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
1794 if (diff
& (1 << 7)) /* USB.CLKO */
1795 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
1800 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
1801 uint32_t diff
, uint32_t value
)
1803 if (s
->compat1509
) {
1804 if (diff
& (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
1805 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"),
1807 if (diff
& (1 << 1)) /* CLK32K */
1808 omap_clk_onoff(omap_findclk(s
, "clk32k_out"),
1813 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
1814 uint32_t diff
, uint32_t value
)
1816 if (diff
& (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
1817 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
1818 omap_findclk(s
, ((value
>> 31) & 1) ?
1819 "ck_48m" : "armper_ck"));
1820 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
1821 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
1822 omap_findclk(s
, ((value
>> 30) & 1) ?
1823 "ck_48m" : "armper_ck"));
1824 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
1825 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
1826 omap_findclk(s
, ((value
>> 29) & 1) ?
1827 "ck_48m" : "armper_ck"));
1828 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
1829 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
1830 omap_findclk(s
, ((value
>> 23) & 1) ?
1831 "ck_48m" : "armper_ck"));
1832 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
1833 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
1834 omap_findclk(s
, ((value
>> 12) & 1) ?
1835 "ck_48m" : "armper_ck"));
1836 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
1837 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
1840 static void omap_pin_cfg_write(void *opaque
, target_phys_addr_t addr
,
1843 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1844 int offset
= addr
- s
->pin_cfg_base
;
1848 case 0x00: /* FUNC_MUX_CTRL_0 */
1849 diff
= s
->func_mux_ctrl
[offset
>> 2] ^ value
;
1850 s
->func_mux_ctrl
[offset
>> 2] = value
;
1851 omap_pin_funcmux0_update(s
, diff
, value
);
1854 case 0x04: /* FUNC_MUX_CTRL_1 */
1855 diff
= s
->func_mux_ctrl
[offset
>> 2] ^ value
;
1856 s
->func_mux_ctrl
[offset
>> 2] = value
;
1857 omap_pin_funcmux1_update(s
, diff
, value
);
1860 case 0x08: /* FUNC_MUX_CTRL_2 */
1861 s
->func_mux_ctrl
[offset
>> 2] = value
;
1864 case 0x0c: /* COMP_MODE_CTRL_0 */
1865 s
->comp_mode_ctrl
[0] = value
;
1866 s
->compat1509
= (value
!= 0x0000eaef);
1867 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
1868 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
1871 case 0x10: /* FUNC_MUX_CTRL_3 */
1872 case 0x14: /* FUNC_MUX_CTRL_4 */
1873 case 0x18: /* FUNC_MUX_CTRL_5 */
1874 case 0x1c: /* FUNC_MUX_CTRL_6 */
1875 case 0x20: /* FUNC_MUX_CTRL_7 */
1876 case 0x24: /* FUNC_MUX_CTRL_8 */
1877 case 0x28: /* FUNC_MUX_CTRL_9 */
1878 case 0x2c: /* FUNC_MUX_CTRL_A */
1879 case 0x30: /* FUNC_MUX_CTRL_B */
1880 case 0x34: /* FUNC_MUX_CTRL_C */
1881 case 0x38: /* FUNC_MUX_CTRL_D */
1882 s
->func_mux_ctrl
[(offset
>> 2) - 1] = value
;
1885 case 0x40: /* PULL_DWN_CTRL_0 */
1886 case 0x44: /* PULL_DWN_CTRL_1 */
1887 case 0x48: /* PULL_DWN_CTRL_2 */
1888 case 0x4c: /* PULL_DWN_CTRL_3 */
1889 s
->pull_dwn_ctrl
[(offset
& 0xf) >> 2] = value
;
1892 case 0x50: /* GATE_INH_CTRL_0 */
1893 s
->gate_inh_ctrl
[0] = value
;
1896 case 0x60: /* VOLTAGE_CTRL_0 */
1897 s
->voltage_ctrl
[0] = value
;
1900 case 0x70: /* TEST_DBG_CTRL_0 */
1901 s
->test_dbg_ctrl
[0] = value
;
1904 case 0x80: /* MOD_CONF_CTRL_0 */
1905 diff
= s
->mod_conf_ctrl
[0] ^ value
;
1906 s
->mod_conf_ctrl
[0] = value
;
1907 omap_pin_modconf1_update(s
, diff
, value
);
1915 static CPUReadMemoryFunc
*omap_pin_cfg_readfn
[] = {
1916 omap_badwidth_read32
,
1917 omap_badwidth_read32
,
1921 static CPUWriteMemoryFunc
*omap_pin_cfg_writefn
[] = {
1922 omap_badwidth_write32
,
1923 omap_badwidth_write32
,
1927 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
1929 /* Start in Compatibility Mode. */
1930 mpu
->compat1509
= 1;
1931 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
1932 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
1933 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
1934 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
1935 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
1936 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
1937 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
1938 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
1939 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
1940 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
1943 static void omap_pin_cfg_init(target_phys_addr_t base
,
1944 struct omap_mpu_state_s
*mpu
)
1946 int iomemtype
= cpu_register_io_memory(0, omap_pin_cfg_readfn
,
1947 omap_pin_cfg_writefn
, mpu
);
1949 mpu
->pin_cfg_base
= base
;
1950 cpu_register_physical_memory(mpu
->pin_cfg_base
, 0x800, iomemtype
);
1951 omap_pin_cfg_reset(mpu
);
1954 /* Device Identification, Die Identification */
1955 static uint32_t omap_id_read(void *opaque
, target_phys_addr_t addr
)
1957 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1960 case 0xfffe1800: /* DIE_ID_LSB */
1962 case 0xfffe1804: /* DIE_ID_MSB */
1965 case 0xfffe2000: /* PRODUCT_ID_LSB */
1967 case 0xfffe2004: /* PRODUCT_ID_MSB */
1970 case 0xfffed400: /* JTAG_ID_LSB */
1971 switch (s
->mpu_model
) {
1979 case 0xfffed404: /* JTAG_ID_MSB */
1980 switch (s
->mpu_model
) {
1993 static void omap_id_write(void *opaque
, target_phys_addr_t addr
,
1999 static CPUReadMemoryFunc
*omap_id_readfn
[] = {
2000 omap_badwidth_read32
,
2001 omap_badwidth_read32
,
2005 static CPUWriteMemoryFunc
*omap_id_writefn
[] = {
2006 omap_badwidth_write32
,
2007 omap_badwidth_write32
,
2011 static void omap_id_init(struct omap_mpu_state_s
*mpu
)
2013 int iomemtype
= cpu_register_io_memory(0, omap_id_readfn
,
2014 omap_id_writefn
, mpu
);
2015 cpu_register_physical_memory(0xfffe1800, 0x800, iomemtype
);
2016 cpu_register_physical_memory(0xfffed400, 0x100, iomemtype
);
2017 if (!cpu_is_omap15xx(mpu
))
2018 cpu_register_physical_memory(0xfffe2000, 0x800, iomemtype
);
2021 /* MPUI Control (Dummy) */
2022 static uint32_t omap_mpui_read(void *opaque
, target_phys_addr_t addr
)
2024 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2025 int offset
= addr
- s
->mpui_base
;
2028 case 0x00: /* CTRL */
2029 return s
->mpui_ctrl
;
2030 case 0x04: /* DEBUG_ADDR */
2032 case 0x08: /* DEBUG_DATA */
2034 case 0x0c: /* DEBUG_FLAG */
2036 case 0x10: /* STATUS */
2039 /* Not in OMAP310 */
2040 case 0x14: /* DSP_STATUS */
2041 case 0x18: /* DSP_BOOT_CONFIG */
2043 case 0x1c: /* DSP_MPUI_CONFIG */
2051 static void omap_mpui_write(void *opaque
, target_phys_addr_t addr
,
2054 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2055 int offset
= addr
- s
->mpui_base
;
2058 case 0x00: /* CTRL */
2059 s
->mpui_ctrl
= value
& 0x007fffff;
2062 case 0x04: /* DEBUG_ADDR */
2063 case 0x08: /* DEBUG_DATA */
2064 case 0x0c: /* DEBUG_FLAG */
2065 case 0x10: /* STATUS */
2066 /* Not in OMAP310 */
2067 case 0x14: /* DSP_STATUS */
2069 case 0x18: /* DSP_BOOT_CONFIG */
2070 case 0x1c: /* DSP_MPUI_CONFIG */
2078 static CPUReadMemoryFunc
*omap_mpui_readfn
[] = {
2079 omap_badwidth_read32
,
2080 omap_badwidth_read32
,
2084 static CPUWriteMemoryFunc
*omap_mpui_writefn
[] = {
2085 omap_badwidth_write32
,
2086 omap_badwidth_write32
,
2090 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
2092 s
->mpui_ctrl
= 0x0003ff1b;
2095 static void omap_mpui_init(target_phys_addr_t base
,
2096 struct omap_mpu_state_s
*mpu
)
2098 int iomemtype
= cpu_register_io_memory(0, omap_mpui_readfn
,
2099 omap_mpui_writefn
, mpu
);
2101 mpu
->mpui_base
= base
;
2102 cpu_register_physical_memory(mpu
->mpui_base
, 0x100, iomemtype
);
2104 omap_mpui_reset(mpu
);
2108 struct omap_tipb_bridge_s
{
2109 target_phys_addr_t base
;
2116 uint16_t enh_control
;
2119 static uint32_t omap_tipb_bridge_read(void *opaque
, target_phys_addr_t addr
)
2121 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
2122 int offset
= addr
- s
->base
;
2125 case 0x00: /* TIPB_CNTL */
2127 case 0x04: /* TIPB_BUS_ALLOC */
2129 case 0x08: /* MPU_TIPB_CNTL */
2131 case 0x0c: /* ENHANCED_TIPB_CNTL */
2132 return s
->enh_control
;
2133 case 0x10: /* ADDRESS_DBG */
2134 case 0x14: /* DATA_DEBUG_LOW */
2135 case 0x18: /* DATA_DEBUG_HIGH */
2137 case 0x1c: /* DEBUG_CNTR_SIG */
2145 static void omap_tipb_bridge_write(void *opaque
, target_phys_addr_t addr
,
2148 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
2149 int offset
= addr
- s
->base
;
2152 case 0x00: /* TIPB_CNTL */
2153 s
->control
= value
& 0xffff;
2156 case 0x04: /* TIPB_BUS_ALLOC */
2157 s
->alloc
= value
& 0x003f;
2160 case 0x08: /* MPU_TIPB_CNTL */
2161 s
->buffer
= value
& 0x0003;
2164 case 0x0c: /* ENHANCED_TIPB_CNTL */
2165 s
->width_intr
= !(value
& 2);
2166 s
->enh_control
= value
& 0x000f;
2169 case 0x10: /* ADDRESS_DBG */
2170 case 0x14: /* DATA_DEBUG_LOW */
2171 case 0x18: /* DATA_DEBUG_HIGH */
2172 case 0x1c: /* DEBUG_CNTR_SIG */
2181 static CPUReadMemoryFunc
*omap_tipb_bridge_readfn
[] = {
2182 omap_badwidth_read16
,
2183 omap_tipb_bridge_read
,
2184 omap_tipb_bridge_read
,
2187 static CPUWriteMemoryFunc
*omap_tipb_bridge_writefn
[] = {
2188 omap_badwidth_write16
,
2189 omap_tipb_bridge_write
,
2190 omap_tipb_bridge_write
,
2193 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
2195 s
->control
= 0xffff;
2198 s
->enh_control
= 0x000f;
2201 struct omap_tipb_bridge_s
*omap_tipb_bridge_init(target_phys_addr_t base
,
2202 qemu_irq abort_irq
, omap_clk clk
)
2205 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*)
2206 qemu_mallocz(sizeof(struct omap_tipb_bridge_s
));
2208 s
->abort
= abort_irq
;
2210 omap_tipb_bridge_reset(s
);
2212 iomemtype
= cpu_register_io_memory(0, omap_tipb_bridge_readfn
,
2213 omap_tipb_bridge_writefn
, s
);
2214 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
2219 /* Dummy Traffic Controller's Memory Interface */
2220 static uint32_t omap_tcmi_read(void *opaque
, target_phys_addr_t addr
)
2222 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2223 int offset
= addr
- s
->tcmi_base
;
2227 case 0x00: /* IMIF_PRIO */
2228 case 0x04: /* EMIFS_PRIO */
2229 case 0x08: /* EMIFF_PRIO */
2230 case 0x0c: /* EMIFS_CONFIG */
2231 case 0x10: /* EMIFS_CS0_CONFIG */
2232 case 0x14: /* EMIFS_CS1_CONFIG */
2233 case 0x18: /* EMIFS_CS2_CONFIG */
2234 case 0x1c: /* EMIFS_CS3_CONFIG */
2235 case 0x24: /* EMIFF_MRS */
2236 case 0x28: /* TIMEOUT1 */
2237 case 0x2c: /* TIMEOUT2 */
2238 case 0x30: /* TIMEOUT3 */
2239 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
2240 case 0x40: /* EMIFS_CFG_DYN_WAIT */
2241 return s
->tcmi_regs
[offset
>> 2];
2243 case 0x20: /* EMIFF_SDRAM_CONFIG */
2244 ret
= s
->tcmi_regs
[offset
>> 2];
2245 s
->tcmi_regs
[offset
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
2246 /* XXX: We can try using the VGA_DIRTY flag for this */
2254 static void omap_tcmi_write(void *opaque
, target_phys_addr_t addr
,
2257 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2258 int offset
= addr
- s
->tcmi_base
;
2261 case 0x00: /* IMIF_PRIO */
2262 case 0x04: /* EMIFS_PRIO */
2263 case 0x08: /* EMIFF_PRIO */
2264 case 0x10: /* EMIFS_CS0_CONFIG */
2265 case 0x14: /* EMIFS_CS1_CONFIG */
2266 case 0x18: /* EMIFS_CS2_CONFIG */
2267 case 0x1c: /* EMIFS_CS3_CONFIG */
2268 case 0x20: /* EMIFF_SDRAM_CONFIG */
2269 case 0x24: /* EMIFF_MRS */
2270 case 0x28: /* TIMEOUT1 */
2271 case 0x2c: /* TIMEOUT2 */
2272 case 0x30: /* TIMEOUT3 */
2273 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
2274 case 0x40: /* EMIFS_CFG_DYN_WAIT */
2275 s
->tcmi_regs
[offset
>> 2] = value
;
2277 case 0x0c: /* EMIFS_CONFIG */
2278 s
->tcmi_regs
[offset
>> 2] = (value
& 0xf) | (1 << 4);
2286 static CPUReadMemoryFunc
*omap_tcmi_readfn
[] = {
2287 omap_badwidth_read32
,
2288 omap_badwidth_read32
,
2292 static CPUWriteMemoryFunc
*omap_tcmi_writefn
[] = {
2293 omap_badwidth_write32
,
2294 omap_badwidth_write32
,
2298 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
2300 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
2301 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
2302 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
2303 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
2304 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
2305 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
2306 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
2307 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
2308 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
2309 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
2310 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
2311 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
2312 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
2313 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
2314 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
2317 static void omap_tcmi_init(target_phys_addr_t base
,
2318 struct omap_mpu_state_s
*mpu
)
2320 int iomemtype
= cpu_register_io_memory(0, omap_tcmi_readfn
,
2321 omap_tcmi_writefn
, mpu
);
2323 mpu
->tcmi_base
= base
;
2324 cpu_register_physical_memory(mpu
->tcmi_base
, 0x100, iomemtype
);
2325 omap_tcmi_reset(mpu
);
2328 /* Digital phase-locked loops control */
2329 static uint32_t omap_dpll_read(void *opaque
, target_phys_addr_t addr
)
2331 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
2332 int offset
= addr
- s
->base
;
2334 if (offset
== 0x00) /* CTL_REG */
2341 static void omap_dpll_write(void *opaque
, target_phys_addr_t addr
,
2344 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
2346 int offset
= addr
- s
->base
;
2347 static const int bypass_div
[4] = { 1, 2, 4, 4 };
2350 if (offset
== 0x00) { /* CTL_REG */
2351 /* See omap_ulpd_pm_write() too */
2352 diff
= s
->mode
& value
;
2353 s
->mode
= value
& 0x2fff;
2354 if (diff
& (0x3ff << 2)) {
2355 if (value
& (1 << 4)) { /* PLL_ENABLE */
2356 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
2357 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
2359 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
2362 omap_clk_setrate(s
->dpll
, div
, mult
);
2365 /* Enter the desired mode. */
2366 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
2368 /* Act as if the lock is restored. */
2375 static CPUReadMemoryFunc
*omap_dpll_readfn
[] = {
2376 omap_badwidth_read16
,
2378 omap_badwidth_read16
,
2381 static CPUWriteMemoryFunc
*omap_dpll_writefn
[] = {
2382 omap_badwidth_write16
,
2384 omap_badwidth_write16
,
2387 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
2390 omap_clk_setrate(s
->dpll
, 1, 1);
2393 static void omap_dpll_init(struct dpll_ctl_s
*s
, target_phys_addr_t base
,
2396 int iomemtype
= cpu_register_io_memory(0, omap_dpll_readfn
,
2397 omap_dpll_writefn
, s
);
2403 cpu_register_physical_memory(s
->base
, 0x100, iomemtype
);
2407 struct omap_uart_s
{
2408 SerialState
*serial
; /* TODO */
2411 static void omap_uart_reset(struct omap_uart_s
*s
)
2415 struct omap_uart_s
*omap_uart_init(target_phys_addr_t base
,
2416 qemu_irq irq
, omap_clk clk
, CharDriverState
*chr
)
2418 struct omap_uart_s
*s
= (struct omap_uart_s
*)
2419 qemu_mallocz(sizeof(struct omap_uart_s
));
2421 s
->serial
= serial_mm_init(base
, 2, irq
, chr
, 1);
2425 /* MPU Clock/Reset/Power Mode Control */
2426 static uint32_t omap_clkm_read(void *opaque
, target_phys_addr_t addr
)
2428 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2429 int offset
= addr
- s
->clkm
.mpu_base
;
2432 case 0x00: /* ARM_CKCTL */
2433 return s
->clkm
.arm_ckctl
;
2435 case 0x04: /* ARM_IDLECT1 */
2436 return s
->clkm
.arm_idlect1
;
2438 case 0x08: /* ARM_IDLECT2 */
2439 return s
->clkm
.arm_idlect2
;
2441 case 0x0c: /* ARM_EWUPCT */
2442 return s
->clkm
.arm_ewupct
;
2444 case 0x10: /* ARM_RSTCT1 */
2445 return s
->clkm
.arm_rstct1
;
2447 case 0x14: /* ARM_RSTCT2 */
2448 return s
->clkm
.arm_rstct2
;
2450 case 0x18: /* ARM_SYSST */
2451 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
2453 case 0x1c: /* ARM_CKOUT1 */
2454 return s
->clkm
.arm_ckout1
;
2456 case 0x20: /* ARM_CKOUT2 */
2464 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
2465 uint16_t diff
, uint16_t value
)
2469 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
2470 if (value
& (1 << 14))
2473 clk
= omap_findclk(s
, "arminth_ck");
2474 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2477 if (diff
& (1 << 12)) { /* ARM_TIMXO */
2478 clk
= omap_findclk(s
, "armtim_ck");
2479 if (value
& (1 << 12))
2480 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
2482 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2485 if (diff
& (3 << 10)) { /* DSPMMUDIV */
2486 clk
= omap_findclk(s
, "dspmmu_ck");
2487 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
2489 if (diff
& (3 << 8)) { /* TCDIV */
2490 clk
= omap_findclk(s
, "tc_ck");
2491 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
2493 if (diff
& (3 << 6)) { /* DSPDIV */
2494 clk
= omap_findclk(s
, "dsp_ck");
2495 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
2497 if (diff
& (3 << 4)) { /* ARMDIV */
2498 clk
= omap_findclk(s
, "arm_ck");
2499 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
2501 if (diff
& (3 << 2)) { /* LCDDIV */
2502 clk
= omap_findclk(s
, "lcd_ck");
2503 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
2505 if (diff
& (3 << 0)) { /* PERDIV */
2506 clk
= omap_findclk(s
, "armper_ck");
2507 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
2511 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
2512 uint16_t diff
, uint16_t value
)
2516 if (value
& (1 << 11)) /* SETARM_IDLE */
2517 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
2518 if (!(value
& (1 << 10))) /* WKUP_MODE */
2519 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
2521 #define SET_CANIDLE(clock, bit) \
2522 if (diff & (1 << bit)) { \
2523 clk = omap_findclk(s, clock); \
2524 omap_clk_canidle(clk, (value >> bit) & 1); \
2526 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
2527 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
2528 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
2529 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
2530 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
2531 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
2532 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
2533 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
2534 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
2535 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
2536 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
2537 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
2538 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
2539 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
2542 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
2543 uint16_t diff
, uint16_t value
)
2547 #define SET_ONOFF(clock, bit) \
2548 if (diff & (1 << bit)) { \
2549 clk = omap_findclk(s, clock); \
2550 omap_clk_onoff(clk, (value >> bit) & 1); \
2552 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
2553 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
2554 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
2555 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
2556 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
2557 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
2558 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
2559 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
2560 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
2561 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
2562 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
2565 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
2566 uint16_t diff
, uint16_t value
)
2570 if (diff
& (3 << 4)) { /* TCLKOUT */
2571 clk
= omap_findclk(s
, "tclk_out");
2572 switch ((value
>> 4) & 3) {
2574 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
2575 omap_clk_onoff(clk
, 1);
2578 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2579 omap_clk_onoff(clk
, 1);
2582 omap_clk_onoff(clk
, 0);
2585 if (diff
& (3 << 2)) { /* DCLKOUT */
2586 clk
= omap_findclk(s
, "dclk_out");
2587 switch ((value
>> 2) & 3) {
2589 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
2592 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
2595 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
2598 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2602 if (diff
& (3 << 0)) { /* ACLKOUT */
2603 clk
= omap_findclk(s
, "aclk_out");
2604 switch ((value
>> 0) & 3) {
2606 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2607 omap_clk_onoff(clk
, 1);
2610 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
2611 omap_clk_onoff(clk
, 1);
2614 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2615 omap_clk_onoff(clk
, 1);
2618 omap_clk_onoff(clk
, 0);
2623 static void omap_clkm_write(void *opaque
, target_phys_addr_t addr
,
2626 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2627 int offset
= addr
- s
->clkm
.mpu_base
;
2630 static const char *clkschemename
[8] = {
2631 "fully synchronous", "fully asynchronous", "synchronous scalable",
2632 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
2636 case 0x00: /* ARM_CKCTL */
2637 diff
= s
->clkm
.arm_ckctl
^ value
;
2638 s
->clkm
.arm_ckctl
= value
& 0x7fff;
2639 omap_clkm_ckctl_update(s
, diff
, value
);
2642 case 0x04: /* ARM_IDLECT1 */
2643 diff
= s
->clkm
.arm_idlect1
^ value
;
2644 s
->clkm
.arm_idlect1
= value
& 0x0fff;
2645 omap_clkm_idlect1_update(s
, diff
, value
);
2648 case 0x08: /* ARM_IDLECT2 */
2649 diff
= s
->clkm
.arm_idlect2
^ value
;
2650 s
->clkm
.arm_idlect2
= value
& 0x07ff;
2651 omap_clkm_idlect2_update(s
, diff
, value
);
2654 case 0x0c: /* ARM_EWUPCT */
2655 diff
= s
->clkm
.arm_ewupct
^ value
;
2656 s
->clkm
.arm_ewupct
= value
& 0x003f;
2659 case 0x10: /* ARM_RSTCT1 */
2660 diff
= s
->clkm
.arm_rstct1
^ value
;
2661 s
->clkm
.arm_rstct1
= value
& 0x0007;
2663 qemu_system_reset_request();
2664 s
->clkm
.cold_start
= 0xa;
2666 if (diff
& ~value
& 4) { /* DSP_RST */
2668 omap_tipb_bridge_reset(s
->private_tipb
);
2669 omap_tipb_bridge_reset(s
->public_tipb
);
2671 if (diff
& 2) { /* DSP_EN */
2672 clk
= omap_findclk(s
, "dsp_ck");
2673 omap_clk_canidle(clk
, (~value
>> 1) & 1);
2677 case 0x14: /* ARM_RSTCT2 */
2678 s
->clkm
.arm_rstct2
= value
& 0x0001;
2681 case 0x18: /* ARM_SYSST */
2682 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
2683 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
2684 printf("%s: clocking scheme set to %s\n", __FUNCTION__
,
2685 clkschemename
[s
->clkm
.clocking_scheme
]);
2687 s
->clkm
.cold_start
&= value
& 0x3f;
2690 case 0x1c: /* ARM_CKOUT1 */
2691 diff
= s
->clkm
.arm_ckout1
^ value
;
2692 s
->clkm
.arm_ckout1
= value
& 0x003f;
2693 omap_clkm_ckout1_update(s
, diff
, value
);
2696 case 0x20: /* ARM_CKOUT2 */
2702 static CPUReadMemoryFunc
*omap_clkm_readfn
[] = {
2703 omap_badwidth_read16
,
2705 omap_badwidth_read16
,
2708 static CPUWriteMemoryFunc
*omap_clkm_writefn
[] = {
2709 omap_badwidth_write16
,
2711 omap_badwidth_write16
,
2714 static uint32_t omap_clkdsp_read(void *opaque
, target_phys_addr_t addr
)
2716 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2717 int offset
= addr
- s
->clkm
.dsp_base
;
2720 case 0x04: /* DSP_IDLECT1 */
2721 return s
->clkm
.dsp_idlect1
;
2723 case 0x08: /* DSP_IDLECT2 */
2724 return s
->clkm
.dsp_idlect2
;
2726 case 0x14: /* DSP_RSTCT2 */
2727 return s
->clkm
.dsp_rstct2
;
2729 case 0x18: /* DSP_SYSST */
2730 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
2731 (s
->env
->halted
<< 6); /* Quite useless... */
2738 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
2739 uint16_t diff
, uint16_t value
)
2743 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
2746 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
2747 uint16_t diff
, uint16_t value
)
2751 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
2754 static void omap_clkdsp_write(void *opaque
, target_phys_addr_t addr
,
2757 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2758 int offset
= addr
- s
->clkm
.dsp_base
;
2762 case 0x04: /* DSP_IDLECT1 */
2763 diff
= s
->clkm
.dsp_idlect1
^ value
;
2764 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
2765 omap_clkdsp_idlect1_update(s
, diff
, value
);
2768 case 0x08: /* DSP_IDLECT2 */
2769 s
->clkm
.dsp_idlect2
= value
& 0x0037;
2770 diff
= s
->clkm
.dsp_idlect1
^ value
;
2771 omap_clkdsp_idlect2_update(s
, diff
, value
);
2774 case 0x14: /* DSP_RSTCT2 */
2775 s
->clkm
.dsp_rstct2
= value
& 0x0001;
2778 case 0x18: /* DSP_SYSST */
2779 s
->clkm
.cold_start
&= value
& 0x3f;
2787 static CPUReadMemoryFunc
*omap_clkdsp_readfn
[] = {
2788 omap_badwidth_read16
,
2790 omap_badwidth_read16
,
2793 static CPUWriteMemoryFunc
*omap_clkdsp_writefn
[] = {
2794 omap_badwidth_write16
,
2796 omap_badwidth_write16
,
2799 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
2801 if (s
->wdt
&& s
->wdt
->reset
)
2802 s
->clkm
.cold_start
= 0x6;
2803 s
->clkm
.clocking_scheme
= 0;
2804 omap_clkm_ckctl_update(s
, ~0, 0x3000);
2805 s
->clkm
.arm_ckctl
= 0x3000;
2806 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
2807 s
->clkm
.arm_idlect1
= 0x0400;
2808 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
2809 s
->clkm
.arm_idlect2
= 0x0100;
2810 s
->clkm
.arm_ewupct
= 0x003f;
2811 s
->clkm
.arm_rstct1
= 0x0000;
2812 s
->clkm
.arm_rstct2
= 0x0000;
2813 s
->clkm
.arm_ckout1
= 0x0015;
2814 s
->clkm
.dpll1_mode
= 0x2002;
2815 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
2816 s
->clkm
.dsp_idlect1
= 0x0040;
2817 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
2818 s
->clkm
.dsp_idlect2
= 0x0000;
2819 s
->clkm
.dsp_rstct2
= 0x0000;
2822 static void omap_clkm_init(target_phys_addr_t mpu_base
,
2823 target_phys_addr_t dsp_base
, struct omap_mpu_state_s
*s
)
2825 int iomemtype
[2] = {
2826 cpu_register_io_memory(0, omap_clkm_readfn
, omap_clkm_writefn
, s
),
2827 cpu_register_io_memory(0, omap_clkdsp_readfn
, omap_clkdsp_writefn
, s
),
2830 s
->clkm
.mpu_base
= mpu_base
;
2831 s
->clkm
.dsp_base
= dsp_base
;
2832 s
->clkm
.arm_idlect1
= 0x03ff;
2833 s
->clkm
.arm_idlect2
= 0x0100;
2834 s
->clkm
.dsp_idlect1
= 0x0002;
2836 s
->clkm
.cold_start
= 0x3a;
2838 cpu_register_physical_memory(s
->clkm
.mpu_base
, 0x100, iomemtype
[0]);
2839 cpu_register_physical_memory(s
->clkm
.dsp_base
, 0x1000, iomemtype
[1]);
2843 struct omap_mpuio_s
{
2844 target_phys_addr_t base
;
2848 qemu_irq handler
[16];
2869 static void omap_mpuio_set(void *opaque
, int line
, int level
)
2871 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2872 uint16_t prev
= s
->inputs
;
2875 s
->inputs
|= 1 << line
;
2877 s
->inputs
&= ~(1 << line
);
2879 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
2880 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
2881 s
->ints
|= 1 << line
;
2882 qemu_irq_raise(s
->irq
);
2885 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
2886 (s
->event
>> 1) == line
) /* PIN_SELECT */
2887 s
->latch
= s
->inputs
;
2891 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
2894 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
2896 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
2900 qemu_set_irq(s
->kbd_irq
, rows
&& ~s
->kbd_mask
&& s
->clk
);
2901 s
->row_latch
= rows
^ 0x1f;
2904 static uint32_t omap_mpuio_read(void *opaque
, target_phys_addr_t addr
)
2906 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2907 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2911 case 0x00: /* INPUT_LATCH */
2914 case 0x04: /* OUTPUT_REG */
2917 case 0x08: /* IO_CNTL */
2920 case 0x10: /* KBR_LATCH */
2921 return s
->row_latch
;
2923 case 0x14: /* KBC_REG */
2926 case 0x18: /* GPIO_EVENT_MODE_REG */
2929 case 0x1c: /* GPIO_INT_EDGE_REG */
2932 case 0x20: /* KBD_INT */
2933 return (s
->row_latch
!= 0x1f) && !s
->kbd_mask
;
2935 case 0x24: /* GPIO_INT */
2939 qemu_irq_lower(s
->irq
);
2942 case 0x28: /* KBD_MASKIT */
2945 case 0x2c: /* GPIO_MASKIT */
2948 case 0x30: /* GPIO_DEBOUNCING_REG */
2951 case 0x34: /* GPIO_LATCH_REG */
2959 static void omap_mpuio_write(void *opaque
, target_phys_addr_t addr
,
2962 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2963 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2968 case 0x04: /* OUTPUT_REG */
2969 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2971 while ((ln
= ffs(diff
))) {
2974 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2979 case 0x08: /* IO_CNTL */
2980 diff
= s
->outputs
& (s
->dir
^ value
);
2983 value
= s
->outputs
& ~s
->dir
;
2984 while ((ln
= ffs(diff
))) {
2987 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2992 case 0x14: /* KBC_REG */
2994 omap_mpuio_kbd_update(s
);
2997 case 0x18: /* GPIO_EVENT_MODE_REG */
2998 s
->event
= value
& 0x1f;
3001 case 0x1c: /* GPIO_INT_EDGE_REG */
3005 case 0x28: /* KBD_MASKIT */
3006 s
->kbd_mask
= value
& 1;
3007 omap_mpuio_kbd_update(s
);
3010 case 0x2c: /* GPIO_MASKIT */
3014 case 0x30: /* GPIO_DEBOUNCING_REG */
3015 s
->debounce
= value
& 0x1ff;
3018 case 0x00: /* INPUT_LATCH */
3019 case 0x10: /* KBR_LATCH */
3020 case 0x20: /* KBD_INT */
3021 case 0x24: /* GPIO_INT */
3022 case 0x34: /* GPIO_LATCH_REG */
3032 static CPUReadMemoryFunc
*omap_mpuio_readfn
[] = {
3033 omap_badwidth_read16
,
3035 omap_badwidth_read16
,
3038 static CPUWriteMemoryFunc
*omap_mpuio_writefn
[] = {
3039 omap_badwidth_write16
,
3041 omap_badwidth_write16
,
3044 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
3056 s
->row_latch
= 0x1f;
3060 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
3062 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
3066 omap_mpuio_kbd_update(s
);
3069 struct omap_mpuio_s
*omap_mpuio_init(target_phys_addr_t base
,
3070 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
3074 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*)
3075 qemu_mallocz(sizeof(struct omap_mpuio_s
));
3079 s
->kbd_irq
= kbd_int
;
3081 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
3082 omap_mpuio_reset(s
);
3084 iomemtype
= cpu_register_io_memory(0, omap_mpuio_readfn
,
3085 omap_mpuio_writefn
, s
);
3086 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
3088 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_mpuio_onoff
, s
, 1)[0]);
3093 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
3098 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
3100 if (line
>= 16 || line
< 0)
3101 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
3102 s
->handler
[line
] = handler
;
3105 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
3107 if (row
>= 5 || row
< 0)
3108 cpu_abort(cpu_single_env
, "%s: No key %i-%i\n",
3109 __FUNCTION__
, col
, row
);
3112 s
->buttons
[row
] |= 1 << col
;
3114 s
->buttons
[row
] &= ~(1 << col
);
3116 omap_mpuio_kbd_update(s
);
3119 /* General-Purpose I/O */
3120 struct omap_gpio_s
{
3121 target_phys_addr_t base
;
3124 qemu_irq handler
[16];
3135 static void omap_gpio_set(void *opaque
, int line
, int level
)
3137 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
3138 uint16_t prev
= s
->inputs
;
3141 s
->inputs
|= 1 << line
;
3143 s
->inputs
&= ~(1 << line
);
3145 if (((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) &
3146 (1 << line
) & s
->dir
& ~s
->mask
) {
3147 s
->ints
|= 1 << line
;
3148 qemu_irq_raise(s
->irq
);
3152 static uint32_t omap_gpio_read(void *opaque
, target_phys_addr_t addr
)
3154 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
3155 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3158 case 0x00: /* DATA_INPUT */
3159 return s
->inputs
& s
->pins
;
3161 case 0x04: /* DATA_OUTPUT */
3164 case 0x08: /* DIRECTION_CONTROL */
3167 case 0x0c: /* INTERRUPT_CONTROL */
3170 case 0x10: /* INTERRUPT_MASK */
3173 case 0x14: /* INTERRUPT_STATUS */
3176 case 0x18: /* PIN_CONTROL (not in OMAP310) */
3185 static void omap_gpio_write(void *opaque
, target_phys_addr_t addr
,
3188 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
3189 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3194 case 0x00: /* DATA_INPUT */
3198 case 0x04: /* DATA_OUTPUT */
3199 diff
= (s
->outputs
^ value
) & ~s
->dir
;
3201 while ((ln
= ffs(diff
))) {
3204 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
3209 case 0x08: /* DIRECTION_CONTROL */
3210 diff
= s
->outputs
& (s
->dir
^ value
);
3213 value
= s
->outputs
& ~s
->dir
;
3214 while ((ln
= ffs(diff
))) {
3217 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
3222 case 0x0c: /* INTERRUPT_CONTROL */
3226 case 0x10: /* INTERRUPT_MASK */
3230 case 0x14: /* INTERRUPT_STATUS */
3233 qemu_irq_lower(s
->irq
);
3236 case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */
3247 /* *Some* sources say the memory region is 32-bit. */
3248 static CPUReadMemoryFunc
*omap_gpio_readfn
[] = {
3249 omap_badwidth_read16
,
3251 omap_badwidth_read16
,
3254 static CPUWriteMemoryFunc
*omap_gpio_writefn
[] = {
3255 omap_badwidth_write16
,
3257 omap_badwidth_write16
,
3260 static void omap_gpio_reset(struct omap_gpio_s
*s
)
3271 struct omap_gpio_s
*omap_gpio_init(target_phys_addr_t base
,
3272 qemu_irq irq
, omap_clk clk
)
3275 struct omap_gpio_s
*s
= (struct omap_gpio_s
*)
3276 qemu_mallocz(sizeof(struct omap_gpio_s
));
3280 s
->in
= qemu_allocate_irqs(omap_gpio_set
, s
, 16);
3283 iomemtype
= cpu_register_io_memory(0, omap_gpio_readfn
,
3284 omap_gpio_writefn
, s
);
3285 cpu_register_physical_memory(s
->base
, 0x1000, iomemtype
);
3290 qemu_irq
*omap_gpio_in_get(struct omap_gpio_s
*s
)
3295 void omap_gpio_out_set(struct omap_gpio_s
*s
, int line
, qemu_irq handler
)
3297 if (line
>= 16 || line
< 0)
3298 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
3299 s
->handler
[line
] = handler
;
3302 /* MicroWire Interface */
3303 struct omap_uwire_s
{
3304 target_phys_addr_t base
;
3314 struct uwire_slave_s
*chip
[4];
3317 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
3319 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
3320 struct uwire_slave_s
*slave
= s
->chip
[chipselect
];
3322 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
3323 if (s
->control
& (1 << 12)) /* CS_CMD */
3324 if (slave
&& slave
->send
)
3325 slave
->send(slave
->opaque
,
3326 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
3327 s
->control
&= ~(1 << 14); /* CSRB */
3328 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3329 * a DRQ. When is the level IRQ supposed to be reset? */
3332 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
3333 if (s
->control
& (1 << 12)) /* CS_CMD */
3334 if (slave
&& slave
->receive
)
3335 s
->rxbuf
= slave
->receive(slave
->opaque
);
3336 s
->control
|= 1 << 15; /* RDRB */
3337 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3338 * a DRQ. When is the level IRQ supposed to be reset? */
3342 static uint32_t omap_uwire_read(void *opaque
, target_phys_addr_t addr
)
3344 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3345 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3348 case 0x00: /* RDR */
3349 s
->control
&= ~(1 << 15); /* RDRB */
3352 case 0x04: /* CSR */
3355 case 0x08: /* SR1 */
3357 case 0x0c: /* SR2 */
3359 case 0x10: /* SR3 */
3361 case 0x14: /* SR4 */
3363 case 0x18: /* SR5 */
3371 static void omap_uwire_write(void *opaque
, target_phys_addr_t addr
,
3374 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3375 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3378 case 0x00: /* TDR */
3379 s
->txbuf
= value
; /* TD */
3380 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
3381 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
3382 (s
->control
& (1 << 12)))) { /* CS_CMD */
3383 s
->control
|= 1 << 14; /* CSRB */
3384 omap_uwire_transfer_start(s
);
3388 case 0x04: /* CSR */
3389 s
->control
= value
& 0x1fff;
3390 if (value
& (1 << 13)) /* START */
3391 omap_uwire_transfer_start(s
);
3394 case 0x08: /* SR1 */
3395 s
->setup
[0] = value
& 0x003f;
3398 case 0x0c: /* SR2 */
3399 s
->setup
[1] = value
& 0x0fc0;
3402 case 0x10: /* SR3 */
3403 s
->setup
[2] = value
& 0x0003;
3406 case 0x14: /* SR4 */
3407 s
->setup
[3] = value
& 0x0001;
3410 case 0x18: /* SR5 */
3411 s
->setup
[4] = value
& 0x000f;
3420 static CPUReadMemoryFunc
*omap_uwire_readfn
[] = {
3421 omap_badwidth_read16
,
3423 omap_badwidth_read16
,
3426 static CPUWriteMemoryFunc
*omap_uwire_writefn
[] = {
3427 omap_badwidth_write16
,
3429 omap_badwidth_write16
,
3432 static void omap_uwire_reset(struct omap_uwire_s
*s
)
3442 struct omap_uwire_s
*omap_uwire_init(target_phys_addr_t base
,
3443 qemu_irq
*irq
, qemu_irq dma
, omap_clk clk
)
3446 struct omap_uwire_s
*s
= (struct omap_uwire_s
*)
3447 qemu_mallocz(sizeof(struct omap_uwire_s
));
3453 omap_uwire_reset(s
);
3455 iomemtype
= cpu_register_io_memory(0, omap_uwire_readfn
,
3456 omap_uwire_writefn
, s
);
3457 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
3462 void omap_uwire_attach(struct omap_uwire_s
*s
,
3463 struct uwire_slave_s
*slave
, int chipselect
)
3465 if (chipselect
< 0 || chipselect
> 3)
3466 cpu_abort(cpu_single_env
, "%s: Bad chipselect %i\n", __FUNCTION__
,
3469 s
->chip
[chipselect
] = slave
;
3472 /* Pseudonoise Pulse-Width Light Modulator */
3473 static void omap_pwl_update(struct omap_mpu_state_s
*s
)
3475 int output
= (s
->pwl
.clk
&& s
->pwl
.enable
) ? s
->pwl
.level
: 0;
3477 if (output
!= s
->pwl
.output
) {
3478 s
->pwl
.output
= output
;
3479 printf("%s: Backlight now at %i/256\n", __FUNCTION__
, output
);
3483 static uint32_t omap_pwl_read(void *opaque
, target_phys_addr_t addr
)
3485 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3486 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3489 case 0x00: /* PWL_LEVEL */
3490 return s
->pwl
.level
;
3491 case 0x04: /* PWL_CTRL */
3492 return s
->pwl
.enable
;
3498 static void omap_pwl_write(void *opaque
, target_phys_addr_t addr
,
3501 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3502 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3505 case 0x00: /* PWL_LEVEL */
3506 s
->pwl
.level
= value
;
3509 case 0x04: /* PWL_CTRL */
3510 s
->pwl
.enable
= value
& 1;
3519 static CPUReadMemoryFunc
*omap_pwl_readfn
[] = {
3521 omap_badwidth_read8
,
3522 omap_badwidth_read8
,
3525 static CPUWriteMemoryFunc
*omap_pwl_writefn
[] = {
3527 omap_badwidth_write8
,
3528 omap_badwidth_write8
,
3531 static void omap_pwl_reset(struct omap_mpu_state_s
*s
)
3540 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
3542 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3548 static void omap_pwl_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3555 iomemtype
= cpu_register_io_memory(0, omap_pwl_readfn
,
3556 omap_pwl_writefn
, s
);
3557 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3559 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_pwl_clk_update
, s
, 1)[0]);
3562 /* Pulse-Width Tone module */
3563 static uint32_t omap_pwt_read(void *opaque
, target_phys_addr_t addr
)
3565 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3566 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3569 case 0x00: /* FRC */
3571 case 0x04: /* VCR */
3573 case 0x08: /* GCR */
3580 static void omap_pwt_write(void *opaque
, target_phys_addr_t addr
,
3583 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3584 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3587 case 0x00: /* FRC */
3588 s
->pwt
.frc
= value
& 0x3f;
3590 case 0x04: /* VRC */
3591 if ((value
^ s
->pwt
.vrc
) & 1) {
3593 printf("%s: %iHz buzz on\n", __FUNCTION__
, (int)
3594 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
3595 ((omap_clk_getrate(s
->pwt
.clk
) >> 3) /
3596 /* Pre-multiplexer divider */
3597 ((s
->pwt
.gcr
& 2) ? 1 : 154) /
3598 /* Octave multiplexer */
3599 (2 << (value
& 3)) *
3600 /* 101/107 divider */
3601 ((value
& (1 << 2)) ? 101 : 107) *
3603 ((value
& (1 << 3)) ? 49 : 55) *
3605 ((value
& (1 << 4)) ? 50 : 63) *
3606 /* 80/127 divider */
3607 ((value
& (1 << 5)) ? 80 : 127) /
3608 (107 * 55 * 63 * 127)));
3610 printf("%s: silence!\n", __FUNCTION__
);
3612 s
->pwt
.vrc
= value
& 0x7f;
3614 case 0x08: /* GCR */
3615 s
->pwt
.gcr
= value
& 3;
3623 static CPUReadMemoryFunc
*omap_pwt_readfn
[] = {
3625 omap_badwidth_read8
,
3626 omap_badwidth_read8
,
3629 static CPUWriteMemoryFunc
*omap_pwt_writefn
[] = {
3631 omap_badwidth_write8
,
3632 omap_badwidth_write8
,
3635 static void omap_pwt_reset(struct omap_mpu_state_s
*s
)
3642 static void omap_pwt_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3650 iomemtype
= cpu_register_io_memory(0, omap_pwt_readfn
,
3651 omap_pwt_writefn
, s
);
3652 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3655 /* Real-time Clock module */
3657 target_phys_addr_t base
;
3669 struct tm
*(*convert
)(const time_t *timep
, struct tm
*result
);
3673 struct tm current_tm
;
3678 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
3680 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
3683 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
3685 s
->alarm_ti
= mktime(&s
->alarm_tm
);
3686 if (s
->alarm_ti
== -1)
3687 printf("%s: conversion failed\n", __FUNCTION__
);
3690 static inline uint8_t omap_rtc_bcd(int num
)
3692 return ((num
/ 10) << 4) | (num
% 10);
3695 static inline int omap_rtc_bin(uint8_t num
)
3697 return (num
& 15) + 10 * (num
>> 4);
3700 static uint32_t omap_rtc_read(void *opaque
, target_phys_addr_t addr
)
3702 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3703 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3707 case 0x00: /* SECONDS_REG */
3708 return omap_rtc_bcd(s
->current_tm
.tm_sec
);
3710 case 0x04: /* MINUTES_REG */
3711 return omap_rtc_bcd(s
->current_tm
.tm_min
);
3713 case 0x08: /* HOURS_REG */
3715 return ((s
->current_tm
.tm_hour
> 11) << 7) |
3716 omap_rtc_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
3718 return omap_rtc_bcd(s
->current_tm
.tm_hour
);
3720 case 0x0c: /* DAYS_REG */
3721 return omap_rtc_bcd(s
->current_tm
.tm_mday
);
3723 case 0x10: /* MONTHS_REG */
3724 return omap_rtc_bcd(s
->current_tm
.tm_mon
+ 1);
3726 case 0x14: /* YEARS_REG */
3727 return omap_rtc_bcd(s
->current_tm
.tm_year
% 100);
3729 case 0x18: /* WEEK_REG */
3730 return s
->current_tm
.tm_wday
;
3732 case 0x20: /* ALARM_SECONDS_REG */
3733 return omap_rtc_bcd(s
->alarm_tm
.tm_sec
);
3735 case 0x24: /* ALARM_MINUTES_REG */
3736 return omap_rtc_bcd(s
->alarm_tm
.tm_min
);
3738 case 0x28: /* ALARM_HOURS_REG */
3740 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
3741 omap_rtc_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
3743 return omap_rtc_bcd(s
->alarm_tm
.tm_hour
);
3745 case 0x2c: /* ALARM_DAYS_REG */
3746 return omap_rtc_bcd(s
->alarm_tm
.tm_mday
);
3748 case 0x30: /* ALARM_MONTHS_REG */
3749 return omap_rtc_bcd(s
->alarm_tm
.tm_mon
+ 1);
3751 case 0x34: /* ALARM_YEARS_REG */
3752 return omap_rtc_bcd(s
->alarm_tm
.tm_year
% 100);
3754 case 0x40: /* RTC_CTRL_REG */
3755 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
3756 (s
->round
<< 1) | s
->running
;
3758 case 0x44: /* RTC_STATUS_REG */
3763 case 0x48: /* RTC_INTERRUPTS_REG */
3764 return s
->interrupts
;
3766 case 0x4c: /* RTC_COMP_LSB_REG */
3767 return ((uint16_t) s
->comp_reg
) & 0xff;
3769 case 0x50: /* RTC_COMP_MSB_REG */
3770 return ((uint16_t) s
->comp_reg
) >> 8;
3777 static void omap_rtc_write(void *opaque
, target_phys_addr_t addr
,
3780 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3781 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3786 case 0x00: /* SECONDS_REG */
3788 printf("RTC SEC_REG <-- %02x\n", value
);
3790 s
->ti
-= s
->current_tm
.tm_sec
;
3791 s
->ti
+= omap_rtc_bin(value
);
3794 case 0x04: /* MINUTES_REG */
3796 printf("RTC MIN_REG <-- %02x\n", value
);
3798 s
->ti
-= s
->current_tm
.tm_min
* 60;
3799 s
->ti
+= omap_rtc_bin(value
) * 60;
3802 case 0x08: /* HOURS_REG */
3804 printf("RTC HRS_REG <-- %02x\n", value
);
3806 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
3808 s
->ti
+= (omap_rtc_bin(value
& 0x3f) & 12) * 3600;
3809 s
->ti
+= ((value
>> 7) & 1) * 43200;
3811 s
->ti
+= omap_rtc_bin(value
& 0x3f) * 3600;
3814 case 0x0c: /* DAYS_REG */
3816 printf("RTC DAY_REG <-- %02x\n", value
);
3818 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
3819 s
->ti
+= omap_rtc_bin(value
) * 86400;
3822 case 0x10: /* MONTHS_REG */
3824 printf("RTC MTH_REG <-- %02x\n", value
);
3826 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3827 new_tm
.tm_mon
= omap_rtc_bin(value
);
3828 ti
[0] = mktime(&s
->current_tm
);
3829 ti
[1] = mktime(&new_tm
);
3831 if (ti
[0] != -1 && ti
[1] != -1) {
3835 /* A less accurate version */
3836 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
3837 s
->ti
+= omap_rtc_bin(value
) * 2592000;
3841 case 0x14: /* YEARS_REG */
3843 printf("RTC YRS_REG <-- %02x\n", value
);
3845 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3846 new_tm
.tm_year
+= omap_rtc_bin(value
) - (new_tm
.tm_year
% 100);
3847 ti
[0] = mktime(&s
->current_tm
);
3848 ti
[1] = mktime(&new_tm
);
3850 if (ti
[0] != -1 && ti
[1] != -1) {
3854 /* A less accurate version */
3855 s
->ti
-= (s
->current_tm
.tm_year
% 100) * 31536000;
3856 s
->ti
+= omap_rtc_bin(value
) * 31536000;
3860 case 0x18: /* WEEK_REG */
3861 return; /* Ignored */
3863 case 0x20: /* ALARM_SECONDS_REG */
3865 printf("ALM SEC_REG <-- %02x\n", value
);
3867 s
->alarm_tm
.tm_sec
= omap_rtc_bin(value
);
3868 omap_rtc_alarm_update(s
);
3871 case 0x24: /* ALARM_MINUTES_REG */
3873 printf("ALM MIN_REG <-- %02x\n", value
);
3875 s
->alarm_tm
.tm_min
= omap_rtc_bin(value
);
3876 omap_rtc_alarm_update(s
);
3879 case 0x28: /* ALARM_HOURS_REG */
3881 printf("ALM HRS_REG <-- %02x\n", value
);
3884 s
->alarm_tm
.tm_hour
=
3885 ((omap_rtc_bin(value
& 0x3f)) % 12) +
3886 ((value
>> 7) & 1) * 12;
3888 s
->alarm_tm
.tm_hour
= omap_rtc_bin(value
);
3889 omap_rtc_alarm_update(s
);
3892 case 0x2c: /* ALARM_DAYS_REG */
3894 printf("ALM DAY_REG <-- %02x\n", value
);
3896 s
->alarm_tm
.tm_mday
= omap_rtc_bin(value
);
3897 omap_rtc_alarm_update(s
);
3900 case 0x30: /* ALARM_MONTHS_REG */
3902 printf("ALM MON_REG <-- %02x\n", value
);
3904 s
->alarm_tm
.tm_mon
= omap_rtc_bin(value
);
3905 omap_rtc_alarm_update(s
);
3908 case 0x34: /* ALARM_YEARS_REG */
3910 printf("ALM YRS_REG <-- %02x\n", value
);
3912 s
->alarm_tm
.tm_year
= omap_rtc_bin(value
);
3913 omap_rtc_alarm_update(s
);
3916 case 0x40: /* RTC_CTRL_REG */
3918 printf("RTC CONTROL <-- %02x\n", value
);
3920 s
->pm_am
= (value
>> 3) & 1;
3921 s
->auto_comp
= (value
>> 2) & 1;
3922 s
->round
= (value
>> 1) & 1;
3923 s
->running
= value
& 1;
3925 s
->status
|= s
->running
<< 1;
3928 case 0x44: /* RTC_STATUS_REG */
3930 printf("RTC STATUSL <-- %02x\n", value
);
3932 s
->status
&= ~((value
& 0xc0) ^ 0x80);
3933 omap_rtc_interrupts_update(s
);
3936 case 0x48: /* RTC_INTERRUPTS_REG */
3938 printf("RTC INTRS <-- %02x\n", value
);
3940 s
->interrupts
= value
;
3943 case 0x4c: /* RTC_COMP_LSB_REG */
3945 printf("RTC COMPLSB <-- %02x\n", value
);
3947 s
->comp_reg
&= 0xff00;
3948 s
->comp_reg
|= 0x00ff & value
;
3951 case 0x50: /* RTC_COMP_MSB_REG */
3953 printf("RTC COMPMSB <-- %02x\n", value
);
3955 s
->comp_reg
&= 0x00ff;
3956 s
->comp_reg
|= 0xff00 & (value
<< 8);
3965 static CPUReadMemoryFunc
*omap_rtc_readfn
[] = {
3967 omap_badwidth_read8
,
3968 omap_badwidth_read8
,
3971 static CPUWriteMemoryFunc
*omap_rtc_writefn
[] = {
3973 omap_badwidth_write8
,
3974 omap_badwidth_write8
,
3977 static void omap_rtc_tick(void *opaque
)
3979 struct omap_rtc_s
*s
= opaque
;
3982 /* Round to nearest full minute. */
3983 if (s
->current_tm
.tm_sec
< 30)
3984 s
->ti
-= s
->current_tm
.tm_sec
;
3986 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
3991 localtime_r(&s
->ti
, &s
->current_tm
);
3993 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
3995 omap_rtc_interrupts_update(s
);
3998 if (s
->interrupts
& 0x04)
3999 switch (s
->interrupts
& 3) {
4002 qemu_irq_raise(s
->irq
);
4005 if (s
->current_tm
.tm_sec
)
4008 qemu_irq_raise(s
->irq
);
4011 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
4014 qemu_irq_raise(s
->irq
);
4017 if (s
->current_tm
.tm_sec
||
4018 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
4021 qemu_irq_raise(s
->irq
);
4031 * Every full hour add a rough approximation of the compensation
4032 * register to the 32kHz Timer (which drives the RTC) value.
4034 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
4035 s
->tick
+= s
->comp_reg
* 1000 / 32768;
4037 qemu_mod_timer(s
->clk
, s
->tick
);
4040 static void omap_rtc_reset(struct omap_rtc_s
*s
)
4048 s
->tick
= qemu_get_clock(rt_clock
);
4049 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
4050 s
->alarm_tm
.tm_mday
= 0x01;
4053 s
->ti
= mktime(s
->convert(&s
->ti
, &s
->current_tm
));
4055 omap_rtc_alarm_update(s
);
4059 struct omap_rtc_s
*omap_rtc_init(target_phys_addr_t base
,
4060 qemu_irq
*irq
, omap_clk clk
)
4063 struct omap_rtc_s
*s
= (struct omap_rtc_s
*)
4064 qemu_mallocz(sizeof(struct omap_rtc_s
));
4069 s
->clk
= qemu_new_timer(rt_clock
, omap_rtc_tick
, s
);
4070 s
->convert
= rtc_utc
? gmtime_r
: localtime_r
;
4074 iomemtype
= cpu_register_io_memory(0, omap_rtc_readfn
,
4075 omap_rtc_writefn
, s
);
4076 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
4081 /* Multi-channel Buffered Serial Port interfaces */
4082 struct omap_mcbsp_s
{
4083 target_phys_addr_t base
;
4101 struct i2s_codec_s
*codec
;
4104 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
4108 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
4110 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
4113 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
4120 qemu_set_irq(s
->rxirq
, irq
);
4122 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
4124 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
4127 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
4134 qemu_set_irq(s
->txirq
, irq
);
4137 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
4139 int prev
= s
->tx_req
;
4141 s
->tx_req
= (s
->tx_rate
||
4142 (s
->spcr
[0] & (1 << 12))) && /* CLKSTP */
4143 (s
->spcr
[1] & (1 << 6)) && /* GRST */
4144 (s
->spcr
[1] & (1 << 0)); /* XRST */
4146 if (!s
->tx_req
&& prev
) {
4147 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
4148 qemu_irq_lower(s
->txdrq
);
4149 omap_mcbsp_intr_update(s
);
4152 s
->codec
->tx_swallow(s
->codec
->opaque
);
4153 } else if (s
->codec
&& s
->tx_req
&& !prev
) {
4154 s
->spcr
[1] |= 1 << 1; /* XRDY */
4155 qemu_irq_raise(s
->txdrq
);
4156 omap_mcbsp_intr_update(s
);
4160 static void omap_mcbsp_rate_update(struct omap_mcbsp_s
*s
)
4162 int rx_clk
= 0, tx_clk
= 0;
4163 int cpu_rate
= 1500000; /* XXX */
4167 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
4168 if (s
->spcr
[0] & (1 << 0)) /* RRST */
4169 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
4170 (s
->pcr
& (1 << 8))) /* CLKRM */
4171 if (~s
->pcr
& (1 << 7)) /* SCLKME */
4173 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
4174 if (s
->spcr
[1] & (1 << 0)) /* XRST */
4175 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
4176 (s
->pcr
& (1 << 9))) /* CLKXM */
4177 if (~s
->pcr
& (1 << 7)) /* SCLKME */
4179 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
4182 s
->codec
->set_rate(s
->codec
->opaque
, rx_clk
, tx_clk
);
4185 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
4187 if (!(s
->spcr
[0] & 1)) { /* RRST */
4189 s
->codec
->in
.len
= 0;
4193 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
4194 s
->spcr
[0] |= 1 << 2; /* RFULL */
4195 s
->spcr
[0] |= 1 << 1; /* RRDY */
4196 qemu_irq_raise(s
->rxdrq
);
4197 omap_mcbsp_intr_update(s
);
4200 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
4202 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
4203 qemu_irq_lower(s
->rxdrq
);
4204 omap_mcbsp_intr_update(s
);
4207 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
4212 omap_mcbsp_req_update(s
);
4215 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
4218 omap_mcbsp_req_update(s
);
4221 static uint32_t omap_mcbsp_read(void *opaque
, target_phys_addr_t addr
)
4223 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4224 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4228 case 0x00: /* DRR2 */
4229 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
4232 case 0x02: /* DRR1 */
4235 if (s
->codec
->in
.len
< 2) {
4236 printf("%s: Rx FIFO underrun\n", __FUNCTION__
);
4237 omap_mcbsp_rx_stop(s
);
4239 s
->codec
->in
.len
-= 2;
4240 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
4241 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
4242 if (!s
->codec
->in
.len
)
4243 omap_mcbsp_rx_stop(s
);
4248 case 0x04: /* DXR2 */
4249 case 0x06: /* DXR1 */
4252 case 0x08: /* SPCR2 */
4254 case 0x0a: /* SPCR1 */
4256 case 0x0c: /* RCR2 */
4258 case 0x0e: /* RCR1 */
4260 case 0x10: /* XCR2 */
4262 case 0x12: /* XCR1 */
4264 case 0x14: /* SRGR2 */
4266 case 0x16: /* SRGR1 */
4268 case 0x18: /* MCR2 */
4270 case 0x1a: /* MCR1 */
4272 case 0x1c: /* RCERA */
4274 case 0x1e: /* RCERB */
4276 case 0x20: /* XCERA */
4278 case 0x22: /* XCERB */
4280 case 0x24: /* PCR0 */
4282 case 0x26: /* RCERC */
4284 case 0x28: /* RCERD */
4286 case 0x2a: /* XCERC */
4288 case 0x2c: /* XCERD */
4290 case 0x2e: /* RCERE */
4292 case 0x30: /* RCERF */
4294 case 0x32: /* XCERE */
4296 case 0x34: /* XCERF */
4298 case 0x36: /* RCERG */
4300 case 0x38: /* RCERH */
4302 case 0x3a: /* XCERG */
4304 case 0x3c: /* XCERH */
4312 static void omap_mcbsp_write(void *opaque
, target_phys_addr_t addr
,
4315 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4316 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4319 case 0x00: /* DRR2 */
4320 case 0x02: /* DRR1 */
4324 case 0x04: /* DXR2 */
4325 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
4328 case 0x06: /* DXR1 */
4332 if (s
->codec
->out
.len
> s
->codec
->out
.size
- 2) {
4333 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4334 omap_mcbsp_tx_stop(s
);
4336 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
4337 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
4338 if (s
->codec
->out
.len
>= s
->codec
->out
.size
)
4339 omap_mcbsp_tx_stop(s
);
4342 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4345 case 0x08: /* SPCR2 */
4346 s
->spcr
[1] &= 0x0002;
4347 s
->spcr
[1] |= 0x03f9 & value
;
4348 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
4349 if (~value
& 1) { /* XRST */
4351 qemu_irq_lower(s
->rxdrq
);
4353 s
->codec
->out
.len
= 0;
4356 omap_mcbsp_rate_update(s
);
4357 omap_mcbsp_req_update(s
);
4359 case 0x0a: /* SPCR1 */
4360 s
->spcr
[0] &= 0x0006;
4361 s
->spcr
[0] |= 0xf8f9 & value
;
4362 if (value
& (1 << 15)) /* DLB */
4363 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__
);
4364 if (~value
& 1) { /* RRST */
4366 qemu_irq_lower(s
->txdrq
);
4368 s
->codec
->in
.len
= 0;
4371 omap_mcbsp_rate_update(s
);
4372 omap_mcbsp_req_update(s
);
4375 case 0x0c: /* RCR2 */
4376 s
->rcr
[1] = value
& 0xffff;
4378 case 0x0e: /* RCR1 */
4379 s
->rcr
[0] = value
& 0x7fe0;
4381 case 0x10: /* XCR2 */
4382 s
->xcr
[1] = value
& 0xffff;
4384 case 0x12: /* XCR1 */
4385 s
->xcr
[0] = value
& 0x7fe0;
4387 case 0x14: /* SRGR2 */
4388 s
->srgr
[1] = value
& 0xffff;
4389 omap_mcbsp_rate_update(s
);
4391 case 0x16: /* SRGR1 */
4392 s
->srgr
[0] = value
& 0xffff;
4393 omap_mcbsp_rate_update(s
);
4395 case 0x18: /* MCR2 */
4396 s
->mcr
[1] = value
& 0x03e3;
4397 if (value
& 3) /* XMCM */
4398 printf("%s: Tx channel selection mode enable attempt\n",
4401 case 0x1a: /* MCR1 */
4402 s
->mcr
[0] = value
& 0x03e1;
4403 if (value
& 1) /* RMCM */
4404 printf("%s: Rx channel selection mode enable attempt\n",
4407 case 0x1c: /* RCERA */
4408 s
->rcer
[0] = value
& 0xffff;
4410 case 0x1e: /* RCERB */
4411 s
->rcer
[1] = value
& 0xffff;
4413 case 0x20: /* XCERA */
4414 s
->xcer
[0] = value
& 0xffff;
4416 case 0x22: /* XCERB */
4417 s
->xcer
[1] = value
& 0xffff;
4419 case 0x24: /* PCR0 */
4420 s
->pcr
= value
& 0x7faf;
4422 case 0x26: /* RCERC */
4423 s
->rcer
[2] = value
& 0xffff;
4425 case 0x28: /* RCERD */
4426 s
->rcer
[3] = value
& 0xffff;
4428 case 0x2a: /* XCERC */
4429 s
->xcer
[2] = value
& 0xffff;
4431 case 0x2c: /* XCERD */
4432 s
->xcer
[3] = value
& 0xffff;
4434 case 0x2e: /* RCERE */
4435 s
->rcer
[4] = value
& 0xffff;
4437 case 0x30: /* RCERF */
4438 s
->rcer
[5] = value
& 0xffff;
4440 case 0x32: /* XCERE */
4441 s
->xcer
[4] = value
& 0xffff;
4443 case 0x34: /* XCERF */
4444 s
->xcer
[5] = value
& 0xffff;
4446 case 0x36: /* RCERG */
4447 s
->rcer
[6] = value
& 0xffff;
4449 case 0x38: /* RCERH */
4450 s
->rcer
[7] = value
& 0xffff;
4452 case 0x3a: /* XCERG */
4453 s
->xcer
[6] = value
& 0xffff;
4455 case 0x3c: /* XCERH */
4456 s
->xcer
[7] = value
& 0xffff;
4463 static CPUReadMemoryFunc
*omap_mcbsp_readfn
[] = {
4464 omap_badwidth_read16
,
4466 omap_badwidth_read16
,
4469 static CPUWriteMemoryFunc
*omap_mcbsp_writefn
[] = {
4470 omap_badwidth_write16
,
4472 omap_badwidth_write16
,
4475 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
4477 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
4478 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
4479 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
4480 s
->srgr
[0] = 0x0001;
4481 s
->srgr
[1] = 0x2000;
4482 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
4483 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
4484 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
4485 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
4491 struct omap_mcbsp_s
*omap_mcbsp_init(target_phys_addr_t base
,
4492 qemu_irq
*irq
, qemu_irq
*dma
, omap_clk clk
)
4495 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*)
4496 qemu_mallocz(sizeof(struct omap_mcbsp_s
));
4503 omap_mcbsp_reset(s
);
4505 iomemtype
= cpu_register_io_memory(0, omap_mcbsp_readfn
,
4506 omap_mcbsp_writefn
, s
);
4507 cpu_register_physical_memory(s
->base
, 0x800, iomemtype
);
4512 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
4514 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4516 omap_mcbsp_rx_start(s
);
4519 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
4521 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4523 omap_mcbsp_tx_start(s
);
4526 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, struct i2s_codec_s
*slave
)
4529 slave
->rx_swallow
= qemu_allocate_irqs(omap_mcbsp_i2s_swallow
, s
, 1)[0];
4530 slave
->tx_start
= qemu_allocate_irqs(omap_mcbsp_i2s_start
, s
, 1)[0];
4533 /* General chip reset */
4534 static void omap_mpu_reset(void *opaque
)
4536 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4538 omap_clkm_reset(mpu
);
4539 omap_inth_reset(mpu
->ih
[0]);
4540 omap_inth_reset(mpu
->ih
[1]);
4541 omap_dma_reset(mpu
->dma
);
4542 omap_mpu_timer_reset(mpu
->timer
[0]);
4543 omap_mpu_timer_reset(mpu
->timer
[1]);
4544 omap_mpu_timer_reset(mpu
->timer
[2]);
4545 omap_wd_timer_reset(mpu
->wdt
);
4546 omap_os_timer_reset(mpu
->os_timer
);
4547 omap_lcdc_reset(mpu
->lcd
);
4548 omap_ulpd_pm_reset(mpu
);
4549 omap_pin_cfg_reset(mpu
);
4550 omap_mpui_reset(mpu
);
4551 omap_tipb_bridge_reset(mpu
->private_tipb
);
4552 omap_tipb_bridge_reset(mpu
->public_tipb
);
4553 omap_dpll_reset(&mpu
->dpll
[0]);
4554 omap_dpll_reset(&mpu
->dpll
[1]);
4555 omap_dpll_reset(&mpu
->dpll
[2]);
4556 omap_uart_reset(mpu
->uart
[0]);
4557 omap_uart_reset(mpu
->uart
[1]);
4558 omap_uart_reset(mpu
->uart
[2]);
4559 omap_mmc_reset(mpu
->mmc
);
4560 omap_mpuio_reset(mpu
->mpuio
);
4561 omap_gpio_reset(mpu
->gpio
);
4562 omap_uwire_reset(mpu
->microwire
);
4563 omap_pwl_reset(mpu
);
4564 omap_pwt_reset(mpu
);
4565 omap_i2c_reset(mpu
->i2c
);
4566 omap_rtc_reset(mpu
->rtc
);
4567 omap_mcbsp_reset(mpu
->mcbsp1
);
4568 omap_mcbsp_reset(mpu
->mcbsp2
);
4569 omap_mcbsp_reset(mpu
->mcbsp3
);
4570 cpu_reset(mpu
->env
);
4573 static const struct omap_map_s
{
4574 target_phys_addr_t phys_dsp
;
4575 target_phys_addr_t phys_mpu
;
4578 } omap15xx_dsp_mm
[] = {
4580 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
4581 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
4582 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
4583 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
4584 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
4585 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
4586 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
4587 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
4588 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
4589 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
4590 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
4591 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
4592 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
4593 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
4594 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
4595 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
4596 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
4598 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
4603 static void omap_setup_dsp_mapping(const struct omap_map_s
*map
)
4607 for (; map
->phys_dsp
; map
++) {
4608 io
= cpu_get_physical_page_desc(map
->phys_mpu
);
4610 cpu_register_physical_memory(map
->phys_dsp
, map
->size
, io
);
4614 static void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
4616 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4618 if (mpu
->env
->halted
)
4619 cpu_interrupt(mpu
->env
, CPU_INTERRUPT_EXITTB
);
4622 struct omap_mpu_state_s
*omap310_mpu_init(unsigned long sdram_size
,
4623 DisplayState
*ds
, const char *core
)
4625 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*)
4626 qemu_mallocz(sizeof(struct omap_mpu_state_s
));
4627 ram_addr_t imif_base
, emiff_base
;
4633 s
->mpu_model
= omap310
;
4634 s
->env
= cpu_init(core
);
4636 fprintf(stderr
, "Unable to find CPU definition\n");
4639 s
->sdram_size
= sdram_size
;
4640 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
4642 s
->wakeup
= qemu_allocate_irqs(omap_mpu_wakeup
, s
, 1)[0];
4647 /* Memory-mapped stuff */
4648 cpu_register_physical_memory(OMAP_EMIFF_BASE
, s
->sdram_size
,
4649 (emiff_base
= qemu_ram_alloc(s
->sdram_size
)) | IO_MEM_RAM
);
4650 cpu_register_physical_memory(OMAP_IMIF_BASE
, s
->sram_size
,
4651 (imif_base
= qemu_ram_alloc(s
->sram_size
)) | IO_MEM_RAM
);
4653 omap_clkm_init(0xfffece00, 0xe1008000, s
);
4655 s
->ih
[0] = omap_inth_init(0xfffecb00, 0x100,
4656 arm_pic_init_cpu(s
->env
),
4657 omap_findclk(s
, "arminth_ck"));
4658 s
->ih
[1] = omap_inth_init(0xfffe0000, 0x800,
4659 &s
->ih
[0]->pins
[OMAP_INT_15XX_IH2_IRQ
],
4660 omap_findclk(s
, "arminth_ck"));
4661 s
->irq
[0] = s
->ih
[0]->pins
;
4662 s
->irq
[1] = s
->ih
[1]->pins
;
4664 s
->dma
= omap_dma_init(0xfffed800, s
->irq
[0], s
,
4665 omap_findclk(s
, "dma_ck"));
4666 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
4667 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
4668 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
4669 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
4670 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
4671 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
4673 s
->timer
[0] = omap_mpu_timer_init(0xfffec500,
4674 s
->irq
[0][OMAP_INT_TIMER1
],
4675 omap_findclk(s
, "mputim_ck"));
4676 s
->timer
[1] = omap_mpu_timer_init(0xfffec600,
4677 s
->irq
[0][OMAP_INT_TIMER2
],
4678 omap_findclk(s
, "mputim_ck"));
4679 s
->timer
[2] = omap_mpu_timer_init(0xfffec700,
4680 s
->irq
[0][OMAP_INT_TIMER3
],
4681 omap_findclk(s
, "mputim_ck"));
4683 s
->wdt
= omap_wd_timer_init(0xfffec800,
4684 s
->irq
[0][OMAP_INT_WD_TIMER
],
4685 omap_findclk(s
, "armwdt_ck"));
4687 s
->os_timer
= omap_os_timer_init(0xfffb9000,
4688 s
->irq
[1][OMAP_INT_OS_TIMER
],
4689 omap_findclk(s
, "clk32-kHz"));
4691 s
->lcd
= omap_lcdc_init(0xfffec000, s
->irq
[0][OMAP_INT_LCD_CTRL
],
4692 &s
->dma
->lcd_ch
, ds
, imif_base
, emiff_base
,
4693 omap_findclk(s
, "lcd_ck"));
4695 omap_ulpd_pm_init(0xfffe0800, s
);
4696 omap_pin_cfg_init(0xfffe1000, s
);
4699 omap_mpui_init(0xfffec900, s
);
4701 s
->private_tipb
= omap_tipb_bridge_init(0xfffeca00,
4702 s
->irq
[0][OMAP_INT_BRIDGE_PRIV
],
4703 omap_findclk(s
, "tipb_ck"));
4704 s
->public_tipb
= omap_tipb_bridge_init(0xfffed300,
4705 s
->irq
[0][OMAP_INT_BRIDGE_PUB
],
4706 omap_findclk(s
, "tipb_ck"));
4708 omap_tcmi_init(0xfffecc00, s
);
4710 s
->uart
[0] = omap_uart_init(0xfffb0000, s
->irq
[1][OMAP_INT_UART1
],
4711 omap_findclk(s
, "uart1_ck"),
4713 s
->uart
[1] = omap_uart_init(0xfffb0800, s
->irq
[1][OMAP_INT_UART2
],
4714 omap_findclk(s
, "uart2_ck"),
4715 serial_hds
[0] ? serial_hds
[1] : 0);
4716 s
->uart
[2] = omap_uart_init(0xe1019800, s
->irq
[0][OMAP_INT_UART3
],
4717 omap_findclk(s
, "uart3_ck"),
4718 serial_hds
[0] && serial_hds
[1] ? serial_hds
[2] : 0);
4720 omap_dpll_init(&s
->dpll
[0], 0xfffecf00, omap_findclk(s
, "dpll1"));
4721 omap_dpll_init(&s
->dpll
[1], 0xfffed000, omap_findclk(s
, "dpll2"));
4722 omap_dpll_init(&s
->dpll
[2], 0xfffed100, omap_findclk(s
, "dpll3"));
4724 s
->mmc
= omap_mmc_init(0xfffb7800, sd_bdrv
, s
->irq
[1][OMAP_INT_OQN
],
4725 &s
->drq
[OMAP_DMA_MMC_TX
], omap_findclk(s
, "mmc_ck"));
4727 s
->mpuio
= omap_mpuio_init(0xfffb5000,
4728 s
->irq
[1][OMAP_INT_KEYBOARD
], s
->irq
[1][OMAP_INT_MPUIO
],
4729 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
4731 s
->gpio
= omap_gpio_init(0xfffce000, s
->irq
[0][OMAP_INT_GPIO_BANK1
],
4732 omap_findclk(s
, "arm_gpio_ck"));
4734 s
->microwire
= omap_uwire_init(0xfffb3000, &s
->irq
[1][OMAP_INT_uWireTX
],
4735 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
4737 omap_pwl_init(0xfffb5800, s
, omap_findclk(s
, "armxor_ck"));
4738 omap_pwt_init(0xfffb6000, s
, omap_findclk(s
, "armxor_ck"));
4740 s
->i2c
= omap_i2c_init(0xfffb3800, s
->irq
[1][OMAP_INT_I2C
],
4741 &s
->drq
[OMAP_DMA_I2C_RX
], omap_findclk(s
, "mpuper_ck"));
4743 s
->rtc
= omap_rtc_init(0xfffb4800, &s
->irq
[1][OMAP_INT_RTC_TIMER
],
4744 omap_findclk(s
, "clk32-kHz"));
4746 s
->mcbsp1
= omap_mcbsp_init(0xfffb1800, &s
->irq
[1][OMAP_INT_McBSP1TX
],
4747 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
4748 s
->mcbsp2
= omap_mcbsp_init(0xfffb1000, &s
->irq
[0][OMAP_INT_310_McBSP2_TX
],
4749 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
4750 s
->mcbsp3
= omap_mcbsp_init(0xfffb7000, &s
->irq
[1][OMAP_INT_McBSP3TX
],
4751 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
4753 /* Register mappings not currenlty implemented:
4754 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4755 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4756 * USB W2FC fffb4000 - fffb47ff
4757 * Camera Interface fffb6800 - fffb6fff
4758 * USB Host fffba000 - fffba7ff
4759 * FAC fffba800 - fffbafff
4760 * HDQ/1-Wire fffbc000 - fffbc7ff
4761 * TIPB switches fffbc800 - fffbcfff
4762 * LED1 fffbd000 - fffbd7ff
4763 * LED2 fffbd800 - fffbdfff
4764 * Mailbox fffcf000 - fffcf7ff
4765 * Local bus IF fffec100 - fffec1ff
4766 * Local bus MMU fffec200 - fffec2ff
4767 * DSP MMU fffed200 - fffed2ff
4770 omap_setup_dsp_mapping(omap15xx_dsp_mm
);
4772 qemu_register_reset(omap_mpu_reset
, s
);