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 "hw/boards.h"
22 #include "hw/arm/arm.h"
23 #include "hw/arm/omap.h"
24 #include "sysemu/sysemu.h"
25 #include "hw/arm/soc_dma.h"
26 #include "sysemu/block-backend.h"
27 #include "sysemu/blockdev.h"
28 #include "qemu/range.h"
29 #include "hw/sysbus.h"
31 /* Should signal the TCMI/GPMC */
32 uint32_t omap_badwidth_read8(void *opaque
, hwaddr addr
)
37 cpu_physical_memory_read(addr
, &ret
, 1);
41 void omap_badwidth_write8(void *opaque
, hwaddr addr
,
47 cpu_physical_memory_write(addr
, &val8
, 1);
50 uint32_t omap_badwidth_read16(void *opaque
, hwaddr addr
)
55 cpu_physical_memory_read(addr
, &ret
, 2);
59 void omap_badwidth_write16(void *opaque
, hwaddr addr
,
62 uint16_t val16
= value
;
65 cpu_physical_memory_write(addr
, &val16
, 2);
68 uint32_t omap_badwidth_read32(void *opaque
, hwaddr addr
)
73 cpu_physical_memory_read(addr
, &ret
, 4);
77 void omap_badwidth_write32(void *opaque
, hwaddr addr
,
81 cpu_physical_memory_write(addr
, &value
, 4);
85 struct omap_mpu_timer_s
{
103 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
105 uint64_t distance
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) - timer
->time
;
107 if (timer
->st
&& timer
->enable
&& timer
->rate
)
108 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
109 timer
->rate
, get_ticks_per_sec());
114 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
116 timer
->val
= omap_timer_read(timer
);
117 timer
->time
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
120 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
124 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
125 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
126 expires
= muldiv64((uint64_t) timer
->val
<< (timer
->ptv
+ 1),
127 get_ticks_per_sec(), timer
->rate
);
129 /* If timer expiry would be sooner than in about 1 ms and
130 * auto-reload isn't set, then fire immediately. This is a hack
131 * to make systems like PalmOS run in acceptable time. PalmOS
132 * sets the interval to a very low value and polls the status bit
133 * in a busy loop when it wants to sleep just a couple of CPU
135 if (expires
> (get_ticks_per_sec() >> 10) || timer
->ar
)
136 timer_mod(timer
->timer
, timer
->time
+ expires
);
138 qemu_bh_schedule(timer
->tick
);
140 timer_del(timer
->timer
);
143 static void omap_timer_fire(void *opaque
)
145 struct omap_mpu_timer_s
*timer
= opaque
;
153 /* Edge-triggered irq */
154 qemu_irq_pulse(timer
->irq
);
157 static void omap_timer_tick(void *opaque
)
159 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
161 omap_timer_sync(timer
);
162 omap_timer_fire(timer
);
163 omap_timer_update(timer
);
166 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
168 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
170 omap_timer_sync(timer
);
171 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
172 omap_timer_update(timer
);
175 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
177 omap_clk_adduser(timer
->clk
,
178 qemu_allocate_irq(omap_timer_clk_update
, timer
, 0));
179 timer
->rate
= omap_clk_getrate(timer
->clk
);
182 static uint64_t omap_mpu_timer_read(void *opaque
, hwaddr addr
,
185 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
188 return omap_badwidth_read32(opaque
, addr
);
192 case 0x00: /* CNTL_TIMER */
193 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
195 case 0x04: /* LOAD_TIM */
198 case 0x08: /* READ_TIM */
199 return omap_timer_read(s
);
206 static void omap_mpu_timer_write(void *opaque
, hwaddr addr
,
207 uint64_t value
, unsigned size
)
209 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
212 omap_badwidth_write32(opaque
, addr
, value
);
217 case 0x00: /* CNTL_TIMER */
219 s
->enable
= (value
>> 5) & 1;
220 s
->ptv
= (value
>> 2) & 7;
221 s
->ar
= (value
>> 1) & 1;
223 omap_timer_update(s
);
226 case 0x04: /* LOAD_TIM */
227 s
->reset_val
= value
;
230 case 0x08: /* READ_TIM */
239 static const MemoryRegionOps omap_mpu_timer_ops
= {
240 .read
= omap_mpu_timer_read
,
241 .write
= omap_mpu_timer_write
,
242 .endianness
= DEVICE_LITTLE_ENDIAN
,
245 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
249 s
->reset_val
= 31337;
257 static struct omap_mpu_timer_s
*omap_mpu_timer_init(MemoryRegion
*system_memory
,
259 qemu_irq irq
, omap_clk clk
)
261 struct omap_mpu_timer_s
*s
= g_new0(struct omap_mpu_timer_s
, 1);
265 s
->timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, s
);
266 s
->tick
= qemu_bh_new(omap_timer_fire
, s
);
267 omap_mpu_timer_reset(s
);
268 omap_timer_clk_setup(s
);
270 memory_region_init_io(&s
->iomem
, NULL
, &omap_mpu_timer_ops
, s
,
271 "omap-mpu-timer", 0x100);
273 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
279 struct omap_watchdog_timer_s
{
280 struct omap_mpu_timer_s timer
;
288 static uint64_t omap_wd_timer_read(void *opaque
, hwaddr addr
,
291 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
294 return omap_badwidth_read16(opaque
, addr
);
298 case 0x00: /* CNTL_TIMER */
299 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
300 (s
->timer
.st
<< 7) | (s
->free
<< 1);
302 case 0x04: /* READ_TIMER */
303 return omap_timer_read(&s
->timer
);
305 case 0x08: /* TIMER_MODE */
306 return s
->mode
<< 15;
313 static void omap_wd_timer_write(void *opaque
, hwaddr addr
,
314 uint64_t value
, unsigned size
)
316 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
319 omap_badwidth_write16(opaque
, addr
, value
);
324 case 0x00: /* CNTL_TIMER */
325 omap_timer_sync(&s
->timer
);
326 s
->timer
.ptv
= (value
>> 9) & 7;
327 s
->timer
.ar
= (value
>> 8) & 1;
328 s
->timer
.st
= (value
>> 7) & 1;
329 s
->free
= (value
>> 1) & 1;
330 omap_timer_update(&s
->timer
);
333 case 0x04: /* LOAD_TIMER */
334 s
->timer
.reset_val
= value
& 0xffff;
337 case 0x08: /* TIMER_MODE */
338 if (!s
->mode
&& ((value
>> 15) & 1))
339 omap_clk_get(s
->timer
.clk
);
340 s
->mode
|= (value
>> 15) & 1;
341 if (s
->last_wr
== 0xf5) {
342 if ((value
& 0xff) == 0xa0) {
345 omap_clk_put(s
->timer
.clk
);
348 /* XXX: on T|E hardware somehow this has no effect,
349 * on Zire 71 it works as specified. */
351 qemu_system_reset_request();
354 s
->last_wr
= value
& 0xff;
362 static const MemoryRegionOps omap_wd_timer_ops
= {
363 .read
= omap_wd_timer_read
,
364 .write
= omap_wd_timer_write
,
365 .endianness
= DEVICE_NATIVE_ENDIAN
,
368 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
370 timer_del(s
->timer
.timer
);
372 omap_clk_get(s
->timer
.clk
);
378 s
->timer
.reset_val
= 0xffff;
383 omap_timer_update(&s
->timer
);
386 static struct omap_watchdog_timer_s
*omap_wd_timer_init(MemoryRegion
*memory
,
388 qemu_irq irq
, omap_clk clk
)
390 struct omap_watchdog_timer_s
*s
= g_new0(struct omap_watchdog_timer_s
, 1);
394 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, &s
->timer
);
395 omap_wd_timer_reset(s
);
396 omap_timer_clk_setup(&s
->timer
);
398 memory_region_init_io(&s
->iomem
, NULL
, &omap_wd_timer_ops
, s
,
399 "omap-wd-timer", 0x100);
400 memory_region_add_subregion(memory
, base
, &s
->iomem
);
406 struct omap_32khz_timer_s
{
407 struct omap_mpu_timer_s timer
;
411 static uint64_t omap_os_timer_read(void *opaque
, hwaddr addr
,
414 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
415 int offset
= addr
& OMAP_MPUI_REG_MASK
;
418 return omap_badwidth_read32(opaque
, addr
);
423 return s
->timer
.reset_val
;
426 return omap_timer_read(&s
->timer
);
429 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
438 static void omap_os_timer_write(void *opaque
, hwaddr addr
,
439 uint64_t value
, unsigned size
)
441 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
442 int offset
= addr
& OMAP_MPUI_REG_MASK
;
445 omap_badwidth_write32(opaque
, addr
, value
);
451 s
->timer
.reset_val
= value
& 0x00ffffff;
459 s
->timer
.ar
= (value
>> 3) & 1;
460 s
->timer
.it_ena
= (value
>> 2) & 1;
461 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
462 omap_timer_sync(&s
->timer
);
463 s
->timer
.enable
= value
& 1;
464 s
->timer
.st
= value
& 1;
465 omap_timer_update(&s
->timer
);
474 static const MemoryRegionOps omap_os_timer_ops
= {
475 .read
= omap_os_timer_read
,
476 .write
= omap_os_timer_write
,
477 .endianness
= DEVICE_NATIVE_ENDIAN
,
480 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
482 timer_del(s
->timer
.timer
);
485 s
->timer
.reset_val
= 0x00ffffff;
492 static struct omap_32khz_timer_s
*omap_os_timer_init(MemoryRegion
*memory
,
494 qemu_irq irq
, omap_clk clk
)
496 struct omap_32khz_timer_s
*s
= g_new0(struct omap_32khz_timer_s
, 1);
500 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, &s
->timer
);
501 omap_os_timer_reset(s
);
502 omap_timer_clk_setup(&s
->timer
);
504 memory_region_init_io(&s
->iomem
, NULL
, &omap_os_timer_ops
, s
,
505 "omap-os-timer", 0x800);
506 memory_region_add_subregion(memory
, base
, &s
->iomem
);
511 /* Ultra Low-Power Device Module */
512 static uint64_t omap_ulpd_pm_read(void *opaque
, hwaddr addr
,
515 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
519 return omap_badwidth_read16(opaque
, addr
);
523 case 0x14: /* IT_STATUS */
524 ret
= s
->ulpd_pm_regs
[addr
>> 2];
525 s
->ulpd_pm_regs
[addr
>> 2] = 0;
526 qemu_irq_lower(qdev_get_gpio_in(s
->ih
[1], OMAP_INT_GAUGE_32K
));
529 case 0x18: /* Reserved */
530 case 0x1c: /* Reserved */
531 case 0x20: /* Reserved */
532 case 0x28: /* Reserved */
533 case 0x2c: /* Reserved */
536 case 0x00: /* COUNTER_32_LSB */
537 case 0x04: /* COUNTER_32_MSB */
538 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
539 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
540 case 0x10: /* GAUGING_CTRL */
541 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
542 case 0x30: /* CLOCK_CTRL */
543 case 0x34: /* SOFT_REQ */
544 case 0x38: /* COUNTER_32_FIQ */
545 case 0x3c: /* DPLL_CTRL */
546 case 0x40: /* STATUS_REQ */
547 /* XXX: check clk::usecount state for every clock */
548 case 0x48: /* LOCL_TIME */
549 case 0x4c: /* APLL_CTRL */
550 case 0x50: /* POWER_CTRL */
551 return s
->ulpd_pm_regs
[addr
>> 2];
558 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
559 uint16_t diff
, uint16_t value
)
561 if (diff
& (1 << 4)) /* USB_MCLK_EN */
562 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
563 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
564 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
567 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
568 uint16_t diff
, uint16_t value
)
570 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
571 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
572 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
573 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
574 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
575 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
576 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
577 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
580 static void omap_ulpd_pm_write(void *opaque
, hwaddr addr
,
581 uint64_t value
, unsigned size
)
583 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
586 static const int bypass_div
[4] = { 1, 2, 4, 4 };
590 omap_badwidth_write16(opaque
, addr
, value
);
595 case 0x00: /* COUNTER_32_LSB */
596 case 0x04: /* COUNTER_32_MSB */
597 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
598 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
599 case 0x14: /* IT_STATUS */
600 case 0x40: /* STATUS_REQ */
604 case 0x10: /* GAUGING_CTRL */
605 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
606 if ((s
->ulpd_pm_regs
[addr
>> 2] ^ value
) & 1) {
607 now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
610 s
->ulpd_gauge_start
= now
;
612 now
-= s
->ulpd_gauge_start
;
615 ticks
= muldiv64(now
, 32768, get_ticks_per_sec());
616 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
617 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
618 if (ticks
>> 32) /* OVERFLOW_32K */
619 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
621 /* High frequency ticks */
622 ticks
= muldiv64(now
, 12000000, get_ticks_per_sec());
623 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
624 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
625 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
626 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
628 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
629 qemu_irq_raise(qdev_get_gpio_in(s
->ih
[1], OMAP_INT_GAUGE_32K
));
632 s
->ulpd_pm_regs
[addr
>> 2] = value
;
635 case 0x18: /* Reserved */
636 case 0x1c: /* Reserved */
637 case 0x20: /* Reserved */
638 case 0x28: /* Reserved */
639 case 0x2c: /* Reserved */
642 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
643 case 0x38: /* COUNTER_32_FIQ */
644 case 0x48: /* LOCL_TIME */
645 case 0x50: /* POWER_CTRL */
646 s
->ulpd_pm_regs
[addr
>> 2] = value
;
649 case 0x30: /* CLOCK_CTRL */
650 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
651 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x3f;
652 omap_ulpd_clk_update(s
, diff
, value
);
655 case 0x34: /* SOFT_REQ */
656 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
657 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x1f;
658 omap_ulpd_req_update(s
, diff
, value
);
661 case 0x3c: /* DPLL_CTRL */
662 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
663 * omitted altogether, probably a typo. */
664 /* This register has identical semantics with DPLL(1:3) control
665 * registers, see omap_dpll_write() */
666 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
667 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x2fff;
668 if (diff
& (0x3ff << 2)) {
669 if (value
& (1 << 4)) { /* PLL_ENABLE */
670 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
671 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
673 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
676 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
679 /* Enter the desired mode. */
680 s
->ulpd_pm_regs
[addr
>> 2] =
681 (s
->ulpd_pm_regs
[addr
>> 2] & 0xfffe) |
682 ((s
->ulpd_pm_regs
[addr
>> 2] >> 4) & 1);
684 /* Act as if the lock is restored. */
685 s
->ulpd_pm_regs
[addr
>> 2] |= 2;
688 case 0x4c: /* APLL_CTRL */
689 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
690 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0xf;
691 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
692 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
693 (value
& (1 << 0)) ? "apll" : "dpll4"));
701 static const MemoryRegionOps omap_ulpd_pm_ops
= {
702 .read
= omap_ulpd_pm_read
,
703 .write
= omap_ulpd_pm_write
,
704 .endianness
= DEVICE_NATIVE_ENDIAN
,
707 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
709 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
710 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
711 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
712 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
713 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
714 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
715 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
716 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
717 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
718 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
719 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
720 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
721 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
722 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
723 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
724 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
725 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
726 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
727 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
728 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
729 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
730 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
731 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
734 static void omap_ulpd_pm_init(MemoryRegion
*system_memory
,
736 struct omap_mpu_state_s
*mpu
)
738 memory_region_init_io(&mpu
->ulpd_pm_iomem
, NULL
, &omap_ulpd_pm_ops
, mpu
,
739 "omap-ulpd-pm", 0x800);
740 memory_region_add_subregion(system_memory
, base
, &mpu
->ulpd_pm_iomem
);
741 omap_ulpd_pm_reset(mpu
);
744 /* OMAP Pin Configuration */
745 static uint64_t omap_pin_cfg_read(void *opaque
, hwaddr addr
,
748 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
751 return omap_badwidth_read32(opaque
, addr
);
755 case 0x00: /* FUNC_MUX_CTRL_0 */
756 case 0x04: /* FUNC_MUX_CTRL_1 */
757 case 0x08: /* FUNC_MUX_CTRL_2 */
758 return s
->func_mux_ctrl
[addr
>> 2];
760 case 0x0c: /* COMP_MODE_CTRL_0 */
761 return s
->comp_mode_ctrl
[0];
763 case 0x10: /* FUNC_MUX_CTRL_3 */
764 case 0x14: /* FUNC_MUX_CTRL_4 */
765 case 0x18: /* FUNC_MUX_CTRL_5 */
766 case 0x1c: /* FUNC_MUX_CTRL_6 */
767 case 0x20: /* FUNC_MUX_CTRL_7 */
768 case 0x24: /* FUNC_MUX_CTRL_8 */
769 case 0x28: /* FUNC_MUX_CTRL_9 */
770 case 0x2c: /* FUNC_MUX_CTRL_A */
771 case 0x30: /* FUNC_MUX_CTRL_B */
772 case 0x34: /* FUNC_MUX_CTRL_C */
773 case 0x38: /* FUNC_MUX_CTRL_D */
774 return s
->func_mux_ctrl
[(addr
>> 2) - 1];
776 case 0x40: /* PULL_DWN_CTRL_0 */
777 case 0x44: /* PULL_DWN_CTRL_1 */
778 case 0x48: /* PULL_DWN_CTRL_2 */
779 case 0x4c: /* PULL_DWN_CTRL_3 */
780 return s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2];
782 case 0x50: /* GATE_INH_CTRL_0 */
783 return s
->gate_inh_ctrl
[0];
785 case 0x60: /* VOLTAGE_CTRL_0 */
786 return s
->voltage_ctrl
[0];
788 case 0x70: /* TEST_DBG_CTRL_0 */
789 return s
->test_dbg_ctrl
[0];
791 case 0x80: /* MOD_CONF_CTRL_0 */
792 return s
->mod_conf_ctrl
[0];
799 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
800 uint32_t diff
, uint32_t value
)
803 if (diff
& (1 << 9)) /* BLUETOOTH */
804 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
806 if (diff
& (1 << 7)) /* USB.CLKO */
807 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
812 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
813 uint32_t diff
, uint32_t value
)
816 if (diff
& (1U << 31)) {
817 /* MCBSP3_CLK_HIZ_DI */
818 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"), (value
>> 31) & 1);
820 if (diff
& (1 << 1)) {
822 omap_clk_onoff(omap_findclk(s
, "clk32k_out"), (~value
>> 1) & 1);
827 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
828 uint32_t diff
, uint32_t value
)
830 if (diff
& (1U << 31)) {
831 /* CONF_MOD_UART3_CLK_MODE_R */
832 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
833 omap_findclk(s
, ((value
>> 31) & 1) ?
834 "ck_48m" : "armper_ck"));
836 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
837 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
838 omap_findclk(s
, ((value
>> 30) & 1) ?
839 "ck_48m" : "armper_ck"));
840 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
841 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
842 omap_findclk(s
, ((value
>> 29) & 1) ?
843 "ck_48m" : "armper_ck"));
844 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
845 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
846 omap_findclk(s
, ((value
>> 23) & 1) ?
847 "ck_48m" : "armper_ck"));
848 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
849 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
850 omap_findclk(s
, ((value
>> 12) & 1) ?
851 "ck_48m" : "armper_ck"));
852 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
853 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
856 static void omap_pin_cfg_write(void *opaque
, hwaddr addr
,
857 uint64_t value
, unsigned size
)
859 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
863 omap_badwidth_write32(opaque
, addr
, value
);
868 case 0x00: /* FUNC_MUX_CTRL_0 */
869 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
870 s
->func_mux_ctrl
[addr
>> 2] = value
;
871 omap_pin_funcmux0_update(s
, diff
, value
);
874 case 0x04: /* FUNC_MUX_CTRL_1 */
875 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
876 s
->func_mux_ctrl
[addr
>> 2] = value
;
877 omap_pin_funcmux1_update(s
, diff
, value
);
880 case 0x08: /* FUNC_MUX_CTRL_2 */
881 s
->func_mux_ctrl
[addr
>> 2] = value
;
884 case 0x0c: /* COMP_MODE_CTRL_0 */
885 s
->comp_mode_ctrl
[0] = value
;
886 s
->compat1509
= (value
!= 0x0000eaef);
887 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
888 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
891 case 0x10: /* FUNC_MUX_CTRL_3 */
892 case 0x14: /* FUNC_MUX_CTRL_4 */
893 case 0x18: /* FUNC_MUX_CTRL_5 */
894 case 0x1c: /* FUNC_MUX_CTRL_6 */
895 case 0x20: /* FUNC_MUX_CTRL_7 */
896 case 0x24: /* FUNC_MUX_CTRL_8 */
897 case 0x28: /* FUNC_MUX_CTRL_9 */
898 case 0x2c: /* FUNC_MUX_CTRL_A */
899 case 0x30: /* FUNC_MUX_CTRL_B */
900 case 0x34: /* FUNC_MUX_CTRL_C */
901 case 0x38: /* FUNC_MUX_CTRL_D */
902 s
->func_mux_ctrl
[(addr
>> 2) - 1] = value
;
905 case 0x40: /* PULL_DWN_CTRL_0 */
906 case 0x44: /* PULL_DWN_CTRL_1 */
907 case 0x48: /* PULL_DWN_CTRL_2 */
908 case 0x4c: /* PULL_DWN_CTRL_3 */
909 s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2] = value
;
912 case 0x50: /* GATE_INH_CTRL_0 */
913 s
->gate_inh_ctrl
[0] = value
;
916 case 0x60: /* VOLTAGE_CTRL_0 */
917 s
->voltage_ctrl
[0] = value
;
920 case 0x70: /* TEST_DBG_CTRL_0 */
921 s
->test_dbg_ctrl
[0] = value
;
924 case 0x80: /* MOD_CONF_CTRL_0 */
925 diff
= s
->mod_conf_ctrl
[0] ^ value
;
926 s
->mod_conf_ctrl
[0] = value
;
927 omap_pin_modconf1_update(s
, diff
, value
);
935 static const MemoryRegionOps omap_pin_cfg_ops
= {
936 .read
= omap_pin_cfg_read
,
937 .write
= omap_pin_cfg_write
,
938 .endianness
= DEVICE_NATIVE_ENDIAN
,
941 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
943 /* Start in Compatibility Mode. */
945 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
946 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
947 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
948 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
949 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
950 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
951 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
952 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
953 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
954 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
957 static void omap_pin_cfg_init(MemoryRegion
*system_memory
,
959 struct omap_mpu_state_s
*mpu
)
961 memory_region_init_io(&mpu
->pin_cfg_iomem
, NULL
, &omap_pin_cfg_ops
, mpu
,
962 "omap-pin-cfg", 0x800);
963 memory_region_add_subregion(system_memory
, base
, &mpu
->pin_cfg_iomem
);
964 omap_pin_cfg_reset(mpu
);
967 /* Device Identification, Die Identification */
968 static uint64_t omap_id_read(void *opaque
, hwaddr addr
,
971 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
974 return omap_badwidth_read32(opaque
, addr
);
978 case 0xfffe1800: /* DIE_ID_LSB */
980 case 0xfffe1804: /* DIE_ID_MSB */
983 case 0xfffe2000: /* PRODUCT_ID_LSB */
985 case 0xfffe2004: /* PRODUCT_ID_MSB */
988 case 0xfffed400: /* JTAG_ID_LSB */
989 switch (s
->mpu_model
) {
995 hw_error("%s: bad mpu model\n", __FUNCTION__
);
999 case 0xfffed404: /* JTAG_ID_MSB */
1000 switch (s
->mpu_model
) {
1006 hw_error("%s: bad mpu model\n", __FUNCTION__
);
1015 static void omap_id_write(void *opaque
, hwaddr addr
,
1016 uint64_t value
, unsigned size
)
1019 omap_badwidth_write32(opaque
, addr
, value
);
1026 static const MemoryRegionOps omap_id_ops
= {
1027 .read
= omap_id_read
,
1028 .write
= omap_id_write
,
1029 .endianness
= DEVICE_NATIVE_ENDIAN
,
1032 static void omap_id_init(MemoryRegion
*memory
, struct omap_mpu_state_s
*mpu
)
1034 memory_region_init_io(&mpu
->id_iomem
, NULL
, &omap_id_ops
, mpu
,
1035 "omap-id", 0x100000000ULL
);
1036 memory_region_init_alias(&mpu
->id_iomem_e18
, NULL
, "omap-id-e18", &mpu
->id_iomem
,
1038 memory_region_add_subregion(memory
, 0xfffe1800, &mpu
->id_iomem_e18
);
1039 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-ed4", &mpu
->id_iomem
,
1041 memory_region_add_subregion(memory
, 0xfffed400, &mpu
->id_iomem_ed4
);
1042 if (!cpu_is_omap15xx(mpu
)) {
1043 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-e20",
1044 &mpu
->id_iomem
, 0xfffe2000, 0x800);
1045 memory_region_add_subregion(memory
, 0xfffe2000, &mpu
->id_iomem_e20
);
1049 /* MPUI Control (Dummy) */
1050 static uint64_t omap_mpui_read(void *opaque
, hwaddr addr
,
1053 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1056 return omap_badwidth_read32(opaque
, addr
);
1060 case 0x00: /* CTRL */
1061 return s
->mpui_ctrl
;
1062 case 0x04: /* DEBUG_ADDR */
1064 case 0x08: /* DEBUG_DATA */
1066 case 0x0c: /* DEBUG_FLAG */
1068 case 0x10: /* STATUS */
1071 /* Not in OMAP310 */
1072 case 0x14: /* DSP_STATUS */
1073 case 0x18: /* DSP_BOOT_CONFIG */
1075 case 0x1c: /* DSP_MPUI_CONFIG */
1083 static void omap_mpui_write(void *opaque
, hwaddr addr
,
1084 uint64_t value
, unsigned size
)
1086 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1089 omap_badwidth_write32(opaque
, addr
, value
);
1094 case 0x00: /* CTRL */
1095 s
->mpui_ctrl
= value
& 0x007fffff;
1098 case 0x04: /* DEBUG_ADDR */
1099 case 0x08: /* DEBUG_DATA */
1100 case 0x0c: /* DEBUG_FLAG */
1101 case 0x10: /* STATUS */
1102 /* Not in OMAP310 */
1103 case 0x14: /* DSP_STATUS */
1106 case 0x18: /* DSP_BOOT_CONFIG */
1107 case 0x1c: /* DSP_MPUI_CONFIG */
1115 static const MemoryRegionOps omap_mpui_ops
= {
1116 .read
= omap_mpui_read
,
1117 .write
= omap_mpui_write
,
1118 .endianness
= DEVICE_NATIVE_ENDIAN
,
1121 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1123 s
->mpui_ctrl
= 0x0003ff1b;
1126 static void omap_mpui_init(MemoryRegion
*memory
, hwaddr base
,
1127 struct omap_mpu_state_s
*mpu
)
1129 memory_region_init_io(&mpu
->mpui_iomem
, NULL
, &omap_mpui_ops
, mpu
,
1130 "omap-mpui", 0x100);
1131 memory_region_add_subregion(memory
, base
, &mpu
->mpui_iomem
);
1133 omap_mpui_reset(mpu
);
1137 struct omap_tipb_bridge_s
{
1145 uint16_t enh_control
;
1148 static uint64_t omap_tipb_bridge_read(void *opaque
, hwaddr addr
,
1151 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1154 return omap_badwidth_read16(opaque
, addr
);
1158 case 0x00: /* TIPB_CNTL */
1160 case 0x04: /* TIPB_BUS_ALLOC */
1162 case 0x08: /* MPU_TIPB_CNTL */
1164 case 0x0c: /* ENHANCED_TIPB_CNTL */
1165 return s
->enh_control
;
1166 case 0x10: /* ADDRESS_DBG */
1167 case 0x14: /* DATA_DEBUG_LOW */
1168 case 0x18: /* DATA_DEBUG_HIGH */
1170 case 0x1c: /* DEBUG_CNTR_SIG */
1178 static void omap_tipb_bridge_write(void *opaque
, hwaddr addr
,
1179 uint64_t value
, unsigned size
)
1181 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1184 omap_badwidth_write16(opaque
, addr
, value
);
1189 case 0x00: /* TIPB_CNTL */
1190 s
->control
= value
& 0xffff;
1193 case 0x04: /* TIPB_BUS_ALLOC */
1194 s
->alloc
= value
& 0x003f;
1197 case 0x08: /* MPU_TIPB_CNTL */
1198 s
->buffer
= value
& 0x0003;
1201 case 0x0c: /* ENHANCED_TIPB_CNTL */
1202 s
->width_intr
= !(value
& 2);
1203 s
->enh_control
= value
& 0x000f;
1206 case 0x10: /* ADDRESS_DBG */
1207 case 0x14: /* DATA_DEBUG_LOW */
1208 case 0x18: /* DATA_DEBUG_HIGH */
1209 case 0x1c: /* DEBUG_CNTR_SIG */
1218 static const MemoryRegionOps omap_tipb_bridge_ops
= {
1219 .read
= omap_tipb_bridge_read
,
1220 .write
= omap_tipb_bridge_write
,
1221 .endianness
= DEVICE_NATIVE_ENDIAN
,
1224 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1226 s
->control
= 0xffff;
1229 s
->enh_control
= 0x000f;
1232 static struct omap_tipb_bridge_s
*omap_tipb_bridge_init(
1233 MemoryRegion
*memory
, hwaddr base
,
1234 qemu_irq abort_irq
, omap_clk clk
)
1236 struct omap_tipb_bridge_s
*s
= g_new0(struct omap_tipb_bridge_s
, 1);
1238 s
->abort
= abort_irq
;
1239 omap_tipb_bridge_reset(s
);
1241 memory_region_init_io(&s
->iomem
, NULL
, &omap_tipb_bridge_ops
, s
,
1242 "omap-tipb-bridge", 0x100);
1243 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1248 /* Dummy Traffic Controller's Memory Interface */
1249 static uint64_t omap_tcmi_read(void *opaque
, hwaddr addr
,
1252 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1256 return omap_badwidth_read32(opaque
, addr
);
1260 case 0x00: /* IMIF_PRIO */
1261 case 0x04: /* EMIFS_PRIO */
1262 case 0x08: /* EMIFF_PRIO */
1263 case 0x0c: /* EMIFS_CONFIG */
1264 case 0x10: /* EMIFS_CS0_CONFIG */
1265 case 0x14: /* EMIFS_CS1_CONFIG */
1266 case 0x18: /* EMIFS_CS2_CONFIG */
1267 case 0x1c: /* EMIFS_CS3_CONFIG */
1268 case 0x24: /* EMIFF_MRS */
1269 case 0x28: /* TIMEOUT1 */
1270 case 0x2c: /* TIMEOUT2 */
1271 case 0x30: /* TIMEOUT3 */
1272 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1273 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1274 return s
->tcmi_regs
[addr
>> 2];
1276 case 0x20: /* EMIFF_SDRAM_CONFIG */
1277 ret
= s
->tcmi_regs
[addr
>> 2];
1278 s
->tcmi_regs
[addr
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1279 /* XXX: We can try using the VGA_DIRTY flag for this */
1287 static void omap_tcmi_write(void *opaque
, hwaddr addr
,
1288 uint64_t value
, unsigned size
)
1290 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1293 omap_badwidth_write32(opaque
, addr
, value
);
1298 case 0x00: /* IMIF_PRIO */
1299 case 0x04: /* EMIFS_PRIO */
1300 case 0x08: /* EMIFF_PRIO */
1301 case 0x10: /* EMIFS_CS0_CONFIG */
1302 case 0x14: /* EMIFS_CS1_CONFIG */
1303 case 0x18: /* EMIFS_CS2_CONFIG */
1304 case 0x1c: /* EMIFS_CS3_CONFIG */
1305 case 0x20: /* EMIFF_SDRAM_CONFIG */
1306 case 0x24: /* EMIFF_MRS */
1307 case 0x28: /* TIMEOUT1 */
1308 case 0x2c: /* TIMEOUT2 */
1309 case 0x30: /* TIMEOUT3 */
1310 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1311 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1312 s
->tcmi_regs
[addr
>> 2] = value
;
1314 case 0x0c: /* EMIFS_CONFIG */
1315 s
->tcmi_regs
[addr
>> 2] = (value
& 0xf) | (1 << 4);
1323 static const MemoryRegionOps omap_tcmi_ops
= {
1324 .read
= omap_tcmi_read
,
1325 .write
= omap_tcmi_write
,
1326 .endianness
= DEVICE_NATIVE_ENDIAN
,
1329 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1331 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1332 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1333 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1334 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1335 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1336 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1337 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1338 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1339 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1340 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1341 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1342 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1343 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1344 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1345 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1348 static void omap_tcmi_init(MemoryRegion
*memory
, hwaddr base
,
1349 struct omap_mpu_state_s
*mpu
)
1351 memory_region_init_io(&mpu
->tcmi_iomem
, NULL
, &omap_tcmi_ops
, mpu
,
1352 "omap-tcmi", 0x100);
1353 memory_region_add_subregion(memory
, base
, &mpu
->tcmi_iomem
);
1354 omap_tcmi_reset(mpu
);
1357 /* Digital phase-locked loops control */
1364 static uint64_t omap_dpll_read(void *opaque
, hwaddr addr
,
1367 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1370 return omap_badwidth_read16(opaque
, addr
);
1373 if (addr
== 0x00) /* CTL_REG */
1380 static void omap_dpll_write(void *opaque
, hwaddr addr
,
1381 uint64_t value
, unsigned size
)
1383 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1385 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1389 omap_badwidth_write16(opaque
, addr
, value
);
1393 if (addr
== 0x00) { /* CTL_REG */
1394 /* See omap_ulpd_pm_write() too */
1395 diff
= s
->mode
& value
;
1396 s
->mode
= value
& 0x2fff;
1397 if (diff
& (0x3ff << 2)) {
1398 if (value
& (1 << 4)) { /* PLL_ENABLE */
1399 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1400 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1402 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1405 omap_clk_setrate(s
->dpll
, div
, mult
);
1408 /* Enter the desired mode. */
1409 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1411 /* Act as if the lock is restored. */
1418 static const MemoryRegionOps omap_dpll_ops
= {
1419 .read
= omap_dpll_read
,
1420 .write
= omap_dpll_write
,
1421 .endianness
= DEVICE_NATIVE_ENDIAN
,
1424 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1427 omap_clk_setrate(s
->dpll
, 1, 1);
1430 static struct dpll_ctl_s
*omap_dpll_init(MemoryRegion
*memory
,
1431 hwaddr base
, omap_clk clk
)
1433 struct dpll_ctl_s
*s
= g_malloc0(sizeof(*s
));
1434 memory_region_init_io(&s
->iomem
, NULL
, &omap_dpll_ops
, s
, "omap-dpll", 0x100);
1439 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1443 /* MPU Clock/Reset/Power Mode Control */
1444 static uint64_t omap_clkm_read(void *opaque
, hwaddr addr
,
1447 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1450 return omap_badwidth_read16(opaque
, addr
);
1454 case 0x00: /* ARM_CKCTL */
1455 return s
->clkm
.arm_ckctl
;
1457 case 0x04: /* ARM_IDLECT1 */
1458 return s
->clkm
.arm_idlect1
;
1460 case 0x08: /* ARM_IDLECT2 */
1461 return s
->clkm
.arm_idlect2
;
1463 case 0x0c: /* ARM_EWUPCT */
1464 return s
->clkm
.arm_ewupct
;
1466 case 0x10: /* ARM_RSTCT1 */
1467 return s
->clkm
.arm_rstct1
;
1469 case 0x14: /* ARM_RSTCT2 */
1470 return s
->clkm
.arm_rstct2
;
1472 case 0x18: /* ARM_SYSST */
1473 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
1475 case 0x1c: /* ARM_CKOUT1 */
1476 return s
->clkm
.arm_ckout1
;
1478 case 0x20: /* ARM_CKOUT2 */
1486 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
1487 uint16_t diff
, uint16_t value
)
1491 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
1492 if (value
& (1 << 14))
1495 clk
= omap_findclk(s
, "arminth_ck");
1496 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1499 if (diff
& (1 << 12)) { /* ARM_TIMXO */
1500 clk
= omap_findclk(s
, "armtim_ck");
1501 if (value
& (1 << 12))
1502 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
1504 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1507 if (diff
& (3 << 10)) { /* DSPMMUDIV */
1508 clk
= omap_findclk(s
, "dspmmu_ck");
1509 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
1511 if (diff
& (3 << 8)) { /* TCDIV */
1512 clk
= omap_findclk(s
, "tc_ck");
1513 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
1515 if (diff
& (3 << 6)) { /* DSPDIV */
1516 clk
= omap_findclk(s
, "dsp_ck");
1517 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
1519 if (diff
& (3 << 4)) { /* ARMDIV */
1520 clk
= omap_findclk(s
, "arm_ck");
1521 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
1523 if (diff
& (3 << 2)) { /* LCDDIV */
1524 clk
= omap_findclk(s
, "lcd_ck");
1525 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
1527 if (diff
& (3 << 0)) { /* PERDIV */
1528 clk
= omap_findclk(s
, "armper_ck");
1529 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
1533 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
1534 uint16_t diff
, uint16_t value
)
1538 if (value
& (1 << 11)) { /* SETARM_IDLE */
1539 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
1541 if (!(value
& (1 << 10))) /* WKUP_MODE */
1542 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
1544 #define SET_CANIDLE(clock, bit) \
1545 if (diff & (1 << bit)) { \
1546 clk = omap_findclk(s, clock); \
1547 omap_clk_canidle(clk, (value >> bit) & 1); \
1549 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1550 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1551 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1552 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1553 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1554 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1555 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1556 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1557 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1558 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1559 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1560 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1561 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1562 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1565 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
1566 uint16_t diff
, uint16_t value
)
1570 #define SET_ONOFF(clock, bit) \
1571 if (diff & (1 << bit)) { \
1572 clk = omap_findclk(s, clock); \
1573 omap_clk_onoff(clk, (value >> bit) & 1); \
1575 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1576 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1577 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1578 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1579 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1580 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1581 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1582 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1583 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1584 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1585 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1588 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
1589 uint16_t diff
, uint16_t value
)
1593 if (diff
& (3 << 4)) { /* TCLKOUT */
1594 clk
= omap_findclk(s
, "tclk_out");
1595 switch ((value
>> 4) & 3) {
1597 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
1598 omap_clk_onoff(clk
, 1);
1601 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1602 omap_clk_onoff(clk
, 1);
1605 omap_clk_onoff(clk
, 0);
1608 if (diff
& (3 << 2)) { /* DCLKOUT */
1609 clk
= omap_findclk(s
, "dclk_out");
1610 switch ((value
>> 2) & 3) {
1612 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
1615 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
1618 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
1621 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1625 if (diff
& (3 << 0)) { /* ACLKOUT */
1626 clk
= omap_findclk(s
, "aclk_out");
1627 switch ((value
>> 0) & 3) {
1629 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1630 omap_clk_onoff(clk
, 1);
1633 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
1634 omap_clk_onoff(clk
, 1);
1637 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1638 omap_clk_onoff(clk
, 1);
1641 omap_clk_onoff(clk
, 0);
1646 static void omap_clkm_write(void *opaque
, hwaddr addr
,
1647 uint64_t value
, unsigned size
)
1649 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1652 static const char *clkschemename
[8] = {
1653 "fully synchronous", "fully asynchronous", "synchronous scalable",
1654 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1658 omap_badwidth_write16(opaque
, addr
, value
);
1663 case 0x00: /* ARM_CKCTL */
1664 diff
= s
->clkm
.arm_ckctl
^ value
;
1665 s
->clkm
.arm_ckctl
= value
& 0x7fff;
1666 omap_clkm_ckctl_update(s
, diff
, value
);
1669 case 0x04: /* ARM_IDLECT1 */
1670 diff
= s
->clkm
.arm_idlect1
^ value
;
1671 s
->clkm
.arm_idlect1
= value
& 0x0fff;
1672 omap_clkm_idlect1_update(s
, diff
, value
);
1675 case 0x08: /* ARM_IDLECT2 */
1676 diff
= s
->clkm
.arm_idlect2
^ value
;
1677 s
->clkm
.arm_idlect2
= value
& 0x07ff;
1678 omap_clkm_idlect2_update(s
, diff
, value
);
1681 case 0x0c: /* ARM_EWUPCT */
1682 s
->clkm
.arm_ewupct
= value
& 0x003f;
1685 case 0x10: /* ARM_RSTCT1 */
1686 diff
= s
->clkm
.arm_rstct1
^ value
;
1687 s
->clkm
.arm_rstct1
= value
& 0x0007;
1689 qemu_system_reset_request();
1690 s
->clkm
.cold_start
= 0xa;
1692 if (diff
& ~value
& 4) { /* DSP_RST */
1694 omap_tipb_bridge_reset(s
->private_tipb
);
1695 omap_tipb_bridge_reset(s
->public_tipb
);
1697 if (diff
& 2) { /* DSP_EN */
1698 clk
= omap_findclk(s
, "dsp_ck");
1699 omap_clk_canidle(clk
, (~value
>> 1) & 1);
1703 case 0x14: /* ARM_RSTCT2 */
1704 s
->clkm
.arm_rstct2
= value
& 0x0001;
1707 case 0x18: /* ARM_SYSST */
1708 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
1709 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
1710 printf("%s: clocking scheme set to %s\n", __FUNCTION__
,
1711 clkschemename
[s
->clkm
.clocking_scheme
]);
1713 s
->clkm
.cold_start
&= value
& 0x3f;
1716 case 0x1c: /* ARM_CKOUT1 */
1717 diff
= s
->clkm
.arm_ckout1
^ value
;
1718 s
->clkm
.arm_ckout1
= value
& 0x003f;
1719 omap_clkm_ckout1_update(s
, diff
, value
);
1722 case 0x20: /* ARM_CKOUT2 */
1728 static const MemoryRegionOps omap_clkm_ops
= {
1729 .read
= omap_clkm_read
,
1730 .write
= omap_clkm_write
,
1731 .endianness
= DEVICE_NATIVE_ENDIAN
,
1734 static uint64_t omap_clkdsp_read(void *opaque
, hwaddr addr
,
1737 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1738 CPUState
*cpu
= CPU(s
->cpu
);
1741 return omap_badwidth_read16(opaque
, addr
);
1745 case 0x04: /* DSP_IDLECT1 */
1746 return s
->clkm
.dsp_idlect1
;
1748 case 0x08: /* DSP_IDLECT2 */
1749 return s
->clkm
.dsp_idlect2
;
1751 case 0x14: /* DSP_RSTCT2 */
1752 return s
->clkm
.dsp_rstct2
;
1754 case 0x18: /* DSP_SYSST */
1756 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
1757 (cpu
->halted
<< 6); /* Quite useless... */
1764 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
1765 uint16_t diff
, uint16_t value
)
1769 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1772 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
1773 uint16_t diff
, uint16_t value
)
1777 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1780 static void omap_clkdsp_write(void *opaque
, hwaddr addr
,
1781 uint64_t value
, unsigned size
)
1783 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1787 omap_badwidth_write16(opaque
, addr
, value
);
1792 case 0x04: /* DSP_IDLECT1 */
1793 diff
= s
->clkm
.dsp_idlect1
^ value
;
1794 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
1795 omap_clkdsp_idlect1_update(s
, diff
, value
);
1798 case 0x08: /* DSP_IDLECT2 */
1799 s
->clkm
.dsp_idlect2
= value
& 0x0037;
1800 diff
= s
->clkm
.dsp_idlect1
^ value
;
1801 omap_clkdsp_idlect2_update(s
, diff
, value
);
1804 case 0x14: /* DSP_RSTCT2 */
1805 s
->clkm
.dsp_rstct2
= value
& 0x0001;
1808 case 0x18: /* DSP_SYSST */
1809 s
->clkm
.cold_start
&= value
& 0x3f;
1817 static const MemoryRegionOps omap_clkdsp_ops
= {
1818 .read
= omap_clkdsp_read
,
1819 .write
= omap_clkdsp_write
,
1820 .endianness
= DEVICE_NATIVE_ENDIAN
,
1823 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
1825 if (s
->wdt
&& s
->wdt
->reset
)
1826 s
->clkm
.cold_start
= 0x6;
1827 s
->clkm
.clocking_scheme
= 0;
1828 omap_clkm_ckctl_update(s
, ~0, 0x3000);
1829 s
->clkm
.arm_ckctl
= 0x3000;
1830 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
1831 s
->clkm
.arm_idlect1
= 0x0400;
1832 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
1833 s
->clkm
.arm_idlect2
= 0x0100;
1834 s
->clkm
.arm_ewupct
= 0x003f;
1835 s
->clkm
.arm_rstct1
= 0x0000;
1836 s
->clkm
.arm_rstct2
= 0x0000;
1837 s
->clkm
.arm_ckout1
= 0x0015;
1838 s
->clkm
.dpll1_mode
= 0x2002;
1839 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
1840 s
->clkm
.dsp_idlect1
= 0x0040;
1841 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
1842 s
->clkm
.dsp_idlect2
= 0x0000;
1843 s
->clkm
.dsp_rstct2
= 0x0000;
1846 static void omap_clkm_init(MemoryRegion
*memory
, hwaddr mpu_base
,
1847 hwaddr dsp_base
, struct omap_mpu_state_s
*s
)
1849 memory_region_init_io(&s
->clkm_iomem
, NULL
, &omap_clkm_ops
, s
,
1850 "omap-clkm", 0x100);
1851 memory_region_init_io(&s
->clkdsp_iomem
, NULL
, &omap_clkdsp_ops
, s
,
1852 "omap-clkdsp", 0x1000);
1854 s
->clkm
.arm_idlect1
= 0x03ff;
1855 s
->clkm
.arm_idlect2
= 0x0100;
1856 s
->clkm
.dsp_idlect1
= 0x0002;
1858 s
->clkm
.cold_start
= 0x3a;
1860 memory_region_add_subregion(memory
, mpu_base
, &s
->clkm_iomem
);
1861 memory_region_add_subregion(memory
, dsp_base
, &s
->clkdsp_iomem
);
1865 struct omap_mpuio_s
{
1869 qemu_irq handler
[16];
1891 static void omap_mpuio_set(void *opaque
, int line
, int level
)
1893 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1894 uint16_t prev
= s
->inputs
;
1897 s
->inputs
|= 1 << line
;
1899 s
->inputs
&= ~(1 << line
);
1901 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
1902 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
1903 s
->ints
|= 1 << line
;
1904 qemu_irq_raise(s
->irq
);
1907 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1908 (s
->event
>> 1) == line
) /* PIN_SELECT */
1909 s
->latch
= s
->inputs
;
1913 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
1916 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
1918 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
1922 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
1923 s
->row_latch
= ~rows
;
1926 static uint64_t omap_mpuio_read(void *opaque
, hwaddr addr
,
1929 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1930 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1934 return omap_badwidth_read16(opaque
, addr
);
1938 case 0x00: /* INPUT_LATCH */
1941 case 0x04: /* OUTPUT_REG */
1944 case 0x08: /* IO_CNTL */
1947 case 0x10: /* KBR_LATCH */
1948 return s
->row_latch
;
1950 case 0x14: /* KBC_REG */
1953 case 0x18: /* GPIO_EVENT_MODE_REG */
1956 case 0x1c: /* GPIO_INT_EDGE_REG */
1959 case 0x20: /* KBD_INT */
1960 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
1962 case 0x24: /* GPIO_INT */
1966 qemu_irq_lower(s
->irq
);
1969 case 0x28: /* KBD_MASKIT */
1972 case 0x2c: /* GPIO_MASKIT */
1975 case 0x30: /* GPIO_DEBOUNCING_REG */
1978 case 0x34: /* GPIO_LATCH_REG */
1986 static void omap_mpuio_write(void *opaque
, hwaddr addr
,
1987 uint64_t value
, unsigned size
)
1989 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1990 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1995 omap_badwidth_write16(opaque
, addr
, value
);
2000 case 0x04: /* OUTPUT_REG */
2001 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2003 while ((ln
= ctz32(diff
)) != 32) {
2005 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2010 case 0x08: /* IO_CNTL */
2011 diff
= s
->outputs
& (s
->dir
^ value
);
2014 value
= s
->outputs
& ~s
->dir
;
2015 while ((ln
= ctz32(diff
)) != 32) {
2017 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2022 case 0x14: /* KBC_REG */
2024 omap_mpuio_kbd_update(s
);
2027 case 0x18: /* GPIO_EVENT_MODE_REG */
2028 s
->event
= value
& 0x1f;
2031 case 0x1c: /* GPIO_INT_EDGE_REG */
2035 case 0x28: /* KBD_MASKIT */
2036 s
->kbd_mask
= value
& 1;
2037 omap_mpuio_kbd_update(s
);
2040 case 0x2c: /* GPIO_MASKIT */
2044 case 0x30: /* GPIO_DEBOUNCING_REG */
2045 s
->debounce
= value
& 0x1ff;
2048 case 0x00: /* INPUT_LATCH */
2049 case 0x10: /* KBR_LATCH */
2050 case 0x20: /* KBD_INT */
2051 case 0x24: /* GPIO_INT */
2052 case 0x34: /* GPIO_LATCH_REG */
2062 static const MemoryRegionOps omap_mpuio_ops
= {
2063 .read
= omap_mpuio_read
,
2064 .write
= omap_mpuio_write
,
2065 .endianness
= DEVICE_NATIVE_ENDIAN
,
2068 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2080 s
->row_latch
= 0x1f;
2084 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2086 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2090 omap_mpuio_kbd_update(s
);
2093 static struct omap_mpuio_s
*omap_mpuio_init(MemoryRegion
*memory
,
2095 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2098 struct omap_mpuio_s
*s
= g_new0(struct omap_mpuio_s
, 1);
2101 s
->kbd_irq
= kbd_int
;
2103 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2104 omap_mpuio_reset(s
);
2106 memory_region_init_io(&s
->iomem
, NULL
, &omap_mpuio_ops
, s
,
2107 "omap-mpuio", 0x800);
2108 memory_region_add_subregion(memory
, base
, &s
->iomem
);
2110 omap_clk_adduser(clk
, qemu_allocate_irq(omap_mpuio_onoff
, s
, 0));
2115 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2120 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2122 if (line
>= 16 || line
< 0)
2123 hw_error("%s: No GPIO line %i\n", __FUNCTION__
, line
);
2124 s
->handler
[line
] = handler
;
2127 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2129 if (row
>= 5 || row
< 0)
2130 hw_error("%s: No key %i-%i\n", __FUNCTION__
, col
, row
);
2133 s
->buttons
[row
] |= 1 << col
;
2135 s
->buttons
[row
] &= ~(1 << col
);
2137 omap_mpuio_kbd_update(s
);
2140 /* MicroWire Interface */
2141 struct omap_uwire_s
{
2152 uWireSlave
*chip
[4];
2155 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
2157 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
2158 uWireSlave
*slave
= s
->chip
[chipselect
];
2160 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
2161 if (s
->control
& (1 << 12)) /* CS_CMD */
2162 if (slave
&& slave
->send
)
2163 slave
->send(slave
->opaque
,
2164 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
2165 s
->control
&= ~(1 << 14); /* CSRB */
2166 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2167 * a DRQ. When is the level IRQ supposed to be reset? */
2170 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
2171 if (s
->control
& (1 << 12)) /* CS_CMD */
2172 if (slave
&& slave
->receive
)
2173 s
->rxbuf
= slave
->receive(slave
->opaque
);
2174 s
->control
|= 1 << 15; /* RDRB */
2175 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2176 * a DRQ. When is the level IRQ supposed to be reset? */
2180 static uint64_t omap_uwire_read(void *opaque
, hwaddr addr
,
2183 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2184 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2187 return omap_badwidth_read16(opaque
, addr
);
2191 case 0x00: /* RDR */
2192 s
->control
&= ~(1 << 15); /* RDRB */
2195 case 0x04: /* CSR */
2198 case 0x08: /* SR1 */
2200 case 0x0c: /* SR2 */
2202 case 0x10: /* SR3 */
2204 case 0x14: /* SR4 */
2206 case 0x18: /* SR5 */
2214 static void omap_uwire_write(void *opaque
, hwaddr addr
,
2215 uint64_t value
, unsigned size
)
2217 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2218 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2221 omap_badwidth_write16(opaque
, addr
, value
);
2226 case 0x00: /* TDR */
2227 s
->txbuf
= value
; /* TD */
2228 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
2229 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2230 (s
->control
& (1 << 12)))) { /* CS_CMD */
2231 s
->control
|= 1 << 14; /* CSRB */
2232 omap_uwire_transfer_start(s
);
2236 case 0x04: /* CSR */
2237 s
->control
= value
& 0x1fff;
2238 if (value
& (1 << 13)) /* START */
2239 omap_uwire_transfer_start(s
);
2242 case 0x08: /* SR1 */
2243 s
->setup
[0] = value
& 0x003f;
2246 case 0x0c: /* SR2 */
2247 s
->setup
[1] = value
& 0x0fc0;
2250 case 0x10: /* SR3 */
2251 s
->setup
[2] = value
& 0x0003;
2254 case 0x14: /* SR4 */
2255 s
->setup
[3] = value
& 0x0001;
2258 case 0x18: /* SR5 */
2259 s
->setup
[4] = value
& 0x000f;
2268 static const MemoryRegionOps omap_uwire_ops
= {
2269 .read
= omap_uwire_read
,
2270 .write
= omap_uwire_write
,
2271 .endianness
= DEVICE_NATIVE_ENDIAN
,
2274 static void omap_uwire_reset(struct omap_uwire_s
*s
)
2284 static struct omap_uwire_s
*omap_uwire_init(MemoryRegion
*system_memory
,
2286 qemu_irq txirq
, qemu_irq rxirq
,
2290 struct omap_uwire_s
*s
= g_new0(struct omap_uwire_s
, 1);
2295 omap_uwire_reset(s
);
2297 memory_region_init_io(&s
->iomem
, NULL
, &omap_uwire_ops
, s
, "omap-uwire", 0x800);
2298 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2303 void omap_uwire_attach(struct omap_uwire_s
*s
,
2304 uWireSlave
*slave
, int chipselect
)
2306 if (chipselect
< 0 || chipselect
> 3) {
2307 fprintf(stderr
, "%s: Bad chipselect %i\n", __FUNCTION__
, chipselect
);
2311 s
->chip
[chipselect
] = slave
;
2314 /* Pseudonoise Pulse-Width Light Modulator */
2323 static void omap_pwl_update(struct omap_pwl_s
*s
)
2325 int output
= (s
->clk
&& s
->enable
) ? s
->level
: 0;
2327 if (output
!= s
->output
) {
2329 printf("%s: Backlight now at %i/256\n", __FUNCTION__
, output
);
2333 static uint64_t omap_pwl_read(void *opaque
, hwaddr addr
,
2336 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2337 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2340 return omap_badwidth_read8(opaque
, addr
);
2344 case 0x00: /* PWL_LEVEL */
2346 case 0x04: /* PWL_CTRL */
2353 static void omap_pwl_write(void *opaque
, hwaddr addr
,
2354 uint64_t value
, unsigned size
)
2356 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2357 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2360 omap_badwidth_write8(opaque
, addr
, value
);
2365 case 0x00: /* PWL_LEVEL */
2369 case 0x04: /* PWL_CTRL */
2370 s
->enable
= value
& 1;
2379 static const MemoryRegionOps omap_pwl_ops
= {
2380 .read
= omap_pwl_read
,
2381 .write
= omap_pwl_write
,
2382 .endianness
= DEVICE_NATIVE_ENDIAN
,
2385 static void omap_pwl_reset(struct omap_pwl_s
*s
)
2394 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
2396 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2402 static struct omap_pwl_s
*omap_pwl_init(MemoryRegion
*system_memory
,
2406 struct omap_pwl_s
*s
= g_malloc0(sizeof(*s
));
2410 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwl_ops
, s
,
2412 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2414 omap_clk_adduser(clk
, qemu_allocate_irq(omap_pwl_clk_update
, s
, 0));
2418 /* Pulse-Width Tone module */
2427 static uint64_t omap_pwt_read(void *opaque
, hwaddr addr
,
2430 struct omap_pwt_s
*s
= (struct omap_pwt_s
*) opaque
;
2431 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2434 return omap_badwidth_read8(opaque
, addr
);
2438 case 0x00: /* FRC */
2440 case 0x04: /* VCR */
2442 case 0x08: /* GCR */
2449 static void omap_pwt_write(void *opaque
, hwaddr addr
,
2450 uint64_t value
, unsigned size
)
2452 struct omap_pwt_s
*s
= (struct omap_pwt_s
*) opaque
;
2453 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2456 omap_badwidth_write8(opaque
, addr
, value
);
2461 case 0x00: /* FRC */
2462 s
->frc
= value
& 0x3f;
2464 case 0x04: /* VRC */
2465 if ((value
^ s
->vrc
) & 1) {
2467 printf("%s: %iHz buzz on\n", __FUNCTION__
, (int)
2468 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2469 ((omap_clk_getrate(s
->clk
) >> 3) /
2470 /* Pre-multiplexer divider */
2471 ((s
->gcr
& 2) ? 1 : 154) /
2472 /* Octave multiplexer */
2473 (2 << (value
& 3)) *
2474 /* 101/107 divider */
2475 ((value
& (1 << 2)) ? 101 : 107) *
2477 ((value
& (1 << 3)) ? 49 : 55) *
2479 ((value
& (1 << 4)) ? 50 : 63) *
2480 /* 80/127 divider */
2481 ((value
& (1 << 5)) ? 80 : 127) /
2482 (107 * 55 * 63 * 127)));
2484 printf("%s: silence!\n", __FUNCTION__
);
2486 s
->vrc
= value
& 0x7f;
2488 case 0x08: /* GCR */
2497 static const MemoryRegionOps omap_pwt_ops
= {
2498 .read
=omap_pwt_read
,
2499 .write
= omap_pwt_write
,
2500 .endianness
= DEVICE_NATIVE_ENDIAN
,
2503 static void omap_pwt_reset(struct omap_pwt_s
*s
)
2510 static struct omap_pwt_s
*omap_pwt_init(MemoryRegion
*system_memory
,
2514 struct omap_pwt_s
*s
= g_malloc0(sizeof(*s
));
2518 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwt_ops
, s
,
2520 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2524 /* Real-time Clock module */
2541 struct tm current_tm
;
2546 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
2548 /* s->alarm is level-triggered */
2549 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
2552 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
2554 s
->alarm_ti
= mktimegm(&s
->alarm_tm
);
2555 if (s
->alarm_ti
== -1)
2556 printf("%s: conversion failed\n", __FUNCTION__
);
2559 static uint64_t omap_rtc_read(void *opaque
, hwaddr addr
,
2562 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2563 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2567 return omap_badwidth_read8(opaque
, addr
);
2571 case 0x00: /* SECONDS_REG */
2572 return to_bcd(s
->current_tm
.tm_sec
);
2574 case 0x04: /* MINUTES_REG */
2575 return to_bcd(s
->current_tm
.tm_min
);
2577 case 0x08: /* HOURS_REG */
2579 return ((s
->current_tm
.tm_hour
> 11) << 7) |
2580 to_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
2582 return to_bcd(s
->current_tm
.tm_hour
);
2584 case 0x0c: /* DAYS_REG */
2585 return to_bcd(s
->current_tm
.tm_mday
);
2587 case 0x10: /* MONTHS_REG */
2588 return to_bcd(s
->current_tm
.tm_mon
+ 1);
2590 case 0x14: /* YEARS_REG */
2591 return to_bcd(s
->current_tm
.tm_year
% 100);
2593 case 0x18: /* WEEK_REG */
2594 return s
->current_tm
.tm_wday
;
2596 case 0x20: /* ALARM_SECONDS_REG */
2597 return to_bcd(s
->alarm_tm
.tm_sec
);
2599 case 0x24: /* ALARM_MINUTES_REG */
2600 return to_bcd(s
->alarm_tm
.tm_min
);
2602 case 0x28: /* ALARM_HOURS_REG */
2604 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
2605 to_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
2607 return to_bcd(s
->alarm_tm
.tm_hour
);
2609 case 0x2c: /* ALARM_DAYS_REG */
2610 return to_bcd(s
->alarm_tm
.tm_mday
);
2612 case 0x30: /* ALARM_MONTHS_REG */
2613 return to_bcd(s
->alarm_tm
.tm_mon
+ 1);
2615 case 0x34: /* ALARM_YEARS_REG */
2616 return to_bcd(s
->alarm_tm
.tm_year
% 100);
2618 case 0x40: /* RTC_CTRL_REG */
2619 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
2620 (s
->round
<< 1) | s
->running
;
2622 case 0x44: /* RTC_STATUS_REG */
2627 case 0x48: /* RTC_INTERRUPTS_REG */
2628 return s
->interrupts
;
2630 case 0x4c: /* RTC_COMP_LSB_REG */
2631 return ((uint16_t) s
->comp_reg
) & 0xff;
2633 case 0x50: /* RTC_COMP_MSB_REG */
2634 return ((uint16_t) s
->comp_reg
) >> 8;
2641 static void omap_rtc_write(void *opaque
, hwaddr addr
,
2642 uint64_t value
, unsigned size
)
2644 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2645 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2650 omap_badwidth_write8(opaque
, addr
, value
);
2655 case 0x00: /* SECONDS_REG */
2657 printf("RTC SEC_REG <-- %02x\n", value
);
2659 s
->ti
-= s
->current_tm
.tm_sec
;
2660 s
->ti
+= from_bcd(value
);
2663 case 0x04: /* MINUTES_REG */
2665 printf("RTC MIN_REG <-- %02x\n", value
);
2667 s
->ti
-= s
->current_tm
.tm_min
* 60;
2668 s
->ti
+= from_bcd(value
) * 60;
2671 case 0x08: /* HOURS_REG */
2673 printf("RTC HRS_REG <-- %02x\n", value
);
2675 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
2677 s
->ti
+= (from_bcd(value
& 0x3f) & 12) * 3600;
2678 s
->ti
+= ((value
>> 7) & 1) * 43200;
2680 s
->ti
+= from_bcd(value
& 0x3f) * 3600;
2683 case 0x0c: /* DAYS_REG */
2685 printf("RTC DAY_REG <-- %02x\n", value
);
2687 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
2688 s
->ti
+= from_bcd(value
) * 86400;
2691 case 0x10: /* MONTHS_REG */
2693 printf("RTC MTH_REG <-- %02x\n", value
);
2695 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2696 new_tm
.tm_mon
= from_bcd(value
);
2697 ti
[0] = mktimegm(&s
->current_tm
);
2698 ti
[1] = mktimegm(&new_tm
);
2700 if (ti
[0] != -1 && ti
[1] != -1) {
2704 /* A less accurate version */
2705 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
2706 s
->ti
+= from_bcd(value
) * 2592000;
2710 case 0x14: /* YEARS_REG */
2712 printf("RTC YRS_REG <-- %02x\n", value
);
2714 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2715 new_tm
.tm_year
+= from_bcd(value
) - (new_tm
.tm_year
% 100);
2716 ti
[0] = mktimegm(&s
->current_tm
);
2717 ti
[1] = mktimegm(&new_tm
);
2719 if (ti
[0] != -1 && ti
[1] != -1) {
2723 /* A less accurate version */
2724 s
->ti
-= (time_t)(s
->current_tm
.tm_year
% 100) * 31536000;
2725 s
->ti
+= (time_t)from_bcd(value
) * 31536000;
2729 case 0x18: /* WEEK_REG */
2730 return; /* Ignored */
2732 case 0x20: /* ALARM_SECONDS_REG */
2734 printf("ALM SEC_REG <-- %02x\n", value
);
2736 s
->alarm_tm
.tm_sec
= from_bcd(value
);
2737 omap_rtc_alarm_update(s
);
2740 case 0x24: /* ALARM_MINUTES_REG */
2742 printf("ALM MIN_REG <-- %02x\n", value
);
2744 s
->alarm_tm
.tm_min
= from_bcd(value
);
2745 omap_rtc_alarm_update(s
);
2748 case 0x28: /* ALARM_HOURS_REG */
2750 printf("ALM HRS_REG <-- %02x\n", value
);
2753 s
->alarm_tm
.tm_hour
=
2754 ((from_bcd(value
& 0x3f)) % 12) +
2755 ((value
>> 7) & 1) * 12;
2757 s
->alarm_tm
.tm_hour
= from_bcd(value
);
2758 omap_rtc_alarm_update(s
);
2761 case 0x2c: /* ALARM_DAYS_REG */
2763 printf("ALM DAY_REG <-- %02x\n", value
);
2765 s
->alarm_tm
.tm_mday
= from_bcd(value
);
2766 omap_rtc_alarm_update(s
);
2769 case 0x30: /* ALARM_MONTHS_REG */
2771 printf("ALM MON_REG <-- %02x\n", value
);
2773 s
->alarm_tm
.tm_mon
= from_bcd(value
);
2774 omap_rtc_alarm_update(s
);
2777 case 0x34: /* ALARM_YEARS_REG */
2779 printf("ALM YRS_REG <-- %02x\n", value
);
2781 s
->alarm_tm
.tm_year
= from_bcd(value
);
2782 omap_rtc_alarm_update(s
);
2785 case 0x40: /* RTC_CTRL_REG */
2787 printf("RTC CONTROL <-- %02x\n", value
);
2789 s
->pm_am
= (value
>> 3) & 1;
2790 s
->auto_comp
= (value
>> 2) & 1;
2791 s
->round
= (value
>> 1) & 1;
2792 s
->running
= value
& 1;
2794 s
->status
|= s
->running
<< 1;
2797 case 0x44: /* RTC_STATUS_REG */
2799 printf("RTC STATUSL <-- %02x\n", value
);
2801 s
->status
&= ~((value
& 0xc0) ^ 0x80);
2802 omap_rtc_interrupts_update(s
);
2805 case 0x48: /* RTC_INTERRUPTS_REG */
2807 printf("RTC INTRS <-- %02x\n", value
);
2809 s
->interrupts
= value
;
2812 case 0x4c: /* RTC_COMP_LSB_REG */
2814 printf("RTC COMPLSB <-- %02x\n", value
);
2816 s
->comp_reg
&= 0xff00;
2817 s
->comp_reg
|= 0x00ff & value
;
2820 case 0x50: /* RTC_COMP_MSB_REG */
2822 printf("RTC COMPMSB <-- %02x\n", value
);
2824 s
->comp_reg
&= 0x00ff;
2825 s
->comp_reg
|= 0xff00 & (value
<< 8);
2834 static const MemoryRegionOps omap_rtc_ops
= {
2835 .read
= omap_rtc_read
,
2836 .write
= omap_rtc_write
,
2837 .endianness
= DEVICE_NATIVE_ENDIAN
,
2840 static void omap_rtc_tick(void *opaque
)
2842 struct omap_rtc_s
*s
= opaque
;
2845 /* Round to nearest full minute. */
2846 if (s
->current_tm
.tm_sec
< 30)
2847 s
->ti
-= s
->current_tm
.tm_sec
;
2849 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
2854 localtime_r(&s
->ti
, &s
->current_tm
);
2856 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
2858 omap_rtc_interrupts_update(s
);
2861 if (s
->interrupts
& 0x04)
2862 switch (s
->interrupts
& 3) {
2865 qemu_irq_pulse(s
->irq
);
2868 if (s
->current_tm
.tm_sec
)
2871 qemu_irq_pulse(s
->irq
);
2874 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
2877 qemu_irq_pulse(s
->irq
);
2880 if (s
->current_tm
.tm_sec
||
2881 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
2884 qemu_irq_pulse(s
->irq
);
2894 * Every full hour add a rough approximation of the compensation
2895 * register to the 32kHz Timer (which drives the RTC) value.
2897 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
2898 s
->tick
+= s
->comp_reg
* 1000 / 32768;
2900 timer_mod(s
->clk
, s
->tick
);
2903 static void omap_rtc_reset(struct omap_rtc_s
*s
)
2913 s
->tick
= qemu_clock_get_ms(rtc_clock
);
2914 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
2915 s
->alarm_tm
.tm_mday
= 0x01;
2917 qemu_get_timedate(&tm
, 0);
2918 s
->ti
= mktimegm(&tm
);
2920 omap_rtc_alarm_update(s
);
2924 static struct omap_rtc_s
*omap_rtc_init(MemoryRegion
*system_memory
,
2926 qemu_irq timerirq
, qemu_irq alarmirq
,
2929 struct omap_rtc_s
*s
= g_new0(struct omap_rtc_s
, 1);
2932 s
->alarm
= alarmirq
;
2933 s
->clk
= timer_new_ms(rtc_clock
, omap_rtc_tick
, s
);
2937 memory_region_init_io(&s
->iomem
, NULL
, &omap_rtc_ops
, s
,
2939 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2944 /* Multi-channel Buffered Serial Port interfaces */
2945 struct omap_mcbsp_s
{
2966 QEMUTimer
*source_timer
;
2967 QEMUTimer
*sink_timer
;
2970 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
2974 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
2976 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
2979 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
2987 qemu_irq_pulse(s
->rxirq
);
2989 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
2991 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
2994 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
3002 qemu_irq_pulse(s
->txirq
);
3005 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
3007 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
3008 s
->spcr
[0] |= 1 << 2; /* RFULL */
3009 s
->spcr
[0] |= 1 << 1; /* RRDY */
3010 qemu_irq_raise(s
->rxdrq
);
3011 omap_mcbsp_intr_update(s
);
3014 static void omap_mcbsp_source_tick(void *opaque
)
3016 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3017 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3022 printf("%s: Rx FIFO overrun\n", __FUNCTION__
);
3024 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
3026 omap_mcbsp_rx_newdata(s
);
3027 timer_mod(s
->source_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3028 get_ticks_per_sec());
3031 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
3033 if (!s
->codec
|| !s
->codec
->rts
)
3034 omap_mcbsp_source_tick(s
);
3035 else if (s
->codec
->in
.len
) {
3036 s
->rx_req
= s
->codec
->in
.len
;
3037 omap_mcbsp_rx_newdata(s
);
3041 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
3043 timer_del(s
->source_timer
);
3046 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
3048 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
3049 qemu_irq_lower(s
->rxdrq
);
3050 omap_mcbsp_intr_update(s
);
3053 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
3055 s
->spcr
[1] |= 1 << 1; /* XRDY */
3056 qemu_irq_raise(s
->txdrq
);
3057 omap_mcbsp_intr_update(s
);
3060 static void omap_mcbsp_sink_tick(void *opaque
)
3062 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3063 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3068 printf("%s: Tx FIFO underrun\n", __FUNCTION__
);
3070 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
3072 omap_mcbsp_tx_newdata(s
);
3073 timer_mod(s
->sink_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3074 get_ticks_per_sec());
3077 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
3079 if (!s
->codec
|| !s
->codec
->cts
)
3080 omap_mcbsp_sink_tick(s
);
3081 else if (s
->codec
->out
.size
) {
3082 s
->tx_req
= s
->codec
->out
.size
;
3083 omap_mcbsp_tx_newdata(s
);
3087 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
3089 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
3090 qemu_irq_lower(s
->txdrq
);
3091 omap_mcbsp_intr_update(s
);
3092 if (s
->codec
&& s
->codec
->cts
)
3093 s
->codec
->tx_swallow(s
->codec
->opaque
);
3096 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
3099 omap_mcbsp_tx_done(s
);
3100 timer_del(s
->sink_timer
);
3103 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
3105 int prev_rx_rate
, prev_tx_rate
;
3106 int rx_rate
= 0, tx_rate
= 0;
3107 int cpu_rate
= 1500000; /* XXX */
3109 /* TODO: check CLKSTP bit */
3110 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3111 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3112 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3113 (s
->pcr
& (1 << 8))) { /* CLKRM */
3114 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3115 rx_rate
= cpu_rate
/
3116 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3119 rx_rate
= s
->codec
->rx_rate
;
3122 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3123 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3124 (s
->pcr
& (1 << 9))) { /* CLKXM */
3125 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3126 tx_rate
= cpu_rate
/
3127 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3130 tx_rate
= s
->codec
->tx_rate
;
3133 prev_tx_rate
= s
->tx_rate
;
3134 prev_rx_rate
= s
->rx_rate
;
3135 s
->tx_rate
= tx_rate
;
3136 s
->rx_rate
= rx_rate
;
3139 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3141 if (!prev_tx_rate
&& tx_rate
)
3142 omap_mcbsp_tx_start(s
);
3143 else if (s
->tx_rate
&& !tx_rate
)
3144 omap_mcbsp_tx_stop(s
);
3146 if (!prev_rx_rate
&& rx_rate
)
3147 omap_mcbsp_rx_start(s
);
3148 else if (prev_tx_rate
&& !tx_rate
)
3149 omap_mcbsp_rx_stop(s
);
3152 static uint64_t omap_mcbsp_read(void *opaque
, hwaddr addr
,
3155 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3156 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3160 return omap_badwidth_read16(opaque
, addr
);
3164 case 0x00: /* DRR2 */
3165 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
3168 case 0x02: /* DRR1 */
3169 if (s
->rx_req
< 2) {
3170 printf("%s: Rx FIFO underrun\n", __FUNCTION__
);
3171 omap_mcbsp_rx_done(s
);
3174 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
3175 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
3176 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
3177 s
->codec
->in
.len
-= 2;
3181 omap_mcbsp_rx_done(s
);
3186 case 0x04: /* DXR2 */
3187 case 0x06: /* DXR1 */
3190 case 0x08: /* SPCR2 */
3192 case 0x0a: /* SPCR1 */
3194 case 0x0c: /* RCR2 */
3196 case 0x0e: /* RCR1 */
3198 case 0x10: /* XCR2 */
3200 case 0x12: /* XCR1 */
3202 case 0x14: /* SRGR2 */
3204 case 0x16: /* SRGR1 */
3206 case 0x18: /* MCR2 */
3208 case 0x1a: /* MCR1 */
3210 case 0x1c: /* RCERA */
3212 case 0x1e: /* RCERB */
3214 case 0x20: /* XCERA */
3216 case 0x22: /* XCERB */
3218 case 0x24: /* PCR0 */
3220 case 0x26: /* RCERC */
3222 case 0x28: /* RCERD */
3224 case 0x2a: /* XCERC */
3226 case 0x2c: /* XCERD */
3228 case 0x2e: /* RCERE */
3230 case 0x30: /* RCERF */
3232 case 0x32: /* XCERE */
3234 case 0x34: /* XCERF */
3236 case 0x36: /* RCERG */
3238 case 0x38: /* RCERH */
3240 case 0x3a: /* XCERG */
3242 case 0x3c: /* XCERH */
3250 static void omap_mcbsp_writeh(void *opaque
, hwaddr addr
,
3253 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3254 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3257 case 0x00: /* DRR2 */
3258 case 0x02: /* DRR1 */
3262 case 0x04: /* DXR2 */
3263 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3266 case 0x06: /* DXR1 */
3267 if (s
->tx_req
> 1) {
3269 if (s
->codec
&& s
->codec
->cts
) {
3270 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
3271 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
3274 omap_mcbsp_tx_done(s
);
3276 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
3279 case 0x08: /* SPCR2 */
3280 s
->spcr
[1] &= 0x0002;
3281 s
->spcr
[1] |= 0x03f9 & value
;
3282 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
3283 if (~value
& 1) /* XRST */
3285 omap_mcbsp_req_update(s
);
3287 case 0x0a: /* SPCR1 */
3288 s
->spcr
[0] &= 0x0006;
3289 s
->spcr
[0] |= 0xf8f9 & value
;
3290 if (value
& (1 << 15)) /* DLB */
3291 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__
);
3292 if (~value
& 1) { /* RRST */
3295 omap_mcbsp_rx_done(s
);
3297 omap_mcbsp_req_update(s
);
3300 case 0x0c: /* RCR2 */
3301 s
->rcr
[1] = value
& 0xffff;
3303 case 0x0e: /* RCR1 */
3304 s
->rcr
[0] = value
& 0x7fe0;
3306 case 0x10: /* XCR2 */
3307 s
->xcr
[1] = value
& 0xffff;
3309 case 0x12: /* XCR1 */
3310 s
->xcr
[0] = value
& 0x7fe0;
3312 case 0x14: /* SRGR2 */
3313 s
->srgr
[1] = value
& 0xffff;
3314 omap_mcbsp_req_update(s
);
3316 case 0x16: /* SRGR1 */
3317 s
->srgr
[0] = value
& 0xffff;
3318 omap_mcbsp_req_update(s
);
3320 case 0x18: /* MCR2 */
3321 s
->mcr
[1] = value
& 0x03e3;
3322 if (value
& 3) /* XMCM */
3323 printf("%s: Tx channel selection mode enable attempt\n",
3326 case 0x1a: /* MCR1 */
3327 s
->mcr
[0] = value
& 0x03e1;
3328 if (value
& 1) /* RMCM */
3329 printf("%s: Rx channel selection mode enable attempt\n",
3332 case 0x1c: /* RCERA */
3333 s
->rcer
[0] = value
& 0xffff;
3335 case 0x1e: /* RCERB */
3336 s
->rcer
[1] = value
& 0xffff;
3338 case 0x20: /* XCERA */
3339 s
->xcer
[0] = value
& 0xffff;
3341 case 0x22: /* XCERB */
3342 s
->xcer
[1] = value
& 0xffff;
3344 case 0x24: /* PCR0 */
3345 s
->pcr
= value
& 0x7faf;
3347 case 0x26: /* RCERC */
3348 s
->rcer
[2] = value
& 0xffff;
3350 case 0x28: /* RCERD */
3351 s
->rcer
[3] = value
& 0xffff;
3353 case 0x2a: /* XCERC */
3354 s
->xcer
[2] = value
& 0xffff;
3356 case 0x2c: /* XCERD */
3357 s
->xcer
[3] = value
& 0xffff;
3359 case 0x2e: /* RCERE */
3360 s
->rcer
[4] = value
& 0xffff;
3362 case 0x30: /* RCERF */
3363 s
->rcer
[5] = value
& 0xffff;
3365 case 0x32: /* XCERE */
3366 s
->xcer
[4] = value
& 0xffff;
3368 case 0x34: /* XCERF */
3369 s
->xcer
[5] = value
& 0xffff;
3371 case 0x36: /* RCERG */
3372 s
->rcer
[6] = value
& 0xffff;
3374 case 0x38: /* RCERH */
3375 s
->rcer
[7] = value
& 0xffff;
3377 case 0x3a: /* XCERG */
3378 s
->xcer
[6] = value
& 0xffff;
3380 case 0x3c: /* XCERH */
3381 s
->xcer
[7] = value
& 0xffff;
3388 static void omap_mcbsp_writew(void *opaque
, hwaddr addr
,
3391 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3392 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3394 if (offset
== 0x04) { /* DXR */
3395 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3397 if (s
->tx_req
> 3) {
3399 if (s
->codec
&& s
->codec
->cts
) {
3400 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3401 (value
>> 24) & 0xff;
3402 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3403 (value
>> 16) & 0xff;
3404 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3405 (value
>> 8) & 0xff;
3406 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3407 (value
>> 0) & 0xff;
3410 omap_mcbsp_tx_done(s
);
3412 printf("%s: Tx FIFO overrun\n", __FUNCTION__
);
3416 omap_badwidth_write16(opaque
, addr
, value
);
3419 static void omap_mcbsp_write(void *opaque
, hwaddr addr
,
3420 uint64_t value
, unsigned size
)
3424 omap_mcbsp_writeh(opaque
, addr
, value
);
3427 omap_mcbsp_writew(opaque
, addr
, value
);
3430 omap_badwidth_write16(opaque
, addr
, value
);
3434 static const MemoryRegionOps omap_mcbsp_ops
= {
3435 .read
= omap_mcbsp_read
,
3436 .write
= omap_mcbsp_write
,
3437 .endianness
= DEVICE_NATIVE_ENDIAN
,
3440 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
3442 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
3443 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
3444 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
3445 s
->srgr
[0] = 0x0001;
3446 s
->srgr
[1] = 0x2000;
3447 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
3448 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
3449 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
3450 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
3455 timer_del(s
->source_timer
);
3456 timer_del(s
->sink_timer
);
3459 static struct omap_mcbsp_s
*omap_mcbsp_init(MemoryRegion
*system_memory
,
3461 qemu_irq txirq
, qemu_irq rxirq
,
3462 qemu_irq
*dma
, omap_clk clk
)
3464 struct omap_mcbsp_s
*s
= g_new0(struct omap_mcbsp_s
, 1);
3470 s
->sink_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_sink_tick
, s
);
3471 s
->source_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_source_tick
, s
);
3472 omap_mcbsp_reset(s
);
3474 memory_region_init_io(&s
->iomem
, NULL
, &omap_mcbsp_ops
, s
, "omap-mcbsp", 0x800);
3475 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3480 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
3482 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3485 s
->rx_req
= s
->codec
->in
.len
;
3486 omap_mcbsp_rx_newdata(s
);
3490 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
3492 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3495 s
->tx_req
= s
->codec
->out
.size
;
3496 omap_mcbsp_tx_newdata(s
);
3500 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, I2SCodec
*slave
)
3503 slave
->rx_swallow
= qemu_allocate_irq(omap_mcbsp_i2s_swallow
, s
, 0);
3504 slave
->tx_start
= qemu_allocate_irq(omap_mcbsp_i2s_start
, s
, 0);
3507 /* LED Pulse Generators */
3520 static void omap_lpg_tick(void *opaque
)
3522 struct omap_lpg_s
*s
= opaque
;
3525 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->period
- s
->on
);
3527 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->on
);
3529 s
->cycle
= !s
->cycle
;
3530 printf("%s: LED is %s\n", __FUNCTION__
, s
->cycle
? "on" : "off");
3533 static void omap_lpg_update(struct omap_lpg_s
*s
)
3535 int64_t on
, period
= 1, ticks
= 1000;
3536 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3538 if (~s
->control
& (1 << 6)) /* LPGRES */
3540 else if (s
->control
& (1 << 7)) /* PERM_ON */
3543 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
3545 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
3546 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
3550 if (on
== period
&& s
->on
< s
->period
)
3551 printf("%s: LED is on\n", __FUNCTION__
);
3552 else if (on
== 0 && s
->on
)
3553 printf("%s: LED is off\n", __FUNCTION__
);
3554 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
3566 static void omap_lpg_reset(struct omap_lpg_s
*s
)
3574 static uint64_t omap_lpg_read(void *opaque
, hwaddr addr
,
3577 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3578 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3581 return omap_badwidth_read8(opaque
, addr
);
3585 case 0x00: /* LCR */
3588 case 0x04: /* PMR */
3596 static void omap_lpg_write(void *opaque
, hwaddr addr
,
3597 uint64_t value
, unsigned size
)
3599 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3600 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3603 omap_badwidth_write8(opaque
, addr
, value
);
3608 case 0x00: /* LCR */
3609 if (~value
& (1 << 6)) /* LPGRES */
3611 s
->control
= value
& 0xff;
3615 case 0x04: /* PMR */
3616 s
->power
= value
& 0x01;
3626 static const MemoryRegionOps omap_lpg_ops
= {
3627 .read
= omap_lpg_read
,
3628 .write
= omap_lpg_write
,
3629 .endianness
= DEVICE_NATIVE_ENDIAN
,
3632 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
3634 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3640 static struct omap_lpg_s
*omap_lpg_init(MemoryRegion
*system_memory
,
3641 hwaddr base
, omap_clk clk
)
3643 struct omap_lpg_s
*s
= g_new0(struct omap_lpg_s
, 1);
3645 s
->tm
= timer_new_ms(QEMU_CLOCK_VIRTUAL
, omap_lpg_tick
, s
);
3649 memory_region_init_io(&s
->iomem
, NULL
, &omap_lpg_ops
, s
, "omap-lpg", 0x800);
3650 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3652 omap_clk_adduser(clk
, qemu_allocate_irq(omap_lpg_clk_update
, s
, 0));
3657 /* MPUI Peripheral Bridge configuration */
3658 static uint64_t omap_mpui_io_read(void *opaque
, hwaddr addr
,
3662 return omap_badwidth_read16(opaque
, addr
);
3665 if (addr
== OMAP_MPUI_BASE
) /* CMR */
3672 static void omap_mpui_io_write(void *opaque
, hwaddr addr
,
3673 uint64_t value
, unsigned size
)
3675 /* FIXME: infinite loop */
3676 omap_badwidth_write16(opaque
, addr
, value
);
3679 static const MemoryRegionOps omap_mpui_io_ops
= {
3680 .read
= omap_mpui_io_read
,
3681 .write
= omap_mpui_io_write
,
3682 .endianness
= DEVICE_NATIVE_ENDIAN
,
3685 static void omap_setup_mpui_io(MemoryRegion
*system_memory
,
3686 struct omap_mpu_state_s
*mpu
)
3688 memory_region_init_io(&mpu
->mpui_io_iomem
, NULL
, &omap_mpui_io_ops
, mpu
,
3689 "omap-mpui-io", 0x7fff);
3690 memory_region_add_subregion(system_memory
, OMAP_MPUI_BASE
,
3691 &mpu
->mpui_io_iomem
);
3694 /* General chip reset */
3695 static void omap1_mpu_reset(void *opaque
)
3697 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3699 omap_dma_reset(mpu
->dma
);
3700 omap_mpu_timer_reset(mpu
->timer
[0]);
3701 omap_mpu_timer_reset(mpu
->timer
[1]);
3702 omap_mpu_timer_reset(mpu
->timer
[2]);
3703 omap_wd_timer_reset(mpu
->wdt
);
3704 omap_os_timer_reset(mpu
->os_timer
);
3705 omap_lcdc_reset(mpu
->lcd
);
3706 omap_ulpd_pm_reset(mpu
);
3707 omap_pin_cfg_reset(mpu
);
3708 omap_mpui_reset(mpu
);
3709 omap_tipb_bridge_reset(mpu
->private_tipb
);
3710 omap_tipb_bridge_reset(mpu
->public_tipb
);
3711 omap_dpll_reset(mpu
->dpll
[0]);
3712 omap_dpll_reset(mpu
->dpll
[1]);
3713 omap_dpll_reset(mpu
->dpll
[2]);
3714 omap_uart_reset(mpu
->uart
[0]);
3715 omap_uart_reset(mpu
->uart
[1]);
3716 omap_uart_reset(mpu
->uart
[2]);
3717 omap_mmc_reset(mpu
->mmc
);
3718 omap_mpuio_reset(mpu
->mpuio
);
3719 omap_uwire_reset(mpu
->microwire
);
3720 omap_pwl_reset(mpu
->pwl
);
3721 omap_pwt_reset(mpu
->pwt
);
3722 omap_rtc_reset(mpu
->rtc
);
3723 omap_mcbsp_reset(mpu
->mcbsp1
);
3724 omap_mcbsp_reset(mpu
->mcbsp2
);
3725 omap_mcbsp_reset(mpu
->mcbsp3
);
3726 omap_lpg_reset(mpu
->led
[0]);
3727 omap_lpg_reset(mpu
->led
[1]);
3728 omap_clkm_reset(mpu
);
3729 cpu_reset(CPU(mpu
->cpu
));
3732 static const struct omap_map_s
{
3737 } omap15xx_dsp_mm
[] = {
3739 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
3740 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
3741 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
3742 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
3743 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
3744 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
3745 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
3746 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
3747 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
3748 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
3749 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
3750 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
3751 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
3752 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
3753 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
3754 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
3755 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
3757 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
3762 static void omap_setup_dsp_mapping(MemoryRegion
*system_memory
,
3763 const struct omap_map_s
*map
)
3767 for (; map
->phys_dsp
; map
++) {
3768 io
= g_new(MemoryRegion
, 1);
3769 memory_region_init_alias(io
, NULL
, map
->name
,
3770 system_memory
, map
->phys_mpu
, map
->size
);
3771 memory_region_add_subregion(system_memory
, map
->phys_dsp
, io
);
3775 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
3777 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3778 CPUState
*cpu
= CPU(mpu
->cpu
);
3781 cpu_interrupt(cpu
, CPU_INTERRUPT_EXITTB
);
3785 static const struct dma_irq_map omap1_dma_irq_map
[] = {
3786 { 0, OMAP_INT_DMA_CH0_6
},
3787 { 0, OMAP_INT_DMA_CH1_7
},
3788 { 0, OMAP_INT_DMA_CH2_8
},
3789 { 0, OMAP_INT_DMA_CH3
},
3790 { 0, OMAP_INT_DMA_CH4
},
3791 { 0, OMAP_INT_DMA_CH5
},
3792 { 1, OMAP_INT_1610_DMA_CH6
},
3793 { 1, OMAP_INT_1610_DMA_CH7
},
3794 { 1, OMAP_INT_1610_DMA_CH8
},
3795 { 1, OMAP_INT_1610_DMA_CH9
},
3796 { 1, OMAP_INT_1610_DMA_CH10
},
3797 { 1, OMAP_INT_1610_DMA_CH11
},
3798 { 1, OMAP_INT_1610_DMA_CH12
},
3799 { 1, OMAP_INT_1610_DMA_CH13
},
3800 { 1, OMAP_INT_1610_DMA_CH14
},
3801 { 1, OMAP_INT_1610_DMA_CH15
}
3804 /* DMA ports for OMAP1 */
3805 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
3808 return range_covers_byte(OMAP_EMIFF_BASE
, s
->sdram_size
, addr
);
3811 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
3814 return range_covers_byte(OMAP_EMIFS_BASE
, OMAP_EMIFF_BASE
- OMAP_EMIFS_BASE
,
3818 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
3821 return range_covers_byte(OMAP_IMIF_BASE
, s
->sram_size
, addr
);
3824 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
3827 return range_covers_byte(0xfffb0000, 0xffff0000 - 0xfffb0000, addr
);
3830 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
3833 return range_covers_byte(OMAP_LOCALBUS_BASE
, 0x1000000, addr
);
3836 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
3839 return range_covers_byte(0xe1010000, 0xe1020004 - 0xe1010000, addr
);
3842 struct omap_mpu_state_s
*omap310_mpu_init(MemoryRegion
*system_memory
,
3843 unsigned long sdram_size
,
3847 struct omap_mpu_state_s
*s
= g_new0(struct omap_mpu_state_s
, 1);
3848 qemu_irq dma_irqs
[6];
3850 SysBusDevice
*busdev
;
3856 s
->mpu_model
= omap310
;
3857 s
->cpu
= cpu_arm_init(core
);
3858 if (s
->cpu
== NULL
) {
3859 fprintf(stderr
, "Unable to find CPU definition\n");
3862 s
->sdram_size
= sdram_size
;
3863 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
3865 s
->wakeup
= qemu_allocate_irq(omap_mpu_wakeup
, s
, 0);
3870 /* Memory-mapped stuff */
3871 memory_region_allocate_system_memory(&s
->emiff_ram
, NULL
, "omap1.dram",
3873 memory_region_add_subregion(system_memory
, OMAP_EMIFF_BASE
, &s
->emiff_ram
);
3874 memory_region_init_ram(&s
->imif_ram
, NULL
, "omap1.sram", s
->sram_size
,
3876 vmstate_register_ram_global(&s
->imif_ram
);
3877 memory_region_add_subregion(system_memory
, OMAP_IMIF_BASE
, &s
->imif_ram
);
3879 omap_clkm_init(system_memory
, 0xfffece00, 0xe1008000, s
);
3881 s
->ih
[0] = qdev_create(NULL
, "omap-intc");
3882 qdev_prop_set_uint32(s
->ih
[0], "size", 0x100);
3883 qdev_prop_set_ptr(s
->ih
[0], "clk", omap_findclk(s
, "arminth_ck"));
3884 qdev_init_nofail(s
->ih
[0]);
3885 busdev
= SYS_BUS_DEVICE(s
->ih
[0]);
3886 sysbus_connect_irq(busdev
, 0,
3887 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_IRQ
));
3888 sysbus_connect_irq(busdev
, 1,
3889 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_FIQ
));
3890 sysbus_mmio_map(busdev
, 0, 0xfffecb00);
3891 s
->ih
[1] = qdev_create(NULL
, "omap-intc");
3892 qdev_prop_set_uint32(s
->ih
[1], "size", 0x800);
3893 qdev_prop_set_ptr(s
->ih
[1], "clk", omap_findclk(s
, "arminth_ck"));
3894 qdev_init_nofail(s
->ih
[1]);
3895 busdev
= SYS_BUS_DEVICE(s
->ih
[1]);
3896 sysbus_connect_irq(busdev
, 0,
3897 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_15XX_IH2_IRQ
));
3898 /* The second interrupt controller's FIQ output is not wired up */
3899 sysbus_mmio_map(busdev
, 0, 0xfffe0000);
3901 for (i
= 0; i
< 6; i
++) {
3902 dma_irqs
[i
] = qdev_get_gpio_in(s
->ih
[omap1_dma_irq_map
[i
].ih
],
3903 omap1_dma_irq_map
[i
].intr
);
3905 s
->dma
= omap_dma_init(0xfffed800, dma_irqs
, system_memory
,
3906 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_DMA_LCD
),
3907 s
, omap_findclk(s
, "dma_ck"), omap_dma_3_1
);
3909 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
3910 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
3911 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
3912 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
3913 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
3914 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
3916 /* Register SDRAM and SRAM DMA ports for fast transfers. */
3917 soc_dma_port_add_mem(s
->dma
, memory_region_get_ram_ptr(&s
->emiff_ram
),
3918 OMAP_EMIFF_BASE
, s
->sdram_size
);
3919 soc_dma_port_add_mem(s
->dma
, memory_region_get_ram_ptr(&s
->imif_ram
),
3920 OMAP_IMIF_BASE
, s
->sram_size
);
3922 s
->timer
[0] = omap_mpu_timer_init(system_memory
, 0xfffec500,
3923 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER1
),
3924 omap_findclk(s
, "mputim_ck"));
3925 s
->timer
[1] = omap_mpu_timer_init(system_memory
, 0xfffec600,
3926 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER2
),
3927 omap_findclk(s
, "mputim_ck"));
3928 s
->timer
[2] = omap_mpu_timer_init(system_memory
, 0xfffec700,
3929 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER3
),
3930 omap_findclk(s
, "mputim_ck"));
3932 s
->wdt
= omap_wd_timer_init(system_memory
, 0xfffec800,
3933 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_WD_TIMER
),
3934 omap_findclk(s
, "armwdt_ck"));
3936 s
->os_timer
= omap_os_timer_init(system_memory
, 0xfffb9000,
3937 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_OS_TIMER
),
3938 omap_findclk(s
, "clk32-kHz"));
3940 s
->lcd
= omap_lcdc_init(system_memory
, 0xfffec000,
3941 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_LCD_CTRL
),
3942 omap_dma_get_lcdch(s
->dma
),
3943 omap_findclk(s
, "lcd_ck"));
3945 omap_ulpd_pm_init(system_memory
, 0xfffe0800, s
);
3946 omap_pin_cfg_init(system_memory
, 0xfffe1000, s
);
3947 omap_id_init(system_memory
, s
);
3949 omap_mpui_init(system_memory
, 0xfffec900, s
);
3951 s
->private_tipb
= omap_tipb_bridge_init(system_memory
, 0xfffeca00,
3952 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_BRIDGE_PRIV
),
3953 omap_findclk(s
, "tipb_ck"));
3954 s
->public_tipb
= omap_tipb_bridge_init(system_memory
, 0xfffed300,
3955 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_BRIDGE_PUB
),
3956 omap_findclk(s
, "tipb_ck"));
3958 omap_tcmi_init(system_memory
, 0xfffecc00, s
);
3960 s
->uart
[0] = omap_uart_init(0xfffb0000,
3961 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_UART1
),
3962 omap_findclk(s
, "uart1_ck"),
3963 omap_findclk(s
, "uart1_ck"),
3964 s
->drq
[OMAP_DMA_UART1_TX
], s
->drq
[OMAP_DMA_UART1_RX
],
3967 s
->uart
[1] = omap_uart_init(0xfffb0800,
3968 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_UART2
),
3969 omap_findclk(s
, "uart2_ck"),
3970 omap_findclk(s
, "uart2_ck"),
3971 s
->drq
[OMAP_DMA_UART2_TX
], s
->drq
[OMAP_DMA_UART2_RX
],
3973 serial_hds
[0] ? serial_hds
[1] : NULL
);
3974 s
->uart
[2] = omap_uart_init(0xfffb9800,
3975 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_UART3
),
3976 omap_findclk(s
, "uart3_ck"),
3977 omap_findclk(s
, "uart3_ck"),
3978 s
->drq
[OMAP_DMA_UART3_TX
], s
->drq
[OMAP_DMA_UART3_RX
],
3980 serial_hds
[0] && serial_hds
[1] ? serial_hds
[2] : NULL
);
3982 s
->dpll
[0] = omap_dpll_init(system_memory
, 0xfffecf00,
3983 omap_findclk(s
, "dpll1"));
3984 s
->dpll
[1] = omap_dpll_init(system_memory
, 0xfffed000,
3985 omap_findclk(s
, "dpll2"));
3986 s
->dpll
[2] = omap_dpll_init(system_memory
, 0xfffed100,
3987 omap_findclk(s
, "dpll3"));
3989 dinfo
= drive_get(IF_SD
, 0, 0);
3991 fprintf(stderr
, "qemu: missing SecureDigital device\n");
3994 s
->mmc
= omap_mmc_init(0xfffb7800, system_memory
,
3995 blk_by_legacy_dinfo(dinfo
),
3996 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_OQN
),
3997 &s
->drq
[OMAP_DMA_MMC_TX
],
3998 omap_findclk(s
, "mmc_ck"));
4000 s
->mpuio
= omap_mpuio_init(system_memory
, 0xfffb5000,
4001 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_KEYBOARD
),
4002 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_MPUIO
),
4003 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
4005 s
->gpio
= qdev_create(NULL
, "omap-gpio");
4006 qdev_prop_set_int32(s
->gpio
, "mpu_model", s
->mpu_model
);
4007 qdev_prop_set_ptr(s
->gpio
, "clk", omap_findclk(s
, "arm_gpio_ck"));
4008 qdev_init_nofail(s
->gpio
);
4009 sysbus_connect_irq(SYS_BUS_DEVICE(s
->gpio
), 0,
4010 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_GPIO_BANK1
));
4011 sysbus_mmio_map(SYS_BUS_DEVICE(s
->gpio
), 0, 0xfffce000);
4013 s
->microwire
= omap_uwire_init(system_memory
, 0xfffb3000,
4014 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_uWireTX
),
4015 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_uWireRX
),
4016 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
4018 s
->pwl
= omap_pwl_init(system_memory
, 0xfffb5800,
4019 omap_findclk(s
, "armxor_ck"));
4020 s
->pwt
= omap_pwt_init(system_memory
, 0xfffb6000,
4021 omap_findclk(s
, "armxor_ck"));
4023 s
->i2c
[0] = qdev_create(NULL
, "omap_i2c");
4024 qdev_prop_set_uint8(s
->i2c
[0], "revision", 0x11);
4025 qdev_prop_set_ptr(s
->i2c
[0], "fclk", omap_findclk(s
, "mpuper_ck"));
4026 qdev_init_nofail(s
->i2c
[0]);
4027 busdev
= SYS_BUS_DEVICE(s
->i2c
[0]);
4028 sysbus_connect_irq(busdev
, 0, qdev_get_gpio_in(s
->ih
[1], OMAP_INT_I2C
));
4029 sysbus_connect_irq(busdev
, 1, s
->drq
[OMAP_DMA_I2C_TX
]);
4030 sysbus_connect_irq(busdev
, 2, s
->drq
[OMAP_DMA_I2C_RX
]);
4031 sysbus_mmio_map(busdev
, 0, 0xfffb3800);
4033 s
->rtc
= omap_rtc_init(system_memory
, 0xfffb4800,
4034 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_RTC_TIMER
),
4035 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_RTC_ALARM
),
4036 omap_findclk(s
, "clk32-kHz"));
4038 s
->mcbsp1
= omap_mcbsp_init(system_memory
, 0xfffb1800,
4039 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP1TX
),
4040 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP1RX
),
4041 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
4042 s
->mcbsp2
= omap_mcbsp_init(system_memory
, 0xfffb1000,
4043 qdev_get_gpio_in(s
->ih
[0],
4044 OMAP_INT_310_McBSP2_TX
),
4045 qdev_get_gpio_in(s
->ih
[0],
4046 OMAP_INT_310_McBSP2_RX
),
4047 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
4048 s
->mcbsp3
= omap_mcbsp_init(system_memory
, 0xfffb7000,
4049 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP3TX
),
4050 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP3RX
),
4051 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
4053 s
->led
[0] = omap_lpg_init(system_memory
,
4054 0xfffbd000, omap_findclk(s
, "clk32-kHz"));
4055 s
->led
[1] = omap_lpg_init(system_memory
,
4056 0xfffbd800, omap_findclk(s
, "clk32-kHz"));
4058 /* Register mappings not currenlty implemented:
4059 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4060 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4061 * USB W2FC fffb4000 - fffb47ff
4062 * Camera Interface fffb6800 - fffb6fff
4063 * USB Host fffba000 - fffba7ff
4064 * FAC fffba800 - fffbafff
4065 * HDQ/1-Wire fffbc000 - fffbc7ff
4066 * TIPB switches fffbc800 - fffbcfff
4067 * Mailbox fffcf000 - fffcf7ff
4068 * Local bus IF fffec100 - fffec1ff
4069 * Local bus MMU fffec200 - fffec2ff
4070 * DSP MMU fffed200 - fffed2ff
4073 omap_setup_dsp_mapping(system_memory
, omap15xx_dsp_mm
);
4074 omap_setup_mpui_io(system_memory
, s
);
4076 qemu_register_reset(omap1_mpu_reset
, s
);