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 static void omap_inth_save_state(QEMUFile *f, void *opaque)
413 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)opaque;
416 qemu_put_be32(f, s->new_agr[0]);
417 qemu_put_be32(f, s->new_agr[1]);
418 qemu_put_sbe32(f, s->sir_intr[0]);
419 qemu_put_sbe32(f, s->sir_intr[1]);
420 qemu_put_sbe32(f, s->autoidle);
421 qemu_put_be32(f, s->mask);
422 qemu_put_byte(f, s->nbanks);
423 for (i = 0; i < s->nbanks; i++) {
424 qemu_put_be32(f, s->bank[i].irqs);
425 qemu_put_be32(f, s->bank[i].inputs);
426 qemu_put_be32(f, s->bank[i].mask);
427 qemu_put_be32(f, s->bank[i].fiq);
428 qemu_put_be32(f, s->bank[i].sens_edge);
429 qemu_put_be32(f, s->bank[i].swi);
430 for (j = 0; j < 32; j++)
431 qemu_put_byte(f, s->bank[i].priority[j]);
435 static int omap_inth_load_state(QEMUFile *f, void *opaque, int version_id)
437 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)opaque;
443 s->new_agr[0] = qemu_get_be32(f);
444 s->new_agr[1] = qemu_get_be32(f);
445 s->sir_intr[0] = qemu_get_sbe32(f);
446 s->sir_intr[1] = qemu_get_sbe32(f);
447 s->autoidle = qemu_get_sbe32(f);
448 s->mask = qemu_get_be32(f);
449 if (qemu_get_byte(f) != s->nbanks)
451 for (i = 0; i < s->nbanks; i++) {
452 s->bank[i].irqs = qemu_get_be32(f);
453 s->bank[i].inputs = qemu_get_be32(f);
454 s->bank[i].mask = qemu_get_be32(f);
455 s->bank[i].fiq = qemu_get_be32(f);
456 s->bank[i].sens_edge = qemu_get_be32(f);
457 s->bank[i].swi = qemu_get_be32(f);
458 for (j = 0; j < 32; j++)
459 s->bank[i].priority[j] = qemu_get_byte(f);
462 omap_inth_update(s, 0);
463 omap_inth_update(s, 1);
468 struct omap_intr_handler_s *omap_inth_init(target_phys_addr_t base,
469 unsigned long size, unsigned char nbanks, qemu_irq **pins,
470 qemu_irq parent_irq, qemu_irq parent_fiq, omap_clk clk)
473 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)
474 qemu_mallocz(sizeof(struct omap_intr_handler_s) +
475 sizeof(struct omap_intr_handler_bank_s) * nbanks);
477 s->parent_intr[0] = parent_irq;
478 s->parent_intr[1] = parent_fiq;
480 s->pins = qemu_allocate_irqs(omap_set_intr, s, nbanks * 32);
486 iomemtype = cpu_register_io_memory(0, omap_inth_readfn,
487 omap_inth_writefn, s);
488 cpu_register_physical_memory(base, size, iomemtype);
490 register_savevm("omap_inth", -1, 0,
491 omap_inth_save_state, omap_inth_load_state, s);
495 static uint32_t omap2_inth_read(void *opaque, target_phys_addr_t addr)
497 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
499 int bank_no, line_no;
500 struct omap_intr_handler_bank_s *bank = 0;
502 if ((offset & 0xf80) == 0x80) {
503 bank_no = (offset & 0x60) >> 5;
504 if (bank_no < s->nbanks) {
506 bank = &s->bank[bank_no];
511 case 0x00: /* INTC_REVISION */
514 case 0x10: /* INTC_SYSCONFIG */
515 return (s->autoidle >> 2) & 1;
517 case 0x14: /* INTC_SYSSTATUS */
518 return 1; /* RESETDONE */
520 case 0x40: /* INTC_SIR_IRQ */
521 return s->sir_intr[0];
523 case 0x44: /* INTC_SIR_FIQ */
524 return s->sir_intr[1];
526 case 0x48: /* INTC_CONTROL */
527 return (!s->mask) << 2; /* GLOBALMASK */
529 case 0x4c: /* INTC_PROTECTION */
532 case 0x50: /* INTC_IDLE */
533 return s->autoidle & 3;
535 /* Per-bank registers */
536 case 0x80: /* INTC_ITR */
539 case 0x84: /* INTC_MIR */
542 case 0x88: /* INTC_MIR_CLEAR */
543 case 0x8c: /* INTC_MIR_SET */
546 case 0x90: /* INTC_ISR_SET */
549 case 0x94: /* INTC_ISR_CLEAR */
552 case 0x98: /* INTC_PENDING_IRQ */
553 return bank->irqs & ~bank->mask & ~bank->fiq;
555 case 0x9c: /* INTC_PENDING_FIQ */
556 return bank->irqs & ~bank->mask & bank->fiq;
558 /* Per-line registers */
559 case 0x100 ... 0x300: /* INTC_ILR */
560 bank_no = (offset - 0x100) >> 7;
561 if (bank_no > s->nbanks)
563 bank = &s->bank[bank_no];
564 line_no = (offset & 0x7f) >> 2;
565 return (bank->priority[line_no] << 2) |
566 ((bank->fiq >> line_no) & 1);
572 static void omap2_inth_write(void *opaque, target_phys_addr_t addr,
575 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
577 int bank_no, line_no;
578 struct omap_intr_handler_bank_s *bank = 0;
580 if ((offset & 0xf80) == 0x80) {
581 bank_no = (offset & 0x60) >> 5;
582 if (bank_no < s->nbanks) {
584 bank = &s->bank[bank_no];
589 case 0x10: /* INTC_SYSCONFIG */
591 s->autoidle |= (value & 1) << 2;
592 if (value & 2) /* SOFTRESET */
596 case 0x48: /* INTC_CONTROL */
597 s->mask = (value & 4) ? 0 : ~0; /* GLOBALMASK */
598 if (value & 2) { /* NEWFIQAGR */
599 qemu_set_irq(s->parent_intr[1], 0);
601 omap_inth_update(s, 1);
603 if (value & 1) { /* NEWIRQAGR */
604 qemu_set_irq(s->parent_intr[0], 0);
606 omap_inth_update(s, 0);
610 case 0x4c: /* INTC_PROTECTION */
611 /* TODO: Make a bitmap (or sizeof(char)map) of access privileges
612 * for every register, see Chapter 3 and 4 for privileged mode. */
614 fprintf(stderr, "%s: protection mode enable attempt\n",
618 case 0x50: /* INTC_IDLE */
620 s->autoidle |= value & 3;
623 /* Per-bank registers */
624 case 0x84: /* INTC_MIR */
626 omap_inth_update(s, 0);
627 omap_inth_update(s, 1);
630 case 0x88: /* INTC_MIR_CLEAR */
631 bank->mask &= ~value;
632 omap_inth_update(s, 0);
633 omap_inth_update(s, 1);
636 case 0x8c: /* INTC_MIR_SET */
640 case 0x90: /* INTC_ISR_SET */
641 bank->irqs |= bank->swi |= value;
642 omap_inth_update(s, 0);
643 omap_inth_update(s, 1);
646 case 0x94: /* INTC_ISR_CLEAR */
648 bank->irqs = bank->swi & bank->inputs;
651 /* Per-line registers */
652 case 0x100 ... 0x300: /* INTC_ILR */
653 bank_no = (offset - 0x100) >> 7;
654 if (bank_no > s->nbanks)
656 bank = &s->bank[bank_no];
657 line_no = (offset & 0x7f) >> 2;
658 bank->priority[line_no] = (value >> 2) & 0x3f;
659 bank->fiq &= ~(1 << line_no);
660 bank->fiq |= (value & 1) << line_no;
663 case 0x00: /* INTC_REVISION */
664 case 0x14: /* INTC_SYSSTATUS */
665 case 0x40: /* INTC_SIR_IRQ */
666 case 0x44: /* INTC_SIR_FIQ */
667 case 0x80: /* INTC_ITR */
668 case 0x98: /* INTC_PENDING_IRQ */
669 case 0x9c: /* INTC_PENDING_FIQ */
676 static CPUReadMemoryFunc *omap2_inth_readfn[] = {
677 omap_badwidth_read32,
678 omap_badwidth_read32,
682 static CPUWriteMemoryFunc *omap2_inth_writefn[] = {
688 struct omap_intr_handler_s *omap2_inth_init(
689 struct omap_mpu_state_s *mpu,
690 target_phys_addr_t base,
691 int size, int nbanks, qemu_irq **pins,
692 qemu_irq parent_irq, qemu_irq parent_fiq,
693 omap_clk fclk, omap_clk iclk)
696 struct omap_intr_handler_s *s = (struct omap_intr_handler_s *)
697 qemu_mallocz(sizeof(struct omap_intr_handler_s) +
698 sizeof(struct omap_intr_handler_bank_s) * nbanks);
700 s->revision = cpu_class_omap3(mpu) ? 0x40 : 0x21;
701 s->parent_intr[0] = parent_irq;
702 s->parent_intr[1] = parent_fiq;
705 s->pins = qemu_allocate_irqs(omap_set_intr_noedge, s, nbanks * 32);
711 iomemtype = cpu_register_io_memory(0, omap2_inth_readfn,
712 omap2_inth_writefn, s);
713 cpu_register_physical_memory(base, size, iomemtype);
715 register_savevm("omap_inth", -1, 0,
716 omap_inth_save_state, omap_inth_load_state, s);
721 struct omap_mpu_timer_s {
738 static inline uint32_t omap_timer_read(struct omap_mpu_timer_s *timer)
740 uint64_t distance = qemu_get_clock(vm_clock) - timer->time;
742 if (timer->st && timer->enable && timer->rate)
743 return timer->val - muldiv64(distance >> (timer->ptv + 1),
744 timer->rate, ticks_per_sec);
749 static inline void omap_timer_sync(struct omap_mpu_timer_s *timer)
751 timer->val = omap_timer_read(timer);
752 timer->time = qemu_get_clock(vm_clock);
755 static inline void omap_timer_update(struct omap_mpu_timer_s *timer)
759 if (timer->enable && timer->st && timer->rate) {
760 timer->val = timer->reset_val; /* Should skip this on clk enable */
761 expires = muldiv64((uint64_t) timer->val << (timer->ptv + 1),
762 ticks_per_sec, timer->rate);
764 /* If timer expiry would be sooner than in about 1 ms and
765 * auto-reload isn't set, then fire immediately. This is a hack
766 * to make systems like PalmOS run in acceptable time. PalmOS
767 * sets the interval to a very low value and polls the status bit
768 * in a busy loop when it wants to sleep just a couple of CPU
770 if (expires > (ticks_per_sec >> 10) || timer->ar)
771 qemu_mod_timer(timer->timer, timer->time + expires);
773 qemu_bh_schedule(timer->tick);
775 qemu_del_timer(timer->timer);
778 static void omap_timer_fire(void *opaque)
780 struct omap_mpu_timer_s *timer = opaque;
788 /* Edge-triggered irq */
789 qemu_irq_pulse(timer->irq);
792 static void omap_timer_tick(void *opaque)
794 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
796 omap_timer_sync(timer);
797 omap_timer_fire(timer);
798 omap_timer_update(timer);
801 static void omap_timer_clk_update(void *opaque, int line, int on)
803 struct omap_mpu_timer_s *timer = (struct omap_mpu_timer_s *) opaque;
805 omap_timer_sync(timer);
806 timer->rate = on ? omap_clk_getrate(timer->clk) : 0;
807 omap_timer_update(timer);
810 static void omap_timer_clk_setup(struct omap_mpu_timer_s *timer)
812 omap_clk_adduser(timer->clk,
813 qemu_allocate_irqs(omap_timer_clk_update, timer, 1)[0]);
814 timer->rate = omap_clk_getrate(timer->clk);
817 static uint32_t omap_mpu_timer_read(void *opaque, target_phys_addr_t addr)
819 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
822 case 0x00: /* CNTL_TIMER */
823 return (s->enable << 5) | (s->ptv << 2) | (s->ar << 1) | s->st;
825 case 0x04: /* LOAD_TIM */
828 case 0x08: /* READ_TIM */
829 return omap_timer_read(s);
836 static void omap_mpu_timer_write(void *opaque, target_phys_addr_t addr,
839 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) opaque;
842 case 0x00: /* CNTL_TIMER */
844 s->enable = (value >> 5) & 1;
845 s->ptv = (value >> 2) & 7;
846 s->ar = (value >> 1) & 1;
848 omap_timer_update(s);
851 case 0x04: /* LOAD_TIM */
852 s->reset_val = value;
855 case 0x08: /* READ_TIM */
864 static CPUReadMemoryFunc *omap_mpu_timer_readfn[] = {
865 omap_badwidth_read32,
866 omap_badwidth_read32,
870 static CPUWriteMemoryFunc *omap_mpu_timer_writefn[] = {
871 omap_badwidth_write32,
872 omap_badwidth_write32,
873 omap_mpu_timer_write,
876 static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s)
878 qemu_del_timer(s->timer);
880 s->reset_val = 31337;
888 struct omap_mpu_timer_s *omap_mpu_timer_init(target_phys_addr_t base,
889 qemu_irq irq, omap_clk clk)
892 struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *)
893 qemu_mallocz(sizeof(struct omap_mpu_timer_s));
897 s->timer = qemu_new_timer(vm_clock, omap_timer_tick, s);
898 s->tick = qemu_bh_new(omap_timer_fire, s);
899 omap_mpu_timer_reset(s);
900 omap_timer_clk_setup(s);
902 iomemtype = cpu_register_io_memory(0, omap_mpu_timer_readfn,
903 omap_mpu_timer_writefn, s);
904 cpu_register_physical_memory(base, 0x100, iomemtype);
910 struct omap_watchdog_timer_s {
911 struct omap_mpu_timer_s timer;
918 static uint32_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr)
920 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
923 case 0x00: /* CNTL_TIMER */
924 return (s->timer.ptv << 9) | (s->timer.ar << 8) |
925 (s->timer.st << 7) | (s->free << 1);
927 case 0x04: /* READ_TIMER */
928 return omap_timer_read(&s->timer);
930 case 0x08: /* TIMER_MODE */
931 return s->mode << 15;
938 static void omap_wd_timer_write(void *opaque, target_phys_addr_t addr,
941 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque;
944 case 0x00: /* CNTL_TIMER */
945 omap_timer_sync(&s->timer);
946 s->timer.ptv = (value >> 9) & 7;
947 s->timer.ar = (value >> 8) & 1;
948 s->timer.st = (value >> 7) & 1;
949 s->free = (value >> 1) & 1;
950 omap_timer_update(&s->timer);
953 case 0x04: /* LOAD_TIMER */
954 s->timer.reset_val = value & 0xffff;
957 case 0x08: /* TIMER_MODE */
958 if (!s->mode && ((value >> 15) & 1))
959 omap_clk_get(s->timer.clk);
960 s->mode |= (value >> 15) & 1;
961 if (s->last_wr == 0xf5) {
962 if ((value & 0xff) == 0xa0) {
965 omap_clk_put(s->timer.clk);
968 /* XXX: on T|E hardware somehow this has no effect,
969 * on Zire 71 it works as specified. */
971 qemu_system_reset_request();
974 s->last_wr = value & 0xff;
982 static CPUReadMemoryFunc *omap_wd_timer_readfn[] = {
983 omap_badwidth_read16,
985 omap_badwidth_read16,
988 static CPUWriteMemoryFunc *omap_wd_timer_writefn[] = {
989 omap_badwidth_write16,
991 omap_badwidth_write16,
994 static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s)
996 qemu_del_timer(s->timer.timer);
998 omap_clk_get(s->timer.clk);
1002 s->timer.enable = 1;
1003 s->timer.it_ena = 1;
1004 s->timer.reset_val = 0xffff;
1009 omap_timer_update(&s->timer);
1012 struct omap_watchdog_timer_s *omap_wd_timer_init(target_phys_addr_t base,
1013 qemu_irq irq, omap_clk clk)
1016 struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *)
1017 qemu_mallocz(sizeof(struct omap_watchdog_timer_s));
1021 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
1022 omap_wd_timer_reset(s);
1023 omap_timer_clk_setup(&s->timer);
1025 iomemtype = cpu_register_io_memory(0, omap_wd_timer_readfn,
1026 omap_wd_timer_writefn, s);
1027 cpu_register_physical_memory(base, 0x100, iomemtype);
1033 struct omap_32khz_timer_s {
1034 struct omap_mpu_timer_s timer;
1037 static uint32_t omap_os_timer_read(void *opaque, target_phys_addr_t addr)
1039 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
1040 int offset = addr & OMAP_MPUI_REG_MASK;
1043 case 0x00: /* TVR */
1044 return s->timer.reset_val;
1046 case 0x04: /* TCR */
1047 return omap_timer_read(&s->timer);
1050 return (s->timer.ar << 3) | (s->timer.it_ena << 2) | s->timer.st;
1059 static void omap_os_timer_write(void *opaque, target_phys_addr_t addr,
1062 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
1063 int offset = addr & OMAP_MPUI_REG_MASK;
1066 case 0x00: /* TVR */
1067 s->timer.reset_val = value & 0x00ffffff;
1070 case 0x04: /* TCR */
1075 s->timer.ar = (value >> 3) & 1;
1076 s->timer.it_ena = (value >> 2) & 1;
1077 if (s->timer.st != (value & 1) || (value & 2)) {
1078 omap_timer_sync(&s->timer);
1079 s->timer.enable = value & 1;
1080 s->timer.st = value & 1;
1081 omap_timer_update(&s->timer);
1090 static CPUReadMemoryFunc *omap_os_timer_readfn[] = {
1091 omap_badwidth_read32,
1092 omap_badwidth_read32,
1096 static CPUWriteMemoryFunc *omap_os_timer_writefn[] = {
1097 omap_badwidth_write32,
1098 omap_badwidth_write32,
1099 omap_os_timer_write,
1102 static void omap_os_timer_reset(struct omap_32khz_timer_s *s)
1104 qemu_del_timer(s->timer.timer);
1105 s->timer.enable = 0;
1106 s->timer.it_ena = 0;
1107 s->timer.reset_val = 0x00ffffff;
1114 struct omap_32khz_timer_s *omap_os_timer_init(target_phys_addr_t base,
1115 qemu_irq irq, omap_clk clk)
1118 struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *)
1119 qemu_mallocz(sizeof(struct omap_32khz_timer_s));
1123 s->timer.timer = qemu_new_timer(vm_clock, omap_timer_tick, &s->timer);
1124 omap_os_timer_reset(s);
1125 omap_timer_clk_setup(&s->timer);
1127 iomemtype = cpu_register_io_memory(0, omap_os_timer_readfn,
1128 omap_os_timer_writefn, s);
1129 cpu_register_physical_memory(base, 0x800, iomemtype);
1134 /* Ultra Low-Power Device Module */
1135 static uint32_t omap_ulpd_pm_read(void *opaque, target_phys_addr_t addr)
1137 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1141 case 0x14: /* IT_STATUS */
1142 ret = s->ulpd_pm_regs[addr >> 2];
1143 s->ulpd_pm_regs[addr >> 2] = 0;
1144 qemu_irq_lower(s->irq[1][OMAP_INT_GAUGE_32K]);
1147 case 0x18: /* Reserved */
1148 case 0x1c: /* Reserved */
1149 case 0x20: /* Reserved */
1150 case 0x28: /* Reserved */
1151 case 0x2c: /* Reserved */
1153 case 0x00: /* COUNTER_32_LSB */
1154 case 0x04: /* COUNTER_32_MSB */
1155 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1156 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1157 case 0x10: /* GAUGING_CTRL */
1158 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1159 case 0x30: /* CLOCK_CTRL */
1160 case 0x34: /* SOFT_REQ */
1161 case 0x38: /* COUNTER_32_FIQ */
1162 case 0x3c: /* DPLL_CTRL */
1163 case 0x40: /* STATUS_REQ */
1164 /* XXX: check clk::usecount state for every clock */
1165 case 0x48: /* LOCL_TIME */
1166 case 0x4c: /* APLL_CTRL */
1167 case 0x50: /* POWER_CTRL */
1168 return s->ulpd_pm_regs[addr >> 2];
1175 static inline void omap_ulpd_clk_update(struct omap_mpu_state_s *s,
1176 uint16_t diff, uint16_t value)
1178 if (diff & (1 << 4)) /* USB_MCLK_EN */
1179 omap_clk_onoff(omap_findclk(s, "usb_clk0"), (value >> 4) & 1);
1180 if (diff & (1 << 5)) /* DIS_USB_PVCI_CLK */
1181 omap_clk_onoff(omap_findclk(s, "usb_w2fc_ck"), (~value >> 5) & 1);
1184 static inline void omap_ulpd_req_update(struct omap_mpu_state_s *s,
1185 uint16_t diff, uint16_t value)
1187 if (diff & (1 << 0)) /* SOFT_DPLL_REQ */
1188 omap_clk_canidle(omap_findclk(s, "dpll4"), (~value >> 0) & 1);
1189 if (diff & (1 << 1)) /* SOFT_COM_REQ */
1190 omap_clk_canidle(omap_findclk(s, "com_mclk_out"), (~value >> 1) & 1);
1191 if (diff & (1 << 2)) /* SOFT_SDW_REQ */
1192 omap_clk_canidle(omap_findclk(s, "bt_mclk_out"), (~value >> 2) & 1);
1193 if (diff & (1 << 3)) /* SOFT_USB_REQ */
1194 omap_clk_canidle(omap_findclk(s, "usb_clk0"), (~value >> 3) & 1);
1197 static void omap_ulpd_pm_write(void *opaque, target_phys_addr_t addr,
1200 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1203 static const int bypass_div[4] = { 1, 2, 4, 4 };
1207 case 0x00: /* COUNTER_32_LSB */
1208 case 0x04: /* COUNTER_32_MSB */
1209 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
1210 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
1211 case 0x14: /* IT_STATUS */
1212 case 0x40: /* STATUS_REQ */
1216 case 0x10: /* GAUGING_CTRL */
1217 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
1218 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
1219 now = qemu_get_clock(vm_clock);
1222 s->ulpd_gauge_start = now;
1224 now -= s->ulpd_gauge_start;
1227 ticks = muldiv64(now, 32768, ticks_per_sec);
1228 s->ulpd_pm_regs[0x00 >> 2] = (ticks >> 0) & 0xffff;
1229 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0xffff;
1230 if (ticks >> 32) /* OVERFLOW_32K */
1231 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
1233 /* High frequency ticks */
1234 ticks = muldiv64(now, 12000000, ticks_per_sec);
1235 s->ulpd_pm_regs[0x08 >> 2] = (ticks >> 0) & 0xffff;
1236 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0xffff;
1237 if (ticks >> 32) /* OVERFLOW_HI_FREQ */
1238 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
1240 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0; /* IT_GAUGING */
1241 qemu_irq_raise(s->irq[1][OMAP_INT_GAUGE_32K]);
1244 s->ulpd_pm_regs[addr >> 2] = value;
1247 case 0x18: /* Reserved */
1248 case 0x1c: /* Reserved */
1249 case 0x20: /* Reserved */
1250 case 0x28: /* Reserved */
1251 case 0x2c: /* Reserved */
1253 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
1254 case 0x38: /* COUNTER_32_FIQ */
1255 case 0x48: /* LOCL_TIME */
1256 case 0x50: /* POWER_CTRL */
1257 s->ulpd_pm_regs[addr >> 2] = value;
1260 case 0x30: /* CLOCK_CTRL */
1261 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
1262 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
1263 omap_ulpd_clk_update(s, diff, value);
1266 case 0x34: /* SOFT_REQ */
1267 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
1268 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
1269 omap_ulpd_req_update(s, diff, value);
1272 case 0x3c: /* DPLL_CTRL */
1273 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
1274 * omitted altogether, probably a typo. */
1275 /* This register has identical semantics with DPLL(1:3) control
1276 * registers, see omap_dpll_write() */
1277 diff = s->ulpd_pm_regs[addr >> 2] & value;
1278 s->ulpd_pm_regs[addr >> 2] = value & 0x2fff;
1279 if (diff & (0x3ff << 2)) {
1280 if (value & (1 << 4)) { /* PLL_ENABLE */
1281 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1282 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1284 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1287 omap_clk_setrate(omap_findclk(s, "dpll4"), div, mult);
1290 /* Enter the desired mode. */
1291 s->ulpd_pm_regs[addr >> 2] =
1292 (s->ulpd_pm_regs[addr >> 2] & 0xfffe) |
1293 ((s->ulpd_pm_regs[addr >> 2] >> 4) & 1);
1295 /* Act as if the lock is restored. */
1296 s->ulpd_pm_regs[addr >> 2] |= 2;
1299 case 0x4c: /* APLL_CTRL */
1300 diff = s->ulpd_pm_regs[addr >> 2] & value;
1301 s->ulpd_pm_regs[addr >> 2] = value & 0xf;
1302 if (diff & (1 << 0)) /* APLL_NDPLL_SWITCH */
1303 omap_clk_reparent(omap_findclk(s, "ck_48m"), omap_findclk(s,
1304 (value & (1 << 0)) ? "apll" : "dpll4"));
1312 static CPUReadMemoryFunc *omap_ulpd_pm_readfn[] = {
1313 omap_badwidth_read16,
1315 omap_badwidth_read16,
1318 static CPUWriteMemoryFunc *omap_ulpd_pm_writefn[] = {
1319 omap_badwidth_write16,
1321 omap_badwidth_write16,
1324 static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu)
1326 mpu->ulpd_pm_regs[0x00 >> 2] = 0x0001;
1327 mpu->ulpd_pm_regs[0x04 >> 2] = 0x0000;
1328 mpu->ulpd_pm_regs[0x08 >> 2] = 0x0001;
1329 mpu->ulpd_pm_regs[0x0c >> 2] = 0x0000;
1330 mpu->ulpd_pm_regs[0x10 >> 2] = 0x0000;
1331 mpu->ulpd_pm_regs[0x18 >> 2] = 0x01;
1332 mpu->ulpd_pm_regs[0x1c >> 2] = 0x01;
1333 mpu->ulpd_pm_regs[0x20 >> 2] = 0x01;
1334 mpu->ulpd_pm_regs[0x24 >> 2] = 0x03ff;
1335 mpu->ulpd_pm_regs[0x28 >> 2] = 0x01;
1336 mpu->ulpd_pm_regs[0x2c >> 2] = 0x01;
1337 omap_ulpd_clk_update(mpu, mpu->ulpd_pm_regs[0x30 >> 2], 0x0000);
1338 mpu->ulpd_pm_regs[0x30 >> 2] = 0x0000;
1339 omap_ulpd_req_update(mpu, mpu->ulpd_pm_regs[0x34 >> 2], 0x0000);
1340 mpu->ulpd_pm_regs[0x34 >> 2] = 0x0000;
1341 mpu->ulpd_pm_regs[0x38 >> 2] = 0x0001;
1342 mpu->ulpd_pm_regs[0x3c >> 2] = 0x2211;
1343 mpu->ulpd_pm_regs[0x40 >> 2] = 0x0000; /* FIXME: dump a real STATUS_REQ */
1344 mpu->ulpd_pm_regs[0x48 >> 2] = 0x960;
1345 mpu->ulpd_pm_regs[0x4c >> 2] = 0x08;
1346 mpu->ulpd_pm_regs[0x50 >> 2] = 0x08;
1347 omap_clk_setrate(omap_findclk(mpu, "dpll4"), 1, 4);
1348 omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4"));
1351 static void omap_ulpd_pm_init(target_phys_addr_t base,
1352 struct omap_mpu_state_s *mpu)
1354 int iomemtype = cpu_register_io_memory(0, omap_ulpd_pm_readfn,
1355 omap_ulpd_pm_writefn, mpu);
1357 cpu_register_physical_memory(base, 0x800, iomemtype);
1358 omap_ulpd_pm_reset(mpu);
1361 /* OMAP Pin Configuration */
1362 static uint32_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr)
1364 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1367 case 0x00: /* FUNC_MUX_CTRL_0 */
1368 case 0x04: /* FUNC_MUX_CTRL_1 */
1369 case 0x08: /* FUNC_MUX_CTRL_2 */
1370 return s->func_mux_ctrl[addr >> 2];
1372 case 0x0c: /* COMP_MODE_CTRL_0 */
1373 return s->comp_mode_ctrl[0];
1375 case 0x10: /* FUNC_MUX_CTRL_3 */
1376 case 0x14: /* FUNC_MUX_CTRL_4 */
1377 case 0x18: /* FUNC_MUX_CTRL_5 */
1378 case 0x1c: /* FUNC_MUX_CTRL_6 */
1379 case 0x20: /* FUNC_MUX_CTRL_7 */
1380 case 0x24: /* FUNC_MUX_CTRL_8 */
1381 case 0x28: /* FUNC_MUX_CTRL_9 */
1382 case 0x2c: /* FUNC_MUX_CTRL_A */
1383 case 0x30: /* FUNC_MUX_CTRL_B */
1384 case 0x34: /* FUNC_MUX_CTRL_C */
1385 case 0x38: /* FUNC_MUX_CTRL_D */
1386 return s->func_mux_ctrl[(addr >> 2) - 1];
1388 case 0x40: /* PULL_DWN_CTRL_0 */
1389 case 0x44: /* PULL_DWN_CTRL_1 */
1390 case 0x48: /* PULL_DWN_CTRL_2 */
1391 case 0x4c: /* PULL_DWN_CTRL_3 */
1392 return s->pull_dwn_ctrl[(addr & 0xf) >> 2];
1394 case 0x50: /* GATE_INH_CTRL_0 */
1395 return s->gate_inh_ctrl[0];
1397 case 0x60: /* VOLTAGE_CTRL_0 */
1398 return s->voltage_ctrl[0];
1400 case 0x70: /* TEST_DBG_CTRL_0 */
1401 return s->test_dbg_ctrl[0];
1403 case 0x80: /* MOD_CONF_CTRL_0 */
1404 return s->mod_conf_ctrl[0];
1411 static inline void omap_pin_funcmux0_update(struct omap_mpu_state_s *s,
1412 uint32_t diff, uint32_t value)
1414 if (s->compat1509) {
1415 if (diff & (1 << 9)) /* BLUETOOTH */
1416 omap_clk_onoff(omap_findclk(s, "bt_mclk_out"),
1418 if (diff & (1 << 7)) /* USB.CLKO */
1419 omap_clk_onoff(omap_findclk(s, "usb.clko"),
1424 static inline void omap_pin_funcmux1_update(struct omap_mpu_state_s *s,
1425 uint32_t diff, uint32_t value)
1427 if (s->compat1509) {
1428 if (diff & (1 << 31)) /* MCBSP3_CLK_HIZ_DI */
1429 omap_clk_onoff(omap_findclk(s, "mcbsp3.clkx"),
1431 if (diff & (1 << 1)) /* CLK32K */
1432 omap_clk_onoff(omap_findclk(s, "clk32k_out"),
1437 static inline void omap_pin_modconf1_update(struct omap_mpu_state_s *s,
1438 uint32_t diff, uint32_t value)
1440 if (diff & (1 << 31)) /* CONF_MOD_UART3_CLK_MODE_R */
1441 omap_clk_reparent(omap_findclk(s, "uart3_ck"),
1442 omap_findclk(s, ((value >> 31) & 1) ?
1443 "ck_48m" : "armper_ck"));
1444 if (diff & (1 << 30)) /* CONF_MOD_UART2_CLK_MODE_R */
1445 omap_clk_reparent(omap_findclk(s, "uart2_ck"),
1446 omap_findclk(s, ((value >> 30) & 1) ?
1447 "ck_48m" : "armper_ck"));
1448 if (diff & (1 << 29)) /* CONF_MOD_UART1_CLK_MODE_R */
1449 omap_clk_reparent(omap_findclk(s, "uart1_ck"),
1450 omap_findclk(s, ((value >> 29) & 1) ?
1451 "ck_48m" : "armper_ck"));
1452 if (diff & (1 << 23)) /* CONF_MOD_MMC_SD_CLK_REQ_R */
1453 omap_clk_reparent(omap_findclk(s, "mmc_ck"),
1454 omap_findclk(s, ((value >> 23) & 1) ?
1455 "ck_48m" : "armper_ck"));
1456 if (diff & (1 << 12)) /* CONF_MOD_COM_MCLK_12_48_S */
1457 omap_clk_reparent(omap_findclk(s, "com_mclk_out"),
1458 omap_findclk(s, ((value >> 12) & 1) ?
1459 "ck_48m" : "armper_ck"));
1460 if (diff & (1 << 9)) /* CONF_MOD_USB_HOST_HHC_UHO */
1461 omap_clk_onoff(omap_findclk(s, "usb_hhc_ck"), (value >> 9) & 1);
1464 static void omap_pin_cfg_write(void *opaque, target_phys_addr_t addr,
1467 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1471 case 0x00: /* FUNC_MUX_CTRL_0 */
1472 diff = s->func_mux_ctrl[addr >> 2] ^ value;
1473 s->func_mux_ctrl[addr >> 2] = value;
1474 omap_pin_funcmux0_update(s, diff, value);
1477 case 0x04: /* FUNC_MUX_CTRL_1 */
1478 diff = s->func_mux_ctrl[addr >> 2] ^ value;
1479 s->func_mux_ctrl[addr >> 2] = value;
1480 omap_pin_funcmux1_update(s, diff, value);
1483 case 0x08: /* FUNC_MUX_CTRL_2 */
1484 s->func_mux_ctrl[addr >> 2] = value;
1487 case 0x0c: /* COMP_MODE_CTRL_0 */
1488 s->comp_mode_ctrl[0] = value;
1489 s->compat1509 = (value != 0x0000eaef);
1490 omap_pin_funcmux0_update(s, ~0, s->func_mux_ctrl[0]);
1491 omap_pin_funcmux1_update(s, ~0, s->func_mux_ctrl[1]);
1494 case 0x10: /* FUNC_MUX_CTRL_3 */
1495 case 0x14: /* FUNC_MUX_CTRL_4 */
1496 case 0x18: /* FUNC_MUX_CTRL_5 */
1497 case 0x1c: /* FUNC_MUX_CTRL_6 */
1498 case 0x20: /* FUNC_MUX_CTRL_7 */
1499 case 0x24: /* FUNC_MUX_CTRL_8 */
1500 case 0x28: /* FUNC_MUX_CTRL_9 */
1501 case 0x2c: /* FUNC_MUX_CTRL_A */
1502 case 0x30: /* FUNC_MUX_CTRL_B */
1503 case 0x34: /* FUNC_MUX_CTRL_C */
1504 case 0x38: /* FUNC_MUX_CTRL_D */
1505 s->func_mux_ctrl[(addr >> 2) - 1] = value;
1508 case 0x40: /* PULL_DWN_CTRL_0 */
1509 case 0x44: /* PULL_DWN_CTRL_1 */
1510 case 0x48: /* PULL_DWN_CTRL_2 */
1511 case 0x4c: /* PULL_DWN_CTRL_3 */
1512 s->pull_dwn_ctrl[(addr & 0xf) >> 2] = value;
1515 case 0x50: /* GATE_INH_CTRL_0 */
1516 s->gate_inh_ctrl[0] = value;
1519 case 0x60: /* VOLTAGE_CTRL_0 */
1520 s->voltage_ctrl[0] = value;
1523 case 0x70: /* TEST_DBG_CTRL_0 */
1524 s->test_dbg_ctrl[0] = value;
1527 case 0x80: /* MOD_CONF_CTRL_0 */
1528 diff = s->mod_conf_ctrl[0] ^ value;
1529 s->mod_conf_ctrl[0] = value;
1530 omap_pin_modconf1_update(s, diff, value);
1538 static CPUReadMemoryFunc *omap_pin_cfg_readfn[] = {
1539 omap_badwidth_read32,
1540 omap_badwidth_read32,
1544 static CPUWriteMemoryFunc *omap_pin_cfg_writefn[] = {
1545 omap_badwidth_write32,
1546 omap_badwidth_write32,
1550 static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu)
1552 /* Start in Compatibility Mode. */
1553 mpu->compat1509 = 1;
1554 omap_pin_funcmux0_update(mpu, mpu->func_mux_ctrl[0], 0);
1555 omap_pin_funcmux1_update(mpu, mpu->func_mux_ctrl[1], 0);
1556 omap_pin_modconf1_update(mpu, mpu->mod_conf_ctrl[0], 0);
1557 memset(mpu->func_mux_ctrl, 0, sizeof(mpu->func_mux_ctrl));
1558 memset(mpu->comp_mode_ctrl, 0, sizeof(mpu->comp_mode_ctrl));
1559 memset(mpu->pull_dwn_ctrl, 0, sizeof(mpu->pull_dwn_ctrl));
1560 memset(mpu->gate_inh_ctrl, 0, sizeof(mpu->gate_inh_ctrl));
1561 memset(mpu->voltage_ctrl, 0, sizeof(mpu->voltage_ctrl));
1562 memset(mpu->test_dbg_ctrl, 0, sizeof(mpu->test_dbg_ctrl));
1563 memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl));
1566 static void omap_pin_cfg_init(target_phys_addr_t base,
1567 struct omap_mpu_state_s *mpu)
1569 int iomemtype = cpu_register_io_memory(0, omap_pin_cfg_readfn,
1570 omap_pin_cfg_writefn, mpu);
1572 cpu_register_physical_memory(base, 0x800, iomemtype);
1573 omap_pin_cfg_reset(mpu);
1576 /* Device Identification, Die Identification */
1577 static uint32_t omap_id_read(void *opaque, target_phys_addr_t addr)
1579 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1582 case 0xfffe1800: /* DIE_ID_LSB */
1584 case 0xfffe1804: /* DIE_ID_MSB */
1587 case 0xfffe2000: /* PRODUCT_ID_LSB */
1589 case 0xfffe2004: /* PRODUCT_ID_MSB */
1592 case 0xfffed400: /* JTAG_ID_LSB */
1593 switch (s->mpu_model) {
1599 cpu_abort(cpu_single_env, "%s: bad mpu model\n", __FUNCTION__);
1603 case 0xfffed404: /* JTAG_ID_MSB */
1604 switch (s->mpu_model) {
1610 cpu_abort(cpu_single_env, "%s: bad mpu model\n", __FUNCTION__);
1619 static void omap_id_write(void *opaque, target_phys_addr_t addr,
1625 static CPUReadMemoryFunc *omap_id_readfn[] = {
1626 omap_badwidth_read32,
1627 omap_badwidth_read32,
1631 static CPUWriteMemoryFunc *omap_id_writefn[] = {
1632 omap_badwidth_write32,
1633 omap_badwidth_write32,
1637 static void omap_id_init(struct omap_mpu_state_s *mpu)
1639 int iomemtype = cpu_register_io_memory(0, omap_id_readfn,
1640 omap_id_writefn, mpu);
1641 cpu_register_physical_memory_offset(0xfffe1800, 0x800, iomemtype, 0xfffe1800);
1642 cpu_register_physical_memory_offset(0xfffed400, 0x100, iomemtype, 0xfffed400);
1643 if (!cpu_is_omap15xx(mpu))
1644 cpu_register_physical_memory_offset(0xfffe2000, 0x800, iomemtype, 0xfffe2000);
1647 /* MPUI Control (Dummy) */
1648 static uint32_t omap_mpui_read(void *opaque, target_phys_addr_t addr)
1650 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1653 case 0x00: /* CTRL */
1654 return s->mpui_ctrl;
1655 case 0x04: /* DEBUG_ADDR */
1657 case 0x08: /* DEBUG_DATA */
1659 case 0x0c: /* DEBUG_FLAG */
1661 case 0x10: /* STATUS */
1664 /* Not in OMAP310 */
1665 case 0x14: /* DSP_STATUS */
1666 case 0x18: /* DSP_BOOT_CONFIG */
1668 case 0x1c: /* DSP_MPUI_CONFIG */
1676 static void omap_mpui_write(void *opaque, target_phys_addr_t addr,
1679 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1682 case 0x00: /* CTRL */
1683 s->mpui_ctrl = value & 0x007fffff;
1686 case 0x04: /* DEBUG_ADDR */
1687 case 0x08: /* DEBUG_DATA */
1688 case 0x0c: /* DEBUG_FLAG */
1689 case 0x10: /* STATUS */
1690 /* Not in OMAP310 */
1691 case 0x14: /* DSP_STATUS */
1693 case 0x18: /* DSP_BOOT_CONFIG */
1694 case 0x1c: /* DSP_MPUI_CONFIG */
1702 static CPUReadMemoryFunc *omap_mpui_readfn[] = {
1703 omap_badwidth_read32,
1704 omap_badwidth_read32,
1708 static CPUWriteMemoryFunc *omap_mpui_writefn[] = {
1709 omap_badwidth_write32,
1710 omap_badwidth_write32,
1714 static void omap_mpui_reset(struct omap_mpu_state_s *s)
1716 s->mpui_ctrl = 0x0003ff1b;
1719 static void omap_mpui_init(target_phys_addr_t base,
1720 struct omap_mpu_state_s *mpu)
1722 int iomemtype = cpu_register_io_memory(0, omap_mpui_readfn,
1723 omap_mpui_writefn, mpu);
1725 cpu_register_physical_memory(base, 0x100, iomemtype);
1727 omap_mpui_reset(mpu);
1731 struct omap_tipb_bridge_s {
1738 uint16_t enh_control;
1741 static uint32_t omap_tipb_bridge_read(void *opaque, target_phys_addr_t addr)
1743 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1746 case 0x00: /* TIPB_CNTL */
1748 case 0x04: /* TIPB_BUS_ALLOC */
1750 case 0x08: /* MPU_TIPB_CNTL */
1752 case 0x0c: /* ENHANCED_TIPB_CNTL */
1753 return s->enh_control;
1754 case 0x10: /* ADDRESS_DBG */
1755 case 0x14: /* DATA_DEBUG_LOW */
1756 case 0x18: /* DATA_DEBUG_HIGH */
1758 case 0x1c: /* DEBUG_CNTR_SIG */
1766 static void omap_tipb_bridge_write(void *opaque, target_phys_addr_t addr,
1769 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) opaque;
1772 case 0x00: /* TIPB_CNTL */
1773 s->control = value & 0xffff;
1776 case 0x04: /* TIPB_BUS_ALLOC */
1777 s->alloc = value & 0x003f;
1780 case 0x08: /* MPU_TIPB_CNTL */
1781 s->buffer = value & 0x0003;
1784 case 0x0c: /* ENHANCED_TIPB_CNTL */
1785 s->width_intr = !(value & 2);
1786 s->enh_control = value & 0x000f;
1789 case 0x10: /* ADDRESS_DBG */
1790 case 0x14: /* DATA_DEBUG_LOW */
1791 case 0x18: /* DATA_DEBUG_HIGH */
1792 case 0x1c: /* DEBUG_CNTR_SIG */
1801 static CPUReadMemoryFunc *omap_tipb_bridge_readfn[] = {
1802 omap_badwidth_read16,
1803 omap_tipb_bridge_read,
1804 omap_tipb_bridge_read,
1807 static CPUWriteMemoryFunc *omap_tipb_bridge_writefn[] = {
1808 omap_badwidth_write16,
1809 omap_tipb_bridge_write,
1810 omap_tipb_bridge_write,
1813 static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s)
1815 s->control = 0xffff;
1818 s->enh_control = 0x000f;
1821 struct omap_tipb_bridge_s *omap_tipb_bridge_init(target_phys_addr_t base,
1822 qemu_irq abort_irq, omap_clk clk)
1825 struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *)
1826 qemu_mallocz(sizeof(struct omap_tipb_bridge_s));
1828 s->abort = abort_irq;
1829 omap_tipb_bridge_reset(s);
1831 iomemtype = cpu_register_io_memory(0, omap_tipb_bridge_readfn,
1832 omap_tipb_bridge_writefn, s);
1833 cpu_register_physical_memory(base, 0x100, iomemtype);
1838 /* Dummy Traffic Controller's Memory Interface */
1839 static uint32_t omap_tcmi_read(void *opaque, target_phys_addr_t addr)
1841 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1845 case 0x00: /* IMIF_PRIO */
1846 case 0x04: /* EMIFS_PRIO */
1847 case 0x08: /* EMIFF_PRIO */
1848 case 0x0c: /* EMIFS_CONFIG */
1849 case 0x10: /* EMIFS_CS0_CONFIG */
1850 case 0x14: /* EMIFS_CS1_CONFIG */
1851 case 0x18: /* EMIFS_CS2_CONFIG */
1852 case 0x1c: /* EMIFS_CS3_CONFIG */
1853 case 0x24: /* EMIFF_MRS */
1854 case 0x28: /* TIMEOUT1 */
1855 case 0x2c: /* TIMEOUT2 */
1856 case 0x30: /* TIMEOUT3 */
1857 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1858 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1859 return s->tcmi_regs[addr >> 2];
1861 case 0x20: /* EMIFF_SDRAM_CONFIG */
1862 ret = s->tcmi_regs[addr >> 2];
1863 s->tcmi_regs[addr >> 2] &= ~1; /* XXX: Clear SLRF on SDRAM access */
1864 /* XXX: We can try using the VGA_DIRTY flag for this */
1872 static void omap_tcmi_write(void *opaque, target_phys_addr_t addr,
1875 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
1878 case 0x00: /* IMIF_PRIO */
1879 case 0x04: /* EMIFS_PRIO */
1880 case 0x08: /* EMIFF_PRIO */
1881 case 0x10: /* EMIFS_CS0_CONFIG */
1882 case 0x14: /* EMIFS_CS1_CONFIG */
1883 case 0x18: /* EMIFS_CS2_CONFIG */
1884 case 0x1c: /* EMIFS_CS3_CONFIG */
1885 case 0x20: /* EMIFF_SDRAM_CONFIG */
1886 case 0x24: /* EMIFF_MRS */
1887 case 0x28: /* TIMEOUT1 */
1888 case 0x2c: /* TIMEOUT2 */
1889 case 0x30: /* TIMEOUT3 */
1890 case 0x3c: /* EMIFF_SDRAM_CONFIG_2 */
1891 case 0x40: /* EMIFS_CFG_DYN_WAIT */
1892 s->tcmi_regs[addr >> 2] = value;
1894 case 0x0c: /* EMIFS_CONFIG */
1895 s->tcmi_regs[addr >> 2] = (value & 0xf) | (1 << 4);
1903 static CPUReadMemoryFunc *omap_tcmi_readfn[] = {
1904 omap_badwidth_read32,
1905 omap_badwidth_read32,
1909 static CPUWriteMemoryFunc *omap_tcmi_writefn[] = {
1910 omap_badwidth_write32,
1911 omap_badwidth_write32,
1915 static void omap_tcmi_reset(struct omap_mpu_state_s *mpu)
1917 mpu->tcmi_regs[0x00 >> 2] = 0x00000000;
1918 mpu->tcmi_regs[0x04 >> 2] = 0x00000000;
1919 mpu->tcmi_regs[0x08 >> 2] = 0x00000000;
1920 mpu->tcmi_regs[0x0c >> 2] = 0x00000010;
1921 mpu->tcmi_regs[0x10 >> 2] = 0x0010fffb;
1922 mpu->tcmi_regs[0x14 >> 2] = 0x0010fffb;
1923 mpu->tcmi_regs[0x18 >> 2] = 0x0010fffb;
1924 mpu->tcmi_regs[0x1c >> 2] = 0x0010fffb;
1925 mpu->tcmi_regs[0x20 >> 2] = 0x00618800;
1926 mpu->tcmi_regs[0x24 >> 2] = 0x00000037;
1927 mpu->tcmi_regs[0x28 >> 2] = 0x00000000;
1928 mpu->tcmi_regs[0x2c >> 2] = 0x00000000;
1929 mpu->tcmi_regs[0x30 >> 2] = 0x00000000;
1930 mpu->tcmi_regs[0x3c >> 2] = 0x00000003;
1931 mpu->tcmi_regs[0x40 >> 2] = 0x00000000;
1934 static void omap_tcmi_init(target_phys_addr_t base,
1935 struct omap_mpu_state_s *mpu)
1937 int iomemtype = cpu_register_io_memory(0, omap_tcmi_readfn,
1938 omap_tcmi_writefn, mpu);
1940 cpu_register_physical_memory(base, 0x100, iomemtype);
1941 omap_tcmi_reset(mpu);
1944 /* Digital phase-locked loops control */
1945 static uint32_t omap_dpll_read(void *opaque, target_phys_addr_t addr)
1947 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1949 if (addr == 0x00) /* CTL_REG */
1956 static void omap_dpll_write(void *opaque, target_phys_addr_t addr,
1959 struct dpll_ctl_s *s = (struct dpll_ctl_s *) opaque;
1961 static const int bypass_div[4] = { 1, 2, 4, 4 };
1964 if (addr == 0x00) { /* CTL_REG */
1965 /* See omap_ulpd_pm_write() too */
1966 diff = s->mode & value;
1967 s->mode = value & 0x2fff;
1968 if (diff & (0x3ff << 2)) {
1969 if (value & (1 << 4)) { /* PLL_ENABLE */
1970 div = ((value >> 5) & 3) + 1; /* PLL_DIV */
1971 mult = MIN((value >> 7) & 0x1f, 1); /* PLL_MULT */
1973 div = bypass_div[((value >> 2) & 3)]; /* BYPASS_DIV */
1976 omap_clk_setrate(s->dpll, div, mult);
1979 /* Enter the desired mode. */
1980 s->mode = (s->mode & 0xfffe) | ((s->mode >> 4) & 1);
1982 /* Act as if the lock is restored. */
1989 static CPUReadMemoryFunc *omap_dpll_readfn[] = {
1990 omap_badwidth_read16,
1992 omap_badwidth_read16,
1995 static CPUWriteMemoryFunc *omap_dpll_writefn[] = {
1996 omap_badwidth_write16,
1998 omap_badwidth_write16,
2001 static void omap_dpll_reset(struct dpll_ctl_s *s)
2004 omap_clk_setrate(s->dpll, 1, 1);
2007 static void omap_dpll_init(struct dpll_ctl_s *s, target_phys_addr_t base,
2010 int iomemtype = cpu_register_io_memory(0, omap_dpll_readfn,
2011 omap_dpll_writefn, s);
2016 cpu_register_physical_memory(base, 0x100, iomemtype);
2020 struct omap_uart_s {
2021 target_phys_addr_t base;
2022 SerialState *serial; /* TODO */
2023 struct omap_target_agent_s *ta;
2036 static void omap_uart_save_state(QEMUFile *f, void *opaque)
2038 struct omap_uart_s *s = (struct omap_uart_s *)opaque;
2040 qemu_put_byte(f, s->eblr);
2041 qemu_put_byte(f, s->syscontrol);
2042 qemu_put_byte(f, s->wkup);
2043 qemu_put_byte(f, s->cfps);
2044 qemu_put_byte(f, s->mdr[0]);
2045 qemu_put_byte(f, s->mdr[1]);
2046 qemu_put_byte(f, s->scr);
2047 qemu_put_byte(f, s->clksel);
2050 static int omap_uart_load_state(QEMUFile *f, void *opaque, int version_id)
2052 struct omap_uart_s *s = (struct omap_uart_s *)opaque;
2057 s->eblr = qemu_get_byte(f);
2058 s->syscontrol = qemu_get_byte(f);
2059 s->wkup = qemu_get_byte(f);
2060 s->cfps = qemu_get_byte(f);
2061 s->mdr[0] = qemu_get_byte(f);
2062 s->mdr[1] = qemu_get_byte(f);
2063 s->scr = qemu_get_byte(f);
2064 s->clksel = qemu_get_byte(f);
2069 void omap_uart_reset(struct omap_uart_s *s)
2078 struct omap_uart_s *omap_uart_init(target_phys_addr_t base,
2079 qemu_irq irq, omap_clk fclk, omap_clk iclk,
2080 qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr)
2082 struct omap_uart_s *s = (struct omap_uart_s *)
2083 qemu_mallocz(sizeof(struct omap_uart_s));
2088 s->serial = serial_mm_init(base, 2, irq, omap_clk_getrate(fclk)/16,
2089 chr ?: qemu_chr_open("null", "null", NULL), 1);
2091 register_savevm("omap_uart", base >> 8, 0,
2092 omap_uart_save_state, omap_uart_load_state, s);
2096 static uint32_t omap_uart_read(void *opaque, target_phys_addr_t addr)
2098 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
2102 case 0x20: /* MDR1 */
2104 case 0x24: /* MDR2 */
2106 case 0x40: /* SCR */
2108 case 0x44: /* SSR */
2110 case 0x48: /* EBLR (OMAP2) */
2112 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2114 case 0x50: /* MVR */
2116 case 0x54: /* SYSC (OMAP2) */
2117 return s->syscontrol;
2118 case 0x58: /* SYSS (OMAP2) */
2120 case 0x5c: /* WER (OMAP2) */
2122 case 0x60: /* CFPS (OMAP2) */
2130 static void omap_uart_write(void *opaque, target_phys_addr_t addr,
2133 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
2137 case 0x20: /* MDR1 */
2138 s->mdr[0] = value & 0x7f;
2140 case 0x24: /* MDR2 */
2141 s->mdr[1] = value & 0xff;
2143 case 0x40: /* SCR */
2144 s->scr = value & 0xff;
2146 case 0x48: /* EBLR (OMAP2) */
2147 s->eblr = value & 0xff;
2149 case 0x4C: /* OSC_12M_SEL (OMAP1) */
2150 s->clksel = value & 1;
2152 case 0x44: /* SSR */
2153 case 0x50: /* MVR */
2154 case 0x58: /* SYSS (OMAP2) */
2157 case 0x54: /* SYSC (OMAP2) */
2158 s->syscontrol = value & 0x1d;
2162 case 0x5c: /* WER (OMAP2) */
2163 s->wkup = value & 0x7f;
2165 case 0x60: /* CFPS (OMAP2) */
2166 s->cfps = value & 0xff;
2173 static CPUReadMemoryFunc *omap_uart_readfn[] = {
2176 omap_badwidth_read8,
2179 static CPUWriteMemoryFunc *omap_uart_writefn[] = {
2182 omap_badwidth_write8,
2185 struct omap_uart_s *omap2_uart_init(struct omap_target_agent_s *ta,
2186 qemu_irq irq, omap_clk fclk, omap_clk iclk,
2187 qemu_irq txdma, qemu_irq rxdma, CharDriverState *chr)
2189 target_phys_addr_t base = omap_l4_attach(ta, 0, 0);
2190 struct omap_uart_s *s = omap_uart_init(base, irq,
2191 fclk, iclk, txdma, rxdma, chr);
2192 int iomemtype = cpu_register_io_memory(0, omap_uart_readfn,
2193 omap_uart_writefn, s);
2197 cpu_register_physical_memory(base + 0x20, 0x100, iomemtype);
2202 void omap_uart_attach(struct omap_uart_s *s, CharDriverState *chr)
2204 /* TODO: Should reuse or destroy current s->serial */
2205 fprintf(stderr, "%s: WARNING - this function is broken, avoid using it\n",
2207 s->serial = serial_mm_init(s->base, 2, s->irq,
2208 omap_clk_getrate(s->fclk) / 16,
2209 chr ?: qemu_chr_open("null", "null", NULL),
2213 /* MPU Clock/Reset/Power Mode Control */
2214 static uint32_t omap_clkm_read(void *opaque, target_phys_addr_t addr)
2216 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2219 case 0x00: /* ARM_CKCTL */
2220 return s->clkm.arm_ckctl;
2222 case 0x04: /* ARM_IDLECT1 */
2223 return s->clkm.arm_idlect1;
2225 case 0x08: /* ARM_IDLECT2 */
2226 return s->clkm.arm_idlect2;
2228 case 0x0c: /* ARM_EWUPCT */
2229 return s->clkm.arm_ewupct;
2231 case 0x10: /* ARM_RSTCT1 */
2232 return s->clkm.arm_rstct1;
2234 case 0x14: /* ARM_RSTCT2 */
2235 return s->clkm.arm_rstct2;
2237 case 0x18: /* ARM_SYSST */
2238 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start;
2240 case 0x1c: /* ARM_CKOUT1 */
2241 return s->clkm.arm_ckout1;
2243 case 0x20: /* ARM_CKOUT2 */
2251 static inline void omap_clkm_ckctl_update(struct omap_mpu_state_s *s,
2252 uint16_t diff, uint16_t value)
2256 if (diff & (1 << 14)) { /* ARM_INTHCK_SEL */
2257 if (value & (1 << 14))
2260 clk = omap_findclk(s, "arminth_ck");
2261 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
2264 if (diff & (1 << 12)) { /* ARM_TIMXO */
2265 clk = omap_findclk(s, "armtim_ck");
2266 if (value & (1 << 12))
2267 omap_clk_reparent(clk, omap_findclk(s, "clkin"));
2269 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
2272 if (diff & (3 << 10)) { /* DSPMMUDIV */
2273 clk = omap_findclk(s, "dspmmu_ck");
2274 omap_clk_setrate(clk, 1 << ((value >> 10) & 3), 1);
2276 if (diff & (3 << 8)) { /* TCDIV */
2277 clk = omap_findclk(s, "tc_ck");
2278 omap_clk_setrate(clk, 1 << ((value >> 8) & 3), 1);
2280 if (diff & (3 << 6)) { /* DSPDIV */
2281 clk = omap_findclk(s, "dsp_ck");
2282 omap_clk_setrate(clk, 1 << ((value >> 6) & 3), 1);
2284 if (diff & (3 << 4)) { /* ARMDIV */
2285 clk = omap_findclk(s, "arm_ck");
2286 omap_clk_setrate(clk, 1 << ((value >> 4) & 3), 1);
2288 if (diff & (3 << 2)) { /* LCDDIV */
2289 clk = omap_findclk(s, "lcd_ck");
2290 omap_clk_setrate(clk, 1 << ((value >> 2) & 3), 1);
2292 if (diff & (3 << 0)) { /* PERDIV */
2293 clk = omap_findclk(s, "armper_ck");
2294 omap_clk_setrate(clk, 1 << ((value >> 0) & 3), 1);
2298 static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s,
2299 uint16_t diff, uint16_t value)
2303 if (value & (1 << 11)) /* SETARM_IDLE */
2304 cpu_interrupt(s->env, CPU_INTERRUPT_HALT);
2305 if (!(value & (1 << 10))) /* WKUP_MODE */
2306 qemu_system_shutdown_request(); /* XXX: disable wakeup from IRQ */
2308 #define SET_CANIDLE(clock, bit) \
2309 if (diff & (1 << bit)) { \
2310 clk = omap_findclk(s, clock); \
2311 omap_clk_canidle(clk, (value >> bit) & 1); \
2313 SET_CANIDLE("mpuwd_ck", 0) /* IDLWDT_ARM */
2314 SET_CANIDLE("armxor_ck", 1) /* IDLXORP_ARM */
2315 SET_CANIDLE("mpuper_ck", 2) /* IDLPER_ARM */
2316 SET_CANIDLE("lcd_ck", 3) /* IDLLCD_ARM */
2317 SET_CANIDLE("lb_ck", 4) /* IDLLB_ARM */
2318 SET_CANIDLE("hsab_ck", 5) /* IDLHSAB_ARM */
2319 SET_CANIDLE("tipb_ck", 6) /* IDLIF_ARM */
2320 SET_CANIDLE("dma_ck", 6) /* IDLIF_ARM */
2321 SET_CANIDLE("tc_ck", 6) /* IDLIF_ARM */
2322 SET_CANIDLE("dpll1", 7) /* IDLDPLL_ARM */
2323 SET_CANIDLE("dpll2", 7) /* IDLDPLL_ARM */
2324 SET_CANIDLE("dpll3", 7) /* IDLDPLL_ARM */
2325 SET_CANIDLE("mpui_ck", 8) /* IDLAPI_ARM */
2326 SET_CANIDLE("armtim_ck", 9) /* IDLTIM_ARM */
2329 static inline void omap_clkm_idlect2_update(struct omap_mpu_state_s *s,
2330 uint16_t diff, uint16_t value)
2334 #define SET_ONOFF(clock, bit) \
2335 if (diff & (1 << bit)) { \
2336 clk = omap_findclk(s, clock); \
2337 omap_clk_onoff(clk, (value >> bit) & 1); \
2339 SET_ONOFF("mpuwd_ck", 0) /* EN_WDTCK */
2340 SET_ONOFF("armxor_ck", 1) /* EN_XORPCK */
2341 SET_ONOFF("mpuper_ck", 2) /* EN_PERCK */
2342 SET_ONOFF("lcd_ck", 3) /* EN_LCDCK */
2343 SET_ONOFF("lb_ck", 4) /* EN_LBCK */
2344 SET_ONOFF("hsab_ck", 5) /* EN_HSABCK */
2345 SET_ONOFF("mpui_ck", 6) /* EN_APICK */
2346 SET_ONOFF("armtim_ck", 7) /* EN_TIMCK */
2347 SET_CANIDLE("dma_ck", 8) /* DMACK_REQ */
2348 SET_ONOFF("arm_gpio_ck", 9) /* EN_GPIOCK */
2349 SET_ONOFF("lbfree_ck", 10) /* EN_LBFREECK */
2352 static inline void omap_clkm_ckout1_update(struct omap_mpu_state_s *s,
2353 uint16_t diff, uint16_t value)
2357 if (diff & (3 << 4)) { /* TCLKOUT */
2358 clk = omap_findclk(s, "tclk_out");
2359 switch ((value >> 4) & 3) {
2361 omap_clk_reparent(clk, omap_findclk(s, "ck_gen3"));
2362 omap_clk_onoff(clk, 1);
2365 omap_clk_reparent(clk, omap_findclk(s, "tc_ck"));
2366 omap_clk_onoff(clk, 1);
2369 omap_clk_onoff(clk, 0);
2372 if (diff & (3 << 2)) { /* DCLKOUT */
2373 clk = omap_findclk(s, "dclk_out");
2374 switch ((value >> 2) & 3) {
2376 omap_clk_reparent(clk, omap_findclk(s, "dspmmu_ck"));
2379 omap_clk_reparent(clk, omap_findclk(s, "ck_gen2"));
2382 omap_clk_reparent(clk, omap_findclk(s, "dsp_ck"));
2385 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
2389 if (diff & (3 << 0)) { /* ACLKOUT */
2390 clk = omap_findclk(s, "aclk_out");
2391 switch ((value >> 0) & 3) {
2393 omap_clk_reparent(clk, omap_findclk(s, "ck_gen1"));
2394 omap_clk_onoff(clk, 1);
2397 omap_clk_reparent(clk, omap_findclk(s, "arm_ck"));
2398 omap_clk_onoff(clk, 1);
2401 omap_clk_reparent(clk, omap_findclk(s, "ck_ref14"));
2402 omap_clk_onoff(clk, 1);
2405 omap_clk_onoff(clk, 0);
2410 static void omap_clkm_write(void *opaque, target_phys_addr_t addr,
2413 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2416 static const char *clkschemename[8] = {
2417 "fully synchronous", "fully asynchronous", "synchronous scalable",
2418 "mix mode 1", "mix mode 2", "bypass mode", "mix mode 3", "mix mode 4",
2422 case 0x00: /* ARM_CKCTL */
2423 diff = s->clkm.arm_ckctl ^ value;
2424 s->clkm.arm_ckctl = value & 0x7fff;
2425 omap_clkm_ckctl_update(s, diff, value);
2428 case 0x04: /* ARM_IDLECT1 */
2429 diff = s->clkm.arm_idlect1 ^ value;
2430 s->clkm.arm_idlect1 = value & 0x0fff;
2431 omap_clkm_idlect1_update(s, diff, value);
2434 case 0x08: /* ARM_IDLECT2 */
2435 diff = s->clkm.arm_idlect2 ^ value;
2436 s->clkm.arm_idlect2 = value & 0x07ff;
2437 omap_clkm_idlect2_update(s, diff, value);
2440 case 0x0c: /* ARM_EWUPCT */
2441 diff = s->clkm.arm_ewupct ^ value;
2442 s->clkm.arm_ewupct = value & 0x003f;
2445 case 0x10: /* ARM_RSTCT1 */
2446 diff = s->clkm.arm_rstct1 ^ value;
2447 s->clkm.arm_rstct1 = value & 0x0007;
2449 qemu_system_reset_request();
2450 s->clkm.cold_start = 0xa;
2452 if (diff & ~value & 4) { /* DSP_RST */
2454 omap_tipb_bridge_reset(s->private_tipb);
2455 omap_tipb_bridge_reset(s->public_tipb);
2457 if (diff & 2) { /* DSP_EN */
2458 clk = omap_findclk(s, "dsp_ck");
2459 omap_clk_canidle(clk, (~value >> 1) & 1);
2463 case 0x14: /* ARM_RSTCT2 */
2464 s->clkm.arm_rstct2 = value & 0x0001;
2467 case 0x18: /* ARM_SYSST */
2468 if ((s->clkm.clocking_scheme ^ (value >> 11)) & 7) {
2469 s->clkm.clocking_scheme = (value >> 11) & 7;
2470 printf("%s: clocking scheme set to %s\n", __FUNCTION__,
2471 clkschemename[s->clkm.clocking_scheme]);
2473 s->clkm.cold_start &= value & 0x3f;
2476 case 0x1c: /* ARM_CKOUT1 */
2477 diff = s->clkm.arm_ckout1 ^ value;
2478 s->clkm.arm_ckout1 = value & 0x003f;
2479 omap_clkm_ckout1_update(s, diff, value);
2482 case 0x20: /* ARM_CKOUT2 */
2488 static CPUReadMemoryFunc *omap_clkm_readfn[] = {
2489 omap_badwidth_read16,
2491 omap_badwidth_read16,
2494 static CPUWriteMemoryFunc *omap_clkm_writefn[] = {
2495 omap_badwidth_write16,
2497 omap_badwidth_write16,
2500 static uint32_t omap_clkdsp_read(void *opaque, target_phys_addr_t addr)
2502 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2505 case 0x04: /* DSP_IDLECT1 */
2506 return s->clkm.dsp_idlect1;
2508 case 0x08: /* DSP_IDLECT2 */
2509 return s->clkm.dsp_idlect2;
2511 case 0x14: /* DSP_RSTCT2 */
2512 return s->clkm.dsp_rstct2;
2514 case 0x18: /* DSP_SYSST */
2515 return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start |
2516 (s->env->halted << 6); /* Quite useless... */
2523 static inline void omap_clkdsp_idlect1_update(struct omap_mpu_state_s *s,
2524 uint16_t diff, uint16_t value)
2528 SET_CANIDLE("dspxor_ck", 1); /* IDLXORP_DSP */
2531 static inline void omap_clkdsp_idlect2_update(struct omap_mpu_state_s *s,
2532 uint16_t diff, uint16_t value)
2536 SET_ONOFF("dspxor_ck", 1); /* EN_XORPCK */
2539 static void omap_clkdsp_write(void *opaque, target_phys_addr_t addr,
2542 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
2546 case 0x04: /* DSP_IDLECT1 */
2547 diff = s->clkm.dsp_idlect1 ^ value;
2548 s->clkm.dsp_idlect1 = value & 0x01f7;
2549 omap_clkdsp_idlect1_update(s, diff, value);
2552 case 0x08: /* DSP_IDLECT2 */
2553 s->clkm.dsp_idlect2 = value & 0x0037;
2554 diff = s->clkm.dsp_idlect1 ^ value;
2555 omap_clkdsp_idlect2_update(s, diff, value);
2558 case 0x14: /* DSP_RSTCT2 */
2559 s->clkm.dsp_rstct2 = value & 0x0001;
2562 case 0x18: /* DSP_SYSST */
2563 s->clkm.cold_start &= value & 0x3f;
2571 static CPUReadMemoryFunc *omap_clkdsp_readfn[] = {
2572 omap_badwidth_read16,
2574 omap_badwidth_read16,
2577 static CPUWriteMemoryFunc *omap_clkdsp_writefn[] = {
2578 omap_badwidth_write16,
2580 omap_badwidth_write16,
2583 static void omap_clkm_reset(struct omap_mpu_state_s *s)
2585 if (s->wdt && s->wdt->reset)
2586 s->clkm.cold_start = 0x6;
2587 s->clkm.clocking_scheme = 0;
2588 omap_clkm_ckctl_update(s, ~0, 0x3000);
2589 s->clkm.arm_ckctl = 0x3000;
2590 omap_clkm_idlect1_update(s, s->clkm.arm_idlect1 ^ 0x0400, 0x0400);
2591 s->clkm.arm_idlect1 = 0x0400;
2592 omap_clkm_idlect2_update(s, s->clkm.arm_idlect2 ^ 0x0100, 0x0100);
2593 s->clkm.arm_idlect2 = 0x0100;
2594 s->clkm.arm_ewupct = 0x003f;
2595 s->clkm.arm_rstct1 = 0x0000;
2596 s->clkm.arm_rstct2 = 0x0000;
2597 s->clkm.arm_ckout1 = 0x0015;
2598 s->clkm.dpll1_mode = 0x2002;
2599 omap_clkdsp_idlect1_update(s, s->clkm.dsp_idlect1 ^ 0x0040, 0x0040);
2600 s->clkm.dsp_idlect1 = 0x0040;
2601 omap_clkdsp_idlect2_update(s, ~0, 0x0000);
2602 s->clkm.dsp_idlect2 = 0x0000;
2603 s->clkm.dsp_rstct2 = 0x0000;
2606 static void omap_clkm_init(target_phys_addr_t mpu_base,
2607 target_phys_addr_t dsp_base, struct omap_mpu_state_s *s)
2609 int iomemtype[2] = {
2610 cpu_register_io_memory(0, omap_clkm_readfn, omap_clkm_writefn, s),
2611 cpu_register_io_memory(0, omap_clkdsp_readfn, omap_clkdsp_writefn, s),
2614 s->clkm.arm_idlect1 = 0x03ff;
2615 s->clkm.arm_idlect2 = 0x0100;
2616 s->clkm.dsp_idlect1 = 0x0002;
2618 s->clkm.cold_start = 0x3a;
2620 cpu_register_physical_memory(mpu_base, 0x100, iomemtype[0]);
2621 cpu_register_physical_memory(dsp_base, 0x1000, iomemtype[1]);
2625 struct omap_mpuio_s {
2629 qemu_irq handler[16];
2650 static void omap_mpuio_set(void *opaque, int line, int level)
2652 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2653 uint16_t prev = s->inputs;
2656 s->inputs |= 1 << line;
2658 s->inputs &= ~(1 << line);
2660 if (((1 << line) & s->dir & ~s->mask) && s->clk) {
2661 if ((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) {
2662 s->ints |= 1 << line;
2663 qemu_irq_raise(s->irq);
2666 if ((s->event & (1 << 0)) && /* SET_GPIO_EVENT_MODE */
2667 (s->event >> 1) == line) /* PIN_SELECT */
2668 s->latch = s->inputs;
2672 static void omap_mpuio_kbd_update(struct omap_mpuio_s *s)
2675 uint8_t *row, rows = 0, cols = ~s->cols;
2677 for (row = s->buttons + 4, i = 1 << 4; i; row --, i >>= 1)
2681 qemu_set_irq(s->kbd_irq, rows && !s->kbd_mask && s->clk);
2682 s->row_latch = ~rows;
2685 static uint32_t omap_mpuio_read(void *opaque, target_phys_addr_t addr)
2687 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2688 int offset = addr & OMAP_MPUI_REG_MASK;
2692 case 0x00: /* INPUT_LATCH */
2695 case 0x04: /* OUTPUT_REG */
2698 case 0x08: /* IO_CNTL */
2701 case 0x10: /* KBR_LATCH */
2702 return s->row_latch;
2704 case 0x14: /* KBC_REG */
2707 case 0x18: /* GPIO_EVENT_MODE_REG */
2710 case 0x1c: /* GPIO_INT_EDGE_REG */
2713 case 0x20: /* KBD_INT */
2714 return (~s->row_latch & 0x1f) && !s->kbd_mask;
2716 case 0x24: /* GPIO_INT */
2720 qemu_irq_lower(s->irq);
2723 case 0x28: /* KBD_MASKIT */
2726 case 0x2c: /* GPIO_MASKIT */
2729 case 0x30: /* GPIO_DEBOUNCING_REG */
2732 case 0x34: /* GPIO_LATCH_REG */
2740 static void omap_mpuio_write(void *opaque, target_phys_addr_t addr,
2743 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2744 int offset = addr & OMAP_MPUI_REG_MASK;
2749 case 0x04: /* OUTPUT_REG */
2750 diff = (s->outputs ^ value) & ~s->dir;
2752 while ((ln = ffs(diff))) {
2755 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2760 case 0x08: /* IO_CNTL */
2761 diff = s->outputs & (s->dir ^ value);
2764 value = s->outputs & ~s->dir;
2765 while ((ln = ffs(diff))) {
2768 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2773 case 0x14: /* KBC_REG */
2775 omap_mpuio_kbd_update(s);
2778 case 0x18: /* GPIO_EVENT_MODE_REG */
2779 s->event = value & 0x1f;
2782 case 0x1c: /* GPIO_INT_EDGE_REG */
2786 case 0x28: /* KBD_MASKIT */
2787 s->kbd_mask = value & 1;
2788 omap_mpuio_kbd_update(s);
2791 case 0x2c: /* GPIO_MASKIT */
2795 case 0x30: /* GPIO_DEBOUNCING_REG */
2796 s->debounce = value & 0x1ff;
2799 case 0x00: /* INPUT_LATCH */
2800 case 0x10: /* KBR_LATCH */
2801 case 0x20: /* KBD_INT */
2802 case 0x24: /* GPIO_INT */
2803 case 0x34: /* GPIO_LATCH_REG */
2813 static CPUReadMemoryFunc *omap_mpuio_readfn[] = {
2814 omap_badwidth_read16,
2816 omap_badwidth_read16,
2819 static CPUWriteMemoryFunc *omap_mpuio_writefn[] = {
2820 omap_badwidth_write16,
2822 omap_badwidth_write16,
2825 static void omap_mpuio_reset(struct omap_mpuio_s *s)
2837 s->row_latch = 0x1f;
2841 static void omap_mpuio_onoff(void *opaque, int line, int on)
2843 struct omap_mpuio_s *s = (struct omap_mpuio_s *) opaque;
2847 omap_mpuio_kbd_update(s);
2850 struct omap_mpuio_s *omap_mpuio_init(target_phys_addr_t base,
2851 qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup,
2855 struct omap_mpuio_s *s = (struct omap_mpuio_s *)
2856 qemu_mallocz(sizeof(struct omap_mpuio_s));
2859 s->kbd_irq = kbd_int;
2861 s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
2862 omap_mpuio_reset(s);
2864 iomemtype = cpu_register_io_memory(0, omap_mpuio_readfn,
2865 omap_mpuio_writefn, s);
2866 cpu_register_physical_memory(base, 0x800, iomemtype);
2868 omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]);
2873 qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s)
2878 void omap_mpuio_out_set(struct omap_mpuio_s *s, int line, qemu_irq handler)
2880 if (line >= 16 || line < 0)
2881 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
2882 s->handler[line] = handler;
2885 void omap_mpuio_key(struct omap_mpuio_s *s, int row, int col, int down)
2887 if (row >= 5 || row < 0)
2888 cpu_abort(cpu_single_env, "%s: No key %i-%i\n",
2889 __FUNCTION__, col, row);
2892 s->buttons[row] |= 1 << col;
2894 s->buttons[row] &= ~(1 << col);
2896 omap_mpuio_kbd_update(s);
2899 /* General-Purpose I/O */
2900 struct omap_gpio_s {
2903 qemu_irq handler[16];
2914 static void omap_gpio_set(void *opaque, int line, int level)
2916 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2917 uint16_t prev = s->inputs;
2920 s->inputs |= 1 << line;
2922 s->inputs &= ~(1 << line);
2924 if (((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) &
2925 (1 << line) & s->dir & ~s->mask) {
2926 s->ints |= 1 << line;
2927 qemu_irq_raise(s->irq);
2931 static uint32_t omap_gpio_read(void *opaque, target_phys_addr_t addr)
2933 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2934 int offset = addr & OMAP_MPUI_REG_MASK;
2937 case 0x00: /* DATA_INPUT */
2938 return s->inputs & s->pins;
2940 case 0x04: /* DATA_OUTPUT */
2943 case 0x08: /* DIRECTION_CONTROL */
2946 case 0x0c: /* INTERRUPT_CONTROL */
2949 case 0x10: /* INTERRUPT_MASK */
2952 case 0x14: /* INTERRUPT_STATUS */
2955 case 0x18: /* PIN_CONTROL (not in OMAP310) */
2964 static void omap_gpio_write(void *opaque, target_phys_addr_t addr,
2967 struct omap_gpio_s *s = (struct omap_gpio_s *) opaque;
2968 int offset = addr & OMAP_MPUI_REG_MASK;
2973 case 0x00: /* DATA_INPUT */
2977 case 0x04: /* DATA_OUTPUT */
2978 diff = (s->outputs ^ value) & ~s->dir;
2980 while ((ln = ffs(diff))) {
2983 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
2988 case 0x08: /* DIRECTION_CONTROL */
2989 diff = s->outputs & (s->dir ^ value);
2992 value = s->outputs & ~s->dir;
2993 while ((ln = ffs(diff))) {
2996 qemu_set_irq(s->handler[ln], (value >> ln) & 1);
3001 case 0x0c: /* INTERRUPT_CONTROL */
3005 case 0x10: /* INTERRUPT_MASK */
3009 case 0x14: /* INTERRUPT_STATUS */
3012 qemu_irq_lower(s->irq);
3015 case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */
3026 /* *Some* sources say the memory region is 32-bit. */
3027 static CPUReadMemoryFunc *omap_gpio_readfn[] = {
3028 omap_badwidth_read16,
3030 omap_badwidth_read16,
3033 static CPUWriteMemoryFunc *omap_gpio_writefn[] = {
3034 omap_badwidth_write16,
3036 omap_badwidth_write16,
3039 static void omap_gpio_reset(struct omap_gpio_s *s)
3050 struct omap_gpio_s *omap_gpio_init(target_phys_addr_t base,
3051 qemu_irq irq, omap_clk clk)
3054 struct omap_gpio_s *s = (struct omap_gpio_s *)
3055 qemu_mallocz(sizeof(struct omap_gpio_s));
3058 s->in = qemu_allocate_irqs(omap_gpio_set, s, 16);
3061 iomemtype = cpu_register_io_memory(0, omap_gpio_readfn,
3062 omap_gpio_writefn, s);
3063 cpu_register_physical_memory(base, 0x1000, iomemtype);
3068 qemu_irq *omap_gpio_in_get(struct omap_gpio_s *s)
3073 void omap_gpio_out_set(struct omap_gpio_s *s, int line, qemu_irq handler)
3075 if (line >= 16 || line < 0)
3076 cpu_abort(cpu_single_env, "%s: No GPIO line %i\n", __FUNCTION__, line);
3077 s->handler[line] = handler;
3080 /* MicroWire Interface */
3081 struct omap_uwire_s {
3091 struct uwire_slave_s *chip[4];
3094 static void omap_uwire_transfer_start(struct omap_uwire_s *s)
3096 int chipselect = (s->control >> 10) & 3; /* INDEX */
3097 struct uwire_slave_s *slave = s->chip[chipselect];
3099 if ((s->control >> 5) & 0x1f) { /* NB_BITS_WR */
3100 if (s->control & (1 << 12)) /* CS_CMD */
3101 if (slave && slave->send)
3102 slave->send(slave->opaque,
3103 s->txbuf >> (16 - ((s->control >> 5) & 0x1f)));
3104 s->control &= ~(1 << 14); /* CSRB */
3105 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3106 * a DRQ. When is the level IRQ supposed to be reset? */
3109 if ((s->control >> 0) & 0x1f) { /* NB_BITS_RD */
3110 if (s->control & (1 << 12)) /* CS_CMD */
3111 if (slave && slave->receive)
3112 s->rxbuf = slave->receive(slave->opaque);
3113 s->control |= 1 << 15; /* RDRB */
3114 /* TODO: depending on s->setup[4] bits [1:0] assert an IRQ or
3115 * a DRQ. When is the level IRQ supposed to be reset? */
3119 static uint32_t omap_uwire_read(void *opaque, target_phys_addr_t addr)
3121 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
3122 int offset = addr & OMAP_MPUI_REG_MASK;
3125 case 0x00: /* RDR */
3126 s->control &= ~(1 << 15); /* RDRB */
3129 case 0x04: /* CSR */
3132 case 0x08: /* SR1 */
3134 case 0x0c: /* SR2 */
3136 case 0x10: /* SR3 */
3138 case 0x14: /* SR4 */
3140 case 0x18: /* SR5 */
3148 static void omap_uwire_write(void *opaque, target_phys_addr_t addr,
3151 struct omap_uwire_s *s = (struct omap_uwire_s *) opaque;
3152 int offset = addr & OMAP_MPUI_REG_MASK;
3155 case 0x00: /* TDR */
3156 s->txbuf = value; /* TD */
3157 if ((s->setup[4] & (1 << 2)) && /* AUTO_TX_EN */
3158 ((s->setup[4] & (1 << 3)) || /* CS_TOGGLE_TX_EN */
3159 (s->control & (1 << 12)))) { /* CS_CMD */
3160 s->control |= 1 << 14; /* CSRB */
3161 omap_uwire_transfer_start(s);
3165 case 0x04: /* CSR */
3166 s->control = value & 0x1fff;
3167 if (value & (1 << 13)) /* START */
3168 omap_uwire_transfer_start(s);
3171 case 0x08: /* SR1 */
3172 s->setup[0] = value & 0x003f;
3175 case 0x0c: /* SR2 */
3176 s->setup[1] = value & 0x0fc0;
3179 case 0x10: /* SR3 */
3180 s->setup[2] = value & 0x0003;
3183 case 0x14: /* SR4 */
3184 s->setup[3] = value & 0x0001;
3187 case 0x18: /* SR5 */
3188 s->setup[4] = value & 0x000f;
3197 static CPUReadMemoryFunc *omap_uwire_readfn[] = {
3198 omap_badwidth_read16,
3200 omap_badwidth_read16,
3203 static CPUWriteMemoryFunc *omap_uwire_writefn[] = {
3204 omap_badwidth_write16,
3206 omap_badwidth_write16,
3209 static void omap_uwire_reset(struct omap_uwire_s *s)
3219 struct omap_uwire_s *omap_uwire_init(target_phys_addr_t base,
3220 qemu_irq *irq, qemu_irq dma, omap_clk clk)
3223 struct omap_uwire_s *s = (struct omap_uwire_s *)
3224 qemu_mallocz(sizeof(struct omap_uwire_s));
3229 omap_uwire_reset(s);
3231 iomemtype = cpu_register_io_memory(0, omap_uwire_readfn,
3232 omap_uwire_writefn, s);
3233 cpu_register_physical_memory(base, 0x800, iomemtype);
3238 void omap_uwire_attach(struct omap_uwire_s *s,
3239 struct uwire_slave_s *slave, int chipselect)
3241 if (chipselect < 0 || chipselect > 3) {
3242 fprintf(stderr, "%s: Bad chipselect %i\n", __FUNCTION__, chipselect);
3246 s->chip[chipselect] = slave;
3249 /* Pseudonoise Pulse-Width Light Modulator */
3250 static void omap_pwl_update(struct omap_mpu_state_s *s)
3252 int output = (s->pwl.clk && s->pwl.enable) ? s->pwl.level : 0;
3254 if (output != s->pwl.output) {
3255 s->pwl.output = output;
3256 printf("%s: Backlight now at %i/256\n", __FUNCTION__, output);
3260 static uint32_t omap_pwl_read(void *opaque, target_phys_addr_t addr)
3262 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3263 int offset = addr & OMAP_MPUI_REG_MASK;
3266 case 0x00: /* PWL_LEVEL */
3267 return s->pwl.level;
3268 case 0x04: /* PWL_CTRL */
3269 return s->pwl.enable;
3275 static void omap_pwl_write(void *opaque, target_phys_addr_t addr,
3278 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3279 int offset = addr & OMAP_MPUI_REG_MASK;
3282 case 0x00: /* PWL_LEVEL */
3283 s->pwl.level = value;
3286 case 0x04: /* PWL_CTRL */
3287 s->pwl.enable = value & 1;
3296 static CPUReadMemoryFunc *omap_pwl_readfn[] = {
3298 omap_badwidth_read8,
3299 omap_badwidth_read8,
3302 static CPUWriteMemoryFunc *omap_pwl_writefn[] = {
3304 omap_badwidth_write8,
3305 omap_badwidth_write8,
3308 static void omap_pwl_reset(struct omap_mpu_state_s *s)
3317 static void omap_pwl_clk_update(void *opaque, int line, int on)
3319 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3325 static void omap_pwl_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
3332 iomemtype = cpu_register_io_memory(0, omap_pwl_readfn,
3333 omap_pwl_writefn, s);
3334 cpu_register_physical_memory(base, 0x800, iomemtype);
3336 omap_clk_adduser(clk, qemu_allocate_irqs(omap_pwl_clk_update, s, 1)[0]);
3339 /* Pulse-Width Tone module */
3340 static uint32_t omap_pwt_read(void *opaque, target_phys_addr_t addr)
3342 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3343 int offset = addr & OMAP_MPUI_REG_MASK;
3346 case 0x00: /* FRC */
3348 case 0x04: /* VCR */
3350 case 0x08: /* GCR */
3357 static void omap_pwt_write(void *opaque, target_phys_addr_t addr,
3360 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;
3361 int offset = addr & OMAP_MPUI_REG_MASK;
3364 case 0x00: /* FRC */
3365 s->pwt.frc = value & 0x3f;
3367 case 0x04: /* VRC */
3368 if ((value ^ s->pwt.vrc) & 1) {
3370 printf("%s: %iHz buzz on\n", __FUNCTION__, (int)
3371 /* 1.5 MHz from a 12-MHz or 13-MHz PWT_CLK */
3372 ((omap_clk_getrate(s->pwt.clk) >> 3) /
3373 /* Pre-multiplexer divider */
3374 ((s->pwt.gcr & 2) ? 1 : 154) /
3375 /* Octave multiplexer */
3376 (2 << (value & 3)) *
3377 /* 101/107 divider */
3378 ((value & (1 << 2)) ? 101 : 107) *
3380 ((value & (1 << 3)) ? 49 : 55) *
3382 ((value & (1 << 4)) ? 50 : 63) *
3383 /* 80/127 divider */
3384 ((value & (1 << 5)) ? 80 : 127) /
3385 (107 * 55 * 63 * 127)));
3387 printf("%s: silence!\n", __FUNCTION__);
3389 s->pwt.vrc = value & 0x7f;
3391 case 0x08: /* GCR */
3392 s->pwt.gcr = value & 3;
3400 static CPUReadMemoryFunc *omap_pwt_readfn[] = {
3402 omap_badwidth_read8,
3403 omap_badwidth_read8,
3406 static CPUWriteMemoryFunc *omap_pwt_writefn[] = {
3408 omap_badwidth_write8,
3409 omap_badwidth_write8,
3412 static void omap_pwt_reset(struct omap_mpu_state_s *s)
3419 static void omap_pwt_init(target_phys_addr_t base, struct omap_mpu_state_s *s,
3427 iomemtype = cpu_register_io_memory(0, omap_pwt_readfn,
3428 omap_pwt_writefn, s);
3429 cpu_register_physical_memory(base, 0x800, iomemtype);
3432 /* Real-time Clock module */
3448 struct tm current_tm;
3453 static void omap_rtc_interrupts_update(struct omap_rtc_s *s)
3455 /* s->alarm is level-triggered */
3456 qemu_set_irq(s->alarm, (s->status >> 6) & 1);
3459 static void omap_rtc_alarm_update(struct omap_rtc_s *s)
3461 s->alarm_ti = mktimegm(&s->alarm_tm);
3462 if (s->alarm_ti == -1)
3463 printf("%s: conversion failed\n", __FUNCTION__);
3466 static inline uint8_t omap_rtc_bcd(int num)
3468 return ((num / 10) << 4) | (num % 10);
3471 static inline int omap_rtc_bin(uint8_t num)
3473 return (num & 15) + 10 * (num >> 4);
3476 static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr)
3478 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
3479 int offset = addr & OMAP_MPUI_REG_MASK;
3483 case 0x00: /* SECONDS_REG */
3484 return omap_rtc_bcd(s->current_tm.tm_sec);
3486 case 0x04: /* MINUTES_REG */
3487 return omap_rtc_bcd(s->current_tm.tm_min);
3489 case 0x08: /* HOURS_REG */
3491 return ((s->current_tm.tm_hour > 11) << 7) |
3492 omap_rtc_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
3494 return omap_rtc_bcd(s->current_tm.tm_hour);
3496 case 0x0c: /* DAYS_REG */
3497 return omap_rtc_bcd(s->current_tm.tm_mday);
3499 case 0x10: /* MONTHS_REG */
3500 return omap_rtc_bcd(s->current_tm.tm_mon + 1);
3502 case 0x14: /* YEARS_REG */
3503 return omap_rtc_bcd(s->current_tm.tm_year % 100);
3505 case 0x18: /* WEEK_REG */
3506 return s->current_tm.tm_wday;
3508 case 0x20: /* ALARM_SECONDS_REG */
3509 return omap_rtc_bcd(s->alarm_tm.tm_sec);
3511 case 0x24: /* ALARM_MINUTES_REG */
3512 return omap_rtc_bcd(s->alarm_tm.tm_min);
3514 case 0x28: /* ALARM_HOURS_REG */
3516 return ((s->alarm_tm.tm_hour > 11) << 7) |
3517 omap_rtc_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
3519 return omap_rtc_bcd(s->alarm_tm.tm_hour);
3521 case 0x2c: /* ALARM_DAYS_REG */
3522 return omap_rtc_bcd(s->alarm_tm.tm_mday);
3524 case 0x30: /* ALARM_MONTHS_REG */
3525 return omap_rtc_bcd(s->alarm_tm.tm_mon + 1);
3527 case 0x34: /* ALARM_YEARS_REG */
3528 return omap_rtc_bcd(s->alarm_tm.tm_year % 100);
3530 case 0x40: /* RTC_CTRL_REG */
3531 return (s->pm_am << 3) | (s->auto_comp << 2) |
3532 (s->round << 1) | s->running;
3534 case 0x44: /* RTC_STATUS_REG */
3539 case 0x48: /* RTC_INTERRUPTS_REG */
3540 return s->interrupts;
3542 case 0x4c: /* RTC_COMP_LSB_REG */
3543 return ((uint16_t) s->comp_reg) & 0xff;
3545 case 0x50: /* RTC_COMP_MSB_REG */
3546 return ((uint16_t) s->comp_reg) >> 8;
3553 static void omap_rtc_write(void *opaque, target_phys_addr_t addr,
3556 struct omap_rtc_s *s = (struct omap_rtc_s *) opaque;
3557 int offset = addr & OMAP_MPUI_REG_MASK;
3562 case 0x00: /* SECONDS_REG */
3564 printf("RTC SEC_REG <-- %02x\n", value);
3566 s->ti -= s->current_tm.tm_sec;
3567 s->ti += omap_rtc_bin(value);
3570 case 0x04: /* MINUTES_REG */
3572 printf("RTC MIN_REG <-- %02x\n", value);
3574 s->ti -= s->current_tm.tm_min * 60;
3575 s->ti += omap_rtc_bin(value) * 60;
3578 case 0x08: /* HOURS_REG */
3580 printf("RTC HRS_REG <-- %02x\n", value);
3582 s->ti -= s->current_tm.tm_hour * 3600;
3584 s->ti += (omap_rtc_bin(value & 0x3f) & 12) * 3600;
3585 s->ti += ((value >> 7) & 1) * 43200;
3587 s->ti += omap_rtc_bin(value & 0x3f) * 3600;
3590 case 0x0c: /* DAYS_REG */
3592 printf("RTC DAY_REG <-- %02x\n", value);
3594 s->ti -= s->current_tm.tm_mday * 86400;
3595 s->ti += omap_rtc_bin(value) * 86400;
3598 case 0x10: /* MONTHS_REG */
3600 printf("RTC MTH_REG <-- %02x\n", value);
3602 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3603 new_tm.tm_mon = omap_rtc_bin(value);
3604 ti[0] = mktimegm(&s->current_tm);
3605 ti[1] = mktimegm(&new_tm);
3607 if (ti[0] != -1 && ti[1] != -1) {
3611 /* A less accurate version */
3612 s->ti -= s->current_tm.tm_mon * 2592000;
3613 s->ti += omap_rtc_bin(value) * 2592000;
3617 case 0x14: /* YEARS_REG */
3619 printf("RTC YRS_REG <-- %02x\n", value);
3621 memcpy(&new_tm, &s->current_tm, sizeof(new_tm));
3622 new_tm.tm_year += omap_rtc_bin(value) - (new_tm.tm_year % 100);
3623 ti[0] = mktimegm(&s->current_tm);
3624 ti[1] = mktimegm(&new_tm);
3626 if (ti[0] != -1 && ti[1] != -1) {
3630 /* A less accurate version */
3631 s->ti -= (s->current_tm.tm_year % 100) * 31536000;
3632 s->ti += omap_rtc_bin(value) * 31536000;
3636 case 0x18: /* WEEK_REG */
3637 return; /* Ignored */
3639 case 0x20: /* ALARM_SECONDS_REG */
3641 printf("ALM SEC_REG <-- %02x\n", value);
3643 s->alarm_tm.tm_sec = omap_rtc_bin(value);
3644 omap_rtc_alarm_update(s);
3647 case 0x24: /* ALARM_MINUTES_REG */
3649 printf("ALM MIN_REG <-- %02x\n", value);
3651 s->alarm_tm.tm_min = omap_rtc_bin(value);
3652 omap_rtc_alarm_update(s);
3655 case 0x28: /* ALARM_HOURS_REG */
3657 printf("ALM HRS_REG <-- %02x\n", value);
3660 s->alarm_tm.tm_hour =
3661 ((omap_rtc_bin(value & 0x3f)) % 12) +
3662 ((value >> 7) & 1) * 12;
3664 s->alarm_tm.tm_hour = omap_rtc_bin(value);
3665 omap_rtc_alarm_update(s);
3668 case 0x2c: /* ALARM_DAYS_REG */
3670 printf("ALM DAY_REG <-- %02x\n", value);
3672 s->alarm_tm.tm_mday = omap_rtc_bin(value);
3673 omap_rtc_alarm_update(s);
3676 case 0x30: /* ALARM_MONTHS_REG */
3678 printf("ALM MON_REG <-- %02x\n", value);
3680 s->alarm_tm.tm_mon = omap_rtc_bin(value);
3681 omap_rtc_alarm_update(s);
3684 case 0x34: /* ALARM_YEARS_REG */
3686 printf("ALM YRS_REG <-- %02x\n", value);
3688 s->alarm_tm.tm_year = omap_rtc_bin(value);
3689 omap_rtc_alarm_update(s);
3692 case 0x40: /* RTC_CTRL_REG */
3694 printf("RTC CONTROL <-- %02x\n", value);
3696 s->pm_am = (value >> 3) & 1;
3697 s->auto_comp = (value >> 2) & 1;
3698 s->round = (value >> 1) & 1;
3699 s->running = value & 1;
3701 s->status |= s->running << 1;
3704 case 0x44: /* RTC_STATUS_REG */
3706 printf("RTC STATUSL <-- %02x\n", value);
3708 s->status &= ~((value & 0xc0) ^ 0x80);
3709 omap_rtc_interrupts_update(s);
3712 case 0x48: /* RTC_INTERRUPTS_REG */
3714 printf("RTC INTRS <-- %02x\n", value);
3716 s->interrupts = value;
3719 case 0x4c: /* RTC_COMP_LSB_REG */
3721 printf("RTC COMPLSB <-- %02x\n", value);
3723 s->comp_reg &= 0xff00;
3724 s->comp_reg |= 0x00ff & value;
3727 case 0x50: /* RTC_COMP_MSB_REG */
3729 printf("RTC COMPMSB <-- %02x\n", value);
3731 s->comp_reg &= 0x00ff;
3732 s->comp_reg |= 0xff00 & (value << 8);
3741 static CPUReadMemoryFunc *omap_rtc_readfn[] = {
3743 omap_badwidth_read8,
3744 omap_badwidth_read8,
3747 static CPUWriteMemoryFunc *omap_rtc_writefn[] = {
3749 omap_badwidth_write8,
3750 omap_badwidth_write8,
3753 static void omap_rtc_tick(void *opaque)
3755 struct omap_rtc_s *s = opaque;
3758 /* Round to nearest full minute. */
3759 if (s->current_tm.tm_sec < 30)
3760 s->ti -= s->current_tm.tm_sec;
3762 s->ti += 60 - s->current_tm.tm_sec;
3767 memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm));
3769 if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) {
3771 omap_rtc_interrupts_update(s);
3774 if (s->interrupts & 0x04)
3775 switch (s->interrupts & 3) {
3778 qemu_irq_pulse(s->irq);
3781 if (s->current_tm.tm_sec)
3784 qemu_irq_pulse(s->irq);
3787 if (s->current_tm.tm_sec || s->current_tm.tm_min)
3790 qemu_irq_pulse(s->irq);
3793 if (s->current_tm.tm_sec ||
3794 s->current_tm.tm_min || s->current_tm.tm_hour)
3797 qemu_irq_pulse(s->irq);
3807 * Every full hour add a rough approximation of the compensation
3808 * register to the 32kHz Timer (which drives the RTC) value.
3810 if (s->auto_comp && !s->current_tm.tm_sec && !s->current_tm.tm_min)
3811 s->tick += s->comp_reg * 1000 / 32768;
3813 qemu_mod_timer(s->clk, s->tick);
3816 static void omap_rtc_reset(struct omap_rtc_s *s)
3826 s->tick = qemu_get_clock(rt_clock);
3827 memset(&s->alarm_tm, 0, sizeof(s->alarm_tm));
3828 s->alarm_tm.tm_mday = 0x01;
3830 qemu_get_timedate(&tm, 0);
3831 s->ti = mktimegm(&tm);
3833 omap_rtc_alarm_update(s);
3837 struct omap_rtc_s *omap_rtc_init(target_phys_addr_t base,
3838 qemu_irq *irq, omap_clk clk)
3841 struct omap_rtc_s *s = (struct omap_rtc_s *)
3842 qemu_mallocz(sizeof(struct omap_rtc_s));
3846 s->clk = qemu_new_timer(rt_clock, omap_rtc_tick, s);
3850 iomemtype = cpu_register_io_memory(0, omap_rtc_readfn,
3851 omap_rtc_writefn, s);
3852 cpu_register_physical_memory(base, 0x800, iomemtype);
3857 /* Multi-channel Buffered Serial Port interfaces */
3858 struct omap_mcbsp_s {
3877 struct i2s_codec_s *codec;
3878 QEMUTimer *source_timer;
3879 QEMUTimer *sink_timer;
3882 static void omap_mcbsp_intr_update(struct omap_mcbsp_s *s)
3886 switch ((s->spcr[0] >> 4) & 3) { /* RINTM */
3888 irq = (s->spcr[0] >> 1) & 1; /* RRDY */
3891 irq = (s->spcr[0] >> 3) & 1; /* RSYNCERR */
3899 qemu_irq_pulse(s->rxirq);
3901 switch ((s->spcr[1] >> 4) & 3) { /* XINTM */
3903 irq = (s->spcr[1] >> 1) & 1; /* XRDY */
3906 irq = (s->spcr[1] >> 3) & 1; /* XSYNCERR */
3914 qemu_irq_pulse(s->txirq);
3917 static void omap_mcbsp_rx_newdata(struct omap_mcbsp_s *s)
3919 if ((s->spcr[0] >> 1) & 1) /* RRDY */
3920 s->spcr[0] |= 1 << 2; /* RFULL */
3921 s->spcr[0] |= 1 << 1; /* RRDY */
3922 qemu_irq_raise(s->rxdrq);
3923 omap_mcbsp_intr_update(s);
3926 static void omap_mcbsp_source_tick(void *opaque)
3928 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3929 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3934 printf("%s: Rx FIFO overrun\n", __FUNCTION__);
3936 s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7];
3938 omap_mcbsp_rx_newdata(s);
3939 qemu_mod_timer(s->source_timer, qemu_get_clock(vm_clock) + ticks_per_sec);
3942 static void omap_mcbsp_rx_start(struct omap_mcbsp_s *s)
3944 if (!s->codec || !s->codec->rts)
3945 omap_mcbsp_source_tick(s);
3946 else if (s->codec->in.len) {
3947 s->rx_req = s->codec->in.len;
3948 omap_mcbsp_rx_newdata(s);
3952 static void omap_mcbsp_rx_stop(struct omap_mcbsp_s *s)
3954 qemu_del_timer(s->source_timer);
3957 static void omap_mcbsp_rx_done(struct omap_mcbsp_s *s)
3959 s->spcr[0] &= ~(1 << 1); /* RRDY */
3960 qemu_irq_lower(s->rxdrq);
3961 omap_mcbsp_intr_update(s);
3964 static void omap_mcbsp_tx_newdata(struct omap_mcbsp_s *s)
3966 s->spcr[1] |= 1 << 1; /* XRDY */
3967 qemu_irq_raise(s->txdrq);
3968 omap_mcbsp_intr_update(s);
3971 static void omap_mcbsp_sink_tick(void *opaque)
3973 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
3974 static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 };
3979 printf("%s: Tx FIFO underrun\n", __FUNCTION__);
3981 s->tx_req = s->tx_rate << bps[(s->xcr[0] >> 5) & 7];
3983 omap_mcbsp_tx_newdata(s);
3984 qemu_mod_timer(s->sink_timer, qemu_get_clock(vm_clock) + ticks_per_sec);
3987 static void omap_mcbsp_tx_start(struct omap_mcbsp_s *s)
3989 if (!s->codec || !s->codec->cts)
3990 omap_mcbsp_sink_tick(s);
3991 else if (s->codec->out.size) {
3992 s->tx_req = s->codec->out.size;
3993 omap_mcbsp_tx_newdata(s);
3997 static void omap_mcbsp_tx_done(struct omap_mcbsp_s *s)
3999 s->spcr[1] &= ~(1 << 1); /* XRDY */
4000 qemu_irq_lower(s->txdrq);
4001 omap_mcbsp_intr_update(s);
4002 if (s->codec && s->codec->cts)
4003 s->codec->tx_swallow(s->codec->opaque);
4006 static void omap_mcbsp_tx_stop(struct omap_mcbsp_s *s)
4009 omap_mcbsp_tx_done(s);
4010 qemu_del_timer(s->sink_timer);
4013 static void omap_mcbsp_req_update(struct omap_mcbsp_s *s)
4015 int prev_rx_rate, prev_tx_rate;
4016 int rx_rate = 0, tx_rate = 0;
4017 int cpu_rate = 1500000; /* XXX */
4019 /* TODO: check CLKSTP bit */
4020 if (s->spcr[1] & (1 << 6)) { /* GRST */
4021 if (s->spcr[0] & (1 << 0)) { /* RRST */
4022 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
4023 (s->pcr & (1 << 8))) { /* CLKRM */
4024 if (~s->pcr & (1 << 7)) /* SCLKME */
4025 rx_rate = cpu_rate /
4026 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
4029 rx_rate = s->codec->rx_rate;
4032 if (s->spcr[1] & (1 << 0)) { /* XRST */
4033 if ((s->srgr[1] & (1 << 13)) && /* CLKSM */
4034 (s->pcr & (1 << 9))) { /* CLKXM */
4035 if (~s->pcr & (1 << 7)) /* SCLKME */
4036 tx_rate = cpu_rate /
4037 ((s->srgr[0] & 0xff) + 1); /* CLKGDV */
4040 tx_rate = s->codec->tx_rate;
4043 prev_tx_rate = s->tx_rate;
4044 prev_rx_rate = s->rx_rate;
4045 s->tx_rate = tx_rate;
4046 s->rx_rate = rx_rate;
4049 s->codec->set_rate(s->codec->opaque, rx_rate, tx_rate);
4051 if (!prev_tx_rate && tx_rate)
4052 omap_mcbsp_tx_start(s);
4053 else if (s->tx_rate && !tx_rate)
4054 omap_mcbsp_tx_stop(s);
4056 if (!prev_rx_rate && rx_rate)
4057 omap_mcbsp_rx_start(s);
4058 else if (prev_tx_rate && !tx_rate)
4059 omap_mcbsp_rx_stop(s);
4062 static uint32_t omap_mcbsp_read(void *opaque, target_phys_addr_t addr)
4064 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4065 int offset = addr & OMAP_MPUI_REG_MASK;
4069 case 0x00: /* DRR2 */
4070 if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */
4073 case 0x02: /* DRR1 */
4074 if (s->rx_req < 2) {
4075 printf("%s: Rx FIFO underrun\n", __FUNCTION__);
4076 omap_mcbsp_rx_done(s);
4079 if (s->codec && s->codec->in.len >= 2) {
4080 ret = s->codec->in.fifo[s->codec->in.start ++] << 8;
4081 ret |= s->codec->in.fifo[s->codec->in.start ++];
4082 s->codec->in.len -= 2;
4086 omap_mcbsp_rx_done(s);
4091 case 0x04: /* DXR2 */
4092 case 0x06: /* DXR1 */
4095 case 0x08: /* SPCR2 */
4097 case 0x0a: /* SPCR1 */
4099 case 0x0c: /* RCR2 */
4101 case 0x0e: /* RCR1 */
4103 case 0x10: /* XCR2 */
4105 case 0x12: /* XCR1 */
4107 case 0x14: /* SRGR2 */
4109 case 0x16: /* SRGR1 */
4111 case 0x18: /* MCR2 */
4113 case 0x1a: /* MCR1 */
4115 case 0x1c: /* RCERA */
4117 case 0x1e: /* RCERB */
4119 case 0x20: /* XCERA */
4121 case 0x22: /* XCERB */
4123 case 0x24: /* PCR0 */
4125 case 0x26: /* RCERC */
4127 case 0x28: /* RCERD */
4129 case 0x2a: /* XCERC */
4131 case 0x2c: /* XCERD */
4133 case 0x2e: /* RCERE */
4135 case 0x30: /* RCERF */
4137 case 0x32: /* XCERE */
4139 case 0x34: /* XCERF */
4141 case 0x36: /* RCERG */
4143 case 0x38: /* RCERH */
4145 case 0x3a: /* XCERG */
4147 case 0x3c: /* XCERH */
4155 static void omap_mcbsp_writeh(void *opaque, target_phys_addr_t addr,
4158 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4159 int offset = addr & OMAP_MPUI_REG_MASK;
4162 case 0x00: /* DRR2 */
4163 case 0x02: /* DRR1 */
4167 case 0x04: /* DXR2 */
4168 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
4171 case 0x06: /* DXR1 */
4172 if (s->tx_req > 1) {
4174 if (s->codec && s->codec->cts) {
4175 s->codec->out.fifo[s->codec->out.len ++] = (value >> 8) & 0xff;
4176 s->codec->out.fifo[s->codec->out.len ++] = (value >> 0) & 0xff;
4179 omap_mcbsp_tx_done(s);
4181 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
4184 case 0x08: /* SPCR2 */
4185 s->spcr[1] &= 0x0002;
4186 s->spcr[1] |= 0x03f9 & value;
4187 s->spcr[1] |= 0x0004 & (value << 2); /* XEMPTY := XRST */
4188 if (~value & 1) /* XRST */
4190 omap_mcbsp_req_update(s);
4192 case 0x0a: /* SPCR1 */
4193 s->spcr[0] &= 0x0006;
4194 s->spcr[0] |= 0xf8f9 & value;
4195 if (value & (1 << 15)) /* DLB */
4196 printf("%s: Digital Loopback mode enable attempt\n", __FUNCTION__);
4197 if (~value & 1) { /* RRST */
4200 omap_mcbsp_rx_done(s);
4202 omap_mcbsp_req_update(s);
4205 case 0x0c: /* RCR2 */
4206 s->rcr[1] = value & 0xffff;
4208 case 0x0e: /* RCR1 */
4209 s->rcr[0] = value & 0x7fe0;
4211 case 0x10: /* XCR2 */
4212 s->xcr[1] = value & 0xffff;
4214 case 0x12: /* XCR1 */
4215 s->xcr[0] = value & 0x7fe0;
4217 case 0x14: /* SRGR2 */
4218 s->srgr[1] = value & 0xffff;
4219 omap_mcbsp_req_update(s);
4221 case 0x16: /* SRGR1 */
4222 s->srgr[0] = value & 0xffff;
4223 omap_mcbsp_req_update(s);
4225 case 0x18: /* MCR2 */
4226 s->mcr[1] = value & 0x03e3;
4227 if (value & 3) /* XMCM */
4228 printf("%s: Tx channel selection mode enable attempt\n",
4231 case 0x1a: /* MCR1 */
4232 s->mcr[0] = value & 0x03e1;
4233 if (value & 1) /* RMCM */
4234 printf("%s: Rx channel selection mode enable attempt\n",
4237 case 0x1c: /* RCERA */
4238 s->rcer[0] = value & 0xffff;
4240 case 0x1e: /* RCERB */
4241 s->rcer[1] = value & 0xffff;
4243 case 0x20: /* XCERA */
4244 s->xcer[0] = value & 0xffff;
4246 case 0x22: /* XCERB */
4247 s->xcer[1] = value & 0xffff;
4249 case 0x24: /* PCR0 */
4250 s->pcr = value & 0x7faf;
4252 case 0x26: /* RCERC */
4253 s->rcer[2] = value & 0xffff;
4255 case 0x28: /* RCERD */
4256 s->rcer[3] = value & 0xffff;
4258 case 0x2a: /* XCERC */
4259 s->xcer[2] = value & 0xffff;
4261 case 0x2c: /* XCERD */
4262 s->xcer[3] = value & 0xffff;
4264 case 0x2e: /* RCERE */
4265 s->rcer[4] = value & 0xffff;
4267 case 0x30: /* RCERF */
4268 s->rcer[5] = value & 0xffff;
4270 case 0x32: /* XCERE */
4271 s->xcer[4] = value & 0xffff;
4273 case 0x34: /* XCERF */
4274 s->xcer[5] = value & 0xffff;
4276 case 0x36: /* RCERG */
4277 s->rcer[6] = value & 0xffff;
4279 case 0x38: /* RCERH */
4280 s->rcer[7] = value & 0xffff;
4282 case 0x3a: /* XCERG */
4283 s->xcer[6] = value & 0xffff;
4285 case 0x3c: /* XCERH */
4286 s->xcer[7] = value & 0xffff;
4293 static void omap_mcbsp_writew(void *opaque, target_phys_addr_t addr,
4296 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4297 int offset = addr & OMAP_MPUI_REG_MASK;
4299 if (offset == 0x04) { /* DXR */
4300 if (((s->xcr[0] >> 5) & 7) < 3) /* XWDLEN1 */
4302 if (s->tx_req > 3) {
4304 if (s->codec && s->codec->cts) {
4305 s->codec->out.fifo[s->codec->out.len ++] =
4306 (value >> 24) & 0xff;
4307 s->codec->out.fifo[s->codec->out.len ++] =
4308 (value >> 16) & 0xff;
4309 s->codec->out.fifo[s->codec->out.len ++] =
4310 (value >> 8) & 0xff;
4311 s->codec->out.fifo[s->codec->out.len ++] =
4312 (value >> 0) & 0xff;
4315 omap_mcbsp_tx_done(s);
4317 printf("%s: Tx FIFO overrun\n", __FUNCTION__);
4321 omap_badwidth_write16(opaque, addr, value);
4324 static CPUReadMemoryFunc *omap_mcbsp_readfn[] = {
4325 omap_badwidth_read16,
4327 omap_badwidth_read16,
4330 static CPUWriteMemoryFunc *omap_mcbsp_writefn[] = {
4331 omap_badwidth_write16,
4336 static void omap_mcbsp_reset(struct omap_mcbsp_s *s)
4338 memset(&s->spcr, 0, sizeof(s->spcr));
4339 memset(&s->rcr, 0, sizeof(s->rcr));
4340 memset(&s->xcr, 0, sizeof(s->xcr));
4341 s->srgr[0] = 0x0001;
4342 s->srgr[1] = 0x2000;
4343 memset(&s->mcr, 0, sizeof(s->mcr));
4344 memset(&s->pcr, 0, sizeof(s->pcr));
4345 memset(&s->rcer, 0, sizeof(s->rcer));
4346 memset(&s->xcer, 0, sizeof(s->xcer));
4351 qemu_del_timer(s->source_timer);
4352 qemu_del_timer(s->sink_timer);
4355 struct omap_mcbsp_s *omap_mcbsp_init(target_phys_addr_t base,
4356 qemu_irq *irq, qemu_irq *dma, omap_clk clk)
4359 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *)
4360 qemu_mallocz(sizeof(struct omap_mcbsp_s));
4366 s->sink_timer = qemu_new_timer(vm_clock, omap_mcbsp_sink_tick, s);
4367 s->source_timer = qemu_new_timer(vm_clock, omap_mcbsp_source_tick, s);
4368 omap_mcbsp_reset(s);
4370 iomemtype = cpu_register_io_memory(0, omap_mcbsp_readfn,
4371 omap_mcbsp_writefn, s);
4372 cpu_register_physical_memory(base, 0x800, iomemtype);
4377 static void omap_mcbsp_i2s_swallow(void *opaque, int line, int level)
4379 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4382 s->rx_req = s->codec->in.len;
4383 omap_mcbsp_rx_newdata(s);
4387 static void omap_mcbsp_i2s_start(void *opaque, int line, int level)
4389 struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque;
4392 s->tx_req = s->codec->out.size;
4393 omap_mcbsp_tx_newdata(s);
4397 void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, struct i2s_codec_s *slave)
4400 slave->rx_swallow = qemu_allocate_irqs(omap_mcbsp_i2s_swallow, s, 1)[0];
4401 slave->tx_start = qemu_allocate_irqs(omap_mcbsp_i2s_start, s, 1)[0];
4404 /* LED Pulse Generators */
4416 static void omap_lpg_tick(void *opaque)
4418 struct omap_lpg_s *s = opaque;
4421 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->period - s->on);
4423 qemu_mod_timer(s->tm, qemu_get_clock(rt_clock) + s->on);
4425 s->cycle = !s->cycle;
4426 printf("%s: LED is %s\n", __FUNCTION__, s->cycle ? "on" : "off");
4429 static void omap_lpg_update(struct omap_lpg_s *s)
4431 int64_t on, period = 1, ticks = 1000;
4432 static const int per[8] = { 1, 2, 4, 8, 12, 16, 20, 24 };
4434 if (~s->control & (1 << 6)) /* LPGRES */
4436 else if (s->control & (1 << 7)) /* PERM_ON */
4439 period = muldiv64(ticks, per[s->control & 7], /* PERCTRL */
4441 on = (s->clk && s->power) ? muldiv64(ticks,
4442 per[(s->control >> 3) & 7], 256) : 0; /* ONCTRL */
4445 qemu_del_timer(s->tm);
4446 if (on == period && s->on < s->period)
4447 printf("%s: LED is on\n", __FUNCTION__);
4448 else if (on == 0 && s->on)
4449 printf("%s: LED is off\n", __FUNCTION__);
4450 else if (on && (on != s->on || period != s->period)) {
4462 static void omap_lpg_reset(struct omap_lpg_s *s)
4470 static uint32_t omap_lpg_read(void *opaque, target_phys_addr_t addr)
4472 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4473 int offset = addr & OMAP_MPUI_REG_MASK;
4476 case 0x00: /* LCR */
4479 case 0x04: /* PMR */
4487 static void omap_lpg_write(void *opaque, target_phys_addr_t addr,
4490 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4491 int offset = addr & OMAP_MPUI_REG_MASK;
4494 case 0x00: /* LCR */
4495 if (~value & (1 << 6)) /* LPGRES */
4497 s->control = value & 0xff;
4501 case 0x04: /* PMR */
4502 s->power = value & 0x01;
4512 static CPUReadMemoryFunc *omap_lpg_readfn[] = {
4514 omap_badwidth_read8,
4515 omap_badwidth_read8,
4518 static CPUWriteMemoryFunc *omap_lpg_writefn[] = {
4520 omap_badwidth_write8,
4521 omap_badwidth_write8,
4524 static void omap_lpg_clk_update(void *opaque, int line, int on)
4526 struct omap_lpg_s *s = (struct omap_lpg_s *) opaque;
4532 struct omap_lpg_s *omap_lpg_init(target_phys_addr_t base, omap_clk clk)
4535 struct omap_lpg_s *s = (struct omap_lpg_s *)
4536 qemu_mallocz(sizeof(struct omap_lpg_s));
4538 s->tm = qemu_new_timer(rt_clock, omap_lpg_tick, s);
4542 iomemtype = cpu_register_io_memory(0, omap_lpg_readfn,
4543 omap_lpg_writefn, s);
4544 cpu_register_physical_memory(base, 0x800, iomemtype);
4546 omap_clk_adduser(clk, qemu_allocate_irqs(omap_lpg_clk_update, s, 1)[0]);
4551 /* MPUI Peripheral Bridge configuration */
4552 static uint32_t omap_mpui_io_read(void *opaque, target_phys_addr_t addr)
4554 if (addr == OMAP_MPUI_BASE) /* CMR */
4561 static CPUReadMemoryFunc *omap_mpui_io_readfn[] = {
4562 omap_badwidth_read16,
4564 omap_badwidth_read16,
4567 static CPUWriteMemoryFunc *omap_mpui_io_writefn[] = {
4568 omap_badwidth_write16,
4569 omap_badwidth_write16,
4570 omap_badwidth_write16,
4573 static void omap_setup_mpui_io(struct omap_mpu_state_s *mpu)
4575 int iomemtype = cpu_register_io_memory(0, omap_mpui_io_readfn,
4576 omap_mpui_io_writefn, mpu);
4577 cpu_register_physical_memory(OMAP_MPUI_BASE, 0x7fff, iomemtype);
4580 /* General chip reset */
4581 static void omap1_mpu_reset(void *opaque)
4583 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4585 omap_inth_reset(mpu->ih[0]);
4586 omap_inth_reset(mpu->ih[1]);
4587 omap_dma_reset(mpu->dma);
4588 omap_mpu_timer_reset(mpu->timer[0]);
4589 omap_mpu_timer_reset(mpu->timer[1]);
4590 omap_mpu_timer_reset(mpu->timer[2]);
4591 omap_wd_timer_reset(mpu->wdt);
4592 omap_os_timer_reset(mpu->os_timer);
4593 omap_lcdc_reset(mpu->lcd);
4594 omap_ulpd_pm_reset(mpu);
4595 omap_pin_cfg_reset(mpu);
4596 omap_mpui_reset(mpu);
4597 omap_tipb_bridge_reset(mpu->private_tipb);
4598 omap_tipb_bridge_reset(mpu->public_tipb);
4599 omap_dpll_reset(&mpu->dpll[0]);
4600 omap_dpll_reset(&mpu->dpll[1]);
4601 omap_dpll_reset(&mpu->dpll[2]);
4602 omap_uart_reset(mpu->uart[0]);
4603 omap_uart_reset(mpu->uart[1]);
4604 omap_uart_reset(mpu->uart[2]);
4605 omap_mmc_reset(mpu->mmc);
4606 omap_mpuio_reset(mpu->mpuio);
4607 omap_gpio_reset(mpu->gpio);
4608 omap_uwire_reset(mpu->microwire);
4609 omap_pwl_reset(mpu);
4610 omap_pwt_reset(mpu);
4611 omap_i2c_reset(mpu->i2c[0]);
4612 omap_rtc_reset(mpu->rtc);
4613 omap_mcbsp_reset(mpu->mcbsp1);
4614 omap_mcbsp_reset(mpu->mcbsp2);
4615 omap_mcbsp_reset(mpu->mcbsp3);
4616 omap_lpg_reset(mpu->led[0]);
4617 omap_lpg_reset(mpu->led[1]);
4618 omap_clkm_reset(mpu);
4619 cpu_reset(mpu->env);
4622 static const struct omap_map_s {
4623 target_phys_addr_t phys_dsp;
4624 target_phys_addr_t phys_mpu;
4627 } omap15xx_dsp_mm[] = {
4629 { 0xe1010000, 0xfffb0000, 0x800, "UART1 BT" }, /* CS0 */
4630 { 0xe1010800, 0xfffb0800, 0x800, "UART2 COM" }, /* CS1 */
4631 { 0xe1011800, 0xfffb1800, 0x800, "McBSP1 audio" }, /* CS3 */
4632 { 0xe1012000, 0xfffb2000, 0x800, "MCSI2 communication" }, /* CS4 */
4633 { 0xe1012800, 0xfffb2800, 0x800, "MCSI1 BT u-Law" }, /* CS5 */
4634 { 0xe1013000, 0xfffb3000, 0x800, "uWire" }, /* CS6 */
4635 { 0xe1013800, 0xfffb3800, 0x800, "I^2C" }, /* CS7 */
4636 { 0xe1014000, 0xfffb4000, 0x800, "USB W2FC" }, /* CS8 */
4637 { 0xe1014800, 0xfffb4800, 0x800, "RTC" }, /* CS9 */
4638 { 0xe1015000, 0xfffb5000, 0x800, "MPUIO" }, /* CS10 */
4639 { 0xe1015800, 0xfffb5800, 0x800, "PWL" }, /* CS11 */
4640 { 0xe1016000, 0xfffb6000, 0x800, "PWT" }, /* CS12 */
4641 { 0xe1017000, 0xfffb7000, 0x800, "McBSP3" }, /* CS14 */
4642 { 0xe1017800, 0xfffb7800, 0x800, "MMC" }, /* CS15 */
4643 { 0xe1019000, 0xfffb9000, 0x800, "32-kHz timer" }, /* CS18 */
4644 { 0xe1019800, 0xfffb9800, 0x800, "UART3" }, /* CS19 */
4645 { 0xe101c800, 0xfffbc800, 0x800, "TIPB switches" }, /* CS25 */
4647 { 0xe101e000, 0xfffce000, 0x800, "GPIOs" }, /* CS28 */
4652 static void omap_setup_dsp_mapping(const struct omap_map_s *map)
4656 for (; map->phys_dsp; map ++) {
4657 io = cpu_get_physical_page_desc(map->phys_mpu);
4659 cpu_register_physical_memory(map->phys_dsp, map->size, io);
4663 void omap_mpu_wakeup(void *opaque, int irq, int req)
4665 struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
4667 if (mpu->env->halted)
4668 cpu_interrupt(mpu->env, CPU_INTERRUPT_EXITTB);
4671 static const struct dma_irq_map omap1_dma_irq_map[] = {
4672 { 0, OMAP_INT_DMA_CH0_6 },
4673 { 0, OMAP_INT_DMA_CH1_7 },
4674 { 0, OMAP_INT_DMA_CH2_8 },
4675 { 0, OMAP_INT_DMA_CH3 },
4676 { 0, OMAP_INT_DMA_CH4 },
4677 { 0, OMAP_INT_DMA_CH5 },
4678 { 1, OMAP_INT_1610_DMA_CH6 },
4679 { 1, OMAP_INT_1610_DMA_CH7 },
4680 { 1, OMAP_INT_1610_DMA_CH8 },
4681 { 1, OMAP_INT_1610_DMA_CH9 },
4682 { 1, OMAP_INT_1610_DMA_CH10 },
4683 { 1, OMAP_INT_1610_DMA_CH11 },
4684 { 1, OMAP_INT_1610_DMA_CH12 },
4685 { 1, OMAP_INT_1610_DMA_CH13 },
4686 { 1, OMAP_INT_1610_DMA_CH14 },
4687 { 1, OMAP_INT_1610_DMA_CH15 }
4690 /* DMA ports for OMAP1 */
4691 static int omap_validate_emiff_addr(struct omap_mpu_state_s *s,
4692 target_phys_addr_t addr)
4694 return addr >= OMAP_EMIFF_BASE && addr < OMAP_EMIFF_BASE + s->sdram_size;
4697 static int omap_validate_emifs_addr(struct omap_mpu_state_s *s,
4698 target_phys_addr_t addr)
4700 return addr >= OMAP_EMIFS_BASE && addr < OMAP_EMIFF_BASE;
4703 static int omap_validate_imif_addr(struct omap_mpu_state_s *s,
4704 target_phys_addr_t addr)
4706 return addr >= OMAP_IMIF_BASE && addr < OMAP_IMIF_BASE + s->sram_size;
4709 static int omap_validate_tipb_addr(struct omap_mpu_state_s *s,
4710 target_phys_addr_t addr)
4712 return addr >= 0xfffb0000 && addr < 0xffff0000;
4715 static int omap_validate_local_addr(struct omap_mpu_state_s *s,
4716 target_phys_addr_t addr)
4718 return addr >= OMAP_LOCALBUS_BASE && addr < OMAP_LOCALBUS_BASE + 0x1000000;
4721 static int omap_validate_tipb_mpui_addr(struct omap_mpu_state_s *s,
4722 target_phys_addr_t addr)
4724 return addr >= 0xe1010000 && addr < 0xe1020004;
4727 struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,
4731 struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
4732 qemu_mallocz(sizeof(struct omap_mpu_state_s));
4733 ram_addr_t imif_base, emiff_base;
4735 qemu_irq dma_irqs[6];
4742 s->mpu_model = omap310;
4743 s->env = cpu_init(core);
4745 fprintf(stderr, "Unable to find CPU definition\n");
4748 s->sdram_size = sdram_size;
4749 s->sram_size = OMAP15XX_SRAM_SIZE;
4751 s->wakeup = qemu_allocate_irqs(omap_mpu_wakeup, s, 1)[0];
4756 /* Memory-mapped stuff */
4757 cpu_register_physical_memory(OMAP_EMIFF_BASE, s->sdram_size,
4758 (emiff_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
4759 cpu_register_physical_memory(OMAP_IMIF_BASE, s->sram_size,
4760 (imif_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
4762 omap_clkm_init(0xfffece00, 0xe1008000, s);
4764 cpu_irq = arm_pic_init_cpu(s->env);
4765 s->ih[0] = omap_inth_init(0xfffecb00, 0x100, 1, &s->irq[0],
4766 cpu_irq[ARM_PIC_CPU_IRQ], cpu_irq[ARM_PIC_CPU_FIQ],
4767 omap_findclk(s, "arminth_ck"));
4768 s->ih[1] = omap_inth_init(0xfffe0000, 0x800, 1, &s->irq[1],
4769 s->ih[0]->pins[OMAP_INT_15XX_IH2_IRQ], NULL,
4770 omap_findclk(s, "arminth_ck"));
4772 for (i = 0; i < 6; i ++)
4774 s->irq[omap1_dma_irq_map[i].ih][omap1_dma_irq_map[i].intr];
4775 s->dma = omap_dma_init(0xfffed800, dma_irqs, s->irq[0][OMAP_INT_DMA_LCD],
4776 s, omap_findclk(s, "dma_ck"), omap_dma_3_1);
4778 s->port[emiff ].addr_valid = omap_validate_emiff_addr;
4779 s->port[emifs ].addr_valid = omap_validate_emifs_addr;
4780 s->port[imif ].addr_valid = omap_validate_imif_addr;
4781 s->port[tipb ].addr_valid = omap_validate_tipb_addr;
4782 s->port[local ].addr_valid = omap_validate_local_addr;
4783 s->port[tipb_mpui].addr_valid = omap_validate_tipb_mpui_addr;
4785 /* Register SDRAM and SRAM DMA ports for fast transfers. */
4786 soc_dma_port_add_mem_ram(s->dma,
4787 emiff_base, OMAP_EMIFF_BASE, s->sdram_size);
4788 soc_dma_port_add_mem_ram(s->dma,
4789 imif_base, OMAP_IMIF_BASE, s->sram_size);
4791 s->timer[0] = omap_mpu_timer_init(0xfffec500,
4792 s->irq[0][OMAP_INT_TIMER1],
4793 omap_findclk(s, "mputim_ck"));
4794 s->timer[1] = omap_mpu_timer_init(0xfffec600,
4795 s->irq[0][OMAP_INT_TIMER2],
4796 omap_findclk(s, "mputim_ck"));
4797 s->timer[2] = omap_mpu_timer_init(0xfffec700,
4798 s->irq[0][OMAP_INT_TIMER3],
4799 omap_findclk(s, "mputim_ck"));
4801 s->wdt = omap_wd_timer_init(0xfffec800,
4802 s->irq[0][OMAP_INT_WD_TIMER],
4803 omap_findclk(s, "armwdt_ck"));
4805 s->os_timer = omap_os_timer_init(0xfffb9000,
4806 s->irq[1][OMAP_INT_OS_TIMER],
4807 omap_findclk(s, "clk32-kHz"));
4809 s->lcd = omap_lcdc_init(0xfffec000, s->irq[0][OMAP_INT_LCD_CTRL],
4810 omap_dma_get_lcdch(s->dma), imif_base, emiff_base,
4811 omap_findclk(s, "lcd_ck"));
4813 omap_ulpd_pm_init(0xfffe0800, s);
4814 omap_pin_cfg_init(0xfffe1000, s);
4817 omap_mpui_init(0xfffec900, s);
4819 s->private_tipb = omap_tipb_bridge_init(0xfffeca00,
4820 s->irq[0][OMAP_INT_BRIDGE_PRIV],
4821 omap_findclk(s, "tipb_ck"));
4822 s->public_tipb = omap_tipb_bridge_init(0xfffed300,
4823 s->irq[0][OMAP_INT_BRIDGE_PUB],
4824 omap_findclk(s, "tipb_ck"));
4826 omap_tcmi_init(0xfffecc00, s);
4828 s->uart[0] = omap_uart_init(0xfffb0000, s->irq[1][OMAP_INT_UART1],
4829 omap_findclk(s, "uart1_ck"),
4830 omap_findclk(s, "uart1_ck"),
4831 s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
4833 s->uart[1] = omap_uart_init(0xfffb0800, s->irq[1][OMAP_INT_UART2],
4834 omap_findclk(s, "uart2_ck"),
4835 omap_findclk(s, "uart2_ck"),
4836 s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
4837 serial_hds[0] ? serial_hds[1] : 0);
4838 s->uart[2] = omap_uart_init(0xfffb9800, s->irq[0][OMAP_INT_UART3],
4839 omap_findclk(s, "uart3_ck"),
4840 omap_findclk(s, "uart3_ck"),
4841 s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX],
4842 serial_hds[0] && serial_hds[1] ? serial_hds[2] : 0);
4844 omap_dpll_init(&s->dpll[0], 0xfffecf00, omap_findclk(s, "dpll1"));
4845 omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2"));
4846 omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3"));
4848 sdindex = drive_get_index(IF_SD, 0, 0);
4849 if (sdindex == -1) {
4850 fprintf(stderr, "qemu: missing SecureDigital device\n");
4853 s->mmc = omap_mmc_init(0xfffb7800, drives_table[sdindex].bdrv,
4854 s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX],
4855 omap_findclk(s, "mmc_ck"));
4857 s->mpuio = omap_mpuio_init(0xfffb5000,
4858 s->irq[1][OMAP_INT_KEYBOARD], s->irq[1][OMAP_INT_MPUIO],
4859 s->wakeup, omap_findclk(s, "clk32-kHz"));
4861 s->gpio = omap_gpio_init(0xfffce000, s->irq[0][OMAP_INT_GPIO_BANK1],
4862 omap_findclk(s, "arm_gpio_ck"));
4864 s->microwire = omap_uwire_init(0xfffb3000, &s->irq[1][OMAP_INT_uWireTX],
4865 s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
4867 omap_pwl_init(0xfffb5800, s, omap_findclk(s, "armxor_ck"));
4868 omap_pwt_init(0xfffb6000, s, omap_findclk(s, "armxor_ck"));
4870 s->i2c[0] = omap_i2c_init(0xfffb3800, s->irq[1][OMAP_INT_I2C],
4871 &s->drq[OMAP_DMA_I2C_RX], omap_findclk(s, "mpuper_ck"));
4873 s->rtc = omap_rtc_init(0xfffb4800, &s->irq[1][OMAP_INT_RTC_TIMER],
4874 omap_findclk(s, "clk32-kHz"));
4876 s->mcbsp1 = omap_mcbsp_init(0xfffb1800, &s->irq[1][OMAP_INT_McBSP1TX],
4877 &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
4878 s->mcbsp2 = omap_mcbsp_init(0xfffb1000, &s->irq[0][OMAP_INT_310_McBSP2_TX],
4879 &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
4880 s->mcbsp3 = omap_mcbsp_init(0xfffb7000, &s->irq[1][OMAP_INT_McBSP3TX],
4881 &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
4883 s->led[0] = omap_lpg_init(0xfffbd000, omap_findclk(s, "clk32-kHz"));
4884 s->led[1] = omap_lpg_init(0xfffbd800, omap_findclk(s, "clk32-kHz"));
4886 /* Register mappings not currenlty implemented:
4887 * MCSI2 Comm fffb2000 - fffb27ff (not mapped on OMAP310)
4888 * MCSI1 Bluetooth fffb2800 - fffb2fff (not mapped on OMAP310)
4889 * USB W2FC fffb4000 - fffb47ff
4890 * Camera Interface fffb6800 - fffb6fff
4891 * USB Host fffba000 - fffba7ff
4892 * FAC fffba800 - fffbafff
4893 * HDQ/1-Wire fffbc000 - fffbc7ff
4894 * TIPB switches fffbc800 - fffbcfff
4895 * Mailbox fffcf000 - fffcf7ff
4896 * Local bus IF fffec100 - fffec1ff
4897 * Local bus MMU fffec200 - fffec2ff
4898 * DSP MMU fffed200 - fffed2ff
4901 omap_setup_dsp_mapping(omap15xx_dsp_mm);
4902 omap_setup_mpui_io(s);
4904 qemu_register_reset(omap1_mpu_reset, s);