2 * TI OMAP processors emulation.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu/error-report.h"
22 #include "qapi/error.h"
23 #include "qemu-common.h"
25 #include "hw/boards.h"
27 #include "hw/arm/arm.h"
28 #include "hw/arm/omap.h"
29 #include "sysemu/sysemu.h"
30 #include "hw/arm/soc_dma.h"
31 #include "sysemu/block-backend.h"
32 #include "sysemu/blockdev.h"
33 #include "qemu/range.h"
34 #include "hw/sysbus.h"
35 #include "qemu/cutils.h"
38 /* Should signal the TCMI/GPMC */
39 uint32_t omap_badwidth_read8(void *opaque
, hwaddr addr
)
44 cpu_physical_memory_read(addr
, &ret
, 1);
48 void omap_badwidth_write8(void *opaque
, hwaddr addr
,
54 cpu_physical_memory_write(addr
, &val8
, 1);
57 uint32_t omap_badwidth_read16(void *opaque
, hwaddr addr
)
62 cpu_physical_memory_read(addr
, &ret
, 2);
66 void omap_badwidth_write16(void *opaque
, hwaddr addr
,
69 uint16_t val16
= value
;
72 cpu_physical_memory_write(addr
, &val16
, 2);
75 uint32_t omap_badwidth_read32(void *opaque
, hwaddr addr
)
80 cpu_physical_memory_read(addr
, &ret
, 4);
84 void omap_badwidth_write32(void *opaque
, hwaddr addr
,
88 cpu_physical_memory_write(addr
, &value
, 4);
92 struct omap_mpu_timer_s
{
110 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
112 uint64_t distance
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) - timer
->time
;
114 if (timer
->st
&& timer
->enable
&& timer
->rate
)
115 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
116 timer
->rate
, NANOSECONDS_PER_SECOND
);
121 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
123 timer
->val
= omap_timer_read(timer
);
124 timer
->time
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
127 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
131 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
132 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
133 expires
= muldiv64((uint64_t) timer
->val
<< (timer
->ptv
+ 1),
134 NANOSECONDS_PER_SECOND
, timer
->rate
);
136 /* If timer expiry would be sooner than in about 1 ms and
137 * auto-reload isn't set, then fire immediately. This is a hack
138 * to make systems like PalmOS run in acceptable time. PalmOS
139 * sets the interval to a very low value and polls the status bit
140 * in a busy loop when it wants to sleep just a couple of CPU
142 if (expires
> (NANOSECONDS_PER_SECOND
>> 10) || timer
->ar
) {
143 timer_mod(timer
->timer
, timer
->time
+ expires
);
145 qemu_bh_schedule(timer
->tick
);
148 timer_del(timer
->timer
);
151 static void omap_timer_fire(void *opaque
)
153 struct omap_mpu_timer_s
*timer
= opaque
;
161 /* Edge-triggered irq */
162 qemu_irq_pulse(timer
->irq
);
165 static void omap_timer_tick(void *opaque
)
167 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
169 omap_timer_sync(timer
);
170 omap_timer_fire(timer
);
171 omap_timer_update(timer
);
174 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
176 struct omap_mpu_timer_s
*timer
= (struct omap_mpu_timer_s
*) opaque
;
178 omap_timer_sync(timer
);
179 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
180 omap_timer_update(timer
);
183 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
185 omap_clk_adduser(timer
->clk
,
186 qemu_allocate_irq(omap_timer_clk_update
, timer
, 0));
187 timer
->rate
= omap_clk_getrate(timer
->clk
);
190 static uint64_t omap_mpu_timer_read(void *opaque
, hwaddr addr
,
193 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
196 return omap_badwidth_read32(opaque
, addr
);
200 case 0x00: /* CNTL_TIMER */
201 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
203 case 0x04: /* LOAD_TIM */
206 case 0x08: /* READ_TIM */
207 return omap_timer_read(s
);
214 static void omap_mpu_timer_write(void *opaque
, hwaddr addr
,
215 uint64_t value
, unsigned size
)
217 struct omap_mpu_timer_s
*s
= (struct omap_mpu_timer_s
*) opaque
;
220 omap_badwidth_write32(opaque
, addr
, value
);
225 case 0x00: /* CNTL_TIMER */
227 s
->enable
= (value
>> 5) & 1;
228 s
->ptv
= (value
>> 2) & 7;
229 s
->ar
= (value
>> 1) & 1;
231 omap_timer_update(s
);
234 case 0x04: /* LOAD_TIM */
235 s
->reset_val
= value
;
238 case 0x08: /* READ_TIM */
247 static const MemoryRegionOps omap_mpu_timer_ops
= {
248 .read
= omap_mpu_timer_read
,
249 .write
= omap_mpu_timer_write
,
250 .endianness
= DEVICE_LITTLE_ENDIAN
,
253 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
257 s
->reset_val
= 31337;
265 static struct omap_mpu_timer_s
*omap_mpu_timer_init(MemoryRegion
*system_memory
,
267 qemu_irq irq
, omap_clk clk
)
269 struct omap_mpu_timer_s
*s
= g_new0(struct omap_mpu_timer_s
, 1);
273 s
->timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, s
);
274 s
->tick
= qemu_bh_new(omap_timer_fire
, s
);
275 omap_mpu_timer_reset(s
);
276 omap_timer_clk_setup(s
);
278 memory_region_init_io(&s
->iomem
, NULL
, &omap_mpu_timer_ops
, s
,
279 "omap-mpu-timer", 0x100);
281 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
287 struct omap_watchdog_timer_s
{
288 struct omap_mpu_timer_s timer
;
296 static uint64_t omap_wd_timer_read(void *opaque
, hwaddr addr
,
299 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
302 return omap_badwidth_read16(opaque
, addr
);
306 case 0x00: /* CNTL_TIMER */
307 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
308 (s
->timer
.st
<< 7) | (s
->free
<< 1);
310 case 0x04: /* READ_TIMER */
311 return omap_timer_read(&s
->timer
);
313 case 0x08: /* TIMER_MODE */
314 return s
->mode
<< 15;
321 static void omap_wd_timer_write(void *opaque
, hwaddr addr
,
322 uint64_t value
, unsigned size
)
324 struct omap_watchdog_timer_s
*s
= (struct omap_watchdog_timer_s
*) opaque
;
327 omap_badwidth_write16(opaque
, addr
, value
);
332 case 0x00: /* CNTL_TIMER */
333 omap_timer_sync(&s
->timer
);
334 s
->timer
.ptv
= (value
>> 9) & 7;
335 s
->timer
.ar
= (value
>> 8) & 1;
336 s
->timer
.st
= (value
>> 7) & 1;
337 s
->free
= (value
>> 1) & 1;
338 omap_timer_update(&s
->timer
);
341 case 0x04: /* LOAD_TIMER */
342 s
->timer
.reset_val
= value
& 0xffff;
345 case 0x08: /* TIMER_MODE */
346 if (!s
->mode
&& ((value
>> 15) & 1))
347 omap_clk_get(s
->timer
.clk
);
348 s
->mode
|= (value
>> 15) & 1;
349 if (s
->last_wr
== 0xf5) {
350 if ((value
& 0xff) == 0xa0) {
353 omap_clk_put(s
->timer
.clk
);
356 /* XXX: on T|E hardware somehow this has no effect,
357 * on Zire 71 it works as specified. */
359 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
362 s
->last_wr
= value
& 0xff;
370 static const MemoryRegionOps omap_wd_timer_ops
= {
371 .read
= omap_wd_timer_read
,
372 .write
= omap_wd_timer_write
,
373 .endianness
= DEVICE_NATIVE_ENDIAN
,
376 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
378 timer_del(s
->timer
.timer
);
380 omap_clk_get(s
->timer
.clk
);
386 s
->timer
.reset_val
= 0xffff;
391 omap_timer_update(&s
->timer
);
394 static struct omap_watchdog_timer_s
*omap_wd_timer_init(MemoryRegion
*memory
,
396 qemu_irq irq
, omap_clk clk
)
398 struct omap_watchdog_timer_s
*s
= g_new0(struct omap_watchdog_timer_s
, 1);
402 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, &s
->timer
);
403 omap_wd_timer_reset(s
);
404 omap_timer_clk_setup(&s
->timer
);
406 memory_region_init_io(&s
->iomem
, NULL
, &omap_wd_timer_ops
, s
,
407 "omap-wd-timer", 0x100);
408 memory_region_add_subregion(memory
, base
, &s
->iomem
);
414 struct omap_32khz_timer_s
{
415 struct omap_mpu_timer_s timer
;
419 static uint64_t omap_os_timer_read(void *opaque
, hwaddr addr
,
422 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
423 int offset
= addr
& OMAP_MPUI_REG_MASK
;
426 return omap_badwidth_read32(opaque
, addr
);
431 return s
->timer
.reset_val
;
434 return omap_timer_read(&s
->timer
);
437 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
446 static void omap_os_timer_write(void *opaque
, hwaddr addr
,
447 uint64_t value
, unsigned size
)
449 struct omap_32khz_timer_s
*s
= (struct omap_32khz_timer_s
*) opaque
;
450 int offset
= addr
& OMAP_MPUI_REG_MASK
;
453 omap_badwidth_write32(opaque
, addr
, value
);
459 s
->timer
.reset_val
= value
& 0x00ffffff;
467 s
->timer
.ar
= (value
>> 3) & 1;
468 s
->timer
.it_ena
= (value
>> 2) & 1;
469 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
470 omap_timer_sync(&s
->timer
);
471 s
->timer
.enable
= value
& 1;
472 s
->timer
.st
= value
& 1;
473 omap_timer_update(&s
->timer
);
482 static const MemoryRegionOps omap_os_timer_ops
= {
483 .read
= omap_os_timer_read
,
484 .write
= omap_os_timer_write
,
485 .endianness
= DEVICE_NATIVE_ENDIAN
,
488 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
490 timer_del(s
->timer
.timer
);
493 s
->timer
.reset_val
= 0x00ffffff;
500 static struct omap_32khz_timer_s
*omap_os_timer_init(MemoryRegion
*memory
,
502 qemu_irq irq
, omap_clk clk
)
504 struct omap_32khz_timer_s
*s
= g_new0(struct omap_32khz_timer_s
, 1);
508 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, &s
->timer
);
509 omap_os_timer_reset(s
);
510 omap_timer_clk_setup(&s
->timer
);
512 memory_region_init_io(&s
->iomem
, NULL
, &omap_os_timer_ops
, s
,
513 "omap-os-timer", 0x800);
514 memory_region_add_subregion(memory
, base
, &s
->iomem
);
519 /* Ultra Low-Power Device Module */
520 static uint64_t omap_ulpd_pm_read(void *opaque
, hwaddr addr
,
523 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
527 return omap_badwidth_read16(opaque
, addr
);
531 case 0x14: /* IT_STATUS */
532 ret
= s
->ulpd_pm_regs
[addr
>> 2];
533 s
->ulpd_pm_regs
[addr
>> 2] = 0;
534 qemu_irq_lower(qdev_get_gpio_in(s
->ih
[1], OMAP_INT_GAUGE_32K
));
537 case 0x18: /* Reserved */
538 case 0x1c: /* Reserved */
539 case 0x20: /* Reserved */
540 case 0x28: /* Reserved */
541 case 0x2c: /* Reserved */
544 case 0x00: /* COUNTER_32_LSB */
545 case 0x04: /* COUNTER_32_MSB */
546 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
547 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
548 case 0x10: /* GAUGING_CTRL */
549 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
550 case 0x30: /* CLOCK_CTRL */
551 case 0x34: /* SOFT_REQ */
552 case 0x38: /* COUNTER_32_FIQ */
553 case 0x3c: /* DPLL_CTRL */
554 case 0x40: /* STATUS_REQ */
555 /* XXX: check clk::usecount state for every clock */
556 case 0x48: /* LOCL_TIME */
557 case 0x4c: /* APLL_CTRL */
558 case 0x50: /* POWER_CTRL */
559 return s
->ulpd_pm_regs
[addr
>> 2];
566 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
567 uint16_t diff
, uint16_t value
)
569 if (diff
& (1 << 4)) /* USB_MCLK_EN */
570 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
571 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
572 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
575 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
576 uint16_t diff
, uint16_t value
)
578 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
579 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
580 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
581 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
582 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
583 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
584 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
585 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
588 static void omap_ulpd_pm_write(void *opaque
, hwaddr addr
,
589 uint64_t value
, unsigned size
)
591 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
594 static const int bypass_div
[4] = { 1, 2, 4, 4 };
598 omap_badwidth_write16(opaque
, addr
, value
);
603 case 0x00: /* COUNTER_32_LSB */
604 case 0x04: /* COUNTER_32_MSB */
605 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
606 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
607 case 0x14: /* IT_STATUS */
608 case 0x40: /* STATUS_REQ */
612 case 0x10: /* GAUGING_CTRL */
613 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
614 if ((s
->ulpd_pm_regs
[addr
>> 2] ^ value
) & 1) {
615 now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
618 s
->ulpd_gauge_start
= now
;
620 now
-= s
->ulpd_gauge_start
;
623 ticks
= muldiv64(now
, 32768, NANOSECONDS_PER_SECOND
);
624 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
625 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
626 if (ticks
>> 32) /* OVERFLOW_32K */
627 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
629 /* High frequency ticks */
630 ticks
= muldiv64(now
, 12000000, NANOSECONDS_PER_SECOND
);
631 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
632 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
633 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
634 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
636 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
637 qemu_irq_raise(qdev_get_gpio_in(s
->ih
[1], OMAP_INT_GAUGE_32K
));
640 s
->ulpd_pm_regs
[addr
>> 2] = value
;
643 case 0x18: /* Reserved */
644 case 0x1c: /* Reserved */
645 case 0x20: /* Reserved */
646 case 0x28: /* Reserved */
647 case 0x2c: /* Reserved */
650 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
651 case 0x38: /* COUNTER_32_FIQ */
652 case 0x48: /* LOCL_TIME */
653 case 0x50: /* POWER_CTRL */
654 s
->ulpd_pm_regs
[addr
>> 2] = value
;
657 case 0x30: /* CLOCK_CTRL */
658 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
659 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x3f;
660 omap_ulpd_clk_update(s
, diff
, value
);
663 case 0x34: /* SOFT_REQ */
664 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
665 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x1f;
666 omap_ulpd_req_update(s
, diff
, value
);
669 case 0x3c: /* DPLL_CTRL */
670 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
671 * omitted altogether, probably a typo. */
672 /* This register has identical semantics with DPLL(1:3) control
673 * registers, see omap_dpll_write() */
674 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
675 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x2fff;
676 if (diff
& (0x3ff << 2)) {
677 if (value
& (1 << 4)) { /* PLL_ENABLE */
678 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
679 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
681 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
684 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
687 /* Enter the desired mode. */
688 s
->ulpd_pm_regs
[addr
>> 2] =
689 (s
->ulpd_pm_regs
[addr
>> 2] & 0xfffe) |
690 ((s
->ulpd_pm_regs
[addr
>> 2] >> 4) & 1);
692 /* Act as if the lock is restored. */
693 s
->ulpd_pm_regs
[addr
>> 2] |= 2;
696 case 0x4c: /* APLL_CTRL */
697 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
698 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0xf;
699 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
700 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
701 (value
& (1 << 0)) ? "apll" : "dpll4"));
709 static const MemoryRegionOps omap_ulpd_pm_ops
= {
710 .read
= omap_ulpd_pm_read
,
711 .write
= omap_ulpd_pm_write
,
712 .endianness
= DEVICE_NATIVE_ENDIAN
,
715 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
717 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
718 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
719 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
720 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
721 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
722 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
723 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
724 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
725 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
726 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
727 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
728 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
729 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
730 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
731 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
732 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
733 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
734 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
735 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
736 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
737 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
738 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
739 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
742 static void omap_ulpd_pm_init(MemoryRegion
*system_memory
,
744 struct omap_mpu_state_s
*mpu
)
746 memory_region_init_io(&mpu
->ulpd_pm_iomem
, NULL
, &omap_ulpd_pm_ops
, mpu
,
747 "omap-ulpd-pm", 0x800);
748 memory_region_add_subregion(system_memory
, base
, &mpu
->ulpd_pm_iomem
);
749 omap_ulpd_pm_reset(mpu
);
752 /* OMAP Pin Configuration */
753 static uint64_t omap_pin_cfg_read(void *opaque
, hwaddr addr
,
756 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
759 return omap_badwidth_read32(opaque
, addr
);
763 case 0x00: /* FUNC_MUX_CTRL_0 */
764 case 0x04: /* FUNC_MUX_CTRL_1 */
765 case 0x08: /* FUNC_MUX_CTRL_2 */
766 return s
->func_mux_ctrl
[addr
>> 2];
768 case 0x0c: /* COMP_MODE_CTRL_0 */
769 return s
->comp_mode_ctrl
[0];
771 case 0x10: /* FUNC_MUX_CTRL_3 */
772 case 0x14: /* FUNC_MUX_CTRL_4 */
773 case 0x18: /* FUNC_MUX_CTRL_5 */
774 case 0x1c: /* FUNC_MUX_CTRL_6 */
775 case 0x20: /* FUNC_MUX_CTRL_7 */
776 case 0x24: /* FUNC_MUX_CTRL_8 */
777 case 0x28: /* FUNC_MUX_CTRL_9 */
778 case 0x2c: /* FUNC_MUX_CTRL_A */
779 case 0x30: /* FUNC_MUX_CTRL_B */
780 case 0x34: /* FUNC_MUX_CTRL_C */
781 case 0x38: /* FUNC_MUX_CTRL_D */
782 return s
->func_mux_ctrl
[(addr
>> 2) - 1];
784 case 0x40: /* PULL_DWN_CTRL_0 */
785 case 0x44: /* PULL_DWN_CTRL_1 */
786 case 0x48: /* PULL_DWN_CTRL_2 */
787 case 0x4c: /* PULL_DWN_CTRL_3 */
788 return s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2];
790 case 0x50: /* GATE_INH_CTRL_0 */
791 return s
->gate_inh_ctrl
[0];
793 case 0x60: /* VOLTAGE_CTRL_0 */
794 return s
->voltage_ctrl
[0];
796 case 0x70: /* TEST_DBG_CTRL_0 */
797 return s
->test_dbg_ctrl
[0];
799 case 0x80: /* MOD_CONF_CTRL_0 */
800 return s
->mod_conf_ctrl
[0];
807 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
808 uint32_t diff
, uint32_t value
)
811 if (diff
& (1 << 9)) /* BLUETOOTH */
812 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
814 if (diff
& (1 << 7)) /* USB.CLKO */
815 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
820 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
821 uint32_t diff
, uint32_t value
)
824 if (diff
& (1U << 31)) {
825 /* MCBSP3_CLK_HIZ_DI */
826 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"), (value
>> 31) & 1);
828 if (diff
& (1 << 1)) {
830 omap_clk_onoff(omap_findclk(s
, "clk32k_out"), (~value
>> 1) & 1);
835 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
836 uint32_t diff
, uint32_t value
)
838 if (diff
& (1U << 31)) {
839 /* CONF_MOD_UART3_CLK_MODE_R */
840 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
841 omap_findclk(s
, ((value
>> 31) & 1) ?
842 "ck_48m" : "armper_ck"));
844 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
845 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
846 omap_findclk(s
, ((value
>> 30) & 1) ?
847 "ck_48m" : "armper_ck"));
848 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
849 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
850 omap_findclk(s
, ((value
>> 29) & 1) ?
851 "ck_48m" : "armper_ck"));
852 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
853 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
854 omap_findclk(s
, ((value
>> 23) & 1) ?
855 "ck_48m" : "armper_ck"));
856 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
857 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
858 omap_findclk(s
, ((value
>> 12) & 1) ?
859 "ck_48m" : "armper_ck"));
860 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
861 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
864 static void omap_pin_cfg_write(void *opaque
, hwaddr addr
,
865 uint64_t value
, unsigned size
)
867 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
871 omap_badwidth_write32(opaque
, addr
, value
);
876 case 0x00: /* FUNC_MUX_CTRL_0 */
877 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
878 s
->func_mux_ctrl
[addr
>> 2] = value
;
879 omap_pin_funcmux0_update(s
, diff
, value
);
882 case 0x04: /* FUNC_MUX_CTRL_1 */
883 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
884 s
->func_mux_ctrl
[addr
>> 2] = value
;
885 omap_pin_funcmux1_update(s
, diff
, value
);
888 case 0x08: /* FUNC_MUX_CTRL_2 */
889 s
->func_mux_ctrl
[addr
>> 2] = value
;
892 case 0x0c: /* COMP_MODE_CTRL_0 */
893 s
->comp_mode_ctrl
[0] = value
;
894 s
->compat1509
= (value
!= 0x0000eaef);
895 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
896 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
899 case 0x10: /* FUNC_MUX_CTRL_3 */
900 case 0x14: /* FUNC_MUX_CTRL_4 */
901 case 0x18: /* FUNC_MUX_CTRL_5 */
902 case 0x1c: /* FUNC_MUX_CTRL_6 */
903 case 0x20: /* FUNC_MUX_CTRL_7 */
904 case 0x24: /* FUNC_MUX_CTRL_8 */
905 case 0x28: /* FUNC_MUX_CTRL_9 */
906 case 0x2c: /* FUNC_MUX_CTRL_A */
907 case 0x30: /* FUNC_MUX_CTRL_B */
908 case 0x34: /* FUNC_MUX_CTRL_C */
909 case 0x38: /* FUNC_MUX_CTRL_D */
910 s
->func_mux_ctrl
[(addr
>> 2) - 1] = value
;
913 case 0x40: /* PULL_DWN_CTRL_0 */
914 case 0x44: /* PULL_DWN_CTRL_1 */
915 case 0x48: /* PULL_DWN_CTRL_2 */
916 case 0x4c: /* PULL_DWN_CTRL_3 */
917 s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2] = value
;
920 case 0x50: /* GATE_INH_CTRL_0 */
921 s
->gate_inh_ctrl
[0] = value
;
924 case 0x60: /* VOLTAGE_CTRL_0 */
925 s
->voltage_ctrl
[0] = value
;
928 case 0x70: /* TEST_DBG_CTRL_0 */
929 s
->test_dbg_ctrl
[0] = value
;
932 case 0x80: /* MOD_CONF_CTRL_0 */
933 diff
= s
->mod_conf_ctrl
[0] ^ value
;
934 s
->mod_conf_ctrl
[0] = value
;
935 omap_pin_modconf1_update(s
, diff
, value
);
943 static const MemoryRegionOps omap_pin_cfg_ops
= {
944 .read
= omap_pin_cfg_read
,
945 .write
= omap_pin_cfg_write
,
946 .endianness
= DEVICE_NATIVE_ENDIAN
,
949 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
951 /* Start in Compatibility Mode. */
953 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
954 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
955 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
956 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
957 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
958 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
959 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
960 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
961 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
962 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
965 static void omap_pin_cfg_init(MemoryRegion
*system_memory
,
967 struct omap_mpu_state_s
*mpu
)
969 memory_region_init_io(&mpu
->pin_cfg_iomem
, NULL
, &omap_pin_cfg_ops
, mpu
,
970 "omap-pin-cfg", 0x800);
971 memory_region_add_subregion(system_memory
, base
, &mpu
->pin_cfg_iomem
);
972 omap_pin_cfg_reset(mpu
);
975 /* Device Identification, Die Identification */
976 static uint64_t omap_id_read(void *opaque
, hwaddr addr
,
979 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
982 return omap_badwidth_read32(opaque
, addr
);
986 case 0xfffe1800: /* DIE_ID_LSB */
988 case 0xfffe1804: /* DIE_ID_MSB */
991 case 0xfffe2000: /* PRODUCT_ID_LSB */
993 case 0xfffe2004: /* PRODUCT_ID_MSB */
996 case 0xfffed400: /* JTAG_ID_LSB */
997 switch (s
->mpu_model
) {
1003 hw_error("%s: bad mpu model\n", __func__
);
1007 case 0xfffed404: /* JTAG_ID_MSB */
1008 switch (s
->mpu_model
) {
1014 hw_error("%s: bad mpu model\n", __func__
);
1023 static void omap_id_write(void *opaque
, hwaddr addr
,
1024 uint64_t value
, unsigned size
)
1027 omap_badwidth_write32(opaque
, addr
, value
);
1034 static const MemoryRegionOps omap_id_ops
= {
1035 .read
= omap_id_read
,
1036 .write
= omap_id_write
,
1037 .endianness
= DEVICE_NATIVE_ENDIAN
,
1040 static void omap_id_init(MemoryRegion
*memory
, struct omap_mpu_state_s
*mpu
)
1042 memory_region_init_io(&mpu
->id_iomem
, NULL
, &omap_id_ops
, mpu
,
1043 "omap-id", 0x100000000ULL
);
1044 memory_region_init_alias(&mpu
->id_iomem_e18
, NULL
, "omap-id-e18", &mpu
->id_iomem
,
1046 memory_region_add_subregion(memory
, 0xfffe1800, &mpu
->id_iomem_e18
);
1047 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-ed4", &mpu
->id_iomem
,
1049 memory_region_add_subregion(memory
, 0xfffed400, &mpu
->id_iomem_ed4
);
1050 if (!cpu_is_omap15xx(mpu
)) {
1051 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-e20",
1052 &mpu
->id_iomem
, 0xfffe2000, 0x800);
1053 memory_region_add_subregion(memory
, 0xfffe2000, &mpu
->id_iomem_e20
);
1057 /* MPUI Control (Dummy) */
1058 static uint64_t omap_mpui_read(void *opaque
, hwaddr addr
,
1061 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1064 return omap_badwidth_read32(opaque
, addr
);
1068 case 0x00: /* CTRL */
1069 return s
->mpui_ctrl
;
1070 case 0x04: /* DEBUG_ADDR */
1072 case 0x08: /* DEBUG_DATA */
1074 case 0x0c: /* DEBUG_FLAG */
1076 case 0x10: /* STATUS */
1079 /* Not in OMAP310 */
1080 case 0x14: /* DSP_STATUS */
1081 case 0x18: /* DSP_BOOT_CONFIG */
1083 case 0x1c: /* DSP_MPUI_CONFIG */
1091 static void omap_mpui_write(void *opaque
, hwaddr addr
,
1092 uint64_t value
, unsigned size
)
1094 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1097 omap_badwidth_write32(opaque
, addr
, value
);
1102 case 0x00: /* CTRL */
1103 s
->mpui_ctrl
= value
& 0x007fffff;
1106 case 0x04: /* DEBUG_ADDR */
1107 case 0x08: /* DEBUG_DATA */
1108 case 0x0c: /* DEBUG_FLAG */
1109 case 0x10: /* STATUS */
1110 /* Not in OMAP310 */
1111 case 0x14: /* DSP_STATUS */
1114 case 0x18: /* DSP_BOOT_CONFIG */
1115 case 0x1c: /* DSP_MPUI_CONFIG */
1123 static const MemoryRegionOps omap_mpui_ops
= {
1124 .read
= omap_mpui_read
,
1125 .write
= omap_mpui_write
,
1126 .endianness
= DEVICE_NATIVE_ENDIAN
,
1129 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1131 s
->mpui_ctrl
= 0x0003ff1b;
1134 static void omap_mpui_init(MemoryRegion
*memory
, hwaddr base
,
1135 struct omap_mpu_state_s
*mpu
)
1137 memory_region_init_io(&mpu
->mpui_iomem
, NULL
, &omap_mpui_ops
, mpu
,
1138 "omap-mpui", 0x100);
1139 memory_region_add_subregion(memory
, base
, &mpu
->mpui_iomem
);
1141 omap_mpui_reset(mpu
);
1145 struct omap_tipb_bridge_s
{
1153 uint16_t enh_control
;
1156 static uint64_t omap_tipb_bridge_read(void *opaque
, hwaddr addr
,
1159 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1162 return omap_badwidth_read16(opaque
, addr
);
1166 case 0x00: /* TIPB_CNTL */
1168 case 0x04: /* TIPB_BUS_ALLOC */
1170 case 0x08: /* MPU_TIPB_CNTL */
1172 case 0x0c: /* ENHANCED_TIPB_CNTL */
1173 return s
->enh_control
;
1174 case 0x10: /* ADDRESS_DBG */
1175 case 0x14: /* DATA_DEBUG_LOW */
1176 case 0x18: /* DATA_DEBUG_HIGH */
1178 case 0x1c: /* DEBUG_CNTR_SIG */
1186 static void omap_tipb_bridge_write(void *opaque
, hwaddr addr
,
1187 uint64_t value
, unsigned size
)
1189 struct omap_tipb_bridge_s
*s
= (struct omap_tipb_bridge_s
*) opaque
;
1192 omap_badwidth_write16(opaque
, addr
, value
);
1197 case 0x00: /* TIPB_CNTL */
1198 s
->control
= value
& 0xffff;
1201 case 0x04: /* TIPB_BUS_ALLOC */
1202 s
->alloc
= value
& 0x003f;
1205 case 0x08: /* MPU_TIPB_CNTL */
1206 s
->buffer
= value
& 0x0003;
1209 case 0x0c: /* ENHANCED_TIPB_CNTL */
1210 s
->width_intr
= !(value
& 2);
1211 s
->enh_control
= value
& 0x000f;
1214 case 0x10: /* ADDRESS_DBG */
1215 case 0x14: /* DATA_DEBUG_LOW */
1216 case 0x18: /* DATA_DEBUG_HIGH */
1217 case 0x1c: /* DEBUG_CNTR_SIG */
1226 static const MemoryRegionOps omap_tipb_bridge_ops
= {
1227 .read
= omap_tipb_bridge_read
,
1228 .write
= omap_tipb_bridge_write
,
1229 .endianness
= DEVICE_NATIVE_ENDIAN
,
1232 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1234 s
->control
= 0xffff;
1237 s
->enh_control
= 0x000f;
1240 static struct omap_tipb_bridge_s
*omap_tipb_bridge_init(
1241 MemoryRegion
*memory
, hwaddr base
,
1242 qemu_irq abort_irq
, omap_clk clk
)
1244 struct omap_tipb_bridge_s
*s
= g_new0(struct omap_tipb_bridge_s
, 1);
1246 s
->abort
= abort_irq
;
1247 omap_tipb_bridge_reset(s
);
1249 memory_region_init_io(&s
->iomem
, NULL
, &omap_tipb_bridge_ops
, s
,
1250 "omap-tipb-bridge", 0x100);
1251 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1256 /* Dummy Traffic Controller's Memory Interface */
1257 static uint64_t omap_tcmi_read(void *opaque
, hwaddr addr
,
1260 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1264 return omap_badwidth_read32(opaque
, addr
);
1268 case 0x00: /* IMIF_PRIO */
1269 case 0x04: /* EMIFS_PRIO */
1270 case 0x08: /* EMIFF_PRIO */
1271 case 0x0c: /* EMIFS_CONFIG */
1272 case 0x10: /* EMIFS_CS0_CONFIG */
1273 case 0x14: /* EMIFS_CS1_CONFIG */
1274 case 0x18: /* EMIFS_CS2_CONFIG */
1275 case 0x1c: /* EMIFS_CS3_CONFIG */
1276 case 0x24: /* EMIFF_MRS */
1277 case 0x28: /* TIMEOUT1 */
1278 case 0x2c: /* TIMEOUT2 */
1279 case 0x30: /* TIMEOUT3 */
1280 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1281 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1282 return s
->tcmi_regs
[addr
>> 2];
1284 case 0x20: /* EMIFF_SDRAM_CONFIG */
1285 ret
= s
->tcmi_regs
[addr
>> 2];
1286 s
->tcmi_regs
[addr
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1287 /* XXX: We can try using the VGA_DIRTY flag for this */
1295 static void omap_tcmi_write(void *opaque
, hwaddr addr
,
1296 uint64_t value
, unsigned size
)
1298 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1301 omap_badwidth_write32(opaque
, addr
, value
);
1306 case 0x00: /* IMIF_PRIO */
1307 case 0x04: /* EMIFS_PRIO */
1308 case 0x08: /* EMIFF_PRIO */
1309 case 0x10: /* EMIFS_CS0_CONFIG */
1310 case 0x14: /* EMIFS_CS1_CONFIG */
1311 case 0x18: /* EMIFS_CS2_CONFIG */
1312 case 0x1c: /* EMIFS_CS3_CONFIG */
1313 case 0x20: /* EMIFF_SDRAM_CONFIG */
1314 case 0x24: /* EMIFF_MRS */
1315 case 0x28: /* TIMEOUT1 */
1316 case 0x2c: /* TIMEOUT2 */
1317 case 0x30: /* TIMEOUT3 */
1318 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1319 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1320 s
->tcmi_regs
[addr
>> 2] = value
;
1322 case 0x0c: /* EMIFS_CONFIG */
1323 s
->tcmi_regs
[addr
>> 2] = (value
& 0xf) | (1 << 4);
1331 static const MemoryRegionOps omap_tcmi_ops
= {
1332 .read
= omap_tcmi_read
,
1333 .write
= omap_tcmi_write
,
1334 .endianness
= DEVICE_NATIVE_ENDIAN
,
1337 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1339 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1340 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1341 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1342 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1343 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1344 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1345 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1346 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1347 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1348 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1349 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1350 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1351 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1352 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1353 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1356 static void omap_tcmi_init(MemoryRegion
*memory
, hwaddr base
,
1357 struct omap_mpu_state_s
*mpu
)
1359 memory_region_init_io(&mpu
->tcmi_iomem
, NULL
, &omap_tcmi_ops
, mpu
,
1360 "omap-tcmi", 0x100);
1361 memory_region_add_subregion(memory
, base
, &mpu
->tcmi_iomem
);
1362 omap_tcmi_reset(mpu
);
1365 /* Digital phase-locked loops control */
1372 static uint64_t omap_dpll_read(void *opaque
, hwaddr addr
,
1375 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1378 return omap_badwidth_read16(opaque
, addr
);
1381 if (addr
== 0x00) /* CTL_REG */
1388 static void omap_dpll_write(void *opaque
, hwaddr addr
,
1389 uint64_t value
, unsigned size
)
1391 struct dpll_ctl_s
*s
= (struct dpll_ctl_s
*) opaque
;
1393 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1397 omap_badwidth_write16(opaque
, addr
, value
);
1401 if (addr
== 0x00) { /* CTL_REG */
1402 /* See omap_ulpd_pm_write() too */
1403 diff
= s
->mode
& value
;
1404 s
->mode
= value
& 0x2fff;
1405 if (diff
& (0x3ff << 2)) {
1406 if (value
& (1 << 4)) { /* PLL_ENABLE */
1407 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1408 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1410 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1413 omap_clk_setrate(s
->dpll
, div
, mult
);
1416 /* Enter the desired mode. */
1417 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1419 /* Act as if the lock is restored. */
1426 static const MemoryRegionOps omap_dpll_ops
= {
1427 .read
= omap_dpll_read
,
1428 .write
= omap_dpll_write
,
1429 .endianness
= DEVICE_NATIVE_ENDIAN
,
1432 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1435 omap_clk_setrate(s
->dpll
, 1, 1);
1438 static struct dpll_ctl_s
*omap_dpll_init(MemoryRegion
*memory
,
1439 hwaddr base
, omap_clk clk
)
1441 struct dpll_ctl_s
*s
= g_malloc0(sizeof(*s
));
1442 memory_region_init_io(&s
->iomem
, NULL
, &omap_dpll_ops
, s
, "omap-dpll", 0x100);
1447 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1451 /* MPU Clock/Reset/Power Mode Control */
1452 static uint64_t omap_clkm_read(void *opaque
, hwaddr addr
,
1455 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1458 return omap_badwidth_read16(opaque
, addr
);
1462 case 0x00: /* ARM_CKCTL */
1463 return s
->clkm
.arm_ckctl
;
1465 case 0x04: /* ARM_IDLECT1 */
1466 return s
->clkm
.arm_idlect1
;
1468 case 0x08: /* ARM_IDLECT2 */
1469 return s
->clkm
.arm_idlect2
;
1471 case 0x0c: /* ARM_EWUPCT */
1472 return s
->clkm
.arm_ewupct
;
1474 case 0x10: /* ARM_RSTCT1 */
1475 return s
->clkm
.arm_rstct1
;
1477 case 0x14: /* ARM_RSTCT2 */
1478 return s
->clkm
.arm_rstct2
;
1480 case 0x18: /* ARM_SYSST */
1481 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
1483 case 0x1c: /* ARM_CKOUT1 */
1484 return s
->clkm
.arm_ckout1
;
1486 case 0x20: /* ARM_CKOUT2 */
1494 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
1495 uint16_t diff
, uint16_t value
)
1499 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
1500 if (value
& (1 << 14))
1503 clk
= omap_findclk(s
, "arminth_ck");
1504 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1507 if (diff
& (1 << 12)) { /* ARM_TIMXO */
1508 clk
= omap_findclk(s
, "armtim_ck");
1509 if (value
& (1 << 12))
1510 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
1512 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1515 if (diff
& (3 << 10)) { /* DSPMMUDIV */
1516 clk
= omap_findclk(s
, "dspmmu_ck");
1517 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
1519 if (diff
& (3 << 8)) { /* TCDIV */
1520 clk
= omap_findclk(s
, "tc_ck");
1521 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
1523 if (diff
& (3 << 6)) { /* DSPDIV */
1524 clk
= omap_findclk(s
, "dsp_ck");
1525 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
1527 if (diff
& (3 << 4)) { /* ARMDIV */
1528 clk
= omap_findclk(s
, "arm_ck");
1529 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
1531 if (diff
& (3 << 2)) { /* LCDDIV */
1532 clk
= omap_findclk(s
, "lcd_ck");
1533 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
1535 if (diff
& (3 << 0)) { /* PERDIV */
1536 clk
= omap_findclk(s
, "armper_ck");
1537 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
1541 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
1542 uint16_t diff
, uint16_t value
)
1546 if (value
& (1 << 11)) { /* SETARM_IDLE */
1547 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
1549 if (!(value
& (1 << 10))) { /* WKUP_MODE */
1550 /* XXX: disable wakeup from IRQ */
1551 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
1554 #define SET_CANIDLE(clock, bit) \
1555 if (diff & (1 << bit)) { \
1556 clk = omap_findclk(s, clock); \
1557 omap_clk_canidle(clk, (value >> bit) & 1); \
1559 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1560 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1561 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1562 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1563 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1564 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1565 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1566 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1567 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1568 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1569 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1570 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1571 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1572 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1575 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
1576 uint16_t diff
, uint16_t value
)
1580 #define SET_ONOFF(clock, bit) \
1581 if (diff & (1 << bit)) { \
1582 clk = omap_findclk(s, clock); \
1583 omap_clk_onoff(clk, (value >> bit) & 1); \
1585 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1586 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1587 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1588 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1589 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1590 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1591 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1592 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1593 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1594 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1595 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1598 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
1599 uint16_t diff
, uint16_t value
)
1603 if (diff
& (3 << 4)) { /* TCLKOUT */
1604 clk
= omap_findclk(s
, "tclk_out");
1605 switch ((value
>> 4) & 3) {
1607 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
1608 omap_clk_onoff(clk
, 1);
1611 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1612 omap_clk_onoff(clk
, 1);
1615 omap_clk_onoff(clk
, 0);
1618 if (diff
& (3 << 2)) { /* DCLKOUT */
1619 clk
= omap_findclk(s
, "dclk_out");
1620 switch ((value
>> 2) & 3) {
1622 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
1625 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
1628 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
1631 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1635 if (diff
& (3 << 0)) { /* ACLKOUT */
1636 clk
= omap_findclk(s
, "aclk_out");
1637 switch ((value
>> 0) & 3) {
1639 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1640 omap_clk_onoff(clk
, 1);
1643 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
1644 omap_clk_onoff(clk
, 1);
1647 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1648 omap_clk_onoff(clk
, 1);
1651 omap_clk_onoff(clk
, 0);
1656 static void omap_clkm_write(void *opaque
, hwaddr addr
,
1657 uint64_t value
, unsigned size
)
1659 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1662 static const char *clkschemename
[8] = {
1663 "fully synchronous", "fully asynchronous", "synchronous scalable",
1664 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1668 omap_badwidth_write16(opaque
, addr
, value
);
1673 case 0x00: /* ARM_CKCTL */
1674 diff
= s
->clkm
.arm_ckctl
^ value
;
1675 s
->clkm
.arm_ckctl
= value
& 0x7fff;
1676 omap_clkm_ckctl_update(s
, diff
, value
);
1679 case 0x04: /* ARM_IDLECT1 */
1680 diff
= s
->clkm
.arm_idlect1
^ value
;
1681 s
->clkm
.arm_idlect1
= value
& 0x0fff;
1682 omap_clkm_idlect1_update(s
, diff
, value
);
1685 case 0x08: /* ARM_IDLECT2 */
1686 diff
= s
->clkm
.arm_idlect2
^ value
;
1687 s
->clkm
.arm_idlect2
= value
& 0x07ff;
1688 omap_clkm_idlect2_update(s
, diff
, value
);
1691 case 0x0c: /* ARM_EWUPCT */
1692 s
->clkm
.arm_ewupct
= value
& 0x003f;
1695 case 0x10: /* ARM_RSTCT1 */
1696 diff
= s
->clkm
.arm_rstct1
^ value
;
1697 s
->clkm
.arm_rstct1
= value
& 0x0007;
1699 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
1700 s
->clkm
.cold_start
= 0xa;
1702 if (diff
& ~value
& 4) { /* DSP_RST */
1704 omap_tipb_bridge_reset(s
->private_tipb
);
1705 omap_tipb_bridge_reset(s
->public_tipb
);
1707 if (diff
& 2) { /* DSP_EN */
1708 clk
= omap_findclk(s
, "dsp_ck");
1709 omap_clk_canidle(clk
, (~value
>> 1) & 1);
1713 case 0x14: /* ARM_RSTCT2 */
1714 s
->clkm
.arm_rstct2
= value
& 0x0001;
1717 case 0x18: /* ARM_SYSST */
1718 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
1719 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
1720 printf("%s: clocking scheme set to %s\n", __func__
,
1721 clkschemename
[s
->clkm
.clocking_scheme
]);
1723 s
->clkm
.cold_start
&= value
& 0x3f;
1726 case 0x1c: /* ARM_CKOUT1 */
1727 diff
= s
->clkm
.arm_ckout1
^ value
;
1728 s
->clkm
.arm_ckout1
= value
& 0x003f;
1729 omap_clkm_ckout1_update(s
, diff
, value
);
1732 case 0x20: /* ARM_CKOUT2 */
1738 static const MemoryRegionOps omap_clkm_ops
= {
1739 .read
= omap_clkm_read
,
1740 .write
= omap_clkm_write
,
1741 .endianness
= DEVICE_NATIVE_ENDIAN
,
1744 static uint64_t omap_clkdsp_read(void *opaque
, hwaddr addr
,
1747 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1748 CPUState
*cpu
= CPU(s
->cpu
);
1751 return omap_badwidth_read16(opaque
, addr
);
1755 case 0x04: /* DSP_IDLECT1 */
1756 return s
->clkm
.dsp_idlect1
;
1758 case 0x08: /* DSP_IDLECT2 */
1759 return s
->clkm
.dsp_idlect2
;
1761 case 0x14: /* DSP_RSTCT2 */
1762 return s
->clkm
.dsp_rstct2
;
1764 case 0x18: /* DSP_SYSST */
1766 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
1767 (cpu
->halted
<< 6); /* Quite useless... */
1774 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
1775 uint16_t diff
, uint16_t value
)
1779 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1782 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
1783 uint16_t diff
, uint16_t value
)
1787 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1790 static void omap_clkdsp_write(void *opaque
, hwaddr addr
,
1791 uint64_t value
, unsigned size
)
1793 struct omap_mpu_state_s
*s
= (struct omap_mpu_state_s
*) opaque
;
1797 omap_badwidth_write16(opaque
, addr
, value
);
1802 case 0x04: /* DSP_IDLECT1 */
1803 diff
= s
->clkm
.dsp_idlect1
^ value
;
1804 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
1805 omap_clkdsp_idlect1_update(s
, diff
, value
);
1808 case 0x08: /* DSP_IDLECT2 */
1809 s
->clkm
.dsp_idlect2
= value
& 0x0037;
1810 diff
= s
->clkm
.dsp_idlect1
^ value
;
1811 omap_clkdsp_idlect2_update(s
, diff
, value
);
1814 case 0x14: /* DSP_RSTCT2 */
1815 s
->clkm
.dsp_rstct2
= value
& 0x0001;
1818 case 0x18: /* DSP_SYSST */
1819 s
->clkm
.cold_start
&= value
& 0x3f;
1827 static const MemoryRegionOps omap_clkdsp_ops
= {
1828 .read
= omap_clkdsp_read
,
1829 .write
= omap_clkdsp_write
,
1830 .endianness
= DEVICE_NATIVE_ENDIAN
,
1833 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
1835 if (s
->wdt
&& s
->wdt
->reset
)
1836 s
->clkm
.cold_start
= 0x6;
1837 s
->clkm
.clocking_scheme
= 0;
1838 omap_clkm_ckctl_update(s
, ~0, 0x3000);
1839 s
->clkm
.arm_ckctl
= 0x3000;
1840 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
1841 s
->clkm
.arm_idlect1
= 0x0400;
1842 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
1843 s
->clkm
.arm_idlect2
= 0x0100;
1844 s
->clkm
.arm_ewupct
= 0x003f;
1845 s
->clkm
.arm_rstct1
= 0x0000;
1846 s
->clkm
.arm_rstct2
= 0x0000;
1847 s
->clkm
.arm_ckout1
= 0x0015;
1848 s
->clkm
.dpll1_mode
= 0x2002;
1849 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
1850 s
->clkm
.dsp_idlect1
= 0x0040;
1851 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
1852 s
->clkm
.dsp_idlect2
= 0x0000;
1853 s
->clkm
.dsp_rstct2
= 0x0000;
1856 static void omap_clkm_init(MemoryRegion
*memory
, hwaddr mpu_base
,
1857 hwaddr dsp_base
, struct omap_mpu_state_s
*s
)
1859 memory_region_init_io(&s
->clkm_iomem
, NULL
, &omap_clkm_ops
, s
,
1860 "omap-clkm", 0x100);
1861 memory_region_init_io(&s
->clkdsp_iomem
, NULL
, &omap_clkdsp_ops
, s
,
1862 "omap-clkdsp", 0x1000);
1864 s
->clkm
.arm_idlect1
= 0x03ff;
1865 s
->clkm
.arm_idlect2
= 0x0100;
1866 s
->clkm
.dsp_idlect1
= 0x0002;
1868 s
->clkm
.cold_start
= 0x3a;
1870 memory_region_add_subregion(memory
, mpu_base
, &s
->clkm_iomem
);
1871 memory_region_add_subregion(memory
, dsp_base
, &s
->clkdsp_iomem
);
1875 struct omap_mpuio_s
{
1879 qemu_irq handler
[16];
1901 static void omap_mpuio_set(void *opaque
, int line
, int level
)
1903 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1904 uint16_t prev
= s
->inputs
;
1907 s
->inputs
|= 1 << line
;
1909 s
->inputs
&= ~(1 << line
);
1911 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
1912 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
1913 s
->ints
|= 1 << line
;
1914 qemu_irq_raise(s
->irq
);
1917 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1918 (s
->event
>> 1) == line
) /* PIN_SELECT */
1919 s
->latch
= s
->inputs
;
1923 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
1926 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
1928 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
1932 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
1933 s
->row_latch
= ~rows
;
1936 static uint64_t omap_mpuio_read(void *opaque
, hwaddr addr
,
1939 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
1940 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1944 return omap_badwidth_read16(opaque
, addr
);
1948 case 0x00: /* INPUT_LATCH */
1951 case 0x04: /* OUTPUT_REG */
1954 case 0x08: /* IO_CNTL */
1957 case 0x10: /* KBR_LATCH */
1958 return s
->row_latch
;
1960 case 0x14: /* KBC_REG */
1963 case 0x18: /* GPIO_EVENT_MODE_REG */
1966 case 0x1c: /* GPIO_INT_EDGE_REG */
1969 case 0x20: /* KBD_INT */
1970 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
1972 case 0x24: /* GPIO_INT */
1976 qemu_irq_lower(s
->irq
);
1979 case 0x28: /* KBD_MASKIT */
1982 case 0x2c: /* GPIO_MASKIT */
1985 case 0x30: /* GPIO_DEBOUNCING_REG */
1988 case 0x34: /* GPIO_LATCH_REG */
1996 static void omap_mpuio_write(void *opaque
, hwaddr addr
,
1997 uint64_t value
, unsigned size
)
1999 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2000 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2005 omap_badwidth_write16(opaque
, addr
, value
);
2010 case 0x04: /* OUTPUT_REG */
2011 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2013 while ((ln
= ctz32(diff
)) != 32) {
2015 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2020 case 0x08: /* IO_CNTL */
2021 diff
= s
->outputs
& (s
->dir
^ value
);
2024 value
= s
->outputs
& ~s
->dir
;
2025 while ((ln
= ctz32(diff
)) != 32) {
2027 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2032 case 0x14: /* KBC_REG */
2034 omap_mpuio_kbd_update(s
);
2037 case 0x18: /* GPIO_EVENT_MODE_REG */
2038 s
->event
= value
& 0x1f;
2041 case 0x1c: /* GPIO_INT_EDGE_REG */
2045 case 0x28: /* KBD_MASKIT */
2046 s
->kbd_mask
= value
& 1;
2047 omap_mpuio_kbd_update(s
);
2050 case 0x2c: /* GPIO_MASKIT */
2054 case 0x30: /* GPIO_DEBOUNCING_REG */
2055 s
->debounce
= value
& 0x1ff;
2058 case 0x00: /* INPUT_LATCH */
2059 case 0x10: /* KBR_LATCH */
2060 case 0x20: /* KBD_INT */
2061 case 0x24: /* GPIO_INT */
2062 case 0x34: /* GPIO_LATCH_REG */
2072 static const MemoryRegionOps omap_mpuio_ops
= {
2073 .read
= omap_mpuio_read
,
2074 .write
= omap_mpuio_write
,
2075 .endianness
= DEVICE_NATIVE_ENDIAN
,
2078 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2090 s
->row_latch
= 0x1f;
2094 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2096 struct omap_mpuio_s
*s
= (struct omap_mpuio_s
*) opaque
;
2100 omap_mpuio_kbd_update(s
);
2103 static struct omap_mpuio_s
*omap_mpuio_init(MemoryRegion
*memory
,
2105 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2108 struct omap_mpuio_s
*s
= g_new0(struct omap_mpuio_s
, 1);
2111 s
->kbd_irq
= kbd_int
;
2113 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2114 omap_mpuio_reset(s
);
2116 memory_region_init_io(&s
->iomem
, NULL
, &omap_mpuio_ops
, s
,
2117 "omap-mpuio", 0x800);
2118 memory_region_add_subregion(memory
, base
, &s
->iomem
);
2120 omap_clk_adduser(clk
, qemu_allocate_irq(omap_mpuio_onoff
, s
, 0));
2125 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2130 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2132 if (line
>= 16 || line
< 0)
2133 hw_error("%s: No GPIO line %i\n", __func__
, line
);
2134 s
->handler
[line
] = handler
;
2137 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2139 if (row
>= 5 || row
< 0)
2140 hw_error("%s: No key %i-%i\n", __func__
, col
, row
);
2143 s
->buttons
[row
] |= 1 << col
;
2145 s
->buttons
[row
] &= ~(1 << col
);
2147 omap_mpuio_kbd_update(s
);
2150 /* MicroWire Interface */
2151 struct omap_uwire_s
{
2162 uWireSlave
*chip
[4];
2165 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
2167 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
2168 uWireSlave
*slave
= s
->chip
[chipselect
];
2170 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
2171 if (s
->control
& (1 << 12)) /* CS_CMD */
2172 if (slave
&& slave
->send
)
2173 slave
->send(slave
->opaque
,
2174 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
2175 s
->control
&= ~(1 << 14); /* CSRB */
2176 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2177 * a DRQ. When is the level IRQ supposed to be reset? */
2180 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
2181 if (s
->control
& (1 << 12)) /* CS_CMD */
2182 if (slave
&& slave
->receive
)
2183 s
->rxbuf
= slave
->receive(slave
->opaque
);
2184 s
->control
|= 1 << 15; /* RDRB */
2185 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2186 * a DRQ. When is the level IRQ supposed to be reset? */
2190 static uint64_t omap_uwire_read(void *opaque
, hwaddr addr
,
2193 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2194 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2197 return omap_badwidth_read16(opaque
, addr
);
2201 case 0x00: /* RDR */
2202 s
->control
&= ~(1 << 15); /* RDRB */
2205 case 0x04: /* CSR */
2208 case 0x08: /* SR1 */
2210 case 0x0c: /* SR2 */
2212 case 0x10: /* SR3 */
2214 case 0x14: /* SR4 */
2216 case 0x18: /* SR5 */
2224 static void omap_uwire_write(void *opaque
, hwaddr addr
,
2225 uint64_t value
, unsigned size
)
2227 struct omap_uwire_s
*s
= (struct omap_uwire_s
*) opaque
;
2228 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2231 omap_badwidth_write16(opaque
, addr
, value
);
2236 case 0x00: /* TDR */
2237 s
->txbuf
= value
; /* TD */
2238 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
2239 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2240 (s
->control
& (1 << 12)))) { /* CS_CMD */
2241 s
->control
|= 1 << 14; /* CSRB */
2242 omap_uwire_transfer_start(s
);
2246 case 0x04: /* CSR */
2247 s
->control
= value
& 0x1fff;
2248 if (value
& (1 << 13)) /* START */
2249 omap_uwire_transfer_start(s
);
2252 case 0x08: /* SR1 */
2253 s
->setup
[0] = value
& 0x003f;
2256 case 0x0c: /* SR2 */
2257 s
->setup
[1] = value
& 0x0fc0;
2260 case 0x10: /* SR3 */
2261 s
->setup
[2] = value
& 0x0003;
2264 case 0x14: /* SR4 */
2265 s
->setup
[3] = value
& 0x0001;
2268 case 0x18: /* SR5 */
2269 s
->setup
[4] = value
& 0x000f;
2278 static const MemoryRegionOps omap_uwire_ops
= {
2279 .read
= omap_uwire_read
,
2280 .write
= omap_uwire_write
,
2281 .endianness
= DEVICE_NATIVE_ENDIAN
,
2284 static void omap_uwire_reset(struct omap_uwire_s
*s
)
2294 static struct omap_uwire_s
*omap_uwire_init(MemoryRegion
*system_memory
,
2296 qemu_irq txirq
, qemu_irq rxirq
,
2300 struct omap_uwire_s
*s
= g_new0(struct omap_uwire_s
, 1);
2305 omap_uwire_reset(s
);
2307 memory_region_init_io(&s
->iomem
, NULL
, &omap_uwire_ops
, s
, "omap-uwire", 0x800);
2308 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2313 void omap_uwire_attach(struct omap_uwire_s
*s
,
2314 uWireSlave
*slave
, int chipselect
)
2316 if (chipselect
< 0 || chipselect
> 3) {
2317 error_report("%s: Bad chipselect %i", __func__
, chipselect
);
2321 s
->chip
[chipselect
] = slave
;
2324 /* Pseudonoise Pulse-Width Light Modulator */
2333 static void omap_pwl_update(struct omap_pwl_s
*s
)
2335 int output
= (s
->clk
&& s
->enable
) ? s
->level
: 0;
2337 if (output
!= s
->output
) {
2339 printf("%s: Backlight now at %i/256\n", __func__
, output
);
2343 static uint64_t omap_pwl_read(void *opaque
, hwaddr addr
,
2346 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2347 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2350 return omap_badwidth_read8(opaque
, addr
);
2354 case 0x00: /* PWL_LEVEL */
2356 case 0x04: /* PWL_CTRL */
2363 static void omap_pwl_write(void *opaque
, hwaddr addr
,
2364 uint64_t value
, unsigned size
)
2366 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2367 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2370 omap_badwidth_write8(opaque
, addr
, value
);
2375 case 0x00: /* PWL_LEVEL */
2379 case 0x04: /* PWL_CTRL */
2380 s
->enable
= value
& 1;
2389 static const MemoryRegionOps omap_pwl_ops
= {
2390 .read
= omap_pwl_read
,
2391 .write
= omap_pwl_write
,
2392 .endianness
= DEVICE_NATIVE_ENDIAN
,
2395 static void omap_pwl_reset(struct omap_pwl_s
*s
)
2404 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
2406 struct omap_pwl_s
*s
= (struct omap_pwl_s
*) opaque
;
2412 static struct omap_pwl_s
*omap_pwl_init(MemoryRegion
*system_memory
,
2416 struct omap_pwl_s
*s
= g_malloc0(sizeof(*s
));
2420 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwl_ops
, s
,
2422 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2424 omap_clk_adduser(clk
, qemu_allocate_irq(omap_pwl_clk_update
, s
, 0));
2428 /* Pulse-Width Tone module */
2437 static uint64_t omap_pwt_read(void *opaque
, hwaddr addr
,
2440 struct omap_pwt_s
*s
= (struct omap_pwt_s
*) opaque
;
2441 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2444 return omap_badwidth_read8(opaque
, addr
);
2448 case 0x00: /* FRC */
2450 case 0x04: /* VCR */
2452 case 0x08: /* GCR */
2459 static void omap_pwt_write(void *opaque
, hwaddr addr
,
2460 uint64_t value
, unsigned size
)
2462 struct omap_pwt_s
*s
= (struct omap_pwt_s
*) opaque
;
2463 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2466 omap_badwidth_write8(opaque
, addr
, value
);
2471 case 0x00: /* FRC */
2472 s
->frc
= value
& 0x3f;
2474 case 0x04: /* VRC */
2475 if ((value
^ s
->vrc
) & 1) {
2477 printf("%s: %iHz buzz on\n", __func__
, (int)
2478 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2479 ((omap_clk_getrate(s
->clk
) >> 3) /
2480 /* Pre-multiplexer divider */
2481 ((s
->gcr
& 2) ? 1 : 154) /
2482 /* Octave multiplexer */
2483 (2 << (value
& 3)) *
2484 /* 101/107 divider */
2485 ((value
& (1 << 2)) ? 101 : 107) *
2487 ((value
& (1 << 3)) ? 49 : 55) *
2489 ((value
& (1 << 4)) ? 50 : 63) *
2490 /* 80/127 divider */
2491 ((value
& (1 << 5)) ? 80 : 127) /
2492 (107 * 55 * 63 * 127)));
2494 printf("%s: silence!\n", __func__
);
2496 s
->vrc
= value
& 0x7f;
2498 case 0x08: /* GCR */
2507 static const MemoryRegionOps omap_pwt_ops
= {
2508 .read
=omap_pwt_read
,
2509 .write
= omap_pwt_write
,
2510 .endianness
= DEVICE_NATIVE_ENDIAN
,
2513 static void omap_pwt_reset(struct omap_pwt_s
*s
)
2520 static struct omap_pwt_s
*omap_pwt_init(MemoryRegion
*system_memory
,
2524 struct omap_pwt_s
*s
= g_malloc0(sizeof(*s
));
2528 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwt_ops
, s
,
2530 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2534 /* Real-time Clock module */
2551 struct tm current_tm
;
2556 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
2558 /* s->alarm is level-triggered */
2559 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
2562 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
2564 s
->alarm_ti
= mktimegm(&s
->alarm_tm
);
2565 if (s
->alarm_ti
== -1)
2566 printf("%s: conversion failed\n", __func__
);
2569 static uint64_t omap_rtc_read(void *opaque
, hwaddr addr
,
2572 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2573 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2577 return omap_badwidth_read8(opaque
, addr
);
2581 case 0x00: /* SECONDS_REG */
2582 return to_bcd(s
->current_tm
.tm_sec
);
2584 case 0x04: /* MINUTES_REG */
2585 return to_bcd(s
->current_tm
.tm_min
);
2587 case 0x08: /* HOURS_REG */
2589 return ((s
->current_tm
.tm_hour
> 11) << 7) |
2590 to_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
2592 return to_bcd(s
->current_tm
.tm_hour
);
2594 case 0x0c: /* DAYS_REG */
2595 return to_bcd(s
->current_tm
.tm_mday
);
2597 case 0x10: /* MONTHS_REG */
2598 return to_bcd(s
->current_tm
.tm_mon
+ 1);
2600 case 0x14: /* YEARS_REG */
2601 return to_bcd(s
->current_tm
.tm_year
% 100);
2603 case 0x18: /* WEEK_REG */
2604 return s
->current_tm
.tm_wday
;
2606 case 0x20: /* ALARM_SECONDS_REG */
2607 return to_bcd(s
->alarm_tm
.tm_sec
);
2609 case 0x24: /* ALARM_MINUTES_REG */
2610 return to_bcd(s
->alarm_tm
.tm_min
);
2612 case 0x28: /* ALARM_HOURS_REG */
2614 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
2615 to_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
2617 return to_bcd(s
->alarm_tm
.tm_hour
);
2619 case 0x2c: /* ALARM_DAYS_REG */
2620 return to_bcd(s
->alarm_tm
.tm_mday
);
2622 case 0x30: /* ALARM_MONTHS_REG */
2623 return to_bcd(s
->alarm_tm
.tm_mon
+ 1);
2625 case 0x34: /* ALARM_YEARS_REG */
2626 return to_bcd(s
->alarm_tm
.tm_year
% 100);
2628 case 0x40: /* RTC_CTRL_REG */
2629 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
2630 (s
->round
<< 1) | s
->running
;
2632 case 0x44: /* RTC_STATUS_REG */
2637 case 0x48: /* RTC_INTERRUPTS_REG */
2638 return s
->interrupts
;
2640 case 0x4c: /* RTC_COMP_LSB_REG */
2641 return ((uint16_t) s
->comp_reg
) & 0xff;
2643 case 0x50: /* RTC_COMP_MSB_REG */
2644 return ((uint16_t) s
->comp_reg
) >> 8;
2651 static void omap_rtc_write(void *opaque
, hwaddr addr
,
2652 uint64_t value
, unsigned size
)
2654 struct omap_rtc_s
*s
= (struct omap_rtc_s
*) opaque
;
2655 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2660 omap_badwidth_write8(opaque
, addr
, value
);
2665 case 0x00: /* SECONDS_REG */
2667 printf("RTC SEC_REG <-- %02x\n", value
);
2669 s
->ti
-= s
->current_tm
.tm_sec
;
2670 s
->ti
+= from_bcd(value
);
2673 case 0x04: /* MINUTES_REG */
2675 printf("RTC MIN_REG <-- %02x\n", value
);
2677 s
->ti
-= s
->current_tm
.tm_min
* 60;
2678 s
->ti
+= from_bcd(value
) * 60;
2681 case 0x08: /* HOURS_REG */
2683 printf("RTC HRS_REG <-- %02x\n", value
);
2685 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
2687 s
->ti
+= (from_bcd(value
& 0x3f) & 12) * 3600;
2688 s
->ti
+= ((value
>> 7) & 1) * 43200;
2690 s
->ti
+= from_bcd(value
& 0x3f) * 3600;
2693 case 0x0c: /* DAYS_REG */
2695 printf("RTC DAY_REG <-- %02x\n", value
);
2697 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
2698 s
->ti
+= from_bcd(value
) * 86400;
2701 case 0x10: /* MONTHS_REG */
2703 printf("RTC MTH_REG <-- %02x\n", value
);
2705 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2706 new_tm
.tm_mon
= from_bcd(value
);
2707 ti
[0] = mktimegm(&s
->current_tm
);
2708 ti
[1] = mktimegm(&new_tm
);
2710 if (ti
[0] != -1 && ti
[1] != -1) {
2714 /* A less accurate version */
2715 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
2716 s
->ti
+= from_bcd(value
) * 2592000;
2720 case 0x14: /* YEARS_REG */
2722 printf("RTC YRS_REG <-- %02x\n", value
);
2724 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2725 new_tm
.tm_year
+= from_bcd(value
) - (new_tm
.tm_year
% 100);
2726 ti
[0] = mktimegm(&s
->current_tm
);
2727 ti
[1] = mktimegm(&new_tm
);
2729 if (ti
[0] != -1 && ti
[1] != -1) {
2733 /* A less accurate version */
2734 s
->ti
-= (time_t)(s
->current_tm
.tm_year
% 100) * 31536000;
2735 s
->ti
+= (time_t)from_bcd(value
) * 31536000;
2739 case 0x18: /* WEEK_REG */
2740 return; /* Ignored */
2742 case 0x20: /* ALARM_SECONDS_REG */
2744 printf("ALM SEC_REG <-- %02x\n", value
);
2746 s
->alarm_tm
.tm_sec
= from_bcd(value
);
2747 omap_rtc_alarm_update(s
);
2750 case 0x24: /* ALARM_MINUTES_REG */
2752 printf("ALM MIN_REG <-- %02x\n", value
);
2754 s
->alarm_tm
.tm_min
= from_bcd(value
);
2755 omap_rtc_alarm_update(s
);
2758 case 0x28: /* ALARM_HOURS_REG */
2760 printf("ALM HRS_REG <-- %02x\n", value
);
2763 s
->alarm_tm
.tm_hour
=
2764 ((from_bcd(value
& 0x3f)) % 12) +
2765 ((value
>> 7) & 1) * 12;
2767 s
->alarm_tm
.tm_hour
= from_bcd(value
);
2768 omap_rtc_alarm_update(s
);
2771 case 0x2c: /* ALARM_DAYS_REG */
2773 printf("ALM DAY_REG <-- %02x\n", value
);
2775 s
->alarm_tm
.tm_mday
= from_bcd(value
);
2776 omap_rtc_alarm_update(s
);
2779 case 0x30: /* ALARM_MONTHS_REG */
2781 printf("ALM MON_REG <-- %02x\n", value
);
2783 s
->alarm_tm
.tm_mon
= from_bcd(value
);
2784 omap_rtc_alarm_update(s
);
2787 case 0x34: /* ALARM_YEARS_REG */
2789 printf("ALM YRS_REG <-- %02x\n", value
);
2791 s
->alarm_tm
.tm_year
= from_bcd(value
);
2792 omap_rtc_alarm_update(s
);
2795 case 0x40: /* RTC_CTRL_REG */
2797 printf("RTC CONTROL <-- %02x\n", value
);
2799 s
->pm_am
= (value
>> 3) & 1;
2800 s
->auto_comp
= (value
>> 2) & 1;
2801 s
->round
= (value
>> 1) & 1;
2802 s
->running
= value
& 1;
2804 s
->status
|= s
->running
<< 1;
2807 case 0x44: /* RTC_STATUS_REG */
2809 printf("RTC STATUSL <-- %02x\n", value
);
2811 s
->status
&= ~((value
& 0xc0) ^ 0x80);
2812 omap_rtc_interrupts_update(s
);
2815 case 0x48: /* RTC_INTERRUPTS_REG */
2817 printf("RTC INTRS <-- %02x\n", value
);
2819 s
->interrupts
= value
;
2822 case 0x4c: /* RTC_COMP_LSB_REG */
2824 printf("RTC COMPLSB <-- %02x\n", value
);
2826 s
->comp_reg
&= 0xff00;
2827 s
->comp_reg
|= 0x00ff & value
;
2830 case 0x50: /* RTC_COMP_MSB_REG */
2832 printf("RTC COMPMSB <-- %02x\n", value
);
2834 s
->comp_reg
&= 0x00ff;
2835 s
->comp_reg
|= 0xff00 & (value
<< 8);
2844 static const MemoryRegionOps omap_rtc_ops
= {
2845 .read
= omap_rtc_read
,
2846 .write
= omap_rtc_write
,
2847 .endianness
= DEVICE_NATIVE_ENDIAN
,
2850 static void omap_rtc_tick(void *opaque
)
2852 struct omap_rtc_s
*s
= opaque
;
2855 /* Round to nearest full minute. */
2856 if (s
->current_tm
.tm_sec
< 30)
2857 s
->ti
-= s
->current_tm
.tm_sec
;
2859 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
2864 localtime_r(&s
->ti
, &s
->current_tm
);
2866 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
2868 omap_rtc_interrupts_update(s
);
2871 if (s
->interrupts
& 0x04)
2872 switch (s
->interrupts
& 3) {
2875 qemu_irq_pulse(s
->irq
);
2878 if (s
->current_tm
.tm_sec
)
2881 qemu_irq_pulse(s
->irq
);
2884 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
2887 qemu_irq_pulse(s
->irq
);
2890 if (s
->current_tm
.tm_sec
||
2891 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
2894 qemu_irq_pulse(s
->irq
);
2904 * Every full hour add a rough approximation of the compensation
2905 * register to the 32kHz Timer (which drives the RTC) value.
2907 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
2908 s
->tick
+= s
->comp_reg
* 1000 / 32768;
2910 timer_mod(s
->clk
, s
->tick
);
2913 static void omap_rtc_reset(struct omap_rtc_s
*s
)
2923 s
->tick
= qemu_clock_get_ms(rtc_clock
);
2924 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
2925 s
->alarm_tm
.tm_mday
= 0x01;
2927 qemu_get_timedate(&tm
, 0);
2928 s
->ti
= mktimegm(&tm
);
2930 omap_rtc_alarm_update(s
);
2934 static struct omap_rtc_s
*omap_rtc_init(MemoryRegion
*system_memory
,
2936 qemu_irq timerirq
, qemu_irq alarmirq
,
2939 struct omap_rtc_s
*s
= g_new0(struct omap_rtc_s
, 1);
2942 s
->alarm
= alarmirq
;
2943 s
->clk
= timer_new_ms(rtc_clock
, omap_rtc_tick
, s
);
2947 memory_region_init_io(&s
->iomem
, NULL
, &omap_rtc_ops
, s
,
2949 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2954 /* Multi-channel Buffered Serial Port interfaces */
2955 struct omap_mcbsp_s
{
2976 QEMUTimer
*source_timer
;
2977 QEMUTimer
*sink_timer
;
2980 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
2984 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
2986 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
2989 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
2997 qemu_irq_pulse(s
->rxirq
);
2999 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
3001 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
3004 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
3012 qemu_irq_pulse(s
->txirq
);
3015 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
3017 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
3018 s
->spcr
[0] |= 1 << 2; /* RFULL */
3019 s
->spcr
[0] |= 1 << 1; /* RRDY */
3020 qemu_irq_raise(s
->rxdrq
);
3021 omap_mcbsp_intr_update(s
);
3024 static void omap_mcbsp_source_tick(void *opaque
)
3026 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3027 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3032 printf("%s: Rx FIFO overrun\n", __func__
);
3034 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
3036 omap_mcbsp_rx_newdata(s
);
3037 timer_mod(s
->source_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3038 NANOSECONDS_PER_SECOND
);
3041 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
3043 if (!s
->codec
|| !s
->codec
->rts
)
3044 omap_mcbsp_source_tick(s
);
3045 else if (s
->codec
->in
.len
) {
3046 s
->rx_req
= s
->codec
->in
.len
;
3047 omap_mcbsp_rx_newdata(s
);
3051 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
3053 timer_del(s
->source_timer
);
3056 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
3058 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
3059 qemu_irq_lower(s
->rxdrq
);
3060 omap_mcbsp_intr_update(s
);
3063 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
3065 s
->spcr
[1] |= 1 << 1; /* XRDY */
3066 qemu_irq_raise(s
->txdrq
);
3067 omap_mcbsp_intr_update(s
);
3070 static void omap_mcbsp_sink_tick(void *opaque
)
3072 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3073 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3078 printf("%s: Tx FIFO underrun\n", __func__
);
3080 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
3082 omap_mcbsp_tx_newdata(s
);
3083 timer_mod(s
->sink_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3084 NANOSECONDS_PER_SECOND
);
3087 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
3089 if (!s
->codec
|| !s
->codec
->cts
)
3090 omap_mcbsp_sink_tick(s
);
3091 else if (s
->codec
->out
.size
) {
3092 s
->tx_req
= s
->codec
->out
.size
;
3093 omap_mcbsp_tx_newdata(s
);
3097 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
3099 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
3100 qemu_irq_lower(s
->txdrq
);
3101 omap_mcbsp_intr_update(s
);
3102 if (s
->codec
&& s
->codec
->cts
)
3103 s
->codec
->tx_swallow(s
->codec
->opaque
);
3106 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
3109 omap_mcbsp_tx_done(s
);
3110 timer_del(s
->sink_timer
);
3113 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
3115 int prev_rx_rate
, prev_tx_rate
;
3116 int rx_rate
= 0, tx_rate
= 0;
3117 int cpu_rate
= 1500000; /* XXX */
3119 /* TODO: check CLKSTP bit */
3120 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3121 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3122 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3123 (s
->pcr
& (1 << 8))) { /* CLKRM */
3124 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3125 rx_rate
= cpu_rate
/
3126 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3129 rx_rate
= s
->codec
->rx_rate
;
3132 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3133 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3134 (s
->pcr
& (1 << 9))) { /* CLKXM */
3135 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3136 tx_rate
= cpu_rate
/
3137 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3140 tx_rate
= s
->codec
->tx_rate
;
3143 prev_tx_rate
= s
->tx_rate
;
3144 prev_rx_rate
= s
->rx_rate
;
3145 s
->tx_rate
= tx_rate
;
3146 s
->rx_rate
= rx_rate
;
3149 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3151 if (!prev_tx_rate
&& tx_rate
)
3152 omap_mcbsp_tx_start(s
);
3153 else if (s
->tx_rate
&& !tx_rate
)
3154 omap_mcbsp_tx_stop(s
);
3156 if (!prev_rx_rate
&& rx_rate
)
3157 omap_mcbsp_rx_start(s
);
3158 else if (prev_tx_rate
&& !tx_rate
)
3159 omap_mcbsp_rx_stop(s
);
3162 static uint64_t omap_mcbsp_read(void *opaque
, hwaddr addr
,
3165 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3166 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3170 return omap_badwidth_read16(opaque
, addr
);
3174 case 0x00: /* DRR2 */
3175 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
3178 case 0x02: /* DRR1 */
3179 if (s
->rx_req
< 2) {
3180 printf("%s: Rx FIFO underrun\n", __func__
);
3181 omap_mcbsp_rx_done(s
);
3184 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
3185 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
3186 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
3187 s
->codec
->in
.len
-= 2;
3191 omap_mcbsp_rx_done(s
);
3196 case 0x04: /* DXR2 */
3197 case 0x06: /* DXR1 */
3200 case 0x08: /* SPCR2 */
3202 case 0x0a: /* SPCR1 */
3204 case 0x0c: /* RCR2 */
3206 case 0x0e: /* RCR1 */
3208 case 0x10: /* XCR2 */
3210 case 0x12: /* XCR1 */
3212 case 0x14: /* SRGR2 */
3214 case 0x16: /* SRGR1 */
3216 case 0x18: /* MCR2 */
3218 case 0x1a: /* MCR1 */
3220 case 0x1c: /* RCERA */
3222 case 0x1e: /* RCERB */
3224 case 0x20: /* XCERA */
3226 case 0x22: /* XCERB */
3228 case 0x24: /* PCR0 */
3230 case 0x26: /* RCERC */
3232 case 0x28: /* RCERD */
3234 case 0x2a: /* XCERC */
3236 case 0x2c: /* XCERD */
3238 case 0x2e: /* RCERE */
3240 case 0x30: /* RCERF */
3242 case 0x32: /* XCERE */
3244 case 0x34: /* XCERF */
3246 case 0x36: /* RCERG */
3248 case 0x38: /* RCERH */
3250 case 0x3a: /* XCERG */
3252 case 0x3c: /* XCERH */
3260 static void omap_mcbsp_writeh(void *opaque
, hwaddr addr
,
3263 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3264 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3267 case 0x00: /* DRR2 */
3268 case 0x02: /* DRR1 */
3272 case 0x04: /* DXR2 */
3273 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3276 case 0x06: /* DXR1 */
3277 if (s
->tx_req
> 1) {
3279 if (s
->codec
&& s
->codec
->cts
) {
3280 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
3281 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
3284 omap_mcbsp_tx_done(s
);
3286 printf("%s: Tx FIFO overrun\n", __func__
);
3289 case 0x08: /* SPCR2 */
3290 s
->spcr
[1] &= 0x0002;
3291 s
->spcr
[1] |= 0x03f9 & value
;
3292 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
3293 if (~value
& 1) /* XRST */
3295 omap_mcbsp_req_update(s
);
3297 case 0x0a: /* SPCR1 */
3298 s
->spcr
[0] &= 0x0006;
3299 s
->spcr
[0] |= 0xf8f9 & value
;
3300 if (value
& (1 << 15)) /* DLB */
3301 printf("%s: Digital Loopback mode enable attempt\n", __func__
);
3302 if (~value
& 1) { /* RRST */
3305 omap_mcbsp_rx_done(s
);
3307 omap_mcbsp_req_update(s
);
3310 case 0x0c: /* RCR2 */
3311 s
->rcr
[1] = value
& 0xffff;
3313 case 0x0e: /* RCR1 */
3314 s
->rcr
[0] = value
& 0x7fe0;
3316 case 0x10: /* XCR2 */
3317 s
->xcr
[1] = value
& 0xffff;
3319 case 0x12: /* XCR1 */
3320 s
->xcr
[0] = value
& 0x7fe0;
3322 case 0x14: /* SRGR2 */
3323 s
->srgr
[1] = value
& 0xffff;
3324 omap_mcbsp_req_update(s
);
3326 case 0x16: /* SRGR1 */
3327 s
->srgr
[0] = value
& 0xffff;
3328 omap_mcbsp_req_update(s
);
3330 case 0x18: /* MCR2 */
3331 s
->mcr
[1] = value
& 0x03e3;
3332 if (value
& 3) /* XMCM */
3333 printf("%s: Tx channel selection mode enable attempt\n", __func__
);
3335 case 0x1a: /* MCR1 */
3336 s
->mcr
[0] = value
& 0x03e1;
3337 if (value
& 1) /* RMCM */
3338 printf("%s: Rx channel selection mode enable attempt\n", __func__
);
3340 case 0x1c: /* RCERA */
3341 s
->rcer
[0] = value
& 0xffff;
3343 case 0x1e: /* RCERB */
3344 s
->rcer
[1] = value
& 0xffff;
3346 case 0x20: /* XCERA */
3347 s
->xcer
[0] = value
& 0xffff;
3349 case 0x22: /* XCERB */
3350 s
->xcer
[1] = value
& 0xffff;
3352 case 0x24: /* PCR0 */
3353 s
->pcr
= value
& 0x7faf;
3355 case 0x26: /* RCERC */
3356 s
->rcer
[2] = value
& 0xffff;
3358 case 0x28: /* RCERD */
3359 s
->rcer
[3] = value
& 0xffff;
3361 case 0x2a: /* XCERC */
3362 s
->xcer
[2] = value
& 0xffff;
3364 case 0x2c: /* XCERD */
3365 s
->xcer
[3] = value
& 0xffff;
3367 case 0x2e: /* RCERE */
3368 s
->rcer
[4] = value
& 0xffff;
3370 case 0x30: /* RCERF */
3371 s
->rcer
[5] = value
& 0xffff;
3373 case 0x32: /* XCERE */
3374 s
->xcer
[4] = value
& 0xffff;
3376 case 0x34: /* XCERF */
3377 s
->xcer
[5] = value
& 0xffff;
3379 case 0x36: /* RCERG */
3380 s
->rcer
[6] = value
& 0xffff;
3382 case 0x38: /* RCERH */
3383 s
->rcer
[7] = value
& 0xffff;
3385 case 0x3a: /* XCERG */
3386 s
->xcer
[6] = value
& 0xffff;
3388 case 0x3c: /* XCERH */
3389 s
->xcer
[7] = value
& 0xffff;
3396 static void omap_mcbsp_writew(void *opaque
, hwaddr addr
,
3399 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3400 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3402 if (offset
== 0x04) { /* DXR */
3403 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3405 if (s
->tx_req
> 3) {
3407 if (s
->codec
&& s
->codec
->cts
) {
3408 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3409 (value
>> 24) & 0xff;
3410 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3411 (value
>> 16) & 0xff;
3412 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3413 (value
>> 8) & 0xff;
3414 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3415 (value
>> 0) & 0xff;
3418 omap_mcbsp_tx_done(s
);
3420 printf("%s: Tx FIFO overrun\n", __func__
);
3424 omap_badwidth_write16(opaque
, addr
, value
);
3427 static void omap_mcbsp_write(void *opaque
, hwaddr addr
,
3428 uint64_t value
, unsigned size
)
3432 omap_mcbsp_writeh(opaque
, addr
, value
);
3435 omap_mcbsp_writew(opaque
, addr
, value
);
3438 omap_badwidth_write16(opaque
, addr
, value
);
3442 static const MemoryRegionOps omap_mcbsp_ops
= {
3443 .read
= omap_mcbsp_read
,
3444 .write
= omap_mcbsp_write
,
3445 .endianness
= DEVICE_NATIVE_ENDIAN
,
3448 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
3450 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
3451 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
3452 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
3453 s
->srgr
[0] = 0x0001;
3454 s
->srgr
[1] = 0x2000;
3455 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
3456 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
3457 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
3458 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
3463 timer_del(s
->source_timer
);
3464 timer_del(s
->sink_timer
);
3467 static struct omap_mcbsp_s
*omap_mcbsp_init(MemoryRegion
*system_memory
,
3469 qemu_irq txirq
, qemu_irq rxirq
,
3470 qemu_irq
*dma
, omap_clk clk
)
3472 struct omap_mcbsp_s
*s
= g_new0(struct omap_mcbsp_s
, 1);
3478 s
->sink_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_sink_tick
, s
);
3479 s
->source_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_source_tick
, s
);
3480 omap_mcbsp_reset(s
);
3482 memory_region_init_io(&s
->iomem
, NULL
, &omap_mcbsp_ops
, s
, "omap-mcbsp", 0x800);
3483 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3488 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
3490 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3493 s
->rx_req
= s
->codec
->in
.len
;
3494 omap_mcbsp_rx_newdata(s
);
3498 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
3500 struct omap_mcbsp_s
*s
= (struct omap_mcbsp_s
*) opaque
;
3503 s
->tx_req
= s
->codec
->out
.size
;
3504 omap_mcbsp_tx_newdata(s
);
3508 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, I2SCodec
*slave
)
3511 slave
->rx_swallow
= qemu_allocate_irq(omap_mcbsp_i2s_swallow
, s
, 0);
3512 slave
->tx_start
= qemu_allocate_irq(omap_mcbsp_i2s_start
, s
, 0);
3515 /* LED Pulse Generators */
3528 static void omap_lpg_tick(void *opaque
)
3530 struct omap_lpg_s
*s
= opaque
;
3533 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->period
- s
->on
);
3535 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->on
);
3537 s
->cycle
= !s
->cycle
;
3538 printf("%s: LED is %s\n", __func__
, s
->cycle
? "on" : "off");
3541 static void omap_lpg_update(struct omap_lpg_s
*s
)
3543 int64_t on
, period
= 1, ticks
= 1000;
3544 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3546 if (~s
->control
& (1 << 6)) /* LPGRES */
3548 else if (s
->control
& (1 << 7)) /* PERM_ON */
3551 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
3553 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
3554 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
3558 if (on
== period
&& s
->on
< s
->period
)
3559 printf("%s: LED is on\n", __func__
);
3560 else if (on
== 0 && s
->on
)
3561 printf("%s: LED is off\n", __func__
);
3562 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
3574 static void omap_lpg_reset(struct omap_lpg_s
*s
)
3582 static uint64_t omap_lpg_read(void *opaque
, hwaddr addr
,
3585 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3586 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3589 return omap_badwidth_read8(opaque
, addr
);
3593 case 0x00: /* LCR */
3596 case 0x04: /* PMR */
3604 static void omap_lpg_write(void *opaque
, hwaddr addr
,
3605 uint64_t value
, unsigned size
)
3607 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3608 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3611 omap_badwidth_write8(opaque
, addr
, value
);
3616 case 0x00: /* LCR */
3617 if (~value
& (1 << 6)) /* LPGRES */
3619 s
->control
= value
& 0xff;
3623 case 0x04: /* PMR */
3624 s
->power
= value
& 0x01;
3634 static const MemoryRegionOps omap_lpg_ops
= {
3635 .read
= omap_lpg_read
,
3636 .write
= omap_lpg_write
,
3637 .endianness
= DEVICE_NATIVE_ENDIAN
,
3640 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
3642 struct omap_lpg_s
*s
= (struct omap_lpg_s
*) opaque
;
3648 static struct omap_lpg_s
*omap_lpg_init(MemoryRegion
*system_memory
,
3649 hwaddr base
, omap_clk clk
)
3651 struct omap_lpg_s
*s
= g_new0(struct omap_lpg_s
, 1);
3653 s
->tm
= timer_new_ms(QEMU_CLOCK_VIRTUAL
, omap_lpg_tick
, s
);
3657 memory_region_init_io(&s
->iomem
, NULL
, &omap_lpg_ops
, s
, "omap-lpg", 0x800);
3658 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3660 omap_clk_adduser(clk
, qemu_allocate_irq(omap_lpg_clk_update
, s
, 0));
3665 /* MPUI Peripheral Bridge configuration */
3666 static uint64_t omap_mpui_io_read(void *opaque
, hwaddr addr
,
3670 return omap_badwidth_read16(opaque
, addr
);
3673 if (addr
== OMAP_MPUI_BASE
) /* CMR */
3680 static void omap_mpui_io_write(void *opaque
, hwaddr addr
,
3681 uint64_t value
, unsigned size
)
3683 /* FIXME: infinite loop */
3684 omap_badwidth_write16(opaque
, addr
, value
);
3687 static const MemoryRegionOps omap_mpui_io_ops
= {
3688 .read
= omap_mpui_io_read
,
3689 .write
= omap_mpui_io_write
,
3690 .endianness
= DEVICE_NATIVE_ENDIAN
,
3693 static void omap_setup_mpui_io(MemoryRegion
*system_memory
,
3694 struct omap_mpu_state_s
*mpu
)
3696 memory_region_init_io(&mpu
->mpui_io_iomem
, NULL
, &omap_mpui_io_ops
, mpu
,
3697 "omap-mpui-io", 0x7fff);
3698 memory_region_add_subregion(system_memory
, OMAP_MPUI_BASE
,
3699 &mpu
->mpui_io_iomem
);
3702 /* General chip reset */
3703 static void omap1_mpu_reset(void *opaque
)
3705 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3707 omap_dma_reset(mpu
->dma
);
3708 omap_mpu_timer_reset(mpu
->timer
[0]);
3709 omap_mpu_timer_reset(mpu
->timer
[1]);
3710 omap_mpu_timer_reset(mpu
->timer
[2]);
3711 omap_wd_timer_reset(mpu
->wdt
);
3712 omap_os_timer_reset(mpu
->os_timer
);
3713 omap_lcdc_reset(mpu
->lcd
);
3714 omap_ulpd_pm_reset(mpu
);
3715 omap_pin_cfg_reset(mpu
);
3716 omap_mpui_reset(mpu
);
3717 omap_tipb_bridge_reset(mpu
->private_tipb
);
3718 omap_tipb_bridge_reset(mpu
->public_tipb
);
3719 omap_dpll_reset(mpu
->dpll
[0]);
3720 omap_dpll_reset(mpu
->dpll
[1]);
3721 omap_dpll_reset(mpu
->dpll
[2]);
3722 omap_uart_reset(mpu
->uart
[0]);
3723 omap_uart_reset(mpu
->uart
[1]);
3724 omap_uart_reset(mpu
->uart
[2]);
3725 omap_mmc_reset(mpu
->mmc
);
3726 omap_mpuio_reset(mpu
->mpuio
);
3727 omap_uwire_reset(mpu
->microwire
);
3728 omap_pwl_reset(mpu
->pwl
);
3729 omap_pwt_reset(mpu
->pwt
);
3730 omap_rtc_reset(mpu
->rtc
);
3731 omap_mcbsp_reset(mpu
->mcbsp1
);
3732 omap_mcbsp_reset(mpu
->mcbsp2
);
3733 omap_mcbsp_reset(mpu
->mcbsp3
);
3734 omap_lpg_reset(mpu
->led
[0]);
3735 omap_lpg_reset(mpu
->led
[1]);
3736 omap_clkm_reset(mpu
);
3737 cpu_reset(CPU(mpu
->cpu
));
3740 static const struct omap_map_s
{
3745 } omap15xx_dsp_mm
[] = {
3747 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
3748 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
3749 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
3750 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
3751 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
3752 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
3753 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
3754 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
3755 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
3756 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
3757 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
3758 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
3759 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
3760 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
3761 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
3762 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
3763 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
3765 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
3770 static void omap_setup_dsp_mapping(MemoryRegion
*system_memory
,
3771 const struct omap_map_s
*map
)
3775 for (; map
->phys_dsp
; map
++) {
3776 io
= g_new(MemoryRegion
, 1);
3777 memory_region_init_alias(io
, NULL
, map
->name
,
3778 system_memory
, map
->phys_mpu
, map
->size
);
3779 memory_region_add_subregion(system_memory
, map
->phys_dsp
, io
);
3783 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
3785 struct omap_mpu_state_s
*mpu
= (struct omap_mpu_state_s
*) opaque
;
3786 CPUState
*cpu
= CPU(mpu
->cpu
);
3789 cpu_interrupt(cpu
, CPU_INTERRUPT_EXITTB
);
3793 static const struct dma_irq_map omap1_dma_irq_map
[] = {
3794 { 0, OMAP_INT_DMA_CH0_6
},
3795 { 0, OMAP_INT_DMA_CH1_7
},
3796 { 0, OMAP_INT_DMA_CH2_8
},
3797 { 0, OMAP_INT_DMA_CH3
},
3798 { 0, OMAP_INT_DMA_CH4
},
3799 { 0, OMAP_INT_DMA_CH5
},
3800 { 1, OMAP_INT_1610_DMA_CH6
},
3801 { 1, OMAP_INT_1610_DMA_CH7
},
3802 { 1, OMAP_INT_1610_DMA_CH8
},
3803 { 1, OMAP_INT_1610_DMA_CH9
},
3804 { 1, OMAP_INT_1610_DMA_CH10
},
3805 { 1, OMAP_INT_1610_DMA_CH11
},
3806 { 1, OMAP_INT_1610_DMA_CH12
},
3807 { 1, OMAP_INT_1610_DMA_CH13
},
3808 { 1, OMAP_INT_1610_DMA_CH14
},
3809 { 1, OMAP_INT_1610_DMA_CH15
}
3812 /* DMA ports for OMAP1 */
3813 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
3816 return range_covers_byte(OMAP_EMIFF_BASE
, s
->sdram_size
, addr
);
3819 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
3822 return range_covers_byte(OMAP_EMIFS_BASE
, OMAP_EMIFF_BASE
- OMAP_EMIFS_BASE
,
3826 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
3829 return range_covers_byte(OMAP_IMIF_BASE
, s
->sram_size
, addr
);
3832 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
3835 return range_covers_byte(0xfffb0000, 0xffff0000 - 0xfffb0000, addr
);
3838 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
3841 return range_covers_byte(OMAP_LOCALBUS_BASE
, 0x1000000, addr
);
3844 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
3847 return range_covers_byte(0xe1010000, 0xe1020004 - 0xe1010000, addr
);
3850 struct omap_mpu_state_s
*omap310_mpu_init(MemoryRegion
*system_memory
,
3851 unsigned long sdram_size
,
3852 const char *cpu_type
)
3855 struct omap_mpu_state_s
*s
= g_new0(struct omap_mpu_state_s
, 1);
3856 qemu_irq dma_irqs
[6];
3858 SysBusDevice
*busdev
;
3861 s
->mpu_model
= omap310
;
3862 s
->cpu
= ARM_CPU(cpu_create(cpu_type
));
3863 s
->sdram_size
= sdram_size
;
3864 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
3866 s
->wakeup
= qemu_allocate_irq(omap_mpu_wakeup
, s
, 0);
3871 /* Memory-mapped stuff */
3872 memory_region_allocate_system_memory(&s
->emiff_ram
, NULL
, "omap1.dram",
3874 memory_region_add_subregion(system_memory
, OMAP_EMIFF_BASE
, &s
->emiff_ram
);
3875 memory_region_init_ram(&s
->imif_ram
, NULL
, "omap1.sram", s
->sram_size
,
3877 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 error_report("missing SecureDigital device");
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
);