Make audio violate POSIX less
[qemu/mini2440.git] / hw / omap2.c
blob58debaf55296b4aa309d336e4b69e9e7a4eecf05
1 /*
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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
22 #include "hw.h"
23 #include "arm-misc.h"
24 #include "omap.h"
25 #include "sysemu.h"
26 #include "qemu-timer.h"
27 #include "qemu-char.h"
28 #include "flash.h"
29 #include "soc_dma.h"
30 #include "audio/audio.h"
32 /* GP timers */
33 struct omap_gp_timer_s {
34 qemu_irq irq;
35 qemu_irq wkup;
36 qemu_irq in;
37 qemu_irq out;
38 omap_clk clk;
39 QEMUTimer *timer;
40 QEMUTimer *match;
41 struct omap_target_agent_s *ta;
43 int in_val;
44 int out_val;
45 int64_t time;
46 int64_t rate;
47 int64_t ticks_per_sec;
49 int16_t config;
50 int status;
51 int it_ena;
52 int wu_ena;
53 int enable;
54 int inout;
55 int capt2;
56 int pt;
57 enum {
58 gpt_trigger_none, gpt_trigger_overflow, gpt_trigger_both
59 } trigger;
60 enum {
61 gpt_capture_none, gpt_capture_rising,
62 gpt_capture_falling, gpt_capture_both
63 } capture;
64 int scpwm;
65 int ce;
66 int pre;
67 int ptv;
68 int ar;
69 int st;
70 int posted;
71 uint32_t val;
72 uint32_t load_val;
73 uint32_t capture_val[2];
74 uint32_t match_val;
75 int capt_num;
77 uint16_t writeh; /* LSB */
78 uint16_t readh; /* MSB */
81 #define GPT_TCAR_IT (1 << 2)
82 #define GPT_OVF_IT (1 << 1)
83 #define GPT_MAT_IT (1 << 0)
85 static inline void omap_gp_timer_intr(struct omap_gp_timer_s *timer, int it)
87 if (timer->it_ena & it) {
88 if (!timer->status)
89 qemu_irq_raise(timer->irq);
91 timer->status |= it;
92 /* Or are the status bits set even when masked?
93 * i.e. is masking applied before or after the status register? */
96 if (timer->wu_ena & it)
97 qemu_irq_pulse(timer->wkup);
100 static inline void omap_gp_timer_out(struct omap_gp_timer_s *timer, int level)
102 if (!timer->inout && timer->out_val != level) {
103 timer->out_val = level;
104 qemu_set_irq(timer->out, level);
108 static inline uint32_t omap_gp_timer_read(struct omap_gp_timer_s *timer)
110 uint64_t distance;
112 if (timer->st && timer->rate) {
113 distance = qemu_get_clock(vm_clock) - timer->time;
114 distance = muldiv64(distance, timer->rate, timer->ticks_per_sec);
116 if (distance >= 0xffffffff - timer->val)
117 return 0xffffffff;
118 else
119 return timer->val + distance;
120 } else
121 return timer->val;
124 static inline void omap_gp_timer_sync(struct omap_gp_timer_s *timer)
126 if (timer->st) {
127 timer->val = omap_gp_timer_read(timer);
128 timer->time = qemu_get_clock(vm_clock);
132 static inline void omap_gp_timer_update(struct omap_gp_timer_s *timer)
134 int64_t expires, matches;
136 if (timer->st && timer->rate) {
137 expires = muldiv64(0x100000000ll - timer->val,
138 timer->ticks_per_sec, timer->rate);
139 qemu_mod_timer(timer->timer, timer->time + expires);
141 if (timer->ce && timer->match_val >= timer->val) {
142 matches = muldiv64(timer->match_val - timer->val,
143 timer->ticks_per_sec, timer->rate);
144 qemu_mod_timer(timer->match, timer->time + matches);
145 } else
146 qemu_del_timer(timer->match);
147 } else {
148 qemu_del_timer(timer->timer);
149 qemu_del_timer(timer->match);
150 omap_gp_timer_out(timer, timer->scpwm);
154 static inline void omap_gp_timer_trigger(struct omap_gp_timer_s *timer)
156 if (timer->pt)
157 /* TODO in overflow-and-match mode if the first event to
158 * occur is the match, don't toggle. */
159 omap_gp_timer_out(timer, !timer->out_val);
160 else
161 /* TODO inverted pulse on timer->out_val == 1? */
162 qemu_irq_pulse(timer->out);
165 static void omap_gp_timer_tick(void *opaque)
167 struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
169 if (!timer->ar) {
170 timer->st = 0;
171 timer->val = 0;
172 } else {
173 timer->val = timer->load_val;
174 timer->time = qemu_get_clock(vm_clock);
177 if (timer->trigger == gpt_trigger_overflow ||
178 timer->trigger == gpt_trigger_both)
179 omap_gp_timer_trigger(timer);
181 omap_gp_timer_intr(timer, GPT_OVF_IT);
182 omap_gp_timer_update(timer);
185 static void omap_gp_timer_match(void *opaque)
187 struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
189 if (timer->trigger == gpt_trigger_both)
190 omap_gp_timer_trigger(timer);
192 omap_gp_timer_intr(timer, GPT_MAT_IT);
195 static void omap_gp_timer_input(void *opaque, int line, int on)
197 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
198 int trigger;
200 switch (s->capture) {
201 default:
202 case gpt_capture_none:
203 trigger = 0;
204 break;
205 case gpt_capture_rising:
206 trigger = !s->in_val && on;
207 break;
208 case gpt_capture_falling:
209 trigger = s->in_val && !on;
210 break;
211 case gpt_capture_both:
212 trigger = (s->in_val == !on);
213 break;
215 s->in_val = on;
217 if (s->inout && trigger && s->capt_num < 2) {
218 s->capture_val[s->capt_num] = omap_gp_timer_read(s);
220 if (s->capt2 == s->capt_num ++)
221 omap_gp_timer_intr(s, GPT_TCAR_IT);
225 static void omap_gp_timer_clk_update(void *opaque, int line, int on)
227 struct omap_gp_timer_s *timer = (struct omap_gp_timer_s *) opaque;
229 omap_gp_timer_sync(timer);
230 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
231 omap_gp_timer_update(timer);
234 static void omap_gp_timer_clk_setup(struct omap_gp_timer_s *timer)
236 omap_clk_adduser(timer->clk,
237 qemu_allocate_irqs(omap_gp_timer_clk_update, timer, 1)[0]);
238 timer->rate = omap_clk_getrate(timer->clk);
241 static void omap_gp_timer_reset(struct omap_gp_timer_s *s)
243 s->config = 0x000;
244 s->status = 0;
245 s->it_ena = 0;
246 s->wu_ena = 0;
247 s->inout = 0;
248 s->capt2 = 0;
249 s->capt_num = 0;
250 s->pt = 0;
251 s->trigger = gpt_trigger_none;
252 s->capture = gpt_capture_none;
253 s->scpwm = 0;
254 s->ce = 0;
255 s->pre = 0;
256 s->ptv = 0;
257 s->ar = 0;
258 s->st = 0;
259 s->posted = 1;
260 s->val = 0x00000000;
261 s->load_val = 0x00000000;
262 s->capture_val[0] = 0x00000000;
263 s->capture_val[1] = 0x00000000;
264 s->match_val = 0x00000000;
265 omap_gp_timer_update(s);
268 static uint32_t omap_gp_timer_readw(void *opaque, target_phys_addr_t addr)
270 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
272 switch (addr) {
273 case 0x00: /* TIDR */
274 return 0x21;
276 case 0x10: /* TIOCP_CFG */
277 return s->config;
279 case 0x14: /* TISTAT */
280 /* ??? When's this bit reset? */
281 return 1; /* RESETDONE */
283 case 0x18: /* TISR */
284 return s->status;
286 case 0x1c: /* TIER */
287 return s->it_ena;
289 case 0x20: /* TWER */
290 return s->wu_ena;
292 case 0x24: /* TCLR */
293 return (s->inout << 14) |
294 (s->capt2 << 13) |
295 (s->pt << 12) |
296 (s->trigger << 10) |
297 (s->capture << 8) |
298 (s->scpwm << 7) |
299 (s->ce << 6) |
300 (s->pre << 5) |
301 (s->ptv << 2) |
302 (s->ar << 1) |
303 (s->st << 0);
305 case 0x28: /* TCRR */
306 return omap_gp_timer_read(s);
308 case 0x2c: /* TLDR */
309 return s->load_val;
311 case 0x30: /* TTGR */
312 return 0xffffffff;
314 case 0x34: /* TWPS */
315 return 0x00000000; /* No posted writes pending. */
317 case 0x38: /* TMAR */
318 return s->match_val;
320 case 0x3c: /* TCAR1 */
321 return s->capture_val[0];
323 case 0x40: /* TSICR */
324 return s->posted << 2;
326 case 0x44: /* TCAR2 */
327 return s->capture_val[1];
330 OMAP_BAD_REG(addr);
331 return 0;
334 static uint32_t omap_gp_timer_readh(void *opaque, target_phys_addr_t addr)
336 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
337 uint32_t ret;
339 if (addr & 2)
340 return s->readh;
341 else {
342 ret = omap_gp_timer_readw(opaque, addr);
343 s->readh = ret >> 16;
344 return ret & 0xffff;
348 static CPUReadMemoryFunc *omap_gp_timer_readfn[] = {
349 omap_badwidth_read32,
350 omap_gp_timer_readh,
351 omap_gp_timer_readw,
354 static void omap_gp_timer_write(void *opaque, target_phys_addr_t addr,
355 uint32_t value)
357 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
359 switch (addr) {
360 case 0x00: /* TIDR */
361 case 0x14: /* TISTAT */
362 case 0x34: /* TWPS */
363 case 0x3c: /* TCAR1 */
364 case 0x44: /* TCAR2 */
365 OMAP_RO_REG(addr);
366 break;
368 case 0x10: /* TIOCP_CFG */
369 s->config = value & 0x33d;
370 if (((value >> 3) & 3) == 3) /* IDLEMODE */
371 fprintf(stderr, "%s: illegal IDLEMODE value in TIOCP_CFG\n",
372 __FUNCTION__);
373 if (value & 2) /* SOFTRESET */
374 omap_gp_timer_reset(s);
375 break;
377 case 0x18: /* TISR */
378 if (value & GPT_TCAR_IT)
379 s->capt_num = 0;
380 if (s->status && !(s->status &= ~value))
381 qemu_irq_lower(s->irq);
382 break;
384 case 0x1c: /* TIER */
385 s->it_ena = value & 7;
386 break;
388 case 0x20: /* TWER */
389 s->wu_ena = value & 7;
390 break;
392 case 0x24: /* TCLR */
393 omap_gp_timer_sync(s);
394 s->inout = (value >> 14) & 1;
395 s->capt2 = (value >> 13) & 1;
396 s->pt = (value >> 12) & 1;
397 s->trigger = (value >> 10) & 3;
398 if (s->capture == gpt_capture_none &&
399 ((value >> 8) & 3) != gpt_capture_none)
400 s->capt_num = 0;
401 s->capture = (value >> 8) & 3;
402 s->scpwm = (value >> 7) & 1;
403 s->ce = (value >> 6) & 1;
404 s->pre = (value >> 5) & 1;
405 s->ptv = (value >> 2) & 7;
406 s->ar = (value >> 1) & 1;
407 s->st = (value >> 0) & 1;
408 if (s->inout && s->trigger != gpt_trigger_none)
409 fprintf(stderr, "%s: GP timer pin must be an output "
410 "for this trigger mode\n", __FUNCTION__);
411 if (!s->inout && s->capture != gpt_capture_none)
412 fprintf(stderr, "%s: GP timer pin must be an input "
413 "for this capture mode\n", __FUNCTION__);
414 if (s->trigger == gpt_trigger_none)
415 omap_gp_timer_out(s, s->scpwm);
416 /* TODO: make sure this doesn't overflow 32-bits */
417 s->ticks_per_sec = ticks_per_sec << (s->pre ? s->ptv + 1 : 0);
418 omap_gp_timer_update(s);
419 break;
421 case 0x28: /* TCRR */
422 s->time = qemu_get_clock(vm_clock);
423 s->val = value;
424 omap_gp_timer_update(s);
425 break;
427 case 0x2c: /* TLDR */
428 s->load_val = value;
429 break;
431 case 0x30: /* TTGR */
432 s->time = qemu_get_clock(vm_clock);
433 s->val = s->load_val;
434 omap_gp_timer_update(s);
435 break;
437 case 0x38: /* TMAR */
438 omap_gp_timer_sync(s);
439 s->match_val = value;
440 omap_gp_timer_update(s);
441 break;
443 case 0x40: /* TSICR */
444 s->posted = (value >> 2) & 1;
445 if (value & 2) /* How much exactly are we supposed to reset? */
446 omap_gp_timer_reset(s);
447 break;
449 default:
450 OMAP_BAD_REG(addr);
454 static void omap_gp_timer_writeh(void *opaque, target_phys_addr_t addr,
455 uint32_t value)
457 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) opaque;
459 if (addr & 2)
460 return omap_gp_timer_write(opaque, addr, (value << 16) | s->writeh);
461 else
462 s->writeh = (uint16_t) value;
465 static CPUWriteMemoryFunc *omap_gp_timer_writefn[] = {
466 omap_badwidth_write32,
467 omap_gp_timer_writeh,
468 omap_gp_timer_write,
471 struct omap_gp_timer_s *omap_gp_timer_init(struct omap_target_agent_s *ta,
472 qemu_irq irq, omap_clk fclk, omap_clk iclk)
474 int iomemtype;
475 struct omap_gp_timer_s *s = (struct omap_gp_timer_s *)
476 qemu_mallocz(sizeof(struct omap_gp_timer_s));
478 s->ta = ta;
479 s->irq = irq;
480 s->clk = fclk;
481 s->timer = qemu_new_timer(vm_clock, omap_gp_timer_tick, s);
482 s->match = qemu_new_timer(vm_clock, omap_gp_timer_match, s);
483 s->in = qemu_allocate_irqs(omap_gp_timer_input, s, 1)[0];
484 omap_gp_timer_reset(s);
485 omap_gp_timer_clk_setup(s);
487 iomemtype = l4_register_io_memory(0, omap_gp_timer_readfn,
488 omap_gp_timer_writefn, s);
489 omap_l4_attach(ta, 0, iomemtype);
491 return s;
494 /* 32-kHz Sync Timer of the OMAP2 */
495 static uint32_t omap_synctimer_read(struct omap_synctimer_s *s) {
496 return muldiv64(qemu_get_clock(vm_clock), 0x8000, ticks_per_sec);
499 static void omap_synctimer_reset(struct omap_synctimer_s *s)
501 s->val = omap_synctimer_read(s);
504 static uint32_t omap_synctimer_readw(void *opaque, target_phys_addr_t addr)
506 struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
508 switch (addr) {
509 case 0x00: /* 32KSYNCNT_REV */
510 return 0x21;
512 case 0x10: /* CR */
513 return omap_synctimer_read(s) - s->val;
516 OMAP_BAD_REG(addr);
517 return 0;
520 static uint32_t omap_synctimer_readh(void *opaque, target_phys_addr_t addr)
522 struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
523 uint32_t ret;
525 if (addr & 2)
526 return s->readh;
527 else {
528 ret = omap_synctimer_readw(opaque, addr);
529 s->readh = ret >> 16;
530 return ret & 0xffff;
534 static CPUReadMemoryFunc *omap_synctimer_readfn[] = {
535 omap_badwidth_read32,
536 omap_synctimer_readh,
537 omap_synctimer_readw,
540 static void omap_synctimer_write(void *opaque, target_phys_addr_t addr,
541 uint32_t value)
543 OMAP_BAD_REG(addr);
546 static CPUWriteMemoryFunc *omap_synctimer_writefn[] = {
547 omap_badwidth_write32,
548 omap_synctimer_write,
549 omap_synctimer_write,
552 void omap_synctimer_init(struct omap_target_agent_s *ta,
553 struct omap_mpu_state_s *mpu, omap_clk fclk, omap_clk iclk)
555 struct omap_synctimer_s *s = &mpu->synctimer;
557 omap_synctimer_reset(s);
558 omap_l4_attach(ta, 0, l4_register_io_memory(0,
559 omap_synctimer_readfn, omap_synctimer_writefn, s));
562 /* General-Purpose Interface of OMAP2 */
563 struct omap2_gpio_s {
564 qemu_irq irq[2];
565 qemu_irq wkup;
566 qemu_irq *in;
567 qemu_irq handler[32];
569 uint8_t config[2];
570 uint32_t inputs;
571 uint32_t outputs;
572 uint32_t dir;
573 uint32_t level[2];
574 uint32_t edge[2];
575 uint32_t mask[2];
576 uint32_t wumask;
577 uint32_t ints[2];
578 uint32_t debounce;
579 uint8_t delay;
582 static inline void omap_gpio_module_int_update(struct omap2_gpio_s *s,
583 int line)
585 qemu_set_irq(s->irq[line], s->ints[line] & s->mask[line]);
588 static void omap_gpio_module_wake(struct omap2_gpio_s *s, int line)
590 if (!(s->config[0] & (1 << 2))) /* ENAWAKEUP */
591 return;
592 if (!(s->config[0] & (3 << 3))) /* Force Idle */
593 return;
594 if (!(s->wumask & (1 << line)))
595 return;
597 qemu_irq_raise(s->wkup);
600 static inline void omap_gpio_module_out_update(struct omap2_gpio_s *s,
601 uint32_t diff)
603 int ln;
605 s->outputs ^= diff;
606 diff &= ~s->dir;
607 while ((ln = ffs(diff))) {
608 ln --;
609 qemu_set_irq(s->handler[ln], (s->outputs >> ln) & 1);
610 diff &= ~(1 << ln);
614 static void omap_gpio_module_level_update(struct omap2_gpio_s *s, int line)
616 s->ints[line] |= s->dir &
617 ((s->inputs & s->level[1]) | (~s->inputs & s->level[0]));
618 omap_gpio_module_int_update(s, line);
621 static inline void omap_gpio_module_int(struct omap2_gpio_s *s, int line)
623 s->ints[0] |= 1 << line;
624 omap_gpio_module_int_update(s, 0);
625 s->ints[1] |= 1 << line;
626 omap_gpio_module_int_update(s, 1);
627 omap_gpio_module_wake(s, line);
630 static void omap_gpio_module_set(void *opaque, int line, int level)
632 struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
634 if (level) {
635 if (s->dir & (1 << line) & ((~s->inputs & s->edge[0]) | s->level[1]))
636 omap_gpio_module_int(s, line);
637 s->inputs |= 1 << line;
638 } else {
639 if (s->dir & (1 << line) & ((s->inputs & s->edge[1]) | s->level[0]))
640 omap_gpio_module_int(s, line);
641 s->inputs &= ~(1 << line);
645 static void omap_gpio_module_reset(struct omap2_gpio_s *s)
647 s->config[0] = 0;
648 s->config[1] = 2;
649 s->ints[0] = 0;
650 s->ints[1] = 0;
651 s->mask[0] = 0;
652 s->mask[1] = 0;
653 s->wumask = 0;
654 s->dir = ~0;
655 s->level[0] = 0;
656 s->level[1] = 0;
657 s->edge[0] = 0;
658 s->edge[1] = 0;
659 s->debounce = 0;
660 s->delay = 0;
663 static uint32_t omap_gpio_module_read(void *opaque, target_phys_addr_t addr)
665 struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
667 switch (addr) {
668 case 0x00: /* GPIO_REVISION */
669 return 0x18;
671 case 0x10: /* GPIO_SYSCONFIG */
672 return s->config[0];
674 case 0x14: /* GPIO_SYSSTATUS */
675 return 0x01;
677 case 0x18: /* GPIO_IRQSTATUS1 */
678 return s->ints[0];
680 case 0x1c: /* GPIO_IRQENABLE1 */
681 case 0x60: /* GPIO_CLEARIRQENABLE1 */
682 case 0x64: /* GPIO_SETIRQENABLE1 */
683 return s->mask[0];
685 case 0x20: /* GPIO_WAKEUPENABLE */
686 case 0x80: /* GPIO_CLEARWKUENA */
687 case 0x84: /* GPIO_SETWKUENA */
688 return s->wumask;
690 case 0x28: /* GPIO_IRQSTATUS2 */
691 return s->ints[1];
693 case 0x2c: /* GPIO_IRQENABLE2 */
694 case 0x70: /* GPIO_CLEARIRQENABLE2 */
695 case 0x74: /* GPIO_SETIREQNEABLE2 */
696 return s->mask[1];
698 case 0x30: /* GPIO_CTRL */
699 return s->config[1];
701 case 0x34: /* GPIO_OE */
702 return s->dir;
704 case 0x38: /* GPIO_DATAIN */
705 return s->inputs;
707 case 0x3c: /* GPIO_DATAOUT */
708 case 0x90: /* GPIO_CLEARDATAOUT */
709 case 0x94: /* GPIO_SETDATAOUT */
710 return s->outputs;
712 case 0x40: /* GPIO_LEVELDETECT0 */
713 return s->level[0];
715 case 0x44: /* GPIO_LEVELDETECT1 */
716 return s->level[1];
718 case 0x48: /* GPIO_RISINGDETECT */
719 return s->edge[0];
721 case 0x4c: /* GPIO_FALLINGDETECT */
722 return s->edge[1];
724 case 0x50: /* GPIO_DEBOUNCENABLE */
725 return s->debounce;
727 case 0x54: /* GPIO_DEBOUNCINGTIME */
728 return s->delay;
731 OMAP_BAD_REG(addr);
732 return 0;
735 static void omap_gpio_module_write(void *opaque, target_phys_addr_t addr,
736 uint32_t value)
738 struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque;
739 uint32_t diff;
740 int ln;
742 switch (addr) {
743 case 0x00: /* GPIO_REVISION */
744 case 0x14: /* GPIO_SYSSTATUS */
745 case 0x38: /* GPIO_DATAIN */
746 OMAP_RO_REG(addr);
747 break;
749 case 0x10: /* GPIO_SYSCONFIG */
750 if (((value >> 3) & 3) == 3)
751 fprintf(stderr, "%s: bad IDLEMODE value\n", __FUNCTION__);
752 if (value & 2)
753 omap_gpio_module_reset(s);
754 s->config[0] = value & 0x1d;
755 break;
757 case 0x18: /* GPIO_IRQSTATUS1 */
758 if (s->ints[0] & value) {
759 s->ints[0] &= ~value;
760 omap_gpio_module_level_update(s, 0);
762 break;
764 case 0x1c: /* GPIO_IRQENABLE1 */
765 s->mask[0] = value;
766 omap_gpio_module_int_update(s, 0);
767 break;
769 case 0x20: /* GPIO_WAKEUPENABLE */
770 s->wumask = value;
771 break;
773 case 0x28: /* GPIO_IRQSTATUS2 */
774 if (s->ints[1] & value) {
775 s->ints[1] &= ~value;
776 omap_gpio_module_level_update(s, 1);
778 break;
780 case 0x2c: /* GPIO_IRQENABLE2 */
781 s->mask[1] = value;
782 omap_gpio_module_int_update(s, 1);
783 break;
785 case 0x30: /* GPIO_CTRL */
786 s->config[1] = value & 7;
787 break;
789 case 0x34: /* GPIO_OE */
790 diff = s->outputs & (s->dir ^ value);
791 s->dir = value;
793 value = s->outputs & ~s->dir;
794 while ((ln = ffs(diff))) {
795 diff &= ~(1 <<-- ln);
796 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
799 omap_gpio_module_level_update(s, 0);
800 omap_gpio_module_level_update(s, 1);
801 break;
803 case 0x3c: /* GPIO_DATAOUT */
804 omap_gpio_module_out_update(s, s->outputs ^ value);
805 break;
807 case 0x40: /* GPIO_LEVELDETECT0 */
808 s->level[0] = value;
809 omap_gpio_module_level_update(s, 0);
810 omap_gpio_module_level_update(s, 1);
811 break;
813 case 0x44: /* GPIO_LEVELDETECT1 */
814 s->level[1] = value;
815 omap_gpio_module_level_update(s, 0);
816 omap_gpio_module_level_update(s, 1);
817 break;
819 case 0x48: /* GPIO_RISINGDETECT */
820 s->edge[0] = value;
821 break;
823 case 0x4c: /* GPIO_FALLINGDETECT */
824 s->edge[1] = value;
825 break;
827 case 0x50: /* GPIO_DEBOUNCENABLE */
828 s->debounce = value;
829 break;
831 case 0x54: /* GPIO_DEBOUNCINGTIME */
832 s->delay = value;
833 break;
835 case 0x60: /* GPIO_CLEARIRQENABLE1 */
836 s->mask[0] &= ~value;
837 omap_gpio_module_int_update(s, 0);
838 break;
840 case 0x64: /* GPIO_SETIRQENABLE1 */
841 s->mask[0] |= value;
842 omap_gpio_module_int_update(s, 0);
843 break;
845 case 0x70: /* GPIO_CLEARIRQENABLE2 */
846 s->mask[1] &= ~value;
847 omap_gpio_module_int_update(s, 1);
848 break;
850 case 0x74: /* GPIO_SETIREQNEABLE2 */
851 s->mask[1] |= value;
852 omap_gpio_module_int_update(s, 1);
853 break;
855 case 0x80: /* GPIO_CLEARWKUENA */
856 s->wumask &= ~value;
857 break;
859 case 0x84: /* GPIO_SETWKUENA */
860 s->wumask |= value;
861 break;
863 case 0x90: /* GPIO_CLEARDATAOUT */
864 omap_gpio_module_out_update(s, s->outputs & value);
865 break;
867 case 0x94: /* GPIO_SETDATAOUT */
868 omap_gpio_module_out_update(s, ~s->outputs & value);
869 break;
871 default:
872 OMAP_BAD_REG(addr);
873 return;
877 static uint32_t omap_gpio_module_readp(void *opaque, target_phys_addr_t addr)
879 return omap_gpio_module_readp(opaque, addr) >> ((addr & 3) << 3);
882 static void omap_gpio_module_writep(void *opaque, target_phys_addr_t addr,
883 uint32_t value)
885 uint32_t cur = 0;
886 uint32_t mask = 0xffff;
888 switch (addr & ~3) {
889 case 0x00: /* GPIO_REVISION */
890 case 0x14: /* GPIO_SYSSTATUS */
891 case 0x38: /* GPIO_DATAIN */
892 OMAP_RO_REG(addr);
893 break;
895 case 0x10: /* GPIO_SYSCONFIG */
896 case 0x1c: /* GPIO_IRQENABLE1 */
897 case 0x20: /* GPIO_WAKEUPENABLE */
898 case 0x2c: /* GPIO_IRQENABLE2 */
899 case 0x30: /* GPIO_CTRL */
900 case 0x34: /* GPIO_OE */
901 case 0x3c: /* GPIO_DATAOUT */
902 case 0x40: /* GPIO_LEVELDETECT0 */
903 case 0x44: /* GPIO_LEVELDETECT1 */
904 case 0x48: /* GPIO_RISINGDETECT */
905 case 0x4c: /* GPIO_FALLINGDETECT */
906 case 0x50: /* GPIO_DEBOUNCENABLE */
907 case 0x54: /* GPIO_DEBOUNCINGTIME */
908 cur = omap_gpio_module_read(opaque, addr & ~3) &
909 ~(mask << ((addr & 3) << 3));
911 /* Fall through. */
912 case 0x18: /* GPIO_IRQSTATUS1 */
913 case 0x28: /* GPIO_IRQSTATUS2 */
914 case 0x60: /* GPIO_CLEARIRQENABLE1 */
915 case 0x64: /* GPIO_SETIRQENABLE1 */
916 case 0x70: /* GPIO_CLEARIRQENABLE2 */
917 case 0x74: /* GPIO_SETIREQNEABLE2 */
918 case 0x80: /* GPIO_CLEARWKUENA */
919 case 0x84: /* GPIO_SETWKUENA */
920 case 0x90: /* GPIO_CLEARDATAOUT */
921 case 0x94: /* GPIO_SETDATAOUT */
922 value <<= (addr & 3) << 3;
923 omap_gpio_module_write(opaque, addr, cur | value);
924 break;
926 default:
927 OMAP_BAD_REG(addr);
928 return;
932 static CPUReadMemoryFunc *omap_gpio_module_readfn[] = {
933 omap_gpio_module_readp,
934 omap_gpio_module_readp,
935 omap_gpio_module_read,
938 static CPUWriteMemoryFunc *omap_gpio_module_writefn[] = {
939 omap_gpio_module_writep,
940 omap_gpio_module_writep,
941 omap_gpio_module_write,
944 static void omap_gpio_module_init(struct omap2_gpio_s *s,
945 struct omap_target_agent_s *ta, int region,
946 qemu_irq mpu, qemu_irq dsp, qemu_irq wkup,
947 omap_clk fclk, omap_clk iclk)
949 int iomemtype;
951 s->irq[0] = mpu;
952 s->irq[1] = dsp;
953 s->wkup = wkup;
954 s->in = qemu_allocate_irqs(omap_gpio_module_set, s, 32);
956 iomemtype = l4_register_io_memory(0, omap_gpio_module_readfn,
957 omap_gpio_module_writefn, s);
958 omap_l4_attach(ta, region, iomemtype);
961 struct omap_gpif_s {
962 struct omap2_gpio_s module[5];
963 int modules;
965 int autoidle;
966 int gpo;
969 static void omap_gpif_reset(struct omap_gpif_s *s)
971 int i;
973 for (i = 0; i < s->modules; i ++)
974 omap_gpio_module_reset(s->module + i);
976 s->autoidle = 0;
977 s->gpo = 0;
980 static uint32_t omap_gpif_top_read(void *opaque, target_phys_addr_t addr)
982 struct omap_gpif_s *s = (struct omap_gpif_s *) opaque;
984 switch (addr) {
985 case 0x00: /* IPGENERICOCPSPL_REVISION */
986 return 0x18;
988 case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */
989 return s->autoidle;
991 case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */
992 return 0x01;
994 case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */
995 return 0x00;
997 case 0x40: /* IPGENERICOCPSPL_GPO */
998 return s->gpo;
1000 case 0x50: /* IPGENERICOCPSPL_GPI */
1001 return 0x00;
1004 OMAP_BAD_REG(addr);
1005 return 0;
1008 static void omap_gpif_top_write(void *opaque, target_phys_addr_t addr,
1009 uint32_t value)
1011 struct omap_gpif_s *s = (struct omap_gpif_s *) opaque;
1013 switch (addr) {
1014 case 0x00: /* IPGENERICOCPSPL_REVISION */
1015 case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */
1016 case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */
1017 case 0x50: /* IPGENERICOCPSPL_GPI */
1018 OMAP_RO_REG(addr);
1019 break;
1021 case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */
1022 if (value & (1 << 1)) /* SOFTRESET */
1023 omap_gpif_reset(s);
1024 s->autoidle = value & 1;
1025 break;
1027 case 0x40: /* IPGENERICOCPSPL_GPO */
1028 s->gpo = value & 1;
1029 break;
1031 default:
1032 OMAP_BAD_REG(addr);
1033 return;
1037 static CPUReadMemoryFunc *omap_gpif_top_readfn[] = {
1038 omap_gpif_top_read,
1039 omap_gpif_top_read,
1040 omap_gpif_top_read,
1043 static CPUWriteMemoryFunc *omap_gpif_top_writefn[] = {
1044 omap_gpif_top_write,
1045 omap_gpif_top_write,
1046 omap_gpif_top_write,
1049 struct omap_gpif_s *omap2_gpio_init(struct omap_target_agent_s *ta,
1050 qemu_irq *irq, omap_clk *fclk, omap_clk iclk, int modules)
1052 int iomemtype, i;
1053 struct omap_gpif_s *s = (struct omap_gpif_s *)
1054 qemu_mallocz(sizeof(struct omap_gpif_s));
1055 int region[4] = { 0, 2, 4, 5 };
1057 s->modules = modules;
1058 for (i = 0; i < modules; i ++)
1059 omap_gpio_module_init(s->module + i, ta, region[i],
1060 irq[i], 0, 0, fclk[i], iclk);
1062 omap_gpif_reset(s);
1064 iomemtype = l4_register_io_memory(0, omap_gpif_top_readfn,
1065 omap_gpif_top_writefn, s);
1066 omap_l4_attach(ta, 1, iomemtype);
1068 return s;
1071 qemu_irq *omap2_gpio_in_get(struct omap_gpif_s *s, int start)
1073 if (start >= s->modules * 32 || start < 0)
1074 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n",
1075 __FUNCTION__, start);
1076 return s->module[start >> 5].in + (start & 31);
1079 void omap2_gpio_out_set(struct omap_gpif_s *s, int line, qemu_irq handler)
1081 if (line >= s->modules * 32 || line < 0)
1082 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
1083 s->module[line >> 5].handler[line & 31] = handler;
1086 /* Multichannel SPI */
1087 struct omap_mcspi_s {
1088 qemu_irq irq;
1089 int chnum;
1091 uint32_t sysconfig;
1092 uint32_t systest;
1093 uint32_t irqst;
1094 uint32_t irqen;
1095 uint32_t wken;
1096 uint32_t control;
1098 struct omap_mcspi_ch_s {
1099 qemu_irq txdrq;
1100 qemu_irq rxdrq;
1101 uint32_t (*txrx)(void *opaque, uint32_t, int);
1102 void *opaque;
1104 uint32_t tx;
1105 uint32_t rx;
1107 uint32_t config;
1108 uint32_t status;
1109 uint32_t control;
1110 } ch[4];
1113 static inline void omap_mcspi_interrupt_update(struct omap_mcspi_s *s)
1115 qemu_set_irq(s->irq, s->irqst & s->irqen);
1118 static inline void omap_mcspi_dmarequest_update(struct omap_mcspi_ch_s *ch)
1120 qemu_set_irq(ch->txdrq,
1121 (ch->control & 1) && /* EN */
1122 (ch->config & (1 << 14)) && /* DMAW */
1123 (ch->status & (1 << 1)) && /* TXS */
1124 ((ch->config >> 12) & 3) != 1); /* TRM */
1125 qemu_set_irq(ch->rxdrq,
1126 (ch->control & 1) && /* EN */
1127 (ch->config & (1 << 15)) && /* DMAW */
1128 (ch->status & (1 << 0)) && /* RXS */
1129 ((ch->config >> 12) & 3) != 2); /* TRM */
1132 static void omap_mcspi_transfer_run(struct omap_mcspi_s *s, int chnum)
1134 struct omap_mcspi_ch_s *ch = s->ch + chnum;
1136 if (!(ch->control & 1)) /* EN */
1137 return;
1138 if ((ch->status & (1 << 0)) && /* RXS */
1139 ((ch->config >> 12) & 3) != 2 && /* TRM */
1140 !(ch->config & (1 << 19))) /* TURBO */
1141 goto intr_update;
1142 if ((ch->status & (1 << 1)) && /* TXS */
1143 ((ch->config >> 12) & 3) != 1) /* TRM */
1144 goto intr_update;
1146 if (!(s->control & 1) || /* SINGLE */
1147 (ch->config & (1 << 20))) { /* FORCE */
1148 if (ch->txrx)
1149 ch->rx = ch->txrx(ch->opaque, ch->tx, /* WL */
1150 1 + (0x1f & (ch->config >> 7)));
1153 ch->tx = 0;
1154 ch->status |= 1 << 2; /* EOT */
1155 ch->status |= 1 << 1; /* TXS */
1156 if (((ch->config >> 12) & 3) != 2) /* TRM */
1157 ch->status |= 1 << 0; /* RXS */
1159 intr_update:
1160 if ((ch->status & (1 << 0)) && /* RXS */
1161 ((ch->config >> 12) & 3) != 2 && /* TRM */
1162 !(ch->config & (1 << 19))) /* TURBO */
1163 s->irqst |= 1 << (2 + 4 * chnum); /* RX_FULL */
1164 if ((ch->status & (1 << 1)) && /* TXS */
1165 ((ch->config >> 12) & 3) != 1) /* TRM */
1166 s->irqst |= 1 << (0 + 4 * chnum); /* TX_EMPTY */
1167 omap_mcspi_interrupt_update(s);
1168 omap_mcspi_dmarequest_update(ch);
1171 static void omap_mcspi_reset(struct omap_mcspi_s *s)
1173 int ch;
1175 s->sysconfig = 0;
1176 s->systest = 0;
1177 s->irqst = 0;
1178 s->irqen = 0;
1179 s->wken = 0;
1180 s->control = 4;
1182 for (ch = 0; ch < 4; ch ++) {
1183 s->ch[ch].config = 0x060000;
1184 s->ch[ch].status = 2; /* TXS */
1185 s->ch[ch].control = 0;
1187 omap_mcspi_dmarequest_update(s->ch + ch);
1190 omap_mcspi_interrupt_update(s);
1193 static uint32_t omap_mcspi_read(void *opaque, target_phys_addr_t addr)
1195 struct omap_mcspi_s *s = (struct omap_mcspi_s *) opaque;
1196 int ch = 0;
1197 uint32_t ret;
1199 switch (addr) {
1200 case 0x00: /* MCSPI_REVISION */
1201 return 0x91;
1203 case 0x10: /* MCSPI_SYSCONFIG */
1204 return s->sysconfig;
1206 case 0x14: /* MCSPI_SYSSTATUS */
1207 return 1; /* RESETDONE */
1209 case 0x18: /* MCSPI_IRQSTATUS */
1210 return s->irqst;
1212 case 0x1c: /* MCSPI_IRQENABLE */
1213 return s->irqen;
1215 case 0x20: /* MCSPI_WAKEUPENABLE */
1216 return s->wken;
1218 case 0x24: /* MCSPI_SYST */
1219 return s->systest;
1221 case 0x28: /* MCSPI_MODULCTRL */
1222 return s->control;
1224 case 0x68: ch ++;
1225 case 0x54: ch ++;
1226 case 0x40: ch ++;
1227 case 0x2c: /* MCSPI_CHCONF */
1228 return s->ch[ch].config;
1230 case 0x6c: ch ++;
1231 case 0x58: ch ++;
1232 case 0x44: ch ++;
1233 case 0x30: /* MCSPI_CHSTAT */
1234 return s->ch[ch].status;
1236 case 0x70: ch ++;
1237 case 0x5c: ch ++;
1238 case 0x48: ch ++;
1239 case 0x34: /* MCSPI_CHCTRL */
1240 return s->ch[ch].control;
1242 case 0x74: ch ++;
1243 case 0x60: ch ++;
1244 case 0x4c: ch ++;
1245 case 0x38: /* MCSPI_TX */
1246 return s->ch[ch].tx;
1248 case 0x78: ch ++;
1249 case 0x64: ch ++;
1250 case 0x50: ch ++;
1251 case 0x3c: /* MCSPI_RX */
1252 s->ch[ch].status &= ~(1 << 0); /* RXS */
1253 ret = s->ch[ch].rx;
1254 omap_mcspi_transfer_run(s, ch);
1255 return ret;
1258 OMAP_BAD_REG(addr);
1259 return 0;
1262 static void omap_mcspi_write(void *opaque, target_phys_addr_t addr,
1263 uint32_t value)
1265 struct omap_mcspi_s *s = (struct omap_mcspi_s *) opaque;
1266 int ch = 0;
1268 switch (addr) {
1269 case 0x00: /* MCSPI_REVISION */
1270 case 0x14: /* MCSPI_SYSSTATUS */
1271 case 0x30: /* MCSPI_CHSTAT0 */
1272 case 0x3c: /* MCSPI_RX0 */
1273 case 0x44: /* MCSPI_CHSTAT1 */
1274 case 0x50: /* MCSPI_RX1 */
1275 case 0x58: /* MCSPI_CHSTAT2 */
1276 case 0x64: /* MCSPI_RX2 */
1277 case 0x6c: /* MCSPI_CHSTAT3 */
1278 case 0x78: /* MCSPI_RX3 */
1279 OMAP_RO_REG(addr);
1280 return;
1282 case 0x10: /* MCSPI_SYSCONFIG */
1283 if (value & (1 << 1)) /* SOFTRESET */
1284 omap_mcspi_reset(s);
1285 s->sysconfig = value & 0x31d;
1286 break;
1288 case 0x18: /* MCSPI_IRQSTATUS */
1289 if (!((s->control & (1 << 3)) && (s->systest & (1 << 11)))) {
1290 s->irqst &= ~value;
1291 omap_mcspi_interrupt_update(s);
1293 break;
1295 case 0x1c: /* MCSPI_IRQENABLE */
1296 s->irqen = value & 0x1777f;
1297 omap_mcspi_interrupt_update(s);
1298 break;
1300 case 0x20: /* MCSPI_WAKEUPENABLE */
1301 s->wken = value & 1;
1302 break;
1304 case 0x24: /* MCSPI_SYST */
1305 if (s->control & (1 << 3)) /* SYSTEM_TEST */
1306 if (value & (1 << 11)) { /* SSB */
1307 s->irqst |= 0x1777f;
1308 omap_mcspi_interrupt_update(s);
1310 s->systest = value & 0xfff;
1311 break;
1313 case 0x28: /* MCSPI_MODULCTRL */
1314 if (value & (1 << 3)) /* SYSTEM_TEST */
1315 if (s->systest & (1 << 11)) { /* SSB */
1316 s->irqst |= 0x1777f;
1317 omap_mcspi_interrupt_update(s);
1319 s->control = value & 0xf;
1320 break;
1322 case 0x68: ch ++;
1323 case 0x54: ch ++;
1324 case 0x40: ch ++;
1325 case 0x2c: /* MCSPI_CHCONF */
1326 if ((value ^ s->ch[ch].config) & (3 << 14)) /* DMAR | DMAW */
1327 omap_mcspi_dmarequest_update(s->ch + ch);
1328 if (((value >> 12) & 3) == 3) /* TRM */
1329 fprintf(stderr, "%s: invalid TRM value (3)\n", __FUNCTION__);
1330 if (((value >> 7) & 0x1f) < 3) /* WL */
1331 fprintf(stderr, "%s: invalid WL value (%i)\n",
1332 __FUNCTION__, (value >> 7) & 0x1f);
1333 s->ch[ch].config = value & 0x7fffff;
1334 break;
1336 case 0x70: ch ++;
1337 case 0x5c: ch ++;
1338 case 0x48: ch ++;
1339 case 0x34: /* MCSPI_CHCTRL */
1340 if (value & ~s->ch[ch].control & 1) { /* EN */
1341 s->ch[ch].control |= 1;
1342 omap_mcspi_transfer_run(s, ch);
1343 } else
1344 s->ch[ch].control = value & 1;
1345 break;
1347 case 0x74: ch ++;
1348 case 0x60: ch ++;
1349 case 0x4c: ch ++;
1350 case 0x38: /* MCSPI_TX */
1351 s->ch[ch].tx = value;
1352 s->ch[ch].status &= ~(1 << 1); /* TXS */
1353 omap_mcspi_transfer_run(s, ch);
1354 break;
1356 default:
1357 OMAP_BAD_REG(addr);
1358 return;
1362 static CPUReadMemoryFunc *omap_mcspi_readfn[] = {
1363 omap_badwidth_read32,
1364 omap_badwidth_read32,
1365 omap_mcspi_read,
1368 static CPUWriteMemoryFunc *omap_mcspi_writefn[] = {
1369 omap_badwidth_write32,
1370 omap_badwidth_write32,
1371 omap_mcspi_write,
1374 struct omap_mcspi_s *omap_mcspi_init(struct omap_target_agent_s *ta, int chnum,
1375 qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk)
1377 int iomemtype;
1378 struct omap_mcspi_s *s = (struct omap_mcspi_s *)
1379 qemu_mallocz(sizeof(struct omap_mcspi_s));
1380 struct omap_mcspi_ch_s *ch = s->ch;
1382 s->irq = irq;
1383 s->chnum = chnum;
1384 while (chnum --) {
1385 ch->txdrq = *drq ++;
1386 ch->rxdrq = *drq ++;
1387 ch ++;
1389 omap_mcspi_reset(s);
1391 iomemtype = l4_register_io_memory(0, omap_mcspi_readfn,
1392 omap_mcspi_writefn, s);
1393 omap_l4_attach(ta, 0, iomemtype);
1395 return s;
1398 void omap_mcspi_attach(struct omap_mcspi_s *s,
1399 uint32_t (*txrx)(void *opaque, uint32_t, int), void *opaque,
1400 int chipselect)
1402 if (chipselect < 0 || chipselect >= s->chnum)
1403 cpu_abort(cpu_single_env, "%s: Bad chipselect %i\n",
1404 __FUNCTION__, chipselect);
1406 s->ch[chipselect].txrx = txrx;
1407 s->ch[chipselect].opaque = opaque;
1410 /* Enhanced Audio Controller (CODEC only) */
1411 struct omap_eac_s {
1412 qemu_irq irq;
1414 uint16_t sysconfig;
1415 uint8_t config[4];
1416 uint8_t control;
1417 uint8_t address;
1418 uint16_t data;
1419 uint8_t vtol;
1420 uint8_t vtsl;
1421 uint16_t mixer;
1422 uint16_t gain[4];
1423 uint8_t att;
1424 uint16_t max[7];
1426 struct {
1427 qemu_irq txdrq;
1428 qemu_irq rxdrq;
1429 uint32_t (*txrx)(void *opaque, uint32_t, int);
1430 void *opaque;
1432 #define EAC_BUF_LEN 1024
1433 uint32_t rxbuf[EAC_BUF_LEN];
1434 int rxoff;
1435 int rxlen;
1436 int rxavail;
1437 uint32_t txbuf[EAC_BUF_LEN];
1438 int txlen;
1439 int txavail;
1441 int enable;
1442 int rate;
1444 uint16_t config[4];
1446 /* These need to be moved to the actual codec */
1447 QEMUSoundCard card;
1448 SWVoiceIn *in_voice;
1449 SWVoiceOut *out_voice;
1450 int hw_enable;
1451 } codec;
1453 struct {
1454 uint8_t control;
1455 uint16_t config;
1456 } modem, bt;
1459 static inline void omap_eac_interrupt_update(struct omap_eac_s *s)
1461 qemu_set_irq(s->irq, (s->codec.config[1] >> 14) & 1); /* AURDI */
1464 static inline void omap_eac_in_dmarequest_update(struct omap_eac_s *s)
1466 qemu_set_irq(s->codec.rxdrq, (s->codec.rxavail || s->codec.rxlen) &&
1467 ((s->codec.config[1] >> 12) & 1)); /* DMAREN */
1470 static inline void omap_eac_out_dmarequest_update(struct omap_eac_s *s)
1472 qemu_set_irq(s->codec.txdrq, s->codec.txlen < s->codec.txavail &&
1473 ((s->codec.config[1] >> 11) & 1)); /* DMAWEN */
1476 static inline void omap_eac_in_refill(struct omap_eac_s *s)
1478 int left = MIN(EAC_BUF_LEN - s->codec.rxlen, s->codec.rxavail) << 2;
1479 int start = ((s->codec.rxoff + s->codec.rxlen) & (EAC_BUF_LEN - 1)) << 2;
1480 int leftwrap = MIN(left, (EAC_BUF_LEN << 2) - start);
1481 int recv = 1;
1482 uint8_t *buf = (uint8_t *) s->codec.rxbuf + start;
1484 left -= leftwrap;
1485 start = 0;
1486 while (leftwrap && (recv = AUD_read(s->codec.in_voice, buf + start,
1487 leftwrap)) > 0) { /* Be defensive */
1488 start += recv;
1489 leftwrap -= recv;
1491 if (recv <= 0)
1492 s->codec.rxavail = 0;
1493 else
1494 s->codec.rxavail -= start >> 2;
1495 s->codec.rxlen += start >> 2;
1497 if (recv > 0 && left > 0) {
1498 start = 0;
1499 while (left && (recv = AUD_read(s->codec.in_voice,
1500 (uint8_t *) s->codec.rxbuf + start,
1501 left)) > 0) { /* Be defensive */
1502 start += recv;
1503 left -= recv;
1505 if (recv <= 0)
1506 s->codec.rxavail = 0;
1507 else
1508 s->codec.rxavail -= start >> 2;
1509 s->codec.rxlen += start >> 2;
1513 static inline void omap_eac_out_empty(struct omap_eac_s *s)
1515 int left = s->codec.txlen << 2;
1516 int start = 0;
1517 int sent = 1;
1519 while (left && (sent = AUD_write(s->codec.out_voice,
1520 (uint8_t *) s->codec.txbuf + start,
1521 left)) > 0) { /* Be defensive */
1522 start += sent;
1523 left -= sent;
1526 if (!sent) {
1527 s->codec.txavail = 0;
1528 omap_eac_out_dmarequest_update(s);
1531 if (start)
1532 s->codec.txlen = 0;
1535 static void omap_eac_in_cb(void *opaque, int avail_b)
1537 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1539 s->codec.rxavail = avail_b >> 2;
1540 omap_eac_in_refill(s);
1541 /* TODO: possibly discard current buffer if overrun */
1542 omap_eac_in_dmarequest_update(s);
1545 static void omap_eac_out_cb(void *opaque, int free_b)
1547 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1549 s->codec.txavail = free_b >> 2;
1550 if (s->codec.txlen)
1551 omap_eac_out_empty(s);
1552 else
1553 omap_eac_out_dmarequest_update(s);
1556 static void omap_eac_enable_update(struct omap_eac_s *s)
1558 s->codec.enable = !(s->codec.config[1] & 1) && /* EACPWD */
1559 (s->codec.config[1] & 2) && /* AUDEN */
1560 s->codec.hw_enable;
1563 static const int omap_eac_fsint[4] = {
1564 8000,
1565 11025,
1566 22050,
1567 44100,
1570 static const int omap_eac_fsint2[8] = {
1571 8000,
1572 11025,
1573 22050,
1574 44100,
1575 48000,
1576 0, 0, 0,
1579 static const int omap_eac_fsint3[16] = {
1580 8000,
1581 11025,
1582 16000,
1583 22050,
1584 24000,
1585 32000,
1586 44100,
1587 48000,
1588 0, 0, 0, 0, 0, 0, 0, 0,
1591 static void omap_eac_rate_update(struct omap_eac_s *s)
1593 int fsint[3];
1595 fsint[2] = (s->codec.config[3] >> 9) & 0xf;
1596 fsint[1] = (s->codec.config[2] >> 0) & 0x7;
1597 fsint[0] = (s->codec.config[0] >> 6) & 0x3;
1598 if (fsint[2] < 0xf)
1599 s->codec.rate = omap_eac_fsint3[fsint[2]];
1600 else if (fsint[1] < 0x7)
1601 s->codec.rate = omap_eac_fsint2[fsint[1]];
1602 else
1603 s->codec.rate = omap_eac_fsint[fsint[0]];
1606 static void omap_eac_volume_update(struct omap_eac_s *s)
1608 /* TODO */
1611 static void omap_eac_format_update(struct omap_eac_s *s)
1613 struct audsettings fmt;
1615 /* The hardware buffers at most one sample */
1616 if (s->codec.rxlen)
1617 s->codec.rxlen = 1;
1619 if (s->codec.in_voice) {
1620 AUD_set_active_in(s->codec.in_voice, 0);
1621 AUD_close_in(&s->codec.card, s->codec.in_voice);
1622 s->codec.in_voice = 0;
1624 if (s->codec.out_voice) {
1625 omap_eac_out_empty(s);
1626 AUD_set_active_out(s->codec.out_voice, 0);
1627 AUD_close_out(&s->codec.card, s->codec.out_voice);
1628 s->codec.out_voice = 0;
1629 s->codec.txavail = 0;
1631 /* Discard what couldn't be written */
1632 s->codec.txlen = 0;
1634 omap_eac_enable_update(s);
1635 if (!s->codec.enable)
1636 return;
1638 omap_eac_rate_update(s);
1639 fmt.endianness = ((s->codec.config[0] >> 8) & 1); /* LI_BI */
1640 fmt.nchannels = ((s->codec.config[0] >> 10) & 1) ? 2 : 1; /* MN_ST */
1641 fmt.freq = s->codec.rate;
1642 /* TODO: signedness possibly depends on the CODEC hardware - or
1643 * does I2S specify it? */
1644 /* All register writes are 16 bits so we we store 16-bit samples
1645 * in the buffers regardless of AGCFR[B8_16] value. */
1646 fmt.fmt = AUD_FMT_U16;
1648 s->codec.in_voice = AUD_open_in(&s->codec.card, s->codec.in_voice,
1649 "eac.codec.in", s, omap_eac_in_cb, &fmt);
1650 s->codec.out_voice = AUD_open_out(&s->codec.card, s->codec.out_voice,
1651 "eac.codec.out", s, omap_eac_out_cb, &fmt);
1653 omap_eac_volume_update(s);
1655 AUD_set_active_in(s->codec.in_voice, 1);
1656 AUD_set_active_out(s->codec.out_voice, 1);
1659 static void omap_eac_reset(struct omap_eac_s *s)
1661 s->sysconfig = 0;
1662 s->config[0] = 0x0c;
1663 s->config[1] = 0x09;
1664 s->config[2] = 0xab;
1665 s->config[3] = 0x03;
1666 s->control = 0x00;
1667 s->address = 0x00;
1668 s->data = 0x0000;
1669 s->vtol = 0x00;
1670 s->vtsl = 0x00;
1671 s->mixer = 0x0000;
1672 s->gain[0] = 0xe7e7;
1673 s->gain[1] = 0x6767;
1674 s->gain[2] = 0x6767;
1675 s->gain[3] = 0x6767;
1676 s->att = 0xce;
1677 s->max[0] = 0;
1678 s->max[1] = 0;
1679 s->max[2] = 0;
1680 s->max[3] = 0;
1681 s->max[4] = 0;
1682 s->max[5] = 0;
1683 s->max[6] = 0;
1685 s->modem.control = 0x00;
1686 s->modem.config = 0x0000;
1687 s->bt.control = 0x00;
1688 s->bt.config = 0x0000;
1689 s->codec.config[0] = 0x0649;
1690 s->codec.config[1] = 0x0000;
1691 s->codec.config[2] = 0x0007;
1692 s->codec.config[3] = 0x1ffc;
1693 s->codec.rxoff = 0;
1694 s->codec.rxlen = 0;
1695 s->codec.txlen = 0;
1696 s->codec.rxavail = 0;
1697 s->codec.txavail = 0;
1699 omap_eac_format_update(s);
1700 omap_eac_interrupt_update(s);
1703 static uint32_t omap_eac_read(void *opaque, target_phys_addr_t addr)
1705 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1706 uint32_t ret;
1708 switch (addr) {
1709 case 0x000: /* CPCFR1 */
1710 return s->config[0];
1711 case 0x004: /* CPCFR2 */
1712 return s->config[1];
1713 case 0x008: /* CPCFR3 */
1714 return s->config[2];
1715 case 0x00c: /* CPCFR4 */
1716 return s->config[3];
1718 case 0x010: /* CPTCTL */
1719 return s->control | ((s->codec.rxavail + s->codec.rxlen > 0) << 7) |
1720 ((s->codec.txlen < s->codec.txavail) << 5);
1722 case 0x014: /* CPTTADR */
1723 return s->address;
1724 case 0x018: /* CPTDATL */
1725 return s->data & 0xff;
1726 case 0x01c: /* CPTDATH */
1727 return s->data >> 8;
1728 case 0x020: /* CPTVSLL */
1729 return s->vtol;
1730 case 0x024: /* CPTVSLH */
1731 return s->vtsl | (3 << 5); /* CRDY1 | CRDY2 */
1732 case 0x040: /* MPCTR */
1733 return s->modem.control;
1734 case 0x044: /* MPMCCFR */
1735 return s->modem.config;
1736 case 0x060: /* BPCTR */
1737 return s->bt.control;
1738 case 0x064: /* BPMCCFR */
1739 return s->bt.config;
1740 case 0x080: /* AMSCFR */
1741 return s->mixer;
1742 case 0x084: /* AMVCTR */
1743 return s->gain[0];
1744 case 0x088: /* AM1VCTR */
1745 return s->gain[1];
1746 case 0x08c: /* AM2VCTR */
1747 return s->gain[2];
1748 case 0x090: /* AM3VCTR */
1749 return s->gain[3];
1750 case 0x094: /* ASTCTR */
1751 return s->att;
1752 case 0x098: /* APD1LCR */
1753 return s->max[0];
1754 case 0x09c: /* APD1RCR */
1755 return s->max[1];
1756 case 0x0a0: /* APD2LCR */
1757 return s->max[2];
1758 case 0x0a4: /* APD2RCR */
1759 return s->max[3];
1760 case 0x0a8: /* APD3LCR */
1761 return s->max[4];
1762 case 0x0ac: /* APD3RCR */
1763 return s->max[5];
1764 case 0x0b0: /* APD4R */
1765 return s->max[6];
1766 case 0x0b4: /* ADWR */
1767 /* This should be write-only? Docs list it as read-only. */
1768 return 0x0000;
1769 case 0x0b8: /* ADRDR */
1770 if (likely(s->codec.rxlen > 1)) {
1771 ret = s->codec.rxbuf[s->codec.rxoff ++];
1772 s->codec.rxlen --;
1773 s->codec.rxoff &= EAC_BUF_LEN - 1;
1774 return ret;
1775 } else if (s->codec.rxlen) {
1776 ret = s->codec.rxbuf[s->codec.rxoff ++];
1777 s->codec.rxlen --;
1778 s->codec.rxoff &= EAC_BUF_LEN - 1;
1779 if (s->codec.rxavail)
1780 omap_eac_in_refill(s);
1781 omap_eac_in_dmarequest_update(s);
1782 return ret;
1784 return 0x0000;
1785 case 0x0bc: /* AGCFR */
1786 return s->codec.config[0];
1787 case 0x0c0: /* AGCTR */
1788 return s->codec.config[1] | ((s->codec.config[1] & 2) << 14);
1789 case 0x0c4: /* AGCFR2 */
1790 return s->codec.config[2];
1791 case 0x0c8: /* AGCFR3 */
1792 return s->codec.config[3];
1793 case 0x0cc: /* MBPDMACTR */
1794 case 0x0d0: /* MPDDMARR */
1795 case 0x0d8: /* MPUDMARR */
1796 case 0x0e4: /* BPDDMARR */
1797 case 0x0ec: /* BPUDMARR */
1798 return 0x0000;
1800 case 0x100: /* VERSION_NUMBER */
1801 return 0x0010;
1803 case 0x104: /* SYSCONFIG */
1804 return s->sysconfig;
1806 case 0x108: /* SYSSTATUS */
1807 return 1 | 0xe; /* RESETDONE | stuff */
1810 OMAP_BAD_REG(addr);
1811 return 0;
1814 static void omap_eac_write(void *opaque, target_phys_addr_t addr,
1815 uint32_t value)
1817 struct omap_eac_s *s = (struct omap_eac_s *) opaque;
1819 switch (addr) {
1820 case 0x098: /* APD1LCR */
1821 case 0x09c: /* APD1RCR */
1822 case 0x0a0: /* APD2LCR */
1823 case 0x0a4: /* APD2RCR */
1824 case 0x0a8: /* APD3LCR */
1825 case 0x0ac: /* APD3RCR */
1826 case 0x0b0: /* APD4R */
1827 case 0x0b8: /* ADRDR */
1828 case 0x0d0: /* MPDDMARR */
1829 case 0x0d8: /* MPUDMARR */
1830 case 0x0e4: /* BPDDMARR */
1831 case 0x0ec: /* BPUDMARR */
1832 case 0x100: /* VERSION_NUMBER */
1833 case 0x108: /* SYSSTATUS */
1834 OMAP_RO_REG(addr);
1835 return;
1837 case 0x000: /* CPCFR1 */
1838 s->config[0] = value & 0xff;
1839 omap_eac_format_update(s);
1840 break;
1841 case 0x004: /* CPCFR2 */
1842 s->config[1] = value & 0xff;
1843 omap_eac_format_update(s);
1844 break;
1845 case 0x008: /* CPCFR3 */
1846 s->config[2] = value & 0xff;
1847 omap_eac_format_update(s);
1848 break;
1849 case 0x00c: /* CPCFR4 */
1850 s->config[3] = value & 0xff;
1851 omap_eac_format_update(s);
1852 break;
1854 case 0x010: /* CPTCTL */
1855 /* Assuming TXF and TXE bits are read-only... */
1856 s->control = value & 0x5f;
1857 omap_eac_interrupt_update(s);
1858 break;
1860 case 0x014: /* CPTTADR */
1861 s->address = value & 0xff;
1862 break;
1863 case 0x018: /* CPTDATL */
1864 s->data &= 0xff00;
1865 s->data |= value & 0xff;
1866 break;
1867 case 0x01c: /* CPTDATH */
1868 s->data &= 0x00ff;
1869 s->data |= value << 8;
1870 break;
1871 case 0x020: /* CPTVSLL */
1872 s->vtol = value & 0xf8;
1873 break;
1874 case 0x024: /* CPTVSLH */
1875 s->vtsl = value & 0x9f;
1876 break;
1877 case 0x040: /* MPCTR */
1878 s->modem.control = value & 0x8f;
1879 break;
1880 case 0x044: /* MPMCCFR */
1881 s->modem.config = value & 0x7fff;
1882 break;
1883 case 0x060: /* BPCTR */
1884 s->bt.control = value & 0x8f;
1885 break;
1886 case 0x064: /* BPMCCFR */
1887 s->bt.config = value & 0x7fff;
1888 break;
1889 case 0x080: /* AMSCFR */
1890 s->mixer = value & 0x0fff;
1891 break;
1892 case 0x084: /* AMVCTR */
1893 s->gain[0] = value & 0xffff;
1894 break;
1895 case 0x088: /* AM1VCTR */
1896 s->gain[1] = value & 0xff7f;
1897 break;
1898 case 0x08c: /* AM2VCTR */
1899 s->gain[2] = value & 0xff7f;
1900 break;
1901 case 0x090: /* AM3VCTR */
1902 s->gain[3] = value & 0xff7f;
1903 break;
1904 case 0x094: /* ASTCTR */
1905 s->att = value & 0xff;
1906 break;
1908 case 0x0b4: /* ADWR */
1909 s->codec.txbuf[s->codec.txlen ++] = value;
1910 if (unlikely(s->codec.txlen == EAC_BUF_LEN ||
1911 s->codec.txlen == s->codec.txavail)) {
1912 if (s->codec.txavail)
1913 omap_eac_out_empty(s);
1914 /* Discard what couldn't be written */
1915 s->codec.txlen = 0;
1917 break;
1919 case 0x0bc: /* AGCFR */
1920 s->codec.config[0] = value & 0x07ff;
1921 omap_eac_format_update(s);
1922 break;
1923 case 0x0c0: /* AGCTR */
1924 s->codec.config[1] = value & 0x780f;
1925 omap_eac_format_update(s);
1926 break;
1927 case 0x0c4: /* AGCFR2 */
1928 s->codec.config[2] = value & 0x003f;
1929 omap_eac_format_update(s);
1930 break;
1931 case 0x0c8: /* AGCFR3 */
1932 s->codec.config[3] = value & 0xffff;
1933 omap_eac_format_update(s);
1934 break;
1935 case 0x0cc: /* MBPDMACTR */
1936 case 0x0d4: /* MPDDMAWR */
1937 case 0x0e0: /* MPUDMAWR */
1938 case 0x0e8: /* BPDDMAWR */
1939 case 0x0f0: /* BPUDMAWR */
1940 break;
1942 case 0x104: /* SYSCONFIG */
1943 if (value & (1 << 1)) /* SOFTRESET */
1944 omap_eac_reset(s);
1945 s->sysconfig = value & 0x31d;
1946 break;
1948 default:
1949 OMAP_BAD_REG(addr);
1950 return;
1954 static CPUReadMemoryFunc *omap_eac_readfn[] = {
1955 omap_badwidth_read16,
1956 omap_eac_read,
1957 omap_badwidth_read16,
1960 static CPUWriteMemoryFunc *omap_eac_writefn[] = {
1961 omap_badwidth_write16,
1962 omap_eac_write,
1963 omap_badwidth_write16,
1966 struct omap_eac_s *omap_eac_init(struct omap_target_agent_s *ta,
1967 qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk)
1969 int iomemtype;
1970 struct omap_eac_s *s = (struct omap_eac_s *)
1971 qemu_mallocz(sizeof(struct omap_eac_s));
1973 s->irq = irq;
1974 s->codec.rxdrq = *drq ++;
1975 s->codec.txdrq = *drq ++;
1976 omap_eac_reset(s);
1978 #ifdef HAS_AUDIO
1979 /* TODO: do AUD_init globally for machine */
1980 AUD_register_card(AUD_init(), "OMAP EAC", &s->codec.card);
1982 iomemtype = cpu_register_io_memory(0, omap_eac_readfn,
1983 omap_eac_writefn, s);
1984 omap_l4_attach(ta, 0, iomemtype);
1985 #endif
1987 return s;
1990 /* STI/XTI (emulation interface) console - reverse engineered only */
1991 struct omap_sti_s {
1992 qemu_irq irq;
1993 CharDriverState *chr;
1995 uint32_t sysconfig;
1996 uint32_t systest;
1997 uint32_t irqst;
1998 uint32_t irqen;
1999 uint32_t clkcontrol;
2000 uint32_t serial_config;
2003 #define STI_TRACE_CONSOLE_CHANNEL 239
2004 #define STI_TRACE_CONTROL_CHANNEL 253
2006 static inline void omap_sti_interrupt_update(struct omap_sti_s *s)
2008 qemu_set_irq(s->irq, s->irqst & s->irqen);
2011 static void omap_sti_reset(struct omap_sti_s *s)
2013 s->sysconfig = 0;
2014 s->irqst = 0;
2015 s->irqen = 0;
2016 s->clkcontrol = 0;
2017 s->serial_config = 0;
2019 omap_sti_interrupt_update(s);
2022 static uint32_t omap_sti_read(void *opaque, target_phys_addr_t addr)
2024 struct omap_sti_s *s = (struct omap_sti_s *) opaque;
2026 switch (addr) {
2027 case 0x00: /* STI_REVISION */
2028 return 0x10;
2030 case 0x10: /* STI_SYSCONFIG */
2031 return s->sysconfig;
2033 case 0x14: /* STI_SYSSTATUS / STI_RX_STATUS / XTI_SYSSTATUS */
2034 return 0x00;
2036 case 0x18: /* STI_IRQSTATUS */
2037 return s->irqst;
2039 case 0x1c: /* STI_IRQSETEN / STI_IRQCLREN */
2040 return s->irqen;
2042 case 0x24: /* STI_ER / STI_DR / XTI_TRACESELECT */
2043 case 0x28: /* STI_RX_DR / XTI_RXDATA */
2044 /* TODO */
2045 return 0;
2047 case 0x2c: /* STI_CLK_CTRL / XTI_SCLKCRTL */
2048 return s->clkcontrol;
2050 case 0x30: /* STI_SERIAL_CFG / XTI_SCONFIG */
2051 return s->serial_config;
2054 OMAP_BAD_REG(addr);
2055 return 0;
2058 static void omap_sti_write(void *opaque, target_phys_addr_t addr,
2059 uint32_t value)
2061 struct omap_sti_s *s = (struct omap_sti_s *) opaque;
2063 switch (addr) {
2064 case 0x00: /* STI_REVISION */
2065 case 0x14: /* STI_SYSSTATUS / STI_RX_STATUS / XTI_SYSSTATUS */
2066 OMAP_RO_REG(addr);
2067 return;
2069 case 0x10: /* STI_SYSCONFIG */
2070 if (value & (1 << 1)) /* SOFTRESET */
2071 omap_sti_reset(s);
2072 s->sysconfig = value & 0xfe;
2073 break;
2075 case 0x18: /* STI_IRQSTATUS */
2076 s->irqst &= ~value;
2077 omap_sti_interrupt_update(s);
2078 break;
2080 case 0x1c: /* STI_IRQSETEN / STI_IRQCLREN */
2081 s->irqen = value & 0xffff;
2082 omap_sti_interrupt_update(s);
2083 break;
2085 case 0x2c: /* STI_CLK_CTRL / XTI_SCLKCRTL */
2086 s->clkcontrol = value & 0xff;
2087 break;
2089 case 0x30: /* STI_SERIAL_CFG / XTI_SCONFIG */
2090 s->serial_config = value & 0xff;
2091 break;
2093 case 0x24: /* STI_ER / STI_DR / XTI_TRACESELECT */
2094 case 0x28: /* STI_RX_DR / XTI_RXDATA */
2095 /* TODO */
2096 return;
2098 default:
2099 OMAP_BAD_REG(addr);
2100 return;
2104 static CPUReadMemoryFunc *omap_sti_readfn[] = {
2105 omap_badwidth_read32,
2106 omap_badwidth_read32,
2107 omap_sti_read,
2110 static CPUWriteMemoryFunc *omap_sti_writefn[] = {
2111 omap_badwidth_write32,
2112 omap_badwidth_write32,
2113 omap_sti_write,
2116 static uint32_t omap_sti_fifo_read(void *opaque, target_phys_addr_t addr)
2118 OMAP_BAD_REG(addr);
2119 return 0;
2122 static void omap_sti_fifo_write(void *opaque, target_phys_addr_t addr,
2123 uint32_t value)
2125 struct omap_sti_s *s = (struct omap_sti_s *) opaque;
2126 int ch = addr >> 6;
2127 uint8_t byte = value;
2129 if (ch == STI_TRACE_CONTROL_CHANNEL) {
2130 /* Flush channel <i>value</i>. */
2131 qemu_chr_write(s->chr, (const uint8_t *) "\r", 1);
2132 } else if (ch == STI_TRACE_CONSOLE_CHANNEL || 1) {
2133 if (value == 0xc0 || value == 0xc3) {
2134 /* Open channel <i>ch</i>. */
2135 } else if (value == 0x00)
2136 qemu_chr_write(s->chr, (const uint8_t *) "\n", 1);
2137 else
2138 qemu_chr_write(s->chr, &byte, 1);
2142 static CPUReadMemoryFunc *omap_sti_fifo_readfn[] = {
2143 omap_sti_fifo_read,
2144 omap_badwidth_read8,
2145 omap_badwidth_read8,
2148 static CPUWriteMemoryFunc *omap_sti_fifo_writefn[] = {
2149 omap_sti_fifo_write,
2150 omap_badwidth_write8,
2151 omap_badwidth_write8,
2154 static struct omap_sti_s *omap_sti_init(struct omap_target_agent_s *ta,
2155 target_phys_addr_t channel_base, qemu_irq irq, omap_clk clk,
2156 CharDriverState *chr)
2158 int iomemtype;
2159 struct omap_sti_s *s = (struct omap_sti_s *)
2160 qemu_mallocz(sizeof(struct omap_sti_s));
2162 s->irq = irq;
2163 omap_sti_reset(s);
2165 s->chr = chr ?: qemu_chr_open("null", "null");
2167 iomemtype = l4_register_io_memory(0, omap_sti_readfn,
2168 omap_sti_writefn, s);
2169 omap_l4_attach(ta, 0, iomemtype);
2171 iomemtype = cpu_register_io_memory(0, omap_sti_fifo_readfn,
2172 omap_sti_fifo_writefn, s);
2173 cpu_register_physical_memory(channel_base, 0x10000, iomemtype);
2175 return s;
2178 /* L4 Interconnect */
2179 struct omap_target_agent_s {
2180 struct omap_l4_s *bus;
2181 int regions;
2182 struct omap_l4_region_s *start;
2183 target_phys_addr_t base;
2184 uint32_t component;
2185 uint32_t control;
2186 uint32_t status;
2189 struct omap_l4_s {
2190 target_phys_addr_t base;
2191 int ta_num;
2192 struct omap_target_agent_s ta[0];
2195 #ifdef L4_MUX_HACK
2196 static int omap_l4_io_entries;
2197 static int omap_cpu_io_entry;
2198 static struct omap_l4_entry {
2199 CPUReadMemoryFunc **mem_read;
2200 CPUWriteMemoryFunc **mem_write;
2201 void *opaque;
2202 } *omap_l4_io_entry;
2203 static CPUReadMemoryFunc **omap_l4_io_readb_fn;
2204 static CPUReadMemoryFunc **omap_l4_io_readh_fn;
2205 static CPUReadMemoryFunc **omap_l4_io_readw_fn;
2206 static CPUWriteMemoryFunc **omap_l4_io_writeb_fn;
2207 static CPUWriteMemoryFunc **omap_l4_io_writeh_fn;
2208 static CPUWriteMemoryFunc **omap_l4_io_writew_fn;
2209 static void **omap_l4_io_opaque;
2211 int l4_register_io_memory(int io_index, CPUReadMemoryFunc **mem_read,
2212 CPUWriteMemoryFunc **mem_write, void *opaque)
2214 omap_l4_io_entry[omap_l4_io_entries].mem_read = mem_read;
2215 omap_l4_io_entry[omap_l4_io_entries].mem_write = mem_write;
2216 omap_l4_io_entry[omap_l4_io_entries].opaque = opaque;
2218 return omap_l4_io_entries ++;
2221 static uint32_t omap_l4_io_readb(void *opaque, target_phys_addr_t addr)
2223 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2225 return omap_l4_io_readb_fn[i](omap_l4_io_opaque[i], addr);
2228 static uint32_t omap_l4_io_readh(void *opaque, target_phys_addr_t addr)
2230 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2232 return omap_l4_io_readh_fn[i](omap_l4_io_opaque[i], addr);
2235 static uint32_t omap_l4_io_readw(void *opaque, target_phys_addr_t addr)
2237 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2239 return omap_l4_io_readw_fn[i](omap_l4_io_opaque[i], addr);
2242 static void omap_l4_io_writeb(void *opaque, target_phys_addr_t addr,
2243 uint32_t value)
2245 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2247 return omap_l4_io_writeb_fn[i](omap_l4_io_opaque[i], addr, value);
2250 static void omap_l4_io_writeh(void *opaque, target_phys_addr_t addr,
2251 uint32_t value)
2253 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2255 return omap_l4_io_writeh_fn[i](omap_l4_io_opaque[i], addr, value);
2258 static void omap_l4_io_writew(void *opaque, target_phys_addr_t addr,
2259 uint32_t value)
2261 unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
2263 return omap_l4_io_writew_fn[i](omap_l4_io_opaque[i], addr, value);
2266 static CPUReadMemoryFunc *omap_l4_io_readfn[] = {
2267 omap_l4_io_readb,
2268 omap_l4_io_readh,
2269 omap_l4_io_readw,
2272 static CPUWriteMemoryFunc *omap_l4_io_writefn[] = {
2273 omap_l4_io_writeb,
2274 omap_l4_io_writeh,
2275 omap_l4_io_writew,
2277 #endif
2279 struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)
2281 struct omap_l4_s *bus = qemu_mallocz(
2282 sizeof(*bus) + ta_num * sizeof(*bus->ta));
2284 bus->ta_num = ta_num;
2285 bus->base = base;
2287 #ifdef L4_MUX_HACK
2288 omap_l4_io_entries = 1;
2289 omap_l4_io_entry = qemu_mallocz(125 * sizeof(*omap_l4_io_entry));
2291 omap_cpu_io_entry =
2292 cpu_register_io_memory(0, omap_l4_io_readfn,
2293 omap_l4_io_writefn, bus);
2294 # define L4_PAGES (0xb4000 / TARGET_PAGE_SIZE)
2295 omap_l4_io_readb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2296 omap_l4_io_readh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2297 omap_l4_io_readw_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2298 omap_l4_io_writeb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2299 omap_l4_io_writeh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2300 omap_l4_io_writew_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
2301 omap_l4_io_opaque = qemu_mallocz(sizeof(void *) * L4_PAGES);
2302 #endif
2304 return bus;
2307 static uint32_t omap_l4ta_read(void *opaque, target_phys_addr_t addr)
2309 struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
2311 switch (addr) {
2312 case 0x00: /* COMPONENT */
2313 return s->component;
2315 case 0x20: /* AGENT_CONTROL */
2316 return s->control;
2318 case 0x28: /* AGENT_STATUS */
2319 return s->status;
2322 OMAP_BAD_REG(addr);
2323 return 0;
2326 static void omap_l4ta_write(void *opaque, target_phys_addr_t addr,
2327 uint32_t value)
2329 struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
2331 switch (addr) {
2332 case 0x00: /* COMPONENT */
2333 case 0x28: /* AGENT_STATUS */
2334 OMAP_RO_REG(addr);
2335 break;
2337 case 0x20: /* AGENT_CONTROL */
2338 s->control = value & 0x01000700;
2339 if (value & 1) /* OCP_RESET */
2340 s->status &= ~1; /* REQ_TIMEOUT */
2341 break;
2343 default:
2344 OMAP_BAD_REG(addr);
2348 static CPUReadMemoryFunc *omap_l4ta_readfn[] = {
2349 omap_badwidth_read16,
2350 omap_l4ta_read,
2351 omap_badwidth_read16,
2354 static CPUWriteMemoryFunc *omap_l4ta_writefn[] = {
2355 omap_badwidth_write32,
2356 omap_badwidth_write32,
2357 omap_l4ta_write,
2360 #define L4TA(n) (n)
2361 #define L4TAO(n) ((n) + 39)
2363 static struct omap_l4_region_s {
2364 target_phys_addr_t offset;
2365 size_t size;
2366 int access;
2367 } omap_l4_region[125] = {
2368 [ 1] = { 0x40800, 0x800, 32 }, /* Initiator agent */
2369 [ 2] = { 0x41000, 0x1000, 32 }, /* Link agent */
2370 [ 0] = { 0x40000, 0x800, 32 }, /* Address and protection */
2371 [ 3] = { 0x00000, 0x1000, 32 | 16 | 8 }, /* System Control and Pinout */
2372 [ 4] = { 0x01000, 0x1000, 32 | 16 | 8 }, /* L4TAO1 */
2373 [ 5] = { 0x04000, 0x1000, 32 | 16 }, /* 32K Timer */
2374 [ 6] = { 0x05000, 0x1000, 32 | 16 | 8 }, /* L4TAO2 */
2375 [ 7] = { 0x08000, 0x800, 32 }, /* PRCM Region A */
2376 [ 8] = { 0x08800, 0x800, 32 }, /* PRCM Region B */
2377 [ 9] = { 0x09000, 0x1000, 32 | 16 | 8 }, /* L4TAO */
2378 [ 10] = { 0x12000, 0x1000, 32 | 16 | 8 }, /* Test (BCM) */
2379 [ 11] = { 0x13000, 0x1000, 32 | 16 | 8 }, /* L4TA1 */
2380 [ 12] = { 0x14000, 0x1000, 32 }, /* Test/emulation (TAP) */
2381 [ 13] = { 0x15000, 0x1000, 32 | 16 | 8 }, /* L4TA2 */
2382 [ 14] = { 0x18000, 0x1000, 32 | 16 | 8 }, /* GPIO1 */
2383 [ 16] = { 0x1a000, 0x1000, 32 | 16 | 8 }, /* GPIO2 */
2384 [ 18] = { 0x1c000, 0x1000, 32 | 16 | 8 }, /* GPIO3 */
2385 [ 19] = { 0x1e000, 0x1000, 32 | 16 | 8 }, /* GPIO4 */
2386 [ 15] = { 0x19000, 0x1000, 32 | 16 | 8 }, /* Quad GPIO TOP */
2387 [ 17] = { 0x1b000, 0x1000, 32 | 16 | 8 }, /* L4TA3 */
2388 [ 20] = { 0x20000, 0x1000, 32 | 16 | 8 }, /* WD Timer 1 (Secure) */
2389 [ 22] = { 0x22000, 0x1000, 32 | 16 | 8 }, /* WD Timer 2 (OMAP) */
2390 [ 21] = { 0x21000, 0x1000, 32 | 16 | 8 }, /* Dual WD timer TOP */
2391 [ 23] = { 0x23000, 0x1000, 32 | 16 | 8 }, /* L4TA4 */
2392 [ 24] = { 0x28000, 0x1000, 32 | 16 | 8 }, /* GP Timer 1 */
2393 [ 25] = { 0x29000, 0x1000, 32 | 16 | 8 }, /* L4TA7 */
2394 [ 26] = { 0x48000, 0x2000, 32 | 16 | 8 }, /* Emulation (ARM11ETB) */
2395 [ 27] = { 0x4a000, 0x1000, 32 | 16 | 8 }, /* L4TA9 */
2396 [ 28] = { 0x50000, 0x400, 32 | 16 | 8 }, /* Display top */
2397 [ 29] = { 0x50400, 0x400, 32 | 16 | 8 }, /* Display control */
2398 [ 30] = { 0x50800, 0x400, 32 | 16 | 8 }, /* Display RFBI */
2399 [ 31] = { 0x50c00, 0x400, 32 | 16 | 8 }, /* Display encoder */
2400 [ 32] = { 0x51000, 0x1000, 32 | 16 | 8 }, /* L4TA10 */
2401 [ 33] = { 0x52000, 0x400, 32 | 16 | 8 }, /* Camera top */
2402 [ 34] = { 0x52400, 0x400, 32 | 16 | 8 }, /* Camera core */
2403 [ 35] = { 0x52800, 0x400, 32 | 16 | 8 }, /* Camera DMA */
2404 [ 36] = { 0x52c00, 0x400, 32 | 16 | 8 }, /* Camera MMU */
2405 [ 37] = { 0x53000, 0x1000, 32 | 16 | 8 }, /* L4TA11 */
2406 [ 38] = { 0x56000, 0x1000, 32 | 16 | 8 }, /* sDMA */
2407 [ 39] = { 0x57000, 0x1000, 32 | 16 | 8 }, /* L4TA12 */
2408 [ 40] = { 0x58000, 0x1000, 32 | 16 | 8 }, /* SSI top */
2409 [ 41] = { 0x59000, 0x1000, 32 | 16 | 8 }, /* SSI GDD */
2410 [ 42] = { 0x5a000, 0x1000, 32 | 16 | 8 }, /* SSI Port1 */
2411 [ 43] = { 0x5b000, 0x1000, 32 | 16 | 8 }, /* SSI Port2 */
2412 [ 44] = { 0x5c000, 0x1000, 32 | 16 | 8 }, /* L4TA13 */
2413 [ 45] = { 0x5e000, 0x1000, 32 | 16 | 8 }, /* USB OTG */
2414 [ 46] = { 0x5f000, 0x1000, 32 | 16 | 8 }, /* L4TAO4 */
2415 [ 47] = { 0x60000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER1SDRC) */
2416 [ 48] = { 0x61000, 0x1000, 32 | 16 | 8 }, /* L4TA14 */
2417 [ 49] = { 0x62000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER2GPMC) */
2418 [ 50] = { 0x63000, 0x1000, 32 | 16 | 8 }, /* L4TA15 */
2419 [ 51] = { 0x64000, 0x1000, 32 | 16 | 8 }, /* Emulation (WIN_TRACER3OCM) */
2420 [ 52] = { 0x65000, 0x1000, 32 | 16 | 8 }, /* L4TA16 */
2421 [ 53] = { 0x66000, 0x300, 32 | 16 | 8 }, /* Emulation (WIN_TRACER4L4) */
2422 [ 54] = { 0x67000, 0x1000, 32 | 16 | 8 }, /* L4TA17 */
2423 [ 55] = { 0x68000, 0x1000, 32 | 16 | 8 }, /* Emulation (XTI) */
2424 [ 56] = { 0x69000, 0x1000, 32 | 16 | 8 }, /* L4TA18 */
2425 [ 57] = { 0x6a000, 0x1000, 16 | 8 }, /* UART1 */
2426 [ 58] = { 0x6b000, 0x1000, 32 | 16 | 8 }, /* L4TA19 */
2427 [ 59] = { 0x6c000, 0x1000, 16 | 8 }, /* UART2 */
2428 [ 60] = { 0x6d000, 0x1000, 32 | 16 | 8 }, /* L4TA20 */
2429 [ 61] = { 0x6e000, 0x1000, 16 | 8 }, /* UART3 */
2430 [ 62] = { 0x6f000, 0x1000, 32 | 16 | 8 }, /* L4TA21 */
2431 [ 63] = { 0x70000, 0x1000, 16 }, /* I2C1 */
2432 [ 64] = { 0x71000, 0x1000, 32 | 16 | 8 }, /* L4TAO5 */
2433 [ 65] = { 0x72000, 0x1000, 16 }, /* I2C2 */
2434 [ 66] = { 0x73000, 0x1000, 32 | 16 | 8 }, /* L4TAO6 */
2435 [ 67] = { 0x74000, 0x1000, 16 }, /* McBSP1 */
2436 [ 68] = { 0x75000, 0x1000, 32 | 16 | 8 }, /* L4TAO7 */
2437 [ 69] = { 0x76000, 0x1000, 16 }, /* McBSP2 */
2438 [ 70] = { 0x77000, 0x1000, 32 | 16 | 8 }, /* L4TAO8 */
2439 [ 71] = { 0x24000, 0x1000, 32 | 16 | 8 }, /* WD Timer 3 (DSP) */
2440 [ 72] = { 0x25000, 0x1000, 32 | 16 | 8 }, /* L4TA5 */
2441 [ 73] = { 0x26000, 0x1000, 32 | 16 | 8 }, /* WD Timer 4 (IVA) */
2442 [ 74] = { 0x27000, 0x1000, 32 | 16 | 8 }, /* L4TA6 */
2443 [ 75] = { 0x2a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 2 */
2444 [ 76] = { 0x2b000, 0x1000, 32 | 16 | 8 }, /* L4TA8 */
2445 [ 77] = { 0x78000, 0x1000, 32 | 16 | 8 }, /* GP Timer 3 */
2446 [ 78] = { 0x79000, 0x1000, 32 | 16 | 8 }, /* L4TA22 */
2447 [ 79] = { 0x7a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 4 */
2448 [ 80] = { 0x7b000, 0x1000, 32 | 16 | 8 }, /* L4TA23 */
2449 [ 81] = { 0x7c000, 0x1000, 32 | 16 | 8 }, /* GP Timer 5 */
2450 [ 82] = { 0x7d000, 0x1000, 32 | 16 | 8 }, /* L4TA24 */
2451 [ 83] = { 0x7e000, 0x1000, 32 | 16 | 8 }, /* GP Timer 6 */
2452 [ 84] = { 0x7f000, 0x1000, 32 | 16 | 8 }, /* L4TA25 */
2453 [ 85] = { 0x80000, 0x1000, 32 | 16 | 8 }, /* GP Timer 7 */
2454 [ 86] = { 0x81000, 0x1000, 32 | 16 | 8 }, /* L4TA26 */
2455 [ 87] = { 0x82000, 0x1000, 32 | 16 | 8 }, /* GP Timer 8 */
2456 [ 88] = { 0x83000, 0x1000, 32 | 16 | 8 }, /* L4TA27 */
2457 [ 89] = { 0x84000, 0x1000, 32 | 16 | 8 }, /* GP Timer 9 */
2458 [ 90] = { 0x85000, 0x1000, 32 | 16 | 8 }, /* L4TA28 */
2459 [ 91] = { 0x86000, 0x1000, 32 | 16 | 8 }, /* GP Timer 10 */
2460 [ 92] = { 0x87000, 0x1000, 32 | 16 | 8 }, /* L4TA29 */
2461 [ 93] = { 0x88000, 0x1000, 32 | 16 | 8 }, /* GP Timer 11 */
2462 [ 94] = { 0x89000, 0x1000, 32 | 16 | 8 }, /* L4TA30 */
2463 [ 95] = { 0x8a000, 0x1000, 32 | 16 | 8 }, /* GP Timer 12 */
2464 [ 96] = { 0x8b000, 0x1000, 32 | 16 | 8 }, /* L4TA31 */
2465 [ 97] = { 0x90000, 0x1000, 16 }, /* EAC */
2466 [ 98] = { 0x91000, 0x1000, 32 | 16 | 8 }, /* L4TA32 */
2467 [ 99] = { 0x92000, 0x1000, 16 }, /* FAC */
2468 [100] = { 0x93000, 0x1000, 32 | 16 | 8 }, /* L4TA33 */
2469 [101] = { 0x94000, 0x1000, 32 | 16 | 8 }, /* IPC (MAILBOX) */
2470 [102] = { 0x95000, 0x1000, 32 | 16 | 8 }, /* L4TA34 */
2471 [103] = { 0x98000, 0x1000, 32 | 16 | 8 }, /* SPI1 */
2472 [104] = { 0x99000, 0x1000, 32 | 16 | 8 }, /* L4TA35 */
2473 [105] = { 0x9a000, 0x1000, 32 | 16 | 8 }, /* SPI2 */
2474 [106] = { 0x9b000, 0x1000, 32 | 16 | 8 }, /* L4TA36 */
2475 [107] = { 0x9c000, 0x1000, 16 | 8 }, /* MMC SDIO */
2476 [108] = { 0x9d000, 0x1000, 32 | 16 | 8 }, /* L4TAO9 */
2477 [109] = { 0x9e000, 0x1000, 32 | 16 | 8 }, /* MS_PRO */
2478 [110] = { 0x9f000, 0x1000, 32 | 16 | 8 }, /* L4TAO10 */
2479 [111] = { 0xa0000, 0x1000, 32 }, /* RNG */
2480 [112] = { 0xa1000, 0x1000, 32 | 16 | 8 }, /* L4TAO11 */
2481 [113] = { 0xa2000, 0x1000, 32 }, /* DES3DES */
2482 [114] = { 0xa3000, 0x1000, 32 | 16 | 8 }, /* L4TAO12 */
2483 [115] = { 0xa4000, 0x1000, 32 }, /* SHA1MD5 */
2484 [116] = { 0xa5000, 0x1000, 32 | 16 | 8 }, /* L4TAO13 */
2485 [117] = { 0xa6000, 0x1000, 32 }, /* AES */
2486 [118] = { 0xa7000, 0x1000, 32 | 16 | 8 }, /* L4TA37 */
2487 [119] = { 0xa8000, 0x2000, 32 }, /* PKA */
2488 [120] = { 0xaa000, 0x1000, 32 | 16 | 8 }, /* L4TA38 */
2489 [121] = { 0xb0000, 0x1000, 32 }, /* MG */
2490 [122] = { 0xb1000, 0x1000, 32 | 16 | 8 },
2491 [123] = { 0xb2000, 0x1000, 32 }, /* HDQ/1-Wire */
2492 [124] = { 0xb3000, 0x1000, 32 | 16 | 8 }, /* L4TA39 */
2495 static struct omap_l4_agent_info_s {
2496 int ta;
2497 int region;
2498 int regions;
2499 int ta_region;
2500 } omap_l4_agent_info[54] = {
2501 { 0, 0, 3, 2 }, /* L4IA initiatior agent */
2502 { L4TAO(1), 3, 2, 1 }, /* Control and pinout module */
2503 { L4TAO(2), 5, 2, 1 }, /* 32K timer */
2504 { L4TAO(3), 7, 3, 2 }, /* PRCM */
2505 { L4TA(1), 10, 2, 1 }, /* BCM */
2506 { L4TA(2), 12, 2, 1 }, /* Test JTAG */
2507 { L4TA(3), 14, 6, 3 }, /* Quad GPIO */
2508 { L4TA(4), 20, 4, 3 }, /* WD timer 1/2 */
2509 { L4TA(7), 24, 2, 1 }, /* GP timer 1 */
2510 { L4TA(9), 26, 2, 1 }, /* ATM11 ETB */
2511 { L4TA(10), 28, 5, 4 }, /* Display subsystem */
2512 { L4TA(11), 33, 5, 4 }, /* Camera subsystem */
2513 { L4TA(12), 38, 2, 1 }, /* sDMA */
2514 { L4TA(13), 40, 5, 4 }, /* SSI */
2515 { L4TAO(4), 45, 2, 1 }, /* USB */
2516 { L4TA(14), 47, 2, 1 }, /* Win Tracer1 */
2517 { L4TA(15), 49, 2, 1 }, /* Win Tracer2 */
2518 { L4TA(16), 51, 2, 1 }, /* Win Tracer3 */
2519 { L4TA(17), 53, 2, 1 }, /* Win Tracer4 */
2520 { L4TA(18), 55, 2, 1 }, /* XTI */
2521 { L4TA(19), 57, 2, 1 }, /* UART1 */
2522 { L4TA(20), 59, 2, 1 }, /* UART2 */
2523 { L4TA(21), 61, 2, 1 }, /* UART3 */
2524 { L4TAO(5), 63, 2, 1 }, /* I2C1 */
2525 { L4TAO(6), 65, 2, 1 }, /* I2C2 */
2526 { L4TAO(7), 67, 2, 1 }, /* McBSP1 */
2527 { L4TAO(8), 69, 2, 1 }, /* McBSP2 */
2528 { L4TA(5), 71, 2, 1 }, /* WD Timer 3 (DSP) */
2529 { L4TA(6), 73, 2, 1 }, /* WD Timer 4 (IVA) */
2530 { L4TA(8), 75, 2, 1 }, /* GP Timer 2 */
2531 { L4TA(22), 77, 2, 1 }, /* GP Timer 3 */
2532 { L4TA(23), 79, 2, 1 }, /* GP Timer 4 */
2533 { L4TA(24), 81, 2, 1 }, /* GP Timer 5 */
2534 { L4TA(25), 83, 2, 1 }, /* GP Timer 6 */
2535 { L4TA(26), 85, 2, 1 }, /* GP Timer 7 */
2536 { L4TA(27), 87, 2, 1 }, /* GP Timer 8 */
2537 { L4TA(28), 89, 2, 1 }, /* GP Timer 9 */
2538 { L4TA(29), 91, 2, 1 }, /* GP Timer 10 */
2539 { L4TA(30), 93, 2, 1 }, /* GP Timer 11 */
2540 { L4TA(31), 95, 2, 1 }, /* GP Timer 12 */
2541 { L4TA(32), 97, 2, 1 }, /* EAC */
2542 { L4TA(33), 99, 2, 1 }, /* FAC */
2543 { L4TA(34), 101, 2, 1 }, /* IPC */
2544 { L4TA(35), 103, 2, 1 }, /* SPI1 */
2545 { L4TA(36), 105, 2, 1 }, /* SPI2 */
2546 { L4TAO(9), 107, 2, 1 }, /* MMC SDIO */
2547 { L4TAO(10), 109, 2, 1 },
2548 { L4TAO(11), 111, 2, 1 }, /* RNG */
2549 { L4TAO(12), 113, 2, 1 }, /* DES3DES */
2550 { L4TAO(13), 115, 2, 1 }, /* SHA1MD5 */
2551 { L4TA(37), 117, 2, 1 }, /* AES */
2552 { L4TA(38), 119, 2, 1 }, /* PKA */
2553 { -1, 121, 2, 1 },
2554 { L4TA(39), 123, 2, 1 }, /* HDQ/1-Wire */
2557 #define omap_l4ta(bus, cs) omap_l4ta_get(bus, L4TA(cs))
2558 #define omap_l4tao(bus, cs) omap_l4ta_get(bus, L4TAO(cs))
2560 struct omap_target_agent_s *omap_l4ta_get(struct omap_l4_s *bus, int cs)
2562 int i, iomemtype;
2563 struct omap_target_agent_s *ta = 0;
2564 struct omap_l4_agent_info_s *info = 0;
2566 for (i = 0; i < bus->ta_num; i ++)
2567 if (omap_l4_agent_info[i].ta == cs) {
2568 ta = &bus->ta[i];
2569 info = &omap_l4_agent_info[i];
2570 break;
2572 if (!ta) {
2573 fprintf(stderr, "%s: bad target agent (%i)\n", __FUNCTION__, cs);
2574 exit(-1);
2577 ta->bus = bus;
2578 ta->start = &omap_l4_region[info->region];
2579 ta->regions = info->regions;
2581 ta->component = ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2582 ta->status = 0x00000000;
2583 ta->control = 0x00000200; /* XXX 01000200 for L4TAO */
2585 iomemtype = l4_register_io_memory(0, omap_l4ta_readfn,
2586 omap_l4ta_writefn, ta);
2587 ta->base = omap_l4_attach(ta, info->ta_region, iomemtype);
2589 return ta;
2592 target_phys_addr_t omap_l4_attach(struct omap_target_agent_s *ta, int region,
2593 int iotype)
2595 target_phys_addr_t base;
2596 ssize_t size;
2597 #ifdef L4_MUX_HACK
2598 int i;
2599 #endif
2601 if (region < 0 || region >= ta->regions) {
2602 fprintf(stderr, "%s: bad io region (%i)\n", __FUNCTION__, region);
2603 exit(-1);
2606 base = ta->bus->base + ta->start[region].offset;
2607 size = ta->start[region].size;
2608 if (iotype) {
2609 #ifndef L4_MUX_HACK
2610 cpu_register_physical_memory(base, size, iotype);
2611 #else
2612 cpu_register_physical_memory(base, size, omap_cpu_io_entry);
2613 i = (base - ta->bus->base) / TARGET_PAGE_SIZE;
2614 for (; size > 0; size -= TARGET_PAGE_SIZE, i ++) {
2615 omap_l4_io_readb_fn[i] = omap_l4_io_entry[iotype].mem_read[0];
2616 omap_l4_io_readh_fn[i] = omap_l4_io_entry[iotype].mem_read[1];
2617 omap_l4_io_readw_fn[i] = omap_l4_io_entry[iotype].mem_read[2];
2618 omap_l4_io_writeb_fn[i] = omap_l4_io_entry[iotype].mem_write[0];
2619 omap_l4_io_writeh_fn[i] = omap_l4_io_entry[iotype].mem_write[1];
2620 omap_l4_io_writew_fn[i] = omap_l4_io_entry[iotype].mem_write[2];
2621 omap_l4_io_opaque[i] = omap_l4_io_entry[iotype].opaque;
2623 #endif
2626 return base;
2629 /* TEST-Chip-level TAP */
2630 static uint32_t omap_tap_read(void *opaque, target_phys_addr_t addr)
2632 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2634 switch (addr) {
2635 case 0x204: /* IDCODE_reg */
2636 switch (s->mpu_model) {
2637 case omap2420:
2638 case omap2422:
2639 case omap2423:
2640 return 0x5b5d902f; /* ES 2.2 */
2641 case omap2430:
2642 return 0x5b68a02f; /* ES 2.2 */
2643 case omap3430:
2644 return 0x1b7ae02f; /* ES 2 */
2645 default:
2646 cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
2649 case 0x208: /* PRODUCTION_ID_reg for OMAP2 */
2650 case 0x210: /* PRODUCTION_ID_reg for OMAP3 */
2651 switch (s->mpu_model) {
2652 case omap2420:
2653 return 0x000254f0; /* POP ESHS2.1.1 in N91/93/95, ES2 in N800 */
2654 case omap2422:
2655 return 0x000400f0;
2656 case omap2423:
2657 return 0x000800f0;
2658 case omap2430:
2659 return 0x000000f0;
2660 case omap3430:
2661 return 0x000000f0;
2662 default:
2663 cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
2666 case 0x20c:
2667 switch (s->mpu_model) {
2668 case omap2420:
2669 case omap2422:
2670 case omap2423:
2671 return 0xcafeb5d9; /* ES 2.2 */
2672 case omap2430:
2673 return 0xcafeb68a; /* ES 2.2 */
2674 case omap3430:
2675 return 0xcafeb7ae; /* ES 2 */
2676 default:
2677 cpu_abort(cpu_single_env, "%s: Bad mpu model\n", __FUNCTION__);
2680 case 0x218: /* DIE_ID_reg */
2681 return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2682 case 0x21c: /* DIE_ID_reg */
2683 return 0x54 << 24;
2684 case 0x220: /* DIE_ID_reg */
2685 return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2686 case 0x224: /* DIE_ID_reg */
2687 return ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
2690 OMAP_BAD_REG(addr);
2691 return 0;
2694 static void omap_tap_write(void *opaque, target_phys_addr_t addr,
2695 uint32_t value)
2697 OMAP_BAD_REG(addr);
2700 static CPUReadMemoryFunc *omap_tap_readfn[] = {
2701 omap_badwidth_read32,
2702 omap_badwidth_read32,
2703 omap_tap_read,
2706 static CPUWriteMemoryFunc *omap_tap_writefn[] = {
2707 omap_badwidth_write32,
2708 omap_badwidth_write32,
2709 omap_tap_write,
2712 void omap_tap_init(struct omap_target_agent_s *ta,
2713 struct omap_mpu_state_s *mpu)
2715 omap_l4_attach(ta, 0, l4_register_io_memory(0,
2716 omap_tap_readfn, omap_tap_writefn, mpu));
2719 /* Power, Reset, and Clock Management */
2720 struct omap_prcm_s {
2721 qemu_irq irq[3];
2722 struct omap_mpu_state_s *mpu;
2724 uint32_t irqst[3];
2725 uint32_t irqen[3];
2727 uint32_t sysconfig;
2728 uint32_t voltctrl;
2729 uint32_t scratch[20];
2731 uint32_t clksrc[1];
2732 uint32_t clkout[1];
2733 uint32_t clkemul[1];
2734 uint32_t clkpol[1];
2735 uint32_t clksel[8];
2736 uint32_t clken[12];
2737 uint32_t clkctrl[4];
2738 uint32_t clkidle[7];
2739 uint32_t setuptime[2];
2741 uint32_t wkup[3];
2742 uint32_t wken[3];
2743 uint32_t wkst[3];
2744 uint32_t rst[4];
2745 uint32_t rstctrl[1];
2746 uint32_t power[4];
2747 uint32_t rsttime_wkup;
2749 uint32_t ev;
2750 uint32_t evtime[2];
2752 int dpll_lock, apll_lock[2];
2755 static void omap_prcm_int_update(struct omap_prcm_s *s, int dom)
2757 qemu_set_irq(s->irq[dom], s->irqst[dom] & s->irqen[dom]);
2758 /* XXX or is the mask applied before PRCM_IRQSTATUS_* ? */
2761 static uint32_t omap_prcm_read(void *opaque, target_phys_addr_t addr)
2763 struct omap_prcm_s *s = (struct omap_prcm_s *) opaque;
2764 uint32_t ret;
2766 switch (addr) {
2767 case 0x000: /* PRCM_REVISION */
2768 return 0x10;
2770 case 0x010: /* PRCM_SYSCONFIG */
2771 return s->sysconfig;
2773 case 0x018: /* PRCM_IRQSTATUS_MPU */
2774 return s->irqst[0];
2776 case 0x01c: /* PRCM_IRQENABLE_MPU */
2777 return s->irqen[0];
2779 case 0x050: /* PRCM_VOLTCTRL */
2780 return s->voltctrl;
2781 case 0x054: /* PRCM_VOLTST */
2782 return s->voltctrl & 3;
2784 case 0x060: /* PRCM_CLKSRC_CTRL */
2785 return s->clksrc[0];
2786 case 0x070: /* PRCM_CLKOUT_CTRL */
2787 return s->clkout[0];
2788 case 0x078: /* PRCM_CLKEMUL_CTRL */
2789 return s->clkemul[0];
2790 case 0x080: /* PRCM_CLKCFG_CTRL */
2791 case 0x084: /* PRCM_CLKCFG_STATUS */
2792 return 0;
2794 case 0x090: /* PRCM_VOLTSETUP */
2795 return s->setuptime[0];
2797 case 0x094: /* PRCM_CLKSSETUP */
2798 return s->setuptime[1];
2800 case 0x098: /* PRCM_POLCTRL */
2801 return s->clkpol[0];
2803 case 0x0b0: /* GENERAL_PURPOSE1 */
2804 case 0x0b4: /* GENERAL_PURPOSE2 */
2805 case 0x0b8: /* GENERAL_PURPOSE3 */
2806 case 0x0bc: /* GENERAL_PURPOSE4 */
2807 case 0x0c0: /* GENERAL_PURPOSE5 */
2808 case 0x0c4: /* GENERAL_PURPOSE6 */
2809 case 0x0c8: /* GENERAL_PURPOSE7 */
2810 case 0x0cc: /* GENERAL_PURPOSE8 */
2811 case 0x0d0: /* GENERAL_PURPOSE9 */
2812 case 0x0d4: /* GENERAL_PURPOSE10 */
2813 case 0x0d8: /* GENERAL_PURPOSE11 */
2814 case 0x0dc: /* GENERAL_PURPOSE12 */
2815 case 0x0e0: /* GENERAL_PURPOSE13 */
2816 case 0x0e4: /* GENERAL_PURPOSE14 */
2817 case 0x0e8: /* GENERAL_PURPOSE15 */
2818 case 0x0ec: /* GENERAL_PURPOSE16 */
2819 case 0x0f0: /* GENERAL_PURPOSE17 */
2820 case 0x0f4: /* GENERAL_PURPOSE18 */
2821 case 0x0f8: /* GENERAL_PURPOSE19 */
2822 case 0x0fc: /* GENERAL_PURPOSE20 */
2823 return s->scratch[(addr - 0xb0) >> 2];
2825 case 0x140: /* CM_CLKSEL_MPU */
2826 return s->clksel[0];
2827 case 0x148: /* CM_CLKSTCTRL_MPU */
2828 return s->clkctrl[0];
2830 case 0x158: /* RM_RSTST_MPU */
2831 return s->rst[0];
2832 case 0x1c8: /* PM_WKDEP_MPU */
2833 return s->wkup[0];
2834 case 0x1d4: /* PM_EVGENCTRL_MPU */
2835 return s->ev;
2836 case 0x1d8: /* PM_EVEGENONTIM_MPU */
2837 return s->evtime[0];
2838 case 0x1dc: /* PM_EVEGENOFFTIM_MPU */
2839 return s->evtime[1];
2840 case 0x1e0: /* PM_PWSTCTRL_MPU */
2841 return s->power[0];
2842 case 0x1e4: /* PM_PWSTST_MPU */
2843 return 0;
2845 case 0x200: /* CM_FCLKEN1_CORE */
2846 return s->clken[0];
2847 case 0x204: /* CM_FCLKEN2_CORE */
2848 return s->clken[1];
2849 case 0x210: /* CM_ICLKEN1_CORE */
2850 return s->clken[2];
2851 case 0x214: /* CM_ICLKEN2_CORE */
2852 return s->clken[3];
2853 case 0x21c: /* CM_ICLKEN4_CORE */
2854 return s->clken[4];
2856 case 0x220: /* CM_IDLEST1_CORE */
2857 /* TODO: check the actual iclk status */
2858 return 0x7ffffff9;
2859 case 0x224: /* CM_IDLEST2_CORE */
2860 /* TODO: check the actual iclk status */
2861 return 0x00000007;
2862 case 0x22c: /* CM_IDLEST4_CORE */
2863 /* TODO: check the actual iclk status */
2864 return 0x0000001f;
2866 case 0x230: /* CM_AUTOIDLE1_CORE */
2867 return s->clkidle[0];
2868 case 0x234: /* CM_AUTOIDLE2_CORE */
2869 return s->clkidle[1];
2870 case 0x238: /* CM_AUTOIDLE3_CORE */
2871 return s->clkidle[2];
2872 case 0x23c: /* CM_AUTOIDLE4_CORE */
2873 return s->clkidle[3];
2875 case 0x240: /* CM_CLKSEL1_CORE */
2876 return s->clksel[1];
2877 case 0x244: /* CM_CLKSEL2_CORE */
2878 return s->clksel[2];
2880 case 0x248: /* CM_CLKSTCTRL_CORE */
2881 return s->clkctrl[1];
2883 case 0x2a0: /* PM_WKEN1_CORE */
2884 return s->wken[0];
2885 case 0x2a4: /* PM_WKEN2_CORE */
2886 return s->wken[1];
2888 case 0x2b0: /* PM_WKST1_CORE */
2889 return s->wkst[0];
2890 case 0x2b4: /* PM_WKST2_CORE */
2891 return s->wkst[1];
2892 case 0x2c8: /* PM_WKDEP_CORE */
2893 return 0x1e;
2895 case 0x2e0: /* PM_PWSTCTRL_CORE */
2896 return s->power[1];
2897 case 0x2e4: /* PM_PWSTST_CORE */
2898 return 0x000030 | (s->power[1] & 0xfc00);
2900 case 0x300: /* CM_FCLKEN_GFX */
2901 return s->clken[5];
2902 case 0x310: /* CM_ICLKEN_GFX */
2903 return s->clken[6];
2904 case 0x320: /* CM_IDLEST_GFX */
2905 /* TODO: check the actual iclk status */
2906 return 0x00000001;
2907 case 0x340: /* CM_CLKSEL_GFX */
2908 return s->clksel[3];
2909 case 0x348: /* CM_CLKSTCTRL_GFX */
2910 return s->clkctrl[2];
2911 case 0x350: /* RM_RSTCTRL_GFX */
2912 return s->rstctrl[0];
2913 case 0x358: /* RM_RSTST_GFX */
2914 return s->rst[1];
2915 case 0x3c8: /* PM_WKDEP_GFX */
2916 return s->wkup[1];
2918 case 0x3e0: /* PM_PWSTCTRL_GFX */
2919 return s->power[2];
2920 case 0x3e4: /* PM_PWSTST_GFX */
2921 return s->power[2] & 3;
2923 case 0x400: /* CM_FCLKEN_WKUP */
2924 return s->clken[7];
2925 case 0x410: /* CM_ICLKEN_WKUP */
2926 return s->clken[8];
2927 case 0x420: /* CM_IDLEST_WKUP */
2928 /* TODO: check the actual iclk status */
2929 return 0x0000003f;
2930 case 0x430: /* CM_AUTOIDLE_WKUP */
2931 return s->clkidle[4];
2932 case 0x440: /* CM_CLKSEL_WKUP */
2933 return s->clksel[4];
2934 case 0x450: /* RM_RSTCTRL_WKUP */
2935 return 0;
2936 case 0x454: /* RM_RSTTIME_WKUP */
2937 return s->rsttime_wkup;
2938 case 0x458: /* RM_RSTST_WKUP */
2939 return s->rst[2];
2940 case 0x4a0: /* PM_WKEN_WKUP */
2941 return s->wken[2];
2942 case 0x4b0: /* PM_WKST_WKUP */
2943 return s->wkst[2];
2945 case 0x500: /* CM_CLKEN_PLL */
2946 return s->clken[9];
2947 case 0x520: /* CM_IDLEST_CKGEN */
2948 ret = 0x0000070 | (s->apll_lock[0] << 9) | (s->apll_lock[1] << 8);
2949 if (!(s->clksel[6] & 3))
2950 /* Core uses 32-kHz clock */
2951 ret |= 3 << 0;
2952 else if (!s->dpll_lock)
2953 /* DPLL not locked, core uses ref_clk */
2954 ret |= 1 << 0;
2955 else
2956 /* Core uses DPLL */
2957 ret |= 2 << 0;
2958 return ret;
2959 case 0x530: /* CM_AUTOIDLE_PLL */
2960 return s->clkidle[5];
2961 case 0x540: /* CM_CLKSEL1_PLL */
2962 return s->clksel[5];
2963 case 0x544: /* CM_CLKSEL2_PLL */
2964 return s->clksel[6];
2966 case 0x800: /* CM_FCLKEN_DSP */
2967 return s->clken[10];
2968 case 0x810: /* CM_ICLKEN_DSP */
2969 return s->clken[11];
2970 case 0x820: /* CM_IDLEST_DSP */
2971 /* TODO: check the actual iclk status */
2972 return 0x00000103;
2973 case 0x830: /* CM_AUTOIDLE_DSP */
2974 return s->clkidle[6];
2975 case 0x840: /* CM_CLKSEL_DSP */
2976 return s->clksel[7];
2977 case 0x848: /* CM_CLKSTCTRL_DSP */
2978 return s->clkctrl[3];
2979 case 0x850: /* RM_RSTCTRL_DSP */
2980 return 0;
2981 case 0x858: /* RM_RSTST_DSP */
2982 return s->rst[3];
2983 case 0x8c8: /* PM_WKDEP_DSP */
2984 return s->wkup[2];
2985 case 0x8e0: /* PM_PWSTCTRL_DSP */
2986 return s->power[3];
2987 case 0x8e4: /* PM_PWSTST_DSP */
2988 return 0x008030 | (s->power[3] & 0x3003);
2990 case 0x8f0: /* PRCM_IRQSTATUS_DSP */
2991 return s->irqst[1];
2992 case 0x8f4: /* PRCM_IRQENABLE_DSP */
2993 return s->irqen[1];
2995 case 0x8f8: /* PRCM_IRQSTATUS_IVA */
2996 return s->irqst[2];
2997 case 0x8fc: /* PRCM_IRQENABLE_IVA */
2998 return s->irqen[2];
3001 OMAP_BAD_REG(addr);
3002 return 0;
3005 static void omap_prcm_apll_update(struct omap_prcm_s *s)
3007 int mode[2];
3009 mode[0] = (s->clken[9] >> 6) & 3;
3010 s->apll_lock[0] = (mode[0] == 3);
3011 mode[1] = (s->clken[9] >> 2) & 3;
3012 s->apll_lock[1] = (mode[1] == 3);
3013 /* TODO: update clocks */
3015 if (mode[0] == 1 || mode[0] == 2 || mode[1] == 1 || mode[2] == 2)
3016 fprintf(stderr, "%s: bad EN_54M_PLL or bad EN_96M_PLL\n",
3017 __FUNCTION__);
3020 static void omap_prcm_dpll_update(struct omap_prcm_s *s)
3022 omap_clk dpll = omap_findclk(s->mpu, "dpll");
3023 omap_clk dpll_x2 = omap_findclk(s->mpu, "dpll");
3024 omap_clk core = omap_findclk(s->mpu, "core_clk");
3025 int mode = (s->clken[9] >> 0) & 3;
3026 int mult, div;
3028 mult = (s->clksel[5] >> 12) & 0x3ff;
3029 div = (s->clksel[5] >> 8) & 0xf;
3030 if (mult == 0 || mult == 1)
3031 mode = 1; /* Bypass */
3033 s->dpll_lock = 0;
3034 switch (mode) {
3035 case 0:
3036 fprintf(stderr, "%s: bad EN_DPLL\n", __FUNCTION__);
3037 break;
3038 case 1: /* Low-power bypass mode (Default) */
3039 case 2: /* Fast-relock bypass mode */
3040 omap_clk_setrate(dpll, 1, 1);
3041 omap_clk_setrate(dpll_x2, 1, 1);
3042 break;
3043 case 3: /* Lock mode */
3044 s->dpll_lock = 1; /* After 20 FINT cycles (ref_clk / (div + 1)). */
3046 omap_clk_setrate(dpll, div + 1, mult);
3047 omap_clk_setrate(dpll_x2, div + 1, mult * 2);
3048 break;
3051 switch ((s->clksel[6] >> 0) & 3) {
3052 case 0:
3053 omap_clk_reparent(core, omap_findclk(s->mpu, "clk32-kHz"));
3054 break;
3055 case 1:
3056 omap_clk_reparent(core, dpll);
3057 break;
3058 case 2:
3059 /* Default */
3060 omap_clk_reparent(core, dpll_x2);
3061 break;
3062 case 3:
3063 fprintf(stderr, "%s: bad CORE_CLK_SRC\n", __FUNCTION__);
3064 break;
3068 static void omap_prcm_write(void *opaque, target_phys_addr_t addr,
3069 uint32_t value)
3071 struct omap_prcm_s *s = (struct omap_prcm_s *) opaque;
3073 switch (addr) {
3074 case 0x000: /* PRCM_REVISION */
3075 case 0x054: /* PRCM_VOLTST */
3076 case 0x084: /* PRCM_CLKCFG_STATUS */
3077 case 0x1e4: /* PM_PWSTST_MPU */
3078 case 0x220: /* CM_IDLEST1_CORE */
3079 case 0x224: /* CM_IDLEST2_CORE */
3080 case 0x22c: /* CM_IDLEST4_CORE */
3081 case 0x2c8: /* PM_WKDEP_CORE */
3082 case 0x2e4: /* PM_PWSTST_CORE */
3083 case 0x320: /* CM_IDLEST_GFX */
3084 case 0x3e4: /* PM_PWSTST_GFX */
3085 case 0x420: /* CM_IDLEST_WKUP */
3086 case 0x520: /* CM_IDLEST_CKGEN */
3087 case 0x820: /* CM_IDLEST_DSP */
3088 case 0x8e4: /* PM_PWSTST_DSP */
3089 OMAP_RO_REG(addr);
3090 return;
3092 case 0x010: /* PRCM_SYSCONFIG */
3093 s->sysconfig = value & 1;
3094 break;
3096 case 0x018: /* PRCM_IRQSTATUS_MPU */
3097 s->irqst[0] &= ~value;
3098 omap_prcm_int_update(s, 0);
3099 break;
3100 case 0x01c: /* PRCM_IRQENABLE_MPU */
3101 s->irqen[0] = value & 0x3f;
3102 omap_prcm_int_update(s, 0);
3103 break;
3105 case 0x050: /* PRCM_VOLTCTRL */
3106 s->voltctrl = value & 0xf1c3;
3107 break;
3109 case 0x060: /* PRCM_CLKSRC_CTRL */
3110 s->clksrc[0] = value & 0xdb;
3111 /* TODO update clocks */
3112 break;
3114 case 0x070: /* PRCM_CLKOUT_CTRL */
3115 s->clkout[0] = value & 0xbbbb;
3116 /* TODO update clocks */
3117 break;
3119 case 0x078: /* PRCM_CLKEMUL_CTRL */
3120 s->clkemul[0] = value & 1;
3121 /* TODO update clocks */
3122 break;
3124 case 0x080: /* PRCM_CLKCFG_CTRL */
3125 break;
3127 case 0x090: /* PRCM_VOLTSETUP */
3128 s->setuptime[0] = value & 0xffff;
3129 break;
3130 case 0x094: /* PRCM_CLKSSETUP */
3131 s->setuptime[1] = value & 0xffff;
3132 break;
3134 case 0x098: /* PRCM_POLCTRL */
3135 s->clkpol[0] = value & 0x701;
3136 break;
3138 case 0x0b0: /* GENERAL_PURPOSE1 */
3139 case 0x0b4: /* GENERAL_PURPOSE2 */
3140 case 0x0b8: /* GENERAL_PURPOSE3 */
3141 case 0x0bc: /* GENERAL_PURPOSE4 */
3142 case 0x0c0: /* GENERAL_PURPOSE5 */
3143 case 0x0c4: /* GENERAL_PURPOSE6 */
3144 case 0x0c8: /* GENERAL_PURPOSE7 */
3145 case 0x0cc: /* GENERAL_PURPOSE8 */
3146 case 0x0d0: /* GENERAL_PURPOSE9 */
3147 case 0x0d4: /* GENERAL_PURPOSE10 */
3148 case 0x0d8: /* GENERAL_PURPOSE11 */
3149 case 0x0dc: /* GENERAL_PURPOSE12 */
3150 case 0x0e0: /* GENERAL_PURPOSE13 */
3151 case 0x0e4: /* GENERAL_PURPOSE14 */
3152 case 0x0e8: /* GENERAL_PURPOSE15 */
3153 case 0x0ec: /* GENERAL_PURPOSE16 */
3154 case 0x0f0: /* GENERAL_PURPOSE17 */
3155 case 0x0f4: /* GENERAL_PURPOSE18 */
3156 case 0x0f8: /* GENERAL_PURPOSE19 */
3157 case 0x0fc: /* GENERAL_PURPOSE20 */
3158 s->scratch[(addr - 0xb0) >> 2] = value;
3159 break;
3161 case 0x140: /* CM_CLKSEL_MPU */
3162 s->clksel[0] = value & 0x1f;
3163 /* TODO update clocks */
3164 break;
3165 case 0x148: /* CM_CLKSTCTRL_MPU */
3166 s->clkctrl[0] = value & 0x1f;
3167 break;
3169 case 0x158: /* RM_RSTST_MPU */
3170 s->rst[0] &= ~value;
3171 break;
3172 case 0x1c8: /* PM_WKDEP_MPU */
3173 s->wkup[0] = value & 0x15;
3174 break;
3176 case 0x1d4: /* PM_EVGENCTRL_MPU */
3177 s->ev = value & 0x1f;
3178 break;
3179 case 0x1d8: /* PM_EVEGENONTIM_MPU */
3180 s->evtime[0] = value;
3181 break;
3182 case 0x1dc: /* PM_EVEGENOFFTIM_MPU */
3183 s->evtime[1] = value;
3184 break;
3186 case 0x1e0: /* PM_PWSTCTRL_MPU */
3187 s->power[0] = value & 0xc0f;
3188 break;
3190 case 0x200: /* CM_FCLKEN1_CORE */
3191 s->clken[0] = value & 0xbfffffff;
3192 /* TODO update clocks */
3193 /* The EN_EAC bit only gets/puts func_96m_clk. */
3194 break;
3195 case 0x204: /* CM_FCLKEN2_CORE */
3196 s->clken[1] = value & 0x00000007;
3197 /* TODO update clocks */
3198 break;
3199 case 0x210: /* CM_ICLKEN1_CORE */
3200 s->clken[2] = value & 0xfffffff9;
3201 /* TODO update clocks */
3202 /* The EN_EAC bit only gets/puts core_l4_iclk. */
3203 break;
3204 case 0x214: /* CM_ICLKEN2_CORE */
3205 s->clken[3] = value & 0x00000007;
3206 /* TODO update clocks */
3207 break;
3208 case 0x21c: /* CM_ICLKEN4_CORE */
3209 s->clken[4] = value & 0x0000001f;
3210 /* TODO update clocks */
3211 break;
3213 case 0x230: /* CM_AUTOIDLE1_CORE */
3214 s->clkidle[0] = value & 0xfffffff9;
3215 /* TODO update clocks */
3216 break;
3217 case 0x234: /* CM_AUTOIDLE2_CORE */
3218 s->clkidle[1] = value & 0x00000007;
3219 /* TODO update clocks */
3220 break;
3221 case 0x238: /* CM_AUTOIDLE3_CORE */
3222 s->clkidle[2] = value & 0x00000007;
3223 /* TODO update clocks */
3224 break;
3225 case 0x23c: /* CM_AUTOIDLE4_CORE */
3226 s->clkidle[3] = value & 0x0000001f;
3227 /* TODO update clocks */
3228 break;
3230 case 0x240: /* CM_CLKSEL1_CORE */
3231 s->clksel[1] = value & 0x0fffbf7f;
3232 /* TODO update clocks */
3233 break;
3235 case 0x244: /* CM_CLKSEL2_CORE */
3236 s->clksel[2] = value & 0x00fffffc;
3237 /* TODO update clocks */
3238 break;
3240 case 0x248: /* CM_CLKSTCTRL_CORE */
3241 s->clkctrl[1] = value & 0x7;
3242 break;
3244 case 0x2a0: /* PM_WKEN1_CORE */
3245 s->wken[0] = value & 0x04667ff8;
3246 break;
3247 case 0x2a4: /* PM_WKEN2_CORE */
3248 s->wken[1] = value & 0x00000005;
3249 break;
3251 case 0x2b0: /* PM_WKST1_CORE */
3252 s->wkst[0] &= ~value;
3253 break;
3254 case 0x2b4: /* PM_WKST2_CORE */
3255 s->wkst[1] &= ~value;
3256 break;
3258 case 0x2e0: /* PM_PWSTCTRL_CORE */
3259 s->power[1] = (value & 0x00fc3f) | (1 << 2);
3260 break;
3262 case 0x300: /* CM_FCLKEN_GFX */
3263 s->clken[5] = value & 6;
3264 /* TODO update clocks */
3265 break;
3266 case 0x310: /* CM_ICLKEN_GFX */
3267 s->clken[6] = value & 1;
3268 /* TODO update clocks */
3269 break;
3270 case 0x340: /* CM_CLKSEL_GFX */
3271 s->clksel[3] = value & 7;
3272 /* TODO update clocks */
3273 break;
3274 case 0x348: /* CM_CLKSTCTRL_GFX */
3275 s->clkctrl[2] = value & 1;
3276 break;
3277 case 0x350: /* RM_RSTCTRL_GFX */
3278 s->rstctrl[0] = value & 1;
3279 /* TODO: reset */
3280 break;
3281 case 0x358: /* RM_RSTST_GFX */
3282 s->rst[1] &= ~value;
3283 break;
3284 case 0x3c8: /* PM_WKDEP_GFX */
3285 s->wkup[1] = value & 0x13;
3286 break;
3287 case 0x3e0: /* PM_PWSTCTRL_GFX */
3288 s->power[2] = (value & 0x00c0f) | (3 << 2);
3289 break;
3291 case 0x400: /* CM_FCLKEN_WKUP */
3292 s->clken[7] = value & 0xd;
3293 /* TODO update clocks */
3294 break;
3295 case 0x410: /* CM_ICLKEN_WKUP */
3296 s->clken[8] = value & 0x3f;
3297 /* TODO update clocks */
3298 break;
3299 case 0x430: /* CM_AUTOIDLE_WKUP */
3300 s->clkidle[4] = value & 0x0000003f;
3301 /* TODO update clocks */
3302 break;
3303 case 0x440: /* CM_CLKSEL_WKUP */
3304 s->clksel[4] = value & 3;
3305 /* TODO update clocks */
3306 break;
3307 case 0x450: /* RM_RSTCTRL_WKUP */
3308 /* TODO: reset */
3309 if (value & 2)
3310 qemu_system_reset_request();
3311 break;
3312 case 0x454: /* RM_RSTTIME_WKUP */
3313 s->rsttime_wkup = value & 0x1fff;
3314 break;
3315 case 0x458: /* RM_RSTST_WKUP */
3316 s->rst[2] &= ~value;
3317 break;
3318 case 0x4a0: /* PM_WKEN_WKUP */
3319 s->wken[2] = value & 0x00000005;
3320 break;
3321 case 0x4b0: /* PM_WKST_WKUP */
3322 s->wkst[2] &= ~value;
3323 break;
3325 case 0x500: /* CM_CLKEN_PLL */
3326 if (value & 0xffffff30)
3327 fprintf(stderr, "%s: write 0s in CM_CLKEN_PLL for "
3328 "future compatiblity\n", __FUNCTION__);
3329 if ((s->clken[9] ^ value) & 0xcc) {
3330 s->clken[9] &= ~0xcc;
3331 s->clken[9] |= value & 0xcc;
3332 omap_prcm_apll_update(s);
3334 if ((s->clken[9] ^ value) & 3) {
3335 s->clken[9] &= ~3;
3336 s->clken[9] |= value & 3;
3337 omap_prcm_dpll_update(s);
3339 break;
3340 case 0x530: /* CM_AUTOIDLE_PLL */
3341 s->clkidle[5] = value & 0x000000cf;
3342 /* TODO update clocks */
3343 break;
3344 case 0x540: /* CM_CLKSEL1_PLL */
3345 if (value & 0xfc4000d7)
3346 fprintf(stderr, "%s: write 0s in CM_CLKSEL1_PLL for "
3347 "future compatiblity\n", __FUNCTION__);
3348 if ((s->clksel[5] ^ value) & 0x003fff00) {
3349 s->clksel[5] = value & 0x03bfff28;
3350 omap_prcm_dpll_update(s);
3352 /* TODO update the other clocks */
3354 s->clksel[5] = value & 0x03bfff28;
3355 break;
3356 case 0x544: /* CM_CLKSEL2_PLL */
3357 if (value & ~3)
3358 fprintf(stderr, "%s: write 0s in CM_CLKSEL2_PLL[31:2] for "
3359 "future compatiblity\n", __FUNCTION__);
3360 if (s->clksel[6] != (value & 3)) {
3361 s->clksel[6] = value & 3;
3362 omap_prcm_dpll_update(s);
3364 break;
3366 case 0x800: /* CM_FCLKEN_DSP */
3367 s->clken[10] = value & 0x501;
3368 /* TODO update clocks */
3369 break;
3370 case 0x810: /* CM_ICLKEN_DSP */
3371 s->clken[11] = value & 0x2;
3372 /* TODO update clocks */
3373 break;
3374 case 0x830: /* CM_AUTOIDLE_DSP */
3375 s->clkidle[6] = value & 0x2;
3376 /* TODO update clocks */
3377 break;
3378 case 0x840: /* CM_CLKSEL_DSP */
3379 s->clksel[7] = value & 0x3fff;
3380 /* TODO update clocks */
3381 break;
3382 case 0x848: /* CM_CLKSTCTRL_DSP */
3383 s->clkctrl[3] = value & 0x101;
3384 break;
3385 case 0x850: /* RM_RSTCTRL_DSP */
3386 /* TODO: reset */
3387 break;
3388 case 0x858: /* RM_RSTST_DSP */
3389 s->rst[3] &= ~value;
3390 break;
3391 case 0x8c8: /* PM_WKDEP_DSP */
3392 s->wkup[2] = value & 0x13;
3393 break;
3394 case 0x8e0: /* PM_PWSTCTRL_DSP */
3395 s->power[3] = (value & 0x03017) | (3 << 2);
3396 break;
3398 case 0x8f0: /* PRCM_IRQSTATUS_DSP */
3399 s->irqst[1] &= ~value;
3400 omap_prcm_int_update(s, 1);
3401 break;
3402 case 0x8f4: /* PRCM_IRQENABLE_DSP */
3403 s->irqen[1] = value & 0x7;
3404 omap_prcm_int_update(s, 1);
3405 break;
3407 case 0x8f8: /* PRCM_IRQSTATUS_IVA */
3408 s->irqst[2] &= ~value;
3409 omap_prcm_int_update(s, 2);
3410 break;
3411 case 0x8fc: /* PRCM_IRQENABLE_IVA */
3412 s->irqen[2] = value & 0x7;
3413 omap_prcm_int_update(s, 2);
3414 break;
3416 default:
3417 OMAP_BAD_REG(addr);
3418 return;
3422 static CPUReadMemoryFunc *omap_prcm_readfn[] = {
3423 omap_badwidth_read32,
3424 omap_badwidth_read32,
3425 omap_prcm_read,
3428 static CPUWriteMemoryFunc *omap_prcm_writefn[] = {
3429 omap_badwidth_write32,
3430 omap_badwidth_write32,
3431 omap_prcm_write,
3434 static void omap_prcm_reset(struct omap_prcm_s *s)
3436 s->sysconfig = 0;
3437 s->irqst[0] = 0;
3438 s->irqst[1] = 0;
3439 s->irqst[2] = 0;
3440 s->irqen[0] = 0;
3441 s->irqen[1] = 0;
3442 s->irqen[2] = 0;
3443 s->voltctrl = 0x1040;
3444 s->ev = 0x14;
3445 s->evtime[0] = 0;
3446 s->evtime[1] = 0;
3447 s->clkctrl[0] = 0;
3448 s->clkctrl[1] = 0;
3449 s->clkctrl[2] = 0;
3450 s->clkctrl[3] = 0;
3451 s->clken[1] = 7;
3452 s->clken[3] = 7;
3453 s->clken[4] = 0;
3454 s->clken[5] = 0;
3455 s->clken[6] = 0;
3456 s->clken[7] = 0xc;
3457 s->clken[8] = 0x3e;
3458 s->clken[9] = 0x0d;
3459 s->clken[10] = 0;
3460 s->clken[11] = 0;
3461 s->clkidle[0] = 0;
3462 s->clkidle[2] = 7;
3463 s->clkidle[3] = 0;
3464 s->clkidle[4] = 0;
3465 s->clkidle[5] = 0x0c;
3466 s->clkidle[6] = 0;
3467 s->clksel[0] = 0x01;
3468 s->clksel[1] = 0x02100121;
3469 s->clksel[2] = 0x00000000;
3470 s->clksel[3] = 0x01;
3471 s->clksel[4] = 0;
3472 s->clksel[7] = 0x0121;
3473 s->wkup[0] = 0x15;
3474 s->wkup[1] = 0x13;
3475 s->wkup[2] = 0x13;
3476 s->wken[0] = 0x04667ff8;
3477 s->wken[1] = 0x00000005;
3478 s->wken[2] = 5;
3479 s->wkst[0] = 0;
3480 s->wkst[1] = 0;
3481 s->wkst[2] = 0;
3482 s->power[0] = 0x00c;
3483 s->power[1] = 4;
3484 s->power[2] = 0x0000c;
3485 s->power[3] = 0x14;
3486 s->rstctrl[0] = 1;
3487 s->rst[3] = 1;
3488 omap_prcm_apll_update(s);
3489 omap_prcm_dpll_update(s);
3492 static void omap_prcm_coldreset(struct omap_prcm_s *s)
3494 s->setuptime[0] = 0;
3495 s->setuptime[1] = 0;
3496 memset(&s->scratch, 0, sizeof(s->scratch));
3497 s->rst[0] = 0x01;
3498 s->rst[1] = 0x00;
3499 s->rst[2] = 0x01;
3500 s->clken[0] = 0;
3501 s->clken[2] = 0;
3502 s->clkidle[1] = 0;
3503 s->clksel[5] = 0;
3504 s->clksel[6] = 2;
3505 s->clksrc[0] = 0x43;
3506 s->clkout[0] = 0x0303;
3507 s->clkemul[0] = 0;
3508 s->clkpol[0] = 0x100;
3509 s->rsttime_wkup = 0x1002;
3511 omap_prcm_reset(s);
3514 struct omap_prcm_s *omap_prcm_init(struct omap_target_agent_s *ta,
3515 qemu_irq mpu_int, qemu_irq dsp_int, qemu_irq iva_int,
3516 struct omap_mpu_state_s *mpu)
3518 int iomemtype;
3519 struct omap_prcm_s *s = (struct omap_prcm_s *)
3520 qemu_mallocz(sizeof(struct omap_prcm_s));
3522 s->irq[0] = mpu_int;
3523 s->irq[1] = dsp_int;
3524 s->irq[2] = iva_int;
3525 s->mpu = mpu;
3526 omap_prcm_coldreset(s);
3528 iomemtype = l4_register_io_memory(0, omap_prcm_readfn,
3529 omap_prcm_writefn, s);
3530 omap_l4_attach(ta, 0, iomemtype);
3531 omap_l4_attach(ta, 1, iomemtype);
3533 return s;
3536 /* System and Pinout control */
3537 struct omap_sysctl_s {
3538 struct omap_mpu_state_s *mpu;
3540 uint32_t sysconfig;
3541 uint32_t devconfig;
3542 uint32_t psaconfig;
3543 uint32_t padconf[0x45];
3544 uint8_t obs;
3545 uint32_t msuspendmux[5];
3548 static uint32_t omap_sysctl_read8(void *opaque, target_phys_addr_t addr)
3551 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3552 int pad_offset, byte_offset;
3553 int value;
3555 switch (addr) {
3556 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3557 pad_offset = (addr - 0x30) >> 2;
3558 byte_offset = (addr - 0x30) & (4 - 1);
3560 value = s->padconf[pad_offset];
3561 value = (value >> (byte_offset * 8)) & 0xff;
3563 return value;
3565 default:
3566 break;
3569 OMAP_BAD_REG(addr);
3570 return 0;
3573 static uint32_t omap_sysctl_read(void *opaque, target_phys_addr_t addr)
3575 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3577 switch (addr) {
3578 case 0x000: /* CONTROL_REVISION */
3579 return 0x20;
3581 case 0x010: /* CONTROL_SYSCONFIG */
3582 return s->sysconfig;
3584 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3585 return s->padconf[(addr - 0x30) >> 2];
3587 case 0x270: /* CONTROL_DEBOBS */
3588 return s->obs;
3590 case 0x274: /* CONTROL_DEVCONF */
3591 return s->devconfig;
3593 case 0x28c: /* CONTROL_EMU_SUPPORT */
3594 return 0;
3596 case 0x290: /* CONTROL_MSUSPENDMUX_0 */
3597 return s->msuspendmux[0];
3598 case 0x294: /* CONTROL_MSUSPENDMUX_1 */
3599 return s->msuspendmux[1];
3600 case 0x298: /* CONTROL_MSUSPENDMUX_2 */
3601 return s->msuspendmux[2];
3602 case 0x29c: /* CONTROL_MSUSPENDMUX_3 */
3603 return s->msuspendmux[3];
3604 case 0x2a0: /* CONTROL_MSUSPENDMUX_4 */
3605 return s->msuspendmux[4];
3606 case 0x2a4: /* CONTROL_MSUSPENDMUX_5 */
3607 return 0;
3609 case 0x2b8: /* CONTROL_PSA_CTRL */
3610 return s->psaconfig;
3611 case 0x2bc: /* CONTROL_PSA_CMD */
3612 case 0x2c0: /* CONTROL_PSA_VALUE */
3613 return 0;
3615 case 0x2b0: /* CONTROL_SEC_CTRL */
3616 return 0x800000f1;
3617 case 0x2d0: /* CONTROL_SEC_EMU */
3618 return 0x80000015;
3619 case 0x2d4: /* CONTROL_SEC_TAP */
3620 return 0x8000007f;
3621 case 0x2b4: /* CONTROL_SEC_TEST */
3622 case 0x2f0: /* CONTROL_SEC_STATUS */
3623 case 0x2f4: /* CONTROL_SEC_ERR_STATUS */
3624 /* Secure mode is not present on general-pusrpose device. Outside
3625 * secure mode these values cannot be read or written. */
3626 return 0;
3628 case 0x2d8: /* CONTROL_OCM_RAM_PERM */
3629 return 0xff;
3630 case 0x2dc: /* CONTROL_OCM_PUB_RAM_ADD */
3631 case 0x2e0: /* CONTROL_EXT_SEC_RAM_START_ADD */
3632 case 0x2e4: /* CONTROL_EXT_SEC_RAM_STOP_ADD */
3633 /* No secure mode so no Extended Secure RAM present. */
3634 return 0;
3636 case 0x2f8: /* CONTROL_STATUS */
3637 /* Device Type => General-purpose */
3638 return 0x0300;
3639 case 0x2fc: /* CONTROL_GENERAL_PURPOSE_STATUS */
3641 case 0x300: /* CONTROL_RPUB_KEY_H_0 */
3642 case 0x304: /* CONTROL_RPUB_KEY_H_1 */
3643 case 0x308: /* CONTROL_RPUB_KEY_H_2 */
3644 case 0x30c: /* CONTROL_RPUB_KEY_H_3 */
3645 return 0xdecafbad;
3647 case 0x310: /* CONTROL_RAND_KEY_0 */
3648 case 0x314: /* CONTROL_RAND_KEY_1 */
3649 case 0x318: /* CONTROL_RAND_KEY_2 */
3650 case 0x31c: /* CONTROL_RAND_KEY_3 */
3651 case 0x320: /* CONTROL_CUST_KEY_0 */
3652 case 0x324: /* CONTROL_CUST_KEY_1 */
3653 case 0x330: /* CONTROL_TEST_KEY_0 */
3654 case 0x334: /* CONTROL_TEST_KEY_1 */
3655 case 0x338: /* CONTROL_TEST_KEY_2 */
3656 case 0x33c: /* CONTROL_TEST_KEY_3 */
3657 case 0x340: /* CONTROL_TEST_KEY_4 */
3658 case 0x344: /* CONTROL_TEST_KEY_5 */
3659 case 0x348: /* CONTROL_TEST_KEY_6 */
3660 case 0x34c: /* CONTROL_TEST_KEY_7 */
3661 case 0x350: /* CONTROL_TEST_KEY_8 */
3662 case 0x354: /* CONTROL_TEST_KEY_9 */
3663 /* Can only be accessed in secure mode and when C_FieldAccEnable
3664 * bit is set in CONTROL_SEC_CTRL.
3665 * TODO: otherwise an interconnect access error is generated. */
3666 return 0;
3669 OMAP_BAD_REG(addr);
3670 return 0;
3673 static void omap_sysctl_write8(void *opaque, target_phys_addr_t addr,
3674 uint32_t value)
3676 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3677 int pad_offset, byte_offset;
3678 int prev_value;
3680 switch (addr) {
3681 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3682 pad_offset = (addr - 0x30) >> 2;
3683 byte_offset = (addr - 0x30) & (4 - 1);
3685 prev_value = s->padconf[pad_offset];
3686 prev_value &= ~(0xff << (byte_offset * 8));
3687 prev_value |= ((value & 0x1f1f1f1f) << (byte_offset * 8)) & 0x1f1f1f1f;
3688 s->padconf[pad_offset] = prev_value;
3689 break;
3691 default:
3692 OMAP_BAD_REG(addr);
3693 break;
3697 static void omap_sysctl_write(void *opaque, target_phys_addr_t addr,
3698 uint32_t value)
3700 struct omap_sysctl_s *s = (struct omap_sysctl_s *) opaque;
3702 switch (addr) {
3703 case 0x000: /* CONTROL_REVISION */
3704 case 0x2a4: /* CONTROL_MSUSPENDMUX_5 */
3705 case 0x2c0: /* CONTROL_PSA_VALUE */
3706 case 0x2f8: /* CONTROL_STATUS */
3707 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 */
3712 case 0x310: /* CONTROL_RAND_KEY_0 */
3713 case 0x314: /* CONTROL_RAND_KEY_1 */
3714 case 0x318: /* CONTROL_RAND_KEY_2 */
3715 case 0x31c: /* CONTROL_RAND_KEY_3 */
3716 case 0x320: /* CONTROL_CUST_KEY_0 */
3717 case 0x324: /* CONTROL_CUST_KEY_1 */
3718 case 0x330: /* CONTROL_TEST_KEY_0 */
3719 case 0x334: /* CONTROL_TEST_KEY_1 */
3720 case 0x338: /* CONTROL_TEST_KEY_2 */
3721 case 0x33c: /* CONTROL_TEST_KEY_3 */
3722 case 0x340: /* CONTROL_TEST_KEY_4 */
3723 case 0x344: /* CONTROL_TEST_KEY_5 */
3724 case 0x348: /* CONTROL_TEST_KEY_6 */
3725 case 0x34c: /* CONTROL_TEST_KEY_7 */
3726 case 0x350: /* CONTROL_TEST_KEY_8 */
3727 case 0x354: /* CONTROL_TEST_KEY_9 */
3728 OMAP_RO_REG(addr);
3729 return;
3731 case 0x010: /* CONTROL_SYSCONFIG */
3732 s->sysconfig = value & 0x1e;
3733 break;
3735 case 0x030 ... 0x140: /* CONTROL_PADCONF - only used in the POP */
3736 /* XXX: should check constant bits */
3737 s->padconf[(addr - 0x30) >> 2] = value & 0x1f1f1f1f;
3738 break;
3740 case 0x270: /* CONTROL_DEBOBS */
3741 s->obs = value & 0xff;
3742 break;
3744 case 0x274: /* CONTROL_DEVCONF */
3745 s->devconfig = value & 0xffffc7ff;
3746 break;
3748 case 0x28c: /* CONTROL_EMU_SUPPORT */
3749 break;
3751 case 0x290: /* CONTROL_MSUSPENDMUX_0 */
3752 s->msuspendmux[0] = value & 0x3fffffff;
3753 break;
3754 case 0x294: /* CONTROL_MSUSPENDMUX_1 */
3755 s->msuspendmux[1] = value & 0x3fffffff;
3756 break;
3757 case 0x298: /* CONTROL_MSUSPENDMUX_2 */
3758 s->msuspendmux[2] = value & 0x3fffffff;
3759 break;
3760 case 0x29c: /* CONTROL_MSUSPENDMUX_3 */
3761 s->msuspendmux[3] = value & 0x3fffffff;
3762 break;
3763 case 0x2a0: /* CONTROL_MSUSPENDMUX_4 */
3764 s->msuspendmux[4] = value & 0x3fffffff;
3765 break;
3767 case 0x2b8: /* CONTROL_PSA_CTRL */
3768 s->psaconfig = value & 0x1c;
3769 s->psaconfig |= (value & 0x20) ? 2 : 1;
3770 break;
3771 case 0x2bc: /* CONTROL_PSA_CMD */
3772 break;
3774 case 0x2b0: /* CONTROL_SEC_CTRL */
3775 case 0x2b4: /* CONTROL_SEC_TEST */
3776 case 0x2d0: /* CONTROL_SEC_EMU */
3777 case 0x2d4: /* CONTROL_SEC_TAP */
3778 case 0x2d8: /* CONTROL_OCM_RAM_PERM */
3779 case 0x2dc: /* CONTROL_OCM_PUB_RAM_ADD */
3780 case 0x2e0: /* CONTROL_EXT_SEC_RAM_START_ADD */
3781 case 0x2e4: /* CONTROL_EXT_SEC_RAM_STOP_ADD */
3782 case 0x2f0: /* CONTROL_SEC_STATUS */
3783 case 0x2f4: /* CONTROL_SEC_ERR_STATUS */
3784 break;
3786 default:
3787 OMAP_BAD_REG(addr);
3788 return;
3792 static CPUReadMemoryFunc *omap_sysctl_readfn[] = {
3793 omap_sysctl_read8,
3794 omap_badwidth_read32, /* TODO */
3795 omap_sysctl_read,
3798 static CPUWriteMemoryFunc *omap_sysctl_writefn[] = {
3799 omap_sysctl_write8,
3800 omap_badwidth_write32, /* TODO */
3801 omap_sysctl_write,
3804 static void omap_sysctl_reset(struct omap_sysctl_s *s)
3806 /* (power-on reset) */
3807 s->sysconfig = 0;
3808 s->obs = 0;
3809 s->devconfig = 0x0c000000;
3810 s->msuspendmux[0] = 0x00000000;
3811 s->msuspendmux[1] = 0x00000000;
3812 s->msuspendmux[2] = 0x00000000;
3813 s->msuspendmux[3] = 0x00000000;
3814 s->msuspendmux[4] = 0x00000000;
3815 s->psaconfig = 1;
3817 s->padconf[0x00] = 0x000f0f0f;
3818 s->padconf[0x01] = 0x00000000;
3819 s->padconf[0x02] = 0x00000000;
3820 s->padconf[0x03] = 0x00000000;
3821 s->padconf[0x04] = 0x00000000;
3822 s->padconf[0x05] = 0x00000000;
3823 s->padconf[0x06] = 0x00000000;
3824 s->padconf[0x07] = 0x00000000;
3825 s->padconf[0x08] = 0x08080800;
3826 s->padconf[0x09] = 0x08080808;
3827 s->padconf[0x0a] = 0x08080808;
3828 s->padconf[0x0b] = 0x08080808;
3829 s->padconf[0x0c] = 0x08080808;
3830 s->padconf[0x0d] = 0x08080800;
3831 s->padconf[0x0e] = 0x08080808;
3832 s->padconf[0x0f] = 0x08080808;
3833 s->padconf[0x10] = 0x18181808; /* | 0x07070700 if SBoot3 */
3834 s->padconf[0x11] = 0x18181818; /* | 0x07070707 if SBoot3 */
3835 s->padconf[0x12] = 0x18181818; /* | 0x07070707 if SBoot3 */
3836 s->padconf[0x13] = 0x18181818; /* | 0x07070707 if SBoot3 */
3837 s->padconf[0x14] = 0x18181818; /* | 0x00070707 if SBoot3 */
3838 s->padconf[0x15] = 0x18181818;
3839 s->padconf[0x16] = 0x18181818; /* | 0x07000000 if SBoot3 */
3840 s->padconf[0x17] = 0x1f001f00;
3841 s->padconf[0x18] = 0x1f1f1f1f;
3842 s->padconf[0x19] = 0x00000000;
3843 s->padconf[0x1a] = 0x1f180000;
3844 s->padconf[0x1b] = 0x00001f1f;
3845 s->padconf[0x1c] = 0x1f001f00;
3846 s->padconf[0x1d] = 0x00000000;
3847 s->padconf[0x1e] = 0x00000000;
3848 s->padconf[0x1f] = 0x08000000;
3849 s->padconf[0x20] = 0x08080808;
3850 s->padconf[0x21] = 0x08080808;
3851 s->padconf[0x22] = 0x0f080808;
3852 s->padconf[0x23] = 0x0f0f0f0f;
3853 s->padconf[0x24] = 0x000f0f0f;
3854 s->padconf[0x25] = 0x1f1f1f0f;
3855 s->padconf[0x26] = 0x080f0f1f;
3856 s->padconf[0x27] = 0x070f1808;
3857 s->padconf[0x28] = 0x0f070707;
3858 s->padconf[0x29] = 0x000f0f1f;
3859 s->padconf[0x2a] = 0x0f0f0f1f;
3860 s->padconf[0x2b] = 0x08000000;
3861 s->padconf[0x2c] = 0x0000001f;
3862 s->padconf[0x2d] = 0x0f0f1f00;
3863 s->padconf[0x2e] = 0x1f1f0f0f;
3864 s->padconf[0x2f] = 0x0f1f1f1f;
3865 s->padconf[0x30] = 0x0f0f0f0f;
3866 s->padconf[0x31] = 0x0f1f0f1f;
3867 s->padconf[0x32] = 0x0f0f0f0f;
3868 s->padconf[0x33] = 0x0f1f0f1f;
3869 s->padconf[0x34] = 0x1f1f0f0f;
3870 s->padconf[0x35] = 0x0f0f1f1f;
3871 s->padconf[0x36] = 0x0f0f1f0f;
3872 s->padconf[0x37] = 0x0f0f0f0f;
3873 s->padconf[0x38] = 0x1f18180f;
3874 s->padconf[0x39] = 0x1f1f1f1f;
3875 s->padconf[0x3a] = 0x00001f1f;
3876 s->padconf[0x3b] = 0x00000000;
3877 s->padconf[0x3c] = 0x00000000;
3878 s->padconf[0x3d] = 0x0f0f0f0f;
3879 s->padconf[0x3e] = 0x18000f0f;
3880 s->padconf[0x3f] = 0x00070000;
3881 s->padconf[0x40] = 0x00000707;
3882 s->padconf[0x41] = 0x0f1f0700;
3883 s->padconf[0x42] = 0x1f1f070f;
3884 s->padconf[0x43] = 0x0008081f;
3885 s->padconf[0x44] = 0x00000800;
3888 struct omap_sysctl_s *omap_sysctl_init(struct omap_target_agent_s *ta,
3889 omap_clk iclk, struct omap_mpu_state_s *mpu)
3891 int iomemtype;
3892 struct omap_sysctl_s *s = (struct omap_sysctl_s *)
3893 qemu_mallocz(sizeof(struct omap_sysctl_s));
3895 s->mpu = mpu;
3896 omap_sysctl_reset(s);
3898 iomemtype = l4_register_io_memory(0, omap_sysctl_readfn,
3899 omap_sysctl_writefn, s);
3900 omap_l4_attach(ta, 0, iomemtype);
3901 omap_l4_attach(ta, 0, iomemtype);
3903 return s;
3906 /* SDRAM Controller Subsystem */
3907 struct omap_sdrc_s {
3908 uint8_t config;
3911 static void omap_sdrc_reset(struct omap_sdrc_s *s)
3913 s->config = 0x10;
3916 static uint32_t omap_sdrc_read(void *opaque, target_phys_addr_t addr)
3918 struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
3920 switch (addr) {
3921 case 0x00: /* SDRC_REVISION */
3922 return 0x20;
3924 case 0x10: /* SDRC_SYSCONFIG */
3925 return s->config;
3927 case 0x14: /* SDRC_SYSSTATUS */
3928 return 1; /* RESETDONE */
3930 case 0x40: /* SDRC_CS_CFG */
3931 case 0x44: /* SDRC_SHARING */
3932 case 0x48: /* SDRC_ERR_ADDR */
3933 case 0x4c: /* SDRC_ERR_TYPE */
3934 case 0x60: /* SDRC_DLLA_SCTRL */
3935 case 0x64: /* SDRC_DLLA_STATUS */
3936 case 0x68: /* SDRC_DLLB_CTRL */
3937 case 0x6c: /* SDRC_DLLB_STATUS */
3938 case 0x70: /* SDRC_POWER */
3939 case 0x80: /* SDRC_MCFG_0 */
3940 case 0x84: /* SDRC_MR_0 */
3941 case 0x88: /* SDRC_EMR1_0 */
3942 case 0x8c: /* SDRC_EMR2_0 */
3943 case 0x90: /* SDRC_EMR3_0 */
3944 case 0x94: /* SDRC_DCDL1_CTRL */
3945 case 0x98: /* SDRC_DCDL2_CTRL */
3946 case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
3947 case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
3948 case 0xa4: /* SDRC_RFR_CTRL_0 */
3949 case 0xa8: /* SDRC_MANUAL_0 */
3950 case 0xb0: /* SDRC_MCFG_1 */
3951 case 0xb4: /* SDRC_MR_1 */
3952 case 0xb8: /* SDRC_EMR1_1 */
3953 case 0xbc: /* SDRC_EMR2_1 */
3954 case 0xc0: /* SDRC_EMR3_1 */
3955 case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
3956 case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
3957 case 0xd4: /* SDRC_RFR_CTRL_1 */
3958 case 0xd8: /* SDRC_MANUAL_1 */
3959 return 0x00;
3962 OMAP_BAD_REG(addr);
3963 return 0;
3966 static void omap_sdrc_write(void *opaque, target_phys_addr_t addr,
3967 uint32_t value)
3969 struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
3971 switch (addr) {
3972 case 0x00: /* SDRC_REVISION */
3973 case 0x14: /* SDRC_SYSSTATUS */
3974 case 0x48: /* SDRC_ERR_ADDR */
3975 case 0x64: /* SDRC_DLLA_STATUS */
3976 case 0x6c: /* SDRC_DLLB_STATUS */
3977 OMAP_RO_REG(addr);
3978 return;
3980 case 0x10: /* SDRC_SYSCONFIG */
3981 if ((value >> 3) != 0x2)
3982 fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
3983 __FUNCTION__, value >> 3);
3984 if (value & 2)
3985 omap_sdrc_reset(s);
3986 s->config = value & 0x18;
3987 break;
3989 case 0x40: /* SDRC_CS_CFG */
3990 case 0x44: /* SDRC_SHARING */
3991 case 0x4c: /* SDRC_ERR_TYPE */
3992 case 0x60: /* SDRC_DLLA_SCTRL */
3993 case 0x68: /* SDRC_DLLB_CTRL */
3994 case 0x70: /* SDRC_POWER */
3995 case 0x80: /* SDRC_MCFG_0 */
3996 case 0x84: /* SDRC_MR_0 */
3997 case 0x88: /* SDRC_EMR1_0 */
3998 case 0x8c: /* SDRC_EMR2_0 */
3999 case 0x90: /* SDRC_EMR3_0 */
4000 case 0x94: /* SDRC_DCDL1_CTRL */
4001 case 0x98: /* SDRC_DCDL2_CTRL */
4002 case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
4003 case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
4004 case 0xa4: /* SDRC_RFR_CTRL_0 */
4005 case 0xa8: /* SDRC_MANUAL_0 */
4006 case 0xb0: /* SDRC_MCFG_1 */
4007 case 0xb4: /* SDRC_MR_1 */
4008 case 0xb8: /* SDRC_EMR1_1 */
4009 case 0xbc: /* SDRC_EMR2_1 */
4010 case 0xc0: /* SDRC_EMR3_1 */
4011 case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
4012 case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
4013 case 0xd4: /* SDRC_RFR_CTRL_1 */
4014 case 0xd8: /* SDRC_MANUAL_1 */
4015 break;
4017 default:
4018 OMAP_BAD_REG(addr);
4019 return;
4023 static CPUReadMemoryFunc *omap_sdrc_readfn[] = {
4024 omap_badwidth_read32,
4025 omap_badwidth_read32,
4026 omap_sdrc_read,
4029 static CPUWriteMemoryFunc *omap_sdrc_writefn[] = {
4030 omap_badwidth_write32,
4031 omap_badwidth_write32,
4032 omap_sdrc_write,
4035 struct omap_sdrc_s *omap_sdrc_init(target_phys_addr_t base)
4037 int iomemtype;
4038 struct omap_sdrc_s *s = (struct omap_sdrc_s *)
4039 qemu_mallocz(sizeof(struct omap_sdrc_s));
4041 omap_sdrc_reset(s);
4043 iomemtype = cpu_register_io_memory(0, omap_sdrc_readfn,
4044 omap_sdrc_writefn, s);
4045 cpu_register_physical_memory(base, 0x1000, iomemtype);
4047 return s;
4050 /* General-Purpose Memory Controller */
4051 struct omap_gpmc_s {
4052 qemu_irq irq;
4054 uint8_t sysconfig;
4055 uint16_t irqst;
4056 uint16_t irqen;
4057 uint16_t timeout;
4058 uint16_t config;
4059 uint32_t prefconfig[2];
4060 int prefcontrol;
4061 int preffifo;
4062 int prefcount;
4063 struct omap_gpmc_cs_file_s {
4064 uint32_t config[7];
4065 target_phys_addr_t base;
4066 size_t size;
4067 int iomemtype;
4068 void (*base_update)(void *opaque, target_phys_addr_t new);
4069 void (*unmap)(void *opaque);
4070 void *opaque;
4071 } cs_file[8];
4072 int ecc_cs;
4073 int ecc_ptr;
4074 uint32_t ecc_cfg;
4075 struct ecc_state_s ecc[9];
4078 static void omap_gpmc_int_update(struct omap_gpmc_s *s)
4080 qemu_set_irq(s->irq, s->irqen & s->irqst);
4083 static void omap_gpmc_cs_map(struct omap_gpmc_cs_file_s *f, int base, int mask)
4085 /* TODO: check for overlapping regions and report access errors */
4086 if ((mask != 0x8 && mask != 0xc && mask != 0xe && mask != 0xf) ||
4087 (base < 0 || base >= 0x40) ||
4088 (base & 0x0f & ~mask)) {
4089 fprintf(stderr, "%s: wrong cs address mapping/decoding!\n",
4090 __FUNCTION__);
4091 return;
4094 if (!f->opaque)
4095 return;
4097 f->base = base << 24;
4098 f->size = (0x0fffffff & ~(mask << 24)) + 1;
4099 /* TODO: rather than setting the size of the mapping (which should be
4100 * constant), the mask should cause wrapping of the address space, so
4101 * that the same memory becomes accessible at every <i>size</i> bytes
4102 * starting from <i>base</i>. */
4103 if (f->iomemtype)
4104 cpu_register_physical_memory(f->base, f->size, f->iomemtype);
4106 if (f->base_update)
4107 f->base_update(f->opaque, f->base);
4110 static void omap_gpmc_cs_unmap(struct omap_gpmc_cs_file_s *f)
4112 if (f->size) {
4113 if (f->unmap)
4114 f->unmap(f->opaque);
4115 if (f->iomemtype)
4116 cpu_register_physical_memory(f->base, f->size, IO_MEM_UNASSIGNED);
4117 f->base = 0;
4118 f->size = 0;
4122 static void omap_gpmc_reset(struct omap_gpmc_s *s)
4124 int i;
4126 s->sysconfig = 0;
4127 s->irqst = 0;
4128 s->irqen = 0;
4129 omap_gpmc_int_update(s);
4130 s->timeout = 0;
4131 s->config = 0xa00;
4132 s->prefconfig[0] = 0x00004000;
4133 s->prefconfig[1] = 0x00000000;
4134 s->prefcontrol = 0;
4135 s->preffifo = 0;
4136 s->prefcount = 0;
4137 for (i = 0; i < 8; i ++) {
4138 if (s->cs_file[i].config[6] & (1 << 6)) /* CSVALID */
4139 omap_gpmc_cs_unmap(s->cs_file + i);
4140 s->cs_file[i].config[0] = i ? 1 << 12 : 0;
4141 s->cs_file[i].config[1] = 0x101001;
4142 s->cs_file[i].config[2] = 0x020201;
4143 s->cs_file[i].config[3] = 0x10031003;
4144 s->cs_file[i].config[4] = 0x10f1111;
4145 s->cs_file[i].config[5] = 0;
4146 s->cs_file[i].config[6] = 0xf00 | (i ? 0 : 1 << 6);
4147 if (s->cs_file[i].config[6] & (1 << 6)) /* CSVALID */
4148 omap_gpmc_cs_map(&s->cs_file[i],
4149 s->cs_file[i].config[6] & 0x1f, /* MASKADDR */
4150 (s->cs_file[i].config[6] >> 8 & 0xf)); /* BASEADDR */
4152 omap_gpmc_cs_map(s->cs_file, 0, 0xf);
4153 s->ecc_cs = 0;
4154 s->ecc_ptr = 0;
4155 s->ecc_cfg = 0x3fcff000;
4156 for (i = 0; i < 9; i ++)
4157 ecc_reset(&s->ecc[i]);
4160 static uint32_t omap_gpmc_read(void *opaque, target_phys_addr_t addr)
4162 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4163 int cs;
4164 struct omap_gpmc_cs_file_s *f;
4166 switch (addr) {
4167 case 0x000: /* GPMC_REVISION */
4168 return 0x20;
4170 case 0x010: /* GPMC_SYSCONFIG */
4171 return s->sysconfig;
4173 case 0x014: /* GPMC_SYSSTATUS */
4174 return 1; /* RESETDONE */
4176 case 0x018: /* GPMC_IRQSTATUS */
4177 return s->irqst;
4179 case 0x01c: /* GPMC_IRQENABLE */
4180 return s->irqen;
4182 case 0x040: /* GPMC_TIMEOUT_CONTROL */
4183 return s->timeout;
4185 case 0x044: /* GPMC_ERR_ADDRESS */
4186 case 0x048: /* GPMC_ERR_TYPE */
4187 return 0;
4189 case 0x050: /* GPMC_CONFIG */
4190 return s->config;
4192 case 0x054: /* GPMC_STATUS */
4193 return 0x001;
4195 case 0x060 ... 0x1d4:
4196 cs = (addr - 0x060) / 0x30;
4197 addr -= cs * 0x30;
4198 f = s->cs_file + cs;
4199 switch (addr) {
4200 case 0x60: /* GPMC_CONFIG1 */
4201 return f->config[0];
4202 case 0x64: /* GPMC_CONFIG2 */
4203 return f->config[1];
4204 case 0x68: /* GPMC_CONFIG3 */
4205 return f->config[2];
4206 case 0x6c: /* GPMC_CONFIG4 */
4207 return f->config[3];
4208 case 0x70: /* GPMC_CONFIG5 */
4209 return f->config[4];
4210 case 0x74: /* GPMC_CONFIG6 */
4211 return f->config[5];
4212 case 0x78: /* GPMC_CONFIG7 */
4213 return f->config[6];
4214 case 0x84: /* GPMC_NAND_DATA */
4215 return 0;
4217 break;
4219 case 0x1e0: /* GPMC_PREFETCH_CONFIG1 */
4220 return s->prefconfig[0];
4221 case 0x1e4: /* GPMC_PREFETCH_CONFIG2 */
4222 return s->prefconfig[1];
4223 case 0x1ec: /* GPMC_PREFETCH_CONTROL */
4224 return s->prefcontrol;
4225 case 0x1f0: /* GPMC_PREFETCH_STATUS */
4226 return (s->preffifo << 24) |
4227 ((s->preffifo >
4228 ((s->prefconfig[0] >> 8) & 0x7f) ? 1 : 0) << 16) |
4229 s->prefcount;
4231 case 0x1f4: /* GPMC_ECC_CONFIG */
4232 return s->ecc_cs;
4233 case 0x1f8: /* GPMC_ECC_CONTROL */
4234 return s->ecc_ptr;
4235 case 0x1fc: /* GPMC_ECC_SIZE_CONFIG */
4236 return s->ecc_cfg;
4237 case 0x200 ... 0x220: /* GPMC_ECC_RESULT */
4238 cs = (addr & 0x1f) >> 2;
4239 /* TODO: check correctness */
4240 return
4241 ((s->ecc[cs].cp & 0x07) << 0) |
4242 ((s->ecc[cs].cp & 0x38) << 13) |
4243 ((s->ecc[cs].lp[0] & 0x1ff) << 3) |
4244 ((s->ecc[cs].lp[1] & 0x1ff) << 19);
4246 case 0x230: /* GPMC_TESTMODE_CTRL */
4247 return 0;
4248 case 0x234: /* GPMC_PSA_LSB */
4249 case 0x238: /* GPMC_PSA_MSB */
4250 return 0x00000000;
4253 OMAP_BAD_REG(addr);
4254 return 0;
4257 static void omap_gpmc_write(void *opaque, target_phys_addr_t addr,
4258 uint32_t value)
4260 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
4261 int cs;
4262 struct omap_gpmc_cs_file_s *f;
4264 switch (addr) {
4265 case 0x000: /* GPMC_REVISION */
4266 case 0x014: /* GPMC_SYSSTATUS */
4267 case 0x054: /* GPMC_STATUS */
4268 case 0x1f0: /* GPMC_PREFETCH_STATUS */
4269 case 0x200 ... 0x220: /* GPMC_ECC_RESULT */
4270 case 0x234: /* GPMC_PSA_LSB */
4271 case 0x238: /* GPMC_PSA_MSB */
4272 OMAP_RO_REG(addr);
4273 break;
4275 case 0x010: /* GPMC_SYSCONFIG */
4276 if ((value >> 3) == 0x3)
4277 fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
4278 __FUNCTION__, value >> 3);
4279 if (value & 2)
4280 omap_gpmc_reset(s);
4281 s->sysconfig = value & 0x19;
4282 break;
4284 case 0x018: /* GPMC_IRQSTATUS */
4285 s->irqen = ~value;
4286 omap_gpmc_int_update(s);
4287 break;
4289 case 0x01c: /* GPMC_IRQENABLE */
4290 s->irqen = value & 0xf03;
4291 omap_gpmc_int_update(s);
4292 break;
4294 case 0x040: /* GPMC_TIMEOUT_CONTROL */
4295 s->timeout = value & 0x1ff1;
4296 break;
4298 case 0x044: /* GPMC_ERR_ADDRESS */
4299 case 0x048: /* GPMC_ERR_TYPE */
4300 break;
4302 case 0x050: /* GPMC_CONFIG */
4303 s->config = value & 0xf13;
4304 break;
4306 case 0x060 ... 0x1d4:
4307 cs = (addr - 0x060) / 0x30;
4308 addr -= cs * 0x30;
4309 f = s->cs_file + cs;
4310 switch (addr) {
4311 case 0x60: /* GPMC_CONFIG1 */
4312 f->config[0] = value & 0xffef3e13;
4313 break;
4314 case 0x64: /* GPMC_CONFIG2 */
4315 f->config[1] = value & 0x001f1f8f;
4316 break;
4317 case 0x68: /* GPMC_CONFIG3 */
4318 f->config[2] = value & 0x001f1f8f;
4319 break;
4320 case 0x6c: /* GPMC_CONFIG4 */
4321 f->config[3] = value & 0x1f8f1f8f;
4322 break;
4323 case 0x70: /* GPMC_CONFIG5 */
4324 f->config[4] = value & 0x0f1f1f1f;
4325 break;
4326 case 0x74: /* GPMC_CONFIG6 */
4327 f->config[5] = value & 0x00000fcf;
4328 break;
4329 case 0x78: /* GPMC_CONFIG7 */
4330 if ((f->config[6] ^ value) & 0xf7f) {
4331 if (f->config[6] & (1 << 6)) /* CSVALID */
4332 omap_gpmc_cs_unmap(f);
4333 if (value & (1 << 6)) /* CSVALID */
4334 omap_gpmc_cs_map(f, value & 0x1f, /* MASKADDR */
4335 (value >> 8 & 0xf)); /* BASEADDR */
4337 f->config[6] = value & 0x00000f7f;
4338 break;
4339 case 0x7c: /* GPMC_NAND_COMMAND */
4340 case 0x80: /* GPMC_NAND_ADDRESS */
4341 case 0x84: /* GPMC_NAND_DATA */
4342 break;
4344 default:
4345 goto bad_reg;
4347 break;
4349 case 0x1e0: /* GPMC_PREFETCH_CONFIG1 */
4350 s->prefconfig[0] = value & 0x7f8f7fbf;
4351 /* TODO: update interrupts, fifos, dmas */
4352 break;
4354 case 0x1e4: /* GPMC_PREFETCH_CONFIG2 */
4355 s->prefconfig[1] = value & 0x3fff;
4356 break;
4358 case 0x1ec: /* GPMC_PREFETCH_CONTROL */
4359 s->prefcontrol = value & 1;
4360 if (s->prefcontrol) {
4361 if (s->prefconfig[0] & 1)
4362 s->preffifo = 0x40;
4363 else
4364 s->preffifo = 0x00;
4366 /* TODO: start */
4367 break;
4369 case 0x1f4: /* GPMC_ECC_CONFIG */
4370 s->ecc_cs = 0x8f;
4371 break;
4372 case 0x1f8: /* GPMC_ECC_CONTROL */
4373 if (value & (1 << 8))
4374 for (cs = 0; cs < 9; cs ++)
4375 ecc_reset(&s->ecc[cs]);
4376 s->ecc_ptr = value & 0xf;
4377 if (s->ecc_ptr == 0 || s->ecc_ptr > 9) {
4378 s->ecc_ptr = 0;
4379 s->ecc_cs &= ~1;
4381 break;
4382 case 0x1fc: /* GPMC_ECC_SIZE_CONFIG */
4383 s->ecc_cfg = value & 0x3fcff1ff;
4384 break;
4385 case 0x230: /* GPMC_TESTMODE_CTRL */
4386 if (value & 7)
4387 fprintf(stderr, "%s: test mode enable attempt\n", __FUNCTION__);
4388 break;
4390 default:
4391 bad_reg:
4392 OMAP_BAD_REG(addr);
4393 return;
4397 static CPUReadMemoryFunc *omap_gpmc_readfn[] = {
4398 omap_badwidth_read32, /* TODO */
4399 omap_badwidth_read32, /* TODO */
4400 omap_gpmc_read,
4403 static CPUWriteMemoryFunc *omap_gpmc_writefn[] = {
4404 omap_badwidth_write32, /* TODO */
4405 omap_badwidth_write32, /* TODO */
4406 omap_gpmc_write,
4409 struct omap_gpmc_s *omap_gpmc_init(target_phys_addr_t base, qemu_irq irq)
4411 int iomemtype;
4412 struct omap_gpmc_s *s = (struct omap_gpmc_s *)
4413 qemu_mallocz(sizeof(struct omap_gpmc_s));
4415 omap_gpmc_reset(s);
4417 iomemtype = cpu_register_io_memory(0, omap_gpmc_readfn,
4418 omap_gpmc_writefn, s);
4419 cpu_register_physical_memory(base, 0x1000, iomemtype);
4421 return s;
4424 void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, int iomemtype,
4425 void (*base_upd)(void *opaque, target_phys_addr_t new),
4426 void (*unmap)(void *opaque), void *opaque)
4428 struct omap_gpmc_cs_file_s *f;
4430 if (cs < 0 || cs >= 8) {
4431 fprintf(stderr, "%s: bad chip-select %i\n", __FUNCTION__, cs);
4432 exit(-1);
4434 f = &s->cs_file[cs];
4436 f->iomemtype = iomemtype;
4437 f->base_update = base_upd;
4438 f->unmap = unmap;
4439 f->opaque = opaque;
4441 if (f->config[6] & (1 << 6)) /* CSVALID */
4442 omap_gpmc_cs_map(f, f->config[6] & 0x1f, /* MASKADDR */
4443 (f->config[6] >> 8 & 0xf)); /* BASEADDR */
4446 /* General chip reset */
4447 static void omap2_mpu_reset(void *opaque)
4449 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4451 omap_inth_reset(mpu->ih[0]);
4452 omap_dma_reset(mpu->dma);
4453 omap_prcm_reset(mpu->prcm);
4454 omap_sysctl_reset(mpu->sysc);
4455 omap_gp_timer_reset(mpu->gptimer[0]);
4456 omap_gp_timer_reset(mpu->gptimer[1]);
4457 omap_gp_timer_reset(mpu->gptimer[2]);
4458 omap_gp_timer_reset(mpu->gptimer[3]);
4459 omap_gp_timer_reset(mpu->gptimer[4]);
4460 omap_gp_timer_reset(mpu->gptimer[5]);
4461 omap_gp_timer_reset(mpu->gptimer[6]);
4462 omap_gp_timer_reset(mpu->gptimer[7]);
4463 omap_gp_timer_reset(mpu->gptimer[8]);
4464 omap_gp_timer_reset(mpu->gptimer[9]);
4465 omap_gp_timer_reset(mpu->gptimer[10]);
4466 omap_gp_timer_reset(mpu->gptimer[11]);
4467 omap_synctimer_reset(&mpu->synctimer);
4468 omap_sdrc_reset(mpu->sdrc);
4469 omap_gpmc_reset(mpu->gpmc);
4470 omap_dss_reset(mpu->dss);
4471 omap_uart_reset(mpu->uart[0]);
4472 omap_uart_reset(mpu->uart[1]);
4473 omap_uart_reset(mpu->uart[2]);
4474 omap_mmc_reset(mpu->mmc);
4475 omap_gpif_reset(mpu->gpif);
4476 omap_mcspi_reset(mpu->mcspi[0]);
4477 omap_mcspi_reset(mpu->mcspi[1]);
4478 omap_i2c_reset(mpu->i2c[0]);
4479 omap_i2c_reset(mpu->i2c[1]);
4480 cpu_reset(mpu->env);
4483 static int omap2_validate_addr(struct omap_mpu_state_s *s,
4484 target_phys_addr_t addr)
4486 return 1;
4489 static const struct dma_irq_map omap2_dma_irq_map[] = {
4490 { 0, OMAP_INT_24XX_SDMA_IRQ0 },
4491 { 0, OMAP_INT_24XX_SDMA_IRQ1 },
4492 { 0, OMAP_INT_24XX_SDMA_IRQ2 },
4493 { 0, OMAP_INT_24XX_SDMA_IRQ3 },
4496 struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,
4497 DisplayState *ds, const char *core)
4499 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
4500 qemu_mallocz(sizeof(struct omap_mpu_state_s));
4501 ram_addr_t sram_base, q2_base;
4502 qemu_irq *cpu_irq;
4503 qemu_irq dma_irqs[4];
4504 omap_clk gpio_clks[4];
4505 int sdindex;
4506 int i;
4508 /* Core */
4509 s->mpu_model = omap2420;
4510 s->env = cpu_init(core ?: "arm1136-r2");
4511 if (!s->env) {
4512 fprintf(stderr, "Unable to find CPU definition\n");
4513 exit(1);
4515 s->sdram_size = sdram_size;
4516 s->sram_size = OMAP242X_SRAM_SIZE;
4518 s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0];
4520 /* Clocks */
4521 omap_clk_init(s);
4523 /* Memory-mapped stuff */
4524 cpu_register_physical_memory(OMAP2_Q2_BASE, s->sdram_size,
4525 (q2_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
4526 cpu_register_physical_memory(OMAP2_SRAM_BASE, s->sram_size,
4527 (sram_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
4529 s->l4 = omap_l4_init(OMAP2_L4_BASE, 54);
4531 /* Actually mapped at any 2K boundary in the ARM11 private-peripheral if */
4532 cpu_irq = arm_pic_init_cpu(s->env);
4533 s->ih[0] = omap2_inth_init(0x480fe000, 0x1000, 3, &s->irq[0],
4534 cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ],
4535 omap_findclk(s, "mpu_intc_fclk"),
4536 omap_findclk(s, "mpu_intc_iclk"));
4538 s->prcm = omap_prcm_init(omap_l4tao(s->l4, 3),
4539 s->irq[0][OMAP_INT_24XX_PRCM_MPU_IRQ], NULL, NULL, s);
4541 s->sysc = omap_sysctl_init(omap_l4tao(s->l4, 1),
4542 omap_findclk(s, "omapctrl_iclk"), s);
4544 for (i = 0; i < 4; i ++)
4545 dma_irqs[i] =
4546 s->irq[omap2_dma_irq_map[i].ih][omap2_dma_irq_map[i].intr];
4547 s->dma = omap_dma4_init(0x48056000, dma_irqs, s, 256, 32,
4548 omap_findclk(s, "sdma_iclk"),
4549 omap_findclk(s, "sdma_fclk"));
4550 s->port->addr_valid = omap2_validate_addr;
4552 /* Register SDRAM and SRAM ports for fast DMA transfers. */
4553 soc_dma_port_add_mem_ram(s->dma, q2_base, OMAP2_Q2_BASE, s->sdram_size);
4554 soc_dma_port_add_mem_ram(s->dma, sram_base, OMAP2_SRAM_BASE, s->sram_size);
4556 s->uart[0] = omap2_uart_init(omap_l4ta(s->l4, 19),
4557 s->irq[0][OMAP_INT_24XX_UART1_IRQ],
4558 omap_findclk(s, "uart1_fclk"),
4559 omap_findclk(s, "uart1_iclk"),
4560 s->drq[OMAP24XX_DMA_UART1_TX],
4561 s->drq[OMAP24XX_DMA_UART1_RX], serial_hds[0]);
4562 s->uart[1] = omap2_uart_init(omap_l4ta(s->l4, 20),
4563 s->irq[0][OMAP_INT_24XX_UART2_IRQ],
4564 omap_findclk(s, "uart2_fclk"),
4565 omap_findclk(s, "uart2_iclk"),
4566 s->drq[OMAP24XX_DMA_UART2_TX],
4567 s->drq[OMAP24XX_DMA_UART2_RX],
4568 serial_hds[0] ? serial_hds[1] : 0);
4569 s->uart[2] = omap2_uart_init(omap_l4ta(s->l4, 21),
4570 s->irq[0][OMAP_INT_24XX_UART3_IRQ],
4571 omap_findclk(s, "uart3_fclk"),
4572 omap_findclk(s, "uart3_iclk"),
4573 s->drq[OMAP24XX_DMA_UART3_TX],
4574 s->drq[OMAP24XX_DMA_UART3_RX],
4575 serial_hds[0] && serial_hds[1] ? serial_hds[2] : 0);
4577 s->gptimer[0] = omap_gp_timer_init(omap_l4ta(s->l4, 7),
4578 s->irq[0][OMAP_INT_24XX_GPTIMER1],
4579 omap_findclk(s, "wu_gpt1_clk"),
4580 omap_findclk(s, "wu_l4_iclk"));
4581 s->gptimer[1] = omap_gp_timer_init(omap_l4ta(s->l4, 8),
4582 s->irq[0][OMAP_INT_24XX_GPTIMER2],
4583 omap_findclk(s, "core_gpt2_clk"),
4584 omap_findclk(s, "core_l4_iclk"));
4585 s->gptimer[2] = omap_gp_timer_init(omap_l4ta(s->l4, 22),
4586 s->irq[0][OMAP_INT_24XX_GPTIMER3],
4587 omap_findclk(s, "core_gpt3_clk"),
4588 omap_findclk(s, "core_l4_iclk"));
4589 s->gptimer[3] = omap_gp_timer_init(omap_l4ta(s->l4, 23),
4590 s->irq[0][OMAP_INT_24XX_GPTIMER4],
4591 omap_findclk(s, "core_gpt4_clk"),
4592 omap_findclk(s, "core_l4_iclk"));
4593 s->gptimer[4] = omap_gp_timer_init(omap_l4ta(s->l4, 24),
4594 s->irq[0][OMAP_INT_24XX_GPTIMER5],
4595 omap_findclk(s, "core_gpt5_clk"),
4596 omap_findclk(s, "core_l4_iclk"));
4597 s->gptimer[5] = omap_gp_timer_init(omap_l4ta(s->l4, 25),
4598 s->irq[0][OMAP_INT_24XX_GPTIMER6],
4599 omap_findclk(s, "core_gpt6_clk"),
4600 omap_findclk(s, "core_l4_iclk"));
4601 s->gptimer[6] = omap_gp_timer_init(omap_l4ta(s->l4, 26),
4602 s->irq[0][OMAP_INT_24XX_GPTIMER7],
4603 omap_findclk(s, "core_gpt7_clk"),
4604 omap_findclk(s, "core_l4_iclk"));
4605 s->gptimer[7] = omap_gp_timer_init(omap_l4ta(s->l4, 27),
4606 s->irq[0][OMAP_INT_24XX_GPTIMER8],
4607 omap_findclk(s, "core_gpt8_clk"),
4608 omap_findclk(s, "core_l4_iclk"));
4609 s->gptimer[8] = omap_gp_timer_init(omap_l4ta(s->l4, 28),
4610 s->irq[0][OMAP_INT_24XX_GPTIMER9],
4611 omap_findclk(s, "core_gpt9_clk"),
4612 omap_findclk(s, "core_l4_iclk"));
4613 s->gptimer[9] = omap_gp_timer_init(omap_l4ta(s->l4, 29),
4614 s->irq[0][OMAP_INT_24XX_GPTIMER10],
4615 omap_findclk(s, "core_gpt10_clk"),
4616 omap_findclk(s, "core_l4_iclk"));
4617 s->gptimer[10] = omap_gp_timer_init(omap_l4ta(s->l4, 30),
4618 s->irq[0][OMAP_INT_24XX_GPTIMER11],
4619 omap_findclk(s, "core_gpt11_clk"),
4620 omap_findclk(s, "core_l4_iclk"));
4621 s->gptimer[11] = omap_gp_timer_init(omap_l4ta(s->l4, 31),
4622 s->irq[0][OMAP_INT_24XX_GPTIMER12],
4623 omap_findclk(s, "core_gpt12_clk"),
4624 omap_findclk(s, "core_l4_iclk"));
4626 omap_tap_init(omap_l4ta(s->l4, 2), s);
4628 omap_synctimer_init(omap_l4tao(s->l4, 2), s,
4629 omap_findclk(s, "clk32-kHz"),
4630 omap_findclk(s, "core_l4_iclk"));
4632 s->i2c[0] = omap2_i2c_init(omap_l4tao(s->l4, 5),
4633 s->irq[0][OMAP_INT_24XX_I2C1_IRQ],
4634 &s->drq[OMAP24XX_DMA_I2C1_TX],
4635 omap_findclk(s, "i2c1.fclk"),
4636 omap_findclk(s, "i2c1.iclk"));
4637 s->i2c[1] = omap2_i2c_init(omap_l4tao(s->l4, 6),
4638 s->irq[0][OMAP_INT_24XX_I2C2_IRQ],
4639 &s->drq[OMAP24XX_DMA_I2C2_TX],
4640 omap_findclk(s, "i2c2.fclk"),
4641 omap_findclk(s, "i2c2.iclk"));
4643 gpio_clks[0] = omap_findclk(s, "gpio1_dbclk");
4644 gpio_clks[1] = omap_findclk(s, "gpio2_dbclk");
4645 gpio_clks[2] = omap_findclk(s, "gpio3_dbclk");
4646 gpio_clks[3] = omap_findclk(s, "gpio4_dbclk");
4647 s->gpif = omap2_gpio_init(omap_l4ta(s->l4, 3),
4648 &s->irq[0][OMAP_INT_24XX_GPIO_BANK1],
4649 gpio_clks, omap_findclk(s, "gpio_iclk"), 4);
4651 s->sdrc = omap_sdrc_init(0x68009000);
4652 s->gpmc = omap_gpmc_init(0x6800a000, s->irq[0][OMAP_INT_24XX_GPMC_IRQ]);
4654 sdindex = drive_get_index(IF_SD, 0, 0);
4655 if (sdindex == -1) {
4656 fprintf(stderr, "qemu: missing SecureDigital device\n");
4657 exit(1);
4659 s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9), drives_table[sdindex].bdrv,
4660 s->irq[0][OMAP_INT_24XX_MMC_IRQ],
4661 &s->drq[OMAP24XX_DMA_MMC1_TX],
4662 omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk"));
4664 s->mcspi[0] = omap_mcspi_init(omap_l4ta(s->l4, 35), 4,
4665 s->irq[0][OMAP_INT_24XX_MCSPI1_IRQ],
4666 &s->drq[OMAP24XX_DMA_SPI1_TX0],
4667 omap_findclk(s, "spi1_fclk"),
4668 omap_findclk(s, "spi1_iclk"));
4669 s->mcspi[1] = omap_mcspi_init(omap_l4ta(s->l4, 36), 2,
4670 s->irq[0][OMAP_INT_24XX_MCSPI2_IRQ],
4671 &s->drq[OMAP24XX_DMA_SPI2_TX0],
4672 omap_findclk(s, "spi2_fclk"),
4673 omap_findclk(s, "spi2_iclk"));
4675 s->dss = omap_dss_init(omap_l4ta(s->l4, 10), 0x68000800, ds,
4676 /* XXX wire M_IRQ_25, D_L2_IRQ_30 and I_IRQ_13 together */
4677 s->irq[0][OMAP_INT_24XX_DSS_IRQ], s->drq[OMAP24XX_DMA_DSS],
4678 omap_findclk(s, "dss_clk1"), omap_findclk(s, "dss_clk2"),
4679 omap_findclk(s, "dss_54m_clk"),
4680 omap_findclk(s, "dss_l3_iclk"),
4681 omap_findclk(s, "dss_l4_iclk"));
4683 omap_sti_init(omap_l4ta(s->l4, 18), 0x54000000,
4684 s->irq[0][OMAP_INT_24XX_STI], omap_findclk(s, "emul_ck"),
4685 serial_hds[0] && serial_hds[1] && serial_hds[2] ?
4686 serial_hds[3] : 0);
4688 s->eac = omap_eac_init(omap_l4ta(s->l4, 32),
4689 s->irq[0][OMAP_INT_24XX_EAC_IRQ],
4690 /* Ten consecutive lines */
4691 &s->drq[OMAP24XX_DMA_EAC_AC_RD],
4692 omap_findclk(s, "func_96m_clk"),
4693 omap_findclk(s, "core_l4_iclk"));
4695 /* All register mappings (includin those not currenlty implemented):
4696 * SystemControlMod 48000000 - 48000fff
4697 * SystemControlL4 48001000 - 48001fff
4698 * 32kHz Timer Mod 48004000 - 48004fff
4699 * 32kHz Timer L4 48005000 - 48005fff
4700 * PRCM ModA 48008000 - 480087ff
4701 * PRCM ModB 48008800 - 48008fff
4702 * PRCM L4 48009000 - 48009fff
4703 * TEST-BCM Mod 48012000 - 48012fff
4704 * TEST-BCM L4 48013000 - 48013fff
4705 * TEST-TAP Mod 48014000 - 48014fff
4706 * TEST-TAP L4 48015000 - 48015fff
4707 * GPIO1 Mod 48018000 - 48018fff
4708 * GPIO Top 48019000 - 48019fff
4709 * GPIO2 Mod 4801a000 - 4801afff
4710 * GPIO L4 4801b000 - 4801bfff
4711 * GPIO3 Mod 4801c000 - 4801cfff
4712 * GPIO4 Mod 4801e000 - 4801efff
4713 * WDTIMER1 Mod 48020000 - 48010fff
4714 * WDTIMER Top 48021000 - 48011fff
4715 * WDTIMER2 Mod 48022000 - 48012fff
4716 * WDTIMER L4 48023000 - 48013fff
4717 * WDTIMER3 Mod 48024000 - 48014fff
4718 * WDTIMER3 L4 48025000 - 48015fff
4719 * WDTIMER4 Mod 48026000 - 48016fff
4720 * WDTIMER4 L4 48027000 - 48017fff
4721 * GPTIMER1 Mod 48028000 - 48018fff
4722 * GPTIMER1 L4 48029000 - 48019fff
4723 * GPTIMER2 Mod 4802a000 - 4801afff
4724 * GPTIMER2 L4 4802b000 - 4801bfff
4725 * L4-Config AP 48040000 - 480407ff
4726 * L4-Config IP 48040800 - 48040fff
4727 * L4-Config LA 48041000 - 48041fff
4728 * ARM11ETB Mod 48048000 - 48049fff
4729 * ARM11ETB L4 4804a000 - 4804afff
4730 * DISPLAY Top 48050000 - 480503ff
4731 * DISPLAY DISPC 48050400 - 480507ff
4732 * DISPLAY RFBI 48050800 - 48050bff
4733 * DISPLAY VENC 48050c00 - 48050fff
4734 * DISPLAY L4 48051000 - 48051fff
4735 * CAMERA Top 48052000 - 480523ff
4736 * CAMERA core 48052400 - 480527ff
4737 * CAMERA DMA 48052800 - 48052bff
4738 * CAMERA MMU 48052c00 - 48052fff
4739 * CAMERA L4 48053000 - 48053fff
4740 * SDMA Mod 48056000 - 48056fff
4741 * SDMA L4 48057000 - 48057fff
4742 * SSI Top 48058000 - 48058fff
4743 * SSI GDD 48059000 - 48059fff
4744 * SSI Port1 4805a000 - 4805afff
4745 * SSI Port2 4805b000 - 4805bfff
4746 * SSI L4 4805c000 - 4805cfff
4747 * USB Mod 4805e000 - 480fefff
4748 * USB L4 4805f000 - 480fffff
4749 * WIN_TRACER1 Mod 48060000 - 48060fff
4750 * WIN_TRACER1 L4 48061000 - 48061fff
4751 * WIN_TRACER2 Mod 48062000 - 48062fff
4752 * WIN_TRACER2 L4 48063000 - 48063fff
4753 * WIN_TRACER3 Mod 48064000 - 48064fff
4754 * WIN_TRACER3 L4 48065000 - 48065fff
4755 * WIN_TRACER4 Top 48066000 - 480660ff
4756 * WIN_TRACER4 ETT 48066100 - 480661ff
4757 * WIN_TRACER4 WT 48066200 - 480662ff
4758 * WIN_TRACER4 L4 48067000 - 48067fff
4759 * XTI Mod 48068000 - 48068fff
4760 * XTI L4 48069000 - 48069fff
4761 * UART1 Mod 4806a000 - 4806afff
4762 * UART1 L4 4806b000 - 4806bfff
4763 * UART2 Mod 4806c000 - 4806cfff
4764 * UART2 L4 4806d000 - 4806dfff
4765 * UART3 Mod 4806e000 - 4806efff
4766 * UART3 L4 4806f000 - 4806ffff
4767 * I2C1 Mod 48070000 - 48070fff
4768 * I2C1 L4 48071000 - 48071fff
4769 * I2C2 Mod 48072000 - 48072fff
4770 * I2C2 L4 48073000 - 48073fff
4771 * McBSP1 Mod 48074000 - 48074fff
4772 * McBSP1 L4 48075000 - 48075fff
4773 * McBSP2 Mod 48076000 - 48076fff
4774 * McBSP2 L4 48077000 - 48077fff
4775 * GPTIMER3 Mod 48078000 - 48078fff
4776 * GPTIMER3 L4 48079000 - 48079fff
4777 * GPTIMER4 Mod 4807a000 - 4807afff
4778 * GPTIMER4 L4 4807b000 - 4807bfff
4779 * GPTIMER5 Mod 4807c000 - 4807cfff
4780 * GPTIMER5 L4 4807d000 - 4807dfff
4781 * GPTIMER6 Mod 4807e000 - 4807efff
4782 * GPTIMER6 L4 4807f000 - 4807ffff
4783 * GPTIMER7 Mod 48080000 - 48080fff
4784 * GPTIMER7 L4 48081000 - 48081fff
4785 * GPTIMER8 Mod 48082000 - 48082fff
4786 * GPTIMER8 L4 48083000 - 48083fff
4787 * GPTIMER9 Mod 48084000 - 48084fff
4788 * GPTIMER9 L4 48085000 - 48085fff
4789 * GPTIMER10 Mod 48086000 - 48086fff
4790 * GPTIMER10 L4 48087000 - 48087fff
4791 * GPTIMER11 Mod 48088000 - 48088fff
4792 * GPTIMER11 L4 48089000 - 48089fff
4793 * GPTIMER12 Mod 4808a000 - 4808afff
4794 * GPTIMER12 L4 4808b000 - 4808bfff
4795 * EAC Mod 48090000 - 48090fff
4796 * EAC L4 48091000 - 48091fff
4797 * FAC Mod 48092000 - 48092fff
4798 * FAC L4 48093000 - 48093fff
4799 * MAILBOX Mod 48094000 - 48094fff
4800 * MAILBOX L4 48095000 - 48095fff
4801 * SPI1 Mod 48098000 - 48098fff
4802 * SPI1 L4 48099000 - 48099fff
4803 * SPI2 Mod 4809a000 - 4809afff
4804 * SPI2 L4 4809b000 - 4809bfff
4805 * MMC/SDIO Mod 4809c000 - 4809cfff
4806 * MMC/SDIO L4 4809d000 - 4809dfff
4807 * MS_PRO Mod 4809e000 - 4809efff
4808 * MS_PRO L4 4809f000 - 4809ffff
4809 * RNG Mod 480a0000 - 480a0fff
4810 * RNG L4 480a1000 - 480a1fff
4811 * DES3DES Mod 480a2000 - 480a2fff
4812 * DES3DES L4 480a3000 - 480a3fff
4813 * SHA1MD5 Mod 480a4000 - 480a4fff
4814 * SHA1MD5 L4 480a5000 - 480a5fff
4815 * AES Mod 480a6000 - 480a6fff
4816 * AES L4 480a7000 - 480a7fff
4817 * PKA Mod 480a8000 - 480a9fff
4818 * PKA L4 480aa000 - 480aafff
4819 * MG Mod 480b0000 - 480b0fff
4820 * MG L4 480b1000 - 480b1fff
4821 * HDQ/1-wire Mod 480b2000 - 480b2fff
4822 * HDQ/1-wire L4 480b3000 - 480b3fff
4823 * MPU interrupt 480fe000 - 480fefff
4824 * STI channel base 54000000 - 5400ffff
4825 * IVA RAM 5c000000 - 5c01ffff
4826 * IVA ROM 5c020000 - 5c027fff
4827 * IMG_BUF_A 5c040000 - 5c040fff
4828 * IMG_BUF_B 5c042000 - 5c042fff
4829 * VLCDS 5c048000 - 5c0487ff
4830 * IMX_COEF 5c049000 - 5c04afff
4831 * IMX_CMD 5c051000 - 5c051fff
4832 * VLCDQ 5c053000 - 5c0533ff
4833 * VLCDH 5c054000 - 5c054fff
4834 * SEQ_CMD 5c055000 - 5c055fff
4835 * IMX_REG 5c056000 - 5c0560ff
4836 * VLCD_REG 5c056100 - 5c0561ff
4837 * SEQ_REG 5c056200 - 5c0562ff
4838 * IMG_BUF_REG 5c056300 - 5c0563ff
4839 * SEQIRQ_REG 5c056400 - 5c0564ff
4840 * OCP_REG 5c060000 - 5c060fff
4841 * SYSC_REG 5c070000 - 5c070fff
4842 * MMU_REG 5d000000 - 5d000fff
4843 * sDMA R 68000400 - 680005ff
4844 * sDMA W 68000600 - 680007ff
4845 * Display Control 68000800 - 680009ff
4846 * DSP subsystem 68000a00 - 68000bff
4847 * MPU subsystem 68000c00 - 68000dff
4848 * IVA subsystem 68001000 - 680011ff
4849 * USB 68001200 - 680013ff
4850 * Camera 68001400 - 680015ff
4851 * VLYNQ (firewall) 68001800 - 68001bff
4852 * VLYNQ 68001e00 - 68001fff
4853 * SSI 68002000 - 680021ff
4854 * L4 68002400 - 680025ff
4855 * DSP (firewall) 68002800 - 68002bff
4856 * DSP subsystem 68002e00 - 68002fff
4857 * IVA (firewall) 68003000 - 680033ff
4858 * IVA 68003600 - 680037ff
4859 * GFX 68003a00 - 68003bff
4860 * CMDWR emulation 68003c00 - 68003dff
4861 * SMS 68004000 - 680041ff
4862 * OCM 68004200 - 680043ff
4863 * GPMC 68004400 - 680045ff
4864 * RAM (firewall) 68005000 - 680053ff
4865 * RAM (err login) 68005400 - 680057ff
4866 * ROM (firewall) 68005800 - 68005bff
4867 * ROM (err login) 68005c00 - 68005fff
4868 * GPMC (firewall) 68006000 - 680063ff
4869 * GPMC (err login) 68006400 - 680067ff
4870 * SMS (err login) 68006c00 - 68006fff
4871 * SMS registers 68008000 - 68008fff
4872 * SDRC registers 68009000 - 68009fff
4873 * GPMC registers 6800a000 6800afff
4876 qemu_register_reset(omap2_mpu_reset, s);
4878 return s;