2 * TI OMAP processors emulation.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "hw/boards.h"
23 #include "hw/arm/arm.h"
24 #include "hw/arm/omap.h"
25 #include "sysemu/sysemu.h"
26 #include "hw/arm/soc_dma.h"
27 #include "sysemu/block-backend.h"
28 #include "sysemu/blockdev.h"
29 #include "qemu/range.h"
30 #include "hw/sysbus.h"
32 /* Should signal the TCMI/GPMC */
33 uint32_t omap_badwidth_read8(void *opaque
, hwaddr addr
)
38 cpu_physical_memory_read(addr
, &ret
, 1);
42 void omap_badwidth_write8(void *opaque
, hwaddr addr
,
48 cpu_physical_memory_write(addr
, &val8
, 1);
51 uint32_t omap_badwidth_read16(void *opaque
, hwaddr addr
)
56 cpu_physical_memory_read(addr
, &ret
, 2);
60 void omap_badwidth_write16(void *opaque
, hwaddr addr
,
63 uint16_t val16
= value
;
66 cpu_physical_memory_write(addr
, &val16
, 2);
69 uint32_t omap_badwidth_read32(void *opaque
, hwaddr addr
)
74 cpu_physical_memory_read(addr
, &ret
, 4);
78 void omap_badwidth_write32(void *opaque
, hwaddr addr
,
82 cpu_physical_memory_write(addr
, &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_clock_get_ns(QEMU_CLOCK_VIRTUAL
) - 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_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
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 timer_mod(timer
->timer
, timer
->time
+ expires
);
139 qemu_bh_schedule(timer
->tick
);
141 timer_del(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_irq(omap_timer_clk_update
, timer
, 0));
180 timer
->rate
= omap_clk_getrate(timer
->clk
);
183 static uint64_t omap_mpu_timer_read(void *opaque
, hwaddr 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
, hwaddr addr
,
208 uint64_t value
, unsigned size
)
210 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
213 omap_badwidth_write32(opaque
, addr
, value
);
218 case 0x00: /* CNTL_TIMER */
220 s
->enable
= (value
>> 5) & 1;
221 s
->ptv
= (value
>> 2) & 7;
222 s
->ar
= (value
>> 1) & 1;
224 omap_timer_update(s
);
227 case 0x04: /* LOAD_TIM */
228 s
->reset_val
= value
;
231 case 0x08: /* READ_TIM */
240 static const MemoryRegionOps omap_mpu_timer_ops
= {
241 .read
= omap_mpu_timer_read
,
242 .write
= omap_mpu_timer_write
,
243 .endianness
= DEVICE_LITTLE_ENDIAN
,
246 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
250 s
->reset_val
= 31337;
258 static struct omap_mpu_timer_s
*omap_mpu_timer_init(MemoryRegion
*system_memory
,
260 qemu_irq irq
, omap_clk clk
)
262 struct omap_mpu_timer_s
*s
= g_new0(struct omap_mpu_timer_s
, 1);
266 s
->timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, 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
, NULL
, &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
, hwaddr 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
, hwaddr addr
,
315 uint64_t value
, unsigned size
)
317 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
320 omap_badwidth_write16(opaque
, addr
, value
);
325 case 0x00: /* CNTL_TIMER */
326 omap_timer_sync(&s
->timer
);
327 s
->timer
.ptv
= (value
>> 9) & 7;
328 s
->timer
.ar
= (value
>> 8) & 1;
329 s
->timer
.st
= (value
>> 7) & 1;
330 s
->free
= (value
>> 1) & 1;
331 omap_timer_update(&s
->timer
);
334 case 0x04: /* LOAD_TIMER */
335 s
->timer
.reset_val
= value
& 0xffff;
338 case 0x08: /* TIMER_MODE */
339 if (!s
->mode
&& ((value
>> 15) & 1))
340 omap_clk_get(s
->timer
.clk
);
341 s
->mode
|= (value
>> 15) & 1;
342 if (s
->last_wr
== 0xf5) {
343 if ((value
& 0xff) == 0xa0) {
346 omap_clk_put(s
->timer
.clk
);
349 /* XXX: on T|E hardware somehow this has no effect,
350 * on Zire 71 it works as specified. */
352 qemu_system_reset_request();
355 s
->last_wr
= value
& 0xff;
363 static const MemoryRegionOps omap_wd_timer_ops
= {
364 .read
= omap_wd_timer_read
,
365 .write
= omap_wd_timer_write
,
366 .endianness
= DEVICE_NATIVE_ENDIAN
,
369 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
371 timer_del(s
->timer
.timer
);
373 omap_clk_get(s
->timer
.clk
);
379 s
->timer
.reset_val
= 0xffff;
384 omap_timer_update(&s
->timer
);
387 static struct omap_watchdog_timer_s
*omap_wd_timer_init(MemoryRegion
*memory
,
389 qemu_irq irq
, omap_clk clk
)
391 struct omap_watchdog_timer_s
*s
= g_new0(struct omap_watchdog_timer_s
, 1);
395 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, 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
, NULL
, &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
, hwaddr 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
, hwaddr 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 omap_badwidth_write32(opaque
, addr
, value
);
452 s
->timer
.reset_val
= value
& 0x00ffffff;
460 s
->timer
.ar
= (value
>> 3) & 1;
461 s
->timer
.it_ena
= (value
>> 2) & 1;
462 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
463 omap_timer_sync(&s
->timer
);
464 s
->timer
.enable
= value
& 1;
465 s
->timer
.st
= value
& 1;
466 omap_timer_update(&s
->timer
);
475 static const MemoryRegionOps omap_os_timer_ops
= {
476 .read
= omap_os_timer_read
,
477 .write
= omap_os_timer_write
,
478 .endianness
= DEVICE_NATIVE_ENDIAN
,
481 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
483 timer_del(s
->timer
.timer
);
486 s
->timer
.reset_val
= 0x00ffffff;
493 static struct omap_32khz_timer_s
*omap_os_timer_init(MemoryRegion
*memory
,
495 qemu_irq irq
, omap_clk clk
)
497 struct omap_32khz_timer_s
*s
= g_new0(struct omap_32khz_timer_s
, 1);
501 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, 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
, NULL
, &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
, hwaddr 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(qdev_get_gpio_in(s
->ih
[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 */
537 case 0x00: /* COUNTER_32_LSB */
538 case 0x04: /* COUNTER_32_MSB */
539 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
540 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
541 case 0x10: /* GAUGING_CTRL */
542 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
543 case 0x30: /* CLOCK_CTRL */
544 case 0x34: /* SOFT_REQ */
545 case 0x38: /* COUNTER_32_FIQ */
546 case 0x3c: /* DPLL_CTRL */
547 case 0x40: /* STATUS_REQ */
548 /* XXX: check clk::usecount state for every clock */
549 case 0x48: /* LOCL_TIME */
550 case 0x4c: /* APLL_CTRL */
551 case 0x50: /* POWER_CTRL */
552 return s
->ulpd_pm_regs
[addr
>> 2];
559 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
560 uint16_t diff
, uint16_t value
)
562 if (diff
& (1 << 4)) /* USB_MCLK_EN */
563 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
564 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
565 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
568 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
569 uint16_t diff
, uint16_t value
)
571 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
572 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
573 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
574 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
575 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
576 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
577 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
578 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
581 static void omap_ulpd_pm_write(void *opaque
, hwaddr addr
,
582 uint64_t value
, unsigned size
)
584 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
587 static const int bypass_div
[4] = { 1, 2, 4, 4 };
591 omap_badwidth_write16(opaque
, addr
, value
);
596 case 0x00: /* COUNTER_32_LSB */
597 case 0x04: /* COUNTER_32_MSB */
598 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
599 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
600 case 0x14: /* IT_STATUS */
601 case 0x40: /* STATUS_REQ */
605 case 0x10: /* GAUGING_CTRL */
606 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
607 if ((s
->ulpd_pm_regs
[addr
>> 2] ^ value
) & 1) {
608 now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
611 s
->ulpd_gauge_start
= now
;
613 now
-= s
->ulpd_gauge_start
;
616 ticks
= muldiv64(now
, 32768, get_ticks_per_sec());
617 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
618 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
619 if (ticks
>> 32) /* OVERFLOW_32K */
620 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
622 /* High frequency ticks */
623 ticks
= muldiv64(now
, 12000000, get_ticks_per_sec());
624 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
625 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
626 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
627 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
629 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
630 qemu_irq_raise(qdev_get_gpio_in(s
->ih
[1], OMAP_INT_GAUGE_32K
));
633 s
->ulpd_pm_regs
[addr
>> 2] = value
;
636 case 0x18: /* Reserved */
637 case 0x1c: /* Reserved */
638 case 0x20: /* Reserved */
639 case 0x28: /* Reserved */
640 case 0x2c: /* Reserved */
643 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
644 case 0x38: /* COUNTER_32_FIQ */
645 case 0x48: /* LOCL_TIME */
646 case 0x50: /* POWER_CTRL */
647 s
->ulpd_pm_regs
[addr
>> 2] = value
;
650 case 0x30: /* CLOCK_CTRL */
651 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
652 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x3f;
653 omap_ulpd_clk_update(s
, diff
, value
);
656 case 0x34: /* SOFT_REQ */
657 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
658 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x1f;
659 omap_ulpd_req_update(s
, diff
, value
);
662 case 0x3c: /* DPLL_CTRL */
663 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
664 * omitted altogether, probably a typo. */
665 /* This register has identical semantics with DPLL(1:3) control
666 * registers, see omap_dpll_write() */
667 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
668 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x2fff;
669 if (diff
& (0x3ff << 2)) {
670 if (value
& (1 << 4)) { /* PLL_ENABLE */
671 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
672 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
674 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
677 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
680 /* Enter the desired mode. */
681 s
->ulpd_pm_regs
[addr
>> 2] =
682 (s
->ulpd_pm_regs
[addr
>> 2] & 0xfffe) |
683 ((s
->ulpd_pm_regs
[addr
>> 2] >> 4) & 1);
685 /* Act as if the lock is restored. */
686 s
->ulpd_pm_regs
[addr
>> 2] |= 2;
689 case 0x4c: /* APLL_CTRL */
690 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
691 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0xf;
692 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
693 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
694 (value
& (1 << 0)) ? "apll" : "dpll4"));
702 static const MemoryRegionOps omap_ulpd_pm_ops
= {
703 .read
= omap_ulpd_pm_read
,
704 .write
= omap_ulpd_pm_write
,
705 .endianness
= DEVICE_NATIVE_ENDIAN
,
708 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
710 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
711 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
712 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
713 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
714 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
715 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
716 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
717 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
718 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
719 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
720 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
721 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
722 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
723 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
724 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
725 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
726 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
727 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
728 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
729 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
730 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
731 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
732 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
735 static void omap_ulpd_pm_init(MemoryRegion
*system_memory
,
737 struct omap_mpu_state_s
*mpu
)
739 memory_region_init_io(&mpu
->ulpd_pm_iomem
, NULL
, &omap_ulpd_pm_ops
, mpu
,
740 "omap-ulpd-pm", 0x800);
741 memory_region_add_subregion(system_memory
, base
, &mpu
->ulpd_pm_iomem
);
742 omap_ulpd_pm_reset(mpu
);
745 /* OMAP Pin Configuration */
746 static uint64_t omap_pin_cfg_read(void *opaque
, hwaddr addr
,
749 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
752 return omap_badwidth_read32(opaque
, addr
);
756 case 0x00: /* FUNC_MUX_CTRL_0 */
757 case 0x04: /* FUNC_MUX_CTRL_1 */
758 case 0x08: /* FUNC_MUX_CTRL_2 */
759 return s
->func_mux_ctrl
[addr
>> 2];
761 case 0x0c: /* COMP_MODE_CTRL_0 */
762 return s
->comp_mode_ctrl
[0];
764 case 0x10: /* FUNC_MUX_CTRL_3 */
765 case 0x14: /* FUNC_MUX_CTRL_4 */
766 case 0x18: /* FUNC_MUX_CTRL_5 */
767 case 0x1c: /* FUNC_MUX_CTRL_6 */
768 case 0x20: /* FUNC_MUX_CTRL_7 */
769 case 0x24: /* FUNC_MUX_CTRL_8 */
770 case 0x28: /* FUNC_MUX_CTRL_9 */
771 case 0x2c: /* FUNC_MUX_CTRL_A */
772 case 0x30: /* FUNC_MUX_CTRL_B */
773 case 0x34: /* FUNC_MUX_CTRL_C */
774 case 0x38: /* FUNC_MUX_CTRL_D */
775 return s
->func_mux_ctrl
[(addr
>> 2) - 1];
777 case 0x40: /* PULL_DWN_CTRL_0 */
778 case 0x44: /* PULL_DWN_CTRL_1 */
779 case 0x48: /* PULL_DWN_CTRL_2 */
780 case 0x4c: /* PULL_DWN_CTRL_3 */
781 return s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2];
783 case 0x50: /* GATE_INH_CTRL_0 */
784 return s
->gate_inh_ctrl
[0];
786 case 0x60: /* VOLTAGE_CTRL_0 */
787 return s
->voltage_ctrl
[0];
789 case 0x70: /* TEST_DBG_CTRL_0 */
790 return s
->test_dbg_ctrl
[0];
792 case 0x80: /* MOD_CONF_CTRL_0 */
793 return s
->mod_conf_ctrl
[0];
800 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
801 uint32_t diff
, uint32_t value
)
804 if (diff
& (1 << 9)) /* BLUETOOTH */
805 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
807 if (diff
& (1 << 7)) /* USB.CLKO */
808 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
813 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
814 uint32_t diff
, uint32_t value
)
817 if (diff
& (1U << 31)) {
818 /* MCBSP3_CLK_HIZ_DI */
819 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"), (value
>> 31) & 1);
821 if (diff
& (1 << 1)) {
823 omap_clk_onoff(omap_findclk(s
, "clk32k_out"), (~value
>> 1) & 1);
828 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
829 uint32_t diff
, uint32_t value
)
831 if (diff
& (1U << 31)) {
832 /* CONF_MOD_UART3_CLK_MODE_R */
833 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
834 omap_findclk(s
, ((value
>> 31) & 1) ?
835 "ck_48m" : "armper_ck"));
837 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
838 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
839 omap_findclk(s
, ((value
>> 30) & 1) ?
840 "ck_48m" : "armper_ck"));
841 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
842 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
843 omap_findclk(s
, ((value
>> 29) & 1) ?
844 "ck_48m" : "armper_ck"));
845 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
846 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
847 omap_findclk(s
, ((value
>> 23) & 1) ?
848 "ck_48m" : "armper_ck"));
849 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
850 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
851 omap_findclk(s
, ((value
>> 12) & 1) ?
852 "ck_48m" : "armper_ck"));
853 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
854 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
857 static void omap_pin_cfg_write(void *opaque
, hwaddr addr
,
858 uint64_t value
, unsigned size
)
860 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
864 omap_badwidth_write32(opaque
, addr
, value
);
869 case 0x00: /* FUNC_MUX_CTRL_0 */
870 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
871 s
->func_mux_ctrl
[addr
>> 2] = value
;
872 omap_pin_funcmux0_update(s
, diff
, value
);
875 case 0x04: /* FUNC_MUX_CTRL_1 */
876 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
877 s
->func_mux_ctrl
[addr
>> 2] = value
;
878 omap_pin_funcmux1_update(s
, diff
, value
);
881 case 0x08: /* FUNC_MUX_CTRL_2 */
882 s
->func_mux_ctrl
[addr
>> 2] = value
;
885 case 0x0c: /* COMP_MODE_CTRL_0 */
886 s
->comp_mode_ctrl
[0] = value
;
887 s
->compat1509
= (value
!= 0x0000eaef);
888 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
889 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
892 case 0x10: /* FUNC_MUX_CTRL_3 */
893 case 0x14: /* FUNC_MUX_CTRL_4 */
894 case 0x18: /* FUNC_MUX_CTRL_5 */
895 case 0x1c: /* FUNC_MUX_CTRL_6 */
896 case 0x20: /* FUNC_MUX_CTRL_7 */
897 case 0x24: /* FUNC_MUX_CTRL_8 */
898 case 0x28: /* FUNC_MUX_CTRL_9 */
899 case 0x2c: /* FUNC_MUX_CTRL_A */
900 case 0x30: /* FUNC_MUX_CTRL_B */
901 case 0x34: /* FUNC_MUX_CTRL_C */
902 case 0x38: /* FUNC_MUX_CTRL_D */
903 s
->func_mux_ctrl
[(addr
>> 2) - 1] = value
;
906 case 0x40: /* PULL_DWN_CTRL_0 */
907 case 0x44: /* PULL_DWN_CTRL_1 */
908 case 0x48: /* PULL_DWN_CTRL_2 */
909 case 0x4c: /* PULL_DWN_CTRL_3 */
910 s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2] = value
;
913 case 0x50: /* GATE_INH_CTRL_0 */
914 s
->gate_inh_ctrl
[0] = value
;
917 case 0x60: /* VOLTAGE_CTRL_0 */
918 s
->voltage_ctrl
[0] = value
;
921 case 0x70: /* TEST_DBG_CTRL_0 */
922 s
->test_dbg_ctrl
[0] = value
;
925 case 0x80: /* MOD_CONF_CTRL_0 */
926 diff
= s
->mod_conf_ctrl
[0] ^ value
;
927 s
->mod_conf_ctrl
[0] = value
;
928 omap_pin_modconf1_update(s
, diff
, value
);
936 static const MemoryRegionOps omap_pin_cfg_ops
= {
937 .read
= omap_pin_cfg_read
,
938 .write
= omap_pin_cfg_write
,
939 .endianness
= DEVICE_NATIVE_ENDIAN
,
942 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
944 /* Start in Compatibility Mode. */
946 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
947 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
948 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
949 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
950 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
951 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
952 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
953 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
954 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
955 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
958 static void omap_pin_cfg_init(MemoryRegion
*system_memory
,
960 struct omap_mpu_state_s
*mpu
)
962 memory_region_init_io(&mpu
->pin_cfg_iomem
, NULL
, &omap_pin_cfg_ops
, mpu
,
963 "omap-pin-cfg", 0x800);
964 memory_region_add_subregion(system_memory
, base
, &mpu
->pin_cfg_iomem
);
965 omap_pin_cfg_reset(mpu
);
968 /* Device Identification, Die Identification */
969 static uint64_t omap_id_read(void *opaque
, hwaddr addr
,
972 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
975 return omap_badwidth_read32(opaque
, addr
);
979 case 0xfffe1800: /* DIE_ID_LSB */
981 case 0xfffe1804: /* DIE_ID_MSB */
984 case 0xfffe2000: /* PRODUCT_ID_LSB */
986 case 0xfffe2004: /* PRODUCT_ID_MSB */
989 case 0xfffed400: /* JTAG_ID_LSB */
990 switch (s
->mpu_model
) {
996 hw_error("%s: bad mpu model\n", __FUNCTION__
);
1000 case 0xfffed404: /* JTAG_ID_MSB */
1001 switch (s
->mpu_model
) {
1007 hw_error("%s: bad mpu model\n", __FUNCTION__
);
1016 static void omap_id_write(void *opaque
, hwaddr addr
,
1017 uint64_t value
, unsigned size
)
1020 omap_badwidth_write32(opaque
, addr
, value
);
1027 static const MemoryRegionOps omap_id_ops
= {
1028 .read
= omap_id_read
,
1029 .write
= omap_id_write
,
1030 .endianness
= DEVICE_NATIVE_ENDIAN
,
1033 static void omap_id_init(MemoryRegion
*memory
, struct omap_mpu_state_s
*mpu
)
1035 memory_region_init_io(&mpu
->id_iomem
, NULL
, &omap_id_ops
, mpu
,
1036 "omap-id", 0x100000000ULL
);
1037 memory_region_init_alias(&mpu
->id_iomem_e18
, NULL
, "omap-id-e18", &mpu
->id_iomem
,
1039 memory_region_add_subregion(memory
, 0xfffe1800, &mpu
->id_iomem_e18
);
1040 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-ed4", &mpu
->id_iomem
,
1042 memory_region_add_subregion(memory
, 0xfffed400, &mpu
->id_iomem_ed4
);
1043 if (!cpu_is_omap15xx(mpu
)) {
1044 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-e20",
1045 &mpu
->id_iomem
, 0xfffe2000, 0x800);
1046 memory_region_add_subregion(memory
, 0xfffe2000, &mpu
->id_iomem_e20
);
1050 /* MPUI Control (Dummy) */
1051 static uint64_t omap_mpui_read(void *opaque
, hwaddr addr
,
1054 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1057 return omap_badwidth_read32(opaque
, addr
);
1061 case 0x00: /* CTRL */
1062 return s
->mpui_ctrl
;
1063 case 0x04: /* DEBUG_ADDR */
1065 case 0x08: /* DEBUG_DATA */
1067 case 0x0c: /* DEBUG_FLAG */
1069 case 0x10: /* STATUS */
1072 /* Not in OMAP310 */
1073 case 0x14: /* DSP_STATUS */
1074 case 0x18: /* DSP_BOOT_CONFIG */
1076 case 0x1c: /* DSP_MPUI_CONFIG */
1084 static void omap_mpui_write(void *opaque
, hwaddr addr
,
1085 uint64_t value
, unsigned size
)
1087 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1090 omap_badwidth_write32(opaque
, addr
, value
);
1095 case 0x00: /* CTRL */
1096 s
->mpui_ctrl
= value
& 0x007fffff;
1099 case 0x04: /* DEBUG_ADDR */
1100 case 0x08: /* DEBUG_DATA */
1101 case 0x0c: /* DEBUG_FLAG */
1102 case 0x10: /* STATUS */
1103 /* Not in OMAP310 */
1104 case 0x14: /* DSP_STATUS */
1107 case 0x18: /* DSP_BOOT_CONFIG */
1108 case 0x1c: /* DSP_MPUI_CONFIG */
1116 static const MemoryRegionOps omap_mpui_ops
= {
1117 .read
= omap_mpui_read
,
1118 .write
= omap_mpui_write
,
1119 .endianness
= DEVICE_NATIVE_ENDIAN
,
1122 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1124 s
->mpui_ctrl
= 0x0003ff1b;
1127 static void omap_mpui_init(MemoryRegion
*memory
, hwaddr base
,
1128 struct omap_mpu_state_s
*mpu
)
1130 memory_region_init_io(&mpu
->mpui_iomem
, NULL
, &omap_mpui_ops
, mpu
,
1131 "omap-mpui", 0x100);
1132 memory_region_add_subregion(memory
, base
, &mpu
->mpui_iomem
);
1134 omap_mpui_reset(mpu
);
1138 struct omap_tipb_bridge_s
{
1146 uint16_t enh_control
;
1149 static uint64_t omap_tipb_bridge_read(void *opaque
, hwaddr addr
,
1152 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1155 return omap_badwidth_read16(opaque
, addr
);
1159 case 0x00: /* TIPB_CNTL */
1161 case 0x04: /* TIPB_BUS_ALLOC */
1163 case 0x08: /* MPU_TIPB_CNTL */
1165 case 0x0c: /* ENHANCED_TIPB_CNTL */
1166 return s
->enh_control
;
1167 case 0x10: /* ADDRESS_DBG */
1168 case 0x14: /* DATA_DEBUG_LOW */
1169 case 0x18: /* DATA_DEBUG_HIGH */
1171 case 0x1c: /* DEBUG_CNTR_SIG */
1179 static void omap_tipb_bridge_write(void *opaque
, hwaddr addr
,
1180 uint64_t value
, unsigned size
)
1182 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1185 omap_badwidth_write16(opaque
, addr
, value
);
1190 case 0x00: /* TIPB_CNTL */
1191 s
->control
= value
& 0xffff;
1194 case 0x04: /* TIPB_BUS_ALLOC */
1195 s
->alloc
= value
& 0x003f;
1198 case 0x08: /* MPU_TIPB_CNTL */
1199 s
->buffer
= value
& 0x0003;
1202 case 0x0c: /* ENHANCED_TIPB_CNTL */
1203 s
->width_intr
= !(value
& 2);
1204 s
->enh_control
= value
& 0x000f;
1207 case 0x10: /* ADDRESS_DBG */
1208 case 0x14: /* DATA_DEBUG_LOW */
1209 case 0x18: /* DATA_DEBUG_HIGH */
1210 case 0x1c: /* DEBUG_CNTR_SIG */
1219 static const MemoryRegionOps omap_tipb_bridge_ops
= {
1220 .read
= omap_tipb_bridge_read
,
1221 .write
= omap_tipb_bridge_write
,
1222 .endianness
= DEVICE_NATIVE_ENDIAN
,
1225 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1227 s
->control
= 0xffff;
1230 s
->enh_control
= 0x000f;
1233 static struct omap_tipb_bridge_s
*omap_tipb_bridge_init(
1234 MemoryRegion
*memory
, hwaddr base
,
1235 qemu_irq abort_irq
, omap_clk clk
)
1237 struct omap_tipb_bridge_s
*s
= g_new0(struct omap_tipb_bridge_s
, 1);
1239 s
->abort
= abort_irq
;
1240 omap_tipb_bridge_reset(s
);
1242 memory_region_init_io(&s
->iomem
, NULL
, &omap_tipb_bridge_ops
, s
,
1243 "omap-tipb-bridge", 0x100);
1244 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1249 /* Dummy Traffic Controller's Memory Interface */
1250 static uint64_t omap_tcmi_read(void *opaque
, hwaddr addr
,
1253 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1257 return omap_badwidth_read32(opaque
, addr
);
1261 case 0x00: /* IMIF_PRIO */
1262 case 0x04: /* EMIFS_PRIO */
1263 case 0x08: /* EMIFF_PRIO */
1264 case 0x0c: /* EMIFS_CONFIG */
1265 case 0x10: /* EMIFS_CS0_CONFIG */
1266 case 0x14: /* EMIFS_CS1_CONFIG */
1267 case 0x18: /* EMIFS_CS2_CONFIG */
1268 case 0x1c: /* EMIFS_CS3_CONFIG */
1269 case 0x24: /* EMIFF_MRS */
1270 case 0x28: /* TIMEOUT1 */
1271 case 0x2c: /* TIMEOUT2 */
1272 case 0x30: /* TIMEOUT3 */
1273 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1274 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1275 return s
->tcmi_regs
[addr
>> 2];
1277 case 0x20: /* EMIFF_SDRAM_CONFIG */
1278 ret
= s
->tcmi_regs
[addr
>> 2];
1279 s
->tcmi_regs
[addr
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1280 /* XXX: We can try using the VGA_DIRTY flag for this */
1288 static void omap_tcmi_write(void *opaque
, hwaddr addr
,
1289 uint64_t value
, unsigned size
)
1291 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1294 omap_badwidth_write32(opaque
, addr
, value
);
1299 case 0x00: /* IMIF_PRIO */
1300 case 0x04: /* EMIFS_PRIO */
1301 case 0x08: /* EMIFF_PRIO */
1302 case 0x10: /* EMIFS_CS0_CONFIG */
1303 case 0x14: /* EMIFS_CS1_CONFIG */
1304 case 0x18: /* EMIFS_CS2_CONFIG */
1305 case 0x1c: /* EMIFS_CS3_CONFIG */
1306 case 0x20: /* EMIFF_SDRAM_CONFIG */
1307 case 0x24: /* EMIFF_MRS */
1308 case 0x28: /* TIMEOUT1 */
1309 case 0x2c: /* TIMEOUT2 */
1310 case 0x30: /* TIMEOUT3 */
1311 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1312 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1313 s
->tcmi_regs
[addr
>> 2] = value
;
1315 case 0x0c: /* EMIFS_CONFIG */
1316 s
->tcmi_regs
[addr
>> 2] = (value
& 0xf) | (1 << 4);
1324 static const MemoryRegionOps omap_tcmi_ops
= {
1325 .read
= omap_tcmi_read
,
1326 .write
= omap_tcmi_write
,
1327 .endianness
= DEVICE_NATIVE_ENDIAN
,
1330 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1332 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1333 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1334 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1335 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1336 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1337 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1338 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1339 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1340 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1341 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1342 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1343 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1344 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1345 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1346 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1349 static void omap_tcmi_init(MemoryRegion
*memory
, hwaddr base
,
1350 struct omap_mpu_state_s
*mpu
)
1352 memory_region_init_io(&mpu
->tcmi_iomem
, NULL
, &omap_tcmi_ops
, mpu
,
1353 "omap-tcmi", 0x100);
1354 memory_region_add_subregion(memory
, base
, &mpu
->tcmi_iomem
);
1355 omap_tcmi_reset(mpu
);
1358 /* Digital phase-locked loops control */
1365 static uint64_t omap_dpll_read(void *opaque
, hwaddr addr
,
1368 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1371 return omap_badwidth_read16(opaque
, addr
);
1374 if (addr
== 0x00) /* CTL_REG */
1381 static void omap_dpll_write(void *opaque
, hwaddr addr
,
1382 uint64_t value
, unsigned size
)
1384 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1386 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1390 omap_badwidth_write16(opaque
, addr
, value
);
1394 if (addr
== 0x00) { /* CTL_REG */
1395 /* See omap_ulpd_pm_write() too */
1396 diff
= s
->mode
& value
;
1397 s
->mode
= value
& 0x2fff;
1398 if (diff
& (0x3ff << 2)) {
1399 if (value
& (1 << 4)) { /* PLL_ENABLE */
1400 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1401 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1403 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1406 omap_clk_setrate(s
->dpll
, div
, mult
);
1409 /* Enter the desired mode. */
1410 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1412 /* Act as if the lock is restored. */
1419 static const MemoryRegionOps omap_dpll_ops
= {
1420 .read
= omap_dpll_read
,
1421 .write
= omap_dpll_write
,
1422 .endianness
= DEVICE_NATIVE_ENDIAN
,
1425 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1428 omap_clk_setrate(s
->dpll
, 1, 1);
1431 static struct dpll_ctl_s
*omap_dpll_init(MemoryRegion
*memory
,
1432 hwaddr base
, omap_clk clk
)
1434 struct dpll_ctl_s
*s
= g_malloc0(sizeof(*s
));
1435 memory_region_init_io(&s
->iomem
, NULL
, &omap_dpll_ops
, s
, "omap-dpll", 0x100);
1440 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1444 /* MPU Clock/Reset/Power Mode Control */
1445 static uint64_t omap_clkm_read(void *opaque
, hwaddr addr
,
1448 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1451 return omap_badwidth_read16(opaque
, addr
);
1455 case 0x00: /* ARM_CKCTL */
1456 return s
->clkm
.arm_ckctl
;
1458 case 0x04: /* ARM_IDLECT1 */
1459 return s
->clkm
.arm_idlect1
;
1461 case 0x08: /* ARM_IDLECT2 */
1462 return s
->clkm
.arm_idlect2
;
1464 case 0x0c: /* ARM_EWUPCT */
1465 return s
->clkm
.arm_ewupct
;
1467 case 0x10: /* ARM_RSTCT1 */
1468 return s
->clkm
.arm_rstct1
;
1470 case 0x14: /* ARM_RSTCT2 */
1471 return s
->clkm
.arm_rstct2
;
1473 case 0x18: /* ARM_SYSST */
1474 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
1476 case 0x1c: /* ARM_CKOUT1 */
1477 return s
->clkm
.arm_ckout1
;
1479 case 0x20: /* ARM_CKOUT2 */
1487 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
1488 uint16_t diff
, uint16_t value
)
1492 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
1493 if (value
& (1 << 14))
1496 clk
= omap_findclk(s
, "arminth_ck");
1497 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1500 if (diff
& (1 << 12)) { /* ARM_TIMXO */
1501 clk
= omap_findclk(s
, "armtim_ck");
1502 if (value
& (1 << 12))
1503 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
1505 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1508 if (diff
& (3 << 10)) { /* DSPMMUDIV */
1509 clk
= omap_findclk(s
, "dspmmu_ck");
1510 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
1512 if (diff
& (3 << 8)) { /* TCDIV */
1513 clk
= omap_findclk(s
, "tc_ck");
1514 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
1516 if (diff
& (3 << 6)) { /* DSPDIV */
1517 clk
= omap_findclk(s
, "dsp_ck");
1518 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
1520 if (diff
& (3 << 4)) { /* ARMDIV */
1521 clk
= omap_findclk(s
, "arm_ck");
1522 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
1524 if (diff
& (3 << 2)) { /* LCDDIV */
1525 clk
= omap_findclk(s
, "lcd_ck");
1526 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
1528 if (diff
& (3 << 0)) { /* PERDIV */
1529 clk
= omap_findclk(s
, "armper_ck");
1530 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
1534 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
1535 uint16_t diff
, uint16_t value
)
1539 if (value
& (1 << 11)) { /* SETARM_IDLE */
1540 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
1542 if (!(value
& (1 << 10))) /* WKUP_MODE */
1543 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
1545 #define SET_CANIDLE(clock, bit) \
1546 if (diff & (1 << bit)) { \
1547 clk = omap_findclk(s, clock); \
1548 omap_clk_canidle(clk, (value >> bit) & 1); \
1550 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1551 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1552 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1553 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1554 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1555 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1556 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1557 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1558 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1559 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1560 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1561 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1562 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1563 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1566 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
1567 uint16_t diff
, uint16_t value
)
1571 #define SET_ONOFF(clock, bit) \
1572 if (diff & (1 << bit)) { \
1573 clk = omap_findclk(s, clock); \
1574 omap_clk_onoff(clk, (value >> bit) & 1); \
1576 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1577 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1578 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1579 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1580 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1581 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1582 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1583 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1584 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1585 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1586 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1589 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
1590 uint16_t diff
, uint16_t value
)
1594 if (diff
& (3 << 4)) { /* TCLKOUT */
1595 clk
= omap_findclk(s
, "tclk_out");
1596 switch ((value
>> 4) & 3) {
1598 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
1599 omap_clk_onoff(clk
, 1);
1602 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1603 omap_clk_onoff(clk
, 1);
1606 omap_clk_onoff(clk
, 0);
1609 if (diff
& (3 << 2)) { /* DCLKOUT */
1610 clk
= omap_findclk(s
, "dclk_out");
1611 switch ((value
>> 2) & 3) {
1613 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
1616 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
1619 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
1622 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1626 if (diff
& (3 << 0)) { /* ACLKOUT */
1627 clk
= omap_findclk(s
, "aclk_out");
1628 switch ((value
>> 0) & 3) {
1630 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1631 omap_clk_onoff(clk
, 1);
1634 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
1635 omap_clk_onoff(clk
, 1);
1638 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1639 omap_clk_onoff(clk
, 1);
1642 omap_clk_onoff(clk
, 0);
1647 static void omap_clkm_write(void *opaque
, hwaddr addr
,
1648 uint64_t value
, unsigned size
)
1650 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1653 static const char *clkschemename
[8] = {
1654 "fully synchronous", "fully asynchronous", "synchronous scalable",
1655 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1659 omap_badwidth_write16(opaque
, addr
, value
);
1664 case 0x00: /* ARM_CKCTL */
1665 diff
= s
->clkm
.arm_ckctl
^ value
;
1666 s
->clkm
.arm_ckctl
= value
& 0x7fff;
1667 omap_clkm_ckctl_update(s
, diff
, value
);
1670 case 0x04: /* ARM_IDLECT1 */
1671 diff
= s
->clkm
.arm_idlect1
^ value
;
1672 s
->clkm
.arm_idlect1
= value
& 0x0fff;
1673 omap_clkm_idlect1_update(s
, diff
, value
);
1676 case 0x08: /* ARM_IDLECT2 */
1677 diff
= s
->clkm
.arm_idlect2
^ value
;
1678 s
->clkm
.arm_idlect2
= value
& 0x07ff;
1679 omap_clkm_idlect2_update(s
, diff
, value
);
1682 case 0x0c: /* ARM_EWUPCT */
1683 s
->clkm
.arm_ewupct
= value
& 0x003f;
1686 case 0x10: /* ARM_RSTCT1 */
1687 diff
= s
->clkm
.arm_rstct1
^ value
;
1688 s
->clkm
.arm_rstct1
= value
& 0x0007;
1690 qemu_system_reset_request();
1691 s
->clkm
.cold_start
= 0xa;
1693 if (diff
& ~value
& 4) { /* DSP_RST */
1695 omap_tipb_bridge_reset(s
->private_tipb
);
1696 omap_tipb_bridge_reset(s
->public_tipb
);
1698 if (diff
& 2) { /* DSP_EN */
1699 clk
= omap_findclk(s
, "dsp_ck");
1700 omap_clk_canidle(clk
, (~value
>> 1) & 1);
1704 case 0x14: /* ARM_RSTCT2 */
1705 s
->clkm
.arm_rstct2
= value
& 0x0001;
1708 case 0x18: /* ARM_SYSST */
1709 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
1710 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
1711 printf("%s: clocking scheme set to %s\n", __FUNCTION__
,
1712 clkschemename
[s
->clkm
.clocking_scheme
]);
1714 s
->clkm
.cold_start
&= value
& 0x3f;
1717 case 0x1c: /* ARM_CKOUT1 */
1718 diff
= s
->clkm
.arm_ckout1
^ value
;
1719 s
->clkm
.arm_ckout1
= value
& 0x003f;
1720 omap_clkm_ckout1_update(s
, diff
, value
);
1723 case 0x20: /* ARM_CKOUT2 */
1729 static const MemoryRegionOps omap_clkm_ops
= {
1730 .read
= omap_clkm_read
,
1731 .write
= omap_clkm_write
,
1732 .endianness
= DEVICE_NATIVE_ENDIAN
,
1735 static uint64_t omap_clkdsp_read(void *opaque
, hwaddr addr
,
1738 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1739 CPUState
*cpu
= CPU(s
->cpu
);
1742 return omap_badwidth_read16(opaque
, addr
);
1746 case 0x04: /* DSP_IDLECT1 */
1747 return s
->clkm
.dsp_idlect1
;
1749 case 0x08: /* DSP_IDLECT2 */
1750 return s
->clkm
.dsp_idlect2
;
1752 case 0x14: /* DSP_RSTCT2 */
1753 return s
->clkm
.dsp_rstct2
;
1755 case 0x18: /* DSP_SYSST */
1757 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
1758 (cpu
->halted
<< 6); /* Quite useless... */
1765 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
1766 uint16_t diff
, uint16_t value
)
1770 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1773 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
1774 uint16_t diff
, uint16_t value
)
1778 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1781 static void omap_clkdsp_write(void *opaque
, hwaddr addr
,
1782 uint64_t value
, unsigned size
)
1784 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1788 omap_badwidth_write16(opaque
, addr
, value
);
1793 case 0x04: /* DSP_IDLECT1 */
1794 diff
= s
->clkm
.dsp_idlect1
^ value
;
1795 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
1796 omap_clkdsp_idlect1_update(s
, diff
, value
);
1799 case 0x08: /* DSP_IDLECT2 */
1800 s
->clkm
.dsp_idlect2
= value
& 0x0037;
1801 diff
= s
->clkm
.dsp_idlect1
^ value
;
1802 omap_clkdsp_idlect2_update(s
, diff
, value
);
1805 case 0x14: /* DSP_RSTCT2 */
1806 s
->clkm
.dsp_rstct2
= value
& 0x0001;
1809 case 0x18: /* DSP_SYSST */
1810 s
->clkm
.cold_start
&= value
& 0x3f;
1818 static const MemoryRegionOps omap_clkdsp_ops
= {
1819 .read
= omap_clkdsp_read
,
1820 .write
= omap_clkdsp_write
,
1821 .endianness
= DEVICE_NATIVE_ENDIAN
,
1824 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
1826 if (s
->wdt
&& s
->wdt
->reset
)
1827 s
->clkm
.cold_start
= 0x6;
1828 s
->clkm
.clocking_scheme
= 0;
1829 omap_clkm_ckctl_update(s
, ~0, 0x3000);
1830 s
->clkm
.arm_ckctl
= 0x3000;
1831 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
1832 s
->clkm
.arm_idlect1
= 0x0400;
1833 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
1834 s
->clkm
.arm_idlect2
= 0x0100;
1835 s
->clkm
.arm_ewupct
= 0x003f;
1836 s
->clkm
.arm_rstct1
= 0x0000;
1837 s
->clkm
.arm_rstct2
= 0x0000;
1838 s
->clkm
.arm_ckout1
= 0x0015;
1839 s
->clkm
.dpll1_mode
= 0x2002;
1840 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
1841 s
->clkm
.dsp_idlect1
= 0x0040;
1842 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
1843 s
->clkm
.dsp_idlect2
= 0x0000;
1844 s
->clkm
.dsp_rstct2
= 0x0000;
1847 static void omap_clkm_init(MemoryRegion
*memory
, hwaddr mpu_base
,
1848 hwaddr dsp_base
, struct omap_mpu_state_s
*s
)
1850 memory_region_init_io(&s
->clkm_iomem
, NULL
, &omap_clkm_ops
, s
,
1851 "omap-clkm", 0x100);
1852 memory_region_init_io(&s
->clkdsp_iomem
, NULL
, &omap_clkdsp_ops
, s
,
1853 "omap-clkdsp", 0x1000);
1855 s
->clkm
.arm_idlect1
= 0x03ff;
1856 s
->clkm
.arm_idlect2
= 0x0100;
1857 s
->clkm
.dsp_idlect1
= 0x0002;
1859 s
->clkm
.cold_start
= 0x3a;
1861 memory_region_add_subregion(memory
, mpu_base
, &s
->clkm_iomem
);
1862 memory_region_add_subregion(memory
, dsp_base
, &s
->clkdsp_iomem
);
1866 struct omap_mpuio_s
{
1870 qemu_irq handler
[16];
1892 static void omap_mpuio_set(void *opaque
, int line
, int level
)
1894 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1895 uint16_t prev
= s
->inputs
;
1898 s
->inputs
|= 1 << line
;
1900 s
->inputs
&= ~(1 << line
);
1902 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
1903 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
1904 s
->ints
|= 1 << line
;
1905 qemu_irq_raise(s
->irq
);
1908 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1909 (s
->event
>> 1) == line
) /* PIN_SELECT */
1910 s
->latch
= s
->inputs
;
1914 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
1917 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
1919 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
1923 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
1924 s
->row_latch
= ~rows
;
1927 static uint64_t omap_mpuio_read(void *opaque
, hwaddr addr
,
1930 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1931 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1935 return omap_badwidth_read16(opaque
, addr
);
1939 case 0x00: /* INPUT_LATCH */
1942 case 0x04: /* OUTPUT_REG */
1945 case 0x08: /* IO_CNTL */
1948 case 0x10: /* KBR_LATCH */
1949 return s
->row_latch
;
1951 case 0x14: /* KBC_REG */
1954 case 0x18: /* GPIO_EVENT_MODE_REG */
1957 case 0x1c: /* GPIO_INT_EDGE_REG */
1960 case 0x20: /* KBD_INT */
1961 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
1963 case 0x24: /* GPIO_INT */
1967 qemu_irq_lower(s
->irq
);
1970 case 0x28: /* KBD_MASKIT */
1973 case 0x2c: /* GPIO_MASKIT */
1976 case 0x30: /* GPIO_DEBOUNCING_REG */
1979 case 0x34: /* GPIO_LATCH_REG */
1987 static void omap_mpuio_write(void *opaque
, hwaddr addr
,
1988 uint64_t value
, unsigned size
)
1990 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1991 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1996 omap_badwidth_write16(opaque
, addr
, value
);
2001 case 0x04: /* OUTPUT_REG */
2002 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2004 while ((ln
= ctz32(diff
)) != 32) {
2006 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2011 case 0x08: /* IO_CNTL */
2012 diff
= s
->outputs
& (s
->dir
^ value
);
2015 value
= s
->outputs
& ~s
->dir
;
2016 while ((ln
= ctz32(diff
)) != 32) {
2018 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2023 case 0x14: /* KBC_REG */
2025 omap_mpuio_kbd_update(s
);
2028 case 0x18: /* GPIO_EVENT_MODE_REG */
2029 s
->event
= value
& 0x1f;
2032 case 0x1c: /* GPIO_INT_EDGE_REG */
2036 case 0x28: /* KBD_MASKIT */
2037 s
->kbd_mask
= value
& 1;
2038 omap_mpuio_kbd_update(s
);
2041 case 0x2c: /* GPIO_MASKIT */
2045 case 0x30: /* GPIO_DEBOUNCING_REG */
2046 s
->debounce
= value
& 0x1ff;
2049 case 0x00: /* INPUT_LATCH */
2050 case 0x10: /* KBR_LATCH */
2051 case 0x20: /* KBD_INT */
2052 case 0x24: /* GPIO_INT */
2053 case 0x34: /* GPIO_LATCH_REG */
2063 static const MemoryRegionOps omap_mpuio_ops
= {
2064 .read
= omap_mpuio_read
,
2065 .write
= omap_mpuio_write
,
2066 .endianness
= DEVICE_NATIVE_ENDIAN
,
2069 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2081 s
->row_latch
= 0x1f;
2085 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2087 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2091 omap_mpuio_kbd_update(s
);
2094 static struct omap_mpuio_s
*omap_mpuio_init(MemoryRegion
*memory
,
2096 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2099 struct omap_mpuio_s
*s
= g_new0(struct omap_mpuio_s
, 1);
2102 s
->kbd_irq
= kbd_int
;
2104 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2105 omap_mpuio_reset(s
);
2107 memory_region_init_io(&s
->iomem
, NULL
, &omap_mpuio_ops
, s
,
2108 "omap-mpuio", 0x800);
2109 memory_region_add_subregion(memory
, base
, &s
->iomem
);
2111 omap_clk_adduser(clk
, qemu_allocate_irq(omap_mpuio_onoff
, s
, 0));
2116 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2121 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2123 if (line
>= 16 || line
< 0)
2124 hw_error("%s: No GPIO line %i\n", __FUNCTION__
, line
);
2125 s
->handler
[line
] = handler
;
2128 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2130 if (row
>= 5 || row
< 0)
2131 hw_error("%s: No key %i-%i\n", __FUNCTION__
, col
, row
);
2134 s
->buttons
[row
] |= 1 << col
;
2136 s
->buttons
[row
] &= ~(1 << col
);
2138 omap_mpuio_kbd_update(s
);
2141 /* MicroWire Interface */
2142 struct omap_uwire_s
{
2153 uWireSlave
*chip
[4];
2156 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
2158 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
2159 uWireSlave
*slave
= s
->chip
[chipselect
];
2161 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
2162 if (s
->control
& (1 << 12)) /* CS_CMD */
2163 if (slave
&& slave
->send
)
2164 slave
->send(slave
->opaque
,
2165 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
2166 s
->control
&= ~(1 << 14); /* CSRB */
2167 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2168 * a DRQ. When is the level IRQ supposed to be reset? */
2171 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
2172 if (s
->control
& (1 << 12)) /* CS_CMD */
2173 if (slave
&& slave
->receive
)
2174 s
->rxbuf
= slave
->receive(slave
->opaque
);
2175 s
->control
|= 1 << 15; /* RDRB */
2176 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2177 * a DRQ. When is the level IRQ supposed to be reset? */
2181 static uint64_t omap_uwire_read(void *opaque
, hwaddr addr
,
2184 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2185 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2188 return omap_badwidth_read16(opaque
, addr
);
2192 case 0x00: /* RDR */
2193 s
->control
&= ~(1 << 15); /* RDRB */
2196 case 0x04: /* CSR */
2199 case 0x08: /* SR1 */
2201 case 0x0c: /* SR2 */
2203 case 0x10: /* SR3 */
2205 case 0x14: /* SR4 */
2207 case 0x18: /* SR5 */
2215 static void omap_uwire_write(void *opaque
, hwaddr addr
,
2216 uint64_t value
, unsigned size
)
2218 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2219 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2222 omap_badwidth_write16(opaque
, addr
, value
);
2227 case 0x00: /* TDR */
2228 s
->txbuf
= value
; /* TD */
2229 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
2230 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2231 (s
->control
& (1 << 12)))) { /* CS_CMD */
2232 s
->control
|= 1 << 14; /* CSRB */
2233 omap_uwire_transfer_start(s
);
2237 case 0x04: /* CSR */
2238 s
->control
= value
& 0x1fff;
2239 if (value
& (1 << 13)) /* START */
2240 omap_uwire_transfer_start(s
);
2243 case 0x08: /* SR1 */
2244 s
->setup
[0] = value
& 0x003f;
2247 case 0x0c: /* SR2 */
2248 s
->setup
[1] = value
& 0x0fc0;
2251 case 0x10: /* SR3 */
2252 s
->setup
[2] = value
& 0x0003;
2255 case 0x14: /* SR4 */
2256 s
->setup
[3] = value
& 0x0001;
2259 case 0x18: /* SR5 */
2260 s
->setup
[4] = value
& 0x000f;
2269 static const MemoryRegionOps omap_uwire_ops
= {
2270 .read
= omap_uwire_read
,
2271 .write
= omap_uwire_write
,
2272 .endianness
= DEVICE_NATIVE_ENDIAN
,
2275 static void omap_uwire_reset(struct omap_uwire_s
*s
)
2285 static struct omap_uwire_s
*omap_uwire_init(MemoryRegion
*system_memory
,
2287 qemu_irq txirq
, qemu_irq rxirq
,
2291 struct omap_uwire_s
*s
= g_new0(struct omap_uwire_s
, 1);
2296 omap_uwire_reset(s
);
2298 memory_region_init_io(&s
->iomem
, NULL
, &omap_uwire_ops
, s
, "omap-uwire", 0x800);
2299 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2304 void omap_uwire_attach(struct omap_uwire_s
*s
,
2305 uWireSlave
*slave
, int chipselect
)
2307 if (chipselect
< 0 || chipselect
> 3) {
2308 fprintf(stderr
, "%s: Bad chipselect %i\n", __FUNCTION__
, chipselect
);
2312 s
->chip
[chipselect
] = slave
;
2315 /* Pseudonoise Pulse-Width Light Modulator */
2324 static void omap_pwl_update(struct omap_pwl_s
*s
)
2326 int output
= (s
->clk
&& s
->enable
) ? s
->level
: 0;
2328 if (output
!= s
->output
) {
2330 printf("%s: Backlight now at %i/256\n", __FUNCTION__
, output
);
2334 static uint64_t omap_pwl_read(void *opaque
, hwaddr addr
,
2337 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2338 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2341 return omap_badwidth_read8(opaque
, addr
);
2345 case 0x00: /* PWL_LEVEL */
2347 case 0x04: /* PWL_CTRL */
2354 static void omap_pwl_write(void *opaque
, hwaddr addr
,
2355 uint64_t value
, unsigned size
)
2357 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2358 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2361 omap_badwidth_write8(opaque
, addr
, value
);
2366 case 0x00: /* PWL_LEVEL */
2370 case 0x04: /* PWL_CTRL */
2371 s
->enable
= value
& 1;
2380 static const MemoryRegionOps omap_pwl_ops
= {
2381 .read
= omap_pwl_read
,
2382 .write
= omap_pwl_write
,
2383 .endianness
= DEVICE_NATIVE_ENDIAN
,
2386 static void omap_pwl_reset(struct omap_pwl_s
*s
)
2395 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
2397 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2403 static struct omap_pwl_s
*omap_pwl_init(MemoryRegion
*system_memory
,
2407 struct omap_pwl_s
*s
= g_malloc0(sizeof(*s
));
2411 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwl_ops
, s
,
2413 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2415 omap_clk_adduser(clk
, qemu_allocate_irq(omap_pwl_clk_update
, s
, 0));
2419 /* Pulse-Width Tone module */
2428 static uint64_t omap_pwt_read(void *opaque
, hwaddr addr
,
2431 struct omap_pwt_s
*s
= (struct omap_pwt_s
*) opaque
;
2432 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2435 return omap_badwidth_read8(opaque
, addr
);
2439 case 0x00: /* FRC */
2441 case 0x04: /* VCR */
2443 case 0x08: /* GCR */
2450 static void omap_pwt_write(void *opaque
, hwaddr addr
,
2451 uint64_t value
, unsigned size
)
2453 struct omap_pwt_s
*s
= (struct omap_pwt_s
*) opaque
;
2454 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2457 omap_badwidth_write8(opaque
, addr
, value
);
2462 case 0x00: /* FRC */
2463 s
->frc
= value
& 0x3f;
2465 case 0x04: /* VRC */
2466 if ((value
^ s
->vrc
) & 1) {
2468 printf("%s: %iHz buzz on\n", __FUNCTION__
, (int)
2469 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2470 ((omap_clk_getrate(s
->clk
) >> 3) /
2471 /* Pre-multiplexer divider */
2472 ((s
->gcr
& 2) ? 1 : 154) /
2473 /* Octave multiplexer */
2474 (2 << (value
& 3)) *
2475 /* 101/107 divider */
2476 ((value
& (1 << 2)) ? 101 : 107) *
2478 ((value
& (1 << 3)) ? 49 : 55) *
2480 ((value
& (1 << 4)) ? 50 : 63) *
2481 /* 80/127 divider */
2482 ((value
& (1 << 5)) ? 80 : 127) /
2483 (107 * 55 * 63 * 127)));
2485 printf("%s: silence!\n", __FUNCTION__
);
2487 s
->vrc
= value
& 0x7f;
2489 case 0x08: /* GCR */
2498 static const MemoryRegionOps omap_pwt_ops
= {
2499 .read
=omap_pwt_read
,
2500 .write
= omap_pwt_write
,
2501 .endianness
= DEVICE_NATIVE_ENDIAN
,
2504 static void omap_pwt_reset(struct omap_pwt_s
*s
)
2511 static struct omap_pwt_s
*omap_pwt_init(MemoryRegion
*system_memory
,
2515 struct omap_pwt_s
*s
= g_malloc0(sizeof(*s
));
2519 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwt_ops
, s
,
2521 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2525 /* Real-time Clock module */
2542 struct tm current_tm
;
2547 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
2549 /* s->alarm is level-triggered */
2550 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
2553 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
2555 s
->alarm_ti
= mktimegm(&s
->alarm_tm
);
2556 if (s
->alarm_ti
== -1)
2557 printf("%s: conversion failed\n", __FUNCTION__
);
2560 static uint64_t omap_rtc_read(void *opaque
, hwaddr addr
,
2563 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2564 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2568 return omap_badwidth_read8(opaque
, addr
);
2572 case 0x00: /* SECONDS_REG */
2573 return to_bcd(s
->current_tm
.tm_sec
);
2575 case 0x04: /* MINUTES_REG */
2576 return to_bcd(s
->current_tm
.tm_min
);
2578 case 0x08: /* HOURS_REG */
2580 return ((s
->current_tm
.tm_hour
> 11) << 7) |
2581 to_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
2583 return to_bcd(s
->current_tm
.tm_hour
);
2585 case 0x0c: /* DAYS_REG */
2586 return to_bcd(s
->current_tm
.tm_mday
);
2588 case 0x10: /* MONTHS_REG */
2589 return to_bcd(s
->current_tm
.tm_mon
+ 1);
2591 case 0x14: /* YEARS_REG */
2592 return to_bcd(s
->current_tm
.tm_year
% 100);
2594 case 0x18: /* WEEK_REG */
2595 return s
->current_tm
.tm_wday
;
2597 case 0x20: /* ALARM_SECONDS_REG */
2598 return to_bcd(s
->alarm_tm
.tm_sec
);
2600 case 0x24: /* ALARM_MINUTES_REG */
2601 return to_bcd(s
->alarm_tm
.tm_min
);
2603 case 0x28: /* ALARM_HOURS_REG */
2605 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
2606 to_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
2608 return to_bcd(s
->alarm_tm
.tm_hour
);
2610 case 0x2c: /* ALARM_DAYS_REG */
2611 return to_bcd(s
->alarm_tm
.tm_mday
);
2613 case 0x30: /* ALARM_MONTHS_REG */
2614 return to_bcd(s
->alarm_tm
.tm_mon
+ 1);
2616 case 0x34: /* ALARM_YEARS_REG */
2617 return to_bcd(s
->alarm_tm
.tm_year
% 100);
2619 case 0x40: /* RTC_CTRL_REG */
2620 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
2621 (s
->round
<< 1) | s
->running
;
2623 case 0x44: /* RTC_STATUS_REG */
2628 case 0x48: /* RTC_INTERRUPTS_REG */
2629 return s
->interrupts
;
2631 case 0x4c: /* RTC_COMP_LSB_REG */
2632 return ((uint16_t) s
->comp_reg
) & 0xff;
2634 case 0x50: /* RTC_COMP_MSB_REG */
2635 return ((uint16_t) s
->comp_reg
) >> 8;
2642 static void omap_rtc_write(void *opaque
, hwaddr addr
,
2643 uint64_t value
, unsigned size
)
2645 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2646 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2651 omap_badwidth_write8(opaque
, addr
, value
);
2656 case 0x00: /* SECONDS_REG */
2658 printf("RTC SEC_REG <-- %02x\n", value
);
2660 s
->ti
-= s
->current_tm
.tm_sec
;
2661 s
->ti
+= from_bcd(value
);
2664 case 0x04: /* MINUTES_REG */
2666 printf("RTC MIN_REG <-- %02x\n", value
);
2668 s
->ti
-= s
->current_tm
.tm_min
* 60;
2669 s
->ti
+= from_bcd(value
) * 60;
2672 case 0x08: /* HOURS_REG */
2674 printf("RTC HRS_REG <-- %02x\n", value
);
2676 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
2678 s
->ti
+= (from_bcd(value
& 0x3f) & 12) * 3600;
2679 s
->ti
+= ((value
>> 7) & 1) * 43200;
2681 s
->ti
+= from_bcd(value
& 0x3f) * 3600;
2684 case 0x0c: /* DAYS_REG */
2686 printf("RTC DAY_REG <-- %02x\n", value
);
2688 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
2689 s
->ti
+= from_bcd(value
) * 86400;
2692 case 0x10: /* MONTHS_REG */
2694 printf("RTC MTH_REG <-- %02x\n", value
);
2696 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2697 new_tm
.tm_mon
= from_bcd(value
);
2698 ti
[0] = mktimegm(&s
->current_tm
);
2699 ti
[1] = mktimegm(&new_tm
);
2701 if (ti
[0] != -1 && ti
[1] != -1) {
2705 /* A less accurate version */
2706 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
2707 s
->ti
+= from_bcd(value
) * 2592000;
2711 case 0x14: /* YEARS_REG */
2713 printf("RTC YRS_REG <-- %02x\n", value
);
2715 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2716 new_tm
.tm_year
+= from_bcd(value
) - (new_tm
.tm_year
% 100);
2717 ti
[0] = mktimegm(&s
->current_tm
);
2718 ti
[1] = mktimegm(&new_tm
);
2720 if (ti
[0] != -1 && ti
[1] != -1) {
2724 /* A less accurate version */
2725 s
->ti
-= (time_t)(s
->current_tm
.tm_year
% 100) * 31536000;
2726 s
->ti
+= (time_t)from_bcd(value
) * 31536000;
2730 case 0x18: /* WEEK_REG */
2731 return; /* Ignored */
2733 case 0x20: /* ALARM_SECONDS_REG */
2735 printf("ALM SEC_REG <-- %02x\n", value
);
2737 s
->alarm_tm
.tm_sec
= from_bcd(value
);
2738 omap_rtc_alarm_update(s
);
2741 case 0x24: /* ALARM_MINUTES_REG */
2743 printf("ALM MIN_REG <-- %02x\n", value
);
2745 s
->alarm_tm
.tm_min
= from_bcd(value
);
2746 omap_rtc_alarm_update(s
);
2749 case 0x28: /* ALARM_HOURS_REG */
2751 printf("ALM HRS_REG <-- %02x\n", value
);
2754 s
->alarm_tm
.tm_hour
=
2755 ((from_bcd(value
& 0x3f)) % 12) +
2756 ((value
>> 7) & 1) * 12;
2758 s
->alarm_tm
.tm_hour
= from_bcd(value
);
2759 omap_rtc_alarm_update(s
);
2762 case 0x2c: /* ALARM_DAYS_REG */
2764 printf("ALM DAY_REG <-- %02x\n", value
);
2766 s
->alarm_tm
.tm_mday
= from_bcd(value
);
2767 omap_rtc_alarm_update(s
);
2770 case 0x30: /* ALARM_MONTHS_REG */
2772 printf("ALM MON_REG <-- %02x\n", value
);
2774 s
->alarm_tm
.tm_mon
= from_bcd(value
);
2775 omap_rtc_alarm_update(s
);
2778 case 0x34: /* ALARM_YEARS_REG */
2780 printf("ALM YRS_REG <-- %02x\n", value
);
2782 s
->alarm_tm
.tm_year
= from_bcd(value
);
2783 omap_rtc_alarm_update(s
);
2786 case 0x40: /* RTC_CTRL_REG */
2788 printf("RTC CONTROL <-- %02x\n", value
);
2790 s
->pm_am
= (value
>> 3) & 1;
2791 s
->auto_comp
= (value
>> 2) & 1;
2792 s
->round
= (value
>> 1) & 1;
2793 s
->running
= value
& 1;
2795 s
->status
|= s
->running
<< 1;
2798 case 0x44: /* RTC_STATUS_REG */
2800 printf("RTC STATUSL <-- %02x\n", value
);
2802 s
->status
&= ~((value
& 0xc0) ^ 0x80);
2803 omap_rtc_interrupts_update(s
);
2806 case 0x48: /* RTC_INTERRUPTS_REG */
2808 printf("RTC INTRS <-- %02x\n", value
);
2810 s
->interrupts
= value
;
2813 case 0x4c: /* RTC_COMP_LSB_REG */
2815 printf("RTC COMPLSB <-- %02x\n", value
);
2817 s
->comp_reg
&= 0xff00;
2818 s
->comp_reg
|= 0x00ff & value
;
2821 case 0x50: /* RTC_COMP_MSB_REG */
2823 printf("RTC COMPMSB <-- %02x\n", value
);
2825 s
->comp_reg
&= 0x00ff;
2826 s
->comp_reg
|= 0xff00 & (value
<< 8);
2835 static const MemoryRegionOps omap_rtc_ops
= {
2836 .read
= omap_rtc_read
,
2837 .write
= omap_rtc_write
,
2838 .endianness
= DEVICE_NATIVE_ENDIAN
,
2841 static void omap_rtc_tick(void *opaque
)
2843 struct omap_rtc_s
*s
= opaque
;
2846 /* Round to nearest full minute. */
2847 if (s
->current_tm
.tm_sec
< 30)
2848 s
->ti
-= s
->current_tm
.tm_sec
;
2850 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
2855 localtime_r(&s
->ti
, &s
->current_tm
);
2857 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
2859 omap_rtc_interrupts_update(s
);
2862 if (s
->interrupts
& 0x04)
2863 switch (s
->interrupts
& 3) {
2866 qemu_irq_pulse(s
->irq
);
2869 if (s
->current_tm
.tm_sec
)
2872 qemu_irq_pulse(s
->irq
);
2875 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
2878 qemu_irq_pulse(s
->irq
);
2881 if (s
->current_tm
.tm_sec
||
2882 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
2885 qemu_irq_pulse(s
->irq
);
2895 * Every full hour add a rough approximation of the compensation
2896 * register to the 32kHz Timer (which drives the RTC) value.
2898 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
2899 s
->tick
+= s
->comp_reg
* 1000 / 32768;
2901 timer_mod(s
->clk
, s
->tick
);
2904 static void omap_rtc_reset(struct omap_rtc_s
*s
)
2914 s
->tick
= qemu_clock_get_ms(rtc_clock
);
2915 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
2916 s
->alarm_tm
.tm_mday
= 0x01;
2918 qemu_get_timedate(&tm
, 0);
2919 s
->ti
= mktimegm(&tm
);
2921 omap_rtc_alarm_update(s
);
2925 static struct omap_rtc_s
*omap_rtc_init(MemoryRegion
*system_memory
,
2927 qemu_irq timerirq
, qemu_irq alarmirq
,
2930 struct omap_rtc_s
*s
= g_new0(struct omap_rtc_s
, 1);
2933 s
->alarm
= alarmirq
;
2934 s
->clk
= timer_new_ms(rtc_clock
, omap_rtc_tick
, s
);
2938 memory_region_init_io(&s
->iomem
, NULL
, &omap_rtc_ops
, s
,
2940 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2945 /* Multi-channel Buffered Serial Port interfaces */
2946 struct omap_mcbsp_s
{
2967 QEMUTimer
*source_timer
;
2968 QEMUTimer
*sink_timer
;
2971 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
2975 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
2977 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
2980 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
2988 qemu_irq_pulse(s
->rxirq
);
2990 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
2992 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
2995 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
3003 qemu_irq_pulse(s
->txirq
);
3006 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
3008 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
3009 s
->spcr
[0] |= 1 << 2; /* RFULL */
3010 s
->spcr
[0] |= 1 << 1; /* RRDY */
3011 qemu_irq_raise(s
->rxdrq
);
3012 omap_mcbsp_intr_update(s
);
3015 static void omap_mcbsp_source_tick(void *opaque
)
3017 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3018 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3023 printf("%s: Rx FIFO overrun\n", __FUNCTION__
);
3025 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
3027 omap_mcbsp_rx_newdata(s
);
3028 timer_mod(s
->source_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3029 get_ticks_per_sec());
3032 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
3034 if (!s
->codec
|| !s
->codec
->rts
)
3035 omap_mcbsp_source_tick(s
);
3036 else if (s
->codec
->in
.len
) {
3037 s
->rx_req
= s
->codec
->in
.len
;
3038 omap_mcbsp_rx_newdata(s
);
3042 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
3044 timer_del(s
->source_timer
);
3047 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
3049 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
3050 qemu_irq_lower(s
->rxdrq
);
3051 omap_mcbsp_intr_update(s
);
3054 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
3056 s
->spcr
[1] |= 1 << 1; /* XRDY */
3057 qemu_irq_raise(s
->txdrq
);
3058 omap_mcbsp_intr_update(s
);
3061 static void omap_mcbsp_sink_tick(void *opaque
)
3063 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3064 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3069 printf("%s: Tx FIFO underrun\n", __FUNCTION__
);
3071 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
3073 omap_mcbsp_tx_newdata(s
);
3074 timer_mod(s
->sink_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3075 get_ticks_per_sec());
3078 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
3080 if (!s
->codec
|| !s
->codec
->cts
)
3081 omap_mcbsp_sink_tick(s
);
3082 else if (s
->codec
->out
.size
) {
3083 s
->tx_req
= s
->codec
->out
.size
;
3084 omap_mcbsp_tx_newdata(s
);
3088 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
3090 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
3091 qemu_irq_lower(s
->txdrq
);
3092 omap_mcbsp_intr_update(s
);
3093 if (s
->codec
&& s
->codec
->cts
)
3094 s
->codec
->tx_swallow(s
->codec
->opaque
);
3097 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
3100 omap_mcbsp_tx_done(s
);
3101 timer_del(s
->sink_timer
);
3104 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
3106 int prev_rx_rate
, prev_tx_rate
;
3107 int rx_rate
= 0, tx_rate
= 0;
3108 int cpu_rate
= 1500000; /* XXX */
3110 /* TODO: check CLKSTP bit */
3111 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3112 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3113 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3114 (s
->pcr
& (1 << 8))) { /* CLKRM */
3115 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3116 rx_rate
= cpu_rate
/
3117 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3120 rx_rate
= s
->codec
->rx_rate
;
3123 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3124 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3125 (s
->pcr
& (1 << 9))) { /* CLKXM */
3126 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3127 tx_rate
= cpu_rate
/
3128 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3131 tx_rate
= s
->codec
->tx_rate
;
3134 prev_tx_rate
= s
->tx_rate
;
3135 prev_rx_rate
= s
->rx_rate
;
3136 s
->tx_rate
= tx_rate
;
3137 s
->rx_rate
= rx_rate
;
3140 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3142 if (!prev_tx_rate
&& tx_rate
)
3143 omap_mcbsp_tx_start(s
);
3144 else if (s
->tx_rate
&& !tx_rate
)
3145 omap_mcbsp_tx_stop(s
);
3147 if (!prev_rx_rate
&& rx_rate
)
3148 omap_mcbsp_rx_start(s
);
3149 else if (prev_tx_rate
&& !tx_rate
)
3150 omap_mcbsp_rx_stop(s
);
3153 static uint64_t omap_mcbsp_read(void *opaque
, hwaddr addr
,
3156 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3157 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3161 return omap_badwidth_read16(opaque
, addr
);
3165 case 0x00: /* DRR2 */
3166 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
3169 case 0x02: /* DRR1 */
3170 if (s
->rx_req
< 2) {
3171 printf("%s: Rx FIFO underrun\n", __FUNCTION__
);
3172 omap_mcbsp_rx_done(s
);
3175 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
3176 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
3177 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
3178 s
->codec
->in
.len
-= 2;
3182 omap_mcbsp_rx_done(s
);
3187 case 0x04: /* DXR2 */
3188 case 0x06: /* DXR1 */
3191 case 0x08: /* SPCR2 */
3193 case 0x0a: /* SPCR1 */
3195 case 0x0c: /* RCR2 */
3197 case 0x0e: /* RCR1 */
3199 case 0x10: /* XCR2 */
3201 case 0x12: /* XCR1 */
3203 case 0x14: /* SRGR2 */
3205 case 0x16: /* SRGR1 */
3207 case 0x18: /* MCR2 */
3209 case 0x1a: /* MCR1 */
3211 case 0x1c: /* RCERA */
3213 case 0x1e: /* RCERB */
3215 case 0x20: /* XCERA */
3217 case 0x22: /* XCERB */
3219 case 0x24: /* PCR0 */
3221 case 0x26: /* RCERC */
3223 case 0x28: /* RCERD */
3225 case 0x2a: /* XCERC */
3227 case 0x2c: /* XCERD */
3229 case 0x2e: /* RCERE */
3231 case 0x30: /* RCERF */
3233 case 0x32: /* XCERE */
3235 case 0x34: /* XCERF */
3237 case 0x36: /* RCERG */
3239 case 0x38: /* RCERH */
3241 case 0x3a: /* XCERG */
3243 case 0x3c: /* XCERH */
3251 static void omap_mcbsp_writeh(void *opaque
, hwaddr addr
,
3254 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3255 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3258 case 0x00: /* DRR2 */
3259 case 0x02: /* DRR1 */
3263 case 0x04: /* DXR2 */
3264 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3267 case 0x06: /* DXR1 */
3268 if (s
->tx_req
> 1) {
3270 if (s
->codec
&& s
->codec
->cts
) {
3271 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
3272 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
3275 omap_mcbsp_tx_done(s
);
3277 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
3280 case 0x08: /* SPCR2 */
3281 s
->spcr
[1] &= 0x0002;
3282 s
->spcr
[1] |= 0x03f9 & value
;
3283 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
3284 if (~value
& 1) /* XRST */
3286 omap_mcbsp_req_update(s
);
3288 case 0x0a: /* SPCR1 */
3289 s
->spcr
[0] &= 0x0006;
3290 s
->spcr
[0] |= 0xf8f9 & value
;
3291 if (value
& (1 << 15)) /* DLB */
3292 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__
);
3293 if (~value
& 1) { /* RRST */
3296 omap_mcbsp_rx_done(s
);
3298 omap_mcbsp_req_update(s
);
3301 case 0x0c: /* RCR2 */
3302 s
->rcr
[1] = value
& 0xffff;
3304 case 0x0e: /* RCR1 */
3305 s
->rcr
[0] = value
& 0x7fe0;
3307 case 0x10: /* XCR2 */
3308 s
->xcr
[1] = value
& 0xffff;
3310 case 0x12: /* XCR1 */
3311 s
->xcr
[0] = value
& 0x7fe0;
3313 case 0x14: /* SRGR2 */
3314 s
->srgr
[1] = value
& 0xffff;
3315 omap_mcbsp_req_update(s
);
3317 case 0x16: /* SRGR1 */
3318 s
->srgr
[0] = value
& 0xffff;
3319 omap_mcbsp_req_update(s
);
3321 case 0x18: /* MCR2 */
3322 s
->mcr
[1] = value
& 0x03e3;
3323 if (value
& 3) /* XMCM */
3324 printf("%s: Tx channel selection mode enable attempt\n",
3327 case 0x1a: /* MCR1 */
3328 s
->mcr
[0] = value
& 0x03e1;
3329 if (value
& 1) /* RMCM */
3330 printf("%s: Rx channel selection mode enable attempt\n",
3333 case 0x1c: /* RCERA */
3334 s
->rcer
[0] = value
& 0xffff;
3336 case 0x1e: /* RCERB */
3337 s
->rcer
[1] = value
& 0xffff;
3339 case 0x20: /* XCERA */
3340 s
->xcer
[0] = value
& 0xffff;
3342 case 0x22: /* XCERB */
3343 s
->xcer
[1] = value
& 0xffff;
3345 case 0x24: /* PCR0 */
3346 s
->pcr
= value
& 0x7faf;
3348 case 0x26: /* RCERC */
3349 s
->rcer
[2] = value
& 0xffff;
3351 case 0x28: /* RCERD */
3352 s
->rcer
[3] = value
& 0xffff;
3354 case 0x2a: /* XCERC */
3355 s
->xcer
[2] = value
& 0xffff;
3357 case 0x2c: /* XCERD */
3358 s
->xcer
[3] = value
& 0xffff;
3360 case 0x2e: /* RCERE */
3361 s
->rcer
[4] = value
& 0xffff;
3363 case 0x30: /* RCERF */
3364 s
->rcer
[5] = value
& 0xffff;
3366 case 0x32: /* XCERE */
3367 s
->xcer
[4] = value
& 0xffff;
3369 case 0x34: /* XCERF */
3370 s
->xcer
[5] = value
& 0xffff;
3372 case 0x36: /* RCERG */
3373 s
->rcer
[6] = value
& 0xffff;
3375 case 0x38: /* RCERH */
3376 s
->rcer
[7] = value
& 0xffff;
3378 case 0x3a: /* XCERG */
3379 s
->xcer
[6] = value
& 0xffff;
3381 case 0x3c: /* XCERH */
3382 s
->xcer
[7] = value
& 0xffff;
3389 static void omap_mcbsp_writew(void *opaque
, hwaddr addr
,
3392 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3393 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3395 if (offset
== 0x04) { /* DXR */
3396 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3398 if (s
->tx_req
> 3) {
3400 if (s
->codec
&& s
->codec
->cts
) {
3401 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3402 (value
>> 24) & 0xff;
3403 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3404 (value
>> 16) & 0xff;
3405 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3406 (value
>> 8) & 0xff;
3407 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3408 (value
>> 0) & 0xff;
3411 omap_mcbsp_tx_done(s
);
3413 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
3417 omap_badwidth_write16(opaque
, addr
, value
);
3420 static void omap_mcbsp_write(void *opaque
, hwaddr addr
,
3421 uint64_t value
, unsigned size
)
3425 omap_mcbsp_writeh(opaque
, addr
, value
);
3428 omap_mcbsp_writew(opaque
, addr
, value
);
3431 omap_badwidth_write16(opaque
, addr
, value
);
3435 static const MemoryRegionOps omap_mcbsp_ops
= {
3436 .read
= omap_mcbsp_read
,
3437 .write
= omap_mcbsp_write
,
3438 .endianness
= DEVICE_NATIVE_ENDIAN
,
3441 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
3443 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
3444 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
3445 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
3446 s
->srgr
[0] = 0x0001;
3447 s
->srgr
[1] = 0x2000;
3448 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
3449 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
3450 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
3451 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
3456 timer_del(s
->source_timer
);
3457 timer_del(s
->sink_timer
);
3460 static struct omap_mcbsp_s
*omap_mcbsp_init(MemoryRegion
*system_memory
,
3462 qemu_irq txirq
, qemu_irq rxirq
,
3463 qemu_irq
*dma
, omap_clk clk
)
3465 struct omap_mcbsp_s
*s
= g_new0(struct omap_mcbsp_s
, 1);
3471 s
->sink_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_sink_tick
, s
);
3472 s
->source_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_source_tick
, s
);
3473 omap_mcbsp_reset(s
);
3475 memory_region_init_io(&s
->iomem
, NULL
, &omap_mcbsp_ops
, s
, "omap-mcbsp", 0x800);
3476 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3481 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
3483 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3486 s
->rx_req
= s
->codec
->in
.len
;
3487 omap_mcbsp_rx_newdata(s
);
3491 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
3493 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3496 s
->tx_req
= s
->codec
->out
.size
;
3497 omap_mcbsp_tx_newdata(s
);
3501 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, I2SCodec
*slave
)
3504 slave
->rx_swallow
= qemu_allocate_irq(omap_mcbsp_i2s_swallow
, s
, 0);
3505 slave
->tx_start
= qemu_allocate_irq(omap_mcbsp_i2s_start
, s
, 0);
3508 /* LED Pulse Generators */
3521 static void omap_lpg_tick(void *opaque
)
3523 struct omap_lpg_s
*s
= opaque
;
3526 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->period
- s
->on
);
3528 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->on
);
3530 s
->cycle
= !s
->cycle
;
3531 printf("%s: LED is %s\n", __FUNCTION__
, s
->cycle
? "on" : "off");
3534 static void omap_lpg_update(struct omap_lpg_s
*s
)
3536 int64_t on
, period
= 1, ticks
= 1000;
3537 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3539 if (~s
->control
& (1 << 6)) /* LPGRES */
3541 else if (s
->control
& (1 << 7)) /* PERM_ON */
3544 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
3546 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
3547 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
3551 if (on
== period
&& s
->on
< s
->period
)
3552 printf("%s: LED is on\n", __FUNCTION__
);
3553 else if (on
== 0 && s
->on
)
3554 printf("%s: LED is off\n", __FUNCTION__
);
3555 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
3567 static void omap_lpg_reset(struct omap_lpg_s
*s
)
3575 static uint64_t omap_lpg_read(void *opaque
, hwaddr addr
,
3578 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3579 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3582 return omap_badwidth_read8(opaque
, addr
);
3586 case 0x00: /* LCR */
3589 case 0x04: /* PMR */
3597 static void omap_lpg_write(void *opaque
, hwaddr addr
,
3598 uint64_t value
, unsigned size
)
3600 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3601 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3604 omap_badwidth_write8(opaque
, addr
, value
);
3609 case 0x00: /* LCR */
3610 if (~value
& (1 << 6)) /* LPGRES */
3612 s
->control
= value
& 0xff;
3616 case 0x04: /* PMR */
3617 s
->power
= value
& 0x01;
3627 static const MemoryRegionOps omap_lpg_ops
= {
3628 .read
= omap_lpg_read
,
3629 .write
= omap_lpg_write
,
3630 .endianness
= DEVICE_NATIVE_ENDIAN
,
3633 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
3635 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3641 static struct omap_lpg_s
*omap_lpg_init(MemoryRegion
*system_memory
,
3642 hwaddr base
, omap_clk clk
)
3644 struct omap_lpg_s
*s
= g_new0(struct omap_lpg_s
, 1);
3646 s
->tm
= timer_new_ms(QEMU_CLOCK_VIRTUAL
, omap_lpg_tick
, s
);
3650 memory_region_init_io(&s
->iomem
, NULL
, &omap_lpg_ops
, s
, "omap-lpg", 0x800);
3651 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3653 omap_clk_adduser(clk
, qemu_allocate_irq(omap_lpg_clk_update
, s
, 0));
3658 /* MPUI Peripheral Bridge configuration */
3659 static uint64_t omap_mpui_io_read(void *opaque
, hwaddr addr
,
3663 return omap_badwidth_read16(opaque
, addr
);
3666 if (addr
== OMAP_MPUI_BASE
) /* CMR */
3673 static void omap_mpui_io_write(void *opaque
, hwaddr addr
,
3674 uint64_t value
, unsigned size
)
3676 /* FIXME: infinite loop */
3677 omap_badwidth_write16(opaque
, addr
, value
);
3680 static const MemoryRegionOps omap_mpui_io_ops
= {
3681 .read
= omap_mpui_io_read
,
3682 .write
= omap_mpui_io_write
,
3683 .endianness
= DEVICE_NATIVE_ENDIAN
,
3686 static void omap_setup_mpui_io(MemoryRegion
*system_memory
,
3687 struct omap_mpu_state_s
*mpu
)
3689 memory_region_init_io(&mpu
->mpui_io_iomem
, NULL
, &omap_mpui_io_ops
, mpu
,
3690 "omap-mpui-io", 0x7fff);
3691 memory_region_add_subregion(system_memory
, OMAP_MPUI_BASE
,
3692 &mpu
->mpui_io_iomem
);
3695 /* General chip reset */
3696 static void omap1_mpu_reset(void *opaque
)
3698 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3700 omap_dma_reset(mpu
->dma
);
3701 omap_mpu_timer_reset(mpu
->timer
[0]);
3702 omap_mpu_timer_reset(mpu
->timer
[1]);
3703 omap_mpu_timer_reset(mpu
->timer
[2]);
3704 omap_wd_timer_reset(mpu
->wdt
);
3705 omap_os_timer_reset(mpu
->os_timer
);
3706 omap_lcdc_reset(mpu
->lcd
);
3707 omap_ulpd_pm_reset(mpu
);
3708 omap_pin_cfg_reset(mpu
);
3709 omap_mpui_reset(mpu
);
3710 omap_tipb_bridge_reset(mpu
->private_tipb
);
3711 omap_tipb_bridge_reset(mpu
->public_tipb
);
3712 omap_dpll_reset(mpu
->dpll
[0]);
3713 omap_dpll_reset(mpu
->dpll
[1]);
3714 omap_dpll_reset(mpu
->dpll
[2]);
3715 omap_uart_reset(mpu
->uart
[0]);
3716 omap_uart_reset(mpu
->uart
[1]);
3717 omap_uart_reset(mpu
->uart
[2]);
3718 omap_mmc_reset(mpu
->mmc
);
3719 omap_mpuio_reset(mpu
->mpuio
);
3720 omap_uwire_reset(mpu
->microwire
);
3721 omap_pwl_reset(mpu
->pwl
);
3722 omap_pwt_reset(mpu
->pwt
);
3723 omap_rtc_reset(mpu
->rtc
);
3724 omap_mcbsp_reset(mpu
->mcbsp1
);
3725 omap_mcbsp_reset(mpu
->mcbsp2
);
3726 omap_mcbsp_reset(mpu
->mcbsp3
);
3727 omap_lpg_reset(mpu
->led
[0]);
3728 omap_lpg_reset(mpu
->led
[1]);
3729 omap_clkm_reset(mpu
);
3730 cpu_reset(CPU(mpu
->cpu
));
3733 static const struct omap_map_s
{
3738 } omap15xx_dsp_mm
[] = {
3740 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
3741 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
3742 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
3743 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
3744 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
3745 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
3746 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
3747 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
3748 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
3749 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
3750 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
3751 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
3752 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
3753 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
3754 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
3755 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
3756 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
3758 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
3763 static void omap_setup_dsp_mapping(MemoryRegion
*system_memory
,
3764 const struct omap_map_s
*map
)
3768 for (; map
->phys_dsp
; map
++) {
3769 io
= g_new(MemoryRegion
, 1);
3770 memory_region_init_alias(io
, NULL
, map
->name
,
3771 system_memory
, map
->phys_mpu
, map
->size
);
3772 memory_region_add_subregion(system_memory
, map
->phys_dsp
, io
);
3776 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
3778 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3779 CPUState
*cpu
= CPU(mpu
->cpu
);
3782 cpu_interrupt(cpu
, CPU_INTERRUPT_EXITTB
);
3786 static const struct dma_irq_map omap1_dma_irq_map
[] = {
3787 { 0, OMAP_INT_DMA_CH0_6
},
3788 { 0, OMAP_INT_DMA_CH1_7
},
3789 { 0, OMAP_INT_DMA_CH2_8
},
3790 { 0, OMAP_INT_DMA_CH3
},
3791 { 0, OMAP_INT_DMA_CH4
},
3792 { 0, OMAP_INT_DMA_CH5
},
3793 { 1, OMAP_INT_1610_DMA_CH6
},
3794 { 1, OMAP_INT_1610_DMA_CH7
},
3795 { 1, OMAP_INT_1610_DMA_CH8
},
3796 { 1, OMAP_INT_1610_DMA_CH9
},
3797 { 1, OMAP_INT_1610_DMA_CH10
},
3798 { 1, OMAP_INT_1610_DMA_CH11
},
3799 { 1, OMAP_INT_1610_DMA_CH12
},
3800 { 1, OMAP_INT_1610_DMA_CH13
},
3801 { 1, OMAP_INT_1610_DMA_CH14
},
3802 { 1, OMAP_INT_1610_DMA_CH15
}
3805 /* DMA ports for OMAP1 */
3806 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
3809 return range_covers_byte(OMAP_EMIFF_BASE
, s
->sdram_size
, addr
);
3812 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
3815 return range_covers_byte(OMAP_EMIFS_BASE
, OMAP_EMIFF_BASE
- OMAP_EMIFS_BASE
,
3819 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
3822 return range_covers_byte(OMAP_IMIF_BASE
, s
->sram_size
, addr
);
3825 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
3828 return range_covers_byte(0xfffb0000, 0xffff0000 - 0xfffb0000, addr
);
3831 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
3834 return range_covers_byte(OMAP_LOCALBUS_BASE
, 0x1000000, addr
);
3837 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
3840 return range_covers_byte(0xe1010000, 0xe1020004 - 0xe1010000, addr
);
3843 struct omap_mpu_state_s
*omap310_mpu_init(MemoryRegion
*system_memory
,
3844 unsigned long sdram_size
,
3848 struct omap_mpu_state_s
*s
= g_new0(struct omap_mpu_state_s
, 1);
3849 qemu_irq dma_irqs
[6];
3851 SysBusDevice
*busdev
;
3857 s
->mpu_model
= omap310
;
3858 s
->cpu
= cpu_arm_init(core
);
3859 if (s
->cpu
== NULL
) {
3860 fprintf(stderr
, "Unable to find CPU definition\n");
3863 s
->sdram_size
= sdram_size
;
3864 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
3866 s
->wakeup
= qemu_allocate_irq(omap_mpu_wakeup
, s
, 0);
3871 /* Memory-mapped stuff */
3872 memory_region_allocate_system_memory(&s
->emiff_ram
, NULL
, "omap1.dram",
3874 memory_region_add_subregion(system_memory
, OMAP_EMIFF_BASE
, &s
->emiff_ram
);
3875 memory_region_init_ram(&s
->imif_ram
, NULL
, "omap1.sram", s
->sram_size
,
3877 vmstate_register_ram_global(&s
->imif_ram
);
3878 memory_region_add_subregion(system_memory
, OMAP_IMIF_BASE
, &s
->imif_ram
);
3880 omap_clkm_init(system_memory
, 0xfffece00, 0xe1008000, s
);
3882 s
->ih
[0] = qdev_create(NULL
, "omap-intc");
3883 qdev_prop_set_uint32(s
->ih
[0], "size", 0x100);
3884 qdev_prop_set_ptr(s
->ih
[0], "clk", omap_findclk(s
, "arminth_ck"));
3885 qdev_init_nofail(s
->ih
[0]);
3886 busdev
= SYS_BUS_DEVICE(s
->ih
[0]);
3887 sysbus_connect_irq(busdev
, 0,
3888 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_IRQ
));
3889 sysbus_connect_irq(busdev
, 1,
3890 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_FIQ
));
3891 sysbus_mmio_map(busdev
, 0, 0xfffecb00);
3892 s
->ih
[1] = qdev_create(NULL
, "omap-intc");
3893 qdev_prop_set_uint32(s
->ih
[1], "size", 0x800);
3894 qdev_prop_set_ptr(s
->ih
[1], "clk", omap_findclk(s
, "arminth_ck"));
3895 qdev_init_nofail(s
->ih
[1]);
3896 busdev
= SYS_BUS_DEVICE(s
->ih
[1]);
3897 sysbus_connect_irq(busdev
, 0,
3898 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_15XX_IH2_IRQ
));
3899 /* The second interrupt controller's FIQ output is not wired up */
3900 sysbus_mmio_map(busdev
, 0, 0xfffe0000);
3902 for (i
= 0; i
< 6; i
++) {
3903 dma_irqs
[i
] = qdev_get_gpio_in(s
->ih
[omap1_dma_irq_map
[i
].ih
],
3904 omap1_dma_irq_map
[i
].intr
);
3906 s
->dma
= omap_dma_init(0xfffed800, dma_irqs
, system_memory
,
3907 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_DMA_LCD
),
3908 s
, omap_findclk(s
, "dma_ck"), omap_dma_3_1
);
3910 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
3911 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
3912 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
3913 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
3914 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
3915 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
3917 /* Register SDRAM and SRAM DMA ports for fast transfers. */
3918 soc_dma_port_add_mem(s
->dma
, memory_region_get_ram_ptr(&s
->emiff_ram
),
3919 OMAP_EMIFF_BASE
, s
->sdram_size
);
3920 soc_dma_port_add_mem(s
->dma
, memory_region_get_ram_ptr(&s
->imif_ram
),
3921 OMAP_IMIF_BASE
, s
->sram_size
);
3923 s
->timer
[0] = omap_mpu_timer_init(system_memory
, 0xfffec500,
3924 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER1
),
3925 omap_findclk(s
, "mputim_ck"));
3926 s
->timer
[1] = omap_mpu_timer_init(system_memory
, 0xfffec600,
3927 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER2
),
3928 omap_findclk(s
, "mputim_ck"));
3929 s
->timer
[2] = omap_mpu_timer_init(system_memory
, 0xfffec700,
3930 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER3
),
3931 omap_findclk(s
, "mputim_ck"));
3933 s
->wdt
= omap_wd_timer_init(system_memory
, 0xfffec800,
3934 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_WD_TIMER
),
3935 omap_findclk(s
, "armwdt_ck"));
3937 s
->os_timer
= omap_os_timer_init(system_memory
, 0xfffb9000,
3938 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_OS_TIMER
),
3939 omap_findclk(s
, "clk32-kHz"));
3941 s
->lcd
= omap_lcdc_init(system_memory
, 0xfffec000,
3942 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_LCD_CTRL
),
3943 omap_dma_get_lcdch(s
->dma
),
3944 omap_findclk(s
, "lcd_ck"));
3946 omap_ulpd_pm_init(system_memory
, 0xfffe0800, s
);
3947 omap_pin_cfg_init(system_memory
, 0xfffe1000, s
);
3948 omap_id_init(system_memory
, s
);
3950 omap_mpui_init(system_memory
, 0xfffec900, s
);
3952 s
->private_tipb
= omap_tipb_bridge_init(system_memory
, 0xfffeca00,
3953 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_BRIDGE_PRIV
),
3954 omap_findclk(s
, "tipb_ck"));
3955 s
->public_tipb
= omap_tipb_bridge_init(system_memory
, 0xfffed300,
3956 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_BRIDGE_PUB
),
3957 omap_findclk(s
, "tipb_ck"));
3959 omap_tcmi_init(system_memory
, 0xfffecc00, s
);
3961 s
->uart
[0] = omap_uart_init(0xfffb0000,
3962 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_UART1
),
3963 omap_findclk(s
, "uart1_ck"),
3964 omap_findclk(s
, "uart1_ck"),
3965 s
->drq
[OMAP_DMA_UART1_TX
], s
->drq
[OMAP_DMA_UART1_RX
],
3968 s
->uart
[1] = omap_uart_init(0xfffb0800,
3969 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_UART2
),
3970 omap_findclk(s
, "uart2_ck"),
3971 omap_findclk(s
, "uart2_ck"),
3972 s
->drq
[OMAP_DMA_UART2_TX
], s
->drq
[OMAP_DMA_UART2_RX
],
3974 serial_hds
[0] ? serial_hds
[1] : NULL
);
3975 s
->uart
[2] = omap_uart_init(0xfffb9800,
3976 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_UART3
),
3977 omap_findclk(s
, "uart3_ck"),
3978 omap_findclk(s
, "uart3_ck"),
3979 s
->drq
[OMAP_DMA_UART3_TX
], s
->drq
[OMAP_DMA_UART3_RX
],
3981 serial_hds
[0] && serial_hds
[1] ? serial_hds
[2] : NULL
);
3983 s
->dpll
[0] = omap_dpll_init(system_memory
, 0xfffecf00,
3984 omap_findclk(s
, "dpll1"));
3985 s
->dpll
[1] = omap_dpll_init(system_memory
, 0xfffed000,
3986 omap_findclk(s
, "dpll2"));
3987 s
->dpll
[2] = omap_dpll_init(system_memory
, 0xfffed100,
3988 omap_findclk(s
, "dpll3"));
3990 dinfo
= drive_get(IF_SD
, 0, 0);
3992 fprintf(stderr
, "qemu: missing SecureDigital device\n");
3995 s
->mmc
= omap_mmc_init(0xfffb7800, system_memory
,
3996 blk_by_legacy_dinfo(dinfo
),
3997 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_OQN
),
3998 &s
->drq
[OMAP_DMA_MMC_TX
],
3999 omap_findclk(s
, "mmc_ck"));
4001 s
->mpuio
= omap_mpuio_init(system_memory
, 0xfffb5000,
4002 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_KEYBOARD
),
4003 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_MPUIO
),
4004 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
4006 s
->gpio
= qdev_create(NULL
, "omap-gpio");
4007 qdev_prop_set_int32(s
->gpio
, "mpu_model", s
->mpu_model
);
4008 qdev_prop_set_ptr(s
->gpio
, "clk", omap_findclk(s
, "arm_gpio_ck"));
4009 qdev_init_nofail(s
->gpio
);
4010 sysbus_connect_irq(SYS_BUS_DEVICE(s
->gpio
), 0,
4011 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_GPIO_BANK1
));
4012 sysbus_mmio_map(SYS_BUS_DEVICE(s
->gpio
), 0, 0xfffce000);
4014 s
->microwire
= omap_uwire_init(system_memory
, 0xfffb3000,
4015 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_uWireTX
),
4016 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_uWireRX
),
4017 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
4019 s
->pwl
= omap_pwl_init(system_memory
, 0xfffb5800,
4020 omap_findclk(s
, "armxor_ck"));
4021 s
->pwt
= omap_pwt_init(system_memory
, 0xfffb6000,
4022 omap_findclk(s
, "armxor_ck"));
4024 s
->i2c
[0] = qdev_create(NULL
, "omap_i2c");
4025 qdev_prop_set_uint8(s
->i2c
[0], "revision", 0x11);
4026 qdev_prop_set_ptr(s
->i2c
[0], "fclk", omap_findclk(s
, "mpuper_ck"));
4027 qdev_init_nofail(s
->i2c
[0]);
4028 busdev
= SYS_BUS_DEVICE(s
->i2c
[0]);
4029 sysbus_connect_irq(busdev
, 0, qdev_get_gpio_in(s
->ih
[1], OMAP_INT_I2C
));
4030 sysbus_connect_irq(busdev
, 1, s
->drq
[OMAP_DMA_I2C_TX
]);
4031 sysbus_connect_irq(busdev
, 2, s
->drq
[OMAP_DMA_I2C_RX
]);
4032 sysbus_mmio_map(busdev
, 0, 0xfffb3800);
4034 s
->rtc
= omap_rtc_init(system_memory
, 0xfffb4800,
4035 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_RTC_TIMER
),
4036 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_RTC_ALARM
),
4037 omap_findclk(s
, "clk32-kHz"));
4039 s
->mcbsp1
= omap_mcbsp_init(system_memory
, 0xfffb1800,
4040 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP1TX
),
4041 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP1RX
),
4042 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
4043 s
->mcbsp2
= omap_mcbsp_init(system_memory
, 0xfffb1000,
4044 qdev_get_gpio_in(s
->ih
[0],
4045 OMAP_INT_310_McBSP2_TX
),
4046 qdev_get_gpio_in(s
->ih
[0],
4047 OMAP_INT_310_McBSP2_RX
),
4048 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
4049 s
->mcbsp3
= omap_mcbsp_init(system_memory
, 0xfffb7000,
4050 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP3TX
),
4051 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP3RX
),
4052 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
4054 s
->led
[0] = omap_lpg_init(system_memory
,
4055 0xfffbd000, omap_findclk(s
, "clk32-kHz"));
4056 s
->led
[1] = omap_lpg_init(system_memory
,
4057 0xfffbd800, omap_findclk(s
, "clk32-kHz"));
4059 /* Register mappings not currenlty implemented:
4060 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4061 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4062 * USB W2FC fffb4000 - fffb47ff
4063 * Camera Interface fffb6800 - fffb6fff
4064 * USB Host fffba000 - fffba7ff
4065 * FAC fffba800 - fffbafff
4066 * HDQ/1-Wire fffbc000 - fffbc7ff
4067 * TIPB switches fffbc800 - fffbcfff
4068 * Mailbox fffcf000 - fffcf7ff
4069 * Local bus IF fffec100 - fffec1ff
4070 * Local bus MMU fffec200 - fffec2ff
4071 * DSP MMU fffed200 - fffed2ff
4074 omap_setup_dsp_mapping(system_memory
, omap15xx_dsp_mm
);
4075 omap_setup_mpui_io(system_memory
, s
);
4077 qemu_register_reset(omap1_mpu_reset
, s
);