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/>.
20 #include "qemu/osdep.h"
21 #include "qemu/error-report.h"
22 #include "qemu/main-loop.h"
23 #include "qapi/error.h"
24 #include "qemu-common.h"
26 #include "hw/boards.h"
29 #include "hw/arm/boot.h"
30 #include "hw/arm/omap.h"
31 #include "sysemu/sysemu.h"
32 #include "hw/arm/soc_dma.h"
33 #include "sysemu/qtest.h"
34 #include "sysemu/reset.h"
35 #include "qemu/range.h"
36 #include "hw/sysbus.h"
37 #include "qemu/cutils.h"
40 static inline void omap_log_badwidth(const char *funcname, hwaddr addr, int sz)
42 qemu_log_mask(LOG_GUEST_ERROR, "%s: %d-bit register %#08" HWADDR_PRIx "\n",
43 funcname, 8 * sz, addr);
46 /* Should signal the TCMI/GPMC */
47 uint32_t omap_badwidth_read8(void *opaque, hwaddr addr)
51 omap_log_badwidth(__func__, addr, 1);
52 cpu_physical_memory_read(addr, &ret, 1);
56 void omap_badwidth_write8(void *opaque, hwaddr addr,
61 omap_log_badwidth(__func__, addr, 1);
62 cpu_physical_memory_write(addr, &val8, 1);
65 uint32_t omap_badwidth_read16(void *opaque, hwaddr addr)
69 omap_log_badwidth(__func__, addr, 2);
70 cpu_physical_memory_read(addr, &ret, 2);
74 void omap_badwidth_write16(void *opaque, hwaddr addr,
77 uint16_t val16 = value;
79 omap_log_badwidth(__func__, addr, 2);
80 cpu_physical_memory_write(addr, &val16, 2);
83 uint32_t omap_badwidth_read32(void *opaque, hwaddr addr)
87 omap_log_badwidth(__func__, addr, 4);
88 cpu_physical_memory_read(addr, &ret, 4);
92 void omap_badwidth_write32(void *opaque, hwaddr addr,
95 omap_log_badwidth(__func__, addr, 4);
96 cpu_physical_memory_write(addr, &value, 4);
100 struct omap_mpu_timer_s {
118 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer)
120 uint64_t distance = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - timer->time;
122 if (timer->st && timer->enable && timer->rate)
123 return timer->val - muldiv64(distance >> (timer->ptv + 1),
124 timer->rate, NANOSECONDS_PER_SECOND);
129 static inline void omap_timer_sync(struct omap_mpu_timer_s *timer)
131 timer->val = omap_timer_read(timer);
132 timer->time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
135 static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
139 if (timer->enable && timer->st && timer->rate) {
140 timer->val = timer->reset_val; /* Should skip this on clk enable */
141 expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
142 NANOSECONDS_PER_SECOND, timer->rate);
144 /* If timer expiry would be sooner than in about 1 ms and
145 * auto-reload isn't set, then fire immediately. This is a hack
146 * to make systems like PalmOS run in acceptable time. PalmOS
147 * sets the interval to a very low value and polls the status bit
148 * in a busy loop when it wants to sleep just a couple of CPU
150 if (expires > (NANOSECONDS_PER_SECOND >> 10) || timer->ar) {
151 timer_mod(timer->timer, timer->time + expires);
153 qemu_bh_schedule(timer->tick);
156 timer_del(timer->timer);
159 static void omap_timer_fire(void *opaque)
161 struct omap_mpu_timer_s *timer = opaque;
169 /* Edge-triggered irq */
170 qemu_irq_pulse(timer->irq);
173 static void omap_timer_tick(void *opaque)
175 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
177 omap_timer_sync(timer);
178 omap_timer_fire(timer);
179 omap_timer_update(timer);
182 static void omap_timer_clk_update(void *opaque, int line, int on)
184 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
186 omap_timer_sync(timer);
187 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
188 omap_timer_update(timer);
191 static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer)
193 omap_clk_adduser(timer->clk,
194 qemu_allocate_irq(omap_timer_clk_update, timer, 0));
195 timer->rate = omap_clk_getrate(timer->clk);
198 static uint64_t omap_mpu_timer_read(void *opaque, hwaddr addr,
201 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
204 return omap_badwidth_read32(opaque, addr);
208 case 0x00: /* CNTL_TIMER */
209 return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st;
211 case 0x04: /* LOAD_TIM */
214 case 0x08: /* READ_TIM */
215 return omap_timer_read(s);
222 static void omap_mpu_timer_write(void *opaque, hwaddr addr,
223 uint64_t value, unsigned size)
225 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
228 omap_badwidth_write32(opaque, addr, value);
233 case 0x00: /* CNTL_TIMER */
235 s->enable = (value >> 5) & 1;
236 s->ptv = (value >> 2) & 7;
237 s->ar = (value >> 1) & 1;
239 omap_timer_update(s);
242 case 0x04: /* LOAD_TIM */
243 s->reset_val = value;
246 case 0x08: /* READ_TIM */
255 static const MemoryRegionOps omap_mpu_timer_ops = {
256 .read = omap_mpu_timer_read,
257 .write = omap_mpu_timer_write,
258 .endianness = DEVICE_LITTLE_ENDIAN,
261 static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s)
265 s->reset_val = 31337;
273 static struct omap_mpu_timer_s *omap_mpu_timer_init(MemoryRegion *system_memory,
275 qemu_irq irq, omap_clk clk)
277 struct omap_mpu_timer_s *s = g_new0(struct omap_mpu_timer_s, 1);
281 s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, omap_timer_tick, s);
282 s->tick = qemu_bh_new(omap_timer_fire, s);
283 omap_mpu_timer_reset(s);
284 omap_timer_clk_setup(s);
286 memory_region_init_io(&s->iomem, NULL, &omap_mpu_timer_ops, s,
287 "omap-mpu-timer", 0x100);
289 memory_region_add_subregion(system_memory, base, &s->iomem);
295 struct omap_watchdog_timer_s {
296 struct omap_mpu_timer_s timer;
304 static uint64_t omap_wd_timer_read(void *opaque, hwaddr addr,
307 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
310 return omap_badwidth_read16(opaque, addr);
314 case 0x00: /* CNTL_TIMER */
315 return (s->timer.ptv << 9) | (s->timer.ar << 8) |
316 (s->timer.st << 7) | (s->free << 1);
318 case 0x04: /* READ_TIMER */
319 return omap_timer_read(&s->timer);
321 case 0x08: /* TIMER_MODE */
322 return s->mode << 15;
329 static void omap_wd_timer_write(void *opaque, hwaddr addr,
330 uint64_t value, unsigned size)
332 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
335 omap_badwidth_write16(opaque, addr, value);
340 case 0x00: /* CNTL_TIMER */
341 omap_timer_sync(&s->timer);
342 s->timer.ptv = (value >> 9) & 7;
343 s->timer.ar = (value >> 8) & 1;
344 s->timer.st = (value >> 7) & 1;
345 s->free = (value >> 1) & 1;
346 omap_timer_update(&s->timer);
349 case 0x04: /* LOAD_TIMER */
350 s->timer.reset_val = value & 0xffff;
353 case 0x08: /* TIMER_MODE */
354 if (!s->mode && ((value >> 15) & 1))
355 omap_clk_get(s->timer.clk);
356 s->mode |= (value >> 15) & 1;
357 if (s->last_wr == 0xf5) {
358 if ((value & 0xff) == 0xa0) {
361 omap_clk_put(s->timer.clk);
364 /* XXX: on T|E hardware somehow this has no effect,
365 * on Zire 71 it works as specified. */
367 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
370 s->last_wr = value & 0xff;
378 static const MemoryRegionOps omap_wd_timer_ops = {
379 .read = omap_wd_timer_read,
380 .write = omap_wd_timer_write,
381 .endianness = DEVICE_NATIVE_ENDIAN,
384 static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s)
386 timer_del(s->timer.timer);
388 omap_clk_get(s->timer.clk);
394 s->timer.reset_val = 0xffff;
399 omap_timer_update(&s->timer);
402 static struct omap_watchdog_timer_s *omap_wd_timer_init(MemoryRegion *memory,
404 qemu_irq irq, omap_clk clk)
406 struct omap_watchdog_timer_s *s = g_new0(struct omap_watchdog_timer_s, 1);
410 s->timer.timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, omap_timer_tick, &s->timer);
411 omap_wd_timer_reset(s);
412 omap_timer_clk_setup(&s->timer);
414 memory_region_init_io(&s->iomem, NULL, &omap_wd_timer_ops, s,
415 "omap-wd-timer", 0x100);
416 memory_region_add_subregion(memory, base, &s->iomem);
422 struct omap_32khz_timer_s {
423 struct omap_mpu_timer_s timer;
427 static uint64_t omap_os_timer_read(void *opaque, hwaddr addr,
430 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
431 int offset = addr & OMAP_MPUI_REG_MASK;
434 return omap_badwidth_read32(opaque, addr);
439 return s->timer.reset_val;
442 return omap_timer_read(&s->timer);
445 return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st;
454 static void omap_os_timer_write(void *opaque, hwaddr addr,
455 uint64_t value, unsigned size)
457 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
458 int offset = addr & OMAP_MPUI_REG_MASK;
461 omap_badwidth_write32(opaque, addr, value);
467 s->timer.reset_val = value & 0x00ffffff;
475 s->timer.ar = (value >> 3) & 1;
476 s->timer.it_ena = (value >> 2) & 1;
477 if (s->timer.st != (value & 1) || (value & 2)) {
478 omap_timer_sync(&s->timer);
479 s->timer.enable = value & 1;
480 s->timer.st = value & 1;
481 omap_timer_update(&s->timer);
490 static const MemoryRegionOps omap_os_timer_ops = {
491 .read = omap_os_timer_read,
492 .write = omap_os_timer_write,
493 .endianness = DEVICE_NATIVE_ENDIAN,
496 static void omap_os_timer_reset(struct omap_32khz_timer_s *s)
498 timer_del(s->timer.timer);
501 s->timer.reset_val = 0x00ffffff;
508 static struct omap_32khz_timer_s *omap_os_timer_init(MemoryRegion *memory,
510 qemu_irq irq, omap_clk clk)
512 struct omap_32khz_timer_s *s = g_new0(struct omap_32khz_timer_s, 1);
516 s->timer.timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, omap_timer_tick, &s->timer);
517 omap_os_timer_reset(s);
518 omap_timer_clk_setup(&s->timer);
520 memory_region_init_io(&s->iomem, NULL, &omap_os_timer_ops, s,
521 "omap-os-timer", 0x800);
522 memory_region_add_subregion(memory, base, &s->iomem);
527 /* Ultra Low-Power Device Module */
528 static uint64_t omap_ulpd_pm_read(void *opaque, hwaddr addr,
531 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
535 return omap_badwidth_read16(opaque, addr);
539 case 0x14: /* IT_STATUS */
540 ret = s->ulpd_pm_regs[addr >> 2];
541 s->ulpd_pm_regs[addr >> 2] = 0;
542 qemu_irq_lower(qdev_get_gpio_in(s->ih[1], OMAP_INT_GAUGE_32K));
545 case 0x18: /* Reserved */
546 case 0x1c: /* Reserved */
547 case 0x20: /* Reserved */
548 case 0x28: /* Reserved */
549 case 0x2c: /* Reserved */
552 case 0x00: /* COUNTER_32_LSB */
553 case 0x04: /* COUNTER_32_MSB */
554 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
555 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
556 case 0x10: /* GAUGING_CTRL */
557 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
558 case 0x30: /* CLOCK_CTRL */
559 case 0x34: /* SOFT_REQ */
560 case 0x38: /* COUNTER_32_FIQ */
561 case 0x3c: /* DPLL_CTRL */
562 case 0x40: /* STATUS_REQ */
563 /* XXX: check clk::usecount state for every clock */
564 case 0x48: /* LOCL_TIME */
565 case 0x4c: /* APLL_CTRL */
566 case 0x50: /* POWER_CTRL */
567 return s->ulpd_pm_regs[addr >> 2];
574 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s,
575 uint16_t diff, uint16_t value)
577 if (diff & (1 << 4)) /* USB_MCLK_EN */
578 omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1);
579 if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */
580 omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1);
583 static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s,
584 uint16_t diff, uint16_t value)
586 if (diff & (1 << 0)) /* SOFT_DPLL_REQ */
587 omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1);
588 if (diff & (1 << 1)) /* SOFT_COM_REQ */
589 omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1);
590 if (diff & (1 << 2)) /* SOFT_SDW_REQ */
591 omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1);
592 if (diff & (1 << 3)) /* SOFT_USB_REQ */
593 omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1);
596 static void omap_ulpd_pm_write(void *opaque, hwaddr addr,
597 uint64_t value, unsigned size)
599 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
602 static const int bypass_div[4] = { 1, 2, 4, 4 };
606 omap_badwidth_write16(opaque, addr, value);
611 case 0x00: /* COUNTER_32_LSB */
612 case 0x04: /* COUNTER_32_MSB */
613 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
614 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
615 case 0x14: /* IT_STATUS */
616 case 0x40: /* STATUS_REQ */
620 case 0x10: /* GAUGING_CTRL */
621 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
622 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
623 now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
626 s->ulpd_gauge_start = now;
628 now -= s->ulpd_gauge_start;
631 ticks = muldiv64(now, 32768, NANOSECONDS_PER_SECOND);
632 s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff;
633 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff;
634 if (ticks >> 32) /* OVERFLOW_32K */
635 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
637 /* High frequency ticks */
638 ticks = muldiv64(now, 12000000, NANOSECONDS_PER_SECOND);
639 s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff;
640 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff;
641 if (ticks >> 32) /* OVERFLOW_HI_FREQ */
642 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
644 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
645 qemu_irq_raise(qdev_get_gpio_in(s->ih[1], OMAP_INT_GAUGE_32K));
648 s->ulpd_pm_regs[addr >> 2] = value;
651 case 0x18: /* Reserved */
652 case 0x1c: /* Reserved */
653 case 0x20: /* Reserved */
654 case 0x28: /* Reserved */
655 case 0x2c: /* Reserved */
658 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
659 case 0x38: /* COUNTER_32_FIQ */
660 case 0x48: /* LOCL_TIME */
661 case 0x50: /* POWER_CTRL */
662 s->ulpd_pm_regs[addr >> 2] = value;
665 case 0x30: /* CLOCK_CTRL */
666 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
667 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
668 omap_ulpd_clk_update(s, diff, value);
671 case 0x34: /* SOFT_REQ */
672 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
673 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
674 omap_ulpd_req_update(s, diff, value);
677 case 0x3c: /* DPLL_CTRL */
678 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
679 * omitted altogether, probably a typo. */
680 /* This register has identical semantics with DPLL(1:3) control
681 * registers, see omap_dpll_write() */
682 diff = s->ulpd_pm_regs[addr >> 2] & value;
683 s->ulpd_pm_regs[addr >> 2] = value & 0x2fff;
684 if (diff & (0x3ff << 2)) {
685 if (value & (1 << 4)) { /* PLL_ENABLE */
686 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
687 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
689 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
692 omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
695 /* Enter the desired mode. */
696 s->ulpd_pm_regs[addr >> 2] =
697 (s->ulpd_pm_regs[addr >> 2] & 0xfffe) |
698 ((s->ulpd_pm_regs[addr >> 2] >> 4) & 1);
700 /* Act as if the lock is restored. */
701 s->ulpd_pm_regs[addr >> 2] |= 2;
704 case 0x4c: /* APLL_CTRL */
705 diff = s->ulpd_pm_regs[addr >> 2] & value;
706 s->ulpd_pm_regs[addr >> 2] = value & 0xf;
707 if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */
708 omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
709 (value & (1 << 0)) ? "apll" : "dpll4"));
717 static const MemoryRegionOps omap_ulpd_pm_ops = {
718 .read = omap_ulpd_pm_read,
719 .write = omap_ulpd_pm_write,
720 .endianness = DEVICE_NATIVE_ENDIAN,
723 static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu)
725 mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001;
726 mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000;
727 mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001;
728 mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000;
729 mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000;
730 mpu->ulpd_pm_regs[0x18 >> 2] = 0x01;
731 mpu->ulpd_pm_regs[0x1c >> 2] = 0x01;
732 mpu->ulpd_pm_regs[0x20 >> 2] = 0x01;
733 mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff;
734 mpu->ulpd_pm_regs[0x28 >> 2] = 0x01;
735 mpu->ulpd_pm_regs[0x2c >> 2] = 0x01;
736 omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000);
737 mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000;
738 omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000);
739 mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000;
740 mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001;
741 mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211;
742 mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
743 mpu->ulpd_pm_regs[0x48 >> 2] = 0x960;
744 mpu->ulpd_pm_regs[0x4c >> 2] = 0x08;
745 mpu->ulpd_pm_regs[0x50 >> 2] = 0x08;
746 omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4);
747 omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4"));
750 static void omap_ulpd_pm_init(MemoryRegion *system_memory,
752 struct omap_mpu_state_s *mpu)
754 memory_region_init_io(&mpu->ulpd_pm_iomem, NULL, &omap_ulpd_pm_ops, mpu,
755 "omap-ulpd-pm", 0x800);
756 memory_region_add_subregion(system_memory, base, &mpu->ulpd_pm_iomem);
757 omap_ulpd_pm_reset(mpu);
760 /* OMAP Pin Configuration */
761 static uint64_t omap_pin_cfg_read(void *opaque, hwaddr addr,
764 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
767 return omap_badwidth_read32(opaque, addr);
771 case 0x00: /* FUNC_MUX_CTRL_0 */
772 case 0x04: /* FUNC_MUX_CTRL_1 */
773 case 0x08: /* FUNC_MUX_CTRL_2 */
774 return s->func_mux_ctrl[addr >> 2];
776 case 0x0c: /* COMP_MODE_CTRL_0 */
777 return s->comp_mode_ctrl[0];
779 case 0x10: /* FUNC_MUX_CTRL_3 */
780 case 0x14: /* FUNC_MUX_CTRL_4 */
781 case 0x18: /* FUNC_MUX_CTRL_5 */
782 case 0x1c: /* FUNC_MUX_CTRL_6 */
783 case 0x20: /* FUNC_MUX_CTRL_7 */
784 case 0x24: /* FUNC_MUX_CTRL_8 */
785 case 0x28: /* FUNC_MUX_CTRL_9 */
786 case 0x2c: /* FUNC_MUX_CTRL_A */
787 case 0x30: /* FUNC_MUX_CTRL_B */
788 case 0x34: /* FUNC_MUX_CTRL_C */
789 case 0x38: /* FUNC_MUX_CTRL_D */
790 return s->func_mux_ctrl[(addr >> 2) - 1];
792 case 0x40: /* PULL_DWN_CTRL_0 */
793 case 0x44: /* PULL_DWN_CTRL_1 */
794 case 0x48: /* PULL_DWN_CTRL_2 */
795 case 0x4c: /* PULL_DWN_CTRL_3 */
796 return s->pull_dwn_ctrl[(addr & 0xf) >> 2];
798 case 0x50: /* GATE_INH_CTRL_0 */
799 return s->gate_inh_ctrl[0];
801 case 0x60: /* VOLTAGE_CTRL_0 */
802 return s->voltage_ctrl[0];
804 case 0x70: /* TEST_DBG_CTRL_0 */
805 return s->test_dbg_ctrl[0];
807 case 0x80: /* MOD_CONF_CTRL_0 */
808 return s->mod_conf_ctrl[0];
815 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s,
816 uint32_t diff, uint32_t value)
819 if (diff & (1 << 9)) /* BLUETOOTH */
820 omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
822 if (diff & (1 << 7)) /* USB.CLKO */
823 omap_clk_onoff(omap_findclk(s, "usb.clko"),
828 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s,
829 uint32_t diff, uint32_t value)
832 if (diff & (1U << 31)) {
833 /* MCBSP3_CLK_HIZ_DI */
834 omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"), (value >> 31) & 1);
836 if (diff & (1 << 1)) {
838 omap_clk_onoff(omap_findclk(s, "clk32k_out"), (~value >> 1) & 1);
843 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s,
844 uint32_t diff, uint32_t value)
846 if (diff & (1U << 31)) {
847 /* CONF_MOD_UART3_CLK_MODE_R */
848 omap_clk_reparent(omap_findclk(s, "uart3_ck"),
849 omap_findclk(s, ((value >> 31) & 1) ?
850 "ck_48m" : "armper_ck"));
852 if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
853 omap_clk_reparent(omap_findclk(s, "uart2_ck"),
854 omap_findclk(s, ((value >> 30) & 1) ?
855 "ck_48m" : "armper_ck"));
856 if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
857 omap_clk_reparent(omap_findclk(s, "uart1_ck"),
858 omap_findclk(s, ((value >> 29) & 1) ?
859 "ck_48m" : "armper_ck"));
860 if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
861 omap_clk_reparent(omap_findclk(s, "mmc_ck"),
862 omap_findclk(s, ((value >> 23) & 1) ?
863 "ck_48m" : "armper_ck"));
864 if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
865 omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
866 omap_findclk(s, ((value >> 12) & 1) ?
867 "ck_48m" : "armper_ck"));
868 if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
869 omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1);
872 static void omap_pin_cfg_write(void *opaque, hwaddr addr,
873 uint64_t value, unsigned size)
875 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
879 omap_badwidth_write32(opaque, addr, value);
884 case 0x00: /* FUNC_MUX_CTRL_0 */
885 diff = s->func_mux_ctrl[addr >> 2] ^ value;
886 s->func_mux_ctrl[addr >> 2] = value;
887 omap_pin_funcmux0_update(s, diff, value);
890 case 0x04: /* FUNC_MUX_CTRL_1 */
891 diff = s->func_mux_ctrl[addr >> 2] ^ value;
892 s->func_mux_ctrl[addr >> 2] = value;
893 omap_pin_funcmux1_update(s, diff, value);
896 case 0x08: /* FUNC_MUX_CTRL_2 */
897 s->func_mux_ctrl[addr >> 2] = value;
900 case 0x0c: /* COMP_MODE_CTRL_0 */
901 s->comp_mode_ctrl[0] = value;
902 s->compat1509 = (value != 0x0000eaef);
903 omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]);
904 omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]);
907 case 0x10: /* FUNC_MUX_CTRL_3 */
908 case 0x14: /* FUNC_MUX_CTRL_4 */
909 case 0x18: /* FUNC_MUX_CTRL_5 */
910 case 0x1c: /* FUNC_MUX_CTRL_6 */
911 case 0x20: /* FUNC_MUX_CTRL_7 */
912 case 0x24: /* FUNC_MUX_CTRL_8 */
913 case 0x28: /* FUNC_MUX_CTRL_9 */
914 case 0x2c: /* FUNC_MUX_CTRL_A */
915 case 0x30: /* FUNC_MUX_CTRL_B */
916 case 0x34: /* FUNC_MUX_CTRL_C */
917 case 0x38: /* FUNC_MUX_CTRL_D */
918 s->func_mux_ctrl[(addr >> 2) - 1] = value;
921 case 0x40: /* PULL_DWN_CTRL_0 */
922 case 0x44: /* PULL_DWN_CTRL_1 */
923 case 0x48: /* PULL_DWN_CTRL_2 */
924 case 0x4c: /* PULL_DWN_CTRL_3 */
925 s->pull_dwn_ctrl[(addr & 0xf) >> 2] = value;
928 case 0x50: /* GATE_INH_CTRL_0 */
929 s->gate_inh_ctrl[0] = value;
932 case 0x60: /* VOLTAGE_CTRL_0 */
933 s->voltage_ctrl[0] = value;
936 case 0x70: /* TEST_DBG_CTRL_0 */
937 s->test_dbg_ctrl[0] = value;
940 case 0x80: /* MOD_CONF_CTRL_0 */
941 diff = s->mod_conf_ctrl[0] ^ value;
942 s->mod_conf_ctrl[0] = value;
943 omap_pin_modconf1_update(s, diff, value);
951 static const MemoryRegionOps omap_pin_cfg_ops = {
952 .read = omap_pin_cfg_read,
953 .write = omap_pin_cfg_write,
954 .endianness = DEVICE_NATIVE_ENDIAN,
957 static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu)
959 /* Start in Compatibility Mode. */
961 omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0);
962 omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0);
963 omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0);
964 memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl));
965 memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl));
966 memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl));
967 memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl));
968 memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl));
969 memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl));
970 memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl));
973 static void omap_pin_cfg_init(MemoryRegion *system_memory,
975 struct omap_mpu_state_s *mpu)
977 memory_region_init_io(&mpu->pin_cfg_iomem, NULL, &omap_pin_cfg_ops, mpu,
978 "omap-pin-cfg", 0x800);
979 memory_region_add_subregion(system_memory, base, &mpu->pin_cfg_iomem);
980 omap_pin_cfg_reset(mpu);
983 /* Device Identification, Die Identification */
984 static uint64_t omap_id_read(void *opaque, hwaddr addr,
987 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
990 return omap_badwidth_read32(opaque, addr);
994 case 0xfffe1800: /* DIE_ID_LSB */
996 case 0xfffe1804: /* DIE_ID_MSB */
999 case 0xfffe2000: /* PRODUCT_ID_LSB */
1001 case 0xfffe2004: /* PRODUCT_ID_MSB */
1004 case 0xfffed400: /* JTAG_ID_LSB */
1005 switch (s->mpu_model) {
1011 hw_error("%s: bad mpu model\n", __func__);
1015 case 0xfffed404: /* JTAG_ID_MSB */
1016 switch (s->mpu_model) {
1022 hw_error("%s: bad mpu model\n", __func__);
1031 static void omap_id_write(void *opaque, hwaddr addr,
1032 uint64_t value, unsigned size)
1035 omap_badwidth_write32(opaque, addr, value);
1042 static const MemoryRegionOps omap_id_ops = {
1043 .read = omap_id_read,
1044 .write = omap_id_write,
1045 .endianness = DEVICE_NATIVE_ENDIAN,
1048 static void omap_id_init(MemoryRegion *memory, struct omap_mpu_state_s *mpu)
1050 memory_region_init_io(&mpu->id_iomem, NULL, &omap_id_ops, mpu,
1051 "omap-id", 0x100000000ULL);
1052 memory_region_init_alias(&mpu->id_iomem_e18, NULL, "omap-id-e18", &mpu->id_iomem,
1054 memory_region_add_subregion(memory, 0xfffe1800, &mpu->id_iomem_e18);
1055 memory_region_init_alias(&mpu->id_iomem_ed4, NULL, "omap-id-ed4", &mpu->id_iomem,
1057 memory_region_add_subregion(memory, 0xfffed400, &mpu->id_iomem_ed4);
1058 if (!cpu_is_omap15xx(mpu)) {
1059 memory_region_init_alias(&mpu->id_iomem_ed4, NULL, "omap-id-e20",
1060 &mpu->id_iomem, 0xfffe2000, 0x800);
1061 memory_region_add_subregion(memory, 0xfffe2000, &mpu->id_iomem_e20);
1065 /* MPUI Control (Dummy) */
1066 static uint64_t omap_mpui_read(void *opaque, hwaddr addr,
1069 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1072 return omap_badwidth_read32(opaque, addr);
1076 case 0x00: /* CTRL */
1077 return s->mpui_ctrl;
1078 case 0x04: /* DEBUG_ADDR */
1080 case 0x08: /* DEBUG_DATA */
1082 case 0x0c: /* DEBUG_FLAG */
1084 case 0x10: /* STATUS */
1087 /* Not in OMAP310 */
1088 case 0x14: /* DSP_STATUS */
1089 case 0x18: /* DSP_BOOT_CONFIG */
1091 case 0x1c: /* DSP_MPUI_CONFIG */
1099 static void omap_mpui_write(void *opaque, hwaddr addr,
1100 uint64_t value, unsigned size)
1102 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1105 omap_badwidth_write32(opaque, addr, value);
1110 case 0x00: /* CTRL */
1111 s->mpui_ctrl = value & 0x007fffff;
1114 case 0x04: /* DEBUG_ADDR */
1115 case 0x08: /* DEBUG_DATA */
1116 case 0x0c: /* DEBUG_FLAG */
1117 case 0x10: /* STATUS */
1118 /* Not in OMAP310 */
1119 case 0x14: /* DSP_STATUS */
1122 case 0x18: /* DSP_BOOT_CONFIG */
1123 case 0x1c: /* DSP_MPUI_CONFIG */
1131 static const MemoryRegionOps omap_mpui_ops = {
1132 .read = omap_mpui_read,
1133 .write = omap_mpui_write,
1134 .endianness = DEVICE_NATIVE_ENDIAN,
1137 static void omap_mpui_reset(struct omap_mpu_state_s *s)
1139 s->mpui_ctrl = 0x0003ff1b;
1142 static void omap_mpui_init(MemoryRegion *memory, hwaddr base,
1143 struct omap_mpu_state_s *mpu)
1145 memory_region_init_io(&mpu->mpui_iomem, NULL, &omap_mpui_ops, mpu,
1146 "omap-mpui", 0x100);
1147 memory_region_add_subregion(memory, base, &mpu->mpui_iomem);
1149 omap_mpui_reset(mpu);
1153 struct omap_tipb_bridge_s {
1161 uint16_t enh_control;
1164 static uint64_t omap_tipb_bridge_read(void *opaque, hwaddr addr,
1167 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1170 return omap_badwidth_read16(opaque, addr);
1174 case 0x00: /* TIPB_CNTL */
1176 case 0x04: /* TIPB_BUS_ALLOC */
1178 case 0x08: /* MPU_TIPB_CNTL */
1180 case 0x0c: /* ENHANCED_TIPB_CNTL */
1181 return s->enh_control;
1182 case 0x10: /* ADDRESS_DBG */
1183 case 0x14: /* DATA_DEBUG_LOW */
1184 case 0x18: /* DATA_DEBUG_HIGH */
1186 case 0x1c: /* DEBUG_CNTR_SIG */
1194 static void omap_tipb_bridge_write(void *opaque, hwaddr addr,
1195 uint64_t value, unsigned size)
1197 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1200 omap_badwidth_write16(opaque, addr, value);
1205 case 0x00: /* TIPB_CNTL */
1206 s->control = value & 0xffff;
1209 case 0x04: /* TIPB_BUS_ALLOC */
1210 s->alloc = value & 0x003f;
1213 case 0x08: /* MPU_TIPB_CNTL */
1214 s->buffer = value & 0x0003;
1217 case 0x0c: /* ENHANCED_TIPB_CNTL */
1218 s->width_intr = !(value & 2);
1219 s->enh_control = value & 0x000f;
1222 case 0x10: /* ADDRESS_DBG */
1223 case 0x14: /* DATA_DEBUG_LOW */
1224 case 0x18: /* DATA_DEBUG_HIGH */
1225 case 0x1c: /* DEBUG_CNTR_SIG */
1234 static const MemoryRegionOps omap_tipb_bridge_ops = {
1235 .read = omap_tipb_bridge_read,
1236 .write = omap_tipb_bridge_write,
1237 .endianness = DEVICE_NATIVE_ENDIAN,
1240 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s)
1242 s->control = 0xffff;
1245 s->enh_control = 0x000f;
1248 static struct omap_tipb_bridge_s *omap_tipb_bridge_init(
1249 MemoryRegion *memory, hwaddr base,
1250 qemu_irq abort_irq, omap_clk clk)
1252 struct omap_tipb_bridge_s *s = g_new0(struct omap_tipb_bridge_s, 1);
1254 s->abort = abort_irq;
1255 omap_tipb_bridge_reset(s);
1257 memory_region_init_io(&s->iomem, NULL, &omap_tipb_bridge_ops, s,
1258 "omap-tipb-bridge", 0x100);
1259 memory_region_add_subregion(memory, base, &s->iomem);
1264 /* Dummy Traffic Controller's Memory Interface */
1265 static uint64_t omap_tcmi_read(void *opaque, hwaddr addr,
1268 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1272 return omap_badwidth_read32(opaque, addr);
1276 case 0x00: /* IMIF_PRIO */
1277 case 0x04: /* EMIFS_PRIO */
1278 case 0x08: /* EMIFF_PRIO */
1279 case 0x0c: /* EMIFS_CONFIG */
1280 case 0x10: /* EMIFS_CS0_CONFIG */
1281 case 0x14: /* EMIFS_CS1_CONFIG */
1282 case 0x18: /* EMIFS_CS2_CONFIG */
1283 case 0x1c: /* EMIFS_CS3_CONFIG */
1284 case 0x24: /* EMIFF_MRS */
1285 case 0x28: /* TIMEOUT1 */
1286 case 0x2c: /* TIMEOUT2 */
1287 case 0x30: /* TIMEOUT3 */
1288 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1289 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1290 return s->tcmi_regs[addr >> 2];
1292 case 0x20: /* EMIFF_SDRAM_CONFIG */
1293 ret = s->tcmi_regs[addr >> 2];
1294 s->tcmi_regs[addr >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1295 /* XXX: We can try using the VGA_DIRTY flag for this */
1303 static void omap_tcmi_write(void *opaque, hwaddr addr,
1304 uint64_t value, unsigned size)
1306 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1309 omap_badwidth_write32(opaque, addr, value);
1314 case 0x00: /* IMIF_PRIO */
1315 case 0x04: /* EMIFS_PRIO */
1316 case 0x08: /* EMIFF_PRIO */
1317 case 0x10: /* EMIFS_CS0_CONFIG */
1318 case 0x14: /* EMIFS_CS1_CONFIG */
1319 case 0x18: /* EMIFS_CS2_CONFIG */
1320 case 0x1c: /* EMIFS_CS3_CONFIG */
1321 case 0x20: /* EMIFF_SDRAM_CONFIG */
1322 case 0x24: /* EMIFF_MRS */
1323 case 0x28: /* TIMEOUT1 */
1324 case 0x2c: /* TIMEOUT2 */
1325 case 0x30: /* TIMEOUT3 */
1326 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1327 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1328 s->tcmi_regs[addr >> 2] = value;
1330 case 0x0c: /* EMIFS_CONFIG */
1331 s->tcmi_regs[addr >> 2] = (value & 0xf) | (1 << 4);
1339 static const MemoryRegionOps omap_tcmi_ops = {
1340 .read = omap_tcmi_read,
1341 .write = omap_tcmi_write,
1342 .endianness = DEVICE_NATIVE_ENDIAN,
1345 static void omap_tcmi_reset(struct omap_mpu_state_s *mpu)
1347 mpu->tcmi_regs[0x00 >> 2] = 0x00000000;
1348 mpu->tcmi_regs[0x04 >> 2] = 0x00000000;
1349 mpu->tcmi_regs[0x08 >> 2] = 0x00000000;
1350 mpu->tcmi_regs[0x0c >> 2] = 0x00000010;
1351 mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb;
1352 mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb;
1353 mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb;
1354 mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb;
1355 mpu->tcmi_regs[0x20 >> 2] = 0x00618800;
1356 mpu->tcmi_regs[0x24 >> 2] = 0x00000037;
1357 mpu->tcmi_regs[0x28 >> 2] = 0x00000000;
1358 mpu->tcmi_regs[0x2c >> 2] = 0x00000000;
1359 mpu->tcmi_regs[0x30 >> 2] = 0x00000000;
1360 mpu->tcmi_regs[0x3c >> 2] = 0x00000003;
1361 mpu->tcmi_regs[0x40 >> 2] = 0x00000000;
1364 static void omap_tcmi_init(MemoryRegion *memory, hwaddr base,
1365 struct omap_mpu_state_s *mpu)
1367 memory_region_init_io(&mpu->tcmi_iomem, NULL, &omap_tcmi_ops, mpu,
1368 "omap-tcmi", 0x100);
1369 memory_region_add_subregion(memory, base, &mpu->tcmi_iomem);
1370 omap_tcmi_reset(mpu);
1373 /* Digital phase-locked loops control */
1380 static uint64_t omap_dpll_read(void *opaque, hwaddr addr,
1383 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1386 return omap_badwidth_read16(opaque, addr);
1389 if (addr == 0x00) /* CTL_REG */
1396 static void omap_dpll_write(void *opaque, hwaddr addr,
1397 uint64_t value, unsigned size)
1399 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1401 static const int bypass_div[4] = { 1, 2, 4, 4 };
1405 omap_badwidth_write16(opaque, addr, value);
1409 if (addr == 0x00) { /* CTL_REG */
1410 /* See omap_ulpd_pm_write() too */
1411 diff = s->mode & value;
1412 s->mode = value & 0x2fff;
1413 if (diff & (0x3ff << 2)) {
1414 if (value & (1 << 4)) { /* PLL_ENABLE */
1415 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1416 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1418 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1421 omap_clk_setrate(s->dpll, div, mult);
1424 /* Enter the desired mode. */
1425 s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1);
1427 /* Act as if the lock is restored. */
1434 static const MemoryRegionOps omap_dpll_ops = {
1435 .read = omap_dpll_read,
1436 .write = omap_dpll_write,
1437 .endianness = DEVICE_NATIVE_ENDIAN,
1440 static void omap_dpll_reset(struct dpll_ctl_s *s)
1443 omap_clk_setrate(s->dpll, 1, 1);
1446 static struct dpll_ctl_s *omap_dpll_init(MemoryRegion *memory,
1447 hwaddr base, omap_clk clk)
1449 struct dpll_ctl_s *s = g_malloc0(sizeof(*s));
1450 memory_region_init_io(&s->iomem, NULL, &omap_dpll_ops, s, "omap-dpll", 0x100);
1455 memory_region_add_subregion(memory, base, &s->iomem);
1459 /* MPU Clock/Reset/Power Mode Control */
1460 static uint64_t omap_clkm_read(void *opaque, hwaddr addr,
1463 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1466 return omap_badwidth_read16(opaque, addr);
1470 case 0x00: /* ARM_CKCTL */
1471 return s->clkm.arm_ckctl;
1473 case 0x04: /* ARM_IDLECT1 */
1474 return s->clkm.arm_idlect1;
1476 case 0x08: /* ARM_IDLECT2 */
1477 return s->clkm.arm_idlect2;
1479 case 0x0c: /* ARM_EWUPCT */
1480 return s->clkm.arm_ewupct;
1482 case 0x10: /* ARM_RSTCT1 */
1483 return s->clkm.arm_rstct1;
1485 case 0x14: /* ARM_RSTCT2 */
1486 return s->clkm.arm_rstct2;
1488 case 0x18: /* ARM_SYSST */
1489 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start;
1491 case 0x1c: /* ARM_CKOUT1 */
1492 return s->clkm.arm_ckout1;
1494 case 0x20: /* ARM_CKOUT2 */
1502 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s,
1503 uint16_t diff, uint16_t value)
1507 if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */
1508 if (value & (1 << 14))
1511 clk = omap_findclk(s, "arminth_ck");
1512 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
1515 if (diff & (1 << 12)) { /* ARM_TIMXO */
1516 clk = omap_findclk(s, "armtim_ck");
1517 if (value & (1 << 12))
1518 omap_clk_reparent(clk, omap_findclk(s, "clkin"));
1520 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
1523 if (diff & (3 << 10)) { /* DSPMMUDIV */
1524 clk = omap_findclk(s, "dspmmu_ck");
1525 omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1);
1527 if (diff & (3 << 8)) { /* TCDIV */
1528 clk = omap_findclk(s, "tc_ck");
1529 omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1);
1531 if (diff & (3 << 6)) { /* DSPDIV */
1532 clk = omap_findclk(s, "dsp_ck");
1533 omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1);
1535 if (diff & (3 << 4)) { /* ARMDIV */
1536 clk = omap_findclk(s, "arm_ck");
1537 omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1);
1539 if (diff & (3 << 2)) { /* LCDDIV */
1540 clk = omap_findclk(s, "lcd_ck");
1541 omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1);
1543 if (diff & (3 << 0)) { /* PERDIV */
1544 clk = omap_findclk(s, "armper_ck");
1545 omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1);
1549 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s,
1550 uint16_t diff, uint16_t value)
1554 if (value & (1 << 11)) { /* SETARM_IDLE */
1555 cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_HALT);
1557 if (!(value & (1 << 10))) { /* WKUP_MODE */
1558 /* XXX: disable wakeup from IRQ */
1559 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
1562 #define SET_CANIDLE(clock, bit) \
1563 if (diff & (1 << bit)) { \
1564 clk = omap_findclk(s, clock); \
1565 omap_clk_canidle(clk, (value >> bit) & 1); \
1567 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1568 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1569 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1570 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1571 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1572 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1573 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1574 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1575 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1576 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1577 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1578 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1579 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1580 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1583 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s,
1584 uint16_t diff, uint16_t value)
1588 #define SET_ONOFF(clock, bit) \
1589 if (diff & (1 << bit)) { \
1590 clk = omap_findclk(s, clock); \
1591 omap_clk_onoff(clk, (value >> bit) & 1); \
1593 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1594 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1595 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1596 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1597 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1598 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1599 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1600 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1601 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1602 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1603 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1606 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s,
1607 uint16_t diff, uint16_t value)
1611 if (diff & (3 << 4)) { /* TCLKOUT */
1612 clk = omap_findclk(s, "tclk_out");
1613 switch ((value >> 4) & 3) {
1615 omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
1616 omap_clk_onoff(clk, 1);
1619 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
1620 omap_clk_onoff(clk, 1);
1623 omap_clk_onoff(clk, 0);
1626 if (diff & (3 << 2)) { /* DCLKOUT */
1627 clk = omap_findclk(s, "dclk_out");
1628 switch ((value >> 2) & 3) {
1630 omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
1633 omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
1636 omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
1639 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
1643 if (diff & (3 << 0)) { /* ACLKOUT */
1644 clk = omap_findclk(s, "aclk_out");
1645 switch ((value >> 0) & 3) {
1647 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
1648 omap_clk_onoff(clk, 1);
1651 omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
1652 omap_clk_onoff(clk, 1);
1655 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
1656 omap_clk_onoff(clk, 1);
1659 omap_clk_onoff(clk, 0);
1664 static void omap_clkm_write(void *opaque, hwaddr addr,
1665 uint64_t value, unsigned size)
1667 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1670 static const char *clkschemename[8] = {
1671 "fully synchronous", "fully asynchronous", "synchronous scalable",
1672 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1676 omap_badwidth_write16(opaque, addr, value);
1681 case 0x00: /* ARM_CKCTL */
1682 diff = s->clkm.arm_ckctl ^ value;
1683 s->clkm.arm_ckctl = value & 0x7fff;
1684 omap_clkm_ckctl_update(s, diff, value);
1687 case 0x04: /* ARM_IDLECT1 */
1688 diff = s->clkm.arm_idlect1 ^ value;
1689 s->clkm.arm_idlect1 = value & 0x0fff;
1690 omap_clkm_idlect1_update(s, diff, value);
1693 case 0x08: /* ARM_IDLECT2 */
1694 diff = s->clkm.arm_idlect2 ^ value;
1695 s->clkm.arm_idlect2 = value & 0x07ff;
1696 omap_clkm_idlect2_update(s, diff, value);
1699 case 0x0c: /* ARM_EWUPCT */
1700 s->clkm.arm_ewupct = value & 0x003f;
1703 case 0x10: /* ARM_RSTCT1 */
1704 diff = s->clkm.arm_rstct1 ^ value;
1705 s->clkm.arm_rstct1 = value & 0x0007;
1707 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
1708 s->clkm.cold_start = 0xa;
1710 if (diff & ~value & 4) { /* DSP_RST */
1712 omap_tipb_bridge_reset(s->private_tipb);
1713 omap_tipb_bridge_reset(s->public_tipb);
1715 if (diff & 2) { /* DSP_EN */
1716 clk = omap_findclk(s, "dsp_ck");
1717 omap_clk_canidle(clk, (~value >> 1) & 1);
1721 case 0x14: /* ARM_RSTCT2 */
1722 s->clkm.arm_rstct2 = value & 0x0001;
1725 case 0x18: /* ARM_SYSST */
1726 if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) {
1727 s->clkm.clocking_scheme = (value >> 11) & 7;
1728 printf("%s: clocking scheme set to %s\n", __func__,
1729 clkschemename[s->clkm.clocking_scheme]);
1731 s->clkm.cold_start &= value & 0x3f;
1734 case 0x1c: /* ARM_CKOUT1 */
1735 diff = s->clkm.arm_ckout1 ^ value;
1736 s->clkm.arm_ckout1 = value & 0x003f;
1737 omap_clkm_ckout1_update(s, diff, value);
1740 case 0x20: /* ARM_CKOUT2 */
1746 static const MemoryRegionOps omap_clkm_ops = {
1747 .read = omap_clkm_read,
1748 .write = omap_clkm_write,
1749 .endianness = DEVICE_NATIVE_ENDIAN,
1752 static uint64_t omap_clkdsp_read(void *opaque, hwaddr addr,
1755 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1756 CPUState *cpu = CPU(s->cpu);
1759 return omap_badwidth_read16(opaque, addr);
1763 case 0x04: /* DSP_IDLECT1 */
1764 return s->clkm.dsp_idlect1;
1766 case 0x08: /* DSP_IDLECT2 */
1767 return s->clkm.dsp_idlect2;
1769 case 0x14: /* DSP_RSTCT2 */
1770 return s->clkm.dsp_rstct2;
1772 case 0x18: /* DSP_SYSST */
1774 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start |
1775 (cpu->halted << 6); /* Quite useless... */
1782 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s,
1783 uint16_t diff, uint16_t value)
1787 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1790 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s,
1791 uint16_t diff, uint16_t value)
1795 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1798 static void omap_clkdsp_write(void *opaque, hwaddr addr,
1799 uint64_t value, unsigned size)
1801 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1805 omap_badwidth_write16(opaque, addr, value);
1810 case 0x04: /* DSP_IDLECT1 */
1811 diff = s->clkm.dsp_idlect1 ^ value;
1812 s->clkm.dsp_idlect1 = value & 0x01f7;
1813 omap_clkdsp_idlect1_update(s, diff, value);
1816 case 0x08: /* DSP_IDLECT2 */
1817 s->clkm.dsp_idlect2 = value & 0x0037;
1818 diff = s->clkm.dsp_idlect1 ^ value;
1819 omap_clkdsp_idlect2_update(s, diff, value);
1822 case 0x14: /* DSP_RSTCT2 */
1823 s->clkm.dsp_rstct2 = value & 0x0001;
1826 case 0x18: /* DSP_SYSST */
1827 s->clkm.cold_start &= value & 0x3f;
1835 static const MemoryRegionOps omap_clkdsp_ops = {
1836 .read = omap_clkdsp_read,
1837 .write = omap_clkdsp_write,
1838 .endianness = DEVICE_NATIVE_ENDIAN,
1841 static void omap_clkm_reset(struct omap_mpu_state_s *s)
1843 if (s->wdt && s->wdt->reset)
1844 s->clkm.cold_start = 0x6;
1845 s->clkm.clocking_scheme = 0;
1846 omap_clkm_ckctl_update(s, ~0, 0x3000);
1847 s->clkm.arm_ckctl = 0x3000;
1848 omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 ^ 0x0400, 0x0400);
1849 s->clkm.arm_idlect1 = 0x0400;
1850 omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 ^ 0x0100, 0x0100);
1851 s->clkm.arm_idlect2 = 0x0100;
1852 s->clkm.arm_ewupct = 0x003f;
1853 s->clkm.arm_rstct1 = 0x0000;
1854 s->clkm.arm_rstct2 = 0x0000;
1855 s->clkm.arm_ckout1 = 0x0015;
1856 s->clkm.dpll1_mode = 0x2002;
1857 omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040);
1858 s->clkm.dsp_idlect1 = 0x0040;
1859 omap_clkdsp_idlect2_update(s, ~0, 0x0000);
1860 s->clkm.dsp_idlect2 = 0x0000;
1861 s->clkm.dsp_rstct2 = 0x0000;
1864 static void omap_clkm_init(MemoryRegion *memory, hwaddr mpu_base,
1865 hwaddr dsp_base, struct omap_mpu_state_s *s)
1867 memory_region_init_io(&s->clkm_iomem, NULL, &omap_clkm_ops, s,
1868 "omap-clkm", 0x100);
1869 memory_region_init_io(&s->clkdsp_iomem, NULL, &omap_clkdsp_ops, s,
1870 "omap-clkdsp", 0x1000);
1872 s->clkm.arm_idlect1 = 0x03ff;
1873 s->clkm.arm_idlect2 = 0x0100;
1874 s->clkm.dsp_idlect1 = 0x0002;
1876 s->clkm.cold_start = 0x3a;
1878 memory_region_add_subregion(memory, mpu_base, &s->clkm_iomem);
1879 memory_region_add_subregion(memory, dsp_base, &s->clkdsp_iomem);
1883 struct omap_mpuio_s {
1887 qemu_irq handler[16];
1909 static void omap_mpuio_set(void *opaque, int line, int level)
1911 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1912 uint16_t prev = s->inputs;
1915 s->inputs |= 1 << line;
1917 s->inputs &= ~(1 << line);
1919 if (((1 << line) & s->dir & ~s->mask) && s->clk) {
1920 if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
1921 s->ints |= 1 << line;
1922 qemu_irq_raise(s->irq);
1925 if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1926 (s->event >> 1) == line) /* PIN_SELECT */
1927 s->latch = s->inputs;
1931 static void omap_mpuio_kbd_update(struct omap_mpuio_s *s)
1934 uint8_t *row, rows = 0, cols = ~s->cols;
1936 for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1)
1940 qemu_set_irq(s->kbd_irq, rows && !s->kbd_mask && s->clk);
1941 s->row_latch = ~rows;
1944 static uint64_t omap_mpuio_read(void *opaque, hwaddr addr,
1947 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
1948 int offset = addr & OMAP_MPUI_REG_MASK;
1952 return omap_badwidth_read16(opaque, addr);
1956 case 0x00: /* INPUT_LATCH */
1959 case 0x04: /* OUTPUT_REG */
1962 case 0x08: /* IO_CNTL */
1965 case 0x10: /* KBR_LATCH */
1966 return s->row_latch;
1968 case 0x14: /* KBC_REG */
1971 case 0x18: /* GPIO_EVENT_MODE_REG */
1974 case 0x1c: /* GPIO_INT_EDGE_REG */
1977 case 0x20: /* KBD_INT */
1978 return (~s->row_latch & 0x1f) && !s->kbd_mask;
1980 case 0x24: /* GPIO_INT */
1984 qemu_irq_lower(s->irq);
1987 case 0x28: /* KBD_MASKIT */
1990 case 0x2c: /* GPIO_MASKIT */
1993 case 0x30: /* GPIO_DEBOUNCING_REG */
1996 case 0x34: /* GPIO_LATCH_REG */
2004 static void omap_mpuio_write(void *opaque, hwaddr addr,
2005 uint64_t value, unsigned size)
2007 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2008 int offset = addr & OMAP_MPUI_REG_MASK;
2013 omap_badwidth_write16(opaque, addr, value);
2018 case 0x04: /* OUTPUT_REG */
2019 diff = (s->outputs ^ value) & ~s->dir;
2021 while ((ln = ctz32(diff)) != 32) {
2023 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2028 case 0x08: /* IO_CNTL */
2029 diff = s->outputs & (s->dir ^ value);
2032 value = s->outputs & ~s->dir;
2033 while ((ln = ctz32(diff)) != 32) {
2035 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2040 case 0x14: /* KBC_REG */
2042 omap_mpuio_kbd_update(s);
2045 case 0x18: /* GPIO_EVENT_MODE_REG */
2046 s->event = value & 0x1f;
2049 case 0x1c: /* GPIO_INT_EDGE_REG */
2053 case 0x28: /* KBD_MASKIT */
2054 s->kbd_mask = value & 1;
2055 omap_mpuio_kbd_update(s);
2058 case 0x2c: /* GPIO_MASKIT */
2062 case 0x30: /* GPIO_DEBOUNCING_REG */
2063 s->debounce = value & 0x1ff;
2066 case 0x00: /* INPUT_LATCH */
2067 case 0x10: /* KBR_LATCH */
2068 case 0x20: /* KBD_INT */
2069 case 0x24: /* GPIO_INT */
2070 case 0x34: /* GPIO_LATCH_REG */
2080 static const MemoryRegionOps omap_mpuio_ops = {
2081 .read = omap_mpuio_read,
2082 .write = omap_mpuio_write,
2083 .endianness = DEVICE_NATIVE_ENDIAN,
2086 static void omap_mpuio_reset(struct omap_mpuio_s *s)
2098 s->row_latch = 0x1f;
2102 static void omap_mpuio_onoff(void *opaque, int line, int on)
2104 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2108 omap_mpuio_kbd_update(s);
2111 static struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory,
2113 qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup,
2116 struct omap_mpuio_s *s = g_new0(struct omap_mpuio_s, 1);
2119 s->kbd_irq = kbd_int;
2121 s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
2122 omap_mpuio_reset(s);
2124 memory_region_init_io(&s->iomem, NULL, &omap_mpuio_ops, s,
2125 "omap-mpuio", 0x800);
2126 memory_region_add_subregion(memory, base, &s->iomem);
2128 omap_clk_adduser(clk, qemu_allocate_irq(omap_mpuio_onoff, s, 0));
2133 qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
2138 void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler)
2140 if (line >= 16 || line < 0)
2141 hw_error("%s: No GPIO line %i\n", __func__, line);
2142 s->handler[line] = handler;
2145 void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down)
2147 if (row >= 5 || row < 0)
2148 hw_error("%s: No key %i-%i\n", __func__, col, row);
2151 s->buttons[row] |= 1 << col;
2153 s->buttons[row] &= ~(1 << col);
2155 omap_mpuio_kbd_update(s);
2158 /* MicroWire Interface */
2159 struct omap_uwire_s {
2170 uWireSlave *chip[4];
2173 static void omap_uwire_transfer_start(struct omap_uwire_s *s)
2175 int chipselect = (s->control >> 10) & 3; /* INDEX */
2176 uWireSlave *slave = s->chip[chipselect];
2178 if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */
2179 if (s->control & (1 << 12)) /* CS_CMD */
2180 if (slave && slave->send)
2181 slave->send(slave->opaque,
2182 s->txbuf >> (16 - ((s->control >> 5) & 0x1f)));
2183 s->control &= ~(1 << 14); /* CSRB */
2184 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2185 * a DRQ. When is the level IRQ supposed to be reset? */
2188 if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */
2189 if (s->control & (1 << 12)) /* CS_CMD */
2190 if (slave && slave->receive)
2191 s->rxbuf = slave->receive(slave->opaque);
2192 s->control |= 1 << 15; /* RDRB */
2193 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2194 * a DRQ. When is the level IRQ supposed to be reset? */
2198 static uint64_t omap_uwire_read(void *opaque, hwaddr addr,
2201 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
2202 int offset = addr & OMAP_MPUI_REG_MASK;
2205 return omap_badwidth_read16(opaque, addr);
2209 case 0x00: /* RDR */
2210 s->control &= ~(1 << 15); /* RDRB */
2213 case 0x04: /* CSR */
2216 case 0x08: /* SR1 */
2218 case 0x0c: /* SR2 */
2220 case 0x10: /* SR3 */
2222 case 0x14: /* SR4 */
2224 case 0x18: /* SR5 */
2232 static void omap_uwire_write(void *opaque, hwaddr addr,
2233 uint64_t value, unsigned size)
2235 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
2236 int offset = addr & OMAP_MPUI_REG_MASK;
2239 omap_badwidth_write16(opaque, addr, value);
2244 case 0x00: /* TDR */
2245 s->txbuf = value; /* TD */
2246 if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */
2247 ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2248 (s->control & (1 << 12)))) { /* CS_CMD */
2249 s->control |= 1 << 14; /* CSRB */
2250 omap_uwire_transfer_start(s);
2254 case 0x04: /* CSR */
2255 s->control = value & 0x1fff;
2256 if (value & (1 << 13)) /* START */
2257 omap_uwire_transfer_start(s);
2260 case 0x08: /* SR1 */
2261 s->setup[0] = value & 0x003f;
2264 case 0x0c: /* SR2 */
2265 s->setup[1] = value & 0x0fc0;
2268 case 0x10: /* SR3 */
2269 s->setup[2] = value & 0x0003;
2272 case 0x14: /* SR4 */
2273 s->setup[3] = value & 0x0001;
2276 case 0x18: /* SR5 */
2277 s->setup[4] = value & 0x000f;
2286 static const MemoryRegionOps omap_uwire_ops = {
2287 .read = omap_uwire_read,
2288 .write = omap_uwire_write,
2289 .endianness = DEVICE_NATIVE_ENDIAN,
2292 static void omap_uwire_reset(struct omap_uwire_s *s)
2302 static struct omap_uwire_s *omap_uwire_init(MemoryRegion *system_memory,
2304 qemu_irq txirq, qemu_irq rxirq,
2308 struct omap_uwire_s *s = g_new0(struct omap_uwire_s, 1);
2313 omap_uwire_reset(s);
2315 memory_region_init_io(&s->iomem, NULL, &omap_uwire_ops, s, "omap-uwire", 0x800);
2316 memory_region_add_subregion(system_memory, base, &s->iomem);
2321 void omap_uwire_attach(struct omap_uwire_s *s,
2322 uWireSlave *slave, int chipselect)
2324 if (chipselect < 0 || chipselect > 3) {
2325 error_report("%s: Bad chipselect %i", __func__, chipselect);
2329 s->chip[chipselect] = slave;
2332 /* Pseudonoise Pulse-Width Light Modulator */
2341 static void omap_pwl_update(struct omap_pwl_s *s)
2343 int output = (s->clk && s->enable) ? s->level : 0;
2345 if (output != s->output) {
2347 printf("%s: Backlight now at %i/256\n", __func__, output);
2351 static uint64_t omap_pwl_read(void *opaque, hwaddr addr,
2354 struct omap_pwl_s *s = (struct omap_pwl_s *) opaque;
2355 int offset = addr & OMAP_MPUI_REG_MASK;
2358 return omap_badwidth_read8(opaque, addr);
2362 case 0x00: /* PWL_LEVEL */
2364 case 0x04: /* PWL_CTRL */
2371 static void omap_pwl_write(void *opaque, hwaddr addr,
2372 uint64_t value, unsigned size)
2374 struct omap_pwl_s *s = (struct omap_pwl_s *) opaque;
2375 int offset = addr & OMAP_MPUI_REG_MASK;
2378 omap_badwidth_write8(opaque, addr, value);
2383 case 0x00: /* PWL_LEVEL */
2387 case 0x04: /* PWL_CTRL */
2388 s->enable = value & 1;
2397 static const MemoryRegionOps omap_pwl_ops = {
2398 .read = omap_pwl_read,
2399 .write = omap_pwl_write,
2400 .endianness = DEVICE_NATIVE_ENDIAN,
2403 static void omap_pwl_reset(struct omap_pwl_s *s)
2412 static void omap_pwl_clk_update(void *opaque, int line, int on)
2414 struct omap_pwl_s *s = (struct omap_pwl_s *) opaque;
2420 static struct omap_pwl_s *omap_pwl_init(MemoryRegion *system_memory,
2424 struct omap_pwl_s *s = g_malloc0(sizeof(*s));
2428 memory_region_init_io(&s->iomem, NULL, &omap_pwl_ops, s,
2430 memory_region_add_subregion(system_memory, base, &s->iomem);
2432 omap_clk_adduser(clk, qemu_allocate_irq(omap_pwl_clk_update, s, 0));
2436 /* Pulse-Width Tone module */
2445 static uint64_t omap_pwt_read(void *opaque, hwaddr addr,
2448 struct omap_pwt_s *s = (struct omap_pwt_s *) opaque;
2449 int offset = addr & OMAP_MPUI_REG_MASK;
2452 return omap_badwidth_read8(opaque, addr);
2456 case 0x00: /* FRC */
2458 case 0x04: /* VCR */
2460 case 0x08: /* GCR */
2467 static void omap_pwt_write(void *opaque, hwaddr addr,
2468 uint64_t value, unsigned size)
2470 struct omap_pwt_s *s = (struct omap_pwt_s *) opaque;
2471 int offset = addr & OMAP_MPUI_REG_MASK;
2474 omap_badwidth_write8(opaque, addr, value);
2479 case 0x00: /* FRC */
2480 s->frc = value & 0x3f;
2482 case 0x04: /* VRC */
2483 if ((value ^ s->vrc) & 1) {
2485 printf("%s: %iHz buzz on\n", __func__, (int)
2486 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2487 ((omap_clk_getrate(s->clk) >> 3) /
2488 /* Pre-multiplexer divider */
2489 ((s->gcr & 2) ? 1 : 154) /
2490 /* Octave multiplexer */
2491 (2 << (value & 3)) *
2492 /* 101/107 divider */
2493 ((value & (1 << 2)) ? 101 : 107) *
2495 ((value & (1 << 3)) ? 49 : 55) *
2497 ((value & (1 << 4)) ? 50 : 63) *
2498 /* 80/127 divider */
2499 ((value & (1 << 5)) ? 80 : 127) /
2500 (107 * 55 * 63 * 127)));
2502 printf("%s: silence!\n", __func__);
2504 s->vrc = value & 0x7f;
2506 case 0x08: /* GCR */
2515 static const MemoryRegionOps omap_pwt_ops = {
2516 .read =omap_pwt_read,
2517 .write = omap_pwt_write,
2518 .endianness = DEVICE_NATIVE_ENDIAN,
2521 static void omap_pwt_reset(struct omap_pwt_s *s)
2528 static struct omap_pwt_s *omap_pwt_init(MemoryRegion *system_memory,
2532 struct omap_pwt_s *s = g_malloc0(sizeof(*s));
2536 memory_region_init_io(&s->iomem, NULL, &omap_pwt_ops, s,
2538 memory_region_add_subregion(system_memory, base, &s->iomem);
2542 /* Real-time Clock module */
2559 struct tm current_tm;
2564 static void omap_rtc_interrupts_update(struct omap_rtc_s *s)
2566 /* s->alarm is level-triggered */
2567 qemu_set_irq(s->alarm, (s->status >> 6) & 1);
2570 static void omap_rtc_alarm_update(struct omap_rtc_s *s)
2572 s->alarm_ti = mktimegm(&s->alarm_tm);
2573 if (s->alarm_ti == -1)
2574 printf("%s: conversion failed\n", __func__);
2577 static uint64_t omap_rtc_read(void *opaque, hwaddr addr,
2580 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
2581 int offset = addr & OMAP_MPUI_REG_MASK;
2585 return omap_badwidth_read8(opaque, addr);
2589 case 0x00: /* SECONDS_REG */
2590 return to_bcd(s->current_tm.tm_sec);
2592 case 0x04: /* MINUTES_REG */
2593 return to_bcd(s->current_tm.tm_min);
2595 case 0x08: /* HOURS_REG */
2597 return ((s->current_tm.tm_hour > 11) << 7) |
2598 to_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
2600 return to_bcd(s->current_tm.tm_hour);
2602 case 0x0c: /* DAYS_REG */
2603 return to_bcd(s->current_tm.tm_mday);
2605 case 0x10: /* MONTHS_REG */
2606 return to_bcd(s->current_tm.tm_mon + 1);
2608 case 0x14: /* YEARS_REG */
2609 return to_bcd(s->current_tm.tm_year % 100);
2611 case 0x18: /* WEEK_REG */
2612 return s->current_tm.tm_wday;
2614 case 0x20: /* ALARM_SECONDS_REG */
2615 return to_bcd(s->alarm_tm.tm_sec);
2617 case 0x24: /* ALARM_MINUTES_REG */
2618 return to_bcd(s->alarm_tm.tm_min);
2620 case 0x28: /* ALARM_HOURS_REG */
2622 return ((s->alarm_tm.tm_hour > 11) << 7) |
2623 to_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
2625 return to_bcd(s->alarm_tm.tm_hour);
2627 case 0x2c: /* ALARM_DAYS_REG */
2628 return to_bcd(s->alarm_tm.tm_mday);
2630 case 0x30: /* ALARM_MONTHS_REG */
2631 return to_bcd(s->alarm_tm.tm_mon + 1);
2633 case 0x34: /* ALARM_YEARS_REG */
2634 return to_bcd(s->alarm_tm.tm_year % 100);
2636 case 0x40: /* RTC_CTRL_REG */
2637 return (s->pm_am << 3) | (s->auto_comp << 2) |
2638 (s->round << 1) | s->running;
2640 case 0x44: /* RTC_STATUS_REG */
2645 case 0x48: /* RTC_INTERRUPTS_REG */
2646 return s->interrupts;
2648 case 0x4c: /* RTC_COMP_LSB_REG */
2649 return ((uint16_t) s->comp_reg) & 0xff;
2651 case 0x50: /* RTC_COMP_MSB_REG */
2652 return ((uint16_t) s->comp_reg) >> 8;
2659 static void omap_rtc_write(void *opaque, hwaddr addr,
2660 uint64_t value, unsigned size)
2662 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
2663 int offset = addr & OMAP_MPUI_REG_MASK;
2668 omap_badwidth_write8(opaque, addr, value);
2673 case 0x00: /* SECONDS_REG */
2675 printf("RTC SEC_REG <-- %02x\n", value);
2677 s->ti -= s->current_tm.tm_sec;
2678 s->ti += from_bcd(value);
2681 case 0x04: /* MINUTES_REG */
2683 printf("RTC MIN_REG <-- %02x\n", value);
2685 s->ti -= s->current_tm.tm_min * 60;
2686 s->ti += from_bcd(value) * 60;
2689 case 0x08: /* HOURS_REG */
2691 printf("RTC HRS_REG <-- %02x\n", value);
2693 s->ti -= s->current_tm.tm_hour * 3600;
2695 s->ti += (from_bcd(value & 0x3f) & 12) * 3600;
2696 s->ti += ((value >> 7) & 1) * 43200;
2698 s->ti += from_bcd(value & 0x3f) * 3600;
2701 case 0x0c: /* DAYS_REG */
2703 printf("RTC DAY_REG <-- %02x\n", value);
2705 s->ti -= s->current_tm.tm_mday * 86400;
2706 s->ti += from_bcd(value) * 86400;
2709 case 0x10: /* MONTHS_REG */
2711 printf("RTC MTH_REG <-- %02x\n", value);
2713 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
2714 new_tm.tm_mon = from_bcd(value);
2715 ti[0] = mktimegm(&s->current_tm);
2716 ti[1] = mktimegm(&new_tm);
2718 if (ti[0] != -1 && ti[1] != -1) {
2722 /* A less accurate version */
2723 s->ti -= s->current_tm.tm_mon * 2592000;
2724 s->ti += from_bcd(value) * 2592000;
2728 case 0x14: /* YEARS_REG */
2730 printf("RTC YRS_REG <-- %02x\n", value);
2732 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
2733 new_tm.tm_year += from_bcd(value) - (new_tm.tm_year % 100);
2734 ti[0] = mktimegm(&s->current_tm);
2735 ti[1] = mktimegm(&new_tm);
2737 if (ti[0] != -1 && ti[1] != -1) {
2741 /* A less accurate version */
2742 s->ti -= (time_t)(s->current_tm.tm_year % 100) * 31536000;
2743 s->ti += (time_t)from_bcd(value) * 31536000;
2747 case 0x18: /* WEEK_REG */
2748 return; /* Ignored */
2750 case 0x20: /* ALARM_SECONDS_REG */
2752 printf("ALM SEC_REG <-- %02x\n", value);
2754 s->alarm_tm.tm_sec = from_bcd(value);
2755 omap_rtc_alarm_update(s);
2758 case 0x24: /* ALARM_MINUTES_REG */
2760 printf("ALM MIN_REG <-- %02x\n", value);
2762 s->alarm_tm.tm_min = from_bcd(value);
2763 omap_rtc_alarm_update(s);
2766 case 0x28: /* ALARM_HOURS_REG */
2768 printf("ALM HRS_REG <-- %02x\n", value);
2771 s->alarm_tm.tm_hour =
2772 ((from_bcd(value & 0x3f)) % 12) +
2773 ((value >> 7) & 1) * 12;
2775 s->alarm_tm.tm_hour = from_bcd(value);
2776 omap_rtc_alarm_update(s);
2779 case 0x2c: /* ALARM_DAYS_REG */
2781 printf("ALM DAY_REG <-- %02x\n", value);
2783 s->alarm_tm.tm_mday = from_bcd(value);
2784 omap_rtc_alarm_update(s);
2787 case 0x30: /* ALARM_MONTHS_REG */
2789 printf("ALM MON_REG <-- %02x\n", value);
2791 s->alarm_tm.tm_mon = from_bcd(value);
2792 omap_rtc_alarm_update(s);
2795 case 0x34: /* ALARM_YEARS_REG */
2797 printf("ALM YRS_REG <-- %02x\n", value);
2799 s->alarm_tm.tm_year = from_bcd(value);
2800 omap_rtc_alarm_update(s);
2803 case 0x40: /* RTC_CTRL_REG */
2805 printf("RTC CONTROL <-- %02x\n", value);
2807 s->pm_am = (value >> 3) & 1;
2808 s->auto_comp = (value >> 2) & 1;
2809 s->round = (value >> 1) & 1;
2810 s->running = value & 1;
2812 s->status |= s->running << 1;
2815 case 0x44: /* RTC_STATUS_REG */
2817 printf("RTC STATUSL <-- %02x\n", value);
2819 s->status &= ~((value & 0xc0) ^ 0x80);
2820 omap_rtc_interrupts_update(s);
2823 case 0x48: /* RTC_INTERRUPTS_REG */
2825 printf("RTC INTRS <-- %02x\n", value);
2827 s->interrupts = value;
2830 case 0x4c: /* RTC_COMP_LSB_REG */
2832 printf("RTC COMPLSB <-- %02x\n", value);
2834 s->comp_reg &= 0xff00;
2835 s->comp_reg |= 0x00ff & value;
2838 case 0x50: /* RTC_COMP_MSB_REG */
2840 printf("RTC COMPMSB <-- %02x\n", value);
2842 s->comp_reg &= 0x00ff;
2843 s->comp_reg |= 0xff00 & (value << 8);
2852 static const MemoryRegionOps omap_rtc_ops = {
2853 .read = omap_rtc_read,
2854 .write = omap_rtc_write,
2855 .endianness = DEVICE_NATIVE_ENDIAN,
2858 static void omap_rtc_tick(void *opaque)
2860 struct omap_rtc_s *s = opaque;
2863 /* Round to nearest full minute. */
2864 if (s->current_tm.tm_sec < 30)
2865 s->ti -= s->current_tm.tm_sec;
2867 s->ti += 60 - s->current_tm.tm_sec;
2872 localtime_r(&s->ti, &s->current_tm);
2874 if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) {
2876 omap_rtc_interrupts_update(s);
2879 if (s->interrupts & 0x04)
2880 switch (s->interrupts & 3) {
2883 qemu_irq_pulse(s->irq);
2886 if (s->current_tm.tm_sec)
2889 qemu_irq_pulse(s->irq);
2892 if (s->current_tm.tm_sec || s->current_tm.tm_min)
2895 qemu_irq_pulse(s->irq);
2898 if (s->current_tm.tm_sec ||
2899 s->current_tm.tm_min || s->current_tm.tm_hour)
2902 qemu_irq_pulse(s->irq);
2912 * Every full hour add a rough approximation of the compensation
2913 * register to the 32kHz Timer (which drives the RTC) value.
2915 if (s->auto_comp && !s->current_tm.tm_sec && !s->current_tm.tm_min)
2916 s->tick += s->comp_reg * 1000 / 32768;
2918 timer_mod(s->clk, s->tick);
2921 static void omap_rtc_reset(struct omap_rtc_s *s)
2931 s->tick = qemu_clock_get_ms(rtc_clock);
2932 memset(&s->alarm_tm, 0, sizeof(s->alarm_tm));
2933 s->alarm_tm.tm_mday = 0x01;
2935 qemu_get_timedate(&tm, 0);
2936 s->ti = mktimegm(&tm);
2938 omap_rtc_alarm_update(s);
2942 static struct omap_rtc_s *omap_rtc_init(MemoryRegion *system_memory,
2944 qemu_irq timerirq, qemu_irq alarmirq,
2947 struct omap_rtc_s *s = g_new0(struct omap_rtc_s, 1);
2950 s->alarm = alarmirq;
2951 s->clk = timer_new_ms(rtc_clock, omap_rtc_tick, s);
2955 memory_region_init_io(&s->iomem, NULL, &omap_rtc_ops, s,
2957 memory_region_add_subregion(system_memory, base, &s->iomem);
2962 /* Multi-channel Buffered Serial Port interfaces */
2963 struct omap_mcbsp_s {
2984 QEMUTimer *source_timer;
2985 QEMUTimer *sink_timer;
2988 static void omap_mcbsp_intr_update(struct omap_mcbsp_s *s)
2992 switch ((s->spcr[0] >> 4) & 3) { /* RINTM */
2994 irq = (s->spcr[0] >> 1) & 1; /* RRDY */
2997 irq = (s->spcr[0] >> 3) & 1; /* RSYNCERR */
3005 qemu_irq_pulse(s->rxirq);
3007 switch ((s->spcr[1] >> 4) & 3) { /* XINTM */
3009 irq = (s->spcr[1] >> 1) & 1; /* XRDY */
3012 irq = (s->spcr[1] >> 3) & 1; /* XSYNCERR */
3020 qemu_irq_pulse(s->txirq);
3023 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s *s)
3025 if ((s->spcr[0] >> 1) & 1) /* RRDY */
3026 s->spcr[0] |= 1 << 2; /* RFULL */
3027 s->spcr[0] |= 1 << 1; /* RRDY */
3028 qemu_irq_raise(s->rxdrq);
3029 omap_mcbsp_intr_update(s);
3032 static void omap_mcbsp_source_tick(void *opaque)
3034 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3035 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3040 printf("%s: Rx FIFO overrun\n", __func__);
3042 s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7];
3044 omap_mcbsp_rx_newdata(s);
3045 timer_mod(s->source_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
3046 NANOSECONDS_PER_SECOND);
3049 static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s)
3051 if (!s->codec || !s->codec->rts)
3052 omap_mcbsp_source_tick(s);
3053 else if (s->codec->in.len) {
3054 s->rx_req = s->codec->in.len;
3055 omap_mcbsp_rx_newdata(s);
3059 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s *s)
3061 timer_del(s->source_timer);
3064 static void omap_mcbsp_rx_done(struct omap_mcbsp_s *s)
3066 s->spcr[0] &= ~(1 << 1); /* RRDY */
3067 qemu_irq_lower(s->rxdrq);
3068 omap_mcbsp_intr_update(s);
3071 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s *s)
3073 s->spcr[1] |= 1 << 1; /* XRDY */
3074 qemu_irq_raise(s->txdrq);
3075 omap_mcbsp_intr_update(s);
3078 static void omap_mcbsp_sink_tick(void *opaque)
3080 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3081 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3086 printf("%s: Tx FIFO underrun\n", __func__);
3088 s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7];
3090 omap_mcbsp_tx_newdata(s);
3091 timer_mod(s->sink_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
3092 NANOSECONDS_PER_SECOND);
3095 static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s)
3097 if (!s->codec || !s->codec->cts)
3098 omap_mcbsp_sink_tick(s);
3099 else if (s->codec->out.size) {
3100 s->tx_req = s->codec->out.size;
3101 omap_mcbsp_tx_newdata(s);
3105 static void omap_mcbsp_tx_done(struct omap_mcbsp_s *s)
3107 s->spcr[1] &= ~(1 << 1); /* XRDY */
3108 qemu_irq_lower(s->txdrq);
3109 omap_mcbsp_intr_update(s);
3110 if (s->codec && s->codec->cts)
3111 s->codec->tx_swallow(s->codec->opaque);
3114 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s *s)
3117 omap_mcbsp_tx_done(s);
3118 timer_del(s->sink_timer);
3121 static void omap_mcbsp_req_update(struct omap_mcbsp_s *s)
3123 int prev_rx_rate, prev_tx_rate;
3124 int rx_rate = 0, tx_rate = 0;
3125 int cpu_rate = 1500000; /* XXX */
3127 /* TODO: check CLKSTP bit */
3128 if (s->spcr[1] & (1 << 6)) { /* GRST */
3129 if (s->spcr[0] & (1 << 0)) { /* RRST */
3130 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3131 (s->pcr & (1 << 8))) { /* CLKRM */
3132 if (~s->pcr & (1 << 7)) /* SCLKME */
3133 rx_rate = cpu_rate /
3134 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3137 rx_rate = s->codec->rx_rate;
3140 if (s->spcr[1] & (1 << 0)) { /* XRST */
3141 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3142 (s->pcr & (1 << 9))) { /* CLKXM */
3143 if (~s->pcr & (1 << 7)) /* SCLKME */
3144 tx_rate = cpu_rate /
3145 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3148 tx_rate = s->codec->tx_rate;
3151 prev_tx_rate = s->tx_rate;
3152 prev_rx_rate = s->rx_rate;
3153 s->tx_rate = tx_rate;
3154 s->rx_rate = rx_rate;
3157 s->codec->set_rate(s->codec->opaque, rx_rate, tx_rate);
3159 if (!prev_tx_rate && tx_rate)
3160 omap_mcbsp_tx_start(s);
3161 else if (s->tx_rate && !tx_rate)
3162 omap_mcbsp_tx_stop(s);
3164 if (!prev_rx_rate && rx_rate)
3165 omap_mcbsp_rx_start(s);
3166 else if (prev_tx_rate && !tx_rate)
3167 omap_mcbsp_rx_stop(s);
3170 static uint64_t omap_mcbsp_read(void *opaque, hwaddr addr,
3173 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3174 int offset = addr & OMAP_MPUI_REG_MASK;
3178 return omap_badwidth_read16(opaque, addr);
3182 case 0x00: /* DRR2 */
3183 if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */
3186 case 0x02: /* DRR1 */
3187 if (s->rx_req < 2) {
3188 printf("%s: Rx FIFO underrun\n", __func__);
3189 omap_mcbsp_rx_done(s);
3192 if (s->codec && s->codec->in.len >= 2) {
3193 ret = s->codec->in.fifo[s->codec->in.start ++] << 8;
3194 ret |= s->codec->in.fifo[s->codec->in.start ++];
3195 s->codec->in.len -= 2;
3199 omap_mcbsp_rx_done(s);
3204 case 0x04: /* DXR2 */
3205 case 0x06: /* DXR1 */
3208 case 0x08: /* SPCR2 */
3210 case 0x0a: /* SPCR1 */
3212 case 0x0c: /* RCR2 */
3214 case 0x0e: /* RCR1 */
3216 case 0x10: /* XCR2 */
3218 case 0x12: /* XCR1 */
3220 case 0x14: /* SRGR2 */
3222 case 0x16: /* SRGR1 */
3224 case 0x18: /* MCR2 */
3226 case 0x1a: /* MCR1 */
3228 case 0x1c: /* RCERA */
3230 case 0x1e: /* RCERB */
3232 case 0x20: /* XCERA */
3234 case 0x22: /* XCERB */
3236 case 0x24: /* PCR0 */
3238 case 0x26: /* RCERC */
3240 case 0x28: /* RCERD */
3242 case 0x2a: /* XCERC */
3244 case 0x2c: /* XCERD */
3246 case 0x2e: /* RCERE */
3248 case 0x30: /* RCERF */
3250 case 0x32: /* XCERE */
3252 case 0x34: /* XCERF */
3254 case 0x36: /* RCERG */
3256 case 0x38: /* RCERH */
3258 case 0x3a: /* XCERG */
3260 case 0x3c: /* XCERH */
3268 static void omap_mcbsp_writeh(void *opaque, hwaddr addr,
3271 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3272 int offset = addr & OMAP_MPUI_REG_MASK;
3275 case 0x00: /* DRR2 */
3276 case 0x02: /* DRR1 */
3280 case 0x04: /* DXR2 */
3281 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
3284 case 0x06: /* DXR1 */
3285 if (s->tx_req > 1) {
3287 if (s->codec && s->codec->cts) {
3288 s->codec->out.fifo[s->codec->out.len ++] = (value >> 8) & 0xff;
3289 s->codec->out.fifo[s->codec->out.len ++] = (value >> 0) & 0xff;
3292 omap_mcbsp_tx_done(s);
3294 printf("%s: Tx FIFO overrun\n", __func__);
3297 case 0x08: /* SPCR2 */
3298 s->spcr[1] &= 0x0002;
3299 s->spcr[1] |= 0x03f9 & value;
3300 s->spcr[1] |= 0x0004 & (value << 2); /* XEMPTY := XRST */
3301 if (~value & 1) /* XRST */
3303 omap_mcbsp_req_update(s);
3305 case 0x0a: /* SPCR1 */
3306 s->spcr[0] &= 0x0006;
3307 s->spcr[0] |= 0xf8f9 & value;
3308 if (value & (1 << 15)) /* DLB */
3309 printf("%s: Digital Loopback mode enable attempt\n", __func__);
3310 if (~value & 1) { /* RRST */
3313 omap_mcbsp_rx_done(s);
3315 omap_mcbsp_req_update(s);
3318 case 0x0c: /* RCR2 */
3319 s->rcr[1] = value & 0xffff;
3321 case 0x0e: /* RCR1 */
3322 s->rcr[0] = value & 0x7fe0;
3324 case 0x10: /* XCR2 */
3325 s->xcr[1] = value & 0xffff;
3327 case 0x12: /* XCR1 */
3328 s->xcr[0] = value & 0x7fe0;
3330 case 0x14: /* SRGR2 */
3331 s->srgr[1] = value & 0xffff;
3332 omap_mcbsp_req_update(s);
3334 case 0x16: /* SRGR1 */
3335 s->srgr[0] = value & 0xffff;
3336 omap_mcbsp_req_update(s);
3338 case 0x18: /* MCR2 */
3339 s->mcr[1] = value & 0x03e3;
3340 if (value & 3) /* XMCM */
3341 printf("%s: Tx channel selection mode enable attempt\n", __func__);
3343 case 0x1a: /* MCR1 */
3344 s->mcr[0] = value & 0x03e1;
3345 if (value & 1) /* RMCM */
3346 printf("%s: Rx channel selection mode enable attempt\n", __func__);
3348 case 0x1c: /* RCERA */
3349 s->rcer[0] = value & 0xffff;
3351 case 0x1e: /* RCERB */
3352 s->rcer[1] = value & 0xffff;
3354 case 0x20: /* XCERA */
3355 s->xcer[0] = value & 0xffff;
3357 case 0x22: /* XCERB */
3358 s->xcer[1] = value & 0xffff;
3360 case 0x24: /* PCR0 */
3361 s->pcr = value & 0x7faf;
3363 case 0x26: /* RCERC */
3364 s->rcer[2] = value & 0xffff;
3366 case 0x28: /* RCERD */
3367 s->rcer[3] = value & 0xffff;
3369 case 0x2a: /* XCERC */
3370 s->xcer[2] = value & 0xffff;
3372 case 0x2c: /* XCERD */
3373 s->xcer[3] = value & 0xffff;
3375 case 0x2e: /* RCERE */
3376 s->rcer[4] = value & 0xffff;
3378 case 0x30: /* RCERF */
3379 s->rcer[5] = value & 0xffff;
3381 case 0x32: /* XCERE */
3382 s->xcer[4] = value & 0xffff;
3384 case 0x34: /* XCERF */
3385 s->xcer[5] = value & 0xffff;
3387 case 0x36: /* RCERG */
3388 s->rcer[6] = value & 0xffff;
3390 case 0x38: /* RCERH */
3391 s->rcer[7] = value & 0xffff;
3393 case 0x3a: /* XCERG */
3394 s->xcer[6] = value & 0xffff;
3396 case 0x3c: /* XCERH */
3397 s->xcer[7] = value & 0xffff;
3404 static void omap_mcbsp_writew(void *opaque, hwaddr addr,
3407 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3408 int offset = addr & OMAP_MPUI_REG_MASK;
3410 if (offset == 0x04) { /* DXR */
3411 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
3413 if (s->tx_req > 3) {
3415 if (s->codec && s->codec->cts) {
3416 s->codec->out.fifo[s->codec->out.len ++] =
3417 (value >> 24) & 0xff;
3418 s->codec->out.fifo[s->codec->out.len ++] =
3419 (value >> 16) & 0xff;
3420 s->codec->out.fifo[s->codec->out.len ++] =
3421 (value >> 8) & 0xff;
3422 s->codec->out.fifo[s->codec->out.len ++] =
3423 (value >> 0) & 0xff;
3426 omap_mcbsp_tx_done(s);
3428 printf("%s: Tx FIFO overrun\n", __func__);
3432 omap_badwidth_write16(opaque, addr, value);
3435 static void omap_mcbsp_write(void *opaque, hwaddr addr,
3436 uint64_t value, unsigned size)
3440 omap_mcbsp_writeh(opaque, addr, value);
3443 omap_mcbsp_writew(opaque, addr, value);
3446 omap_badwidth_write16(opaque, addr, value);
3450 static const MemoryRegionOps omap_mcbsp_ops = {
3451 .read = omap_mcbsp_read,
3452 .write = omap_mcbsp_write,
3453 .endianness = DEVICE_NATIVE_ENDIAN,
3456 static void omap_mcbsp_reset(struct omap_mcbsp_s *s)
3458 memset(&s->spcr, 0, sizeof(s->spcr));
3459 memset(&s->rcr, 0, sizeof(s->rcr));
3460 memset(&s->xcr, 0, sizeof(s->xcr));
3461 s->srgr[0] = 0x0001;
3462 s->srgr[1] = 0x2000;
3463 memset(&s->mcr, 0, sizeof(s->mcr));
3464 memset(&s->pcr, 0, sizeof(s->pcr));
3465 memset(&s->rcer, 0, sizeof(s->rcer));
3466 memset(&s->xcer, 0, sizeof(s->xcer));
3471 timer_del(s->source_timer);
3472 timer_del(s->sink_timer);
3475 static struct omap_mcbsp_s *omap_mcbsp_init(MemoryRegion *system_memory,
3477 qemu_irq txirq, qemu_irq rxirq,
3478 qemu_irq *dma, omap_clk clk)
3480 struct omap_mcbsp_s *s = g_new0(struct omap_mcbsp_s, 1);
3486 s->sink_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, omap_mcbsp_sink_tick, s);
3487 s->source_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, omap_mcbsp_source_tick, s);
3488 omap_mcbsp_reset(s);
3490 memory_region_init_io(&s->iomem, NULL, &omap_mcbsp_ops, s, "omap-mcbsp", 0x800);
3491 memory_region_add_subregion(system_memory, base, &s->iomem);
3496 static void omap_mcbsp_i2s_swallow(void *opaque, int line, int level)
3498 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3501 s->rx_req = s->codec->in.len;
3502 omap_mcbsp_rx_newdata(s);
3506 static void omap_mcbsp_i2s_start(void *opaque, int line, int level)
3508 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3511 s->tx_req = s->codec->out.size;
3512 omap_mcbsp_tx_newdata(s);
3516 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, I2SCodec *slave)
3519 slave->rx_swallow = qemu_allocate_irq(omap_mcbsp_i2s_swallow, s, 0);
3520 slave->tx_start = qemu_allocate_irq(omap_mcbsp_i2s_start, s, 0);
3523 /* LED Pulse Generators */
3536 static void omap_lpg_tick(void *opaque)
3538 struct omap_lpg_s *s = opaque;
3541 timer_mod(s->tm, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + s->period - s->on);
3543 timer_mod(s->tm, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + s->on);
3545 s->cycle = !s->cycle;
3546 printf("%s: LED is %s\n", __func__, s->cycle ? "on" : "off");
3549 static void omap_lpg_update(struct omap_lpg_s *s)
3551 int64_t on, period = 1, ticks = 1000;
3552 static const int per[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3554 if (~s->control & (1 << 6)) /* LPGRES */
3556 else if (s->control & (1 << 7)) /* PERM_ON */
3559 period = muldiv64(ticks, per[s->control & 7], /* PERCTRL */
3561 on = (s->clk && s->power) ? muldiv64(ticks,
3562 per[(s->control >> 3) & 7], 256) : 0; /* ONCTRL */
3566 if (on == period && s->on < s->period)
3567 printf("%s: LED is on\n", __func__);
3568 else if (on == 0 && s->on)
3569 printf("%s: LED is off\n", __func__);
3570 else if (on && (on != s->on || period != s->period)) {
3582 static void omap_lpg_reset(struct omap_lpg_s *s)
3590 static uint64_t omap_lpg_read(void *opaque, hwaddr addr,
3593 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3594 int offset = addr & OMAP_MPUI_REG_MASK;
3597 return omap_badwidth_read8(opaque, addr);
3601 case 0x00: /* LCR */
3604 case 0x04: /* PMR */
3612 static void omap_lpg_write(void *opaque, hwaddr addr,
3613 uint64_t value, unsigned size)
3615 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3616 int offset = addr & OMAP_MPUI_REG_MASK;
3619 omap_badwidth_write8(opaque, addr, value);
3624 case 0x00: /* LCR */
3625 if (~value & (1 << 6)) /* LPGRES */
3627 s->control = value & 0xff;
3631 case 0x04: /* PMR */
3632 s->power = value & 0x01;
3642 static const MemoryRegionOps omap_lpg_ops = {
3643 .read = omap_lpg_read,
3644 .write = omap_lpg_write,
3645 .endianness = DEVICE_NATIVE_ENDIAN,
3648 static void omap_lpg_clk_update(void *opaque, int line, int on)
3650 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
3656 static struct omap_lpg_s *omap_lpg_init(MemoryRegion *system_memory,
3657 hwaddr base, omap_clk clk)
3659 struct omap_lpg_s *s = g_new0(struct omap_lpg_s, 1);
3661 s->tm = timer_new_ms(QEMU_CLOCK_VIRTUAL, omap_lpg_tick, s);
3665 memory_region_init_io(&s->iomem, NULL, &omap_lpg_ops, s, "omap-lpg", 0x800);
3666 memory_region_add_subregion(system_memory, base, &s->iomem);
3668 omap_clk_adduser(clk, qemu_allocate_irq(omap_lpg_clk_update, s, 0));
3673 /* MPUI Peripheral Bridge configuration */
3674 static uint64_t omap_mpui_io_read(void *opaque, hwaddr addr,
3678 return omap_badwidth_read16(opaque, addr);
3681 if (addr == OMAP_MPUI_BASE) /* CMR */
3688 static void omap_mpui_io_write(void *opaque, hwaddr addr,
3689 uint64_t value, unsigned size)
3691 /* FIXME: infinite loop */
3692 omap_badwidth_write16(opaque, addr, value);
3695 static const MemoryRegionOps omap_mpui_io_ops = {
3696 .read = omap_mpui_io_read,
3697 .write = omap_mpui_io_write,
3698 .endianness = DEVICE_NATIVE_ENDIAN,
3701 static void omap_setup_mpui_io(MemoryRegion *system_memory,
3702 struct omap_mpu_state_s *mpu)
3704 memory_region_init_io(&mpu->mpui_io_iomem, NULL, &omap_mpui_io_ops, mpu,
3705 "omap-mpui-io", 0x7fff);
3706 memory_region_add_subregion(system_memory, OMAP_MPUI_BASE,
3707 &mpu->mpui_io_iomem);
3710 /* General chip reset */
3711 static void omap1_mpu_reset(void *opaque)
3713 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
3715 omap_dma_reset(mpu->dma);
3716 omap_mpu_timer_reset(mpu->timer[0]);
3717 omap_mpu_timer_reset(mpu->timer[1]);
3718 omap_mpu_timer_reset(mpu->timer[2]);
3719 omap_wd_timer_reset(mpu->wdt);
3720 omap_os_timer_reset(mpu->os_timer);
3721 omap_lcdc_reset(mpu->lcd);
3722 omap_ulpd_pm_reset(mpu);
3723 omap_pin_cfg_reset(mpu);
3724 omap_mpui_reset(mpu);
3725 omap_tipb_bridge_reset(mpu->private_tipb);
3726 omap_tipb_bridge_reset(mpu->public_tipb);
3727 omap_dpll_reset(mpu->dpll[0]);
3728 omap_dpll_reset(mpu->dpll[1]);
3729 omap_dpll_reset(mpu->dpll[2]);
3730 omap_uart_reset(mpu->uart[0]);
3731 omap_uart_reset(mpu->uart[1]);
3732 omap_uart_reset(mpu->uart[2]);
3733 omap_mmc_reset(mpu->mmc);
3734 omap_mpuio_reset(mpu->mpuio);
3735 omap_uwire_reset(mpu->microwire);
3736 omap_pwl_reset(mpu->pwl);
3737 omap_pwt_reset(mpu->pwt);
3738 omap_rtc_reset(mpu->rtc);
3739 omap_mcbsp_reset(mpu->mcbsp1);
3740 omap_mcbsp_reset(mpu->mcbsp2);
3741 omap_mcbsp_reset(mpu->mcbsp3);
3742 omap_lpg_reset(mpu->led[0]);
3743 omap_lpg_reset(mpu->led[1]);
3744 omap_clkm_reset(mpu);
3745 cpu_reset(CPU(mpu->cpu));
3748 static const struct omap_map_s {
3753 } omap15xx_dsp_mm[] = {
3755 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
3756 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
3757 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
3758 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
3759 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
3760 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
3761 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
3762 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
3763 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
3764 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
3765 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
3766 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
3767 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
3768 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
3769 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
3770 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
3771 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
3773 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
3778 static void omap_setup_dsp_mapping(MemoryRegion *system_memory,
3779 const struct omap_map_s *map)
3783 for (; map->phys_dsp; map ++) {
3784 io = g_new(MemoryRegion, 1);
3785 memory_region_init_alias(io, NULL, map->name,
3786 system_memory, map->phys_mpu, map->size);
3787 memory_region_add_subregion(system_memory, map->phys_dsp, io);
3791 void omap_mpu_wakeup(void *opaque, int irq, int req)
3793 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
3794 CPUState *cpu = CPU(mpu->cpu);
3797 cpu_interrupt(cpu, CPU_INTERRUPT_EXITTB);
3801 static const struct dma_irq_map omap1_dma_irq_map[] = {
3802 { 0, OMAP_INT_DMA_CH0_6 },
3803 { 0, OMAP_INT_DMA_CH1_7 },
3804 { 0, OMAP_INT_DMA_CH2_8 },
3805 { 0, OMAP_INT_DMA_CH3 },
3806 { 0, OMAP_INT_DMA_CH4 },
3807 { 0, OMAP_INT_DMA_CH5 },
3808 { 1, OMAP_INT_1610_DMA_CH6 },
3809 { 1, OMAP_INT_1610_DMA_CH7 },
3810 { 1, OMAP_INT_1610_DMA_CH8 },
3811 { 1, OMAP_INT_1610_DMA_CH9 },
3812 { 1, OMAP_INT_1610_DMA_CH10 },
3813 { 1, OMAP_INT_1610_DMA_CH11 },
3814 { 1, OMAP_INT_1610_DMA_CH12 },
3815 { 1, OMAP_INT_1610_DMA_CH13 },
3816 { 1, OMAP_INT_1610_DMA_CH14 },
3817 { 1, OMAP_INT_1610_DMA_CH15 }
3820 /* DMA ports for OMAP1 */
3821 static int omap_validate_emiff_addr(struct omap_mpu_state_s *s,
3824 return range_covers_byte(OMAP_EMIFF_BASE, s->sdram_size, addr);
3827 static int omap_validate_emifs_addr(struct omap_mpu_state_s *s,
3830 return range_covers_byte(OMAP_EMIFS_BASE, OMAP_EMIFF_BASE - OMAP_EMIFS_BASE,
3834 static int omap_validate_imif_addr(struct omap_mpu_state_s *s,
3837 return range_covers_byte(OMAP_IMIF_BASE, s->sram_size, addr);
3840 static int omap_validate_tipb_addr(struct omap_mpu_state_s *s,
3843 return range_covers_byte(0xfffb0000, 0xffff0000 - 0xfffb0000, addr);
3846 static int omap_validate_local_addr(struct omap_mpu_state_s *s,
3849 return range_covers_byte(OMAP_LOCALBUS_BASE, 0x1000000, addr);
3852 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s *s,
3855 return range_covers_byte(0xe1010000, 0xe1020004 - 0xe1010000, addr);
3858 struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
3859 unsigned long sdram_size,
3860 const char *cpu_type)
3863 struct omap_mpu_state_s *s = g_new0(struct omap_mpu_state_s, 1);
3864 qemu_irq dma_irqs[6];
3866 SysBusDevice *busdev;
3869 s->mpu_model = omap310;
3870 s->cpu = ARM_CPU(cpu_create(cpu_type));
3871 s->sdram_size = sdram_size;
3872 s->sram_size = OMAP15XX_SRAM_SIZE;
3874 s->wakeup = qemu_allocate_irq(omap_mpu_wakeup, s, 0);
3879 /* Memory-mapped stuff */
3880 memory_region_allocate_system_memory(&s->emiff_ram, NULL, "omap1.dram",
3882 memory_region_add_subregion(system_memory, OMAP_EMIFF_BASE, &s->emiff_ram);
3883 memory_region_init_ram(&s->imif_ram, NULL, "omap1.sram", s->sram_size,
3885 memory_region_add_subregion(system_memory, OMAP_IMIF_BASE, &s->imif_ram);
3887 omap_clkm_init(system_memory, 0xfffece00, 0xe1008000, s);
3889 s->ih[0] = qdev_create(NULL, "omap-intc");
3890 qdev_prop_set_uint32(s->ih[0], "size", 0x100);
3891 qdev_prop_set_ptr(s->ih[0], "clk", omap_findclk(s, "arminth_ck"));
3892 qdev_init_nofail(s->ih[0]);
3893 busdev = SYS_BUS_DEVICE(s->ih[0]);
3894 sysbus_connect_irq(busdev, 0,
3895 qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ));
3896 sysbus_connect_irq(busdev, 1,
3897 qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_FIQ));
3898 sysbus_mmio_map(busdev, 0, 0xfffecb00);
3899 s->ih[1] = qdev_create(NULL, "omap-intc");
3900 qdev_prop_set_uint32(s->ih[1], "size", 0x800);
3901 qdev_prop_set_ptr(s->ih[1], "clk", omap_findclk(s, "arminth_ck"));
3902 qdev_init_nofail(s->ih[1]);
3903 busdev = SYS_BUS_DEVICE(s->ih[1]);
3904 sysbus_connect_irq(busdev, 0,
3905 qdev_get_gpio_in(s->ih[0], OMAP_INT_15XX_IH2_IRQ));
3906 /* The second interrupt controller's FIQ output is not wired up */
3907 sysbus_mmio_map(busdev, 0, 0xfffe0000);
3909 for (i = 0; i < 6; i++) {
3910 dma_irqs[i] = qdev_get_gpio_in(s->ih[omap1_dma_irq_map[i].ih],
3911 omap1_dma_irq_map[i].intr);
3913 s->dma = omap_dma_init(0xfffed800, dma_irqs, system_memory,
3914 qdev_get_gpio_in(s->ih[0], OMAP_INT_DMA_LCD),
3915 s, omap_findclk(s, "dma_ck"), omap_dma_3_1);
3917 s->port[emiff ].addr_valid = omap_validate_emiff_addr;
3918 s->port[emifs ].addr_valid = omap_validate_emifs_addr;
3919 s->port[imif ].addr_valid = omap_validate_imif_addr;
3920 s->port[tipb ].addr_valid = omap_validate_tipb_addr;
3921 s->port[local ].addr_valid = omap_validate_local_addr;
3922 s->port[tipb_mpui].addr_valid = omap_validate_tipb_mpui_addr;
3924 /* Register SDRAM and SRAM DMA ports for fast transfers. */
3925 soc_dma_port_add_mem(s->dma, memory_region_get_ram_ptr(&s->emiff_ram),
3926 OMAP_EMIFF_BASE, s->sdram_size);
3927 soc_dma_port_add_mem(s->dma, memory_region_get_ram_ptr(&s->imif_ram),
3928 OMAP_IMIF_BASE, s->sram_size);
3930 s->timer[0] = omap_mpu_timer_init(system_memory, 0xfffec500,
3931 qdev_get_gpio_in(s->ih[0], OMAP_INT_TIMER1),
3932 omap_findclk(s, "mputim_ck"));
3933 s->timer[1] = omap_mpu_timer_init(system_memory, 0xfffec600,
3934 qdev_get_gpio_in(s->ih[0], OMAP_INT_TIMER2),
3935 omap_findclk(s, "mputim_ck"));
3936 s->timer[2] = omap_mpu_timer_init(system_memory, 0xfffec700,
3937 qdev_get_gpio_in(s->ih[0], OMAP_INT_TIMER3),
3938 omap_findclk(s, "mputim_ck"));
3940 s->wdt = omap_wd_timer_init(system_memory, 0xfffec800,
3941 qdev_get_gpio_in(s->ih[0], OMAP_INT_WD_TIMER),
3942 omap_findclk(s, "armwdt_ck"));
3944 s->os_timer = omap_os_timer_init(system_memory, 0xfffb9000,
3945 qdev_get_gpio_in(s->ih[1], OMAP_INT_OS_TIMER),
3946 omap_findclk(s, "clk32-kHz"));
3948 s->lcd = omap_lcdc_init(system_memory, 0xfffec000,
3949 qdev_get_gpio_in(s->ih[0], OMAP_INT_LCD_CTRL),
3950 omap_dma_get_lcdch(s->dma),
3951 omap_findclk(s, "lcd_ck"));
3953 omap_ulpd_pm_init(system_memory, 0xfffe0800, s);
3954 omap_pin_cfg_init(system_memory, 0xfffe1000, s);
3955 omap_id_init(system_memory, s);
3957 omap_mpui_init(system_memory, 0xfffec900, s);
3959 s->private_tipb = omap_tipb_bridge_init(system_memory, 0xfffeca00,
3960 qdev_get_gpio_in(s->ih[0], OMAP_INT_BRIDGE_PRIV),
3961 omap_findclk(s, "tipb_ck"));
3962 s->public_tipb = omap_tipb_bridge_init(system_memory, 0xfffed300,
3963 qdev_get_gpio_in(s->ih[0], OMAP_INT_BRIDGE_PUB),
3964 omap_findclk(s, "tipb_ck"));
3966 omap_tcmi_init(system_memory, 0xfffecc00, s);
3968 s->uart[0] = omap_uart_init(0xfffb0000,
3969 qdev_get_gpio_in(s->ih[1], OMAP_INT_UART1),
3970 omap_findclk(s, "uart1_ck"),
3971 omap_findclk(s, "uart1_ck"),
3972 s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
3975 s->uart[1] = omap_uart_init(0xfffb0800,
3976 qdev_get_gpio_in(s->ih[1], OMAP_INT_UART2),
3977 omap_findclk(s, "uart2_ck"),
3978 omap_findclk(s, "uart2_ck"),
3979 s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
3981 serial_hd(0) ? serial_hd(1) : NULL);
3982 s->uart[2] = omap_uart_init(0xfffb9800,
3983 qdev_get_gpio_in(s->ih[0], OMAP_INT_UART3),
3984 omap_findclk(s, "uart3_ck"),
3985 omap_findclk(s, "uart3_ck"),
3986 s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX],
3988 serial_hd(0) && serial_hd(1) ? serial_hd(2) : NULL);
3990 s->dpll[0] = omap_dpll_init(system_memory, 0xfffecf00,
3991 omap_findclk(s, "dpll1"));
3992 s->dpll[1] = omap_dpll_init(system_memory, 0xfffed000,
3993 omap_findclk(s, "dpll2"));
3994 s->dpll[2] = omap_dpll_init(system_memory, 0xfffed100,
3995 omap_findclk(s, "dpll3"));
3997 dinfo = drive_get(IF_SD, 0, 0);
3998 if (!dinfo && !qtest_enabled()) {
3999 warn_report("missing SecureDigital device");
4001 s->mmc = omap_mmc_init(0xfffb7800, system_memory,
4002 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
4003 qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN),
4004 &s->drq[OMAP_DMA_MMC_TX],
4005 omap_findclk(s, "mmc_ck"));
4007 s->mpuio = omap_mpuio_init(system_memory, 0xfffb5000,
4008 qdev_get_gpio_in(s->ih[1], OMAP_INT_KEYBOARD),
4009 qdev_get_gpio_in(s->ih[1], OMAP_INT_MPUIO),
4010 s->wakeup, omap_findclk(s, "clk32-kHz"));
4012 s->gpio = qdev_create(NULL, "omap-gpio");
4013 qdev_prop_set_int32(s->gpio, "mpu_model", s->mpu_model);
4014 qdev_prop_set_ptr(s->gpio, "clk", omap_findclk(s, "arm_gpio_ck"));
4015 qdev_init_nofail(s->gpio);
4016 sysbus_connect_irq(SYS_BUS_DEVICE(s->gpio), 0,
4017 qdev_get_gpio_in(s->ih[0], OMAP_INT_GPIO_BANK1));
4018 sysbus_mmio_map(SYS_BUS_DEVICE(s->gpio), 0, 0xfffce000);
4020 s->microwire = omap_uwire_init(system_memory, 0xfffb3000,
4021 qdev_get_gpio_in(s->ih[1], OMAP_INT_uWireTX),
4022 qdev_get_gpio_in(s->ih[1], OMAP_INT_uWireRX),
4023 s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
4025 s->pwl = omap_pwl_init(system_memory, 0xfffb5800,
4026 omap_findclk(s, "armxor_ck"));
4027 s->pwt = omap_pwt_init(system_memory, 0xfffb6000,
4028 omap_findclk(s, "armxor_ck"));
4030 s->i2c[0] = qdev_create(NULL, "omap_i2c");
4031 qdev_prop_set_uint8(s->i2c[0], "revision", 0x11);
4032 qdev_prop_set_ptr(s->i2c[0], "fclk", omap_findclk(s, "mpuper_ck"));
4033 qdev_init_nofail(s->i2c[0]);
4034 busdev = SYS_BUS_DEVICE(s->i2c[0]);
4035 sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(s->ih[1], OMAP_INT_I2C));
4036 sysbus_connect_irq(busdev, 1, s->drq[OMAP_DMA_I2C_TX]);
4037 sysbus_connect_irq(busdev, 2, s->drq[OMAP_DMA_I2C_RX]);
4038 sysbus_mmio_map(busdev, 0, 0xfffb3800);
4040 s->rtc = omap_rtc_init(system_memory, 0xfffb4800,
4041 qdev_get_gpio_in(s->ih[1], OMAP_INT_RTC_TIMER),
4042 qdev_get_gpio_in(s->ih[1], OMAP_INT_RTC_ALARM),
4043 omap_findclk(s, "clk32-kHz"));
4045 s->mcbsp1 = omap_mcbsp_init(system_memory, 0xfffb1800,
4046 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP1TX),
4047 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP1RX),
4048 &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
4049 s->mcbsp2 = omap_mcbsp_init(system_memory, 0xfffb1000,
4050 qdev_get_gpio_in(s->ih[0],
4051 OMAP_INT_310_McBSP2_TX),
4052 qdev_get_gpio_in(s->ih[0],
4053 OMAP_INT_310_McBSP2_RX),
4054 &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
4055 s->mcbsp3 = omap_mcbsp_init(system_memory, 0xfffb7000,
4056 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP3TX),
4057 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP3RX),
4058 &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
4060 s->led[0] = omap_lpg_init(system_memory,
4061 0xfffbd000, omap_findclk(s, "clk32-kHz"));
4062 s->led[1] = omap_lpg_init(system_memory,
4063 0xfffbd800, omap_findclk(s, "clk32-kHz"));
4065 /* Register mappings not currenlty implemented:
4066 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4067 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4068 * USB W2FC fffb4000 - fffb47ff
4069 * Camera Interface fffb6800 - fffb6fff
4070 * USB Host fffba000 - fffba7ff
4071 * FAC fffba800 - fffbafff
4072 * HDQ/1-Wire fffbc000 - fffbc7ff
4073 * TIPB switches fffbc800 - fffbcfff
4074 * Mailbox fffcf000 - fffcf7ff
4075 * Local bus IF fffec100 - fffec1ff
4076 * Local bus MMU fffec200 - fffec2ff
4077 * DSP MMU fffed200 - fffed2ff
4080 omap_setup_dsp_mapping(system_memory, omap15xx_dsp_mm);
4081 omap_setup_mpui_io(system_memory, s);
4083 qemu_register_reset(omap1_mpu_reset, s);