2 * TI OMAP processors emulation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "qemu-timer.h"
24 #include "qemu-char.h"
26 /* We use pc-style serial ports. */
29 /* Should signal the TCMI/GPMC */
30 uint32_t omap_badwidth_read8(void *opaque, target_phys_addr_t addr)
35 cpu_physical_memory_read(addr, (void *) &ret, 1);
39 void omap_badwidth_write8(void *opaque, target_phys_addr_t addr,
45 cpu_physical_memory_write(addr, (void *) &val8, 1);
48 uint32_t omap_badwidth_read16(void *opaque, target_phys_addr_t addr)
53 cpu_physical_memory_read(addr, (void *) &ret, 2);
57 void omap_badwidth_write16(void *opaque, target_phys_addr_t addr,
60 uint16_t val16 = value;
63 cpu_physical_memory_write(addr, (void *) &val16, 2);
66 uint32_t omap_badwidth_read32(void *opaque, target_phys_addr_t addr)
71 cpu_physical_memory_read(addr, (void *) &ret, 4);
75 void omap_badwidth_write32(void *opaque, target_phys_addr_t addr,
79 cpu_physical_memory_write(addr, (void *) &value, 4);
82 /* Interrupt Handlers */
83 struct omap_intr_handler_bank_s {
90 unsigned char priority[32];
93 struct omap_intr_handler_s {
95 qemu_irq parent_intr[2];
104 struct omap_intr_handler_bank_s bank[];
107 static void omap_inth_sir_update(struct omap_intr_handler_s *s, int is_fiq)
109 int i, j, sir_intr, p_intr, p, f;
114 /* Find the interrupt line with the highest dynamic priority.
115 * Note: 0 denotes the hightest priority.
116 * If all interrupts have the same priority, the default order is IRQ_N,
117 * IRQ_N-1,...,IRQ_0. */
118 for (j = 0; j < s->nbanks; ++j) {
119 level = s->bank[j].irqs & ~s->bank[j].mask &
120 (is_fiq ? s->bank[j].fiq : ~s->bank[j].fiq);
121 for (f = ffs(level), i = f - 1, level >>= f - 1; f; i += f,
123 p = s->bank[j].priority[i];
126 sir_intr = 32 * j + i;
131 s->sir_intr[is_fiq] = sir_intr;
134 static inline void omap_inth_update(struct omap_intr_handler_s *s, int is_fiq)
137 uint32_t has_intr = 0;
139 for (i = 0; i < s->nbanks; ++i)
140 has_intr |= s->bank[i].irqs & ~s->bank[i].mask &
141 (is_fiq ? s->bank[i].fiq : ~s->bank[i].fiq);
143 if (s->new_agr[is_fiq] & has_intr & s->mask) {
144 s->new_agr[is_fiq] = 0;
145 omap_inth_sir_update(s, is_fiq);
146 qemu_set_irq(s->parent_intr[is_fiq], 1);
150 #define INT_FALLING_EDGE 0
151 #define INT_LOW_LEVEL 1
153 static void omap_set_intr(void *opaque, int irq, int req)
155 struct omap_intr_handler_s *ih = (struct omap_intr_handler_s *) opaque;
158 struct omap_intr_handler_bank_s *bank = &ih->bank[irq >> 5];
162 rise = ~bank->irqs & (1 << n);
163 if (~bank->sens_edge & (1 << n))
164 rise &= ~bank->inputs;
166 bank->inputs |= (1 << n);
169 omap_inth_update(ih, 0);
170 omap_inth_update(ih, 1);
173 rise = bank->sens_edge & bank->irqs & (1 << n);
175 bank->inputs &= ~(1 << n);
179 /* Simplified version with no edge detection */
180 static void omap_set_intr_noedge(void *opaque, int irq, int req)
182 struct omap_intr_handler_s *ih = (struct omap_intr_handler_s *) opaque;
185 struct omap_intr_handler_bank_s *bank = &ih->bank[irq >> 5];
189 rise = ~bank->inputs & (1 << n);
191 bank->irqs |= bank->inputs |= rise;
192 omap_inth_update(ih, 0);
193 omap_inth_update(ih, 1);
196 bank->irqs = (bank->inputs &= ~(1 << n)) | bank->swi;
199 static uint32_t omap_inth_read(void *opaque, target_phys_addr_t addr)
201 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
202 int i, offset = addr;
203 int bank_no = offset >> 8;
205 struct omap_intr_handler_bank_s *bank = &s->bank[bank_no];
215 case 0x10: /* SIR_IRQ_CODE */
216 case 0x14: /* SIR_FIQ_CODE */
219 line_no = s->sir_intr[(offset - 0x10) >> 2];
220 bank = &s->bank[line_no >> 5];
222 if (((bank->sens_edge >> i) & 1) == INT_FALLING_EDGE)
223 bank->irqs &= ~(1 << i);
226 case 0x18: /* CONTROL_REG */
231 case 0x1c: /* ILR0 */
232 case 0x20: /* ILR1 */
233 case 0x24: /* ILR2 */
234 case 0x28: /* ILR3 */
235 case 0x2c: /* ILR4 */
236 case 0x30: /* ILR5 */
237 case 0x34: /* ILR6 */
238 case 0x38: /* ILR7 */
239 case 0x3c: /* ILR8 */
240 case 0x40: /* ILR9 */
241 case 0x44: /* ILR10 */
242 case 0x48: /* ILR11 */
243 case 0x4c: /* ILR12 */
244 case 0x50: /* ILR13 */
245 case 0x54: /* ILR14 */
246 case 0x58: /* ILR15 */
247 case 0x5c: /* ILR16 */
248 case 0x60: /* ILR17 */
249 case 0x64: /* ILR18 */
250 case 0x68: /* ILR19 */
251 case 0x6c: /* ILR20 */
252 case 0x70: /* ILR21 */
253 case 0x74: /* ILR22 */
254 case 0x78: /* ILR23 */
255 case 0x7c: /* ILR24 */
256 case 0x80: /* ILR25 */
257 case 0x84: /* ILR26 */
258 case 0x88: /* ILR27 */
259 case 0x8c: /* ILR28 */
260 case 0x90: /* ILR29 */
261 case 0x94: /* ILR30 */
262 case 0x98: /* ILR31 */
263 i = (offset - 0x1c) >> 2;
264 return (bank->priority[i] << 2) |
265 (((bank->sens_edge >> i) & 1) << 1) |
266 ((bank->fiq >> i) & 1);
276 static void omap_inth_write(void *opaque, target_phys_addr_t addr,
279 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
280 int i, offset = addr;
281 int bank_no = offset >> 8;
282 struct omap_intr_handler_bank_s *bank = &s->bank[bank_no];
287 /* Important: ignore the clearing if the IRQ is level-triggered and
288 the input bit is 1 */
289 bank->irqs &= value | (bank->inputs & bank->sens_edge);
294 omap_inth_update(s, 0);
295 omap_inth_update(s, 1);
298 case 0x10: /* SIR_IRQ_CODE */
299 case 0x14: /* SIR_FIQ_CODE */
303 case 0x18: /* CONTROL_REG */
307 qemu_set_irq(s->parent_intr[1], 0);
309 omap_inth_update(s, 1);
312 qemu_set_irq(s->parent_intr[0], 0);
314 omap_inth_update(s, 0);
318 case 0x1c: /* ILR0 */
319 case 0x20: /* ILR1 */
320 case 0x24: /* ILR2 */
321 case 0x28: /* ILR3 */
322 case 0x2c: /* ILR4 */
323 case 0x30: /* ILR5 */
324 case 0x34: /* ILR6 */
325 case 0x38: /* ILR7 */
326 case 0x3c: /* ILR8 */
327 case 0x40: /* ILR9 */
328 case 0x44: /* ILR10 */
329 case 0x48: /* ILR11 */
330 case 0x4c: /* ILR12 */
331 case 0x50: /* ILR13 */
332 case 0x54: /* ILR14 */
333 case 0x58: /* ILR15 */
334 case 0x5c: /* ILR16 */
335 case 0x60: /* ILR17 */
336 case 0x64: /* ILR18 */
337 case 0x68: /* ILR19 */
338 case 0x6c: /* ILR20 */
339 case 0x70: /* ILR21 */
340 case 0x74: /* ILR22 */
341 case 0x78: /* ILR23 */
342 case 0x7c: /* ILR24 */
343 case 0x80: /* ILR25 */
344 case 0x84: /* ILR26 */
345 case 0x88: /* ILR27 */
346 case 0x8c: /* ILR28 */
347 case 0x90: /* ILR29 */
348 case 0x94: /* ILR30 */
349 case 0x98: /* ILR31 */
350 i = (offset - 0x1c) >> 2;
351 bank->priority[i] = (value >> 2) & 0x1f;
352 bank->sens_edge &= ~(1 << i);
353 bank->sens_edge |= ((value >> 1) & 1) << i;
354 bank->fiq &= ~(1 << i);
355 bank->fiq |= (value & 1) << i;
359 for (i = 0; i < 32; i ++)
360 if (value & (1 << i)) {
361 omap_set_intr(s, 32 * bank_no + i, 1);
369 static CPUReadMemoryFunc * const omap_inth_readfn[] = {
370 omap_badwidth_read32,
371 omap_badwidth_read32,
375 static CPUWriteMemoryFunc * const omap_inth_writefn[] = {
381 void omap_inth_reset(struct omap_intr_handler_s *s)
385 for (i = 0; i < s->nbanks; ++i){
386 s->bank[i].irqs = 0x00000000;
387 s->bank[i].mask = 0xffffffff;
388 s->bank[i].sens_edge = 0x00000000;
389 s->bank[i].fiq = 0x00000000;
390 s->bank[i].inputs = 0x00000000;
391 s->bank[i].swi = 0x00000000;
392 memset(s->bank[i].priority, 0, sizeof(s->bank[i].priority));
395 s->bank[i].sens_edge = 0xffffffff;
405 qemu_set_irq(s->parent_intr[0], 0);
406 qemu_set_irq(s->parent_intr[1], 0);
409 struct omap_intr_handler_s *omap_inth_init(target_phys_addr_t base,
410 unsigned long size, unsigned char nbanks, qemu_irq **pins,
411 qemu_irq parent_irq, qemu_irq parent_fiq, omap_clk clk)
414 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)
415 qemu_mallocz(sizeof(struct omap_intr_handler_s) +
416 sizeof(struct omap_intr_handler_bank_s) * nbanks);
418 s->parent_intr[0] = parent_irq;
419 s->parent_intr[1] = parent_fiq;
421 s->pins = qemu_allocate_irqs(omap_set_intr, s, nbanks * 32);
427 iomemtype = cpu_register_io_memory(omap_inth_readfn,
428 omap_inth_writefn, s);
429 cpu_register_physical_memory(base, size, iomemtype);
434 static uint32_t omap2_inth_read(void *opaque, target_phys_addr_t addr)
436 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
438 int bank_no, line_no;
439 struct omap_intr_handler_bank_s *bank = NULL;
441 if ((offset & 0xf80) == 0x80) {
442 bank_no = (offset & 0x60) >> 5;
443 if (bank_no < s->nbanks) {
445 bank = &s->bank[bank_no];
450 case 0x00: /* INTC_REVISION */
453 case 0x10: /* INTC_SYSCONFIG */
454 return (s->autoidle >> 2) & 1;
456 case 0x14: /* INTC_SYSSTATUS */
457 return 1; /* RESETDONE */
459 case 0x40: /* INTC_SIR_IRQ */
460 return s->sir_intr[0];
462 case 0x44: /* INTC_SIR_FIQ */
463 return s->sir_intr[1];
465 case 0x48: /* INTC_CONTROL */
466 return (!s->mask) << 2; /* GLOBALMASK */
468 case 0x4c: /* INTC_PROTECTION */
471 case 0x50: /* INTC_IDLE */
472 return s->autoidle & 3;
474 /* Per-bank registers */
475 case 0x80: /* INTC_ITR */
478 case 0x84: /* INTC_MIR */
481 case 0x88: /* INTC_MIR_CLEAR */
482 case 0x8c: /* INTC_MIR_SET */
485 case 0x90: /* INTC_ISR_SET */
488 case 0x94: /* INTC_ISR_CLEAR */
491 case 0x98: /* INTC_PENDING_IRQ */
492 return bank->irqs & ~bank->mask & ~bank->fiq;
494 case 0x9c: /* INTC_PENDING_FIQ */
495 return bank->irqs & ~bank->mask & bank->fiq;
497 /* Per-line registers */
498 case 0x100 ... 0x300: /* INTC_ILR */
499 bank_no = (offset - 0x100) >> 7;
500 if (bank_no > s->nbanks)
502 bank = &s->bank[bank_no];
503 line_no = (offset & 0x7f) >> 2;
504 return (bank->priority[line_no] << 2) |
505 ((bank->fiq >> line_no) & 1);
511 static void omap2_inth_write(void *opaque, target_phys_addr_t addr,
514 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
516 int bank_no, line_no;
517 struct omap_intr_handler_bank_s *bank = NULL;
519 if ((offset & 0xf80) == 0x80) {
520 bank_no = (offset & 0x60) >> 5;
521 if (bank_no < s->nbanks) {
523 bank = &s->bank[bank_no];
528 case 0x10: /* INTC_SYSCONFIG */
530 s->autoidle |= (value & 1) << 2;
531 if (value & 2) /* SOFTRESET */
535 case 0x48: /* INTC_CONTROL */
536 s->mask = (value & 4) ? 0 : ~0; /* GLOBALMASK */
537 if (value & 2) { /* NEWFIQAGR */
538 qemu_set_irq(s->parent_intr[1], 0);
540 omap_inth_update(s, 1);
542 if (value & 1) { /* NEWIRQAGR */
543 qemu_set_irq(s->parent_intr[0], 0);
545 omap_inth_update(s, 0);
549 case 0x4c: /* INTC_PROTECTION */
550 /* TODO: Make a bitmap (or sizeof(char)map) of access privileges
551 * for every register, see Chapter 3 and 4 for privileged mode. */
553 fprintf(stderr, "%s: protection mode enable attempt\n",
557 case 0x50: /* INTC_IDLE */
559 s->autoidle |= value & 3;
562 /* Per-bank registers */
563 case 0x84: /* INTC_MIR */
565 omap_inth_update(s, 0);
566 omap_inth_update(s, 1);
569 case 0x88: /* INTC_MIR_CLEAR */
570 bank->mask &= ~value;
571 omap_inth_update(s, 0);
572 omap_inth_update(s, 1);
575 case 0x8c: /* INTC_MIR_SET */
579 case 0x90: /* INTC_ISR_SET */
580 bank->irqs |= bank->swi |= value;
581 omap_inth_update(s, 0);
582 omap_inth_update(s, 1);
585 case 0x94: /* INTC_ISR_CLEAR */
587 bank->irqs = bank->swi & bank->inputs;
590 /* Per-line registers */
591 case 0x100 ... 0x300: /* INTC_ILR */
592 bank_no = (offset - 0x100) >> 7;
593 if (bank_no > s->nbanks)
595 bank = &s->bank[bank_no];
596 line_no = (offset & 0x7f) >> 2;
597 bank->priority[line_no] = (value >> 2) & 0x3f;
598 bank->fiq &= ~(1 << line_no);
599 bank->fiq |= (value & 1) << line_no;
602 case 0x00: /* INTC_REVISION */
603 case 0x14: /* INTC_SYSSTATUS */
604 case 0x40: /* INTC_SIR_IRQ */
605 case 0x44: /* INTC_SIR_FIQ */
606 case 0x80: /* INTC_ITR */
607 case 0x98: /* INTC_PENDING_IRQ */
608 case 0x9c: /* INTC_PENDING_FIQ */
615 static CPUReadMemoryFunc * const omap2_inth_readfn[] = {
616 omap_badwidth_read32,
617 omap_badwidth_read32,
621 static CPUWriteMemoryFunc * const omap2_inth_writefn[] = {
627 struct omap_intr_handler_s *omap2_inth_init(target_phys_addr_t base,
628 int size, int nbanks, qemu_irq **pins,
629 qemu_irq parent_irq, qemu_irq parent_fiq,
630 omap_clk fclk, omap_clk iclk)
633 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)
634 qemu_mallocz(sizeof(struct omap_intr_handler_s) +
635 sizeof(struct omap_intr_handler_bank_s) * nbanks);
637 s->parent_intr[0] = parent_irq;
638 s->parent_intr[1] = parent_fiq;
641 s->pins = qemu_allocate_irqs(omap_set_intr_noedge, s, nbanks * 32);
647 iomemtype = cpu_register_io_memory(omap2_inth_readfn,
648 omap2_inth_writefn, s);
649 cpu_register_physical_memory(base, size, iomemtype);
655 struct omap_mpu_timer_s {
672 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer)
674 uint64_t distance = qemu_get_clock(vm_clock) - timer->time;
676 if (timer->st && timer->enable && timer->rate)
677 return timer->val - muldiv64(distance >> (timer->ptv + 1),
678 timer->rate, get_ticks_per_sec());
683 static inline void omap_timer_sync(struct omap_mpu_timer_s *timer)
685 timer->val = omap_timer_read(timer);
686 timer->time = qemu_get_clock(vm_clock);
689 static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
693 if (timer->enable && timer->st && timer->rate) {
694 timer->val = timer->reset_val; /* Should skip this on clk enable */
695 expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
696 get_ticks_per_sec(), timer->rate);
698 /* If timer expiry would be sooner than in about 1 ms and
699 * auto-reload isn't set, then fire immediately. This is a hack
700 * to make systems like PalmOS run in acceptable time. PalmOS
701 * sets the interval to a very low value and polls the status bit
702 * in a busy loop when it wants to sleep just a couple of CPU
704 if (expires > (get_ticks_per_sec() >> 10) || timer->ar)
705 qemu_mod_timer(timer->timer, timer->time + expires);
707 qemu_bh_schedule(timer->tick);
709 qemu_del_timer(timer->timer);
712 static void omap_timer_fire(void *opaque)
714 struct omap_mpu_timer_s *timer = opaque;
722 /* Edge-triggered irq */
723 qemu_irq_pulse(timer->irq);
726 static void omap_timer_tick(void *opaque)
728 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
730 omap_timer_sync(timer);
731 omap_timer_fire(timer);
732 omap_timer_update(timer);
735 static void omap_timer_clk_update(void *opaque, int line, int on)
737 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
739 omap_timer_sync(timer);
740 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
741 omap_timer_update(timer);
744 static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer)
746 omap_clk_adduser(timer->clk,
747 qemu_allocate_irqs(omap_timer_clk_update, timer, 1)[0]);
748 timer->rate = omap_clk_getrate(timer->clk);
751 static uint32_t omap_mpu_timer_read(void *opaque, target_phys_addr_t addr)
753 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
756 case 0x00: /* CNTL_TIMER */
757 return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st;
759 case 0x04: /* LOAD_TIM */
762 case 0x08: /* READ_TIM */
763 return omap_timer_read(s);
770 static void omap_mpu_timer_write(void *opaque, target_phys_addr_t addr,
773 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
776 case 0x00: /* CNTL_TIMER */
778 s->enable = (value >> 5) & 1;
779 s->ptv = (value >> 2) & 7;
780 s->ar = (value >> 1) & 1;
782 omap_timer_update(s);
785 case 0x04: /* LOAD_TIM */
786 s->reset_val = value;
789 case 0x08: /* READ_TIM */
798 static CPUReadMemoryFunc * const omap_mpu_timer_readfn[] = {
799 omap_badwidth_read32,
800 omap_badwidth_read32,
804 static CPUWriteMemoryFunc * const omap_mpu_timer_writefn[] = {
805 omap_badwidth_write32,
806 omap_badwidth_write32,
807 omap_mpu_timer_write,
810 static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s)
812 qemu_del_timer(s->timer);
814 s->reset_val = 31337;
822 struct omap_mpu_timer_s *omap_mpu_timer_init(target_phys_addr_t base,
823 qemu_irq irq, omap_clk clk)
826 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *)
827 qemu_mallocz(sizeof(struct omap_mpu_timer_s));
831 s->timer = qemu_new_timer(vm_clock, omap_timer_tick, s);
832 s->tick = qemu_bh_new(omap_timer_fire, s);
833 omap_mpu_timer_reset(s);
834 omap_timer_clk_setup(s);
836 iomemtype = cpu_register_io_memory(omap_mpu_timer_readfn,
837 omap_mpu_timer_writefn, s);
838 cpu_register_physical_memory(base, 0x100, iomemtype);
844 struct omap_watchdog_timer_s {
845 struct omap_mpu_timer_s timer;
852 static uint32_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr)
854 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
857 case 0x00: /* CNTL_TIMER */
858 return (s->timer.ptv << 9) | (s->timer.ar << 8) |
859 (s->timer.st << 7) | (s->free << 1);
861 case 0x04: /* READ_TIMER */
862 return omap_timer_read(&s->timer);
864 case 0x08: /* TIMER_MODE */
865 return s->mode << 15;
872 static void omap_wd_timer_write(void *opaque, target_phys_addr_t addr,
875 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
878 case 0x00: /* CNTL_TIMER */
879 omap_timer_sync(&s->timer);
880 s->timer.ptv = (value >> 9) & 7;
881 s->timer.ar = (value >> 8) & 1;
882 s->timer.st = (value >> 7) & 1;
883 s->free = (value >> 1) & 1;
884 omap_timer_update(&s->timer);
887 case 0x04: /* LOAD_TIMER */
888 s->timer.reset_val = value & 0xffff;
891 case 0x08: /* TIMER_MODE */
892 if (!s->mode && ((value >> 15) & 1))
893 omap_clk_get(s->timer.clk);
894 s->mode |= (value >> 15) & 1;
895 if (s->last_wr == 0xf5) {
896 if ((value & 0xff) == 0xa0) {
899 omap_clk_put(s->timer.clk);
902 /* XXX: on T|E hardware somehow this has no effect,
903 * on Zire 71 it works as specified. */
905 qemu_system_reset_request();
908 s->last_wr = value & 0xff;
916 static CPUReadMemoryFunc * const omap_wd_timer_readfn[] = {
917 omap_badwidth_read16,
919 omap_badwidth_read16,
922 static CPUWriteMemoryFunc * const omap_wd_timer_writefn[] = {
923 omap_badwidth_write16,
925 omap_badwidth_write16,
928 static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s)
930 qemu_del_timer(s->timer.timer);
932 omap_clk_get(s->timer.clk);
938 s->timer.reset_val = 0xffff;
943 omap_timer_update(&s->timer);
946 struct omap_watchdog_timer_s *omap_wd_timer_init(target_phys_addr_t base,
947 qemu_irq irq, omap_clk clk)
950 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *)
951 qemu_mallocz(sizeof(struct omap_watchdog_timer_s));
955 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
956 omap_wd_timer_reset(s);
957 omap_timer_clk_setup(&s->timer);
959 iomemtype = cpu_register_io_memory(omap_wd_timer_readfn,
960 omap_wd_timer_writefn, s);
961 cpu_register_physical_memory(base, 0x100, iomemtype);
967 struct omap_32khz_timer_s {
968 struct omap_mpu_timer_s timer;
971 static uint32_t omap_os_timer_read(void *opaque, target_phys_addr_t addr)
973 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
974 int offset = addr & OMAP_MPUI_REG_MASK;
978 return s->timer.reset_val;
981 return omap_timer_read(&s->timer);
984 return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st;
993 static void omap_os_timer_write(void *opaque, target_phys_addr_t addr,
996 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
997 int offset = addr & OMAP_MPUI_REG_MASK;
1000 case 0x00: /* TVR */
1001 s->timer.reset_val = value & 0x00ffffff;
1004 case 0x04: /* TCR */
1009 s->timer.ar = (value >> 3) & 1;
1010 s->timer.it_ena = (value >> 2) & 1;
1011 if (s->timer.st != (value & 1) || (value & 2)) {
1012 omap_timer_sync(&s->timer);
1013 s->timer.enable = value & 1;
1014 s->timer.st = value & 1;
1015 omap_timer_update(&s->timer);
1024 static CPUReadMemoryFunc * const omap_os_timer_readfn[] = {
1025 omap_badwidth_read32,
1026 omap_badwidth_read32,
1030 static CPUWriteMemoryFunc * const omap_os_timer_writefn[] = {
1031 omap_badwidth_write32,
1032 omap_badwidth_write32,
1033 omap_os_timer_write,
1036 static void omap_os_timer_reset(struct omap_32khz_timer_s *s)
1038 qemu_del_timer(s->timer.timer);
1039 s->timer.enable = 0;
1040 s->timer.it_ena = 0;
1041 s->timer.reset_val = 0x00ffffff;
1048 struct omap_32khz_timer_s *omap_os_timer_init(target_phys_addr_t base,
1049 qemu_irq irq, omap_clk clk)
1052 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *)
1053 qemu_mallocz(sizeof(struct omap_32khz_timer_s));
1057 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
1058 omap_os_timer_reset(s);
1059 omap_timer_clk_setup(&s->timer);
1061 iomemtype = cpu_register_io_memory(omap_os_timer_readfn,
1062 omap_os_timer_writefn, s);
1063 cpu_register_physical_memory(base, 0x800, iomemtype);
1068 /* Ultra Low-Power Device Module */
1069 static uint32_t omap_ulpd_pm_read(void *opaque, target_phys_addr_t addr)
1071 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1075 case 0x14: /* IT_STATUS */
1076 ret = s->ulpd_pm_regs[addr >> 2];
1077 s->ulpd_pm_regs[addr >> 2] = 0;
1078 qemu_irq_lower(s->irq[1][OMAP_INT_GAUGE_32K]);
1081 case 0x18: /* Reserved */
1082 case 0x1c: /* Reserved */
1083 case 0x20: /* Reserved */
1084 case 0x28: /* Reserved */
1085 case 0x2c: /* Reserved */
1087 case 0x00: /* COUNTER_32_LSB */
1088 case 0x04: /* COUNTER_32_MSB */
1089 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1090 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1091 case 0x10: /* GAUGING_CTRL */
1092 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1093 case 0x30: /* CLOCK_CTRL */
1094 case 0x34: /* SOFT_REQ */
1095 case 0x38: /* COUNTER_32_FIQ */
1096 case 0x3c: /* DPLL_CTRL */
1097 case 0x40: /* STATUS_REQ */
1098 /* XXX: check clk::usecount state for every clock */
1099 case 0x48: /* LOCL_TIME */
1100 case 0x4c: /* APLL_CTRL */
1101 case 0x50: /* POWER_CTRL */
1102 return s->ulpd_pm_regs[addr >> 2];
1109 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s,
1110 uint16_t diff, uint16_t value)
1112 if (diff & (1 << 4)) /* USB_MCLK_EN */
1113 omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1);
1114 if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */
1115 omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1);
1118 static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s,
1119 uint16_t diff, uint16_t value)
1121 if (diff & (1 << 0)) /* SOFT_DPLL_REQ */
1122 omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1);
1123 if (diff & (1 << 1)) /* SOFT_COM_REQ */
1124 omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1);
1125 if (diff & (1 << 2)) /* SOFT_SDW_REQ */
1126 omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1);
1127 if (diff & (1 << 3)) /* SOFT_USB_REQ */
1128 omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1);
1131 static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr,
1134 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1137 static const int bypass_div[4] = { 1, 2, 4, 4 };
1141 case 0x00: /* COUNTER_32_LSB */
1142 case 0x04: /* COUNTER_32_MSB */
1143 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1144 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1145 case 0x14: /* IT_STATUS */
1146 case 0x40: /* STATUS_REQ */
1150 case 0x10: /* GAUGING_CTRL */
1151 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
1152 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
1153 now = qemu_get_clock(vm_clock);
1156 s->ulpd_gauge_start = now;
1158 now -= s->ulpd_gauge_start;
1161 ticks = muldiv64(now, 32768, get_ticks_per_sec());
1162 s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff;
1163 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff;
1164 if (ticks >> 32) /* OVERFLOW_32K */
1165 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
1167 /* High frequency ticks */
1168 ticks = muldiv64(now, 12000000, get_ticks_per_sec());
1169 s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff;
1170 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff;
1171 if (ticks >> 32) /* OVERFLOW_HI_FREQ */
1172 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
1174 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
1175 qemu_irq_raise(s->irq[1][OMAP_INT_GAUGE_32K]);
1178 s->ulpd_pm_regs[addr >> 2] = value;
1181 case 0x18: /* Reserved */
1182 case 0x1c: /* Reserved */
1183 case 0x20: /* Reserved */
1184 case 0x28: /* Reserved */
1185 case 0x2c: /* Reserved */
1187 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1188 case 0x38: /* COUNTER_32_FIQ */
1189 case 0x48: /* LOCL_TIME */
1190 case 0x50: /* POWER_CTRL */
1191 s->ulpd_pm_regs[addr >> 2] = value;
1194 case 0x30: /* CLOCK_CTRL */
1195 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
1196 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
1197 omap_ulpd_clk_update(s, diff, value);
1200 case 0x34: /* SOFT_REQ */
1201 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
1202 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
1203 omap_ulpd_req_update(s, diff, value);
1206 case 0x3c: /* DPLL_CTRL */
1207 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
1208 * omitted altogether, probably a typo. */
1209 /* This register has identical semantics with DPLL(1:3) control
1210 * registers, see omap_dpll_write() */
1211 diff = s->ulpd_pm_regs[addr >> 2] & value;
1212 s->ulpd_pm_regs[addr >> 2] = value & 0x2fff;
1213 if (diff & (0x3ff << 2)) {
1214 if (value & (1 << 4)) { /* PLL_ENABLE */
1215 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1216 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1218 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1221 omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
1224 /* Enter the desired mode. */
1225 s->ulpd_pm_regs[addr >> 2] =
1226 (s->ulpd_pm_regs[addr >> 2] & 0xfffe) |
1227 ((s->ulpd_pm_regs[addr >> 2] >> 4) & 1);
1229 /* Act as if the lock is restored. */
1230 s->ulpd_pm_regs[addr >> 2] |= 2;
1233 case 0x4c: /* APLL_CTRL */
1234 diff = s->ulpd_pm_regs[addr >> 2] & value;
1235 s->ulpd_pm_regs[addr >> 2] = value & 0xf;
1236 if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */
1237 omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
1238 (value & (1 << 0)) ? "apll" : "dpll4"));
1246 static CPUReadMemoryFunc * const omap_ulpd_pm_readfn[] = {
1247 omap_badwidth_read16,
1249 omap_badwidth_read16,
1252 static CPUWriteMemoryFunc * const omap_ulpd_pm_writefn[] = {
1253 omap_badwidth_write16,
1255 omap_badwidth_write16,
1258 static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu)
1260 mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001;
1261 mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000;
1262 mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001;
1263 mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000;
1264 mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000;
1265 mpu->ulpd_pm_regs[0x18 >> 2] = 0x01;
1266 mpu->ulpd_pm_regs[0x1c >> 2] = 0x01;
1267 mpu->ulpd_pm_regs[0x20 >> 2] = 0x01;
1268 mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff;
1269 mpu->ulpd_pm_regs[0x28 >> 2] = 0x01;
1270 mpu->ulpd_pm_regs[0x2c >> 2] = 0x01;
1271 omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000);
1272 mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000;
1273 omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000);
1274 mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000;
1275 mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001;
1276 mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211;
1277 mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
1278 mpu->ulpd_pm_regs[0x48 >> 2] = 0x960;
1279 mpu->ulpd_pm_regs[0x4c >> 2] = 0x08;
1280 mpu->ulpd_pm_regs[0x50 >> 2] = 0x08;
1281 omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4);
1282 omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4"));
1285 static void omap_ulpd_pm_init(target_phys_addr_t base,
1286 struct omap_mpu_state_s *mpu)
1288 int iomemtype = cpu_register_io_memory(omap_ulpd_pm_readfn,
1289 omap_ulpd_pm_writefn, mpu);
1291 cpu_register_physical_memory(base, 0x800, iomemtype);
1292 omap_ulpd_pm_reset(mpu);
1295 /* OMAP Pin Configuration */
1296 static uint32_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr)
1298 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1301 case 0x00: /* FUNC_MUX_CTRL_0 */
1302 case 0x04: /* FUNC_MUX_CTRL_1 */
1303 case 0x08: /* FUNC_MUX_CTRL_2 */
1304 return s->func_mux_ctrl[addr >> 2];
1306 case 0x0c: /* COMP_MODE_CTRL_0 */
1307 return s->comp_mode_ctrl[0];
1309 case 0x10: /* FUNC_MUX_CTRL_3 */
1310 case 0x14: /* FUNC_MUX_CTRL_4 */
1311 case 0x18: /* FUNC_MUX_CTRL_5 */
1312 case 0x1c: /* FUNC_MUX_CTRL_6 */
1313 case 0x20: /* FUNC_MUX_CTRL_7 */
1314 case 0x24: /* FUNC_MUX_CTRL_8 */
1315 case 0x28: /* FUNC_MUX_CTRL_9 */
1316 case 0x2c: /* FUNC_MUX_CTRL_A */
1317 case 0x30: /* FUNC_MUX_CTRL_B */
1318 case 0x34: /* FUNC_MUX_CTRL_C */
1319 case 0x38: /* FUNC_MUX_CTRL_D */
1320 return s->func_mux_ctrl[(addr >> 2) - 1];
1322 case 0x40: /* PULL_DWN_CTRL_0 */
1323 case 0x44: /* PULL_DWN_CTRL_1 */
1324 case 0x48: /* PULL_DWN_CTRL_2 */
1325 case 0x4c: /* PULL_DWN_CTRL_3 */
1326 return s->pull_dwn_ctrl[(addr & 0xf) >> 2];
1328 case 0x50: /* GATE_INH_CTRL_0 */
1329 return s->gate_inh_ctrl[0];
1331 case 0x60: /* VOLTAGE_CTRL_0 */
1332 return s->voltage_ctrl[0];
1334 case 0x70: /* TEST_DBG_CTRL_0 */
1335 return s->test_dbg_ctrl[0];
1337 case 0x80: /* MOD_CONF_CTRL_0 */
1338 return s->mod_conf_ctrl[0];
1345 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s,
1346 uint32_t diff, uint32_t value)
1348 if (s->compat1509) {
1349 if (diff & (1 << 9)) /* BLUETOOTH */
1350 omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
1352 if (diff & (1 << 7)) /* USB.CLKO */
1353 omap_clk_onoff(omap_findclk(s, "usb.clko"),
1358 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s,
1359 uint32_t diff, uint32_t value)
1361 if (s->compat1509) {
1362 if (diff & (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
1363 omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"),
1365 if (diff & (1 << 1)) /* CLK32K */
1366 omap_clk_onoff(omap_findclk(s, "clk32k_out"),
1371 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s,
1372 uint32_t diff, uint32_t value)
1374 if (diff & (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
1375 omap_clk_reparent(omap_findclk(s, "uart3_ck"),
1376 omap_findclk(s, ((value >> 31) & 1) ?
1377 "ck_48m" : "armper_ck"));
1378 if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
1379 omap_clk_reparent(omap_findclk(s, "uart2_ck"),
1380 omap_findclk(s, ((value >> 30) & 1) ?
1381 "ck_48m" : "armper_ck"));
1382 if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
1383 omap_clk_reparent(omap_findclk(s, "uart1_ck"),
1384 omap_findclk(s, ((value >> 29) & 1) ?
1385 "ck_48m" : "armper_ck"));
1386 if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
1387 omap_clk_reparent(omap_findclk(s, "mmc_ck"),
1388 omap_findclk(s, ((value >> 23) & 1) ?
1389 "ck_48m" : "armper_ck"));
1390 if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
1391 omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
1392 omap_findclk(s, ((value >> 12) & 1) ?
1393 "ck_48m" : "armper_ck"));
1394 if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
1395 omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1);
1398 static void omap_pin_cfg_write(void *opaque, target_phys_addr_t addr,
1401 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1405 case 0x00: /* FUNC_MUX_CTRL_0 */
1406 diff = s->func_mux_ctrl[addr >> 2] ^ value;
1407 s->func_mux_ctrl[addr >> 2] = value;
1408 omap_pin_funcmux0_update(s, diff, value);
1411 case 0x04: /* FUNC_MUX_CTRL_1 */
1412 diff = s->func_mux_ctrl[addr >> 2] ^ value;
1413 s->func_mux_ctrl[addr >> 2] = value;
1414 omap_pin_funcmux1_update(s, diff, value);
1417 case 0x08: /* FUNC_MUX_CTRL_2 */
1418 s->func_mux_ctrl[addr >> 2] = value;
1421 case 0x0c: /* COMP_MODE_CTRL_0 */
1422 s->comp_mode_ctrl[0] = value;
1423 s->compat1509 = (value != 0x0000eaef);
1424 omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]);
1425 omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]);
1428 case 0x10: /* FUNC_MUX_CTRL_3 */
1429 case 0x14: /* FUNC_MUX_CTRL_4 */
1430 case 0x18: /* FUNC_MUX_CTRL_5 */
1431 case 0x1c: /* FUNC_MUX_CTRL_6 */
1432 case 0x20: /* FUNC_MUX_CTRL_7 */
1433 case 0x24: /* FUNC_MUX_CTRL_8 */
1434 case 0x28: /* FUNC_MUX_CTRL_9 */
1435 case 0x2c: /* FUNC_MUX_CTRL_A */
1436 case 0x30: /* FUNC_MUX_CTRL_B */
1437 case 0x34: /* FUNC_MUX_CTRL_C */
1438 case 0x38: /* FUNC_MUX_CTRL_D */
1439 s->func_mux_ctrl[(addr >> 2) - 1] = value;
1442 case 0x40: /* PULL_DWN_CTRL_0 */
1443 case 0x44: /* PULL_DWN_CTRL_1 */
1444 case 0x48: /* PULL_DWN_CTRL_2 */
1445 case 0x4c: /* PULL_DWN_CTRL_3 */
1446 s->pull_dwn_ctrl[(addr & 0xf) >> 2] = value;
1449 case 0x50: /* GATE_INH_CTRL_0 */
1450 s->gate_inh_ctrl[0] = value;
1453 case 0x60: /* VOLTAGE_CTRL_0 */
1454 s->voltage_ctrl[0] = value;
1457 case 0x70: /* TEST_DBG_CTRL_0 */
1458 s->test_dbg_ctrl[0] = value;
1461 case 0x80: /* MOD_CONF_CTRL_0 */
1462 diff = s->mod_conf_ctrl[0] ^ value;
1463 s->mod_conf_ctrl[0] = value;
1464 omap_pin_modconf1_update(s, diff, value);
1472 static CPUReadMemoryFunc * const omap_pin_cfg_readfn[] = {
1473 omap_badwidth_read32,
1474 omap_badwidth_read32,
1478 static CPUWriteMemoryFunc * const omap_pin_cfg_writefn[] = {
1479 omap_badwidth_write32,
1480 omap_badwidth_write32,
1484 static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu)
1486 /* Start in Compatibility Mode. */
1487 mpu->compat1509 = 1;
1488 omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0);
1489 omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0);
1490 omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0);
1491 memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl));
1492 memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl));
1493 memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl));
1494 memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl));
1495 memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl));
1496 memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl));
1497 memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl));
1500 static void omap_pin_cfg_init(target_phys_addr_t base,
1501 struct omap_mpu_state_s *mpu)
1503 int iomemtype = cpu_register_io_memory(omap_pin_cfg_readfn,
1504 omap_pin_cfg_writefn, mpu);
1506 cpu_register_physical_memory(base, 0x800, iomemtype);
1507 omap_pin_cfg_reset(mpu);
1510 /* Device Identification, Die Identification */
1511 static uint32_t omap_id_read(void *opaque, target_phys_addr_t addr)
1513 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1516 case 0xfffe1800: /* DIE_ID_LSB */
1518 case 0xfffe1804: /* DIE_ID_MSB */
1521 case 0xfffe2000: /* PRODUCT_ID_LSB */
1523 case 0xfffe2004: /* PRODUCT_ID_MSB */
1526 case 0xfffed400: /* JTAG_ID_LSB */
1527 switch (s->mpu_model) {
1533 hw_error("%s: bad mpu model\n", __FUNCTION__);
1537 case 0xfffed404: /* JTAG_ID_MSB */
1538 switch (s->mpu_model) {
1544 hw_error("%s: bad mpu model\n", __FUNCTION__);
1553 static void omap_id_write(void *opaque, target_phys_addr_t addr,
1559 static CPUReadMemoryFunc * const omap_id_readfn[] = {
1560 omap_badwidth_read32,
1561 omap_badwidth_read32,
1565 static CPUWriteMemoryFunc * const omap_id_writefn[] = {
1566 omap_badwidth_write32,
1567 omap_badwidth_write32,
1571 static void omap_id_init(struct omap_mpu_state_s *mpu)
1573 int iomemtype = cpu_register_io_memory(omap_id_readfn,
1574 omap_id_writefn, mpu);
1575 cpu_register_physical_memory_offset(0xfffe1800, 0x800, iomemtype, 0xfffe1800);
1576 cpu_register_physical_memory_offset(0xfffed400, 0x100, iomemtype, 0xfffed400);
1577 if (!cpu_is_omap15xx(mpu))
1578 cpu_register_physical_memory_offset(0xfffe2000, 0x800, iomemtype, 0xfffe2000);
1581 /* MPUI Control (Dummy) */
1582 static uint32_t omap_mpui_read(void *opaque, target_phys_addr_t addr)
1584 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1587 case 0x00: /* CTRL */
1588 return s->mpui_ctrl;
1589 case 0x04: /* DEBUG_ADDR */
1591 case 0x08: /* DEBUG_DATA */
1593 case 0x0c: /* DEBUG_FLAG */
1595 case 0x10: /* STATUS */
1598 /* Not in OMAP310 */
1599 case 0x14: /* DSP_STATUS */
1600 case 0x18: /* DSP_BOOT_CONFIG */
1602 case 0x1c: /* DSP_MPUI_CONFIG */
1610 static void omap_mpui_write(void *opaque, target_phys_addr_t addr,
1613 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1616 case 0x00: /* CTRL */
1617 s->mpui_ctrl = value & 0x007fffff;
1620 case 0x04: /* DEBUG_ADDR */
1621 case 0x08: /* DEBUG_DATA */
1622 case 0x0c: /* DEBUG_FLAG */
1623 case 0x10: /* STATUS */
1624 /* Not in OMAP310 */
1625 case 0x14: /* DSP_STATUS */
1627 case 0x18: /* DSP_BOOT_CONFIG */
1628 case 0x1c: /* DSP_MPUI_CONFIG */
1636 static CPUReadMemoryFunc * const omap_mpui_readfn[] = {
1637 omap_badwidth_read32,
1638 omap_badwidth_read32,
1642 static CPUWriteMemoryFunc * const omap_mpui_writefn[] = {
1643 omap_badwidth_write32,
1644 omap_badwidth_write32,
1648 static void omap_mpui_reset(struct omap_mpu_state_s *s)
1650 s->mpui_ctrl = 0x0003ff1b;
1653 static void omap_mpui_init(target_phys_addr_t base,
1654 struct omap_mpu_state_s *mpu)
1656 int iomemtype = cpu_register_io_memory(omap_mpui_readfn,
1657 omap_mpui_writefn, mpu);
1659 cpu_register_physical_memory(base, 0x100, iomemtype);
1661 omap_mpui_reset(mpu);
1665 struct omap_tipb_bridge_s {
1672 uint16_t enh_control;
1675 static uint32_t omap_tipb_bridge_read(void *opaque, target_phys_addr_t addr)
1677 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1680 case 0x00: /* TIPB_CNTL */
1682 case 0x04: /* TIPB_BUS_ALLOC */
1684 case 0x08: /* MPU_TIPB_CNTL */
1686 case 0x0c: /* ENHANCED_TIPB_CNTL */
1687 return s->enh_control;
1688 case 0x10: /* ADDRESS_DBG */
1689 case 0x14: /* DATA_DEBUG_LOW */
1690 case 0x18: /* DATA_DEBUG_HIGH */
1692 case 0x1c: /* DEBUG_CNTR_SIG */
1700 static void omap_tipb_bridge_write(void *opaque, target_phys_addr_t addr,
1703 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1706 case 0x00: /* TIPB_CNTL */
1707 s->control = value & 0xffff;
1710 case 0x04: /* TIPB_BUS_ALLOC */
1711 s->alloc = value & 0x003f;
1714 case 0x08: /* MPU_TIPB_CNTL */
1715 s->buffer = value & 0x0003;
1718 case 0x0c: /* ENHANCED_TIPB_CNTL */
1719 s->width_intr = !(value & 2);
1720 s->enh_control = value & 0x000f;
1723 case 0x10: /* ADDRESS_DBG */
1724 case 0x14: /* DATA_DEBUG_LOW */
1725 case 0x18: /* DATA_DEBUG_HIGH */
1726 case 0x1c: /* DEBUG_CNTR_SIG */
1735 static CPUReadMemoryFunc * const omap_tipb_bridge_readfn[] = {
1736 omap_badwidth_read16,
1737 omap_tipb_bridge_read,
1738 omap_tipb_bridge_read,
1741 static CPUWriteMemoryFunc * const omap_tipb_bridge_writefn[] = {
1742 omap_badwidth_write16,
1743 omap_tipb_bridge_write,
1744 omap_tipb_bridge_write,
1747 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s)
1749 s->control = 0xffff;
1752 s->enh_control = 0x000f;
1755 struct omap_tipb_bridge_s *omap_tipb_bridge_init(target_phys_addr_t base,
1756 qemu_irq abort_irq, omap_clk clk)
1759 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *)
1760 qemu_mallocz(sizeof(struct omap_tipb_bridge_s));
1762 s->abort = abort_irq;
1763 omap_tipb_bridge_reset(s);
1765 iomemtype = cpu_register_io_memory(omap_tipb_bridge_readfn,
1766 omap_tipb_bridge_writefn, s);
1767 cpu_register_physical_memory(base, 0x100, iomemtype);
1772 /* Dummy Traffic Controller's Memory Interface */
1773 static uint32_t omap_tcmi_read(void *opaque, target_phys_addr_t addr)
1775 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1779 case 0x00: /* IMIF_PRIO */
1780 case 0x04: /* EMIFS_PRIO */
1781 case 0x08: /* EMIFF_PRIO */
1782 case 0x0c: /* EMIFS_CONFIG */
1783 case 0x10: /* EMIFS_CS0_CONFIG */
1784 case 0x14: /* EMIFS_CS1_CONFIG */
1785 case 0x18: /* EMIFS_CS2_CONFIG */
1786 case 0x1c: /* EMIFS_CS3_CONFIG */
1787 case 0x24: /* EMIFF_MRS */
1788 case 0x28: /* TIMEOUT1 */
1789 case 0x2c: /* TIMEOUT2 */
1790 case 0x30: /* TIMEOUT3 */
1791 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1792 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1793 return s->tcmi_regs[addr >> 2];
1795 case 0x20: /* EMIFF_SDRAM_CONFIG */
1796 ret = s->tcmi_regs[addr >> 2];
1797 s->tcmi_regs[addr >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1798 /* XXX: We can try using the VGA_DIRTY flag for this */
1806 static void omap_tcmi_write(void *opaque, target_phys_addr_t addr,
1809 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1812 case 0x00: /* IMIF_PRIO */
1813 case 0x04: /* EMIFS_PRIO */
1814 case 0x08: /* EMIFF_PRIO */
1815 case 0x10: /* EMIFS_CS0_CONFIG */
1816 case 0x14: /* EMIFS_CS1_CONFIG */
1817 case 0x18: /* EMIFS_CS2_CONFIG */
1818 case 0x1c: /* EMIFS_CS3_CONFIG */
1819 case 0x20: /* EMIFF_SDRAM_CONFIG */
1820 case 0x24: /* EMIFF_MRS */
1821 case 0x28: /* TIMEOUT1 */
1822 case 0x2c: /* TIMEOUT2 */
1823 case 0x30: /* TIMEOUT3 */
1824 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1825 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1826 s->tcmi_regs[addr >> 2] = value;
1828 case 0x0c: /* EMIFS_CONFIG */
1829 s->tcmi_regs[addr >> 2] = (value & 0xf) | (1 << 4);
1837 static CPUReadMemoryFunc * const omap_tcmi_readfn[] = {
1838 omap_badwidth_read32,
1839 omap_badwidth_read32,
1843 static CPUWriteMemoryFunc * const omap_tcmi_writefn[] = {
1844 omap_badwidth_write32,
1845 omap_badwidth_write32,
1849 static void omap_tcmi_reset(struct omap_mpu_state_s *mpu)
1851 mpu->tcmi_regs[0x00 >> 2] = 0x00000000;
1852 mpu->tcmi_regs[0x04 >> 2] = 0x00000000;
1853 mpu->tcmi_regs[0x08 >> 2] = 0x00000000;
1854 mpu->tcmi_regs[0x0c >> 2] = 0x00000010;
1855 mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb;
1856 mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb;
1857 mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb;
1858 mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb;
1859 mpu->tcmi_regs[0x20 >> 2] = 0x00618800;
1860 mpu->tcmi_regs[0x24 >> 2] = 0x00000037;
1861 mpu->tcmi_regs[0x28 >> 2] = 0x00000000;
1862 mpu->tcmi_regs[0x2c >> 2] = 0x00000000;
1863 mpu->tcmi_regs[0x30 >> 2] = 0x00000000;
1864 mpu->tcmi_regs[0x3c >> 2] = 0x00000003;
1865 mpu->tcmi_regs[0x40 >> 2] = 0x00000000;
1868 static void omap_tcmi_init(target_phys_addr_t base,
1869 struct omap_mpu_state_s *mpu)
1871 int iomemtype = cpu_register_io_memory(omap_tcmi_readfn,
1872 omap_tcmi_writefn, mpu);
1874 cpu_register_physical_memory(base, 0x100, iomemtype);
1875 omap_tcmi_reset(mpu);
1878 /* Digital phase-locked loops control */
1879 static uint32_t omap_dpll_read(void *opaque, target_phys_addr_t addr)
1881 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1883 if (addr == 0x00) /* CTL_REG */
1890 static void omap_dpll_write(void *opaque, target_phys_addr_t addr,
1893 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1895 static const int bypass_div[4] = { 1, 2, 4, 4 };
1898 if (addr == 0x00) { /* CTL_REG */
1899 /* See omap_ulpd_pm_write() too */
1900 diff = s->mode & value;
1901 s->mode = value & 0x2fff;
1902 if (diff & (0x3ff << 2)) {
1903 if (value & (1 << 4)) { /* PLL_ENABLE */
1904 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1905 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1907 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1910 omap_clk_setrate(s->dpll, div, mult);
1913 /* Enter the desired mode. */
1914 s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1);
1916 /* Act as if the lock is restored. */
1923 static CPUReadMemoryFunc * const omap_dpll_readfn[] = {
1924 omap_badwidth_read16,
1926 omap_badwidth_read16,
1929 static CPUWriteMemoryFunc * const omap_dpll_writefn[] = {
1930 omap_badwidth_write16,
1932 omap_badwidth_write16,
1935 static void omap_dpll_reset(struct dpll_ctl_s *s)
1938 omap_clk_setrate(s->dpll, 1, 1);
1941 static void omap_dpll_init(struct dpll_ctl_s *s, target_phys_addr_t base,
1944 int iomemtype = cpu_register_io_memory(omap_dpll_readfn,
1945 omap_dpll_writefn, s);
1950 cpu_register_physical_memory(base, 0x100, iomemtype);
1954 struct omap_uart_s {
1955 target_phys_addr_t base;
1956 SerialState *serial; /* TODO */
1957 struct omap_target_agent_s *ta;
1970 void omap_uart_reset(struct omap_uart_s *s)
1979 struct omap_uart_s *omap_uart_init(target_phys_addr_t base,
1980 qemu_irq irq, omap_clk fclk, omap_clk iclk,
1981 qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr)
1983 struct omap_uart_s *s = (struct omap_uart_s *)
1984 qemu_mallocz(sizeof(struct omap_uart_s));
1989 #ifdef TARGET_WORDS_BIGENDIAN
1990 s->serial = serial_mm_init(base, 2, irq, omap_clk_getrate(fclk)/16,
1991 chr ?: qemu_chr_open("null", "null", NULL), 1,
1994 s->serial = serial_mm_init(base, 2, irq, omap_clk_getrate(fclk)/16,
1995 chr ?: qemu_chr_open("null", "null", NULL), 1,
2001 static uint32_t omap_uart_read(void *opaque, target_phys_addr_t addr)
2003 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
2007 case 0x20: /* MDR1 */
2009 case 0x24: /* MDR2 */
2011 case 0x40: /* SCR */
2013 case 0x44: /* SSR */
2015 case 0x48: /* EBLR (OMAP2) */
2017 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2019 case 0x50: /* MVR */
2021 case 0x54: /* SYSC (OMAP2) */
2022 return s->syscontrol;
2023 case 0x58: /* SYSS (OMAP2) */
2025 case 0x5c: /* WER (OMAP2) */
2027 case 0x60: /* CFPS (OMAP2) */
2035 static void omap_uart_write(void *opaque, target_phys_addr_t addr,
2038 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
2042 case 0x20: /* MDR1 */
2043 s->mdr[0] = value & 0x7f;
2045 case 0x24: /* MDR2 */
2046 s->mdr[1] = value & 0xff;
2048 case 0x40: /* SCR */
2049 s->scr = value & 0xff;
2051 case 0x48: /* EBLR (OMAP2) */
2052 s->eblr = value & 0xff;
2054 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2055 s->clksel = value & 1;
2057 case 0x44: /* SSR */
2058 case 0x50: /* MVR */
2059 case 0x58: /* SYSS (OMAP2) */
2062 case 0x54: /* SYSC (OMAP2) */
2063 s->syscontrol = value & 0x1d;
2067 case 0x5c: /* WER (OMAP2) */
2068 s->wkup = value & 0x7f;
2070 case 0x60: /* CFPS (OMAP2) */
2071 s->cfps = value & 0xff;
2078 static CPUReadMemoryFunc * const omap_uart_readfn[] = {
2081 omap_badwidth_read8,
2084 static CPUWriteMemoryFunc * const omap_uart_writefn[] = {
2087 omap_badwidth_write8,
2090 struct omap_uart_s *omap2_uart_init(struct omap_target_agent_s *ta,
2091 qemu_irq irq, omap_clk fclk, omap_clk iclk,
2092 qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr)
2094 target_phys_addr_t base = omap_l4_attach(ta, 0, 0);
2095 struct omap_uart_s *s = omap_uart_init(base, irq,
2096 fclk, iclk, txdma, rxdma, chr);
2097 int iomemtype = cpu_register_io_memory(omap_uart_readfn,
2098 omap_uart_writefn, s);
2102 cpu_register_physical_memory(base + 0x20, 0x100, iomemtype);
2107 void omap_uart_attach(struct omap_uart_s *s, CharDriverState *chr)
2109 /* TODO: Should reuse or destroy current s->serial */
2110 #ifdef TARGET_WORDS_BIGENDIAN
2111 s->serial = serial_mm_init(s->base, 2, s->irq,
2112 omap_clk_getrate(s->fclk) / 16,
2113 chr ?: qemu_chr_open("null", "null", NULL), 1,
2116 s->serial = serial_mm_init(s->base, 2, s->irq,
2117 omap_clk_getrate(s->fclk) / 16,
2118 chr ?: qemu_chr_open("null", "null", NULL), 1,
2123 /* MPU Clock/Reset/Power Mode Control */
2124 static uint32_t omap_clkm_read(void *opaque, target_phys_addr_t addr)
2126 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2129 case 0x00: /* ARM_CKCTL */
2130 return s->clkm.arm_ckctl;
2132 case 0x04: /* ARM_IDLECT1 */
2133 return s->clkm.arm_idlect1;
2135 case 0x08: /* ARM_IDLECT2 */
2136 return s->clkm.arm_idlect2;
2138 case 0x0c: /* ARM_EWUPCT */
2139 return s->clkm.arm_ewupct;
2141 case 0x10: /* ARM_RSTCT1 */
2142 return s->clkm.arm_rstct1;
2144 case 0x14: /* ARM_RSTCT2 */
2145 return s->clkm.arm_rstct2;
2147 case 0x18: /* ARM_SYSST */
2148 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start;
2150 case 0x1c: /* ARM_CKOUT1 */
2151 return s->clkm.arm_ckout1;
2153 case 0x20: /* ARM_CKOUT2 */
2161 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s,
2162 uint16_t diff, uint16_t value)
2166 if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */
2167 if (value & (1 << 14))
2170 clk = omap_findclk(s, "arminth_ck");
2171 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
2174 if (diff & (1 << 12)) { /* ARM_TIMXO */
2175 clk = omap_findclk(s, "armtim_ck");
2176 if (value & (1 << 12))
2177 omap_clk_reparent(clk, omap_findclk(s, "clkin"));
2179 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
2182 if (diff & (3 << 10)) { /* DSPMMUDIV */
2183 clk = omap_findclk(s, "dspmmu_ck");
2184 omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1);
2186 if (diff & (3 << 8)) { /* TCDIV */
2187 clk = omap_findclk(s, "tc_ck");
2188 omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1);
2190 if (diff & (3 << 6)) { /* DSPDIV */
2191 clk = omap_findclk(s, "dsp_ck");
2192 omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1);
2194 if (diff & (3 << 4)) { /* ARMDIV */
2195 clk = omap_findclk(s, "arm_ck");
2196 omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1);
2198 if (diff & (3 << 2)) { /* LCDDIV */
2199 clk = omap_findclk(s, "lcd_ck");
2200 omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1);
2202 if (diff & (3 << 0)) { /* PERDIV */
2203 clk = omap_findclk(s, "armper_ck");
2204 omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1);
2208 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s,
2209 uint16_t diff, uint16_t value)
2213 if (value & (1 << 11)) /* SETARM_IDLE */
2214 cpu_interrupt(s->env, CPU_INTERRUPT_HALT);
2215 if (!(value & (1 << 10))) /* WKUP_MODE */
2216 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
2218 #define SET_CANIDLE(clock, bit) \
2219 if (diff & (1 << bit)) { \
2220 clk = omap_findclk(s, clock); \
2221 omap_clk_canidle(clk, (value >> bit) & 1); \
2223 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
2224 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
2225 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
2226 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
2227 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
2228 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
2229 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
2230 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
2231 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
2232 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
2233 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
2234 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
2235 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
2236 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
2239 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s,
2240 uint16_t diff, uint16_t value)
2244 #define SET_ONOFF(clock, bit) \
2245 if (diff & (1 << bit)) { \
2246 clk = omap_findclk(s, clock); \
2247 omap_clk_onoff(clk, (value >> bit) & 1); \
2249 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
2250 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
2251 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
2252 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
2253 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
2254 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
2255 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
2256 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
2257 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
2258 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
2259 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
2262 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s,
2263 uint16_t diff, uint16_t value)
2267 if (diff & (3 << 4)) { /* TCLKOUT */
2268 clk = omap_findclk(s, "tclk_out");
2269 switch ((value >> 4) & 3) {
2271 omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
2272 omap_clk_onoff(clk, 1);
2275 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
2276 omap_clk_onoff(clk, 1);
2279 omap_clk_onoff(clk, 0);
2282 if (diff & (3 << 2)) { /* DCLKOUT */
2283 clk = omap_findclk(s, "dclk_out");
2284 switch ((value >> 2) & 3) {
2286 omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
2289 omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
2292 omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
2295 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
2299 if (diff & (3 << 0)) { /* ACLKOUT */
2300 clk = omap_findclk(s, "aclk_out");
2301 switch ((value >> 0) & 3) {
2303 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
2304 omap_clk_onoff(clk, 1);
2307 omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
2308 omap_clk_onoff(clk, 1);
2311 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
2312 omap_clk_onoff(clk, 1);
2315 omap_clk_onoff(clk, 0);
2320 static void omap_clkm_write(void *opaque, target_phys_addr_t addr,
2323 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2326 static const char *clkschemename[8] = {
2327 "fully synchronous", "fully asynchronous", "synchronous scalable",
2328 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
2332 case 0x00: /* ARM_CKCTL */
2333 diff = s->clkm.arm_ckctl ^ value;
2334 s->clkm.arm_ckctl = value & 0x7fff;
2335 omap_clkm_ckctl_update(s, diff, value);
2338 case 0x04: /* ARM_IDLECT1 */
2339 diff = s->clkm.arm_idlect1 ^ value;
2340 s->clkm.arm_idlect1 = value & 0x0fff;
2341 omap_clkm_idlect1_update(s, diff, value);
2344 case 0x08: /* ARM_IDLECT2 */
2345 diff = s->clkm.arm_idlect2 ^ value;
2346 s->clkm.arm_idlect2 = value & 0x07ff;
2347 omap_clkm_idlect2_update(s, diff, value);
2350 case 0x0c: /* ARM_EWUPCT */
2351 s->clkm.arm_ewupct = value & 0x003f;
2354 case 0x10: /* ARM_RSTCT1 */
2355 diff = s->clkm.arm_rstct1 ^ value;
2356 s->clkm.arm_rstct1 = value & 0x0007;
2358 qemu_system_reset_request();
2359 s->clkm.cold_start = 0xa;
2361 if (diff & ~value & 4) { /* DSP_RST */
2363 omap_tipb_bridge_reset(s->private_tipb);
2364 omap_tipb_bridge_reset(s->public_tipb);
2366 if (diff & 2) { /* DSP_EN */
2367 clk = omap_findclk(s, "dsp_ck");
2368 omap_clk_canidle(clk, (~value >> 1) & 1);
2372 case 0x14: /* ARM_RSTCT2 */
2373 s->clkm.arm_rstct2 = value & 0x0001;
2376 case 0x18: /* ARM_SYSST */
2377 if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) {
2378 s->clkm.clocking_scheme = (value >> 11) & 7;
2379 printf("%s: clocking scheme set to %s\n", __FUNCTION__,
2380 clkschemename[s->clkm.clocking_scheme]);
2382 s->clkm.cold_start &= value & 0x3f;
2385 case 0x1c: /* ARM_CKOUT1 */
2386 diff = s->clkm.arm_ckout1 ^ value;
2387 s->clkm.arm_ckout1 = value & 0x003f;
2388 omap_clkm_ckout1_update(s, diff, value);
2391 case 0x20: /* ARM_CKOUT2 */
2397 static CPUReadMemoryFunc * const omap_clkm_readfn[] = {
2398 omap_badwidth_read16,
2400 omap_badwidth_read16,
2403 static CPUWriteMemoryFunc * const omap_clkm_writefn[] = {
2404 omap_badwidth_write16,
2406 omap_badwidth_write16,
2409 static uint32_t omap_clkdsp_read(void *opaque, target_phys_addr_t addr)
2411 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2414 case 0x04: /* DSP_IDLECT1 */
2415 return s->clkm.dsp_idlect1;
2417 case 0x08: /* DSP_IDLECT2 */
2418 return s->clkm.dsp_idlect2;
2420 case 0x14: /* DSP_RSTCT2 */
2421 return s->clkm.dsp_rstct2;
2423 case 0x18: /* DSP_SYSST */
2424 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start |
2425 (s->env->halted << 6); /* Quite useless... */
2432 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s,
2433 uint16_t diff, uint16_t value)
2437 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
2440 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s,
2441 uint16_t diff, uint16_t value)
2445 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
2448 static void omap_clkdsp_write(void *opaque, target_phys_addr_t addr,
2451 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2455 case 0x04: /* DSP_IDLECT1 */
2456 diff = s->clkm.dsp_idlect1 ^ value;
2457 s->clkm.dsp_idlect1 = value & 0x01f7;
2458 omap_clkdsp_idlect1_update(s, diff, value);
2461 case 0x08: /* DSP_IDLECT2 */
2462 s->clkm.dsp_idlect2 = value & 0x0037;
2463 diff = s->clkm.dsp_idlect1 ^ value;
2464 omap_clkdsp_idlect2_update(s, diff, value);
2467 case 0x14: /* DSP_RSTCT2 */
2468 s->clkm.dsp_rstct2 = value & 0x0001;
2471 case 0x18: /* DSP_SYSST */
2472 s->clkm.cold_start &= value & 0x3f;
2480 static CPUReadMemoryFunc * const omap_clkdsp_readfn[] = {
2481 omap_badwidth_read16,
2483 omap_badwidth_read16,
2486 static CPUWriteMemoryFunc * const omap_clkdsp_writefn[] = {
2487 omap_badwidth_write16,
2489 omap_badwidth_write16,
2492 static void omap_clkm_reset(struct omap_mpu_state_s *s)
2494 if (s->wdt && s->wdt->reset)
2495 s->clkm.cold_start = 0x6;
2496 s->clkm.clocking_scheme = 0;
2497 omap_clkm_ckctl_update(s, ~0, 0x3000);
2498 s->clkm.arm_ckctl = 0x3000;
2499 omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 ^ 0x0400, 0x0400);
2500 s->clkm.arm_idlect1 = 0x0400;
2501 omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 ^ 0x0100, 0x0100);
2502 s->clkm.arm_idlect2 = 0x0100;
2503 s->clkm.arm_ewupct = 0x003f;
2504 s->clkm.arm_rstct1 = 0x0000;
2505 s->clkm.arm_rstct2 = 0x0000;
2506 s->clkm.arm_ckout1 = 0x0015;
2507 s->clkm.dpll1_mode = 0x2002;
2508 omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040);
2509 s->clkm.dsp_idlect1 = 0x0040;
2510 omap_clkdsp_idlect2_update(s, ~0, 0x0000);
2511 s->clkm.dsp_idlect2 = 0x0000;
2512 s->clkm.dsp_rstct2 = 0x0000;
2515 static void omap_clkm_init(target_phys_addr_t mpu_base,
2516 target_phys_addr_t dsp_base, struct omap_mpu_state_s *s)
2518 int iomemtype[2] = {
2519 cpu_register_io_memory(omap_clkm_readfn, omap_clkm_writefn, s),
2520 cpu_register_io_memory(omap_clkdsp_readfn, omap_clkdsp_writefn, s),
2523 s->clkm.arm_idlect1 = 0x03ff;
2524 s->clkm.arm_idlect2 = 0x0100;
2525 s->clkm.dsp_idlect1 = 0x0002;
2527 s->clkm.cold_start = 0x3a;
2529 cpu_register_physical_memory(mpu_base, 0x100, iomemtype[0]);
2530 cpu_register_physical_memory(dsp_base, 0x1000, iomemtype[1]);
2534 struct omap_mpuio_s {
2538 qemu_irq handler[16];
2559 static void omap_mpuio_set(void *opaque, int line, int level)
2561 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2562 uint16_t prev = s->inputs;
2565 s->inputs |= 1 << line;
2567 s->inputs &= ~(1 << line);
2569 if (((1 << line) & s->dir & ~s->mask) && s->clk) {
2570 if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
2571 s->ints |= 1 << line;
2572 qemu_irq_raise(s->irq);
2575 if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */
2576 (s->event >> 1) == line) /* PIN_SELECT */
2577 s->latch = s->inputs;
2581 static void omap_mpuio_kbd_update(struct omap_mpuio_s *s)
2584 uint8_t *row, rows = 0, cols = ~s->cols;
2586 for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1)
2590 qemu_set_irq(s->kbd_irq, rows && !s->kbd_mask && s->clk);
2591 s->row_latch = ~rows;
2594 static uint32_t omap_mpuio_read(void *opaque, target_phys_addr_t addr)
2596 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2597 int offset = addr & OMAP_MPUI_REG_MASK;
2601 case 0x00: /* INPUT_LATCH */
2604 case 0x04: /* OUTPUT_REG */
2607 case 0x08: /* IO_CNTL */
2610 case 0x10: /* KBR_LATCH */
2611 return s->row_latch;
2613 case 0x14: /* KBC_REG */
2616 case 0x18: /* GPIO_EVENT_MODE_REG */
2619 case 0x1c: /* GPIO_INT_EDGE_REG */
2622 case 0x20: /* KBD_INT */
2623 return (~s->row_latch & 0x1f) && !s->kbd_mask;
2625 case 0x24: /* GPIO_INT */
2629 qemu_irq_lower(s->irq);
2632 case 0x28: /* KBD_MASKIT */
2635 case 0x2c: /* GPIO_MASKIT */
2638 case 0x30: /* GPIO_DEBOUNCING_REG */
2641 case 0x34: /* GPIO_LATCH_REG */
2649 static void omap_mpuio_write(void *opaque, target_phys_addr_t addr,
2652 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2653 int offset = addr & OMAP_MPUI_REG_MASK;
2658 case 0x04: /* OUTPUT_REG */
2659 diff = (s->outputs ^ value) & ~s->dir;
2661 while ((ln = ffs(diff))) {
2664 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2669 case 0x08: /* IO_CNTL */
2670 diff = s->outputs & (s->dir ^ value);
2673 value = s->outputs & ~s->dir;
2674 while ((ln = ffs(diff))) {
2677 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2682 case 0x14: /* KBC_REG */
2684 omap_mpuio_kbd_update(s);
2687 case 0x18: /* GPIO_EVENT_MODE_REG */
2688 s->event = value & 0x1f;
2691 case 0x1c: /* GPIO_INT_EDGE_REG */
2695 case 0x28: /* KBD_MASKIT */
2696 s->kbd_mask = value & 1;
2697 omap_mpuio_kbd_update(s);
2700 case 0x2c: /* GPIO_MASKIT */
2704 case 0x30: /* GPIO_DEBOUNCING_REG */
2705 s->debounce = value & 0x1ff;
2708 case 0x00: /* INPUT_LATCH */
2709 case 0x10: /* KBR_LATCH */
2710 case 0x20: /* KBD_INT */
2711 case 0x24: /* GPIO_INT */
2712 case 0x34: /* GPIO_LATCH_REG */
2722 static CPUReadMemoryFunc * const omap_mpuio_readfn[] = {
2723 omap_badwidth_read16,
2725 omap_badwidth_read16,
2728 static CPUWriteMemoryFunc * const omap_mpuio_writefn[] = {
2729 omap_badwidth_write16,
2731 omap_badwidth_write16,
2734 static void omap_mpuio_reset(struct omap_mpuio_s *s)
2746 s->row_latch = 0x1f;
2750 static void omap_mpuio_onoff(void *opaque, int line, int on)
2752 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2756 omap_mpuio_kbd_update(s);
2759 struct omap_mpuio_s *omap_mpuio_init(target_phys_addr_t base,
2760 qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup,
2764 struct omap_mpuio_s *s = (struct omap_mpuio_s *)
2765 qemu_mallocz(sizeof(struct omap_mpuio_s));
2768 s->kbd_irq = kbd_int;
2770 s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
2771 omap_mpuio_reset(s);
2773 iomemtype = cpu_register_io_memory(omap_mpuio_readfn,
2774 omap_mpuio_writefn, s);
2775 cpu_register_physical_memory(base, 0x800, iomemtype);
2777 omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]);
2782 qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
2787 void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler)
2789 if (line >= 16 || line < 0)
2790 hw_error("%s: No GPIO line %i\n", __FUNCTION__, line);
2791 s->handler[line] = handler;
2794 void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down)
2796 if (row >= 5 || row < 0)
2797 hw_error("%s: No key %i-%i\n", __FUNCTION__, col, row);
2800 s->buttons[row] |= 1 << col;
2802 s->buttons[row] &= ~(1 << col);
2804 omap_mpuio_kbd_update(s);
2807 /* General-Purpose I/O */
2808 struct omap_gpio_s {
2811 qemu_irq handler[16];
2822 static void omap_gpio_set(void *opaque, int line, int level)
2824 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2825 uint16_t prev = s->inputs;
2828 s->inputs |= 1 << line;
2830 s->inputs &= ~(1 << line);
2832 if (((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) &
2833 (1 << line) & s->dir & ~s->mask) {
2834 s->ints |= 1 << line;
2835 qemu_irq_raise(s->irq);
2839 static uint32_t omap_gpio_read(void *opaque, target_phys_addr_t addr)
2841 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2842 int offset = addr & OMAP_MPUI_REG_MASK;
2845 case 0x00: /* DATA_INPUT */
2846 return s->inputs & s->pins;
2848 case 0x04: /* DATA_OUTPUT */
2851 case 0x08: /* DIRECTION_CONTROL */
2854 case 0x0c: /* INTERRUPT_CONTROL */
2857 case 0x10: /* INTERRUPT_MASK */
2860 case 0x14: /* INTERRUPT_STATUS */
2863 case 0x18: /* PIN_CONTROL (not in OMAP310) */
2872 static void omap_gpio_write(void *opaque, target_phys_addr_t addr,
2875 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2876 int offset = addr & OMAP_MPUI_REG_MASK;
2881 case 0x00: /* DATA_INPUT */
2885 case 0x04: /* DATA_OUTPUT */
2886 diff = (s->outputs ^ value) & ~s->dir;
2888 while ((ln = ffs(diff))) {
2891 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2896 case 0x08: /* DIRECTION_CONTROL */
2897 diff = s->outputs & (s->dir ^ value);
2900 value = s->outputs & ~s->dir;
2901 while ((ln = ffs(diff))) {
2904 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2909 case 0x0c: /* INTERRUPT_CONTROL */
2913 case 0x10: /* INTERRUPT_MASK */
2917 case 0x14: /* INTERRUPT_STATUS */
2920 qemu_irq_lower(s->irq);
2923 case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */
2934 /* *Some* sources say the memory region is 32-bit. */
2935 static CPUReadMemoryFunc * const omap_gpio_readfn[] = {
2936 omap_badwidth_read16,
2938 omap_badwidth_read16,
2941 static CPUWriteMemoryFunc * const omap_gpio_writefn[] = {
2942 omap_badwidth_write16,
2944 omap_badwidth_write16,
2947 static void omap_gpio_reset(struct omap_gpio_s *s)
2958 struct omap_gpio_s *omap_gpio_init(target_phys_addr_t base,
2959 qemu_irq irq, omap_clk clk)
2962 struct omap_gpio_s *s = (struct omap_gpio_s *)
2963 qemu_mallocz(sizeof(struct omap_gpio_s));
2966 s->in = qemu_allocate_irqs(omap_gpio_set, s, 16);
2969 iomemtype = cpu_register_io_memory(omap_gpio_readfn,
2970 omap_gpio_writefn, s);
2971 cpu_register_physical_memory(base, 0x1000, iomemtype);
2976 qemu_irq *omap_gpio_in_get(struct omap_gpio_s *s)
2981 void omap_gpio_out_set(struct omap_gpio_s *s, int line, qemu_irq handler)
2983 if (line >= 16 || line < 0)
2984 hw_error("%s: No GPIO line %i\n", __FUNCTION__, line);
2985 s->handler[line] = handler;
2988 /* MicroWire Interface */
2989 struct omap_uwire_s {
2999 uWireSlave *chip[4];
3002 static void omap_uwire_transfer_start(struct omap_uwire_s *s)
3004 int chipselect = (s->control >> 10) & 3; /* INDEX */
3005 uWireSlave *slave = s->chip[chipselect];
3007 if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */
3008 if (s->control & (1 << 12)) /* CS_CMD */
3009 if (slave && slave->send)
3010 slave->send(slave->opaque,
3011 s->txbuf >> (16 - ((s->control >> 5) & 0x1f)));
3012 s->control &= ~(1 << 14); /* CSRB */
3013 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3014 * a DRQ. When is the level IRQ supposed to be reset? */
3017 if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */
3018 if (s->control & (1 << 12)) /* CS_CMD */
3019 if (slave && slave->receive)
3020 s->rxbuf = slave->receive(slave->opaque);
3021 s->control |= 1 << 15; /* RDRB */
3022 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3023 * a DRQ. When is the level IRQ supposed to be reset? */
3027 static uint32_t omap_uwire_read(void *opaque, target_phys_addr_t addr)
3029 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
3030 int offset = addr & OMAP_MPUI_REG_MASK;
3033 case 0x00: /* RDR */
3034 s->control &= ~(1 << 15); /* RDRB */
3037 case 0x04: /* CSR */
3040 case 0x08: /* SR1 */
3042 case 0x0c: /* SR2 */
3044 case 0x10: /* SR3 */
3046 case 0x14: /* SR4 */
3048 case 0x18: /* SR5 */
3056 static void omap_uwire_write(void *opaque, target_phys_addr_t addr,
3059 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
3060 int offset = addr & OMAP_MPUI_REG_MASK;
3063 case 0x00: /* TDR */
3064 s->txbuf = value; /* TD */
3065 if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */
3066 ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
3067 (s->control & (1 << 12)))) { /* CS_CMD */
3068 s->control |= 1 << 14; /* CSRB */
3069 omap_uwire_transfer_start(s);
3073 case 0x04: /* CSR */
3074 s->control = value & 0x1fff;
3075 if (value & (1 << 13)) /* START */
3076 omap_uwire_transfer_start(s);
3079 case 0x08: /* SR1 */
3080 s->setup[0] = value & 0x003f;
3083 case 0x0c: /* SR2 */
3084 s->setup[1] = value & 0x0fc0;
3087 case 0x10: /* SR3 */
3088 s->setup[2] = value & 0x0003;
3091 case 0x14: /* SR4 */
3092 s->setup[3] = value & 0x0001;
3095 case 0x18: /* SR5 */
3096 s->setup[4] = value & 0x000f;
3105 static CPUReadMemoryFunc * const omap_uwire_readfn[] = {
3106 omap_badwidth_read16,
3108 omap_badwidth_read16,
3111 static CPUWriteMemoryFunc * const omap_uwire_writefn[] = {
3112 omap_badwidth_write16,
3114 omap_badwidth_write16,
3117 static void omap_uwire_reset(struct omap_uwire_s *s)
3127 struct omap_uwire_s *omap_uwire_init(target_phys_addr_t base,
3128 qemu_irq *irq, qemu_irq dma, omap_clk clk)
3131 struct omap_uwire_s *s = (struct omap_uwire_s *)
3132 qemu_mallocz(sizeof(struct omap_uwire_s));
3137 omap_uwire_reset(s);
3139 iomemtype = cpu_register_io_memory(omap_uwire_readfn,
3140 omap_uwire_writefn, s);
3141 cpu_register_physical_memory(base, 0x800, iomemtype);
3146 void omap_uwire_attach(struct omap_uwire_s *s,
3147 uWireSlave *slave, int chipselect)
3149 if (chipselect < 0 || chipselect > 3) {
3150 fprintf(stderr, "%s: Bad chipselect %i\n", __FUNCTION__, chipselect);
3154 s->chip[chipselect] = slave;
3157 /* Pseudonoise Pulse-Width Light Modulator */
3158 static void omap_pwl_update(struct omap_mpu_state_s *s)
3160 int output = (s->pwl.clk && s->pwl.enable) ? s->pwl.level : 0;
3162 if (output != s->pwl.output) {
3163 s->pwl.output = output;
3164 printf("%s: Backlight now at %i/256\n", __FUNCTION__, output);
3168 static uint32_t omap_pwl_read(void *opaque, target_phys_addr_t addr)
3170 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3171 int offset = addr & OMAP_MPUI_REG_MASK;
3174 case 0x00: /* PWL_LEVEL */
3175 return s->pwl.level;
3176 case 0x04: /* PWL_CTRL */
3177 return s->pwl.enable;
3183 static void omap_pwl_write(void *opaque, target_phys_addr_t addr,
3186 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3187 int offset = addr & OMAP_MPUI_REG_MASK;
3190 case 0x00: /* PWL_LEVEL */
3191 s->pwl.level = value;
3194 case 0x04: /* PWL_CTRL */
3195 s->pwl.enable = value & 1;
3204 static CPUReadMemoryFunc * const omap_pwl_readfn[] = {
3206 omap_badwidth_read8,
3207 omap_badwidth_read8,
3210 static CPUWriteMemoryFunc * const omap_pwl_writefn[] = {
3212 omap_badwidth_write8,
3213 omap_badwidth_write8,
3216 static void omap_pwl_reset(struct omap_mpu_state_s *s)
3225 static void omap_pwl_clk_update(void *opaque, int line, int on)
3227 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3233 static void omap_pwl_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
3240 iomemtype = cpu_register_io_memory(omap_pwl_readfn,
3241 omap_pwl_writefn, s);
3242 cpu_register_physical_memory(base, 0x800, iomemtype);
3244 omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]);
3247 /* Pulse-Width Tone module */
3248 static uint32_t omap_pwt_read(void *opaque, target_phys_addr_t addr)
3250 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3251 int offset = addr & OMAP_MPUI_REG_MASK;
3254 case 0x00: /* FRC */
3256 case 0x04: /* VCR */
3258 case 0x08: /* GCR */
3265 static void omap_pwt_write(void *opaque, target_phys_addr_t addr,
3268 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3269 int offset = addr & OMAP_MPUI_REG_MASK;
3272 case 0x00: /* FRC */
3273 s->pwt.frc = value & 0x3f;
3275 case 0x04: /* VRC */
3276 if ((value ^ s->pwt.vrc) & 1) {
3278 printf("%s: %iHz buzz on\n", __FUNCTION__, (int)
3279 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
3280 ((omap_clk_getrate(s->pwt.clk) >> 3) /
3281 /* Pre-multiplexer divider */
3282 ((s->pwt.gcr & 2) ? 1 : 154) /
3283 /* Octave multiplexer */
3284 (2 << (value & 3)) *
3285 /* 101/107 divider */
3286 ((value & (1 << 2)) ? 101 : 107) *
3288 ((value & (1 << 3)) ? 49 : 55) *
3290 ((value & (1 << 4)) ? 50 : 63) *
3291 /* 80/127 divider */
3292 ((value & (1 << 5)) ? 80 : 127) /
3293 (107 * 55 * 63 * 127)));
3295 printf("%s: silence!\n", __FUNCTION__);
3297 s->pwt.vrc = value & 0x7f;
3299 case 0x08: /* GCR */
3300 s->pwt.gcr = value & 3;
3308 static CPUReadMemoryFunc * const omap_pwt_readfn[] = {
3310 omap_badwidth_read8,
3311 omap_badwidth_read8,
3314 static CPUWriteMemoryFunc * const omap_pwt_writefn[] = {
3316 omap_badwidth_write8,
3317 omap_badwidth_write8,
3320 static void omap_pwt_reset(struct omap_mpu_state_s *s)
3327 static void omap_pwt_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
3335 iomemtype = cpu_register_io_memory(omap_pwt_readfn,
3336 omap_pwt_writefn, s);
3337 cpu_register_physical_memory(base, 0x800, iomemtype);
3340 /* Real-time Clock module */
3356 struct tm current_tm;
3361 static void omap_rtc_interrupts_update(struct omap_rtc_s *s)
3363 /* s->alarm is level-triggered */
3364 qemu_set_irq(s->alarm, (s->status >> 6) & 1);
3367 static void omap_rtc_alarm_update(struct omap_rtc_s *s)
3369 s->alarm_ti = mktimegm(&s->alarm_tm);
3370 if (s->alarm_ti == -1)
3371 printf("%s: conversion failed\n", __FUNCTION__);
3374 static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr)
3376 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
3377 int offset = addr & OMAP_MPUI_REG_MASK;
3381 case 0x00: /* SECONDS_REG */
3382 return to_bcd(s->current_tm.tm_sec);
3384 case 0x04: /* MINUTES_REG */
3385 return to_bcd(s->current_tm.tm_min);
3387 case 0x08: /* HOURS_REG */
3389 return ((s->current_tm.tm_hour > 11) << 7) |
3390 to_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
3392 return to_bcd(s->current_tm.tm_hour);
3394 case 0x0c: /* DAYS_REG */
3395 return to_bcd(s->current_tm.tm_mday);
3397 case 0x10: /* MONTHS_REG */
3398 return to_bcd(s->current_tm.tm_mon + 1);
3400 case 0x14: /* YEARS_REG */
3401 return to_bcd(s->current_tm.tm_year % 100);
3403 case 0x18: /* WEEK_REG */
3404 return s->current_tm.tm_wday;
3406 case 0x20: /* ALARM_SECONDS_REG */
3407 return to_bcd(s->alarm_tm.tm_sec);
3409 case 0x24: /* ALARM_MINUTES_REG */
3410 return to_bcd(s->alarm_tm.tm_min);
3412 case 0x28: /* ALARM_HOURS_REG */
3414 return ((s->alarm_tm.tm_hour > 11) << 7) |
3415 to_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
3417 return to_bcd(s->alarm_tm.tm_hour);
3419 case 0x2c: /* ALARM_DAYS_REG */
3420 return to_bcd(s->alarm_tm.tm_mday);
3422 case 0x30: /* ALARM_MONTHS_REG */
3423 return to_bcd(s->alarm_tm.tm_mon + 1);
3425 case 0x34: /* ALARM_YEARS_REG */
3426 return to_bcd(s->alarm_tm.tm_year % 100);
3428 case 0x40: /* RTC_CTRL_REG */
3429 return (s->pm_am << 3) | (s->auto_comp << 2) |
3430 (s->round << 1) | s->running;
3432 case 0x44: /* RTC_STATUS_REG */
3437 case 0x48: /* RTC_INTERRUPTS_REG */
3438 return s->interrupts;
3440 case 0x4c: /* RTC_COMP_LSB_REG */
3441 return ((uint16_t) s->comp_reg) & 0xff;
3443 case 0x50: /* RTC_COMP_MSB_REG */
3444 return ((uint16_t) s->comp_reg) >> 8;
3451 static void omap_rtc_write(void *opaque, target_phys_addr_t addr,
3454 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
3455 int offset = addr & OMAP_MPUI_REG_MASK;
3460 case 0x00: /* SECONDS_REG */
3462 printf("RTC SEC_REG <-- %02x\n", value);
3464 s->ti -= s->current_tm.tm_sec;
3465 s->ti += from_bcd(value);
3468 case 0x04: /* MINUTES_REG */
3470 printf("RTC MIN_REG <-- %02x\n", value);
3472 s->ti -= s->current_tm.tm_min * 60;
3473 s->ti += from_bcd(value) * 60;
3476 case 0x08: /* HOURS_REG */
3478 printf("RTC HRS_REG <-- %02x\n", value);
3480 s->ti -= s->current_tm.tm_hour * 3600;
3482 s->ti += (from_bcd(value & 0x3f) & 12) * 3600;
3483 s->ti += ((value >> 7) & 1) * 43200;
3485 s->ti += from_bcd(value & 0x3f) * 3600;
3488 case 0x0c: /* DAYS_REG */
3490 printf("RTC DAY_REG <-- %02x\n", value);
3492 s->ti -= s->current_tm.tm_mday * 86400;
3493 s->ti += from_bcd(value) * 86400;
3496 case 0x10: /* MONTHS_REG */
3498 printf("RTC MTH_REG <-- %02x\n", value);
3500 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3501 new_tm.tm_mon = from_bcd(value);
3502 ti[0] = mktimegm(&s->current_tm);
3503 ti[1] = mktimegm(&new_tm);
3505 if (ti[0] != -1 && ti[1] != -1) {
3509 /* A less accurate version */
3510 s->ti -= s->current_tm.tm_mon * 2592000;
3511 s->ti += from_bcd(value) * 2592000;
3515 case 0x14: /* YEARS_REG */
3517 printf("RTC YRS_REG <-- %02x\n", value);
3519 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3520 new_tm.tm_year += from_bcd(value) - (new_tm.tm_year % 100);
3521 ti[0] = mktimegm(&s->current_tm);
3522 ti[1] = mktimegm(&new_tm);
3524 if (ti[0] != -1 && ti[1] != -1) {
3528 /* A less accurate version */
3529 s->ti -= (s->current_tm.tm_year % 100) * 31536000;
3530 s->ti += from_bcd(value) * 31536000;
3534 case 0x18: /* WEEK_REG */
3535 return; /* Ignored */
3537 case 0x20: /* ALARM_SECONDS_REG */
3539 printf("ALM SEC_REG <-- %02x\n", value);
3541 s->alarm_tm.tm_sec = from_bcd(value);
3542 omap_rtc_alarm_update(s);
3545 case 0x24: /* ALARM_MINUTES_REG */
3547 printf("ALM MIN_REG <-- %02x\n", value);
3549 s->alarm_tm.tm_min = from_bcd(value);
3550 omap_rtc_alarm_update(s);
3553 case 0x28: /* ALARM_HOURS_REG */
3555 printf("ALM HRS_REG <-- %02x\n", value);
3558 s->alarm_tm.tm_hour =
3559 ((from_bcd(value & 0x3f)) % 12) +
3560 ((value >> 7) & 1) * 12;
3562 s->alarm_tm.tm_hour = from_bcd(value);
3563 omap_rtc_alarm_update(s);
3566 case 0x2c: /* ALARM_DAYS_REG */
3568 printf("ALM DAY_REG <-- %02x\n", value);
3570 s->alarm_tm.tm_mday = from_bcd(value);
3571 omap_rtc_alarm_update(s);
3574 case 0x30: /* ALARM_MONTHS_REG */
3576 printf("ALM MON_REG <-- %02x\n", value);
3578 s->alarm_tm.tm_mon = from_bcd(value);
3579 omap_rtc_alarm_update(s);
3582 case 0x34: /* ALARM_YEARS_REG */
3584 printf("ALM YRS_REG <-- %02x\n", value);
3586 s->alarm_tm.tm_year = from_bcd(value);
3587 omap_rtc_alarm_update(s);
3590 case 0x40: /* RTC_CTRL_REG */
3592 printf("RTC CONTROL <-- %02x\n", value);
3594 s->pm_am = (value >> 3) & 1;
3595 s->auto_comp = (value >> 2) & 1;
3596 s->round = (value >> 1) & 1;
3597 s->running = value & 1;
3599 s->status |= s->running << 1;
3602 case 0x44: /* RTC_STATUS_REG */
3604 printf("RTC STATUSL <-- %02x\n", value);
3606 s->status &= ~((value & 0xc0) ^ 0x80);
3607 omap_rtc_interrupts_update(s);
3610 case 0x48: /* RTC_INTERRUPTS_REG */
3612 printf("RTC INTRS <-- %02x\n", value);
3614 s->interrupts = value;
3617 case 0x4c: /* RTC_COMP_LSB_REG */
3619 printf("RTC COMPLSB <-- %02x\n", value);
3621 s->comp_reg &= 0xff00;
3622 s->comp_reg |= 0x00ff & value;
3625 case 0x50: /* RTC_COMP_MSB_REG */
3627 printf("RTC COMPMSB <-- %02x\n", value);
3629 s->comp_reg &= 0x00ff;
3630 s->comp_reg |= 0xff00 & (value << 8);
3639 static CPUReadMemoryFunc * const omap_rtc_readfn[] = {
3641 omap_badwidth_read8,
3642 omap_badwidth_read8,
3645 static CPUWriteMemoryFunc * const omap_rtc_writefn[] = {
3647 omap_badwidth_write8,
3648 omap_badwidth_write8,
3651 static void omap_rtc_tick(void *opaque)
3653 struct omap_rtc_s *s = opaque;
3656 /* Round to nearest full minute. */
3657 if (s->current_tm.tm_sec < 30)
3658 s->ti -= s->current_tm.tm_sec;
3660 s->ti += 60 - s->current_tm.tm_sec;
3665 memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm));
3667 if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) {
3669 omap_rtc_interrupts_update(s);
3672 if (s->interrupts & 0x04)
3673 switch (s->interrupts & 3) {
3676 qemu_irq_pulse(s->irq);
3679 if (s->current_tm.tm_sec)
3682 qemu_irq_pulse(s->irq);
3685 if (s->current_tm.tm_sec || s->current_tm.tm_min)
3688 qemu_irq_pulse(s->irq);
3691 if (s->current_tm.tm_sec ||
3692 s->current_tm.tm_min || s->current_tm.tm_hour)
3695 qemu_irq_pulse(s->irq);
3705 * Every full hour add a rough approximation of the compensation
3706 * register to the 32kHz Timer (which drives the RTC) value.
3708 if (s->auto_comp && !s->current_tm.tm_sec && !s->current_tm.tm_min)
3709 s->tick += s->comp_reg * 1000 / 32768;
3711 qemu_mod_timer(s->clk, s->tick);
3714 static void omap_rtc_reset(struct omap_rtc_s *s)
3724 s->tick = qemu_get_clock(rt_clock);
3725 memset(&s->alarm_tm, 0, sizeof(s->alarm_tm));
3726 s->alarm_tm.tm_mday = 0x01;
3728 qemu_get_timedate(&tm, 0);
3729 s->ti = mktimegm(&tm);
3731 omap_rtc_alarm_update(s);
3735 struct omap_rtc_s *omap_rtc_init(target_phys_addr_t base,
3736 qemu_irq *irq, omap_clk clk)
3739 struct omap_rtc_s *s = (struct omap_rtc_s *)
3740 qemu_mallocz(sizeof(struct omap_rtc_s));
3744 s->clk = qemu_new_timer(rt_clock, omap_rtc_tick, s);
3748 iomemtype = cpu_register_io_memory(omap_rtc_readfn,
3749 omap_rtc_writefn, s);
3750 cpu_register_physical_memory(base, 0x800, iomemtype);
3755 /* Multi-channel Buffered Serial Port interfaces */
3756 struct omap_mcbsp_s {
3776 QEMUTimer *source_timer;
3777 QEMUTimer *sink_timer;
3780 static void omap_mcbsp_intr_update(struct omap_mcbsp_s *s)
3784 switch ((s->spcr[0] >> 4) & 3) { /* RINTM */
3786 irq = (s->spcr[0] >> 1) & 1; /* RRDY */
3789 irq = (s->spcr[0] >> 3) & 1; /* RSYNCERR */
3797 qemu_irq_pulse(s->rxirq);
3799 switch ((s->spcr[1] >> 4) & 3) { /* XINTM */
3801 irq = (s->spcr[1] >> 1) & 1; /* XRDY */
3804 irq = (s->spcr[1] >> 3) & 1; /* XSYNCERR */
3812 qemu_irq_pulse(s->txirq);
3815 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s *s)
3817 if ((s->spcr[0] >> 1) & 1) /* RRDY */
3818 s->spcr[0] |= 1 << 2; /* RFULL */
3819 s->spcr[0] |= 1 << 1; /* RRDY */
3820 qemu_irq_raise(s->rxdrq);
3821 omap_mcbsp_intr_update(s);
3824 static void omap_mcbsp_source_tick(void *opaque)
3826 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3827 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3832 printf("%s: Rx FIFO overrun\n", __FUNCTION__);
3834 s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7];
3836 omap_mcbsp_rx_newdata(s);
3837 qemu_mod_timer(s->source_timer, qemu_get_clock(vm_clock) +
3838 get_ticks_per_sec());
3841 static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s)
3843 if (!s->codec || !s->codec->rts)
3844 omap_mcbsp_source_tick(s);
3845 else if (s->codec->in.len) {
3846 s->rx_req = s->codec->in.len;
3847 omap_mcbsp_rx_newdata(s);
3851 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s *s)
3853 qemu_del_timer(s->source_timer);
3856 static void omap_mcbsp_rx_done(struct omap_mcbsp_s *s)
3858 s->spcr[0] &= ~(1 << 1); /* RRDY */
3859 qemu_irq_lower(s->rxdrq);
3860 omap_mcbsp_intr_update(s);
3863 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s *s)
3865 s->spcr[1] |= 1 << 1; /* XRDY */
3866 qemu_irq_raise(s->txdrq);
3867 omap_mcbsp_intr_update(s);
3870 static void omap_mcbsp_sink_tick(void *opaque)
3872 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3873 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3878 printf("%s: Tx FIFO underrun\n", __FUNCTION__);
3880 s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7];
3882 omap_mcbsp_tx_newdata(s);
3883 qemu_mod_timer(s->sink_timer, qemu_get_clock(vm_clock) +
3884 get_ticks_per_sec());
3887 static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s)
3889 if (!s->codec || !s->codec->cts)
3890 omap_mcbsp_sink_tick(s);
3891 else if (s->codec->out.size) {
3892 s->tx_req = s->codec->out.size;
3893 omap_mcbsp_tx_newdata(s);
3897 static void omap_mcbsp_tx_done(struct omap_mcbsp_s *s)
3899 s->spcr[1] &= ~(1 << 1); /* XRDY */
3900 qemu_irq_lower(s->txdrq);
3901 omap_mcbsp_intr_update(s);
3902 if (s->codec && s->codec->cts)
3903 s->codec->tx_swallow(s->codec->opaque);
3906 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s *s)
3909 omap_mcbsp_tx_done(s);
3910 qemu_del_timer(s->sink_timer);
3913 static void omap_mcbsp_req_update(struct omap_mcbsp_s *s)
3915 int prev_rx_rate, prev_tx_rate;
3916 int rx_rate = 0, tx_rate = 0;
3917 int cpu_rate = 1500000; /* XXX */
3919 /* TODO: check CLKSTP bit */
3920 if (s->spcr[1] & (1 << 6)) { /* GRST */
3921 if (s->spcr[0] & (1 << 0)) { /* RRST */
3922 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3923 (s->pcr & (1 << 8))) { /* CLKRM */
3924 if (~s->pcr & (1 << 7)) /* SCLKME */
3925 rx_rate = cpu_rate /
3926 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3929 rx_rate = s->codec->rx_rate;
3932 if (s->spcr[1] & (1 << 0)) { /* XRST */
3933 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3934 (s->pcr & (1 << 9))) { /* CLKXM */
3935 if (~s->pcr & (1 << 7)) /* SCLKME */
3936 tx_rate = cpu_rate /
3937 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3940 tx_rate = s->codec->tx_rate;
3943 prev_tx_rate = s->tx_rate;
3944 prev_rx_rate = s->rx_rate;
3945 s->tx_rate = tx_rate;
3946 s->rx_rate = rx_rate;
3949 s->codec->set_rate(s->codec->opaque, rx_rate, tx_rate);
3951 if (!prev_tx_rate && tx_rate)
3952 omap_mcbsp_tx_start(s);
3953 else if (s->tx_rate && !tx_rate)
3954 omap_mcbsp_tx_stop(s);
3956 if (!prev_rx_rate && rx_rate)
3957 omap_mcbsp_rx_start(s);
3958 else if (prev_tx_rate && !tx_rate)
3959 omap_mcbsp_rx_stop(s);
3962 static uint32_t omap_mcbsp_read(void *opaque, target_phys_addr_t addr)
3964 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3965 int offset = addr & OMAP_MPUI_REG_MASK;
3969 case 0x00: /* DRR2 */
3970 if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */
3973 case 0x02: /* DRR1 */
3974 if (s->rx_req < 2) {
3975 printf("%s: Rx FIFO underrun\n", __FUNCTION__);
3976 omap_mcbsp_rx_done(s);
3979 if (s->codec && s->codec->in.len >= 2) {
3980 ret = s->codec->in.fifo[s->codec->in.start ++] << 8;
3981 ret |= s->codec->in.fifo[s->codec->in.start ++];
3982 s->codec->in.len -= 2;
3986 omap_mcbsp_rx_done(s);
3991 case 0x04: /* DXR2 */
3992 case 0x06: /* DXR1 */
3995 case 0x08: /* SPCR2 */
3997 case 0x0a: /* SPCR1 */
3999 case 0x0c: /* RCR2 */
4001 case 0x0e: /* RCR1 */
4003 case 0x10: /* XCR2 */
4005 case 0x12: /* XCR1 */
4007 case 0x14: /* SRGR2 */
4009 case 0x16: /* SRGR1 */
4011 case 0x18: /* MCR2 */
4013 case 0x1a: /* MCR1 */
4015 case 0x1c: /* RCERA */
4017 case 0x1e: /* RCERB */
4019 case 0x20: /* XCERA */
4021 case 0x22: /* XCERB */
4023 case 0x24: /* PCR0 */
4025 case 0x26: /* RCERC */
4027 case 0x28: /* RCERD */
4029 case 0x2a: /* XCERC */
4031 case 0x2c: /* XCERD */
4033 case 0x2e: /* RCERE */
4035 case 0x30: /* RCERF */
4037 case 0x32: /* XCERE */
4039 case 0x34: /* XCERF */
4041 case 0x36: /* RCERG */
4043 case 0x38: /* RCERH */
4045 case 0x3a: /* XCERG */
4047 case 0x3c: /* XCERH */
4055 static void omap_mcbsp_writeh(void *opaque, target_phys_addr_t addr,
4058 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4059 int offset = addr & OMAP_MPUI_REG_MASK;
4062 case 0x00: /* DRR2 */
4063 case 0x02: /* DRR1 */
4067 case 0x04: /* DXR2 */
4068 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
4071 case 0x06: /* DXR1 */
4072 if (s->tx_req > 1) {
4074 if (s->codec && s->codec->cts) {
4075 s->codec->out.fifo[s->codec->out.len ++] = (value >> 8) & 0xff;
4076 s->codec->out.fifo[s->codec->out.len ++] = (value >> 0) & 0xff;
4079 omap_mcbsp_tx_done(s);
4081 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
4084 case 0x08: /* SPCR2 */
4085 s->spcr[1] &= 0x0002;
4086 s->spcr[1] |= 0x03f9 & value;
4087 s->spcr[1] |= 0x0004 & (value << 2); /* XEMPTY := XRST */
4088 if (~value & 1) /* XRST */
4090 omap_mcbsp_req_update(s);
4092 case 0x0a: /* SPCR1 */
4093 s->spcr[0] &= 0x0006;
4094 s->spcr[0] |= 0xf8f9 & value;
4095 if (value & (1 << 15)) /* DLB */
4096 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__);
4097 if (~value & 1) { /* RRST */
4100 omap_mcbsp_rx_done(s);
4102 omap_mcbsp_req_update(s);
4105 case 0x0c: /* RCR2 */
4106 s->rcr[1] = value & 0xffff;
4108 case 0x0e: /* RCR1 */
4109 s->rcr[0] = value & 0x7fe0;
4111 case 0x10: /* XCR2 */
4112 s->xcr[1] = value & 0xffff;
4114 case 0x12: /* XCR1 */
4115 s->xcr[0] = value & 0x7fe0;
4117 case 0x14: /* SRGR2 */
4118 s->srgr[1] = value & 0xffff;
4119 omap_mcbsp_req_update(s);
4121 case 0x16: /* SRGR1 */
4122 s->srgr[0] = value & 0xffff;
4123 omap_mcbsp_req_update(s);
4125 case 0x18: /* MCR2 */
4126 s->mcr[1] = value & 0x03e3;
4127 if (value & 3) /* XMCM */
4128 printf("%s: Tx channel selection mode enable attempt\n",
4131 case 0x1a: /* MCR1 */
4132 s->mcr[0] = value & 0x03e1;
4133 if (value & 1) /* RMCM */
4134 printf("%s: Rx channel selection mode enable attempt\n",
4137 case 0x1c: /* RCERA */
4138 s->rcer[0] = value & 0xffff;
4140 case 0x1e: /* RCERB */
4141 s->rcer[1] = value & 0xffff;
4143 case 0x20: /* XCERA */
4144 s->xcer[0] = value & 0xffff;
4146 case 0x22: /* XCERB */
4147 s->xcer[1] = value & 0xffff;
4149 case 0x24: /* PCR0 */
4150 s->pcr = value & 0x7faf;
4152 case 0x26: /* RCERC */
4153 s->rcer[2] = value & 0xffff;
4155 case 0x28: /* RCERD */
4156 s->rcer[3] = value & 0xffff;
4158 case 0x2a: /* XCERC */
4159 s->xcer[2] = value & 0xffff;
4161 case 0x2c: /* XCERD */
4162 s->xcer[3] = value & 0xffff;
4164 case 0x2e: /* RCERE */
4165 s->rcer[4] = value & 0xffff;
4167 case 0x30: /* RCERF */
4168 s->rcer[5] = value & 0xffff;
4170 case 0x32: /* XCERE */
4171 s->xcer[4] = value & 0xffff;
4173 case 0x34: /* XCERF */
4174 s->xcer[5] = value & 0xffff;
4176 case 0x36: /* RCERG */
4177 s->rcer[6] = value & 0xffff;
4179 case 0x38: /* RCERH */
4180 s->rcer[7] = value & 0xffff;
4182 case 0x3a: /* XCERG */
4183 s->xcer[6] = value & 0xffff;
4185 case 0x3c: /* XCERH */
4186 s->xcer[7] = value & 0xffff;
4193 static void omap_mcbsp_writew(void *opaque, target_phys_addr_t addr,
4196 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4197 int offset = addr & OMAP_MPUI_REG_MASK;
4199 if (offset == 0x04) { /* DXR */
4200 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
4202 if (s->tx_req > 3) {
4204 if (s->codec && s->codec->cts) {
4205 s->codec->out.fifo[s->codec->out.len ++] =
4206 (value >> 24) & 0xff;
4207 s->codec->out.fifo[s->codec->out.len ++] =
4208 (value >> 16) & 0xff;
4209 s->codec->out.fifo[s->codec->out.len ++] =
4210 (value >> 8) & 0xff;
4211 s->codec->out.fifo[s->codec->out.len ++] =
4212 (value >> 0) & 0xff;
4215 omap_mcbsp_tx_done(s);
4217 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
4221 omap_badwidth_write16(opaque, addr, value);
4224 static CPUReadMemoryFunc * const omap_mcbsp_readfn[] = {
4225 omap_badwidth_read16,
4227 omap_badwidth_read16,
4230 static CPUWriteMemoryFunc * const omap_mcbsp_writefn[] = {
4231 omap_badwidth_write16,
4236 static void omap_mcbsp_reset(struct omap_mcbsp_s *s)
4238 memset(&s->spcr, 0, sizeof(s->spcr));
4239 memset(&s->rcr, 0, sizeof(s->rcr));
4240 memset(&s->xcr, 0, sizeof(s->xcr));
4241 s->srgr[0] = 0x0001;
4242 s->srgr[1] = 0x2000;
4243 memset(&s->mcr, 0, sizeof(s->mcr));
4244 memset(&s->pcr, 0, sizeof(s->pcr));
4245 memset(&s->rcer, 0, sizeof(s->rcer));
4246 memset(&s->xcer, 0, sizeof(s->xcer));
4251 qemu_del_timer(s->source_timer);
4252 qemu_del_timer(s->sink_timer);
4255 struct omap_mcbsp_s *omap_mcbsp_init(target_phys_addr_t base,
4256 qemu_irq *irq, qemu_irq *dma, omap_clk clk)
4259 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *)
4260 qemu_mallocz(sizeof(struct omap_mcbsp_s));
4266 s->sink_timer = qemu_new_timer(vm_clock, omap_mcbsp_sink_tick, s);
4267 s->source_timer = qemu_new_timer(vm_clock, omap_mcbsp_source_tick, s);
4268 omap_mcbsp_reset(s);
4270 iomemtype = cpu_register_io_memory(omap_mcbsp_readfn,
4271 omap_mcbsp_writefn, s);
4272 cpu_register_physical_memory(base, 0x800, iomemtype);
4277 static void omap_mcbsp_i2s_swallow(void *opaque, int line, int level)
4279 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4282 s->rx_req = s->codec->in.len;
4283 omap_mcbsp_rx_newdata(s);
4287 static void omap_mcbsp_i2s_start(void *opaque, int line, int level)
4289 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4292 s->tx_req = s->codec->out.size;
4293 omap_mcbsp_tx_newdata(s);
4297 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, I2SCodec *slave)
4300 slave->rx_swallow = qemu_allocate_irqs(omap_mcbsp_i2s_swallow, s, 1)[0];
4301 slave->tx_start = qemu_allocate_irqs(omap_mcbsp_i2s_start, s, 1)[0];
4304 /* LED Pulse Generators */
4316 static void omap_lpg_tick(void *opaque)
4318 struct omap_lpg_s *s = opaque;
4321 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->period - s->on);
4323 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->on);
4325 s->cycle = !s->cycle;
4326 printf("%s: LED is %s\n", __FUNCTION__, s->cycle ? "on" : "off");
4329 static void omap_lpg_update(struct omap_lpg_s *s)
4331 int64_t on, period = 1, ticks = 1000;
4332 static const int per[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
4334 if (~s->control & (1 << 6)) /* LPGRES */
4336 else if (s->control & (1 << 7)) /* PERM_ON */
4339 period = muldiv64(ticks, per[s->control & 7], /* PERCTRL */
4341 on = (s->clk && s->power) ? muldiv64(ticks,
4342 per[(s->control >> 3) & 7], 256) : 0; /* ONCTRL */
4345 qemu_del_timer(s->tm);
4346 if (on == period && s->on < s->period)
4347 printf("%s: LED is on\n", __FUNCTION__);
4348 else if (on == 0 && s->on)
4349 printf("%s: LED is off\n", __FUNCTION__);
4350 else if (on && (on != s->on || period != s->period)) {
4362 static void omap_lpg_reset(struct omap_lpg_s *s)
4370 static uint32_t omap_lpg_read(void *opaque, target_phys_addr_t addr)
4372 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4373 int offset = addr & OMAP_MPUI_REG_MASK;
4376 case 0x00: /* LCR */
4379 case 0x04: /* PMR */
4387 static void omap_lpg_write(void *opaque, target_phys_addr_t addr,
4390 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4391 int offset = addr & OMAP_MPUI_REG_MASK;
4394 case 0x00: /* LCR */
4395 if (~value & (1 << 6)) /* LPGRES */
4397 s->control = value & 0xff;
4401 case 0x04: /* PMR */
4402 s->power = value & 0x01;
4412 static CPUReadMemoryFunc * const omap_lpg_readfn[] = {
4414 omap_badwidth_read8,
4415 omap_badwidth_read8,
4418 static CPUWriteMemoryFunc * const omap_lpg_writefn[] = {
4420 omap_badwidth_write8,
4421 omap_badwidth_write8,
4424 static void omap_lpg_clk_update(void *opaque, int line, int on)
4426 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4432 struct omap_lpg_s *omap_lpg_init(target_phys_addr_t base, omap_clk clk)
4435 struct omap_lpg_s *s = (struct omap_lpg_s *)
4436 qemu_mallocz(sizeof(struct omap_lpg_s));
4438 s->tm = qemu_new_timer(rt_clock, omap_lpg_tick, s);
4442 iomemtype = cpu_register_io_memory(omap_lpg_readfn,
4443 omap_lpg_writefn, s);
4444 cpu_register_physical_memory(base, 0x800, iomemtype);
4446 omap_clk_adduser(clk, qemu_allocate_irqs(omap_lpg_clk_update, s, 1)[0]);
4451 /* MPUI Peripheral Bridge configuration */
4452 static uint32_t omap_mpui_io_read(void *opaque, target_phys_addr_t addr)
4454 if (addr == OMAP_MPUI_BASE) /* CMR */
4461 static CPUReadMemoryFunc * const omap_mpui_io_readfn[] = {
4462 omap_badwidth_read16,
4464 omap_badwidth_read16,
4467 static CPUWriteMemoryFunc * const omap_mpui_io_writefn[] = {
4468 omap_badwidth_write16,
4469 omap_badwidth_write16,
4470 omap_badwidth_write16,
4473 static void omap_setup_mpui_io(struct omap_mpu_state_s *mpu)
4475 int iomemtype = cpu_register_io_memory(omap_mpui_io_readfn,
4476 omap_mpui_io_writefn, mpu);
4477 cpu_register_physical_memory(OMAP_MPUI_BASE, 0x7fff, iomemtype);
4480 /* General chip reset */
4481 static void omap1_mpu_reset(void *opaque)
4483 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4485 omap_inth_reset(mpu->ih[0]);
4486 omap_inth_reset(mpu->ih[1]);
4487 omap_dma_reset(mpu->dma);
4488 omap_mpu_timer_reset(mpu->timer[0]);
4489 omap_mpu_timer_reset(mpu->timer[1]);
4490 omap_mpu_timer_reset(mpu->timer[2]);
4491 omap_wd_timer_reset(mpu->wdt);
4492 omap_os_timer_reset(mpu->os_timer);
4493 omap_lcdc_reset(mpu->lcd);
4494 omap_ulpd_pm_reset(mpu);
4495 omap_pin_cfg_reset(mpu);
4496 omap_mpui_reset(mpu);
4497 omap_tipb_bridge_reset(mpu->private_tipb);
4498 omap_tipb_bridge_reset(mpu->public_tipb);
4499 omap_dpll_reset(&mpu->dpll[0]);
4500 omap_dpll_reset(&mpu->dpll[1]);
4501 omap_dpll_reset(&mpu->dpll[2]);
4502 omap_uart_reset(mpu->uart[0]);
4503 omap_uart_reset(mpu->uart[1]);
4504 omap_uart_reset(mpu->uart[2]);
4505 omap_mmc_reset(mpu->mmc);
4506 omap_mpuio_reset(mpu->mpuio);
4507 omap_gpio_reset(mpu->gpio);
4508 omap_uwire_reset(mpu->microwire);
4509 omap_pwl_reset(mpu);
4510 omap_pwt_reset(mpu);
4511 omap_i2c_reset(mpu->i2c[0]);
4512 omap_rtc_reset(mpu->rtc);
4513 omap_mcbsp_reset(mpu->mcbsp1);
4514 omap_mcbsp_reset(mpu->mcbsp2);
4515 omap_mcbsp_reset(mpu->mcbsp3);
4516 omap_lpg_reset(mpu->led[0]);
4517 omap_lpg_reset(mpu->led[1]);
4518 omap_clkm_reset(mpu);
4519 cpu_reset(mpu->env);
4522 static const struct omap_map_s {
4523 target_phys_addr_t phys_dsp;
4524 target_phys_addr_t phys_mpu;
4527 } omap15xx_dsp_mm[] = {
4529 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
4530 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
4531 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
4532 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
4533 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
4534 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
4535 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
4536 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
4537 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
4538 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
4539 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
4540 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
4541 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
4542 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
4543 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
4544 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
4545 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
4547 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
4552 static void omap_setup_dsp_mapping(const struct omap_map_s *map)
4556 for (; map->phys_dsp; map ++) {
4557 io = cpu_get_physical_page_desc(map->phys_mpu);
4559 cpu_register_physical_memory(map->phys_dsp, map->size, io);
4563 void omap_mpu_wakeup(void *opaque, int irq, int req)
4565 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4567 if (mpu->env->halted)
4568 cpu_interrupt(mpu->env, CPU_INTERRUPT_EXITTB);
4571 static const struct dma_irq_map omap1_dma_irq_map[] = {
4572 { 0, OMAP_INT_DMA_CH0_6 },
4573 { 0, OMAP_INT_DMA_CH1_7 },
4574 { 0, OMAP_INT_DMA_CH2_8 },
4575 { 0, OMAP_INT_DMA_CH3 },
4576 { 0, OMAP_INT_DMA_CH4 },
4577 { 0, OMAP_INT_DMA_CH5 },
4578 { 1, OMAP_INT_1610_DMA_CH6 },
4579 { 1, OMAP_INT_1610_DMA_CH7 },
4580 { 1, OMAP_INT_1610_DMA_CH8 },
4581 { 1, OMAP_INT_1610_DMA_CH9 },
4582 { 1, OMAP_INT_1610_DMA_CH10 },
4583 { 1, OMAP_INT_1610_DMA_CH11 },
4584 { 1, OMAP_INT_1610_DMA_CH12 },
4585 { 1, OMAP_INT_1610_DMA_CH13 },
4586 { 1, OMAP_INT_1610_DMA_CH14 },
4587 { 1, OMAP_INT_1610_DMA_CH15 }
4590 /* DMA ports for OMAP1 */
4591 static int omap_validate_emiff_addr(struct omap_mpu_state_s *s,
4592 target_phys_addr_t addr)
4594 return addr >= OMAP_EMIFF_BASE && addr < OMAP_EMIFF_BASE + s->sdram_size;
4597 static int omap_validate_emifs_addr(struct omap_mpu_state_s *s,
4598 target_phys_addr_t addr)
4600 return addr >= OMAP_EMIFS_BASE && addr < OMAP_EMIFF_BASE;
4603 static int omap_validate_imif_addr(struct omap_mpu_state_s *s,
4604 target_phys_addr_t addr)
4606 return addr >= OMAP_IMIF_BASE && addr < OMAP_IMIF_BASE + s->sram_size;
4609 static int omap_validate_tipb_addr(struct omap_mpu_state_s *s,
4610 target_phys_addr_t addr)
4612 return addr >= 0xfffb0000 && addr < 0xffff0000;
4615 static int omap_validate_local_addr(struct omap_mpu_state_s *s,
4616 target_phys_addr_t addr)
4618 return addr >= OMAP_LOCALBUS_BASE && addr < OMAP_LOCALBUS_BASE + 0x1000000;
4621 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s *s,
4622 target_phys_addr_t addr)
4624 return addr >= 0xe1010000 && addr < 0xe1020004;
4627 struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,
4631 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
4632 qemu_mallocz(sizeof(struct omap_mpu_state_s));
4633 ram_addr_t imif_base, emiff_base;
4635 qemu_irq dma_irqs[6];
4642 s->mpu_model = omap310;
4643 s->env = cpu_init(core);
4645 fprintf(stderr, "Unable to find CPU definition\n");
4648 s->sdram_size = sdram_size;
4649 s->sram_size = OMAP15XX_SRAM_SIZE;
4651 s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0];
4656 /* Memory-mapped stuff */
4657 cpu_register_physical_memory(OMAP_EMIFF_BASE, s->sdram_size,
4658 (emiff_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
4659 cpu_register_physical_memory(OMAP_IMIF_BASE, s->sram_size,
4660 (imif_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
4662 omap_clkm_init(0xfffece00, 0xe1008000, s);
4664 cpu_irq = arm_pic_init_cpu(s->env);
4665 s->ih[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s->irq[0],
4666 cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ],
4667 omap_findclk(s, "arminth_ck"));
4668 s->ih[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s->irq[1],
4669 s->ih[0]->pins[OMAP_INT_15XX_IH2_IRQ], NULL,
4670 omap_findclk(s, "arminth_ck"));
4672 for (i = 0; i < 6; i ++)
4674 s->irq[omap1_dma_irq_map[i].ih][omap1_dma_irq_map[i].intr];
4675 s->dma = omap_dma_init(0xfffed800, dma_irqs, s->irq[0][OMAP_INT_DMA_LCD],
4676 s, omap_findclk(s, "dma_ck"), omap_dma_3_1);
4678 s->port[emiff ].addr_valid = omap_validate_emiff_addr;
4679 s->port[emifs ].addr_valid = omap_validate_emifs_addr;
4680 s->port[imif ].addr_valid = omap_validate_imif_addr;
4681 s->port[tipb ].addr_valid = omap_validate_tipb_addr;
4682 s->port[local ].addr_valid = omap_validate_local_addr;
4683 s->port[tipb_mpui].addr_valid = omap_validate_tipb_mpui_addr;
4685 /* Register SDRAM and SRAM DMA ports for fast transfers. */
4686 soc_dma_port_add_mem_ram(s->dma,
4687 emiff_base, OMAP_EMIFF_BASE, s->sdram_size);
4688 soc_dma_port_add_mem_ram(s->dma,
4689 imif_base, OMAP_IMIF_BASE, s->sram_size);
4691 s->timer[0] = omap_mpu_timer_init(0xfffec500,
4692 s->irq[0][OMAP_INT_TIMER1],
4693 omap_findclk(s, "mputim_ck"));
4694 s->timer[1] = omap_mpu_timer_init(0xfffec600,
4695 s->irq[0][OMAP_INT_TIMER2],
4696 omap_findclk(s, "mputim_ck"));
4697 s->timer[2] = omap_mpu_timer_init(0xfffec700,
4698 s->irq[0][OMAP_INT_TIMER3],
4699 omap_findclk(s, "mputim_ck"));
4701 s->wdt = omap_wd_timer_init(0xfffec800,
4702 s->irq[0][OMAP_INT_WD_TIMER],
4703 omap_findclk(s, "armwdt_ck"));
4705 s->os_timer = omap_os_timer_init(0xfffb9000,
4706 s->irq[1][OMAP_INT_OS_TIMER],
4707 omap_findclk(s, "clk32-kHz"));
4709 s->lcd = omap_lcdc_init(0xfffec000, s->irq[0][OMAP_INT_LCD_CTRL],
4710 omap_dma_get_lcdch(s->dma), imif_base, emiff_base,
4711 omap_findclk(s, "lcd_ck"));
4713 omap_ulpd_pm_init(0xfffe0800, s);
4714 omap_pin_cfg_init(0xfffe1000, s);
4717 omap_mpui_init(0xfffec900, s);
4719 s->private_tipb = omap_tipb_bridge_init(0xfffeca00,
4720 s->irq[0][OMAP_INT_BRIDGE_PRIV],
4721 omap_findclk(s, "tipb_ck"));
4722 s->public_tipb = omap_tipb_bridge_init(0xfffed300,
4723 s->irq[0][OMAP_INT_BRIDGE_PUB],
4724 omap_findclk(s, "tipb_ck"));
4726 omap_tcmi_init(0xfffecc00, s);
4728 s->uart[0] = omap_uart_init(0xfffb0000, s->irq[1][OMAP_INT_UART1],
4729 omap_findclk(s, "uart1_ck"),
4730 omap_findclk(s, "uart1_ck"),
4731 s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
4733 s->uart[1] = omap_uart_init(0xfffb0800, s->irq[1][OMAP_INT_UART2],
4734 omap_findclk(s, "uart2_ck"),
4735 omap_findclk(s, "uart2_ck"),
4736 s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
4737 serial_hds[0] ? serial_hds[1] : NULL);
4738 s->uart[2] = omap_uart_init(0xfffb9800, s->irq[0][OMAP_INT_UART3],
4739 omap_findclk(s, "uart3_ck"),
4740 omap_findclk(s, "uart3_ck"),
4741 s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX],
4742 serial_hds[0] && serial_hds[1] ? serial_hds[2] : NULL);
4744 omap_dpll_init(&s->dpll[0], 0xfffecf00, omap_findclk(s, "dpll1"));
4745 omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2"));
4746 omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3"));
4748 dinfo = drive_get(IF_SD, 0, 0);
4750 fprintf(stderr, "qemu: missing SecureDigital device\n");
4753 s->mmc = omap_mmc_init(0xfffb7800, dinfo->bdrv,
4754 s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX],
4755 omap_findclk(s, "mmc_ck"));
4757 s->mpuio = omap_mpuio_init(0xfffb5000,
4758 s->irq[1][OMAP_INT_KEYBOARD], s->irq[1][OMAP_INT_MPUIO],
4759 s->wakeup, omap_findclk(s, "clk32-kHz"));
4761 s->gpio = omap_gpio_init(0xfffce000, s->irq[0][OMAP_INT_GPIO_BANK1],
4762 omap_findclk(s, "arm_gpio_ck"));
4764 s->microwire = omap_uwire_init(0xfffb3000, &s->irq[1][OMAP_INT_uWireTX],
4765 s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
4767 omap_pwl_init(0xfffb5800, s, omap_findclk(s, "armxor_ck"));
4768 omap_pwt_init(0xfffb6000, s, omap_findclk(s, "armxor_ck"));
4770 s->i2c[0] = omap_i2c_init(0xfffb3800, s->irq[1][OMAP_INT_I2C],
4771 &s->drq[OMAP_DMA_I2C_RX], omap_findclk(s, "mpuper_ck"));
4773 s->rtc = omap_rtc_init(0xfffb4800, &s->irq[1][OMAP_INT_RTC_TIMER],
4774 omap_findclk(s, "clk32-kHz"));
4776 s->mcbsp1 = omap_mcbsp_init(0xfffb1800, &s->irq[1][OMAP_INT_McBSP1TX],
4777 &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
4778 s->mcbsp2 = omap_mcbsp_init(0xfffb1000, &s->irq[0][OMAP_INT_310_McBSP2_TX],
4779 &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
4780 s->mcbsp3 = omap_mcbsp_init(0xfffb7000, &s->irq[1][OMAP_INT_McBSP3TX],
4781 &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
4783 s->led[0] = omap_lpg_init(0xfffbd000, omap_findclk(s, "clk32-kHz"));
4784 s->led[1] = omap_lpg_init(0xfffbd800, omap_findclk(s, "clk32-kHz"));
4786 /* Register mappings not currenlty implemented:
4787 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4788 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4789 * USB W2FC fffb4000 - fffb47ff
4790 * Camera Interface fffb6800 - fffb6fff
4791 * USB Host fffba000 - fffba7ff
4792 * FAC fffba800 - fffbafff
4793 * HDQ/1-Wire fffbc000 - fffbc7ff
4794 * TIPB switches fffbc800 - fffbcfff
4795 * Mailbox fffcf000 - fffcf7ff
4796 * Local bus IF fffec100 - fffec1ff
4797 * Local bus MMU fffec200 - fffec2ff
4798 * DSP MMU fffed200 - fffed2ff
4801 omap_setup_dsp_mapping(omap15xx_dsp_mm);
4802 omap_setup_mpui_io(s);
4804 qemu_register_reset(omap1_mpu_reset, s);