2 * TI OMAP processors emulation.
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 {
104 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer)
106 uint64_t distance = qemu_get_clock_ns(vm_clock) - timer->time;
108 if (timer->st && timer->enable && timer->rate)
109 return timer->val - muldiv64(distance >> (timer->ptv + 1),
110 timer->rate, get_ticks_per_sec());
115 static inline void omap_timer_sync(struct omap_mpu_timer_s *timer)
117 timer->val = omap_timer_read(timer);
118 timer->time = qemu_get_clock_ns(vm_clock);
121 static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
125 if (timer->enable && timer->st && timer->rate) {
126 timer->val = timer->reset_val; /* Should skip this on clk enable */
127 expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
128 get_ticks_per_sec(), timer->rate);
130 /* If timer expiry would be sooner than in about 1 ms and
131 * auto-reload isn't set, then fire immediately. This is a hack
132 * to make systems like PalmOS run in acceptable time. PalmOS
133 * sets the interval to a very low value and polls the status bit
134 * in a busy loop when it wants to sleep just a couple of CPU
136 if (expires > (get_ticks_per_sec() >> 10) || timer->ar)
137 qemu_mod_timer(timer->timer, timer->time + expires);
139 qemu_bh_schedule(timer->tick);
141 qemu_del_timer(timer->timer);
144 static void omap_timer_fire(void *opaque)
146 struct omap_mpu_timer_s *timer = opaque;
154 /* Edge-triggered irq */
155 qemu_irq_pulse(timer->irq);
158 static void omap_timer_tick(void *opaque)
160 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
162 omap_timer_sync(timer);
163 omap_timer_fire(timer);
164 omap_timer_update(timer);
167 static void omap_timer_clk_update(void *opaque, int line, int on)
169 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
171 omap_timer_sync(timer);
172 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
173 omap_timer_update(timer);
176 static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer)
178 omap_clk_adduser(timer->clk,
179 qemu_allocate_irqs(omap_timer_clk_update, timer, 1)[0]);
180 timer->rate = omap_clk_getrate(timer->clk);
183 static uint64_t omap_mpu_timer_read(void *opaque, target_phys_addr_t addr,
186 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
189 return omap_badwidth_read32(opaque, addr);
193 case 0x00: /* CNTL_TIMER */
194 return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st;
196 case 0x04: /* LOAD_TIM */
199 case 0x08: /* READ_TIM */
200 return omap_timer_read(s);
207 static void omap_mpu_timer_write(void *opaque, target_phys_addr_t addr,
208 uint64_t value, unsigned size)
210 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
213 return omap_badwidth_write32(opaque, addr, value);
217 case 0x00: /* CNTL_TIMER */
219 s->enable = (value >> 5) & 1;
220 s->ptv = (value >> 2) & 7;
221 s->ar = (value >> 1) & 1;
223 omap_timer_update(s);
226 case 0x04: /* LOAD_TIM */
227 s->reset_val = value;
230 case 0x08: /* READ_TIM */
239 static const MemoryRegionOps omap_mpu_timer_ops = {
240 .read = omap_mpu_timer_read,
241 .write = omap_mpu_timer_write,
242 .endianness = DEVICE_LITTLE_ENDIAN,
245 static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s)
247 qemu_del_timer(s->timer);
249 s->reset_val = 31337;
257 static struct omap_mpu_timer_s *omap_mpu_timer_init(MemoryRegion *system_memory,
258 target_phys_addr_t base,
259 qemu_irq irq, omap_clk clk)
261 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *)
262 g_malloc0(sizeof(struct omap_mpu_timer_s));
266 s->timer = qemu_new_timer_ns(vm_clock, omap_timer_tick, s);
267 s->tick = qemu_bh_new(omap_timer_fire, s);
268 omap_mpu_timer_reset(s);
269 omap_timer_clk_setup(s);
271 memory_region_init_io(&s->iomem, &omap_mpu_timer_ops, s,
272 "omap-mpu-timer", 0x100);
274 memory_region_add_subregion(system_memory, base, &s->iomem);
280 struct omap_watchdog_timer_s {
281 struct omap_mpu_timer_s timer;
289 static uint64_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr,
292 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
295 return omap_badwidth_read16(opaque, addr);
299 case 0x00: /* CNTL_TIMER */
300 return (s->timer.ptv << 9) | (s->timer.ar << 8) |
301 (s->timer.st << 7) | (s->free << 1);
303 case 0x04: /* READ_TIMER */
304 return omap_timer_read(&s->timer);
306 case 0x08: /* TIMER_MODE */
307 return s->mode << 15;
314 static void omap_wd_timer_write(void *opaque, target_phys_addr_t addr,
315 uint64_t value, unsigned size)
317 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
320 return omap_badwidth_write16(opaque, addr, value);
324 case 0x00: /* CNTL_TIMER */
325 omap_timer_sync(&s->timer);
326 s->timer.ptv = (value >> 9) & 7;
327 s->timer.ar = (value >> 8) & 1;
328 s->timer.st = (value >> 7) & 1;
329 s->free = (value >> 1) & 1;
330 omap_timer_update(&s->timer);
333 case 0x04: /* LOAD_TIMER */
334 s->timer.reset_val = value & 0xffff;
337 case 0x08: /* TIMER_MODE */
338 if (!s->mode && ((value >> 15) & 1))
339 omap_clk_get(s->timer.clk);
340 s->mode |= (value >> 15) & 1;
341 if (s->last_wr == 0xf5) {
342 if ((value & 0xff) == 0xa0) {
345 omap_clk_put(s->timer.clk);
348 /* XXX: on T|E hardware somehow this has no effect,
349 * on Zire 71 it works as specified. */
351 qemu_system_reset_request();
354 s->last_wr = value & 0xff;
362 static const MemoryRegionOps omap_wd_timer_ops = {
363 .read = omap_wd_timer_read,
364 .write = omap_wd_timer_write,
365 .endianness = DEVICE_NATIVE_ENDIAN,
368 static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s)
370 qemu_del_timer(s->timer.timer);
372 omap_clk_get(s->timer.clk);
378 s->timer.reset_val = 0xffff;
383 omap_timer_update(&s->timer);
386 static struct omap_watchdog_timer_s *omap_wd_timer_init(MemoryRegion *memory,
387 target_phys_addr_t base,
388 qemu_irq irq, omap_clk clk)
390 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *)
391 g_malloc0(sizeof(struct omap_watchdog_timer_s));
395 s->timer.timer = qemu_new_timer_ns(vm_clock, omap_timer_tick, &s->timer);
396 omap_wd_timer_reset(s);
397 omap_timer_clk_setup(&s->timer);
399 memory_region_init_io(&s->iomem, &omap_wd_timer_ops, s,
400 "omap-wd-timer", 0x100);
401 memory_region_add_subregion(memory, base, &s->iomem);
407 struct omap_32khz_timer_s {
408 struct omap_mpu_timer_s timer;
412 static uint64_t omap_os_timer_read(void *opaque, target_phys_addr_t addr,
415 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
416 int offset = addr & OMAP_MPUI_REG_MASK;
419 return omap_badwidth_read32(opaque, addr);
424 return s->timer.reset_val;
427 return omap_timer_read(&s->timer);
430 return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st;
439 static void omap_os_timer_write(void *opaque, target_phys_addr_t addr,
440 uint64_t value, unsigned size)
442 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
443 int offset = addr & OMAP_MPUI_REG_MASK;
446 return omap_badwidth_write32(opaque, addr, value);
451 s->timer.reset_val = value & 0x00ffffff;
459 s->timer.ar = (value >> 3) & 1;
460 s->timer.it_ena = (value >> 2) & 1;
461 if (s->timer.st != (value & 1) || (value & 2)) {
462 omap_timer_sync(&s->timer);
463 s->timer.enable = value & 1;
464 s->timer.st = value & 1;
465 omap_timer_update(&s->timer);
474 static const MemoryRegionOps omap_os_timer_ops = {
475 .read = omap_os_timer_read,
476 .write = omap_os_timer_write,
477 .endianness = DEVICE_NATIVE_ENDIAN,
480 static void omap_os_timer_reset(struct omap_32khz_timer_s *s)
482 qemu_del_timer(s->timer.timer);
485 s->timer.reset_val = 0x00ffffff;
492 static struct omap_32khz_timer_s *omap_os_timer_init(MemoryRegion *memory,
493 target_phys_addr_t base,
494 qemu_irq irq, omap_clk clk)
496 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *)
497 g_malloc0(sizeof(struct omap_32khz_timer_s));
501 s->timer.timer = qemu_new_timer_ns(vm_clock, omap_timer_tick, &s->timer);
502 omap_os_timer_reset(s);
503 omap_timer_clk_setup(&s->timer);
505 memory_region_init_io(&s->iomem, &omap_os_timer_ops, s,
506 "omap-os-timer", 0x800);
507 memory_region_add_subregion(memory, base, &s->iomem);
512 /* Ultra Low-Power Device Module */
513 static uint64_t omap_ulpd_pm_read(void *opaque, target_phys_addr_t addr,
516 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
520 return omap_badwidth_read16(opaque, addr);
524 case 0x14: /* IT_STATUS */
525 ret = s->ulpd_pm_regs[addr >> 2];
526 s->ulpd_pm_regs[addr >> 2] = 0;
527 qemu_irq_lower(s->irq[1][OMAP_INT_GAUGE_32K]);
530 case 0x18: /* Reserved */
531 case 0x1c: /* Reserved */
532 case 0x20: /* Reserved */
533 case 0x28: /* Reserved */
534 case 0x2c: /* Reserved */
536 case 0x00: /* COUNTER_32_LSB */
537 case 0x04: /* COUNTER_32_MSB */
538 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
539 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
540 case 0x10: /* GAUGING_CTRL */
541 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
542 case 0x30: /* CLOCK_CTRL */
543 case 0x34: /* SOFT_REQ */
544 case 0x38: /* COUNTER_32_FIQ */
545 case 0x3c: /* DPLL_CTRL */
546 case 0x40: /* STATUS_REQ */
547 /* XXX: check clk::usecount state for every clock */
548 case 0x48: /* LOCL_TIME */
549 case 0x4c: /* APLL_CTRL */
550 case 0x50: /* POWER_CTRL */
551 return s->ulpd_pm_regs[addr >> 2];
558 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s,
559 uint16_t diff, uint16_t value)
561 if (diff & (1 << 4)) /* USB_MCLK_EN */
562 omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1);
563 if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */
564 omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1);
567 static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s,
568 uint16_t diff, uint16_t value)
570 if (diff & (1 << 0)) /* SOFT_DPLL_REQ */
571 omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1);
572 if (diff & (1 << 1)) /* SOFT_COM_REQ */
573 omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1);
574 if (diff & (1 << 2)) /* SOFT_SDW_REQ */
575 omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1);
576 if (diff & (1 << 3)) /* SOFT_USB_REQ */
577 omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1);
580 static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr,
581 uint64_t value, unsigned size)
583 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
586 static const int bypass_div[4] = { 1, 2, 4, 4 };
590 return omap_badwidth_write16(opaque, addr, value);
594 case 0x00: /* COUNTER_32_LSB */
595 case 0x04: /* COUNTER_32_MSB */
596 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
597 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
598 case 0x14: /* IT_STATUS */
599 case 0x40: /* STATUS_REQ */
603 case 0x10: /* GAUGING_CTRL */
604 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
605 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
606 now = qemu_get_clock_ns(vm_clock);
609 s->ulpd_gauge_start = now;
611 now -= s->ulpd_gauge_start;
614 ticks = muldiv64(now, 32768, get_ticks_per_sec());
615 s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff;
616 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff;
617 if (ticks >> 32) /* OVERFLOW_32K */
618 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
620 /* High frequency ticks */
621 ticks = muldiv64(now, 12000000, get_ticks_per_sec());
622 s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff;
623 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff;
624 if (ticks >> 32) /* OVERFLOW_HI_FREQ */
625 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
627 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
628 qemu_irq_raise(s->irq[1][OMAP_INT_GAUGE_32K]);
631 s->ulpd_pm_regs[addr >> 2] = value;
634 case 0x18: /* Reserved */
635 case 0x1c: /* Reserved */
636 case 0x20: /* Reserved */
637 case 0x28: /* Reserved */
638 case 0x2c: /* Reserved */
640 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
641 case 0x38: /* COUNTER_32_FIQ */
642 case 0x48: /* LOCL_TIME */
643 case 0x50: /* POWER_CTRL */
644 s->ulpd_pm_regs[addr >> 2] = value;
647 case 0x30: /* CLOCK_CTRL */
648 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
649 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
650 omap_ulpd_clk_update(s, diff, value);
653 case 0x34: /* SOFT_REQ */
654 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
655 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
656 omap_ulpd_req_update(s, diff, value);
659 case 0x3c: /* DPLL_CTRL */
660 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
661 * omitted altogether, probably a typo. */
662 /* This register has identical semantics with DPLL(1:3) control
663 * registers, see omap_dpll_write() */
664 diff = s->ulpd_pm_regs[addr >> 2] & value;
665 s->ulpd_pm_regs[addr >> 2] = value & 0x2fff;
666 if (diff & (0x3ff << 2)) {
667 if (value & (1 << 4)) { /* PLL_ENABLE */
668 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
669 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
671 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
674 omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
677 /* Enter the desired mode. */
678 s->ulpd_pm_regs[addr >> 2] =
679 (s->ulpd_pm_regs[addr >> 2] & 0xfffe) |
680 ((s->ulpd_pm_regs[addr >> 2] >> 4) & 1);
682 /* Act as if the lock is restored. */
683 s->ulpd_pm_regs[addr >> 2] |= 2;
686 case 0x4c: /* APLL_CTRL */
687 diff = s->ulpd_pm_regs[addr >> 2] & value;
688 s->ulpd_pm_regs[addr >> 2] = value & 0xf;
689 if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */
690 omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
691 (value & (1 << 0)) ? "apll" : "dpll4"));
699 static const MemoryRegionOps omap_ulpd_pm_ops = {
700 .read = omap_ulpd_pm_read,
701 .write = omap_ulpd_pm_write,
702 .endianness = DEVICE_NATIVE_ENDIAN,
705 static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu)
707 mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001;
708 mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000;
709 mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001;
710 mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000;
711 mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000;
712 mpu->ulpd_pm_regs[0x18 >> 2] = 0x01;
713 mpu->ulpd_pm_regs[0x1c >> 2] = 0x01;
714 mpu->ulpd_pm_regs[0x20 >> 2] = 0x01;
715 mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff;
716 mpu->ulpd_pm_regs[0x28 >> 2] = 0x01;
717 mpu->ulpd_pm_regs[0x2c >> 2] = 0x01;
718 omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000);
719 mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000;
720 omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000);
721 mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000;
722 mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001;
723 mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211;
724 mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
725 mpu->ulpd_pm_regs[0x48 >> 2] = 0x960;
726 mpu->ulpd_pm_regs[0x4c >> 2] = 0x08;
727 mpu->ulpd_pm_regs[0x50 >> 2] = 0x08;
728 omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4);
729 omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4"));
732 static void omap_ulpd_pm_init(MemoryRegion *system_memory,
733 target_phys_addr_t base,
734 struct omap_mpu_state_s *mpu)
736 memory_region_init_io(&mpu->ulpd_pm_iomem, &omap_ulpd_pm_ops, mpu,
737 "omap-ulpd-pm", 0x800);
738 memory_region_add_subregion(system_memory, base, &mpu->ulpd_pm_iomem);
739 omap_ulpd_pm_reset(mpu);
742 /* OMAP Pin Configuration */
743 static uint64_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr,
746 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
749 return omap_badwidth_read32(opaque, addr);
753 case 0x00: /* FUNC_MUX_CTRL_0 */
754 case 0x04: /* FUNC_MUX_CTRL_1 */
755 case 0x08: /* FUNC_MUX_CTRL_2 */
756 return s->func_mux_ctrl[addr >> 2];
758 case 0x0c: /* COMP_MODE_CTRL_0 */
759 return s->comp_mode_ctrl[0];
761 case 0x10: /* FUNC_MUX_CTRL_3 */
762 case 0x14: /* FUNC_MUX_CTRL_4 */
763 case 0x18: /* FUNC_MUX_CTRL_5 */
764 case 0x1c: /* FUNC_MUX_CTRL_6 */
765 case 0x20: /* FUNC_MUX_CTRL_7 */
766 case 0x24: /* FUNC_MUX_CTRL_8 */
767 case 0x28: /* FUNC_MUX_CTRL_9 */
768 case 0x2c: /* FUNC_MUX_CTRL_A */
769 case 0x30: /* FUNC_MUX_CTRL_B */
770 case 0x34: /* FUNC_MUX_CTRL_C */
771 case 0x38: /* FUNC_MUX_CTRL_D */
772 return s->func_mux_ctrl[(addr >> 2) - 1];
774 case 0x40: /* PULL_DWN_CTRL_0 */
775 case 0x44: /* PULL_DWN_CTRL_1 */
776 case 0x48: /* PULL_DWN_CTRL_2 */
777 case 0x4c: /* PULL_DWN_CTRL_3 */
778 return s->pull_dwn_ctrl[(addr & 0xf) >> 2];
780 case 0x50: /* GATE_INH_CTRL_0 */
781 return s->gate_inh_ctrl[0];
783 case 0x60: /* VOLTAGE_CTRL_0 */
784 return s->voltage_ctrl[0];
786 case 0x70: /* TEST_DBG_CTRL_0 */
787 return s->test_dbg_ctrl[0];
789 case 0x80: /* MOD_CONF_CTRL_0 */
790 return s->mod_conf_ctrl[0];
797 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s,
798 uint32_t diff, uint32_t value)
801 if (diff & (1 << 9)) /* BLUETOOTH */
802 omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
804 if (diff & (1 << 7)) /* USB.CLKO */
805 omap_clk_onoff(omap_findclk(s, "usb.clko"),
810 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s,
811 uint32_t diff, uint32_t value)
814 if (diff & (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
815 omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"),
817 if (diff & (1 << 1)) /* CLK32K */
818 omap_clk_onoff(omap_findclk(s, "clk32k_out"),
823 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s,
824 uint32_t diff, uint32_t value)
826 if (diff & (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
827 omap_clk_reparent(omap_findclk(s, "uart3_ck"),
828 omap_findclk(s, ((value >> 31) & 1) ?
829 "ck_48m" : "armper_ck"));
830 if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
831 omap_clk_reparent(omap_findclk(s, "uart2_ck"),
832 omap_findclk(s, ((value >> 30) & 1) ?
833 "ck_48m" : "armper_ck"));
834 if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
835 omap_clk_reparent(omap_findclk(s, "uart1_ck"),
836 omap_findclk(s, ((value >> 29) & 1) ?
837 "ck_48m" : "armper_ck"));
838 if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
839 omap_clk_reparent(omap_findclk(s, "mmc_ck"),
840 omap_findclk(s, ((value >> 23) & 1) ?
841 "ck_48m" : "armper_ck"));
842 if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
843 omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
844 omap_findclk(s, ((value >> 12) & 1) ?
845 "ck_48m" : "armper_ck"));
846 if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
847 omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1);
850 static void omap_pin_cfg_write(void *opaque, target_phys_addr_t addr,
851 uint64_t value, unsigned size)
853 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
857 return omap_badwidth_write32(opaque, addr, value);
861 case 0x00: /* FUNC_MUX_CTRL_0 */
862 diff = s->func_mux_ctrl[addr >> 2] ^ value;
863 s->func_mux_ctrl[addr >> 2] = value;
864 omap_pin_funcmux0_update(s, diff, value);
867 case 0x04: /* FUNC_MUX_CTRL_1 */
868 diff = s->func_mux_ctrl[addr >> 2] ^ value;
869 s->func_mux_ctrl[addr >> 2] = value;
870 omap_pin_funcmux1_update(s, diff, value);
873 case 0x08: /* FUNC_MUX_CTRL_2 */
874 s->func_mux_ctrl[addr >> 2] = value;
877 case 0x0c: /* COMP_MODE_CTRL_0 */
878 s->comp_mode_ctrl[0] = value;
879 s->compat1509 = (value != 0x0000eaef);
880 omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]);
881 omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]);
884 case 0x10: /* FUNC_MUX_CTRL_3 */
885 case 0x14: /* FUNC_MUX_CTRL_4 */
886 case 0x18: /* FUNC_MUX_CTRL_5 */
887 case 0x1c: /* FUNC_MUX_CTRL_6 */
888 case 0x20: /* FUNC_MUX_CTRL_7 */
889 case 0x24: /* FUNC_MUX_CTRL_8 */
890 case 0x28: /* FUNC_MUX_CTRL_9 */
891 case 0x2c: /* FUNC_MUX_CTRL_A */
892 case 0x30: /* FUNC_MUX_CTRL_B */
893 case 0x34: /* FUNC_MUX_CTRL_C */
894 case 0x38: /* FUNC_MUX_CTRL_D */
895 s->func_mux_ctrl[(addr >> 2) - 1] = value;
898 case 0x40: /* PULL_DWN_CTRL_0 */
899 case 0x44: /* PULL_DWN_CTRL_1 */
900 case 0x48: /* PULL_DWN_CTRL_2 */
901 case 0x4c: /* PULL_DWN_CTRL_3 */
902 s->pull_dwn_ctrl[(addr & 0xf) >> 2] = value;
905 case 0x50: /* GATE_INH_CTRL_0 */
906 s->gate_inh_ctrl[0] = value;
909 case 0x60: /* VOLTAGE_CTRL_0 */
910 s->voltage_ctrl[0] = value;
913 case 0x70: /* TEST_DBG_CTRL_0 */
914 s->test_dbg_ctrl[0] = value;
917 case 0x80: /* MOD_CONF_CTRL_0 */
918 diff = s->mod_conf_ctrl[0] ^ value;
919 s->mod_conf_ctrl[0] = value;
920 omap_pin_modconf1_update(s, diff, value);
928 static const MemoryRegionOps omap_pin_cfg_ops = {
929 .read = omap_pin_cfg_read,
930 .write = omap_pin_cfg_write,
931 .endianness = DEVICE_NATIVE_ENDIAN,
934 static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu)
936 /* Start in Compatibility Mode. */
938 omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0);
939 omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0);
940 omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0);
941 memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl));
942 memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl));
943 memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl));
944 memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl));
945 memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl));
946 memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl));
947 memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl));
950 static void omap_pin_cfg_init(MemoryRegion *system_memory,
951 target_phys_addr_t base,
952 struct omap_mpu_state_s *mpu)
954 memory_region_init_io(&mpu->pin_cfg_iomem, &omap_pin_cfg_ops, mpu,
955 "omap-pin-cfg", 0x800);
956 memory_region_add_subregion(system_memory, base, &mpu->pin_cfg_iomem);
957 omap_pin_cfg_reset(mpu);
960 /* Device Identification, Die Identification */
961 static uint64_t omap_id_read(void *opaque, target_phys_addr_t addr,
964 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
967 return omap_badwidth_read32(opaque, addr);
971 case 0xfffe1800: /* DIE_ID_LSB */
973 case 0xfffe1804: /* DIE_ID_MSB */
976 case 0xfffe2000: /* PRODUCT_ID_LSB */
978 case 0xfffe2004: /* PRODUCT_ID_MSB */
981 case 0xfffed400: /* JTAG_ID_LSB */
982 switch (s->mpu_model) {
988 hw_error("%s: bad mpu model\n", __FUNCTION__);
992 case 0xfffed404: /* JTAG_ID_MSB */
993 switch (s->mpu_model) {
999 hw_error("%s: bad mpu model\n", __FUNCTION__);
1008 static void omap_id_write(void *opaque, target_phys_addr_t addr,
1009 uint64_t value, unsigned size)
1012 return omap_badwidth_write32(opaque, addr, value);
1018 static const MemoryRegionOps omap_id_ops = {
1019 .read = omap_id_read,
1020 .write = omap_id_write,
1021 .endianness = DEVICE_NATIVE_ENDIAN,
1024 static void omap_id_init(MemoryRegion *memory, struct omap_mpu_state_s *mpu)
1026 memory_region_init_io(&mpu->id_iomem, &omap_id_ops, mpu,
1027 "omap-id", 0x100000000ULL);
1028 memory_region_init_alias(&mpu->id_iomem_e18, "omap-id-e18", &mpu->id_iomem,
1030 memory_region_add_subregion(memory, 0xfffe1800, &mpu->id_iomem_e18);
1031 memory_region_init_alias(&mpu->id_iomem_ed4, "omap-id-ed4", &mpu->id_iomem,
1033 memory_region_add_subregion(memory, 0xfffed400, &mpu->id_iomem_ed4);
1034 if (!cpu_is_omap15xx(mpu)) {
1035 memory_region_init_alias(&mpu->id_iomem_ed4, "omap-id-e20",
1036 &mpu->id_iomem, 0xfffe2000, 0x800);
1037 memory_region_add_subregion(memory, 0xfffe2000, &mpu->id_iomem_e20);
1041 /* MPUI Control (Dummy) */
1042 static uint64_t omap_mpui_read(void *opaque, target_phys_addr_t addr,
1045 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1048 return omap_badwidth_read32(opaque, addr);
1052 case 0x00: /* CTRL */
1053 return s->mpui_ctrl;
1054 case 0x04: /* DEBUG_ADDR */
1056 case 0x08: /* DEBUG_DATA */
1058 case 0x0c: /* DEBUG_FLAG */
1060 case 0x10: /* STATUS */
1063 /* Not in OMAP310 */
1064 case 0x14: /* DSP_STATUS */
1065 case 0x18: /* DSP_BOOT_CONFIG */
1067 case 0x1c: /* DSP_MPUI_CONFIG */
1075 static void omap_mpui_write(void *opaque, target_phys_addr_t addr,
1076 uint64_t value, unsigned size)
1078 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1081 return omap_badwidth_write32(opaque, addr, value);
1085 case 0x00: /* CTRL */
1086 s->mpui_ctrl = value & 0x007fffff;
1089 case 0x04: /* DEBUG_ADDR */
1090 case 0x08: /* DEBUG_DATA */
1091 case 0x0c: /* DEBUG_FLAG */
1092 case 0x10: /* STATUS */
1093 /* Not in OMAP310 */
1094 case 0x14: /* DSP_STATUS */
1096 case 0x18: /* DSP_BOOT_CONFIG */
1097 case 0x1c: /* DSP_MPUI_CONFIG */
1105 static const MemoryRegionOps omap_mpui_ops = {
1106 .read = omap_mpui_read,
1107 .write = omap_mpui_write,
1108 .endianness = DEVICE_NATIVE_ENDIAN,
1111 static void omap_mpui_reset(struct omap_mpu_state_s *s)
1113 s->mpui_ctrl = 0x0003ff1b;
1116 static void omap_mpui_init(MemoryRegion *memory, target_phys_addr_t base,
1117 struct omap_mpu_state_s *mpu)
1119 memory_region_init_io(&mpu->mpui_iomem, &omap_mpui_ops, mpu,
1120 "omap-mpui", 0x100);
1121 memory_region_add_subregion(memory, base, &mpu->mpui_iomem);
1123 omap_mpui_reset(mpu);
1127 struct omap_tipb_bridge_s {
1135 uint16_t enh_control;
1138 static uint64_t omap_tipb_bridge_read(void *opaque, target_phys_addr_t addr,
1141 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1144 return omap_badwidth_read16(opaque, addr);
1148 case 0x00: /* TIPB_CNTL */
1150 case 0x04: /* TIPB_BUS_ALLOC */
1152 case 0x08: /* MPU_TIPB_CNTL */
1154 case 0x0c: /* ENHANCED_TIPB_CNTL */
1155 return s->enh_control;
1156 case 0x10: /* ADDRESS_DBG */
1157 case 0x14: /* DATA_DEBUG_LOW */
1158 case 0x18: /* DATA_DEBUG_HIGH */
1160 case 0x1c: /* DEBUG_CNTR_SIG */
1168 static void omap_tipb_bridge_write(void *opaque, target_phys_addr_t addr,
1169 uint64_t value, unsigned size)
1171 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1174 return omap_badwidth_write16(opaque, addr, value);
1178 case 0x00: /* TIPB_CNTL */
1179 s->control = value & 0xffff;
1182 case 0x04: /* TIPB_BUS_ALLOC */
1183 s->alloc = value & 0x003f;
1186 case 0x08: /* MPU_TIPB_CNTL */
1187 s->buffer = value & 0x0003;
1190 case 0x0c: /* ENHANCED_TIPB_CNTL */
1191 s->width_intr = !(value & 2);
1192 s->enh_control = value & 0x000f;
1195 case 0x10: /* ADDRESS_DBG */
1196 case 0x14: /* DATA_DEBUG_LOW */
1197 case 0x18: /* DATA_DEBUG_HIGH */
1198 case 0x1c: /* DEBUG_CNTR_SIG */
1207 static const MemoryRegionOps omap_tipb_bridge_ops = {
1208 .read = omap_tipb_bridge_read,
1209 .write = omap_tipb_bridge_write,
1210 .endianness = DEVICE_NATIVE_ENDIAN,
1213 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s)
1215 s->control = 0xffff;
1218 s->enh_control = 0x000f;
1221 static struct omap_tipb_bridge_s *omap_tipb_bridge_init(
1222 MemoryRegion *memory, target_phys_addr_t base,
1223 qemu_irq abort_irq, omap_clk clk)
1225 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *)
1226 g_malloc0(sizeof(struct omap_tipb_bridge_s));
1228 s->abort = abort_irq;
1229 omap_tipb_bridge_reset(s);
1231 memory_region_init_io(&s->iomem, &omap_tipb_bridge_ops, s,
1232 "omap-tipb-bridge", 0x100);
1233 memory_region_add_subregion(memory, base, &s->iomem);
1238 /* Dummy Traffic Controller's Memory Interface */
1239 static uint64_t omap_tcmi_read(void *opaque, target_phys_addr_t addr,
1242 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1246 return omap_badwidth_read32(opaque, addr);
1250 case 0x00: /* IMIF_PRIO */
1251 case 0x04: /* EMIFS_PRIO */
1252 case 0x08: /* EMIFF_PRIO */
1253 case 0x0c: /* EMIFS_CONFIG */
1254 case 0x10: /* EMIFS_CS0_CONFIG */
1255 case 0x14: /* EMIFS_CS1_CONFIG */
1256 case 0x18: /* EMIFS_CS2_CONFIG */
1257 case 0x1c: /* EMIFS_CS3_CONFIG */
1258 case 0x24: /* EMIFF_MRS */
1259 case 0x28: /* TIMEOUT1 */
1260 case 0x2c: /* TIMEOUT2 */
1261 case 0x30: /* TIMEOUT3 */
1262 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1263 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1264 return s->tcmi_regs[addr >> 2];
1266 case 0x20: /* EMIFF_SDRAM_CONFIG */
1267 ret = s->tcmi_regs[addr >> 2];
1268 s->tcmi_regs[addr >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1269 /* XXX: We can try using the VGA_DIRTY flag for this */
1277 static void omap_tcmi_write(void *opaque, target_phys_addr_t addr,
1278 uint64_t value, unsigned size)
1280 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1283 return omap_badwidth_write32(opaque, addr, value);
1287 case 0x00: /* IMIF_PRIO */
1288 case 0x04: /* EMIFS_PRIO */
1289 case 0x08: /* EMIFF_PRIO */
1290 case 0x10: /* EMIFS_CS0_CONFIG */
1291 case 0x14: /* EMIFS_CS1_CONFIG */
1292 case 0x18: /* EMIFS_CS2_CONFIG */
1293 case 0x1c: /* EMIFS_CS3_CONFIG */
1294 case 0x20: /* EMIFF_SDRAM_CONFIG */
1295 case 0x24: /* EMIFF_MRS */
1296 case 0x28: /* TIMEOUT1 */
1297 case 0x2c: /* TIMEOUT2 */
1298 case 0x30: /* TIMEOUT3 */
1299 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1300 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1301 s->tcmi_regs[addr >> 2] = value;
1303 case 0x0c: /* EMIFS_CONFIG */
1304 s->tcmi_regs[addr >> 2] = (value & 0xf) | (1 << 4);
1312 static const MemoryRegionOps omap_tcmi_ops = {
1313 .read = omap_tcmi_read,
1314 .write = omap_tcmi_write,
1315 .endianness = DEVICE_NATIVE_ENDIAN,
1318 static void omap_tcmi_reset(struct omap_mpu_state_s *mpu)
1320 mpu->tcmi_regs[0x00 >> 2] = 0x00000000;
1321 mpu->tcmi_regs[0x04 >> 2] = 0x00000000;
1322 mpu->tcmi_regs[0x08 >> 2] = 0x00000000;
1323 mpu->tcmi_regs[0x0c >> 2] = 0x00000010;
1324 mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb;
1325 mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb;
1326 mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb;
1327 mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb;
1328 mpu->tcmi_regs[0x20 >> 2] = 0x00618800;
1329 mpu->tcmi_regs[0x24 >> 2] = 0x00000037;
1330 mpu->tcmi_regs[0x28 >> 2] = 0x00000000;
1331 mpu->tcmi_regs[0x2c >> 2] = 0x00000000;
1332 mpu->tcmi_regs[0x30 >> 2] = 0x00000000;
1333 mpu->tcmi_regs[0x3c >> 2] = 0x00000003;
1334 mpu->tcmi_regs[0x40 >> 2] = 0x00000000;
1337 static void omap_tcmi_init(MemoryRegion *memory, target_phys_addr_t base,
1338 struct omap_mpu_state_s *mpu)
1340 memory_region_init_io(&mpu->tcmi_iomem, &omap_tcmi_ops, mpu,
1341 "omap-tcmi", 0x100);
1342 memory_region_add_subregion(memory, base, &mpu->tcmi_iomem);
1343 omap_tcmi_reset(mpu);
1346 /* Digital phase-locked loops control */
1347 static uint64_t omap_dpll_read(void *opaque, target_phys_addr_t addr,
1350 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1353 return omap_badwidth_read16(opaque, addr);
1356 if (addr == 0x00) /* CTL_REG */
1363 static void omap_dpll_write(void *opaque, target_phys_addr_t addr,
1364 uint64_t value, unsigned size)
1366 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1368 static const int bypass_div[4] = { 1, 2, 4, 4 };
1372 return omap_badwidth_write16(opaque, addr, value);
1375 if (addr == 0x00) { /* CTL_REG */
1376 /* See omap_ulpd_pm_write() too */
1377 diff = s->mode & value;
1378 s->mode = value & 0x2fff;
1379 if (diff & (0x3ff << 2)) {
1380 if (value & (1 << 4)) { /* PLL_ENABLE */
1381 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1382 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1384 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1387 omap_clk_setrate(s->dpll, div, mult);
1390 /* Enter the desired mode. */
1391 s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1);
1393 /* Act as if the lock is restored. */
1400 static const MemoryRegionOps omap_dpll_ops = {
1401 .read = omap_dpll_read,
1402 .write = omap_dpll_write,
1403 .endianness = DEVICE_NATIVE_ENDIAN,
1406 static void omap_dpll_reset(struct dpll_ctl_s *s)
1409 omap_clk_setrate(s->dpll, 1, 1);
1412 static void omap_dpll_init(MemoryRegion *memory, struct dpll_ctl_s *s,
1413 target_phys_addr_t base, omap_clk clk)
1415 memory_region_init_io(&s->iomem, &omap_dpll_ops, s, "omap-dpll", 0x100);
1420 memory_region_add_subregion(memory, base, &s->iomem);
1423 /* MPU Clock/Reset/Power Mode Control */
1424 static uint64_t omap_clkm_read(void *opaque, target_phys_addr_t addr,
1427 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1430 return omap_badwidth_read16(opaque, addr);
1434 case 0x00: /* ARM_CKCTL */
1435 return s->clkm.arm_ckctl;
1437 case 0x04: /* ARM_IDLECT1 */
1438 return s->clkm.arm_idlect1;
1440 case 0x08: /* ARM_IDLECT2 */
1441 return s->clkm.arm_idlect2;
1443 case 0x0c: /* ARM_EWUPCT */
1444 return s->clkm.arm_ewupct;
1446 case 0x10: /* ARM_RSTCT1 */
1447 return s->clkm.arm_rstct1;
1449 case 0x14: /* ARM_RSTCT2 */
1450 return s->clkm.arm_rstct2;
1452 case 0x18: /* ARM_SYSST */
1453 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start;
1455 case 0x1c: /* ARM_CKOUT1 */
1456 return s->clkm.arm_ckout1;
1458 case 0x20: /* ARM_CKOUT2 */
1466 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s,
1467 uint16_t diff, uint16_t value)
1471 if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */
1472 if (value & (1 << 14))
1475 clk = omap_findclk(s, "arminth_ck");
1476 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
1479 if (diff & (1 << 12)) { /* ARM_TIMXO */
1480 clk = omap_findclk(s, "armtim_ck");
1481 if (value & (1 << 12))
1482 omap_clk_reparent(clk, omap_findclk(s, "clkin"));
1484 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
1487 if (diff & (3 << 10)) { /* DSPMMUDIV */
1488 clk = omap_findclk(s, "dspmmu_ck");
1489 omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1);
1491 if (diff & (3 << 8)) { /* TCDIV */
1492 clk = omap_findclk(s, "tc_ck");
1493 omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1);
1495 if (diff & (3 << 6)) { /* DSPDIV */
1496 clk = omap_findclk(s, "dsp_ck");
1497 omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1);
1499 if (diff & (3 << 4)) { /* ARMDIV */
1500 clk = omap_findclk(s, "arm_ck");
1501 omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1);
1503 if (diff & (3 << 2)) { /* LCDDIV */
1504 clk = omap_findclk(s, "lcd_ck");
1505 omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1);
1507 if (diff & (3 << 0)) { /* PERDIV */
1508 clk = omap_findclk(s, "armper_ck");
1509 omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1);
1513 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s,
1514 uint16_t diff, uint16_t value)
1518 if (value & (1 << 11)) /* SETARM_IDLE */
1519 cpu_interrupt(s->env, CPU_INTERRUPT_HALT);
1520 if (!(value & (1 << 10))) /* WKUP_MODE */
1521 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
1523 #define SET_CANIDLE(clock, bit) \
1524 if (diff & (1 << bit)) { \
1525 clk = omap_findclk(s, clock); \
1526 omap_clk_canidle(clk, (value >> bit) & 1); \
1528 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1529 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1530 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1531 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1532 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1533 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1534 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1535 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1536 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1537 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1538 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1539 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1540 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1541 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1544 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s,
1545 uint16_t diff, uint16_t value)
1549 #define SET_ONOFF(clock, bit) \
1550 if (diff & (1 << bit)) { \
1551 clk = omap_findclk(s, clock); \
1552 omap_clk_onoff(clk, (value >> bit) & 1); \
1554 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1555 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1556 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1557 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1558 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1559 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1560 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1561 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1562 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1563 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1564 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1567 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s,
1568 uint16_t diff, uint16_t value)
1572 if (diff & (3 << 4)) { /* TCLKOUT */
1573 clk = omap_findclk(s, "tclk_out");
1574 switch ((value >> 4) & 3) {
1576 omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
1577 omap_clk_onoff(clk, 1);
1580 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
1581 omap_clk_onoff(clk, 1);
1584 omap_clk_onoff(clk, 0);
1587 if (diff & (3 << 2)) { /* DCLKOUT */
1588 clk = omap_findclk(s, "dclk_out");
1589 switch ((value >> 2) & 3) {
1591 omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
1594 omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
1597 omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
1600 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
1604 if (diff & (3 << 0)) { /* ACLKOUT */
1605 clk = omap_findclk(s, "aclk_out");
1606 switch ((value >> 0) & 3) {
1608 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
1609 omap_clk_onoff(clk, 1);
1612 omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
1613 omap_clk_onoff(clk, 1);
1616 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
1617 omap_clk_onoff(clk, 1);
1620 omap_clk_onoff(clk, 0);
1625 static void omap_clkm_write(void *opaque, target_phys_addr_t addr,
1626 uint64_t value, unsigned size)
1628 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1631 static const char *clkschemename[8] = {
1632 "fully synchronous", "fully asynchronous", "synchronous scalable",
1633 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1637 return omap_badwidth_write16(opaque, addr, value);
1641 case 0x00: /* ARM_CKCTL */
1642 diff = s->clkm.arm_ckctl ^ value;
1643 s->clkm.arm_ckctl = value & 0x7fff;
1644 omap_clkm_ckctl_update(s, diff, value);
1647 case 0x04: /* ARM_IDLECT1 */
1648 diff = s->clkm.arm_idlect1 ^ value;
1649 s->clkm.arm_idlect1 = value & 0x0fff;
1650 omap_clkm_idlect1_update(s, diff, value);
1653 case 0x08: /* ARM_IDLECT2 */
1654 diff = s->clkm.arm_idlect2 ^ value;
1655 s->clkm.arm_idlect2 = value & 0x07ff;
1656 omap_clkm_idlect2_update(s, diff, value);
1659 case 0x0c: /* ARM_EWUPCT */
1660 s->clkm.arm_ewupct = value & 0x003f;
1663 case 0x10: /* ARM_RSTCT1 */
1664 diff = s->clkm.arm_rstct1 ^ value;
1665 s->clkm.arm_rstct1 = value & 0x0007;
1667 qemu_system_reset_request();
1668 s->clkm.cold_start = 0xa;
1670 if (diff & ~value & 4) { /* DSP_RST */
1672 omap_tipb_bridge_reset(s->private_tipb);
1673 omap_tipb_bridge_reset(s->public_tipb);
1675 if (diff & 2) { /* DSP_EN */
1676 clk = omap_findclk(s, "dsp_ck");
1677 omap_clk_canidle(clk, (~value >> 1) & 1);
1681 case 0x14: /* ARM_RSTCT2 */
1682 s->clkm.arm_rstct2 = value & 0x0001;
1685 case 0x18: /* ARM_SYSST */
1686 if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) {
1687 s->clkm.clocking_scheme = (value >> 11) & 7;
1688 printf("%s: clocking scheme set to %s\n", __FUNCTION__,
1689 clkschemename[s->clkm.clocking_scheme]);
1691 s->clkm.cold_start &= value & 0x3f;
1694 case 0x1c: /* ARM_CKOUT1 */
1695 diff = s->clkm.arm_ckout1 ^ value;
1696 s->clkm.arm_ckout1 = value & 0x003f;
1697 omap_clkm_ckout1_update(s, diff, value);
1700 case 0x20: /* ARM_CKOUT2 */
1706 static const MemoryRegionOps omap_clkm_ops = {
1707 .read = omap_clkm_read,
1708 .write = omap_clkm_write,
1709 .endianness = DEVICE_NATIVE_ENDIAN,
1712 static uint64_t omap_clkdsp_read(void *opaque, target_phys_addr_t addr,
1715 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1718 return omap_badwidth_read16(opaque, addr);
1722 case 0x04: /* DSP_IDLECT1 */
1723 return s->clkm.dsp_idlect1;
1725 case 0x08: /* DSP_IDLECT2 */
1726 return s->clkm.dsp_idlect2;
1728 case 0x14: /* DSP_RSTCT2 */
1729 return s->clkm.dsp_rstct2;
1731 case 0x18: /* DSP_SYSST */
1732 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start |
1733 (s->env->halted << 6); /* Quite useless... */
1740 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s,
1741 uint16_t diff, uint16_t value)
1745 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1748 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s,
1749 uint16_t diff, uint16_t value)
1753 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1756 static void omap_clkdsp_write(void *opaque, target_phys_addr_t addr,
1757 uint64_t value, unsigned size)
1759 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1763 return omap_badwidth_write16(opaque, addr, value);
1767 case 0x04: /* DSP_IDLECT1 */
1768 diff = s->clkm.dsp_idlect1 ^ value;
1769 s->clkm.dsp_idlect1 = value & 0x01f7;
1770 omap_clkdsp_idlect1_update(s, diff, value);
1773 case 0x08: /* DSP_IDLECT2 */
1774 s->clkm.dsp_idlect2 = value & 0x0037;
1775 diff = s->clkm.dsp_idlect1 ^ value;
1776 omap_clkdsp_idlect2_update(s, diff, value);
1779 case 0x14: /* DSP_RSTCT2 */
1780 s->clkm.dsp_rstct2 = value & 0x0001;
1783 case 0x18: /* DSP_SYSST */
1784 s->clkm.cold_start &= value & 0x3f;
1792 static const MemoryRegionOps omap_clkdsp_ops = {
1793 .read = omap_clkdsp_read,
1794 .write = omap_clkdsp_write,
1795 .endianness = DEVICE_NATIVE_ENDIAN,
1798 static void omap_clkm_reset(struct omap_mpu_state_s *s)
1800 if (s->wdt && s->wdt->reset)
1801 s->clkm.cold_start = 0x6;
1802 s->clkm.clocking_scheme = 0;
1803 omap_clkm_ckctl_update(s, ~0, 0x3000);
1804 s->clkm.arm_ckctl = 0x3000;
1805 omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 ^ 0x0400, 0x0400);
1806 s->clkm.arm_idlect1 = 0x0400;
1807 omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 ^ 0x0100, 0x0100);
1808 s->clkm.arm_idlect2 = 0x0100;
1809 s->clkm.arm_ewupct = 0x003f;
1810 s->clkm.arm_rstct1 = 0x0000;
1811 s->clkm.arm_rstct2 = 0x0000;
1812 s->clkm.arm_ckout1 = 0x0015;
1813 s->clkm.dpll1_mode = 0x2002;
1814 omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040);
1815 s->clkm.dsp_idlect1 = 0x0040;
1816 omap_clkdsp_idlect2_update(s, ~0, 0x0000);
1817 s->clkm.dsp_idlect2 = 0x0000;
1818 s->clkm.dsp_rstct2 = 0x0000;
1821 static void omap_clkm_init(MemoryRegion *memory, target_phys_addr_t mpu_base,
1822 target_phys_addr_t dsp_base, struct omap_mpu_state_s *s)
1824 memory_region_init_io(&s->clkm_iomem, &omap_clkm_ops, s,
1825 "omap-clkm", 0x100);
1826 memory_region_init_io(&s->clkdsp_iomem, &omap_clkdsp_ops, s,
1827 "omap-clkdsp", 0x1000);
1829 s->clkm.arm_idlect1 = 0x03ff;
1830 s->clkm.arm_idlect2 = 0x0100;
1831 s->clkm.dsp_idlect1 = 0x0002;
1833 s->clkm.cold_start = 0x3a;
1835 memory_region_add_subregion(memory, mpu_base, &s->clkm_iomem);
1836 memory_region_add_subregion(memory, dsp_base, &s->clkdsp_iomem);
1840 struct omap_mpuio_s {
1844 qemu_irq handler[16];
1866 static void omap_mpuio_set(void *opaque, int line, int level)
1868 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1869 uint16_t prev = s->inputs;
1872 s->inputs |= 1 << line;
1874 s->inputs &= ~(1 << line);
1876 if (((1 << line) & s->dir & ~s->mask) && s->clk) {
1877 if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
1878 s->ints |= 1 << line;
1879 qemu_irq_raise(s->irq);
1882 if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1883 (s->event >> 1) == line) /* PIN_SELECT */
1884 s->latch = s->inputs;
1888 static void omap_mpuio_kbd_update(struct omap_mpuio_s *s)
1891 uint8_t *row, rows = 0, cols = ~s->cols;
1893 for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1)
1897 qemu_set_irq(s->kbd_irq, rows && !s->kbd_mask && s->clk);
1898 s->row_latch = ~rows;
1901 static uint64_t omap_mpuio_read(void *opaque, target_phys_addr_t addr,
1904 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1905 int offset = addr & OMAP_MPUI_REG_MASK;
1909 return omap_badwidth_read16(opaque, addr);
1913 case 0x00: /* INPUT_LATCH */
1916 case 0x04: /* OUTPUT_REG */
1919 case 0x08: /* IO_CNTL */
1922 case 0x10: /* KBR_LATCH */
1923 return s->row_latch;
1925 case 0x14: /* KBC_REG */
1928 case 0x18: /* GPIO_EVENT_MODE_REG */
1931 case 0x1c: /* GPIO_INT_EDGE_REG */
1934 case 0x20: /* KBD_INT */
1935 return (~s->row_latch & 0x1f) && !s->kbd_mask;
1937 case 0x24: /* GPIO_INT */
1941 qemu_irq_lower(s->irq);
1944 case 0x28: /* KBD_MASKIT */
1947 case 0x2c: /* GPIO_MASKIT */
1950 case 0x30: /* GPIO_DEBOUNCING_REG */
1953 case 0x34: /* GPIO_LATCH_REG */
1961 static void omap_mpuio_write(void *opaque, target_phys_addr_t addr,
1962 uint64_t value, unsigned size)
1964 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1965 int offset = addr & OMAP_MPUI_REG_MASK;
1970 return omap_badwidth_write16(opaque, addr, value);
1974 case 0x04: /* OUTPUT_REG */
1975 diff = (s->outputs ^ value) & ~s->dir;
1977 while ((ln = ffs(diff))) {
1980 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
1985 case 0x08: /* IO_CNTL */
1986 diff = s->outputs & (s->dir ^ value);
1989 value = s->outputs & ~s->dir;
1990 while ((ln = ffs(diff))) {
1993 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
1998 case 0x14: /* KBC_REG */
2000 omap_mpuio_kbd_update(s);
2003 case 0x18: /* GPIO_EVENT_MODE_REG */
2004 s->event = value & 0x1f;
2007 case 0x1c: /* GPIO_INT_EDGE_REG */
2011 case 0x28: /* KBD_MASKIT */
2012 s->kbd_mask = value & 1;
2013 omap_mpuio_kbd_update(s);
2016 case 0x2c: /* GPIO_MASKIT */
2020 case 0x30: /* GPIO_DEBOUNCING_REG */
2021 s->debounce = value & 0x1ff;
2024 case 0x00: /* INPUT_LATCH */
2025 case 0x10: /* KBR_LATCH */
2026 case 0x20: /* KBD_INT */
2027 case 0x24: /* GPIO_INT */
2028 case 0x34: /* GPIO_LATCH_REG */
2038 static const MemoryRegionOps omap_mpuio_ops = {
2039 .read = omap_mpuio_read,
2040 .write = omap_mpuio_write,
2041 .endianness = DEVICE_NATIVE_ENDIAN,
2044 static void omap_mpuio_reset(struct omap_mpuio_s *s)
2056 s->row_latch = 0x1f;
2060 static void omap_mpuio_onoff(void *opaque, int line, int on)
2062 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2066 omap_mpuio_kbd_update(s);
2069 struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory,
2070 target_phys_addr_t base,
2071 qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup,
2074 struct omap_mpuio_s *s = (struct omap_mpuio_s *)
2075 g_malloc0(sizeof(struct omap_mpuio_s));
2078 s->kbd_irq = kbd_int;
2080 s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
2081 omap_mpuio_reset(s);
2083 memory_region_init_io(&s->iomem, &omap_mpuio_ops, s,
2084 "omap-mpuio", 0x800);
2085 memory_region_add_subregion(memory, base, &s->iomem);
2087 omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]);
2092 qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
2097 void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler)
2099 if (line >= 16 || line < 0)
2100 hw_error("%s: No GPIO line %i\n", __FUNCTION__, line);
2101 s->handler[line] = handler;
2104 void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down)
2106 if (row >= 5 || row < 0)
2107 hw_error("%s: No key %i-%i\n", __FUNCTION__, col, row);
2110 s->buttons[row] |= 1 << col;
2112 s->buttons[row] &= ~(1 << col);
2114 omap_mpuio_kbd_update(s);
2117 /* MicroWire Interface */
2118 struct omap_uwire_s {
2128 uWireSlave *chip[4];
2131 static void omap_uwire_transfer_start(struct omap_uwire_s *s)
2133 int chipselect = (s->control >> 10) & 3; /* INDEX */
2134 uWireSlave *slave = s->chip[chipselect];
2136 if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */
2137 if (s->control & (1 << 12)) /* CS_CMD */
2138 if (slave && slave->send)
2139 slave->send(slave->opaque,
2140 s->txbuf >> (16 - ((s->control >> 5) & 0x1f)));
2141 s->control &= ~(1 << 14); /* CSRB */
2142 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2143 * a DRQ. When is the level IRQ supposed to be reset? */
2146 if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */
2147 if (s->control & (1 << 12)) /* CS_CMD */
2148 if (slave && slave->receive)
2149 s->rxbuf = slave->receive(slave->opaque);
2150 s->control |= 1 << 15; /* RDRB */
2151 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2152 * a DRQ. When is the level IRQ supposed to be reset? */
2156 static uint32_t omap_uwire_read(void *opaque, target_phys_addr_t addr)
2158 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
2159 int offset = addr & OMAP_MPUI_REG_MASK;
2162 case 0x00: /* RDR */
2163 s->control &= ~(1 << 15); /* RDRB */
2166 case 0x04: /* CSR */
2169 case 0x08: /* SR1 */
2171 case 0x0c: /* SR2 */
2173 case 0x10: /* SR3 */
2175 case 0x14: /* SR4 */
2177 case 0x18: /* SR5 */
2185 static void omap_uwire_write(void *opaque, target_phys_addr_t addr,
2188 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
2189 int offset = addr & OMAP_MPUI_REG_MASK;
2192 case 0x00: /* TDR */
2193 s->txbuf = value; /* TD */
2194 if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */
2195 ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2196 (s->control & (1 << 12)))) { /* CS_CMD */
2197 s->control |= 1 << 14; /* CSRB */
2198 omap_uwire_transfer_start(s);
2202 case 0x04: /* CSR */
2203 s->control = value & 0x1fff;
2204 if (value & (1 << 13)) /* START */
2205 omap_uwire_transfer_start(s);
2208 case 0x08: /* SR1 */
2209 s->setup[0] = value & 0x003f;
2212 case 0x0c: /* SR2 */
2213 s->setup[1] = value & 0x0fc0;
2216 case 0x10: /* SR3 */
2217 s->setup[2] = value & 0x0003;
2220 case 0x14: /* SR4 */
2221 s->setup[3] = value & 0x0001;
2224 case 0x18: /* SR5 */
2225 s->setup[4] = value & 0x000f;
2234 static CPUReadMemoryFunc * const omap_uwire_readfn[] = {
2235 omap_badwidth_read16,
2237 omap_badwidth_read16,
2240 static CPUWriteMemoryFunc * const omap_uwire_writefn[] = {
2241 omap_badwidth_write16,
2243 omap_badwidth_write16,
2246 static void omap_uwire_reset(struct omap_uwire_s *s)
2256 struct omap_uwire_s *omap_uwire_init(target_phys_addr_t base,
2257 qemu_irq *irq, qemu_irq dma, omap_clk clk)
2260 struct omap_uwire_s *s = (struct omap_uwire_s *)
2261 g_malloc0(sizeof(struct omap_uwire_s));
2266 omap_uwire_reset(s);
2268 iomemtype = cpu_register_io_memory(omap_uwire_readfn,
2269 omap_uwire_writefn, s, DEVICE_NATIVE_ENDIAN);
2270 cpu_register_physical_memory(base, 0x800, iomemtype);
2275 void omap_uwire_attach(struct omap_uwire_s *s,
2276 uWireSlave *slave, int chipselect)
2278 if (chipselect < 0 || chipselect > 3) {
2279 fprintf(stderr, "%s: Bad chipselect %i\n", __FUNCTION__, chipselect);
2283 s->chip[chipselect] = slave;
2286 /* Pseudonoise Pulse-Width Light Modulator */
2287 static void omap_pwl_update(struct omap_mpu_state_s *s)
2289 int output = (s->pwl.clk && s->pwl.enable) ? s->pwl.level : 0;
2291 if (output != s->pwl.output) {
2292 s->pwl.output = output;
2293 printf("%s: Backlight now at %i/256\n", __FUNCTION__, output);
2297 static uint32_t omap_pwl_read(void *opaque, target_phys_addr_t addr)
2299 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2300 int offset = addr & OMAP_MPUI_REG_MASK;
2303 case 0x00: /* PWL_LEVEL */
2304 return s->pwl.level;
2305 case 0x04: /* PWL_CTRL */
2306 return s->pwl.enable;
2312 static void omap_pwl_write(void *opaque, target_phys_addr_t addr,
2315 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2316 int offset = addr & OMAP_MPUI_REG_MASK;
2319 case 0x00: /* PWL_LEVEL */
2320 s->pwl.level = value;
2323 case 0x04: /* PWL_CTRL */
2324 s->pwl.enable = value & 1;
2333 static CPUReadMemoryFunc * const omap_pwl_readfn[] = {
2335 omap_badwidth_read8,
2336 omap_badwidth_read8,
2339 static CPUWriteMemoryFunc * const omap_pwl_writefn[] = {
2341 omap_badwidth_write8,
2342 omap_badwidth_write8,
2345 static void omap_pwl_reset(struct omap_mpu_state_s *s)
2354 static void omap_pwl_clk_update(void *opaque, int line, int on)
2356 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2362 static void omap_pwl_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
2369 iomemtype = cpu_register_io_memory(omap_pwl_readfn,
2370 omap_pwl_writefn, s, DEVICE_NATIVE_ENDIAN);
2371 cpu_register_physical_memory(base, 0x800, iomemtype);
2373 omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]);
2376 /* Pulse-Width Tone module */
2377 static uint32_t omap_pwt_read(void *opaque, target_phys_addr_t addr)
2379 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2380 int offset = addr & OMAP_MPUI_REG_MASK;
2383 case 0x00: /* FRC */
2385 case 0x04: /* VCR */
2387 case 0x08: /* GCR */
2394 static void omap_pwt_write(void *opaque, target_phys_addr_t addr,
2397 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2398 int offset = addr & OMAP_MPUI_REG_MASK;
2401 case 0x00: /* FRC */
2402 s->pwt.frc = value & 0x3f;
2404 case 0x04: /* VRC */
2405 if ((value ^ s->pwt.vrc) & 1) {
2407 printf("%s: %iHz buzz on\n", __FUNCTION__, (int)
2408 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2409 ((omap_clk_getrate(s->pwt.clk) >> 3) /
2410 /* Pre-multiplexer divider */
2411 ((s->pwt.gcr & 2) ? 1 : 154) /
2412 /* Octave multiplexer */
2413 (2 << (value & 3)) *
2414 /* 101/107 divider */
2415 ((value & (1 << 2)) ? 101 : 107) *
2417 ((value & (1 << 3)) ? 49 : 55) *
2419 ((value & (1 << 4)) ? 50 : 63) *
2420 /* 80/127 divider */
2421 ((value & (1 << 5)) ? 80 : 127) /
2422 (107 * 55 * 63 * 127)));
2424 printf("%s: silence!\n", __FUNCTION__);
2426 s->pwt.vrc = value & 0x7f;
2428 case 0x08: /* GCR */
2429 s->pwt.gcr = value & 3;
2437 static CPUReadMemoryFunc * const omap_pwt_readfn[] = {
2439 omap_badwidth_read8,
2440 omap_badwidth_read8,
2443 static CPUWriteMemoryFunc * const omap_pwt_writefn[] = {
2445 omap_badwidth_write8,
2446 omap_badwidth_write8,
2449 static void omap_pwt_reset(struct omap_mpu_state_s *s)
2456 static void omap_pwt_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
2464 iomemtype = cpu_register_io_memory(omap_pwt_readfn,
2465 omap_pwt_writefn, s, DEVICE_NATIVE_ENDIAN);
2466 cpu_register_physical_memory(base, 0x800, iomemtype);
2469 /* Real-time Clock module */
2485 struct tm current_tm;
2490 static void omap_rtc_interrupts_update(struct omap_rtc_s *s)
2492 /* s->alarm is level-triggered */
2493 qemu_set_irq(s->alarm, (s->status >> 6) & 1);
2496 static void omap_rtc_alarm_update(struct omap_rtc_s *s)
2498 s->alarm_ti = mktimegm(&s->alarm_tm);
2499 if (s->alarm_ti == -1)
2500 printf("%s: conversion failed\n", __FUNCTION__);
2503 static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr)
2505 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
2506 int offset = addr & OMAP_MPUI_REG_MASK;
2510 case 0x00: /* SECONDS_REG */
2511 return to_bcd(s->current_tm.tm_sec);
2513 case 0x04: /* MINUTES_REG */
2514 return to_bcd(s->current_tm.tm_min);
2516 case 0x08: /* HOURS_REG */
2518 return ((s->current_tm.tm_hour > 11) << 7) |
2519 to_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
2521 return to_bcd(s->current_tm.tm_hour);
2523 case 0x0c: /* DAYS_REG */
2524 return to_bcd(s->current_tm.tm_mday);
2526 case 0x10: /* MONTHS_REG */
2527 return to_bcd(s->current_tm.tm_mon + 1);
2529 case 0x14: /* YEARS_REG */
2530 return to_bcd(s->current_tm.tm_year % 100);
2532 case 0x18: /* WEEK_REG */
2533 return s->current_tm.tm_wday;
2535 case 0x20: /* ALARM_SECONDS_REG */
2536 return to_bcd(s->alarm_tm.tm_sec);
2538 case 0x24: /* ALARM_MINUTES_REG */
2539 return to_bcd(s->alarm_tm.tm_min);
2541 case 0x28: /* ALARM_HOURS_REG */
2543 return ((s->alarm_tm.tm_hour > 11) << 7) |
2544 to_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
2546 return to_bcd(s->alarm_tm.tm_hour);
2548 case 0x2c: /* ALARM_DAYS_REG */
2549 return to_bcd(s->alarm_tm.tm_mday);
2551 case 0x30: /* ALARM_MONTHS_REG */
2552 return to_bcd(s->alarm_tm.tm_mon + 1);
2554 case 0x34: /* ALARM_YEARS_REG */
2555 return to_bcd(s->alarm_tm.tm_year % 100);
2557 case 0x40: /* RTC_CTRL_REG */
2558 return (s->pm_am << 3) | (s->auto_comp << 2) |
2559 (s->round << 1) | s->running;
2561 case 0x44: /* RTC_STATUS_REG */
2566 case 0x48: /* RTC_INTERRUPTS_REG */
2567 return s->interrupts;
2569 case 0x4c: /* RTC_COMP_LSB_REG */
2570 return ((uint16_t) s->comp_reg) & 0xff;
2572 case 0x50: /* RTC_COMP_MSB_REG */
2573 return ((uint16_t) s->comp_reg) >> 8;
2580 static void omap_rtc_write(void *opaque, target_phys_addr_t addr,
2583 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
2584 int offset = addr & OMAP_MPUI_REG_MASK;
2589 case 0x00: /* SECONDS_REG */
2591 printf("RTC SEC_REG <-- %02x\n", value);
2593 s->ti -= s->current_tm.tm_sec;
2594 s->ti += from_bcd(value);
2597 case 0x04: /* MINUTES_REG */
2599 printf("RTC MIN_REG <-- %02x\n", value);
2601 s->ti -= s->current_tm.tm_min * 60;
2602 s->ti += from_bcd(value) * 60;
2605 case 0x08: /* HOURS_REG */
2607 printf("RTC HRS_REG <-- %02x\n", value);
2609 s->ti -= s->current_tm.tm_hour * 3600;
2611 s->ti += (from_bcd(value & 0x3f) & 12) * 3600;
2612 s->ti += ((value >> 7) & 1) * 43200;
2614 s->ti += from_bcd(value & 0x3f) * 3600;
2617 case 0x0c: /* DAYS_REG */
2619 printf("RTC DAY_REG <-- %02x\n", value);
2621 s->ti -= s->current_tm.tm_mday * 86400;
2622 s->ti += from_bcd(value) * 86400;
2625 case 0x10: /* MONTHS_REG */
2627 printf("RTC MTH_REG <-- %02x\n", value);
2629 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
2630 new_tm.tm_mon = from_bcd(value);
2631 ti[0] = mktimegm(&s->current_tm);
2632 ti[1] = mktimegm(&new_tm);
2634 if (ti[0] != -1 && ti[1] != -1) {
2638 /* A less accurate version */
2639 s->ti -= s->current_tm.tm_mon * 2592000;
2640 s->ti += from_bcd(value) * 2592000;
2644 case 0x14: /* YEARS_REG */
2646 printf("RTC YRS_REG <-- %02x\n", value);
2648 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
2649 new_tm.tm_year += from_bcd(value) - (new_tm.tm_year % 100);
2650 ti[0] = mktimegm(&s->current_tm);
2651 ti[1] = mktimegm(&new_tm);
2653 if (ti[0] != -1 && ti[1] != -1) {
2657 /* A less accurate version */
2658 s->ti -= (s->current_tm.tm_year % 100) * 31536000;
2659 s->ti += from_bcd(value) * 31536000;
2663 case 0x18: /* WEEK_REG */
2664 return; /* Ignored */
2666 case 0x20: /* ALARM_SECONDS_REG */
2668 printf("ALM SEC_REG <-- %02x\n", value);
2670 s->alarm_tm.tm_sec = from_bcd(value);
2671 omap_rtc_alarm_update(s);
2674 case 0x24: /* ALARM_MINUTES_REG */
2676 printf("ALM MIN_REG <-- %02x\n", value);
2678 s->alarm_tm.tm_min = from_bcd(value);
2679 omap_rtc_alarm_update(s);
2682 case 0x28: /* ALARM_HOURS_REG */
2684 printf("ALM HRS_REG <-- %02x\n", value);
2687 s->alarm_tm.tm_hour =
2688 ((from_bcd(value & 0x3f)) % 12) +
2689 ((value >> 7) & 1) * 12;
2691 s->alarm_tm.tm_hour = from_bcd(value);
2692 omap_rtc_alarm_update(s);
2695 case 0x2c: /* ALARM_DAYS_REG */
2697 printf("ALM DAY_REG <-- %02x\n", value);
2699 s->alarm_tm.tm_mday = from_bcd(value);
2700 omap_rtc_alarm_update(s);
2703 case 0x30: /* ALARM_MONTHS_REG */
2705 printf("ALM MON_REG <-- %02x\n", value);
2707 s->alarm_tm.tm_mon = from_bcd(value);
2708 omap_rtc_alarm_update(s);
2711 case 0x34: /* ALARM_YEARS_REG */
2713 printf("ALM YRS_REG <-- %02x\n", value);
2715 s->alarm_tm.tm_year = from_bcd(value);
2716 omap_rtc_alarm_update(s);
2719 case 0x40: /* RTC_CTRL_REG */
2721 printf("RTC CONTROL <-- %02x\n", value);
2723 s->pm_am = (value >> 3) & 1;
2724 s->auto_comp = (value >> 2) & 1;
2725 s->round = (value >> 1) & 1;
2726 s->running = value & 1;
2728 s->status |= s->running << 1;
2731 case 0x44: /* RTC_STATUS_REG */
2733 printf("RTC STATUSL <-- %02x\n", value);
2735 s->status &= ~((value & 0xc0) ^ 0x80);
2736 omap_rtc_interrupts_update(s);
2739 case 0x48: /* RTC_INTERRUPTS_REG */
2741 printf("RTC INTRS <-- %02x\n", value);
2743 s->interrupts = value;
2746 case 0x4c: /* RTC_COMP_LSB_REG */
2748 printf("RTC COMPLSB <-- %02x\n", value);
2750 s->comp_reg &= 0xff00;
2751 s->comp_reg |= 0x00ff & value;
2754 case 0x50: /* RTC_COMP_MSB_REG */
2756 printf("RTC COMPMSB <-- %02x\n", value);
2758 s->comp_reg &= 0x00ff;
2759 s->comp_reg |= 0xff00 & (value << 8);
2768 static CPUReadMemoryFunc * const omap_rtc_readfn[] = {
2770 omap_badwidth_read8,
2771 omap_badwidth_read8,
2774 static CPUWriteMemoryFunc * const omap_rtc_writefn[] = {
2776 omap_badwidth_write8,
2777 omap_badwidth_write8,
2780 static void omap_rtc_tick(void *opaque)
2782 struct omap_rtc_s *s = opaque;
2785 /* Round to nearest full minute. */
2786 if (s->current_tm.tm_sec < 30)
2787 s->ti -= s->current_tm.tm_sec;
2789 s->ti += 60 - s->current_tm.tm_sec;
2794 memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm));
2796 if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) {
2798 omap_rtc_interrupts_update(s);
2801 if (s->interrupts & 0x04)
2802 switch (s->interrupts & 3) {
2805 qemu_irq_pulse(s->irq);
2808 if (s->current_tm.tm_sec)
2811 qemu_irq_pulse(s->irq);
2814 if (s->current_tm.tm_sec || s->current_tm.tm_min)
2817 qemu_irq_pulse(s->irq);
2820 if (s->current_tm.tm_sec ||
2821 s->current_tm.tm_min || s->current_tm.tm_hour)
2824 qemu_irq_pulse(s->irq);
2834 * Every full hour add a rough approximation of the compensation
2835 * register to the 32kHz Timer (which drives the RTC) value.
2837 if (s->auto_comp && !s->current_tm.tm_sec && !s->current_tm.tm_min)
2838 s->tick += s->comp_reg * 1000 / 32768;
2840 qemu_mod_timer(s->clk, s->tick);
2843 static void omap_rtc_reset(struct omap_rtc_s *s)
2853 s->tick = qemu_get_clock_ms(rt_clock);
2854 memset(&s->alarm_tm, 0, sizeof(s->alarm_tm));
2855 s->alarm_tm.tm_mday = 0x01;
2857 qemu_get_timedate(&tm, 0);
2858 s->ti = mktimegm(&tm);
2860 omap_rtc_alarm_update(s);
2864 static struct omap_rtc_s *omap_rtc_init(target_phys_addr_t base,
2865 qemu_irq *irq, omap_clk clk)
2868 struct omap_rtc_s *s = (struct omap_rtc_s *)
2869 g_malloc0(sizeof(struct omap_rtc_s));
2873 s->clk = qemu_new_timer_ms(rt_clock, omap_rtc_tick, s);
2877 iomemtype = cpu_register_io_memory(omap_rtc_readfn,
2878 omap_rtc_writefn, s, DEVICE_NATIVE_ENDIAN);
2879 cpu_register_physical_memory(base, 0x800, iomemtype);
2884 /* Multi-channel Buffered Serial Port interfaces */
2885 struct omap_mcbsp_s {
2905 QEMUTimer *source_timer;
2906 QEMUTimer *sink_timer;
2909 static void omap_mcbsp_intr_update(struct omap_mcbsp_s *s)
2913 switch ((s->spcr[0] >> 4) & 3) { /* RINTM */
2915 irq = (s->spcr[0] >> 1) & 1; /* RRDY */
2918 irq = (s->spcr[0] >> 3) & 1; /* RSYNCERR */
2926 qemu_irq_pulse(s->rxirq);
2928 switch ((s->spcr[1] >> 4) & 3) { /* XINTM */
2930 irq = (s->spcr[1] >> 1) & 1; /* XRDY */
2933 irq = (s->spcr[1] >> 3) & 1; /* XSYNCERR */
2941 qemu_irq_pulse(s->txirq);
2944 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s *s)
2946 if ((s->spcr[0] >> 1) & 1) /* RRDY */
2947 s->spcr[0] |= 1 << 2; /* RFULL */
2948 s->spcr[0] |= 1 << 1; /* RRDY */
2949 qemu_irq_raise(s->rxdrq);
2950 omap_mcbsp_intr_update(s);
2953 static void omap_mcbsp_source_tick(void *opaque)
2955 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
2956 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
2961 printf("%s: Rx FIFO overrun\n", __FUNCTION__);
2963 s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7];
2965 omap_mcbsp_rx_newdata(s);
2966 qemu_mod_timer(s->source_timer, qemu_get_clock_ns(vm_clock) +
2967 get_ticks_per_sec());
2970 static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s)
2972 if (!s->codec || !s->codec->rts)
2973 omap_mcbsp_source_tick(s);
2974 else if (s->codec->in.len) {
2975 s->rx_req = s->codec->in.len;
2976 omap_mcbsp_rx_newdata(s);
2980 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s *s)
2982 qemu_del_timer(s->source_timer);
2985 static void omap_mcbsp_rx_done(struct omap_mcbsp_s *s)
2987 s->spcr[0] &= ~(1 << 1); /* RRDY */
2988 qemu_irq_lower(s->rxdrq);
2989 omap_mcbsp_intr_update(s);
2992 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s *s)
2994 s->spcr[1] |= 1 << 1; /* XRDY */
2995 qemu_irq_raise(s->txdrq);
2996 omap_mcbsp_intr_update(s);
2999 static void omap_mcbsp_sink_tick(void *opaque)
3001 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3002 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3007 printf("%s: Tx FIFO underrun\n", __FUNCTION__);
3009 s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7];
3011 omap_mcbsp_tx_newdata(s);
3012 qemu_mod_timer(s->sink_timer, qemu_get_clock_ns(vm_clock) +
3013 get_ticks_per_sec());
3016 static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s)
3018 if (!s->codec || !s->codec->cts)
3019 omap_mcbsp_sink_tick(s);
3020 else if (s->codec->out.size) {
3021 s->tx_req = s->codec->out.size;
3022 omap_mcbsp_tx_newdata(s);
3026 static void omap_mcbsp_tx_done(struct omap_mcbsp_s *s)
3028 s->spcr[1] &= ~(1 << 1); /* XRDY */
3029 qemu_irq_lower(s->txdrq);
3030 omap_mcbsp_intr_update(s);
3031 if (s->codec && s->codec->cts)
3032 s->codec->tx_swallow(s->codec->opaque);
3035 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s *s)
3038 omap_mcbsp_tx_done(s);
3039 qemu_del_timer(s->sink_timer);
3042 static void omap_mcbsp_req_update(struct omap_mcbsp_s *s)
3044 int prev_rx_rate, prev_tx_rate;
3045 int rx_rate = 0, tx_rate = 0;
3046 int cpu_rate = 1500000; /* XXX */
3048 /* TODO: check CLKSTP bit */
3049 if (s->spcr[1] & (1 << 6)) { /* GRST */
3050 if (s->spcr[0] & (1 << 0)) { /* RRST */
3051 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3052 (s->pcr & (1 << 8))) { /* CLKRM */
3053 if (~s->pcr & (1 << 7)) /* SCLKME */
3054 rx_rate = cpu_rate /
3055 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3058 rx_rate = s->codec->rx_rate;
3061 if (s->spcr[1] & (1 << 0)) { /* XRST */
3062 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3063 (s->pcr & (1 << 9))) { /* CLKXM */
3064 if (~s->pcr & (1 << 7)) /* SCLKME */
3065 tx_rate = cpu_rate /
3066 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3069 tx_rate = s->codec->tx_rate;
3072 prev_tx_rate = s->tx_rate;
3073 prev_rx_rate = s->rx_rate;
3074 s->tx_rate = tx_rate;
3075 s->rx_rate = rx_rate;
3078 s->codec->set_rate(s->codec->opaque, rx_rate, tx_rate);
3080 if (!prev_tx_rate && tx_rate)
3081 omap_mcbsp_tx_start(s);
3082 else if (s->tx_rate && !tx_rate)
3083 omap_mcbsp_tx_stop(s);
3085 if (!prev_rx_rate && rx_rate)
3086 omap_mcbsp_rx_start(s);
3087 else if (prev_tx_rate && !tx_rate)
3088 omap_mcbsp_rx_stop(s);
3091 static uint32_t omap_mcbsp_read(void *opaque, target_phys_addr_t addr)
3093 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3094 int offset = addr & OMAP_MPUI_REG_MASK;
3098 case 0x00: /* DRR2 */
3099 if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */
3102 case 0x02: /* DRR1 */
3103 if (s->rx_req < 2) {
3104 printf("%s: Rx FIFO underrun\n", __FUNCTION__);
3105 omap_mcbsp_rx_done(s);
3108 if (s->codec && s->codec->in.len >= 2) {
3109 ret = s->codec->in.fifo[s->codec->in.start ++] << 8;
3110 ret |= s->codec->in.fifo[s->codec->in.start ++];
3111 s->codec->in.len -= 2;
3115 omap_mcbsp_rx_done(s);
3120 case 0x04: /* DXR2 */
3121 case 0x06: /* DXR1 */
3124 case 0x08: /* SPCR2 */
3126 case 0x0a: /* SPCR1 */
3128 case 0x0c: /* RCR2 */
3130 case 0x0e: /* RCR1 */
3132 case 0x10: /* XCR2 */
3134 case 0x12: /* XCR1 */
3136 case 0x14: /* SRGR2 */
3138 case 0x16: /* SRGR1 */
3140 case 0x18: /* MCR2 */
3142 case 0x1a: /* MCR1 */
3144 case 0x1c: /* RCERA */
3146 case 0x1e: /* RCERB */
3148 case 0x20: /* XCERA */
3150 case 0x22: /* XCERB */
3152 case 0x24: /* PCR0 */
3154 case 0x26: /* RCERC */
3156 case 0x28: /* RCERD */
3158 case 0x2a: /* XCERC */
3160 case 0x2c: /* XCERD */
3162 case 0x2e: /* RCERE */
3164 case 0x30: /* RCERF */
3166 case 0x32: /* XCERE */
3168 case 0x34: /* XCERF */
3170 case 0x36: /* RCERG */
3172 case 0x38: /* RCERH */
3174 case 0x3a: /* XCERG */
3176 case 0x3c: /* XCERH */
3184 static void omap_mcbsp_writeh(void *opaque, target_phys_addr_t addr,
3187 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3188 int offset = addr & OMAP_MPUI_REG_MASK;
3191 case 0x00: /* DRR2 */
3192 case 0x02: /* DRR1 */
3196 case 0x04: /* DXR2 */
3197 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
3200 case 0x06: /* DXR1 */
3201 if (s->tx_req > 1) {
3203 if (s->codec && s->codec->cts) {
3204 s->codec->out.fifo[s->codec->out.len ++] = (value >> 8) & 0xff;
3205 s->codec->out.fifo[s->codec->out.len ++] = (value >> 0) & 0xff;
3208 omap_mcbsp_tx_done(s);
3210 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
3213 case 0x08: /* SPCR2 */
3214 s->spcr[1] &= 0x0002;
3215 s->spcr[1] |= 0x03f9 & value;
3216 s->spcr[1] |= 0x0004 & (value << 2); /* XEMPTY := XRST */
3217 if (~value & 1) /* XRST */
3219 omap_mcbsp_req_update(s);
3221 case 0x0a: /* SPCR1 */
3222 s->spcr[0] &= 0x0006;
3223 s->spcr[0] |= 0xf8f9 & value;
3224 if (value & (1 << 15)) /* DLB */
3225 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__);
3226 if (~value & 1) { /* RRST */
3229 omap_mcbsp_rx_done(s);
3231 omap_mcbsp_req_update(s);
3234 case 0x0c: /* RCR2 */
3235 s->rcr[1] = value & 0xffff;
3237 case 0x0e: /* RCR1 */
3238 s->rcr[0] = value & 0x7fe0;
3240 case 0x10: /* XCR2 */
3241 s->xcr[1] = value & 0xffff;
3243 case 0x12: /* XCR1 */
3244 s->xcr[0] = value & 0x7fe0;
3246 case 0x14: /* SRGR2 */
3247 s->srgr[1] = value & 0xffff;
3248 omap_mcbsp_req_update(s);
3250 case 0x16: /* SRGR1 */
3251 s->srgr[0] = value & 0xffff;
3252 omap_mcbsp_req_update(s);
3254 case 0x18: /* MCR2 */
3255 s->mcr[1] = value & 0x03e3;
3256 if (value & 3) /* XMCM */
3257 printf("%s: Tx channel selection mode enable attempt\n",
3260 case 0x1a: /* MCR1 */
3261 s->mcr[0] = value & 0x03e1;
3262 if (value & 1) /* RMCM */
3263 printf("%s: Rx channel selection mode enable attempt\n",
3266 case 0x1c: /* RCERA */
3267 s->rcer[0] = value & 0xffff;
3269 case 0x1e: /* RCERB */
3270 s->rcer[1] = value & 0xffff;
3272 case 0x20: /* XCERA */
3273 s->xcer[0] = value & 0xffff;
3275 case 0x22: /* XCERB */
3276 s->xcer[1] = value & 0xffff;
3278 case 0x24: /* PCR0 */
3279 s->pcr = value & 0x7faf;
3281 case 0x26: /* RCERC */
3282 s->rcer[2] = value & 0xffff;
3284 case 0x28: /* RCERD */
3285 s->rcer[3] = value & 0xffff;
3287 case 0x2a: /* XCERC */
3288 s->xcer[2] = value & 0xffff;
3290 case 0x2c: /* XCERD */
3291 s->xcer[3] = value & 0xffff;
3293 case 0x2e: /* RCERE */
3294 s->rcer[4] = value & 0xffff;
3296 case 0x30: /* RCERF */
3297 s->rcer[5] = value & 0xffff;
3299 case 0x32: /* XCERE */
3300 s->xcer[4] = value & 0xffff;
3302 case 0x34: /* XCERF */
3303 s->xcer[5] = value & 0xffff;
3305 case 0x36: /* RCERG */
3306 s->rcer[6] = value & 0xffff;
3308 case 0x38: /* RCERH */
3309 s->rcer[7] = value & 0xffff;
3311 case 0x3a: /* XCERG */
3312 s->xcer[6] = value & 0xffff;
3314 case 0x3c: /* XCERH */
3315 s->xcer[7] = value & 0xffff;
3322 static void omap_mcbsp_writew(void *opaque, target_phys_addr_t addr,
3325 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3326 int offset = addr & OMAP_MPUI_REG_MASK;
3328 if (offset == 0x04) { /* DXR */
3329 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
3331 if (s->tx_req > 3) {
3333 if (s->codec && s->codec->cts) {
3334 s->codec->out.fifo[s->codec->out.len ++] =
3335 (value >> 24) & 0xff;
3336 s->codec->out.fifo[s->codec->out.len ++] =
3337 (value >> 16) & 0xff;
3338 s->codec->out.fifo[s->codec->out.len ++] =
3339 (value >> 8) & 0xff;
3340 s->codec->out.fifo[s->codec->out.len ++] =
3341 (value >> 0) & 0xff;
3344 omap_mcbsp_tx_done(s);
3346 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
3350 omap_badwidth_write16(opaque, addr, value);
3353 static CPUReadMemoryFunc * const omap_mcbsp_readfn[] = {
3354 omap_badwidth_read16,
3356 omap_badwidth_read16,
3359 static CPUWriteMemoryFunc * const omap_mcbsp_writefn[] = {
3360 omap_badwidth_write16,
3365 static void omap_mcbsp_reset(struct omap_mcbsp_s *s)
3367 memset(&s->spcr, 0, sizeof(s->spcr));
3368 memset(&s->rcr, 0, sizeof(s->rcr));
3369 memset(&s->xcr, 0, sizeof(s->xcr));
3370 s->srgr[0] = 0x0001;
3371 s->srgr[1] = 0x2000;
3372 memset(&s->mcr, 0, sizeof(s->mcr));
3373 memset(&s->pcr, 0, sizeof(s->pcr));
3374 memset(&s->rcer, 0, sizeof(s->rcer));
3375 memset(&s->xcer, 0, sizeof(s->xcer));
3380 qemu_del_timer(s->source_timer);
3381 qemu_del_timer(s->sink_timer);
3384 struct omap_mcbsp_s *omap_mcbsp_init(target_phys_addr_t base,
3385 qemu_irq *irq, qemu_irq *dma, omap_clk clk)
3388 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *)
3389 g_malloc0(sizeof(struct omap_mcbsp_s));
3395 s->sink_timer = qemu_new_timer_ns(vm_clock, omap_mcbsp_sink_tick, s);
3396 s->source_timer = qemu_new_timer_ns(vm_clock, omap_mcbsp_source_tick, s);
3397 omap_mcbsp_reset(s);
3399 iomemtype = cpu_register_io_memory(omap_mcbsp_readfn,
3400 omap_mcbsp_writefn, s, DEVICE_NATIVE_ENDIAN);
3401 cpu_register_physical_memory(base, 0x800, iomemtype);
3406 static void omap_mcbsp_i2s_swallow(void *opaque, int line, int level)
3408 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3411 s->rx_req = s->codec->in.len;
3412 omap_mcbsp_rx_newdata(s);
3416 static void omap_mcbsp_i2s_start(void *opaque, int line, int level)
3418 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3421 s->tx_req = s->codec->out.size;
3422 omap_mcbsp_tx_newdata(s);
3426 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, I2SCodec *slave)
3429 slave->rx_swallow = qemu_allocate_irqs(omap_mcbsp_i2s_swallow, s, 1)[0];
3430 slave->tx_start = qemu_allocate_irqs(omap_mcbsp_i2s_start, s, 1)[0];
3433 /* LED Pulse Generators */
3445 static void omap_lpg_tick(void *opaque)
3447 struct omap_lpg_s *s = opaque;
3450 qemu_mod_timer(s->tm, qemu_get_clock_ms(rt_clock) + s->period - s->on);
3452 qemu_mod_timer(s->tm, qemu_get_clock_ms(rt_clock) + s->on);
3454 s->cycle = !s->cycle;
3455 printf("%s: LED is %s\n", __FUNCTION__, s->cycle ? "on" : "off");
3458 static void omap_lpg_update(struct omap_lpg_s *s)
3460 int64_t on, period = 1, ticks = 1000;
3461 static const int per[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3463 if (~s->control & (1 << 6)) /* LPGRES */
3465 else if (s->control & (1 << 7)) /* PERM_ON */
3468 period = muldiv64(ticks, per[s->control & 7], /* PERCTRL */
3470 on = (s->clk && s->power) ? muldiv64(ticks,
3471 per[(s->control >> 3) & 7], 256) : 0; /* ONCTRL */
3474 qemu_del_timer(s->tm);
3475 if (on == period && s->on < s->period)
3476 printf("%s: LED is on\n", __FUNCTION__);
3477 else if (on == 0 && s->on)
3478 printf("%s: LED is off\n", __FUNCTION__);
3479 else if (on && (on != s->on || period != s->period)) {
3491 static void omap_lpg_reset(struct omap_lpg_s *s)
3499 static uint32_t omap_lpg_read(void *opaque, target_phys_addr_t addr)
3501 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3502 int offset = addr & OMAP_MPUI_REG_MASK;
3505 case 0x00: /* LCR */
3508 case 0x04: /* PMR */
3516 static void omap_lpg_write(void *opaque, target_phys_addr_t addr,
3519 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3520 int offset = addr & OMAP_MPUI_REG_MASK;
3523 case 0x00: /* LCR */
3524 if (~value & (1 << 6)) /* LPGRES */
3526 s->control = value & 0xff;
3530 case 0x04: /* PMR */
3531 s->power = value & 0x01;
3541 static CPUReadMemoryFunc * const omap_lpg_readfn[] = {
3543 omap_badwidth_read8,
3544 omap_badwidth_read8,
3547 static CPUWriteMemoryFunc * const omap_lpg_writefn[] = {
3549 omap_badwidth_write8,
3550 omap_badwidth_write8,
3553 static void omap_lpg_clk_update(void *opaque, int line, int on)
3555 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3561 static struct omap_lpg_s *omap_lpg_init(target_phys_addr_t base, omap_clk clk)
3564 struct omap_lpg_s *s = (struct omap_lpg_s *)
3565 g_malloc0(sizeof(struct omap_lpg_s));
3567 s->tm = qemu_new_timer_ms(rt_clock, omap_lpg_tick, s);
3571 iomemtype = cpu_register_io_memory(omap_lpg_readfn,
3572 omap_lpg_writefn, s, DEVICE_NATIVE_ENDIAN);
3573 cpu_register_physical_memory(base, 0x800, iomemtype);
3575 omap_clk_adduser(clk, qemu_allocate_irqs(omap_lpg_clk_update, s, 1)[0]);
3580 /* MPUI Peripheral Bridge configuration */
3581 static uint32_t omap_mpui_io_read(void *opaque, target_phys_addr_t addr)
3583 if (addr == OMAP_MPUI_BASE) /* CMR */
3590 static CPUReadMemoryFunc * const omap_mpui_io_readfn[] = {
3591 omap_badwidth_read16,
3593 omap_badwidth_read16,
3596 static CPUWriteMemoryFunc * const omap_mpui_io_writefn[] = {
3597 omap_badwidth_write16,
3598 omap_badwidth_write16,
3599 omap_badwidth_write16,
3602 static void omap_setup_mpui_io(struct omap_mpu_state_s *mpu)
3604 int iomemtype = cpu_register_io_memory(omap_mpui_io_readfn,
3605 omap_mpui_io_writefn, mpu, DEVICE_NATIVE_ENDIAN);
3606 cpu_register_physical_memory(OMAP_MPUI_BASE, 0x7fff, iomemtype);
3609 /* General chip reset */
3610 static void omap1_mpu_reset(void *opaque)
3612 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
3614 omap_inth_reset(mpu->ih[0]);
3615 omap_inth_reset(mpu->ih[1]);
3616 omap_dma_reset(mpu->dma);
3617 omap_mpu_timer_reset(mpu->timer[0]);
3618 omap_mpu_timer_reset(mpu->timer[1]);
3619 omap_mpu_timer_reset(mpu->timer[2]);
3620 omap_wd_timer_reset(mpu->wdt);
3621 omap_os_timer_reset(mpu->os_timer);
3622 omap_lcdc_reset(mpu->lcd);
3623 omap_ulpd_pm_reset(mpu);
3624 omap_pin_cfg_reset(mpu);
3625 omap_mpui_reset(mpu);
3626 omap_tipb_bridge_reset(mpu->private_tipb);
3627 omap_tipb_bridge_reset(mpu->public_tipb);
3628 omap_dpll_reset(&mpu->dpll[0]);
3629 omap_dpll_reset(&mpu->dpll[1]);
3630 omap_dpll_reset(&mpu->dpll[2]);
3631 omap_uart_reset(mpu->uart[0]);
3632 omap_uart_reset(mpu->uart[1]);
3633 omap_uart_reset(mpu->uart[2]);
3634 omap_mmc_reset(mpu->mmc);
3635 omap_mpuio_reset(mpu->mpuio);
3636 omap_uwire_reset(mpu->microwire);
3637 omap_pwl_reset(mpu);
3638 omap_pwt_reset(mpu);
3639 omap_i2c_reset(mpu->i2c[0]);
3640 omap_rtc_reset(mpu->rtc);
3641 omap_mcbsp_reset(mpu->mcbsp1);
3642 omap_mcbsp_reset(mpu->mcbsp2);
3643 omap_mcbsp_reset(mpu->mcbsp3);
3644 omap_lpg_reset(mpu->led[0]);
3645 omap_lpg_reset(mpu->led[1]);
3646 omap_clkm_reset(mpu);
3647 cpu_reset(mpu->env);
3650 static const struct omap_map_s {
3651 target_phys_addr_t phys_dsp;
3652 target_phys_addr_t phys_mpu;
3655 } omap15xx_dsp_mm[] = {
3657 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
3658 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
3659 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
3660 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
3661 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
3662 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
3663 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
3664 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
3665 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
3666 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
3667 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
3668 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
3669 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
3670 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
3671 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
3672 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
3673 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
3675 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
3680 static void omap_setup_dsp_mapping(const struct omap_map_s *map)
3684 for (; map->phys_dsp; map ++) {
3685 io = cpu_get_physical_page_desc(map->phys_mpu);
3687 cpu_register_physical_memory(map->phys_dsp, map->size, io);
3691 void omap_mpu_wakeup(void *opaque, int irq, int req)
3693 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
3695 if (mpu->env->halted)
3696 cpu_interrupt(mpu->env, CPU_INTERRUPT_EXITTB);
3699 static const struct dma_irq_map omap1_dma_irq_map[] = {
3700 { 0, OMAP_INT_DMA_CH0_6 },
3701 { 0, OMAP_INT_DMA_CH1_7 },
3702 { 0, OMAP_INT_DMA_CH2_8 },
3703 { 0, OMAP_INT_DMA_CH3 },
3704 { 0, OMAP_INT_DMA_CH4 },
3705 { 0, OMAP_INT_DMA_CH5 },
3706 { 1, OMAP_INT_1610_DMA_CH6 },
3707 { 1, OMAP_INT_1610_DMA_CH7 },
3708 { 1, OMAP_INT_1610_DMA_CH8 },
3709 { 1, OMAP_INT_1610_DMA_CH9 },
3710 { 1, OMAP_INT_1610_DMA_CH10 },
3711 { 1, OMAP_INT_1610_DMA_CH11 },
3712 { 1, OMAP_INT_1610_DMA_CH12 },
3713 { 1, OMAP_INT_1610_DMA_CH13 },
3714 { 1, OMAP_INT_1610_DMA_CH14 },
3715 { 1, OMAP_INT_1610_DMA_CH15 }
3718 /* DMA ports for OMAP1 */
3719 static int omap_validate_emiff_addr(struct omap_mpu_state_s *s,
3720 target_phys_addr_t addr)
3722 return range_covers_byte(OMAP_EMIFF_BASE, s->sdram_size, addr);
3725 static int omap_validate_emifs_addr(struct omap_mpu_state_s *s,
3726 target_phys_addr_t addr)
3728 return range_covers_byte(OMAP_EMIFS_BASE, OMAP_EMIFF_BASE - OMAP_EMIFS_BASE,
3732 static int omap_validate_imif_addr(struct omap_mpu_state_s *s,
3733 target_phys_addr_t addr)
3735 return range_covers_byte(OMAP_IMIF_BASE, s->sram_size, addr);
3738 static int omap_validate_tipb_addr(struct omap_mpu_state_s *s,
3739 target_phys_addr_t addr)
3741 return range_covers_byte(0xfffb0000, 0xffff0000 - 0xfffb0000, addr);
3744 static int omap_validate_local_addr(struct omap_mpu_state_s *s,
3745 target_phys_addr_t addr)
3747 return range_covers_byte(OMAP_LOCALBUS_BASE, 0x1000000, addr);
3750 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s *s,
3751 target_phys_addr_t addr)
3753 return range_covers_byte(0xe1010000, 0xe1020004 - 0xe1010000, addr);
3756 struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
3757 unsigned long sdram_size,
3761 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
3762 g_malloc0(sizeof(struct omap_mpu_state_s));
3763 ram_addr_t imif_base, emiff_base;
3765 qemu_irq dma_irqs[6];
3772 s->mpu_model = omap310;
3773 s->env = cpu_init(core);
3775 fprintf(stderr, "Unable to find CPU definition\n");
3778 s->sdram_size = sdram_size;
3779 s->sram_size = OMAP15XX_SRAM_SIZE;
3781 s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0];
3786 /* Memory-mapped stuff */
3787 cpu_register_physical_memory(OMAP_EMIFF_BASE, s->sdram_size,
3788 (emiff_base = qemu_ram_alloc(NULL, "omap1.dram",
3789 s->sdram_size)) | IO_MEM_RAM);
3790 cpu_register_physical_memory(OMAP_IMIF_BASE, s->sram_size,
3791 (imif_base = qemu_ram_alloc(NULL, "omap1.sram",
3792 s->sram_size)) | IO_MEM_RAM);
3794 omap_clkm_init(system_memory, 0xfffece00, 0xe1008000, s);
3796 cpu_irq = arm_pic_init_cpu(s->env);
3797 s->ih[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s->irq[0],
3798 cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ],
3799 omap_findclk(s, "arminth_ck"));
3800 s->ih[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s->irq[1],
3801 omap_inth_get_pin(s->ih[0], OMAP_INT_15XX_IH2_IRQ),
3802 NULL, omap_findclk(s, "arminth_ck"));
3804 for (i = 0; i < 6; i ++)
3806 s->irq[omap1_dma_irq_map[i].ih][omap1_dma_irq_map[i].intr];
3807 s->dma = omap_dma_init(0xfffed800, dma_irqs, s->irq[0][OMAP_INT_DMA_LCD],
3808 s, omap_findclk(s, "dma_ck"), omap_dma_3_1);
3810 s->port[emiff ].addr_valid = omap_validate_emiff_addr;
3811 s->port[emifs ].addr_valid = omap_validate_emifs_addr;
3812 s->port[imif ].addr_valid = omap_validate_imif_addr;
3813 s->port[tipb ].addr_valid = omap_validate_tipb_addr;
3814 s->port[local ].addr_valid = omap_validate_local_addr;
3815 s->port[tipb_mpui].addr_valid = omap_validate_tipb_mpui_addr;
3817 /* Register SDRAM and SRAM DMA ports for fast transfers. */
3818 soc_dma_port_add_mem_ram(s->dma,
3819 emiff_base, OMAP_EMIFF_BASE, s->sdram_size);
3820 soc_dma_port_add_mem_ram(s->dma,
3821 imif_base, OMAP_IMIF_BASE, s->sram_size);
3823 s->timer[0] = omap_mpu_timer_init(system_memory, 0xfffec500,
3824 s->irq[0][OMAP_INT_TIMER1],
3825 omap_findclk(s, "mputim_ck"));
3826 s->timer[1] = omap_mpu_timer_init(system_memory, 0xfffec600,
3827 s->irq[0][OMAP_INT_TIMER2],
3828 omap_findclk(s, "mputim_ck"));
3829 s->timer[2] = omap_mpu_timer_init(system_memory, 0xfffec700,
3830 s->irq[0][OMAP_INT_TIMER3],
3831 omap_findclk(s, "mputim_ck"));
3833 s->wdt = omap_wd_timer_init(system_memory, 0xfffec800,
3834 s->irq[0][OMAP_INT_WD_TIMER],
3835 omap_findclk(s, "armwdt_ck"));
3837 s->os_timer = omap_os_timer_init(system_memory, 0xfffb9000,
3838 s->irq[1][OMAP_INT_OS_TIMER],
3839 omap_findclk(s, "clk32-kHz"));
3841 s->lcd = omap_lcdc_init(0xfffec000, s->irq[0][OMAP_INT_LCD_CTRL],
3842 omap_dma_get_lcdch(s->dma), imif_base, emiff_base,
3843 omap_findclk(s, "lcd_ck"));
3845 omap_ulpd_pm_init(system_memory, 0xfffe0800, s);
3846 omap_pin_cfg_init(system_memory, 0xfffe1000, s);
3847 omap_id_init(system_memory, s);
3849 omap_mpui_init(system_memory, 0xfffec900, s);
3851 s->private_tipb = omap_tipb_bridge_init(system_memory, 0xfffeca00,
3852 s->irq[0][OMAP_INT_BRIDGE_PRIV],
3853 omap_findclk(s, "tipb_ck"));
3854 s->public_tipb = omap_tipb_bridge_init(system_memory, 0xfffed300,
3855 s->irq[0][OMAP_INT_BRIDGE_PUB],
3856 omap_findclk(s, "tipb_ck"));
3858 omap_tcmi_init(system_memory, 0xfffecc00, s);
3860 s->uart[0] = omap_uart_init(0xfffb0000, s->irq[1][OMAP_INT_UART1],
3861 omap_findclk(s, "uart1_ck"),
3862 omap_findclk(s, "uart1_ck"),
3863 s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
3866 s->uart[1] = omap_uart_init(0xfffb0800, s->irq[1][OMAP_INT_UART2],
3867 omap_findclk(s, "uart2_ck"),
3868 omap_findclk(s, "uart2_ck"),
3869 s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
3871 serial_hds[0] ? serial_hds[1] : NULL);
3872 s->uart[2] = omap_uart_init(0xfffb9800, s->irq[0][OMAP_INT_UART3],
3873 omap_findclk(s, "uart3_ck"),
3874 omap_findclk(s, "uart3_ck"),
3875 s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX],
3877 serial_hds[0] && serial_hds[1] ? serial_hds[2] : NULL);
3879 omap_dpll_init(system_memory,
3880 &s->dpll[0], 0xfffecf00, omap_findclk(s, "dpll1"));
3881 omap_dpll_init(system_memory,
3882 &s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2"));
3883 omap_dpll_init(system_memory,
3884 &s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3"));
3886 dinfo = drive_get(IF_SD, 0, 0);
3888 fprintf(stderr, "qemu: missing SecureDigital device\n");
3891 s->mmc = omap_mmc_init(0xfffb7800, dinfo->bdrv,
3892 s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX],
3893 omap_findclk(s, "mmc_ck"));
3895 s->mpuio = omap_mpuio_init(system_memory, 0xfffb5000,
3896 s->irq[1][OMAP_INT_KEYBOARD], s->irq[1][OMAP_INT_MPUIO],
3897 s->wakeup, omap_findclk(s, "clk32-kHz"));
3899 s->gpio = qdev_create(NULL, "omap-gpio");
3900 qdev_prop_set_int32(s->gpio, "mpu_model", s->mpu_model);
3901 qdev_init_nofail(s->gpio);
3902 sysbus_connect_irq(sysbus_from_qdev(s->gpio), 0,
3903 s->irq[0][OMAP_INT_GPIO_BANK1]);
3904 sysbus_mmio_map(sysbus_from_qdev(s->gpio), 0, 0xfffce000);
3906 s->microwire = omap_uwire_init(0xfffb3000, &s->irq[1][OMAP_INT_uWireTX],
3907 s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
3909 omap_pwl_init(0xfffb5800, s, omap_findclk(s, "armxor_ck"));
3910 omap_pwt_init(0xfffb6000, s, omap_findclk(s, "armxor_ck"));
3912 s->i2c[0] = omap_i2c_init(0xfffb3800, s->irq[1][OMAP_INT_I2C],
3913 &s->drq[OMAP_DMA_I2C_RX], omap_findclk(s, "mpuper_ck"));
3915 s->rtc = omap_rtc_init(0xfffb4800, &s->irq[1][OMAP_INT_RTC_TIMER],
3916 omap_findclk(s, "clk32-kHz"));
3918 s->mcbsp1 = omap_mcbsp_init(0xfffb1800, &s->irq[1][OMAP_INT_McBSP1TX],
3919 &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
3920 s->mcbsp2 = omap_mcbsp_init(0xfffb1000, &s->irq[0][OMAP_INT_310_McBSP2_TX],
3921 &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
3922 s->mcbsp3 = omap_mcbsp_init(0xfffb7000, &s->irq[1][OMAP_INT_McBSP3TX],
3923 &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
3925 s->led[0] = omap_lpg_init(0xfffbd000, omap_findclk(s, "clk32-kHz"));
3926 s->led[1] = omap_lpg_init(0xfffbd800, omap_findclk(s, "clk32-kHz"));
3928 /* Register mappings not currenlty implemented:
3929 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
3930 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
3931 * USB W2FC fffb4000 - fffb47ff
3932 * Camera Interface fffb6800 - fffb6fff
3933 * USB Host fffba000 - fffba7ff
3934 * FAC fffba800 - fffbafff
3935 * HDQ/1-Wire fffbc000 - fffbc7ff
3936 * TIPB switches fffbc800 - fffbcfff
3937 * Mailbox fffcf000 - fffcf7ff
3938 * Local bus IF fffec100 - fffec1ff
3939 * Local bus MMU fffec200 - fffec2ff
3940 * DSP MMU fffed200 - fffed2ff
3943 omap_setup_dsp_mapping(omap15xx_dsp_mm);
3944 omap_setup_mpui_io(s);
3946 qemu_register_reset(omap1_mpu_reset, s);