2 * TI OMAP processors emulation.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "qemu-timer.h"
25 #include "qemu-char.h"
27 /* We use pc-style serial ports. */
30 /* Should signal the TCMI/GPMC */
31 uint32_t omap_badwidth_read8(void *opaque
, target_phys_addr_t addr
)
36 cpu_physical_memory_read(addr
, (void *) &ret
, 1);
40 void omap_badwidth_write8(void *opaque
, target_phys_addr_t addr
,
46 cpu_physical_memory_write(addr
, (void *) &val8
, 1);
49 uint32_t omap_badwidth_read16(void *opaque
, target_phys_addr_t addr
)
54 cpu_physical_memory_read(addr
, (void *) &ret
, 2);
58 void omap_badwidth_write16(void *opaque
, target_phys_addr_t addr
,
61 uint16_t val16
= value
;
64 cpu_physical_memory_write(addr
, (void *) &val16
, 2);
67 uint32_t omap_badwidth_read32(void *opaque
, target_phys_addr_t addr
)
72 cpu_physical_memory_read(addr
, (void *) &ret
, 4);
76 void omap_badwidth_write32(void *opaque
, target_phys_addr_t addr
,
80 cpu_physical_memory_write(addr
, (void *) &value
, 4);
83 /* Interrupt Handlers */
84 struct omap_intr_handler_bank_s
{
91 unsigned char priority
[32];
94 struct omap_intr_handler_s
{
96 qemu_irq parent_intr
[2];
105 struct omap_intr_handler_bank_s bank
[];
108 static void omap_inth_sir_update(struct omap_intr_handler_s
*s
, int is_fiq
)
110 int i
, j
, sir_intr
, p_intr
, p
, f
;
115 /* Find the interrupt line with the highest dynamic priority.
116 * Note: 0 denotes the hightest priority.
117 * If all interrupts have the same priority, the default order is IRQ_N,
118 * IRQ_N-1,...,IRQ_0. */
119 for (j
= 0; j
< s
->nbanks
; ++j
) {
120 level
= s
->bank
[j
].irqs
& ~s
->bank
[j
].mask
&
121 (is_fiq
? s
->bank
[j
].fiq
: ~s
->bank
[j
].fiq
);
122 for (f
= ffs(level
), i
= f
- 1, level
>>= f
- 1; f
; i
+= f
,
124 p
= s
->bank
[j
].priority
[i
];
127 sir_intr
= 32 * j
+ i
;
132 s
->sir_intr
[is_fiq
] = sir_intr
;
135 static inline void omap_inth_update(struct omap_intr_handler_s
*s
, int is_fiq
)
138 uint32_t has_intr
= 0;
140 for (i
= 0; i
< s
->nbanks
; ++i
)
141 has_intr
|= s
->bank
[i
].irqs
& ~s
->bank
[i
].mask
&
142 (is_fiq
? s
->bank
[i
].fiq
: ~s
->bank
[i
].fiq
);
144 if (s
->new_agr
[is_fiq
] & has_intr
& s
->mask
) {
145 s
->new_agr
[is_fiq
] = 0;
146 omap_inth_sir_update(s
, is_fiq
);
147 qemu_set_irq(s
->parent_intr
[is_fiq
], 1);
151 #define INT_FALLING_EDGE 0
152 #define INT_LOW_LEVEL 1
154 static void omap_set_intr(void *opaque
, int irq
, int req
)
156 struct omap_intr_handler_s
*ih
= (struct omap_intr_handler_s
*) opaque
;
159 struct omap_intr_handler_bank_s
*bank
= &ih
->bank
[irq
>> 5];
163 rise
= ~bank
->irqs
& (1 << n
);
164 if (~bank
->sens_edge
& (1 << n
))
165 rise
&= ~bank
->inputs
;
167 bank
->inputs
|= (1 << n
);
170 omap_inth_update(ih
, 0);
171 omap_inth_update(ih
, 1);
174 rise
= bank
->sens_edge
& bank
->irqs
& (1 << n
);
176 bank
->inputs
&= ~(1 << n
);
180 /* Simplified version with no edge detection */
181 static void omap_set_intr_noedge(void *opaque
, int irq
, int req
)
183 struct omap_intr_handler_s
*ih
= (struct omap_intr_handler_s
*) opaque
;
186 struct omap_intr_handler_bank_s
*bank
= &ih
->bank
[irq
>> 5];
190 rise
= ~bank
->inputs
& (1 << n
);
192 bank
->irqs
|= bank
->inputs
|= rise
;
193 omap_inth_update(ih
, 0);
194 omap_inth_update(ih
, 1);
197 bank
->irqs
= (bank
->inputs
&= ~(1 << n
)) | bank
->swi
;
200 static uint32_t omap_inth_read(void *opaque
, target_phys_addr_t addr
)
202 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
203 int i
, offset
= addr
;
204 int bank_no
= offset
>> 8;
206 struct omap_intr_handler_bank_s
*bank
= &s
->bank
[bank_no
];
216 case 0x10: /* SIR_IRQ_CODE */
217 case 0x14: /* SIR_FIQ_CODE */
220 line_no
= s
->sir_intr
[(offset
- 0x10) >> 2];
221 bank
= &s
->bank
[line_no
>> 5];
223 if (((bank
->sens_edge
>> i
) & 1) == INT_FALLING_EDGE
)
224 bank
->irqs
&= ~(1 << i
);
227 case 0x18: /* CONTROL_REG */
232 case 0x1c: /* ILR0 */
233 case 0x20: /* ILR1 */
234 case 0x24: /* ILR2 */
235 case 0x28: /* ILR3 */
236 case 0x2c: /* ILR4 */
237 case 0x30: /* ILR5 */
238 case 0x34: /* ILR6 */
239 case 0x38: /* ILR7 */
240 case 0x3c: /* ILR8 */
241 case 0x40: /* ILR9 */
242 case 0x44: /* ILR10 */
243 case 0x48: /* ILR11 */
244 case 0x4c: /* ILR12 */
245 case 0x50: /* ILR13 */
246 case 0x54: /* ILR14 */
247 case 0x58: /* ILR15 */
248 case 0x5c: /* ILR16 */
249 case 0x60: /* ILR17 */
250 case 0x64: /* ILR18 */
251 case 0x68: /* ILR19 */
252 case 0x6c: /* ILR20 */
253 case 0x70: /* ILR21 */
254 case 0x74: /* ILR22 */
255 case 0x78: /* ILR23 */
256 case 0x7c: /* ILR24 */
257 case 0x80: /* ILR25 */
258 case 0x84: /* ILR26 */
259 case 0x88: /* ILR27 */
260 case 0x8c: /* ILR28 */
261 case 0x90: /* ILR29 */
262 case 0x94: /* ILR30 */
263 case 0x98: /* ILR31 */
264 i
= (offset
- 0x1c) >> 2;
265 return (bank
->priority
[i
] << 2) |
266 (((bank
->sens_edge
>> i
) & 1) << 1) |
267 ((bank
->fiq
>> i
) & 1);
277 static void omap_inth_write(void *opaque
, target_phys_addr_t addr
,
280 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
281 int i
, offset
= addr
;
282 int bank_no
= offset
>> 8;
283 struct omap_intr_handler_bank_s
*bank
= &s
->bank
[bank_no
];
288 /* Important: ignore the clearing if the IRQ is level-triggered and
289 the input bit is 1 */
290 bank
->irqs
&= value
| (bank
->inputs
& bank
->sens_edge
);
295 omap_inth_update(s
, 0);
296 omap_inth_update(s
, 1);
299 case 0x10: /* SIR_IRQ_CODE */
300 case 0x14: /* SIR_FIQ_CODE */
304 case 0x18: /* CONTROL_REG */
308 qemu_set_irq(s
->parent_intr
[1], 0);
310 omap_inth_update(s
, 1);
313 qemu_set_irq(s
->parent_intr
[0], 0);
315 omap_inth_update(s
, 0);
319 case 0x1c: /* ILR0 */
320 case 0x20: /* ILR1 */
321 case 0x24: /* ILR2 */
322 case 0x28: /* ILR3 */
323 case 0x2c: /* ILR4 */
324 case 0x30: /* ILR5 */
325 case 0x34: /* ILR6 */
326 case 0x38: /* ILR7 */
327 case 0x3c: /* ILR8 */
328 case 0x40: /* ILR9 */
329 case 0x44: /* ILR10 */
330 case 0x48: /* ILR11 */
331 case 0x4c: /* ILR12 */
332 case 0x50: /* ILR13 */
333 case 0x54: /* ILR14 */
334 case 0x58: /* ILR15 */
335 case 0x5c: /* ILR16 */
336 case 0x60: /* ILR17 */
337 case 0x64: /* ILR18 */
338 case 0x68: /* ILR19 */
339 case 0x6c: /* ILR20 */
340 case 0x70: /* ILR21 */
341 case 0x74: /* ILR22 */
342 case 0x78: /* ILR23 */
343 case 0x7c: /* ILR24 */
344 case 0x80: /* ILR25 */
345 case 0x84: /* ILR26 */
346 case 0x88: /* ILR27 */
347 case 0x8c: /* ILR28 */
348 case 0x90: /* ILR29 */
349 case 0x94: /* ILR30 */
350 case 0x98: /* ILR31 */
351 i
= (offset
- 0x1c) >> 2;
352 bank
->priority
[i
] = (value
>> 2) & 0x1f;
353 bank
->sens_edge
&= ~(1 << i
);
354 bank
->sens_edge
|= ((value
>> 1) & 1) << i
;
355 bank
->fiq
&= ~(1 << i
);
356 bank
->fiq
|= (value
& 1) << i
;
360 for (i
= 0; i
< 32; i
++)
361 if (value
& (1 << i
)) {
362 omap_set_intr(s
, 32 * bank_no
+ i
, 1);
370 static CPUReadMemoryFunc
*omap_inth_readfn
[] = {
371 omap_badwidth_read32
,
372 omap_badwidth_read32
,
376 static CPUWriteMemoryFunc
*omap_inth_writefn
[] = {
382 void omap_inth_reset(struct omap_intr_handler_s
*s
)
386 for (i
= 0; i
< s
->nbanks
; ++i
){
387 s
->bank
[i
].irqs
= 0x00000000;
388 s
->bank
[i
].mask
= 0xffffffff;
389 s
->bank
[i
].sens_edge
= 0x00000000;
390 s
->bank
[i
].fiq
= 0x00000000;
391 s
->bank
[i
].inputs
= 0x00000000;
392 s
->bank
[i
].swi
= 0x00000000;
393 memset(s
->bank
[i
].priority
, 0, sizeof(s
->bank
[i
].priority
));
396 s
->bank
[i
].sens_edge
= 0xffffffff;
406 qemu_set_irq(s
->parent_intr
[0], 0);
407 qemu_set_irq(s
->parent_intr
[1], 0);
410 struct omap_intr_handler_s
*omap_inth_init(target_phys_addr_t base
,
411 unsigned long size
, unsigned char nbanks
, qemu_irq
**pins
,
412 qemu_irq parent_irq
, qemu_irq parent_fiq
, omap_clk clk
)
415 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*)
416 qemu_mallocz(sizeof(struct omap_intr_handler_s
) +
417 sizeof(struct omap_intr_handler_bank_s
) * nbanks
);
419 s
->parent_intr
[0] = parent_irq
;
420 s
->parent_intr
[1] = parent_fiq
;
422 s
->pins
= qemu_allocate_irqs(omap_set_intr
, s
, nbanks
* 32);
428 iomemtype
= cpu_register_io_memory(0, omap_inth_readfn
,
429 omap_inth_writefn
, s
);
430 cpu_register_physical_memory(base
, size
, iomemtype
);
435 static uint32_t omap2_inth_read(void *opaque
, target_phys_addr_t addr
)
437 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
439 int bank_no
, line_no
;
440 struct omap_intr_handler_bank_s
*bank
= 0;
442 if ((offset
& 0xf80) == 0x80) {
443 bank_no
= (offset
& 0x60) >> 5;
444 if (bank_no
< s
->nbanks
) {
446 bank
= &s
->bank
[bank_no
];
451 case 0x00: /* INTC_REVISION */
454 case 0x10: /* INTC_SYSCONFIG */
455 return (s
->autoidle
>> 2) & 1;
457 case 0x14: /* INTC_SYSSTATUS */
458 return 1; /* RESETDONE */
460 case 0x40: /* INTC_SIR_IRQ */
461 return s
->sir_intr
[0];
463 case 0x44: /* INTC_SIR_FIQ */
464 return s
->sir_intr
[1];
466 case 0x48: /* INTC_CONTROL */
467 return (!s
->mask
) << 2; /* GLOBALMASK */
469 case 0x4c: /* INTC_PROTECTION */
472 case 0x50: /* INTC_IDLE */
473 return s
->autoidle
& 3;
475 /* Per-bank registers */
476 case 0x80: /* INTC_ITR */
479 case 0x84: /* INTC_MIR */
482 case 0x88: /* INTC_MIR_CLEAR */
483 case 0x8c: /* INTC_MIR_SET */
486 case 0x90: /* INTC_ISR_SET */
489 case 0x94: /* INTC_ISR_CLEAR */
492 case 0x98: /* INTC_PENDING_IRQ */
493 return bank
->irqs
& ~bank
->mask
& ~bank
->fiq
;
495 case 0x9c: /* INTC_PENDING_FIQ */
496 return bank
->irqs
& ~bank
->mask
& bank
->fiq
;
498 /* Per-line registers */
499 case 0x100 ... 0x300: /* INTC_ILR */
500 bank_no
= (offset
- 0x100) >> 7;
501 if (bank_no
> s
->nbanks
)
503 bank
= &s
->bank
[bank_no
];
504 line_no
= (offset
& 0x7f) >> 2;
505 return (bank
->priority
[line_no
] << 2) |
506 ((bank
->fiq
>> line_no
) & 1);
512 static void omap2_inth_write(void *opaque
, target_phys_addr_t addr
,
515 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*) opaque
;
517 int bank_no
, line_no
;
518 struct omap_intr_handler_bank_s
*bank
= 0;
520 if ((offset
& 0xf80) == 0x80) {
521 bank_no
= (offset
& 0x60) >> 5;
522 if (bank_no
< s
->nbanks
) {
524 bank
= &s
->bank
[bank_no
];
529 case 0x10: /* INTC_SYSCONFIG */
531 s
->autoidle
|= (value
& 1) << 2;
532 if (value
& 2) /* SOFTRESET */
536 case 0x48: /* INTC_CONTROL */
537 s
->mask
= (value
& 4) ? 0 : ~0; /* GLOBALMASK */
538 if (value
& 2) { /* NEWFIQAGR */
539 qemu_set_irq(s
->parent_intr
[1], 0);
541 omap_inth_update(s
, 1);
543 if (value
& 1) { /* NEWIRQAGR */
544 qemu_set_irq(s
->parent_intr
[0], 0);
546 omap_inth_update(s
, 0);
550 case 0x4c: /* INTC_PROTECTION */
551 /* TODO: Make a bitmap (or sizeof(char)map) of access privileges
552 * for every register, see Chapter 3 and 4 for privileged mode. */
554 fprintf(stderr
, "%s: protection mode enable attempt\n",
558 case 0x50: /* INTC_IDLE */
560 s
->autoidle
|= value
& 3;
563 /* Per-bank registers */
564 case 0x84: /* INTC_MIR */
566 omap_inth_update(s
, 0);
567 omap_inth_update(s
, 1);
570 case 0x88: /* INTC_MIR_CLEAR */
571 bank
->mask
&= ~value
;
572 omap_inth_update(s
, 0);
573 omap_inth_update(s
, 1);
576 case 0x8c: /* INTC_MIR_SET */
580 case 0x90: /* INTC_ISR_SET */
581 bank
->irqs
|= bank
->swi
|= value
;
582 omap_inth_update(s
, 0);
583 omap_inth_update(s
, 1);
586 case 0x94: /* INTC_ISR_CLEAR */
588 bank
->irqs
= bank
->swi
& bank
->inputs
;
591 /* Per-line registers */
592 case 0x100 ... 0x300: /* INTC_ILR */
593 bank_no
= (offset
- 0x100) >> 7;
594 if (bank_no
> s
->nbanks
)
596 bank
= &s
->bank
[bank_no
];
597 line_no
= (offset
& 0x7f) >> 2;
598 bank
->priority
[line_no
] = (value
>> 2) & 0x3f;
599 bank
->fiq
&= ~(1 << line_no
);
600 bank
->fiq
|= (value
& 1) << line_no
;
603 case 0x00: /* INTC_REVISION */
604 case 0x14: /* INTC_SYSSTATUS */
605 case 0x40: /* INTC_SIR_IRQ */
606 case 0x44: /* INTC_SIR_FIQ */
607 case 0x80: /* INTC_ITR */
608 case 0x98: /* INTC_PENDING_IRQ */
609 case 0x9c: /* INTC_PENDING_FIQ */
616 static CPUReadMemoryFunc
*omap2_inth_readfn
[] = {
617 omap_badwidth_read32
,
618 omap_badwidth_read32
,
622 static CPUWriteMemoryFunc
*omap2_inth_writefn
[] = {
628 struct omap_intr_handler_s
*omap2_inth_init(target_phys_addr_t base
,
629 int size
, int nbanks
, qemu_irq
**pins
,
630 qemu_irq parent_irq
, qemu_irq parent_fiq
,
631 omap_clk fclk
, omap_clk iclk
)
634 struct omap_intr_handler_s
*s
= (struct omap_intr_handler_s
*)
635 qemu_mallocz(sizeof(struct omap_intr_handler_s
) +
636 sizeof(struct omap_intr_handler_bank_s
) * nbanks
);
638 s
->parent_intr
[0] = parent_irq
;
639 s
->parent_intr
[1] = parent_fiq
;
642 s
->pins
= qemu_allocate_irqs(omap_set_intr_noedge
, s
, nbanks
* 32);
648 iomemtype
= cpu_register_io_memory(0, omap2_inth_readfn
,
649 omap2_inth_writefn
, s
);
650 cpu_register_physical_memory(base
, size
, iomemtype
);
656 struct omap_mpu_timer_s
{
673 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
675 uint64_t distance
= qemu_get_clock(vm_clock
) - timer
->time
;
677 if (timer
->st
&& timer
->enable
&& timer
->rate
)
678 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
679 timer
->rate
, ticks_per_sec
);
684 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
686 timer
->val
= omap_timer_read(timer
);
687 timer
->time
= qemu_get_clock(vm_clock
);
690 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
694 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
695 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
696 expires
= muldiv64((uint64_t) timer
->val
<< (timer
->ptv
+ 1),
697 ticks_per_sec
, timer
->rate
);
699 /* If timer expiry would be sooner than in about 1 ms and
700 * auto-reload isn't set, then fire immediately. This is a hack
701 * to make systems like PalmOS run in acceptable time. PalmOS
702 * sets the interval to a very low value and polls the status bit
703 * in a busy loop when it wants to sleep just a couple of CPU
705 if (expires
> (ticks_per_sec
>> 10) || timer
->ar
)
706 qemu_mod_timer(timer
->timer
, timer
->time
+ expires
);
708 qemu_bh_schedule(timer
->tick
);
710 qemu_del_timer(timer
->timer
);
713 static void omap_timer_fire(void *opaque
)
715 struct omap_mpu_timer_s
*timer
= opaque
;
723 /* Edge-triggered irq */
724 qemu_irq_pulse(timer
->irq
);
727 static void omap_timer_tick(void *opaque
)
729 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
731 omap_timer_sync(timer
);
732 omap_timer_fire(timer
);
733 omap_timer_update(timer
);
736 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
738 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
740 omap_timer_sync(timer
);
741 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
742 omap_timer_update(timer
);
745 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
747 omap_clk_adduser(timer
->clk
,
748 qemu_allocate_irqs(omap_timer_clk_update
, timer
, 1)[0]);
749 timer
->rate
= omap_clk_getrate(timer
->clk
);
752 static uint32_t omap_mpu_timer_read(void *opaque
, target_phys_addr_t addr
)
754 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
757 case 0x00: /* CNTL_TIMER */
758 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
760 case 0x04: /* LOAD_TIM */
763 case 0x08: /* READ_TIM */
764 return omap_timer_read(s
);
771 static void omap_mpu_timer_write(void *opaque
, target_phys_addr_t addr
,
774 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
777 case 0x00: /* CNTL_TIMER */
779 s
->enable
= (value
>> 5) & 1;
780 s
->ptv
= (value
>> 2) & 7;
781 s
->ar
= (value
>> 1) & 1;
783 omap_timer_update(s
);
786 case 0x04: /* LOAD_TIM */
787 s
->reset_val
= value
;
790 case 0x08: /* READ_TIM */
799 static CPUReadMemoryFunc
*omap_mpu_timer_readfn
[] = {
800 omap_badwidth_read32
,
801 omap_badwidth_read32
,
805 static CPUWriteMemoryFunc
*omap_mpu_timer_writefn
[] = {
806 omap_badwidth_write32
,
807 omap_badwidth_write32
,
808 omap_mpu_timer_write
,
811 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
813 qemu_del_timer(s
->timer
);
815 s
->reset_val
= 31337;
823 struct omap_mpu_timer_s
*omap_mpu_timer_init(target_phys_addr_t base
,
824 qemu_irq irq
, omap_clk clk
)
827 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*)
828 qemu_mallocz(sizeof(struct omap_mpu_timer_s
));
832 s
->timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, s
);
833 s
->tick
= qemu_bh_new(omap_timer_fire
, s
);
834 omap_mpu_timer_reset(s
);
835 omap_timer_clk_setup(s
);
837 iomemtype
= cpu_register_io_memory(0, omap_mpu_timer_readfn
,
838 omap_mpu_timer_writefn
, s
);
839 cpu_register_physical_memory(base
, 0x100, iomemtype
);
845 struct omap_watchdog_timer_s
{
846 struct omap_mpu_timer_s timer
;
853 static uint32_t omap_wd_timer_read(void *opaque
, target_phys_addr_t addr
)
855 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
858 case 0x00: /* CNTL_TIMER */
859 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
860 (s
->timer
.st
<< 7) | (s
->free
<< 1);
862 case 0x04: /* READ_TIMER */
863 return omap_timer_read(&s
->timer
);
865 case 0x08: /* TIMER_MODE */
866 return s
->mode
<< 15;
873 static void omap_wd_timer_write(void *opaque
, target_phys_addr_t addr
,
876 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
879 case 0x00: /* CNTL_TIMER */
880 omap_timer_sync(&s
->timer
);
881 s
->timer
.ptv
= (value
>> 9) & 7;
882 s
->timer
.ar
= (value
>> 8) & 1;
883 s
->timer
.st
= (value
>> 7) & 1;
884 s
->free
= (value
>> 1) & 1;
885 omap_timer_update(&s
->timer
);
888 case 0x04: /* LOAD_TIMER */
889 s
->timer
.reset_val
= value
& 0xffff;
892 case 0x08: /* TIMER_MODE */
893 if (!s
->mode
&& ((value
>> 15) & 1))
894 omap_clk_get(s
->timer
.clk
);
895 s
->mode
|= (value
>> 15) & 1;
896 if (s
->last_wr
== 0xf5) {
897 if ((value
& 0xff) == 0xa0) {
900 omap_clk_put(s
->timer
.clk
);
903 /* XXX: on T|E hardware somehow this has no effect,
904 * on Zire 71 it works as specified. */
906 qemu_system_reset_request();
909 s
->last_wr
= value
& 0xff;
917 static CPUReadMemoryFunc
*omap_wd_timer_readfn
[] = {
918 omap_badwidth_read16
,
920 omap_badwidth_read16
,
923 static CPUWriteMemoryFunc
*omap_wd_timer_writefn
[] = {
924 omap_badwidth_write16
,
926 omap_badwidth_write16
,
929 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
931 qemu_del_timer(s
->timer
.timer
);
933 omap_clk_get(s
->timer
.clk
);
939 s
->timer
.reset_val
= 0xffff;
944 omap_timer_update(&s
->timer
);
947 struct omap_watchdog_timer_s
*omap_wd_timer_init(target_phys_addr_t base
,
948 qemu_irq irq
, omap_clk clk
)
951 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*)
952 qemu_mallocz(sizeof(struct omap_watchdog_timer_s
));
956 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
957 omap_wd_timer_reset(s
);
958 omap_timer_clk_setup(&s
->timer
);
960 iomemtype
= cpu_register_io_memory(0, omap_wd_timer_readfn
,
961 omap_wd_timer_writefn
, s
);
962 cpu_register_physical_memory(base
, 0x100, iomemtype
);
968 struct omap_32khz_timer_s
{
969 struct omap_mpu_timer_s timer
;
972 static uint32_t omap_os_timer_read(void *opaque
, target_phys_addr_t addr
)
974 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
975 int offset
= addr
& OMAP_MPUI_REG_MASK
;
979 return s
->timer
.reset_val
;
982 return omap_timer_read(&s
->timer
);
985 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
994 static void omap_os_timer_write(void *opaque
, target_phys_addr_t addr
,
997 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
998 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1001 case 0x00: /* TVR */
1002 s
->timer
.reset_val
= value
& 0x00ffffff;
1005 case 0x04: /* TCR */
1010 s
->timer
.ar
= (value
>> 3) & 1;
1011 s
->timer
.it_ena
= (value
>> 2) & 1;
1012 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
1013 omap_timer_sync(&s
->timer
);
1014 s
->timer
.enable
= value
& 1;
1015 s
->timer
.st
= value
& 1;
1016 omap_timer_update(&s
->timer
);
1025 static CPUReadMemoryFunc
*omap_os_timer_readfn
[] = {
1026 omap_badwidth_read32
,
1027 omap_badwidth_read32
,
1031 static CPUWriteMemoryFunc
*omap_os_timer_writefn
[] = {
1032 omap_badwidth_write32
,
1033 omap_badwidth_write32
,
1034 omap_os_timer_write
,
1037 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
1039 qemu_del_timer(s
->timer
.timer
);
1040 s
->timer
.enable
= 0;
1041 s
->timer
.it_ena
= 0;
1042 s
->timer
.reset_val
= 0x00ffffff;
1049 struct omap_32khz_timer_s
*omap_os_timer_init(target_phys_addr_t base
,
1050 qemu_irq irq
, omap_clk clk
)
1053 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*)
1054 qemu_mallocz(sizeof(struct omap_32khz_timer_s
));
1058 s
->timer
.timer
= qemu_new_timer(vm_clock
, omap_timer_tick
, &s
->timer
);
1059 omap_os_timer_reset(s
);
1060 omap_timer_clk_setup(&s
->timer
);
1062 iomemtype
= cpu_register_io_memory(0, omap_os_timer_readfn
,
1063 omap_os_timer_writefn
, s
);
1064 cpu_register_physical_memory(base
, 0x800, iomemtype
);
1069 /* Ultra Low-Power Device Module */
1070 static uint32_t omap_ulpd_pm_read(void *opaque
, target_phys_addr_t addr
)
1072 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1076 case 0x14: /* IT_STATUS */
1077 ret
= s
->ulpd_pm_regs
[addr
>> 2];
1078 s
->ulpd_pm_regs
[addr
>> 2] = 0;
1079 qemu_irq_lower(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1082 case 0x18: /* Reserved */
1083 case 0x1c: /* Reserved */
1084 case 0x20: /* Reserved */
1085 case 0x28: /* Reserved */
1086 case 0x2c: /* Reserved */
1088 case 0x00: /* COUNTER_32_LSB */
1089 case 0x04: /* COUNTER_32_MSB */
1090 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1091 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1092 case 0x10: /* GAUGING_CTRL */
1093 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1094 case 0x30: /* CLOCK_CTRL */
1095 case 0x34: /* SOFT_REQ */
1096 case 0x38: /* COUNTER_32_FIQ */
1097 case 0x3c: /* DPLL_CTRL */
1098 case 0x40: /* STATUS_REQ */
1099 /* XXX: check clk::usecount state for every clock */
1100 case 0x48: /* LOCL_TIME */
1101 case 0x4c: /* APLL_CTRL */
1102 case 0x50: /* POWER_CTRL */
1103 return s
->ulpd_pm_regs
[addr
>> 2];
1110 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
1111 uint16_t diff
, uint16_t value
)
1113 if (diff
& (1 << 4)) /* USB_MCLK_EN */
1114 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
1115 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
1116 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
1119 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
1120 uint16_t diff
, uint16_t value
)
1122 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
1123 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
1124 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
1125 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
1126 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
1127 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
1128 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
1129 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
1132 static void omap_ulpd_pm_write(void *opaque
, target_phys_addr_t addr
,
1135 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1138 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1142 case 0x00: /* COUNTER_32_LSB */
1143 case 0x04: /* COUNTER_32_MSB */
1144 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1145 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1146 case 0x14: /* IT_STATUS */
1147 case 0x40: /* STATUS_REQ */
1151 case 0x10: /* GAUGING_CTRL */
1152 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
1153 if ((s
->ulpd_pm_regs
[addr
>> 2] ^ value
) & 1) {
1154 now
= qemu_get_clock(vm_clock
);
1157 s
->ulpd_gauge_start
= now
;
1159 now
-= s
->ulpd_gauge_start
;
1162 ticks
= muldiv64(now
, 32768, ticks_per_sec
);
1163 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
1164 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
1165 if (ticks
>> 32) /* OVERFLOW_32K */
1166 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
1168 /* High frequency ticks */
1169 ticks
= muldiv64(now
, 12000000, ticks_per_sec
);
1170 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
1171 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
1172 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
1173 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
1175 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
1176 qemu_irq_raise(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
1179 s
->ulpd_pm_regs
[addr
>> 2] = value
;
1182 case 0x18: /* Reserved */
1183 case 0x1c: /* Reserved */
1184 case 0x20: /* Reserved */
1185 case 0x28: /* Reserved */
1186 case 0x2c: /* Reserved */
1188 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1189 case 0x38: /* COUNTER_32_FIQ */
1190 case 0x48: /* LOCL_TIME */
1191 case 0x50: /* POWER_CTRL */
1192 s
->ulpd_pm_regs
[addr
>> 2] = value
;
1195 case 0x30: /* CLOCK_CTRL */
1196 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
1197 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x3f;
1198 omap_ulpd_clk_update(s
, diff
, value
);
1201 case 0x34: /* SOFT_REQ */
1202 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
1203 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x1f;
1204 omap_ulpd_req_update(s
, diff
, value
);
1207 case 0x3c: /* DPLL_CTRL */
1208 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
1209 * omitted altogether, probably a typo. */
1210 /* This register has identical semantics with DPLL(1:3) control
1211 * registers, see omap_dpll_write() */
1212 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
1213 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x2fff;
1214 if (diff
& (0x3ff << 2)) {
1215 if (value
& (1 << 4)) { /* PLL_ENABLE */
1216 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1217 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1219 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1222 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
1225 /* Enter the desired mode. */
1226 s
->ulpd_pm_regs
[addr
>> 2] =
1227 (s
->ulpd_pm_regs
[addr
>> 2] & 0xfffe) |
1228 ((s
->ulpd_pm_regs
[addr
>> 2] >> 4) & 1);
1230 /* Act as if the lock is restored. */
1231 s
->ulpd_pm_regs
[addr
>> 2] |= 2;
1234 case 0x4c: /* APLL_CTRL */
1235 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
1236 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0xf;
1237 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
1238 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
1239 (value
& (1 << 0)) ? "apll" : "dpll4"));
1247 static CPUReadMemoryFunc
*omap_ulpd_pm_readfn
[] = {
1248 omap_badwidth_read16
,
1250 omap_badwidth_read16
,
1253 static CPUWriteMemoryFunc
*omap_ulpd_pm_writefn
[] = {
1254 omap_badwidth_write16
,
1256 omap_badwidth_write16
,
1259 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
1261 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
1262 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
1263 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
1264 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
1265 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
1266 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
1267 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
1268 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
1269 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
1270 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
1271 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
1272 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
1273 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
1274 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
1275 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
1276 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
1277 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
1278 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
1279 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
1280 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
1281 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
1282 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
1283 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
1286 static void omap_ulpd_pm_init(target_phys_addr_t base
,
1287 struct omap_mpu_state_s
*mpu
)
1289 int iomemtype
= cpu_register_io_memory(0, omap_ulpd_pm_readfn
,
1290 omap_ulpd_pm_writefn
, mpu
);
1292 cpu_register_physical_memory(base
, 0x800, iomemtype
);
1293 omap_ulpd_pm_reset(mpu
);
1296 /* OMAP Pin Configuration */
1297 static uint32_t omap_pin_cfg_read(void *opaque
, target_phys_addr_t addr
)
1299 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1302 case 0x00: /* FUNC_MUX_CTRL_0 */
1303 case 0x04: /* FUNC_MUX_CTRL_1 */
1304 case 0x08: /* FUNC_MUX_CTRL_2 */
1305 return s
->func_mux_ctrl
[addr
>> 2];
1307 case 0x0c: /* COMP_MODE_CTRL_0 */
1308 return s
->comp_mode_ctrl
[0];
1310 case 0x10: /* FUNC_MUX_CTRL_3 */
1311 case 0x14: /* FUNC_MUX_CTRL_4 */
1312 case 0x18: /* FUNC_MUX_CTRL_5 */
1313 case 0x1c: /* FUNC_MUX_CTRL_6 */
1314 case 0x20: /* FUNC_MUX_CTRL_7 */
1315 case 0x24: /* FUNC_MUX_CTRL_8 */
1316 case 0x28: /* FUNC_MUX_CTRL_9 */
1317 case 0x2c: /* FUNC_MUX_CTRL_A */
1318 case 0x30: /* FUNC_MUX_CTRL_B */
1319 case 0x34: /* FUNC_MUX_CTRL_C */
1320 case 0x38: /* FUNC_MUX_CTRL_D */
1321 return s
->func_mux_ctrl
[(addr
>> 2) - 1];
1323 case 0x40: /* PULL_DWN_CTRL_0 */
1324 case 0x44: /* PULL_DWN_CTRL_1 */
1325 case 0x48: /* PULL_DWN_CTRL_2 */
1326 case 0x4c: /* PULL_DWN_CTRL_3 */
1327 return s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2];
1329 case 0x50: /* GATE_INH_CTRL_0 */
1330 return s
->gate_inh_ctrl
[0];
1332 case 0x60: /* VOLTAGE_CTRL_0 */
1333 return s
->voltage_ctrl
[0];
1335 case 0x70: /* TEST_DBG_CTRL_0 */
1336 return s
->test_dbg_ctrl
[0];
1338 case 0x80: /* MOD_CONF_CTRL_0 */
1339 return s
->mod_conf_ctrl
[0];
1346 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
1347 uint32_t diff
, uint32_t value
)
1349 if (s
->compat1509
) {
1350 if (diff
& (1 << 9)) /* BLUETOOTH */
1351 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
1353 if (diff
& (1 << 7)) /* USB.CLKO */
1354 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
1359 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
1360 uint32_t diff
, uint32_t value
)
1362 if (s
->compat1509
) {
1363 if (diff
& (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
1364 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"),
1366 if (diff
& (1 << 1)) /* CLK32K */
1367 omap_clk_onoff(omap_findclk(s
, "clk32k_out"),
1372 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
1373 uint32_t diff
, uint32_t value
)
1375 if (diff
& (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
1376 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
1377 omap_findclk(s
, ((value
>> 31) & 1) ?
1378 "ck_48m" : "armper_ck"));
1379 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
1380 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
1381 omap_findclk(s
, ((value
>> 30) & 1) ?
1382 "ck_48m" : "armper_ck"));
1383 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
1384 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
1385 omap_findclk(s
, ((value
>> 29) & 1) ?
1386 "ck_48m" : "armper_ck"));
1387 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
1388 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
1389 omap_findclk(s
, ((value
>> 23) & 1) ?
1390 "ck_48m" : "armper_ck"));
1391 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
1392 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
1393 omap_findclk(s
, ((value
>> 12) & 1) ?
1394 "ck_48m" : "armper_ck"));
1395 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
1396 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
1399 static void omap_pin_cfg_write(void *opaque
, target_phys_addr_t addr
,
1402 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1406 case 0x00: /* FUNC_MUX_CTRL_0 */
1407 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
1408 s
->func_mux_ctrl
[addr
>> 2] = value
;
1409 omap_pin_funcmux0_update(s
, diff
, value
);
1412 case 0x04: /* FUNC_MUX_CTRL_1 */
1413 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
1414 s
->func_mux_ctrl
[addr
>> 2] = value
;
1415 omap_pin_funcmux1_update(s
, diff
, value
);
1418 case 0x08: /* FUNC_MUX_CTRL_2 */
1419 s
->func_mux_ctrl
[addr
>> 2] = value
;
1422 case 0x0c: /* COMP_MODE_CTRL_0 */
1423 s
->comp_mode_ctrl
[0] = value
;
1424 s
->compat1509
= (value
!= 0x0000eaef);
1425 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
1426 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
1429 case 0x10: /* FUNC_MUX_CTRL_3 */
1430 case 0x14: /* FUNC_MUX_CTRL_4 */
1431 case 0x18: /* FUNC_MUX_CTRL_5 */
1432 case 0x1c: /* FUNC_MUX_CTRL_6 */
1433 case 0x20: /* FUNC_MUX_CTRL_7 */
1434 case 0x24: /* FUNC_MUX_CTRL_8 */
1435 case 0x28: /* FUNC_MUX_CTRL_9 */
1436 case 0x2c: /* FUNC_MUX_CTRL_A */
1437 case 0x30: /* FUNC_MUX_CTRL_B */
1438 case 0x34: /* FUNC_MUX_CTRL_C */
1439 case 0x38: /* FUNC_MUX_CTRL_D */
1440 s
->func_mux_ctrl
[(addr
>> 2) - 1] = value
;
1443 case 0x40: /* PULL_DWN_CTRL_0 */
1444 case 0x44: /* PULL_DWN_CTRL_1 */
1445 case 0x48: /* PULL_DWN_CTRL_2 */
1446 case 0x4c: /* PULL_DWN_CTRL_3 */
1447 s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2] = value
;
1450 case 0x50: /* GATE_INH_CTRL_0 */
1451 s
->gate_inh_ctrl
[0] = value
;
1454 case 0x60: /* VOLTAGE_CTRL_0 */
1455 s
->voltage_ctrl
[0] = value
;
1458 case 0x70: /* TEST_DBG_CTRL_0 */
1459 s
->test_dbg_ctrl
[0] = value
;
1462 case 0x80: /* MOD_CONF_CTRL_0 */
1463 diff
= s
->mod_conf_ctrl
[0] ^ value
;
1464 s
->mod_conf_ctrl
[0] = value
;
1465 omap_pin_modconf1_update(s
, diff
, value
);
1473 static CPUReadMemoryFunc
*omap_pin_cfg_readfn
[] = {
1474 omap_badwidth_read32
,
1475 omap_badwidth_read32
,
1479 static CPUWriteMemoryFunc
*omap_pin_cfg_writefn
[] = {
1480 omap_badwidth_write32
,
1481 omap_badwidth_write32
,
1485 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
1487 /* Start in Compatibility Mode. */
1488 mpu
->compat1509
= 1;
1489 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
1490 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
1491 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
1492 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
1493 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
1494 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
1495 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
1496 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
1497 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
1498 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
1501 static void omap_pin_cfg_init(target_phys_addr_t base
,
1502 struct omap_mpu_state_s
*mpu
)
1504 int iomemtype
= cpu_register_io_memory(0, omap_pin_cfg_readfn
,
1505 omap_pin_cfg_writefn
, mpu
);
1507 cpu_register_physical_memory(base
, 0x800, iomemtype
);
1508 omap_pin_cfg_reset(mpu
);
1511 /* Device Identification, Die Identification */
1512 static uint32_t omap_id_read(void *opaque
, target_phys_addr_t addr
)
1514 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1517 case 0xfffe1800: /* DIE_ID_LSB */
1519 case 0xfffe1804: /* DIE_ID_MSB */
1522 case 0xfffe2000: /* PRODUCT_ID_LSB */
1524 case 0xfffe2004: /* PRODUCT_ID_MSB */
1527 case 0xfffed400: /* JTAG_ID_LSB */
1528 switch (s
->mpu_model
) {
1534 cpu_abort(cpu_single_env
, "%s: bad mpu model\n", __FUNCTION__
);
1538 case 0xfffed404: /* JTAG_ID_MSB */
1539 switch (s
->mpu_model
) {
1545 cpu_abort(cpu_single_env
, "%s: bad mpu model\n", __FUNCTION__
);
1554 static void omap_id_write(void *opaque
, target_phys_addr_t addr
,
1560 static CPUReadMemoryFunc
*omap_id_readfn
[] = {
1561 omap_badwidth_read32
,
1562 omap_badwidth_read32
,
1566 static CPUWriteMemoryFunc
*omap_id_writefn
[] = {
1567 omap_badwidth_write32
,
1568 omap_badwidth_write32
,
1572 static void omap_id_init(struct omap_mpu_state_s
*mpu
)
1574 int iomemtype
= cpu_register_io_memory(0, omap_id_readfn
,
1575 omap_id_writefn
, mpu
);
1576 cpu_register_physical_memory_offset(0xfffe1800, 0x800, iomemtype
, 0xfffe1800);
1577 cpu_register_physical_memory_offset(0xfffed400, 0x100, iomemtype
, 0xfffed400);
1578 if (!cpu_is_omap15xx(mpu
))
1579 cpu_register_physical_memory_offset(0xfffe2000, 0x800, iomemtype
, 0xfffe2000);
1582 /* MPUI Control (Dummy) */
1583 static uint32_t omap_mpui_read(void *opaque
, target_phys_addr_t addr
)
1585 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1588 case 0x00: /* CTRL */
1589 return s
->mpui_ctrl
;
1590 case 0x04: /* DEBUG_ADDR */
1592 case 0x08: /* DEBUG_DATA */
1594 case 0x0c: /* DEBUG_FLAG */
1596 case 0x10: /* STATUS */
1599 /* Not in OMAP310 */
1600 case 0x14: /* DSP_STATUS */
1601 case 0x18: /* DSP_BOOT_CONFIG */
1603 case 0x1c: /* DSP_MPUI_CONFIG */
1611 static void omap_mpui_write(void *opaque
, target_phys_addr_t addr
,
1614 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1617 case 0x00: /* CTRL */
1618 s
->mpui_ctrl
= value
& 0x007fffff;
1621 case 0x04: /* DEBUG_ADDR */
1622 case 0x08: /* DEBUG_DATA */
1623 case 0x0c: /* DEBUG_FLAG */
1624 case 0x10: /* STATUS */
1625 /* Not in OMAP310 */
1626 case 0x14: /* DSP_STATUS */
1628 case 0x18: /* DSP_BOOT_CONFIG */
1629 case 0x1c: /* DSP_MPUI_CONFIG */
1637 static CPUReadMemoryFunc
*omap_mpui_readfn
[] = {
1638 omap_badwidth_read32
,
1639 omap_badwidth_read32
,
1643 static CPUWriteMemoryFunc
*omap_mpui_writefn
[] = {
1644 omap_badwidth_write32
,
1645 omap_badwidth_write32
,
1649 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1651 s
->mpui_ctrl
= 0x0003ff1b;
1654 static void omap_mpui_init(target_phys_addr_t base
,
1655 struct omap_mpu_state_s
*mpu
)
1657 int iomemtype
= cpu_register_io_memory(0, omap_mpui_readfn
,
1658 omap_mpui_writefn
, mpu
);
1660 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1662 omap_mpui_reset(mpu
);
1666 struct omap_tipb_bridge_s
{
1673 uint16_t enh_control
;
1676 static uint32_t omap_tipb_bridge_read(void *opaque
, target_phys_addr_t addr
)
1678 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1681 case 0x00: /* TIPB_CNTL */
1683 case 0x04: /* TIPB_BUS_ALLOC */
1685 case 0x08: /* MPU_TIPB_CNTL */
1687 case 0x0c: /* ENHANCED_TIPB_CNTL */
1688 return s
->enh_control
;
1689 case 0x10: /* ADDRESS_DBG */
1690 case 0x14: /* DATA_DEBUG_LOW */
1691 case 0x18: /* DATA_DEBUG_HIGH */
1693 case 0x1c: /* DEBUG_CNTR_SIG */
1701 static void omap_tipb_bridge_write(void *opaque
, target_phys_addr_t addr
,
1704 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1707 case 0x00: /* TIPB_CNTL */
1708 s
->control
= value
& 0xffff;
1711 case 0x04: /* TIPB_BUS_ALLOC */
1712 s
->alloc
= value
& 0x003f;
1715 case 0x08: /* MPU_TIPB_CNTL */
1716 s
->buffer
= value
& 0x0003;
1719 case 0x0c: /* ENHANCED_TIPB_CNTL */
1720 s
->width_intr
= !(value
& 2);
1721 s
->enh_control
= value
& 0x000f;
1724 case 0x10: /* ADDRESS_DBG */
1725 case 0x14: /* DATA_DEBUG_LOW */
1726 case 0x18: /* DATA_DEBUG_HIGH */
1727 case 0x1c: /* DEBUG_CNTR_SIG */
1736 static CPUReadMemoryFunc
*omap_tipb_bridge_readfn
[] = {
1737 omap_badwidth_read16
,
1738 omap_tipb_bridge_read
,
1739 omap_tipb_bridge_read
,
1742 static CPUWriteMemoryFunc
*omap_tipb_bridge_writefn
[] = {
1743 omap_badwidth_write16
,
1744 omap_tipb_bridge_write
,
1745 omap_tipb_bridge_write
,
1748 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1750 s
->control
= 0xffff;
1753 s
->enh_control
= 0x000f;
1756 struct omap_tipb_bridge_s
*omap_tipb_bridge_init(target_phys_addr_t base
,
1757 qemu_irq abort_irq
, omap_clk clk
)
1760 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*)
1761 qemu_mallocz(sizeof(struct omap_tipb_bridge_s
));
1763 s
->abort
= abort_irq
;
1764 omap_tipb_bridge_reset(s
);
1766 iomemtype
= cpu_register_io_memory(0, omap_tipb_bridge_readfn
,
1767 omap_tipb_bridge_writefn
, s
);
1768 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1773 /* Dummy Traffic Controller's Memory Interface */
1774 static uint32_t omap_tcmi_read(void *opaque
, target_phys_addr_t addr
)
1776 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1780 case 0x00: /* IMIF_PRIO */
1781 case 0x04: /* EMIFS_PRIO */
1782 case 0x08: /* EMIFF_PRIO */
1783 case 0x0c: /* EMIFS_CONFIG */
1784 case 0x10: /* EMIFS_CS0_CONFIG */
1785 case 0x14: /* EMIFS_CS1_CONFIG */
1786 case 0x18: /* EMIFS_CS2_CONFIG */
1787 case 0x1c: /* EMIFS_CS3_CONFIG */
1788 case 0x24: /* EMIFF_MRS */
1789 case 0x28: /* TIMEOUT1 */
1790 case 0x2c: /* TIMEOUT2 */
1791 case 0x30: /* TIMEOUT3 */
1792 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1793 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1794 return s
->tcmi_regs
[addr
>> 2];
1796 case 0x20: /* EMIFF_SDRAM_CONFIG */
1797 ret
= s
->tcmi_regs
[addr
>> 2];
1798 s
->tcmi_regs
[addr
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1799 /* XXX: We can try using the VGA_DIRTY flag for this */
1807 static void omap_tcmi_write(void *opaque
, target_phys_addr_t addr
,
1810 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1813 case 0x00: /* IMIF_PRIO */
1814 case 0x04: /* EMIFS_PRIO */
1815 case 0x08: /* EMIFF_PRIO */
1816 case 0x10: /* EMIFS_CS0_CONFIG */
1817 case 0x14: /* EMIFS_CS1_CONFIG */
1818 case 0x18: /* EMIFS_CS2_CONFIG */
1819 case 0x1c: /* EMIFS_CS3_CONFIG */
1820 case 0x20: /* EMIFF_SDRAM_CONFIG */
1821 case 0x24: /* EMIFF_MRS */
1822 case 0x28: /* TIMEOUT1 */
1823 case 0x2c: /* TIMEOUT2 */
1824 case 0x30: /* TIMEOUT3 */
1825 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1826 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1827 s
->tcmi_regs
[addr
>> 2] = value
;
1829 case 0x0c: /* EMIFS_CONFIG */
1830 s
->tcmi_regs
[addr
>> 2] = (value
& 0xf) | (1 << 4);
1838 static CPUReadMemoryFunc
*omap_tcmi_readfn
[] = {
1839 omap_badwidth_read32
,
1840 omap_badwidth_read32
,
1844 static CPUWriteMemoryFunc
*omap_tcmi_writefn
[] = {
1845 omap_badwidth_write32
,
1846 omap_badwidth_write32
,
1850 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1852 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1853 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1854 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1855 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1856 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1857 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1858 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1859 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1860 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1861 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1862 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1863 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1864 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1865 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1866 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1869 static void omap_tcmi_init(target_phys_addr_t base
,
1870 struct omap_mpu_state_s
*mpu
)
1872 int iomemtype
= cpu_register_io_memory(0, omap_tcmi_readfn
,
1873 omap_tcmi_writefn
, mpu
);
1875 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1876 omap_tcmi_reset(mpu
);
1879 /* Digital phase-locked loops control */
1880 static uint32_t omap_dpll_read(void *opaque
, target_phys_addr_t addr
)
1882 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1884 if (addr
== 0x00) /* CTL_REG */
1891 static void omap_dpll_write(void *opaque
, target_phys_addr_t addr
,
1894 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1896 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1899 if (addr
== 0x00) { /* CTL_REG */
1900 /* See omap_ulpd_pm_write() too */
1901 diff
= s
->mode
& value
;
1902 s
->mode
= value
& 0x2fff;
1903 if (diff
& (0x3ff << 2)) {
1904 if (value
& (1 << 4)) { /* PLL_ENABLE */
1905 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1906 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1908 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1911 omap_clk_setrate(s
->dpll
, div
, mult
);
1914 /* Enter the desired mode. */
1915 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1917 /* Act as if the lock is restored. */
1924 static CPUReadMemoryFunc
*omap_dpll_readfn
[] = {
1925 omap_badwidth_read16
,
1927 omap_badwidth_read16
,
1930 static CPUWriteMemoryFunc
*omap_dpll_writefn
[] = {
1931 omap_badwidth_write16
,
1933 omap_badwidth_write16
,
1936 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1939 omap_clk_setrate(s
->dpll
, 1, 1);
1942 static void omap_dpll_init(struct dpll_ctl_s
*s
, target_phys_addr_t base
,
1945 int iomemtype
= cpu_register_io_memory(0, omap_dpll_readfn
,
1946 omap_dpll_writefn
, s
);
1951 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1955 struct omap_uart_s
{
1956 target_phys_addr_t base
;
1957 SerialState
*serial
; /* TODO */
1958 struct omap_target_agent_s
*ta
;
1971 void omap_uart_reset(struct omap_uart_s
*s
)
1980 struct omap_uart_s
*omap_uart_init(target_phys_addr_t base
,
1981 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
1982 qemu_irq txdma
, qemu_irq rxdma
, CharDriverState
*chr
)
1984 struct omap_uart_s
*s
= (struct omap_uart_s
*)
1985 qemu_mallocz(sizeof(struct omap_uart_s
));
1990 s
->serial
= serial_mm_init(base
, 2, irq
, omap_clk_getrate(fclk
)/16,
1991 chr
?: qemu_chr_open("null", "null"), 1);
1996 static uint32_t omap_uart_read(void *opaque
, target_phys_addr_t addr
)
1998 struct omap_uart_s
*s
= (struct omap_uart_s
*) opaque
;
2002 case 0x20: /* MDR1 */
2004 case 0x24: /* MDR2 */
2006 case 0x40: /* SCR */
2008 case 0x44: /* SSR */
2010 case 0x48: /* EBLR (OMAP2) */
2012 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2014 case 0x50: /* MVR */
2016 case 0x54: /* SYSC (OMAP2) */
2017 return s
->syscontrol
;
2018 case 0x58: /* SYSS (OMAP2) */
2020 case 0x5c: /* WER (OMAP2) */
2022 case 0x60: /* CFPS (OMAP2) */
2030 static void omap_uart_write(void *opaque
, target_phys_addr_t addr
,
2033 struct omap_uart_s
*s
= (struct omap_uart_s
*) opaque
;
2037 case 0x20: /* MDR1 */
2038 s
->mdr
[0] = value
& 0x7f;
2040 case 0x24: /* MDR2 */
2041 s
->mdr
[1] = value
& 0xff;
2043 case 0x40: /* SCR */
2044 s
->scr
= value
& 0xff;
2046 case 0x48: /* EBLR (OMAP2) */
2047 s
->eblr
= value
& 0xff;
2049 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2050 s
->clksel
= value
& 1;
2052 case 0x44: /* SSR */
2053 case 0x50: /* MVR */
2054 case 0x58: /* SYSS (OMAP2) */
2057 case 0x54: /* SYSC (OMAP2) */
2058 s
->syscontrol
= value
& 0x1d;
2062 case 0x5c: /* WER (OMAP2) */
2063 s
->wkup
= value
& 0x7f;
2065 case 0x60: /* CFPS (OMAP2) */
2066 s
->cfps
= value
& 0xff;
2073 static CPUReadMemoryFunc
*omap_uart_readfn
[] = {
2076 omap_badwidth_read8
,
2079 static CPUWriteMemoryFunc
*omap_uart_writefn
[] = {
2082 omap_badwidth_write8
,
2085 struct omap_uart_s
*omap2_uart_init(struct omap_target_agent_s
*ta
,
2086 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
2087 qemu_irq txdma
, qemu_irq rxdma
, CharDriverState
*chr
)
2089 target_phys_addr_t base
= omap_l4_attach(ta
, 0, 0);
2090 struct omap_uart_s
*s
= omap_uart_init(base
, irq
,
2091 fclk
, iclk
, txdma
, rxdma
, chr
);
2092 int iomemtype
= cpu_register_io_memory(0, omap_uart_readfn
,
2093 omap_uart_writefn
, s
);
2097 cpu_register_physical_memory(base
+ 0x20, 0x100, iomemtype
);
2102 void omap_uart_attach(struct omap_uart_s
*s
, CharDriverState
*chr
)
2104 /* TODO: Should reuse or destroy current s->serial */
2105 s
->serial
= serial_mm_init(s
->base
, 2, s
->irq
,
2106 omap_clk_getrate(s
->fclk
) / 16,
2107 chr
?: qemu_chr_open("null", "null"), 1);
2110 /* MPU Clock/Reset/Power Mode Control */
2111 static uint32_t omap_clkm_read(void *opaque
, target_phys_addr_t addr
)
2113 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2116 case 0x00: /* ARM_CKCTL */
2117 return s
->clkm
.arm_ckctl
;
2119 case 0x04: /* ARM_IDLECT1 */
2120 return s
->clkm
.arm_idlect1
;
2122 case 0x08: /* ARM_IDLECT2 */
2123 return s
->clkm
.arm_idlect2
;
2125 case 0x0c: /* ARM_EWUPCT */
2126 return s
->clkm
.arm_ewupct
;
2128 case 0x10: /* ARM_RSTCT1 */
2129 return s
->clkm
.arm_rstct1
;
2131 case 0x14: /* ARM_RSTCT2 */
2132 return s
->clkm
.arm_rstct2
;
2134 case 0x18: /* ARM_SYSST */
2135 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
2137 case 0x1c: /* ARM_CKOUT1 */
2138 return s
->clkm
.arm_ckout1
;
2140 case 0x20: /* ARM_CKOUT2 */
2148 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
2149 uint16_t diff
, uint16_t value
)
2153 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
2154 if (value
& (1 << 14))
2157 clk
= omap_findclk(s
, "arminth_ck");
2158 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2161 if (diff
& (1 << 12)) { /* ARM_TIMXO */
2162 clk
= omap_findclk(s
, "armtim_ck");
2163 if (value
& (1 << 12))
2164 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
2166 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2169 if (diff
& (3 << 10)) { /* DSPMMUDIV */
2170 clk
= omap_findclk(s
, "dspmmu_ck");
2171 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
2173 if (diff
& (3 << 8)) { /* TCDIV */
2174 clk
= omap_findclk(s
, "tc_ck");
2175 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
2177 if (diff
& (3 << 6)) { /* DSPDIV */
2178 clk
= omap_findclk(s
, "dsp_ck");
2179 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
2181 if (diff
& (3 << 4)) { /* ARMDIV */
2182 clk
= omap_findclk(s
, "arm_ck");
2183 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
2185 if (diff
& (3 << 2)) { /* LCDDIV */
2186 clk
= omap_findclk(s
, "lcd_ck");
2187 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
2189 if (diff
& (3 << 0)) { /* PERDIV */
2190 clk
= omap_findclk(s
, "armper_ck");
2191 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
2195 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
2196 uint16_t diff
, uint16_t value
)
2200 if (value
& (1 << 11)) /* SETARM_IDLE */
2201 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
2202 if (!(value
& (1 << 10))) /* WKUP_MODE */
2203 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
2205 #define SET_CANIDLE(clock, bit) \
2206 if (diff & (1 << bit)) { \
2207 clk = omap_findclk(s, clock); \
2208 omap_clk_canidle(clk, (value >> bit) & 1); \
2210 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
2211 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
2212 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
2213 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
2214 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
2215 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
2216 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
2217 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
2218 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
2219 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
2220 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
2221 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
2222 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
2223 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
2226 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
2227 uint16_t diff
, uint16_t value
)
2231 #define SET_ONOFF(clock, bit) \
2232 if (diff & (1 << bit)) { \
2233 clk = omap_findclk(s, clock); \
2234 omap_clk_onoff(clk, (value >> bit) & 1); \
2236 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
2237 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
2238 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
2239 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
2240 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
2241 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
2242 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
2243 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
2244 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
2245 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
2246 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
2249 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
2250 uint16_t diff
, uint16_t value
)
2254 if (diff
& (3 << 4)) { /* TCLKOUT */
2255 clk
= omap_findclk(s
, "tclk_out");
2256 switch ((value
>> 4) & 3) {
2258 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
2259 omap_clk_onoff(clk
, 1);
2262 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
2263 omap_clk_onoff(clk
, 1);
2266 omap_clk_onoff(clk
, 0);
2269 if (diff
& (3 << 2)) { /* DCLKOUT */
2270 clk
= omap_findclk(s
, "dclk_out");
2271 switch ((value
>> 2) & 3) {
2273 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
2276 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
2279 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
2282 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2286 if (diff
& (3 << 0)) { /* ACLKOUT */
2287 clk
= omap_findclk(s
, "aclk_out");
2288 switch ((value
>> 0) & 3) {
2290 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
2291 omap_clk_onoff(clk
, 1);
2294 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
2295 omap_clk_onoff(clk
, 1);
2298 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
2299 omap_clk_onoff(clk
, 1);
2302 omap_clk_onoff(clk
, 0);
2307 static void omap_clkm_write(void *opaque
, target_phys_addr_t addr
,
2310 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2313 static const char *clkschemename
[8] = {
2314 "fully synchronous", "fully asynchronous", "synchronous scalable",
2315 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
2319 case 0x00: /* ARM_CKCTL */
2320 diff
= s
->clkm
.arm_ckctl
^ value
;
2321 s
->clkm
.arm_ckctl
= value
& 0x7fff;
2322 omap_clkm_ckctl_update(s
, diff
, value
);
2325 case 0x04: /* ARM_IDLECT1 */
2326 diff
= s
->clkm
.arm_idlect1
^ value
;
2327 s
->clkm
.arm_idlect1
= value
& 0x0fff;
2328 omap_clkm_idlect1_update(s
, diff
, value
);
2331 case 0x08: /* ARM_IDLECT2 */
2332 diff
= s
->clkm
.arm_idlect2
^ value
;
2333 s
->clkm
.arm_idlect2
= value
& 0x07ff;
2334 omap_clkm_idlect2_update(s
, diff
, value
);
2337 case 0x0c: /* ARM_EWUPCT */
2338 diff
= s
->clkm
.arm_ewupct
^ value
;
2339 s
->clkm
.arm_ewupct
= value
& 0x003f;
2342 case 0x10: /* ARM_RSTCT1 */
2343 diff
= s
->clkm
.arm_rstct1
^ value
;
2344 s
->clkm
.arm_rstct1
= value
& 0x0007;
2346 qemu_system_reset_request();
2347 s
->clkm
.cold_start
= 0xa;
2349 if (diff
& ~value
& 4) { /* DSP_RST */
2351 omap_tipb_bridge_reset(s
->private_tipb
);
2352 omap_tipb_bridge_reset(s
->public_tipb
);
2354 if (diff
& 2) { /* DSP_EN */
2355 clk
= omap_findclk(s
, "dsp_ck");
2356 omap_clk_canidle(clk
, (~value
>> 1) & 1);
2360 case 0x14: /* ARM_RSTCT2 */
2361 s
->clkm
.arm_rstct2
= value
& 0x0001;
2364 case 0x18: /* ARM_SYSST */
2365 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
2366 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
2367 printf("%s: clocking scheme set to %s\n", __FUNCTION__
,
2368 clkschemename
[s
->clkm
.clocking_scheme
]);
2370 s
->clkm
.cold_start
&= value
& 0x3f;
2373 case 0x1c: /* ARM_CKOUT1 */
2374 diff
= s
->clkm
.arm_ckout1
^ value
;
2375 s
->clkm
.arm_ckout1
= value
& 0x003f;
2376 omap_clkm_ckout1_update(s
, diff
, value
);
2379 case 0x20: /* ARM_CKOUT2 */
2385 static CPUReadMemoryFunc
*omap_clkm_readfn
[] = {
2386 omap_badwidth_read16
,
2388 omap_badwidth_read16
,
2391 static CPUWriteMemoryFunc
*omap_clkm_writefn
[] = {
2392 omap_badwidth_write16
,
2394 omap_badwidth_write16
,
2397 static uint32_t omap_clkdsp_read(void *opaque
, target_phys_addr_t addr
)
2399 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2402 case 0x04: /* DSP_IDLECT1 */
2403 return s
->clkm
.dsp_idlect1
;
2405 case 0x08: /* DSP_IDLECT2 */
2406 return s
->clkm
.dsp_idlect2
;
2408 case 0x14: /* DSP_RSTCT2 */
2409 return s
->clkm
.dsp_rstct2
;
2411 case 0x18: /* DSP_SYSST */
2412 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
2413 (s
->env
->halted
<< 6); /* Quite useless... */
2420 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
2421 uint16_t diff
, uint16_t value
)
2425 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
2428 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
2429 uint16_t diff
, uint16_t value
)
2433 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
2436 static void omap_clkdsp_write(void *opaque
, target_phys_addr_t addr
,
2439 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2443 case 0x04: /* DSP_IDLECT1 */
2444 diff
= s
->clkm
.dsp_idlect1
^ value
;
2445 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
2446 omap_clkdsp_idlect1_update(s
, diff
, value
);
2449 case 0x08: /* DSP_IDLECT2 */
2450 s
->clkm
.dsp_idlect2
= value
& 0x0037;
2451 diff
= s
->clkm
.dsp_idlect1
^ value
;
2452 omap_clkdsp_idlect2_update(s
, diff
, value
);
2455 case 0x14: /* DSP_RSTCT2 */
2456 s
->clkm
.dsp_rstct2
= value
& 0x0001;
2459 case 0x18: /* DSP_SYSST */
2460 s
->clkm
.cold_start
&= value
& 0x3f;
2468 static CPUReadMemoryFunc
*omap_clkdsp_readfn
[] = {
2469 omap_badwidth_read16
,
2471 omap_badwidth_read16
,
2474 static CPUWriteMemoryFunc
*omap_clkdsp_writefn
[] = {
2475 omap_badwidth_write16
,
2477 omap_badwidth_write16
,
2480 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
2482 if (s
->wdt
&& s
->wdt
->reset
)
2483 s
->clkm
.cold_start
= 0x6;
2484 s
->clkm
.clocking_scheme
= 0;
2485 omap_clkm_ckctl_update(s
, ~0, 0x3000);
2486 s
->clkm
.arm_ckctl
= 0x3000;
2487 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
2488 s
->clkm
.arm_idlect1
= 0x0400;
2489 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
2490 s
->clkm
.arm_idlect2
= 0x0100;
2491 s
->clkm
.arm_ewupct
= 0x003f;
2492 s
->clkm
.arm_rstct1
= 0x0000;
2493 s
->clkm
.arm_rstct2
= 0x0000;
2494 s
->clkm
.arm_ckout1
= 0x0015;
2495 s
->clkm
.dpll1_mode
= 0x2002;
2496 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
2497 s
->clkm
.dsp_idlect1
= 0x0040;
2498 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
2499 s
->clkm
.dsp_idlect2
= 0x0000;
2500 s
->clkm
.dsp_rstct2
= 0x0000;
2503 static void omap_clkm_init(target_phys_addr_t mpu_base
,
2504 target_phys_addr_t dsp_base
, struct omap_mpu_state_s
*s
)
2506 int iomemtype
[2] = {
2507 cpu_register_io_memory(0, omap_clkm_readfn
, omap_clkm_writefn
, s
),
2508 cpu_register_io_memory(0, omap_clkdsp_readfn
, omap_clkdsp_writefn
, s
),
2511 s
->clkm
.arm_idlect1
= 0x03ff;
2512 s
->clkm
.arm_idlect2
= 0x0100;
2513 s
->clkm
.dsp_idlect1
= 0x0002;
2515 s
->clkm
.cold_start
= 0x3a;
2517 cpu_register_physical_memory(mpu_base
, 0x100, iomemtype
[0]);
2518 cpu_register_physical_memory(dsp_base
, 0x1000, iomemtype
[1]);
2522 struct omap_mpuio_s
{
2526 qemu_irq handler
[16];
2547 static void omap_mpuio_set(void *opaque
, int line
, int level
)
2549 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2550 uint16_t prev
= s
->inputs
;
2553 s
->inputs
|= 1 << line
;
2555 s
->inputs
&= ~(1 << line
);
2557 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
2558 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
2559 s
->ints
|= 1 << line
;
2560 qemu_irq_raise(s
->irq
);
2563 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
2564 (s
->event
>> 1) == line
) /* PIN_SELECT */
2565 s
->latch
= s
->inputs
;
2569 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
2572 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
2574 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
2578 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
2579 s
->row_latch
= ~rows
;
2582 static uint32_t omap_mpuio_read(void *opaque
, target_phys_addr_t addr
)
2584 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2585 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2589 case 0x00: /* INPUT_LATCH */
2592 case 0x04: /* OUTPUT_REG */
2595 case 0x08: /* IO_CNTL */
2598 case 0x10: /* KBR_LATCH */
2599 return s
->row_latch
;
2601 case 0x14: /* KBC_REG */
2604 case 0x18: /* GPIO_EVENT_MODE_REG */
2607 case 0x1c: /* GPIO_INT_EDGE_REG */
2610 case 0x20: /* KBD_INT */
2611 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
2613 case 0x24: /* GPIO_INT */
2617 qemu_irq_lower(s
->irq
);
2620 case 0x28: /* KBD_MASKIT */
2623 case 0x2c: /* GPIO_MASKIT */
2626 case 0x30: /* GPIO_DEBOUNCING_REG */
2629 case 0x34: /* GPIO_LATCH_REG */
2637 static void omap_mpuio_write(void *opaque
, target_phys_addr_t addr
,
2640 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2641 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2646 case 0x04: /* OUTPUT_REG */
2647 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2649 while ((ln
= ffs(diff
))) {
2652 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2657 case 0x08: /* IO_CNTL */
2658 diff
= s
->outputs
& (s
->dir
^ value
);
2661 value
= s
->outputs
& ~s
->dir
;
2662 while ((ln
= ffs(diff
))) {
2665 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2670 case 0x14: /* KBC_REG */
2672 omap_mpuio_kbd_update(s
);
2675 case 0x18: /* GPIO_EVENT_MODE_REG */
2676 s
->event
= value
& 0x1f;
2679 case 0x1c: /* GPIO_INT_EDGE_REG */
2683 case 0x28: /* KBD_MASKIT */
2684 s
->kbd_mask
= value
& 1;
2685 omap_mpuio_kbd_update(s
);
2688 case 0x2c: /* GPIO_MASKIT */
2692 case 0x30: /* GPIO_DEBOUNCING_REG */
2693 s
->debounce
= value
& 0x1ff;
2696 case 0x00: /* INPUT_LATCH */
2697 case 0x10: /* KBR_LATCH */
2698 case 0x20: /* KBD_INT */
2699 case 0x24: /* GPIO_INT */
2700 case 0x34: /* GPIO_LATCH_REG */
2710 static CPUReadMemoryFunc
*omap_mpuio_readfn
[] = {
2711 omap_badwidth_read16
,
2713 omap_badwidth_read16
,
2716 static CPUWriteMemoryFunc
*omap_mpuio_writefn
[] = {
2717 omap_badwidth_write16
,
2719 omap_badwidth_write16
,
2722 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2734 s
->row_latch
= 0x1f;
2738 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2740 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2744 omap_mpuio_kbd_update(s
);
2747 struct omap_mpuio_s
*omap_mpuio_init(target_phys_addr_t base
,
2748 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2752 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*)
2753 qemu_mallocz(sizeof(struct omap_mpuio_s
));
2756 s
->kbd_irq
= kbd_int
;
2758 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2759 omap_mpuio_reset(s
);
2761 iomemtype
= cpu_register_io_memory(0, omap_mpuio_readfn
,
2762 omap_mpuio_writefn
, s
);
2763 cpu_register_physical_memory(base
, 0x800, iomemtype
);
2765 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_mpuio_onoff
, s
, 1)[0]);
2770 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2775 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2777 if (line
>= 16 || line
< 0)
2778 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
2779 s
->handler
[line
] = handler
;
2782 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2784 if (row
>= 5 || row
< 0)
2785 cpu_abort(cpu_single_env
, "%s: No key %i-%i\n",
2786 __FUNCTION__
, col
, row
);
2789 s
->buttons
[row
] |= 1 << col
;
2791 s
->buttons
[row
] &= ~(1 << col
);
2793 omap_mpuio_kbd_update(s
);
2796 /* General-Purpose I/O */
2797 struct omap_gpio_s
{
2800 qemu_irq handler
[16];
2811 static void omap_gpio_set(void *opaque
, int line
, int level
)
2813 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2814 uint16_t prev
= s
->inputs
;
2817 s
->inputs
|= 1 << line
;
2819 s
->inputs
&= ~(1 << line
);
2821 if (((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) &
2822 (1 << line
) & s
->dir
& ~s
->mask
) {
2823 s
->ints
|= 1 << line
;
2824 qemu_irq_raise(s
->irq
);
2828 static uint32_t omap_gpio_read(void *opaque
, target_phys_addr_t addr
)
2830 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2831 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2834 case 0x00: /* DATA_INPUT */
2835 return s
->inputs
& s
->pins
;
2837 case 0x04: /* DATA_OUTPUT */
2840 case 0x08: /* DIRECTION_CONTROL */
2843 case 0x0c: /* INTERRUPT_CONTROL */
2846 case 0x10: /* INTERRUPT_MASK */
2849 case 0x14: /* INTERRUPT_STATUS */
2852 case 0x18: /* PIN_CONTROL (not in OMAP310) */
2861 static void omap_gpio_write(void *opaque
, target_phys_addr_t addr
,
2864 struct omap_gpio_s
*s
= (struct omap_gpio_s
*) opaque
;
2865 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2870 case 0x00: /* DATA_INPUT */
2874 case 0x04: /* DATA_OUTPUT */
2875 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2877 while ((ln
= ffs(diff
))) {
2880 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2885 case 0x08: /* DIRECTION_CONTROL */
2886 diff
= s
->outputs
& (s
->dir
^ value
);
2889 value
= s
->outputs
& ~s
->dir
;
2890 while ((ln
= ffs(diff
))) {
2893 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2898 case 0x0c: /* INTERRUPT_CONTROL */
2902 case 0x10: /* INTERRUPT_MASK */
2906 case 0x14: /* INTERRUPT_STATUS */
2909 qemu_irq_lower(s
->irq
);
2912 case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */
2923 /* *Some* sources say the memory region is 32-bit. */
2924 static CPUReadMemoryFunc
*omap_gpio_readfn
[] = {
2925 omap_badwidth_read16
,
2927 omap_badwidth_read16
,
2930 static CPUWriteMemoryFunc
*omap_gpio_writefn
[] = {
2931 omap_badwidth_write16
,
2933 omap_badwidth_write16
,
2936 static void omap_gpio_reset(struct omap_gpio_s
*s
)
2947 struct omap_gpio_s
*omap_gpio_init(target_phys_addr_t base
,
2948 qemu_irq irq
, omap_clk clk
)
2951 struct omap_gpio_s
*s
= (struct omap_gpio_s
*)
2952 qemu_mallocz(sizeof(struct omap_gpio_s
));
2955 s
->in
= qemu_allocate_irqs(omap_gpio_set
, s
, 16);
2958 iomemtype
= cpu_register_io_memory(0, omap_gpio_readfn
,
2959 omap_gpio_writefn
, s
);
2960 cpu_register_physical_memory(base
, 0x1000, iomemtype
);
2965 qemu_irq
*omap_gpio_in_get(struct omap_gpio_s
*s
)
2970 void omap_gpio_out_set(struct omap_gpio_s
*s
, int line
, qemu_irq handler
)
2972 if (line
>= 16 || line
< 0)
2973 cpu_abort(cpu_single_env
, "%s: No GPIO line %i\n", __FUNCTION__
, line
);
2974 s
->handler
[line
] = handler
;
2977 /* MicroWire Interface */
2978 struct omap_uwire_s
{
2988 struct uwire_slave_s
*chip
[4];
2991 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
2993 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
2994 struct uwire_slave_s
*slave
= s
->chip
[chipselect
];
2996 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
2997 if (s
->control
& (1 << 12)) /* CS_CMD */
2998 if (slave
&& slave
->send
)
2999 slave
->send(slave
->opaque
,
3000 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
3001 s
->control
&= ~(1 << 14); /* CSRB */
3002 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3003 * a DRQ. When is the level IRQ supposed to be reset? */
3006 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
3007 if (s
->control
& (1 << 12)) /* CS_CMD */
3008 if (slave
&& slave
->receive
)
3009 s
->rxbuf
= slave
->receive(slave
->opaque
);
3010 s
->control
|= 1 << 15; /* RDRB */
3011 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3012 * a DRQ. When is the level IRQ supposed to be reset? */
3016 static uint32_t omap_uwire_read(void *opaque
, target_phys_addr_t addr
)
3018 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3019 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3022 case 0x00: /* RDR */
3023 s
->control
&= ~(1 << 15); /* RDRB */
3026 case 0x04: /* CSR */
3029 case 0x08: /* SR1 */
3031 case 0x0c: /* SR2 */
3033 case 0x10: /* SR3 */
3035 case 0x14: /* SR4 */
3037 case 0x18: /* SR5 */
3045 static void omap_uwire_write(void *opaque
, target_phys_addr_t addr
,
3048 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
3049 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3052 case 0x00: /* TDR */
3053 s
->txbuf
= value
; /* TD */
3054 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
3055 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
3056 (s
->control
& (1 << 12)))) { /* CS_CMD */
3057 s
->control
|= 1 << 14; /* CSRB */
3058 omap_uwire_transfer_start(s
);
3062 case 0x04: /* CSR */
3063 s
->control
= value
& 0x1fff;
3064 if (value
& (1 << 13)) /* START */
3065 omap_uwire_transfer_start(s
);
3068 case 0x08: /* SR1 */
3069 s
->setup
[0] = value
& 0x003f;
3072 case 0x0c: /* SR2 */
3073 s
->setup
[1] = value
& 0x0fc0;
3076 case 0x10: /* SR3 */
3077 s
->setup
[2] = value
& 0x0003;
3080 case 0x14: /* SR4 */
3081 s
->setup
[3] = value
& 0x0001;
3084 case 0x18: /* SR5 */
3085 s
->setup
[4] = value
& 0x000f;
3094 static CPUReadMemoryFunc
*omap_uwire_readfn
[] = {
3095 omap_badwidth_read16
,
3097 omap_badwidth_read16
,
3100 static CPUWriteMemoryFunc
*omap_uwire_writefn
[] = {
3101 omap_badwidth_write16
,
3103 omap_badwidth_write16
,
3106 static void omap_uwire_reset(struct omap_uwire_s
*s
)
3116 struct omap_uwire_s
*omap_uwire_init(target_phys_addr_t base
,
3117 qemu_irq
*irq
, qemu_irq dma
, omap_clk clk
)
3120 struct omap_uwire_s
*s
= (struct omap_uwire_s
*)
3121 qemu_mallocz(sizeof(struct omap_uwire_s
));
3126 omap_uwire_reset(s
);
3128 iomemtype
= cpu_register_io_memory(0, omap_uwire_readfn
,
3129 omap_uwire_writefn
, s
);
3130 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3135 void omap_uwire_attach(struct omap_uwire_s
*s
,
3136 struct uwire_slave_s
*slave
, int chipselect
)
3138 if (chipselect
< 0 || chipselect
> 3) {
3139 fprintf(stderr
, "%s: Bad chipselect %i\n", __FUNCTION__
, chipselect
);
3143 s
->chip
[chipselect
] = slave
;
3146 /* Pseudonoise Pulse-Width Light Modulator */
3147 static void omap_pwl_update(struct omap_mpu_state_s
*s
)
3149 int output
= (s
->pwl
.clk
&& s
->pwl
.enable
) ? s
->pwl
.level
: 0;
3151 if (output
!= s
->pwl
.output
) {
3152 s
->pwl
.output
= output
;
3153 printf("%s: Backlight now at %i/256\n", __FUNCTION__
, output
);
3157 static uint32_t omap_pwl_read(void *opaque
, target_phys_addr_t addr
)
3159 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3160 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3163 case 0x00: /* PWL_LEVEL */
3164 return s
->pwl
.level
;
3165 case 0x04: /* PWL_CTRL */
3166 return s
->pwl
.enable
;
3172 static void omap_pwl_write(void *opaque
, target_phys_addr_t addr
,
3175 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3176 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3179 case 0x00: /* PWL_LEVEL */
3180 s
->pwl
.level
= value
;
3183 case 0x04: /* PWL_CTRL */
3184 s
->pwl
.enable
= value
& 1;
3193 static CPUReadMemoryFunc
*omap_pwl_readfn
[] = {
3195 omap_badwidth_read8
,
3196 omap_badwidth_read8
,
3199 static CPUWriteMemoryFunc
*omap_pwl_writefn
[] = {
3201 omap_badwidth_write8
,
3202 omap_badwidth_write8
,
3205 static void omap_pwl_reset(struct omap_mpu_state_s
*s
)
3214 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
3216 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3222 static void omap_pwl_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3229 iomemtype
= cpu_register_io_memory(0, omap_pwl_readfn
,
3230 omap_pwl_writefn
, s
);
3231 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3233 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_pwl_clk_update
, s
, 1)[0]);
3236 /* Pulse-Width Tone module */
3237 static uint32_t omap_pwt_read(void *opaque
, target_phys_addr_t addr
)
3239 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3240 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3243 case 0x00: /* FRC */
3245 case 0x04: /* VCR */
3247 case 0x08: /* GCR */
3254 static void omap_pwt_write(void *opaque
, target_phys_addr_t addr
,
3257 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
3258 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3261 case 0x00: /* FRC */
3262 s
->pwt
.frc
= value
& 0x3f;
3264 case 0x04: /* VRC */
3265 if ((value
^ s
->pwt
.vrc
) & 1) {
3267 printf("%s: %iHz buzz on\n", __FUNCTION__
, (int)
3268 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
3269 ((omap_clk_getrate(s
->pwt
.clk
) >> 3) /
3270 /* Pre-multiplexer divider */
3271 ((s
->pwt
.gcr
& 2) ? 1 : 154) /
3272 /* Octave multiplexer */
3273 (2 << (value
& 3)) *
3274 /* 101/107 divider */
3275 ((value
& (1 << 2)) ? 101 : 107) *
3277 ((value
& (1 << 3)) ? 49 : 55) *
3279 ((value
& (1 << 4)) ? 50 : 63) *
3280 /* 80/127 divider */
3281 ((value
& (1 << 5)) ? 80 : 127) /
3282 (107 * 55 * 63 * 127)));
3284 printf("%s: silence!\n", __FUNCTION__
);
3286 s
->pwt
.vrc
= value
& 0x7f;
3288 case 0x08: /* GCR */
3289 s
->pwt
.gcr
= value
& 3;
3297 static CPUReadMemoryFunc
*omap_pwt_readfn
[] = {
3299 omap_badwidth_read8
,
3300 omap_badwidth_read8
,
3303 static CPUWriteMemoryFunc
*omap_pwt_writefn
[] = {
3305 omap_badwidth_write8
,
3306 omap_badwidth_write8
,
3309 static void omap_pwt_reset(struct omap_mpu_state_s
*s
)
3316 static void omap_pwt_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
3324 iomemtype
= cpu_register_io_memory(0, omap_pwt_readfn
,
3325 omap_pwt_writefn
, s
);
3326 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3329 /* Real-time Clock module */
3345 struct tm current_tm
;
3350 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
3352 /* s->alarm is level-triggered */
3353 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
3356 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
3358 s
->alarm_ti
= mktimegm(&s
->alarm_tm
);
3359 if (s
->alarm_ti
== -1)
3360 printf("%s: conversion failed\n", __FUNCTION__
);
3363 static inline uint8_t omap_rtc_bcd(int num
)
3365 return ((num
/ 10) << 4) | (num
% 10);
3368 static inline int omap_rtc_bin(uint8_t num
)
3370 return (num
& 15) + 10 * (num
>> 4);
3373 static uint32_t omap_rtc_read(void *opaque
, target_phys_addr_t addr
)
3375 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3376 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3380 case 0x00: /* SECONDS_REG */
3381 return omap_rtc_bcd(s
->current_tm
.tm_sec
);
3383 case 0x04: /* MINUTES_REG */
3384 return omap_rtc_bcd(s
->current_tm
.tm_min
);
3386 case 0x08: /* HOURS_REG */
3388 return ((s
->current_tm
.tm_hour
> 11) << 7) |
3389 omap_rtc_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
3391 return omap_rtc_bcd(s
->current_tm
.tm_hour
);
3393 case 0x0c: /* DAYS_REG */
3394 return omap_rtc_bcd(s
->current_tm
.tm_mday
);
3396 case 0x10: /* MONTHS_REG */
3397 return omap_rtc_bcd(s
->current_tm
.tm_mon
+ 1);
3399 case 0x14: /* YEARS_REG */
3400 return omap_rtc_bcd(s
->current_tm
.tm_year
% 100);
3402 case 0x18: /* WEEK_REG */
3403 return s
->current_tm
.tm_wday
;
3405 case 0x20: /* ALARM_SECONDS_REG */
3406 return omap_rtc_bcd(s
->alarm_tm
.tm_sec
);
3408 case 0x24: /* ALARM_MINUTES_REG */
3409 return omap_rtc_bcd(s
->alarm_tm
.tm_min
);
3411 case 0x28: /* ALARM_HOURS_REG */
3413 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
3414 omap_rtc_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
3416 return omap_rtc_bcd(s
->alarm_tm
.tm_hour
);
3418 case 0x2c: /* ALARM_DAYS_REG */
3419 return omap_rtc_bcd(s
->alarm_tm
.tm_mday
);
3421 case 0x30: /* ALARM_MONTHS_REG */
3422 return omap_rtc_bcd(s
->alarm_tm
.tm_mon
+ 1);
3424 case 0x34: /* ALARM_YEARS_REG */
3425 return omap_rtc_bcd(s
->alarm_tm
.tm_year
% 100);
3427 case 0x40: /* RTC_CTRL_REG */
3428 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
3429 (s
->round
<< 1) | s
->running
;
3431 case 0x44: /* RTC_STATUS_REG */
3436 case 0x48: /* RTC_INTERRUPTS_REG */
3437 return s
->interrupts
;
3439 case 0x4c: /* RTC_COMP_LSB_REG */
3440 return ((uint16_t) s
->comp_reg
) & 0xff;
3442 case 0x50: /* RTC_COMP_MSB_REG */
3443 return ((uint16_t) s
->comp_reg
) >> 8;
3450 static void omap_rtc_write(void *opaque
, target_phys_addr_t addr
,
3453 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
3454 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3459 case 0x00: /* SECONDS_REG */
3461 printf("RTC SEC_REG <-- %02x\n", value
);
3463 s
->ti
-= s
->current_tm
.tm_sec
;
3464 s
->ti
+= omap_rtc_bin(value
);
3467 case 0x04: /* MINUTES_REG */
3469 printf("RTC MIN_REG <-- %02x\n", value
);
3471 s
->ti
-= s
->current_tm
.tm_min
* 60;
3472 s
->ti
+= omap_rtc_bin(value
) * 60;
3475 case 0x08: /* HOURS_REG */
3477 printf("RTC HRS_REG <-- %02x\n", value
);
3479 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
3481 s
->ti
+= (omap_rtc_bin(value
& 0x3f) & 12) * 3600;
3482 s
->ti
+= ((value
>> 7) & 1) * 43200;
3484 s
->ti
+= omap_rtc_bin(value
& 0x3f) * 3600;
3487 case 0x0c: /* DAYS_REG */
3489 printf("RTC DAY_REG <-- %02x\n", value
);
3491 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
3492 s
->ti
+= omap_rtc_bin(value
) * 86400;
3495 case 0x10: /* MONTHS_REG */
3497 printf("RTC MTH_REG <-- %02x\n", value
);
3499 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3500 new_tm
.tm_mon
= omap_rtc_bin(value
);
3501 ti
[0] = mktimegm(&s
->current_tm
);
3502 ti
[1] = mktimegm(&new_tm
);
3504 if (ti
[0] != -1 && ti
[1] != -1) {
3508 /* A less accurate version */
3509 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
3510 s
->ti
+= omap_rtc_bin(value
) * 2592000;
3514 case 0x14: /* YEARS_REG */
3516 printf("RTC YRS_REG <-- %02x\n", value
);
3518 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
3519 new_tm
.tm_year
+= omap_rtc_bin(value
) - (new_tm
.tm_year
% 100);
3520 ti
[0] = mktimegm(&s
->current_tm
);
3521 ti
[1] = mktimegm(&new_tm
);
3523 if (ti
[0] != -1 && ti
[1] != -1) {
3527 /* A less accurate version */
3528 s
->ti
-= (s
->current_tm
.tm_year
% 100) * 31536000;
3529 s
->ti
+= omap_rtc_bin(value
) * 31536000;
3533 case 0x18: /* WEEK_REG */
3534 return; /* Ignored */
3536 case 0x20: /* ALARM_SECONDS_REG */
3538 printf("ALM SEC_REG <-- %02x\n", value
);
3540 s
->alarm_tm
.tm_sec
= omap_rtc_bin(value
);
3541 omap_rtc_alarm_update(s
);
3544 case 0x24: /* ALARM_MINUTES_REG */
3546 printf("ALM MIN_REG <-- %02x\n", value
);
3548 s
->alarm_tm
.tm_min
= omap_rtc_bin(value
);
3549 omap_rtc_alarm_update(s
);
3552 case 0x28: /* ALARM_HOURS_REG */
3554 printf("ALM HRS_REG <-- %02x\n", value
);
3557 s
->alarm_tm
.tm_hour
=
3558 ((omap_rtc_bin(value
& 0x3f)) % 12) +
3559 ((value
>> 7) & 1) * 12;
3561 s
->alarm_tm
.tm_hour
= omap_rtc_bin(value
);
3562 omap_rtc_alarm_update(s
);
3565 case 0x2c: /* ALARM_DAYS_REG */
3567 printf("ALM DAY_REG <-- %02x\n", value
);
3569 s
->alarm_tm
.tm_mday
= omap_rtc_bin(value
);
3570 omap_rtc_alarm_update(s
);
3573 case 0x30: /* ALARM_MONTHS_REG */
3575 printf("ALM MON_REG <-- %02x\n", value
);
3577 s
->alarm_tm
.tm_mon
= omap_rtc_bin(value
);
3578 omap_rtc_alarm_update(s
);
3581 case 0x34: /* ALARM_YEARS_REG */
3583 printf("ALM YRS_REG <-- %02x\n", value
);
3585 s
->alarm_tm
.tm_year
= omap_rtc_bin(value
);
3586 omap_rtc_alarm_update(s
);
3589 case 0x40: /* RTC_CTRL_REG */
3591 printf("RTC CONTROL <-- %02x\n", value
);
3593 s
->pm_am
= (value
>> 3) & 1;
3594 s
->auto_comp
= (value
>> 2) & 1;
3595 s
->round
= (value
>> 1) & 1;
3596 s
->running
= value
& 1;
3598 s
->status
|= s
->running
<< 1;
3601 case 0x44: /* RTC_STATUS_REG */
3603 printf("RTC STATUSL <-- %02x\n", value
);
3605 s
->status
&= ~((value
& 0xc0) ^ 0x80);
3606 omap_rtc_interrupts_update(s
);
3609 case 0x48: /* RTC_INTERRUPTS_REG */
3611 printf("RTC INTRS <-- %02x\n", value
);
3613 s
->interrupts
= value
;
3616 case 0x4c: /* RTC_COMP_LSB_REG */
3618 printf("RTC COMPLSB <-- %02x\n", value
);
3620 s
->comp_reg
&= 0xff00;
3621 s
->comp_reg
|= 0x00ff & value
;
3624 case 0x50: /* RTC_COMP_MSB_REG */
3626 printf("RTC COMPMSB <-- %02x\n", value
);
3628 s
->comp_reg
&= 0x00ff;
3629 s
->comp_reg
|= 0xff00 & (value
<< 8);
3638 static CPUReadMemoryFunc
*omap_rtc_readfn
[] = {
3640 omap_badwidth_read8
,
3641 omap_badwidth_read8
,
3644 static CPUWriteMemoryFunc
*omap_rtc_writefn
[] = {
3646 omap_badwidth_write8
,
3647 omap_badwidth_write8
,
3650 static void omap_rtc_tick(void *opaque
)
3652 struct omap_rtc_s
*s
= opaque
;
3655 /* Round to nearest full minute. */
3656 if (s
->current_tm
.tm_sec
< 30)
3657 s
->ti
-= s
->current_tm
.tm_sec
;
3659 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
3664 memcpy(&s
->current_tm
, localtime(&s
->ti
), sizeof(s
->current_tm
));
3666 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
3668 omap_rtc_interrupts_update(s
);
3671 if (s
->interrupts
& 0x04)
3672 switch (s
->interrupts
& 3) {
3675 qemu_irq_pulse(s
->irq
);
3678 if (s
->current_tm
.tm_sec
)
3681 qemu_irq_pulse(s
->irq
);
3684 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
3687 qemu_irq_pulse(s
->irq
);
3690 if (s
->current_tm
.tm_sec
||
3691 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
3694 qemu_irq_pulse(s
->irq
);
3704 * Every full hour add a rough approximation of the compensation
3705 * register to the 32kHz Timer (which drives the RTC) value.
3707 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
3708 s
->tick
+= s
->comp_reg
* 1000 / 32768;
3710 qemu_mod_timer(s
->clk
, s
->tick
);
3713 static void omap_rtc_reset(struct omap_rtc_s
*s
)
3723 s
->tick
= qemu_get_clock(rt_clock
);
3724 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
3725 s
->alarm_tm
.tm_mday
= 0x01;
3727 qemu_get_timedate(&tm
, 0);
3728 s
->ti
= mktimegm(&tm
);
3730 omap_rtc_alarm_update(s
);
3734 struct omap_rtc_s
*omap_rtc_init(target_phys_addr_t base
,
3735 qemu_irq
*irq
, omap_clk clk
)
3738 struct omap_rtc_s
*s
= (struct omap_rtc_s
*)
3739 qemu_mallocz(sizeof(struct omap_rtc_s
));
3743 s
->clk
= qemu_new_timer(rt_clock
, omap_rtc_tick
, s
);
3747 iomemtype
= cpu_register_io_memory(0, omap_rtc_readfn
,
3748 omap_rtc_writefn
, s
);
3749 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3754 /* Multi-channel Buffered Serial Port interfaces */
3755 struct omap_mcbsp_s
{
3774 struct i2s_codec_s
*codec
;
3775 QEMUTimer
*source_timer
;
3776 QEMUTimer
*sink_timer
;
3779 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
3783 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
3785 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
3788 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
3796 qemu_irq_pulse(s
->rxirq
);
3798 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
3800 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
3803 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
3811 qemu_irq_pulse(s
->txirq
);
3814 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
3816 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
3817 s
->spcr
[0] |= 1 << 2; /* RFULL */
3818 s
->spcr
[0] |= 1 << 1; /* RRDY */
3819 qemu_irq_raise(s
->rxdrq
);
3820 omap_mcbsp_intr_update(s
);
3823 static void omap_mcbsp_source_tick(void *opaque
)
3825 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3826 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3831 printf("%s: Rx FIFO overrun\n", __FUNCTION__
);
3833 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
3835 omap_mcbsp_rx_newdata(s
);
3836 qemu_mod_timer(s
->source_timer
, qemu_get_clock(vm_clock
) + ticks_per_sec
);
3839 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
3841 if (!s
->codec
|| !s
->codec
->rts
)
3842 omap_mcbsp_source_tick(s
);
3843 else if (s
->codec
->in
.len
) {
3844 s
->rx_req
= s
->codec
->in
.len
;
3845 omap_mcbsp_rx_newdata(s
);
3849 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
3851 qemu_del_timer(s
->source_timer
);
3854 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
3856 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
3857 qemu_irq_lower(s
->rxdrq
);
3858 omap_mcbsp_intr_update(s
);
3861 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
3863 s
->spcr
[1] |= 1 << 1; /* XRDY */
3864 qemu_irq_raise(s
->txdrq
);
3865 omap_mcbsp_intr_update(s
);
3868 static void omap_mcbsp_sink_tick(void *opaque
)
3870 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3871 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3876 printf("%s: Tx FIFO underrun\n", __FUNCTION__
);
3878 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
3880 omap_mcbsp_tx_newdata(s
);
3881 qemu_mod_timer(s
->sink_timer
, qemu_get_clock(vm_clock
) + ticks_per_sec
);
3884 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
3886 if (!s
->codec
|| !s
->codec
->cts
)
3887 omap_mcbsp_sink_tick(s
);
3888 else if (s
->codec
->out
.size
) {
3889 s
->tx_req
= s
->codec
->out
.size
;
3890 omap_mcbsp_tx_newdata(s
);
3894 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
3896 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
3897 qemu_irq_lower(s
->txdrq
);
3898 omap_mcbsp_intr_update(s
);
3899 if (s
->codec
&& s
->codec
->cts
)
3900 s
->codec
->tx_swallow(s
->codec
->opaque
);
3903 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
3906 omap_mcbsp_tx_done(s
);
3907 qemu_del_timer(s
->sink_timer
);
3910 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
3912 int prev_rx_rate
, prev_tx_rate
;
3913 int rx_rate
= 0, tx_rate
= 0;
3914 int cpu_rate
= 1500000; /* XXX */
3916 /* TODO: check CLKSTP bit */
3917 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3918 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3919 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3920 (s
->pcr
& (1 << 8))) { /* CLKRM */
3921 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3922 rx_rate
= cpu_rate
/
3923 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3926 rx_rate
= s
->codec
->rx_rate
;
3929 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3930 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3931 (s
->pcr
& (1 << 9))) { /* CLKXM */
3932 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3933 tx_rate
= cpu_rate
/
3934 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3937 tx_rate
= s
->codec
->tx_rate
;
3940 prev_tx_rate
= s
->tx_rate
;
3941 prev_rx_rate
= s
->rx_rate
;
3942 s
->tx_rate
= tx_rate
;
3943 s
->rx_rate
= rx_rate
;
3946 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3948 if (!prev_tx_rate
&& tx_rate
)
3949 omap_mcbsp_tx_start(s
);
3950 else if (s
->tx_rate
&& !tx_rate
)
3951 omap_mcbsp_tx_stop(s
);
3953 if (!prev_rx_rate
&& rx_rate
)
3954 omap_mcbsp_rx_start(s
);
3955 else if (prev_tx_rate
&& !tx_rate
)
3956 omap_mcbsp_rx_stop(s
);
3959 static uint32_t omap_mcbsp_read(void *opaque
, target_phys_addr_t addr
)
3961 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3962 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3966 case 0x00: /* DRR2 */
3967 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
3970 case 0x02: /* DRR1 */
3971 if (s
->rx_req
< 2) {
3972 printf("%s: Rx FIFO underrun\n", __FUNCTION__
);
3973 omap_mcbsp_rx_done(s
);
3976 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
3977 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
3978 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
3979 s
->codec
->in
.len
-= 2;
3983 omap_mcbsp_rx_done(s
);
3988 case 0x04: /* DXR2 */
3989 case 0x06: /* DXR1 */
3992 case 0x08: /* SPCR2 */
3994 case 0x0a: /* SPCR1 */
3996 case 0x0c: /* RCR2 */
3998 case 0x0e: /* RCR1 */
4000 case 0x10: /* XCR2 */
4002 case 0x12: /* XCR1 */
4004 case 0x14: /* SRGR2 */
4006 case 0x16: /* SRGR1 */
4008 case 0x18: /* MCR2 */
4010 case 0x1a: /* MCR1 */
4012 case 0x1c: /* RCERA */
4014 case 0x1e: /* RCERB */
4016 case 0x20: /* XCERA */
4018 case 0x22: /* XCERB */
4020 case 0x24: /* PCR0 */
4022 case 0x26: /* RCERC */
4024 case 0x28: /* RCERD */
4026 case 0x2a: /* XCERC */
4028 case 0x2c: /* XCERD */
4030 case 0x2e: /* RCERE */
4032 case 0x30: /* RCERF */
4034 case 0x32: /* XCERE */
4036 case 0x34: /* XCERF */
4038 case 0x36: /* RCERG */
4040 case 0x38: /* RCERH */
4042 case 0x3a: /* XCERG */
4044 case 0x3c: /* XCERH */
4052 static void omap_mcbsp_writeh(void *opaque
, target_phys_addr_t addr
,
4055 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4056 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4059 case 0x00: /* DRR2 */
4060 case 0x02: /* DRR1 */
4064 case 0x04: /* DXR2 */
4065 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
4068 case 0x06: /* DXR1 */
4069 if (s
->tx_req
> 1) {
4071 if (s
->codec
&& s
->codec
->cts
) {
4072 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
4073 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
4076 omap_mcbsp_tx_done(s
);
4078 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4081 case 0x08: /* SPCR2 */
4082 s
->spcr
[1] &= 0x0002;
4083 s
->spcr
[1] |= 0x03f9 & value
;
4084 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
4085 if (~value
& 1) /* XRST */
4087 omap_mcbsp_req_update(s
);
4089 case 0x0a: /* SPCR1 */
4090 s
->spcr
[0] &= 0x0006;
4091 s
->spcr
[0] |= 0xf8f9 & value
;
4092 if (value
& (1 << 15)) /* DLB */
4093 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__
);
4094 if (~value
& 1) { /* RRST */
4097 omap_mcbsp_rx_done(s
);
4099 omap_mcbsp_req_update(s
);
4102 case 0x0c: /* RCR2 */
4103 s
->rcr
[1] = value
& 0xffff;
4105 case 0x0e: /* RCR1 */
4106 s
->rcr
[0] = value
& 0x7fe0;
4108 case 0x10: /* XCR2 */
4109 s
->xcr
[1] = value
& 0xffff;
4111 case 0x12: /* XCR1 */
4112 s
->xcr
[0] = value
& 0x7fe0;
4114 case 0x14: /* SRGR2 */
4115 s
->srgr
[1] = value
& 0xffff;
4116 omap_mcbsp_req_update(s
);
4118 case 0x16: /* SRGR1 */
4119 s
->srgr
[0] = value
& 0xffff;
4120 omap_mcbsp_req_update(s
);
4122 case 0x18: /* MCR2 */
4123 s
->mcr
[1] = value
& 0x03e3;
4124 if (value
& 3) /* XMCM */
4125 printf("%s: Tx channel selection mode enable attempt\n",
4128 case 0x1a: /* MCR1 */
4129 s
->mcr
[0] = value
& 0x03e1;
4130 if (value
& 1) /* RMCM */
4131 printf("%s: Rx channel selection mode enable attempt\n",
4134 case 0x1c: /* RCERA */
4135 s
->rcer
[0] = value
& 0xffff;
4137 case 0x1e: /* RCERB */
4138 s
->rcer
[1] = value
& 0xffff;
4140 case 0x20: /* XCERA */
4141 s
->xcer
[0] = value
& 0xffff;
4143 case 0x22: /* XCERB */
4144 s
->xcer
[1] = value
& 0xffff;
4146 case 0x24: /* PCR0 */
4147 s
->pcr
= value
& 0x7faf;
4149 case 0x26: /* RCERC */
4150 s
->rcer
[2] = value
& 0xffff;
4152 case 0x28: /* RCERD */
4153 s
->rcer
[3] = value
& 0xffff;
4155 case 0x2a: /* XCERC */
4156 s
->xcer
[2] = value
& 0xffff;
4158 case 0x2c: /* XCERD */
4159 s
->xcer
[3] = value
& 0xffff;
4161 case 0x2e: /* RCERE */
4162 s
->rcer
[4] = value
& 0xffff;
4164 case 0x30: /* RCERF */
4165 s
->rcer
[5] = value
& 0xffff;
4167 case 0x32: /* XCERE */
4168 s
->xcer
[4] = value
& 0xffff;
4170 case 0x34: /* XCERF */
4171 s
->xcer
[5] = value
& 0xffff;
4173 case 0x36: /* RCERG */
4174 s
->rcer
[6] = value
& 0xffff;
4176 case 0x38: /* RCERH */
4177 s
->rcer
[7] = value
& 0xffff;
4179 case 0x3a: /* XCERG */
4180 s
->xcer
[6] = value
& 0xffff;
4182 case 0x3c: /* XCERH */
4183 s
->xcer
[7] = value
& 0xffff;
4190 static void omap_mcbsp_writew(void *opaque
, target_phys_addr_t addr
,
4193 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4194 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4196 if (offset
== 0x04) { /* DXR */
4197 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
4199 if (s
->tx_req
> 3) {
4201 if (s
->codec
&& s
->codec
->cts
) {
4202 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4203 (value
>> 24) & 0xff;
4204 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4205 (value
>> 16) & 0xff;
4206 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4207 (value
>> 8) & 0xff;
4208 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
4209 (value
>> 0) & 0xff;
4212 omap_mcbsp_tx_done(s
);
4214 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
4218 omap_badwidth_write16(opaque
, addr
, value
);
4221 static CPUReadMemoryFunc
*omap_mcbsp_readfn
[] = {
4222 omap_badwidth_read16
,
4224 omap_badwidth_read16
,
4227 static CPUWriteMemoryFunc
*omap_mcbsp_writefn
[] = {
4228 omap_badwidth_write16
,
4233 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
4235 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
4236 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
4237 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
4238 s
->srgr
[0] = 0x0001;
4239 s
->srgr
[1] = 0x2000;
4240 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
4241 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
4242 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
4243 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
4248 qemu_del_timer(s
->source_timer
);
4249 qemu_del_timer(s
->sink_timer
);
4252 struct omap_mcbsp_s
*omap_mcbsp_init(target_phys_addr_t base
,
4253 qemu_irq
*irq
, qemu_irq
*dma
, omap_clk clk
)
4256 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*)
4257 qemu_mallocz(sizeof(struct omap_mcbsp_s
));
4263 s
->sink_timer
= qemu_new_timer(vm_clock
, omap_mcbsp_sink_tick
, s
);
4264 s
->source_timer
= qemu_new_timer(vm_clock
, omap_mcbsp_source_tick
, s
);
4265 omap_mcbsp_reset(s
);
4267 iomemtype
= cpu_register_io_memory(0, omap_mcbsp_readfn
,
4268 omap_mcbsp_writefn
, s
);
4269 cpu_register_physical_memory(base
, 0x800, iomemtype
);
4274 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
4276 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4279 s
->rx_req
= s
->codec
->in
.len
;
4280 omap_mcbsp_rx_newdata(s
);
4284 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
4286 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
4289 s
->tx_req
= s
->codec
->out
.size
;
4290 omap_mcbsp_tx_newdata(s
);
4294 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, struct i2s_codec_s
*slave
)
4297 slave
->rx_swallow
= qemu_allocate_irqs(omap_mcbsp_i2s_swallow
, s
, 1)[0];
4298 slave
->tx_start
= qemu_allocate_irqs(omap_mcbsp_i2s_start
, s
, 1)[0];
4301 /* LED Pulse Generators */
4313 static void omap_lpg_tick(void *opaque
)
4315 struct omap_lpg_s
*s
= opaque
;
4318 qemu_mod_timer(s
->tm
, qemu_get_clock(rt_clock
) + s
->period
- s
->on
);
4320 qemu_mod_timer(s
->tm
, qemu_get_clock(rt_clock
) + s
->on
);
4322 s
->cycle
= !s
->cycle
;
4323 printf("%s: LED is %s\n", __FUNCTION__
, s
->cycle
? "on" : "off");
4326 static void omap_lpg_update(struct omap_lpg_s
*s
)
4328 int64_t on
, period
= 1, ticks
= 1000;
4329 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
4331 if (~s
->control
& (1 << 6)) /* LPGRES */
4333 else if (s
->control
& (1 << 7)) /* PERM_ON */
4336 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
4338 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
4339 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
4342 qemu_del_timer(s
->tm
);
4343 if (on
== period
&& s
->on
< s
->period
)
4344 printf("%s: LED is on\n", __FUNCTION__
);
4345 else if (on
== 0 && s
->on
)
4346 printf("%s: LED is off\n", __FUNCTION__
);
4347 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
4359 static void omap_lpg_reset(struct omap_lpg_s
*s
)
4367 static uint32_t omap_lpg_read(void *opaque
, target_phys_addr_t addr
)
4369 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4370 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4373 case 0x00: /* LCR */
4376 case 0x04: /* PMR */
4384 static void omap_lpg_write(void *opaque
, target_phys_addr_t addr
,
4387 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4388 int offset
= addr
& OMAP_MPUI_REG_MASK
;
4391 case 0x00: /* LCR */
4392 if (~value
& (1 << 6)) /* LPGRES */
4394 s
->control
= value
& 0xff;
4398 case 0x04: /* PMR */
4399 s
->power
= value
& 0x01;
4409 static CPUReadMemoryFunc
*omap_lpg_readfn
[] = {
4411 omap_badwidth_read8
,
4412 omap_badwidth_read8
,
4415 static CPUWriteMemoryFunc
*omap_lpg_writefn
[] = {
4417 omap_badwidth_write8
,
4418 omap_badwidth_write8
,
4421 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
4423 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
4429 struct omap_lpg_s
*omap_lpg_init(target_phys_addr_t base
, omap_clk clk
)
4432 struct omap_lpg_s
*s
= (struct omap_lpg_s
*)
4433 qemu_mallocz(sizeof(struct omap_lpg_s
));
4435 s
->tm
= qemu_new_timer(rt_clock
, omap_lpg_tick
, s
);
4439 iomemtype
= cpu_register_io_memory(0, omap_lpg_readfn
,
4440 omap_lpg_writefn
, s
);
4441 cpu_register_physical_memory(base
, 0x800, iomemtype
);
4443 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_lpg_clk_update
, s
, 1)[0]);
4448 /* MPUI Peripheral Bridge configuration */
4449 static uint32_t omap_mpui_io_read(void *opaque
, target_phys_addr_t addr
)
4451 if (addr
== OMAP_MPUI_BASE
) /* CMR */
4458 static CPUReadMemoryFunc
*omap_mpui_io_readfn
[] = {
4459 omap_badwidth_read16
,
4461 omap_badwidth_read16
,
4464 static CPUWriteMemoryFunc
*omap_mpui_io_writefn
[] = {
4465 omap_badwidth_write16
,
4466 omap_badwidth_write16
,
4467 omap_badwidth_write16
,
4470 static void omap_setup_mpui_io(struct omap_mpu_state_s
*mpu
)
4472 int iomemtype
= cpu_register_io_memory(0, omap_mpui_io_readfn
,
4473 omap_mpui_io_writefn
, mpu
);
4474 cpu_register_physical_memory(OMAP_MPUI_BASE
, 0x7fff, iomemtype
);
4477 /* General chip reset */
4478 static void omap1_mpu_reset(void *opaque
)
4480 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4482 omap_inth_reset(mpu
->ih
[0]);
4483 omap_inth_reset(mpu
->ih
[1]);
4484 omap_dma_reset(mpu
->dma
);
4485 omap_mpu_timer_reset(mpu
->timer
[0]);
4486 omap_mpu_timer_reset(mpu
->timer
[1]);
4487 omap_mpu_timer_reset(mpu
->timer
[2]);
4488 omap_wd_timer_reset(mpu
->wdt
);
4489 omap_os_timer_reset(mpu
->os_timer
);
4490 omap_lcdc_reset(mpu
->lcd
);
4491 omap_ulpd_pm_reset(mpu
);
4492 omap_pin_cfg_reset(mpu
);
4493 omap_mpui_reset(mpu
);
4494 omap_tipb_bridge_reset(mpu
->private_tipb
);
4495 omap_tipb_bridge_reset(mpu
->public_tipb
);
4496 omap_dpll_reset(&mpu
->dpll
[0]);
4497 omap_dpll_reset(&mpu
->dpll
[1]);
4498 omap_dpll_reset(&mpu
->dpll
[2]);
4499 omap_uart_reset(mpu
->uart
[0]);
4500 omap_uart_reset(mpu
->uart
[1]);
4501 omap_uart_reset(mpu
->uart
[2]);
4502 omap_mmc_reset(mpu
->mmc
);
4503 omap_mpuio_reset(mpu
->mpuio
);
4504 omap_gpio_reset(mpu
->gpio
);
4505 omap_uwire_reset(mpu
->microwire
);
4506 omap_pwl_reset(mpu
);
4507 omap_pwt_reset(mpu
);
4508 omap_i2c_reset(mpu
->i2c
[0]);
4509 omap_rtc_reset(mpu
->rtc
);
4510 omap_mcbsp_reset(mpu
->mcbsp1
);
4511 omap_mcbsp_reset(mpu
->mcbsp2
);
4512 omap_mcbsp_reset(mpu
->mcbsp3
);
4513 omap_lpg_reset(mpu
->led
[0]);
4514 omap_lpg_reset(mpu
->led
[1]);
4515 omap_clkm_reset(mpu
);
4516 cpu_reset(mpu
->env
);
4519 static const struct omap_map_s
{
4520 target_phys_addr_t phys_dsp
;
4521 target_phys_addr_t phys_mpu
;
4524 } omap15xx_dsp_mm
[] = {
4526 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
4527 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
4528 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
4529 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
4530 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
4531 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
4532 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
4533 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
4534 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
4535 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
4536 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
4537 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
4538 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
4539 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
4540 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
4541 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
4542 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
4544 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
4549 static void omap_setup_dsp_mapping(const struct omap_map_s
*map
)
4553 for (; map
->phys_dsp
; map
++) {
4554 io
= cpu_get_physical_page_desc(map
->phys_mpu
);
4556 cpu_register_physical_memory(map
->phys_dsp
, map
->size
, io
);
4560 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
4562 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
4564 if (mpu
->env
->halted
)
4565 cpu_interrupt(mpu
->env
, CPU_INTERRUPT_EXITTB
);
4568 static const struct dma_irq_map omap1_dma_irq_map
[] = {
4569 { 0, OMAP_INT_DMA_CH0_6
},
4570 { 0, OMAP_INT_DMA_CH1_7
},
4571 { 0, OMAP_INT_DMA_CH2_8
},
4572 { 0, OMAP_INT_DMA_CH3
},
4573 { 0, OMAP_INT_DMA_CH4
},
4574 { 0, OMAP_INT_DMA_CH5
},
4575 { 1, OMAP_INT_1610_DMA_CH6
},
4576 { 1, OMAP_INT_1610_DMA_CH7
},
4577 { 1, OMAP_INT_1610_DMA_CH8
},
4578 { 1, OMAP_INT_1610_DMA_CH9
},
4579 { 1, OMAP_INT_1610_DMA_CH10
},
4580 { 1, OMAP_INT_1610_DMA_CH11
},
4581 { 1, OMAP_INT_1610_DMA_CH12
},
4582 { 1, OMAP_INT_1610_DMA_CH13
},
4583 { 1, OMAP_INT_1610_DMA_CH14
},
4584 { 1, OMAP_INT_1610_DMA_CH15
}
4587 /* DMA ports for OMAP1 */
4588 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
4589 target_phys_addr_t addr
)
4591 return addr
>= OMAP_EMIFF_BASE
&& addr
< OMAP_EMIFF_BASE
+ s
->sdram_size
;
4594 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
4595 target_phys_addr_t addr
)
4597 return addr
>= OMAP_EMIFS_BASE
&& addr
< OMAP_EMIFF_BASE
;
4600 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
4601 target_phys_addr_t addr
)
4603 return addr
>= OMAP_IMIF_BASE
&& addr
< OMAP_IMIF_BASE
+ s
->sram_size
;
4606 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
4607 target_phys_addr_t addr
)
4609 return addr
>= 0xfffb0000 && addr
< 0xffff0000;
4612 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
4613 target_phys_addr_t addr
)
4615 return addr
>= OMAP_LOCALBUS_BASE
&& addr
< OMAP_LOCALBUS_BASE
+ 0x1000000;
4618 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
4619 target_phys_addr_t addr
)
4621 return addr
>= 0xe1010000 && addr
< 0xe1020004;
4624 struct omap_mpu_state_s
*omap310_mpu_init(unsigned long sdram_size
,
4625 DisplayState
*ds
, const char *core
)
4628 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*)
4629 qemu_mallocz(sizeof(struct omap_mpu_state_s
));
4630 ram_addr_t imif_base
, emiff_base
;
4632 qemu_irq dma_irqs
[6];
4639 s
->mpu_model
= omap310
;
4640 s
->env
= cpu_init(core
);
4642 fprintf(stderr
, "Unable to find CPU definition\n");
4645 s
->sdram_size
= sdram_size
;
4646 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
4648 s
->wakeup
= qemu_allocate_irqs(omap_mpu_wakeup
, s
, 1)[0];
4653 /* Memory-mapped stuff */
4654 cpu_register_physical_memory(OMAP_EMIFF_BASE
, s
->sdram_size
,
4655 (emiff_base
= qemu_ram_alloc(s
->sdram_size
)) | IO_MEM_RAM
);
4656 cpu_register_physical_memory(OMAP_IMIF_BASE
, s
->sram_size
,
4657 (imif_base
= qemu_ram_alloc(s
->sram_size
)) | IO_MEM_RAM
);
4659 omap_clkm_init(0xfffece00, 0xe1008000, s
);
4661 cpu_irq
= arm_pic_init_cpu(s
->env
);
4662 s
->ih
[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s
->irq
[0],
4663 cpu_irq
[ARM_PIC_CPU_IRQ
], cpu_irq
[ARM_PIC_CPU_FIQ
],
4664 omap_findclk(s
, "arminth_ck"));
4665 s
->ih
[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s
->irq
[1],
4666 s
->ih
[0]->pins
[OMAP_INT_15XX_IH2_IRQ
], NULL
,
4667 omap_findclk(s
, "arminth_ck"));
4669 for (i
= 0; i
< 6; i
++)
4671 s
->irq
[omap1_dma_irq_map
[i
].ih
][omap1_dma_irq_map
[i
].intr
];
4672 s
->dma
= omap_dma_init(0xfffed800, dma_irqs
, s
->irq
[0][OMAP_INT_DMA_LCD
],
4673 s
, omap_findclk(s
, "dma_ck"), omap_dma_3_1
);
4675 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
4676 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
4677 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
4678 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
4679 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
4680 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
4682 /* Register SDRAM and SRAM DMA ports for fast transfers. */
4683 soc_dma_port_add_mem_ram(s
->dma
,
4684 emiff_base
, OMAP_EMIFF_BASE
, s
->sdram_size
);
4685 soc_dma_port_add_mem_ram(s
->dma
,
4686 imif_base
, OMAP_IMIF_BASE
, s
->sram_size
);
4688 s
->timer
[0] = omap_mpu_timer_init(0xfffec500,
4689 s
->irq
[0][OMAP_INT_TIMER1
],
4690 omap_findclk(s
, "mputim_ck"));
4691 s
->timer
[1] = omap_mpu_timer_init(0xfffec600,
4692 s
->irq
[0][OMAP_INT_TIMER2
],
4693 omap_findclk(s
, "mputim_ck"));
4694 s
->timer
[2] = omap_mpu_timer_init(0xfffec700,
4695 s
->irq
[0][OMAP_INT_TIMER3
],
4696 omap_findclk(s
, "mputim_ck"));
4698 s
->wdt
= omap_wd_timer_init(0xfffec800,
4699 s
->irq
[0][OMAP_INT_WD_TIMER
],
4700 omap_findclk(s
, "armwdt_ck"));
4702 s
->os_timer
= omap_os_timer_init(0xfffb9000,
4703 s
->irq
[1][OMAP_INT_OS_TIMER
],
4704 omap_findclk(s
, "clk32-kHz"));
4706 s
->lcd
= omap_lcdc_init(0xfffec000, s
->irq
[0][OMAP_INT_LCD_CTRL
],
4707 omap_dma_get_lcdch(s
->dma
), ds
, imif_base
, emiff_base
,
4708 omap_findclk(s
, "lcd_ck"));
4710 omap_ulpd_pm_init(0xfffe0800, s
);
4711 omap_pin_cfg_init(0xfffe1000, s
);
4714 omap_mpui_init(0xfffec900, s
);
4716 s
->private_tipb
= omap_tipb_bridge_init(0xfffeca00,
4717 s
->irq
[0][OMAP_INT_BRIDGE_PRIV
],
4718 omap_findclk(s
, "tipb_ck"));
4719 s
->public_tipb
= omap_tipb_bridge_init(0xfffed300,
4720 s
->irq
[0][OMAP_INT_BRIDGE_PUB
],
4721 omap_findclk(s
, "tipb_ck"));
4723 omap_tcmi_init(0xfffecc00, s
);
4725 s
->uart
[0] = omap_uart_init(0xfffb0000, s
->irq
[1][OMAP_INT_UART1
],
4726 omap_findclk(s
, "uart1_ck"),
4727 omap_findclk(s
, "uart1_ck"),
4728 s
->drq
[OMAP_DMA_UART1_TX
], s
->drq
[OMAP_DMA_UART1_RX
],
4730 s
->uart
[1] = omap_uart_init(0xfffb0800, s
->irq
[1][OMAP_INT_UART2
],
4731 omap_findclk(s
, "uart2_ck"),
4732 omap_findclk(s
, "uart2_ck"),
4733 s
->drq
[OMAP_DMA_UART2_TX
], s
->drq
[OMAP_DMA_UART2_RX
],
4734 serial_hds
[0] ? serial_hds
[1] : 0);
4735 s
->uart
[2] = omap_uart_init(0xfffb9800, s
->irq
[0][OMAP_INT_UART3
],
4736 omap_findclk(s
, "uart3_ck"),
4737 omap_findclk(s
, "uart3_ck"),
4738 s
->drq
[OMAP_DMA_UART3_TX
], s
->drq
[OMAP_DMA_UART3_RX
],
4739 serial_hds
[0] && serial_hds
[1] ? serial_hds
[2] : 0);
4741 omap_dpll_init(&s
->dpll
[0], 0xfffecf00, omap_findclk(s
, "dpll1"));
4742 omap_dpll_init(&s
->dpll
[1], 0xfffed000, omap_findclk(s
, "dpll2"));
4743 omap_dpll_init(&s
->dpll
[2], 0xfffed100, omap_findclk(s
, "dpll3"));
4745 sdindex
= drive_get_index(IF_SD
, 0, 0);
4746 if (sdindex
== -1) {
4747 fprintf(stderr
, "qemu: missing SecureDigital device\n");
4750 s
->mmc
= omap_mmc_init(0xfffb7800, drives_table
[sdindex
].bdrv
,
4751 s
->irq
[1][OMAP_INT_OQN
], &s
->drq
[OMAP_DMA_MMC_TX
],
4752 omap_findclk(s
, "mmc_ck"));
4754 s
->mpuio
= omap_mpuio_init(0xfffb5000,
4755 s
->irq
[1][OMAP_INT_KEYBOARD
], s
->irq
[1][OMAP_INT_MPUIO
],
4756 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
4758 s
->gpio
= omap_gpio_init(0xfffce000, s
->irq
[0][OMAP_INT_GPIO_BANK1
],
4759 omap_findclk(s
, "arm_gpio_ck"));
4761 s
->microwire
= omap_uwire_init(0xfffb3000, &s
->irq
[1][OMAP_INT_uWireTX
],
4762 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
4764 omap_pwl_init(0xfffb5800, s
, omap_findclk(s
, "armxor_ck"));
4765 omap_pwt_init(0xfffb6000, s
, omap_findclk(s
, "armxor_ck"));
4767 s
->i2c
[0] = omap_i2c_init(0xfffb3800, s
->irq
[1][OMAP_INT_I2C
],
4768 &s
->drq
[OMAP_DMA_I2C_RX
], omap_findclk(s
, "mpuper_ck"));
4770 s
->rtc
= omap_rtc_init(0xfffb4800, &s
->irq
[1][OMAP_INT_RTC_TIMER
],
4771 omap_findclk(s
, "clk32-kHz"));
4773 s
->mcbsp1
= omap_mcbsp_init(0xfffb1800, &s
->irq
[1][OMAP_INT_McBSP1TX
],
4774 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
4775 s
->mcbsp2
= omap_mcbsp_init(0xfffb1000, &s
->irq
[0][OMAP_INT_310_McBSP2_TX
],
4776 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
4777 s
->mcbsp3
= omap_mcbsp_init(0xfffb7000, &s
->irq
[1][OMAP_INT_McBSP3TX
],
4778 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
4780 s
->led
[0] = omap_lpg_init(0xfffbd000, omap_findclk(s
, "clk32-kHz"));
4781 s
->led
[1] = omap_lpg_init(0xfffbd800, omap_findclk(s
, "clk32-kHz"));
4783 /* Register mappings not currenlty implemented:
4784 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4785 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4786 * USB W2FC fffb4000 - fffb47ff
4787 * Camera Interface fffb6800 - fffb6fff
4788 * USB Host fffba000 - fffba7ff
4789 * FAC fffba800 - fffbafff
4790 * HDQ/1-Wire fffbc000 - fffbc7ff
4791 * TIPB switches fffbc800 - fffbcfff
4792 * Mailbox fffcf000 - fffcf7ff
4793 * Local bus IF fffec100 - fffec1ff
4794 * Local bus MMU fffec200 - fffec2ff
4795 * DSP MMU fffed200 - fffed2ff
4798 omap_setup_dsp_mapping(omap15xx_dsp_mm
);
4799 omap_setup_mpui_io(s
);
4801 qemu_register_reset(omap1_mpu_reset
, s
);