2 * TI OMAP processors emulation.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "qemu-timer.h"
25 #include "qemu-char.h"
27 /* We use pc-style serial ports. */
30 /* Should signal the TCMI/GPMC */
31 uint32_t omap_badwidth_read8(void *opaque, target_phys_addr_t addr)
36 cpu_physical_memory_read(addr, (void *) &ret, 1);
40 void omap_badwidth_write8(void *opaque, target_phys_addr_t addr,
46 cpu_physical_memory_write(addr, (void *) &val8, 1);
49 uint32_t omap_badwidth_read16(void *opaque, target_phys_addr_t addr)
54 cpu_physical_memory_read(addr, (void *) &ret, 2);
58 void omap_badwidth_write16(void *opaque, target_phys_addr_t addr,
61 uint16_t val16 = value;
64 cpu_physical_memory_write(addr, (void *) &val16, 2);
67 uint32_t omap_badwidth_read32(void *opaque, target_phys_addr_t addr)
72 cpu_physical_memory_read(addr, (void *) &ret, 4);
76 void omap_badwidth_write32(void *opaque, target_phys_addr_t addr,
80 cpu_physical_memory_write(addr, (void *) &value, 4);
83 /* Interrupt Handlers */
84 struct omap_intr_handler_bank_s {
91 unsigned char priority[32];
94 struct omap_intr_handler_s {
96 qemu_irq parent_intr[2];
106 struct omap_intr_handler_bank_s bank[];
109 static void omap_inth_sir_update(struct omap_intr_handler_s *s, int is_fiq)
111 int i, j, sir_intr, p_intr, p, f;
116 /* Find the interrupt line with the highest dynamic priority.
117 * Note: 0 denotes the hightest priority.
118 * If all interrupts have the same priority, the default order is IRQ_N,
119 * IRQ_N-1,...,IRQ_0. */
120 for (j = 0; j < s->nbanks; ++j) {
121 level = s->bank[j].irqs & ~s->bank[j].mask &
122 (is_fiq ? s->bank[j].fiq : ~s->bank[j].fiq);
123 for (f = ffs(level), i = f - 1, level >>= f - 1; f; i += f,
125 p = s->bank[j].priority[i];
128 sir_intr = 32 * j + i;
133 s->sir_intr[is_fiq] = sir_intr;
136 static inline void omap_inth_update(struct omap_intr_handler_s *s, int is_fiq)
139 uint32_t has_intr = 0;
141 for (i = 0; i < s->nbanks; ++i)
142 has_intr |= s->bank[i].irqs & ~s->bank[i].mask &
143 (is_fiq ? s->bank[i].fiq : ~s->bank[i].fiq);
145 if (s->new_agr[is_fiq] & has_intr & s->mask) {
146 s->new_agr[is_fiq] = 0;
147 omap_inth_sir_update(s, is_fiq);
148 qemu_set_irq(s->parent_intr[is_fiq], 1);
152 #define INT_FALLING_EDGE 0
153 #define INT_LOW_LEVEL 1
155 static void omap_set_intr(void *opaque, int irq, int req)
157 struct omap_intr_handler_s *ih = (struct omap_intr_handler_s *) opaque;
160 struct omap_intr_handler_bank_s *bank = &ih->bank[irq >> 5];
164 rise = ~bank->irqs & (1 << n);
165 if (~bank->sens_edge & (1 << n))
166 rise &= ~bank->inputs;
168 bank->inputs |= (1 << n);
171 omap_inth_update(ih, 0);
172 omap_inth_update(ih, 1);
175 rise = bank->sens_edge & bank->irqs & (1 << n);
177 bank->inputs &= ~(1 << n);
181 /* Simplified version with no edge detection */
182 static void omap_set_intr_noedge(void *opaque, int irq, int req)
184 struct omap_intr_handler_s *ih = (struct omap_intr_handler_s *) opaque;
187 struct omap_intr_handler_bank_s *bank = &ih->bank[irq >> 5];
191 rise = ~bank->inputs & (1 << n);
193 bank->irqs |= bank->inputs |= rise;
194 omap_inth_update(ih, 0);
195 omap_inth_update(ih, 1);
198 bank->irqs = (bank->inputs &= ~(1 << n)) | bank->swi;
201 static uint32_t omap_inth_read(void *opaque, target_phys_addr_t addr)
203 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
204 int i, offset = addr;
205 int bank_no = offset >> 8;
207 struct omap_intr_handler_bank_s *bank = &s->bank[bank_no];
217 case 0x10: /* SIR_IRQ_CODE */
218 case 0x14: /* SIR_FIQ_CODE */
221 line_no = s->sir_intr[(offset - 0x10) >> 2];
222 bank = &s->bank[line_no >> 5];
224 if (((bank->sens_edge >> i) & 1) == INT_FALLING_EDGE)
225 bank->irqs &= ~(1 << i);
228 case 0x18: /* CONTROL_REG */
233 case 0x1c: /* ILR0 */
234 case 0x20: /* ILR1 */
235 case 0x24: /* ILR2 */
236 case 0x28: /* ILR3 */
237 case 0x2c: /* ILR4 */
238 case 0x30: /* ILR5 */
239 case 0x34: /* ILR6 */
240 case 0x38: /* ILR7 */
241 case 0x3c: /* ILR8 */
242 case 0x40: /* ILR9 */
243 case 0x44: /* ILR10 */
244 case 0x48: /* ILR11 */
245 case 0x4c: /* ILR12 */
246 case 0x50: /* ILR13 */
247 case 0x54: /* ILR14 */
248 case 0x58: /* ILR15 */
249 case 0x5c: /* ILR16 */
250 case 0x60: /* ILR17 */
251 case 0x64: /* ILR18 */
252 case 0x68: /* ILR19 */
253 case 0x6c: /* ILR20 */
254 case 0x70: /* ILR21 */
255 case 0x74: /* ILR22 */
256 case 0x78: /* ILR23 */
257 case 0x7c: /* ILR24 */
258 case 0x80: /* ILR25 */
259 case 0x84: /* ILR26 */
260 case 0x88: /* ILR27 */
261 case 0x8c: /* ILR28 */
262 case 0x90: /* ILR29 */
263 case 0x94: /* ILR30 */
264 case 0x98: /* ILR31 */
265 i = (offset - 0x1c) >> 2;
266 return (bank->priority[i] << 2) |
267 (((bank->sens_edge >> i) & 1) << 1) |
268 ((bank->fiq >> i) & 1);
278 static void omap_inth_write(void *opaque, target_phys_addr_t addr,
281 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
282 int i, offset = addr;
283 int bank_no = offset >> 8;
284 struct omap_intr_handler_bank_s *bank = &s->bank[bank_no];
289 /* Important: ignore the clearing if the IRQ is level-triggered and
290 the input bit is 1 */
291 bank->irqs &= value | (bank->inputs & bank->sens_edge);
296 omap_inth_update(s, 0);
297 omap_inth_update(s, 1);
300 case 0x10: /* SIR_IRQ_CODE */
301 case 0x14: /* SIR_FIQ_CODE */
305 case 0x18: /* CONTROL_REG */
309 qemu_set_irq(s->parent_intr[1], 0);
311 omap_inth_update(s, 1);
314 qemu_set_irq(s->parent_intr[0], 0);
316 omap_inth_update(s, 0);
320 case 0x1c: /* ILR0 */
321 case 0x20: /* ILR1 */
322 case 0x24: /* ILR2 */
323 case 0x28: /* ILR3 */
324 case 0x2c: /* ILR4 */
325 case 0x30: /* ILR5 */
326 case 0x34: /* ILR6 */
327 case 0x38: /* ILR7 */
328 case 0x3c: /* ILR8 */
329 case 0x40: /* ILR9 */
330 case 0x44: /* ILR10 */
331 case 0x48: /* ILR11 */
332 case 0x4c: /* ILR12 */
333 case 0x50: /* ILR13 */
334 case 0x54: /* ILR14 */
335 case 0x58: /* ILR15 */
336 case 0x5c: /* ILR16 */
337 case 0x60: /* ILR17 */
338 case 0x64: /* ILR18 */
339 case 0x68: /* ILR19 */
340 case 0x6c: /* ILR20 */
341 case 0x70: /* ILR21 */
342 case 0x74: /* ILR22 */
343 case 0x78: /* ILR23 */
344 case 0x7c: /* ILR24 */
345 case 0x80: /* ILR25 */
346 case 0x84: /* ILR26 */
347 case 0x88: /* ILR27 */
348 case 0x8c: /* ILR28 */
349 case 0x90: /* ILR29 */
350 case 0x94: /* ILR30 */
351 case 0x98: /* ILR31 */
352 i = (offset - 0x1c) >> 2;
353 bank->priority[i] = (value >> 2) & 0x1f;
354 bank->sens_edge &= ~(1 << i);
355 bank->sens_edge |= ((value >> 1) & 1) << i;
356 bank->fiq &= ~(1 << i);
357 bank->fiq |= (value & 1) << i;
361 for (i = 0; i < 32; i ++)
362 if (value & (1 << i)) {
363 omap_set_intr(s, 32 * bank_no + i, 1);
371 static CPUReadMemoryFunc *omap_inth_readfn[] = {
372 omap_badwidth_read32,
373 omap_badwidth_read32,
377 static CPUWriteMemoryFunc *omap_inth_writefn[] = {
383 void omap_inth_reset(struct omap_intr_handler_s *s)
387 for (i = 0; i < s->nbanks; ++i){
388 s->bank[i].irqs = 0x00000000;
389 s->bank[i].mask = 0xffffffff;
390 s->bank[i].sens_edge = 0x00000000;
391 s->bank[i].fiq = 0x00000000;
392 s->bank[i].inputs = 0x00000000;
393 s->bank[i].swi = 0x00000000;
394 memset(s->bank[i].priority, 0, sizeof(s->bank[i].priority));
397 s->bank[i].sens_edge = 0xffffffff;
407 qemu_set_irq(s->parent_intr[0], 0);
408 qemu_set_irq(s->parent_intr[1], 0);
411 struct omap_intr_handler_s *omap_inth_init(target_phys_addr_t base,
412 unsigned long size, unsigned char nbanks, qemu_irq **pins,
413 qemu_irq parent_irq, qemu_irq parent_fiq, omap_clk clk)
416 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)
417 qemu_mallocz(sizeof(struct omap_intr_handler_s) +
418 sizeof(struct omap_intr_handler_bank_s) * nbanks);
420 s->parent_intr[0] = parent_irq;
421 s->parent_intr[1] = parent_fiq;
423 s->pins = qemu_allocate_irqs(omap_set_intr, s, nbanks * 32);
429 iomemtype = cpu_register_io_memory(0, omap_inth_readfn,
430 omap_inth_writefn, s);
431 cpu_register_physical_memory(base, size, iomemtype);
436 static uint32_t omap2_inth_read(void *opaque, target_phys_addr_t addr)
438 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
440 int bank_no, line_no;
441 struct omap_intr_handler_bank_s *bank = 0;
443 if ((offset & 0xf80) == 0x80) {
444 bank_no = (offset & 0x60) >> 5;
445 if (bank_no < s->nbanks) {
447 bank = &s->bank[bank_no];
452 case 0x00: /* INTC_REVISION */
455 case 0x10: /* INTC_SYSCONFIG */
456 return (s->autoidle >> 2) & 1;
458 case 0x14: /* INTC_SYSSTATUS */
459 return 1; /* RESETDONE */
461 case 0x40: /* INTC_SIR_IRQ */
462 return s->sir_intr[0];
464 case 0x44: /* INTC_SIR_FIQ */
465 return s->sir_intr[1];
467 case 0x48: /* INTC_CONTROL */
468 return (!s->mask) << 2; /* GLOBALMASK */
470 case 0x4c: /* INTC_PROTECTION */
473 case 0x50: /* INTC_IDLE */
474 return s->autoidle & 3;
476 /* Per-bank registers */
477 case 0x80: /* INTC_ITR */
480 case 0x84: /* INTC_MIR */
483 case 0x88: /* INTC_MIR_CLEAR */
484 case 0x8c: /* INTC_MIR_SET */
487 case 0x90: /* INTC_ISR_SET */
490 case 0x94: /* INTC_ISR_CLEAR */
493 case 0x98: /* INTC_PENDING_IRQ */
494 return bank->irqs & ~bank->mask & ~bank->fiq;
496 case 0x9c: /* INTC_PENDING_FIQ */
497 return bank->irqs & ~bank->mask & bank->fiq;
499 /* Per-line registers */
500 case 0x100 ... 0x300: /* INTC_ILR */
501 bank_no = (offset - 0x100) >> 7;
502 if (bank_no > s->nbanks)
504 bank = &s->bank[bank_no];
505 line_no = (offset & 0x7f) >> 2;
506 return (bank->priority[line_no] << 2) |
507 ((bank->fiq >> line_no) & 1);
513 static void omap2_inth_write(void *opaque, target_phys_addr_t addr,
516 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
518 int bank_no, line_no;
519 struct omap_intr_handler_bank_s *bank = 0;
521 if ((offset & 0xf80) == 0x80) {
522 bank_no = (offset & 0x60) >> 5;
523 if (bank_no < s->nbanks) {
525 bank = &s->bank[bank_no];
530 case 0x10: /* INTC_SYSCONFIG */
532 s->autoidle |= (value & 1) << 2;
533 if (value & 2) /* SOFTRESET */
537 case 0x48: /* INTC_CONTROL */
538 s->mask = (value & 4) ? 0 : ~0; /* GLOBALMASK */
539 if (value & 2) { /* NEWFIQAGR */
540 qemu_set_irq(s->parent_intr[1], 0);
542 omap_inth_update(s, 1);
544 if (value & 1) { /* NEWIRQAGR */
545 qemu_set_irq(s->parent_intr[0], 0);
547 omap_inth_update(s, 0);
551 case 0x4c: /* INTC_PROTECTION */
552 /* TODO: Make a bitmap (or sizeof(char)map) of access privileges
553 * for every register, see Chapter 3 and 4 for privileged mode. */
555 fprintf(stderr, "%s: protection mode enable attempt\n",
559 case 0x50: /* INTC_IDLE */
561 s->autoidle |= value & 3;
564 /* Per-bank registers */
565 case 0x84: /* INTC_MIR */
567 omap_inth_update(s, 0);
568 omap_inth_update(s, 1);
571 case 0x88: /* INTC_MIR_CLEAR */
572 bank->mask &= ~value;
573 omap_inth_update(s, 0);
574 omap_inth_update(s, 1);
577 case 0x8c: /* INTC_MIR_SET */
581 case 0x90: /* INTC_ISR_SET */
582 bank->irqs |= bank->swi |= value;
583 omap_inth_update(s, 0);
584 omap_inth_update(s, 1);
587 case 0x94: /* INTC_ISR_CLEAR */
589 bank->irqs = bank->swi & bank->inputs;
592 /* Per-line registers */
593 case 0x100 ... 0x300: /* INTC_ILR */
594 bank_no = (offset - 0x100) >> 7;
595 if (bank_no > s->nbanks)
597 bank = &s->bank[bank_no];
598 line_no = (offset & 0x7f) >> 2;
599 bank->priority[line_no] = (value >> 2) & 0x3f;
600 bank->fiq &= ~(1 << line_no);
601 bank->fiq |= (value & 1) << line_no;
604 case 0x00: /* INTC_REVISION */
605 case 0x14: /* INTC_SYSSTATUS */
606 case 0x40: /* INTC_SIR_IRQ */
607 case 0x44: /* INTC_SIR_FIQ */
608 case 0x80: /* INTC_ITR */
609 case 0x98: /* INTC_PENDING_IRQ */
610 case 0x9c: /* INTC_PENDING_FIQ */
617 static CPUReadMemoryFunc *omap2_inth_readfn[] = {
618 omap_badwidth_read32,
619 omap_badwidth_read32,
623 static CPUWriteMemoryFunc *omap2_inth_writefn[] = {
629 struct omap_intr_handler_s *omap2_inth_init(
630 struct omap_mpu_state_s *mpu,
631 target_phys_addr_t base,
632 int size, int nbanks, qemu_irq **pins,
633 qemu_irq parent_irq, qemu_irq parent_fiq,
634 omap_clk fclk, omap_clk iclk)
637 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)
638 qemu_mallocz(sizeof(struct omap_intr_handler_s) +
639 sizeof(struct omap_intr_handler_bank_s) * nbanks);
641 s->revision = cpu_class_omap3(mpu) ? 0x40 : 0x21;
642 s->parent_intr[0] = parent_irq;
643 s->parent_intr[1] = parent_fiq;
646 s->pins = qemu_allocate_irqs(omap_set_intr_noedge, s, nbanks * 32);
652 iomemtype = cpu_register_io_memory(0, omap2_inth_readfn,
653 omap2_inth_writefn, s);
654 cpu_register_physical_memory(base, size, iomemtype);
660 struct omap_mpu_timer_s {
677 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer)
679 uint64_t distance = qemu_get_clock(vm_clock) - timer->time;
681 if (timer->st && timer->enable && timer->rate)
682 return timer->val - muldiv64(distance >> (timer->ptv + 1),
683 timer->rate, ticks_per_sec);
688 static inline void omap_timer_sync(struct omap_mpu_timer_s *timer)
690 timer->val = omap_timer_read(timer);
691 timer->time = qemu_get_clock(vm_clock);
694 static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
698 if (timer->enable && timer->st && timer->rate) {
699 timer->val = timer->reset_val; /* Should skip this on clk enable */
700 expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
701 ticks_per_sec, timer->rate);
703 /* If timer expiry would be sooner than in about 1 ms and
704 * auto-reload isn't set, then fire immediately. This is a hack
705 * to make systems like PalmOS run in acceptable time. PalmOS
706 * sets the interval to a very low value and polls the status bit
707 * in a busy loop when it wants to sleep just a couple of CPU
709 if (expires > (ticks_per_sec >> 10) || timer->ar)
710 qemu_mod_timer(timer->timer, timer->time + expires);
712 qemu_bh_schedule(timer->tick);
714 qemu_del_timer(timer->timer);
717 static void omap_timer_fire(void *opaque)
719 struct omap_mpu_timer_s *timer = opaque;
727 /* Edge-triggered irq */
728 qemu_irq_pulse(timer->irq);
731 static void omap_timer_tick(void *opaque)
733 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
735 omap_timer_sync(timer);
736 omap_timer_fire(timer);
737 omap_timer_update(timer);
740 static void omap_timer_clk_update(void *opaque, int line, int on)
742 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
744 omap_timer_sync(timer);
745 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
746 omap_timer_update(timer);
749 static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer)
751 omap_clk_adduser(timer->clk,
752 qemu_allocate_irqs(omap_timer_clk_update, timer, 1)[0]);
753 timer->rate = omap_clk_getrate(timer->clk);
756 static uint32_t omap_mpu_timer_read(void *opaque, target_phys_addr_t addr)
758 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
761 case 0x00: /* CNTL_TIMER */
762 return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st;
764 case 0x04: /* LOAD_TIM */
767 case 0x08: /* READ_TIM */
768 return omap_timer_read(s);
775 static void omap_mpu_timer_write(void *opaque, target_phys_addr_t addr,
778 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
781 case 0x00: /* CNTL_TIMER */
783 s->enable = (value >> 5) & 1;
784 s->ptv = (value >> 2) & 7;
785 s->ar = (value >> 1) & 1;
787 omap_timer_update(s);
790 case 0x04: /* LOAD_TIM */
791 s->reset_val = value;
794 case 0x08: /* READ_TIM */
803 static CPUReadMemoryFunc *omap_mpu_timer_readfn[] = {
804 omap_badwidth_read32,
805 omap_badwidth_read32,
809 static CPUWriteMemoryFunc *omap_mpu_timer_writefn[] = {
810 omap_badwidth_write32,
811 omap_badwidth_write32,
812 omap_mpu_timer_write,
815 static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s)
817 qemu_del_timer(s->timer);
819 s->reset_val = 31337;
827 struct omap_mpu_timer_s *omap_mpu_timer_init(target_phys_addr_t base,
828 qemu_irq irq, omap_clk clk)
831 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *)
832 qemu_mallocz(sizeof(struct omap_mpu_timer_s));
836 s->timer = qemu_new_timer(vm_clock, omap_timer_tick, s);
837 s->tick = qemu_bh_new(omap_timer_fire, s);
838 omap_mpu_timer_reset(s);
839 omap_timer_clk_setup(s);
841 iomemtype = cpu_register_io_memory(0, omap_mpu_timer_readfn,
842 omap_mpu_timer_writefn, s);
843 cpu_register_physical_memory(base, 0x100, iomemtype);
849 struct omap_watchdog_timer_s {
850 struct omap_mpu_timer_s timer;
857 static uint32_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr)
859 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
862 case 0x00: /* CNTL_TIMER */
863 return (s->timer.ptv << 9) | (s->timer.ar << 8) |
864 (s->timer.st << 7) | (s->free << 1);
866 case 0x04: /* READ_TIMER */
867 return omap_timer_read(&s->timer);
869 case 0x08: /* TIMER_MODE */
870 return s->mode << 15;
877 static void omap_wd_timer_write(void *opaque, target_phys_addr_t addr,
880 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
883 case 0x00: /* CNTL_TIMER */
884 omap_timer_sync(&s->timer);
885 s->timer.ptv = (value >> 9) & 7;
886 s->timer.ar = (value >> 8) & 1;
887 s->timer.st = (value >> 7) & 1;
888 s->free = (value >> 1) & 1;
889 omap_timer_update(&s->timer);
892 case 0x04: /* LOAD_TIMER */
893 s->timer.reset_val = value & 0xffff;
896 case 0x08: /* TIMER_MODE */
897 if (!s->mode && ((value >> 15) & 1))
898 omap_clk_get(s->timer.clk);
899 s->mode |= (value >> 15) & 1;
900 if (s->last_wr == 0xf5) {
901 if ((value & 0xff) == 0xa0) {
904 omap_clk_put(s->timer.clk);
907 /* XXX: on T|E hardware somehow this has no effect,
908 * on Zire 71 it works as specified. */
910 qemu_system_reset_request();
913 s->last_wr = value & 0xff;
921 static CPUReadMemoryFunc *omap_wd_timer_readfn[] = {
922 omap_badwidth_read16,
924 omap_badwidth_read16,
927 static CPUWriteMemoryFunc *omap_wd_timer_writefn[] = {
928 omap_badwidth_write16,
930 omap_badwidth_write16,
933 static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s)
935 qemu_del_timer(s->timer.timer);
937 omap_clk_get(s->timer.clk);
943 s->timer.reset_val = 0xffff;
948 omap_timer_update(&s->timer);
951 struct omap_watchdog_timer_s *omap_wd_timer_init(target_phys_addr_t base,
952 qemu_irq irq, omap_clk clk)
955 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *)
956 qemu_mallocz(sizeof(struct omap_watchdog_timer_s));
960 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
961 omap_wd_timer_reset(s);
962 omap_timer_clk_setup(&s->timer);
964 iomemtype = cpu_register_io_memory(0, omap_wd_timer_readfn,
965 omap_wd_timer_writefn, s);
966 cpu_register_physical_memory(base, 0x100, iomemtype);
972 struct omap_32khz_timer_s {
973 struct omap_mpu_timer_s timer;
976 static uint32_t omap_os_timer_read(void *opaque, target_phys_addr_t addr)
978 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
979 int offset = addr & OMAP_MPUI_REG_MASK;
983 return s->timer.reset_val;
986 return omap_timer_read(&s->timer);
989 return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st;
998 static void omap_os_timer_write(void *opaque, target_phys_addr_t addr,
1001 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
1002 int offset = addr & OMAP_MPUI_REG_MASK;
1005 case 0x00: /* TVR */
1006 s->timer.reset_val = value & 0x00ffffff;
1009 case 0x04: /* TCR */
1014 s->timer.ar = (value >> 3) & 1;
1015 s->timer.it_ena = (value >> 2) & 1;
1016 if (s->timer.st != (value & 1) || (value & 2)) {
1017 omap_timer_sync(&s->timer);
1018 s->timer.enable = value & 1;
1019 s->timer.st = value & 1;
1020 omap_timer_update(&s->timer);
1029 static CPUReadMemoryFunc *omap_os_timer_readfn[] = {
1030 omap_badwidth_read32,
1031 omap_badwidth_read32,
1035 static CPUWriteMemoryFunc *omap_os_timer_writefn[] = {
1036 omap_badwidth_write32,
1037 omap_badwidth_write32,
1038 omap_os_timer_write,
1041 static void omap_os_timer_reset(struct omap_32khz_timer_s *s)
1043 qemu_del_timer(s->timer.timer);
1044 s->timer.enable = 0;
1045 s->timer.it_ena = 0;
1046 s->timer.reset_val = 0x00ffffff;
1053 struct omap_32khz_timer_s *omap_os_timer_init(target_phys_addr_t base,
1054 qemu_irq irq, omap_clk clk)
1057 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *)
1058 qemu_mallocz(sizeof(struct omap_32khz_timer_s));
1062 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
1063 omap_os_timer_reset(s);
1064 omap_timer_clk_setup(&s->timer);
1066 iomemtype = cpu_register_io_memory(0, omap_os_timer_readfn,
1067 omap_os_timer_writefn, s);
1068 cpu_register_physical_memory(base, 0x800, iomemtype);
1073 /* Ultra Low-Power Device Module */
1074 static uint32_t omap_ulpd_pm_read(void *opaque, target_phys_addr_t addr)
1076 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1080 case 0x14: /* IT_STATUS */
1081 ret = s->ulpd_pm_regs[addr >> 2];
1082 s->ulpd_pm_regs[addr >> 2] = 0;
1083 qemu_irq_lower(s->irq[1][OMAP_INT_GAUGE_32K]);
1086 case 0x18: /* Reserved */
1087 case 0x1c: /* Reserved */
1088 case 0x20: /* Reserved */
1089 case 0x28: /* Reserved */
1090 case 0x2c: /* Reserved */
1092 case 0x00: /* COUNTER_32_LSB */
1093 case 0x04: /* COUNTER_32_MSB */
1094 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1095 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1096 case 0x10: /* GAUGING_CTRL */
1097 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1098 case 0x30: /* CLOCK_CTRL */
1099 case 0x34: /* SOFT_REQ */
1100 case 0x38: /* COUNTER_32_FIQ */
1101 case 0x3c: /* DPLL_CTRL */
1102 case 0x40: /* STATUS_REQ */
1103 /* XXX: check clk::usecount state for every clock */
1104 case 0x48: /* LOCL_TIME */
1105 case 0x4c: /* APLL_CTRL */
1106 case 0x50: /* POWER_CTRL */
1107 return s->ulpd_pm_regs[addr >> 2];
1114 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s,
1115 uint16_t diff, uint16_t value)
1117 if (diff & (1 << 4)) /* USB_MCLK_EN */
1118 omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1);
1119 if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */
1120 omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1);
1123 static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s,
1124 uint16_t diff, uint16_t value)
1126 if (diff & (1 << 0)) /* SOFT_DPLL_REQ */
1127 omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1);
1128 if (diff & (1 << 1)) /* SOFT_COM_REQ */
1129 omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1);
1130 if (diff & (1 << 2)) /* SOFT_SDW_REQ */
1131 omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1);
1132 if (diff & (1 << 3)) /* SOFT_USB_REQ */
1133 omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1);
1136 static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr,
1139 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1142 static const int bypass_div[4] = { 1, 2, 4, 4 };
1146 case 0x00: /* COUNTER_32_LSB */
1147 case 0x04: /* COUNTER_32_MSB */
1148 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1149 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1150 case 0x14: /* IT_STATUS */
1151 case 0x40: /* STATUS_REQ */
1155 case 0x10: /* GAUGING_CTRL */
1156 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
1157 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
1158 now = qemu_get_clock(vm_clock);
1161 s->ulpd_gauge_start = now;
1163 now -= s->ulpd_gauge_start;
1166 ticks = muldiv64(now, 32768, ticks_per_sec);
1167 s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff;
1168 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff;
1169 if (ticks >> 32) /* OVERFLOW_32K */
1170 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
1172 /* High frequency ticks */
1173 ticks = muldiv64(now, 12000000, ticks_per_sec);
1174 s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff;
1175 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff;
1176 if (ticks >> 32) /* OVERFLOW_HI_FREQ */
1177 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
1179 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
1180 qemu_irq_raise(s->irq[1][OMAP_INT_GAUGE_32K]);
1183 s->ulpd_pm_regs[addr >> 2] = value;
1186 case 0x18: /* Reserved */
1187 case 0x1c: /* Reserved */
1188 case 0x20: /* Reserved */
1189 case 0x28: /* Reserved */
1190 case 0x2c: /* Reserved */
1192 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1193 case 0x38: /* COUNTER_32_FIQ */
1194 case 0x48: /* LOCL_TIME */
1195 case 0x50: /* POWER_CTRL */
1196 s->ulpd_pm_regs[addr >> 2] = value;
1199 case 0x30: /* CLOCK_CTRL */
1200 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
1201 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
1202 omap_ulpd_clk_update(s, diff, value);
1205 case 0x34: /* SOFT_REQ */
1206 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
1207 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
1208 omap_ulpd_req_update(s, diff, value);
1211 case 0x3c: /* DPLL_CTRL */
1212 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
1213 * omitted altogether, probably a typo. */
1214 /* This register has identical semantics with DPLL(1:3) control
1215 * registers, see omap_dpll_write() */
1216 diff = s->ulpd_pm_regs[addr >> 2] & value;
1217 s->ulpd_pm_regs[addr >> 2] = value & 0x2fff;
1218 if (diff & (0x3ff << 2)) {
1219 if (value & (1 << 4)) { /* PLL_ENABLE */
1220 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1221 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1223 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1226 omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
1229 /* Enter the desired mode. */
1230 s->ulpd_pm_regs[addr >> 2] =
1231 (s->ulpd_pm_regs[addr >> 2] & 0xfffe) |
1232 ((s->ulpd_pm_regs[addr >> 2] >> 4) & 1);
1234 /* Act as if the lock is restored. */
1235 s->ulpd_pm_regs[addr >> 2] |= 2;
1238 case 0x4c: /* APLL_CTRL */
1239 diff = s->ulpd_pm_regs[addr >> 2] & value;
1240 s->ulpd_pm_regs[addr >> 2] = value & 0xf;
1241 if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */
1242 omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
1243 (value & (1 << 0)) ? "apll" : "dpll4"));
1251 static CPUReadMemoryFunc *omap_ulpd_pm_readfn[] = {
1252 omap_badwidth_read16,
1254 omap_badwidth_read16,
1257 static CPUWriteMemoryFunc *omap_ulpd_pm_writefn[] = {
1258 omap_badwidth_write16,
1260 omap_badwidth_write16,
1263 static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu)
1265 mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001;
1266 mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000;
1267 mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001;
1268 mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000;
1269 mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000;
1270 mpu->ulpd_pm_regs[0x18 >> 2] = 0x01;
1271 mpu->ulpd_pm_regs[0x1c >> 2] = 0x01;
1272 mpu->ulpd_pm_regs[0x20 >> 2] = 0x01;
1273 mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff;
1274 mpu->ulpd_pm_regs[0x28 >> 2] = 0x01;
1275 mpu->ulpd_pm_regs[0x2c >> 2] = 0x01;
1276 omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000);
1277 mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000;
1278 omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000);
1279 mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000;
1280 mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001;
1281 mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211;
1282 mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
1283 mpu->ulpd_pm_regs[0x48 >> 2] = 0x960;
1284 mpu->ulpd_pm_regs[0x4c >> 2] = 0x08;
1285 mpu->ulpd_pm_regs[0x50 >> 2] = 0x08;
1286 omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4);
1287 omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4"));
1290 static void omap_ulpd_pm_init(target_phys_addr_t base,
1291 struct omap_mpu_state_s *mpu)
1293 int iomemtype = cpu_register_io_memory(0, omap_ulpd_pm_readfn,
1294 omap_ulpd_pm_writefn, mpu);
1296 cpu_register_physical_memory(base, 0x800, iomemtype);
1297 omap_ulpd_pm_reset(mpu);
1300 /* OMAP Pin Configuration */
1301 static uint32_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr)
1303 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1306 case 0x00: /* FUNC_MUX_CTRL_0 */
1307 case 0x04: /* FUNC_MUX_CTRL_1 */
1308 case 0x08: /* FUNC_MUX_CTRL_2 */
1309 return s->func_mux_ctrl[addr >> 2];
1311 case 0x0c: /* COMP_MODE_CTRL_0 */
1312 return s->comp_mode_ctrl[0];
1314 case 0x10: /* FUNC_MUX_CTRL_3 */
1315 case 0x14: /* FUNC_MUX_CTRL_4 */
1316 case 0x18: /* FUNC_MUX_CTRL_5 */
1317 case 0x1c: /* FUNC_MUX_CTRL_6 */
1318 case 0x20: /* FUNC_MUX_CTRL_7 */
1319 case 0x24: /* FUNC_MUX_CTRL_8 */
1320 case 0x28: /* FUNC_MUX_CTRL_9 */
1321 case 0x2c: /* FUNC_MUX_CTRL_A */
1322 case 0x30: /* FUNC_MUX_CTRL_B */
1323 case 0x34: /* FUNC_MUX_CTRL_C */
1324 case 0x38: /* FUNC_MUX_CTRL_D */
1325 return s->func_mux_ctrl[(addr >> 2) - 1];
1327 case 0x40: /* PULL_DWN_CTRL_0 */
1328 case 0x44: /* PULL_DWN_CTRL_1 */
1329 case 0x48: /* PULL_DWN_CTRL_2 */
1330 case 0x4c: /* PULL_DWN_CTRL_3 */
1331 return s->pull_dwn_ctrl[(addr & 0xf) >> 2];
1333 case 0x50: /* GATE_INH_CTRL_0 */
1334 return s->gate_inh_ctrl[0];
1336 case 0x60: /* VOLTAGE_CTRL_0 */
1337 return s->voltage_ctrl[0];
1339 case 0x70: /* TEST_DBG_CTRL_0 */
1340 return s->test_dbg_ctrl[0];
1342 case 0x80: /* MOD_CONF_CTRL_0 */
1343 return s->mod_conf_ctrl[0];
1350 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s,
1351 uint32_t diff, uint32_t value)
1353 if (s->compat1509) {
1354 if (diff & (1 << 9)) /* BLUETOOTH */
1355 omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
1357 if (diff & (1 << 7)) /* USB.CLKO */
1358 omap_clk_onoff(omap_findclk(s, "usb.clko"),
1363 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s,
1364 uint32_t diff, uint32_t value)
1366 if (s->compat1509) {
1367 if (diff & (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
1368 omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"),
1370 if (diff & (1 << 1)) /* CLK32K */
1371 omap_clk_onoff(omap_findclk(s, "clk32k_out"),
1376 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s,
1377 uint32_t diff, uint32_t value)
1379 if (diff & (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
1380 omap_clk_reparent(omap_findclk(s, "uart3_ck"),
1381 omap_findclk(s, ((value >> 31) & 1) ?
1382 "ck_48m" : "armper_ck"));
1383 if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
1384 omap_clk_reparent(omap_findclk(s, "uart2_ck"),
1385 omap_findclk(s, ((value >> 30) & 1) ?
1386 "ck_48m" : "armper_ck"));
1387 if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
1388 omap_clk_reparent(omap_findclk(s, "uart1_ck"),
1389 omap_findclk(s, ((value >> 29) & 1) ?
1390 "ck_48m" : "armper_ck"));
1391 if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
1392 omap_clk_reparent(omap_findclk(s, "mmc_ck"),
1393 omap_findclk(s, ((value >> 23) & 1) ?
1394 "ck_48m" : "armper_ck"));
1395 if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
1396 omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
1397 omap_findclk(s, ((value >> 12) & 1) ?
1398 "ck_48m" : "armper_ck"));
1399 if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
1400 omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1);
1403 static void omap_pin_cfg_write(void *opaque, target_phys_addr_t addr,
1406 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1410 case 0x00: /* FUNC_MUX_CTRL_0 */
1411 diff = s->func_mux_ctrl[addr >> 2] ^ value;
1412 s->func_mux_ctrl[addr >> 2] = value;
1413 omap_pin_funcmux0_update(s, diff, value);
1416 case 0x04: /* FUNC_MUX_CTRL_1 */
1417 diff = s->func_mux_ctrl[addr >> 2] ^ value;
1418 s->func_mux_ctrl[addr >> 2] = value;
1419 omap_pin_funcmux1_update(s, diff, value);
1422 case 0x08: /* FUNC_MUX_CTRL_2 */
1423 s->func_mux_ctrl[addr >> 2] = value;
1426 case 0x0c: /* COMP_MODE_CTRL_0 */
1427 s->comp_mode_ctrl[0] = value;
1428 s->compat1509 = (value != 0x0000eaef);
1429 omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]);
1430 omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]);
1433 case 0x10: /* FUNC_MUX_CTRL_3 */
1434 case 0x14: /* FUNC_MUX_CTRL_4 */
1435 case 0x18: /* FUNC_MUX_CTRL_5 */
1436 case 0x1c: /* FUNC_MUX_CTRL_6 */
1437 case 0x20: /* FUNC_MUX_CTRL_7 */
1438 case 0x24: /* FUNC_MUX_CTRL_8 */
1439 case 0x28: /* FUNC_MUX_CTRL_9 */
1440 case 0x2c: /* FUNC_MUX_CTRL_A */
1441 case 0x30: /* FUNC_MUX_CTRL_B */
1442 case 0x34: /* FUNC_MUX_CTRL_C */
1443 case 0x38: /* FUNC_MUX_CTRL_D */
1444 s->func_mux_ctrl[(addr >> 2) - 1] = value;
1447 case 0x40: /* PULL_DWN_CTRL_0 */
1448 case 0x44: /* PULL_DWN_CTRL_1 */
1449 case 0x48: /* PULL_DWN_CTRL_2 */
1450 case 0x4c: /* PULL_DWN_CTRL_3 */
1451 s->pull_dwn_ctrl[(addr & 0xf) >> 2] = value;
1454 case 0x50: /* GATE_INH_CTRL_0 */
1455 s->gate_inh_ctrl[0] = value;
1458 case 0x60: /* VOLTAGE_CTRL_0 */
1459 s->voltage_ctrl[0] = value;
1462 case 0x70: /* TEST_DBG_CTRL_0 */
1463 s->test_dbg_ctrl[0] = value;
1466 case 0x80: /* MOD_CONF_CTRL_0 */
1467 diff = s->mod_conf_ctrl[0] ^ value;
1468 s->mod_conf_ctrl[0] = value;
1469 omap_pin_modconf1_update(s, diff, value);
1477 static CPUReadMemoryFunc *omap_pin_cfg_readfn[] = {
1478 omap_badwidth_read32,
1479 omap_badwidth_read32,
1483 static CPUWriteMemoryFunc *omap_pin_cfg_writefn[] = {
1484 omap_badwidth_write32,
1485 omap_badwidth_write32,
1489 static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu)
1491 /* Start in Compatibility Mode. */
1492 mpu->compat1509 = 1;
1493 omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0);
1494 omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0);
1495 omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0);
1496 memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl));
1497 memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl));
1498 memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl));
1499 memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl));
1500 memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl));
1501 memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl));
1502 memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl));
1505 static void omap_pin_cfg_init(target_phys_addr_t base,
1506 struct omap_mpu_state_s *mpu)
1508 int iomemtype = cpu_register_io_memory(0, omap_pin_cfg_readfn,
1509 omap_pin_cfg_writefn, mpu);
1511 cpu_register_physical_memory(base, 0x800, iomemtype);
1512 omap_pin_cfg_reset(mpu);
1515 /* Device Identification, Die Identification */
1516 static uint32_t omap_id_read(void *opaque, target_phys_addr_t addr)
1518 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1521 case 0xfffe1800: /* DIE_ID_LSB */
1523 case 0xfffe1804: /* DIE_ID_MSB */
1526 case 0xfffe2000: /* PRODUCT_ID_LSB */
1528 case 0xfffe2004: /* PRODUCT_ID_MSB */
1531 case 0xfffed400: /* JTAG_ID_LSB */
1532 switch (s->mpu_model) {
1538 cpu_abort(cpu_single_env, "%s: bad mpu model\n", __FUNCTION__);
1542 case 0xfffed404: /* JTAG_ID_MSB */
1543 switch (s->mpu_model) {
1549 cpu_abort(cpu_single_env, "%s: bad mpu model\n", __FUNCTION__);
1558 static void omap_id_write(void *opaque, target_phys_addr_t addr,
1564 static CPUReadMemoryFunc *omap_id_readfn[] = {
1565 omap_badwidth_read32,
1566 omap_badwidth_read32,
1570 static CPUWriteMemoryFunc *omap_id_writefn[] = {
1571 omap_badwidth_write32,
1572 omap_badwidth_write32,
1576 static void omap_id_init(struct omap_mpu_state_s *mpu)
1578 int iomemtype = cpu_register_io_memory(0, omap_id_readfn,
1579 omap_id_writefn, mpu);
1580 cpu_register_physical_memory_offset(0xfffe1800, 0x800, iomemtype, 0xfffe1800);
1581 cpu_register_physical_memory_offset(0xfffed400, 0x100, iomemtype, 0xfffed400);
1582 if (!cpu_is_omap15xx(mpu))
1583 cpu_register_physical_memory_offset(0xfffe2000, 0x800, iomemtype, 0xfffe2000);
1586 /* MPUI Control (Dummy) */
1587 static uint32_t omap_mpui_read(void *opaque, target_phys_addr_t addr)
1589 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1592 case 0x00: /* CTRL */
1593 return s->mpui_ctrl;
1594 case 0x04: /* DEBUG_ADDR */
1596 case 0x08: /* DEBUG_DATA */
1598 case 0x0c: /* DEBUG_FLAG */
1600 case 0x10: /* STATUS */
1603 /* Not in OMAP310 */
1604 case 0x14: /* DSP_STATUS */
1605 case 0x18: /* DSP_BOOT_CONFIG */
1607 case 0x1c: /* DSP_MPUI_CONFIG */
1615 static void omap_mpui_write(void *opaque, target_phys_addr_t addr,
1618 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1621 case 0x00: /* CTRL */
1622 s->mpui_ctrl = value & 0x007fffff;
1625 case 0x04: /* DEBUG_ADDR */
1626 case 0x08: /* DEBUG_DATA */
1627 case 0x0c: /* DEBUG_FLAG */
1628 case 0x10: /* STATUS */
1629 /* Not in OMAP310 */
1630 case 0x14: /* DSP_STATUS */
1632 case 0x18: /* DSP_BOOT_CONFIG */
1633 case 0x1c: /* DSP_MPUI_CONFIG */
1641 static CPUReadMemoryFunc *omap_mpui_readfn[] = {
1642 omap_badwidth_read32,
1643 omap_badwidth_read32,
1647 static CPUWriteMemoryFunc *omap_mpui_writefn[] = {
1648 omap_badwidth_write32,
1649 omap_badwidth_write32,
1653 static void omap_mpui_reset(struct omap_mpu_state_s *s)
1655 s->mpui_ctrl = 0x0003ff1b;
1658 static void omap_mpui_init(target_phys_addr_t base,
1659 struct omap_mpu_state_s *mpu)
1661 int iomemtype = cpu_register_io_memory(0, omap_mpui_readfn,
1662 omap_mpui_writefn, mpu);
1664 cpu_register_physical_memory(base, 0x100, iomemtype);
1666 omap_mpui_reset(mpu);
1670 struct omap_tipb_bridge_s {
1677 uint16_t enh_control;
1680 static uint32_t omap_tipb_bridge_read(void *opaque, target_phys_addr_t addr)
1682 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1685 case 0x00: /* TIPB_CNTL */
1687 case 0x04: /* TIPB_BUS_ALLOC */
1689 case 0x08: /* MPU_TIPB_CNTL */
1691 case 0x0c: /* ENHANCED_TIPB_CNTL */
1692 return s->enh_control;
1693 case 0x10: /* ADDRESS_DBG */
1694 case 0x14: /* DATA_DEBUG_LOW */
1695 case 0x18: /* DATA_DEBUG_HIGH */
1697 case 0x1c: /* DEBUG_CNTR_SIG */
1705 static void omap_tipb_bridge_write(void *opaque, target_phys_addr_t addr,
1708 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1711 case 0x00: /* TIPB_CNTL */
1712 s->control = value & 0xffff;
1715 case 0x04: /* TIPB_BUS_ALLOC */
1716 s->alloc = value & 0x003f;
1719 case 0x08: /* MPU_TIPB_CNTL */
1720 s->buffer = value & 0x0003;
1723 case 0x0c: /* ENHANCED_TIPB_CNTL */
1724 s->width_intr = !(value & 2);
1725 s->enh_control = value & 0x000f;
1728 case 0x10: /* ADDRESS_DBG */
1729 case 0x14: /* DATA_DEBUG_LOW */
1730 case 0x18: /* DATA_DEBUG_HIGH */
1731 case 0x1c: /* DEBUG_CNTR_SIG */
1740 static CPUReadMemoryFunc *omap_tipb_bridge_readfn[] = {
1741 omap_badwidth_read16,
1742 omap_tipb_bridge_read,
1743 omap_tipb_bridge_read,
1746 static CPUWriteMemoryFunc *omap_tipb_bridge_writefn[] = {
1747 omap_badwidth_write16,
1748 omap_tipb_bridge_write,
1749 omap_tipb_bridge_write,
1752 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s)
1754 s->control = 0xffff;
1757 s->enh_control = 0x000f;
1760 struct omap_tipb_bridge_s *omap_tipb_bridge_init(target_phys_addr_t base,
1761 qemu_irq abort_irq, omap_clk clk)
1764 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *)
1765 qemu_mallocz(sizeof(struct omap_tipb_bridge_s));
1767 s->abort = abort_irq;
1768 omap_tipb_bridge_reset(s);
1770 iomemtype = cpu_register_io_memory(0, omap_tipb_bridge_readfn,
1771 omap_tipb_bridge_writefn, s);
1772 cpu_register_physical_memory(base, 0x100, iomemtype);
1777 /* Dummy Traffic Controller's Memory Interface */
1778 static uint32_t omap_tcmi_read(void *opaque, target_phys_addr_t addr)
1780 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1784 case 0x00: /* IMIF_PRIO */
1785 case 0x04: /* EMIFS_PRIO */
1786 case 0x08: /* EMIFF_PRIO */
1787 case 0x0c: /* EMIFS_CONFIG */
1788 case 0x10: /* EMIFS_CS0_CONFIG */
1789 case 0x14: /* EMIFS_CS1_CONFIG */
1790 case 0x18: /* EMIFS_CS2_CONFIG */
1791 case 0x1c: /* EMIFS_CS3_CONFIG */
1792 case 0x24: /* EMIFF_MRS */
1793 case 0x28: /* TIMEOUT1 */
1794 case 0x2c: /* TIMEOUT2 */
1795 case 0x30: /* TIMEOUT3 */
1796 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1797 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1798 return s->tcmi_regs[addr >> 2];
1800 case 0x20: /* EMIFF_SDRAM_CONFIG */
1801 ret = s->tcmi_regs[addr >> 2];
1802 s->tcmi_regs[addr >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1803 /* XXX: We can try using the VGA_DIRTY flag for this */
1811 static void omap_tcmi_write(void *opaque, target_phys_addr_t addr,
1814 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1817 case 0x00: /* IMIF_PRIO */
1818 case 0x04: /* EMIFS_PRIO */
1819 case 0x08: /* EMIFF_PRIO */
1820 case 0x10: /* EMIFS_CS0_CONFIG */
1821 case 0x14: /* EMIFS_CS1_CONFIG */
1822 case 0x18: /* EMIFS_CS2_CONFIG */
1823 case 0x1c: /* EMIFS_CS3_CONFIG */
1824 case 0x20: /* EMIFF_SDRAM_CONFIG */
1825 case 0x24: /* EMIFF_MRS */
1826 case 0x28: /* TIMEOUT1 */
1827 case 0x2c: /* TIMEOUT2 */
1828 case 0x30: /* TIMEOUT3 */
1829 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1830 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1831 s->tcmi_regs[addr >> 2] = value;
1833 case 0x0c: /* EMIFS_CONFIG */
1834 s->tcmi_regs[addr >> 2] = (value & 0xf) | (1 << 4);
1842 static CPUReadMemoryFunc *omap_tcmi_readfn[] = {
1843 omap_badwidth_read32,
1844 omap_badwidth_read32,
1848 static CPUWriteMemoryFunc *omap_tcmi_writefn[] = {
1849 omap_badwidth_write32,
1850 omap_badwidth_write32,
1854 static void omap_tcmi_reset(struct omap_mpu_state_s *mpu)
1856 mpu->tcmi_regs[0x00 >> 2] = 0x00000000;
1857 mpu->tcmi_regs[0x04 >> 2] = 0x00000000;
1858 mpu->tcmi_regs[0x08 >> 2] = 0x00000000;
1859 mpu->tcmi_regs[0x0c >> 2] = 0x00000010;
1860 mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb;
1861 mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb;
1862 mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb;
1863 mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb;
1864 mpu->tcmi_regs[0x20 >> 2] = 0x00618800;
1865 mpu->tcmi_regs[0x24 >> 2] = 0x00000037;
1866 mpu->tcmi_regs[0x28 >> 2] = 0x00000000;
1867 mpu->tcmi_regs[0x2c >> 2] = 0x00000000;
1868 mpu->tcmi_regs[0x30 >> 2] = 0x00000000;
1869 mpu->tcmi_regs[0x3c >> 2] = 0x00000003;
1870 mpu->tcmi_regs[0x40 >> 2] = 0x00000000;
1873 static void omap_tcmi_init(target_phys_addr_t base,
1874 struct omap_mpu_state_s *mpu)
1876 int iomemtype = cpu_register_io_memory(0, omap_tcmi_readfn,
1877 omap_tcmi_writefn, mpu);
1879 cpu_register_physical_memory(base, 0x100, iomemtype);
1880 omap_tcmi_reset(mpu);
1883 /* Digital phase-locked loops control */
1884 static uint32_t omap_dpll_read(void *opaque, target_phys_addr_t addr)
1886 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1888 if (addr == 0x00) /* CTL_REG */
1895 static void omap_dpll_write(void *opaque, target_phys_addr_t addr,
1898 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1900 static const int bypass_div[4] = { 1, 2, 4, 4 };
1903 if (addr == 0x00) { /* CTL_REG */
1904 /* See omap_ulpd_pm_write() too */
1905 diff = s->mode & value;
1906 s->mode = value & 0x2fff;
1907 if (diff & (0x3ff << 2)) {
1908 if (value & (1 << 4)) { /* PLL_ENABLE */
1909 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1910 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1912 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1915 omap_clk_setrate(s->dpll, div, mult);
1918 /* Enter the desired mode. */
1919 s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1);
1921 /* Act as if the lock is restored. */
1928 static CPUReadMemoryFunc *omap_dpll_readfn[] = {
1929 omap_badwidth_read16,
1931 omap_badwidth_read16,
1934 static CPUWriteMemoryFunc *omap_dpll_writefn[] = {
1935 omap_badwidth_write16,
1937 omap_badwidth_write16,
1940 static void omap_dpll_reset(struct dpll_ctl_s *s)
1943 omap_clk_setrate(s->dpll, 1, 1);
1946 static void omap_dpll_init(struct dpll_ctl_s *s, target_phys_addr_t base,
1949 int iomemtype = cpu_register_io_memory(0, omap_dpll_readfn,
1950 omap_dpll_writefn, s);
1955 cpu_register_physical_memory(base, 0x100, iomemtype);
1959 struct omap_uart_s {
1960 target_phys_addr_t base;
1961 SerialState *serial; /* TODO */
1962 struct omap_target_agent_s *ta;
1975 void omap_uart_reset(struct omap_uart_s *s)
1984 struct omap_uart_s *omap_uart_init(target_phys_addr_t base,
1985 qemu_irq irq, omap_clk fclk, omap_clk iclk,
1986 qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr)
1988 struct omap_uart_s *s = (struct omap_uart_s *)
1989 qemu_mallocz(sizeof(struct omap_uart_s));
1994 s->serial = serial_mm_init(base, 2, irq, omap_clk_getrate(fclk)/16,
1995 chr ?: qemu_chr_open("null", "null", NULL), 1);
2000 static uint32_t omap_uart_read(void *opaque, target_phys_addr_t addr)
2002 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
2006 case 0x20: /* MDR1 */
2008 case 0x24: /* MDR2 */
2010 case 0x40: /* SCR */
2012 case 0x44: /* SSR */
2014 case 0x48: /* EBLR (OMAP2) */
2016 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2018 case 0x50: /* MVR */
2020 case 0x54: /* SYSC (OMAP2) */
2021 return s->syscontrol;
2022 case 0x58: /* SYSS (OMAP2) */
2024 case 0x5c: /* WER (OMAP2) */
2026 case 0x60: /* CFPS (OMAP2) */
2034 static void omap_uart_write(void *opaque, target_phys_addr_t addr,
2037 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
2041 case 0x20: /* MDR1 */
2042 s->mdr[0] = value & 0x7f;
2044 case 0x24: /* MDR2 */
2045 s->mdr[1] = value & 0xff;
2047 case 0x40: /* SCR */
2048 s->scr = value & 0xff;
2050 case 0x48: /* EBLR (OMAP2) */
2051 s->eblr = value & 0xff;
2053 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2054 s->clksel = value & 1;
2056 case 0x44: /* SSR */
2057 case 0x50: /* MVR */
2058 case 0x58: /* SYSS (OMAP2) */
2061 case 0x54: /* SYSC (OMAP2) */
2062 s->syscontrol = value & 0x1d;
2066 case 0x5c: /* WER (OMAP2) */
2067 s->wkup = value & 0x7f;
2069 case 0x60: /* CFPS (OMAP2) */
2070 s->cfps = value & 0xff;
2077 static CPUReadMemoryFunc *omap_uart_readfn[] = {
2080 omap_badwidth_read8,
2083 static CPUWriteMemoryFunc *omap_uart_writefn[] = {
2086 omap_badwidth_write8,
2089 struct omap_uart_s *omap2_uart_init(struct omap_target_agent_s *ta,
2090 qemu_irq irq, omap_clk fclk, omap_clk iclk,
2091 qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr)
2093 target_phys_addr_t base = omap_l4_attach(ta, 0, 0);
2094 struct omap_uart_s *s = omap_uart_init(base, irq,
2095 fclk, iclk, txdma, rxdma, chr);
2096 int iomemtype = cpu_register_io_memory(0, omap_uart_readfn,
2097 omap_uart_writefn, s);
2101 cpu_register_physical_memory(base + 0x20, 0x100, iomemtype);
2106 void omap_uart_attach(struct omap_uart_s *s, CharDriverState *chr)
2108 /* TODO: Should reuse or destroy current s->serial */
2109 s->serial = serial_mm_init(s->base, 2, s->irq,
2110 omap_clk_getrate(s->fclk) / 16,
2111 chr ?: qemu_chr_open("null", "null", NULL), 1);
2114 /* MPU Clock/Reset/Power Mode Control */
2115 static uint32_t omap_clkm_read(void *opaque, target_phys_addr_t addr)
2117 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2120 case 0x00: /* ARM_CKCTL */
2121 return s->clkm.arm_ckctl;
2123 case 0x04: /* ARM_IDLECT1 */
2124 return s->clkm.arm_idlect1;
2126 case 0x08: /* ARM_IDLECT2 */
2127 return s->clkm.arm_idlect2;
2129 case 0x0c: /* ARM_EWUPCT */
2130 return s->clkm.arm_ewupct;
2132 case 0x10: /* ARM_RSTCT1 */
2133 return s->clkm.arm_rstct1;
2135 case 0x14: /* ARM_RSTCT2 */
2136 return s->clkm.arm_rstct2;
2138 case 0x18: /* ARM_SYSST */
2139 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start;
2141 case 0x1c: /* ARM_CKOUT1 */
2142 return s->clkm.arm_ckout1;
2144 case 0x20: /* ARM_CKOUT2 */
2152 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s,
2153 uint16_t diff, uint16_t value)
2157 if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */
2158 if (value & (1 << 14))
2161 clk = omap_findclk(s, "arminth_ck");
2162 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
2165 if (diff & (1 << 12)) { /* ARM_TIMXO */
2166 clk = omap_findclk(s, "armtim_ck");
2167 if (value & (1 << 12))
2168 omap_clk_reparent(clk, omap_findclk(s, "clkin"));
2170 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
2173 if (diff & (3 << 10)) { /* DSPMMUDIV */
2174 clk = omap_findclk(s, "dspmmu_ck");
2175 omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1);
2177 if (diff & (3 << 8)) { /* TCDIV */
2178 clk = omap_findclk(s, "tc_ck");
2179 omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1);
2181 if (diff & (3 << 6)) { /* DSPDIV */
2182 clk = omap_findclk(s, "dsp_ck");
2183 omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1);
2185 if (diff & (3 << 4)) { /* ARMDIV */
2186 clk = omap_findclk(s, "arm_ck");
2187 omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1);
2189 if (diff & (3 << 2)) { /* LCDDIV */
2190 clk = omap_findclk(s, "lcd_ck");
2191 omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1);
2193 if (diff & (3 << 0)) { /* PERDIV */
2194 clk = omap_findclk(s, "armper_ck");
2195 omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1);
2199 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s,
2200 uint16_t diff, uint16_t value)
2204 if (value & (1 << 11)) /* SETARM_IDLE */
2205 cpu_interrupt(s->env, CPU_INTERRUPT_HALT);
2206 if (!(value & (1 << 10))) /* WKUP_MODE */
2207 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
2209 #define SET_CANIDLE(clock, bit) \
2210 if (diff & (1 << bit)) { \
2211 clk = omap_findclk(s, clock); \
2212 omap_clk_canidle(clk, (value >> bit) & 1); \
2214 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
2215 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
2216 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
2217 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
2218 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
2219 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
2220 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
2221 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
2222 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
2223 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
2224 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
2225 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
2226 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
2227 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
2230 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s,
2231 uint16_t diff, uint16_t value)
2235 #define SET_ONOFF(clock, bit) \
2236 if (diff & (1 << bit)) { \
2237 clk = omap_findclk(s, clock); \
2238 omap_clk_onoff(clk, (value >> bit) & 1); \
2240 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
2241 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
2242 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
2243 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
2244 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
2245 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
2246 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
2247 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
2248 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
2249 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
2250 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
2253 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s,
2254 uint16_t diff, uint16_t value)
2258 if (diff & (3 << 4)) { /* TCLKOUT */
2259 clk = omap_findclk(s, "tclk_out");
2260 switch ((value >> 4) & 3) {
2262 omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
2263 omap_clk_onoff(clk, 1);
2266 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
2267 omap_clk_onoff(clk, 1);
2270 omap_clk_onoff(clk, 0);
2273 if (diff & (3 << 2)) { /* DCLKOUT */
2274 clk = omap_findclk(s, "dclk_out");
2275 switch ((value >> 2) & 3) {
2277 omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
2280 omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
2283 omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
2286 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
2290 if (diff & (3 << 0)) { /* ACLKOUT */
2291 clk = omap_findclk(s, "aclk_out");
2292 switch ((value >> 0) & 3) {
2294 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
2295 omap_clk_onoff(clk, 1);
2298 omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
2299 omap_clk_onoff(clk, 1);
2302 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
2303 omap_clk_onoff(clk, 1);
2306 omap_clk_onoff(clk, 0);
2311 static void omap_clkm_write(void *opaque, target_phys_addr_t addr,
2314 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2317 static const char *clkschemename[8] = {
2318 "fully synchronous", "fully asynchronous", "synchronous scalable",
2319 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
2323 case 0x00: /* ARM_CKCTL */
2324 diff = s->clkm.arm_ckctl ^ value;
2325 s->clkm.arm_ckctl = value & 0x7fff;
2326 omap_clkm_ckctl_update(s, diff, value);
2329 case 0x04: /* ARM_IDLECT1 */
2330 diff = s->clkm.arm_idlect1 ^ value;
2331 s->clkm.arm_idlect1 = value & 0x0fff;
2332 omap_clkm_idlect1_update(s, diff, value);
2335 case 0x08: /* ARM_IDLECT2 */
2336 diff = s->clkm.arm_idlect2 ^ value;
2337 s->clkm.arm_idlect2 = value & 0x07ff;
2338 omap_clkm_idlect2_update(s, diff, value);
2341 case 0x0c: /* ARM_EWUPCT */
2342 diff = s->clkm.arm_ewupct ^ value;
2343 s->clkm.arm_ewupct = value & 0x003f;
2346 case 0x10: /* ARM_RSTCT1 */
2347 diff = s->clkm.arm_rstct1 ^ value;
2348 s->clkm.arm_rstct1 = value & 0x0007;
2350 qemu_system_reset_request();
2351 s->clkm.cold_start = 0xa;
2353 if (diff & ~value & 4) { /* DSP_RST */
2355 omap_tipb_bridge_reset(s->private_tipb);
2356 omap_tipb_bridge_reset(s->public_tipb);
2358 if (diff & 2) { /* DSP_EN */
2359 clk = omap_findclk(s, "dsp_ck");
2360 omap_clk_canidle(clk, (~value >> 1) & 1);
2364 case 0x14: /* ARM_RSTCT2 */
2365 s->clkm.arm_rstct2 = value & 0x0001;
2368 case 0x18: /* ARM_SYSST */
2369 if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) {
2370 s->clkm.clocking_scheme = (value >> 11) & 7;
2371 printf("%s: clocking scheme set to %s\n", __FUNCTION__,
2372 clkschemename[s->clkm.clocking_scheme]);
2374 s->clkm.cold_start &= value & 0x3f;
2377 case 0x1c: /* ARM_CKOUT1 */
2378 diff = s->clkm.arm_ckout1 ^ value;
2379 s->clkm.arm_ckout1 = value & 0x003f;
2380 omap_clkm_ckout1_update(s, diff, value);
2383 case 0x20: /* ARM_CKOUT2 */
2389 static CPUReadMemoryFunc *omap_clkm_readfn[] = {
2390 omap_badwidth_read16,
2392 omap_badwidth_read16,
2395 static CPUWriteMemoryFunc *omap_clkm_writefn[] = {
2396 omap_badwidth_write16,
2398 omap_badwidth_write16,
2401 static uint32_t omap_clkdsp_read(void *opaque, target_phys_addr_t addr)
2403 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2406 case 0x04: /* DSP_IDLECT1 */
2407 return s->clkm.dsp_idlect1;
2409 case 0x08: /* DSP_IDLECT2 */
2410 return s->clkm.dsp_idlect2;
2412 case 0x14: /* DSP_RSTCT2 */
2413 return s->clkm.dsp_rstct2;
2415 case 0x18: /* DSP_SYSST */
2416 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start |
2417 (s->env->halted << 6); /* Quite useless... */
2424 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s,
2425 uint16_t diff, uint16_t value)
2429 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
2432 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s,
2433 uint16_t diff, uint16_t value)
2437 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
2440 static void omap_clkdsp_write(void *opaque, target_phys_addr_t addr,
2443 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2447 case 0x04: /* DSP_IDLECT1 */
2448 diff = s->clkm.dsp_idlect1 ^ value;
2449 s->clkm.dsp_idlect1 = value & 0x01f7;
2450 omap_clkdsp_idlect1_update(s, diff, value);
2453 case 0x08: /* DSP_IDLECT2 */
2454 s->clkm.dsp_idlect2 = value & 0x0037;
2455 diff = s->clkm.dsp_idlect1 ^ value;
2456 omap_clkdsp_idlect2_update(s, diff, value);
2459 case 0x14: /* DSP_RSTCT2 */
2460 s->clkm.dsp_rstct2 = value & 0x0001;
2463 case 0x18: /* DSP_SYSST */
2464 s->clkm.cold_start &= value & 0x3f;
2472 static CPUReadMemoryFunc *omap_clkdsp_readfn[] = {
2473 omap_badwidth_read16,
2475 omap_badwidth_read16,
2478 static CPUWriteMemoryFunc *omap_clkdsp_writefn[] = {
2479 omap_badwidth_write16,
2481 omap_badwidth_write16,
2484 static void omap_clkm_reset(struct omap_mpu_state_s *s)
2486 if (s->wdt && s->wdt->reset)
2487 s->clkm.cold_start = 0x6;
2488 s->clkm.clocking_scheme = 0;
2489 omap_clkm_ckctl_update(s, ~0, 0x3000);
2490 s->clkm.arm_ckctl = 0x3000;
2491 omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 ^ 0x0400, 0x0400);
2492 s->clkm.arm_idlect1 = 0x0400;
2493 omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 ^ 0x0100, 0x0100);
2494 s->clkm.arm_idlect2 = 0x0100;
2495 s->clkm.arm_ewupct = 0x003f;
2496 s->clkm.arm_rstct1 = 0x0000;
2497 s->clkm.arm_rstct2 = 0x0000;
2498 s->clkm.arm_ckout1 = 0x0015;
2499 s->clkm.dpll1_mode = 0x2002;
2500 omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040);
2501 s->clkm.dsp_idlect1 = 0x0040;
2502 omap_clkdsp_idlect2_update(s, ~0, 0x0000);
2503 s->clkm.dsp_idlect2 = 0x0000;
2504 s->clkm.dsp_rstct2 = 0x0000;
2507 static void omap_clkm_init(target_phys_addr_t mpu_base,
2508 target_phys_addr_t dsp_base, struct omap_mpu_state_s *s)
2510 int iomemtype[2] = {
2511 cpu_register_io_memory(0, omap_clkm_readfn, omap_clkm_writefn, s),
2512 cpu_register_io_memory(0, omap_clkdsp_readfn, omap_clkdsp_writefn, s),
2515 s->clkm.arm_idlect1 = 0x03ff;
2516 s->clkm.arm_idlect2 = 0x0100;
2517 s->clkm.dsp_idlect1 = 0x0002;
2519 s->clkm.cold_start = 0x3a;
2521 cpu_register_physical_memory(mpu_base, 0x100, iomemtype[0]);
2522 cpu_register_physical_memory(dsp_base, 0x1000, iomemtype[1]);
2526 struct omap_mpuio_s {
2530 qemu_irq handler[16];
2551 static void omap_mpuio_set(void *opaque, int line, int level)
2553 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2554 uint16_t prev = s->inputs;
2557 s->inputs |= 1 << line;
2559 s->inputs &= ~(1 << line);
2561 if (((1 << line) & s->dir & ~s->mask) && s->clk) {
2562 if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
2563 s->ints |= 1 << line;
2564 qemu_irq_raise(s->irq);
2567 if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */
2568 (s->event >> 1) == line) /* PIN_SELECT */
2569 s->latch = s->inputs;
2573 static void omap_mpuio_kbd_update(struct omap_mpuio_s *s)
2576 uint8_t *row, rows = 0, cols = ~s->cols;
2578 for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1)
2582 qemu_set_irq(s->kbd_irq, rows && !s->kbd_mask && s->clk);
2583 s->row_latch = ~rows;
2586 static uint32_t omap_mpuio_read(void *opaque, target_phys_addr_t addr)
2588 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2589 int offset = addr & OMAP_MPUI_REG_MASK;
2593 case 0x00: /* INPUT_LATCH */
2596 case 0x04: /* OUTPUT_REG */
2599 case 0x08: /* IO_CNTL */
2602 case 0x10: /* KBR_LATCH */
2603 return s->row_latch;
2605 case 0x14: /* KBC_REG */
2608 case 0x18: /* GPIO_EVENT_MODE_REG */
2611 case 0x1c: /* GPIO_INT_EDGE_REG */
2614 case 0x20: /* KBD_INT */
2615 return (~s->row_latch & 0x1f) && !s->kbd_mask;
2617 case 0x24: /* GPIO_INT */
2621 qemu_irq_lower(s->irq);
2624 case 0x28: /* KBD_MASKIT */
2627 case 0x2c: /* GPIO_MASKIT */
2630 case 0x30: /* GPIO_DEBOUNCING_REG */
2633 case 0x34: /* GPIO_LATCH_REG */
2641 static void omap_mpuio_write(void *opaque, target_phys_addr_t addr,
2644 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2645 int offset = addr & OMAP_MPUI_REG_MASK;
2650 case 0x04: /* OUTPUT_REG */
2651 diff = (s->outputs ^ value) & ~s->dir;
2653 while ((ln = ffs(diff))) {
2656 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2661 case 0x08: /* IO_CNTL */
2662 diff = s->outputs & (s->dir ^ value);
2665 value = s->outputs & ~s->dir;
2666 while ((ln = ffs(diff))) {
2669 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2674 case 0x14: /* KBC_REG */
2676 omap_mpuio_kbd_update(s);
2679 case 0x18: /* GPIO_EVENT_MODE_REG */
2680 s->event = value & 0x1f;
2683 case 0x1c: /* GPIO_INT_EDGE_REG */
2687 case 0x28: /* KBD_MASKIT */
2688 s->kbd_mask = value & 1;
2689 omap_mpuio_kbd_update(s);
2692 case 0x2c: /* GPIO_MASKIT */
2696 case 0x30: /* GPIO_DEBOUNCING_REG */
2697 s->debounce = value & 0x1ff;
2700 case 0x00: /* INPUT_LATCH */
2701 case 0x10: /* KBR_LATCH */
2702 case 0x20: /* KBD_INT */
2703 case 0x24: /* GPIO_INT */
2704 case 0x34: /* GPIO_LATCH_REG */
2714 static CPUReadMemoryFunc *omap_mpuio_readfn[] = {
2715 omap_badwidth_read16,
2717 omap_badwidth_read16,
2720 static CPUWriteMemoryFunc *omap_mpuio_writefn[] = {
2721 omap_badwidth_write16,
2723 omap_badwidth_write16,
2726 static void omap_mpuio_reset(struct omap_mpuio_s *s)
2738 s->row_latch = 0x1f;
2742 static void omap_mpuio_onoff(void *opaque, int line, int on)
2744 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2748 omap_mpuio_kbd_update(s);
2751 struct omap_mpuio_s *omap_mpuio_init(target_phys_addr_t base,
2752 qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup,
2756 struct omap_mpuio_s *s = (struct omap_mpuio_s *)
2757 qemu_mallocz(sizeof(struct omap_mpuio_s));
2760 s->kbd_irq = kbd_int;
2762 s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
2763 omap_mpuio_reset(s);
2765 iomemtype = cpu_register_io_memory(0, omap_mpuio_readfn,
2766 omap_mpuio_writefn, s);
2767 cpu_register_physical_memory(base, 0x800, iomemtype);
2769 omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]);
2774 qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
2779 void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler)
2781 if (line >= 16 || line < 0)
2782 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
2783 s->handler[line] = handler;
2786 void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down)
2788 if (row >= 5 || row < 0)
2789 cpu_abort(cpu_single_env, "%s: No key %i-%i\n",
2790 __FUNCTION__, col, row);
2793 s->buttons[row] |= 1 << col;
2795 s->buttons[row] &= ~(1 << col);
2797 omap_mpuio_kbd_update(s);
2800 /* General-Purpose I/O */
2801 struct omap_gpio_s {
2804 qemu_irq handler[16];
2815 static void omap_gpio_set(void *opaque, int line, int level)
2817 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2818 uint16_t prev = s->inputs;
2821 s->inputs |= 1 << line;
2823 s->inputs &= ~(1 << line);
2825 if (((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) &
2826 (1 << line) & s->dir & ~s->mask) {
2827 s->ints |= 1 << line;
2828 qemu_irq_raise(s->irq);
2832 static uint32_t omap_gpio_read(void *opaque, target_phys_addr_t addr)
2834 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2835 int offset = addr & OMAP_MPUI_REG_MASK;
2838 case 0x00: /* DATA_INPUT */
2839 return s->inputs & s->pins;
2841 case 0x04: /* DATA_OUTPUT */
2844 case 0x08: /* DIRECTION_CONTROL */
2847 case 0x0c: /* INTERRUPT_CONTROL */
2850 case 0x10: /* INTERRUPT_MASK */
2853 case 0x14: /* INTERRUPT_STATUS */
2856 case 0x18: /* PIN_CONTROL (not in OMAP310) */
2865 static void omap_gpio_write(void *opaque, target_phys_addr_t addr,
2868 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2869 int offset = addr & OMAP_MPUI_REG_MASK;
2874 case 0x00: /* DATA_INPUT */
2878 case 0x04: /* DATA_OUTPUT */
2879 diff = (s->outputs ^ value) & ~s->dir;
2881 while ((ln = ffs(diff))) {
2884 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2889 case 0x08: /* DIRECTION_CONTROL */
2890 diff = s->outputs & (s->dir ^ value);
2893 value = s->outputs & ~s->dir;
2894 while ((ln = ffs(diff))) {
2897 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2902 case 0x0c: /* INTERRUPT_CONTROL */
2906 case 0x10: /* INTERRUPT_MASK */
2910 case 0x14: /* INTERRUPT_STATUS */
2913 qemu_irq_lower(s->irq);
2916 case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */
2927 /* *Some* sources say the memory region is 32-bit. */
2928 static CPUReadMemoryFunc *omap_gpio_readfn[] = {
2929 omap_badwidth_read16,
2931 omap_badwidth_read16,
2934 static CPUWriteMemoryFunc *omap_gpio_writefn[] = {
2935 omap_badwidth_write16,
2937 omap_badwidth_write16,
2940 static void omap_gpio_reset(struct omap_gpio_s *s)
2951 struct omap_gpio_s *omap_gpio_init(target_phys_addr_t base,
2952 qemu_irq irq, omap_clk clk)
2955 struct omap_gpio_s *s = (struct omap_gpio_s *)
2956 qemu_mallocz(sizeof(struct omap_gpio_s));
2959 s->in = qemu_allocate_irqs(omap_gpio_set, s, 16);
2962 iomemtype = cpu_register_io_memory(0, omap_gpio_readfn,
2963 omap_gpio_writefn, s);
2964 cpu_register_physical_memory(base, 0x1000, iomemtype);
2969 qemu_irq *omap_gpio_in_get(struct omap_gpio_s *s)
2974 void omap_gpio_out_set(struct omap_gpio_s *s, int line, qemu_irq handler)
2976 if (line >= 16 || line < 0)
2977 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
2978 s->handler[line] = handler;
2981 /* MicroWire Interface */
2982 struct omap_uwire_s {
2992 struct uwire_slave_s *chip[4];
2995 static void omap_uwire_transfer_start(struct omap_uwire_s *s)
2997 int chipselect = (s->control >> 10) & 3; /* INDEX */
2998 struct uwire_slave_s *slave = s->chip[chipselect];
3000 if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */
3001 if (s->control & (1 << 12)) /* CS_CMD */
3002 if (slave && slave->send)
3003 slave->send(slave->opaque,
3004 s->txbuf >> (16 - ((s->control >> 5) & 0x1f)));
3005 s->control &= ~(1 << 14); /* CSRB */
3006 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3007 * a DRQ. When is the level IRQ supposed to be reset? */
3010 if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */
3011 if (s->control & (1 << 12)) /* CS_CMD */
3012 if (slave && slave->receive)
3013 s->rxbuf = slave->receive(slave->opaque);
3014 s->control |= 1 << 15; /* RDRB */
3015 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3016 * a DRQ. When is the level IRQ supposed to be reset? */
3020 static uint32_t omap_uwire_read(void *opaque, target_phys_addr_t addr)
3022 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
3023 int offset = addr & OMAP_MPUI_REG_MASK;
3026 case 0x00: /* RDR */
3027 s->control &= ~(1 << 15); /* RDRB */
3030 case 0x04: /* CSR */
3033 case 0x08: /* SR1 */
3035 case 0x0c: /* SR2 */
3037 case 0x10: /* SR3 */
3039 case 0x14: /* SR4 */
3041 case 0x18: /* SR5 */
3049 static void omap_uwire_write(void *opaque, target_phys_addr_t addr,
3052 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
3053 int offset = addr & OMAP_MPUI_REG_MASK;
3056 case 0x00: /* TDR */
3057 s->txbuf = value; /* TD */
3058 if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */
3059 ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
3060 (s->control & (1 << 12)))) { /* CS_CMD */
3061 s->control |= 1 << 14; /* CSRB */
3062 omap_uwire_transfer_start(s);
3066 case 0x04: /* CSR */
3067 s->control = value & 0x1fff;
3068 if (value & (1 << 13)) /* START */
3069 omap_uwire_transfer_start(s);
3072 case 0x08: /* SR1 */
3073 s->setup[0] = value & 0x003f;
3076 case 0x0c: /* SR2 */
3077 s->setup[1] = value & 0x0fc0;
3080 case 0x10: /* SR3 */
3081 s->setup[2] = value & 0x0003;
3084 case 0x14: /* SR4 */
3085 s->setup[3] = value & 0x0001;
3088 case 0x18: /* SR5 */
3089 s->setup[4] = value & 0x000f;
3098 static CPUReadMemoryFunc *omap_uwire_readfn[] = {
3099 omap_badwidth_read16,
3101 omap_badwidth_read16,
3104 static CPUWriteMemoryFunc *omap_uwire_writefn[] = {
3105 omap_badwidth_write16,
3107 omap_badwidth_write16,
3110 static void omap_uwire_reset(struct omap_uwire_s *s)
3120 struct omap_uwire_s *omap_uwire_init(target_phys_addr_t base,
3121 qemu_irq *irq, qemu_irq dma, omap_clk clk)
3124 struct omap_uwire_s *s = (struct omap_uwire_s *)
3125 qemu_mallocz(sizeof(struct omap_uwire_s));
3130 omap_uwire_reset(s);
3132 iomemtype = cpu_register_io_memory(0, omap_uwire_readfn,
3133 omap_uwire_writefn, s);
3134 cpu_register_physical_memory(base, 0x800, iomemtype);
3139 void omap_uwire_attach(struct omap_uwire_s *s,
3140 struct uwire_slave_s *slave, int chipselect)
3142 if (chipselect < 0 || chipselect > 3) {
3143 fprintf(stderr, "%s: Bad chipselect %i\n", __FUNCTION__, chipselect);
3147 s->chip[chipselect] = slave;
3150 /* Pseudonoise Pulse-Width Light Modulator */
3151 static void omap_pwl_update(struct omap_mpu_state_s *s)
3153 int output = (s->pwl.clk && s->pwl.enable) ? s->pwl.level : 0;
3155 if (output != s->pwl.output) {
3156 s->pwl.output = output;
3157 printf("%s: Backlight now at %i/256\n", __FUNCTION__, output);
3161 static uint32_t omap_pwl_read(void *opaque, target_phys_addr_t addr)
3163 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3164 int offset = addr & OMAP_MPUI_REG_MASK;
3167 case 0x00: /* PWL_LEVEL */
3168 return s->pwl.level;
3169 case 0x04: /* PWL_CTRL */
3170 return s->pwl.enable;
3176 static void omap_pwl_write(void *opaque, target_phys_addr_t addr,
3179 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3180 int offset = addr & OMAP_MPUI_REG_MASK;
3183 case 0x00: /* PWL_LEVEL */
3184 s->pwl.level = value;
3187 case 0x04: /* PWL_CTRL */
3188 s->pwl.enable = value & 1;
3197 static CPUReadMemoryFunc *omap_pwl_readfn[] = {
3199 omap_badwidth_read8,
3200 omap_badwidth_read8,
3203 static CPUWriteMemoryFunc *omap_pwl_writefn[] = {
3205 omap_badwidth_write8,
3206 omap_badwidth_write8,
3209 static void omap_pwl_reset(struct omap_mpu_state_s *s)
3218 static void omap_pwl_clk_update(void *opaque, int line, int on)
3220 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3226 static void omap_pwl_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
3233 iomemtype = cpu_register_io_memory(0, omap_pwl_readfn,
3234 omap_pwl_writefn, s);
3235 cpu_register_physical_memory(base, 0x800, iomemtype);
3237 omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]);
3240 /* Pulse-Width Tone module */
3241 static uint32_t omap_pwt_read(void *opaque, target_phys_addr_t addr)
3243 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3244 int offset = addr & OMAP_MPUI_REG_MASK;
3247 case 0x00: /* FRC */
3249 case 0x04: /* VCR */
3251 case 0x08: /* GCR */
3258 static void omap_pwt_write(void *opaque, target_phys_addr_t addr,
3261 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3262 int offset = addr & OMAP_MPUI_REG_MASK;
3265 case 0x00: /* FRC */
3266 s->pwt.frc = value & 0x3f;
3268 case 0x04: /* VRC */
3269 if ((value ^ s->pwt.vrc) & 1) {
3271 printf("%s: %iHz buzz on\n", __FUNCTION__, (int)
3272 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
3273 ((omap_clk_getrate(s->pwt.clk) >> 3) /
3274 /* Pre-multiplexer divider */
3275 ((s->pwt.gcr & 2) ? 1 : 154) /
3276 /* Octave multiplexer */
3277 (2 << (value & 3)) *
3278 /* 101/107 divider */
3279 ((value & (1 << 2)) ? 101 : 107) *
3281 ((value & (1 << 3)) ? 49 : 55) *
3283 ((value & (1 << 4)) ? 50 : 63) *
3284 /* 80/127 divider */
3285 ((value & (1 << 5)) ? 80 : 127) /
3286 (107 * 55 * 63 * 127)));
3288 printf("%s: silence!\n", __FUNCTION__);
3290 s->pwt.vrc = value & 0x7f;
3292 case 0x08: /* GCR */
3293 s->pwt.gcr = value & 3;
3301 static CPUReadMemoryFunc *omap_pwt_readfn[] = {
3303 omap_badwidth_read8,
3304 omap_badwidth_read8,
3307 static CPUWriteMemoryFunc *omap_pwt_writefn[] = {
3309 omap_badwidth_write8,
3310 omap_badwidth_write8,
3313 static void omap_pwt_reset(struct omap_mpu_state_s *s)
3320 static void omap_pwt_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
3328 iomemtype = cpu_register_io_memory(0, omap_pwt_readfn,
3329 omap_pwt_writefn, s);
3330 cpu_register_physical_memory(base, 0x800, iomemtype);
3333 /* Real-time Clock module */
3349 struct tm current_tm;
3354 static void omap_rtc_interrupts_update(struct omap_rtc_s *s)
3356 /* s->alarm is level-triggered */
3357 qemu_set_irq(s->alarm, (s->status >> 6) & 1);
3360 static void omap_rtc_alarm_update(struct omap_rtc_s *s)
3362 s->alarm_ti = mktimegm(&s->alarm_tm);
3363 if (s->alarm_ti == -1)
3364 printf("%s: conversion failed\n", __FUNCTION__);
3367 static inline uint8_t omap_rtc_bcd(int num)
3369 return ((num / 10) << 4) | (num % 10);
3372 static inline int omap_rtc_bin(uint8_t num)
3374 return (num & 15) + 10 * (num >> 4);
3377 static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr)
3379 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
3380 int offset = addr & OMAP_MPUI_REG_MASK;
3384 case 0x00: /* SECONDS_REG */
3385 return omap_rtc_bcd(s->current_tm.tm_sec);
3387 case 0x04: /* MINUTES_REG */
3388 return omap_rtc_bcd(s->current_tm.tm_min);
3390 case 0x08: /* HOURS_REG */
3392 return ((s->current_tm.tm_hour > 11) << 7) |
3393 omap_rtc_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
3395 return omap_rtc_bcd(s->current_tm.tm_hour);
3397 case 0x0c: /* DAYS_REG */
3398 return omap_rtc_bcd(s->current_tm.tm_mday);
3400 case 0x10: /* MONTHS_REG */
3401 return omap_rtc_bcd(s->current_tm.tm_mon + 1);
3403 case 0x14: /* YEARS_REG */
3404 return omap_rtc_bcd(s->current_tm.tm_year % 100);
3406 case 0x18: /* WEEK_REG */
3407 return s->current_tm.tm_wday;
3409 case 0x20: /* ALARM_SECONDS_REG */
3410 return omap_rtc_bcd(s->alarm_tm.tm_sec);
3412 case 0x24: /* ALARM_MINUTES_REG */
3413 return omap_rtc_bcd(s->alarm_tm.tm_min);
3415 case 0x28: /* ALARM_HOURS_REG */
3417 return ((s->alarm_tm.tm_hour > 11) << 7) |
3418 omap_rtc_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
3420 return omap_rtc_bcd(s->alarm_tm.tm_hour);
3422 case 0x2c: /* ALARM_DAYS_REG */
3423 return omap_rtc_bcd(s->alarm_tm.tm_mday);
3425 case 0x30: /* ALARM_MONTHS_REG */
3426 return omap_rtc_bcd(s->alarm_tm.tm_mon + 1);
3428 case 0x34: /* ALARM_YEARS_REG */
3429 return omap_rtc_bcd(s->alarm_tm.tm_year % 100);
3431 case 0x40: /* RTC_CTRL_REG */
3432 return (s->pm_am << 3) | (s->auto_comp << 2) |
3433 (s->round << 1) | s->running;
3435 case 0x44: /* RTC_STATUS_REG */
3440 case 0x48: /* RTC_INTERRUPTS_REG */
3441 return s->interrupts;
3443 case 0x4c: /* RTC_COMP_LSB_REG */
3444 return ((uint16_t) s->comp_reg) & 0xff;
3446 case 0x50: /* RTC_COMP_MSB_REG */
3447 return ((uint16_t) s->comp_reg) >> 8;
3454 static void omap_rtc_write(void *opaque, target_phys_addr_t addr,
3457 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
3458 int offset = addr & OMAP_MPUI_REG_MASK;
3463 case 0x00: /* SECONDS_REG */
3465 printf("RTC SEC_REG <-- %02x\n", value);
3467 s->ti -= s->current_tm.tm_sec;
3468 s->ti += omap_rtc_bin(value);
3471 case 0x04: /* MINUTES_REG */
3473 printf("RTC MIN_REG <-- %02x\n", value);
3475 s->ti -= s->current_tm.tm_min * 60;
3476 s->ti += omap_rtc_bin(value) * 60;
3479 case 0x08: /* HOURS_REG */
3481 printf("RTC HRS_REG <-- %02x\n", value);
3483 s->ti -= s->current_tm.tm_hour * 3600;
3485 s->ti += (omap_rtc_bin(value & 0x3f) & 12) * 3600;
3486 s->ti += ((value >> 7) & 1) * 43200;
3488 s->ti += omap_rtc_bin(value & 0x3f) * 3600;
3491 case 0x0c: /* DAYS_REG */
3493 printf("RTC DAY_REG <-- %02x\n", value);
3495 s->ti -= s->current_tm.tm_mday * 86400;
3496 s->ti += omap_rtc_bin(value) * 86400;
3499 case 0x10: /* MONTHS_REG */
3501 printf("RTC MTH_REG <-- %02x\n", value);
3503 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3504 new_tm.tm_mon = omap_rtc_bin(value);
3505 ti[0] = mktimegm(&s->current_tm);
3506 ti[1] = mktimegm(&new_tm);
3508 if (ti[0] != -1 && ti[1] != -1) {
3512 /* A less accurate version */
3513 s->ti -= s->current_tm.tm_mon * 2592000;
3514 s->ti += omap_rtc_bin(value) * 2592000;
3518 case 0x14: /* YEARS_REG */
3520 printf("RTC YRS_REG <-- %02x\n", value);
3522 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3523 new_tm.tm_year += omap_rtc_bin(value) - (new_tm.tm_year % 100);
3524 ti[0] = mktimegm(&s->current_tm);
3525 ti[1] = mktimegm(&new_tm);
3527 if (ti[0] != -1 && ti[1] != -1) {
3531 /* A less accurate version */
3532 s->ti -= (s->current_tm.tm_year % 100) * 31536000;
3533 s->ti += omap_rtc_bin(value) * 31536000;
3537 case 0x18: /* WEEK_REG */
3538 return; /* Ignored */
3540 case 0x20: /* ALARM_SECONDS_REG */
3542 printf("ALM SEC_REG <-- %02x\n", value);
3544 s->alarm_tm.tm_sec = omap_rtc_bin(value);
3545 omap_rtc_alarm_update(s);
3548 case 0x24: /* ALARM_MINUTES_REG */
3550 printf("ALM MIN_REG <-- %02x\n", value);
3552 s->alarm_tm.tm_min = omap_rtc_bin(value);
3553 omap_rtc_alarm_update(s);
3556 case 0x28: /* ALARM_HOURS_REG */
3558 printf("ALM HRS_REG <-- %02x\n", value);
3561 s->alarm_tm.tm_hour =
3562 ((omap_rtc_bin(value & 0x3f)) % 12) +
3563 ((value >> 7) & 1) * 12;
3565 s->alarm_tm.tm_hour = omap_rtc_bin(value);
3566 omap_rtc_alarm_update(s);
3569 case 0x2c: /* ALARM_DAYS_REG */
3571 printf("ALM DAY_REG <-- %02x\n", value);
3573 s->alarm_tm.tm_mday = omap_rtc_bin(value);
3574 omap_rtc_alarm_update(s);
3577 case 0x30: /* ALARM_MONTHS_REG */
3579 printf("ALM MON_REG <-- %02x\n", value);
3581 s->alarm_tm.tm_mon = omap_rtc_bin(value);
3582 omap_rtc_alarm_update(s);
3585 case 0x34: /* ALARM_YEARS_REG */
3587 printf("ALM YRS_REG <-- %02x\n", value);
3589 s->alarm_tm.tm_year = omap_rtc_bin(value);
3590 omap_rtc_alarm_update(s);
3593 case 0x40: /* RTC_CTRL_REG */
3595 printf("RTC CONTROL <-- %02x\n", value);
3597 s->pm_am = (value >> 3) & 1;
3598 s->auto_comp = (value >> 2) & 1;
3599 s->round = (value >> 1) & 1;
3600 s->running = value & 1;
3602 s->status |= s->running << 1;
3605 case 0x44: /* RTC_STATUS_REG */
3607 printf("RTC STATUSL <-- %02x\n", value);
3609 s->status &= ~((value & 0xc0) ^ 0x80);
3610 omap_rtc_interrupts_update(s);
3613 case 0x48: /* RTC_INTERRUPTS_REG */
3615 printf("RTC INTRS <-- %02x\n", value);
3617 s->interrupts = value;
3620 case 0x4c: /* RTC_COMP_LSB_REG */
3622 printf("RTC COMPLSB <-- %02x\n", value);
3624 s->comp_reg &= 0xff00;
3625 s->comp_reg |= 0x00ff & value;
3628 case 0x50: /* RTC_COMP_MSB_REG */
3630 printf("RTC COMPMSB <-- %02x\n", value);
3632 s->comp_reg &= 0x00ff;
3633 s->comp_reg |= 0xff00 & (value << 8);
3642 static CPUReadMemoryFunc *omap_rtc_readfn[] = {
3644 omap_badwidth_read8,
3645 omap_badwidth_read8,
3648 static CPUWriteMemoryFunc *omap_rtc_writefn[] = {
3650 omap_badwidth_write8,
3651 omap_badwidth_write8,
3654 static void omap_rtc_tick(void *opaque)
3656 struct omap_rtc_s *s = opaque;
3659 /* Round to nearest full minute. */
3660 if (s->current_tm.tm_sec < 30)
3661 s->ti -= s->current_tm.tm_sec;
3663 s->ti += 60 - s->current_tm.tm_sec;
3668 memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm));
3670 if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) {
3672 omap_rtc_interrupts_update(s);
3675 if (s->interrupts & 0x04)
3676 switch (s->interrupts & 3) {
3679 qemu_irq_pulse(s->irq);
3682 if (s->current_tm.tm_sec)
3685 qemu_irq_pulse(s->irq);
3688 if (s->current_tm.tm_sec || s->current_tm.tm_min)
3691 qemu_irq_pulse(s->irq);
3694 if (s->current_tm.tm_sec ||
3695 s->current_tm.tm_min || s->current_tm.tm_hour)
3698 qemu_irq_pulse(s->irq);
3708 * Every full hour add a rough approximation of the compensation
3709 * register to the 32kHz Timer (which drives the RTC) value.
3711 if (s->auto_comp && !s->current_tm.tm_sec && !s->current_tm.tm_min)
3712 s->tick += s->comp_reg * 1000 / 32768;
3714 qemu_mod_timer(s->clk, s->tick);
3717 static void omap_rtc_reset(struct omap_rtc_s *s)
3727 s->tick = qemu_get_clock(rt_clock);
3728 memset(&s->alarm_tm, 0, sizeof(s->alarm_tm));
3729 s->alarm_tm.tm_mday = 0x01;
3731 qemu_get_timedate(&tm, 0);
3732 s->ti = mktimegm(&tm);
3734 omap_rtc_alarm_update(s);
3738 struct omap_rtc_s *omap_rtc_init(target_phys_addr_t base,
3739 qemu_irq *irq, omap_clk clk)
3742 struct omap_rtc_s *s = (struct omap_rtc_s *)
3743 qemu_mallocz(sizeof(struct omap_rtc_s));
3747 s->clk = qemu_new_timer(rt_clock, omap_rtc_tick, s);
3751 iomemtype = cpu_register_io_memory(0, omap_rtc_readfn,
3752 omap_rtc_writefn, s);
3753 cpu_register_physical_memory(base, 0x800, iomemtype);
3758 /* Multi-channel Buffered Serial Port interfaces */
3759 struct omap_mcbsp_s {
3778 struct i2s_codec_s *codec;
3779 QEMUTimer *source_timer;
3780 QEMUTimer *sink_timer;
3783 static void omap_mcbsp_intr_update(struct omap_mcbsp_s *s)
3787 switch ((s->spcr[0] >> 4) & 3) { /* RINTM */
3789 irq = (s->spcr[0] >> 1) & 1; /* RRDY */
3792 irq = (s->spcr[0] >> 3) & 1; /* RSYNCERR */
3800 qemu_irq_pulse(s->rxirq);
3802 switch ((s->spcr[1] >> 4) & 3) { /* XINTM */
3804 irq = (s->spcr[1] >> 1) & 1; /* XRDY */
3807 irq = (s->spcr[1] >> 3) & 1; /* XSYNCERR */
3815 qemu_irq_pulse(s->txirq);
3818 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s *s)
3820 if ((s->spcr[0] >> 1) & 1) /* RRDY */
3821 s->spcr[0] |= 1 << 2; /* RFULL */
3822 s->spcr[0] |= 1 << 1; /* RRDY */
3823 qemu_irq_raise(s->rxdrq);
3824 omap_mcbsp_intr_update(s);
3827 static void omap_mcbsp_source_tick(void *opaque)
3829 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3830 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3835 printf("%s: Rx FIFO overrun\n", __FUNCTION__);
3837 s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7];
3839 omap_mcbsp_rx_newdata(s);
3840 qemu_mod_timer(s->source_timer, qemu_get_clock(vm_clock) + ticks_per_sec);
3843 static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s)
3845 if (!s->codec || !s->codec->rts)
3846 omap_mcbsp_source_tick(s);
3847 else if (s->codec->in.len) {
3848 s->rx_req = s->codec->in.len;
3849 omap_mcbsp_rx_newdata(s);
3853 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s *s)
3855 qemu_del_timer(s->source_timer);
3858 static void omap_mcbsp_rx_done(struct omap_mcbsp_s *s)
3860 s->spcr[0] &= ~(1 << 1); /* RRDY */
3861 qemu_irq_lower(s->rxdrq);
3862 omap_mcbsp_intr_update(s);
3865 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s *s)
3867 s->spcr[1] |= 1 << 1; /* XRDY */
3868 qemu_irq_raise(s->txdrq);
3869 omap_mcbsp_intr_update(s);
3872 static void omap_mcbsp_sink_tick(void *opaque)
3874 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3875 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3880 printf("%s: Tx FIFO underrun\n", __FUNCTION__);
3882 s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7];
3884 omap_mcbsp_tx_newdata(s);
3885 qemu_mod_timer(s->sink_timer, qemu_get_clock(vm_clock) + ticks_per_sec);
3888 static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s)
3890 if (!s->codec || !s->codec->cts)
3891 omap_mcbsp_sink_tick(s);
3892 else if (s->codec->out.size) {
3893 s->tx_req = s->codec->out.size;
3894 omap_mcbsp_tx_newdata(s);
3898 static void omap_mcbsp_tx_done(struct omap_mcbsp_s *s)
3900 s->spcr[1] &= ~(1 << 1); /* XRDY */
3901 qemu_irq_lower(s->txdrq);
3902 omap_mcbsp_intr_update(s);
3903 if (s->codec && s->codec->cts)
3904 s->codec->tx_swallow(s->codec->opaque);
3907 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s *s)
3910 omap_mcbsp_tx_done(s);
3911 qemu_del_timer(s->sink_timer);
3914 static void omap_mcbsp_req_update(struct omap_mcbsp_s *s)
3916 int prev_rx_rate, prev_tx_rate;
3917 int rx_rate = 0, tx_rate = 0;
3918 int cpu_rate = 1500000; /* XXX */
3920 /* TODO: check CLKSTP bit */
3921 if (s->spcr[1] & (1 << 6)) { /* GRST */
3922 if (s->spcr[0] & (1 << 0)) { /* RRST */
3923 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3924 (s->pcr & (1 << 8))) { /* CLKRM */
3925 if (~s->pcr & (1 << 7)) /* SCLKME */
3926 rx_rate = cpu_rate /
3927 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3930 rx_rate = s->codec->rx_rate;
3933 if (s->spcr[1] & (1 << 0)) { /* XRST */
3934 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
3935 (s->pcr & (1 << 9))) { /* CLKXM */
3936 if (~s->pcr & (1 << 7)) /* SCLKME */
3937 tx_rate = cpu_rate /
3938 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
3941 tx_rate = s->codec->tx_rate;
3944 prev_tx_rate = s->tx_rate;
3945 prev_rx_rate = s->rx_rate;
3946 s->tx_rate = tx_rate;
3947 s->rx_rate = rx_rate;
3950 s->codec->set_rate(s->codec->opaque, rx_rate, tx_rate);
3952 if (!prev_tx_rate && tx_rate)
3953 omap_mcbsp_tx_start(s);
3954 else if (s->tx_rate && !tx_rate)
3955 omap_mcbsp_tx_stop(s);
3957 if (!prev_rx_rate && rx_rate)
3958 omap_mcbsp_rx_start(s);
3959 else if (prev_tx_rate && !tx_rate)
3960 omap_mcbsp_rx_stop(s);
3963 static uint32_t omap_mcbsp_read(void *opaque, target_phys_addr_t addr)
3965 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3966 int offset = addr & OMAP_MPUI_REG_MASK;
3970 case 0x00: /* DRR2 */
3971 if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */
3974 case 0x02: /* DRR1 */
3975 if (s->rx_req < 2) {
3976 printf("%s: Rx FIFO underrun\n", __FUNCTION__);
3977 omap_mcbsp_rx_done(s);
3980 if (s->codec && s->codec->in.len >= 2) {
3981 ret = s->codec->in.fifo[s->codec->in.start ++] << 8;
3982 ret |= s->codec->in.fifo[s->codec->in.start ++];
3983 s->codec->in.len -= 2;
3987 omap_mcbsp_rx_done(s);
3992 case 0x04: /* DXR2 */
3993 case 0x06: /* DXR1 */
3996 case 0x08: /* SPCR2 */
3998 case 0x0a: /* SPCR1 */
4000 case 0x0c: /* RCR2 */
4002 case 0x0e: /* RCR1 */
4004 case 0x10: /* XCR2 */
4006 case 0x12: /* XCR1 */
4008 case 0x14: /* SRGR2 */
4010 case 0x16: /* SRGR1 */
4012 case 0x18: /* MCR2 */
4014 case 0x1a: /* MCR1 */
4016 case 0x1c: /* RCERA */
4018 case 0x1e: /* RCERB */
4020 case 0x20: /* XCERA */
4022 case 0x22: /* XCERB */
4024 case 0x24: /* PCR0 */
4026 case 0x26: /* RCERC */
4028 case 0x28: /* RCERD */
4030 case 0x2a: /* XCERC */
4032 case 0x2c: /* XCERD */
4034 case 0x2e: /* RCERE */
4036 case 0x30: /* RCERF */
4038 case 0x32: /* XCERE */
4040 case 0x34: /* XCERF */
4042 case 0x36: /* RCERG */
4044 case 0x38: /* RCERH */
4046 case 0x3a: /* XCERG */
4048 case 0x3c: /* XCERH */
4056 static void omap_mcbsp_writeh(void *opaque, target_phys_addr_t addr,
4059 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4060 int offset = addr & OMAP_MPUI_REG_MASK;
4063 case 0x00: /* DRR2 */
4064 case 0x02: /* DRR1 */
4068 case 0x04: /* DXR2 */
4069 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
4072 case 0x06: /* DXR1 */
4073 if (s->tx_req > 1) {
4075 if (s->codec && s->codec->cts) {
4076 s->codec->out.fifo[s->codec->out.len ++] = (value >> 8) & 0xff;
4077 s->codec->out.fifo[s->codec->out.len ++] = (value >> 0) & 0xff;
4080 omap_mcbsp_tx_done(s);
4082 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
4085 case 0x08: /* SPCR2 */
4086 s->spcr[1] &= 0x0002;
4087 s->spcr[1] |= 0x03f9 & value;
4088 s->spcr[1] |= 0x0004 & (value << 2); /* XEMPTY := XRST */
4089 if (~value & 1) /* XRST */
4091 omap_mcbsp_req_update(s);
4093 case 0x0a: /* SPCR1 */
4094 s->spcr[0] &= 0x0006;
4095 s->spcr[0] |= 0xf8f9 & value;
4096 if (value & (1 << 15)) /* DLB */
4097 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__);
4098 if (~value & 1) { /* RRST */
4101 omap_mcbsp_rx_done(s);
4103 omap_mcbsp_req_update(s);
4106 case 0x0c: /* RCR2 */
4107 s->rcr[1] = value & 0xffff;
4109 case 0x0e: /* RCR1 */
4110 s->rcr[0] = value & 0x7fe0;
4112 case 0x10: /* XCR2 */
4113 s->xcr[1] = value & 0xffff;
4115 case 0x12: /* XCR1 */
4116 s->xcr[0] = value & 0x7fe0;
4118 case 0x14: /* SRGR2 */
4119 s->srgr[1] = value & 0xffff;
4120 omap_mcbsp_req_update(s);
4122 case 0x16: /* SRGR1 */
4123 s->srgr[0] = value & 0xffff;
4124 omap_mcbsp_req_update(s);
4126 case 0x18: /* MCR2 */
4127 s->mcr[1] = value & 0x03e3;
4128 if (value & 3) /* XMCM */
4129 printf("%s: Tx channel selection mode enable attempt\n",
4132 case 0x1a: /* MCR1 */
4133 s->mcr[0] = value & 0x03e1;
4134 if (value & 1) /* RMCM */
4135 printf("%s: Rx channel selection mode enable attempt\n",
4138 case 0x1c: /* RCERA */
4139 s->rcer[0] = value & 0xffff;
4141 case 0x1e: /* RCERB */
4142 s->rcer[1] = value & 0xffff;
4144 case 0x20: /* XCERA */
4145 s->xcer[0] = value & 0xffff;
4147 case 0x22: /* XCERB */
4148 s->xcer[1] = value & 0xffff;
4150 case 0x24: /* PCR0 */
4151 s->pcr = value & 0x7faf;
4153 case 0x26: /* RCERC */
4154 s->rcer[2] = value & 0xffff;
4156 case 0x28: /* RCERD */
4157 s->rcer[3] = value & 0xffff;
4159 case 0x2a: /* XCERC */
4160 s->xcer[2] = value & 0xffff;
4162 case 0x2c: /* XCERD */
4163 s->xcer[3] = value & 0xffff;
4165 case 0x2e: /* RCERE */
4166 s->rcer[4] = value & 0xffff;
4168 case 0x30: /* RCERF */
4169 s->rcer[5] = value & 0xffff;
4171 case 0x32: /* XCERE */
4172 s->xcer[4] = value & 0xffff;
4174 case 0x34: /* XCERF */
4175 s->xcer[5] = value & 0xffff;
4177 case 0x36: /* RCERG */
4178 s->rcer[6] = value & 0xffff;
4180 case 0x38: /* RCERH */
4181 s->rcer[7] = value & 0xffff;
4183 case 0x3a: /* XCERG */
4184 s->xcer[6] = value & 0xffff;
4186 case 0x3c: /* XCERH */
4187 s->xcer[7] = value & 0xffff;
4194 static void omap_mcbsp_writew(void *opaque, target_phys_addr_t addr,
4197 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4198 int offset = addr & OMAP_MPUI_REG_MASK;
4200 if (offset == 0x04) { /* DXR */
4201 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
4203 if (s->tx_req > 3) {
4205 if (s->codec && s->codec->cts) {
4206 s->codec->out.fifo[s->codec->out.len ++] =
4207 (value >> 24) & 0xff;
4208 s->codec->out.fifo[s->codec->out.len ++] =
4209 (value >> 16) & 0xff;
4210 s->codec->out.fifo[s->codec->out.len ++] =
4211 (value >> 8) & 0xff;
4212 s->codec->out.fifo[s->codec->out.len ++] =
4213 (value >> 0) & 0xff;
4216 omap_mcbsp_tx_done(s);
4218 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
4222 omap_badwidth_write16(opaque, addr, value);
4225 static CPUReadMemoryFunc *omap_mcbsp_readfn[] = {
4226 omap_badwidth_read16,
4228 omap_badwidth_read16,
4231 static CPUWriteMemoryFunc *omap_mcbsp_writefn[] = {
4232 omap_badwidth_write16,
4237 static void omap_mcbsp_reset(struct omap_mcbsp_s *s)
4239 memset(&s->spcr, 0, sizeof(s->spcr));
4240 memset(&s->rcr, 0, sizeof(s->rcr));
4241 memset(&s->xcr, 0, sizeof(s->xcr));
4242 s->srgr[0] = 0x0001;
4243 s->srgr[1] = 0x2000;
4244 memset(&s->mcr, 0, sizeof(s->mcr));
4245 memset(&s->pcr, 0, sizeof(s->pcr));
4246 memset(&s->rcer, 0, sizeof(s->rcer));
4247 memset(&s->xcer, 0, sizeof(s->xcer));
4252 qemu_del_timer(s->source_timer);
4253 qemu_del_timer(s->sink_timer);
4256 struct omap_mcbsp_s *omap_mcbsp_init(target_phys_addr_t base,
4257 qemu_irq *irq, qemu_irq *dma, omap_clk clk)
4260 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *)
4261 qemu_mallocz(sizeof(struct omap_mcbsp_s));
4267 s->sink_timer = qemu_new_timer(vm_clock, omap_mcbsp_sink_tick, s);
4268 s->source_timer = qemu_new_timer(vm_clock, omap_mcbsp_source_tick, s);
4269 omap_mcbsp_reset(s);
4271 iomemtype = cpu_register_io_memory(0, omap_mcbsp_readfn,
4272 omap_mcbsp_writefn, s);
4273 cpu_register_physical_memory(base, 0x800, iomemtype);
4278 static void omap_mcbsp_i2s_swallow(void *opaque, int line, int level)
4280 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4283 s->rx_req = s->codec->in.len;
4284 omap_mcbsp_rx_newdata(s);
4288 static void omap_mcbsp_i2s_start(void *opaque, int line, int level)
4290 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4293 s->tx_req = s->codec->out.size;
4294 omap_mcbsp_tx_newdata(s);
4298 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, struct i2s_codec_s *slave)
4301 slave->rx_swallow = qemu_allocate_irqs(omap_mcbsp_i2s_swallow, s, 1)[0];
4302 slave->tx_start = qemu_allocate_irqs(omap_mcbsp_i2s_start, s, 1)[0];
4305 /* LED Pulse Generators */
4317 static void omap_lpg_tick(void *opaque)
4319 struct omap_lpg_s *s = opaque;
4322 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->period - s->on);
4324 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->on);
4326 s->cycle = !s->cycle;
4327 printf("%s: LED is %s\n", __FUNCTION__, s->cycle ? "on" : "off");
4330 static void omap_lpg_update(struct omap_lpg_s *s)
4332 int64_t on, period = 1, ticks = 1000;
4333 static const int per[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
4335 if (~s->control & (1 << 6)) /* LPGRES */
4337 else if (s->control & (1 << 7)) /* PERM_ON */
4340 period = muldiv64(ticks, per[s->control & 7], /* PERCTRL */
4342 on = (s->clk && s->power) ? muldiv64(ticks,
4343 per[(s->control >> 3) & 7], 256) : 0; /* ONCTRL */
4346 qemu_del_timer(s->tm);
4347 if (on == period && s->on < s->period)
4348 printf("%s: LED is on\n", __FUNCTION__);
4349 else if (on == 0 && s->on)
4350 printf("%s: LED is off\n", __FUNCTION__);
4351 else if (on && (on != s->on || period != s->period)) {
4363 static void omap_lpg_reset(struct omap_lpg_s *s)
4371 static uint32_t omap_lpg_read(void *opaque, target_phys_addr_t addr)
4373 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4374 int offset = addr & OMAP_MPUI_REG_MASK;
4377 case 0x00: /* LCR */
4380 case 0x04: /* PMR */
4388 static void omap_lpg_write(void *opaque, target_phys_addr_t addr,
4391 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4392 int offset = addr & OMAP_MPUI_REG_MASK;
4395 case 0x00: /* LCR */
4396 if (~value & (1 << 6)) /* LPGRES */
4398 s->control = value & 0xff;
4402 case 0x04: /* PMR */
4403 s->power = value & 0x01;
4413 static CPUReadMemoryFunc *omap_lpg_readfn[] = {
4415 omap_badwidth_read8,
4416 omap_badwidth_read8,
4419 static CPUWriteMemoryFunc *omap_lpg_writefn[] = {
4421 omap_badwidth_write8,
4422 omap_badwidth_write8,
4425 static void omap_lpg_clk_update(void *opaque, int line, int on)
4427 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4433 struct omap_lpg_s *omap_lpg_init(target_phys_addr_t base, omap_clk clk)
4436 struct omap_lpg_s *s = (struct omap_lpg_s *)
4437 qemu_mallocz(sizeof(struct omap_lpg_s));
4439 s->tm = qemu_new_timer(rt_clock, omap_lpg_tick, s);
4443 iomemtype = cpu_register_io_memory(0, omap_lpg_readfn,
4444 omap_lpg_writefn, s);
4445 cpu_register_physical_memory(base, 0x800, iomemtype);
4447 omap_clk_adduser(clk, qemu_allocate_irqs(omap_lpg_clk_update, s, 1)[0]);
4452 /* MPUI Peripheral Bridge configuration */
4453 static uint32_t omap_mpui_io_read(void *opaque, target_phys_addr_t addr)
4455 if (addr == OMAP_MPUI_BASE) /* CMR */
4462 static CPUReadMemoryFunc *omap_mpui_io_readfn[] = {
4463 omap_badwidth_read16,
4465 omap_badwidth_read16,
4468 static CPUWriteMemoryFunc *omap_mpui_io_writefn[] = {
4469 omap_badwidth_write16,
4470 omap_badwidth_write16,
4471 omap_badwidth_write16,
4474 static void omap_setup_mpui_io(struct omap_mpu_state_s *mpu)
4476 int iomemtype = cpu_register_io_memory(0, omap_mpui_io_readfn,
4477 omap_mpui_io_writefn, mpu);
4478 cpu_register_physical_memory(OMAP_MPUI_BASE, 0x7fff, iomemtype);
4481 /* General chip reset */
4482 static void omap1_mpu_reset(void *opaque)
4484 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4486 omap_inth_reset(mpu->ih[0]);
4487 omap_inth_reset(mpu->ih[1]);
4488 omap_dma_reset(mpu->dma);
4489 omap_mpu_timer_reset(mpu->timer[0]);
4490 omap_mpu_timer_reset(mpu->timer[1]);
4491 omap_mpu_timer_reset(mpu->timer[2]);
4492 omap_wd_timer_reset(mpu->wdt);
4493 omap_os_timer_reset(mpu->os_timer);
4494 omap_lcdc_reset(mpu->lcd);
4495 omap_ulpd_pm_reset(mpu);
4496 omap_pin_cfg_reset(mpu);
4497 omap_mpui_reset(mpu);
4498 omap_tipb_bridge_reset(mpu->private_tipb);
4499 omap_tipb_bridge_reset(mpu->public_tipb);
4500 omap_dpll_reset(&mpu->dpll[0]);
4501 omap_dpll_reset(&mpu->dpll[1]);
4502 omap_dpll_reset(&mpu->dpll[2]);
4503 omap_uart_reset(mpu->uart[0]);
4504 omap_uart_reset(mpu->uart[1]);
4505 omap_uart_reset(mpu->uart[2]);
4506 omap_mmc_reset(mpu->mmc);
4507 omap_mpuio_reset(mpu->mpuio);
4508 omap_gpio_reset(mpu->gpio);
4509 omap_uwire_reset(mpu->microwire);
4510 omap_pwl_reset(mpu);
4511 omap_pwt_reset(mpu);
4512 omap_i2c_reset(mpu->i2c[0]);
4513 omap_rtc_reset(mpu->rtc);
4514 omap_mcbsp_reset(mpu->mcbsp1);
4515 omap_mcbsp_reset(mpu->mcbsp2);
4516 omap_mcbsp_reset(mpu->mcbsp3);
4517 omap_lpg_reset(mpu->led[0]);
4518 omap_lpg_reset(mpu->led[1]);
4519 omap_clkm_reset(mpu);
4520 cpu_reset(mpu->env);
4523 static const struct omap_map_s {
4524 target_phys_addr_t phys_dsp;
4525 target_phys_addr_t phys_mpu;
4528 } omap15xx_dsp_mm[] = {
4530 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
4531 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
4532 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
4533 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
4534 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
4535 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
4536 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
4537 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
4538 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
4539 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
4540 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
4541 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
4542 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
4543 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
4544 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
4545 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
4546 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
4548 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
4553 static void omap_setup_dsp_mapping(const struct omap_map_s *map)
4557 for (; map->phys_dsp; map ++) {
4558 io = cpu_get_physical_page_desc(map->phys_mpu);
4560 cpu_register_physical_memory(map->phys_dsp, map->size, io);
4564 void omap_mpu_wakeup(void *opaque, int irq, int req)
4566 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4568 if (mpu->env->halted)
4569 cpu_interrupt(mpu->env, CPU_INTERRUPT_EXITTB);
4572 static const struct dma_irq_map omap1_dma_irq_map[] = {
4573 { 0, OMAP_INT_DMA_CH0_6 },
4574 { 0, OMAP_INT_DMA_CH1_7 },
4575 { 0, OMAP_INT_DMA_CH2_8 },
4576 { 0, OMAP_INT_DMA_CH3 },
4577 { 0, OMAP_INT_DMA_CH4 },
4578 { 0, OMAP_INT_DMA_CH5 },
4579 { 1, OMAP_INT_1610_DMA_CH6 },
4580 { 1, OMAP_INT_1610_DMA_CH7 },
4581 { 1, OMAP_INT_1610_DMA_CH8 },
4582 { 1, OMAP_INT_1610_DMA_CH9 },
4583 { 1, OMAP_INT_1610_DMA_CH10 },
4584 { 1, OMAP_INT_1610_DMA_CH11 },
4585 { 1, OMAP_INT_1610_DMA_CH12 },
4586 { 1, OMAP_INT_1610_DMA_CH13 },
4587 { 1, OMAP_INT_1610_DMA_CH14 },
4588 { 1, OMAP_INT_1610_DMA_CH15 }
4591 /* DMA ports for OMAP1 */
4592 static int omap_validate_emiff_addr(struct omap_mpu_state_s *s,
4593 target_phys_addr_t addr)
4595 return addr >= OMAP_EMIFF_BASE && addr < OMAP_EMIFF_BASE + s->sdram_size;
4598 static int omap_validate_emifs_addr(struct omap_mpu_state_s *s,
4599 target_phys_addr_t addr)
4601 return addr >= OMAP_EMIFS_BASE && addr < OMAP_EMIFF_BASE;
4604 static int omap_validate_imif_addr(struct omap_mpu_state_s *s,
4605 target_phys_addr_t addr)
4607 return addr >= OMAP_IMIF_BASE && addr < OMAP_IMIF_BASE + s->sram_size;
4610 static int omap_validate_tipb_addr(struct omap_mpu_state_s *s,
4611 target_phys_addr_t addr)
4613 return addr >= 0xfffb0000 && addr < 0xffff0000;
4616 static int omap_validate_local_addr(struct omap_mpu_state_s *s,
4617 target_phys_addr_t addr)
4619 return addr >= OMAP_LOCALBUS_BASE && addr < OMAP_LOCALBUS_BASE + 0x1000000;
4622 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s *s,
4623 target_phys_addr_t addr)
4625 return addr >= 0xe1010000 && addr < 0xe1020004;
4628 struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,
4632 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
4633 qemu_mallocz(sizeof(struct omap_mpu_state_s));
4634 ram_addr_t imif_base, emiff_base;
4636 qemu_irq dma_irqs[6];
4643 s->mpu_model = omap310;
4644 s->env = cpu_init(core);
4646 fprintf(stderr, "Unable to find CPU definition\n");
4649 s->sdram_size = sdram_size;
4650 s->sram_size = OMAP15XX_SRAM_SIZE;
4652 s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0];
4657 /* Memory-mapped stuff */
4658 cpu_register_physical_memory(OMAP_EMIFF_BASE, s->sdram_size,
4659 (emiff_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
4660 cpu_register_physical_memory(OMAP_IMIF_BASE, s->sram_size,
4661 (imif_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
4663 omap_clkm_init(0xfffece00, 0xe1008000, s);
4665 cpu_irq = arm_pic_init_cpu(s->env);
4666 s->ih[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s->irq[0],
4667 cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ],
4668 omap_findclk(s, "arminth_ck"));
4669 s->ih[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s->irq[1],
4670 s->ih[0]->pins[OMAP_INT_15XX_IH2_IRQ], NULL,
4671 omap_findclk(s, "arminth_ck"));
4673 for (i = 0; i < 6; i ++)
4675 s->irq[omap1_dma_irq_map[i].ih][omap1_dma_irq_map[i].intr];
4676 s->dma = omap_dma_init(0xfffed800, dma_irqs, s->irq[0][OMAP_INT_DMA_LCD],
4677 s, omap_findclk(s, "dma_ck"), omap_dma_3_1);
4679 s->port[emiff ].addr_valid = omap_validate_emiff_addr;
4680 s->port[emifs ].addr_valid = omap_validate_emifs_addr;
4681 s->port[imif ].addr_valid = omap_validate_imif_addr;
4682 s->port[tipb ].addr_valid = omap_validate_tipb_addr;
4683 s->port[local ].addr_valid = omap_validate_local_addr;
4684 s->port[tipb_mpui].addr_valid = omap_validate_tipb_mpui_addr;
4686 /* Register SDRAM and SRAM DMA ports for fast transfers. */
4687 soc_dma_port_add_mem_ram(s->dma,
4688 emiff_base, OMAP_EMIFF_BASE, s->sdram_size);
4689 soc_dma_port_add_mem_ram(s->dma,
4690 imif_base, OMAP_IMIF_BASE, s->sram_size);
4692 s->timer[0] = omap_mpu_timer_init(0xfffec500,
4693 s->irq[0][OMAP_INT_TIMER1],
4694 omap_findclk(s, "mputim_ck"));
4695 s->timer[1] = omap_mpu_timer_init(0xfffec600,
4696 s->irq[0][OMAP_INT_TIMER2],
4697 omap_findclk(s, "mputim_ck"));
4698 s->timer[2] = omap_mpu_timer_init(0xfffec700,
4699 s->irq[0][OMAP_INT_TIMER3],
4700 omap_findclk(s, "mputim_ck"));
4702 s->wdt = omap_wd_timer_init(0xfffec800,
4703 s->irq[0][OMAP_INT_WD_TIMER],
4704 omap_findclk(s, "armwdt_ck"));
4706 s->os_timer = omap_os_timer_init(0xfffb9000,
4707 s->irq[1][OMAP_INT_OS_TIMER],
4708 omap_findclk(s, "clk32-kHz"));
4710 s->lcd = omap_lcdc_init(0xfffec000, s->irq[0][OMAP_INT_LCD_CTRL],
4711 omap_dma_get_lcdch(s->dma), imif_base, emiff_base,
4712 omap_findclk(s, "lcd_ck"));
4714 omap_ulpd_pm_init(0xfffe0800, s);
4715 omap_pin_cfg_init(0xfffe1000, s);
4718 omap_mpui_init(0xfffec900, s);
4720 s->private_tipb = omap_tipb_bridge_init(0xfffeca00,
4721 s->irq[0][OMAP_INT_BRIDGE_PRIV],
4722 omap_findclk(s, "tipb_ck"));
4723 s->public_tipb = omap_tipb_bridge_init(0xfffed300,
4724 s->irq[0][OMAP_INT_BRIDGE_PUB],
4725 omap_findclk(s, "tipb_ck"));
4727 omap_tcmi_init(0xfffecc00, s);
4729 s->uart[0] = omap_uart_init(0xfffb0000, s->irq[1][OMAP_INT_UART1],
4730 omap_findclk(s, "uart1_ck"),
4731 omap_findclk(s, "uart1_ck"),
4732 s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
4734 s->uart[1] = omap_uart_init(0xfffb0800, s->irq[1][OMAP_INT_UART2],
4735 omap_findclk(s, "uart2_ck"),
4736 omap_findclk(s, "uart2_ck"),
4737 s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
4738 serial_hds[0] ? serial_hds[1] : 0);
4739 s->uart[2] = omap_uart_init(0xfffb9800, s->irq[0][OMAP_INT_UART3],
4740 omap_findclk(s, "uart3_ck"),
4741 omap_findclk(s, "uart3_ck"),
4742 s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX],
4743 serial_hds[0] && serial_hds[1] ? serial_hds[2] : 0);
4745 omap_dpll_init(&s->dpll[0], 0xfffecf00, omap_findclk(s, "dpll1"));
4746 omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2"));
4747 omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3"));
4749 sdindex = drive_get_index(IF_SD, 0, 0);
4750 if (sdindex == -1) {
4751 fprintf(stderr, "qemu: missing SecureDigital device\n");
4754 s->mmc = omap_mmc_init(0xfffb7800, drives_table[sdindex].bdrv,
4755 s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX],
4756 omap_findclk(s, "mmc_ck"));
4758 s->mpuio = omap_mpuio_init(0xfffb5000,
4759 s->irq[1][OMAP_INT_KEYBOARD], s->irq[1][OMAP_INT_MPUIO],
4760 s->wakeup, omap_findclk(s, "clk32-kHz"));
4762 s->gpio = omap_gpio_init(0xfffce000, s->irq[0][OMAP_INT_GPIO_BANK1],
4763 omap_findclk(s, "arm_gpio_ck"));
4765 s->microwire = omap_uwire_init(0xfffb3000, &s->irq[1][OMAP_INT_uWireTX],
4766 s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
4768 omap_pwl_init(0xfffb5800, s, omap_findclk(s, "armxor_ck"));
4769 omap_pwt_init(0xfffb6000, s, omap_findclk(s, "armxor_ck"));
4771 s->i2c[0] = omap_i2c_init(0xfffb3800, s->irq[1][OMAP_INT_I2C],
4772 &s->drq[OMAP_DMA_I2C_RX], omap_findclk(s, "mpuper_ck"));
4774 s->rtc = omap_rtc_init(0xfffb4800, &s->irq[1][OMAP_INT_RTC_TIMER],
4775 omap_findclk(s, "clk32-kHz"));
4777 s->mcbsp1 = omap_mcbsp_init(0xfffb1800, &s->irq[1][OMAP_INT_McBSP1TX],
4778 &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
4779 s->mcbsp2 = omap_mcbsp_init(0xfffb1000, &s->irq[0][OMAP_INT_310_McBSP2_TX],
4780 &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
4781 s->mcbsp3 = omap_mcbsp_init(0xfffb7000, &s->irq[1][OMAP_INT_McBSP3TX],
4782 &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
4784 s->led[0] = omap_lpg_init(0xfffbd000, omap_findclk(s, "clk32-kHz"));
4785 s->led[1] = omap_lpg_init(0xfffbd800, omap_findclk(s, "clk32-kHz"));
4787 /* Register mappings not currenlty implemented:
4788 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4789 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4790 * USB W2FC fffb4000 - fffb47ff
4791 * Camera Interface fffb6800 - fffb6fff
4792 * USB Host fffba000 - fffba7ff
4793 * FAC fffba800 - fffbafff
4794 * HDQ/1-Wire fffbc000 - fffbc7ff
4795 * TIPB switches fffbc800 - fffbcfff
4796 * Mailbox fffcf000 - fffcf7ff
4797 * Local bus IF fffec100 - fffec1ff
4798 * Local bus MMU fffec200 - fffec2ff
4799 * DSP MMU fffed200 - fffed2ff
4802 omap_setup_dsp_mapping(omap15xx_dsp_mm);
4803 omap_setup_mpui_io(s);
4805 qemu_register_reset(omap1_mpu_reset, s);