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"
22 #include "qemu/error-report.h"
23 #include "qemu/main-loop.h"
24 #include "qapi/error.h"
26 #include "exec/address-spaces.h"
29 #include "hw/qdev-properties.h"
30 #include "hw/arm/boot.h"
31 #include "hw/arm/omap.h"
32 #include "sysemu/blockdev.h"
33 #include "sysemu/sysemu.h"
34 #include "hw/arm/soc_dma.h"
35 #include "sysemu/qtest.h"
36 #include "sysemu/reset.h"
37 #include "sysemu/runstate.h"
38 #include "sysemu/rtc.h"
39 #include "qemu/range.h"
40 #include "hw/sysbus.h"
41 #include "qemu/cutils.h"
44 static inline void omap_log_badwidth(const char *funcname
, hwaddr addr
, int sz
)
46 qemu_log_mask(LOG_GUEST_ERROR
, "%s: %d-bit register %#08" HWADDR_PRIx
"\n",
47 funcname
, 8 * sz
, addr
);
50 /* Should signal the TCMI/GPMC */
51 uint32_t omap_badwidth_read8(void *opaque
, hwaddr addr
)
55 omap_log_badwidth(__func__
, addr
, 1);
56 cpu_physical_memory_read(addr
, &ret
, 1);
60 void omap_badwidth_write8(void *opaque
, hwaddr addr
,
65 omap_log_badwidth(__func__
, addr
, 1);
66 cpu_physical_memory_write(addr
, &val8
, 1);
69 uint32_t omap_badwidth_read16(void *opaque
, hwaddr addr
)
73 omap_log_badwidth(__func__
, addr
, 2);
74 cpu_physical_memory_read(addr
, &ret
, 2);
78 void omap_badwidth_write16(void *opaque
, hwaddr addr
,
81 uint16_t val16
= value
;
83 omap_log_badwidth(__func__
, addr
, 2);
84 cpu_physical_memory_write(addr
, &val16
, 2);
87 uint32_t omap_badwidth_read32(void *opaque
, hwaddr addr
)
91 omap_log_badwidth(__func__
, addr
, 4);
92 cpu_physical_memory_read(addr
, &ret
, 4);
96 void omap_badwidth_write32(void *opaque
, hwaddr addr
,
99 omap_log_badwidth(__func__
, addr
, 4);
100 cpu_physical_memory_write(addr
, &value
, 4);
104 struct omap_mpu_timer_s
{
122 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s
*timer
)
124 uint64_t distance
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) - timer
->time
;
126 if (timer
->st
&& timer
->enable
&& timer
->rate
)
127 return timer
->val
- muldiv64(distance
>> (timer
->ptv
+ 1),
128 timer
->rate
, NANOSECONDS_PER_SECOND
);
133 static inline void omap_timer_sync(struct omap_mpu_timer_s
*timer
)
135 timer
->val
= omap_timer_read(timer
);
136 timer
->time
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
139 static inline void omap_timer_update(struct omap_mpu_timer_s
*timer
)
143 if (timer
->enable
&& timer
->st
&& timer
->rate
) {
144 timer
->val
= timer
->reset_val
; /* Should skip this on clk enable */
145 expires
= muldiv64((uint64_t) timer
->val
<< (timer
->ptv
+ 1),
146 NANOSECONDS_PER_SECOND
, timer
->rate
);
148 /* If timer expiry would be sooner than in about 1 ms and
149 * auto-reload isn't set, then fire immediately. This is a hack
150 * to make systems like PalmOS run in acceptable time. PalmOS
151 * sets the interval to a very low value and polls the status bit
152 * in a busy loop when it wants to sleep just a couple of CPU
154 if (expires
> (NANOSECONDS_PER_SECOND
>> 10) || timer
->ar
) {
155 timer_mod(timer
->timer
, timer
->time
+ expires
);
157 qemu_bh_schedule(timer
->tick
);
160 timer_del(timer
->timer
);
163 static void omap_timer_fire(void *opaque
)
165 struct omap_mpu_timer_s
*timer
= opaque
;
173 /* Edge-triggered irq */
174 qemu_irq_pulse(timer
->irq
);
177 static void omap_timer_tick(void *opaque
)
179 struct omap_mpu_timer_s
*timer
= opaque
;
181 omap_timer_sync(timer
);
182 omap_timer_fire(timer
);
183 omap_timer_update(timer
);
186 static void omap_timer_clk_update(void *opaque
, int line
, int on
)
188 struct omap_mpu_timer_s
*timer
= opaque
;
190 omap_timer_sync(timer
);
191 timer
->rate
= on
? omap_clk_getrate(timer
->clk
) : 0;
192 omap_timer_update(timer
);
195 static void omap_timer_clk_setup(struct omap_mpu_timer_s
*timer
)
197 omap_clk_adduser(timer
->clk
,
198 qemu_allocate_irq(omap_timer_clk_update
, timer
, 0));
199 timer
->rate
= omap_clk_getrate(timer
->clk
);
202 static uint64_t omap_mpu_timer_read(void *opaque
, hwaddr addr
,
205 struct omap_mpu_timer_s
*s
= opaque
;
208 return omap_badwidth_read32(opaque
, addr
);
212 case 0x00: /* CNTL_TIMER */
213 return (s
->enable
<< 5) | (s
->ptv
<< 2) | (s
->ar
<< 1) | s
->st
;
215 case 0x04: /* LOAD_TIM */
218 case 0x08: /* READ_TIM */
219 return omap_timer_read(s
);
226 static void omap_mpu_timer_write(void *opaque
, hwaddr addr
,
227 uint64_t value
, unsigned size
)
229 struct omap_mpu_timer_s
*s
= opaque
;
232 omap_badwidth_write32(opaque
, addr
, value
);
237 case 0x00: /* CNTL_TIMER */
239 s
->enable
= (value
>> 5) & 1;
240 s
->ptv
= (value
>> 2) & 7;
241 s
->ar
= (value
>> 1) & 1;
243 omap_timer_update(s
);
246 case 0x04: /* LOAD_TIM */
247 s
->reset_val
= value
;
250 case 0x08: /* READ_TIM */
259 static const MemoryRegionOps omap_mpu_timer_ops
= {
260 .read
= omap_mpu_timer_read
,
261 .write
= omap_mpu_timer_write
,
262 .endianness
= DEVICE_LITTLE_ENDIAN
,
265 static void omap_mpu_timer_reset(struct omap_mpu_timer_s
*s
)
269 s
->reset_val
= 31337;
277 static struct omap_mpu_timer_s
*omap_mpu_timer_init(MemoryRegion
*system_memory
,
279 qemu_irq irq
, omap_clk clk
)
281 struct omap_mpu_timer_s
*s
= g_new0(struct omap_mpu_timer_s
, 1);
285 s
->timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, s
);
286 s
->tick
= qemu_bh_new(omap_timer_fire
, s
);
287 omap_mpu_timer_reset(s
);
288 omap_timer_clk_setup(s
);
290 memory_region_init_io(&s
->iomem
, NULL
, &omap_mpu_timer_ops
, s
,
291 "omap-mpu-timer", 0x100);
293 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
299 struct omap_watchdog_timer_s
{
300 struct omap_mpu_timer_s timer
;
308 static uint64_t omap_wd_timer_read(void *opaque
, hwaddr addr
,
311 struct omap_watchdog_timer_s
*s
= opaque
;
314 return omap_badwidth_read16(opaque
, addr
);
318 case 0x00: /* CNTL_TIMER */
319 return (s
->timer
.ptv
<< 9) | (s
->timer
.ar
<< 8) |
320 (s
->timer
.st
<< 7) | (s
->free
<< 1);
322 case 0x04: /* READ_TIMER */
323 return omap_timer_read(&s
->timer
);
325 case 0x08: /* TIMER_MODE */
326 return s
->mode
<< 15;
333 static void omap_wd_timer_write(void *opaque
, hwaddr addr
,
334 uint64_t value
, unsigned size
)
336 struct omap_watchdog_timer_s
*s
= opaque
;
339 omap_badwidth_write16(opaque
, addr
, value
);
344 case 0x00: /* CNTL_TIMER */
345 omap_timer_sync(&s
->timer
);
346 s
->timer
.ptv
= (value
>> 9) & 7;
347 s
->timer
.ar
= (value
>> 8) & 1;
348 s
->timer
.st
= (value
>> 7) & 1;
349 s
->free
= (value
>> 1) & 1;
350 omap_timer_update(&s
->timer
);
353 case 0x04: /* LOAD_TIMER */
354 s
->timer
.reset_val
= value
& 0xffff;
357 case 0x08: /* TIMER_MODE */
358 if (!s
->mode
&& ((value
>> 15) & 1))
359 omap_clk_get(s
->timer
.clk
);
360 s
->mode
|= (value
>> 15) & 1;
361 if (s
->last_wr
== 0xf5) {
362 if ((value
& 0xff) == 0xa0) {
365 omap_clk_put(s
->timer
.clk
);
368 /* XXX: on T|E hardware somehow this has no effect,
369 * on Zire 71 it works as specified. */
371 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
374 s
->last_wr
= value
& 0xff;
382 static const MemoryRegionOps omap_wd_timer_ops
= {
383 .read
= omap_wd_timer_read
,
384 .write
= omap_wd_timer_write
,
385 .endianness
= DEVICE_NATIVE_ENDIAN
,
388 static void omap_wd_timer_reset(struct omap_watchdog_timer_s
*s
)
390 timer_del(s
->timer
.timer
);
392 omap_clk_get(s
->timer
.clk
);
398 s
->timer
.reset_val
= 0xffff;
403 omap_timer_update(&s
->timer
);
406 static struct omap_watchdog_timer_s
*omap_wd_timer_init(MemoryRegion
*memory
,
408 qemu_irq irq
, omap_clk clk
)
410 struct omap_watchdog_timer_s
*s
= g_new0(struct omap_watchdog_timer_s
, 1);
414 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, &s
->timer
);
415 omap_wd_timer_reset(s
);
416 omap_timer_clk_setup(&s
->timer
);
418 memory_region_init_io(&s
->iomem
, NULL
, &omap_wd_timer_ops
, s
,
419 "omap-wd-timer", 0x100);
420 memory_region_add_subregion(memory
, base
, &s
->iomem
);
426 struct omap_32khz_timer_s
{
427 struct omap_mpu_timer_s timer
;
431 static uint64_t omap_os_timer_read(void *opaque
, hwaddr addr
,
434 struct omap_32khz_timer_s
*s
= opaque
;
435 int offset
= addr
& OMAP_MPUI_REG_MASK
;
438 return omap_badwidth_read32(opaque
, addr
);
443 return s
->timer
.reset_val
;
446 return omap_timer_read(&s
->timer
);
449 return (s
->timer
.ar
<< 3) | (s
->timer
.it_ena
<< 2) | s
->timer
.st
;
458 static void omap_os_timer_write(void *opaque
, hwaddr addr
,
459 uint64_t value
, unsigned size
)
461 struct omap_32khz_timer_s
*s
= opaque
;
462 int offset
= addr
& OMAP_MPUI_REG_MASK
;
465 omap_badwidth_write32(opaque
, addr
, value
);
471 s
->timer
.reset_val
= value
& 0x00ffffff;
479 s
->timer
.ar
= (value
>> 3) & 1;
480 s
->timer
.it_ena
= (value
>> 2) & 1;
481 if (s
->timer
.st
!= (value
& 1) || (value
& 2)) {
482 omap_timer_sync(&s
->timer
);
483 s
->timer
.enable
= value
& 1;
484 s
->timer
.st
= value
& 1;
485 omap_timer_update(&s
->timer
);
494 static const MemoryRegionOps omap_os_timer_ops
= {
495 .read
= omap_os_timer_read
,
496 .write
= omap_os_timer_write
,
497 .endianness
= DEVICE_NATIVE_ENDIAN
,
500 static void omap_os_timer_reset(struct omap_32khz_timer_s
*s
)
502 timer_del(s
->timer
.timer
);
505 s
->timer
.reset_val
= 0x00ffffff;
512 static struct omap_32khz_timer_s
*omap_os_timer_init(MemoryRegion
*memory
,
514 qemu_irq irq
, omap_clk clk
)
516 struct omap_32khz_timer_s
*s
= g_new0(struct omap_32khz_timer_s
, 1);
520 s
->timer
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_timer_tick
, &s
->timer
);
521 omap_os_timer_reset(s
);
522 omap_timer_clk_setup(&s
->timer
);
524 memory_region_init_io(&s
->iomem
, NULL
, &omap_os_timer_ops
, s
,
525 "omap-os-timer", 0x800);
526 memory_region_add_subregion(memory
, base
, &s
->iomem
);
531 /* Ultra Low-Power Device Module */
532 static uint64_t omap_ulpd_pm_read(void *opaque
, hwaddr addr
,
535 struct omap_mpu_state_s
*s
= opaque
;
539 return omap_badwidth_read16(opaque
, addr
);
543 case 0x14: /* IT_STATUS */
544 ret
= s
->ulpd_pm_regs
[addr
>> 2];
545 s
->ulpd_pm_regs
[addr
>> 2] = 0;
546 qemu_irq_lower(qdev_get_gpio_in(s
->ih
[1], OMAP_INT_GAUGE_32K
));
549 case 0x18: /* Reserved */
550 case 0x1c: /* Reserved */
551 case 0x20: /* Reserved */
552 case 0x28: /* Reserved */
553 case 0x2c: /* Reserved */
556 case 0x00: /* COUNTER_32_LSB */
557 case 0x04: /* COUNTER_32_MSB */
558 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
559 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
560 case 0x10: /* GAUGING_CTRL */
561 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
562 case 0x30: /* CLOCK_CTRL */
563 case 0x34: /* SOFT_REQ */
564 case 0x38: /* COUNTER_32_FIQ */
565 case 0x3c: /* DPLL_CTRL */
566 case 0x40: /* STATUS_REQ */
567 /* XXX: check clk::usecount state for every clock */
568 case 0x48: /* LOCL_TIME */
569 case 0x4c: /* APLL_CTRL */
570 case 0x50: /* POWER_CTRL */
571 return s
->ulpd_pm_regs
[addr
>> 2];
578 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s
*s
,
579 uint16_t diff
, uint16_t value
)
581 if (diff
& (1 << 4)) /* USB_MCLK_EN */
582 omap_clk_onoff(omap_findclk(s
, "usb_clk0"), (value
>> 4) & 1);
583 if (diff
& (1 << 5)) /* DIS_USB_PVCI_CLK */
584 omap_clk_onoff(omap_findclk(s
, "usb_w2fc_ck"), (~value
>> 5) & 1);
587 static inline void omap_ulpd_req_update(struct omap_mpu_state_s
*s
,
588 uint16_t diff
, uint16_t value
)
590 if (diff
& (1 << 0)) /* SOFT_DPLL_REQ */
591 omap_clk_canidle(omap_findclk(s
, "dpll4"), (~value
>> 0) & 1);
592 if (diff
& (1 << 1)) /* SOFT_COM_REQ */
593 omap_clk_canidle(omap_findclk(s
, "com_mclk_out"), (~value
>> 1) & 1);
594 if (diff
& (1 << 2)) /* SOFT_SDW_REQ */
595 omap_clk_canidle(omap_findclk(s
, "bt_mclk_out"), (~value
>> 2) & 1);
596 if (diff
& (1 << 3)) /* SOFT_USB_REQ */
597 omap_clk_canidle(omap_findclk(s
, "usb_clk0"), (~value
>> 3) & 1);
600 static void omap_ulpd_pm_write(void *opaque
, hwaddr addr
,
601 uint64_t value
, unsigned size
)
603 struct omap_mpu_state_s
*s
= opaque
;
606 static const int bypass_div
[4] = { 1, 2, 4, 4 };
610 omap_badwidth_write16(opaque
, addr
, value
);
615 case 0x00: /* COUNTER_32_LSB */
616 case 0x04: /* COUNTER_32_MSB */
617 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
618 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
619 case 0x14: /* IT_STATUS */
620 case 0x40: /* STATUS_REQ */
624 case 0x10: /* GAUGING_CTRL */
625 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
626 if ((s
->ulpd_pm_regs
[addr
>> 2] ^ value
) & 1) {
627 now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
630 s
->ulpd_gauge_start
= now
;
632 now
-= s
->ulpd_gauge_start
;
635 ticks
= muldiv64(now
, 32768, NANOSECONDS_PER_SECOND
);
636 s
->ulpd_pm_regs
[0x00 >> 2] = (ticks
>> 0) & 0xffff;
637 s
->ulpd_pm_regs
[0x04 >> 2] = (ticks
>> 16) & 0xffff;
638 if (ticks
>> 32) /* OVERFLOW_32K */
639 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 2;
641 /* High frequency ticks */
642 ticks
= muldiv64(now
, 12000000, NANOSECONDS_PER_SECOND
);
643 s
->ulpd_pm_regs
[0x08 >> 2] = (ticks
>> 0) & 0xffff;
644 s
->ulpd_pm_regs
[0x0c >> 2] = (ticks
>> 16) & 0xffff;
645 if (ticks
>> 32) /* OVERFLOW_HI_FREQ */
646 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 1;
648 s
->ulpd_pm_regs
[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
649 qemu_irq_raise(qdev_get_gpio_in(s
->ih
[1], OMAP_INT_GAUGE_32K
));
652 s
->ulpd_pm_regs
[addr
>> 2] = value
;
655 case 0x18: /* Reserved */
656 case 0x1c: /* Reserved */
657 case 0x20: /* Reserved */
658 case 0x28: /* Reserved */
659 case 0x2c: /* Reserved */
662 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
663 case 0x38: /* COUNTER_32_FIQ */
664 case 0x48: /* LOCL_TIME */
665 case 0x50: /* POWER_CTRL */
666 s
->ulpd_pm_regs
[addr
>> 2] = value
;
669 case 0x30: /* CLOCK_CTRL */
670 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
671 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x3f;
672 omap_ulpd_clk_update(s
, diff
, value
);
675 case 0x34: /* SOFT_REQ */
676 diff
= s
->ulpd_pm_regs
[addr
>> 2] ^ value
;
677 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x1f;
678 omap_ulpd_req_update(s
, diff
, value
);
681 case 0x3c: /* DPLL_CTRL */
682 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
683 * omitted altogether, probably a typo. */
684 /* This register has identical semantics with DPLL(1:3) control
685 * registers, see omap_dpll_write() */
686 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
687 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0x2fff;
688 if (diff
& (0x3ff << 2)) {
689 if (value
& (1 << 4)) { /* PLL_ENABLE */
690 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
691 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
693 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
696 omap_clk_setrate(omap_findclk(s
, "dpll4"), div
, mult
);
699 /* Enter the desired mode. */
700 s
->ulpd_pm_regs
[addr
>> 2] =
701 (s
->ulpd_pm_regs
[addr
>> 2] & 0xfffe) |
702 ((s
->ulpd_pm_regs
[addr
>> 2] >> 4) & 1);
704 /* Act as if the lock is restored. */
705 s
->ulpd_pm_regs
[addr
>> 2] |= 2;
708 case 0x4c: /* APLL_CTRL */
709 diff
= s
->ulpd_pm_regs
[addr
>> 2] & value
;
710 s
->ulpd_pm_regs
[addr
>> 2] = value
& 0xf;
711 if (diff
& (1 << 0)) /* APLL_NDPLL_SWITCH */
712 omap_clk_reparent(omap_findclk(s
, "ck_48m"), omap_findclk(s
,
713 (value
& (1 << 0)) ? "apll" : "dpll4"));
721 static const MemoryRegionOps omap_ulpd_pm_ops
= {
722 .read
= omap_ulpd_pm_read
,
723 .write
= omap_ulpd_pm_write
,
724 .endianness
= DEVICE_NATIVE_ENDIAN
,
727 static void omap_ulpd_pm_reset(struct omap_mpu_state_s
*mpu
)
729 mpu
->ulpd_pm_regs
[0x00 >> 2] = 0x0001;
730 mpu
->ulpd_pm_regs
[0x04 >> 2] = 0x0000;
731 mpu
->ulpd_pm_regs
[0x08 >> 2] = 0x0001;
732 mpu
->ulpd_pm_regs
[0x0c >> 2] = 0x0000;
733 mpu
->ulpd_pm_regs
[0x10 >> 2] = 0x0000;
734 mpu
->ulpd_pm_regs
[0x18 >> 2] = 0x01;
735 mpu
->ulpd_pm_regs
[0x1c >> 2] = 0x01;
736 mpu
->ulpd_pm_regs
[0x20 >> 2] = 0x01;
737 mpu
->ulpd_pm_regs
[0x24 >> 2] = 0x03ff;
738 mpu
->ulpd_pm_regs
[0x28 >> 2] = 0x01;
739 mpu
->ulpd_pm_regs
[0x2c >> 2] = 0x01;
740 omap_ulpd_clk_update(mpu
, mpu
->ulpd_pm_regs
[0x30 >> 2], 0x0000);
741 mpu
->ulpd_pm_regs
[0x30 >> 2] = 0x0000;
742 omap_ulpd_req_update(mpu
, mpu
->ulpd_pm_regs
[0x34 >> 2], 0x0000);
743 mpu
->ulpd_pm_regs
[0x34 >> 2] = 0x0000;
744 mpu
->ulpd_pm_regs
[0x38 >> 2] = 0x0001;
745 mpu
->ulpd_pm_regs
[0x3c >> 2] = 0x2211;
746 mpu
->ulpd_pm_regs
[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
747 mpu
->ulpd_pm_regs
[0x48 >> 2] = 0x960;
748 mpu
->ulpd_pm_regs
[0x4c >> 2] = 0x08;
749 mpu
->ulpd_pm_regs
[0x50 >> 2] = 0x08;
750 omap_clk_setrate(omap_findclk(mpu
, "dpll4"), 1, 4);
751 omap_clk_reparent(omap_findclk(mpu
, "ck_48m"), omap_findclk(mpu
, "dpll4"));
754 static void omap_ulpd_pm_init(MemoryRegion
*system_memory
,
756 struct omap_mpu_state_s
*mpu
)
758 memory_region_init_io(&mpu
->ulpd_pm_iomem
, NULL
, &omap_ulpd_pm_ops
, mpu
,
759 "omap-ulpd-pm", 0x800);
760 memory_region_add_subregion(system_memory
, base
, &mpu
->ulpd_pm_iomem
);
761 omap_ulpd_pm_reset(mpu
);
764 /* OMAP Pin Configuration */
765 static uint64_t omap_pin_cfg_read(void *opaque
, hwaddr addr
,
768 struct omap_mpu_state_s
*s
= opaque
;
771 return omap_badwidth_read32(opaque
, addr
);
775 case 0x00: /* FUNC_MUX_CTRL_0 */
776 case 0x04: /* FUNC_MUX_CTRL_1 */
777 case 0x08: /* FUNC_MUX_CTRL_2 */
778 return s
->func_mux_ctrl
[addr
>> 2];
780 case 0x0c: /* COMP_MODE_CTRL_0 */
781 return s
->comp_mode_ctrl
[0];
783 case 0x10: /* FUNC_MUX_CTRL_3 */
784 case 0x14: /* FUNC_MUX_CTRL_4 */
785 case 0x18: /* FUNC_MUX_CTRL_5 */
786 case 0x1c: /* FUNC_MUX_CTRL_6 */
787 case 0x20: /* FUNC_MUX_CTRL_7 */
788 case 0x24: /* FUNC_MUX_CTRL_8 */
789 case 0x28: /* FUNC_MUX_CTRL_9 */
790 case 0x2c: /* FUNC_MUX_CTRL_A */
791 case 0x30: /* FUNC_MUX_CTRL_B */
792 case 0x34: /* FUNC_MUX_CTRL_C */
793 case 0x38: /* FUNC_MUX_CTRL_D */
794 return s
->func_mux_ctrl
[(addr
>> 2) - 1];
796 case 0x40: /* PULL_DWN_CTRL_0 */
797 case 0x44: /* PULL_DWN_CTRL_1 */
798 case 0x48: /* PULL_DWN_CTRL_2 */
799 case 0x4c: /* PULL_DWN_CTRL_3 */
800 return s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2];
802 case 0x50: /* GATE_INH_CTRL_0 */
803 return s
->gate_inh_ctrl
[0];
805 case 0x60: /* VOLTAGE_CTRL_0 */
806 return s
->voltage_ctrl
[0];
808 case 0x70: /* TEST_DBG_CTRL_0 */
809 return s
->test_dbg_ctrl
[0];
811 case 0x80: /* MOD_CONF_CTRL_0 */
812 return s
->mod_conf_ctrl
[0];
819 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s
*s
,
820 uint32_t diff
, uint32_t value
)
823 if (diff
& (1 << 9)) /* BLUETOOTH */
824 omap_clk_onoff(omap_findclk(s
, "bt_mclk_out"),
826 if (diff
& (1 << 7)) /* USB.CLKO */
827 omap_clk_onoff(omap_findclk(s
, "usb.clko"),
832 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s
*s
,
833 uint32_t diff
, uint32_t value
)
836 if (diff
& (1U << 31)) {
837 /* MCBSP3_CLK_HIZ_DI */
838 omap_clk_onoff(omap_findclk(s
, "mcbsp3.clkx"), (value
>> 31) & 1);
840 if (diff
& (1 << 1)) {
842 omap_clk_onoff(omap_findclk(s
, "clk32k_out"), (~value
>> 1) & 1);
847 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s
*s
,
848 uint32_t diff
, uint32_t value
)
850 if (diff
& (1U << 31)) {
851 /* CONF_MOD_UART3_CLK_MODE_R */
852 omap_clk_reparent(omap_findclk(s
, "uart3_ck"),
853 omap_findclk(s
, ((value
>> 31) & 1) ?
854 "ck_48m" : "armper_ck"));
856 if (diff
& (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
857 omap_clk_reparent(omap_findclk(s
, "uart2_ck"),
858 omap_findclk(s
, ((value
>> 30) & 1) ?
859 "ck_48m" : "armper_ck"));
860 if (diff
& (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
861 omap_clk_reparent(omap_findclk(s
, "uart1_ck"),
862 omap_findclk(s
, ((value
>> 29) & 1) ?
863 "ck_48m" : "armper_ck"));
864 if (diff
& (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
865 omap_clk_reparent(omap_findclk(s
, "mmc_ck"),
866 omap_findclk(s
, ((value
>> 23) & 1) ?
867 "ck_48m" : "armper_ck"));
868 if (diff
& (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
869 omap_clk_reparent(omap_findclk(s
, "com_mclk_out"),
870 omap_findclk(s
, ((value
>> 12) & 1) ?
871 "ck_48m" : "armper_ck"));
872 if (diff
& (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
873 omap_clk_onoff(omap_findclk(s
, "usb_hhc_ck"), (value
>> 9) & 1);
876 static void omap_pin_cfg_write(void *opaque
, hwaddr addr
,
877 uint64_t value
, unsigned size
)
879 struct omap_mpu_state_s
*s
= opaque
;
883 omap_badwidth_write32(opaque
, addr
, value
);
888 case 0x00: /* FUNC_MUX_CTRL_0 */
889 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
890 s
->func_mux_ctrl
[addr
>> 2] = value
;
891 omap_pin_funcmux0_update(s
, diff
, value
);
894 case 0x04: /* FUNC_MUX_CTRL_1 */
895 diff
= s
->func_mux_ctrl
[addr
>> 2] ^ value
;
896 s
->func_mux_ctrl
[addr
>> 2] = value
;
897 omap_pin_funcmux1_update(s
, diff
, value
);
900 case 0x08: /* FUNC_MUX_CTRL_2 */
901 s
->func_mux_ctrl
[addr
>> 2] = value
;
904 case 0x0c: /* COMP_MODE_CTRL_0 */
905 s
->comp_mode_ctrl
[0] = value
;
906 s
->compat1509
= (value
!= 0x0000eaef);
907 omap_pin_funcmux0_update(s
, ~0, s
->func_mux_ctrl
[0]);
908 omap_pin_funcmux1_update(s
, ~0, s
->func_mux_ctrl
[1]);
911 case 0x10: /* FUNC_MUX_CTRL_3 */
912 case 0x14: /* FUNC_MUX_CTRL_4 */
913 case 0x18: /* FUNC_MUX_CTRL_5 */
914 case 0x1c: /* FUNC_MUX_CTRL_6 */
915 case 0x20: /* FUNC_MUX_CTRL_7 */
916 case 0x24: /* FUNC_MUX_CTRL_8 */
917 case 0x28: /* FUNC_MUX_CTRL_9 */
918 case 0x2c: /* FUNC_MUX_CTRL_A */
919 case 0x30: /* FUNC_MUX_CTRL_B */
920 case 0x34: /* FUNC_MUX_CTRL_C */
921 case 0x38: /* FUNC_MUX_CTRL_D */
922 s
->func_mux_ctrl
[(addr
>> 2) - 1] = value
;
925 case 0x40: /* PULL_DWN_CTRL_0 */
926 case 0x44: /* PULL_DWN_CTRL_1 */
927 case 0x48: /* PULL_DWN_CTRL_2 */
928 case 0x4c: /* PULL_DWN_CTRL_3 */
929 s
->pull_dwn_ctrl
[(addr
& 0xf) >> 2] = value
;
932 case 0x50: /* GATE_INH_CTRL_0 */
933 s
->gate_inh_ctrl
[0] = value
;
936 case 0x60: /* VOLTAGE_CTRL_0 */
937 s
->voltage_ctrl
[0] = value
;
940 case 0x70: /* TEST_DBG_CTRL_0 */
941 s
->test_dbg_ctrl
[0] = value
;
944 case 0x80: /* MOD_CONF_CTRL_0 */
945 diff
= s
->mod_conf_ctrl
[0] ^ value
;
946 s
->mod_conf_ctrl
[0] = value
;
947 omap_pin_modconf1_update(s
, diff
, value
);
955 static const MemoryRegionOps omap_pin_cfg_ops
= {
956 .read
= omap_pin_cfg_read
,
957 .write
= omap_pin_cfg_write
,
958 .endianness
= DEVICE_NATIVE_ENDIAN
,
961 static void omap_pin_cfg_reset(struct omap_mpu_state_s
*mpu
)
963 /* Start in Compatibility Mode. */
965 omap_pin_funcmux0_update(mpu
, mpu
->func_mux_ctrl
[0], 0);
966 omap_pin_funcmux1_update(mpu
, mpu
->func_mux_ctrl
[1], 0);
967 omap_pin_modconf1_update(mpu
, mpu
->mod_conf_ctrl
[0], 0);
968 memset(mpu
->func_mux_ctrl
, 0, sizeof(mpu
->func_mux_ctrl
));
969 memset(mpu
->comp_mode_ctrl
, 0, sizeof(mpu
->comp_mode_ctrl
));
970 memset(mpu
->pull_dwn_ctrl
, 0, sizeof(mpu
->pull_dwn_ctrl
));
971 memset(mpu
->gate_inh_ctrl
, 0, sizeof(mpu
->gate_inh_ctrl
));
972 memset(mpu
->voltage_ctrl
, 0, sizeof(mpu
->voltage_ctrl
));
973 memset(mpu
->test_dbg_ctrl
, 0, sizeof(mpu
->test_dbg_ctrl
));
974 memset(mpu
->mod_conf_ctrl
, 0, sizeof(mpu
->mod_conf_ctrl
));
977 static void omap_pin_cfg_init(MemoryRegion
*system_memory
,
979 struct omap_mpu_state_s
*mpu
)
981 memory_region_init_io(&mpu
->pin_cfg_iomem
, NULL
, &omap_pin_cfg_ops
, mpu
,
982 "omap-pin-cfg", 0x800);
983 memory_region_add_subregion(system_memory
, base
, &mpu
->pin_cfg_iomem
);
984 omap_pin_cfg_reset(mpu
);
987 /* Device Identification, Die Identification */
988 static uint64_t omap_id_read(void *opaque
, hwaddr addr
,
991 struct omap_mpu_state_s
*s
= opaque
;
994 return omap_badwidth_read32(opaque
, addr
);
998 case 0xfffe1800: /* DIE_ID_LSB */
1000 case 0xfffe1804: /* DIE_ID_MSB */
1003 case 0xfffe2000: /* PRODUCT_ID_LSB */
1005 case 0xfffe2004: /* PRODUCT_ID_MSB */
1008 case 0xfffed400: /* JTAG_ID_LSB */
1009 switch (s
->mpu_model
) {
1015 hw_error("%s: bad mpu model\n", __func__
);
1019 case 0xfffed404: /* JTAG_ID_MSB */
1020 switch (s
->mpu_model
) {
1026 hw_error("%s: bad mpu model\n", __func__
);
1035 static void omap_id_write(void *opaque
, hwaddr addr
,
1036 uint64_t value
, unsigned size
)
1039 omap_badwidth_write32(opaque
, addr
, value
);
1046 static const MemoryRegionOps omap_id_ops
= {
1047 .read
= omap_id_read
,
1048 .write
= omap_id_write
,
1049 .endianness
= DEVICE_NATIVE_ENDIAN
,
1052 static void omap_id_init(MemoryRegion
*memory
, struct omap_mpu_state_s
*mpu
)
1054 memory_region_init_io(&mpu
->id_iomem
, NULL
, &omap_id_ops
, mpu
,
1055 "omap-id", 0x100000000ULL
);
1056 memory_region_init_alias(&mpu
->id_iomem_e18
, NULL
, "omap-id-e18", &mpu
->id_iomem
,
1058 memory_region_add_subregion(memory
, 0xfffe1800, &mpu
->id_iomem_e18
);
1059 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-ed4", &mpu
->id_iomem
,
1061 memory_region_add_subregion(memory
, 0xfffed400, &mpu
->id_iomem_ed4
);
1062 if (!cpu_is_omap15xx(mpu
)) {
1063 memory_region_init_alias(&mpu
->id_iomem_ed4
, NULL
, "omap-id-e20",
1064 &mpu
->id_iomem
, 0xfffe2000, 0x800);
1065 memory_region_add_subregion(memory
, 0xfffe2000, &mpu
->id_iomem_e20
);
1069 /* MPUI Control (Dummy) */
1070 static uint64_t omap_mpui_read(void *opaque
, hwaddr addr
,
1073 struct omap_mpu_state_s
*s
= opaque
;
1076 return omap_badwidth_read32(opaque
, addr
);
1080 case 0x00: /* CTRL */
1081 return s
->mpui_ctrl
;
1082 case 0x04: /* DEBUG_ADDR */
1084 case 0x08: /* DEBUG_DATA */
1086 case 0x0c: /* DEBUG_FLAG */
1088 case 0x10: /* STATUS */
1091 /* Not in OMAP310 */
1092 case 0x14: /* DSP_STATUS */
1093 case 0x18: /* DSP_BOOT_CONFIG */
1095 case 0x1c: /* DSP_MPUI_CONFIG */
1103 static void omap_mpui_write(void *opaque
, hwaddr addr
,
1104 uint64_t value
, unsigned size
)
1106 struct omap_mpu_state_s
*s
= opaque
;
1109 omap_badwidth_write32(opaque
, addr
, value
);
1114 case 0x00: /* CTRL */
1115 s
->mpui_ctrl
= value
& 0x007fffff;
1118 case 0x04: /* DEBUG_ADDR */
1119 case 0x08: /* DEBUG_DATA */
1120 case 0x0c: /* DEBUG_FLAG */
1121 case 0x10: /* STATUS */
1122 /* Not in OMAP310 */
1123 case 0x14: /* DSP_STATUS */
1126 case 0x18: /* DSP_BOOT_CONFIG */
1127 case 0x1c: /* DSP_MPUI_CONFIG */
1135 static const MemoryRegionOps omap_mpui_ops
= {
1136 .read
= omap_mpui_read
,
1137 .write
= omap_mpui_write
,
1138 .endianness
= DEVICE_NATIVE_ENDIAN
,
1141 static void omap_mpui_reset(struct omap_mpu_state_s
*s
)
1143 s
->mpui_ctrl
= 0x0003ff1b;
1146 static void omap_mpui_init(MemoryRegion
*memory
, hwaddr base
,
1147 struct omap_mpu_state_s
*mpu
)
1149 memory_region_init_io(&mpu
->mpui_iomem
, NULL
, &omap_mpui_ops
, mpu
,
1150 "omap-mpui", 0x100);
1151 memory_region_add_subregion(memory
, base
, &mpu
->mpui_iomem
);
1153 omap_mpui_reset(mpu
);
1157 struct omap_tipb_bridge_s
{
1165 uint16_t enh_control
;
1168 static uint64_t omap_tipb_bridge_read(void *opaque
, hwaddr addr
,
1171 struct omap_tipb_bridge_s
*s
= opaque
;
1174 return omap_badwidth_read16(opaque
, addr
);
1178 case 0x00: /* TIPB_CNTL */
1180 case 0x04: /* TIPB_BUS_ALLOC */
1182 case 0x08: /* MPU_TIPB_CNTL */
1184 case 0x0c: /* ENHANCED_TIPB_CNTL */
1185 return s
->enh_control
;
1186 case 0x10: /* ADDRESS_DBG */
1187 case 0x14: /* DATA_DEBUG_LOW */
1188 case 0x18: /* DATA_DEBUG_HIGH */
1190 case 0x1c: /* DEBUG_CNTR_SIG */
1198 static void omap_tipb_bridge_write(void *opaque
, hwaddr addr
,
1199 uint64_t value
, unsigned size
)
1201 struct omap_tipb_bridge_s
*s
= opaque
;
1204 omap_badwidth_write16(opaque
, addr
, value
);
1209 case 0x00: /* TIPB_CNTL */
1210 s
->control
= value
& 0xffff;
1213 case 0x04: /* TIPB_BUS_ALLOC */
1214 s
->alloc
= value
& 0x003f;
1217 case 0x08: /* MPU_TIPB_CNTL */
1218 s
->buffer
= value
& 0x0003;
1221 case 0x0c: /* ENHANCED_TIPB_CNTL */
1222 s
->width_intr
= !(value
& 2);
1223 s
->enh_control
= value
& 0x000f;
1226 case 0x10: /* ADDRESS_DBG */
1227 case 0x14: /* DATA_DEBUG_LOW */
1228 case 0x18: /* DATA_DEBUG_HIGH */
1229 case 0x1c: /* DEBUG_CNTR_SIG */
1238 static const MemoryRegionOps omap_tipb_bridge_ops
= {
1239 .read
= omap_tipb_bridge_read
,
1240 .write
= omap_tipb_bridge_write
,
1241 .endianness
= DEVICE_NATIVE_ENDIAN
,
1244 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s
*s
)
1246 s
->control
= 0xffff;
1249 s
->enh_control
= 0x000f;
1252 static struct omap_tipb_bridge_s
*omap_tipb_bridge_init(
1253 MemoryRegion
*memory
, hwaddr base
,
1254 qemu_irq abort_irq
, omap_clk clk
)
1256 struct omap_tipb_bridge_s
*s
= g_new0(struct omap_tipb_bridge_s
, 1);
1258 s
->abort
= abort_irq
;
1259 omap_tipb_bridge_reset(s
);
1261 memory_region_init_io(&s
->iomem
, NULL
, &omap_tipb_bridge_ops
, s
,
1262 "omap-tipb-bridge", 0x100);
1263 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1268 /* Dummy Traffic Controller's Memory Interface */
1269 static uint64_t omap_tcmi_read(void *opaque
, hwaddr addr
,
1272 struct omap_mpu_state_s
*s
= opaque
;
1276 return omap_badwidth_read32(opaque
, addr
);
1280 case 0x00: /* IMIF_PRIO */
1281 case 0x04: /* EMIFS_PRIO */
1282 case 0x08: /* EMIFF_PRIO */
1283 case 0x0c: /* EMIFS_CONFIG */
1284 case 0x10: /* EMIFS_CS0_CONFIG */
1285 case 0x14: /* EMIFS_CS1_CONFIG */
1286 case 0x18: /* EMIFS_CS2_CONFIG */
1287 case 0x1c: /* EMIFS_CS3_CONFIG */
1288 case 0x24: /* EMIFF_MRS */
1289 case 0x28: /* TIMEOUT1 */
1290 case 0x2c: /* TIMEOUT2 */
1291 case 0x30: /* TIMEOUT3 */
1292 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1293 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1294 return s
->tcmi_regs
[addr
>> 2];
1296 case 0x20: /* EMIFF_SDRAM_CONFIG */
1297 ret
= s
->tcmi_regs
[addr
>> 2];
1298 s
->tcmi_regs
[addr
>> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1299 /* XXX: We can try using the VGA_DIRTY flag for this */
1307 static void omap_tcmi_write(void *opaque
, hwaddr addr
,
1308 uint64_t value
, unsigned size
)
1310 struct omap_mpu_state_s
*s
= opaque
;
1313 omap_badwidth_write32(opaque
, addr
, value
);
1318 case 0x00: /* IMIF_PRIO */
1319 case 0x04: /* EMIFS_PRIO */
1320 case 0x08: /* EMIFF_PRIO */
1321 case 0x10: /* EMIFS_CS0_CONFIG */
1322 case 0x14: /* EMIFS_CS1_CONFIG */
1323 case 0x18: /* EMIFS_CS2_CONFIG */
1324 case 0x1c: /* EMIFS_CS3_CONFIG */
1325 case 0x20: /* EMIFF_SDRAM_CONFIG */
1326 case 0x24: /* EMIFF_MRS */
1327 case 0x28: /* TIMEOUT1 */
1328 case 0x2c: /* TIMEOUT2 */
1329 case 0x30: /* TIMEOUT3 */
1330 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1331 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1332 s
->tcmi_regs
[addr
>> 2] = value
;
1334 case 0x0c: /* EMIFS_CONFIG */
1335 s
->tcmi_regs
[addr
>> 2] = (value
& 0xf) | (1 << 4);
1343 static const MemoryRegionOps omap_tcmi_ops
= {
1344 .read
= omap_tcmi_read
,
1345 .write
= omap_tcmi_write
,
1346 .endianness
= DEVICE_NATIVE_ENDIAN
,
1349 static void omap_tcmi_reset(struct omap_mpu_state_s
*mpu
)
1351 mpu
->tcmi_regs
[0x00 >> 2] = 0x00000000;
1352 mpu
->tcmi_regs
[0x04 >> 2] = 0x00000000;
1353 mpu
->tcmi_regs
[0x08 >> 2] = 0x00000000;
1354 mpu
->tcmi_regs
[0x0c >> 2] = 0x00000010;
1355 mpu
->tcmi_regs
[0x10 >> 2] = 0x0010fffb;
1356 mpu
->tcmi_regs
[0x14 >> 2] = 0x0010fffb;
1357 mpu
->tcmi_regs
[0x18 >> 2] = 0x0010fffb;
1358 mpu
->tcmi_regs
[0x1c >> 2] = 0x0010fffb;
1359 mpu
->tcmi_regs
[0x20 >> 2] = 0x00618800;
1360 mpu
->tcmi_regs
[0x24 >> 2] = 0x00000037;
1361 mpu
->tcmi_regs
[0x28 >> 2] = 0x00000000;
1362 mpu
->tcmi_regs
[0x2c >> 2] = 0x00000000;
1363 mpu
->tcmi_regs
[0x30 >> 2] = 0x00000000;
1364 mpu
->tcmi_regs
[0x3c >> 2] = 0x00000003;
1365 mpu
->tcmi_regs
[0x40 >> 2] = 0x00000000;
1368 static void omap_tcmi_init(MemoryRegion
*memory
, hwaddr base
,
1369 struct omap_mpu_state_s
*mpu
)
1371 memory_region_init_io(&mpu
->tcmi_iomem
, NULL
, &omap_tcmi_ops
, mpu
,
1372 "omap-tcmi", 0x100);
1373 memory_region_add_subregion(memory
, base
, &mpu
->tcmi_iomem
);
1374 omap_tcmi_reset(mpu
);
1377 /* Digital phase-locked loops control */
1384 static uint64_t omap_dpll_read(void *opaque
, hwaddr addr
,
1387 struct dpll_ctl_s
*s
= opaque
;
1390 return omap_badwidth_read16(opaque
, addr
);
1393 if (addr
== 0x00) /* CTL_REG */
1400 static void omap_dpll_write(void *opaque
, hwaddr addr
,
1401 uint64_t value
, unsigned size
)
1403 struct dpll_ctl_s
*s
= opaque
;
1405 static const int bypass_div
[4] = { 1, 2, 4, 4 };
1409 omap_badwidth_write16(opaque
, addr
, value
);
1413 if (addr
== 0x00) { /* CTL_REG */
1414 /* See omap_ulpd_pm_write() too */
1415 diff
= s
->mode
& value
;
1416 s
->mode
= value
& 0x2fff;
1417 if (diff
& (0x3ff << 2)) {
1418 if (value
& (1 << 4)) { /* PLL_ENABLE */
1419 div
= ((value
>> 5) & 3) + 1; /* PLL_DIV */
1420 mult
= MIN((value
>> 7) & 0x1f, 1); /* PLL_MULT */
1422 div
= bypass_div
[((value
>> 2) & 3)]; /* BYPASS_DIV */
1425 omap_clk_setrate(s
->dpll
, div
, mult
);
1428 /* Enter the desired mode. */
1429 s
->mode
= (s
->mode
& 0xfffe) | ((s
->mode
>> 4) & 1);
1431 /* Act as if the lock is restored. */
1438 static const MemoryRegionOps omap_dpll_ops
= {
1439 .read
= omap_dpll_read
,
1440 .write
= omap_dpll_write
,
1441 .endianness
= DEVICE_NATIVE_ENDIAN
,
1444 static void omap_dpll_reset(struct dpll_ctl_s
*s
)
1447 omap_clk_setrate(s
->dpll
, 1, 1);
1450 static struct dpll_ctl_s
*omap_dpll_init(MemoryRegion
*memory
,
1451 hwaddr base
, omap_clk clk
)
1453 struct dpll_ctl_s
*s
= g_malloc0(sizeof(*s
));
1454 memory_region_init_io(&s
->iomem
, NULL
, &omap_dpll_ops
, s
, "omap-dpll", 0x100);
1459 memory_region_add_subregion(memory
, base
, &s
->iomem
);
1463 /* MPU Clock/Reset/Power Mode Control */
1464 static uint64_t omap_clkm_read(void *opaque
, hwaddr addr
,
1467 struct omap_mpu_state_s
*s
= opaque
;
1470 return omap_badwidth_read16(opaque
, addr
);
1474 case 0x00: /* ARM_CKCTL */
1475 return s
->clkm
.arm_ckctl
;
1477 case 0x04: /* ARM_IDLECT1 */
1478 return s
->clkm
.arm_idlect1
;
1480 case 0x08: /* ARM_IDLECT2 */
1481 return s
->clkm
.arm_idlect2
;
1483 case 0x0c: /* ARM_EWUPCT */
1484 return s
->clkm
.arm_ewupct
;
1486 case 0x10: /* ARM_RSTCT1 */
1487 return s
->clkm
.arm_rstct1
;
1489 case 0x14: /* ARM_RSTCT2 */
1490 return s
->clkm
.arm_rstct2
;
1492 case 0x18: /* ARM_SYSST */
1493 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
;
1495 case 0x1c: /* ARM_CKOUT1 */
1496 return s
->clkm
.arm_ckout1
;
1498 case 0x20: /* ARM_CKOUT2 */
1506 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s
*s
,
1507 uint16_t diff
, uint16_t value
)
1511 if (diff
& (1 << 14)) { /* ARM_INTHCK_SEL */
1512 if (value
& (1 << 14))
1515 clk
= omap_findclk(s
, "arminth_ck");
1516 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1519 if (diff
& (1 << 12)) { /* ARM_TIMXO */
1520 clk
= omap_findclk(s
, "armtim_ck");
1521 if (value
& (1 << 12))
1522 omap_clk_reparent(clk
, omap_findclk(s
, "clkin"));
1524 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1527 if (diff
& (3 << 10)) { /* DSPMMUDIV */
1528 clk
= omap_findclk(s
, "dspmmu_ck");
1529 omap_clk_setrate(clk
, 1 << ((value
>> 10) & 3), 1);
1531 if (diff
& (3 << 8)) { /* TCDIV */
1532 clk
= omap_findclk(s
, "tc_ck");
1533 omap_clk_setrate(clk
, 1 << ((value
>> 8) & 3), 1);
1535 if (diff
& (3 << 6)) { /* DSPDIV */
1536 clk
= omap_findclk(s
, "dsp_ck");
1537 omap_clk_setrate(clk
, 1 << ((value
>> 6) & 3), 1);
1539 if (diff
& (3 << 4)) { /* ARMDIV */
1540 clk
= omap_findclk(s
, "arm_ck");
1541 omap_clk_setrate(clk
, 1 << ((value
>> 4) & 3), 1);
1543 if (diff
& (3 << 2)) { /* LCDDIV */
1544 clk
= omap_findclk(s
, "lcd_ck");
1545 omap_clk_setrate(clk
, 1 << ((value
>> 2) & 3), 1);
1547 if (diff
& (3 << 0)) { /* PERDIV */
1548 clk
= omap_findclk(s
, "armper_ck");
1549 omap_clk_setrate(clk
, 1 << ((value
>> 0) & 3), 1);
1553 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s
*s
,
1554 uint16_t diff
, uint16_t value
)
1558 if (value
& (1 << 11)) { /* SETARM_IDLE */
1559 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
1561 if (!(value
& (1 << 10))) { /* WKUP_MODE */
1562 /* XXX: disable wakeup from IRQ */
1563 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
1566 #define SET_CANIDLE(clock, bit) \
1567 if (diff & (1 << bit)) { \
1568 clk = omap_findclk(s, clock); \
1569 omap_clk_canidle(clk, (value >> bit) & 1); \
1571 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
1572 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
1573 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
1574 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
1575 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
1576 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
1577 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
1578 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
1579 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
1580 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
1581 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
1582 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
1583 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
1584 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
1587 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s
*s
,
1588 uint16_t diff
, uint16_t value
)
1592 #define SET_ONOFF(clock, bit) \
1593 if (diff & (1 << bit)) { \
1594 clk = omap_findclk(s, clock); \
1595 omap_clk_onoff(clk, (value >> bit) & 1); \
1597 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
1598 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
1599 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
1600 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
1601 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
1602 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
1603 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
1604 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
1605 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
1606 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
1607 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
1610 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s
*s
,
1611 uint16_t diff
, uint16_t value
)
1615 if (diff
& (3 << 4)) { /* TCLKOUT */
1616 clk
= omap_findclk(s
, "tclk_out");
1617 switch ((value
>> 4) & 3) {
1619 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen3"));
1620 omap_clk_onoff(clk
, 1);
1623 omap_clk_reparent(clk
, omap_findclk(s
, "tc_ck"));
1624 omap_clk_onoff(clk
, 1);
1627 omap_clk_onoff(clk
, 0);
1630 if (diff
& (3 << 2)) { /* DCLKOUT */
1631 clk
= omap_findclk(s
, "dclk_out");
1632 switch ((value
>> 2) & 3) {
1634 omap_clk_reparent(clk
, omap_findclk(s
, "dspmmu_ck"));
1637 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen2"));
1640 omap_clk_reparent(clk
, omap_findclk(s
, "dsp_ck"));
1643 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1647 if (diff
& (3 << 0)) { /* ACLKOUT */
1648 clk
= omap_findclk(s
, "aclk_out");
1649 switch ((value
>> 0) & 3) {
1651 omap_clk_reparent(clk
, omap_findclk(s
, "ck_gen1"));
1652 omap_clk_onoff(clk
, 1);
1655 omap_clk_reparent(clk
, omap_findclk(s
, "arm_ck"));
1656 omap_clk_onoff(clk
, 1);
1659 omap_clk_reparent(clk
, omap_findclk(s
, "ck_ref14"));
1660 omap_clk_onoff(clk
, 1);
1663 omap_clk_onoff(clk
, 0);
1668 static void omap_clkm_write(void *opaque
, hwaddr addr
,
1669 uint64_t value
, unsigned size
)
1671 struct omap_mpu_state_s
*s
= opaque
;
1674 static const char *clkschemename
[8] = {
1675 "fully synchronous", "fully asynchronous", "synchronous scalable",
1676 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
1680 omap_badwidth_write16(opaque
, addr
, value
);
1685 case 0x00: /* ARM_CKCTL */
1686 diff
= s
->clkm
.arm_ckctl
^ value
;
1687 s
->clkm
.arm_ckctl
= value
& 0x7fff;
1688 omap_clkm_ckctl_update(s
, diff
, value
);
1691 case 0x04: /* ARM_IDLECT1 */
1692 diff
= s
->clkm
.arm_idlect1
^ value
;
1693 s
->clkm
.arm_idlect1
= value
& 0x0fff;
1694 omap_clkm_idlect1_update(s
, diff
, value
);
1697 case 0x08: /* ARM_IDLECT2 */
1698 diff
= s
->clkm
.arm_idlect2
^ value
;
1699 s
->clkm
.arm_idlect2
= value
& 0x07ff;
1700 omap_clkm_idlect2_update(s
, diff
, value
);
1703 case 0x0c: /* ARM_EWUPCT */
1704 s
->clkm
.arm_ewupct
= value
& 0x003f;
1707 case 0x10: /* ARM_RSTCT1 */
1708 diff
= s
->clkm
.arm_rstct1
^ value
;
1709 s
->clkm
.arm_rstct1
= value
& 0x0007;
1711 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
1712 s
->clkm
.cold_start
= 0xa;
1714 if (diff
& ~value
& 4) { /* DSP_RST */
1716 omap_tipb_bridge_reset(s
->private_tipb
);
1717 omap_tipb_bridge_reset(s
->public_tipb
);
1719 if (diff
& 2) { /* DSP_EN */
1720 clk
= omap_findclk(s
, "dsp_ck");
1721 omap_clk_canidle(clk
, (~value
>> 1) & 1);
1725 case 0x14: /* ARM_RSTCT2 */
1726 s
->clkm
.arm_rstct2
= value
& 0x0001;
1729 case 0x18: /* ARM_SYSST */
1730 if ((s
->clkm
.clocking_scheme
^ (value
>> 11)) & 7) {
1731 s
->clkm
.clocking_scheme
= (value
>> 11) & 7;
1732 printf("%s: clocking scheme set to %s\n", __func__
,
1733 clkschemename
[s
->clkm
.clocking_scheme
]);
1735 s
->clkm
.cold_start
&= value
& 0x3f;
1738 case 0x1c: /* ARM_CKOUT1 */
1739 diff
= s
->clkm
.arm_ckout1
^ value
;
1740 s
->clkm
.arm_ckout1
= value
& 0x003f;
1741 omap_clkm_ckout1_update(s
, diff
, value
);
1744 case 0x20: /* ARM_CKOUT2 */
1750 static const MemoryRegionOps omap_clkm_ops
= {
1751 .read
= omap_clkm_read
,
1752 .write
= omap_clkm_write
,
1753 .endianness
= DEVICE_NATIVE_ENDIAN
,
1756 static uint64_t omap_clkdsp_read(void *opaque
, hwaddr addr
,
1759 struct omap_mpu_state_s
*s
= opaque
;
1760 CPUState
*cpu
= CPU(s
->cpu
);
1763 return omap_badwidth_read16(opaque
, addr
);
1767 case 0x04: /* DSP_IDLECT1 */
1768 return s
->clkm
.dsp_idlect1
;
1770 case 0x08: /* DSP_IDLECT2 */
1771 return s
->clkm
.dsp_idlect2
;
1773 case 0x14: /* DSP_RSTCT2 */
1774 return s
->clkm
.dsp_rstct2
;
1776 case 0x18: /* DSP_SYSST */
1777 return (s
->clkm
.clocking_scheme
<< 11) | s
->clkm
.cold_start
|
1778 (cpu
->halted
<< 6); /* Quite useless... */
1785 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s
*s
,
1786 uint16_t diff
, uint16_t value
)
1790 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
1793 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s
*s
,
1794 uint16_t diff
, uint16_t value
)
1798 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
1801 static void omap_clkdsp_write(void *opaque
, hwaddr addr
,
1802 uint64_t value
, unsigned size
)
1804 struct omap_mpu_state_s
*s
= opaque
;
1808 omap_badwidth_write16(opaque
, addr
, value
);
1813 case 0x04: /* DSP_IDLECT1 */
1814 diff
= s
->clkm
.dsp_idlect1
^ value
;
1815 s
->clkm
.dsp_idlect1
= value
& 0x01f7;
1816 omap_clkdsp_idlect1_update(s
, diff
, value
);
1819 case 0x08: /* DSP_IDLECT2 */
1820 s
->clkm
.dsp_idlect2
= value
& 0x0037;
1821 diff
= s
->clkm
.dsp_idlect1
^ value
;
1822 omap_clkdsp_idlect2_update(s
, diff
, value
);
1825 case 0x14: /* DSP_RSTCT2 */
1826 s
->clkm
.dsp_rstct2
= value
& 0x0001;
1829 case 0x18: /* DSP_SYSST */
1830 s
->clkm
.cold_start
&= value
& 0x3f;
1838 static const MemoryRegionOps omap_clkdsp_ops
= {
1839 .read
= omap_clkdsp_read
,
1840 .write
= omap_clkdsp_write
,
1841 .endianness
= DEVICE_NATIVE_ENDIAN
,
1844 static void omap_clkm_reset(struct omap_mpu_state_s
*s
)
1846 if (s
->wdt
&& s
->wdt
->reset
)
1847 s
->clkm
.cold_start
= 0x6;
1848 s
->clkm
.clocking_scheme
= 0;
1849 omap_clkm_ckctl_update(s
, ~0, 0x3000);
1850 s
->clkm
.arm_ckctl
= 0x3000;
1851 omap_clkm_idlect1_update(s
, s
->clkm
.arm_idlect1
^ 0x0400, 0x0400);
1852 s
->clkm
.arm_idlect1
= 0x0400;
1853 omap_clkm_idlect2_update(s
, s
->clkm
.arm_idlect2
^ 0x0100, 0x0100);
1854 s
->clkm
.arm_idlect2
= 0x0100;
1855 s
->clkm
.arm_ewupct
= 0x003f;
1856 s
->clkm
.arm_rstct1
= 0x0000;
1857 s
->clkm
.arm_rstct2
= 0x0000;
1858 s
->clkm
.arm_ckout1
= 0x0015;
1859 s
->clkm
.dpll1_mode
= 0x2002;
1860 omap_clkdsp_idlect1_update(s
, s
->clkm
.dsp_idlect1
^ 0x0040, 0x0040);
1861 s
->clkm
.dsp_idlect1
= 0x0040;
1862 omap_clkdsp_idlect2_update(s
, ~0, 0x0000);
1863 s
->clkm
.dsp_idlect2
= 0x0000;
1864 s
->clkm
.dsp_rstct2
= 0x0000;
1867 static void omap_clkm_init(MemoryRegion
*memory
, hwaddr mpu_base
,
1868 hwaddr dsp_base
, struct omap_mpu_state_s
*s
)
1870 memory_region_init_io(&s
->clkm_iomem
, NULL
, &omap_clkm_ops
, s
,
1871 "omap-clkm", 0x100);
1872 memory_region_init_io(&s
->clkdsp_iomem
, NULL
, &omap_clkdsp_ops
, s
,
1873 "omap-clkdsp", 0x1000);
1875 s
->clkm
.arm_idlect1
= 0x03ff;
1876 s
->clkm
.arm_idlect2
= 0x0100;
1877 s
->clkm
.dsp_idlect1
= 0x0002;
1879 s
->clkm
.cold_start
= 0x3a;
1881 memory_region_add_subregion(memory
, mpu_base
, &s
->clkm_iomem
);
1882 memory_region_add_subregion(memory
, dsp_base
, &s
->clkdsp_iomem
);
1886 struct omap_mpuio_s
{
1890 qemu_irq handler
[16];
1912 static void omap_mpuio_set(void *opaque
, int line
, int level
)
1914 struct omap_mpuio_s
*s
= opaque
;
1915 uint16_t prev
= s
->inputs
;
1918 s
->inputs
|= 1 << line
;
1920 s
->inputs
&= ~(1 << line
);
1922 if (((1 << line
) & s
->dir
& ~s
->mask
) && s
->clk
) {
1923 if ((s
->edge
& s
->inputs
& ~prev
) | (~s
->edge
& ~s
->inputs
& prev
)) {
1924 s
->ints
|= 1 << line
;
1925 qemu_irq_raise(s
->irq
);
1928 if ((s
->event
& (1 << 0)) && /* SET_GPIO_EVENT_MODE */
1929 (s
->event
>> 1) == line
) /* PIN_SELECT */
1930 s
->latch
= s
->inputs
;
1934 static void omap_mpuio_kbd_update(struct omap_mpuio_s
*s
)
1937 uint8_t *row
, rows
= 0, cols
= ~s
->cols
;
1939 for (row
= s
->buttons
+ 4, i
= 1 << 4; i
; row
--, i
>>= 1)
1943 qemu_set_irq(s
->kbd_irq
, rows
&& !s
->kbd_mask
&& s
->clk
);
1944 s
->row_latch
= ~rows
;
1947 static uint64_t omap_mpuio_read(void *opaque
, hwaddr addr
,
1950 struct omap_mpuio_s
*s
= opaque
;
1951 int offset
= addr
& OMAP_MPUI_REG_MASK
;
1955 return omap_badwidth_read16(opaque
, addr
);
1959 case 0x00: /* INPUT_LATCH */
1962 case 0x04: /* OUTPUT_REG */
1965 case 0x08: /* IO_CNTL */
1968 case 0x10: /* KBR_LATCH */
1969 return s
->row_latch
;
1971 case 0x14: /* KBC_REG */
1974 case 0x18: /* GPIO_EVENT_MODE_REG */
1977 case 0x1c: /* GPIO_INT_EDGE_REG */
1980 case 0x20: /* KBD_INT */
1981 return (~s
->row_latch
& 0x1f) && !s
->kbd_mask
;
1983 case 0x24: /* GPIO_INT */
1987 qemu_irq_lower(s
->irq
);
1990 case 0x28: /* KBD_MASKIT */
1993 case 0x2c: /* GPIO_MASKIT */
1996 case 0x30: /* GPIO_DEBOUNCING_REG */
1999 case 0x34: /* GPIO_LATCH_REG */
2007 static void omap_mpuio_write(void *opaque
, hwaddr addr
,
2008 uint64_t value
, unsigned size
)
2010 struct omap_mpuio_s
*s
= opaque
;
2011 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2016 omap_badwidth_write16(opaque
, addr
, value
);
2021 case 0x04: /* OUTPUT_REG */
2022 diff
= (s
->outputs
^ value
) & ~s
->dir
;
2024 while ((ln
= ctz32(diff
)) != 32) {
2026 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2031 case 0x08: /* IO_CNTL */
2032 diff
= s
->outputs
& (s
->dir
^ value
);
2035 value
= s
->outputs
& ~s
->dir
;
2036 while ((ln
= ctz32(diff
)) != 32) {
2038 qemu_set_irq(s
->handler
[ln
], (value
>> ln
) & 1);
2043 case 0x14: /* KBC_REG */
2045 omap_mpuio_kbd_update(s
);
2048 case 0x18: /* GPIO_EVENT_MODE_REG */
2049 s
->event
= value
& 0x1f;
2052 case 0x1c: /* GPIO_INT_EDGE_REG */
2056 case 0x28: /* KBD_MASKIT */
2057 s
->kbd_mask
= value
& 1;
2058 omap_mpuio_kbd_update(s
);
2061 case 0x2c: /* GPIO_MASKIT */
2065 case 0x30: /* GPIO_DEBOUNCING_REG */
2066 s
->debounce
= value
& 0x1ff;
2069 case 0x00: /* INPUT_LATCH */
2070 case 0x10: /* KBR_LATCH */
2071 case 0x20: /* KBD_INT */
2072 case 0x24: /* GPIO_INT */
2073 case 0x34: /* GPIO_LATCH_REG */
2083 static const MemoryRegionOps omap_mpuio_ops
= {
2084 .read
= omap_mpuio_read
,
2085 .write
= omap_mpuio_write
,
2086 .endianness
= DEVICE_NATIVE_ENDIAN
,
2089 static void omap_mpuio_reset(struct omap_mpuio_s
*s
)
2101 s
->row_latch
= 0x1f;
2105 static void omap_mpuio_onoff(void *opaque
, int line
, int on
)
2107 struct omap_mpuio_s
*s
= opaque
;
2111 omap_mpuio_kbd_update(s
);
2114 static struct omap_mpuio_s
*omap_mpuio_init(MemoryRegion
*memory
,
2116 qemu_irq kbd_int
, qemu_irq gpio_int
, qemu_irq wakeup
,
2119 struct omap_mpuio_s
*s
= g_new0(struct omap_mpuio_s
, 1);
2122 s
->kbd_irq
= kbd_int
;
2124 s
->in
= qemu_allocate_irqs(omap_mpuio_set
, s
, 16);
2125 omap_mpuio_reset(s
);
2127 memory_region_init_io(&s
->iomem
, NULL
, &omap_mpuio_ops
, s
,
2128 "omap-mpuio", 0x800);
2129 memory_region_add_subregion(memory
, base
, &s
->iomem
);
2131 omap_clk_adduser(clk
, qemu_allocate_irq(omap_mpuio_onoff
, s
, 0));
2136 qemu_irq
*omap_mpuio_in_get(struct omap_mpuio_s
*s
)
2141 void omap_mpuio_out_set(struct omap_mpuio_s
*s
, int line
, qemu_irq handler
)
2143 if (line
>= 16 || line
< 0)
2144 hw_error("%s: No GPIO line %i\n", __func__
, line
);
2145 s
->handler
[line
] = handler
;
2148 void omap_mpuio_key(struct omap_mpuio_s
*s
, int row
, int col
, int down
)
2150 if (row
>= 5 || row
< 0)
2151 hw_error("%s: No key %i-%i\n", __func__
, col
, row
);
2154 s
->buttons
[row
] |= 1 << col
;
2156 s
->buttons
[row
] &= ~(1 << col
);
2158 omap_mpuio_kbd_update(s
);
2161 /* MicroWire Interface */
2162 struct omap_uwire_s
{
2173 uWireSlave
*chip
[4];
2176 static void omap_uwire_transfer_start(struct omap_uwire_s
*s
)
2178 int chipselect
= (s
->control
>> 10) & 3; /* INDEX */
2179 uWireSlave
*slave
= s
->chip
[chipselect
];
2181 if ((s
->control
>> 5) & 0x1f) { /* NB_BITS_WR */
2182 if (s
->control
& (1 << 12)) /* CS_CMD */
2183 if (slave
&& slave
->send
)
2184 slave
->send(slave
->opaque
,
2185 s
->txbuf
>> (16 - ((s
->control
>> 5) & 0x1f)));
2186 s
->control
&= ~(1 << 14); /* CSRB */
2187 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2188 * a DRQ. When is the level IRQ supposed to be reset? */
2191 if ((s
->control
>> 0) & 0x1f) { /* NB_BITS_RD */
2192 if (s
->control
& (1 << 12)) /* CS_CMD */
2193 if (slave
&& slave
->receive
)
2194 s
->rxbuf
= slave
->receive(slave
->opaque
);
2195 s
->control
|= 1 << 15; /* RDRB */
2196 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
2197 * a DRQ. When is the level IRQ supposed to be reset? */
2201 static uint64_t omap_uwire_read(void *opaque
, hwaddr addr
, unsigned size
)
2203 struct omap_uwire_s
*s
= opaque
;
2204 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2207 return omap_badwidth_read16(opaque
, addr
);
2211 case 0x00: /* RDR */
2212 s
->control
&= ~(1 << 15); /* RDRB */
2215 case 0x04: /* CSR */
2218 case 0x08: /* SR1 */
2220 case 0x0c: /* SR2 */
2222 case 0x10: /* SR3 */
2224 case 0x14: /* SR4 */
2226 case 0x18: /* SR5 */
2234 static void omap_uwire_write(void *opaque
, hwaddr addr
,
2235 uint64_t value
, unsigned size
)
2237 struct omap_uwire_s
*s
= opaque
;
2238 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2241 omap_badwidth_write16(opaque
, addr
, value
);
2246 case 0x00: /* TDR */
2247 s
->txbuf
= value
; /* TD */
2248 if ((s
->setup
[4] & (1 << 2)) && /* AUTO_TX_EN */
2249 ((s
->setup
[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
2250 (s
->control
& (1 << 12)))) { /* CS_CMD */
2251 s
->control
|= 1 << 14; /* CSRB */
2252 omap_uwire_transfer_start(s
);
2256 case 0x04: /* CSR */
2257 s
->control
= value
& 0x1fff;
2258 if (value
& (1 << 13)) /* START */
2259 omap_uwire_transfer_start(s
);
2262 case 0x08: /* SR1 */
2263 s
->setup
[0] = value
& 0x003f;
2266 case 0x0c: /* SR2 */
2267 s
->setup
[1] = value
& 0x0fc0;
2270 case 0x10: /* SR3 */
2271 s
->setup
[2] = value
& 0x0003;
2274 case 0x14: /* SR4 */
2275 s
->setup
[3] = value
& 0x0001;
2278 case 0x18: /* SR5 */
2279 s
->setup
[4] = value
& 0x000f;
2288 static const MemoryRegionOps omap_uwire_ops
= {
2289 .read
= omap_uwire_read
,
2290 .write
= omap_uwire_write
,
2291 .endianness
= DEVICE_NATIVE_ENDIAN
,
2294 static void omap_uwire_reset(struct omap_uwire_s
*s
)
2304 static struct omap_uwire_s
*omap_uwire_init(MemoryRegion
*system_memory
,
2306 qemu_irq txirq
, qemu_irq rxirq
,
2310 struct omap_uwire_s
*s
= g_new0(struct omap_uwire_s
, 1);
2315 omap_uwire_reset(s
);
2317 memory_region_init_io(&s
->iomem
, NULL
, &omap_uwire_ops
, s
, "omap-uwire", 0x800);
2318 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2323 void omap_uwire_attach(struct omap_uwire_s
*s
,
2324 uWireSlave
*slave
, int chipselect
)
2326 if (chipselect
< 0 || chipselect
> 3) {
2327 error_report("%s: Bad chipselect %i", __func__
, chipselect
);
2331 s
->chip
[chipselect
] = slave
;
2334 /* Pseudonoise Pulse-Width Light Modulator */
2343 static void omap_pwl_update(struct omap_pwl_s
*s
)
2345 int output
= (s
->clk
&& s
->enable
) ? s
->level
: 0;
2347 if (output
!= s
->output
) {
2349 printf("%s: Backlight now at %i/256\n", __func__
, output
);
2353 static uint64_t omap_pwl_read(void *opaque
, hwaddr addr
, unsigned size
)
2355 struct omap_pwl_s
*s
= opaque
;
2356 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2359 return omap_badwidth_read8(opaque
, addr
);
2363 case 0x00: /* PWL_LEVEL */
2365 case 0x04: /* PWL_CTRL */
2372 static void omap_pwl_write(void *opaque
, hwaddr addr
,
2373 uint64_t value
, unsigned size
)
2375 struct omap_pwl_s
*s
= opaque
;
2376 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2379 omap_badwidth_write8(opaque
, addr
, value
);
2384 case 0x00: /* PWL_LEVEL */
2388 case 0x04: /* PWL_CTRL */
2389 s
->enable
= value
& 1;
2398 static const MemoryRegionOps omap_pwl_ops
= {
2399 .read
= omap_pwl_read
,
2400 .write
= omap_pwl_write
,
2401 .endianness
= DEVICE_NATIVE_ENDIAN
,
2404 static void omap_pwl_reset(struct omap_pwl_s
*s
)
2413 static void omap_pwl_clk_update(void *opaque
, int line
, int on
)
2415 struct omap_pwl_s
*s
= opaque
;
2421 static struct omap_pwl_s
*omap_pwl_init(MemoryRegion
*system_memory
,
2425 struct omap_pwl_s
*s
= g_malloc0(sizeof(*s
));
2429 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwl_ops
, s
,
2431 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2433 omap_clk_adduser(clk
, qemu_allocate_irq(omap_pwl_clk_update
, s
, 0));
2437 /* Pulse-Width Tone module */
2446 static uint64_t omap_pwt_read(void *opaque
, hwaddr addr
, unsigned size
)
2448 struct omap_pwt_s
*s
= opaque
;
2449 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2452 return omap_badwidth_read8(opaque
, addr
);
2456 case 0x00: /* FRC */
2458 case 0x04: /* VCR */
2460 case 0x08: /* GCR */
2467 static void omap_pwt_write(void *opaque
, hwaddr addr
,
2468 uint64_t value
, unsigned size
)
2470 struct omap_pwt_s
*s
= opaque
;
2471 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2474 omap_badwidth_write8(opaque
, addr
, value
);
2479 case 0x00: /* FRC */
2480 s
->frc
= value
& 0x3f;
2482 case 0x04: /* VRC */
2483 if ((value
^ s
->vrc
) & 1) {
2485 printf("%s: %iHz buzz on\n", __func__
, (int)
2486 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
2487 ((omap_clk_getrate(s
->clk
) >> 3) /
2488 /* Pre-multiplexer divider */
2489 ((s
->gcr
& 2) ? 1 : 154) /
2490 /* Octave multiplexer */
2491 (2 << (value
& 3)) *
2492 /* 101/107 divider */
2493 ((value
& (1 << 2)) ? 101 : 107) *
2495 ((value
& (1 << 3)) ? 49 : 55) *
2497 ((value
& (1 << 4)) ? 50 : 63) *
2498 /* 80/127 divider */
2499 ((value
& (1 << 5)) ? 80 : 127) /
2500 (107 * 55 * 63 * 127)));
2502 printf("%s: silence!\n", __func__
);
2504 s
->vrc
= value
& 0x7f;
2506 case 0x08: /* GCR */
2515 static const MemoryRegionOps omap_pwt_ops
= {
2516 .read
=omap_pwt_read
,
2517 .write
= omap_pwt_write
,
2518 .endianness
= DEVICE_NATIVE_ENDIAN
,
2521 static void omap_pwt_reset(struct omap_pwt_s
*s
)
2528 static struct omap_pwt_s
*omap_pwt_init(MemoryRegion
*system_memory
,
2532 struct omap_pwt_s
*s
= g_malloc0(sizeof(*s
));
2536 memory_region_init_io(&s
->iomem
, NULL
, &omap_pwt_ops
, s
,
2538 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2542 /* Real-time Clock module */
2559 struct tm current_tm
;
2564 static void omap_rtc_interrupts_update(struct omap_rtc_s
*s
)
2566 /* s->alarm is level-triggered */
2567 qemu_set_irq(s
->alarm
, (s
->status
>> 6) & 1);
2570 static void omap_rtc_alarm_update(struct omap_rtc_s
*s
)
2572 s
->alarm_ti
= mktimegm(&s
->alarm_tm
);
2573 if (s
->alarm_ti
== -1)
2574 printf("%s: conversion failed\n", __func__
);
2577 static uint64_t omap_rtc_read(void *opaque
, hwaddr addr
, unsigned size
)
2579 struct omap_rtc_s
*s
= opaque
;
2580 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2584 return omap_badwidth_read8(opaque
, addr
);
2588 case 0x00: /* SECONDS_REG */
2589 return to_bcd(s
->current_tm
.tm_sec
);
2591 case 0x04: /* MINUTES_REG */
2592 return to_bcd(s
->current_tm
.tm_min
);
2594 case 0x08: /* HOURS_REG */
2596 return ((s
->current_tm
.tm_hour
> 11) << 7) |
2597 to_bcd(((s
->current_tm
.tm_hour
- 1) % 12) + 1);
2599 return to_bcd(s
->current_tm
.tm_hour
);
2601 case 0x0c: /* DAYS_REG */
2602 return to_bcd(s
->current_tm
.tm_mday
);
2604 case 0x10: /* MONTHS_REG */
2605 return to_bcd(s
->current_tm
.tm_mon
+ 1);
2607 case 0x14: /* YEARS_REG */
2608 return to_bcd(s
->current_tm
.tm_year
% 100);
2610 case 0x18: /* WEEK_REG */
2611 return s
->current_tm
.tm_wday
;
2613 case 0x20: /* ALARM_SECONDS_REG */
2614 return to_bcd(s
->alarm_tm
.tm_sec
);
2616 case 0x24: /* ALARM_MINUTES_REG */
2617 return to_bcd(s
->alarm_tm
.tm_min
);
2619 case 0x28: /* ALARM_HOURS_REG */
2621 return ((s
->alarm_tm
.tm_hour
> 11) << 7) |
2622 to_bcd(((s
->alarm_tm
.tm_hour
- 1) % 12) + 1);
2624 return to_bcd(s
->alarm_tm
.tm_hour
);
2626 case 0x2c: /* ALARM_DAYS_REG */
2627 return to_bcd(s
->alarm_tm
.tm_mday
);
2629 case 0x30: /* ALARM_MONTHS_REG */
2630 return to_bcd(s
->alarm_tm
.tm_mon
+ 1);
2632 case 0x34: /* ALARM_YEARS_REG */
2633 return to_bcd(s
->alarm_tm
.tm_year
% 100);
2635 case 0x40: /* RTC_CTRL_REG */
2636 return (s
->pm_am
<< 3) | (s
->auto_comp
<< 2) |
2637 (s
->round
<< 1) | s
->running
;
2639 case 0x44: /* RTC_STATUS_REG */
2644 case 0x48: /* RTC_INTERRUPTS_REG */
2645 return s
->interrupts
;
2647 case 0x4c: /* RTC_COMP_LSB_REG */
2648 return ((uint16_t) s
->comp_reg
) & 0xff;
2650 case 0x50: /* RTC_COMP_MSB_REG */
2651 return ((uint16_t) s
->comp_reg
) >> 8;
2658 static void omap_rtc_write(void *opaque
, hwaddr addr
,
2659 uint64_t value
, unsigned size
)
2661 struct omap_rtc_s
*s
= opaque
;
2662 int offset
= addr
& OMAP_MPUI_REG_MASK
;
2667 omap_badwidth_write8(opaque
, addr
, value
);
2672 case 0x00: /* SECONDS_REG */
2674 printf("RTC SEC_REG <-- %02x\n", value
);
2676 s
->ti
-= s
->current_tm
.tm_sec
;
2677 s
->ti
+= from_bcd(value
);
2680 case 0x04: /* MINUTES_REG */
2682 printf("RTC MIN_REG <-- %02x\n", value
);
2684 s
->ti
-= s
->current_tm
.tm_min
* 60;
2685 s
->ti
+= from_bcd(value
) * 60;
2688 case 0x08: /* HOURS_REG */
2690 printf("RTC HRS_REG <-- %02x\n", value
);
2692 s
->ti
-= s
->current_tm
.tm_hour
* 3600;
2694 s
->ti
+= (from_bcd(value
& 0x3f) & 12) * 3600;
2695 s
->ti
+= ((value
>> 7) & 1) * 43200;
2697 s
->ti
+= from_bcd(value
& 0x3f) * 3600;
2700 case 0x0c: /* DAYS_REG */
2702 printf("RTC DAY_REG <-- %02x\n", value
);
2704 s
->ti
-= s
->current_tm
.tm_mday
* 86400;
2705 s
->ti
+= from_bcd(value
) * 86400;
2708 case 0x10: /* MONTHS_REG */
2710 printf("RTC MTH_REG <-- %02x\n", value
);
2712 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2713 new_tm
.tm_mon
= from_bcd(value
);
2714 ti
[0] = mktimegm(&s
->current_tm
);
2715 ti
[1] = mktimegm(&new_tm
);
2717 if (ti
[0] != -1 && ti
[1] != -1) {
2721 /* A less accurate version */
2722 s
->ti
-= s
->current_tm
.tm_mon
* 2592000;
2723 s
->ti
+= from_bcd(value
) * 2592000;
2727 case 0x14: /* YEARS_REG */
2729 printf("RTC YRS_REG <-- %02x\n", value
);
2731 memcpy(&new_tm
, &s
->current_tm
, sizeof(new_tm
));
2732 new_tm
.tm_year
+= from_bcd(value
) - (new_tm
.tm_year
% 100);
2733 ti
[0] = mktimegm(&s
->current_tm
);
2734 ti
[1] = mktimegm(&new_tm
);
2736 if (ti
[0] != -1 && ti
[1] != -1) {
2740 /* A less accurate version */
2741 s
->ti
-= (time_t)(s
->current_tm
.tm_year
% 100) * 31536000;
2742 s
->ti
+= (time_t)from_bcd(value
) * 31536000;
2746 case 0x18: /* WEEK_REG */
2747 return; /* Ignored */
2749 case 0x20: /* ALARM_SECONDS_REG */
2751 printf("ALM SEC_REG <-- %02x\n", value
);
2753 s
->alarm_tm
.tm_sec
= from_bcd(value
);
2754 omap_rtc_alarm_update(s
);
2757 case 0x24: /* ALARM_MINUTES_REG */
2759 printf("ALM MIN_REG <-- %02x\n", value
);
2761 s
->alarm_tm
.tm_min
= from_bcd(value
);
2762 omap_rtc_alarm_update(s
);
2765 case 0x28: /* ALARM_HOURS_REG */
2767 printf("ALM HRS_REG <-- %02x\n", value
);
2770 s
->alarm_tm
.tm_hour
=
2771 ((from_bcd(value
& 0x3f)) % 12) +
2772 ((value
>> 7) & 1) * 12;
2774 s
->alarm_tm
.tm_hour
= from_bcd(value
);
2775 omap_rtc_alarm_update(s
);
2778 case 0x2c: /* ALARM_DAYS_REG */
2780 printf("ALM DAY_REG <-- %02x\n", value
);
2782 s
->alarm_tm
.tm_mday
= from_bcd(value
);
2783 omap_rtc_alarm_update(s
);
2786 case 0x30: /* ALARM_MONTHS_REG */
2788 printf("ALM MON_REG <-- %02x\n", value
);
2790 s
->alarm_tm
.tm_mon
= from_bcd(value
);
2791 omap_rtc_alarm_update(s
);
2794 case 0x34: /* ALARM_YEARS_REG */
2796 printf("ALM YRS_REG <-- %02x\n", value
);
2798 s
->alarm_tm
.tm_year
= from_bcd(value
);
2799 omap_rtc_alarm_update(s
);
2802 case 0x40: /* RTC_CTRL_REG */
2804 printf("RTC CONTROL <-- %02x\n", value
);
2806 s
->pm_am
= (value
>> 3) & 1;
2807 s
->auto_comp
= (value
>> 2) & 1;
2808 s
->round
= (value
>> 1) & 1;
2809 s
->running
= value
& 1;
2811 s
->status
|= s
->running
<< 1;
2814 case 0x44: /* RTC_STATUS_REG */
2816 printf("RTC STATUSL <-- %02x\n", value
);
2818 s
->status
&= ~((value
& 0xc0) ^ 0x80);
2819 omap_rtc_interrupts_update(s
);
2822 case 0x48: /* RTC_INTERRUPTS_REG */
2824 printf("RTC INTRS <-- %02x\n", value
);
2826 s
->interrupts
= value
;
2829 case 0x4c: /* RTC_COMP_LSB_REG */
2831 printf("RTC COMPLSB <-- %02x\n", value
);
2833 s
->comp_reg
&= 0xff00;
2834 s
->comp_reg
|= 0x00ff & value
;
2837 case 0x50: /* RTC_COMP_MSB_REG */
2839 printf("RTC COMPMSB <-- %02x\n", value
);
2841 s
->comp_reg
&= 0x00ff;
2842 s
->comp_reg
|= 0xff00 & (value
<< 8);
2851 static const MemoryRegionOps omap_rtc_ops
= {
2852 .read
= omap_rtc_read
,
2853 .write
= omap_rtc_write
,
2854 .endianness
= DEVICE_NATIVE_ENDIAN
,
2857 static void omap_rtc_tick(void *opaque
)
2859 struct omap_rtc_s
*s
= opaque
;
2862 /* Round to nearest full minute. */
2863 if (s
->current_tm
.tm_sec
< 30)
2864 s
->ti
-= s
->current_tm
.tm_sec
;
2866 s
->ti
+= 60 - s
->current_tm
.tm_sec
;
2871 localtime_r(&s
->ti
, &s
->current_tm
);
2873 if ((s
->interrupts
& 0x08) && s
->ti
== s
->alarm_ti
) {
2875 omap_rtc_interrupts_update(s
);
2878 if (s
->interrupts
& 0x04)
2879 switch (s
->interrupts
& 3) {
2882 qemu_irq_pulse(s
->irq
);
2885 if (s
->current_tm
.tm_sec
)
2888 qemu_irq_pulse(s
->irq
);
2891 if (s
->current_tm
.tm_sec
|| s
->current_tm
.tm_min
)
2894 qemu_irq_pulse(s
->irq
);
2897 if (s
->current_tm
.tm_sec
||
2898 s
->current_tm
.tm_min
|| s
->current_tm
.tm_hour
)
2901 qemu_irq_pulse(s
->irq
);
2911 * Every full hour add a rough approximation of the compensation
2912 * register to the 32kHz Timer (which drives the RTC) value.
2914 if (s
->auto_comp
&& !s
->current_tm
.tm_sec
&& !s
->current_tm
.tm_min
)
2915 s
->tick
+= s
->comp_reg
* 1000 / 32768;
2917 timer_mod(s
->clk
, s
->tick
);
2920 static void omap_rtc_reset(struct omap_rtc_s
*s
)
2930 s
->tick
= qemu_clock_get_ms(rtc_clock
);
2931 memset(&s
->alarm_tm
, 0, sizeof(s
->alarm_tm
));
2932 s
->alarm_tm
.tm_mday
= 0x01;
2934 qemu_get_timedate(&tm
, 0);
2935 s
->ti
= mktimegm(&tm
);
2937 omap_rtc_alarm_update(s
);
2941 static struct omap_rtc_s
*omap_rtc_init(MemoryRegion
*system_memory
,
2943 qemu_irq timerirq
, qemu_irq alarmirq
,
2946 struct omap_rtc_s
*s
= g_new0(struct omap_rtc_s
, 1);
2949 s
->alarm
= alarmirq
;
2950 s
->clk
= timer_new_ms(rtc_clock
, omap_rtc_tick
, s
);
2954 memory_region_init_io(&s
->iomem
, NULL
, &omap_rtc_ops
, s
,
2956 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
2961 /* Multi-channel Buffered Serial Port interfaces */
2962 struct omap_mcbsp_s
{
2983 QEMUTimer
*source_timer
;
2984 QEMUTimer
*sink_timer
;
2987 static void omap_mcbsp_intr_update(struct omap_mcbsp_s
*s
)
2991 switch ((s
->spcr
[0] >> 4) & 3) { /* RINTM */
2993 irq
= (s
->spcr
[0] >> 1) & 1; /* RRDY */
2996 irq
= (s
->spcr
[0] >> 3) & 1; /* RSYNCERR */
3004 qemu_irq_pulse(s
->rxirq
);
3006 switch ((s
->spcr
[1] >> 4) & 3) { /* XINTM */
3008 irq
= (s
->spcr
[1] >> 1) & 1; /* XRDY */
3011 irq
= (s
->spcr
[1] >> 3) & 1; /* XSYNCERR */
3019 qemu_irq_pulse(s
->txirq
);
3022 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s
*s
)
3024 if ((s
->spcr
[0] >> 1) & 1) /* RRDY */
3025 s
->spcr
[0] |= 1 << 2; /* RFULL */
3026 s
->spcr
[0] |= 1 << 1; /* RRDY */
3027 qemu_irq_raise(s
->rxdrq
);
3028 omap_mcbsp_intr_update(s
);
3031 static void omap_mcbsp_source_tick(void *opaque
)
3033 struct omap_mcbsp_s
*s
= opaque
;
3034 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3039 printf("%s: Rx FIFO overrun\n", __func__
);
3041 s
->rx_req
= s
->rx_rate
<< bps
[(s
->rcr
[0] >> 5) & 7];
3043 omap_mcbsp_rx_newdata(s
);
3044 timer_mod(s
->source_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3045 NANOSECONDS_PER_SECOND
);
3048 static void omap_mcbsp_rx_start(struct omap_mcbsp_s
*s
)
3050 if (!s
->codec
|| !s
->codec
->rts
)
3051 omap_mcbsp_source_tick(s
);
3052 else if (s
->codec
->in
.len
) {
3053 s
->rx_req
= s
->codec
->in
.len
;
3054 omap_mcbsp_rx_newdata(s
);
3058 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s
*s
)
3060 timer_del(s
->source_timer
);
3063 static void omap_mcbsp_rx_done(struct omap_mcbsp_s
*s
)
3065 s
->spcr
[0] &= ~(1 << 1); /* RRDY */
3066 qemu_irq_lower(s
->rxdrq
);
3067 omap_mcbsp_intr_update(s
);
3070 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s
*s
)
3072 s
->spcr
[1] |= 1 << 1; /* XRDY */
3073 qemu_irq_raise(s
->txdrq
);
3074 omap_mcbsp_intr_update(s
);
3077 static void omap_mcbsp_sink_tick(void *opaque
)
3079 struct omap_mcbsp_s
*s
= opaque
;
3080 static const int bps
[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3085 printf("%s: Tx FIFO underrun\n", __func__
);
3087 s
->tx_req
= s
->tx_rate
<< bps
[(s
->xcr
[0] >> 5) & 7];
3089 omap_mcbsp_tx_newdata(s
);
3090 timer_mod(s
->sink_timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
3091 NANOSECONDS_PER_SECOND
);
3094 static void omap_mcbsp_tx_start(struct omap_mcbsp_s
*s
)
3096 if (!s
->codec
|| !s
->codec
->cts
)
3097 omap_mcbsp_sink_tick(s
);
3098 else if (s
->codec
->out
.size
) {
3099 s
->tx_req
= s
->codec
->out
.size
;
3100 omap_mcbsp_tx_newdata(s
);
3104 static void omap_mcbsp_tx_done(struct omap_mcbsp_s
*s
)
3106 s
->spcr
[1] &= ~(1 << 1); /* XRDY */
3107 qemu_irq_lower(s
->txdrq
);
3108 omap_mcbsp_intr_update(s
);
3109 if (s
->codec
&& s
->codec
->cts
)
3110 s
->codec
->tx_swallow(s
->codec
->opaque
);
3113 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s
*s
)
3116 omap_mcbsp_tx_done(s
);
3117 timer_del(s
->sink_timer
);
3120 static void omap_mcbsp_req_update(struct omap_mcbsp_s
*s
)
3122 int prev_rx_rate
, prev_tx_rate
;
3123 int rx_rate
= 0, tx_rate
= 0;
3124 int cpu_rate
= 1500000; /* XXX */
3126 /* TODO: check CLKSTP bit */
3127 if (s
->spcr
[1] & (1 << 6)) { /* GRST */
3128 if (s
->spcr
[0] & (1 << 0)) { /* RRST */
3129 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3130 (s
->pcr
& (1 << 8))) { /* CLKRM */
3131 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3132 rx_rate
= cpu_rate
/
3133 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3136 rx_rate
= s
->codec
->rx_rate
;
3139 if (s
->spcr
[1] & (1 << 0)) { /* XRST */
3140 if ((s
->srgr
[1] & (1 << 13)) && /* CLKSM */
3141 (s
->pcr
& (1 << 9))) { /* CLKXM */
3142 if (~s
->pcr
& (1 << 7)) /* SCLKME */
3143 tx_rate
= cpu_rate
/
3144 ((s
->srgr
[0] & 0xff) + 1); /* CLKGDV */
3147 tx_rate
= s
->codec
->tx_rate
;
3150 prev_tx_rate
= s
->tx_rate
;
3151 prev_rx_rate
= s
->rx_rate
;
3152 s
->tx_rate
= tx_rate
;
3153 s
->rx_rate
= rx_rate
;
3156 s
->codec
->set_rate(s
->codec
->opaque
, rx_rate
, tx_rate
);
3158 if (!prev_tx_rate
&& tx_rate
)
3159 omap_mcbsp_tx_start(s
);
3160 else if (s
->tx_rate
&& !tx_rate
)
3161 omap_mcbsp_tx_stop(s
);
3163 if (!prev_rx_rate
&& rx_rate
)
3164 omap_mcbsp_rx_start(s
);
3165 else if (prev_tx_rate
&& !tx_rate
)
3166 omap_mcbsp_rx_stop(s
);
3169 static uint64_t omap_mcbsp_read(void *opaque
, hwaddr addr
,
3172 struct omap_mcbsp_s
*s
= opaque
;
3173 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3177 return omap_badwidth_read16(opaque
, addr
);
3181 case 0x00: /* DRR2 */
3182 if (((s
->rcr
[0] >> 5) & 7) < 3) /* RWDLEN1 */
3185 case 0x02: /* DRR1 */
3186 if (s
->rx_req
< 2) {
3187 printf("%s: Rx FIFO underrun\n", __func__
);
3188 omap_mcbsp_rx_done(s
);
3191 if (s
->codec
&& s
->codec
->in
.len
>= 2) {
3192 ret
= s
->codec
->in
.fifo
[s
->codec
->in
.start
++] << 8;
3193 ret
|= s
->codec
->in
.fifo
[s
->codec
->in
.start
++];
3194 s
->codec
->in
.len
-= 2;
3198 omap_mcbsp_rx_done(s
);
3203 case 0x04: /* DXR2 */
3204 case 0x06: /* DXR1 */
3207 case 0x08: /* SPCR2 */
3209 case 0x0a: /* SPCR1 */
3211 case 0x0c: /* RCR2 */
3213 case 0x0e: /* RCR1 */
3215 case 0x10: /* XCR2 */
3217 case 0x12: /* XCR1 */
3219 case 0x14: /* SRGR2 */
3221 case 0x16: /* SRGR1 */
3223 case 0x18: /* MCR2 */
3225 case 0x1a: /* MCR1 */
3227 case 0x1c: /* RCERA */
3229 case 0x1e: /* RCERB */
3231 case 0x20: /* XCERA */
3233 case 0x22: /* XCERB */
3235 case 0x24: /* PCR0 */
3237 case 0x26: /* RCERC */
3239 case 0x28: /* RCERD */
3241 case 0x2a: /* XCERC */
3243 case 0x2c: /* XCERD */
3245 case 0x2e: /* RCERE */
3247 case 0x30: /* RCERF */
3249 case 0x32: /* XCERE */
3251 case 0x34: /* XCERF */
3253 case 0x36: /* RCERG */
3255 case 0x38: /* RCERH */
3257 case 0x3a: /* XCERG */
3259 case 0x3c: /* XCERH */
3267 static void omap_mcbsp_writeh(void *opaque
, hwaddr addr
,
3270 struct omap_mcbsp_s
*s
= opaque
;
3271 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3274 case 0x00: /* DRR2 */
3275 case 0x02: /* DRR1 */
3279 case 0x04: /* DXR2 */
3280 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3283 case 0x06: /* DXR1 */
3284 if (s
->tx_req
> 1) {
3286 if (s
->codec
&& s
->codec
->cts
) {
3287 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 8) & 0xff;
3288 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] = (value
>> 0) & 0xff;
3291 omap_mcbsp_tx_done(s
);
3293 printf("%s: Tx FIFO overrun\n", __func__
);
3296 case 0x08: /* SPCR2 */
3297 s
->spcr
[1] &= 0x0002;
3298 s
->spcr
[1] |= 0x03f9 & value
;
3299 s
->spcr
[1] |= 0x0004 & (value
<< 2); /* XEMPTY := XRST */
3300 if (~value
& 1) /* XRST */
3302 omap_mcbsp_req_update(s
);
3304 case 0x0a: /* SPCR1 */
3305 s
->spcr
[0] &= 0x0006;
3306 s
->spcr
[0] |= 0xf8f9 & value
;
3307 if (value
& (1 << 15)) /* DLB */
3308 printf("%s: Digital Loopback mode enable attempt\n", __func__
);
3309 if (~value
& 1) { /* RRST */
3312 omap_mcbsp_rx_done(s
);
3314 omap_mcbsp_req_update(s
);
3317 case 0x0c: /* RCR2 */
3318 s
->rcr
[1] = value
& 0xffff;
3320 case 0x0e: /* RCR1 */
3321 s
->rcr
[0] = value
& 0x7fe0;
3323 case 0x10: /* XCR2 */
3324 s
->xcr
[1] = value
& 0xffff;
3326 case 0x12: /* XCR1 */
3327 s
->xcr
[0] = value
& 0x7fe0;
3329 case 0x14: /* SRGR2 */
3330 s
->srgr
[1] = value
& 0xffff;
3331 omap_mcbsp_req_update(s
);
3333 case 0x16: /* SRGR1 */
3334 s
->srgr
[0] = value
& 0xffff;
3335 omap_mcbsp_req_update(s
);
3337 case 0x18: /* MCR2 */
3338 s
->mcr
[1] = value
& 0x03e3;
3339 if (value
& 3) /* XMCM */
3340 printf("%s: Tx channel selection mode enable attempt\n", __func__
);
3342 case 0x1a: /* MCR1 */
3343 s
->mcr
[0] = value
& 0x03e1;
3344 if (value
& 1) /* RMCM */
3345 printf("%s: Rx channel selection mode enable attempt\n", __func__
);
3347 case 0x1c: /* RCERA */
3348 s
->rcer
[0] = value
& 0xffff;
3350 case 0x1e: /* RCERB */
3351 s
->rcer
[1] = value
& 0xffff;
3353 case 0x20: /* XCERA */
3354 s
->xcer
[0] = value
& 0xffff;
3356 case 0x22: /* XCERB */
3357 s
->xcer
[1] = value
& 0xffff;
3359 case 0x24: /* PCR0 */
3360 s
->pcr
= value
& 0x7faf;
3362 case 0x26: /* RCERC */
3363 s
->rcer
[2] = value
& 0xffff;
3365 case 0x28: /* RCERD */
3366 s
->rcer
[3] = value
& 0xffff;
3368 case 0x2a: /* XCERC */
3369 s
->xcer
[2] = value
& 0xffff;
3371 case 0x2c: /* XCERD */
3372 s
->xcer
[3] = value
& 0xffff;
3374 case 0x2e: /* RCERE */
3375 s
->rcer
[4] = value
& 0xffff;
3377 case 0x30: /* RCERF */
3378 s
->rcer
[5] = value
& 0xffff;
3380 case 0x32: /* XCERE */
3381 s
->xcer
[4] = value
& 0xffff;
3383 case 0x34: /* XCERF */
3384 s
->xcer
[5] = value
& 0xffff;
3386 case 0x36: /* RCERG */
3387 s
->rcer
[6] = value
& 0xffff;
3389 case 0x38: /* RCERH */
3390 s
->rcer
[7] = value
& 0xffff;
3392 case 0x3a: /* XCERG */
3393 s
->xcer
[6] = value
& 0xffff;
3395 case 0x3c: /* XCERH */
3396 s
->xcer
[7] = value
& 0xffff;
3403 static void omap_mcbsp_writew(void *opaque
, hwaddr addr
,
3406 struct omap_mcbsp_s
*s
= opaque
;
3407 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3409 if (offset
== 0x04) { /* DXR */
3410 if (((s
->xcr
[0] >> 5) & 7) < 3) /* XWDLEN1 */
3412 if (s
->tx_req
> 3) {
3414 if (s
->codec
&& s
->codec
->cts
) {
3415 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3416 (value
>> 24) & 0xff;
3417 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3418 (value
>> 16) & 0xff;
3419 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3420 (value
>> 8) & 0xff;
3421 s
->codec
->out
.fifo
[s
->codec
->out
.len
++] =
3422 (value
>> 0) & 0xff;
3425 omap_mcbsp_tx_done(s
);
3427 printf("%s: Tx FIFO overrun\n", __func__
);
3431 omap_badwidth_write16(opaque
, addr
, value
);
3434 static void omap_mcbsp_write(void *opaque
, hwaddr addr
,
3435 uint64_t value
, unsigned size
)
3439 omap_mcbsp_writeh(opaque
, addr
, value
);
3442 omap_mcbsp_writew(opaque
, addr
, value
);
3445 omap_badwidth_write16(opaque
, addr
, value
);
3449 static const MemoryRegionOps omap_mcbsp_ops
= {
3450 .read
= omap_mcbsp_read
,
3451 .write
= omap_mcbsp_write
,
3452 .endianness
= DEVICE_NATIVE_ENDIAN
,
3455 static void omap_mcbsp_reset(struct omap_mcbsp_s
*s
)
3457 memset(&s
->spcr
, 0, sizeof(s
->spcr
));
3458 memset(&s
->rcr
, 0, sizeof(s
->rcr
));
3459 memset(&s
->xcr
, 0, sizeof(s
->xcr
));
3460 s
->srgr
[0] = 0x0001;
3461 s
->srgr
[1] = 0x2000;
3462 memset(&s
->mcr
, 0, sizeof(s
->mcr
));
3463 memset(&s
->pcr
, 0, sizeof(s
->pcr
));
3464 memset(&s
->rcer
, 0, sizeof(s
->rcer
));
3465 memset(&s
->xcer
, 0, sizeof(s
->xcer
));
3470 timer_del(s
->source_timer
);
3471 timer_del(s
->sink_timer
);
3474 static struct omap_mcbsp_s
*omap_mcbsp_init(MemoryRegion
*system_memory
,
3476 qemu_irq txirq
, qemu_irq rxirq
,
3477 qemu_irq
*dma
, omap_clk clk
)
3479 struct omap_mcbsp_s
*s
= g_new0(struct omap_mcbsp_s
, 1);
3485 s
->sink_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_sink_tick
, s
);
3486 s
->source_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, omap_mcbsp_source_tick
, s
);
3487 omap_mcbsp_reset(s
);
3489 memory_region_init_io(&s
->iomem
, NULL
, &omap_mcbsp_ops
, s
, "omap-mcbsp", 0x800);
3490 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3495 static void omap_mcbsp_i2s_swallow(void *opaque
, int line
, int level
)
3497 struct omap_mcbsp_s
*s
= opaque
;
3500 s
->rx_req
= s
->codec
->in
.len
;
3501 omap_mcbsp_rx_newdata(s
);
3505 static void omap_mcbsp_i2s_start(void *opaque
, int line
, int level
)
3507 struct omap_mcbsp_s
*s
= opaque
;
3510 s
->tx_req
= s
->codec
->out
.size
;
3511 omap_mcbsp_tx_newdata(s
);
3515 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s
*s
, I2SCodec
*slave
)
3518 slave
->rx_swallow
= qemu_allocate_irq(omap_mcbsp_i2s_swallow
, s
, 0);
3519 slave
->tx_start
= qemu_allocate_irq(omap_mcbsp_i2s_start
, s
, 0);
3522 /* LED Pulse Generators */
3535 static void omap_lpg_tick(void *opaque
)
3537 struct omap_lpg_s
*s
= opaque
;
3540 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->period
- s
->on
);
3542 timer_mod(s
->tm
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + s
->on
);
3544 s
->cycle
= !s
->cycle
;
3545 printf("%s: LED is %s\n", __func__
, s
->cycle
? "on" : "off");
3548 static void omap_lpg_update(struct omap_lpg_s
*s
)
3550 int64_t on
, period
= 1, ticks
= 1000;
3551 static const int per
[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
3553 if (~s
->control
& (1 << 6)) /* LPGRES */
3555 else if (s
->control
& (1 << 7)) /* PERM_ON */
3558 period
= muldiv64(ticks
, per
[s
->control
& 7], /* PERCTRL */
3560 on
= (s
->clk
&& s
->power
) ? muldiv64(ticks
,
3561 per
[(s
->control
>> 3) & 7], 256) : 0; /* ONCTRL */
3565 if (on
== period
&& s
->on
< s
->period
)
3566 printf("%s: LED is on\n", __func__
);
3567 else if (on
== 0 && s
->on
)
3568 printf("%s: LED is off\n", __func__
);
3569 else if (on
&& (on
!= s
->on
|| period
!= s
->period
)) {
3581 static void omap_lpg_reset(struct omap_lpg_s
*s
)
3589 static uint64_t omap_lpg_read(void *opaque
, hwaddr addr
, unsigned size
)
3591 struct omap_lpg_s
*s
= opaque
;
3592 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3595 return omap_badwidth_read8(opaque
, addr
);
3599 case 0x00: /* LCR */
3602 case 0x04: /* PMR */
3610 static void omap_lpg_write(void *opaque
, hwaddr addr
,
3611 uint64_t value
, unsigned size
)
3613 struct omap_lpg_s
*s
= opaque
;
3614 int offset
= addr
& OMAP_MPUI_REG_MASK
;
3617 omap_badwidth_write8(opaque
, addr
, value
);
3622 case 0x00: /* LCR */
3623 if (~value
& (1 << 6)) /* LPGRES */
3625 s
->control
= value
& 0xff;
3629 case 0x04: /* PMR */
3630 s
->power
= value
& 0x01;
3640 static const MemoryRegionOps omap_lpg_ops
= {
3641 .read
= omap_lpg_read
,
3642 .write
= omap_lpg_write
,
3643 .endianness
= DEVICE_NATIVE_ENDIAN
,
3646 static void omap_lpg_clk_update(void *opaque
, int line
, int on
)
3648 struct omap_lpg_s
*s
= opaque
;
3654 static struct omap_lpg_s
*omap_lpg_init(MemoryRegion
*system_memory
,
3655 hwaddr base
, omap_clk clk
)
3657 struct omap_lpg_s
*s
= g_new0(struct omap_lpg_s
, 1);
3659 s
->tm
= timer_new_ms(QEMU_CLOCK_VIRTUAL
, omap_lpg_tick
, s
);
3663 memory_region_init_io(&s
->iomem
, NULL
, &omap_lpg_ops
, s
, "omap-lpg", 0x800);
3664 memory_region_add_subregion(system_memory
, base
, &s
->iomem
);
3666 omap_clk_adduser(clk
, qemu_allocate_irq(omap_lpg_clk_update
, s
, 0));
3671 /* MPUI Peripheral Bridge configuration */
3672 static uint64_t omap_mpui_io_read(void *opaque
, hwaddr addr
,
3676 return omap_badwidth_read16(opaque
, addr
);
3679 if (addr
== OMAP_MPUI_BASE
) /* CMR */
3686 static void omap_mpui_io_write(void *opaque
, hwaddr addr
,
3687 uint64_t value
, unsigned size
)
3689 /* FIXME: infinite loop */
3690 omap_badwidth_write16(opaque
, addr
, value
);
3693 static const MemoryRegionOps omap_mpui_io_ops
= {
3694 .read
= omap_mpui_io_read
,
3695 .write
= omap_mpui_io_write
,
3696 .endianness
= DEVICE_NATIVE_ENDIAN
,
3699 static void omap_setup_mpui_io(MemoryRegion
*system_memory
,
3700 struct omap_mpu_state_s
*mpu
)
3702 memory_region_init_io(&mpu
->mpui_io_iomem
, NULL
, &omap_mpui_io_ops
, mpu
,
3703 "omap-mpui-io", 0x7fff);
3704 memory_region_add_subregion(system_memory
, OMAP_MPUI_BASE
,
3705 &mpu
->mpui_io_iomem
);
3708 /* General chip reset */
3709 static void omap1_mpu_reset(void *opaque
)
3711 struct omap_mpu_state_s
*mpu
= opaque
;
3713 omap_dma_reset(mpu
->dma
);
3714 omap_mpu_timer_reset(mpu
->timer
[0]);
3715 omap_mpu_timer_reset(mpu
->timer
[1]);
3716 omap_mpu_timer_reset(mpu
->timer
[2]);
3717 omap_wd_timer_reset(mpu
->wdt
);
3718 omap_os_timer_reset(mpu
->os_timer
);
3719 omap_lcdc_reset(mpu
->lcd
);
3720 omap_ulpd_pm_reset(mpu
);
3721 omap_pin_cfg_reset(mpu
);
3722 omap_mpui_reset(mpu
);
3723 omap_tipb_bridge_reset(mpu
->private_tipb
);
3724 omap_tipb_bridge_reset(mpu
->public_tipb
);
3725 omap_dpll_reset(mpu
->dpll
[0]);
3726 omap_dpll_reset(mpu
->dpll
[1]);
3727 omap_dpll_reset(mpu
->dpll
[2]);
3728 omap_uart_reset(mpu
->uart
[0]);
3729 omap_uart_reset(mpu
->uart
[1]);
3730 omap_uart_reset(mpu
->uart
[2]);
3731 omap_mmc_reset(mpu
->mmc
);
3732 omap_mpuio_reset(mpu
->mpuio
);
3733 omap_uwire_reset(mpu
->microwire
);
3734 omap_pwl_reset(mpu
->pwl
);
3735 omap_pwt_reset(mpu
->pwt
);
3736 omap_rtc_reset(mpu
->rtc
);
3737 omap_mcbsp_reset(mpu
->mcbsp1
);
3738 omap_mcbsp_reset(mpu
->mcbsp2
);
3739 omap_mcbsp_reset(mpu
->mcbsp3
);
3740 omap_lpg_reset(mpu
->led
[0]);
3741 omap_lpg_reset(mpu
->led
[1]);
3742 omap_clkm_reset(mpu
);
3743 cpu_reset(CPU(mpu
->cpu
));
3746 static const struct omap_map_s
{
3751 } omap15xx_dsp_mm
[] = {
3753 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
3754 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
3755 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
3756 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
3757 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
3758 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
3759 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
3760 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
3761 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
3762 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
3763 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
3764 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
3765 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
3766 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
3767 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
3768 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
3769 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
3771 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
3776 static void omap_setup_dsp_mapping(MemoryRegion
*system_memory
,
3777 const struct omap_map_s
*map
)
3781 for (; map
->phys_dsp
; map
++) {
3782 io
= g_new(MemoryRegion
, 1);
3783 memory_region_init_alias(io
, NULL
, map
->name
,
3784 system_memory
, map
->phys_mpu
, map
->size
);
3785 memory_region_add_subregion(system_memory
, map
->phys_dsp
, io
);
3789 void omap_mpu_wakeup(void *opaque
, int irq
, int req
)
3791 struct omap_mpu_state_s
*mpu
= opaque
;
3792 CPUState
*cpu
= CPU(mpu
->cpu
);
3795 cpu_interrupt(cpu
, CPU_INTERRUPT_EXITTB
);
3799 static const struct dma_irq_map omap1_dma_irq_map
[] = {
3800 { 0, OMAP_INT_DMA_CH0_6
},
3801 { 0, OMAP_INT_DMA_CH1_7
},
3802 { 0, OMAP_INT_DMA_CH2_8
},
3803 { 0, OMAP_INT_DMA_CH3
},
3804 { 0, OMAP_INT_DMA_CH4
},
3805 { 0, OMAP_INT_DMA_CH5
},
3806 { 1, OMAP_INT_1610_DMA_CH6
},
3807 { 1, OMAP_INT_1610_DMA_CH7
},
3808 { 1, OMAP_INT_1610_DMA_CH8
},
3809 { 1, OMAP_INT_1610_DMA_CH9
},
3810 { 1, OMAP_INT_1610_DMA_CH10
},
3811 { 1, OMAP_INT_1610_DMA_CH11
},
3812 { 1, OMAP_INT_1610_DMA_CH12
},
3813 { 1, OMAP_INT_1610_DMA_CH13
},
3814 { 1, OMAP_INT_1610_DMA_CH14
},
3815 { 1, OMAP_INT_1610_DMA_CH15
}
3818 /* DMA ports for OMAP1 */
3819 static int omap_validate_emiff_addr(struct omap_mpu_state_s
*s
,
3822 return range_covers_byte(OMAP_EMIFF_BASE
, s
->sdram_size
, addr
);
3825 static int omap_validate_emifs_addr(struct omap_mpu_state_s
*s
,
3828 return range_covers_byte(OMAP_EMIFS_BASE
, OMAP_EMIFF_BASE
- OMAP_EMIFS_BASE
,
3832 static int omap_validate_imif_addr(struct omap_mpu_state_s
*s
,
3835 return range_covers_byte(OMAP_IMIF_BASE
, s
->sram_size
, addr
);
3838 static int omap_validate_tipb_addr(struct omap_mpu_state_s
*s
,
3841 return range_covers_byte(0xfffb0000, 0xffff0000 - 0xfffb0000, addr
);
3844 static int omap_validate_local_addr(struct omap_mpu_state_s
*s
,
3847 return range_covers_byte(OMAP_LOCALBUS_BASE
, 0x1000000, addr
);
3850 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s
*s
,
3853 return range_covers_byte(0xe1010000, 0xe1020004 - 0xe1010000, addr
);
3856 struct omap_mpu_state_s
*omap310_mpu_init(MemoryRegion
*dram
,
3857 const char *cpu_type
)
3860 struct omap_mpu_state_s
*s
= g_new0(struct omap_mpu_state_s
, 1);
3861 qemu_irq dma_irqs
[6];
3863 SysBusDevice
*busdev
;
3864 MemoryRegion
*system_memory
= get_system_memory();
3867 s
->mpu_model
= omap310
;
3868 s
->cpu
= ARM_CPU(cpu_create(cpu_type
));
3869 s
->sdram_size
= memory_region_size(dram
);
3870 s
->sram_size
= OMAP15XX_SRAM_SIZE
;
3872 s
->wakeup
= qemu_allocate_irq(omap_mpu_wakeup
, s
, 0);
3877 /* Memory-mapped stuff */
3878 memory_region_init_ram(&s
->imif_ram
, NULL
, "omap1.sram", s
->sram_size
,
3880 memory_region_add_subregion(system_memory
, OMAP_IMIF_BASE
, &s
->imif_ram
);
3882 omap_clkm_init(system_memory
, 0xfffece00, 0xe1008000, s
);
3884 s
->ih
[0] = qdev_new("omap-intc");
3885 qdev_prop_set_uint32(s
->ih
[0], "size", 0x100);
3886 omap_intc_set_iclk(OMAP_INTC(s
->ih
[0]), omap_findclk(s
, "arminth_ck"));
3887 busdev
= SYS_BUS_DEVICE(s
->ih
[0]);
3888 sysbus_realize_and_unref(busdev
, &error_fatal
);
3889 sysbus_connect_irq(busdev
, 0,
3890 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_IRQ
));
3891 sysbus_connect_irq(busdev
, 1,
3892 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_FIQ
));
3893 sysbus_mmio_map(busdev
, 0, 0xfffecb00);
3894 s
->ih
[1] = qdev_new("omap-intc");
3895 qdev_prop_set_uint32(s
->ih
[1], "size", 0x800);
3896 omap_intc_set_iclk(OMAP_INTC(s
->ih
[1]), omap_findclk(s
, "arminth_ck"));
3897 busdev
= SYS_BUS_DEVICE(s
->ih
[1]);
3898 sysbus_realize_and_unref(busdev
, &error_fatal
);
3899 sysbus_connect_irq(busdev
, 0,
3900 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_15XX_IH2_IRQ
));
3901 /* The second interrupt controller's FIQ output is not wired up */
3902 sysbus_mmio_map(busdev
, 0, 0xfffe0000);
3904 for (i
= 0; i
< 6; i
++) {
3905 dma_irqs
[i
] = qdev_get_gpio_in(s
->ih
[omap1_dma_irq_map
[i
].ih
],
3906 omap1_dma_irq_map
[i
].intr
);
3908 s
->dma
= omap_dma_init(0xfffed800, dma_irqs
, system_memory
,
3909 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_DMA_LCD
),
3910 s
, omap_findclk(s
, "dma_ck"), omap_dma_3_1
);
3912 s
->port
[emiff
].addr_valid
= omap_validate_emiff_addr
;
3913 s
->port
[emifs
].addr_valid
= omap_validate_emifs_addr
;
3914 s
->port
[imif
].addr_valid
= omap_validate_imif_addr
;
3915 s
->port
[tipb
].addr_valid
= omap_validate_tipb_addr
;
3916 s
->port
[local
].addr_valid
= omap_validate_local_addr
;
3917 s
->port
[tipb_mpui
].addr_valid
= omap_validate_tipb_mpui_addr
;
3919 /* Register SDRAM and SRAM DMA ports for fast transfers. */
3920 soc_dma_port_add_mem(s
->dma
, memory_region_get_ram_ptr(dram
),
3921 OMAP_EMIFF_BASE
, s
->sdram_size
);
3922 soc_dma_port_add_mem(s
->dma
, memory_region_get_ram_ptr(&s
->imif_ram
),
3923 OMAP_IMIF_BASE
, s
->sram_size
);
3925 s
->timer
[0] = omap_mpu_timer_init(system_memory
, 0xfffec500,
3926 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER1
),
3927 omap_findclk(s
, "mputim_ck"));
3928 s
->timer
[1] = omap_mpu_timer_init(system_memory
, 0xfffec600,
3929 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER2
),
3930 omap_findclk(s
, "mputim_ck"));
3931 s
->timer
[2] = omap_mpu_timer_init(system_memory
, 0xfffec700,
3932 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_TIMER3
),
3933 omap_findclk(s
, "mputim_ck"));
3935 s
->wdt
= omap_wd_timer_init(system_memory
, 0xfffec800,
3936 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_WD_TIMER
),
3937 omap_findclk(s
, "armwdt_ck"));
3939 s
->os_timer
= omap_os_timer_init(system_memory
, 0xfffb9000,
3940 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_OS_TIMER
),
3941 omap_findclk(s
, "clk32-kHz"));
3943 s
->lcd
= omap_lcdc_init(system_memory
, 0xfffec000,
3944 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_LCD_CTRL
),
3945 omap_dma_get_lcdch(s
->dma
),
3946 omap_findclk(s
, "lcd_ck"));
3948 omap_ulpd_pm_init(system_memory
, 0xfffe0800, s
);
3949 omap_pin_cfg_init(system_memory
, 0xfffe1000, s
);
3950 omap_id_init(system_memory
, s
);
3952 omap_mpui_init(system_memory
, 0xfffec900, s
);
3954 s
->private_tipb
= omap_tipb_bridge_init(system_memory
, 0xfffeca00,
3955 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_BRIDGE_PRIV
),
3956 omap_findclk(s
, "tipb_ck"));
3957 s
->public_tipb
= omap_tipb_bridge_init(system_memory
, 0xfffed300,
3958 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_BRIDGE_PUB
),
3959 omap_findclk(s
, "tipb_ck"));
3961 omap_tcmi_init(system_memory
, 0xfffecc00, s
);
3963 s
->uart
[0] = omap_uart_init(0xfffb0000,
3964 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_UART1
),
3965 omap_findclk(s
, "uart1_ck"),
3966 omap_findclk(s
, "uart1_ck"),
3967 s
->drq
[OMAP_DMA_UART1_TX
], s
->drq
[OMAP_DMA_UART1_RX
],
3970 s
->uart
[1] = omap_uart_init(0xfffb0800,
3971 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_UART2
),
3972 omap_findclk(s
, "uart2_ck"),
3973 omap_findclk(s
, "uart2_ck"),
3974 s
->drq
[OMAP_DMA_UART2_TX
], s
->drq
[OMAP_DMA_UART2_RX
],
3976 serial_hd(0) ? serial_hd(1) : NULL
);
3977 s
->uart
[2] = omap_uart_init(0xfffb9800,
3978 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_UART3
),
3979 omap_findclk(s
, "uart3_ck"),
3980 omap_findclk(s
, "uart3_ck"),
3981 s
->drq
[OMAP_DMA_UART3_TX
], s
->drq
[OMAP_DMA_UART3_RX
],
3983 serial_hd(0) && serial_hd(1) ? serial_hd(2) : NULL
);
3985 s
->dpll
[0] = omap_dpll_init(system_memory
, 0xfffecf00,
3986 omap_findclk(s
, "dpll1"));
3987 s
->dpll
[1] = omap_dpll_init(system_memory
, 0xfffed000,
3988 omap_findclk(s
, "dpll2"));
3989 s
->dpll
[2] = omap_dpll_init(system_memory
, 0xfffed100,
3990 omap_findclk(s
, "dpll3"));
3992 dinfo
= drive_get(IF_SD
, 0, 0);
3993 if (!dinfo
&& !qtest_enabled()) {
3994 warn_report("missing SecureDigital device");
3996 s
->mmc
= omap_mmc_init(0xfffb7800, system_memory
,
3997 dinfo
? blk_by_legacy_dinfo(dinfo
) : NULL
,
3998 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_OQN
),
3999 &s
->drq
[OMAP_DMA_MMC_TX
],
4000 omap_findclk(s
, "mmc_ck"));
4002 s
->mpuio
= omap_mpuio_init(system_memory
, 0xfffb5000,
4003 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_KEYBOARD
),
4004 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_MPUIO
),
4005 s
->wakeup
, omap_findclk(s
, "clk32-kHz"));
4007 s
->gpio
= qdev_new("omap-gpio");
4008 qdev_prop_set_int32(s
->gpio
, "mpu_model", s
->mpu_model
);
4009 omap_gpio_set_clk(OMAP1_GPIO(s
->gpio
), omap_findclk(s
, "arm_gpio_ck"));
4010 sysbus_realize_and_unref(SYS_BUS_DEVICE(s
->gpio
), &error_fatal
);
4011 sysbus_connect_irq(SYS_BUS_DEVICE(s
->gpio
), 0,
4012 qdev_get_gpio_in(s
->ih
[0], OMAP_INT_GPIO_BANK1
));
4013 sysbus_mmio_map(SYS_BUS_DEVICE(s
->gpio
), 0, 0xfffce000);
4015 s
->microwire
= omap_uwire_init(system_memory
, 0xfffb3000,
4016 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_uWireTX
),
4017 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_uWireRX
),
4018 s
->drq
[OMAP_DMA_UWIRE_TX
], omap_findclk(s
, "mpuper_ck"));
4020 s
->pwl
= omap_pwl_init(system_memory
, 0xfffb5800,
4021 omap_findclk(s
, "armxor_ck"));
4022 s
->pwt
= omap_pwt_init(system_memory
, 0xfffb6000,
4023 omap_findclk(s
, "armxor_ck"));
4025 s
->i2c
[0] = qdev_new("omap_i2c");
4026 qdev_prop_set_uint8(s
->i2c
[0], "revision", 0x11);
4027 omap_i2c_set_fclk(OMAP_I2C(s
->i2c
[0]), omap_findclk(s
, "mpuper_ck"));
4028 busdev
= SYS_BUS_DEVICE(s
->i2c
[0]);
4029 sysbus_realize_and_unref(busdev
, &error_fatal
);
4030 sysbus_connect_irq(busdev
, 0, qdev_get_gpio_in(s
->ih
[1], OMAP_INT_I2C
));
4031 sysbus_connect_irq(busdev
, 1, s
->drq
[OMAP_DMA_I2C_TX
]);
4032 sysbus_connect_irq(busdev
, 2, s
->drq
[OMAP_DMA_I2C_RX
]);
4033 sysbus_mmio_map(busdev
, 0, 0xfffb3800);
4035 s
->rtc
= omap_rtc_init(system_memory
, 0xfffb4800,
4036 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_RTC_TIMER
),
4037 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_RTC_ALARM
),
4038 omap_findclk(s
, "clk32-kHz"));
4040 s
->mcbsp1
= omap_mcbsp_init(system_memory
, 0xfffb1800,
4041 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP1TX
),
4042 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP1RX
),
4043 &s
->drq
[OMAP_DMA_MCBSP1_TX
], omap_findclk(s
, "dspxor_ck"));
4044 s
->mcbsp2
= omap_mcbsp_init(system_memory
, 0xfffb1000,
4045 qdev_get_gpio_in(s
->ih
[0],
4046 OMAP_INT_310_McBSP2_TX
),
4047 qdev_get_gpio_in(s
->ih
[0],
4048 OMAP_INT_310_McBSP2_RX
),
4049 &s
->drq
[OMAP_DMA_MCBSP2_TX
], omap_findclk(s
, "mpuper_ck"));
4050 s
->mcbsp3
= omap_mcbsp_init(system_memory
, 0xfffb7000,
4051 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP3TX
),
4052 qdev_get_gpio_in(s
->ih
[1], OMAP_INT_McBSP3RX
),
4053 &s
->drq
[OMAP_DMA_MCBSP3_TX
], omap_findclk(s
, "dspxor_ck"));
4055 s
->led
[0] = omap_lpg_init(system_memory
,
4056 0xfffbd000, omap_findclk(s
, "clk32-kHz"));
4057 s
->led
[1] = omap_lpg_init(system_memory
,
4058 0xfffbd800, omap_findclk(s
, "clk32-kHz"));
4060 /* Register mappings not currenlty implemented:
4061 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4062 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4063 * USB W2FC fffb4000 - fffb47ff
4064 * Camera Interface fffb6800 - fffb6fff
4065 * USB Host fffba000 - fffba7ff
4066 * FAC fffba800 - fffbafff
4067 * HDQ/1-Wire fffbc000 - fffbc7ff
4068 * TIPB switches fffbc800 - fffbcfff
4069 * Mailbox fffcf000 - fffcf7ff
4070 * Local bus IF fffec100 - fffec1ff
4071 * Local bus MMU fffec200 - fffec2ff
4072 * DSP MMU fffed200 - fffed2ff
4075 omap_setup_dsp_mapping(system_memory
, omap15xx_dsp_mm
);
4076 omap_setup_mpui_io(system_memory
, s
);
4078 qemu_register_reset(omap1_mpu_reset
, s
);