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, see <http://www.gnu.org/licenses/>.
23 #include "qemu-timer.h"
24 #include "qemu-char.h"
26 /* We use pc-style serial ports. */
32 /* Should signal the TCMI/GPMC */
33 uint32_t omap_badwidth_read8(void *opaque
, target_phys_addr_t addr
)
38 cpu_physical_memory_read(addr
, (void *) &ret
, 1);
42 void omap_badwidth_write8(void *opaque
, target_phys_addr_t addr
,
48 cpu_physical_memory_write(addr
, (void *) &val8
, 1);
51 uint32_t omap_badwidth_read16(void *opaque
, target_phys_addr_t addr
)
56 cpu_physical_memory_read(addr
, (void *) &ret
, 2);
60 void omap_badwidth_write16(void *opaque
, target_phys_addr_t addr
,
63 uint16_t val16
= value
;
66 cpu_physical_memory_write(addr
, (void *) &val16
, 2);
69 uint32_t omap_badwidth_read32(void *opaque
, target_phys_addr_t addr
)
74 cpu_physical_memory_read(addr
, (void *) &ret
, 4);
78 void omap_badwidth_write32(void *opaque
, target_phys_addr_t addr
,
82 cpu_physical_memory_write(addr
, (void *) &value
, 4);
86 struct omap_mpu_timer_s
{
103 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
105 uint64_t distance
= qemu_get_clock_ns(vm_clock
) - timer
->time
;
107 if (timer
->st
&& timer
->enable
&& timer
->rate
)
108 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
109 timer
->rate
, get_ticks_per_sec());
114 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
116 timer
->val
= omap_timer_read(timer
);
117 timer
->time
= qemu_get_clock_ns(vm_clock
);
120 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
124 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
125 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
126 expires
= muldiv64((uint64_t) timer
->val
<< (timer
->ptv
+ 1),
127 get_ticks_per_sec(), timer
->rate
);
129 /* If timer expiry would be sooner than in about 1 ms and
130 * auto-reload isn't set, then fire immediately. This is a hack
131 * to make systems like PalmOS run in acceptable time. PalmOS
132 * sets the interval to a very low value and polls the status bit
133 * in a busy loop when it wants to sleep just a couple of CPU
135 if (expires
> (get_ticks_per_sec() >> 10) || timer
->ar
)
136 qemu_mod_timer(timer
->timer
, timer
->time
+ expires
);
138 qemu_bh_schedule(timer
->tick
);
140 qemu_del_timer(timer
->timer
);
143 static void omap_timer_fire(void *opaque
)
145 struct omap_mpu_timer_s
*timer
= opaque
;
153 /* Edge-triggered irq */
154 qemu_irq_pulse(timer
->irq
);
157 static void omap_timer_tick(void *opaque
)
159 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
161 omap_timer_sync(timer
);
162 omap_timer_fire(timer
);
163 omap_timer_update(timer
);
166 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
168 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
170 omap_timer_sync(timer
);
171 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
172 omap_timer_update(timer
);
175 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
177 omap_clk_adduser(timer
->clk
,
178 qemu_allocate_irqs(omap_timer_clk_update
, timer
, 1)[0]);
179 timer
->rate
= omap_clk_getrate(timer
->clk
);
182 static uint32_t omap_mpu_timer_read(void *opaque
, target_phys_addr_t addr
)
184 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
187 case 0x00: /* CNTL_TIMER */
188 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
190 case 0x04: /* LOAD_TIM */
193 case 0x08: /* READ_TIM */
194 return omap_timer_read(s
);
201 static void omap_mpu_timer_write(void *opaque
, target_phys_addr_t addr
,
204 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
207 case 0x00: /* CNTL_TIMER */
209 s
->enable
= (value
>> 5) & 1;
210 s
->ptv
= (value
>> 2) & 7;
211 s
->ar
= (value
>> 1) & 1;
213 omap_timer_update(s
);
216 case 0x04: /* LOAD_TIM */
217 s
->reset_val
= value
;
220 case 0x08: /* READ_TIM */
229 static CPUReadMemoryFunc
* const omap_mpu_timer_readfn
[] = {
230 omap_badwidth_read32
,
231 omap_badwidth_read32
,
235 static CPUWriteMemoryFunc
* const omap_mpu_timer_writefn
[] = {
236 omap_badwidth_write32
,
237 omap_badwidth_write32
,
238 omap_mpu_timer_write
,
241 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
243 qemu_del_timer(s
->timer
);
245 s
->reset_val
= 31337;
253 static struct omap_mpu_timer_s
*omap_mpu_timer_init(target_phys_addr_t base
,
254 qemu_irq irq
, omap_clk clk
)
257 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*)
258 qemu_mallocz(sizeof(struct omap_mpu_timer_s
));
262 s
->timer
= qemu_new_timer_ns(vm_clock
, omap_timer_tick
, s
);
263 s
->tick
= qemu_bh_new(omap_timer_fire
, s
);
264 omap_mpu_timer_reset(s
);
265 omap_timer_clk_setup(s
);
267 iomemtype
= cpu_register_io_memory(omap_mpu_timer_readfn
,
268 omap_mpu_timer_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
269 cpu_register_physical_memory(base
, 0x100, iomemtype
);
275 struct omap_watchdog_timer_s
{
276 struct omap_mpu_timer_s timer
;
283 static uint32_t omap_wd_timer_read(void *opaque
, target_phys_addr_t addr
)
285 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
288 case 0x00: /* CNTL_TIMER */
289 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
290 (s
->timer
.st
<< 7) | (s
->free
<< 1);
292 case 0x04: /* READ_TIMER */
293 return omap_timer_read(&s
->timer
);
295 case 0x08: /* TIMER_MODE */
296 return s
->mode
<< 15;
303 static void omap_wd_timer_write(void *opaque
, target_phys_addr_t addr
,
306 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
309 case 0x00: /* CNTL_TIMER */
310 omap_timer_sync(&s
->timer
);
311 s
->timer
.ptv
= (value
>> 9) & 7;
312 s
->timer
.ar
= (value
>> 8) & 1;
313 s
->timer
.st
= (value
>> 7) & 1;
314 s
->free
= (value
>> 1) & 1;
315 omap_timer_update(&s
->timer
);
318 case 0x04: /* LOAD_TIMER */
319 s
->timer
.reset_val
= value
& 0xffff;
322 case 0x08: /* TIMER_MODE */
323 if (!s
->mode
&& ((value
>> 15) & 1))
324 omap_clk_get(s
->timer
.clk
);
325 s
->mode
|= (value
>> 15) & 1;
326 if (s
->last_wr
== 0xf5) {
327 if ((value
& 0xff) == 0xa0) {
330 omap_clk_put(s
->timer
.clk
);
333 /* XXX: on T|E hardware somehow this has no effect,
334 * on Zire 71 it works as specified. */
336 qemu_system_reset_request();
339 s
->last_wr
= value
& 0xff;
347 static CPUReadMemoryFunc
* const omap_wd_timer_readfn
[] = {
348 omap_badwidth_read16
,
350 omap_badwidth_read16
,
353 static CPUWriteMemoryFunc
* const omap_wd_timer_writefn
[] = {
354 omap_badwidth_write16
,
356 omap_badwidth_write16
,
359 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
361 qemu_del_timer(s
->timer
.timer
);
363 omap_clk_get(s
->timer
.clk
);
369 s
->timer
.reset_val
= 0xffff;
374 omap_timer_update(&s
->timer
);
377 static struct omap_watchdog_timer_s
*omap_wd_timer_init(target_phys_addr_t base
,
378 qemu_irq irq
, omap_clk clk
)
381 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*)
382 qemu_mallocz(sizeof(struct omap_watchdog_timer_s
));
386 s
->timer
.timer
= qemu_new_timer_ns(vm_clock
, omap_timer_tick
, &s
->timer
);
387 omap_wd_timer_reset(s
);
388 omap_timer_clk_setup(&s
->timer
);
390 iomemtype
= cpu_register_io_memory(omap_wd_timer_readfn
,
391 omap_wd_timer_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
392 cpu_register_physical_memory(base
, 0x100, iomemtype
);
398 struct omap_32khz_timer_s
{
399 struct omap_mpu_timer_s timer
;
402 static uint32_t omap_os_timer_read(void *opaque
, target_phys_addr_t addr
)
404 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
405 int offset
= addr
& OMAP_MPUI_REG_MASK
;
409 return s
->timer
.reset_val
;
412 return omap_timer_read(&s
->timer
);
415 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
424 static void omap_os_timer_write(void *opaque
, target_phys_addr_t addr
,
427 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
428 int offset
= addr
& OMAP_MPUI_REG_MASK
;
432 s
->timer
.reset_val
= value
& 0x00ffffff;
440 s
->timer
.ar
= (value
>> 3) & 1;
441 s
->timer
.it_ena
= (value
>> 2) & 1;
442 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
443 omap_timer_sync(&s
->timer
);
444 s
->timer
.enable
= value
& 1;
445 s
->timer
.st
= value
& 1;
446 omap_timer_update(&s
->timer
);
455 static CPUReadMemoryFunc
* const omap_os_timer_readfn
[] = {
456 omap_badwidth_read32
,
457 omap_badwidth_read32
,
461 static CPUWriteMemoryFunc
* const omap_os_timer_writefn
[] = {
462 omap_badwidth_write32
,
463 omap_badwidth_write32
,
467 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
469 qemu_del_timer(s
->timer
.timer
);
472 s
->timer
.reset_val
= 0x00ffffff;
479 static struct omap_32khz_timer_s
*omap_os_timer_init(target_phys_addr_t base
,
480 qemu_irq irq
, omap_clk clk
)
483 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*)
484 qemu_mallocz(sizeof(struct omap_32khz_timer_s
));
488 s
->timer
.timer
= qemu_new_timer_ns(vm_clock
, omap_timer_tick
, &s
->timer
);
489 omap_os_timer_reset(s
);
490 omap_timer_clk_setup(&s
->timer
);
492 iomemtype
= cpu_register_io_memory(omap_os_timer_readfn
,
493 omap_os_timer_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
494 cpu_register_physical_memory(base
, 0x800, iomemtype
);
499 /* Ultra Low-Power Device Module */
500 static uint32_t omap_ulpd_pm_read(void *opaque
, target_phys_addr_t addr
)
502 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
506 case 0x14: /* IT_STATUS */
507 ret
= s
->ulpd_pm_regs
[addr
>> 2];
508 s
->ulpd_pm_regs
[addr
>> 2] = 0;
509 qemu_irq_lower(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
512 case 0x18: /* Reserved */
513 case 0x1c: /* Reserved */
514 case 0x20: /* Reserved */
515 case 0x28: /* Reserved */
516 case 0x2c: /* Reserved */
518 case 0x00: /* COUNTER_32_LSB */
519 case 0x04: /* COUNTER_32_MSB */
520 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
521 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
522 case 0x10: /* GAUGING_CTRL */
523 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
524 case 0x30: /* CLOCK_CTRL */
525 case 0x34: /* SOFT_REQ */
526 case 0x38: /* COUNTER_32_FIQ */
527 case 0x3c: /* DPLL_CTRL */
528 case 0x40: /* STATUS_REQ */
529 /* XXX: check clk::usecount state for every clock */
530 case 0x48: /* LOCL_TIME */
531 case 0x4c: /* APLL_CTRL */
532 case 0x50: /* POWER_CTRL */
533 return s
->ulpd_pm_regs
[addr
>> 2];
540 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
541 uint16_t diff
, uint16_t value
)
543 if (diff
& (1 << 4)) /* USB_MCLK_EN */
544 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
545 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
546 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
549 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
550 uint16_t diff
, uint16_t value
)
552 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
553 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
554 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
555 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
556 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
557 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
558 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
559 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
562 static void omap_ulpd_pm_write(void *opaque
, target_phys_addr_t addr
,
565 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
568 static const int bypass_div
[4] = { 1, 2, 4, 4 };
572 case 0x00: /* COUNTER_32_LSB */
573 case 0x04: /* COUNTER_32_MSB */
574 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
575 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
576 case 0x14: /* IT_STATUS */
577 case 0x40: /* STATUS_REQ */
581 case 0x10: /* GAUGING_CTRL */
582 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
583 if ((s
->ulpd_pm_regs
[addr
>> 2] ^ value
) & 1) {
584 now
= qemu_get_clock_ns(vm_clock
);
587 s
->ulpd_gauge_start
= now
;
589 now
-= s
->ulpd_gauge_start
;
592 ticks
= muldiv64(now
, 32768, get_ticks_per_sec());
593 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
594 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
595 if (ticks
>> 32) /* OVERFLOW_32K */
596 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
598 /* High frequency ticks */
599 ticks
= muldiv64(now
, 12000000, get_ticks_per_sec());
600 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
601 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
602 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
603 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
605 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
606 qemu_irq_raise(s
->irq
[1][OMAP_INT_GAUGE_32K
]);
609 s
->ulpd_pm_regs
[addr
>> 2] = value
;
612 case 0x18: /* Reserved */
613 case 0x1c: /* Reserved */
614 case 0x20: /* Reserved */
615 case 0x28: /* Reserved */
616 case 0x2c: /* Reserved */
618 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
619 case 0x38: /* COUNTER_32_FIQ */
620 case 0x48: /* LOCL_TIME */
621 case 0x50: /* POWER_CTRL */
622 s
->ulpd_pm_regs
[addr
>> 2] = value
;
625 case 0x30: /* CLOCK_CTRL */
626 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
627 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x3f;
628 omap_ulpd_clk_update(s
, diff
, value
);
631 case 0x34: /* SOFT_REQ */
632 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
633 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x1f;
634 omap_ulpd_req_update(s
, diff
, value
);
637 case 0x3c: /* DPLL_CTRL */
638 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
639 * omitted altogether, probably a typo. */
640 /* This register has identical semantics with DPLL(1:3) control
641 * registers, see omap_dpll_write() */
642 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
643 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x2fff;
644 if (diff
& (0x3ff << 2)) {
645 if (value
& (1 << 4)) { /* PLL_ENABLE */
646 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
647 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
649 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
652 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
655 /* Enter the desired mode. */
656 s
->ulpd_pm_regs
[addr
>> 2] =
657 (s
->ulpd_pm_regs
[addr
>> 2] & 0xfffe) |
658 ((s
->ulpd_pm_regs
[addr
>> 2] >> 4) & 1);
660 /* Act as if the lock is restored. */
661 s
->ulpd_pm_regs
[addr
>> 2] |= 2;
664 case 0x4c: /* APLL_CTRL */
665 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
666 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0xf;
667 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
668 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
669 (value
& (1 << 0)) ? "apll" : "dpll4"));
677 static CPUReadMemoryFunc
* const omap_ulpd_pm_readfn
[] = {
678 omap_badwidth_read16
,
680 omap_badwidth_read16
,
683 static CPUWriteMemoryFunc
* const omap_ulpd_pm_writefn
[] = {
684 omap_badwidth_write16
,
686 omap_badwidth_write16
,
689 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
691 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
692 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
693 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
694 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
695 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
696 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
697 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
698 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
699 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
700 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
701 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
702 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
703 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
704 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
705 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
706 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
707 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
708 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
709 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
710 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
711 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
712 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
713 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
716 static void omap_ulpd_pm_init(target_phys_addr_t base
,
717 struct omap_mpu_state_s
*mpu
)
719 int iomemtype
= cpu_register_io_memory(omap_ulpd_pm_readfn
,
720 omap_ulpd_pm_writefn
, mpu
, DEVICE_NATIVE_ENDIAN
);
722 cpu_register_physical_memory(base
, 0x800, iomemtype
);
723 omap_ulpd_pm_reset(mpu
);
726 /* OMAP Pin Configuration */
727 static uint32_t omap_pin_cfg_read(void *opaque
, target_phys_addr_t addr
)
729 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
732 case 0x00: /* FUNC_MUX_CTRL_0 */
733 case 0x04: /* FUNC_MUX_CTRL_1 */
734 case 0x08: /* FUNC_MUX_CTRL_2 */
735 return s
->func_mux_ctrl
[addr
>> 2];
737 case 0x0c: /* COMP_MODE_CTRL_0 */
738 return s
->comp_mode_ctrl
[0];
740 case 0x10: /* FUNC_MUX_CTRL_3 */
741 case 0x14: /* FUNC_MUX_CTRL_4 */
742 case 0x18: /* FUNC_MUX_CTRL_5 */
743 case 0x1c: /* FUNC_MUX_CTRL_6 */
744 case 0x20: /* FUNC_MUX_CTRL_7 */
745 case 0x24: /* FUNC_MUX_CTRL_8 */
746 case 0x28: /* FUNC_MUX_CTRL_9 */
747 case 0x2c: /* FUNC_MUX_CTRL_A */
748 case 0x30: /* FUNC_MUX_CTRL_B */
749 case 0x34: /* FUNC_MUX_CTRL_C */
750 case 0x38: /* FUNC_MUX_CTRL_D */
751 return s
->func_mux_ctrl
[(addr
>> 2) - 1];
753 case 0x40: /* PULL_DWN_CTRL_0 */
754 case 0x44: /* PULL_DWN_CTRL_1 */
755 case 0x48: /* PULL_DWN_CTRL_2 */
756 case 0x4c: /* PULL_DWN_CTRL_3 */
757 return s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2];
759 case 0x50: /* GATE_INH_CTRL_0 */
760 return s
->gate_inh_ctrl
[0];
762 case 0x60: /* VOLTAGE_CTRL_0 */
763 return s
->voltage_ctrl
[0];
765 case 0x70: /* TEST_DBG_CTRL_0 */
766 return s
->test_dbg_ctrl
[0];
768 case 0x80: /* MOD_CONF_CTRL_0 */
769 return s
->mod_conf_ctrl
[0];
776 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
777 uint32_t diff
, uint32_t value
)
780 if (diff
& (1 << 9)) /* BLUETOOTH */
781 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
783 if (diff
& (1 << 7)) /* USB.CLKO */
784 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
789 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
790 uint32_t diff
, uint32_t value
)
793 if (diff
& (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
794 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"),
796 if (diff
& (1 << 1)) /* CLK32K */
797 omap_clk_onoff(omap_findclk(s
, "clk32k_out"),
802 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
803 uint32_t diff
, uint32_t value
)
805 if (diff
& (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
806 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
807 omap_findclk(s
, ((value
>> 31) & 1) ?
808 "ck_48m" : "armper_ck"));
809 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
810 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
811 omap_findclk(s
, ((value
>> 30) & 1) ?
812 "ck_48m" : "armper_ck"));
813 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
814 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
815 omap_findclk(s
, ((value
>> 29) & 1) ?
816 "ck_48m" : "armper_ck"));
817 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
818 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
819 omap_findclk(s
, ((value
>> 23) & 1) ?
820 "ck_48m" : "armper_ck"));
821 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
822 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
823 omap_findclk(s
, ((value
>> 12) & 1) ?
824 "ck_48m" : "armper_ck"));
825 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
826 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
829 static void omap_pin_cfg_write(void *opaque
, target_phys_addr_t addr
,
832 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
836 case 0x00: /* FUNC_MUX_CTRL_0 */
837 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
838 s
->func_mux_ctrl
[addr
>> 2] = value
;
839 omap_pin_funcmux0_update(s
, diff
, value
);
842 case 0x04: /* FUNC_MUX_CTRL_1 */
843 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
844 s
->func_mux_ctrl
[addr
>> 2] = value
;
845 omap_pin_funcmux1_update(s
, diff
, value
);
848 case 0x08: /* FUNC_MUX_CTRL_2 */
849 s
->func_mux_ctrl
[addr
>> 2] = value
;
852 case 0x0c: /* COMP_MODE_CTRL_0 */
853 s
->comp_mode_ctrl
[0] = value
;
854 s
->compat1509
= (value
!= 0x0000eaef);
855 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
856 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
859 case 0x10: /* FUNC_MUX_CTRL_3 */
860 case 0x14: /* FUNC_MUX_CTRL_4 */
861 case 0x18: /* FUNC_MUX_CTRL_5 */
862 case 0x1c: /* FUNC_MUX_CTRL_6 */
863 case 0x20: /* FUNC_MUX_CTRL_7 */
864 case 0x24: /* FUNC_MUX_CTRL_8 */
865 case 0x28: /* FUNC_MUX_CTRL_9 */
866 case 0x2c: /* FUNC_MUX_CTRL_A */
867 case 0x30: /* FUNC_MUX_CTRL_B */
868 case 0x34: /* FUNC_MUX_CTRL_C */
869 case 0x38: /* FUNC_MUX_CTRL_D */
870 s
->func_mux_ctrl
[(addr
>> 2) - 1] = value
;
873 case 0x40: /* PULL_DWN_CTRL_0 */
874 case 0x44: /* PULL_DWN_CTRL_1 */
875 case 0x48: /* PULL_DWN_CTRL_2 */
876 case 0x4c: /* PULL_DWN_CTRL_3 */
877 s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2] = value
;
880 case 0x50: /* GATE_INH_CTRL_0 */
881 s
->gate_inh_ctrl
[0] = value
;
884 case 0x60: /* VOLTAGE_CTRL_0 */
885 s
->voltage_ctrl
[0] = value
;
888 case 0x70: /* TEST_DBG_CTRL_0 */
889 s
->test_dbg_ctrl
[0] = value
;
892 case 0x80: /* MOD_CONF_CTRL_0 */
893 diff
= s
->mod_conf_ctrl
[0] ^ value
;
894 s
->mod_conf_ctrl
[0] = value
;
895 omap_pin_modconf1_update(s
, diff
, value
);
903 static CPUReadMemoryFunc
* const omap_pin_cfg_readfn
[] = {
904 omap_badwidth_read32
,
905 omap_badwidth_read32
,
909 static CPUWriteMemoryFunc
* const omap_pin_cfg_writefn
[] = {
910 omap_badwidth_write32
,
911 omap_badwidth_write32
,
915 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
917 /* Start in Compatibility Mode. */
919 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
920 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
921 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
922 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
923 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
924 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
925 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
926 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
927 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
928 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
931 static void omap_pin_cfg_init(target_phys_addr_t base
,
932 struct omap_mpu_state_s
*mpu
)
934 int iomemtype
= cpu_register_io_memory(omap_pin_cfg_readfn
,
935 omap_pin_cfg_writefn
, mpu
, DEVICE_NATIVE_ENDIAN
);
937 cpu_register_physical_memory(base
, 0x800, iomemtype
);
938 omap_pin_cfg_reset(mpu
);
941 /* Device Identification, Die Identification */
942 static uint32_t omap_id_read(void *opaque
, target_phys_addr_t addr
)
944 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
947 case 0xfffe1800: /* DIE_ID_LSB */
949 case 0xfffe1804: /* DIE_ID_MSB */
952 case 0xfffe2000: /* PRODUCT_ID_LSB */
954 case 0xfffe2004: /* PRODUCT_ID_MSB */
957 case 0xfffed400: /* JTAG_ID_LSB */
958 switch (s
->mpu_model
) {
964 hw_error("%s: bad mpu model\n", __FUNCTION__
);
968 case 0xfffed404: /* JTAG_ID_MSB */
969 switch (s
->mpu_model
) {
975 hw_error("%s: bad mpu model\n", __FUNCTION__
);
984 static void omap_id_write(void *opaque
, target_phys_addr_t addr
,
990 static CPUReadMemoryFunc
* const omap_id_readfn
[] = {
991 omap_badwidth_read32
,
992 omap_badwidth_read32
,
996 static CPUWriteMemoryFunc
* const omap_id_writefn
[] = {
997 omap_badwidth_write32
,
998 omap_badwidth_write32
,
1002 static void omap_id_init(struct omap_mpu_state_s
*mpu
)
1004 int iomemtype
= cpu_register_io_memory(omap_id_readfn
,
1005 omap_id_writefn
, mpu
, DEVICE_NATIVE_ENDIAN
);
1006 cpu_register_physical_memory_offset(0xfffe1800, 0x800, iomemtype
, 0xfffe1800);
1007 cpu_register_physical_memory_offset(0xfffed400, 0x100, iomemtype
, 0xfffed400);
1008 if (!cpu_is_omap15xx(mpu
))
1009 cpu_register_physical_memory_offset(0xfffe2000, 0x800, iomemtype
, 0xfffe2000);
1012 /* MPUI Control (Dummy) */
1013 static uint32_t omap_mpui_read(void *opaque
, target_phys_addr_t addr
)
1015 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1018 case 0x00: /* CTRL */
1019 return s
->mpui_ctrl
;
1020 case 0x04: /* DEBUG_ADDR */
1022 case 0x08: /* DEBUG_DATA */
1024 case 0x0c: /* DEBUG_FLAG */
1026 case 0x10: /* STATUS */
1029 /* Not in OMAP310 */
1030 case 0x14: /* DSP_STATUS */
1031 case 0x18: /* DSP_BOOT_CONFIG */
1033 case 0x1c: /* DSP_MPUI_CONFIG */
1041 static void omap_mpui_write(void *opaque
, target_phys_addr_t addr
,
1044 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1047 case 0x00: /* CTRL */
1048 s
->mpui_ctrl
= value
& 0x007fffff;
1051 case 0x04: /* DEBUG_ADDR */
1052 case 0x08: /* DEBUG_DATA */
1053 case 0x0c: /* DEBUG_FLAG */
1054 case 0x10: /* STATUS */
1055 /* Not in OMAP310 */
1056 case 0x14: /* DSP_STATUS */
1058 case 0x18: /* DSP_BOOT_CONFIG */
1059 case 0x1c: /* DSP_MPUI_CONFIG */
1067 static CPUReadMemoryFunc
* const omap_mpui_readfn
[] = {
1068 omap_badwidth_read32
,
1069 omap_badwidth_read32
,
1073 static CPUWriteMemoryFunc
* const omap_mpui_writefn
[] = {
1074 omap_badwidth_write32
,
1075 omap_badwidth_write32
,
1079 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1081 s
->mpui_ctrl
= 0x0003ff1b;
1084 static void omap_mpui_init(target_phys_addr_t base
,
1085 struct omap_mpu_state_s
*mpu
)
1087 int iomemtype
= cpu_register_io_memory(omap_mpui_readfn
,
1088 omap_mpui_writefn
, mpu
, DEVICE_NATIVE_ENDIAN
);
1090 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1092 omap_mpui_reset(mpu
);
1096 struct omap_tipb_bridge_s
{
1103 uint16_t enh_control
;
1106 static uint32_t omap_tipb_bridge_read(void *opaque
, target_phys_addr_t addr
)
1108 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1111 case 0x00: /* TIPB_CNTL */
1113 case 0x04: /* TIPB_BUS_ALLOC */
1115 case 0x08: /* MPU_TIPB_CNTL */
1117 case 0x0c: /* ENHANCED_TIPB_CNTL */
1118 return s
->enh_control
;
1119 case 0x10: /* ADDRESS_DBG */
1120 case 0x14: /* DATA_DEBUG_LOW */
1121 case 0x18: /* DATA_DEBUG_HIGH */
1123 case 0x1c: /* DEBUG_CNTR_SIG */
1131 static void omap_tipb_bridge_write(void *opaque
, target_phys_addr_t addr
,
1134 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1137 case 0x00: /* TIPB_CNTL */
1138 s
->control
= value
& 0xffff;
1141 case 0x04: /* TIPB_BUS_ALLOC */
1142 s
->alloc
= value
& 0x003f;
1145 case 0x08: /* MPU_TIPB_CNTL */
1146 s
->buffer
= value
& 0x0003;
1149 case 0x0c: /* ENHANCED_TIPB_CNTL */
1150 s
->width_intr
= !(value
& 2);
1151 s
->enh_control
= value
& 0x000f;
1154 case 0x10: /* ADDRESS_DBG */
1155 case 0x14: /* DATA_DEBUG_LOW */
1156 case 0x18: /* DATA_DEBUG_HIGH */
1157 case 0x1c: /* DEBUG_CNTR_SIG */
1166 static CPUReadMemoryFunc
* const omap_tipb_bridge_readfn
[] = {
1167 omap_badwidth_read16
,
1168 omap_tipb_bridge_read
,
1169 omap_tipb_bridge_read
,
1172 static CPUWriteMemoryFunc
* const omap_tipb_bridge_writefn
[] = {
1173 omap_badwidth_write16
,
1174 omap_tipb_bridge_write
,
1175 omap_tipb_bridge_write
,
1178 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1180 s
->control
= 0xffff;
1183 s
->enh_control
= 0x000f;
1186 static struct omap_tipb_bridge_s
*omap_tipb_bridge_init(target_phys_addr_t base
,
1187 qemu_irq abort_irq
, omap_clk clk
)
1190 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*)
1191 qemu_mallocz(sizeof(struct omap_tipb_bridge_s
));
1193 s
->abort
= abort_irq
;
1194 omap_tipb_bridge_reset(s
);
1196 iomemtype
= cpu_register_io_memory(omap_tipb_bridge_readfn
,
1197 omap_tipb_bridge_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
1198 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1203 /* Dummy Traffic Controller's Memory Interface */
1204 static uint32_t omap_tcmi_read(void *opaque
, target_phys_addr_t addr
)
1206 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1210 case 0x00: /* IMIF_PRIO */
1211 case 0x04: /* EMIFS_PRIO */
1212 case 0x08: /* EMIFF_PRIO */
1213 case 0x0c: /* EMIFS_CONFIG */
1214 case 0x10: /* EMIFS_CS0_CONFIG */
1215 case 0x14: /* EMIFS_CS1_CONFIG */
1216 case 0x18: /* EMIFS_CS2_CONFIG */
1217 case 0x1c: /* EMIFS_CS3_CONFIG */
1218 case 0x24: /* EMIFF_MRS */
1219 case 0x28: /* TIMEOUT1 */
1220 case 0x2c: /* TIMEOUT2 */
1221 case 0x30: /* TIMEOUT3 */
1222 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1223 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1224 return s
->tcmi_regs
[addr
>> 2];
1226 case 0x20: /* EMIFF_SDRAM_CONFIG */
1227 ret
= s
->tcmi_regs
[addr
>> 2];
1228 s
->tcmi_regs
[addr
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1229 /* XXX: We can try using the VGA_DIRTY flag for this */
1237 static void omap_tcmi_write(void *opaque
, target_phys_addr_t addr
,
1240 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1243 case 0x00: /* IMIF_PRIO */
1244 case 0x04: /* EMIFS_PRIO */
1245 case 0x08: /* EMIFF_PRIO */
1246 case 0x10: /* EMIFS_CS0_CONFIG */
1247 case 0x14: /* EMIFS_CS1_CONFIG */
1248 case 0x18: /* EMIFS_CS2_CONFIG */
1249 case 0x1c: /* EMIFS_CS3_CONFIG */
1250 case 0x20: /* EMIFF_SDRAM_CONFIG */
1251 case 0x24: /* EMIFF_MRS */
1252 case 0x28: /* TIMEOUT1 */
1253 case 0x2c: /* TIMEOUT2 */
1254 case 0x30: /* TIMEOUT3 */
1255 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1256 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1257 s
->tcmi_regs
[addr
>> 2] = value
;
1259 case 0x0c: /* EMIFS_CONFIG */
1260 s
->tcmi_regs
[addr
>> 2] = (value
& 0xf) | (1 << 4);
1268 static CPUReadMemoryFunc
* const omap_tcmi_readfn
[] = {
1269 omap_badwidth_read32
,
1270 omap_badwidth_read32
,
1274 static CPUWriteMemoryFunc
* const omap_tcmi_writefn
[] = {
1275 omap_badwidth_write32
,
1276 omap_badwidth_write32
,
1280 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1282 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1283 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1284 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1285 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1286 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1287 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1288 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1289 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1290 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1291 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1292 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1293 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1294 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1295 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1296 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1299 static void omap_tcmi_init(target_phys_addr_t base
,
1300 struct omap_mpu_state_s
*mpu
)
1302 int iomemtype
= cpu_register_io_memory(omap_tcmi_readfn
,
1303 omap_tcmi_writefn
, mpu
, DEVICE_NATIVE_ENDIAN
);
1305 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1306 omap_tcmi_reset(mpu
);
1309 /* Digital phase-locked loops control */
1310 static uint32_t omap_dpll_read(void *opaque
, target_phys_addr_t addr
)
1312 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1314 if (addr
== 0x00) /* CTL_REG */
1321 static void omap_dpll_write(void *opaque
, target_phys_addr_t addr
,
1324 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1326 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1329 if (addr
== 0x00) { /* CTL_REG */
1330 /* See omap_ulpd_pm_write() too */
1331 diff
= s
->mode
& value
;
1332 s
->mode
= value
& 0x2fff;
1333 if (diff
& (0x3ff << 2)) {
1334 if (value
& (1 << 4)) { /* PLL_ENABLE */
1335 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1336 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1338 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1341 omap_clk_setrate(s
->dpll
, div
, mult
);
1344 /* Enter the desired mode. */
1345 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1347 /* Act as if the lock is restored. */
1354 static CPUReadMemoryFunc
* const omap_dpll_readfn
[] = {
1355 omap_badwidth_read16
,
1357 omap_badwidth_read16
,
1360 static CPUWriteMemoryFunc
* const omap_dpll_writefn
[] = {
1361 omap_badwidth_write16
,
1363 omap_badwidth_write16
,
1366 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1369 omap_clk_setrate(s
->dpll
, 1, 1);
1372 static void omap_dpll_init(struct dpll_ctl_s
*s
, target_phys_addr_t base
,
1375 int iomemtype
= cpu_register_io_memory(omap_dpll_readfn
,
1376 omap_dpll_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
1381 cpu_register_physical_memory(base
, 0x100, iomemtype
);
1384 /* MPU Clock/Reset/Power Mode Control */
1385 static uint32_t omap_clkm_read(void *opaque
, target_phys_addr_t addr
)
1387 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1390 case 0x00: /* ARM_CKCTL */
1391 return s
->clkm
.arm_ckctl
;
1393 case 0x04: /* ARM_IDLECT1 */
1394 return s
->clkm
.arm_idlect1
;
1396 case 0x08: /* ARM_IDLECT2 */
1397 return s
->clkm
.arm_idlect2
;
1399 case 0x0c: /* ARM_EWUPCT */
1400 return s
->clkm
.arm_ewupct
;
1402 case 0x10: /* ARM_RSTCT1 */
1403 return s
->clkm
.arm_rstct1
;
1405 case 0x14: /* ARM_RSTCT2 */
1406 return s
->clkm
.arm_rstct2
;
1408 case 0x18: /* ARM_SYSST */
1409 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
1411 case 0x1c: /* ARM_CKOUT1 */
1412 return s
->clkm
.arm_ckout1
;
1414 case 0x20: /* ARM_CKOUT2 */
1422 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
1423 uint16_t diff
, uint16_t value
)
1427 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
1428 if (value
& (1 << 14))
1431 clk
= omap_findclk(s
, "arminth_ck");
1432 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1435 if (diff
& (1 << 12)) { /* ARM_TIMXO */
1436 clk
= omap_findclk(s
, "armtim_ck");
1437 if (value
& (1 << 12))
1438 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
1440 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1443 if (diff
& (3 << 10)) { /* DSPMMUDIV */
1444 clk
= omap_findclk(s
, "dspmmu_ck");
1445 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
1447 if (diff
& (3 << 8)) { /* TCDIV */
1448 clk
= omap_findclk(s
, "tc_ck");
1449 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
1451 if (diff
& (3 << 6)) { /* DSPDIV */
1452 clk
= omap_findclk(s
, "dsp_ck");
1453 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
1455 if (diff
& (3 << 4)) { /* ARMDIV */
1456 clk
= omap_findclk(s
, "arm_ck");
1457 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
1459 if (diff
& (3 << 2)) { /* LCDDIV */
1460 clk
= omap_findclk(s
, "lcd_ck");
1461 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
1463 if (diff
& (3 << 0)) { /* PERDIV */
1464 clk
= omap_findclk(s
, "armper_ck");
1465 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
1469 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
1470 uint16_t diff
, uint16_t value
)
1474 if (value
& (1 << 11)) /* SETARM_IDLE */
1475 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
1476 if (!(value
& (1 << 10))) /* WKUP_MODE */
1477 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
1479 #define SET_CANIDLE(clock, bit) \
1480 if (diff & (1 << bit)) { \
1481 clk = omap_findclk(s, clock); \
1482 omap_clk_canidle(clk, (value >> bit) & 1); \
1484 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1485 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1486 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1487 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1488 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1489 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1490 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1491 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1492 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1493 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1494 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1495 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1496 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1497 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1500 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
1501 uint16_t diff
, uint16_t value
)
1505 #define SET_ONOFF(clock, bit) \
1506 if (diff & (1 << bit)) { \
1507 clk = omap_findclk(s, clock); \
1508 omap_clk_onoff(clk, (value >> bit) & 1); \
1510 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1511 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1512 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1513 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1514 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1515 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1516 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1517 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1518 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1519 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1520 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1523 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
1524 uint16_t diff
, uint16_t value
)
1528 if (diff
& (3 << 4)) { /* TCLKOUT */
1529 clk
= omap_findclk(s
, "tclk_out");
1530 switch ((value
>> 4) & 3) {
1532 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
1533 omap_clk_onoff(clk
, 1);
1536 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1537 omap_clk_onoff(clk
, 1);
1540 omap_clk_onoff(clk
, 0);
1543 if (diff
& (3 << 2)) { /* DCLKOUT */
1544 clk
= omap_findclk(s
, "dclk_out");
1545 switch ((value
>> 2) & 3) {
1547 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
1550 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
1553 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
1556 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1560 if (diff
& (3 << 0)) { /* ACLKOUT */
1561 clk
= omap_findclk(s
, "aclk_out");
1562 switch ((value
>> 0) & 3) {
1564 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1565 omap_clk_onoff(clk
, 1);
1568 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
1569 omap_clk_onoff(clk
, 1);
1572 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1573 omap_clk_onoff(clk
, 1);
1576 omap_clk_onoff(clk
, 0);
1581 static void omap_clkm_write(void *opaque
, target_phys_addr_t addr
,
1584 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1587 static const char *clkschemename
[8] = {
1588 "fully synchronous", "fully asynchronous", "synchronous scalable",
1589 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1593 case 0x00: /* ARM_CKCTL */
1594 diff
= s
->clkm
.arm_ckctl
^ value
;
1595 s
->clkm
.arm_ckctl
= value
& 0x7fff;
1596 omap_clkm_ckctl_update(s
, diff
, value
);
1599 case 0x04: /* ARM_IDLECT1 */
1600 diff
= s
->clkm
.arm_idlect1
^ value
;
1601 s
->clkm
.arm_idlect1
= value
& 0x0fff;
1602 omap_clkm_idlect1_update(s
, diff
, value
);
1605 case 0x08: /* ARM_IDLECT2 */
1606 diff
= s
->clkm
.arm_idlect2
^ value
;
1607 s
->clkm
.arm_idlect2
= value
& 0x07ff;
1608 omap_clkm_idlect2_update(s
, diff
, value
);
1611 case 0x0c: /* ARM_EWUPCT */
1612 s
->clkm
.arm_ewupct
= value
& 0x003f;
1615 case 0x10: /* ARM_RSTCT1 */
1616 diff
= s
->clkm
.arm_rstct1
^ value
;
1617 s
->clkm
.arm_rstct1
= value
& 0x0007;
1619 qemu_system_reset_request();
1620 s
->clkm
.cold_start
= 0xa;
1622 if (diff
& ~value
& 4) { /* DSP_RST */
1624 omap_tipb_bridge_reset(s
->private_tipb
);
1625 omap_tipb_bridge_reset(s
->public_tipb
);
1627 if (diff
& 2) { /* DSP_EN */
1628 clk
= omap_findclk(s
, "dsp_ck");
1629 omap_clk_canidle(clk
, (~value
>> 1) & 1);
1633 case 0x14: /* ARM_RSTCT2 */
1634 s
->clkm
.arm_rstct2
= value
& 0x0001;
1637 case 0x18: /* ARM_SYSST */
1638 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
1639 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
1640 printf("%s: clocking scheme set to %s\n", __FUNCTION__
,
1641 clkschemename
[s
->clkm
.clocking_scheme
]);
1643 s
->clkm
.cold_start
&= value
& 0x3f;
1646 case 0x1c: /* ARM_CKOUT1 */
1647 diff
= s
->clkm
.arm_ckout1
^ value
;
1648 s
->clkm
.arm_ckout1
= value
& 0x003f;
1649 omap_clkm_ckout1_update(s
, diff
, value
);
1652 case 0x20: /* ARM_CKOUT2 */
1658 static CPUReadMemoryFunc
* const omap_clkm_readfn
[] = {
1659 omap_badwidth_read16
,
1661 omap_badwidth_read16
,
1664 static CPUWriteMemoryFunc
* const omap_clkm_writefn
[] = {
1665 omap_badwidth_write16
,
1667 omap_badwidth_write16
,
1670 static uint32_t omap_clkdsp_read(void *opaque
, target_phys_addr_t addr
)
1672 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1675 case 0x04: /* DSP_IDLECT1 */
1676 return s
->clkm
.dsp_idlect1
;
1678 case 0x08: /* DSP_IDLECT2 */
1679 return s
->clkm
.dsp_idlect2
;
1681 case 0x14: /* DSP_RSTCT2 */
1682 return s
->clkm
.dsp_rstct2
;
1684 case 0x18: /* DSP_SYSST */
1685 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
1686 (s
->env
->halted
<< 6); /* Quite useless... */
1693 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
1694 uint16_t diff
, uint16_t value
)
1698 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1701 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
1702 uint16_t diff
, uint16_t value
)
1706 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1709 static void omap_clkdsp_write(void *opaque
, target_phys_addr_t addr
,
1712 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1716 case 0x04: /* DSP_IDLECT1 */
1717 diff
= s
->clkm
.dsp_idlect1
^ value
;
1718 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
1719 omap_clkdsp_idlect1_update(s
, diff
, value
);
1722 case 0x08: /* DSP_IDLECT2 */
1723 s
->clkm
.dsp_idlect2
= value
& 0x0037;
1724 diff
= s
->clkm
.dsp_idlect1
^ value
;
1725 omap_clkdsp_idlect2_update(s
, diff
, value
);
1728 case 0x14: /* DSP_RSTCT2 */
1729 s
->clkm
.dsp_rstct2
= value
& 0x0001;
1732 case 0x18: /* DSP_SYSST */
1733 s
->clkm
.cold_start
&= value
& 0x3f;
1741 static CPUReadMemoryFunc
* const omap_clkdsp_readfn
[] = {
1742 omap_badwidth_read16
,
1744 omap_badwidth_read16
,
1747 static CPUWriteMemoryFunc
* const omap_clkdsp_writefn
[] = {
1748 omap_badwidth_write16
,
1750 omap_badwidth_write16
,
1753 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
1755 if (s
->wdt
&& s
->wdt
->reset
)
1756 s
->clkm
.cold_start
= 0x6;
1757 s
->clkm
.clocking_scheme
= 0;
1758 omap_clkm_ckctl_update(s
, ~0, 0x3000);
1759 s
->clkm
.arm_ckctl
= 0x3000;
1760 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
1761 s
->clkm
.arm_idlect1
= 0x0400;
1762 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
1763 s
->clkm
.arm_idlect2
= 0x0100;
1764 s
->clkm
.arm_ewupct
= 0x003f;
1765 s
->clkm
.arm_rstct1
= 0x0000;
1766 s
->clkm
.arm_rstct2
= 0x0000;
1767 s
->clkm
.arm_ckout1
= 0x0015;
1768 s
->clkm
.dpll1_mode
= 0x2002;
1769 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
1770 s
->clkm
.dsp_idlect1
= 0x0040;
1771 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
1772 s
->clkm
.dsp_idlect2
= 0x0000;
1773 s
->clkm
.dsp_rstct2
= 0x0000;
1776 static void omap_clkm_init(target_phys_addr_t mpu_base
,
1777 target_phys_addr_t dsp_base
, struct omap_mpu_state_s
*s
)
1779 int iomemtype
[2] = {
1780 cpu_register_io_memory(omap_clkm_readfn
, omap_clkm_writefn
, s
,
1781 DEVICE_NATIVE_ENDIAN
),
1782 cpu_register_io_memory(omap_clkdsp_readfn
, omap_clkdsp_writefn
, s
,
1783 DEVICE_NATIVE_ENDIAN
),
1786 s
->clkm
.arm_idlect1
= 0x03ff;
1787 s
->clkm
.arm_idlect2
= 0x0100;
1788 s
->clkm
.dsp_idlect1
= 0x0002;
1790 s
->clkm
.cold_start
= 0x3a;
1792 cpu_register_physical_memory(mpu_base
, 0x100, iomemtype
[0]);
1793 cpu_register_physical_memory(dsp_base
, 0x1000, iomemtype
[1]);
1797 struct omap_mpuio_s
{
1801 qemu_irq handler
[16];
1822 static void omap_mpuio_set(void *opaque
, int line
, int level
)
1824 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1825 uint16_t prev
= s
->inputs
;
1828 s
->inputs
|= 1 << line
;
1830 s
->inputs
&= ~(1 << line
);
1832 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
1833 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
1834 s
->ints
|= 1 << line
;
1835 qemu_irq_raise(s
->irq
);
1838 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1839 (s
->event
>> 1) == line
) /* PIN_SELECT */
1840 s
->latch
= s
->inputs
;
1844 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
1847 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
1849 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
1853 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
1854 s
->row_latch
= ~rows
;
1857 static uint32_t omap_mpuio_read(void *opaque
, target_phys_addr_t addr
)
1859 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1860 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1864 case 0x00: /* INPUT_LATCH */
1867 case 0x04: /* OUTPUT_REG */
1870 case 0x08: /* IO_CNTL */
1873 case 0x10: /* KBR_LATCH */
1874 return s
->row_latch
;
1876 case 0x14: /* KBC_REG */
1879 case 0x18: /* GPIO_EVENT_MODE_REG */
1882 case 0x1c: /* GPIO_INT_EDGE_REG */
1885 case 0x20: /* KBD_INT */
1886 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
1888 case 0x24: /* GPIO_INT */
1892 qemu_irq_lower(s
->irq
);
1895 case 0x28: /* KBD_MASKIT */
1898 case 0x2c: /* GPIO_MASKIT */
1901 case 0x30: /* GPIO_DEBOUNCING_REG */
1904 case 0x34: /* GPIO_LATCH_REG */
1912 static void omap_mpuio_write(void *opaque
, target_phys_addr_t addr
,
1915 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1916 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1921 case 0x04: /* OUTPUT_REG */
1922 diff
= (s
->outputs
^ value
) & ~s
->dir
;
1924 while ((ln
= ffs(diff
))) {
1927 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
1932 case 0x08: /* IO_CNTL */
1933 diff
= s
->outputs
& (s
->dir
^ value
);
1936 value
= s
->outputs
& ~s
->dir
;
1937 while ((ln
= ffs(diff
))) {
1940 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
1945 case 0x14: /* KBC_REG */
1947 omap_mpuio_kbd_update(s
);
1950 case 0x18: /* GPIO_EVENT_MODE_REG */
1951 s
->event
= value
& 0x1f;
1954 case 0x1c: /* GPIO_INT_EDGE_REG */
1958 case 0x28: /* KBD_MASKIT */
1959 s
->kbd_mask
= value
& 1;
1960 omap_mpuio_kbd_update(s
);
1963 case 0x2c: /* GPIO_MASKIT */
1967 case 0x30: /* GPIO_DEBOUNCING_REG */
1968 s
->debounce
= value
& 0x1ff;
1971 case 0x00: /* INPUT_LATCH */
1972 case 0x10: /* KBR_LATCH */
1973 case 0x20: /* KBD_INT */
1974 case 0x24: /* GPIO_INT */
1975 case 0x34: /* GPIO_LATCH_REG */
1985 static CPUReadMemoryFunc
* const omap_mpuio_readfn
[] = {
1986 omap_badwidth_read16
,
1988 omap_badwidth_read16
,
1991 static CPUWriteMemoryFunc
* const omap_mpuio_writefn
[] = {
1992 omap_badwidth_write16
,
1994 omap_badwidth_write16
,
1997 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2009 s
->row_latch
= 0x1f;
2013 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2015 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2019 omap_mpuio_kbd_update(s
);
2022 struct omap_mpuio_s
*omap_mpuio_init(target_phys_addr_t base
,
2023 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2027 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*)
2028 qemu_mallocz(sizeof(struct omap_mpuio_s
));
2031 s
->kbd_irq
= kbd_int
;
2033 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2034 omap_mpuio_reset(s
);
2036 iomemtype
= cpu_register_io_memory(omap_mpuio_readfn
,
2037 omap_mpuio_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
2038 cpu_register_physical_memory(base
, 0x800, iomemtype
);
2040 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_mpuio_onoff
, s
, 1)[0]);
2045 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2050 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2052 if (line
>= 16 || line
< 0)
2053 hw_error("%s: No GPIO line %i\n", __FUNCTION__
, line
);
2054 s
->handler
[line
] = handler
;
2057 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2059 if (row
>= 5 || row
< 0)
2060 hw_error("%s: No key %i-%i\n", __FUNCTION__
, col
, row
);
2063 s
->buttons
[row
] |= 1 << col
;
2065 s
->buttons
[row
] &= ~(1 << col
);
2067 omap_mpuio_kbd_update(s
);
2070 /* MicroWire Interface */
2071 struct omap_uwire_s
{
2081 uWireSlave
*chip
[4];
2084 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
2086 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
2087 uWireSlave
*slave
= s
->chip
[chipselect
];
2089 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
2090 if (s
->control
& (1 << 12)) /* CS_CMD */
2091 if (slave
&& slave
->send
)
2092 slave
->send(slave
->opaque
,
2093 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
2094 s
->control
&= ~(1 << 14); /* CSRB */
2095 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2096 * a DRQ. When is the level IRQ supposed to be reset? */
2099 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
2100 if (s
->control
& (1 << 12)) /* CS_CMD */
2101 if (slave
&& slave
->receive
)
2102 s
->rxbuf
= slave
->receive(slave
->opaque
);
2103 s
->control
|= 1 << 15; /* RDRB */
2104 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2105 * a DRQ. When is the level IRQ supposed to be reset? */
2109 static uint32_t omap_uwire_read(void *opaque
, target_phys_addr_t addr
)
2111 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2112 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2115 case 0x00: /* RDR */
2116 s
->control
&= ~(1 << 15); /* RDRB */
2119 case 0x04: /* CSR */
2122 case 0x08: /* SR1 */
2124 case 0x0c: /* SR2 */
2126 case 0x10: /* SR3 */
2128 case 0x14: /* SR4 */
2130 case 0x18: /* SR5 */
2138 static void omap_uwire_write(void *opaque
, target_phys_addr_t addr
,
2141 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2142 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2145 case 0x00: /* TDR */
2146 s
->txbuf
= value
; /* TD */
2147 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
2148 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2149 (s
->control
& (1 << 12)))) { /* CS_CMD */
2150 s
->control
|= 1 << 14; /* CSRB */
2151 omap_uwire_transfer_start(s
);
2155 case 0x04: /* CSR */
2156 s
->control
= value
& 0x1fff;
2157 if (value
& (1 << 13)) /* START */
2158 omap_uwire_transfer_start(s
);
2161 case 0x08: /* SR1 */
2162 s
->setup
[0] = value
& 0x003f;
2165 case 0x0c: /* SR2 */
2166 s
->setup
[1] = value
& 0x0fc0;
2169 case 0x10: /* SR3 */
2170 s
->setup
[2] = value
& 0x0003;
2173 case 0x14: /* SR4 */
2174 s
->setup
[3] = value
& 0x0001;
2177 case 0x18: /* SR5 */
2178 s
->setup
[4] = value
& 0x000f;
2187 static CPUReadMemoryFunc
* const omap_uwire_readfn
[] = {
2188 omap_badwidth_read16
,
2190 omap_badwidth_read16
,
2193 static CPUWriteMemoryFunc
* const omap_uwire_writefn
[] = {
2194 omap_badwidth_write16
,
2196 omap_badwidth_write16
,
2199 static void omap_uwire_reset(struct omap_uwire_s
*s
)
2209 struct omap_uwire_s
*omap_uwire_init(target_phys_addr_t base
,
2210 qemu_irq
*irq
, qemu_irq dma
, omap_clk clk
)
2213 struct omap_uwire_s
*s
= (struct omap_uwire_s
*)
2214 qemu_mallocz(sizeof(struct omap_uwire_s
));
2219 omap_uwire_reset(s
);
2221 iomemtype
= cpu_register_io_memory(omap_uwire_readfn
,
2222 omap_uwire_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
2223 cpu_register_physical_memory(base
, 0x800, iomemtype
);
2228 void omap_uwire_attach(struct omap_uwire_s
*s
,
2229 uWireSlave
*slave
, int chipselect
)
2231 if (chipselect
< 0 || chipselect
> 3) {
2232 fprintf(stderr
, "%s: Bad chipselect %i\n", __FUNCTION__
, chipselect
);
2236 s
->chip
[chipselect
] = slave
;
2239 /* Pseudonoise Pulse-Width Light Modulator */
2240 static void omap_pwl_update(struct omap_mpu_state_s
*s
)
2242 int output
= (s
->pwl
.clk
&& s
->pwl
.enable
) ? s
->pwl
.level
: 0;
2244 if (output
!= s
->pwl
.output
) {
2245 s
->pwl
.output
= output
;
2246 printf("%s: Backlight now at %i/256\n", __FUNCTION__
, output
);
2250 static uint32_t omap_pwl_read(void *opaque
, target_phys_addr_t addr
)
2252 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2253 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2256 case 0x00: /* PWL_LEVEL */
2257 return s
->pwl
.level
;
2258 case 0x04: /* PWL_CTRL */
2259 return s
->pwl
.enable
;
2265 static void omap_pwl_write(void *opaque
, target_phys_addr_t addr
,
2268 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2269 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2272 case 0x00: /* PWL_LEVEL */
2273 s
->pwl
.level
= value
;
2276 case 0x04: /* PWL_CTRL */
2277 s
->pwl
.enable
= value
& 1;
2286 static CPUReadMemoryFunc
* const omap_pwl_readfn
[] = {
2288 omap_badwidth_read8
,
2289 omap_badwidth_read8
,
2292 static CPUWriteMemoryFunc
* const omap_pwl_writefn
[] = {
2294 omap_badwidth_write8
,
2295 omap_badwidth_write8
,
2298 static void omap_pwl_reset(struct omap_mpu_state_s
*s
)
2307 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
2309 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2315 static void omap_pwl_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
2322 iomemtype
= cpu_register_io_memory(omap_pwl_readfn
,
2323 omap_pwl_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
2324 cpu_register_physical_memory(base
, 0x800, iomemtype
);
2326 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_pwl_clk_update
, s
, 1)[0]);
2329 /* Pulse-Width Tone module */
2330 static uint32_t omap_pwt_read(void *opaque
, target_phys_addr_t addr
)
2332 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2333 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2336 case 0x00: /* FRC */
2338 case 0x04: /* VCR */
2340 case 0x08: /* GCR */
2347 static void omap_pwt_write(void *opaque
, target_phys_addr_t addr
,
2350 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
2351 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2354 case 0x00: /* FRC */
2355 s
->pwt
.frc
= value
& 0x3f;
2357 case 0x04: /* VRC */
2358 if ((value
^ s
->pwt
.vrc
) & 1) {
2360 printf("%s: %iHz buzz on\n", __FUNCTION__
, (int)
2361 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2362 ((omap_clk_getrate(s
->pwt
.clk
) >> 3) /
2363 /* Pre-multiplexer divider */
2364 ((s
->pwt
.gcr
& 2) ? 1 : 154) /
2365 /* Octave multiplexer */
2366 (2 << (value
& 3)) *
2367 /* 101/107 divider */
2368 ((value
& (1 << 2)) ? 101 : 107) *
2370 ((value
& (1 << 3)) ? 49 : 55) *
2372 ((value
& (1 << 4)) ? 50 : 63) *
2373 /* 80/127 divider */
2374 ((value
& (1 << 5)) ? 80 : 127) /
2375 (107 * 55 * 63 * 127)));
2377 printf("%s: silence!\n", __FUNCTION__
);
2379 s
->pwt
.vrc
= value
& 0x7f;
2381 case 0x08: /* GCR */
2382 s
->pwt
.gcr
= value
& 3;
2390 static CPUReadMemoryFunc
* const omap_pwt_readfn
[] = {
2392 omap_badwidth_read8
,
2393 omap_badwidth_read8
,
2396 static CPUWriteMemoryFunc
* const omap_pwt_writefn
[] = {
2398 omap_badwidth_write8
,
2399 omap_badwidth_write8
,
2402 static void omap_pwt_reset(struct omap_mpu_state_s
*s
)
2409 static void omap_pwt_init(target_phys_addr_t base
, struct omap_mpu_state_s
*s
,
2417 iomemtype
= cpu_register_io_memory(omap_pwt_readfn
,
2418 omap_pwt_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
2419 cpu_register_physical_memory(base
, 0x800, iomemtype
);
2422 /* Real-time Clock module */
2438 struct tm current_tm
;
2443 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
2445 /* s->alarm is level-triggered */
2446 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
2449 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
2451 s
->alarm_ti
= mktimegm(&s
->alarm_tm
);
2452 if (s
->alarm_ti
== -1)
2453 printf("%s: conversion failed\n", __FUNCTION__
);
2456 static uint32_t omap_rtc_read(void *opaque
, target_phys_addr_t addr
)
2458 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2459 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2463 case 0x00: /* SECONDS_REG */
2464 return to_bcd(s
->current_tm
.tm_sec
);
2466 case 0x04: /* MINUTES_REG */
2467 return to_bcd(s
->current_tm
.tm_min
);
2469 case 0x08: /* HOURS_REG */
2471 return ((s
->current_tm
.tm_hour
> 11) << 7) |
2472 to_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
2474 return to_bcd(s
->current_tm
.tm_hour
);
2476 case 0x0c: /* DAYS_REG */
2477 return to_bcd(s
->current_tm
.tm_mday
);
2479 case 0x10: /* MONTHS_REG */
2480 return to_bcd(s
->current_tm
.tm_mon
+ 1);
2482 case 0x14: /* YEARS_REG */
2483 return to_bcd(s
->current_tm
.tm_year
% 100);
2485 case 0x18: /* WEEK_REG */
2486 return s
->current_tm
.tm_wday
;
2488 case 0x20: /* ALARM_SECONDS_REG */
2489 return to_bcd(s
->alarm_tm
.tm_sec
);
2491 case 0x24: /* ALARM_MINUTES_REG */
2492 return to_bcd(s
->alarm_tm
.tm_min
);
2494 case 0x28: /* ALARM_HOURS_REG */
2496 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
2497 to_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
2499 return to_bcd(s
->alarm_tm
.tm_hour
);
2501 case 0x2c: /* ALARM_DAYS_REG */
2502 return to_bcd(s
->alarm_tm
.tm_mday
);
2504 case 0x30: /* ALARM_MONTHS_REG */
2505 return to_bcd(s
->alarm_tm
.tm_mon
+ 1);
2507 case 0x34: /* ALARM_YEARS_REG */
2508 return to_bcd(s
->alarm_tm
.tm_year
% 100);
2510 case 0x40: /* RTC_CTRL_REG */
2511 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
2512 (s
->round
<< 1) | s
->running
;
2514 case 0x44: /* RTC_STATUS_REG */
2519 case 0x48: /* RTC_INTERRUPTS_REG */
2520 return s
->interrupts
;
2522 case 0x4c: /* RTC_COMP_LSB_REG */
2523 return ((uint16_t) s
->comp_reg
) & 0xff;
2525 case 0x50: /* RTC_COMP_MSB_REG */
2526 return ((uint16_t) s
->comp_reg
) >> 8;
2533 static void omap_rtc_write(void *opaque
, target_phys_addr_t addr
,
2536 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2537 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2542 case 0x00: /* SECONDS_REG */
2544 printf("RTC SEC_REG <-- %02x\n", value
);
2546 s
->ti
-= s
->current_tm
.tm_sec
;
2547 s
->ti
+= from_bcd(value
);
2550 case 0x04: /* MINUTES_REG */
2552 printf("RTC MIN_REG <-- %02x\n", value
);
2554 s
->ti
-= s
->current_tm
.tm_min
* 60;
2555 s
->ti
+= from_bcd(value
) * 60;
2558 case 0x08: /* HOURS_REG */
2560 printf("RTC HRS_REG <-- %02x\n", value
);
2562 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
2564 s
->ti
+= (from_bcd(value
& 0x3f) & 12) * 3600;
2565 s
->ti
+= ((value
>> 7) & 1) * 43200;
2567 s
->ti
+= from_bcd(value
& 0x3f) * 3600;
2570 case 0x0c: /* DAYS_REG */
2572 printf("RTC DAY_REG <-- %02x\n", value
);
2574 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
2575 s
->ti
+= from_bcd(value
) * 86400;
2578 case 0x10: /* MONTHS_REG */
2580 printf("RTC MTH_REG <-- %02x\n", value
);
2582 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2583 new_tm
.tm_mon
= from_bcd(value
);
2584 ti
[0] = mktimegm(&s
->current_tm
);
2585 ti
[1] = mktimegm(&new_tm
);
2587 if (ti
[0] != -1 && ti
[1] != -1) {
2591 /* A less accurate version */
2592 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
2593 s
->ti
+= from_bcd(value
) * 2592000;
2597 case 0x14: /* YEARS_REG */
2599 printf("RTC YRS_REG <-- %02x\n", value
);
2601 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2602 new_tm
.tm_year
+= from_bcd(value
) - (new_tm
.tm_year
% 100);
2603 ti
[0] = mktimegm(&s
->current_tm
);
2604 ti
[1] = mktimegm(&new_tm
);
2606 if (ti
[0] != -1 && ti
[1] != -1) {
2610 /* A less accurate version */
2611 s
->ti
-= (s
->current_tm
.tm_year
% 100) * 31536000;
2612 s
->ti
+= from_bcd(value
) * 31536000;
2616 case 0x18: /* WEEK_REG */
2617 return; /* Ignored */
2619 case 0x20: /* ALARM_SECONDS_REG */
2621 printf("ALM SEC_REG <-- %02x\n", value
);
2623 s
->alarm_tm
.tm_sec
= from_bcd(value
);
2624 omap_rtc_alarm_update(s
);
2627 case 0x24: /* ALARM_MINUTES_REG */
2629 printf("ALM MIN_REG <-- %02x\n", value
);
2631 s
->alarm_tm
.tm_min
= from_bcd(value
);
2632 omap_rtc_alarm_update(s
);
2635 case 0x28: /* ALARM_HOURS_REG */
2637 printf("ALM HRS_REG <-- %02x\n", value
);
2640 s
->alarm_tm
.tm_hour
=
2641 ((from_bcd(value
& 0x3f)) % 12) +
2642 ((value
>> 7) & 1) * 12;
2644 s
->alarm_tm
.tm_hour
= from_bcd(value
);
2645 omap_rtc_alarm_update(s
);
2648 case 0x2c: /* ALARM_DAYS_REG */
2650 printf("ALM DAY_REG <-- %02x\n", value
);
2652 s
->alarm_tm
.tm_mday
= from_bcd(value
);
2653 omap_rtc_alarm_update(s
);
2656 case 0x30: /* ALARM_MONTHS_REG */
2658 printf("ALM MON_REG <-- %02x\n", value
);
2660 s
->alarm_tm
.tm_mon
= from_bcd(value
);
2661 omap_rtc_alarm_update(s
);
2664 case 0x34: /* ALARM_YEARS_REG */
2666 printf("ALM YRS_REG <-- %02x\n", value
);
2668 s
->alarm_tm
.tm_year
= from_bcd(value
);
2669 omap_rtc_alarm_update(s
);
2672 case 0x40: /* RTC_CTRL_REG */
2674 printf("RTC CONTROL <-- %02x\n", value
);
2676 s
->pm_am
= (value
>> 3) & 1;
2677 s
->auto_comp
= (value
>> 2) & 1;
2678 s
->round
= (value
>> 1) & 1;
2679 s
->running
= value
& 1;
2681 s
->status
|= s
->running
<< 1;
2684 case 0x44: /* RTC_STATUS_REG */
2686 printf("RTC STATUSL <-- %02x\n", value
);
2688 s
->status
&= ~((value
& 0xc0) ^ 0x80);
2689 omap_rtc_interrupts_update(s
);
2692 case 0x48: /* RTC_INTERRUPTS_REG */
2694 printf("RTC INTRS <-- %02x\n", value
);
2696 s
->interrupts
= value
;
2699 case 0x4c: /* RTC_COMP_LSB_REG */
2701 printf("RTC COMPLSB <-- %02x\n", value
);
2703 s
->comp_reg
&= 0xff00;
2704 s
->comp_reg
|= 0x00ff & value
;
2707 case 0x50: /* RTC_COMP_MSB_REG */
2709 printf("RTC COMPMSB <-- %02x\n", value
);
2711 s
->comp_reg
&= 0x00ff;
2712 s
->comp_reg
|= 0xff00 & (value
<< 8);
2721 static CPUReadMemoryFunc
* const omap_rtc_readfn
[] = {
2723 omap_badwidth_read8
,
2724 omap_badwidth_read8
,
2727 static CPUWriteMemoryFunc
* const omap_rtc_writefn
[] = {
2729 omap_badwidth_write8
,
2730 omap_badwidth_write8
,
2733 static void omap_rtc_tick(void *opaque
)
2735 struct omap_rtc_s
*s
= opaque
;
2738 /* Round to nearest full minute. */
2739 if (s
->current_tm
.tm_sec
< 30)
2740 s
->ti
-= s
->current_tm
.tm_sec
;
2742 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
2747 memcpy(&s
->current_tm
, localtime(&s
->ti
), sizeof(s
->current_tm
));
2749 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
2751 omap_rtc_interrupts_update(s
);
2754 if (s
->interrupts
& 0x04)
2755 switch (s
->interrupts
& 3) {
2758 qemu_irq_pulse(s
->irq
);
2761 if (s
->current_tm
.tm_sec
)
2764 qemu_irq_pulse(s
->irq
);
2767 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
2770 qemu_irq_pulse(s
->irq
);
2773 if (s
->current_tm
.tm_sec
||
2774 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
2777 qemu_irq_pulse(s
->irq
);
2787 * Every full hour add a rough approximation of the compensation
2788 * register to the 32kHz Timer (which drives the RTC) value.
2790 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
2791 s
->tick
+= s
->comp_reg
* 1000 / 32768;
2793 qemu_mod_timer(s
->clk
, s
->tick
);
2796 static void omap_rtc_reset(struct omap_rtc_s
*s
)
2806 s
->tick
= qemu_get_clock_ms(rt_clock
);
2807 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
2808 s
->alarm_tm
.tm_mday
= 0x01;
2810 qemu_get_timedate(&tm
, 0);
2811 s
->ti
= mktimegm(&tm
);
2813 omap_rtc_alarm_update(s
);
2817 static struct omap_rtc_s
*omap_rtc_init(target_phys_addr_t base
,
2818 qemu_irq
*irq
, omap_clk clk
)
2821 struct omap_rtc_s
*s
= (struct omap_rtc_s
*)
2822 qemu_mallocz(sizeof(struct omap_rtc_s
));
2826 s
->clk
= qemu_new_timer_ms(rt_clock
, omap_rtc_tick
, s
);
2830 iomemtype
= cpu_register_io_memory(omap_rtc_readfn
,
2831 omap_rtc_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
2832 cpu_register_physical_memory(base
, 0x800, iomemtype
);
2837 /* Multi-channel Buffered Serial Port interfaces */
2838 struct omap_mcbsp_s
{
2858 QEMUTimer
*source_timer
;
2859 QEMUTimer
*sink_timer
;
2862 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
2866 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
2868 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
2871 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
2879 qemu_irq_pulse(s
->rxirq
);
2881 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
2883 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
2886 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
2894 qemu_irq_pulse(s
->txirq
);
2897 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
2899 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
2900 s
->spcr
[0] |= 1 << 2; /* RFULL */
2901 s
->spcr
[0] |= 1 << 1; /* RRDY */
2902 qemu_irq_raise(s
->rxdrq
);
2903 omap_mcbsp_intr_update(s
);
2906 static void omap_mcbsp_source_tick(void *opaque
)
2908 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
2909 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
2914 printf("%s: Rx FIFO overrun\n", __FUNCTION__
);
2916 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
2918 omap_mcbsp_rx_newdata(s
);
2919 qemu_mod_timer(s
->source_timer
, qemu_get_clock_ns(vm_clock
) +
2920 get_ticks_per_sec());
2923 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
2925 if (!s
->codec
|| !s
->codec
->rts
)
2926 omap_mcbsp_source_tick(s
);
2927 else if (s
->codec
->in
.len
) {
2928 s
->rx_req
= s
->codec
->in
.len
;
2929 omap_mcbsp_rx_newdata(s
);
2933 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
2935 qemu_del_timer(s
->source_timer
);
2938 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
2940 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
2941 qemu_irq_lower(s
->rxdrq
);
2942 omap_mcbsp_intr_update(s
);
2945 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
2947 s
->spcr
[1] |= 1 << 1; /* XRDY */
2948 qemu_irq_raise(s
->txdrq
);
2949 omap_mcbsp_intr_update(s
);
2952 static void omap_mcbsp_sink_tick(void *opaque
)
2954 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
2955 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
2960 printf("%s: Tx FIFO underrun\n", __FUNCTION__
);
2962 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
2964 omap_mcbsp_tx_newdata(s
);
2965 qemu_mod_timer(s
->sink_timer
, qemu_get_clock_ns(vm_clock
) +
2966 get_ticks_per_sec());
2969 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
2971 if (!s
->codec
|| !s
->codec
->cts
)
2972 omap_mcbsp_sink_tick(s
);
2973 else if (s
->codec
->out
.size
) {
2974 s
->tx_req
= s
->codec
->out
.size
;
2975 omap_mcbsp_tx_newdata(s
);
2979 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
2981 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
2982 qemu_irq_lower(s
->txdrq
);
2983 omap_mcbsp_intr_update(s
);
2984 if (s
->codec
&& s
->codec
->cts
)
2985 s
->codec
->tx_swallow(s
->codec
->opaque
);
2988 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
2991 omap_mcbsp_tx_done(s
);
2992 qemu_del_timer(s
->sink_timer
);
2995 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
2997 int prev_rx_rate
, prev_tx_rate
;
2998 int rx_rate
= 0, tx_rate
= 0;
2999 int cpu_rate
= 1500000; /* XXX */
3001 /* TODO: check CLKSTP bit */
3002 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3003 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3004 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3005 (s
->pcr
& (1 << 8))) { /* CLKRM */
3006 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3007 rx_rate
= cpu_rate
/
3008 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3011 rx_rate
= s
->codec
->rx_rate
;
3014 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3015 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3016 (s
->pcr
& (1 << 9))) { /* CLKXM */
3017 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3018 tx_rate
= cpu_rate
/
3019 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3022 tx_rate
= s
->codec
->tx_rate
;
3025 prev_tx_rate
= s
->tx_rate
;
3026 prev_rx_rate
= s
->rx_rate
;
3027 s
->tx_rate
= tx_rate
;
3028 s
->rx_rate
= rx_rate
;
3031 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3033 if (!prev_tx_rate
&& tx_rate
)
3034 omap_mcbsp_tx_start(s
);
3035 else if (s
->tx_rate
&& !tx_rate
)
3036 omap_mcbsp_tx_stop(s
);
3038 if (!prev_rx_rate
&& rx_rate
)
3039 omap_mcbsp_rx_start(s
);
3040 else if (prev_tx_rate
&& !tx_rate
)
3041 omap_mcbsp_rx_stop(s
);
3044 static uint32_t omap_mcbsp_read(void *opaque
, target_phys_addr_t addr
)
3046 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3047 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3051 case 0x00: /* DRR2 */
3052 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
3055 case 0x02: /* DRR1 */
3056 if (s
->rx_req
< 2) {
3057 printf("%s: Rx FIFO underrun\n", __FUNCTION__
);
3058 omap_mcbsp_rx_done(s
);
3061 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
3062 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
3063 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
3064 s
->codec
->in
.len
-= 2;
3068 omap_mcbsp_rx_done(s
);
3073 case 0x04: /* DXR2 */
3074 case 0x06: /* DXR1 */
3077 case 0x08: /* SPCR2 */
3079 case 0x0a: /* SPCR1 */
3081 case 0x0c: /* RCR2 */
3083 case 0x0e: /* RCR1 */
3085 case 0x10: /* XCR2 */
3087 case 0x12: /* XCR1 */
3089 case 0x14: /* SRGR2 */
3091 case 0x16: /* SRGR1 */
3093 case 0x18: /* MCR2 */
3095 case 0x1a: /* MCR1 */
3097 case 0x1c: /* RCERA */
3099 case 0x1e: /* RCERB */
3101 case 0x20: /* XCERA */
3103 case 0x22: /* XCERB */
3105 case 0x24: /* PCR0 */
3107 case 0x26: /* RCERC */
3109 case 0x28: /* RCERD */
3111 case 0x2a: /* XCERC */
3113 case 0x2c: /* XCERD */
3115 case 0x2e: /* RCERE */
3117 case 0x30: /* RCERF */
3119 case 0x32: /* XCERE */
3121 case 0x34: /* XCERF */
3123 case 0x36: /* RCERG */
3125 case 0x38: /* RCERH */
3127 case 0x3a: /* XCERG */
3129 case 0x3c: /* XCERH */
3137 static void omap_mcbsp_writeh(void *opaque
, target_phys_addr_t addr
,
3140 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3141 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3144 case 0x00: /* DRR2 */
3145 case 0x02: /* DRR1 */
3149 case 0x04: /* DXR2 */
3150 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3153 case 0x06: /* DXR1 */
3154 if (s
->tx_req
> 1) {
3156 if (s
->codec
&& s
->codec
->cts
) {
3157 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
3158 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
3161 omap_mcbsp_tx_done(s
);
3163 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
3166 case 0x08: /* SPCR2 */
3167 s
->spcr
[1] &= 0x0002;
3168 s
->spcr
[1] |= 0x03f9 & value
;
3169 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
3170 if (~value
& 1) /* XRST */
3172 omap_mcbsp_req_update(s
);
3174 case 0x0a: /* SPCR1 */
3175 s
->spcr
[0] &= 0x0006;
3176 s
->spcr
[0] |= 0xf8f9 & value
;
3177 if (value
& (1 << 15)) /* DLB */
3178 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__
);
3179 if (~value
& 1) { /* RRST */
3182 omap_mcbsp_rx_done(s
);
3184 omap_mcbsp_req_update(s
);
3187 case 0x0c: /* RCR2 */
3188 s
->rcr
[1] = value
& 0xffff;
3190 case 0x0e: /* RCR1 */
3191 s
->rcr
[0] = value
& 0x7fe0;
3193 case 0x10: /* XCR2 */
3194 s
->xcr
[1] = value
& 0xffff;
3196 case 0x12: /* XCR1 */
3197 s
->xcr
[0] = value
& 0x7fe0;
3199 case 0x14: /* SRGR2 */
3200 s
->srgr
[1] = value
& 0xffff;
3201 omap_mcbsp_req_update(s
);
3203 case 0x16: /* SRGR1 */
3204 s
->srgr
[0] = value
& 0xffff;
3205 omap_mcbsp_req_update(s
);
3207 case 0x18: /* MCR2 */
3208 s
->mcr
[1] = value
& 0x03e3;
3209 if (value
& 3) /* XMCM */
3210 printf("%s: Tx channel selection mode enable attempt\n",
3213 case 0x1a: /* MCR1 */
3214 s
->mcr
[0] = value
& 0x03e1;
3215 if (value
& 1) /* RMCM */
3216 printf("%s: Rx channel selection mode enable attempt\n",
3219 case 0x1c: /* RCERA */
3220 s
->rcer
[0] = value
& 0xffff;
3222 case 0x1e: /* RCERB */
3223 s
->rcer
[1] = value
& 0xffff;
3225 case 0x20: /* XCERA */
3226 s
->xcer
[0] = value
& 0xffff;
3228 case 0x22: /* XCERB */
3229 s
->xcer
[1] = value
& 0xffff;
3231 case 0x24: /* PCR0 */
3232 s
->pcr
= value
& 0x7faf;
3234 case 0x26: /* RCERC */
3235 s
->rcer
[2] = value
& 0xffff;
3237 case 0x28: /* RCERD */
3238 s
->rcer
[3] = value
& 0xffff;
3240 case 0x2a: /* XCERC */
3241 s
->xcer
[2] = value
& 0xffff;
3243 case 0x2c: /* XCERD */
3244 s
->xcer
[3] = value
& 0xffff;
3246 case 0x2e: /* RCERE */
3247 s
->rcer
[4] = value
& 0xffff;
3249 case 0x30: /* RCERF */
3250 s
->rcer
[5] = value
& 0xffff;
3252 case 0x32: /* XCERE */
3253 s
->xcer
[4] = value
& 0xffff;
3255 case 0x34: /* XCERF */
3256 s
->xcer
[5] = value
& 0xffff;
3258 case 0x36: /* RCERG */
3259 s
->rcer
[6] = value
& 0xffff;
3261 case 0x38: /* RCERH */
3262 s
->rcer
[7] = value
& 0xffff;
3264 case 0x3a: /* XCERG */
3265 s
->xcer
[6] = value
& 0xffff;
3267 case 0x3c: /* XCERH */
3268 s
->xcer
[7] = value
& 0xffff;
3275 static void omap_mcbsp_writew(void *opaque
, target_phys_addr_t addr
,
3278 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3279 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3281 if (offset
== 0x04) { /* DXR */
3282 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3284 if (s
->tx_req
> 3) {
3286 if (s
->codec
&& s
->codec
->cts
) {
3287 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3288 (value
>> 24) & 0xff;
3289 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3290 (value
>> 16) & 0xff;
3291 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3292 (value
>> 8) & 0xff;
3293 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3294 (value
>> 0) & 0xff;
3297 omap_mcbsp_tx_done(s
);
3299 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
3303 omap_badwidth_write16(opaque
, addr
, value
);
3306 static CPUReadMemoryFunc
* const omap_mcbsp_readfn
[] = {
3307 omap_badwidth_read16
,
3309 omap_badwidth_read16
,
3312 static CPUWriteMemoryFunc
* const omap_mcbsp_writefn
[] = {
3313 omap_badwidth_write16
,
3318 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
3320 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
3321 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
3322 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
3323 s
->srgr
[0] = 0x0001;
3324 s
->srgr
[1] = 0x2000;
3325 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
3326 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
3327 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
3328 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
3333 qemu_del_timer(s
->source_timer
);
3334 qemu_del_timer(s
->sink_timer
);
3337 struct omap_mcbsp_s
*omap_mcbsp_init(target_phys_addr_t base
,
3338 qemu_irq
*irq
, qemu_irq
*dma
, omap_clk clk
)
3341 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*)
3342 qemu_mallocz(sizeof(struct omap_mcbsp_s
));
3348 s
->sink_timer
= qemu_new_timer_ns(vm_clock
, omap_mcbsp_sink_tick
, s
);
3349 s
->source_timer
= qemu_new_timer_ns(vm_clock
, omap_mcbsp_source_tick
, s
);
3350 omap_mcbsp_reset(s
);
3352 iomemtype
= cpu_register_io_memory(omap_mcbsp_readfn
,
3353 omap_mcbsp_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
3354 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3359 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
3361 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3364 s
->rx_req
= s
->codec
->in
.len
;
3365 omap_mcbsp_rx_newdata(s
);
3369 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
3371 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3374 s
->tx_req
= s
->codec
->out
.size
;
3375 omap_mcbsp_tx_newdata(s
);
3379 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, I2SCodec
*slave
)
3382 slave
->rx_swallow
= qemu_allocate_irqs(omap_mcbsp_i2s_swallow
, s
, 1)[0];
3383 slave
->tx_start
= qemu_allocate_irqs(omap_mcbsp_i2s_start
, s
, 1)[0];
3386 /* LED Pulse Generators */
3398 static void omap_lpg_tick(void *opaque
)
3400 struct omap_lpg_s
*s
= opaque
;
3403 qemu_mod_timer(s
->tm
, qemu_get_clock_ms(rt_clock
) + s
->period
- s
->on
);
3405 qemu_mod_timer(s
->tm
, qemu_get_clock_ms(rt_clock
) + s
->on
);
3407 s
->cycle
= !s
->cycle
;
3408 printf("%s: LED is %s\n", __FUNCTION__
, s
->cycle
? "on" : "off");
3411 static void omap_lpg_update(struct omap_lpg_s
*s
)
3413 int64_t on
, period
= 1, ticks
= 1000;
3414 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3416 if (~s
->control
& (1 << 6)) /* LPGRES */
3418 else if (s
->control
& (1 << 7)) /* PERM_ON */
3421 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
3423 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
3424 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
3427 qemu_del_timer(s
->tm
);
3428 if (on
== period
&& s
->on
< s
->period
)
3429 printf("%s: LED is on\n", __FUNCTION__
);
3430 else if (on
== 0 && s
->on
)
3431 printf("%s: LED is off\n", __FUNCTION__
);
3432 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
3444 static void omap_lpg_reset(struct omap_lpg_s
*s
)
3452 static uint32_t omap_lpg_read(void *opaque
, target_phys_addr_t addr
)
3454 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3455 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3458 case 0x00: /* LCR */
3461 case 0x04: /* PMR */
3469 static void omap_lpg_write(void *opaque
, target_phys_addr_t addr
,
3472 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3473 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3476 case 0x00: /* LCR */
3477 if (~value
& (1 << 6)) /* LPGRES */
3479 s
->control
= value
& 0xff;
3483 case 0x04: /* PMR */
3484 s
->power
= value
& 0x01;
3494 static CPUReadMemoryFunc
* const omap_lpg_readfn
[] = {
3496 omap_badwidth_read8
,
3497 omap_badwidth_read8
,
3500 static CPUWriteMemoryFunc
* const omap_lpg_writefn
[] = {
3502 omap_badwidth_write8
,
3503 omap_badwidth_write8
,
3506 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
3508 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3514 static struct omap_lpg_s
*omap_lpg_init(target_phys_addr_t base
, omap_clk clk
)
3517 struct omap_lpg_s
*s
= (struct omap_lpg_s
*)
3518 qemu_mallocz(sizeof(struct omap_lpg_s
));
3520 s
->tm
= qemu_new_timer_ms(rt_clock
, omap_lpg_tick
, s
);
3524 iomemtype
= cpu_register_io_memory(omap_lpg_readfn
,
3525 omap_lpg_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
3526 cpu_register_physical_memory(base
, 0x800, iomemtype
);
3528 omap_clk_adduser(clk
, qemu_allocate_irqs(omap_lpg_clk_update
, s
, 1)[0]);
3533 /* MPUI Peripheral Bridge configuration */
3534 static uint32_t omap_mpui_io_read(void *opaque
, target_phys_addr_t addr
)
3536 if (addr
== OMAP_MPUI_BASE
) /* CMR */
3543 static CPUReadMemoryFunc
* const omap_mpui_io_readfn
[] = {
3544 omap_badwidth_read16
,
3546 omap_badwidth_read16
,
3549 static CPUWriteMemoryFunc
* const omap_mpui_io_writefn
[] = {
3550 omap_badwidth_write16
,
3551 omap_badwidth_write16
,
3552 omap_badwidth_write16
,
3555 static void omap_setup_mpui_io(struct omap_mpu_state_s
*mpu
)
3557 int iomemtype
= cpu_register_io_memory(omap_mpui_io_readfn
,
3558 omap_mpui_io_writefn
, mpu
, DEVICE_NATIVE_ENDIAN
);
3559 cpu_register_physical_memory(OMAP_MPUI_BASE
, 0x7fff, iomemtype
);
3562 /* General chip reset */
3563 static void omap1_mpu_reset(void *opaque
)
3565 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3567 omap_inth_reset(mpu
->ih
[0]);
3568 omap_inth_reset(mpu
->ih
[1]);
3569 omap_dma_reset(mpu
->dma
);
3570 omap_mpu_timer_reset(mpu
->timer
[0]);
3571 omap_mpu_timer_reset(mpu
->timer
[1]);
3572 omap_mpu_timer_reset(mpu
->timer
[2]);
3573 omap_wd_timer_reset(mpu
->wdt
);
3574 omap_os_timer_reset(mpu
->os_timer
);
3575 omap_lcdc_reset(mpu
->lcd
);
3576 omap_ulpd_pm_reset(mpu
);
3577 omap_pin_cfg_reset(mpu
);
3578 omap_mpui_reset(mpu
);
3579 omap_tipb_bridge_reset(mpu
->private_tipb
);
3580 omap_tipb_bridge_reset(mpu
->public_tipb
);
3581 omap_dpll_reset(&mpu
->dpll
[0]);
3582 omap_dpll_reset(&mpu
->dpll
[1]);
3583 omap_dpll_reset(&mpu
->dpll
[2]);
3584 omap_uart_reset(mpu
->uart
[0]);
3585 omap_uart_reset(mpu
->uart
[1]);
3586 omap_uart_reset(mpu
->uart
[2]);
3587 omap_mmc_reset(mpu
->mmc
);
3588 omap_mpuio_reset(mpu
->mpuio
);
3589 omap_uwire_reset(mpu
->microwire
);
3590 omap_pwl_reset(mpu
);
3591 omap_pwt_reset(mpu
);
3592 omap_i2c_reset(mpu
->i2c
[0]);
3593 omap_rtc_reset(mpu
->rtc
);
3594 omap_mcbsp_reset(mpu
->mcbsp1
);
3595 omap_mcbsp_reset(mpu
->mcbsp2
);
3596 omap_mcbsp_reset(mpu
->mcbsp3
);
3597 omap_lpg_reset(mpu
->led
[0]);
3598 omap_lpg_reset(mpu
->led
[1]);
3599 omap_clkm_reset(mpu
);
3600 cpu_reset(mpu
->env
);
3603 static const struct omap_map_s
{
3604 target_phys_addr_t phys_dsp
;
3605 target_phys_addr_t phys_mpu
;
3608 } omap15xx_dsp_mm
[] = {
3610 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
3611 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
3612 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
3613 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
3614 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
3615 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
3616 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
3617 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
3618 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
3619 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
3620 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
3621 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
3622 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
3623 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
3624 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
3625 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
3626 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
3628 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
3633 static void omap_setup_dsp_mapping(const struct omap_map_s
*map
)
3637 for (; map
->phys_dsp
; map
++) {
3638 io
= cpu_get_physical_page_desc(map
->phys_mpu
);
3640 cpu_register_physical_memory(map
->phys_dsp
, map
->size
, io
);
3644 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
3646 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3648 if (mpu
->env
->halted
)
3649 cpu_interrupt(mpu
->env
, CPU_INTERRUPT_EXITTB
);
3652 static const struct dma_irq_map omap1_dma_irq_map
[] = {
3653 { 0, OMAP_INT_DMA_CH0_6
},
3654 { 0, OMAP_INT_DMA_CH1_7
},
3655 { 0, OMAP_INT_DMA_CH2_8
},
3656 { 0, OMAP_INT_DMA_CH3
},
3657 { 0, OMAP_INT_DMA_CH4
},
3658 { 0, OMAP_INT_DMA_CH5
},
3659 { 1, OMAP_INT_1610_DMA_CH6
},
3660 { 1, OMAP_INT_1610_DMA_CH7
},
3661 { 1, OMAP_INT_1610_DMA_CH8
},
3662 { 1, OMAP_INT_1610_DMA_CH9
},
3663 { 1, OMAP_INT_1610_DMA_CH10
},
3664 { 1, OMAP_INT_1610_DMA_CH11
},
3665 { 1, OMAP_INT_1610_DMA_CH12
},
3666 { 1, OMAP_INT_1610_DMA_CH13
},
3667 { 1, OMAP_INT_1610_DMA_CH14
},
3668 { 1, OMAP_INT_1610_DMA_CH15
}
3671 /* DMA ports for OMAP1 */
3672 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
3673 target_phys_addr_t addr
)
3675 return range_covers_byte(OMAP_EMIFF_BASE
, s
->sdram_size
, addr
);
3678 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
3679 target_phys_addr_t addr
)
3681 return range_covers_byte(OMAP_EMIFS_BASE
, OMAP_EMIFF_BASE
- OMAP_EMIFS_BASE
,
3685 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
3686 target_phys_addr_t addr
)
3688 return range_covers_byte(OMAP_IMIF_BASE
, s
->sram_size
, addr
);
3691 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
3692 target_phys_addr_t addr
)
3694 return range_covers_byte(0xfffb0000, 0xffff0000 - 0xfffb0000, addr
);
3697 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
3698 target_phys_addr_t addr
)
3700 return range_covers_byte(OMAP_LOCALBUS_BASE
, 0x1000000, addr
);
3703 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
3704 target_phys_addr_t addr
)
3706 return range_covers_byte(0xe1010000, 0xe1020004 - 0xe1010000, addr
);
3709 struct omap_mpu_state_s
*omap310_mpu_init(unsigned long sdram_size
,
3713 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*)
3714 qemu_mallocz(sizeof(struct omap_mpu_state_s
));
3715 ram_addr_t imif_base
, emiff_base
;
3717 qemu_irq dma_irqs
[6];
3724 s
->mpu_model
= omap310
;
3725 s
->env
= cpu_init(core
);
3727 fprintf(stderr
, "Unable to find CPU definition\n");
3730 s
->sdram_size
= sdram_size
;
3731 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
3733 s
->wakeup
= qemu_allocate_irqs(omap_mpu_wakeup
, s
, 1)[0];
3738 /* Memory-mapped stuff */
3739 cpu_register_physical_memory(OMAP_EMIFF_BASE
, s
->sdram_size
,
3740 (emiff_base
= qemu_ram_alloc(NULL
, "omap1.dram",
3741 s
->sdram_size
)) | IO_MEM_RAM
);
3742 cpu_register_physical_memory(OMAP_IMIF_BASE
, s
->sram_size
,
3743 (imif_base
= qemu_ram_alloc(NULL
, "omap1.sram",
3744 s
->sram_size
)) | IO_MEM_RAM
);
3746 omap_clkm_init(0xfffece00, 0xe1008000, s
);
3748 cpu_irq
= arm_pic_init_cpu(s
->env
);
3749 s
->ih
[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s
->irq
[0],
3750 cpu_irq
[ARM_PIC_CPU_IRQ
], cpu_irq
[ARM_PIC_CPU_FIQ
],
3751 omap_findclk(s
, "arminth_ck"));
3752 s
->ih
[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s
->irq
[1],
3753 omap_inth_get_pin(s
->ih
[0], OMAP_INT_15XX_IH2_IRQ
),
3754 NULL
, omap_findclk(s
, "arminth_ck"));
3756 for (i
= 0; i
< 6; i
++)
3758 s
->irq
[omap1_dma_irq_map
[i
].ih
][omap1_dma_irq_map
[i
].intr
];
3759 s
->dma
= omap_dma_init(0xfffed800, dma_irqs
, s
->irq
[0][OMAP_INT_DMA_LCD
],
3760 s
, omap_findclk(s
, "dma_ck"), omap_dma_3_1
);
3762 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
3763 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
3764 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
3765 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
3766 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
3767 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
3769 /* Register SDRAM and SRAM DMA ports for fast transfers. */
3770 soc_dma_port_add_mem_ram(s
->dma
,
3771 emiff_base
, OMAP_EMIFF_BASE
, s
->sdram_size
);
3772 soc_dma_port_add_mem_ram(s
->dma
,
3773 imif_base
, OMAP_IMIF_BASE
, s
->sram_size
);
3775 s
->timer
[0] = omap_mpu_timer_init(0xfffec500,
3776 s
->irq
[0][OMAP_INT_TIMER1
],
3777 omap_findclk(s
, "mputim_ck"));
3778 s
->timer
[1] = omap_mpu_timer_init(0xfffec600,
3779 s
->irq
[0][OMAP_INT_TIMER2
],
3780 omap_findclk(s
, "mputim_ck"));
3781 s
->timer
[2] = omap_mpu_timer_init(0xfffec700,
3782 s
->irq
[0][OMAP_INT_TIMER3
],
3783 omap_findclk(s
, "mputim_ck"));
3785 s
->wdt
= omap_wd_timer_init(0xfffec800,
3786 s
->irq
[0][OMAP_INT_WD_TIMER
],
3787 omap_findclk(s
, "armwdt_ck"));
3789 s
->os_timer
= omap_os_timer_init(0xfffb9000,
3790 s
->irq
[1][OMAP_INT_OS_TIMER
],
3791 omap_findclk(s
, "clk32-kHz"));
3793 s
->lcd
= omap_lcdc_init(0xfffec000, s
->irq
[0][OMAP_INT_LCD_CTRL
],
3794 omap_dma_get_lcdch(s
->dma
), imif_base
, emiff_base
,
3795 omap_findclk(s
, "lcd_ck"));
3797 omap_ulpd_pm_init(0xfffe0800, s
);
3798 omap_pin_cfg_init(0xfffe1000, s
);
3801 omap_mpui_init(0xfffec900, s
);
3803 s
->private_tipb
= omap_tipb_bridge_init(0xfffeca00,
3804 s
->irq
[0][OMAP_INT_BRIDGE_PRIV
],
3805 omap_findclk(s
, "tipb_ck"));
3806 s
->public_tipb
= omap_tipb_bridge_init(0xfffed300,
3807 s
->irq
[0][OMAP_INT_BRIDGE_PUB
],
3808 omap_findclk(s
, "tipb_ck"));
3810 omap_tcmi_init(0xfffecc00, s
);
3812 s
->uart
[0] = omap_uart_init(0xfffb0000, s
->irq
[1][OMAP_INT_UART1
],
3813 omap_findclk(s
, "uart1_ck"),
3814 omap_findclk(s
, "uart1_ck"),
3815 s
->drq
[OMAP_DMA_UART1_TX
], s
->drq
[OMAP_DMA_UART1_RX
],
3818 s
->uart
[1] = omap_uart_init(0xfffb0800, s
->irq
[1][OMAP_INT_UART2
],
3819 omap_findclk(s
, "uart2_ck"),
3820 omap_findclk(s
, "uart2_ck"),
3821 s
->drq
[OMAP_DMA_UART2_TX
], s
->drq
[OMAP_DMA_UART2_RX
],
3823 serial_hds
[0] ? serial_hds
[1] : NULL
);
3824 s
->uart
[2] = omap_uart_init(0xfffb9800, s
->irq
[0][OMAP_INT_UART3
],
3825 omap_findclk(s
, "uart3_ck"),
3826 omap_findclk(s
, "uart3_ck"),
3827 s
->drq
[OMAP_DMA_UART3_TX
], s
->drq
[OMAP_DMA_UART3_RX
],
3829 serial_hds
[0] && serial_hds
[1] ? serial_hds
[2] : NULL
);
3831 omap_dpll_init(&s
->dpll
[0], 0xfffecf00, omap_findclk(s
, "dpll1"));
3832 omap_dpll_init(&s
->dpll
[1], 0xfffed000, omap_findclk(s
, "dpll2"));
3833 omap_dpll_init(&s
->dpll
[2], 0xfffed100, omap_findclk(s
, "dpll3"));
3835 dinfo
= drive_get(IF_SD
, 0, 0);
3837 fprintf(stderr
, "qemu: missing SecureDigital device\n");
3840 s
->mmc
= omap_mmc_init(0xfffb7800, dinfo
->bdrv
,
3841 s
->irq
[1][OMAP_INT_OQN
], &s
->drq
[OMAP_DMA_MMC_TX
],
3842 omap_findclk(s
, "mmc_ck"));
3844 s
->mpuio
= omap_mpuio_init(0xfffb5000,
3845 s
->irq
[1][OMAP_INT_KEYBOARD
], s
->irq
[1][OMAP_INT_MPUIO
],
3846 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
3848 s
->gpio
= qdev_create(NULL
, "omap-gpio");
3849 qdev_prop_set_int32(s
->gpio
, "mpu_model", s
->mpu_model
);
3850 qdev_init_nofail(s
->gpio
);
3851 sysbus_connect_irq(sysbus_from_qdev(s
->gpio
), 0,
3852 s
->irq
[0][OMAP_INT_GPIO_BANK1
]);
3853 sysbus_mmio_map(sysbus_from_qdev(s
->gpio
), 0, 0xfffce000);
3855 s
->microwire
= omap_uwire_init(0xfffb3000, &s
->irq
[1][OMAP_INT_uWireTX
],
3856 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
3858 omap_pwl_init(0xfffb5800, s
, omap_findclk(s
, "armxor_ck"));
3859 omap_pwt_init(0xfffb6000, s
, omap_findclk(s
, "armxor_ck"));
3861 s
->i2c
[0] = omap_i2c_init(0xfffb3800, s
->irq
[1][OMAP_INT_I2C
],
3862 &s
->drq
[OMAP_DMA_I2C_RX
], omap_findclk(s
, "mpuper_ck"));
3864 s
->rtc
= omap_rtc_init(0xfffb4800, &s
->irq
[1][OMAP_INT_RTC_TIMER
],
3865 omap_findclk(s
, "clk32-kHz"));
3867 s
->mcbsp1
= omap_mcbsp_init(0xfffb1800, &s
->irq
[1][OMAP_INT_McBSP1TX
],
3868 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
3869 s
->mcbsp2
= omap_mcbsp_init(0xfffb1000, &s
->irq
[0][OMAP_INT_310_McBSP2_TX
],
3870 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
3871 s
->mcbsp3
= omap_mcbsp_init(0xfffb7000, &s
->irq
[1][OMAP_INT_McBSP3TX
],
3872 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
3874 s
->led
[0] = omap_lpg_init(0xfffbd000, omap_findclk(s
, "clk32-kHz"));
3875 s
->led
[1] = omap_lpg_init(0xfffbd800, omap_findclk(s
, "clk32-kHz"));
3877 /* Register mappings not currenlty implemented:
3878 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
3879 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
3880 * USB W2FC fffb4000 - fffb47ff
3881 * Camera Interface fffb6800 - fffb6fff
3882 * USB Host fffba000 - fffba7ff
3883 * FAC fffba800 - fffbafff
3884 * HDQ/1-Wire fffbc000 - fffbc7ff
3885 * TIPB switches fffbc800 - fffbcfff
3886 * Mailbox fffcf000 - fffcf7ff
3887 * Local bus IF fffec100 - fffec1ff
3888 * Local bus MMU fffec200 - fffec2ff
3889 * DSP MMU fffed200 - fffed2ff
3892 omap_setup_dsp_mapping(omap15xx_dsp_mm
);
3893 omap_setup_mpui_io(s
);
3895 qemu_register_reset(omap1_mpu_reset
, s
);