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. */
31 /* Should signal the TCMI/GPMC */
32 uint32_t omap_badwidth_read8(void *opaque, target_phys_addr_t addr)
37 cpu_physical_memory_read(addr, (void *) &ret, 1);
41 void omap_badwidth_write8(void *opaque, target_phys_addr_t addr,
47 cpu_physical_memory_write(addr, (void *) &val8, 1);
50 uint32_t omap_badwidth_read16(void *opaque, target_phys_addr_t addr)
55 cpu_physical_memory_read(addr, (void *) &ret, 2);
59 void omap_badwidth_write16(void *opaque, target_phys_addr_t addr,
62 uint16_t val16 = value;
65 cpu_physical_memory_write(addr, (void *) &val16, 2);
68 uint32_t omap_badwidth_read32(void *opaque, target_phys_addr_t addr)
73 cpu_physical_memory_read(addr, (void *) &ret, 4);
77 void omap_badwidth_write32(void *opaque, target_phys_addr_t addr,
81 cpu_physical_memory_write(addr, (void *) &value, 4);
85 struct omap_mpu_timer_s {
102 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer)
104 uint64_t distance = qemu_get_clock(vm_clock) - timer->time;
106 if (timer->st && timer->enable && timer->rate)
107 return timer->val - muldiv64(distance >> (timer->ptv + 1),
108 timer->rate, get_ticks_per_sec());
113 static inline void omap_timer_sync(struct omap_mpu_timer_s *timer)
115 timer->val = omap_timer_read(timer);
116 timer->time = qemu_get_clock(vm_clock);
119 static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
123 if (timer->enable && timer->st && timer->rate) {
124 timer->val = timer->reset_val; /* Should skip this on clk enable */
125 expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
126 get_ticks_per_sec(), timer->rate);
128 /* If timer expiry would be sooner than in about 1 ms and
129 * auto-reload isn't set, then fire immediately. This is a hack
130 * to make systems like PalmOS run in acceptable time. PalmOS
131 * sets the interval to a very low value and polls the status bit
132 * in a busy loop when it wants to sleep just a couple of CPU
134 if (expires > (get_ticks_per_sec() >> 10) || timer->ar)
135 qemu_mod_timer(timer->timer, timer->time + expires);
137 qemu_bh_schedule(timer->tick);
139 qemu_del_timer(timer->timer);
142 static void omap_timer_fire(void *opaque)
144 struct omap_mpu_timer_s *timer = opaque;
152 /* Edge-triggered irq */
153 qemu_irq_pulse(timer->irq);
156 static void omap_timer_tick(void *opaque)
158 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
160 omap_timer_sync(timer);
161 omap_timer_fire(timer);
162 omap_timer_update(timer);
165 static void omap_timer_clk_update(void *opaque, int line, int on)
167 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
169 omap_timer_sync(timer);
170 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
171 omap_timer_update(timer);
174 static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer)
176 omap_clk_adduser(timer->clk,
177 qemu_allocate_irqs(omap_timer_clk_update, timer, 1)[0]);
178 timer->rate = omap_clk_getrate(timer->clk);
181 static uint32_t omap_mpu_timer_read(void *opaque, target_phys_addr_t addr)
183 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
186 case 0x00: /* CNTL_TIMER */
187 return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st;
189 case 0x04: /* LOAD_TIM */
192 case 0x08: /* READ_TIM */
193 return omap_timer_read(s);
200 static void omap_mpu_timer_write(void *opaque, target_phys_addr_t addr,
203 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
206 case 0x00: /* CNTL_TIMER */
208 s->enable = (value >> 5) & 1;
209 s->ptv = (value >> 2) & 7;
210 s->ar = (value >> 1) & 1;
212 omap_timer_update(s);
215 case 0x04: /* LOAD_TIM */
216 s->reset_val = value;
219 case 0x08: /* READ_TIM */
228 static CPUReadMemoryFunc * const omap_mpu_timer_readfn[] = {
229 omap_badwidth_read32,
230 omap_badwidth_read32,
234 static CPUWriteMemoryFunc * const omap_mpu_timer_writefn[] = {
235 omap_badwidth_write32,
236 omap_badwidth_write32,
237 omap_mpu_timer_write,
240 static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s)
242 qemu_del_timer(s->timer);
244 s->reset_val = 31337;
252 static struct omap_mpu_timer_s *omap_mpu_timer_init(target_phys_addr_t base,
253 qemu_irq irq, omap_clk clk)
256 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *)
257 qemu_mallocz(sizeof(struct omap_mpu_timer_s));
261 s->timer = qemu_new_timer(vm_clock, omap_timer_tick, s);
262 s->tick = qemu_bh_new(omap_timer_fire, s);
263 omap_mpu_timer_reset(s);
264 omap_timer_clk_setup(s);
266 iomemtype = cpu_register_io_memory(omap_mpu_timer_readfn,
267 omap_mpu_timer_writefn, s, DEVICE_NATIVE_ENDIAN);
268 cpu_register_physical_memory(base, 0x100, iomemtype);
274 struct omap_watchdog_timer_s {
275 struct omap_mpu_timer_s timer;
282 static uint32_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr)
284 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
287 case 0x00: /* CNTL_TIMER */
288 return (s->timer.ptv << 9) | (s->timer.ar << 8) |
289 (s->timer.st << 7) | (s->free << 1);
291 case 0x04: /* READ_TIMER */
292 return omap_timer_read(&s->timer);
294 case 0x08: /* TIMER_MODE */
295 return s->mode << 15;
302 static void omap_wd_timer_write(void *opaque, target_phys_addr_t addr,
305 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
308 case 0x00: /* CNTL_TIMER */
309 omap_timer_sync(&s->timer);
310 s->timer.ptv = (value >> 9) & 7;
311 s->timer.ar = (value >> 8) & 1;
312 s->timer.st = (value >> 7) & 1;
313 s->free = (value >> 1) & 1;
314 omap_timer_update(&s->timer);
317 case 0x04: /* LOAD_TIMER */
318 s->timer.reset_val = value & 0xffff;
321 case 0x08: /* TIMER_MODE */
322 if (!s->mode && ((value >> 15) & 1))
323 omap_clk_get(s->timer.clk);
324 s->mode |= (value >> 15) & 1;
325 if (s->last_wr == 0xf5) {
326 if ((value & 0xff) == 0xa0) {
329 omap_clk_put(s->timer.clk);
332 /* XXX: on T|E hardware somehow this has no effect,
333 * on Zire 71 it works as specified. */
335 qemu_system_reset_request();
338 s->last_wr = value & 0xff;
346 static CPUReadMemoryFunc * const omap_wd_timer_readfn[] = {
347 omap_badwidth_read16,
349 omap_badwidth_read16,
352 static CPUWriteMemoryFunc * const omap_wd_timer_writefn[] = {
353 omap_badwidth_write16,
355 omap_badwidth_write16,
358 static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s)
360 qemu_del_timer(s->timer.timer);
362 omap_clk_get(s->timer.clk);
368 s->timer.reset_val = 0xffff;
373 omap_timer_update(&s->timer);
376 static struct omap_watchdog_timer_s *omap_wd_timer_init(target_phys_addr_t base,
377 qemu_irq irq, omap_clk clk)
380 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *)
381 qemu_mallocz(sizeof(struct omap_watchdog_timer_s));
385 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
386 omap_wd_timer_reset(s);
387 omap_timer_clk_setup(&s->timer);
389 iomemtype = cpu_register_io_memory(omap_wd_timer_readfn,
390 omap_wd_timer_writefn, s, DEVICE_NATIVE_ENDIAN);
391 cpu_register_physical_memory(base, 0x100, iomemtype);
397 struct omap_32khz_timer_s {
398 struct omap_mpu_timer_s timer;
401 static uint32_t omap_os_timer_read(void *opaque, target_phys_addr_t addr)
403 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
404 int offset = addr & OMAP_MPUI_REG_MASK;
408 return s->timer.reset_val;
411 return omap_timer_read(&s->timer);
414 return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st;
423 static void omap_os_timer_write(void *opaque, target_phys_addr_t addr,
426 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
427 int offset = addr & OMAP_MPUI_REG_MASK;
431 s->timer.reset_val = value & 0x00ffffff;
439 s->timer.ar = (value >> 3) & 1;
440 s->timer.it_ena = (value >> 2) & 1;
441 if (s->timer.st != (value & 1) || (value & 2)) {
442 omap_timer_sync(&s->timer);
443 s->timer.enable = value & 1;
444 s->timer.st = value & 1;
445 omap_timer_update(&s->timer);
454 static CPUReadMemoryFunc * const omap_os_timer_readfn[] = {
455 omap_badwidth_read32,
456 omap_badwidth_read32,
460 static CPUWriteMemoryFunc * const omap_os_timer_writefn[] = {
461 omap_badwidth_write32,
462 omap_badwidth_write32,
466 static void omap_os_timer_reset(struct omap_32khz_timer_s *s)
468 qemu_del_timer(s->timer.timer);
471 s->timer.reset_val = 0x00ffffff;
478 static struct omap_32khz_timer_s *omap_os_timer_init(target_phys_addr_t base,
479 qemu_irq irq, omap_clk clk)
482 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *)
483 qemu_mallocz(sizeof(struct omap_32khz_timer_s));
487 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
488 omap_os_timer_reset(s);
489 omap_timer_clk_setup(&s->timer);
491 iomemtype = cpu_register_io_memory(omap_os_timer_readfn,
492 omap_os_timer_writefn, s, DEVICE_NATIVE_ENDIAN);
493 cpu_register_physical_memory(base, 0x800, iomemtype);
498 /* Ultra Low-Power Device Module */
499 static uint32_t omap_ulpd_pm_read(void *opaque, target_phys_addr_t addr)
501 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
505 case 0x14: /* IT_STATUS */
506 ret = s->ulpd_pm_regs[addr >> 2];
507 s->ulpd_pm_regs[addr >> 2] = 0;
508 qemu_irq_lower(s->irq[1][OMAP_INT_GAUGE_32K]);
511 case 0x18: /* Reserved */
512 case 0x1c: /* Reserved */
513 case 0x20: /* Reserved */
514 case 0x28: /* Reserved */
515 case 0x2c: /* Reserved */
517 case 0x00: /* COUNTER_32_LSB */
518 case 0x04: /* COUNTER_32_MSB */
519 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
520 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
521 case 0x10: /* GAUGING_CTRL */
522 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
523 case 0x30: /* CLOCK_CTRL */
524 case 0x34: /* SOFT_REQ */
525 case 0x38: /* COUNTER_32_FIQ */
526 case 0x3c: /* DPLL_CTRL */
527 case 0x40: /* STATUS_REQ */
528 /* XXX: check clk::usecount state for every clock */
529 case 0x48: /* LOCL_TIME */
530 case 0x4c: /* APLL_CTRL */
531 case 0x50: /* POWER_CTRL */
532 return s->ulpd_pm_regs[addr >> 2];
539 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s,
540 uint16_t diff, uint16_t value)
542 if (diff & (1 << 4)) /* USB_MCLK_EN */
543 omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1);
544 if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */
545 omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1);
548 static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s,
549 uint16_t diff, uint16_t value)
551 if (diff & (1 << 0)) /* SOFT_DPLL_REQ */
552 omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1);
553 if (diff & (1 << 1)) /* SOFT_COM_REQ */
554 omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1);
555 if (diff & (1 << 2)) /* SOFT_SDW_REQ */
556 omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1);
557 if (diff & (1 << 3)) /* SOFT_USB_REQ */
558 omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1);
561 static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr,
564 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
567 static const int bypass_div[4] = { 1, 2, 4, 4 };
571 case 0x00: /* COUNTER_32_LSB */
572 case 0x04: /* COUNTER_32_MSB */
573 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
574 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
575 case 0x14: /* IT_STATUS */
576 case 0x40: /* STATUS_REQ */
580 case 0x10: /* GAUGING_CTRL */
581 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
582 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
583 now = qemu_get_clock(vm_clock);
586 s->ulpd_gauge_start = now;
588 now -= s->ulpd_gauge_start;
591 ticks = muldiv64(now, 32768, get_ticks_per_sec());
592 s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff;
593 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff;
594 if (ticks >> 32) /* OVERFLOW_32K */
595 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
597 /* High frequency ticks */
598 ticks = muldiv64(now, 12000000, get_ticks_per_sec());
599 s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff;
600 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff;
601 if (ticks >> 32) /* OVERFLOW_HI_FREQ */
602 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
604 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
605 qemu_irq_raise(s->irq[1][OMAP_INT_GAUGE_32K]);
608 s->ulpd_pm_regs[addr >> 2] = value;
611 case 0x18: /* Reserved */
612 case 0x1c: /* Reserved */
613 case 0x20: /* Reserved */
614 case 0x28: /* Reserved */
615 case 0x2c: /* Reserved */
617 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
618 case 0x38: /* COUNTER_32_FIQ */
619 case 0x48: /* LOCL_TIME */
620 case 0x50: /* POWER_CTRL */
621 s->ulpd_pm_regs[addr >> 2] = value;
624 case 0x30: /* CLOCK_CTRL */
625 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
626 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
627 omap_ulpd_clk_update(s, diff, value);
630 case 0x34: /* SOFT_REQ */
631 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
632 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
633 omap_ulpd_req_update(s, diff, value);
636 case 0x3c: /* DPLL_CTRL */
637 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
638 * omitted altogether, probably a typo. */
639 /* This register has identical semantics with DPLL(1:3) control
640 * registers, see omap_dpll_write() */
641 diff = s->ulpd_pm_regs[addr >> 2] & value;
642 s->ulpd_pm_regs[addr >> 2] = value & 0x2fff;
643 if (diff & (0x3ff << 2)) {
644 if (value & (1 << 4)) { /* PLL_ENABLE */
645 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
646 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
648 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
651 omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
654 /* Enter the desired mode. */
655 s->ulpd_pm_regs[addr >> 2] =
656 (s->ulpd_pm_regs[addr >> 2] & 0xfffe) |
657 ((s->ulpd_pm_regs[addr >> 2] >> 4) & 1);
659 /* Act as if the lock is restored. */
660 s->ulpd_pm_regs[addr >> 2] |= 2;
663 case 0x4c: /* APLL_CTRL */
664 diff = s->ulpd_pm_regs[addr >> 2] & value;
665 s->ulpd_pm_regs[addr >> 2] = value & 0xf;
666 if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */
667 omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
668 (value & (1 << 0)) ? "apll" : "dpll4"));
676 static CPUReadMemoryFunc * const omap_ulpd_pm_readfn[] = {
677 omap_badwidth_read16,
679 omap_badwidth_read16,
682 static CPUWriteMemoryFunc * const omap_ulpd_pm_writefn[] = {
683 omap_badwidth_write16,
685 omap_badwidth_write16,
688 static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu)
690 mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001;
691 mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000;
692 mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001;
693 mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000;
694 mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000;
695 mpu->ulpd_pm_regs[0x18 >> 2] = 0x01;
696 mpu->ulpd_pm_regs[0x1c >> 2] = 0x01;
697 mpu->ulpd_pm_regs[0x20 >> 2] = 0x01;
698 mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff;
699 mpu->ulpd_pm_regs[0x28 >> 2] = 0x01;
700 mpu->ulpd_pm_regs[0x2c >> 2] = 0x01;
701 omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000);
702 mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000;
703 omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000);
704 mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000;
705 mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001;
706 mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211;
707 mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
708 mpu->ulpd_pm_regs[0x48 >> 2] = 0x960;
709 mpu->ulpd_pm_regs[0x4c >> 2] = 0x08;
710 mpu->ulpd_pm_regs[0x50 >> 2] = 0x08;
711 omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4);
712 omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4"));
715 static void omap_ulpd_pm_init(target_phys_addr_t base,
716 struct omap_mpu_state_s *mpu)
718 int iomemtype = cpu_register_io_memory(omap_ulpd_pm_readfn,
719 omap_ulpd_pm_writefn, mpu, DEVICE_NATIVE_ENDIAN);
721 cpu_register_physical_memory(base, 0x800, iomemtype);
722 omap_ulpd_pm_reset(mpu);
725 /* OMAP Pin Configuration */
726 static uint32_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr)
728 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
731 case 0x00: /* FUNC_MUX_CTRL_0 */
732 case 0x04: /* FUNC_MUX_CTRL_1 */
733 case 0x08: /* FUNC_MUX_CTRL_2 */
734 return s->func_mux_ctrl[addr >> 2];
736 case 0x0c: /* COMP_MODE_CTRL_0 */
737 return s->comp_mode_ctrl[0];
739 case 0x10: /* FUNC_MUX_CTRL_3 */
740 case 0x14: /* FUNC_MUX_CTRL_4 */
741 case 0x18: /* FUNC_MUX_CTRL_5 */
742 case 0x1c: /* FUNC_MUX_CTRL_6 */
743 case 0x20: /* FUNC_MUX_CTRL_7 */
744 case 0x24: /* FUNC_MUX_CTRL_8 */
745 case 0x28: /* FUNC_MUX_CTRL_9 */
746 case 0x2c: /* FUNC_MUX_CTRL_A */
747 case 0x30: /* FUNC_MUX_CTRL_B */
748 case 0x34: /* FUNC_MUX_CTRL_C */
749 case 0x38: /* FUNC_MUX_CTRL_D */
750 return s->func_mux_ctrl[(addr >> 2) - 1];
752 case 0x40: /* PULL_DWN_CTRL_0 */
753 case 0x44: /* PULL_DWN_CTRL_1 */
754 case 0x48: /* PULL_DWN_CTRL_2 */
755 case 0x4c: /* PULL_DWN_CTRL_3 */
756 return s->pull_dwn_ctrl[(addr & 0xf) >> 2];
758 case 0x50: /* GATE_INH_CTRL_0 */
759 return s->gate_inh_ctrl[0];
761 case 0x60: /* VOLTAGE_CTRL_0 */
762 return s->voltage_ctrl[0];
764 case 0x70: /* TEST_DBG_CTRL_0 */
765 return s->test_dbg_ctrl[0];
767 case 0x80: /* MOD_CONF_CTRL_0 */
768 return s->mod_conf_ctrl[0];
775 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s,
776 uint32_t diff, uint32_t value)
779 if (diff & (1 << 9)) /* BLUETOOTH */
780 omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
782 if (diff & (1 << 7)) /* USB.CLKO */
783 omap_clk_onoff(omap_findclk(s, "usb.clko"),
788 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s,
789 uint32_t diff, uint32_t value)
792 if (diff & (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
793 omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"),
795 if (diff & (1 << 1)) /* CLK32K */
796 omap_clk_onoff(omap_findclk(s, "clk32k_out"),
801 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s,
802 uint32_t diff, uint32_t value)
804 if (diff & (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
805 omap_clk_reparent(omap_findclk(s, "uart3_ck"),
806 omap_findclk(s, ((value >> 31) & 1) ?
807 "ck_48m" : "armper_ck"));
808 if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
809 omap_clk_reparent(omap_findclk(s, "uart2_ck"),
810 omap_findclk(s, ((value >> 30) & 1) ?
811 "ck_48m" : "armper_ck"));
812 if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
813 omap_clk_reparent(omap_findclk(s, "uart1_ck"),
814 omap_findclk(s, ((value >> 29) & 1) ?
815 "ck_48m" : "armper_ck"));
816 if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
817 omap_clk_reparent(omap_findclk(s, "mmc_ck"),
818 omap_findclk(s, ((value >> 23) & 1) ?
819 "ck_48m" : "armper_ck"));
820 if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
821 omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
822 omap_findclk(s, ((value >> 12) & 1) ?
823 "ck_48m" : "armper_ck"));
824 if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
825 omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1);
828 static void omap_pin_cfg_write(void *opaque, target_phys_addr_t addr,
831 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
835 case 0x00: /* FUNC_MUX_CTRL_0 */
836 diff = s->func_mux_ctrl[addr >> 2] ^ value;
837 s->func_mux_ctrl[addr >> 2] = value;
838 omap_pin_funcmux0_update(s, diff, value);
841 case 0x04: /* FUNC_MUX_CTRL_1 */
842 diff = s->func_mux_ctrl[addr >> 2] ^ value;
843 s->func_mux_ctrl[addr >> 2] = value;
844 omap_pin_funcmux1_update(s, diff, value);
847 case 0x08: /* FUNC_MUX_CTRL_2 */
848 s->func_mux_ctrl[addr >> 2] = value;
851 case 0x0c: /* COMP_MODE_CTRL_0 */
852 s->comp_mode_ctrl[0] = value;
853 s->compat1509 = (value != 0x0000eaef);
854 omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]);
855 omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]);
858 case 0x10: /* FUNC_MUX_CTRL_3 */
859 case 0x14: /* FUNC_MUX_CTRL_4 */
860 case 0x18: /* FUNC_MUX_CTRL_5 */
861 case 0x1c: /* FUNC_MUX_CTRL_6 */
862 case 0x20: /* FUNC_MUX_CTRL_7 */
863 case 0x24: /* FUNC_MUX_CTRL_8 */
864 case 0x28: /* FUNC_MUX_CTRL_9 */
865 case 0x2c: /* FUNC_MUX_CTRL_A */
866 case 0x30: /* FUNC_MUX_CTRL_B */
867 case 0x34: /* FUNC_MUX_CTRL_C */
868 case 0x38: /* FUNC_MUX_CTRL_D */
869 s->func_mux_ctrl[(addr >> 2) - 1] = value;
872 case 0x40: /* PULL_DWN_CTRL_0 */
873 case 0x44: /* PULL_DWN_CTRL_1 */
874 case 0x48: /* PULL_DWN_CTRL_2 */
875 case 0x4c: /* PULL_DWN_CTRL_3 */
876 s->pull_dwn_ctrl[(addr & 0xf) >> 2] = value;
879 case 0x50: /* GATE_INH_CTRL_0 */
880 s->gate_inh_ctrl[0] = value;
883 case 0x60: /* VOLTAGE_CTRL_0 */
884 s->voltage_ctrl[0] = value;
887 case 0x70: /* TEST_DBG_CTRL_0 */
888 s->test_dbg_ctrl[0] = value;
891 case 0x80: /* MOD_CONF_CTRL_0 */
892 diff = s->mod_conf_ctrl[0] ^ value;
893 s->mod_conf_ctrl[0] = value;
894 omap_pin_modconf1_update(s, diff, value);
902 static CPUReadMemoryFunc * const omap_pin_cfg_readfn[] = {
903 omap_badwidth_read32,
904 omap_badwidth_read32,
908 static CPUWriteMemoryFunc * const omap_pin_cfg_writefn[] = {
909 omap_badwidth_write32,
910 omap_badwidth_write32,
914 static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu)
916 /* Start in Compatibility Mode. */
918 omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0);
919 omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0);
920 omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0);
921 memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl));
922 memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl));
923 memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl));
924 memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl));
925 memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl));
926 memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl));
927 memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl));
930 static void omap_pin_cfg_init(target_phys_addr_t base,
931 struct omap_mpu_state_s *mpu)
933 int iomemtype = cpu_register_io_memory(omap_pin_cfg_readfn,
934 omap_pin_cfg_writefn, mpu, DEVICE_NATIVE_ENDIAN);
936 cpu_register_physical_memory(base, 0x800, iomemtype);
937 omap_pin_cfg_reset(mpu);
940 /* Device Identification, Die Identification */
941 static uint32_t omap_id_read(void *opaque, target_phys_addr_t addr)
943 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
946 case 0xfffe1800: /* DIE_ID_LSB */
948 case 0xfffe1804: /* DIE_ID_MSB */
951 case 0xfffe2000: /* PRODUCT_ID_LSB */
953 case 0xfffe2004: /* PRODUCT_ID_MSB */
956 case 0xfffed400: /* JTAG_ID_LSB */
957 switch (s->mpu_model) {
963 hw_error("%s: bad mpu model\n", __FUNCTION__);
967 case 0xfffed404: /* JTAG_ID_MSB */
968 switch (s->mpu_model) {
974 hw_error("%s: bad mpu model\n", __FUNCTION__);
983 static void omap_id_write(void *opaque, target_phys_addr_t addr,
989 static CPUReadMemoryFunc * const omap_id_readfn[] = {
990 omap_badwidth_read32,
991 omap_badwidth_read32,
995 static CPUWriteMemoryFunc * const omap_id_writefn[] = {
996 omap_badwidth_write32,
997 omap_badwidth_write32,
1001 static void omap_id_init(struct omap_mpu_state_s *mpu)
1003 int iomemtype = cpu_register_io_memory(omap_id_readfn,
1004 omap_id_writefn, mpu, DEVICE_NATIVE_ENDIAN);
1005 cpu_register_physical_memory_offset(0xfffe1800, 0x800, iomemtype, 0xfffe1800);
1006 cpu_register_physical_memory_offset(0xfffed400, 0x100, iomemtype, 0xfffed400);
1007 if (!cpu_is_omap15xx(mpu))
1008 cpu_register_physical_memory_offset(0xfffe2000, 0x800, iomemtype, 0xfffe2000);
1011 /* MPUI Control (Dummy) */
1012 static uint32_t omap_mpui_read(void *opaque, target_phys_addr_t addr)
1014 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1017 case 0x00: /* CTRL */
1018 return s->mpui_ctrl;
1019 case 0x04: /* DEBUG_ADDR */
1021 case 0x08: /* DEBUG_DATA */
1023 case 0x0c: /* DEBUG_FLAG */
1025 case 0x10: /* STATUS */
1028 /* Not in OMAP310 */
1029 case 0x14: /* DSP_STATUS */
1030 case 0x18: /* DSP_BOOT_CONFIG */
1032 case 0x1c: /* DSP_MPUI_CONFIG */
1040 static void omap_mpui_write(void *opaque, target_phys_addr_t addr,
1043 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1046 case 0x00: /* CTRL */
1047 s->mpui_ctrl = value & 0x007fffff;
1050 case 0x04: /* DEBUG_ADDR */
1051 case 0x08: /* DEBUG_DATA */
1052 case 0x0c: /* DEBUG_FLAG */
1053 case 0x10: /* STATUS */
1054 /* Not in OMAP310 */
1055 case 0x14: /* DSP_STATUS */
1057 case 0x18: /* DSP_BOOT_CONFIG */
1058 case 0x1c: /* DSP_MPUI_CONFIG */
1066 static CPUReadMemoryFunc * const omap_mpui_readfn[] = {
1067 omap_badwidth_read32,
1068 omap_badwidth_read32,
1072 static CPUWriteMemoryFunc * const omap_mpui_writefn[] = {
1073 omap_badwidth_write32,
1074 omap_badwidth_write32,
1078 static void omap_mpui_reset(struct omap_mpu_state_s *s)
1080 s->mpui_ctrl = 0x0003ff1b;
1083 static void omap_mpui_init(target_phys_addr_t base,
1084 struct omap_mpu_state_s *mpu)
1086 int iomemtype = cpu_register_io_memory(omap_mpui_readfn,
1087 omap_mpui_writefn, mpu, DEVICE_NATIVE_ENDIAN);
1089 cpu_register_physical_memory(base, 0x100, iomemtype);
1091 omap_mpui_reset(mpu);
1095 struct omap_tipb_bridge_s {
1102 uint16_t enh_control;
1105 static uint32_t omap_tipb_bridge_read(void *opaque, target_phys_addr_t addr)
1107 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1110 case 0x00: /* TIPB_CNTL */
1112 case 0x04: /* TIPB_BUS_ALLOC */
1114 case 0x08: /* MPU_TIPB_CNTL */
1116 case 0x0c: /* ENHANCED_TIPB_CNTL */
1117 return s->enh_control;
1118 case 0x10: /* ADDRESS_DBG */
1119 case 0x14: /* DATA_DEBUG_LOW */
1120 case 0x18: /* DATA_DEBUG_HIGH */
1122 case 0x1c: /* DEBUG_CNTR_SIG */
1130 static void omap_tipb_bridge_write(void *opaque, target_phys_addr_t addr,
1133 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1136 case 0x00: /* TIPB_CNTL */
1137 s->control = value & 0xffff;
1140 case 0x04: /* TIPB_BUS_ALLOC */
1141 s->alloc = value & 0x003f;
1144 case 0x08: /* MPU_TIPB_CNTL */
1145 s->buffer = value & 0x0003;
1148 case 0x0c: /* ENHANCED_TIPB_CNTL */
1149 s->width_intr = !(value & 2);
1150 s->enh_control = value & 0x000f;
1153 case 0x10: /* ADDRESS_DBG */
1154 case 0x14: /* DATA_DEBUG_LOW */
1155 case 0x18: /* DATA_DEBUG_HIGH */
1156 case 0x1c: /* DEBUG_CNTR_SIG */
1165 static CPUReadMemoryFunc * const omap_tipb_bridge_readfn[] = {
1166 omap_badwidth_read16,
1167 omap_tipb_bridge_read,
1168 omap_tipb_bridge_read,
1171 static CPUWriteMemoryFunc * const omap_tipb_bridge_writefn[] = {
1172 omap_badwidth_write16,
1173 omap_tipb_bridge_write,
1174 omap_tipb_bridge_write,
1177 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s)
1179 s->control = 0xffff;
1182 s->enh_control = 0x000f;
1185 static struct omap_tipb_bridge_s *omap_tipb_bridge_init(target_phys_addr_t base,
1186 qemu_irq abort_irq, omap_clk clk)
1189 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *)
1190 qemu_mallocz(sizeof(struct omap_tipb_bridge_s));
1192 s->abort = abort_irq;
1193 omap_tipb_bridge_reset(s);
1195 iomemtype = cpu_register_io_memory(omap_tipb_bridge_readfn,
1196 omap_tipb_bridge_writefn, s, DEVICE_NATIVE_ENDIAN);
1197 cpu_register_physical_memory(base, 0x100, iomemtype);
1202 /* Dummy Traffic Controller's Memory Interface */
1203 static uint32_t omap_tcmi_read(void *opaque, target_phys_addr_t addr)
1205 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1209 case 0x00: /* IMIF_PRIO */
1210 case 0x04: /* EMIFS_PRIO */
1211 case 0x08: /* EMIFF_PRIO */
1212 case 0x0c: /* EMIFS_CONFIG */
1213 case 0x10: /* EMIFS_CS0_CONFIG */
1214 case 0x14: /* EMIFS_CS1_CONFIG */
1215 case 0x18: /* EMIFS_CS2_CONFIG */
1216 case 0x1c: /* EMIFS_CS3_CONFIG */
1217 case 0x24: /* EMIFF_MRS */
1218 case 0x28: /* TIMEOUT1 */
1219 case 0x2c: /* TIMEOUT2 */
1220 case 0x30: /* TIMEOUT3 */
1221 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1222 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1223 return s->tcmi_regs[addr >> 2];
1225 case 0x20: /* EMIFF_SDRAM_CONFIG */
1226 ret = s->tcmi_regs[addr >> 2];
1227 s->tcmi_regs[addr >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1228 /* XXX: We can try using the VGA_DIRTY flag for this */
1236 static void omap_tcmi_write(void *opaque, target_phys_addr_t addr,
1239 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1242 case 0x00: /* IMIF_PRIO */
1243 case 0x04: /* EMIFS_PRIO */
1244 case 0x08: /* EMIFF_PRIO */
1245 case 0x10: /* EMIFS_CS0_CONFIG */
1246 case 0x14: /* EMIFS_CS1_CONFIG */
1247 case 0x18: /* EMIFS_CS2_CONFIG */
1248 case 0x1c: /* EMIFS_CS3_CONFIG */
1249 case 0x20: /* EMIFF_SDRAM_CONFIG */
1250 case 0x24: /* EMIFF_MRS */
1251 case 0x28: /* TIMEOUT1 */
1252 case 0x2c: /* TIMEOUT2 */
1253 case 0x30: /* TIMEOUT3 */
1254 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1255 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1256 s->tcmi_regs[addr >> 2] = value;
1258 case 0x0c: /* EMIFS_CONFIG */
1259 s->tcmi_regs[addr >> 2] = (value & 0xf) | (1 << 4);
1267 static CPUReadMemoryFunc * const omap_tcmi_readfn[] = {
1268 omap_badwidth_read32,
1269 omap_badwidth_read32,
1273 static CPUWriteMemoryFunc * const omap_tcmi_writefn[] = {
1274 omap_badwidth_write32,
1275 omap_badwidth_write32,
1279 static void omap_tcmi_reset(struct omap_mpu_state_s *mpu)
1281 mpu->tcmi_regs[0x00 >> 2] = 0x00000000;
1282 mpu->tcmi_regs[0x04 >> 2] = 0x00000000;
1283 mpu->tcmi_regs[0x08 >> 2] = 0x00000000;
1284 mpu->tcmi_regs[0x0c >> 2] = 0x00000010;
1285 mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb;
1286 mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb;
1287 mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb;
1288 mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb;
1289 mpu->tcmi_regs[0x20 >> 2] = 0x00618800;
1290 mpu->tcmi_regs[0x24 >> 2] = 0x00000037;
1291 mpu->tcmi_regs[0x28 >> 2] = 0x00000000;
1292 mpu->tcmi_regs[0x2c >> 2] = 0x00000000;
1293 mpu->tcmi_regs[0x30 >> 2] = 0x00000000;
1294 mpu->tcmi_regs[0x3c >> 2] = 0x00000003;
1295 mpu->tcmi_regs[0x40 >> 2] = 0x00000000;
1298 static void omap_tcmi_init(target_phys_addr_t base,
1299 struct omap_mpu_state_s *mpu)
1301 int iomemtype = cpu_register_io_memory(omap_tcmi_readfn,
1302 omap_tcmi_writefn, mpu, DEVICE_NATIVE_ENDIAN);
1304 cpu_register_physical_memory(base, 0x100, iomemtype);
1305 omap_tcmi_reset(mpu);
1308 /* Digital phase-locked loops control */
1309 static uint32_t omap_dpll_read(void *opaque, target_phys_addr_t addr)
1311 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1313 if (addr == 0x00) /* CTL_REG */
1320 static void omap_dpll_write(void *opaque, target_phys_addr_t addr,
1323 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1325 static const int bypass_div[4] = { 1, 2, 4, 4 };
1328 if (addr == 0x00) { /* CTL_REG */
1329 /* See omap_ulpd_pm_write() too */
1330 diff = s->mode & value;
1331 s->mode = value & 0x2fff;
1332 if (diff & (0x3ff << 2)) {
1333 if (value & (1 << 4)) { /* PLL_ENABLE */
1334 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1335 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1337 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1340 omap_clk_setrate(s->dpll, div, mult);
1343 /* Enter the desired mode. */
1344 s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1);
1346 /* Act as if the lock is restored. */
1353 static CPUReadMemoryFunc * const omap_dpll_readfn[] = {
1354 omap_badwidth_read16,
1356 omap_badwidth_read16,
1359 static CPUWriteMemoryFunc * const omap_dpll_writefn[] = {
1360 omap_badwidth_write16,
1362 omap_badwidth_write16,
1365 static void omap_dpll_reset(struct dpll_ctl_s *s)
1368 omap_clk_setrate(s->dpll, 1, 1);
1371 static void omap_dpll_init(struct dpll_ctl_s *s, target_phys_addr_t base,
1374 int iomemtype = cpu_register_io_memory(omap_dpll_readfn,
1375 omap_dpll_writefn, s, DEVICE_NATIVE_ENDIAN);
1380 cpu_register_physical_memory(base, 0x100, iomemtype);
1383 /* MPU Clock/Reset/Power Mode Control */
1384 static uint32_t omap_clkm_read(void *opaque, target_phys_addr_t addr)
1386 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1389 case 0x00: /* ARM_CKCTL */
1390 return s->clkm.arm_ckctl;
1392 case 0x04: /* ARM_IDLECT1 */
1393 return s->clkm.arm_idlect1;
1395 case 0x08: /* ARM_IDLECT2 */
1396 return s->clkm.arm_idlect2;
1398 case 0x0c: /* ARM_EWUPCT */
1399 return s->clkm.arm_ewupct;
1401 case 0x10: /* ARM_RSTCT1 */
1402 return s->clkm.arm_rstct1;
1404 case 0x14: /* ARM_RSTCT2 */
1405 return s->clkm.arm_rstct2;
1407 case 0x18: /* ARM_SYSST */
1408 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start;
1410 case 0x1c: /* ARM_CKOUT1 */
1411 return s->clkm.arm_ckout1;
1413 case 0x20: /* ARM_CKOUT2 */
1421 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s,
1422 uint16_t diff, uint16_t value)
1426 if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */
1427 if (value & (1 << 14))
1430 clk = omap_findclk(s, "arminth_ck");
1431 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
1434 if (diff & (1 << 12)) { /* ARM_TIMXO */
1435 clk = omap_findclk(s, "armtim_ck");
1436 if (value & (1 << 12))
1437 omap_clk_reparent(clk, omap_findclk(s, "clkin"));
1439 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
1442 if (diff & (3 << 10)) { /* DSPMMUDIV */
1443 clk = omap_findclk(s, "dspmmu_ck");
1444 omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1);
1446 if (diff & (3 << 8)) { /* TCDIV */
1447 clk = omap_findclk(s, "tc_ck");
1448 omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1);
1450 if (diff & (3 << 6)) { /* DSPDIV */
1451 clk = omap_findclk(s, "dsp_ck");
1452 omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1);
1454 if (diff & (3 << 4)) { /* ARMDIV */
1455 clk = omap_findclk(s, "arm_ck");
1456 omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1);
1458 if (diff & (3 << 2)) { /* LCDDIV */
1459 clk = omap_findclk(s, "lcd_ck");
1460 omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1);
1462 if (diff & (3 << 0)) { /* PERDIV */
1463 clk = omap_findclk(s, "armper_ck");
1464 omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1);
1468 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s,
1469 uint16_t diff, uint16_t value)
1473 if (value & (1 << 11)) /* SETARM_IDLE */
1474 cpu_interrupt(s->env, CPU_INTERRUPT_HALT);
1475 if (!(value & (1 << 10))) /* WKUP_MODE */
1476 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
1478 #define SET_CANIDLE(clock, bit) \
1479 if (diff & (1 << bit)) { \
1480 clk = omap_findclk(s, clock); \
1481 omap_clk_canidle(clk, (value >> bit) & 1); \
1483 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1484 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1485 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1486 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1487 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1488 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1489 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1490 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1491 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1492 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1493 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1494 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1495 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1496 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1499 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s,
1500 uint16_t diff, uint16_t value)
1504 #define SET_ONOFF(clock, bit) \
1505 if (diff & (1 << bit)) { \
1506 clk = omap_findclk(s, clock); \
1507 omap_clk_onoff(clk, (value >> bit) & 1); \
1509 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1510 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1511 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1512 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1513 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1514 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1515 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1516 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1517 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1518 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1519 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1522 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s,
1523 uint16_t diff, uint16_t value)
1527 if (diff & (3 << 4)) { /* TCLKOUT */
1528 clk = omap_findclk(s, "tclk_out");
1529 switch ((value >> 4) & 3) {
1531 omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
1532 omap_clk_onoff(clk, 1);
1535 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
1536 omap_clk_onoff(clk, 1);
1539 omap_clk_onoff(clk, 0);
1542 if (diff & (3 << 2)) { /* DCLKOUT */
1543 clk = omap_findclk(s, "dclk_out");
1544 switch ((value >> 2) & 3) {
1546 omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
1549 omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
1552 omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
1555 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
1559 if (diff & (3 << 0)) { /* ACLKOUT */
1560 clk = omap_findclk(s, "aclk_out");
1561 switch ((value >> 0) & 3) {
1563 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
1564 omap_clk_onoff(clk, 1);
1567 omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
1568 omap_clk_onoff(clk, 1);
1571 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
1572 omap_clk_onoff(clk, 1);
1575 omap_clk_onoff(clk, 0);
1580 static void omap_clkm_write(void *opaque, target_phys_addr_t addr,
1583 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1586 static const char *clkschemename[8] = {
1587 "fully synchronous", "fully asynchronous", "synchronous scalable",
1588 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1592 case 0x00: /* ARM_CKCTL */
1593 diff = s->clkm.arm_ckctl ^ value;
1594 s->clkm.arm_ckctl = value & 0x7fff;
1595 omap_clkm_ckctl_update(s, diff, value);
1598 case 0x04: /* ARM_IDLECT1 */
1599 diff = s->clkm.arm_idlect1 ^ value;
1600 s->clkm.arm_idlect1 = value & 0x0fff;
1601 omap_clkm_idlect1_update(s, diff, value);
1604 case 0x08: /* ARM_IDLECT2 */
1605 diff = s->clkm.arm_idlect2 ^ value;
1606 s->clkm.arm_idlect2 = value & 0x07ff;
1607 omap_clkm_idlect2_update(s, diff, value);
1610 case 0x0c: /* ARM_EWUPCT */
1611 s->clkm.arm_ewupct = value & 0x003f;
1614 case 0x10: /* ARM_RSTCT1 */
1615 diff = s->clkm.arm_rstct1 ^ value;
1616 s->clkm.arm_rstct1 = value & 0x0007;
1618 qemu_system_reset_request();
1619 s->clkm.cold_start = 0xa;
1621 if (diff & ~value & 4) { /* DSP_RST */
1623 omap_tipb_bridge_reset(s->private_tipb);
1624 omap_tipb_bridge_reset(s->public_tipb);
1626 if (diff & 2) { /* DSP_EN */
1627 clk = omap_findclk(s, "dsp_ck");
1628 omap_clk_canidle(clk, (~value >> 1) & 1);
1632 case 0x14: /* ARM_RSTCT2 */
1633 s->clkm.arm_rstct2 = value & 0x0001;
1636 case 0x18: /* ARM_SYSST */
1637 if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) {
1638 s->clkm.clocking_scheme = (value >> 11) & 7;
1639 printf("%s: clocking scheme set to %s\n", __FUNCTION__,
1640 clkschemename[s->clkm.clocking_scheme]);
1642 s->clkm.cold_start &= value & 0x3f;
1645 case 0x1c: /* ARM_CKOUT1 */
1646 diff = s->clkm.arm_ckout1 ^ value;
1647 s->clkm.arm_ckout1 = value & 0x003f;
1648 omap_clkm_ckout1_update(s, diff, value);
1651 case 0x20: /* ARM_CKOUT2 */
1657 static CPUReadMemoryFunc * const omap_clkm_readfn[] = {
1658 omap_badwidth_read16,
1660 omap_badwidth_read16,
1663 static CPUWriteMemoryFunc * const omap_clkm_writefn[] = {
1664 omap_badwidth_write16,
1666 omap_badwidth_write16,
1669 static uint32_t omap_clkdsp_read(void *opaque, target_phys_addr_t addr)
1671 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1674 case 0x04: /* DSP_IDLECT1 */
1675 return s->clkm.dsp_idlect1;
1677 case 0x08: /* DSP_IDLECT2 */
1678 return s->clkm.dsp_idlect2;
1680 case 0x14: /* DSP_RSTCT2 */
1681 return s->clkm.dsp_rstct2;
1683 case 0x18: /* DSP_SYSST */
1684 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start |
1685 (s->env->halted << 6); /* Quite useless... */
1692 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s,
1693 uint16_t diff, uint16_t value)
1697 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1700 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s,
1701 uint16_t diff, uint16_t value)
1705 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1708 static void omap_clkdsp_write(void *opaque, target_phys_addr_t addr,
1711 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1715 case 0x04: /* DSP_IDLECT1 */
1716 diff = s->clkm.dsp_idlect1 ^ value;
1717 s->clkm.dsp_idlect1 = value & 0x01f7;
1718 omap_clkdsp_idlect1_update(s, diff, value);
1721 case 0x08: /* DSP_IDLECT2 */
1722 s->clkm.dsp_idlect2 = value & 0x0037;
1723 diff = s->clkm.dsp_idlect1 ^ value;
1724 omap_clkdsp_idlect2_update(s, diff, value);
1727 case 0x14: /* DSP_RSTCT2 */
1728 s->clkm.dsp_rstct2 = value & 0x0001;
1731 case 0x18: /* DSP_SYSST */
1732 s->clkm.cold_start &= value & 0x3f;
1740 static CPUReadMemoryFunc * const omap_clkdsp_readfn[] = {
1741 omap_badwidth_read16,
1743 omap_badwidth_read16,
1746 static CPUWriteMemoryFunc * const omap_clkdsp_writefn[] = {
1747 omap_badwidth_write16,
1749 omap_badwidth_write16,
1752 static void omap_clkm_reset(struct omap_mpu_state_s *s)
1754 if (s->wdt && s->wdt->reset)
1755 s->clkm.cold_start = 0x6;
1756 s->clkm.clocking_scheme = 0;
1757 omap_clkm_ckctl_update(s, ~0, 0x3000);
1758 s->clkm.arm_ckctl = 0x3000;
1759 omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 ^ 0x0400, 0x0400);
1760 s->clkm.arm_idlect1 = 0x0400;
1761 omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 ^ 0x0100, 0x0100);
1762 s->clkm.arm_idlect2 = 0x0100;
1763 s->clkm.arm_ewupct = 0x003f;
1764 s->clkm.arm_rstct1 = 0x0000;
1765 s->clkm.arm_rstct2 = 0x0000;
1766 s->clkm.arm_ckout1 = 0x0015;
1767 s->clkm.dpll1_mode = 0x2002;
1768 omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040);
1769 s->clkm.dsp_idlect1 = 0x0040;
1770 omap_clkdsp_idlect2_update(s, ~0, 0x0000);
1771 s->clkm.dsp_idlect2 = 0x0000;
1772 s->clkm.dsp_rstct2 = 0x0000;
1775 static void omap_clkm_init(target_phys_addr_t mpu_base,
1776 target_phys_addr_t dsp_base, struct omap_mpu_state_s *s)
1778 int iomemtype[2] = {
1779 cpu_register_io_memory(omap_clkm_readfn, omap_clkm_writefn, s,
1780 DEVICE_NATIVE_ENDIAN),
1781 cpu_register_io_memory(omap_clkdsp_readfn, omap_clkdsp_writefn, s,
1782 DEVICE_NATIVE_ENDIAN),
1785 s->clkm.arm_idlect1 = 0x03ff;
1786 s->clkm.arm_idlect2 = 0x0100;
1787 s->clkm.dsp_idlect1 = 0x0002;
1789 s->clkm.cold_start = 0x3a;
1791 cpu_register_physical_memory(mpu_base, 0x100, iomemtype[0]);
1792 cpu_register_physical_memory(dsp_base, 0x1000, iomemtype[1]);
1796 struct omap_mpuio_s {
1800 qemu_irq handler[16];
1821 static void omap_mpuio_set(void *opaque, int line, int level)
1823 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1824 uint16_t prev = s->inputs;
1827 s->inputs |= 1 << line;
1829 s->inputs &= ~(1 << line);
1831 if (((1 << line) & s->dir & ~s->mask) && s->clk) {
1832 if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
1833 s->ints |= 1 << line;
1834 qemu_irq_raise(s->irq);
1837 if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1838 (s->event >> 1) == line) /* PIN_SELECT */
1839 s->latch = s->inputs;
1843 static void omap_mpuio_kbd_update(struct omap_mpuio_s *s)
1846 uint8_t *row, rows = 0, cols = ~s->cols;
1848 for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1)
1852 qemu_set_irq(s->kbd_irq, rows && !s->kbd_mask && s->clk);
1853 s->row_latch = ~rows;
1856 static uint32_t omap_mpuio_read(void *opaque, target_phys_addr_t addr)
1858 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1859 int offset = addr & OMAP_MPUI_REG_MASK;
1863 case 0x00: /* INPUT_LATCH */
1866 case 0x04: /* OUTPUT_REG */
1869 case 0x08: /* IO_CNTL */
1872 case 0x10: /* KBR_LATCH */
1873 return s->row_latch;
1875 case 0x14: /* KBC_REG */
1878 case 0x18: /* GPIO_EVENT_MODE_REG */
1881 case 0x1c: /* GPIO_INT_EDGE_REG */
1884 case 0x20: /* KBD_INT */
1885 return (~s->row_latch & 0x1f) && !s->kbd_mask;
1887 case 0x24: /* GPIO_INT */
1891 qemu_irq_lower(s->irq);
1894 case 0x28: /* KBD_MASKIT */
1897 case 0x2c: /* GPIO_MASKIT */
1900 case 0x30: /* GPIO_DEBOUNCING_REG */
1903 case 0x34: /* GPIO_LATCH_REG */
1911 static void omap_mpuio_write(void *opaque, target_phys_addr_t addr,
1914 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1915 int offset = addr & OMAP_MPUI_REG_MASK;
1920 case 0x04: /* OUTPUT_REG */
1921 diff = (s->outputs ^ value) & ~s->dir;
1923 while ((ln = ffs(diff))) {
1926 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
1931 case 0x08: /* IO_CNTL */
1932 diff = s->outputs & (s->dir ^ value);
1935 value = s->outputs & ~s->dir;
1936 while ((ln = ffs(diff))) {
1939 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
1944 case 0x14: /* KBC_REG */
1946 omap_mpuio_kbd_update(s);
1949 case 0x18: /* GPIO_EVENT_MODE_REG */
1950 s->event = value & 0x1f;
1953 case 0x1c: /* GPIO_INT_EDGE_REG */
1957 case 0x28: /* KBD_MASKIT */
1958 s->kbd_mask = value & 1;
1959 omap_mpuio_kbd_update(s);
1962 case 0x2c: /* GPIO_MASKIT */
1966 case 0x30: /* GPIO_DEBOUNCING_REG */
1967 s->debounce = value & 0x1ff;
1970 case 0x00: /* INPUT_LATCH */
1971 case 0x10: /* KBR_LATCH */
1972 case 0x20: /* KBD_INT */
1973 case 0x24: /* GPIO_INT */
1974 case 0x34: /* GPIO_LATCH_REG */
1984 static CPUReadMemoryFunc * const omap_mpuio_readfn[] = {
1985 omap_badwidth_read16,
1987 omap_badwidth_read16,
1990 static CPUWriteMemoryFunc * const omap_mpuio_writefn[] = {
1991 omap_badwidth_write16,
1993 omap_badwidth_write16,
1996 static void omap_mpuio_reset(struct omap_mpuio_s *s)
2008 s->row_latch = 0x1f;
2012 static void omap_mpuio_onoff(void *opaque, int line, int on)
2014 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2018 omap_mpuio_kbd_update(s);
2021 struct omap_mpuio_s *omap_mpuio_init(target_phys_addr_t base,
2022 qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup,
2026 struct omap_mpuio_s *s = (struct omap_mpuio_s *)
2027 qemu_mallocz(sizeof(struct omap_mpuio_s));
2030 s->kbd_irq = kbd_int;
2032 s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
2033 omap_mpuio_reset(s);
2035 iomemtype = cpu_register_io_memory(omap_mpuio_readfn,
2036 omap_mpuio_writefn, s, DEVICE_NATIVE_ENDIAN);
2037 cpu_register_physical_memory(base, 0x800, iomemtype);
2039 omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]);
2044 qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
2049 void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler)
2051 if (line >= 16 || line < 0)
2052 hw_error("%s: No GPIO line %i\n", __FUNCTION__, line);
2053 s->handler[line] = handler;
2056 void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down)
2058 if (row >= 5 || row < 0)
2059 hw_error("%s: No key %i-%i\n", __FUNCTION__, col, row);
2062 s->buttons[row] |= 1 << col;
2064 s->buttons[row] &= ~(1 << col);
2066 omap_mpuio_kbd_update(s);
2069 /* MicroWire Interface */
2070 struct omap_uwire_s {
2080 uWireSlave *chip[4];
2083 static void omap_uwire_transfer_start(struct omap_uwire_s *s)
2085 int chipselect = (s->control >> 10) & 3; /* INDEX */
2086 uWireSlave *slave = s->chip[chipselect];
2088 if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */
2089 if (s->control & (1 << 12)) /* CS_CMD */
2090 if (slave && slave->send)
2091 slave->send(slave->opaque,
2092 s->txbuf >> (16 - ((s->control >> 5) & 0x1f)));
2093 s->control &= ~(1 << 14); /* CSRB */
2094 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2095 * a DRQ. When is the level IRQ supposed to be reset? */
2098 if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */
2099 if (s->control & (1 << 12)) /* CS_CMD */
2100 if (slave && slave->receive)
2101 s->rxbuf = slave->receive(slave->opaque);
2102 s->control |= 1 << 15; /* RDRB */
2103 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2104 * a DRQ. When is the level IRQ supposed to be reset? */
2108 static uint32_t omap_uwire_read(void *opaque, target_phys_addr_t addr)
2110 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
2111 int offset = addr & OMAP_MPUI_REG_MASK;
2114 case 0x00: /* RDR */
2115 s->control &= ~(1 << 15); /* RDRB */
2118 case 0x04: /* CSR */
2121 case 0x08: /* SR1 */
2123 case 0x0c: /* SR2 */
2125 case 0x10: /* SR3 */
2127 case 0x14: /* SR4 */
2129 case 0x18: /* SR5 */
2137 static void omap_uwire_write(void *opaque, target_phys_addr_t addr,
2140 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
2141 int offset = addr & OMAP_MPUI_REG_MASK;
2144 case 0x00: /* TDR */
2145 s->txbuf = value; /* TD */
2146 if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */
2147 ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2148 (s->control & (1 << 12)))) { /* CS_CMD */
2149 s->control |= 1 << 14; /* CSRB */
2150 omap_uwire_transfer_start(s);
2154 case 0x04: /* CSR */
2155 s->control = value & 0x1fff;
2156 if (value & (1 << 13)) /* START */
2157 omap_uwire_transfer_start(s);
2160 case 0x08: /* SR1 */
2161 s->setup[0] = value & 0x003f;
2164 case 0x0c: /* SR2 */
2165 s->setup[1] = value & 0x0fc0;
2168 case 0x10: /* SR3 */
2169 s->setup[2] = value & 0x0003;
2172 case 0x14: /* SR4 */
2173 s->setup[3] = value & 0x0001;
2176 case 0x18: /* SR5 */
2177 s->setup[4] = value & 0x000f;
2186 static CPUReadMemoryFunc * const omap_uwire_readfn[] = {
2187 omap_badwidth_read16,
2189 omap_badwidth_read16,
2192 static CPUWriteMemoryFunc * const omap_uwire_writefn[] = {
2193 omap_badwidth_write16,
2195 omap_badwidth_write16,
2198 static void omap_uwire_reset(struct omap_uwire_s *s)
2208 struct omap_uwire_s *omap_uwire_init(target_phys_addr_t base,
2209 qemu_irq *irq, qemu_irq dma, omap_clk clk)
2212 struct omap_uwire_s *s = (struct omap_uwire_s *)
2213 qemu_mallocz(sizeof(struct omap_uwire_s));
2218 omap_uwire_reset(s);
2220 iomemtype = cpu_register_io_memory(omap_uwire_readfn,
2221 omap_uwire_writefn, s, DEVICE_NATIVE_ENDIAN);
2222 cpu_register_physical_memory(base, 0x800, iomemtype);
2227 void omap_uwire_attach(struct omap_uwire_s *s,
2228 uWireSlave *slave, int chipselect)
2230 if (chipselect < 0 || chipselect > 3) {
2231 fprintf(stderr, "%s: Bad chipselect %i\n", __FUNCTION__, chipselect);
2235 s->chip[chipselect] = slave;
2238 /* Pseudonoise Pulse-Width Light Modulator */
2239 static void omap_pwl_update(struct omap_mpu_state_s *s)
2241 int output = (s->pwl.clk && s->pwl.enable) ? s->pwl.level : 0;
2243 if (output != s->pwl.output) {
2244 s->pwl.output = output;
2245 printf("%s: Backlight now at %i/256\n", __FUNCTION__, output);
2249 static uint32_t omap_pwl_read(void *opaque, target_phys_addr_t addr)
2251 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2252 int offset = addr & OMAP_MPUI_REG_MASK;
2255 case 0x00: /* PWL_LEVEL */
2256 return s->pwl.level;
2257 case 0x04: /* PWL_CTRL */
2258 return s->pwl.enable;
2264 static void omap_pwl_write(void *opaque, target_phys_addr_t addr,
2267 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2268 int offset = addr & OMAP_MPUI_REG_MASK;
2271 case 0x00: /* PWL_LEVEL */
2272 s->pwl.level = value;
2275 case 0x04: /* PWL_CTRL */
2276 s->pwl.enable = value & 1;
2285 static CPUReadMemoryFunc * const omap_pwl_readfn[] = {
2287 omap_badwidth_read8,
2288 omap_badwidth_read8,
2291 static CPUWriteMemoryFunc * const omap_pwl_writefn[] = {
2293 omap_badwidth_write8,
2294 omap_badwidth_write8,
2297 static void omap_pwl_reset(struct omap_mpu_state_s *s)
2306 static void omap_pwl_clk_update(void *opaque, int line, int on)
2308 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2314 static void omap_pwl_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
2321 iomemtype = cpu_register_io_memory(omap_pwl_readfn,
2322 omap_pwl_writefn, s, DEVICE_NATIVE_ENDIAN);
2323 cpu_register_physical_memory(base, 0x800, iomemtype);
2325 omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]);
2328 /* Pulse-Width Tone module */
2329 static uint32_t omap_pwt_read(void *opaque, target_phys_addr_t addr)
2331 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2332 int offset = addr & OMAP_MPUI_REG_MASK;
2335 case 0x00: /* FRC */
2337 case 0x04: /* VCR */
2339 case 0x08: /* GCR */
2346 static void omap_pwt_write(void *opaque, target_phys_addr_t addr,
2349 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2350 int offset = addr & OMAP_MPUI_REG_MASK;
2353 case 0x00: /* FRC */
2354 s->pwt.frc = value & 0x3f;
2356 case 0x04: /* VRC */
2357 if ((value ^ s->pwt.vrc) & 1) {
2359 printf("%s: %iHz buzz on\n", __FUNCTION__, (int)
2360 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2361 ((omap_clk_getrate(s->pwt.clk) >> 3) /
2362 /* Pre-multiplexer divider */
2363 ((s->pwt.gcr & 2) ? 1 : 154) /
2364 /* Octave multiplexer */
2365 (2 << (value & 3)) *
2366 /* 101/107 divider */
2367 ((value & (1 << 2)) ? 101 : 107) *
2369 ((value & (1 << 3)) ? 49 : 55) *
2371 ((value & (1 << 4)) ? 50 : 63) *
2372 /* 80/127 divider */
2373 ((value & (1 << 5)) ? 80 : 127) /
2374 (107 * 55 * 63 * 127)));
2376 printf("%s: silence!\n", __FUNCTION__);
2378 s->pwt.vrc = value & 0x7f;
2380 case 0x08: /* GCR */
2381 s->pwt.gcr = value & 3;
2389 static CPUReadMemoryFunc * const omap_pwt_readfn[] = {
2391 omap_badwidth_read8,
2392 omap_badwidth_read8,
2395 static CPUWriteMemoryFunc * const omap_pwt_writefn[] = {
2397 omap_badwidth_write8,
2398 omap_badwidth_write8,
2401 static void omap_pwt_reset(struct omap_mpu_state_s *s)
2408 static void omap_pwt_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
2416 iomemtype = cpu_register_io_memory(omap_pwt_readfn,
2417 omap_pwt_writefn, s, DEVICE_NATIVE_ENDIAN);
2418 cpu_register_physical_memory(base, 0x800, iomemtype);
2421 /* Real-time Clock module */
2437 struct tm current_tm;
2442 static void omap_rtc_interrupts_update(struct omap_rtc_s *s)
2444 /* s->alarm is level-triggered */
2445 qemu_set_irq(s->alarm, (s->status >> 6) & 1);
2448 static void omap_rtc_alarm_update(struct omap_rtc_s *s)
2450 s->alarm_ti = mktimegm(&s->alarm_tm);
2451 if (s->alarm_ti == -1)
2452 printf("%s: conversion failed\n", __FUNCTION__);
2455 static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr)
2457 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
2458 int offset = addr & OMAP_MPUI_REG_MASK;
2462 case 0x00: /* SECONDS_REG */
2463 return to_bcd(s->current_tm.tm_sec);
2465 case 0x04: /* MINUTES_REG */
2466 return to_bcd(s->current_tm.tm_min);
2468 case 0x08: /* HOURS_REG */
2470 return ((s->current_tm.tm_hour > 11) << 7) |
2471 to_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
2473 return to_bcd(s->current_tm.tm_hour);
2475 case 0x0c: /* DAYS_REG */
2476 return to_bcd(s->current_tm.tm_mday);
2478 case 0x10: /* MONTHS_REG */
2479 return to_bcd(s->current_tm.tm_mon + 1);
2481 case 0x14: /* YEARS_REG */
2482 return to_bcd(s->current_tm.tm_year % 100);
2484 case 0x18: /* WEEK_REG */
2485 return s->current_tm.tm_wday;
2487 case 0x20: /* ALARM_SECONDS_REG */
2488 return to_bcd(s->alarm_tm.tm_sec);
2490 case 0x24: /* ALARM_MINUTES_REG */
2491 return to_bcd(s->alarm_tm.tm_min);
2493 case 0x28: /* ALARM_HOURS_REG */
2495 return ((s->alarm_tm.tm_hour > 11) << 7) |
2496 to_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
2498 return to_bcd(s->alarm_tm.tm_hour);
2500 case 0x2c: /* ALARM_DAYS_REG */
2501 return to_bcd(s->alarm_tm.tm_mday);
2503 case 0x30: /* ALARM_MONTHS_REG */
2504 return to_bcd(s->alarm_tm.tm_mon + 1);
2506 case 0x34: /* ALARM_YEARS_REG */
2507 return to_bcd(s->alarm_tm.tm_year % 100);
2509 case 0x40: /* RTC_CTRL_REG */
2510 return (s->pm_am << 3) | (s->auto_comp << 2) |
2511 (s->round << 1) | s->running;
2513 case 0x44: /* RTC_STATUS_REG */
2518 case 0x48: /* RTC_INTERRUPTS_REG */
2519 return s->interrupts;
2521 case 0x4c: /* RTC_COMP_LSB_REG */
2522 return ((uint16_t) s->comp_reg) & 0xff;
2524 case 0x50: /* RTC_COMP_MSB_REG */
2525 return ((uint16_t) s->comp_reg) >> 8;
2532 static void omap_rtc_write(void *opaque, target_phys_addr_t addr,
2535 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
2536 int offset = addr & OMAP_MPUI_REG_MASK;
2541 case 0x00: /* SECONDS_REG */
2543 printf("RTC SEC_REG <-- %02x\n", value);
2545 s->ti -= s->current_tm.tm_sec;
2546 s->ti += from_bcd(value);
2549 case 0x04: /* MINUTES_REG */
2551 printf("RTC MIN_REG <-- %02x\n", value);
2553 s->ti -= s->current_tm.tm_min * 60;
2554 s->ti += from_bcd(value) * 60;
2557 case 0x08: /* HOURS_REG */
2559 printf("RTC HRS_REG <-- %02x\n", value);
2561 s->ti -= s->current_tm.tm_hour * 3600;
2563 s->ti += (from_bcd(value & 0x3f) & 12) * 3600;
2564 s->ti += ((value >> 7) & 1) * 43200;
2566 s->ti += from_bcd(value & 0x3f) * 3600;
2569 case 0x0c: /* DAYS_REG */
2571 printf("RTC DAY_REG <-- %02x\n", value);
2573 s->ti -= s->current_tm.tm_mday * 86400;
2574 s->ti += from_bcd(value) * 86400;
2577 case 0x10: /* MONTHS_REG */
2579 printf("RTC MTH_REG <-- %02x\n", value);
2581 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
2582 new_tm.tm_mon = from_bcd(value);
2583 ti[0] = mktimegm(&s->current_tm);
2584 ti[1] = mktimegm(&new_tm);
2586 if (ti[0] != -1 && ti[1] != -1) {
2590 /* A less accurate version */
2591 s->ti -= s->current_tm.tm_mon * 2592000;
2592 s->ti += from_bcd(value) * 2592000;
2596 case 0x14: /* YEARS_REG */
2598 printf("RTC YRS_REG <-- %02x\n", value);
2600 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
2601 new_tm.tm_year += from_bcd(value) - (new_tm.tm_year % 100);
2602 ti[0] = mktimegm(&s->current_tm);
2603 ti[1] = mktimegm(&new_tm);
2605 if (ti[0] != -1 && ti[1] != -1) {
2609 /* A less accurate version */
2610 s->ti -= (s->current_tm.tm_year % 100) * 31536000;
2611 s->ti += from_bcd(value) * 31536000;
2615 case 0x18: /* WEEK_REG */
2616 return; /* Ignored */
2618 case 0x20: /* ALARM_SECONDS_REG */
2620 printf("ALM SEC_REG <-- %02x\n", value);
2622 s->alarm_tm.tm_sec = from_bcd(value);
2623 omap_rtc_alarm_update(s);
2626 case 0x24: /* ALARM_MINUTES_REG */
2628 printf("ALM MIN_REG <-- %02x\n", value);
2630 s->alarm_tm.tm_min = from_bcd(value);
2631 omap_rtc_alarm_update(s);
2634 case 0x28: /* ALARM_HOURS_REG */
2636 printf("ALM HRS_REG <-- %02x\n", value);
2639 s->alarm_tm.tm_hour =
2640 ((from_bcd(value & 0x3f)) % 12) +
2641 ((value >> 7) & 1) * 12;
2643 s->alarm_tm.tm_hour = from_bcd(value);
2644 omap_rtc_alarm_update(s);
2647 case 0x2c: /* ALARM_DAYS_REG */
2649 printf("ALM DAY_REG <-- %02x\n", value);
2651 s->alarm_tm.tm_mday = from_bcd(value);
2652 omap_rtc_alarm_update(s);
2655 case 0x30: /* ALARM_MONTHS_REG */
2657 printf("ALM MON_REG <-- %02x\n", value);
2659 s->alarm_tm.tm_mon = from_bcd(value);
2660 omap_rtc_alarm_update(s);
2663 case 0x34: /* ALARM_YEARS_REG */
2665 printf("ALM YRS_REG <-- %02x\n", value);
2667 s->alarm_tm.tm_year = from_bcd(value);
2668 omap_rtc_alarm_update(s);
2671 case 0x40: /* RTC_CTRL_REG */
2673 printf("RTC CONTROL <-- %02x\n", value);
2675 s->pm_am = (value >> 3) & 1;
2676 s->auto_comp = (value >> 2) & 1;
2677 s->round = (value >> 1) & 1;
2678 s->running = value & 1;
2680 s->status |= s->running << 1;
2683 case 0x44: /* RTC_STATUS_REG */
2685 printf("RTC STATUSL <-- %02x\n", value);
2687 s->status &= ~((value & 0xc0) ^ 0x80);
2688 omap_rtc_interrupts_update(s);
2691 case 0x48: /* RTC_INTERRUPTS_REG */
2693 printf("RTC INTRS <-- %02x\n", value);
2695 s->interrupts = value;
2698 case 0x4c: /* RTC_COMP_LSB_REG */
2700 printf("RTC COMPLSB <-- %02x\n", value);
2702 s->comp_reg &= 0xff00;
2703 s->comp_reg |= 0x00ff & value;
2706 case 0x50: /* RTC_COMP_MSB_REG */
2708 printf("RTC COMPMSB <-- %02x\n", value);
2710 s->comp_reg &= 0x00ff;
2711 s->comp_reg |= 0xff00 & (value << 8);
2720 static CPUReadMemoryFunc * const omap_rtc_readfn[] = {
2722 omap_badwidth_read8,
2723 omap_badwidth_read8,
2726 static CPUWriteMemoryFunc * const omap_rtc_writefn[] = {
2728 omap_badwidth_write8,
2729 omap_badwidth_write8,
2732 static void omap_rtc_tick(void *opaque)
2734 struct omap_rtc_s *s = opaque;
2737 /* Round to nearest full minute. */
2738 if (s->current_tm.tm_sec < 30)
2739 s->ti -= s->current_tm.tm_sec;
2741 s->ti += 60 - s->current_tm.tm_sec;
2746 memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm));
2748 if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) {
2750 omap_rtc_interrupts_update(s);
2753 if (s->interrupts & 0x04)
2754 switch (s->interrupts & 3) {
2757 qemu_irq_pulse(s->irq);
2760 if (s->current_tm.tm_sec)
2763 qemu_irq_pulse(s->irq);
2766 if (s->current_tm.tm_sec || s->current_tm.tm_min)
2769 qemu_irq_pulse(s->irq);
2772 if (s->current_tm.tm_sec ||
2773 s->current_tm.tm_min || s->current_tm.tm_hour)
2776 qemu_irq_pulse(s->irq);
2786 * Every full hour add a rough approximation of the compensation
2787 * register to the 32kHz Timer (which drives the RTC) value.
2789 if (s->auto_comp && !s->current_tm.tm_sec && !s->current_tm.tm_min)
2790 s->tick += s->comp_reg * 1000 / 32768;
2792 qemu_mod_timer(s->clk, s->tick);
2795 static void omap_rtc_reset(struct omap_rtc_s *s)
2805 s->tick = qemu_get_clock(rt_clock);
2806 memset(&s->alarm_tm, 0, sizeof(s->alarm_tm));
2807 s->alarm_tm.tm_mday = 0x01;
2809 qemu_get_timedate(&tm, 0);
2810 s->ti = mktimegm(&tm);
2812 omap_rtc_alarm_update(s);
2816 static struct omap_rtc_s *omap_rtc_init(target_phys_addr_t base,
2817 qemu_irq *irq, omap_clk clk)
2820 struct omap_rtc_s *s = (struct omap_rtc_s *)
2821 qemu_mallocz(sizeof(struct omap_rtc_s));
2825 s->clk = qemu_new_timer(rt_clock, omap_rtc_tick, s);
2829 iomemtype = cpu_register_io_memory(omap_rtc_readfn,
2830 omap_rtc_writefn, s, DEVICE_NATIVE_ENDIAN);
2831 cpu_register_physical_memory(base, 0x800, iomemtype);
2836 /* Multi-channel Buffered Serial Port interfaces */
2837 struct omap_mcbsp_s {
2857 QEMUTimer *source_timer;
2858 QEMUTimer *sink_timer;
2861 static void omap_mcbsp_intr_update(struct omap_mcbsp_s *s)
2865 switch ((s->spcr[0] >> 4) & 3) { /* RINTM */
2867 irq = (s->spcr[0] >> 1) & 1; /* RRDY */
2870 irq = (s->spcr[0] >> 3) & 1; /* RSYNCERR */
2878 qemu_irq_pulse(s->rxirq);
2880 switch ((s->spcr[1] >> 4) & 3) { /* XINTM */
2882 irq = (s->spcr[1] >> 1) & 1; /* XRDY */
2885 irq = (s->spcr[1] >> 3) & 1; /* XSYNCERR */
2893 qemu_irq_pulse(s->txirq);
2896 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s *s)
2898 if ((s->spcr[0] >> 1) & 1) /* RRDY */
2899 s->spcr[0] |= 1 << 2; /* RFULL */
2900 s->spcr[0] |= 1 << 1; /* RRDY */
2901 qemu_irq_raise(s->rxdrq);
2902 omap_mcbsp_intr_update(s);
2905 static void omap_mcbsp_source_tick(void *opaque)
2907 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
2908 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
2913 printf("%s: Rx FIFO overrun\n", __FUNCTION__);
2915 s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7];
2917 omap_mcbsp_rx_newdata(s);
2918 qemu_mod_timer(s->source_timer, qemu_get_clock(vm_clock) +
2919 get_ticks_per_sec());
2922 static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s)
2924 if (!s->codec || !s->codec->rts)
2925 omap_mcbsp_source_tick(s);
2926 else if (s->codec->in.len) {
2927 s->rx_req = s->codec->in.len;
2928 omap_mcbsp_rx_newdata(s);
2932 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s *s)
2934 qemu_del_timer(s->source_timer);
2937 static void omap_mcbsp_rx_done(struct omap_mcbsp_s *s)
2939 s->spcr[0] &= ~(1 << 1); /* RRDY */
2940 qemu_irq_lower(s->rxdrq);
2941 omap_mcbsp_intr_update(s);
2944 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s *s)
2946 s->spcr[1] |= 1 << 1; /* XRDY */
2947 qemu_irq_raise(s->txdrq);
2948 omap_mcbsp_intr_update(s);
2951 static void omap_mcbsp_sink_tick(void *opaque)
2953 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
2954 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
2959 printf("%s: Tx FIFO underrun\n", __FUNCTION__);
2961 s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7];
2963 omap_mcbsp_tx_newdata(s);
2964 qemu_mod_timer(s->sink_timer, qemu_get_clock(vm_clock) +
2965 get_ticks_per_sec());
2968 static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s)
2970 if (!s->codec || !s->codec->cts)
2971 omap_mcbsp_sink_tick(s);
2972 else if (s->codec->out.size) {
2973 s->tx_req = s->codec->out.size;
2974 omap_mcbsp_tx_newdata(s);
2978 static void omap_mcbsp_tx_done(struct omap_mcbsp_s *s)
2980 s->spcr[1] &= ~(1 << 1); /* XRDY */
2981 qemu_irq_lower(s->txdrq);
2982 omap_mcbsp_intr_update(s);
2983 if (s->codec && s->codec->cts)
2984 s->codec->tx_swallow(s->codec->opaque);
2987 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s *s)
2990 omap_mcbsp_tx_done(s);
2991 qemu_del_timer(s->sink_timer);
2994 static void omap_mcbsp_req_update(struct omap_mcbsp_s *s)
2996 int prev_rx_rate, prev_tx_rate;
2997 int rx_rate = 0, tx_rate = 0;
2998 int cpu_rate = 1500000; /* XXX */
3000 /* TODO: check CLKSTP bit */
3001 if (s->spcr[1] & (1 << 6)) { /* GRST */
3002 if (s->spcr[0] & (1 << 0)) { /* RRST */
3003 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3004 (s->pcr & (1 << 8))) { /* CLKRM */
3005 if (~s->pcr & (1 << 7)) /* SCLKME */
3006 rx_rate = cpu_rate /
3007 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3010 rx_rate = s->codec->rx_rate;
3013 if (s->spcr[1] & (1 << 0)) { /* XRST */
3014 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3015 (s->pcr & (1 << 9))) { /* CLKXM */
3016 if (~s->pcr & (1 << 7)) /* SCLKME */
3017 tx_rate = cpu_rate /
3018 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3021 tx_rate = s->codec->tx_rate;
3024 prev_tx_rate = s->tx_rate;
3025 prev_rx_rate = s->rx_rate;
3026 s->tx_rate = tx_rate;
3027 s->rx_rate = rx_rate;
3030 s->codec->set_rate(s->codec->opaque, rx_rate, tx_rate);
3032 if (!prev_tx_rate && tx_rate)
3033 omap_mcbsp_tx_start(s);
3034 else if (s->tx_rate && !tx_rate)
3035 omap_mcbsp_tx_stop(s);
3037 if (!prev_rx_rate && rx_rate)
3038 omap_mcbsp_rx_start(s);
3039 else if (prev_tx_rate && !tx_rate)
3040 omap_mcbsp_rx_stop(s);
3043 static uint32_t omap_mcbsp_read(void *opaque, target_phys_addr_t addr)
3045 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3046 int offset = addr & OMAP_MPUI_REG_MASK;
3050 case 0x00: /* DRR2 */
3051 if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */
3054 case 0x02: /* DRR1 */
3055 if (s->rx_req < 2) {
3056 printf("%s: Rx FIFO underrun\n", __FUNCTION__);
3057 omap_mcbsp_rx_done(s);
3060 if (s->codec && s->codec->in.len >= 2) {
3061 ret = s->codec->in.fifo[s->codec->in.start ++] << 8;
3062 ret |= s->codec->in.fifo[s->codec->in.start ++];
3063 s->codec->in.len -= 2;
3067 omap_mcbsp_rx_done(s);
3072 case 0x04: /* DXR2 */
3073 case 0x06: /* DXR1 */
3076 case 0x08: /* SPCR2 */
3078 case 0x0a: /* SPCR1 */
3080 case 0x0c: /* RCR2 */
3082 case 0x0e: /* RCR1 */
3084 case 0x10: /* XCR2 */
3086 case 0x12: /* XCR1 */
3088 case 0x14: /* SRGR2 */
3090 case 0x16: /* SRGR1 */
3092 case 0x18: /* MCR2 */
3094 case 0x1a: /* MCR1 */
3096 case 0x1c: /* RCERA */
3098 case 0x1e: /* RCERB */
3100 case 0x20: /* XCERA */
3102 case 0x22: /* XCERB */
3104 case 0x24: /* PCR0 */
3106 case 0x26: /* RCERC */
3108 case 0x28: /* RCERD */
3110 case 0x2a: /* XCERC */
3112 case 0x2c: /* XCERD */
3114 case 0x2e: /* RCERE */
3116 case 0x30: /* RCERF */
3118 case 0x32: /* XCERE */
3120 case 0x34: /* XCERF */
3122 case 0x36: /* RCERG */
3124 case 0x38: /* RCERH */
3126 case 0x3a: /* XCERG */
3128 case 0x3c: /* XCERH */
3136 static void omap_mcbsp_writeh(void *opaque, target_phys_addr_t addr,
3139 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3140 int offset = addr & OMAP_MPUI_REG_MASK;
3143 case 0x00: /* DRR2 */
3144 case 0x02: /* DRR1 */
3148 case 0x04: /* DXR2 */
3149 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
3152 case 0x06: /* DXR1 */
3153 if (s->tx_req > 1) {
3155 if (s->codec && s->codec->cts) {
3156 s->codec->out.fifo[s->codec->out.len ++] = (value >> 8) & 0xff;
3157 s->codec->out.fifo[s->codec->out.len ++] = (value >> 0) & 0xff;
3160 omap_mcbsp_tx_done(s);
3162 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
3165 case 0x08: /* SPCR2 */
3166 s->spcr[1] &= 0x0002;
3167 s->spcr[1] |= 0x03f9 & value;
3168 s->spcr[1] |= 0x0004 & (value << 2); /* XEMPTY := XRST */
3169 if (~value & 1) /* XRST */
3171 omap_mcbsp_req_update(s);
3173 case 0x0a: /* SPCR1 */
3174 s->spcr[0] &= 0x0006;
3175 s->spcr[0] |= 0xf8f9 & value;
3176 if (value & (1 << 15)) /* DLB */
3177 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__);
3178 if (~value & 1) { /* RRST */
3181 omap_mcbsp_rx_done(s);
3183 omap_mcbsp_req_update(s);
3186 case 0x0c: /* RCR2 */
3187 s->rcr[1] = value & 0xffff;
3189 case 0x0e: /* RCR1 */
3190 s->rcr[0] = value & 0x7fe0;
3192 case 0x10: /* XCR2 */
3193 s->xcr[1] = value & 0xffff;
3195 case 0x12: /* XCR1 */
3196 s->xcr[0] = value & 0x7fe0;
3198 case 0x14: /* SRGR2 */
3199 s->srgr[1] = value & 0xffff;
3200 omap_mcbsp_req_update(s);
3202 case 0x16: /* SRGR1 */
3203 s->srgr[0] = value & 0xffff;
3204 omap_mcbsp_req_update(s);
3206 case 0x18: /* MCR2 */
3207 s->mcr[1] = value & 0x03e3;
3208 if (value & 3) /* XMCM */
3209 printf("%s: Tx channel selection mode enable attempt\n",
3212 case 0x1a: /* MCR1 */
3213 s->mcr[0] = value & 0x03e1;
3214 if (value & 1) /* RMCM */
3215 printf("%s: Rx channel selection mode enable attempt\n",
3218 case 0x1c: /* RCERA */
3219 s->rcer[0] = value & 0xffff;
3221 case 0x1e: /* RCERB */
3222 s->rcer[1] = value & 0xffff;
3224 case 0x20: /* XCERA */
3225 s->xcer[0] = value & 0xffff;
3227 case 0x22: /* XCERB */
3228 s->xcer[1] = value & 0xffff;
3230 case 0x24: /* PCR0 */
3231 s->pcr = value & 0x7faf;
3233 case 0x26: /* RCERC */
3234 s->rcer[2] = value & 0xffff;
3236 case 0x28: /* RCERD */
3237 s->rcer[3] = value & 0xffff;
3239 case 0x2a: /* XCERC */
3240 s->xcer[2] = value & 0xffff;
3242 case 0x2c: /* XCERD */
3243 s->xcer[3] = value & 0xffff;
3245 case 0x2e: /* RCERE */
3246 s->rcer[4] = value & 0xffff;
3248 case 0x30: /* RCERF */
3249 s->rcer[5] = value & 0xffff;
3251 case 0x32: /* XCERE */
3252 s->xcer[4] = value & 0xffff;
3254 case 0x34: /* XCERF */
3255 s->xcer[5] = value & 0xffff;
3257 case 0x36: /* RCERG */
3258 s->rcer[6] = value & 0xffff;
3260 case 0x38: /* RCERH */
3261 s->rcer[7] = value & 0xffff;
3263 case 0x3a: /* XCERG */
3264 s->xcer[6] = value & 0xffff;
3266 case 0x3c: /* XCERH */
3267 s->xcer[7] = value & 0xffff;
3274 static void omap_mcbsp_writew(void *opaque, target_phys_addr_t addr,
3277 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3278 int offset = addr & OMAP_MPUI_REG_MASK;
3280 if (offset == 0x04) { /* DXR */
3281 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
3283 if (s->tx_req > 3) {
3285 if (s->codec && s->codec->cts) {
3286 s->codec->out.fifo[s->codec->out.len ++] =
3287 (value >> 24) & 0xff;
3288 s->codec->out.fifo[s->codec->out.len ++] =
3289 (value >> 16) & 0xff;
3290 s->codec->out.fifo[s->codec->out.len ++] =
3291 (value >> 8) & 0xff;
3292 s->codec->out.fifo[s->codec->out.len ++] =
3293 (value >> 0) & 0xff;
3296 omap_mcbsp_tx_done(s);
3298 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
3302 omap_badwidth_write16(opaque, addr, value);
3305 static CPUReadMemoryFunc * const omap_mcbsp_readfn[] = {
3306 omap_badwidth_read16,
3308 omap_badwidth_read16,
3311 static CPUWriteMemoryFunc * const omap_mcbsp_writefn[] = {
3312 omap_badwidth_write16,
3317 static void omap_mcbsp_reset(struct omap_mcbsp_s *s)
3319 memset(&s->spcr, 0, sizeof(s->spcr));
3320 memset(&s->rcr, 0, sizeof(s->rcr));
3321 memset(&s->xcr, 0, sizeof(s->xcr));
3322 s->srgr[0] = 0x0001;
3323 s->srgr[1] = 0x2000;
3324 memset(&s->mcr, 0, sizeof(s->mcr));
3325 memset(&s->pcr, 0, sizeof(s->pcr));
3326 memset(&s->rcer, 0, sizeof(s->rcer));
3327 memset(&s->xcer, 0, sizeof(s->xcer));
3332 qemu_del_timer(s->source_timer);
3333 qemu_del_timer(s->sink_timer);
3336 struct omap_mcbsp_s *omap_mcbsp_init(target_phys_addr_t base,
3337 qemu_irq *irq, qemu_irq *dma, omap_clk clk)
3340 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *)
3341 qemu_mallocz(sizeof(struct omap_mcbsp_s));
3347 s->sink_timer = qemu_new_timer(vm_clock, omap_mcbsp_sink_tick, s);
3348 s->source_timer = qemu_new_timer(vm_clock, omap_mcbsp_source_tick, s);
3349 omap_mcbsp_reset(s);
3351 iomemtype = cpu_register_io_memory(omap_mcbsp_readfn,
3352 omap_mcbsp_writefn, s, DEVICE_NATIVE_ENDIAN);
3353 cpu_register_physical_memory(base, 0x800, iomemtype);
3358 static void omap_mcbsp_i2s_swallow(void *opaque, int line, int level)
3360 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3363 s->rx_req = s->codec->in.len;
3364 omap_mcbsp_rx_newdata(s);
3368 static void omap_mcbsp_i2s_start(void *opaque, int line, int level)
3370 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3373 s->tx_req = s->codec->out.size;
3374 omap_mcbsp_tx_newdata(s);
3378 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, I2SCodec *slave)
3381 slave->rx_swallow = qemu_allocate_irqs(omap_mcbsp_i2s_swallow, s, 1)[0];
3382 slave->tx_start = qemu_allocate_irqs(omap_mcbsp_i2s_start, s, 1)[0];
3385 /* LED Pulse Generators */
3397 static void omap_lpg_tick(void *opaque)
3399 struct omap_lpg_s *s = opaque;
3402 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->period - s->on);
3404 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->on);
3406 s->cycle = !s->cycle;
3407 printf("%s: LED is %s\n", __FUNCTION__, s->cycle ? "on" : "off");
3410 static void omap_lpg_update(struct omap_lpg_s *s)
3412 int64_t on, period = 1, ticks = 1000;
3413 static const int per[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3415 if (~s->control & (1 << 6)) /* LPGRES */
3417 else if (s->control & (1 << 7)) /* PERM_ON */
3420 period = muldiv64(ticks, per[s->control & 7], /* PERCTRL */
3422 on = (s->clk && s->power) ? muldiv64(ticks,
3423 per[(s->control >> 3) & 7], 256) : 0; /* ONCTRL */
3426 qemu_del_timer(s->tm);
3427 if (on == period && s->on < s->period)
3428 printf("%s: LED is on\n", __FUNCTION__);
3429 else if (on == 0 && s->on)
3430 printf("%s: LED is off\n", __FUNCTION__);
3431 else if (on && (on != s->on || period != s->period)) {
3443 static void omap_lpg_reset(struct omap_lpg_s *s)
3451 static uint32_t omap_lpg_read(void *opaque, target_phys_addr_t addr)
3453 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3454 int offset = addr & OMAP_MPUI_REG_MASK;
3457 case 0x00: /* LCR */
3460 case 0x04: /* PMR */
3468 static void omap_lpg_write(void *opaque, target_phys_addr_t addr,
3471 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3472 int offset = addr & OMAP_MPUI_REG_MASK;
3475 case 0x00: /* LCR */
3476 if (~value & (1 << 6)) /* LPGRES */
3478 s->control = value & 0xff;
3482 case 0x04: /* PMR */
3483 s->power = value & 0x01;
3493 static CPUReadMemoryFunc * const omap_lpg_readfn[] = {
3495 omap_badwidth_read8,
3496 omap_badwidth_read8,
3499 static CPUWriteMemoryFunc * const omap_lpg_writefn[] = {
3501 omap_badwidth_write8,
3502 omap_badwidth_write8,
3505 static void omap_lpg_clk_update(void *opaque, int line, int on)
3507 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3513 static struct omap_lpg_s *omap_lpg_init(target_phys_addr_t base, omap_clk clk)
3516 struct omap_lpg_s *s = (struct omap_lpg_s *)
3517 qemu_mallocz(sizeof(struct omap_lpg_s));
3519 s->tm = qemu_new_timer(rt_clock, omap_lpg_tick, s);
3523 iomemtype = cpu_register_io_memory(omap_lpg_readfn,
3524 omap_lpg_writefn, s, DEVICE_NATIVE_ENDIAN);
3525 cpu_register_physical_memory(base, 0x800, iomemtype);
3527 omap_clk_adduser(clk, qemu_allocate_irqs(omap_lpg_clk_update, s, 1)[0]);
3532 /* MPUI Peripheral Bridge configuration */
3533 static uint32_t omap_mpui_io_read(void *opaque, target_phys_addr_t addr)
3535 if (addr == OMAP_MPUI_BASE) /* CMR */
3542 static CPUReadMemoryFunc * const omap_mpui_io_readfn[] = {
3543 omap_badwidth_read16,
3545 omap_badwidth_read16,
3548 static CPUWriteMemoryFunc * const omap_mpui_io_writefn[] = {
3549 omap_badwidth_write16,
3550 omap_badwidth_write16,
3551 omap_badwidth_write16,
3554 static void omap_setup_mpui_io(struct omap_mpu_state_s *mpu)
3556 int iomemtype = cpu_register_io_memory(omap_mpui_io_readfn,
3557 omap_mpui_io_writefn, mpu, DEVICE_NATIVE_ENDIAN);
3558 cpu_register_physical_memory(OMAP_MPUI_BASE, 0x7fff, iomemtype);
3561 /* General chip reset */
3562 static void omap1_mpu_reset(void *opaque)
3564 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
3566 omap_inth_reset(mpu->ih[0]);
3567 omap_inth_reset(mpu->ih[1]);
3568 omap_dma_reset(mpu->dma);
3569 omap_mpu_timer_reset(mpu->timer[0]);
3570 omap_mpu_timer_reset(mpu->timer[1]);
3571 omap_mpu_timer_reset(mpu->timer[2]);
3572 omap_wd_timer_reset(mpu->wdt);
3573 omap_os_timer_reset(mpu->os_timer);
3574 omap_lcdc_reset(mpu->lcd);
3575 omap_ulpd_pm_reset(mpu);
3576 omap_pin_cfg_reset(mpu);
3577 omap_mpui_reset(mpu);
3578 omap_tipb_bridge_reset(mpu->private_tipb);
3579 omap_tipb_bridge_reset(mpu->public_tipb);
3580 omap_dpll_reset(&mpu->dpll[0]);
3581 omap_dpll_reset(&mpu->dpll[1]);
3582 omap_dpll_reset(&mpu->dpll[2]);
3583 omap_uart_reset(mpu->uart[0]);
3584 omap_uart_reset(mpu->uart[1]);
3585 omap_uart_reset(mpu->uart[2]);
3586 omap_mmc_reset(mpu->mmc);
3587 omap_mpuio_reset(mpu->mpuio);
3588 omap_gpio_reset(mpu->gpio);
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 = omap_gpio_init(0xfffce000, s->irq[0][OMAP_INT_GPIO_BANK1],
3849 omap_findclk(s, "arm_gpio_ck"));
3851 s->microwire = omap_uwire_init(0xfffb3000, &s->irq[1][OMAP_INT_uWireTX],
3852 s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
3854 omap_pwl_init(0xfffb5800, s, omap_findclk(s, "armxor_ck"));
3855 omap_pwt_init(0xfffb6000, s, omap_findclk(s, "armxor_ck"));
3857 s->i2c[0] = omap_i2c_init(0xfffb3800, s->irq[1][OMAP_INT_I2C],
3858 &s->drq[OMAP_DMA_I2C_RX], omap_findclk(s, "mpuper_ck"));
3860 s->rtc = omap_rtc_init(0xfffb4800, &s->irq[1][OMAP_INT_RTC_TIMER],
3861 omap_findclk(s, "clk32-kHz"));
3863 s->mcbsp1 = omap_mcbsp_init(0xfffb1800, &s->irq[1][OMAP_INT_McBSP1TX],
3864 &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
3865 s->mcbsp2 = omap_mcbsp_init(0xfffb1000, &s->irq[0][OMAP_INT_310_McBSP2_TX],
3866 &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
3867 s->mcbsp3 = omap_mcbsp_init(0xfffb7000, &s->irq[1][OMAP_INT_McBSP3TX],
3868 &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
3870 s->led[0] = omap_lpg_init(0xfffbd000, omap_findclk(s, "clk32-kHz"));
3871 s->led[1] = omap_lpg_init(0xfffbd800, omap_findclk(s, "clk32-kHz"));
3873 /* Register mappings not currenlty implemented:
3874 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
3875 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
3876 * USB W2FC fffb4000 - fffb47ff
3877 * Camera Interface fffb6800 - fffb6fff
3878 * USB Host fffba000 - fffba7ff
3879 * FAC fffba800 - fffbafff
3880 * HDQ/1-Wire fffbc000 - fffbc7ff
3881 * TIPB switches fffbc800 - fffbcfff
3882 * Mailbox fffcf000 - fffcf7ff
3883 * Local bus IF fffec100 - fffec1ff
3884 * Local bus MMU fffec200 - fffec2ff
3885 * DSP MMU fffed200 - fffed2ff
3888 omap_setup_dsp_mapping(omap15xx_dsp_mm);
3889 omap_setup_mpui_io(s);
3891 qemu_register_reset(omap1_mpu_reset, s);