2 * TI OMAP processors emulation.
4 * Copyright (C) 2007-2008 Nokia Corporation
5 * Written by Andrzej Zaborowski <andrew@openedhand.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 or
10 * (at your option) version 3 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "qemu-timer.h"
26 #include "qemu-char.h"
29 #include "audio/audio.h"
32 struct omap_gp_timer_s {
40 struct omap_target_agent_s *ta;
46 int64_t ticks_per_sec;
57 gpt_trigger_none, gpt_trigger_overflow, gpt_trigger_both
60 gpt_capture_none, gpt_capture_rising,
61 gpt_capture_falling, gpt_capture_both
72 uint32_t capture_val[2];
76 uint16_t writeh; /* LSB */
77 uint16_t readh; /* MSB */
80 #define GPT_TCAR_IT (1 << 2)
81 #define GPT_OVF_IT (1 << 1)
82 #define GPT_MAT_IT (1 << 0)
84 /*if the clock source of gptimer changes, rate must be regenerated*/
85 void omap_gp_timer_change_clk(struct omap_gp_timer_s *timer)
87 timer->rate = omap_clk_getrate(timer->clk);
90 static inline void omap_gp_timer_intr(struct omap_gp_timer_s *timer, int it)
92 if (timer->it_ena & it) {
94 qemu_irq_raise(timer->irq);
97 /* Or are the status bits set even when masked?
98 * i.e. is masking applied before or after the status register? */
101 if (timer->wu_ena & it)
102 qemu_irq_pulse(timer->wkup);
105 static inline void omap_gp_timer_out(struct omap_gp_timer_s *timer, int level)
107 if (!timer->inout && timer->out_val != level) {
108 timer->out_val = level;
109 qemu_set_irq(timer->out, level);
113 static inline uint32_t omap_gp_timer_read(struct omap_gp_timer_s *timer)
115 uint64_t distance, rate;
117 if (timer->st && timer->rate) {
118 distance = qemu_get_clock(vm_clock) - timer->time;
120 /*if ticks_per_sec is bigger than 32bit we cannot use muldiv64*/
121 if (timer->ticks_per_sec > 0xffffffff) {
122 distance /= ticks_per_sec / 1000; /*distance ms*/
123 rate = timer->rate >> (timer->pre ? timer->ptv + 1 : 0);
124 distance = muldiv64(distance, rate, 1000);
126 distance = muldiv64(distance, timer->rate, timer->ticks_per_sec);
128 if (distance >= 0xffffffff - timer->val)
131 return timer->val + distance;
136 static inline void omap_gp_timer_sync(struct omap_gp_timer_s *timer)
139 timer->val = omap_gp_timer_read(timer);
140 timer->time = qemu_get_clock(vm_clock);
144 static inline void omap_gp_timer_update(struct omap_gp_timer_s *timer)
146 int64_t expires, matches, rate;
148 if (timer->st && timer->rate) {
149 if (timer->ticks_per_sec > 0xffffffff) {
150 rate = timer->rate >> (timer->pre ? timer->ptv + 1 : 0); /*1s -> rate ticks*/
151 expires = muldiv64(0x100000000ll - timer->val, ticks_per_sec, rate);
153 expires = muldiv64(0x100000000ll - timer->val,
154 timer->ticks_per_sec, timer->rate);
155 qemu_mod_timer(timer->timer, timer->time + expires);
157 if (timer->ce && timer->match_val >= timer->val) {
158 if (timer->ticks_per_sec > 0xffffffff) {
159 rate = timer->rate >> (timer->pre ? timer->ptv + 1 : 0); /*1s -> rate ticks*/
160 matches = muldiv64(timer->match_val - timer->val, ticks_per_sec, rate);
162 matches = muldiv64(timer->match_val - timer->val,
163 timer->ticks_per_sec, timer->rate);
164 qemu_mod_timer(timer->match, timer->time + matches);
166 qemu_del_timer(timer->match);
168 qemu_del_timer(timer->timer);
169 qemu_del_timer(timer->match);
170 omap_gp_timer_out(timer, timer->scpwm);
174 static inline void omap_gp_timer_trigger(struct omap_gp_timer_s *timer)
177 /* TODO in overflow-and-match mode if the first event to
178 * occur is the match, don't toggle. */
179 omap_gp_timer_out(timer, !timer->out_val);
181 /* TODO inverted pulse on timer->out_val == 1? */
182 qemu_irq_pulse(timer->out);
185 static void omap_gp_timer_tick(void *opaque)
187 struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
193 timer->val = timer->load_val;
194 timer->time = qemu_get_clock(vm_clock);
197 if (timer->trigger == gpt_trigger_overflow ||
198 timer->trigger == gpt_trigger_both)
199 omap_gp_timer_trigger(timer);
201 omap_gp_timer_intr(timer, GPT_OVF_IT);
202 omap_gp_timer_update(timer);
205 static void omap_gp_timer_match(void *opaque)
207 struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
209 if (timer->trigger == gpt_trigger_both)
210 omap_gp_timer_trigger(timer);
212 omap_gp_timer_intr(timer, GPT_MAT_IT);
215 static void omap_gp_timer_input(void *opaque, int line, int on)
217 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
220 switch (s->capture) {
222 case gpt_capture_none:
225 case gpt_capture_rising:
226 trigger = !s->in_val && on;
228 case gpt_capture_falling:
229 trigger = s->in_val && !on;
231 case gpt_capture_both:
232 trigger = (s->in_val == !on);
237 if (s->inout && trigger && s->capt_num < 2) {
238 s->capture_val[s->capt_num] = omap_gp_timer_read(s);
240 if (s->capt2 == s->capt_num ++)
241 omap_gp_timer_intr(s, GPT_TCAR_IT);
245 static void omap_gp_timer_clk_update(void *opaque, int line, int on)
247 struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
249 omap_gp_timer_sync(timer);
250 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
251 omap_gp_timer_update(timer);
254 static void omap_gp_timer_clk_setup(struct omap_gp_timer_s *timer)
256 omap_clk_adduser(timer->clk,
257 qemu_allocate_irqs(omap_gp_timer_clk_update, timer, 1)[0]);
258 timer->rate = omap_clk_getrate(timer->clk);
259 //fprintf(stderr, "omap gptimer clk rate 0x%llx\n", timer->rate);
262 static void omap_gp_timer_reset(struct omap_gp_timer_s *s)
272 s->trigger = gpt_trigger_none;
273 s->capture = gpt_capture_none;
282 s->load_val = 0x00000000;
283 s->capture_val[0] = 0x00000000;
284 s->capture_val[1] = 0x00000000;
285 s->match_val = 0x00000000;
286 omap_gp_timer_update(s);
289 static uint32_t omap_gp_timer_readw(void *opaque, target_phys_addr_t addr)
291 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
294 case 0x00: /* TIDR */
297 case 0x10: /* TIOCP_CFG */
300 case 0x14: /* TISTAT */
301 /* ??? When's this bit reset? */
302 return 1; /* RESETDONE */
304 case 0x18: /* TISR */
307 case 0x1c: /* TIER */
310 case 0x20: /* TWER */
313 case 0x24: /* TCLR */
314 return (s->inout << 14) |
326 case 0x28: /* TCRR */
327 return omap_gp_timer_read(s);
329 case 0x2c: /* TLDR */
332 case 0x30: /* TTGR */
335 case 0x34: /* TWPS */
336 return 0x00000000; /* No posted writes pending. */
338 case 0x38: /* TMAR */
341 case 0x3c: /* TCAR1 */
342 return s->capture_val[0];
344 case 0x40: /* TSICR */
345 return s->posted << 2;
347 case 0x44: /* TCAR2 */
348 return s->capture_val[1];
355 static uint32_t omap_gp_timer_readh(void *opaque, target_phys_addr_t addr)
357 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
363 ret = omap_gp_timer_readw(opaque, addr);
364 s->readh = ret >> 16;
369 static CPUReadMemoryFunc *omap_gp_timer_readfn[] = {
370 omap_badwidth_read32,
375 static void omap_gp_timer_write(void *opaque, target_phys_addr_t addr,
378 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
381 case 0x00: /* TIDR */
382 case 0x14: /* TISTAT */
383 case 0x34: /* TWPS */
384 case 0x3c: /* TCAR1 */
385 case 0x44: /* TCAR2 */
389 case 0x10: /* TIOCP_CFG */
390 s->config = value & 0x33d;
391 if (((value >> 3) & 3) == 3) /* IDLEMODE */
392 fprintf(stderr, "%s: illegal IDLEMODE value in TIOCP_CFG\n",
394 if (value & 2) /* SOFTRESET */
395 omap_gp_timer_reset(s);
398 case 0x18: /* TISR */
399 if (value & GPT_TCAR_IT)
401 if (s->status && !(s->status &= ~value))
402 qemu_irq_lower(s->irq);
405 case 0x1c: /* TIER */
406 s->it_ena = value & 7;
409 case 0x20: /* TWER */
410 s->wu_ena = value & 7;
413 case 0x24: /* TCLR */
414 omap_gp_timer_sync(s);
415 s->inout = (value >> 14) & 1;
416 s->capt2 = (value >> 13) & 1;
417 s->pt = (value >> 12) & 1;
418 s->trigger = (value >> 10) & 3;
419 if (s->capture == gpt_capture_none &&
420 ((value >> 8) & 3) != gpt_capture_none)
422 s->capture = (value >> 8) & 3;
423 s->scpwm = (value >> 7) & 1;
424 s->ce = (value >> 6) & 1;
425 s->pre = (value >> 5) & 1;
426 s->ptv = (value >> 2) & 7;
427 s->ar = (value >> 1) & 1;
428 s->st = (value >> 0) & 1;
429 if (s->inout && s->trigger != gpt_trigger_none)
430 fprintf(stderr, "%s: GP timer pin must be an output "
431 "for this trigger mode\n", __FUNCTION__);
432 if (!s->inout && s->capture != gpt_capture_none)
433 fprintf(stderr, "%s: GP timer pin must be an input "
434 "for this capture mode\n", __FUNCTION__);
435 if (s->trigger == gpt_trigger_none)
436 omap_gp_timer_out(s, s->scpwm);
437 /* TODO: make sure this doesn't overflow 32-bits */
438 s->ticks_per_sec = ticks_per_sec << (s->pre ? s->ptv + 1 : 0);
439 omap_gp_timer_update(s);
442 case 0x28: /* TCRR */
443 s->time = qemu_get_clock(vm_clock);
445 omap_gp_timer_update(s);
448 case 0x2c: /* TLDR */
452 case 0x30: /* TTGR */
453 s->time = qemu_get_clock(vm_clock);
454 s->val = s->load_val;
455 omap_gp_timer_update(s);
458 case 0x38: /* TMAR */
459 omap_gp_timer_sync(s);
460 s->match_val = value;
461 omap_gp_timer_update(s);
464 case 0x40: /* TSICR */
465 s->posted = (value >> 2) & 1;
466 if (value & 2) /* How much exactly are we supposed to reset? */
467 omap_gp_timer_reset(s);
475 static void omap_gp_timer_writeh(void *opaque, target_phys_addr_t addr,
478 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
481 return omap_gp_timer_write(opaque, addr, (value << 16) | s->writeh);
483 s->writeh = (uint16_t) value;
486 static CPUWriteMemoryFunc *omap_gp_timer_writefn[] = {
487 omap_badwidth_write32,
488 omap_gp_timer_writeh,
492 struct omap_gp_timer_s *omap_gp_timer_init(struct omap_target_agent_s *ta,
493 qemu_irq irq, omap_clk fclk, omap_clk iclk)
496 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *)
497 qemu_mallocz(sizeof(struct omap_gp_timer_s));
502 s->timer = qemu_new_timer(vm_clock, omap_gp_timer_tick, s);
503 s->match = qemu_new_timer(vm_clock, omap_gp_timer_match, s);
504 s->in = qemu_allocate_irqs(omap_gp_timer_input, s, 1)[0];
505 omap_gp_timer_reset(s);
506 omap_gp_timer_clk_setup(s);
508 iomemtype = l4_register_io_memory(0, omap_gp_timer_readfn,
509 omap_gp_timer_writefn, s);
510 omap_l4_attach(ta, 0, iomemtype);
515 /* 32-kHz Sync Timer of the OMAP2 */
516 static uint32_t omap_synctimer_read(struct omap_synctimer_s *s) {
517 return muldiv64(qemu_get_clock(vm_clock), 0x8000, ticks_per_sec);
520 static void omap_synctimer_reset(struct omap_synctimer_s *s)
522 s->val = omap_synctimer_read(s);
525 static uint32_t omap_synctimer_readw(void *opaque, target_phys_addr_t addr)
527 struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
530 case 0x00: /* 32KSYNCNT_REV */
533 return omap_synctimer_read(s) - s->val;
540 static uint32_t omap3_synctimer_readw(void *opaque, target_phys_addr_t addr)
542 struct omap_synctimer_s *s = (struct omap_synctimer_s *)opaque;
543 return (addr == 0x04)
545 : omap_synctimer_readw(opaque, addr);
548 static uint32_t omap_synctimer_readh(void *opaque, target_phys_addr_t addr)
550 struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
556 ret = omap_synctimer_readw(opaque, addr);
557 s->readh = ret >> 16;
561 static uint32_t omap3_synctimer_readh(void *opaque, target_phys_addr_t addr)
563 struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
569 ret = omap3_synctimer_readw(opaque, addr);
570 s->readh = ret >> 16;
574 static CPUReadMemoryFunc *omap_synctimer_readfn[] = {
575 omap_badwidth_read32,
576 omap_synctimer_readh,
577 omap_synctimer_readw,
580 static CPUReadMemoryFunc *omap3_synctimer_readfn[] = {
581 omap_badwidth_read32,
582 omap3_synctimer_readh,
583 omap3_synctimer_readw,
586 static void omap_synctimer_write(void *opaque, target_phys_addr_t addr,
592 static void omap3_synctimer_write(void *opaque, target_phys_addr_t addr,
595 struct omap_synctimer_s *s = (struct omap_synctimer_s *)opaque;
596 if (addr == 0x04) /* SYSCONFIG */
597 s->sysconfig = value & 0x0c;
602 static CPUWriteMemoryFunc *omap_synctimer_writefn[] = {
603 omap_badwidth_write32,
604 omap_synctimer_write,
605 omap_synctimer_write,
608 static CPUWriteMemoryFunc *omap3_synctimer_writefn[] = {
609 omap_badwidth_write32,
610 omap3_synctimer_write,
611 omap3_synctimer_write,
614 void omap_synctimer_init(struct omap_target_agent_s *ta,
615 struct omap_mpu_state_s *mpu, omap_clk fclk, omap_clk iclk)
617 struct omap_synctimer_s *s = &mpu->synctimer;
619 omap_synctimer_reset(s);
620 if (cpu_class_omap3(mpu))
621 omap_l4_attach(ta, 0, l4_register_io_memory(0,
622 omap3_synctimer_readfn, omap3_synctimer_writefn, s));
624 omap_l4_attach(ta, 0, l4_register_io_memory(0,
625 omap_synctimer_readfn, omap_synctimer_writefn, s));
628 /* General-Purpose Interface of OMAP2 */
629 struct omap2_gpio_s {
633 qemu_irq handler[32];
649 static inline void omap_gpio_module_int_update(struct omap2_gpio_s *s,
652 qemu_set_irq(s->irq[line], s->ints[line] & s->mask[line]);
655 static void omap_gpio_module_wake(struct omap2_gpio_s *s, int line)
657 if (!(s->config[0] & (1 << 2))) /* ENAWAKEUP */
659 if (!(s->config[0] & (3 << 3))) /* Force Idle */
661 if (!(s->wumask & (1 << line)))
664 qemu_irq_raise(s->wkup);
667 static inline void omap_gpio_module_out_update(struct omap2_gpio_s *s,
674 while ((ln = ffs(diff))) {
676 qemu_set_irq(s->handler[ln], (s->outputs >> ln) & 1);
681 static void omap_gpio_module_level_update(struct omap2_gpio_s *s, int line)
683 s->ints[line] |= s->dir &
684 ((s->inputs & s->level[1]) | (~s->inputs & s->level[0]));
685 omap_gpio_module_int_update(s, line);
688 static inline void omap_gpio_module_int(struct omap2_gpio_s *s, int line)
690 s->ints[0] |= 1 << line;
691 omap_gpio_module_int_update(s, 0);
692 s->ints[1] |= 1 << line;
693 omap_gpio_module_int_update(s, 1);
694 omap_gpio_module_wake(s, line);
697 static void omap_gpio_module_set(void *opaque, int line, int level)
699 struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
702 if (s->dir & (1 << line) & ((~s->inputs & s->edge[0]) | s->level[1]))
703 omap_gpio_module_int(s, line);
704 s->inputs |= 1 << line;
706 if (s->dir & (1 << line) & ((s->inputs & s->edge[1]) | s->level[0]))
707 omap_gpio_module_int(s, line);
708 s->inputs &= ~(1 << line);
712 static void omap_gpio_module_reset(struct omap2_gpio_s *s)
730 static uint32_t omap_gpio_module_read(void *opaque, target_phys_addr_t addr)
732 struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
735 case 0x00: /* GPIO_REVISION */
738 case 0x10: /* GPIO_SYSCONFIG */
741 case 0x14: /* GPIO_SYSSTATUS */
744 case 0x18: /* GPIO_IRQSTATUS1 */
747 case 0x1c: /* GPIO_IRQENABLE1 */
748 case 0x60: /* GPIO_CLEARIRQENABLE1 */
749 case 0x64: /* GPIO_SETIRQENABLE1 */
752 case 0x20: /* GPIO_WAKEUPENABLE */
753 case 0x80: /* GPIO_CLEARWKUENA */
754 case 0x84: /* GPIO_SETWKUENA */
757 case 0x28: /* GPIO_IRQSTATUS2 */
760 case 0x2c: /* GPIO_IRQENABLE2 */
761 case 0x70: /* GPIO_CLEARIRQENABLE2 */
762 case 0x74: /* GPIO_SETIREQNEABLE2 */
765 case 0x30: /* GPIO_CTRL */
768 case 0x34: /* GPIO_OE */
771 case 0x38: /* GPIO_DATAIN */
774 case 0x3c: /* GPIO_DATAOUT */
775 case 0x90: /* GPIO_CLEARDATAOUT */
776 case 0x94: /* GPIO_SETDATAOUT */
779 case 0x40: /* GPIO_LEVELDETECT0 */
782 case 0x44: /* GPIO_LEVELDETECT1 */
785 case 0x48: /* GPIO_RISINGDETECT */
788 case 0x4c: /* GPIO_FALLINGDETECT */
791 case 0x50: /* GPIO_DEBOUNCENABLE */
794 case 0x54: /* GPIO_DEBOUNCINGTIME */
802 static void omap_gpio_module_write(void *opaque, target_phys_addr_t addr,
805 struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
810 case 0x00: /* GPIO_REVISION */
811 case 0x14: /* GPIO_SYSSTATUS */
812 case 0x38: /* GPIO_DATAIN */
813 OMAP_RO_REGV(addr, value);
816 case 0x10: /* GPIO_SYSCONFIG */
817 if (((value >> 3) & 3) == 3)
818 fprintf(stderr, "%s: bad IDLEMODE value\n", __FUNCTION__);
820 omap_gpio_module_reset(s);
821 s->config[0] = value & 0x1d;
824 case 0x18: /* GPIO_IRQSTATUS1 */
825 if (s->ints[0] & value) {
826 s->ints[0] &= ~value;
827 omap_gpio_module_level_update(s, 0);
831 case 0x1c: /* GPIO_IRQENABLE1 */
833 omap_gpio_module_int_update(s, 0);
836 case 0x20: /* GPIO_WAKEUPENABLE */
840 case 0x28: /* GPIO_IRQSTATUS2 */
841 if (s->ints[1] & value) {
842 s->ints[1] &= ~value;
843 omap_gpio_module_level_update(s, 1);
847 case 0x2c: /* GPIO_IRQENABLE2 */
849 omap_gpio_module_int_update(s, 1);
852 case 0x30: /* GPIO_CTRL */
853 s->config[1] = value & 7;
856 case 0x34: /* GPIO_OE */
857 diff = s->outputs & (s->dir ^ value);
860 value = s->outputs & ~s->dir;
861 while ((ln = ffs(diff))) {
862 diff &= ~(1 <<-- ln);
863 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
866 omap_gpio_module_level_update(s, 0);
867 omap_gpio_module_level_update(s, 1);
870 case 0x3c: /* GPIO_DATAOUT */
871 omap_gpio_module_out_update(s, s->outputs ^ value);
874 case 0x40: /* GPIO_LEVELDETECT0 */
876 omap_gpio_module_level_update(s, 0);
877 omap_gpio_module_level_update(s, 1);
880 case 0x44: /* GPIO_LEVELDETECT1 */
882 omap_gpio_module_level_update(s, 0);
883 omap_gpio_module_level_update(s, 1);
886 case 0x48: /* GPIO_RISINGDETECT */
890 case 0x4c: /* GPIO_FALLINGDETECT */
894 case 0x50: /* GPIO_DEBOUNCENABLE */
898 case 0x54: /* GPIO_DEBOUNCINGTIME */
902 case 0x60: /* GPIO_CLEARIRQENABLE1 */
903 s->mask[0] &= ~value;
904 omap_gpio_module_int_update(s, 0);
907 case 0x64: /* GPIO_SETIRQENABLE1 */
909 omap_gpio_module_int_update(s, 0);
912 case 0x70: /* GPIO_CLEARIRQENABLE2 */
913 s->mask[1] &= ~value;
914 omap_gpio_module_int_update(s, 1);
917 case 0x74: /* GPIO_SETIREQNEABLE2 */
919 omap_gpio_module_int_update(s, 1);
922 case 0x80: /* GPIO_CLEARWKUENA */
926 case 0x84: /* GPIO_SETWKUENA */
930 case 0x90: /* GPIO_CLEARDATAOUT */
931 omap_gpio_module_out_update(s, s->outputs & value);
934 case 0x94: /* GPIO_SETDATAOUT */
935 omap_gpio_module_out_update(s, ~s->outputs & value);
939 OMAP_BAD_REGV(addr, value);
944 static uint32_t omap_gpio_module_readp(void *opaque, target_phys_addr_t addr)
946 return omap_gpio_module_readp(opaque, addr) >> ((addr & 3) << 3);
949 static void omap_gpio_module_writep(void *opaque, target_phys_addr_t addr,
953 uint32_t mask = 0xffff;
956 case 0x00: /* GPIO_REVISION */
957 case 0x14: /* GPIO_SYSSTATUS */
958 case 0x38: /* GPIO_DATAIN */
962 case 0x10: /* GPIO_SYSCONFIG */
963 case 0x1c: /* GPIO_IRQENABLE1 */
964 case 0x20: /* GPIO_WAKEUPENABLE */
965 case 0x2c: /* GPIO_IRQENABLE2 */
966 case 0x30: /* GPIO_CTRL */
967 case 0x34: /* GPIO_OE */
968 case 0x3c: /* GPIO_DATAOUT */
969 case 0x40: /* GPIO_LEVELDETECT0 */
970 case 0x44: /* GPIO_LEVELDETECT1 */
971 case 0x48: /* GPIO_RISINGDETECT */
972 case 0x4c: /* GPIO_FALLINGDETECT */
973 case 0x50: /* GPIO_DEBOUNCENABLE */
974 case 0x54: /* GPIO_DEBOUNCINGTIME */
975 cur = omap_gpio_module_read(opaque, addr & ~3) &
976 ~(mask << ((addr & 3) << 3));
979 case 0x18: /* GPIO_IRQSTATUS1 */
980 case 0x28: /* GPIO_IRQSTATUS2 */
981 case 0x60: /* GPIO_CLEARIRQENABLE1 */
982 case 0x64: /* GPIO_SETIRQENABLE1 */
983 case 0x70: /* GPIO_CLEARIRQENABLE2 */
984 case 0x74: /* GPIO_SETIREQNEABLE2 */
985 case 0x80: /* GPIO_CLEARWKUENA */
986 case 0x84: /* GPIO_SETWKUENA */
987 case 0x90: /* GPIO_CLEARDATAOUT */
988 case 0x94: /* GPIO_SETDATAOUT */
989 value <<= (addr & 3) << 3;
990 omap_gpio_module_write(opaque, addr, cur | value);
999 static CPUReadMemoryFunc *omap_gpio_module_readfn[] = {
1000 omap_gpio_module_readp,
1001 omap_gpio_module_readp,
1002 omap_gpio_module_read,
1005 static CPUWriteMemoryFunc *omap_gpio_module_writefn[] = {
1006 omap_gpio_module_writep,
1007 omap_gpio_module_writep,
1008 omap_gpio_module_write,
1011 static void omap_gpio_module_init(struct omap_mpu_state_s *mpu,
1012 struct omap2_gpio_s *s,
1013 struct omap_target_agent_s *ta, int region,
1014 qemu_irq mpu_irq, qemu_irq dsp_irq, qemu_irq wkup_irq,
1015 omap_clk fclk, omap_clk iclk)
1019 s->revision = cpu_class_omap3(mpu) ? 0x25 : 0x18;
1020 s->irq[0] = mpu_irq;
1021 s->irq[1] = dsp_irq;
1023 s->in = qemu_allocate_irqs(omap_gpio_module_set, s, 32);
1025 iomemtype = l4_register_io_memory(0, omap_gpio_module_readfn,
1026 omap_gpio_module_writefn, s);
1027 omap_l4_attach(ta, region, iomemtype);
1030 struct omap_gpif_s {
1031 struct omap2_gpio_s module[6];
1038 static void omap_gpif_reset(struct omap_gpif_s *s)
1042 for (i = 0; i < s->modules; i ++)
1043 omap_gpio_module_reset(s->module + i);
1049 static uint32_t omap_gpif_top_read(void *opaque, target_phys_addr_t addr)
1051 struct omap_gpif_s *s = (struct omap_gpif_s *) opaque;
1054 case 0x00: /* IPGENERICOCPSPL_REVISION */
1057 case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */
1060 case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */
1063 case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */
1066 case 0x40: /* IPGENERICOCPSPL_GPO */
1069 case 0x50: /* IPGENERICOCPSPL_GPI */
1077 static void omap_gpif_top_write(void *opaque, target_phys_addr_t addr,
1080 struct omap_gpif_s *s = (struct omap_gpif_s *) opaque;
1083 case 0x00: /* IPGENERICOCPSPL_REVISION */
1084 case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */
1085 case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */
1086 case 0x50: /* IPGENERICOCPSPL_GPI */
1090 case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */
1091 if (value & (1 << 1)) /* SOFTRESET */
1093 s->autoidle = value & 1;
1096 case 0x40: /* IPGENERICOCPSPL_GPO */
1106 static CPUReadMemoryFunc *omap_gpif_top_readfn[] = {
1112 static CPUWriteMemoryFunc *omap_gpif_top_writefn[] = {
1113 omap_gpif_top_write,
1114 omap_gpif_top_write,
1115 omap_gpif_top_write,
1118 struct omap_gpif_s *omap2_gpio_init(struct omap_mpu_state_s *mpu,
1119 struct omap_target_agent_s *ta,
1120 qemu_irq *irq, omap_clk *fclk, omap_clk iclk, int modules)
1123 struct omap_gpif_s *s = (struct omap_gpif_s *)
1124 qemu_mallocz(sizeof(struct omap_gpif_s));
1125 int region[4] = { 0, 2, 4, 5 };
1127 s->modules = modules;
1128 for (i = 0; i < modules; i ++)
1129 omap_gpio_module_init(mpu, s->module + i, ta, region[i],
1130 irq[i], 0, 0, fclk[i], iclk);
1134 iomemtype = l4_register_io_memory(0, omap_gpif_top_readfn,
1135 omap_gpif_top_writefn, s);
1136 omap_l4_attach(ta, 1, iomemtype);
1141 struct omap_gpif_s *omap3_gpif_init()
1143 struct omap_gpif_s *s = (struct omap_gpif_s *)
1144 qemu_mallocz(sizeof(struct omap_gpif_s));
1149 void omap3_gpio_init(struct omap_mpu_state_s *mpu,
1150 struct omap_gpif_s *s,struct omap_target_agent_s *ta,
1151 qemu_irq *irq, omap_clk *fclk, omap_clk iclk, int module_index)
1154 omap_gpio_module_init(mpu, s->module + module_index, ta, 0,
1155 irq[module_index], 0, 0, NULL,NULL);
1158 qemu_irq *omap2_gpio_in_get(struct omap_gpif_s *s, int start)
1160 if (start >= s->modules * 32 || start < 0)
1161 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n",
1162 __FUNCTION__, start);
1163 return s->module[start >> 5].in + (start & 31);
1166 void omap2_gpio_out_set(struct omap_gpif_s *s, int line, qemu_irq handler)
1168 if (line >= s->modules * 32 || line < 0)
1169 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
1170 s->module[line >> 5].handler[line & 31] = handler;
1173 /* Multichannel SPI */
1174 struct omap_mcspi_s {
1185 struct omap_mcspi_ch_s {
1188 uint32_t (*txrx)(void *opaque, uint32_t, int);
1200 static inline void omap_mcspi_interrupt_update(struct omap_mcspi_s *s)
1202 qemu_set_irq(s->irq, s->irqst & s->irqen);
1205 static inline void omap_mcspi_dmarequest_update(struct omap_mcspi_ch_s *ch)
1207 qemu_set_irq(ch->txdrq,
1208 (ch->control & 1) && /* EN */
1209 (ch->config & (1 << 14)) && /* DMAW */
1210 (ch->status & (1 << 1)) && /* TXS */
1211 ((ch->config >> 12) & 3) != 1); /* TRM */
1212 qemu_set_irq(ch->rxdrq,
1213 (ch->control & 1) && /* EN */
1214 (ch->config & (1 << 15)) && /* DMAW */
1215 (ch->status & (1 << 0)) && /* RXS */
1216 ((ch->config >> 12) & 3) != 2); /* TRM */
1219 static void omap_mcspi_transfer_run(struct omap_mcspi_s *s, int chnum)
1221 struct omap_mcspi_ch_s *ch = s->ch + chnum;
1223 if (!(ch->control & 1)) /* EN */
1225 if ((ch->status & (1 << 0)) && /* RXS */
1226 ((ch->config >> 12) & 3) != 2 && /* TRM */
1227 !(ch->config & (1 << 19))) /* TURBO */
1229 if ((ch->status & (1 << 1)) && /* TXS */
1230 ((ch->config >> 12) & 3) != 1) /* TRM */
1233 if (!(s->control & 1) || /* SINGLE */
1234 (ch->config & (1 << 20))) { /* FORCE */
1236 ch->rx = ch->txrx(ch->opaque, ch->tx, /* WL */
1237 1 + (0x1f & (ch->config >> 7)));
1241 ch->status |= 1 << 2; /* EOT */
1242 ch->status |= 1 << 1; /* TXS */
1243 if (((ch->config >> 12) & 3) != 2) /* TRM */
1244 ch->status |= 1 << 0; /* RXS */
1247 if ((ch->status & (1 << 0)) && /* RXS */
1248 ((ch->config >> 12) & 3) != 2 && /* TRM */
1249 !(ch->config & (1 << 19))) /* TURBO */
1250 s->irqst |= 1 << (2 + 4 * chnum); /* RX_FULL */
1251 if ((ch->status & (1 << 1)) && /* TXS */
1252 ((ch->config >> 12) & 3) != 1) /* TRM */
1253 s->irqst |= 1 << (0 + 4 * chnum); /* TX_EMPTY */
1254 omap_mcspi_interrupt_update(s);
1255 omap_mcspi_dmarequest_update(ch);
1258 static void omap_mcspi_reset(struct omap_mcspi_s *s)
1269 for (ch = 0; ch < 4; ch ++) {
1270 s->ch[ch].config = 0x060000;
1271 s->ch[ch].status = 2; /* TXS */
1272 s->ch[ch].control = 0;
1274 omap_mcspi_dmarequest_update(s->ch + ch);
1277 omap_mcspi_interrupt_update(s);
1280 static uint32_t omap_mcspi_read(void *opaque, target_phys_addr_t addr)
1282 struct omap_mcspi_s *s = (struct omap_mcspi_s *) opaque;
1287 case 0x00: /* MCSPI_REVISION */
1290 case 0x10: /* MCSPI_SYSCONFIG */
1291 return s->sysconfig;
1293 case 0x14: /* MCSPI_SYSSTATUS */
1294 return 1; /* RESETDONE */
1296 case 0x18: /* MCSPI_IRQSTATUS */
1299 case 0x1c: /* MCSPI_IRQENABLE */
1302 case 0x20: /* MCSPI_WAKEUPENABLE */
1305 case 0x24: /* MCSPI_SYST */
1308 case 0x28: /* MCSPI_MODULCTRL */
1314 case 0x2c: /* MCSPI_CHCONF */
1315 return s->ch[ch].config;
1320 case 0x30: /* MCSPI_CHSTAT */
1321 return s->ch[ch].status;
1326 case 0x34: /* MCSPI_CHCTRL */
1327 return s->ch[ch].control;
1332 case 0x38: /* MCSPI_TX */
1333 return s->ch[ch].tx;
1338 case 0x3c: /* MCSPI_RX */
1339 s->ch[ch].status &= ~(1 << 0); /* RXS */
1341 omap_mcspi_transfer_run(s, ch);
1349 static void omap_mcspi_write(void *opaque, target_phys_addr_t addr,
1352 struct omap_mcspi_s *s = (struct omap_mcspi_s *) opaque;
1356 case 0x00: /* MCSPI_REVISION */
1357 case 0x14: /* MCSPI_SYSSTATUS */
1358 case 0x30: /* MCSPI_CHSTAT0 */
1359 case 0x3c: /* MCSPI_RX0 */
1360 case 0x44: /* MCSPI_CHSTAT1 */
1361 case 0x50: /* MCSPI_RX1 */
1362 case 0x58: /* MCSPI_CHSTAT2 */
1363 case 0x64: /* MCSPI_RX2 */
1364 case 0x6c: /* MCSPI_CHSTAT3 */
1365 case 0x78: /* MCSPI_RX3 */
1369 case 0x10: /* MCSPI_SYSCONFIG */
1370 if (value & (1 << 1)) /* SOFTRESET */
1371 omap_mcspi_reset(s);
1372 s->sysconfig = value & 0x31d;
1375 case 0x18: /* MCSPI_IRQSTATUS */
1376 if (!((s->control & (1 << 3)) && (s->systest & (1 << 11)))) {
1378 omap_mcspi_interrupt_update(s);
1382 case 0x1c: /* MCSPI_IRQENABLE */
1383 s->irqen = value & 0x1777f;
1384 omap_mcspi_interrupt_update(s);
1387 case 0x20: /* MCSPI_WAKEUPENABLE */
1388 s->wken = value & 1;
1391 case 0x24: /* MCSPI_SYST */
1392 if (s->control & (1 << 3)) /* SYSTEM_TEST */
1393 if (value & (1 << 11)) { /* SSB */
1394 s->irqst |= 0x1777f;
1395 omap_mcspi_interrupt_update(s);
1397 s->systest = value & 0xfff;
1400 case 0x28: /* MCSPI_MODULCTRL */
1401 if (value & (1 << 3)) /* SYSTEM_TEST */
1402 if (s->systest & (1 << 11)) { /* SSB */
1403 s->irqst |= 0x1777f;
1404 omap_mcspi_interrupt_update(s);
1406 s->control = value & 0xf;
1412 case 0x2c: /* MCSPI_CHCONF */
1413 if ((value ^ s->ch[ch].config) & (3 << 14)) /* DMAR | DMAW */
1414 omap_mcspi_dmarequest_update(s->ch + ch);
1415 if (((value >> 12) & 3) == 3) /* TRM */
1416 fprintf(stderr, "%s: invalid TRM value (3)\n", __FUNCTION__);
1417 if (((value >> 7) & 0x1f) < 3) /* WL */
1418 fprintf(stderr, "%s: invalid WL value (%i)\n",
1419 __FUNCTION__, (value >> 7) & 0x1f);
1420 s->ch[ch].config = value & 0x7fffff;
1426 case 0x34: /* MCSPI_CHCTRL */
1427 if (value & ~s->ch[ch].control & 1) { /* EN */
1428 s->ch[ch].control |= 1;
1429 omap_mcspi_transfer_run(s, ch);
1431 s->ch[ch].control = value & 1;
1437 case 0x38: /* MCSPI_TX */
1438 s->ch[ch].tx = value;
1439 s->ch[ch].status &= ~(1 << 1); /* TXS */
1440 omap_mcspi_transfer_run(s, ch);
1449 static CPUReadMemoryFunc *omap_mcspi_readfn[] = {
1450 omap_badwidth_read32,
1451 omap_badwidth_read32,
1455 static CPUWriteMemoryFunc *omap_mcspi_writefn[] = {
1456 omap_badwidth_write32,
1457 omap_badwidth_write32,
1461 struct omap_mcspi_s *omap_mcspi_init(struct omap_target_agent_s *ta, int chnum,
1462 qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk)
1465 struct omap_mcspi_s *s = (struct omap_mcspi_s *)
1466 qemu_mallocz(sizeof(struct omap_mcspi_s));
1467 struct omap_mcspi_ch_s *ch = s->ch;
1472 ch->txdrq = *drq ++;
1473 ch->rxdrq = *drq ++;
1476 omap_mcspi_reset(s);
1478 iomemtype = l4_register_io_memory(0, omap_mcspi_readfn,
1479 omap_mcspi_writefn, s);
1480 omap_l4_attach(ta, 0, iomemtype);
1485 void omap_mcspi_attach(struct omap_mcspi_s *s,
1486 uint32_t (*txrx)(void *opaque, uint32_t, int), void *opaque,
1489 if (chipselect < 0 || chipselect >= s->chnum)
1490 cpu_abort(cpu_single_env, "%s: Bad chipselect %i\n",
1491 __FUNCTION__, chipselect);
1493 s->ch[chipselect].txrx = txrx;
1494 s->ch[chipselect].opaque = opaque;
1497 /* Enhanced Audio Controller (CODEC only) */
1516 uint32_t (*txrx)(void *opaque, uint32_t, int);
1519 #define EAC_BUF_LEN 1024
1520 uint32_t rxbuf[EAC_BUF_LEN];
1524 uint32_t txbuf[EAC_BUF_LEN];
1533 /* These need to be moved to the actual codec */
1535 SWVoiceIn *in_voice;
1536 SWVoiceOut *out_voice;
1546 static inline void omap_eac_interrupt_update(struct omap_eac_s *s)
1548 qemu_set_irq(s->irq, (s->codec.config[1] >> 14) & 1); /* AURDI */
1551 static inline void omap_eac_in_dmarequest_update(struct omap_eac_s *s)
1553 qemu_set_irq(s->codec.rxdrq, (s->codec.rxavail || s->codec.rxlen) &&
1554 ((s->codec.config[1] >> 12) & 1)); /* DMAREN */
1557 static inline void omap_eac_out_dmarequest_update(struct omap_eac_s *s)
1559 qemu_set_irq(s->codec.txdrq, s->codec.txlen < s->codec.txavail &&
1560 ((s->codec.config[1] >> 11) & 1)); /* DMAWEN */
1563 static inline void omap_eac_in_refill(struct omap_eac_s *s)
1565 int left = MIN(EAC_BUF_LEN - s->codec.rxlen, s->codec.rxavail) << 2;
1566 int start = ((s->codec.rxoff + s->codec.rxlen) & (EAC_BUF_LEN - 1)) << 2;
1567 int leftwrap = MIN(left, (EAC_BUF_LEN << 2) - start);
1569 uint8_t *buf = (uint8_t *) s->codec.rxbuf + start;
1573 while (leftwrap && (recv = AUD_read(s->codec.in_voice, buf + start,
1574 leftwrap)) > 0) { /* Be defensive */
1579 s->codec.rxavail = 0;
1581 s->codec.rxavail -= start >> 2;
1582 s->codec.rxlen += start >> 2;
1584 if (recv > 0 && left > 0) {
1586 while (left && (recv = AUD_read(s->codec.in_voice,
1587 (uint8_t *) s->codec.rxbuf + start,
1588 left)) > 0) { /* Be defensive */
1593 s->codec.rxavail = 0;
1595 s->codec.rxavail -= start >> 2;
1596 s->codec.rxlen += start >> 2;
1600 static inline void omap_eac_out_empty(struct omap_eac_s *s)
1602 int left = s->codec.txlen << 2;
1606 while (left && (sent = AUD_write(s->codec.out_voice,
1607 (uint8_t *) s->codec.txbuf + start,
1608 left)) > 0) { /* Be defensive */
1614 s->codec.txavail = 0;
1615 omap_eac_out_dmarequest_update(s);
1622 static void omap_eac_in_cb(void *opaque, int avail_b)
1624 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1626 s->codec.rxavail = avail_b >> 2;
1627 omap_eac_in_refill(s);
1628 /* TODO: possibly discard current buffer if overrun */
1629 omap_eac_in_dmarequest_update(s);
1632 static void omap_eac_out_cb(void *opaque, int free_b)
1634 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1636 s->codec.txavail = free_b >> 2;
1638 omap_eac_out_empty(s);
1640 omap_eac_out_dmarequest_update(s);
1643 static void omap_eac_enable_update(struct omap_eac_s *s)
1645 s->codec.enable = !(s->codec.config[1] & 1) && /* EACPWD */
1646 (s->codec.config[1] & 2) && /* AUDEN */
1650 static const int omap_eac_fsint[4] = {
1657 static const int omap_eac_fsint2[8] = {
1666 static const int omap_eac_fsint3[16] = {
1675 0, 0, 0, 0, 0, 0, 0, 0,
1678 static void omap_eac_rate_update(struct omap_eac_s *s)
1682 fsint[2] = (s->codec.config[3] >> 9) & 0xf;
1683 fsint[1] = (s->codec.config[2] >> 0) & 0x7;
1684 fsint[0] = (s->codec.config[0] >> 6) & 0x3;
1686 s->codec.rate = omap_eac_fsint3[fsint[2]];
1687 else if (fsint[1] < 0x7)
1688 s->codec.rate = omap_eac_fsint2[fsint[1]];
1690 s->codec.rate = omap_eac_fsint[fsint[0]];
1693 static void omap_eac_volume_update(struct omap_eac_s *s)
1698 static void omap_eac_format_update(struct omap_eac_s *s)
1700 struct audsettings fmt;
1702 /* The hardware buffers at most one sample */
1706 if (s->codec.in_voice) {
1707 AUD_set_active_in(s->codec.in_voice, 0);
1708 AUD_close_in(&s->codec.card, s->codec.in_voice);
1709 s->codec.in_voice = 0;
1711 if (s->codec.out_voice) {
1712 omap_eac_out_empty(s);
1713 AUD_set_active_out(s->codec.out_voice, 0);
1714 AUD_close_out(&s->codec.card, s->codec.out_voice);
1715 s->codec.out_voice = 0;
1716 s->codec.txavail = 0;
1718 /* Discard what couldn't be written */
1721 omap_eac_enable_update(s);
1722 if (!s->codec.enable)
1725 omap_eac_rate_update(s);
1726 fmt.endianness = ((s->codec.config[0] >> 8) & 1); /* LI_BI */
1727 fmt.nchannels = ((s->codec.config[0] >> 10) & 1) ? 2 : 1; /* MN_ST */
1728 fmt.freq = s->codec.rate;
1729 /* TODO: signedness possibly depends on the CODEC hardware - or
1730 * does I2S specify it? */
1731 /* All register writes are 16 bits so we we store 16-bit samples
1732 * in the buffers regardless of AGCFR[B8_16] value. */
1733 fmt.fmt = AUD_FMT_U16;
1735 s->codec.in_voice = AUD_open_in(&s->codec.card, s->codec.in_voice,
1736 "eac.codec.in", s, omap_eac_in_cb, &fmt);
1737 s->codec.out_voice = AUD_open_out(&s->codec.card, s->codec.out_voice,
1738 "eac.codec.out", s, omap_eac_out_cb, &fmt);
1740 omap_eac_volume_update(s);
1742 AUD_set_active_in(s->codec.in_voice, 1);
1743 AUD_set_active_out(s->codec.out_voice, 1);
1746 static void omap_eac_reset(struct omap_eac_s *s)
1749 s->config[0] = 0x0c;
1750 s->config[1] = 0x09;
1751 s->config[2] = 0xab;
1752 s->config[3] = 0x03;
1759 s->gain[0] = 0xe7e7;
1760 s->gain[1] = 0x6767;
1761 s->gain[2] = 0x6767;
1762 s->gain[3] = 0x6767;
1772 s->modem.control = 0x00;
1773 s->modem.config = 0x0000;
1774 s->bt.control = 0x00;
1775 s->bt.config = 0x0000;
1776 s->codec.config[0] = 0x0649;
1777 s->codec.config[1] = 0x0000;
1778 s->codec.config[2] = 0x0007;
1779 s->codec.config[3] = 0x1ffc;
1783 s->codec.rxavail = 0;
1784 s->codec.txavail = 0;
1786 omap_eac_format_update(s);
1787 omap_eac_interrupt_update(s);
1790 static uint32_t omap_eac_read(void *opaque, target_phys_addr_t addr)
1792 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1796 case 0x000: /* CPCFR1 */
1797 return s->config[0];
1798 case 0x004: /* CPCFR2 */
1799 return s->config[1];
1800 case 0x008: /* CPCFR3 */
1801 return s->config[2];
1802 case 0x00c: /* CPCFR4 */
1803 return s->config[3];
1805 case 0x010: /* CPTCTL */
1806 return s->control | ((s->codec.rxavail + s->codec.rxlen > 0) << 7) |
1807 ((s->codec.txlen < s->codec.txavail) << 5);
1809 case 0x014: /* CPTTADR */
1811 case 0x018: /* CPTDATL */
1812 return s->data & 0xff;
1813 case 0x01c: /* CPTDATH */
1814 return s->data >> 8;
1815 case 0x020: /* CPTVSLL */
1817 case 0x024: /* CPTVSLH */
1818 return s->vtsl | (3 << 5); /* CRDY1 | CRDY2 */
1819 case 0x040: /* MPCTR */
1820 return s->modem.control;
1821 case 0x044: /* MPMCCFR */
1822 return s->modem.config;
1823 case 0x060: /* BPCTR */
1824 return s->bt.control;
1825 case 0x064: /* BPMCCFR */
1826 return s->bt.config;
1827 case 0x080: /* AMSCFR */
1829 case 0x084: /* AMVCTR */
1831 case 0x088: /* AM1VCTR */
1833 case 0x08c: /* AM2VCTR */
1835 case 0x090: /* AM3VCTR */
1837 case 0x094: /* ASTCTR */
1839 case 0x098: /* APD1LCR */
1841 case 0x09c: /* APD1RCR */
1843 case 0x0a0: /* APD2LCR */
1845 case 0x0a4: /* APD2RCR */
1847 case 0x0a8: /* APD3LCR */
1849 case 0x0ac: /* APD3RCR */
1851 case 0x0b0: /* APD4R */
1853 case 0x0b4: /* ADWR */
1854 /* This should be write-only? Docs list it as read-only. */
1856 case 0x0b8: /* ADRDR */
1857 if (likely(s->codec.rxlen > 1)) {
1858 ret = s->codec.rxbuf[s->codec.rxoff ++];
1860 s->codec.rxoff &= EAC_BUF_LEN - 1;
1862 } else if (s->codec.rxlen) {
1863 ret = s->codec.rxbuf[s->codec.rxoff ++];
1865 s->codec.rxoff &= EAC_BUF_LEN - 1;
1866 if (s->codec.rxavail)
1867 omap_eac_in_refill(s);
1868 omap_eac_in_dmarequest_update(s);
1872 case 0x0bc: /* AGCFR */
1873 return s->codec.config[0];
1874 case 0x0c0: /* AGCTR */
1875 return s->codec.config[1] | ((s->codec.config[1] & 2) << 14);
1876 case 0x0c4: /* AGCFR2 */
1877 return s->codec.config[2];
1878 case 0x0c8: /* AGCFR3 */
1879 return s->codec.config[3];
1880 case 0x0cc: /* MBPDMACTR */
1881 case 0x0d0: /* MPDDMARR */
1882 case 0x0d8: /* MPUDMARR */
1883 case 0x0e4: /* BPDDMARR */
1884 case 0x0ec: /* BPUDMARR */
1887 case 0x100: /* VERSION_NUMBER */
1890 case 0x104: /* SYSCONFIG */
1891 return s->sysconfig;
1893 case 0x108: /* SYSSTATUS */
1894 return 1 | 0xe; /* RESETDONE | stuff */
1901 static void omap_eac_write(void *opaque, target_phys_addr_t addr,
1904 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1907 case 0x098: /* APD1LCR */
1908 case 0x09c: /* APD1RCR */
1909 case 0x0a0: /* APD2LCR */
1910 case 0x0a4: /* APD2RCR */
1911 case 0x0a8: /* APD3LCR */
1912 case 0x0ac: /* APD3RCR */
1913 case 0x0b0: /* APD4R */
1914 case 0x0b8: /* ADRDR */
1915 case 0x0d0: /* MPDDMARR */
1916 case 0x0d8: /* MPUDMARR */
1917 case 0x0e4: /* BPDDMARR */
1918 case 0x0ec: /* BPUDMARR */
1919 case 0x100: /* VERSION_NUMBER */
1920 case 0x108: /* SYSSTATUS */
1924 case 0x000: /* CPCFR1 */
1925 s->config[0] = value & 0xff;
1926 omap_eac_format_update(s);
1928 case 0x004: /* CPCFR2 */
1929 s->config[1] = value & 0xff;
1930 omap_eac_format_update(s);
1932 case 0x008: /* CPCFR3 */
1933 s->config[2] = value & 0xff;
1934 omap_eac_format_update(s);
1936 case 0x00c: /* CPCFR4 */
1937 s->config[3] = value & 0xff;
1938 omap_eac_format_update(s);
1941 case 0x010: /* CPTCTL */
1942 /* Assuming TXF and TXE bits are read-only... */
1943 s->control = value & 0x5f;
1944 omap_eac_interrupt_update(s);
1947 case 0x014: /* CPTTADR */
1948 s->address = value & 0xff;
1950 case 0x018: /* CPTDATL */
1952 s->data |= value & 0xff;
1954 case 0x01c: /* CPTDATH */
1956 s->data |= value << 8;
1958 case 0x020: /* CPTVSLL */
1959 s->vtol = value & 0xf8;
1961 case 0x024: /* CPTVSLH */
1962 s->vtsl = value & 0x9f;
1964 case 0x040: /* MPCTR */
1965 s->modem.control = value & 0x8f;
1967 case 0x044: /* MPMCCFR */
1968 s->modem.config = value & 0x7fff;
1970 case 0x060: /* BPCTR */
1971 s->bt.control = value & 0x8f;
1973 case 0x064: /* BPMCCFR */
1974 s->bt.config = value & 0x7fff;
1976 case 0x080: /* AMSCFR */
1977 s->mixer = value & 0x0fff;
1979 case 0x084: /* AMVCTR */
1980 s->gain[0] = value & 0xffff;
1982 case 0x088: /* AM1VCTR */
1983 s->gain[1] = value & 0xff7f;
1985 case 0x08c: /* AM2VCTR */
1986 s->gain[2] = value & 0xff7f;
1988 case 0x090: /* AM3VCTR */
1989 s->gain[3] = value & 0xff7f;
1991 case 0x094: /* ASTCTR */
1992 s->att = value & 0xff;
1995 case 0x0b4: /* ADWR */
1996 s->codec.txbuf[s->codec.txlen ++] = value;
1997 if (unlikely(s->codec.txlen == EAC_BUF_LEN ||
1998 s->codec.txlen == s->codec.txavail)) {
1999 if (s->codec.txavail)
2000 omap_eac_out_empty(s);
2001 /* Discard what couldn't be written */
2006 case 0x0bc: /* AGCFR */
2007 s->codec.config[0] = value & 0x07ff;
2008 omap_eac_format_update(s);
2010 case 0x0c0: /* AGCTR */
2011 s->codec.config[1] = value & 0x780f;
2012 omap_eac_format_update(s);
2014 case 0x0c4: /* AGCFR2 */
2015 s->codec.config[2] = value & 0x003f;
2016 omap_eac_format_update(s);
2018 case 0x0c8: /* AGCFR3 */
2019 s->codec.config[3] = value & 0xffff;
2020 omap_eac_format_update(s);
2022 case 0x0cc: /* MBPDMACTR */
2023 case 0x0d4: /* MPDDMAWR */
2024 case 0x0e0: /* MPUDMAWR */
2025 case 0x0e8: /* BPDDMAWR */
2026 case 0x0f0: /* BPUDMAWR */
2029 case 0x104: /* SYSCONFIG */
2030 if (value & (1 << 1)) /* SOFTRESET */
2032 s->sysconfig = value & 0x31d;
2041 static CPUReadMemoryFunc *omap_eac_readfn[] = {
2042 omap_badwidth_read16,
2044 omap_badwidth_read16,
2047 static CPUWriteMemoryFunc *omap_eac_writefn[] = {
2048 omap_badwidth_write16,
2050 omap_badwidth_write16,
2053 struct omap_eac_s *omap_eac_init(struct omap_target_agent_s *ta,
2054 qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk)
2057 struct omap_eac_s *s = (struct omap_eac_s *)
2058 qemu_mallocz(sizeof(struct omap_eac_s));
2061 s->codec.rxdrq = *drq ++;
2062 s->codec.txdrq = *drq ++;
2066 /* TODO: do AUD_init globally for machine */
2067 AUD_register_card(AUD_init(), "OMAP EAC", &s->codec.card);
2069 iomemtype = cpu_register_io_memory(0, omap_eac_readfn,
2070 omap_eac_writefn, s);
2071 omap_l4_attach(ta, 0, iomemtype);
2077 /* STI/XTI (emulation interface) console - reverse engineered only */
2080 CharDriverState *chr;
2086 uint32_t clkcontrol;
2087 uint32_t serial_config;
2090 #define STI_TRACE_CONSOLE_CHANNEL 239
2091 #define STI_TRACE_CONTROL_CHANNEL 253
2093 static inline void omap_sti_interrupt_update(struct omap_sti_s *s)
2095 qemu_set_irq(s->irq, s->irqst & s->irqen);
2098 static void omap_sti_reset(struct omap_sti_s *s)
2104 s->serial_config = 0;
2106 omap_sti_interrupt_update(s);
2109 static uint32_t omap_sti_read(void *opaque, target_phys_addr_t addr)
2111 struct omap_sti_s *s = (struct omap_sti_s *) opaque;
2114 case 0x00: /* STI_REVISION */
2117 case 0x10: /* STI_SYSCONFIG */
2118 return s->sysconfig;
2120 case 0x14: /* STI_SYSSTATUS / STI_RX_STATUS / XTI_SYSSTATUS */
2123 case 0x18: /* STI_IRQSTATUS */
2126 case 0x1c: /* STI_IRQSETEN / STI_IRQCLREN */
2129 case 0x24: /* STI_ER / STI_DR / XTI_TRACESELECT */
2130 case 0x28: /* STI_RX_DR / XTI_RXDATA */
2134 case 0x2c: /* STI_CLK_CTRL / XTI_SCLKCRTL */
2135 return s->clkcontrol;
2137 case 0x30: /* STI_SERIAL_CFG / XTI_SCONFIG */
2138 return s->serial_config;
2145 static void omap_sti_write(void *opaque, target_phys_addr_t addr,
2148 struct omap_sti_s *s = (struct omap_sti_s *) opaque;
2151 case 0x00: /* STI_REVISION */
2152 case 0x14: /* STI_SYSSTATUS / STI_RX_STATUS / XTI_SYSSTATUS */
2156 case 0x10: /* STI_SYSCONFIG */
2157 if (value & (1 << 1)) /* SOFTRESET */
2159 s->sysconfig = value & 0xfe;
2162 case 0x18: /* STI_IRQSTATUS */
2164 omap_sti_interrupt_update(s);
2167 case 0x1c: /* STI_IRQSETEN / STI_IRQCLREN */
2168 s->irqen = value & 0xffff;
2169 omap_sti_interrupt_update(s);
2172 case 0x2c: /* STI_CLK_CTRL / XTI_SCLKCRTL */
2173 s->clkcontrol = value & 0xff;
2176 case 0x30: /* STI_SERIAL_CFG / XTI_SCONFIG */
2177 s->serial_config = value & 0xff;
2180 case 0x24: /* STI_ER / STI_DR / XTI_TRACESELECT */
2181 case 0x28: /* STI_RX_DR / XTI_RXDATA */
2191 static CPUReadMemoryFunc *omap_sti_readfn[] = {
2192 omap_badwidth_read32,
2193 omap_badwidth_read32,
2197 static CPUWriteMemoryFunc *omap_sti_writefn[] = {
2198 omap_badwidth_write32,
2199 omap_badwidth_write32,
2203 static uint32_t omap_sti_fifo_read(void *opaque, target_phys_addr_t addr)
2209 static void omap_sti_fifo_write(void *opaque, target_phys_addr_t addr,
2212 struct omap_sti_s *s = (struct omap_sti_s *) opaque;
2214 uint8_t byte = value;
2216 if (ch == STI_TRACE_CONTROL_CHANNEL) {
2217 /* Flush channel <i>value</i>. */
2218 qemu_chr_write(s->chr, (const uint8_t *) "\r", 1);
2219 } else if (ch == STI_TRACE_CONSOLE_CHANNEL || 1) {
2220 if (value == 0xc0 || value == 0xc3) {
2221 /* Open channel <i>ch</i>. */
2222 } else if (value == 0x00)
2223 qemu_chr_write(s->chr, (const uint8_t *) "\n", 1);
2225 qemu_chr_write(s->chr, &byte, 1);
2229 static CPUReadMemoryFunc *omap_sti_fifo_readfn[] = {
2231 omap_badwidth_read8,
2232 omap_badwidth_read8,
2235 static CPUWriteMemoryFunc *omap_sti_fifo_writefn[] = {
2236 omap_sti_fifo_write,
2237 omap_badwidth_write8,
2238 omap_badwidth_write8,
2241 static struct omap_sti_s *omap_sti_init(struct omap_target_agent_s *ta,
2242 target_phys_addr_t channel_base, qemu_irq irq, omap_clk clk,
2243 CharDriverState *chr)
2246 struct omap_sti_s *s = (struct omap_sti_s *)
2247 qemu_mallocz(sizeof(struct omap_sti_s));
2252 s->chr = chr ?: qemu_chr_open("null", "null", NULL);
2254 iomemtype = l4_register_io_memory(0, omap_sti_readfn,
2255 omap_sti_writefn, s);
2256 omap_l4_attach(ta, 0, iomemtype);
2258 iomemtype = cpu_register_io_memory(0, omap_sti_fifo_readfn,
2259 omap_sti_fifo_writefn, s);
2260 cpu_register_physical_memory(channel_base, 0x10000, iomemtype);
2265 /* L4 Interconnect */
2267 static int omap_l4_io_entries;
2268 static int omap_cpu_io_entry;
2269 static struct omap_l4_entry {
2270 CPUReadMemoryFunc **mem_read;
2271 CPUWriteMemoryFunc **mem_write;
2273 } *omap_l4_io_entry;
2274 static CPUReadMemoryFunc **omap_l4_io_readb_fn;
2275 static CPUReadMemoryFunc **omap_l4_io_readh_fn;
2276 static CPUReadMemoryFunc **omap_l4_io_readw_fn;
2277 static CPUWriteMemoryFunc **omap_l4_io_writeb_fn;
2278 static CPUWriteMemoryFunc **omap_l4_io_writeh_fn;
2279 static CPUWriteMemoryFunc **omap_l4_io_writew_fn;
2280 static void **omap_l4_io_opaque;
2282 int l4_register_io_memory(int io_index, CPUReadMemoryFunc **mem_read,
2283 CPUWriteMemoryFunc **mem_write, void *opaque)
2285 omap_l4_io_entry[omap_l4_io_entries].mem_read = mem_read;
2286 omap_l4_io_entry[omap_l4_io_entries].mem_write = mem_write;
2287 omap_l4_io_entry[omap_l4_io_entries].opaque = opaque;
2289 return omap_l4_io_entries ++;
2292 static uint32_t omap_l4_io_readb(void *opaque, target_phys_addr_t addr)
2294 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2296 return omap_l4_io_readb_fn[i](omap_l4_io_opaque[i], addr);
2299 static uint32_t omap_l4_io_readh(void *opaque, target_phys_addr_t addr)
2301 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2303 return omap_l4_io_readh_fn[i](omap_l4_io_opaque[i], addr);
2306 static uint32_t omap_l4_io_readw(void *opaque, target_phys_addr_t addr)
2308 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2310 return omap_l4_io_readw_fn[i](omap_l4_io_opaque[i], addr);
2313 static void omap_l4_io_writeb(void *opaque, target_phys_addr_t addr,
2316 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2318 return omap_l4_io_writeb_fn[i](omap_l4_io_opaque[i], addr, value);
2321 static void omap_l4_io_writeh(void *opaque, target_phys_addr_t addr,
2324 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2326 return omap_l4_io_writeh_fn[i](omap_l4_io_opaque[i], addr, value);
2329 static void omap_l4_io_writew(void *opaque, target_phys_addr_t addr,
2332 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2334 return omap_l4_io_writew_fn[i](omap_l4_io_opaque[i], addr, value);
2337 static CPUReadMemoryFunc *omap_l4_io_readfn[] = {
2343 static CPUWriteMemoryFunc *omap_l4_io_writefn[] = {
2350 struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)
2352 struct omap_l4_s *bus = qemu_mallocz(
2353 sizeof(*bus) + ta_num * sizeof(*bus->ta));
2355 bus->ta_num = ta_num;
2359 omap_l4_io_entries = 1;
2360 omap_l4_io_entry = qemu_mallocz(125 * sizeof(*omap_l4_io_entry));
2363 cpu_register_io_memory(0, omap_l4_io_readfn,
2364 omap_l4_io_writefn, bus);
2365 # define L4_PAGES (0xb4000 / TARGET_PAGE_SIZE)
2366 omap_l4_io_readb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2367 omap_l4_io_readh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2368 omap_l4_io_readw_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2369 omap_l4_io_writeb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2370 omap_l4_io_writeh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2371 omap_l4_io_writew_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2372 omap_l4_io_opaque = qemu_mallocz(sizeof(void *) * L4_PAGES);
2378 static uint32_t omap_l4ta_read(void *opaque, target_phys_addr_t addr)
2380 struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
2383 case 0x00: /* COMPONENT */
2384 return s->component;
2386 case 0x20: /* AGENT_CONTROL */
2389 case 0x28: /* AGENT_STATUS */
2397 static void omap_l4ta_write(void *opaque, target_phys_addr_t addr,
2400 struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
2403 case 0x00: /* COMPONENT */
2404 case 0x28: /* AGENT_STATUS */
2408 case 0x20: /* AGENT_CONTROL */
2409 s->control = value & 0x01000700;
2410 if (value & 1) /* OCP_RESET */
2411 s->status &= ~1; /* REQ_TIMEOUT */
2419 static CPUReadMemoryFunc *omap_l4ta_readfn[] = {
2420 omap_badwidth_read16,
2422 omap_badwidth_read16,
2425 static CPUWriteMemoryFunc *omap_l4ta_writefn[] = {
2426 omap_badwidth_write32,
2427 omap_badwidth_write32,
2432 #define L4TAO(n) ((n) + 39)
2434 static struct omap_l4_region_s omap_l4_region[125] = {
2435 [ 1] = { 0x40800, 0x800, 32 }, /* Initiator agent */
2436 [ 2] = { 0x41000, 0x1000, 32 }, /* Link agent */
2437 [ 0] = { 0x40000, 0x800, 32 }, /* Address and protection */
2438 [ 3] = { 0x00000, 0x1000, 32 | 16 | 8 }, /* System Control and Pinout */
2439 [ 4] = { 0x01000, 0x1000, 32 | 16 | 8 }, /* L4TAO1 */
2440 [ 5] = { 0x04000, 0x1000, 32 | 16 }, /* 32K Timer */
2441 [ 6] = { 0x05000, 0x1000, 32 | 16 | 8 }, /* L4TAO2 */
2442 [ 7] = { 0x08000, 0x800, 32 }, /* PRCM Region A */
2443 [ 8] = { 0x08800, 0x800, 32 }, /* PRCM Region B */
2444 [ 9] = { 0x09000, 0x1000, 32 | 16 | 8 }, /* L4TAO */
2445 [ 10] = { 0x12000, 0x1000, 32 | 16 | 8 }, /* Test (BCM) */
2446 [ 11] = { 0x13000, 0x1000, 32 | 16 | 8 }, /* L4TA1 */
2447 [ 12] = { 0x14000, 0x1000, 32 }, /* Test/emulation (TAP) */
2448 [ 13] = { 0x15000, 0x1000, 32 | 16 | 8 }, /* L4TA2 */
2449 [ 14] = { 0x18000, 0x1000, 32 | 16 | 8 }, /* GPIO1 */
2450 [ 16] = { 0x1a000, 0x1000, 32 | 16 | 8 }, /* GPIO2 */
2451 [ 18] = { 0x1c000, 0x1000, 32 | 16 | 8 }, /* GPIO3 */
2452 [ 19] = { 0x1e000, 0x1000, 32 | 16 | 8 }, /* GPIO4 */
2453 [ 15] = { 0x19000, 0x1000, 32 | 16 | 8 }, /* Quad GPIO TOP */
2454 [ 17] = { 0x1b000, 0x1000, 32 | 16 | 8 }, /* L4TA3 */
2455 [ 20] = { 0x20000, 0x1000, 32 | 16 | 8 }, /* WD Timer 1 (Secure) */
2456 [ 22] = { 0x22000, 0x1000, 32 | 16 | 8 }, /* WD Timer 2 (OMAP) */
2457 [ 21] = { 0x21000, 0x1000, 32 | 16 | 8 }, /* Dual WD timer TOP */
2458 [ 23] = { 0x23000, 0x1000, 32 | 16 | 8 }, /* L4TA4 */
2459 [ 24] = { 0x28000, 0x1000, 32 | 16 | 8 }, /* GP Timer 1 */
2460 [ 25] = { 0x29000, 0x1000, 32 | 16 | 8 }, /* L4TA7 */
2461 [ 26] = { 0x48000, 0x2000, 32 | 16 | 8 }, /* Emulation (ARM11ETB) */
2462 [ 27] = { 0x4a000, 0x1000, 32 | 16 | 8 }, /* L4TA9 */
2463 [ 28] = { 0x50000, 0x400, 32 | 16 | 8 }, /* Display top */
2464 [ 29] = { 0x50400, 0x400, 32 | 16 | 8 }, /* Display control */
2465 [ 30] = { 0x50800, 0x400, 32 | 16 | 8 }, /* Display RFBI */
2466 [ 31] = { 0x50c00, 0x400, 32 | 16 | 8 }, /* Display encoder */
2467 [ 32] = { 0x51000, 0x1000, 32 | 16 | 8 }, /* L4TA10 */
2468 [ 33] = { 0x52000, 0x400, 32 | 16 | 8 }, /* Camera top */
2469 [ 34] = { 0x52400, 0x400, 32 | 16 | 8 }, /* Camera core */
2470 [ 35] = { 0x52800, 0x400, 32 | 16 | 8 }, /* Camera DMA */
2471 [ 36] = { 0x52c00, 0x400, 32 | 16 | 8 }, /* Camera MMU */
2472 [ 37] = { 0x53000, 0x1000, 32 | 16 | 8 }, /* L4TA11 */
2473 [ 38] = { 0x56000, 0x1000, 32 | 16 | 8 }, /* sDMA */
2474 [ 39] = { 0x57000, 0x1000, 32 | 16 | 8 }, /* L4TA12 */
2475 [ 40] = { 0x58000, 0x1000, 32 | 16 | 8 }, /* SSI top */
2476 [ 41] = { 0x59000, 0x1000, 32 | 16 | 8 }, /* SSI GDD */
2477 [ 42] = { 0x5a000, 0x1000, 32 | 16 | 8 }, /* SSI Port1 */
2478 [ 43] = { 0x5b000, 0x1000, 32 | 16 | 8 }, /* SSI Port2 */
2479 [ 44] = { 0x5c000, 0x1000, 32 | 16 | 8 }, /* L4TA13 */
2480 [ 45] = { 0x5e000, 0x1000, 32 | 16 | 8 }, /* USB OTG */
2481 [ 46] = { 0x5f000, 0x1000, 32 | 16 | 8 }, /* L4TAO4 */
2482 [ 47] = { 0x60000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER1SDRC) */
2483 [ 48] = { 0x61000, 0x1000, 32 | 16 | 8 }, /* L4TA14 */
2484 [ 49] = { 0x62000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER2GPMC) */
2485 [ 50] = { 0x63000, 0x1000, 32 | 16 | 8 }, /* L4TA15 */
2486 [ 51] = { 0x64000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER3OCM) */
2487 [ 52] = { 0x65000, 0x1000, 32 | 16 | 8 }, /* L4TA16 */
2488 [ 53] = { 0x66000, 0x300, 32 | 16 | 8 }, /* Emulation (WIN_TRACER4L4) */
2489 [ 54] = { 0x67000, 0x1000, 32 | 16 | 8 }, /* L4TA17 */
2490 [ 55] = { 0x68000, 0x1000, 32 | 16 | 8 }, /* Emulation (XTI) */
2491 [ 56] = { 0x69000, 0x1000, 32 | 16 | 8 }, /* L4TA18 */
2492 [ 57] = { 0x6a000, 0x1000, 16 | 8 }, /* UART1 */
2493 [ 58] = { 0x6b000, 0x1000, 32 | 16 | 8 }, /* L4TA19 */
2494 [ 59] = { 0x6c000, 0x1000, 16 | 8 }, /* UART2 */
2495 [ 60] = { 0x6d000, 0x1000, 32 | 16 | 8 }, /* L4TA20 */
2496 [ 61] = { 0x6e000, 0x1000, 16 | 8 }, /* UART3 */
2497 [ 62] = { 0x6f000, 0x1000, 32 | 16 | 8 }, /* L4TA21 */
2498 [ 63] = { 0x70000, 0x1000, 16 }, /* I2C1 */
2499 [ 64] = { 0x71000, 0x1000, 32 | 16 | 8 }, /* L4TAO5 */
2500 [ 65] = { 0x72000, 0x1000, 16 }, /* I2C2 */
2501 [ 66] = { 0x73000, 0x1000, 32 | 16 | 8 }, /* L4TAO6 */
2502 [ 67] = { 0x74000, 0x1000, 16 }, /* McBSP1 */
2503 [ 68] = { 0x75000, 0x1000, 32 | 16 | 8 }, /* L4TAO7 */
2504 [ 69] = { 0x76000, 0x1000, 16 }, /* McBSP2 */
2505 [ 70] = { 0x77000, 0x1000, 32 | 16 | 8 }, /* L4TAO8 */
2506 [ 71] = { 0x24000, 0x1000, 32 | 16 | 8 }, /* WD Timer 3 (DSP) */
2507 [ 72] = { 0x25000, 0x1000, 32 | 16 | 8 }, /* L4TA5 */
2508 [ 73] = { 0x26000, 0x1000, 32 | 16 | 8 }, /* WD Timer 4 (IVA) */
2509 [ 74] = { 0x27000, 0x1000, 32 | 16 | 8 }, /* L4TA6 */
2510 [ 75] = { 0x2a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 2 */
2511 [ 76] = { 0x2b000, 0x1000, 32 | 16 | 8 }, /* L4TA8 */
2512 [ 77] = { 0x78000, 0x1000, 32 | 16 | 8 }, /* GP Timer 3 */
2513 [ 78] = { 0x79000, 0x1000, 32 | 16 | 8 }, /* L4TA22 */
2514 [ 79] = { 0x7a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 4 */
2515 [ 80] = { 0x7b000, 0x1000, 32 | 16 | 8 }, /* L4TA23 */
2516 [ 81] = { 0x7c000, 0x1000, 32 | 16 | 8 }, /* GP Timer 5 */
2517 [ 82] = { 0x7d000, 0x1000, 32 | 16 | 8 }, /* L4TA24 */
2518 [ 83] = { 0x7e000, 0x1000, 32 | 16 | 8 }, /* GP Timer 6 */
2519 [ 84] = { 0x7f000, 0x1000, 32 | 16 | 8 }, /* L4TA25 */
2520 [ 85] = { 0x80000, 0x1000, 32 | 16 | 8 }, /* GP Timer 7 */
2521 [ 86] = { 0x81000, 0x1000, 32 | 16 | 8 }, /* L4TA26 */
2522 [ 87] = { 0x82000, 0x1000, 32 | 16 | 8 }, /* GP Timer 8 */
2523 [ 88] = { 0x83000, 0x1000, 32 | 16 | 8 }, /* L4TA27 */
2524 [ 89] = { 0x84000, 0x1000, 32 | 16 | 8 }, /* GP Timer 9 */
2525 [ 90] = { 0x85000, 0x1000, 32 | 16 | 8 }, /* L4TA28 */
2526 [ 91] = { 0x86000, 0x1000, 32 | 16 | 8 }, /* GP Timer 10 */
2527 [ 92] = { 0x87000, 0x1000, 32 | 16 | 8 }, /* L4TA29 */
2528 [ 93] = { 0x88000, 0x1000, 32 | 16 | 8 }, /* GP Timer 11 */
2529 [ 94] = { 0x89000, 0x1000, 32 | 16 | 8 }, /* L4TA30 */
2530 [ 95] = { 0x8a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 12 */
2531 [ 96] = { 0x8b000, 0x1000, 32 | 16 | 8 }, /* L4TA31 */
2532 [ 97] = { 0x90000, 0x1000, 16 }, /* EAC */
2533 [ 98] = { 0x91000, 0x1000, 32 | 16 | 8 }, /* L4TA32 */
2534 [ 99] = { 0x92000, 0x1000, 16 }, /* FAC */
2535 [100] = { 0x93000, 0x1000, 32 | 16 | 8 }, /* L4TA33 */
2536 [101] = { 0x94000, 0x1000, 32 | 16 | 8 }, /* IPC (MAILBOX) */
2537 [102] = { 0x95000, 0x1000, 32 | 16 | 8 }, /* L4TA34 */
2538 [103] = { 0x98000, 0x1000, 32 | 16 | 8 }, /* SPI1 */
2539 [104] = { 0x99000, 0x1000, 32 | 16 | 8 }, /* L4TA35 */
2540 [105] = { 0x9a000, 0x1000, 32 | 16 | 8 }, /* SPI2 */
2541 [106] = { 0x9b000, 0x1000, 32 | 16 | 8 }, /* L4TA36 */
2542 [107] = { 0x9c000, 0x1000, 16 | 8 }, /* MMC SDIO */
2543 [108] = { 0x9d000, 0x1000, 32 | 16 | 8 }, /* L4TAO9 */
2544 [109] = { 0x9e000, 0x1000, 32 | 16 | 8 }, /* MS_PRO */
2545 [110] = { 0x9f000, 0x1000, 32 | 16 | 8 }, /* L4TAO10 */
2546 [111] = { 0xa0000, 0x1000, 32 }, /* RNG */
2547 [112] = { 0xa1000, 0x1000, 32 | 16 | 8 }, /* L4TAO11 */
2548 [113] = { 0xa2000, 0x1000, 32 }, /* DES3DES */
2549 [114] = { 0xa3000, 0x1000, 32 | 16 | 8 }, /* L4TAO12 */
2550 [115] = { 0xa4000, 0x1000, 32 }, /* SHA1MD5 */
2551 [116] = { 0xa5000, 0x1000, 32 | 16 | 8 }, /* L4TAO13 */
2552 [117] = { 0xa6000, 0x1000, 32 }, /* AES */
2553 [118] = { 0xa7000, 0x1000, 32 | 16 | 8 }, /* L4TA37 */
2554 [119] = { 0xa8000, 0x2000, 32 }, /* PKA */
2555 [120] = { 0xaa000, 0x1000, 32 | 16 | 8 }, /* L4TA38 */
2556 [121] = { 0xb0000, 0x1000, 32 }, /* MG */
2557 [122] = { 0xb1000, 0x1000, 32 | 16 | 8 },
2558 [123] = { 0xb2000, 0x1000, 32 }, /* HDQ/1-Wire */
2559 [124] = { 0xb3000, 0x1000, 32 | 16 | 8 }, /* L4TA39 */
2562 static struct omap_l4_agent_info_s omap_l4_agent_info[54] = {
2563 { 0, 0, 3, 2 }, /* L4IA initiatior agent */
2564 { L4TAO(1), 3, 2, 1 }, /* Control and pinout module */
2565 { L4TAO(2), 5, 2, 1 }, /* 32K timer */
2566 { L4TAO(3), 7, 3, 2 }, /* PRCM */
2567 { L4TA(1), 10, 2, 1 }, /* BCM */
2568 { L4TA(2), 12, 2, 1 }, /* Test JTAG */
2569 { L4TA(3), 14, 6, 3 }, /* Quad GPIO */
2570 { L4TA(4), 20, 4, 3 }, /* WD timer 1/2 */
2571 { L4TA(7), 24, 2, 1 }, /* GP timer 1 */
2572 { L4TA(9), 26, 2, 1 }, /* ATM11 ETB */
2573 { L4TA(10), 28, 5, 4 }, /* Display subsystem */
2574 { L4TA(11), 33, 5, 4 }, /* Camera subsystem */
2575 { L4TA(12), 38, 2, 1 }, /* sDMA */
2576 { L4TA(13), 40, 5, 4 }, /* SSI */
2577 { L4TAO(4), 45, 2, 1 }, /* USB */
2578 { L4TA(14), 47, 2, 1 }, /* Win Tracer1 */
2579 { L4TA(15), 49, 2, 1 }, /* Win Tracer2 */
2580 { L4TA(16), 51, 2, 1 }, /* Win Tracer3 */
2581 { L4TA(17), 53, 2, 1 }, /* Win Tracer4 */
2582 { L4TA(18), 55, 2, 1 }, /* XTI */
2583 { L4TA(19), 57, 2, 1 }, /* UART1 */
2584 { L4TA(20), 59, 2, 1 }, /* UART2 */
2585 { L4TA(21), 61, 2, 1 }, /* UART3 */
2586 { L4TAO(5), 63, 2, 1 }, /* I2C1 */
2587 { L4TAO(6), 65, 2, 1 }, /* I2C2 */
2588 { L4TAO(7), 67, 2, 1 }, /* McBSP1 */
2589 { L4TAO(8), 69, 2, 1 }, /* McBSP2 */
2590 { L4TA(5), 71, 2, 1 }, /* WD Timer 3 (DSP) */
2591 { L4TA(6), 73, 2, 1 }, /* WD Timer 4 (IVA) */
2592 { L4TA(8), 75, 2, 1 }, /* GP Timer 2 */
2593 { L4TA(22), 77, 2, 1 }, /* GP Timer 3 */
2594 { L4TA(23), 79, 2, 1 }, /* GP Timer 4 */
2595 { L4TA(24), 81, 2, 1 }, /* GP Timer 5 */
2596 { L4TA(25), 83, 2, 1 }, /* GP Timer 6 */
2597 { L4TA(26), 85, 2, 1 }, /* GP Timer 7 */
2598 { L4TA(27), 87, 2, 1 }, /* GP Timer 8 */
2599 { L4TA(28), 89, 2, 1 }, /* GP Timer 9 */
2600 { L4TA(29), 91, 2, 1 }, /* GP Timer 10 */
2601 { L4TA(30), 93, 2, 1 }, /* GP Timer 11 */
2602 { L4TA(31), 95, 2, 1 }, /* GP Timer 12 */
2603 { L4TA(32), 97, 2, 1 }, /* EAC */
2604 { L4TA(33), 99, 2, 1 }, /* FAC */
2605 { L4TA(34), 101, 2, 1 }, /* IPC */
2606 { L4TA(35), 103, 2, 1 }, /* SPI1 */
2607 { L4TA(36), 105, 2, 1 }, /* SPI2 */
2608 { L4TAO(9), 107, 2, 1 }, /* MMC SDIO */
2609 { L4TAO(10), 109, 2, 1 },
2610 { L4TAO(11), 111, 2, 1 }, /* RNG */
2611 { L4TAO(12), 113, 2, 1 }, /* DES3DES */
2612 { L4TAO(13), 115, 2, 1 }, /* SHA1MD5 */
2613 { L4TA(37), 117, 2, 1 }, /* AES */
2614 { L4TA(38), 119, 2, 1 }, /* PKA */
2616 { L4TA(39), 123, 2, 1 }, /* HDQ/1-Wire */
2619 #define omap_l4ta(bus, cs) omap_l4ta_get(bus, L4TA(cs))
2620 #define omap_l4tao(bus, cs) omap_l4ta_get(bus, L4TAO(cs))
2622 struct omap_target_agent_s *omap_l4ta_get(struct omap_l4_s *bus, int cs)
2625 struct omap_target_agent_s *ta = 0;
2626 struct omap_l4_agent_info_s *info = 0;
2628 for (i = 0; i < bus->ta_num; i ++)
2629 if (omap_l4_agent_info[i].ta == cs) {
2631 info = &omap_l4_agent_info[i];
2635 fprintf(stderr, "%s: bad target agent (%i)\n", __FUNCTION__, cs);
2640 ta->start = &omap_l4_region[info->region];
2641 ta->regions = info->regions;
2643 ta->component = ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2644 ta->status = 0x00000000;
2645 ta->control = 0x00000200; /* XXX 01000200 for L4TAO */
2647 iomemtype = l4_register_io_memory(0, omap_l4ta_readfn,
2648 omap_l4ta_writefn, ta);
2649 ta->base = omap_l4_attach(ta, info->ta_region, iomemtype);
2654 target_phys_addr_t omap_l4_attach(struct omap_target_agent_s *ta, int region,
2657 target_phys_addr_t base;
2663 if (region < 0 || region >= ta->regions) {
2664 fprintf(stderr, "%s: bad io region (%i)\n", __FUNCTION__, region);
2668 base = ta->bus->base + ta->start[region].offset;
2669 size = ta->start[region].size;
2672 cpu_register_physical_memory(base, size, iotype);
2674 cpu_register_physical_memory(base, size, omap_cpu_io_entry);
2675 i = (base - ta->bus->base) / TARGET_PAGE_SIZE;
2676 for (; size > 0; size -= TARGET_PAGE_SIZE, i ++) {
2677 omap_l4_io_readb_fn[i] = omap_l4_io_entry[iotype].mem_read[0];
2678 omap_l4_io_readh_fn[i] = omap_l4_io_entry[iotype].mem_read[1];
2679 omap_l4_io_readw_fn[i] = omap_l4_io_entry[iotype].mem_read[2];
2680 omap_l4_io_writeb_fn[i] = omap_l4_io_entry[iotype].mem_write[0];
2681 omap_l4_io_writeh_fn[i] = omap_l4_io_entry[iotype].mem_write[1];
2682 omap_l4_io_writew_fn[i] = omap_l4_io_entry[iotype].mem_write[2];
2683 omap_l4_io_opaque[i] = omap_l4_io_entry[iotype].opaque;
2691 /* TEST-Chip-level TAP */
2692 static uint32_t omap_tap_read(void *opaque, target_phys_addr_t addr)
2694 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2697 case 0x204: /* IDCODE_reg */
2698 switch (s->mpu_model) {
2702 return 0x5b5d902f; /* ES 2.2 */
2704 return 0x5b68a02f; /* ES 2.2 */
2706 return 0x1b7ae02f; /* ES 2 */
2708 return 0x3b7ae02f; /* ES 3.0 */
2710 cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
2713 case 0x208: /* PRODUCTION_ID_reg for OMAP2 */
2714 case 0x210: /* PRODUCTION_ID_reg for OMAP3 */
2715 switch (s->mpu_model) {
2717 return 0x000254f0; /* POP ESHS2.1.1 in N91/93/95, ES2 in N800 */
2729 cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
2733 switch (s->mpu_model) {
2737 return 0xcafeb5d9; /* ES 2.2 */
2739 return 0xcafeb68a; /* ES 2.2 */
2742 return 0xcafeb7ae; /* ES 2 */
2744 cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
2747 case 0x218: /* DIE_ID_reg */
2748 return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2749 case 0x21c: /* DIE_ID_reg */
2751 case 0x220: /* DIE_ID_reg */
2752 return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2753 case 0x224: /* DIE_ID_reg */
2754 return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2761 static void omap_tap_write(void *opaque, target_phys_addr_t addr,
2767 static CPUReadMemoryFunc *omap_tap_readfn[] = {
2768 omap_badwidth_read32,
2769 omap_badwidth_read32,
2773 static CPUWriteMemoryFunc *omap_tap_writefn[] = {
2774 omap_badwidth_write32,
2775 omap_badwidth_write32,
2779 void omap_tap_init(struct omap_target_agent_s *ta,
2780 struct omap_mpu_state_s *mpu)
2782 omap_l4_attach(ta, 0, l4_register_io_memory(0,
2783 omap_tap_readfn, omap_tap_writefn, mpu));
2786 /* Power, Reset, and Clock Management */
2787 struct omap_prcm_s {
2789 struct omap_mpu_state_s *mpu;
2796 uint32_t scratch[20];
2800 uint32_t clkemul[1];
2804 uint32_t clkctrl[4];
2805 uint32_t clkidle[7];
2806 uint32_t setuptime[2];
2812 uint32_t rstctrl[1];
2814 uint32_t rsttime_wkup;
2819 int dpll_lock, apll_lock[2];
2822 static void omap_prcm_int_update(struct omap_prcm_s *s, int dom)
2824 qemu_set_irq(s->irq[dom], s->irqst[dom] & s->irqen[dom]);
2825 /* XXX or is the mask applied before PRCM_IRQSTATUS_* ? */
2828 static uint32_t omap_prcm_read(void *opaque, target_phys_addr_t addr)
2830 struct omap_prcm_s *s = (struct omap_prcm_s *) opaque;
2834 case 0x000: /* PRCM_REVISION */
2837 case 0x010: /* PRCM_SYSCONFIG */
2838 return s->sysconfig;
2840 case 0x018: /* PRCM_IRQSTATUS_MPU */
2843 case 0x01c: /* PRCM_IRQENABLE_MPU */
2846 case 0x050: /* PRCM_VOLTCTRL */
2848 case 0x054: /* PRCM_VOLTST */
2849 return s->voltctrl & 3;
2851 case 0x060: /* PRCM_CLKSRC_CTRL */
2852 return s->clksrc[0];
2853 case 0x070: /* PRCM_CLKOUT_CTRL */
2854 return s->clkout[0];
2855 case 0x078: /* PRCM_CLKEMUL_CTRL */
2856 return s->clkemul[0];
2857 case 0x080: /* PRCM_CLKCFG_CTRL */
2858 case 0x084: /* PRCM_CLKCFG_STATUS */
2861 case 0x090: /* PRCM_VOLTSETUP */
2862 return s->setuptime[0];
2864 case 0x094: /* PRCM_CLKSSETUP */
2865 return s->setuptime[1];
2867 case 0x098: /* PRCM_POLCTRL */
2868 return s->clkpol[0];
2870 case 0x0b0: /* GENERAL_PURPOSE1 */
2871 case 0x0b4: /* GENERAL_PURPOSE2 */
2872 case 0x0b8: /* GENERAL_PURPOSE3 */
2873 case 0x0bc: /* GENERAL_PURPOSE4 */
2874 case 0x0c0: /* GENERAL_PURPOSE5 */
2875 case 0x0c4: /* GENERAL_PURPOSE6 */
2876 case 0x0c8: /* GENERAL_PURPOSE7 */
2877 case 0x0cc: /* GENERAL_PURPOSE8 */
2878 case 0x0d0: /* GENERAL_PURPOSE9 */
2879 case 0x0d4: /* GENERAL_PURPOSE10 */
2880 case 0x0d8: /* GENERAL_PURPOSE11 */
2881 case 0x0dc: /* GENERAL_PURPOSE12 */
2882 case 0x0e0: /* GENERAL_PURPOSE13 */
2883 case 0x0e4: /* GENERAL_PURPOSE14 */
2884 case 0x0e8: /* GENERAL_PURPOSE15 */
2885 case 0x0ec: /* GENERAL_PURPOSE16 */
2886 case 0x0f0: /* GENERAL_PURPOSE17 */
2887 case 0x0f4: /* GENERAL_PURPOSE18 */
2888 case 0x0f8: /* GENERAL_PURPOSE19 */
2889 case 0x0fc: /* GENERAL_PURPOSE20 */
2890 return s->scratch[(addr - 0xb0) >> 2];
2892 case 0x140: /* CM_CLKSEL_MPU */
2893 return s->clksel[0];
2894 case 0x148: /* CM_CLKSTCTRL_MPU */
2895 return s->clkctrl[0];
2897 case 0x158: /* RM_RSTST_MPU */
2899 case 0x1c8: /* PM_WKDEP_MPU */
2901 case 0x1d4: /* PM_EVGENCTRL_MPU */
2903 case 0x1d8: /* PM_EVEGENONTIM_MPU */
2904 return s->evtime[0];
2905 case 0x1dc: /* PM_EVEGENOFFTIM_MPU */
2906 return s->evtime[1];
2907 case 0x1e0: /* PM_PWSTCTRL_MPU */
2909 case 0x1e4: /* PM_PWSTST_MPU */
2912 case 0x200: /* CM_FCLKEN1_CORE */
2914 case 0x204: /* CM_FCLKEN2_CORE */
2916 case 0x210: /* CM_ICLKEN1_CORE */
2918 case 0x214: /* CM_ICLKEN2_CORE */
2920 case 0x21c: /* CM_ICLKEN4_CORE */
2923 case 0x220: /* CM_IDLEST1_CORE */
2924 /* TODO: check the actual iclk status */
2926 case 0x224: /* CM_IDLEST2_CORE */
2927 /* TODO: check the actual iclk status */
2929 case 0x22c: /* CM_IDLEST4_CORE */
2930 /* TODO: check the actual iclk status */
2933 case 0x230: /* CM_AUTOIDLE1_CORE */
2934 return s->clkidle[0];
2935 case 0x234: /* CM_AUTOIDLE2_CORE */
2936 return s->clkidle[1];
2937 case 0x238: /* CM_AUTOIDLE3_CORE */
2938 return s->clkidle[2];
2939 case 0x23c: /* CM_AUTOIDLE4_CORE */
2940 return s->clkidle[3];
2942 case 0x240: /* CM_CLKSEL1_CORE */
2943 return s->clksel[1];
2944 case 0x244: /* CM_CLKSEL2_CORE */
2945 return s->clksel[2];
2947 case 0x248: /* CM_CLKSTCTRL_CORE */
2948 return s->clkctrl[1];
2950 case 0x2a0: /* PM_WKEN1_CORE */
2952 case 0x2a4: /* PM_WKEN2_CORE */
2955 case 0x2b0: /* PM_WKST1_CORE */
2957 case 0x2b4: /* PM_WKST2_CORE */
2959 case 0x2c8: /* PM_WKDEP_CORE */
2962 case 0x2e0: /* PM_PWSTCTRL_CORE */
2964 case 0x2e4: /* PM_PWSTST_CORE */
2965 return 0x000030 | (s->power[1] & 0xfc00);
2967 case 0x300: /* CM_FCLKEN_GFX */
2969 case 0x310: /* CM_ICLKEN_GFX */
2971 case 0x320: /* CM_IDLEST_GFX */
2972 /* TODO: check the actual iclk status */
2974 case 0x340: /* CM_CLKSEL_GFX */
2975 return s->clksel[3];
2976 case 0x348: /* CM_CLKSTCTRL_GFX */
2977 return s->clkctrl[2];
2978 case 0x350: /* RM_RSTCTRL_GFX */
2979 return s->rstctrl[0];
2980 case 0x358: /* RM_RSTST_GFX */
2982 case 0x3c8: /* PM_WKDEP_GFX */
2985 case 0x3e0: /* PM_PWSTCTRL_GFX */
2987 case 0x3e4: /* PM_PWSTST_GFX */
2988 return s->power[2] & 3;
2990 case 0x400: /* CM_FCLKEN_WKUP */
2992 case 0x410: /* CM_ICLKEN_WKUP */
2994 case 0x420: /* CM_IDLEST_WKUP */
2995 /* TODO: check the actual iclk status */
2997 case 0x430: /* CM_AUTOIDLE_WKUP */
2998 return s->clkidle[4];
2999 case 0x440: /* CM_CLKSEL_WKUP */
3000 return s->clksel[4];
3001 case 0x450: /* RM_RSTCTRL_WKUP */
3003 case 0x454: /* RM_RSTTIME_WKUP */
3004 return s->rsttime_wkup;
3005 case 0x458: /* RM_RSTST_WKUP */
3007 case 0x4a0: /* PM_WKEN_WKUP */
3009 case 0x4b0: /* PM_WKST_WKUP */
3012 case 0x500: /* CM_CLKEN_PLL */
3014 case 0x520: /* CM_IDLEST_CKGEN */
3015 ret = 0x0000070 | (s->apll_lock[0] << 9) | (s->apll_lock[1] << 8);
3016 if (!(s->clksel[6] & 3))
3017 /* Core uses 32-kHz clock */
3019 else if (!s->dpll_lock)
3020 /* DPLL not locked, core uses ref_clk */
3023 /* Core uses DPLL */
3026 case 0x530: /* CM_AUTOIDLE_PLL */
3027 return s->clkidle[5];
3028 case 0x540: /* CM_CLKSEL1_PLL */
3029 return s->clksel[5];
3030 case 0x544: /* CM_CLKSEL2_PLL */
3031 return s->clksel[6];
3033 case 0x800: /* CM_FCLKEN_DSP */
3034 return s->clken[10];
3035 case 0x810: /* CM_ICLKEN_DSP */
3036 return s->clken[11];
3037 case 0x820: /* CM_IDLEST_DSP */
3038 /* TODO: check the actual iclk status */
3040 case 0x830: /* CM_AUTOIDLE_DSP */
3041 return s->clkidle[6];
3042 case 0x840: /* CM_CLKSEL_DSP */
3043 return s->clksel[7];
3044 case 0x848: /* CM_CLKSTCTRL_DSP */
3045 return s->clkctrl[3];
3046 case 0x850: /* RM_RSTCTRL_DSP */
3048 case 0x858: /* RM_RSTST_DSP */
3050 case 0x8c8: /* PM_WKDEP_DSP */
3052 case 0x8e0: /* PM_PWSTCTRL_DSP */
3054 case 0x8e4: /* PM_PWSTST_DSP */
3055 return 0x008030 | (s->power[3] & 0x3003);
3057 case 0x8f0: /* PRCM_IRQSTATUS_DSP */
3059 case 0x8f4: /* PRCM_IRQENABLE_DSP */
3062 case 0x8f8: /* PRCM_IRQSTATUS_IVA */
3064 case 0x8fc: /* PRCM_IRQENABLE_IVA */
3072 static void omap_prcm_apll_update(struct omap_prcm_s *s)
3076 mode[0] = (s->clken[9] >> 6) & 3;
3077 s->apll_lock[0] = (mode[0] == 3);
3078 mode[1] = (s->clken[9] >> 2) & 3;
3079 s->apll_lock[1] = (mode[1] == 3);
3080 /* TODO: update clocks */
3082 if (mode[0] == 1 || mode[0] == 2 || mode[1] == 1 || mode[2] == 2)
3083 fprintf(stderr, "%s: bad EN_54M_PLL or bad EN_96M_PLL\n",
3087 static void omap_prcm_dpll_update(struct omap_prcm_s *s)
3089 omap_clk dpll = omap_findclk(s->mpu, "dpll");
3090 omap_clk dpll_x2 = omap_findclk(s->mpu, "dpll");
3091 omap_clk core = omap_findclk(s->mpu, "core_clk");
3092 int mode = (s->clken[9] >> 0) & 3;
3095 mult = (s->clksel[5] >> 12) & 0x3ff;
3096 div = (s->clksel[5] >> 8) & 0xf;
3097 if (mult == 0 || mult == 1)
3098 mode = 1; /* Bypass */
3103 fprintf(stderr, "%s: bad EN_DPLL\n", __FUNCTION__);
3105 case 1: /* Low-power bypass mode (Default) */
3106 case 2: /* Fast-relock bypass mode */
3107 omap_clk_setrate(dpll, 1, 1);
3108 omap_clk_setrate(dpll_x2, 1, 1);
3110 case 3: /* Lock mode */
3111 s->dpll_lock = 1; /* After 20 FINT cycles (ref_clk / (div + 1)). */
3113 omap_clk_setrate(dpll, div + 1, mult);
3114 omap_clk_setrate(dpll_x2, div + 1, mult * 2);
3118 switch ((s->clksel[6] >> 0) & 3) {
3120 omap_clk_reparent(core, omap_findclk(s->mpu, "clk32-kHz"));
3123 omap_clk_reparent(core, dpll);
3127 omap_clk_reparent(core, dpll_x2);
3130 fprintf(stderr, "%s: bad CORE_CLK_SRC\n", __FUNCTION__);
3135 static void omap_prcm_write(void *opaque, target_phys_addr_t addr,
3138 struct omap_prcm_s *s = (struct omap_prcm_s *) opaque;
3141 case 0x000: /* PRCM_REVISION */
3142 case 0x054: /* PRCM_VOLTST */
3143 case 0x084: /* PRCM_CLKCFG_STATUS */
3144 case 0x1e4: /* PM_PWSTST_MPU */
3145 case 0x220: /* CM_IDLEST1_CORE */
3146 case 0x224: /* CM_IDLEST2_CORE */
3147 case 0x22c: /* CM_IDLEST4_CORE */
3148 case 0x2c8: /* PM_WKDEP_CORE */
3149 case 0x2e4: /* PM_PWSTST_CORE */
3150 case 0x320: /* CM_IDLEST_GFX */
3151 case 0x3e4: /* PM_PWSTST_GFX */
3152 case 0x420: /* CM_IDLEST_WKUP */
3153 case 0x520: /* CM_IDLEST_CKGEN */
3154 case 0x820: /* CM_IDLEST_DSP */
3155 case 0x8e4: /* PM_PWSTST_DSP */
3159 case 0x010: /* PRCM_SYSCONFIG */
3160 s->sysconfig = value & 1;
3163 case 0x018: /* PRCM_IRQSTATUS_MPU */
3164 s->irqst[0] &= ~value;
3165 omap_prcm_int_update(s, 0);
3167 case 0x01c: /* PRCM_IRQENABLE_MPU */
3168 s->irqen[0] = value & 0x3f;
3169 omap_prcm_int_update(s, 0);
3172 case 0x050: /* PRCM_VOLTCTRL */
3173 s->voltctrl = value & 0xf1c3;
3176 case 0x060: /* PRCM_CLKSRC_CTRL */
3177 s->clksrc[0] = value & 0xdb;
3178 /* TODO update clocks */
3181 case 0x070: /* PRCM_CLKOUT_CTRL */
3182 s->clkout[0] = value & 0xbbbb;
3183 /* TODO update clocks */
3186 case 0x078: /* PRCM_CLKEMUL_CTRL */
3187 s->clkemul[0] = value & 1;
3188 /* TODO update clocks */
3191 case 0x080: /* PRCM_CLKCFG_CTRL */
3194 case 0x090: /* PRCM_VOLTSETUP */
3195 s->setuptime[0] = value & 0xffff;
3197 case 0x094: /* PRCM_CLKSSETUP */
3198 s->setuptime[1] = value & 0xffff;
3201 case 0x098: /* PRCM_POLCTRL */
3202 s->clkpol[0] = value & 0x701;
3205 case 0x0b0: /* GENERAL_PURPOSE1 */
3206 case 0x0b4: /* GENERAL_PURPOSE2 */
3207 case 0x0b8: /* GENERAL_PURPOSE3 */
3208 case 0x0bc: /* GENERAL_PURPOSE4 */
3209 case 0x0c0: /* GENERAL_PURPOSE5 */
3210 case 0x0c4: /* GENERAL_PURPOSE6 */
3211 case 0x0c8: /* GENERAL_PURPOSE7 */
3212 case 0x0cc: /* GENERAL_PURPOSE8 */
3213 case 0x0d0: /* GENERAL_PURPOSE9 */
3214 case 0x0d4: /* GENERAL_PURPOSE10 */
3215 case 0x0d8: /* GENERAL_PURPOSE11 */
3216 case 0x0dc: /* GENERAL_PURPOSE12 */
3217 case 0x0e0: /* GENERAL_PURPOSE13 */
3218 case 0x0e4: /* GENERAL_PURPOSE14 */
3219 case 0x0e8: /* GENERAL_PURPOSE15 */
3220 case 0x0ec: /* GENERAL_PURPOSE16 */
3221 case 0x0f0: /* GENERAL_PURPOSE17 */
3222 case 0x0f4: /* GENERAL_PURPOSE18 */
3223 case 0x0f8: /* GENERAL_PURPOSE19 */
3224 case 0x0fc: /* GENERAL_PURPOSE20 */
3225 s->scratch[(addr - 0xb0) >> 2] = value;
3228 case 0x140: /* CM_CLKSEL_MPU */
3229 s->clksel[0] = value & 0x1f;
3230 /* TODO update clocks */
3232 case 0x148: /* CM_CLKSTCTRL_MPU */
3233 s->clkctrl[0] = value & 0x1f;
3236 case 0x158: /* RM_RSTST_MPU */
3237 s->rst[0] &= ~value;
3239 case 0x1c8: /* PM_WKDEP_MPU */
3240 s->wkup[0] = value & 0x15;
3243 case 0x1d4: /* PM_EVGENCTRL_MPU */
3244 s->ev = value & 0x1f;
3246 case 0x1d8: /* PM_EVEGENONTIM_MPU */
3247 s->evtime[0] = value;
3249 case 0x1dc: /* PM_EVEGENOFFTIM_MPU */
3250 s->evtime[1] = value;
3253 case 0x1e0: /* PM_PWSTCTRL_MPU */
3254 s->power[0] = value & 0xc0f;
3257 case 0x200: /* CM_FCLKEN1_CORE */
3258 s->clken[0] = value & 0xbfffffff;
3259 /* TODO update clocks */
3260 /* The EN_EAC bit only gets/puts func_96m_clk. */
3262 case 0x204: /* CM_FCLKEN2_CORE */
3263 s->clken[1] = value & 0x00000007;
3264 /* TODO update clocks */
3266 case 0x210: /* CM_ICLKEN1_CORE */
3267 s->clken[2] = value & 0xfffffff9;
3268 /* TODO update clocks */
3269 /* The EN_EAC bit only gets/puts core_l4_iclk. */
3271 case 0x214: /* CM_ICLKEN2_CORE */
3272 s->clken[3] = value & 0x00000007;
3273 /* TODO update clocks */
3275 case 0x21c: /* CM_ICLKEN4_CORE */
3276 s->clken[4] = value & 0x0000001f;
3277 /* TODO update clocks */
3280 case 0x230: /* CM_AUTOIDLE1_CORE */
3281 s->clkidle[0] = value & 0xfffffff9;
3282 /* TODO update clocks */
3284 case 0x234: /* CM_AUTOIDLE2_CORE */
3285 s->clkidle[1] = value & 0x00000007;
3286 /* TODO update clocks */
3288 case 0x238: /* CM_AUTOIDLE3_CORE */
3289 s->clkidle[2] = value & 0x00000007;
3290 /* TODO update clocks */
3292 case 0x23c: /* CM_AUTOIDLE4_CORE */
3293 s->clkidle[3] = value & 0x0000001f;
3294 /* TODO update clocks */
3297 case 0x240: /* CM_CLKSEL1_CORE */
3298 s->clksel[1] = value & 0x0fffbf7f;
3299 /* TODO update clocks */
3302 case 0x244: /* CM_CLKSEL2_CORE */
3303 s->clksel[2] = value & 0x00fffffc;
3304 /* TODO update clocks */
3307 case 0x248: /* CM_CLKSTCTRL_CORE */
3308 s->clkctrl[1] = value & 0x7;
3311 case 0x2a0: /* PM_WKEN1_CORE */
3312 s->wken[0] = value & 0x04667ff8;
3314 case 0x2a4: /* PM_WKEN2_CORE */
3315 s->wken[1] = value & 0x00000005;
3318 case 0x2b0: /* PM_WKST1_CORE */
3319 s->wkst[0] &= ~value;
3321 case 0x2b4: /* PM_WKST2_CORE */
3322 s->wkst[1] &= ~value;
3325 case 0x2e0: /* PM_PWSTCTRL_CORE */
3326 s->power[1] = (value & 0x00fc3f) | (1 << 2);
3329 case 0x300: /* CM_FCLKEN_GFX */
3330 s->clken[5] = value & 6;
3331 /* TODO update clocks */
3333 case 0x310: /* CM_ICLKEN_GFX */
3334 s->clken[6] = value & 1;
3335 /* TODO update clocks */
3337 case 0x340: /* CM_CLKSEL_GFX */
3338 s->clksel[3] = value & 7;
3339 /* TODO update clocks */
3341 case 0x348: /* CM_CLKSTCTRL_GFX */
3342 s->clkctrl[2] = value & 1;
3344 case 0x350: /* RM_RSTCTRL_GFX */
3345 s->rstctrl[0] = value & 1;
3348 case 0x358: /* RM_RSTST_GFX */
3349 s->rst[1] &= ~value;
3351 case 0x3c8: /* PM_WKDEP_GFX */
3352 s->wkup[1] = value & 0x13;
3354 case 0x3e0: /* PM_PWSTCTRL_GFX */
3355 s->power[2] = (value & 0x00c0f) | (3 << 2);
3358 case 0x400: /* CM_FCLKEN_WKUP */
3359 s->clken[7] = value & 0xd;
3360 /* TODO update clocks */
3362 case 0x410: /* CM_ICLKEN_WKUP */
3363 s->clken[8] = value & 0x3f;
3364 /* TODO update clocks */
3366 case 0x430: /* CM_AUTOIDLE_WKUP */
3367 s->clkidle[4] = value & 0x0000003f;
3368 /* TODO update clocks */
3370 case 0x440: /* CM_CLKSEL_WKUP */
3371 s->clksel[4] = value & 3;
3372 /* TODO update clocks */
3374 case 0x450: /* RM_RSTCTRL_WKUP */
3377 qemu_system_reset_request();
3379 case 0x454: /* RM_RSTTIME_WKUP */
3380 s->rsttime_wkup = value & 0x1fff;
3382 case 0x458: /* RM_RSTST_WKUP */
3383 s->rst[2] &= ~value;
3385 case 0x4a0: /* PM_WKEN_WKUP */
3386 s->wken[2] = value & 0x00000005;
3388 case 0x4b0: /* PM_WKST_WKUP */
3389 s->wkst[2] &= ~value;
3392 case 0x500: /* CM_CLKEN_PLL */
3393 if (value & 0xffffff30)
3394 fprintf(stderr, "%s: write 0s in CM_CLKEN_PLL for "
3395 "future compatiblity\n", __FUNCTION__);
3396 if ((s->clken[9] ^ value) & 0xcc) {
3397 s->clken[9] &= ~0xcc;
3398 s->clken[9] |= value & 0xcc;
3399 omap_prcm_apll_update(s);
3401 if ((s->clken[9] ^ value) & 3) {
3403 s->clken[9] |= value & 3;
3404 omap_prcm_dpll_update(s);
3407 case 0x530: /* CM_AUTOIDLE_PLL */
3408 s->clkidle[5] = value & 0x000000cf;
3409 /* TODO update clocks */
3411 case 0x540: /* CM_CLKSEL1_PLL */
3412 if (value & 0xfc4000d7)
3413 fprintf(stderr, "%s: write 0s in CM_CLKSEL1_PLL for "
3414 "future compatiblity\n", __FUNCTION__);
3415 if ((s->clksel[5] ^ value) & 0x003fff00) {
3416 s->clksel[5] = value & 0x03bfff28;
3417 omap_prcm_dpll_update(s);
3419 /* TODO update the other clocks */
3421 s->clksel[5] = value & 0x03bfff28;
3423 case 0x544: /* CM_CLKSEL2_PLL */
3425 fprintf(stderr, "%s: write 0s in CM_CLKSEL2_PLL[31:2] for "
3426 "future compatiblity\n", __FUNCTION__);
3427 if (s->clksel[6] != (value & 3)) {
3428 s->clksel[6] = value & 3;
3429 omap_prcm_dpll_update(s);
3433 case 0x800: /* CM_FCLKEN_DSP */
3434 s->clken[10] = value & 0x501;
3435 /* TODO update clocks */
3437 case 0x810: /* CM_ICLKEN_DSP */
3438 s->clken[11] = value & 0x2;
3439 /* TODO update clocks */
3441 case 0x830: /* CM_AUTOIDLE_DSP */
3442 s->clkidle[6] = value & 0x2;
3443 /* TODO update clocks */
3445 case 0x840: /* CM_CLKSEL_DSP */
3446 s->clksel[7] = value & 0x3fff;
3447 /* TODO update clocks */
3449 case 0x848: /* CM_CLKSTCTRL_DSP */
3450 s->clkctrl[3] = value & 0x101;
3452 case 0x850: /* RM_RSTCTRL_DSP */
3455 case 0x858: /* RM_RSTST_DSP */
3456 s->rst[3] &= ~value;
3458 case 0x8c8: /* PM_WKDEP_DSP */
3459 s->wkup[2] = value & 0x13;
3461 case 0x8e0: /* PM_PWSTCTRL_DSP */
3462 s->power[3] = (value & 0x03017) | (3 << 2);
3465 case 0x8f0: /* PRCM_IRQSTATUS_DSP */
3466 s->irqst[1] &= ~value;
3467 omap_prcm_int_update(s, 1);
3469 case 0x8f4: /* PRCM_IRQENABLE_DSP */
3470 s->irqen[1] = value & 0x7;
3471 omap_prcm_int_update(s, 1);
3474 case 0x8f8: /* PRCM_IRQSTATUS_IVA */
3475 s->irqst[2] &= ~value;
3476 omap_prcm_int_update(s, 2);
3478 case 0x8fc: /* PRCM_IRQENABLE_IVA */
3479 s->irqen[2] = value & 0x7;
3480 omap_prcm_int_update(s, 2);
3489 static CPUReadMemoryFunc *omap_prcm_readfn[] = {
3490 omap_badwidth_read32,
3491 omap_badwidth_read32,
3495 static CPUWriteMemoryFunc *omap_prcm_writefn[] = {
3496 omap_badwidth_write32,
3497 omap_badwidth_write32,
3501 static void omap_prcm_reset(struct omap_prcm_s *s)
3510 s->voltctrl = 0x1040;
3532 s->clkidle[5] = 0x0c;
3534 s->clksel[0] = 0x01;
3535 s->clksel[1] = 0x02100121;
3536 s->clksel[2] = 0x00000000;
3537 s->clksel[3] = 0x01;
3539 s->clksel[7] = 0x0121;
3543 s->wken[0] = 0x04667ff8;
3544 s->wken[1] = 0x00000005;
3549 s->power[0] = 0x00c;
3551 s->power[2] = 0x0000c;
3555 omap_prcm_apll_update(s);
3556 omap_prcm_dpll_update(s);
3559 static void omap_prcm_coldreset(struct omap_prcm_s *s)
3561 s->setuptime[0] = 0;
3562 s->setuptime[1] = 0;
3563 memset(&s->scratch, 0, sizeof(s->scratch));
3572 s->clksrc[0] = 0x43;
3573 s->clkout[0] = 0x0303;
3575 s->clkpol[0] = 0x100;
3576 s->rsttime_wkup = 0x1002;
3581 struct omap_prcm_s *omap_prcm_init(struct omap_target_agent_s *ta,
3582 qemu_irq mpu_int, qemu_irq dsp_int, qemu_irq iva_int,
3583 struct omap_mpu_state_s *mpu)
3586 struct omap_prcm_s *s = (struct omap_prcm_s *)
3587 qemu_mallocz(sizeof(struct omap_prcm_s));
3589 s->irq[0] = mpu_int;
3590 s->irq[1] = dsp_int;
3591 s->irq[2] = iva_int;
3593 omap_prcm_coldreset(s);
3595 iomemtype = l4_register_io_memory(0, omap_prcm_readfn,
3596 omap_prcm_writefn, s);
3597 omap_l4_attach(ta, 0, iomemtype);
3598 omap_l4_attach(ta, 1, iomemtype);
3603 /* System and Pinout control */
3604 struct omap_sysctl_s {
3605 struct omap_mpu_state_s *mpu;
3610 uint32_t padconf[0x45];
3612 uint32_t msuspendmux[5];
3615 static uint32_t omap_sysctl_read8(void *opaque, target_phys_addr_t addr)
3618 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3619 int pad_offset, byte_offset;
3623 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3624 pad_offset = (addr - 0x30) >> 2;
3625 byte_offset = (addr - 0x30) & (4 - 1);
3627 value = s->padconf[pad_offset];
3628 value = (value >> (byte_offset * 8)) & 0xff;
3640 static uint32_t omap_sysctl_read(void *opaque, target_phys_addr_t addr)
3642 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3645 case 0x000: /* CONTROL_REVISION */
3648 case 0x010: /* CONTROL_SYSCONFIG */
3649 return s->sysconfig;
3651 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3652 return s->padconf[(addr - 0x30) >> 2];
3654 case 0x270: /* CONTROL_DEBOBS */
3657 case 0x274: /* CONTROL_DEVCONF */
3658 return s->devconfig;
3660 case 0x28c: /* CONTROL_EMU_SUPPORT */
3663 case 0x290: /* CONTROL_MSUSPENDMUX_0 */
3664 return s->msuspendmux[0];
3665 case 0x294: /* CONTROL_MSUSPENDMUX_1 */
3666 return s->msuspendmux[1];
3667 case 0x298: /* CONTROL_MSUSPENDMUX_2 */
3668 return s->msuspendmux[2];
3669 case 0x29c: /* CONTROL_MSUSPENDMUX_3 */
3670 return s->msuspendmux[3];
3671 case 0x2a0: /* CONTROL_MSUSPENDMUX_4 */
3672 return s->msuspendmux[4];
3673 case 0x2a4: /* CONTROL_MSUSPENDMUX_5 */
3676 case 0x2b8: /* CONTROL_PSA_CTRL */
3677 return s->psaconfig;
3678 case 0x2bc: /* CONTROL_PSA_CMD */
3679 case 0x2c0: /* CONTROL_PSA_VALUE */
3682 case 0x2b0: /* CONTROL_SEC_CTRL */
3684 case 0x2d0: /* CONTROL_SEC_EMU */
3686 case 0x2d4: /* CONTROL_SEC_TAP */
3688 case 0x2b4: /* CONTROL_SEC_TEST */
3689 case 0x2f0: /* CONTROL_SEC_STATUS */
3690 case 0x2f4: /* CONTROL_SEC_ERR_STATUS */
3691 /* Secure mode is not present on general-pusrpose device. Outside
3692 * secure mode these values cannot be read or written. */
3695 case 0x2d8: /* CONTROL_OCM_RAM_PERM */
3697 case 0x2dc: /* CONTROL_OCM_PUB_RAM_ADD */
3698 case 0x2e0: /* CONTROL_EXT_SEC_RAM_START_ADD */
3699 case 0x2e4: /* CONTROL_EXT_SEC_RAM_STOP_ADD */
3700 /* No secure mode so no Extended Secure RAM present. */
3703 case 0x2f8: /* CONTROL_STATUS */
3704 /* Device Type => General-purpose */
3706 case 0x2fc: /* CONTROL_GENERAL_PURPOSE_STATUS */
3708 case 0x300: /* CONTROL_RPUB_KEY_H_0 */
3709 case 0x304: /* CONTROL_RPUB_KEY_H_1 */
3710 case 0x308: /* CONTROL_RPUB_KEY_H_2 */
3711 case 0x30c: /* CONTROL_RPUB_KEY_H_3 */
3714 case 0x310: /* CONTROL_RAND_KEY_0 */
3715 case 0x314: /* CONTROL_RAND_KEY_1 */
3716 case 0x318: /* CONTROL_RAND_KEY_2 */
3717 case 0x31c: /* CONTROL_RAND_KEY_3 */
3718 case 0x320: /* CONTROL_CUST_KEY_0 */
3719 case 0x324: /* CONTROL_CUST_KEY_1 */
3720 case 0x330: /* CONTROL_TEST_KEY_0 */
3721 case 0x334: /* CONTROL_TEST_KEY_1 */
3722 case 0x338: /* CONTROL_TEST_KEY_2 */
3723 case 0x33c: /* CONTROL_TEST_KEY_3 */
3724 case 0x340: /* CONTROL_TEST_KEY_4 */
3725 case 0x344: /* CONTROL_TEST_KEY_5 */
3726 case 0x348: /* CONTROL_TEST_KEY_6 */
3727 case 0x34c: /* CONTROL_TEST_KEY_7 */
3728 case 0x350: /* CONTROL_TEST_KEY_8 */
3729 case 0x354: /* CONTROL_TEST_KEY_9 */
3730 /* Can only be accessed in secure mode and when C_FieldAccEnable
3731 * bit is set in CONTROL_SEC_CTRL.
3732 * TODO: otherwise an interconnect access error is generated. */
3740 static void omap_sysctl_write8(void *opaque, target_phys_addr_t addr,
3743 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3744 int pad_offset, byte_offset;
3748 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3749 pad_offset = (addr - 0x30) >> 2;
3750 byte_offset = (addr - 0x30) & (4 - 1);
3752 prev_value = s->padconf[pad_offset];
3753 prev_value &= ~(0xff << (byte_offset * 8));
3754 prev_value |= ((value & 0x1f1f1f1f) << (byte_offset * 8)) & 0x1f1f1f1f;
3755 s->padconf[pad_offset] = prev_value;
3764 static void omap_sysctl_write(void *opaque, target_phys_addr_t addr,
3767 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3770 case 0x000: /* CONTROL_REVISION */
3771 case 0x2a4: /* CONTROL_MSUSPENDMUX_5 */
3772 case 0x2c0: /* CONTROL_PSA_VALUE */
3773 case 0x2f8: /* CONTROL_STATUS */
3774 case 0x2fc: /* CONTROL_GENERAL_PURPOSE_STATUS */
3775 case 0x300: /* CONTROL_RPUB_KEY_H_0 */
3776 case 0x304: /* CONTROL_RPUB_KEY_H_1 */
3777 case 0x308: /* CONTROL_RPUB_KEY_H_2 */
3778 case 0x30c: /* CONTROL_RPUB_KEY_H_3 */
3779 case 0x310: /* CONTROL_RAND_KEY_0 */
3780 case 0x314: /* CONTROL_RAND_KEY_1 */
3781 case 0x318: /* CONTROL_RAND_KEY_2 */
3782 case 0x31c: /* CONTROL_RAND_KEY_3 */
3783 case 0x320: /* CONTROL_CUST_KEY_0 */
3784 case 0x324: /* CONTROL_CUST_KEY_1 */
3785 case 0x330: /* CONTROL_TEST_KEY_0 */
3786 case 0x334: /* CONTROL_TEST_KEY_1 */
3787 case 0x338: /* CONTROL_TEST_KEY_2 */
3788 case 0x33c: /* CONTROL_TEST_KEY_3 */
3789 case 0x340: /* CONTROL_TEST_KEY_4 */
3790 case 0x344: /* CONTROL_TEST_KEY_5 */
3791 case 0x348: /* CONTROL_TEST_KEY_6 */
3792 case 0x34c: /* CONTROL_TEST_KEY_7 */
3793 case 0x350: /* CONTROL_TEST_KEY_8 */
3794 case 0x354: /* CONTROL_TEST_KEY_9 */
3798 case 0x010: /* CONTROL_SYSCONFIG */
3799 s->sysconfig = value & 0x1e;
3802 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3803 /* XXX: should check constant bits */
3804 s->padconf[(addr - 0x30) >> 2] = value & 0x1f1f1f1f;
3807 case 0x270: /* CONTROL_DEBOBS */
3808 s->obs = value & 0xff;
3811 case 0x274: /* CONTROL_DEVCONF */
3812 s->devconfig = value & 0xffffc7ff;
3815 case 0x28c: /* CONTROL_EMU_SUPPORT */
3818 case 0x290: /* CONTROL_MSUSPENDMUX_0 */
3819 s->msuspendmux[0] = value & 0x3fffffff;
3821 case 0x294: /* CONTROL_MSUSPENDMUX_1 */
3822 s->msuspendmux[1] = value & 0x3fffffff;
3824 case 0x298: /* CONTROL_MSUSPENDMUX_2 */
3825 s->msuspendmux[2] = value & 0x3fffffff;
3827 case 0x29c: /* CONTROL_MSUSPENDMUX_3 */
3828 s->msuspendmux[3] = value & 0x3fffffff;
3830 case 0x2a0: /* CONTROL_MSUSPENDMUX_4 */
3831 s->msuspendmux[4] = value & 0x3fffffff;
3834 case 0x2b8: /* CONTROL_PSA_CTRL */
3835 s->psaconfig = value & 0x1c;
3836 s->psaconfig |= (value & 0x20) ? 2 : 1;
3838 case 0x2bc: /* CONTROL_PSA_CMD */
3841 case 0x2b0: /* CONTROL_SEC_CTRL */
3842 case 0x2b4: /* CONTROL_SEC_TEST */
3843 case 0x2d0: /* CONTROL_SEC_EMU */
3844 case 0x2d4: /* CONTROL_SEC_TAP */
3845 case 0x2d8: /* CONTROL_OCM_RAM_PERM */
3846 case 0x2dc: /* CONTROL_OCM_PUB_RAM_ADD */
3847 case 0x2e0: /* CONTROL_EXT_SEC_RAM_START_ADD */
3848 case 0x2e4: /* CONTROL_EXT_SEC_RAM_STOP_ADD */
3849 case 0x2f0: /* CONTROL_SEC_STATUS */
3850 case 0x2f4: /* CONTROL_SEC_ERR_STATUS */
3859 static CPUReadMemoryFunc *omap_sysctl_readfn[] = {
3861 omap_badwidth_read32, /* TODO */
3865 static CPUWriteMemoryFunc *omap_sysctl_writefn[] = {
3867 omap_badwidth_write32, /* TODO */
3871 static void omap_sysctl_reset(struct omap_sysctl_s *s)
3873 /* (power-on reset) */
3876 s->devconfig = 0x0c000000;
3877 s->msuspendmux[0] = 0x00000000;
3878 s->msuspendmux[1] = 0x00000000;
3879 s->msuspendmux[2] = 0x00000000;
3880 s->msuspendmux[3] = 0x00000000;
3881 s->msuspendmux[4] = 0x00000000;
3884 s->padconf[0x00] = 0x000f0f0f;
3885 s->padconf[0x01] = 0x00000000;
3886 s->padconf[0x02] = 0x00000000;
3887 s->padconf[0x03] = 0x00000000;
3888 s->padconf[0x04] = 0x00000000;
3889 s->padconf[0x05] = 0x00000000;
3890 s->padconf[0x06] = 0x00000000;
3891 s->padconf[0x07] = 0x00000000;
3892 s->padconf[0x08] = 0x08080800;
3893 s->padconf[0x09] = 0x08080808;
3894 s->padconf[0x0a] = 0x08080808;
3895 s->padconf[0x0b] = 0x08080808;
3896 s->padconf[0x0c] = 0x08080808;
3897 s->padconf[0x0d] = 0x08080800;
3898 s->padconf[0x0e] = 0x08080808;
3899 s->padconf[0x0f] = 0x08080808;
3900 s->padconf[0x10] = 0x18181808; /* | 0x07070700 if SBoot3 */
3901 s->padconf[0x11] = 0x18181818; /* | 0x07070707 if SBoot3 */
3902 s->padconf[0x12] = 0x18181818; /* | 0x07070707 if SBoot3 */
3903 s->padconf[0x13] = 0x18181818; /* | 0x07070707 if SBoot3 */
3904 s->padconf[0x14] = 0x18181818; /* | 0x00070707 if SBoot3 */
3905 s->padconf[0x15] = 0x18181818;
3906 s->padconf[0x16] = 0x18181818; /* | 0x07000000 if SBoot3 */
3907 s->padconf[0x17] = 0x1f001f00;
3908 s->padconf[0x18] = 0x1f1f1f1f;
3909 s->padconf[0x19] = 0x00000000;
3910 s->padconf[0x1a] = 0x1f180000;
3911 s->padconf[0x1b] = 0x00001f1f;
3912 s->padconf[0x1c] = 0x1f001f00;
3913 s->padconf[0x1d] = 0x00000000;
3914 s->padconf[0x1e] = 0x00000000;
3915 s->padconf[0x1f] = 0x08000000;
3916 s->padconf[0x20] = 0x08080808;
3917 s->padconf[0x21] = 0x08080808;
3918 s->padconf[0x22] = 0x0f080808;
3919 s->padconf[0x23] = 0x0f0f0f0f;
3920 s->padconf[0x24] = 0x000f0f0f;
3921 s->padconf[0x25] = 0x1f1f1f0f;
3922 s->padconf[0x26] = 0x080f0f1f;
3923 s->padconf[0x27] = 0x070f1808;
3924 s->padconf[0x28] = 0x0f070707;
3925 s->padconf[0x29] = 0x000f0f1f;
3926 s->padconf[0x2a] = 0x0f0f0f1f;
3927 s->padconf[0x2b] = 0x08000000;
3928 s->padconf[0x2c] = 0x0000001f;
3929 s->padconf[0x2d] = 0x0f0f1f00;
3930 s->padconf[0x2e] = 0x1f1f0f0f;
3931 s->padconf[0x2f] = 0x0f1f1f1f;
3932 s->padconf[0x30] = 0x0f0f0f0f;
3933 s->padconf[0x31] = 0x0f1f0f1f;
3934 s->padconf[0x32] = 0x0f0f0f0f;
3935 s->padconf[0x33] = 0x0f1f0f1f;
3936 s->padconf[0x34] = 0x1f1f0f0f;
3937 s->padconf[0x35] = 0x0f0f1f1f;
3938 s->padconf[0x36] = 0x0f0f1f0f;
3939 s->padconf[0x37] = 0x0f0f0f0f;
3940 s->padconf[0x38] = 0x1f18180f;
3941 s->padconf[0x39] = 0x1f1f1f1f;
3942 s->padconf[0x3a] = 0x00001f1f;
3943 s->padconf[0x3b] = 0x00000000;
3944 s->padconf[0x3c] = 0x00000000;
3945 s->padconf[0x3d] = 0x0f0f0f0f;
3946 s->padconf[0x3e] = 0x18000f0f;
3947 s->padconf[0x3f] = 0x00070000;
3948 s->padconf[0x40] = 0x00000707;
3949 s->padconf[0x41] = 0x0f1f0700;
3950 s->padconf[0x42] = 0x1f1f070f;
3951 s->padconf[0x43] = 0x0008081f;
3952 s->padconf[0x44] = 0x00000800;
3955 struct omap_sysctl_s *omap_sysctl_init(struct omap_target_agent_s *ta,
3956 omap_clk iclk, struct omap_mpu_state_s *mpu)
3959 struct omap_sysctl_s *s = (struct omap_sysctl_s *)
3960 qemu_mallocz(sizeof(struct omap_sysctl_s));
3963 omap_sysctl_reset(s);
3965 iomemtype = l4_register_io_memory(0, omap_sysctl_readfn,
3966 omap_sysctl_writefn, s);
3967 omap_l4_attach(ta, 0, iomemtype);
3972 /* SDRAM Controller Subsystem */
3973 struct omap_sdrc_s {
3983 uint32_t actim_ctrla;
3984 uint32_t actim_ctrlb;
3990 static void omap_sdrc_reset(struct omap_sdrc_s *s)
3994 s->sharing = 0; // TODO: copy from system control module
3996 s->power_reg = 0x85;
3997 s->cs[0].mcfg = s->cs[1].mcfg = 0; // TODO: copy from system control module!
3998 s->cs[0].mr = s->cs[1].mr = 0x0024;
3999 s->cs[0].emr2 = s->cs[1].emr2 = 0;
4000 s->cs[0].actim_ctrla = s->cs[1].actim_ctrla = 0;
4001 s->cs[0].actim_ctrlb = s->cs[1].actim_ctrlb = 0;
4002 s->cs[0].rfr_ctrl = s->cs[1].rfr_ctrl = 0;
4003 s->cs[0].manual = s->cs[1].manual = 0;
4006 static uint32_t omap_sdrc_read(void *opaque, target_phys_addr_t addr)
4008 struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
4012 case 0x00: /* SDRC_REVISION */
4015 case 0x10: /* SDRC_SYSCONFIG */
4018 case 0x14: /* SDRC_SYSSTATUS */
4019 return 1; /* RESETDONE */
4021 case 0x40: /* SDRC_CS_CFG */
4024 case 0x44: /* SDRC_SHARING */
4027 case 0x48: /* SDRC_ERR_ADDR */
4030 case 0x4c: /* SDRC_ERR_TYPE */
4033 case 0x60: /* SDRC_DLLA_SCTRL */
4034 return s->dlla_ctrl;
4036 case 0x64: /* SDRC_DLLA_STATUS */
4037 return ~(s->dlla_ctrl & 0x4);
4039 case 0x68: /* SDRC_DLLB_CTRL */
4040 case 0x6c: /* SDRC_DLLB_STATUS */
4043 case 0x70: /* SDRC_POWER */
4044 return s->power_reg;
4051 switch (addr & 0x3f) {
4052 case 0x00: /* SDRC_MCFG_x */
4053 return s->cs[cs].mcfg;
4054 case 0x04: /* SDRC_MR_x */
4055 return s->cs[cs].mr;
4056 case 0x08: /* SDRC_EMR1_x */
4058 case 0x0c: /* SDRC_EMR2_x */
4059 return s->cs[cs].emr2;
4060 case 0x10: /* SDRC_EMR3_x */
4064 return s->cs[1].actim_ctrla; /* SDRC_ACTIM_CTRLA_1 */
4065 return 0x00; /* SDRC_DCDL1_CTRL */
4068 return s->cs[1].actim_ctrlb; /* SDRC_ACTIM_CTRLB_1 */
4069 return 0x00; /* SDRC_DCDL2_CTRL */
4072 return s->cs[0].actim_ctrla; /* SDRC_ACTIM_CTRLA_0 */
4076 return s->cs[0].actim_ctrlb; /* SDRC_ACTIM_CTRLB_0 */
4078 case 0x24: /* SDRC_RFR_CTRL_x */
4079 return s->cs[cs].rfr_ctrl;
4080 case 0x28: /* SDRC_MANUAL_x */
4081 return s->cs[cs].manual;
4085 addr += cs * 0x30; // restore address to get correct error messages
4096 static void omap_sdrc_write(void *opaque, target_phys_addr_t addr,
4099 struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
4103 case 0x00: /* SDRC_REVISION */
4104 case 0x14: /* SDRC_SYSSTATUS */
4105 case 0x48: /* SDRC_ERR_ADDR */
4106 case 0x64: /* SDRC_DLLA_STATUS */
4107 case 0x6c: /* SDRC_DLLB_STATUS */
4108 OMAP_RO_REGV(addr, value);
4111 case 0x10: /* SDRC_SYSCONFIG */
4112 /* ignore invalid idle mode settings */
4113 /*if ((value >> 3) != 0x2)
4114 fprintf(stderr, "%s: bad SDRAM idle mode %i for SDRC_SYSCONFIG (full value 0x%08x)\n",
4115 __FUNCTION__, value >> 3, value);*/
4118 s->config = value & 0x18;
4121 case 0x40: /* SDRC_CS_CFG */
4122 s->cscfg = value & 0x30f;
4125 case 0x44: /* SDRC_SHARING */
4126 if (!(s->sharing & 0x40000000)) /* LOCK */
4127 s->sharing = value & 0x40007f00;
4130 case 0x4c: /* SDRC_ERR_TYPE */
4131 OMAP_BAD_REGV(addr, value);
4134 case 0x60: /* SDRC_DLLA_CTRL */
4135 s->dlla_ctrl = value & 0xffff00fe;
4138 case 0x68: /* SDRC_DLLB_CTRL */
4139 /* silently ignore */
4140 /*OMAP_BAD_REGV(addr, value);*/
4143 case 0x70: /* SDRC_POWER_REG */
4144 s->power_reg = value & 0x04fffffd;
4152 switch (addr & 0x3f) {
4153 case 0x00: /* SDRC_MCFG_x */
4154 if (!(s->cs[cs].mcfg & 0x40000000)) { /* LOCKSTATUS */
4155 if (value & 0x00080000) /* ADDRMUXLEGACY */
4156 s->cs[cs].mcfg = value & 0x477bffdf;
4158 s->cs[cs].mcfg = value & 0x41fbffdf; // ????
4161 case 0x04: /* SDRC_MR_x */
4162 s->cs[cs].mr = value & 0xfff;
4164 case 0x08: /* SDRC_EMR1_x */
4166 case 0x0c: /* SDRC_EMR2_x */
4167 s->cs[cs].emr2 = value & 0xfff;
4169 case 0x10: /* SDRC_EMR3_x */
4173 s->cs[1].actim_ctrla = value & 0xffffffdf; /* SDRC_ACTIM_CTRLA_1 */
4174 break; /* SDRC_DCDL1_CTRL */
4177 s->cs[1].actim_ctrlb = value & 0x000377ff; /* SDRC_ACTIM_CTRLB_1 */
4178 break; /* SDRC_DCDL2_CTRL */
4181 s->cs[0].actim_ctrla = value & 0xffffffdf; /* SDRC_ACTIM_CTRLA_0 */
4183 OMAP_BAD_REGV(addr + 0x30, value);
4187 s->cs[0].actim_ctrlb = value & 0x000377ff; /* SDRC_ACTIM_CTRLB_0 */
4189 OMAP_BAD_REGV(addr + 0x30, value);
4191 case 0x24: /* SDRC_RFR_CTRL_x */
4192 s->cs[cs].rfr_ctrl = value & 0x00ffff03;
4194 case 0x28: /* SDRC_MANUAL_x */
4195 s->cs[cs].manual = value & 0xffff000f;
4198 OMAP_BAD_REGV(addr + cs * 0x30, value);
4204 OMAP_BAD_REGV(addr, value);
4209 static CPUReadMemoryFunc *omap_sdrc_readfn[] = {
4210 omap_badwidth_read32,
4211 omap_badwidth_read32,
4215 static CPUWriteMemoryFunc *omap_sdrc_writefn[] = {
4216 omap_badwidth_write32,
4217 omap_badwidth_write32,
4221 struct omap_sdrc_s *omap_sdrc_init(target_phys_addr_t base)
4224 struct omap_sdrc_s *s = (struct omap_sdrc_s *)
4225 qemu_mallocz(sizeof(struct omap_sdrc_s));
4229 iomemtype = cpu_register_io_memory(0, omap_sdrc_readfn,
4230 omap_sdrc_writefn, s);
4231 cpu_register_physical_memory(base, 0x1000, iomemtype);
4236 /* General-Purpose Memory Controller */
4237 struct omap_gpmc_s {
4246 uint32_t prefconfig[2];
4250 struct omap_gpmc_cs_file_s {
4252 target_phys_addr_t base;
4255 void (*base_update)(void *opaque, target_phys_addr_t new);
4256 void (*unmap)(void *opaque);
4258 struct nand_flash_s *nand;
4263 struct ecc_state_s ecc[9];
4266 static void omap_gpmc_int_update(struct omap_gpmc_s *s)
4268 qemu_set_irq(s->irq, s->irqen & s->irqst);
4271 static void omap_gpmc_cs_map(struct omap_gpmc_cs_file_s *f, int base, int mask)
4273 /* TODO: check for overlapping regions and report access errors */
4274 if ((mask != 0x8 && mask != 0xc && mask != 0xe && mask != 0xf) ||
4275 (base < 0 || base >= 0x40) ||
4276 (base & 0x0f & ~mask)) {
4277 fprintf(stderr, "%s: wrong cs address mapping/decoding!\n",
4285 f->base = base << 24;
4286 f->size = (0x0fffffff & ~(mask << 24)) + 1;
4287 /* TODO: rather than setting the size of the mapping (which should be
4288 * constant), the mask should cause wrapping of the address space, so
4289 * that the same memory becomes accessible at every <i>size</i> bytes
4290 * starting from <i>base</i>. */
4292 cpu_register_physical_memory(f->base, f->size, f->iomemtype);
4295 f->base_update(f->opaque, f->base);
4298 static void omap_gpmc_cs_unmap(struct omap_gpmc_cs_file_s *f)
4302 f->unmap(f->opaque);
4304 cpu_register_physical_memory(f->base, f->size, IO_MEM_UNASSIGNED);
4310 static void omap_gpmc_reset(struct omap_gpmc_s *s)
4317 omap_gpmc_int_update(s);
4320 s->prefconfig[0] = 0x00004000;
4321 s->prefconfig[1] = 0x00000000;
4325 for (i = 0; i < 8; i ++) {
4326 if (s->cs_file[i].config[6] & (1 << 6)) /* CSVALID */
4327 omap_gpmc_cs_unmap(s->cs_file + i);
4328 s->cs_file[i].config[0] = i ? 1 << 12 : 0;
4329 s->cs_file[i].config[1] = 0x101001;
4330 s->cs_file[i].config[2] = 0x020201;
4331 s->cs_file[i].config[3] = 0x10031003;
4332 s->cs_file[i].config[4] = 0x10f1111;
4333 s->cs_file[i].config[5] = 0;
4334 s->cs_file[i].config[6] = 0xf00 | (i ? 0 : 1 << 6);
4335 if (s->cs_file[i].config[6] & (1 << 6)) /* CSVALID */
4336 omap_gpmc_cs_map(&s->cs_file[i],
4337 s->cs_file[i].config[6] & 0x3f, /* MASKADDR */
4338 (s->cs_file[i].config[6] >> 8 & 0xf)); /* BASEADDR */
4340 omap_gpmc_cs_map(s->cs_file, 0, 0xf);
4343 s->ecc_cfg = 0x3fcff000;
4344 for (i = 0; i < 9; i ++)
4345 ecc_reset(&s->ecc[i]);
4348 static uint32_t omap_gpmc_read(void *opaque, target_phys_addr_t addr)
4350 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4352 struct omap_gpmc_cs_file_s *f;
4353 uint32_t x1, x2, x3, x4;
4356 case 0x000: /* GPMC_REVISION */
4359 case 0x010: /* GPMC_SYSCONFIG */
4360 return s->sysconfig;
4362 case 0x014: /* GPMC_SYSSTATUS */
4363 return 1; /* RESETDONE */
4365 case 0x018: /* GPMC_IRQSTATUS */
4368 case 0x01c: /* GPMC_IRQENABLE */
4371 case 0x040: /* GPMC_TIMEOUT_CONTROL */
4374 case 0x044: /* GPMC_ERR_ADDRESS */
4375 case 0x048: /* GPMC_ERR_TYPE */
4378 case 0x050: /* GPMC_CONFIG */
4381 case 0x054: /* GPMC_STATUS */
4384 case 0x060 ... 0x1d4:
4385 cs = (addr - 0x060) / 0x30;
4387 f = s->cs_file + cs;
4389 case 0x60: /* GPMC_CONFIG1 */
4390 return f->config[0];
4391 case 0x64: /* GPMC_CONFIG2 */
4392 return f->config[1];
4393 case 0x68: /* GPMC_CONFIG3 */
4394 return f->config[2];
4395 case 0x6c: /* GPMC_CONFIG4 */
4396 return f->config[3];
4397 case 0x70: /* GPMC_CONFIG5 */
4398 return f->config[4];
4399 case 0x74: /* GPMC_CONFIG6 */
4400 return f->config[5];
4401 case 0x78: /* GPMC_CONFIG7 */
4402 return f->config[6];
4403 case 0x84: /* GPMC_NAND_DATA */
4404 if (((f->config[0] >> 10) & 3) == 2 /* NAND device type ? */
4406 nand_setpins(f->nand, 0, 0, 0, 1, 0);
4407 switch (((f->config[0] >> 12) & 3)) {
4409 x1 = nand_getio(f->nand);
4410 x2 = nand_getio(f->nand);
4411 x3 = nand_getio(f->nand);
4412 x4 = nand_getio(f->nand);
4413 return (x4 << 24) | (x3 << 16) | (x2 << 8) | x1;
4415 x1 = nand_getio(f->nand);
4416 x2 = nand_getio(f->nand);
4417 return (x2 << 16) | x1;
4428 case 0x1e0: /* GPMC_PREFETCH_CONFIG1 */
4429 return s->prefconfig[0];
4430 case 0x1e4: /* GPMC_PREFETCH_CONFIG2 */
4431 return s->prefconfig[1];
4432 case 0x1ec: /* GPMC_PREFETCH_CONTROL */
4433 return s->prefcontrol;
4434 case 0x1f0: /* GPMC_PREFETCH_STATUS */
4435 return (s->preffifo << 24) |
4437 ((s->prefconfig[0] >> 8) & 0x7f) ? 1 : 0) << 16) |
4440 case 0x1f4: /* GPMC_ECC_CONFIG */
4442 case 0x1f8: /* GPMC_ECC_CONTROL */
4444 case 0x1fc: /* GPMC_ECC_SIZE_CONFIG */
4446 case 0x200 ... 0x220: /* GPMC_ECC_RESULT */
4447 cs = (addr & 0x1f) >> 2;
4448 /* TODO: check correctness */
4450 ((s->ecc[cs].cp & 0x07) << 0) |
4451 ((s->ecc[cs].cp & 0x38) << 13) |
4452 ((s->ecc[cs].lp[0] & 0x1ff) << 3) |
4453 ((s->ecc[cs].lp[1] & 0x1ff) << 19);
4455 case 0x230: /* GPMC_TESTMODE_CTRL */
4457 case 0x234: /* GPMC_PSA_LSB */
4458 case 0x238: /* GPMC_PSA_MSB */
4466 static uint32_t omap_gpmc_read8(void *opaque, target_phys_addr_t addr)
4468 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4470 struct omap_gpmc_cs_file_s *f;
4473 case 0x060 ... 0x1d4:
4474 cs = (addr - 0x060) / 0x30;
4476 f = s->cs_file + cs;
4478 case 0x84 ... 0x87: /* GPMC_NAND_DATA */
4479 if (((f->config[0] >> 10) & 3) == 2 /* NAND device type ? */
4481 nand_setpins(f->nand, 0, 0, 0, 1, 0);
4482 switch (((f->config[0] >> 12) & 3)) {
4484 return nand_getio(f->nand);
4486 /* reading 8bits from a 16bit device?! */
4487 return nand_getio(f->nand);
4504 static uint32_t omap_gpmc_read16(void *opaque, target_phys_addr_t addr)
4506 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4508 struct omap_gpmc_cs_file_s *f;
4512 case 0x060 ... 0x1d4:
4513 cs = (addr - 0x060) / 0x30;
4515 f = s->cs_file + cs;
4517 case 0x84: /* GPMC_NAND_DATA */
4519 if (((f->config[0] >> 10) & 3) == 2 /* NAND device type ? */
4521 nand_setpins(f->nand, 0, 0, 0, 1, 0);
4522 switch (((f->config[0] >> 12) & 3)) {
4524 x1 = nand_getio(f->nand);
4525 x2 = nand_getio(f->nand);
4526 return (x2 << 8) | x1;
4528 return nand_getio(f->nand);
4545 static void omap_gpmc_write(void *opaque, target_phys_addr_t addr,
4548 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4550 struct omap_gpmc_cs_file_s *f;
4553 case 0x000: /* GPMC_REVISION */
4554 case 0x014: /* GPMC_SYSSTATUS */
4555 case 0x054: /* GPMC_STATUS */
4556 case 0x1f0: /* GPMC_PREFETCH_STATUS */
4557 case 0x200 ... 0x220: /* GPMC_ECC_RESULT */
4558 case 0x234: /* GPMC_PSA_LSB */
4559 case 0x238: /* GPMC_PSA_MSB */
4560 OMAP_RO_REGV(addr, value);
4563 case 0x010: /* GPMC_SYSCONFIG */
4564 if ((value >> 3) == 0x3)
4565 fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
4566 __FUNCTION__, value >> 3);
4569 s->sysconfig = value & 0x19;
4572 case 0x018: /* GPMC_IRQSTATUS */
4574 omap_gpmc_int_update(s);
4577 case 0x01c: /* GPMC_IRQENABLE */
4578 s->irqen = value & 0xf03;
4579 omap_gpmc_int_update(s);
4582 case 0x040: /* GPMC_TIMEOUT_CONTROL */
4583 s->timeout = value & 0x1ff1;
4586 case 0x044: /* GPMC_ERR_ADDRESS */
4587 case 0x048: /* GPMC_ERR_TYPE */
4590 case 0x050: /* GPMC_CONFIG */
4591 s->config = value & 0xf13;
4594 case 0x060 ... 0x1d4:
4595 cs = (addr - 0x060) / 0x30;
4597 f = s->cs_file + cs;
4599 case 0x60: /* GPMC_CONFIG1 */
4600 f->config[0] = value & 0xffef3e13;
4602 case 0x64: /* GPMC_CONFIG2 */
4603 f->config[1] = value & 0x001f1f8f;
4605 case 0x68: /* GPMC_CONFIG3 */
4606 f->config[2] = value & 0x001f1f8f;
4608 case 0x6c: /* GPMC_CONFIG4 */
4609 f->config[3] = value & 0x1f8f1f8f;
4611 case 0x70: /* GPMC_CONFIG5 */
4612 f->config[4] = value & 0x0f1f1f1f;
4614 case 0x74: /* GPMC_CONFIG6 */
4615 f->config[5] = value & 0x00000fcf;
4617 case 0x78: /* GPMC_CONFIG7 */
4618 if ((f->config[6] ^ value) & 0xf7f) {
4619 if (f->config[6] & (1 << 6)) /* CSVALID */
4620 omap_gpmc_cs_unmap(f);
4621 if (value & (1 << 6)) /* CSVALID */
4622 omap_gpmc_cs_map(f, value & 0x3f, /* MASKADDR */
4623 (value >> 8 & 0xf)); /* BASEADDR */
4625 f->config[6] = value & 0x00000f7f;
4627 case 0x7c: /* GPMC_NAND_COMMAND */
4628 case 0x80: /* GPMC_NAND_ADDRESS */
4629 case 0x84: /* GPMC_NAND_DATA */
4630 if (((f->config[0] >> 10) & 3) == 2 /* NAND device type ? */
4633 case 0x7c: nand_setpins(f->nand, 1, 0, 0, 1, 0); break; /* CLE */
4634 case 0x80: nand_setpins(f->nand, 0, 1, 0, 1, 0); break; /* ALE */
4635 case 0x84: nand_setpins(f->nand, 0, 0, 0, 1, 0); break;
4638 switch (((f->config[0] >> 12) & 3)) {
4640 nand_setio(f->nand, value & 0xff);
4641 nand_setio(f->nand, (value >> 8) & 0xff);
4642 nand_setio(f->nand, (value >> 16) & 0xff);
4643 nand_setio(f->nand, (value >> 24) & 0xff);
4646 nand_setio(f->nand, value & 0xffff);
4647 nand_setio(f->nand, (value >> 16) & 0xffff);
4659 case 0x1e0: /* GPMC_PREFETCH_CONFIG1 */
4660 s->prefconfig[0] = value & 0x7f8f7fbf;
4661 /* TODO: update interrupts, fifos, dmas */
4664 case 0x1e4: /* GPMC_PREFETCH_CONFIG2 */
4665 s->prefconfig[1] = value & 0x3fff;
4668 case 0x1ec: /* GPMC_PREFETCH_CONTROL */
4669 s->prefcontrol = value & 1;
4670 if (s->prefcontrol) {
4671 if (s->prefconfig[0] & 1)
4679 case 0x1f4: /* GPMC_ECC_CONFIG */
4682 case 0x1f8: /* GPMC_ECC_CONTROL */
4683 if (value & (1 << 8))
4684 for (cs = 0; cs < 9; cs ++)
4685 ecc_reset(&s->ecc[cs]);
4686 s->ecc_ptr = value & 0xf;
4687 if (s->ecc_ptr == 0 || s->ecc_ptr > 9) {
4692 case 0x1fc: /* GPMC_ECC_SIZE_CONFIG */
4693 s->ecc_cfg = value & 0x3fcff1ff;
4695 case 0x230: /* GPMC_TESTMODE_CTRL */
4697 fprintf(stderr, "%s: test mode enable attempt\n", __FUNCTION__);
4702 OMAP_BAD_REGV(addr, value);
4707 static void omap_gpmc_write8(void *opaque, target_phys_addr_t addr,
4710 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4712 struct omap_gpmc_cs_file_s *f;
4715 case 0x060 ... 0x1d4:
4716 cs = (addr - 0x060) / 0x30;
4718 f = s->cs_file + cs;
4720 case 0x7c ... 0x7f: /* GPMC_NAND_COMMAND */
4721 case 0x80 ... 0x83: /* GPMC_NAND_ADDRESS */
4722 case 0x84 ... 0x87: /* GPMC_NAND_DATA */
4723 if (((f->config[0] >> 10) & 3) == 2 /* NAND device type ? */
4727 nand_setpins(f->nand, 1, 0, 0, 1, 0); /* CLE */
4730 nand_setpins(f->nand, 0, 1, 0, 1, 0); /* ALE */
4733 nand_setpins(f->nand, 0, 0, 0, 1, 0);
4738 switch (((f->config[0] >> 12) & 3)) {
4740 nand_setio(f->nand, value & 0xff);
4743 /* writing to a 16bit device with 8bit access!? */
4744 nand_setio(f->nand, value & 0xffff);
4757 OMAP_BAD_REGV(addr, value);
4762 static void omap_gpmc_write16(void *opaque, target_phys_addr_t addr,
4765 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4767 struct omap_gpmc_cs_file_s *f;
4770 case 0x060 ... 0x1d4:
4771 cs = (addr - 0x060) / 0x30;
4773 f = s->cs_file + cs;
4775 case 0x7c: /* GPMC_NAND_COMMAND */
4777 case 0x80: /* GPMC_NAND_ADDRESS */
4779 case 0x84: /* GPMC_NAND_DATA */
4781 if (((f->config[0] >> 10) & 3) == 2 /* NAND device type ? */
4786 nand_setpins(f->nand, 1, 0, 0, 1, 0); /* CLE */
4790 nand_setpins(f->nand, 0, 1, 0, 1, 0); /* ALE */
4794 nand_setpins(f->nand, 0, 0, 0, 1, 0);
4799 switch (((f->config[0] >> 12) & 3)) {
4801 nand_setio(f->nand, value & 0xff);
4802 nand_setio(f->nand, (value >> 8) & 0xff);
4805 nand_setio(f->nand, value & 0xffff);
4818 OMAP_BAD_REGV(addr, value);
4823 static CPUReadMemoryFunc *omap_gpmc_readfn[] = {
4829 static CPUWriteMemoryFunc *omap_gpmc_writefn[] = {
4835 struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu,
4836 target_phys_addr_t base, qemu_irq irq)
4839 struct omap_gpmc_s *s = (struct omap_gpmc_s *)
4840 qemu_mallocz(sizeof(struct omap_gpmc_s));
4842 s->revision = cpu_class_omap3(mpu) ? 0x50 : 0x20;
4845 iomemtype = cpu_register_io_memory(0, omap_gpmc_readfn,
4846 omap_gpmc_writefn, s);
4847 cpu_register_physical_memory(base, 0x1000, iomemtype);
4852 void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, int iomemtype,
4853 void (*base_upd)(void *opaque, target_phys_addr_t new),
4854 void (*unmap)(void *opaque), void *opaque,
4855 struct nand_flash_s *nand_s)
4857 struct omap_gpmc_cs_file_s *f;
4859 if (cs < 0 || cs >= 8) {
4860 fprintf(stderr, "%s: bad chip-select %i\n", __FUNCTION__, cs);
4863 f = &s->cs_file[cs];
4865 f->iomemtype = iomemtype;
4866 f->base_update = base_upd;
4872 f->config[0] &= ~(0xf << 10);
4873 f->config[0] |= 2 << 10; /* DEVICETYPE = NAND */
4874 if (nand_getbuswidth(f->nand) == 16)
4875 f->config[0] |= 1 << 12; /* 16-bit device */
4878 if (f->config[6] & (1 << 6)) /* CSVALID */
4879 omap_gpmc_cs_map(f, f->config[6] & 0x3f, /* MASKADDR */
4880 (f->config[6] >> 8 & 0xf)); /* BASEADDR */
4883 /* General chip reset */
4884 static void omap2_mpu_reset(void *opaque)
4886 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4888 omap_inth_reset(mpu->ih[0]);
4889 omap_dma_reset(mpu->dma);
4890 omap_prcm_reset(mpu->prcm);
4891 omap_sysctl_reset(mpu->sysc);
4892 omap_gp_timer_reset(mpu->gptimer[0]);
4893 omap_gp_timer_reset(mpu->gptimer[1]);
4894 omap_gp_timer_reset(mpu->gptimer[2]);
4895 omap_gp_timer_reset(mpu->gptimer[3]);
4896 omap_gp_timer_reset(mpu->gptimer[4]);
4897 omap_gp_timer_reset(mpu->gptimer[5]);
4898 omap_gp_timer_reset(mpu->gptimer[6]);
4899 omap_gp_timer_reset(mpu->gptimer[7]);
4900 omap_gp_timer_reset(mpu->gptimer[8]);
4901 omap_gp_timer_reset(mpu->gptimer[9]);
4902 omap_gp_timer_reset(mpu->gptimer[10]);
4903 omap_gp_timer_reset(mpu->gptimer[11]);
4904 omap_synctimer_reset(&mpu->synctimer);
4905 omap_sdrc_reset(mpu->sdrc);
4906 omap_gpmc_reset(mpu->gpmc);
4907 omap_dss_reset(mpu->dss);
4908 omap_uart_reset(mpu->uart[0]);
4909 omap_uart_reset(mpu->uart[1]);
4910 omap_uart_reset(mpu->uart[2]);
4911 omap_mmc_reset(mpu->mmc);
4912 omap_gpif_reset(mpu->gpif);
4913 omap_mcspi_reset(mpu->mcspi[0]);
4914 omap_mcspi_reset(mpu->mcspi[1]);
4915 omap_i2c_reset(mpu->i2c[0]);
4916 omap_i2c_reset(mpu->i2c[1]);
4917 cpu_reset(mpu->env);
4920 static int omap2_validate_addr(struct omap_mpu_state_s *s,
4921 target_phys_addr_t addr)
4926 static const struct dma_irq_map omap2_dma_irq_map[] = {
4927 { 0, OMAP_INT_24XX_SDMA_IRQ0 },
4928 { 0, OMAP_INT_24XX_SDMA_IRQ1 },
4929 { 0, OMAP_INT_24XX_SDMA_IRQ2 },
4930 { 0, OMAP_INT_24XX_SDMA_IRQ3 },
4933 struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,
4936 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
4937 qemu_mallocz(sizeof(struct omap_mpu_state_s));
4938 ram_addr_t sram_base, q2_base;
4940 qemu_irq dma_irqs[4];
4941 omap_clk gpio_clks[4];
4946 s->mpu_model = omap2420;
4947 s->env = cpu_init(core ?: "arm1136-r2");
4949 fprintf(stderr, "Unable to find CPU definition\n");
4952 s->sdram_size = sdram_size;
4953 s->sram_size = OMAP242X_SRAM_SIZE;
4955 s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0];
4960 /* Memory-mapped stuff */
4961 cpu_register_physical_memory(OMAP2_Q2_BASE, s->sdram_size,
4962 (q2_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
4963 cpu_register_physical_memory(OMAP2_SRAM_BASE, s->sram_size,
4964 (sram_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
4966 s->l4 = omap_l4_init(OMAP2_L4_BASE, 54);
4968 /* Actually mapped at any 2K boundary in the ARM11 private-peripheral if */
4969 cpu_irq = arm_pic_init_cpu(s->env);
4970 s->ih[0] = omap2_inth_init(s,
4971 0x480fe000, 0x1000, 3, &s->irq[0],
4972 cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ],
4973 omap_findclk(s, "mpu_intc_fclk"),
4974 omap_findclk(s, "mpu_intc_iclk"));
4976 s->prcm = omap_prcm_init(omap_l4tao(s->l4, 3),
4977 s->irq[0][OMAP_INT_24XX_PRCM_MPU_IRQ], NULL, NULL, s);
4979 s->sysc = omap_sysctl_init(omap_l4tao(s->l4, 1),
4980 omap_findclk(s, "omapctrl_iclk"), s);
4982 for (i = 0; i < 4; i ++)
4984 s->irq[omap2_dma_irq_map[i].ih][omap2_dma_irq_map[i].intr];
4985 s->dma = omap_dma4_init(0x48056000, dma_irqs, s, 256, 32,
4986 omap_findclk(s, "sdma_iclk"),
4987 omap_findclk(s, "sdma_fclk"));
4988 s->port->addr_valid = omap2_validate_addr;
4990 /* Register SDRAM and SRAM ports for fast DMA transfers. */
4991 soc_dma_port_add_mem_ram(s->dma, q2_base, OMAP2_Q2_BASE, s->sdram_size);
4992 soc_dma_port_add_mem_ram(s->dma, sram_base, OMAP2_SRAM_BASE, s->sram_size);
4994 s->uart[0] = omap2_uart_init(omap_l4ta(s->l4, 19),
4995 s->irq[0][OMAP_INT_24XX_UART1_IRQ],
4996 omap_findclk(s, "uart1_fclk"),
4997 omap_findclk(s, "uart1_iclk"),
4998 s->drq[OMAP24XX_DMA_UART1_TX],
4999 s->drq[OMAP24XX_DMA_UART1_RX], serial_hds[0]);
5000 s->uart[1] = omap2_uart_init(omap_l4ta(s->l4, 20),
5001 s->irq[0][OMAP_INT_24XX_UART2_IRQ],
5002 omap_findclk(s, "uart2_fclk"),
5003 omap_findclk(s, "uart2_iclk"),
5004 s->drq[OMAP24XX_DMA_UART2_TX],
5005 s->drq[OMAP24XX_DMA_UART2_RX],
5006 serial_hds[0] ? serial_hds[1] : 0);
5007 s->uart[2] = omap2_uart_init(omap_l4ta(s->l4, 21),
5008 s->irq[0][OMAP_INT_24XX_UART3_IRQ],
5009 omap_findclk(s, "uart3_fclk"),
5010 omap_findclk(s, "uart3_iclk"),
5011 s->drq[OMAP24XX_DMA_UART3_TX],
5012 s->drq[OMAP24XX_DMA_UART3_RX],
5013 serial_hds[0] && serial_hds[1] ? serial_hds[2] : 0);
5015 s->gptimer[0] = omap_gp_timer_init(omap_l4ta(s->l4, 7),
5016 s->irq[0][OMAP_INT_24XX_GPTIMER1],
5017 omap_findclk(s, "wu_gpt1_clk"),
5018 omap_findclk(s, "wu_l4_iclk"));
5019 s->gptimer[1] = omap_gp_timer_init(omap_l4ta(s->l4, 8),
5020 s->irq[0][OMAP_INT_24XX_GPTIMER2],
5021 omap_findclk(s, "core_gpt2_clk"),
5022 omap_findclk(s, "core_l4_iclk"));
5023 s->gptimer[2] = omap_gp_timer_init(omap_l4ta(s->l4, 22),
5024 s->irq[0][OMAP_INT_24XX_GPTIMER3],
5025 omap_findclk(s, "core_gpt3_clk"),
5026 omap_findclk(s, "core_l4_iclk"));
5027 s->gptimer[3] = omap_gp_timer_init(omap_l4ta(s->l4, 23),
5028 s->irq[0][OMAP_INT_24XX_GPTIMER4],
5029 omap_findclk(s, "core_gpt4_clk"),
5030 omap_findclk(s, "core_l4_iclk"));
5031 s->gptimer[4] = omap_gp_timer_init(omap_l4ta(s->l4, 24),
5032 s->irq[0][OMAP_INT_24XX_GPTIMER5],
5033 omap_findclk(s, "core_gpt5_clk"),
5034 omap_findclk(s, "core_l4_iclk"));
5035 s->gptimer[5] = omap_gp_timer_init(omap_l4ta(s->l4, 25),
5036 s->irq[0][OMAP_INT_24XX_GPTIMER6],
5037 omap_findclk(s, "core_gpt6_clk"),
5038 omap_findclk(s, "core_l4_iclk"));
5039 s->gptimer[6] = omap_gp_timer_init(omap_l4ta(s->l4, 26),
5040 s->irq[0][OMAP_INT_24XX_GPTIMER7],
5041 omap_findclk(s, "core_gpt7_clk"),
5042 omap_findclk(s, "core_l4_iclk"));
5043 s->gptimer[7] = omap_gp_timer_init(omap_l4ta(s->l4, 27),
5044 s->irq[0][OMAP_INT_24XX_GPTIMER8],
5045 omap_findclk(s, "core_gpt8_clk"),
5046 omap_findclk(s, "core_l4_iclk"));
5047 s->gptimer[8] = omap_gp_timer_init(omap_l4ta(s->l4, 28),
5048 s->irq[0][OMAP_INT_24XX_GPTIMER9],
5049 omap_findclk(s, "core_gpt9_clk"),
5050 omap_findclk(s, "core_l4_iclk"));
5051 s->gptimer[9] = omap_gp_timer_init(omap_l4ta(s->l4, 29),
5052 s->irq[0][OMAP_INT_24XX_GPTIMER10],
5053 omap_findclk(s, "core_gpt10_clk"),
5054 omap_findclk(s, "core_l4_iclk"));
5055 s->gptimer[10] = omap_gp_timer_init(omap_l4ta(s->l4, 30),
5056 s->irq[0][OMAP_INT_24XX_GPTIMER11],
5057 omap_findclk(s, "core_gpt11_clk"),
5058 omap_findclk(s, "core_l4_iclk"));
5059 s->gptimer[11] = omap_gp_timer_init(omap_l4ta(s->l4, 31),
5060 s->irq[0][OMAP_INT_24XX_GPTIMER12],
5061 omap_findclk(s, "core_gpt12_clk"),
5062 omap_findclk(s, "core_l4_iclk"));
5064 omap_tap_init(omap_l4ta(s->l4, 2), s);
5066 omap_synctimer_init(omap_l4tao(s->l4, 2), s,
5067 omap_findclk(s, "clk32-kHz"),
5068 omap_findclk(s, "core_l4_iclk"));
5070 s->i2c[0] = omap2_i2c_init(omap_l4tao(s->l4, 5),
5071 s->irq[0][OMAP_INT_24XX_I2C1_IRQ],
5072 &s->drq[OMAP24XX_DMA_I2C1_TX],
5073 omap_findclk(s, "i2c1.fclk"),
5074 omap_findclk(s, "i2c1.iclk"));
5075 s->i2c[1] = omap2_i2c_init(omap_l4tao(s->l4, 6),
5076 s->irq[0][OMAP_INT_24XX_I2C2_IRQ],
5077 &s->drq[OMAP24XX_DMA_I2C2_TX],
5078 omap_findclk(s, "i2c2.fclk"),
5079 omap_findclk(s, "i2c2.iclk"));
5081 gpio_clks[0] = omap_findclk(s, "gpio1_dbclk");
5082 gpio_clks[1] = omap_findclk(s, "gpio2_dbclk");
5083 gpio_clks[2] = omap_findclk(s, "gpio3_dbclk");
5084 gpio_clks[3] = omap_findclk(s, "gpio4_dbclk");
5085 s->gpif = omap2_gpio_init(s, omap_l4ta(s->l4, 3),
5086 &s->irq[0][OMAP_INT_24XX_GPIO_BANK1],
5087 gpio_clks, omap_findclk(s, "gpio_iclk"), 4);
5089 s->sdrc = omap_sdrc_init(0x68009000);
5090 s->gpmc = omap_gpmc_init(s, 0x6800a000, s->irq[0][OMAP_INT_24XX_GPMC_IRQ]);
5092 sdindex = drive_get_index(IF_SD, 0, 0);
5093 if (sdindex == -1) {
5094 fprintf(stderr, "qemu: missing SecureDigital device\n");
5097 s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9), drives_table[sdindex].bdrv,
5098 s->irq[0][OMAP_INT_24XX_MMC_IRQ],
5099 &s->drq[OMAP24XX_DMA_MMC1_TX],
5100 omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk"));
5102 s->mcspi[0] = omap_mcspi_init(omap_l4ta(s->l4, 35), 4,
5103 s->irq[0][OMAP_INT_24XX_MCSPI1_IRQ],
5104 &s->drq[OMAP24XX_DMA_SPI1_TX0],
5105 omap_findclk(s, "spi1_fclk"),
5106 omap_findclk(s, "spi1_iclk"));
5107 s->mcspi[1] = omap_mcspi_init(omap_l4ta(s->l4, 36), 2,
5108 s->irq[0][OMAP_INT_24XX_MCSPI2_IRQ],
5109 &s->drq[OMAP24XX_DMA_SPI2_TX0],
5110 omap_findclk(s, "spi2_fclk"),
5111 omap_findclk(s, "spi2_iclk"));
5113 s->dss = omap_dss_init(s, omap_l4ta(s->l4, 10),
5114 /* XXX wire M_IRQ_25, D_L2_IRQ_30 and I_IRQ_13 together */
5115 s->irq[0][OMAP_INT_24XX_DSS_IRQ], s->drq[OMAP24XX_DMA_DSS],
5116 omap_findclk(s, "dss_clk1"), omap_findclk(s, "dss_clk2"),
5117 omap_findclk(s, "dss_54m_clk"),
5118 omap_findclk(s, "dss_l3_iclk"),
5119 omap_findclk(s, "dss_l4_iclk"));
5121 omap_sti_init(omap_l4ta(s->l4, 18), 0x54000000,
5122 s->irq[0][OMAP_INT_24XX_STI], omap_findclk(s, "emul_ck"),
5123 serial_hds[0] && serial_hds[1] && serial_hds[2] ?
5126 s->eac = omap_eac_init(omap_l4ta(s->l4, 32),
5127 s->irq[0][OMAP_INT_24XX_EAC_IRQ],
5128 /* Ten consecutive lines */
5129 &s->drq[OMAP24XX_DMA_EAC_AC_RD],
5130 omap_findclk(s, "func_96m_clk"),
5131 omap_findclk(s, "core_l4_iclk"));
5133 /* All register mappings (includin those not currenlty implemented):
5134 * SystemControlMod 48000000 - 48000fff
5135 * SystemControlL4 48001000 - 48001fff
5136 * 32kHz Timer Mod 48004000 - 48004fff
5137 * 32kHz Timer L4 48005000 - 48005fff
5138 * PRCM ModA 48008000 - 480087ff
5139 * PRCM ModB 48008800 - 48008fff
5140 * PRCM L4 48009000 - 48009fff
5141 * TEST-BCM Mod 48012000 - 48012fff
5142 * TEST-BCM L4 48013000 - 48013fff
5143 * TEST-TAP Mod 48014000 - 48014fff
5144 * TEST-TAP L4 48015000 - 48015fff
5145 * GPIO1 Mod 48018000 - 48018fff
5146 * GPIO Top 48019000 - 48019fff
5147 * GPIO2 Mod 4801a000 - 4801afff
5148 * GPIO L4 4801b000 - 4801bfff
5149 * GPIO3 Mod 4801c000 - 4801cfff
5150 * GPIO4 Mod 4801e000 - 4801efff
5151 * WDTIMER1 Mod 48020000 - 48010fff
5152 * WDTIMER Top 48021000 - 48011fff
5153 * WDTIMER2 Mod 48022000 - 48012fff
5154 * WDTIMER L4 48023000 - 48013fff
5155 * WDTIMER3 Mod 48024000 - 48014fff
5156 * WDTIMER3 L4 48025000 - 48015fff
5157 * WDTIMER4 Mod 48026000 - 48016fff
5158 * WDTIMER4 L4 48027000 - 48017fff
5159 * GPTIMER1 Mod 48028000 - 48018fff
5160 * GPTIMER1 L4 48029000 - 48019fff
5161 * GPTIMER2 Mod 4802a000 - 4801afff
5162 * GPTIMER2 L4 4802b000 - 4801bfff
5163 * L4-Config AP 48040000 - 480407ff
5164 * L4-Config IP 48040800 - 48040fff
5165 * L4-Config LA 48041000 - 48041fff
5166 * ARM11ETB Mod 48048000 - 48049fff
5167 * ARM11ETB L4 4804a000 - 4804afff
5168 * DISPLAY Top 48050000 - 480503ff
5169 * DISPLAY DISPC 48050400 - 480507ff
5170 * DISPLAY RFBI 48050800 - 48050bff
5171 * DISPLAY VENC 48050c00 - 48050fff
5172 * DISPLAY L4 48051000 - 48051fff
5173 * CAMERA Top 48052000 - 480523ff
5174 * CAMERA core 48052400 - 480527ff
5175 * CAMERA DMA 48052800 - 48052bff
5176 * CAMERA MMU 48052c00 - 48052fff
5177 * CAMERA L4 48053000 - 48053fff
5178 * SDMA Mod 48056000 - 48056fff
5179 * SDMA L4 48057000 - 48057fff
5180 * SSI Top 48058000 - 48058fff
5181 * SSI GDD 48059000 - 48059fff
5182 * SSI Port1 4805a000 - 4805afff
5183 * SSI Port2 4805b000 - 4805bfff
5184 * SSI L4 4805c000 - 4805cfff
5185 * USB Mod 4805e000 - 480fefff
5186 * USB L4 4805f000 - 480fffff
5187 * WIN_TRACER1 Mod 48060000 - 48060fff
5188 * WIN_TRACER1 L4 48061000 - 48061fff
5189 * WIN_TRACER2 Mod 48062000 - 48062fff
5190 * WIN_TRACER2 L4 48063000 - 48063fff
5191 * WIN_TRACER3 Mod 48064000 - 48064fff
5192 * WIN_TRACER3 L4 48065000 - 48065fff
5193 * WIN_TRACER4 Top 48066000 - 480660ff
5194 * WIN_TRACER4 ETT 48066100 - 480661ff
5195 * WIN_TRACER4 WT 48066200 - 480662ff
5196 * WIN_TRACER4 L4 48067000 - 48067fff
5197 * XTI Mod 48068000 - 48068fff
5198 * XTI L4 48069000 - 48069fff
5199 * UART1 Mod 4806a000 - 4806afff
5200 * UART1 L4 4806b000 - 4806bfff
5201 * UART2 Mod 4806c000 - 4806cfff
5202 * UART2 L4 4806d000 - 4806dfff
5203 * UART3 Mod 4806e000 - 4806efff
5204 * UART3 L4 4806f000 - 4806ffff
5205 * I2C1 Mod 48070000 - 48070fff
5206 * I2C1 L4 48071000 - 48071fff
5207 * I2C2 Mod 48072000 - 48072fff
5208 * I2C2 L4 48073000 - 48073fff
5209 * McBSP1 Mod 48074000 - 48074fff
5210 * McBSP1 L4 48075000 - 48075fff
5211 * McBSP2 Mod 48076000 - 48076fff
5212 * McBSP2 L4 48077000 - 48077fff
5213 * GPTIMER3 Mod 48078000 - 48078fff
5214 * GPTIMER3 L4 48079000 - 48079fff
5215 * GPTIMER4 Mod 4807a000 - 4807afff
5216 * GPTIMER4 L4 4807b000 - 4807bfff
5217 * GPTIMER5 Mod 4807c000 - 4807cfff
5218 * GPTIMER5 L4 4807d000 - 4807dfff
5219 * GPTIMER6 Mod 4807e000 - 4807efff
5220 * GPTIMER6 L4 4807f000 - 4807ffff
5221 * GPTIMER7 Mod 48080000 - 48080fff
5222 * GPTIMER7 L4 48081000 - 48081fff
5223 * GPTIMER8 Mod 48082000 - 48082fff
5224 * GPTIMER8 L4 48083000 - 48083fff
5225 * GPTIMER9 Mod 48084000 - 48084fff
5226 * GPTIMER9 L4 48085000 - 48085fff
5227 * GPTIMER10 Mod 48086000 - 48086fff
5228 * GPTIMER10 L4 48087000 - 48087fff
5229 * GPTIMER11 Mod 48088000 - 48088fff
5230 * GPTIMER11 L4 48089000 - 48089fff
5231 * GPTIMER12 Mod 4808a000 - 4808afff
5232 * GPTIMER12 L4 4808b000 - 4808bfff
5233 * EAC Mod 48090000 - 48090fff
5234 * EAC L4 48091000 - 48091fff
5235 * FAC Mod 48092000 - 48092fff
5236 * FAC L4 48093000 - 48093fff
5237 * MAILBOX Mod 48094000 - 48094fff
5238 * MAILBOX L4 48095000 - 48095fff
5239 * SPI1 Mod 48098000 - 48098fff
5240 * SPI1 L4 48099000 - 48099fff
5241 * SPI2 Mod 4809a000 - 4809afff
5242 * SPI2 L4 4809b000 - 4809bfff
5243 * MMC/SDIO Mod 4809c000 - 4809cfff
5244 * MMC/SDIO L4 4809d000 - 4809dfff
5245 * MS_PRO Mod 4809e000 - 4809efff
5246 * MS_PRO L4 4809f000 - 4809ffff
5247 * RNG Mod 480a0000 - 480a0fff
5248 * RNG L4 480a1000 - 480a1fff
5249 * DES3DES Mod 480a2000 - 480a2fff
5250 * DES3DES L4 480a3000 - 480a3fff
5251 * SHA1MD5 Mod 480a4000 - 480a4fff
5252 * SHA1MD5 L4 480a5000 - 480a5fff
5253 * AES Mod 480a6000 - 480a6fff
5254 * AES L4 480a7000 - 480a7fff
5255 * PKA Mod 480a8000 - 480a9fff
5256 * PKA L4 480aa000 - 480aafff
5257 * MG Mod 480b0000 - 480b0fff
5258 * MG L4 480b1000 - 480b1fff
5259 * HDQ/1-wire Mod 480b2000 - 480b2fff
5260 * HDQ/1-wire L4 480b3000 - 480b3fff
5261 * MPU interrupt 480fe000 - 480fefff
5262 * STI channel base 54000000 - 5400ffff
5263 * IVA RAM 5c000000 - 5c01ffff
5264 * IVA ROM 5c020000 - 5c027fff
5265 * IMG_BUF_A 5c040000 - 5c040fff
5266 * IMG_BUF_B 5c042000 - 5c042fff
5267 * VLCDS 5c048000 - 5c0487ff
5268 * IMX_COEF 5c049000 - 5c04afff
5269 * IMX_CMD 5c051000 - 5c051fff
5270 * VLCDQ 5c053000 - 5c0533ff
5271 * VLCDH 5c054000 - 5c054fff
5272 * SEQ_CMD 5c055000 - 5c055fff
5273 * IMX_REG 5c056000 - 5c0560ff
5274 * VLCD_REG 5c056100 - 5c0561ff
5275 * SEQ_REG 5c056200 - 5c0562ff
5276 * IMG_BUF_REG 5c056300 - 5c0563ff
5277 * SEQIRQ_REG 5c056400 - 5c0564ff
5278 * OCP_REG 5c060000 - 5c060fff
5279 * SYSC_REG 5c070000 - 5c070fff
5280 * MMU_REG 5d000000 - 5d000fff
5281 * sDMA R 68000400 - 680005ff
5282 * sDMA W 68000600 - 680007ff
5283 * Display Control 68000800 - 680009ff
5284 * DSP subsystem 68000a00 - 68000bff
5285 * MPU subsystem 68000c00 - 68000dff
5286 * IVA subsystem 68001000 - 680011ff
5287 * USB 68001200 - 680013ff
5288 * Camera 68001400 - 680015ff
5289 * VLYNQ (firewall) 68001800 - 68001bff
5290 * VLYNQ 68001e00 - 68001fff
5291 * SSI 68002000 - 680021ff
5292 * L4 68002400 - 680025ff
5293 * DSP (firewall) 68002800 - 68002bff
5294 * DSP subsystem 68002e00 - 68002fff
5295 * IVA (firewall) 68003000 - 680033ff
5296 * IVA 68003600 - 680037ff
5297 * GFX 68003a00 - 68003bff
5298 * CMDWR emulation 68003c00 - 68003dff
5299 * SMS 68004000 - 680041ff
5300 * OCM 68004200 - 680043ff
5301 * GPMC 68004400 - 680045ff
5302 * RAM (firewall) 68005000 - 680053ff
5303 * RAM (err login) 68005400 - 680057ff
5304 * ROM (firewall) 68005800 - 68005bff
5305 * ROM (err login) 68005c00 - 68005fff
5306 * GPMC (firewall) 68006000 - 680063ff
5307 * GPMC (err login) 68006400 - 680067ff
5308 * SMS (err login) 68006c00 - 68006fff
5309 * SMS registers 68008000 - 68008fff
5310 * SDRC registers 68009000 - 68009fff
5311 * GPMC registers 6800a000 6800afff
5314 qemu_register_reset(omap2_mpu_reset, s);