2 * Intel XScale PXA255/270 processor support.
4 * Copyright (c) 2006 Openedhand Ltd.
5 * Written by Andrzej Zaborowski <balrog@zabor.org>
7 * This code is licenced under the GPL.
13 target_phys_addr_t io_base
;
16 { 0x40100000, PXA2XX_PIC_FFUART
},
17 { 0x40200000, PXA2XX_PIC_BTUART
},
18 { 0x40700000, PXA2XX_PIC_STUART
},
19 { 0x41600000, PXA25X_PIC_HWUART
},
21 }, pxa270_serial
[] = {
22 { 0x40100000, PXA2XX_PIC_FFUART
},
23 { 0x40200000, PXA2XX_PIC_BTUART
},
24 { 0x40700000, PXA2XX_PIC_STUART
},
29 target_phys_addr_t io_base
;
32 { 0x41000000, PXA2XX_PIC_SSP
},
35 { 0x41000000, PXA2XX_PIC_SSP
},
36 { 0x41400000, PXA25X_PIC_NSSP
},
39 { 0x41000000, PXA2XX_PIC_SSP
},
40 { 0x41400000, PXA25X_PIC_NSSP
},
41 { 0x41500000, PXA26X_PIC_ASSP
},
44 { 0x41000000, PXA2XX_PIC_SSP
},
45 { 0x41700000, PXA27X_PIC_SSP2
},
46 { 0x41900000, PXA2XX_PIC_SSP3
},
50 #define PMCR 0x00 /* Power Manager Control register */
51 #define PSSR 0x04 /* Power Manager Sleep Status register */
52 #define PSPR 0x08 /* Power Manager Scratch-Pad register */
53 #define PWER 0x0c /* Power Manager Wake-Up Enable register */
54 #define PRER 0x10 /* Power Manager Rising-Edge Detect Enable register */
55 #define PFER 0x14 /* Power Manager Falling-Edge Detect Enable register */
56 #define PEDR 0x18 /* Power Manager Edge-Detect Status register */
57 #define PCFR 0x1c /* Power Manager General Configuration register */
58 #define PGSR0 0x20 /* Power Manager GPIO Sleep-State register 0 */
59 #define PGSR1 0x24 /* Power Manager GPIO Sleep-State register 1 */
60 #define PGSR2 0x28 /* Power Manager GPIO Sleep-State register 2 */
61 #define PGSR3 0x2c /* Power Manager GPIO Sleep-State register 3 */
62 #define RCSR 0x30 /* Reset Controller Status register */
63 #define PSLR 0x34 /* Power Manager Sleep Configuration register */
64 #define PTSR 0x38 /* Power Manager Standby Configuration register */
65 #define PVCR 0x40 /* Power Manager Voltage Change Control register */
66 #define PUCR 0x4c /* Power Manager USIM Card Control/Status register */
67 #define PKWR 0x50 /* Power Manager Keyboard Wake-Up Enable register */
68 #define PKSR 0x54 /* Power Manager Keyboard Level-Detect Status */
69 #define PCMD0 0x80 /* Power Manager I2C Command register File 0 */
70 #define PCMD31 0xfc /* Power Manager I2C Command register File 31 */
72 static uint32_t pxa2xx_pm_read(void *opaque
, target_phys_addr_t addr
)
74 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
82 return s
->pm_regs
[addr
>> 2];
85 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
91 static void pxa2xx_pm_write(void *opaque
, target_phys_addr_t addr
,
94 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
99 s
->pm_regs
[addr
>> 2] &= 0x15 & ~(value
& 0x2a);
100 s
->pm_regs
[addr
>> 2] |= value
& 0x15;
103 case PSSR
: /* Read-clean registers */
106 s
->pm_regs
[addr
>> 2] &= ~value
;
109 default: /* Read-write registers */
110 if (addr
>= PMCR
&& addr
<= PCMD31
&& !(addr
& 3)) {
111 s
->pm_regs
[addr
>> 2] = value
;
115 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
120 static CPUReadMemoryFunc
*pxa2xx_pm_readfn
[] = {
126 static CPUWriteMemoryFunc
*pxa2xx_pm_writefn
[] = {
132 #define CCCR 0x00 /* Core Clock Configuration register */
133 #define CKEN 0x04 /* Clock Enable register */
134 #define OSCC 0x08 /* Oscillator Configuration register */
135 #define CCSR 0x0c /* Core Clock Status register */
137 static uint32_t pxa2xx_cm_read(void *opaque
, target_phys_addr_t addr
)
139 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
146 return s
->cm_regs
[addr
>> 2];
149 return s
->cm_regs
[CCCR
>> 2] | (3 << 28);
152 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
158 static void pxa2xx_cm_write(void *opaque
, target_phys_addr_t addr
,
161 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
167 s
->cm_regs
[addr
>> 2] = value
;
171 s
->cm_regs
[addr
>> 2] &= ~0x6e;
172 s
->cm_regs
[addr
>> 2] |= value
& 0x6e;
176 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
181 static CPUReadMemoryFunc
*pxa2xx_cm_readfn
[] = {
187 static CPUWriteMemoryFunc
*pxa2xx_cm_writefn
[] = {
193 static uint32_t pxa2xx_clkpwr_read(void *opaque
, int op2
, int reg
, int crm
)
195 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
198 case 6: /* Clock Configuration register */
201 case 7: /* Power Mode register */
205 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
211 static void pxa2xx_clkpwr_write(void *opaque
, int op2
, int reg
, int crm
,
214 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
215 static const char *pwrmode
[8] = {
216 "Normal", "Idle", "Deep-idle", "Standby",
217 "Sleep", "reserved (!)", "reserved (!)", "Deep-sleep",
221 case 6: /* Clock Configuration register */
222 s
->clkcfg
= value
& 0xf;
224 printf("%s: CPU frequency change attempt\n", __FUNCTION__
);
227 case 7: /* Power Mode register */
229 printf("%s: CPU voltage change attempt\n", __FUNCTION__
);
237 if (!(s
->cm_regs
[CCCR
] & (1 << 31))) { /* CPDIS */
238 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
245 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
246 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
250 s
->env
->uncached_cpsr
=
251 ARM_CPU_MODE_SVC
| CPSR_A
| CPSR_F
| CPSR_I
;
252 s
->env
->cp15
.c1_sys
= 0;
253 s
->env
->cp15
.c1_coproc
= 0;
254 s
->env
->cp15
.c2_base
= 0;
256 s
->pm_regs
[PSSR
>> 2] |= 0x8; /* Set STS */
257 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
260 * The scratch-pad register is almost universally used
261 * for storing the return address on suspend. For the
262 * lack of a resuming bootloader, perform a jump
263 * directly to that address.
265 memset(s
->env
->regs
, 0, 4 * 15);
266 s
->env
->regs
[15] = s
->pm_regs
[PSPR
>> 2];
269 buffer
= 0xe59ff000; /* ldr pc, [pc, #0] */
270 cpu_physical_memory_write(0, &buffer
, 4);
271 buffer
= s
->pm_regs
[PSPR
>> 2];
272 cpu_physical_memory_write(8, &buffer
, 4);
276 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_HALT
);
282 printf("%s: machine entered %s mode\n", __FUNCTION__
,
288 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
293 /* Performace Monitoring Registers */
294 #define CPPMNC 0 /* Performance Monitor Control register */
295 #define CPCCNT 1 /* Clock Counter register */
296 #define CPINTEN 4 /* Interrupt Enable register */
297 #define CPFLAG 5 /* Overflow Flag register */
298 #define CPEVTSEL 8 /* Event Selection register */
300 #define CPPMN0 0 /* Performance Count register 0 */
301 #define CPPMN1 1 /* Performance Count register 1 */
302 #define CPPMN2 2 /* Performance Count register 2 */
303 #define CPPMN3 3 /* Performance Count register 3 */
305 static uint32_t pxa2xx_perf_read(void *opaque
, int op2
, int reg
, int crm
)
307 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
314 return qemu_get_clock(vm_clock
);
323 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
329 static void pxa2xx_perf_write(void *opaque
, int op2
, int reg
, int crm
,
332 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
346 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
351 static uint32_t pxa2xx_cp14_read(void *opaque
, int op2
, int reg
, int crm
)
355 return pxa2xx_clkpwr_read(opaque
, op2
, reg
, crm
);
357 return pxa2xx_perf_read(opaque
, op2
, reg
, crm
);
368 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
374 static void pxa2xx_cp14_write(void *opaque
, int op2
, int reg
, int crm
,
379 pxa2xx_clkpwr_write(opaque
, op2
, reg
, crm
, value
);
382 pxa2xx_perf_write(opaque
, op2
, reg
, crm
, value
);
394 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
399 #define MDCNFG 0x00 /* SDRAM Configuration register */
400 #define MDREFR 0x04 /* SDRAM Refresh Control register */
401 #define MSC0 0x08 /* Static Memory Control register 0 */
402 #define MSC1 0x0c /* Static Memory Control register 1 */
403 #define MSC2 0x10 /* Static Memory Control register 2 */
404 #define MECR 0x14 /* Expansion Memory Bus Config register */
405 #define SXCNFG 0x1c /* Synchronous Static Memory Config register */
406 #define MCMEM0 0x28 /* PC Card Memory Socket 0 Timing register */
407 #define MCMEM1 0x2c /* PC Card Memory Socket 1 Timing register */
408 #define MCATT0 0x30 /* PC Card Attribute Socket 0 register */
409 #define MCATT1 0x34 /* PC Card Attribute Socket 1 register */
410 #define MCIO0 0x38 /* PC Card I/O Socket 0 Timing register */
411 #define MCIO1 0x3c /* PC Card I/O Socket 1 Timing register */
412 #define MDMRS 0x40 /* SDRAM Mode Register Set Config register */
413 #define BOOT_DEF 0x44 /* Boot-time Default Configuration register */
414 #define ARB_CNTL 0x48 /* Arbiter Control register */
415 #define BSCNTR0 0x4c /* Memory Buffer Strength Control register 0 */
416 #define BSCNTR1 0x50 /* Memory Buffer Strength Control register 1 */
417 #define LCDBSCNTR 0x54 /* LCD Buffer Strength Control register */
418 #define MDMRSLP 0x58 /* Low Power SDRAM Mode Set Config register */
419 #define BSCNTR2 0x5c /* Memory Buffer Strength Control register 2 */
420 #define BSCNTR3 0x60 /* Memory Buffer Strength Control register 3 */
421 #define SA1110 0x64 /* SA-1110 Memory Compatibility register */
423 static uint32_t pxa2xx_mm_read(void *opaque
, target_phys_addr_t addr
)
425 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
429 case MDCNFG
... SA1110
:
431 return s
->mm_regs
[addr
>> 2];
434 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
440 static void pxa2xx_mm_write(void *opaque
, target_phys_addr_t addr
,
443 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
447 case MDCNFG
... SA1110
:
448 if ((addr
& 3) == 0) {
449 s
->mm_regs
[addr
>> 2] = value
;
454 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
459 static CPUReadMemoryFunc
*pxa2xx_mm_readfn
[] = {
465 static CPUWriteMemoryFunc
*pxa2xx_mm_writefn
[] = {
471 /* Synchronous Serial Ports */
472 struct pxa2xx_ssp_s
{
473 target_phys_addr_t base
;
486 uint32_t rx_fifo
[16];
490 uint32_t (*readfn
)(void *opaque
);
491 void (*writefn
)(void *opaque
, uint32_t value
);
495 #define SSCR0 0x00 /* SSP Control register 0 */
496 #define SSCR1 0x04 /* SSP Control register 1 */
497 #define SSSR 0x08 /* SSP Status register */
498 #define SSITR 0x0c /* SSP Interrupt Test register */
499 #define SSDR 0x10 /* SSP Data register */
500 #define SSTO 0x28 /* SSP Time-Out register */
501 #define SSPSP 0x2c /* SSP Programmable Serial Protocol register */
502 #define SSTSA 0x30 /* SSP TX Time Slot Active register */
503 #define SSRSA 0x34 /* SSP RX Time Slot Active register */
504 #define SSTSS 0x38 /* SSP Time Slot Status register */
505 #define SSACD 0x3c /* SSP Audio Clock Divider register */
507 /* Bitfields for above registers */
508 #define SSCR0_SPI(x) (((x) & 0x30) == 0x00)
509 #define SSCR0_SSP(x) (((x) & 0x30) == 0x10)
510 #define SSCR0_UWIRE(x) (((x) & 0x30) == 0x20)
511 #define SSCR0_PSP(x) (((x) & 0x30) == 0x30)
512 #define SSCR0_SSE (1 << 7)
513 #define SSCR0_RIM (1 << 22)
514 #define SSCR0_TIM (1 << 23)
515 #define SSCR0_MOD (1 << 31)
516 #define SSCR0_DSS(x) (((((x) >> 16) & 0x10) | ((x) & 0xf)) + 1)
517 #define SSCR1_RIE (1 << 0)
518 #define SSCR1_TIE (1 << 1)
519 #define SSCR1_LBM (1 << 2)
520 #define SSCR1_MWDS (1 << 5)
521 #define SSCR1_TFT(x) ((((x) >> 6) & 0xf) + 1)
522 #define SSCR1_RFT(x) ((((x) >> 10) & 0xf) + 1)
523 #define SSCR1_EFWR (1 << 14)
524 #define SSCR1_PINTE (1 << 18)
525 #define SSCR1_TINTE (1 << 19)
526 #define SSCR1_RSRE (1 << 20)
527 #define SSCR1_TSRE (1 << 21)
528 #define SSCR1_EBCEI (1 << 29)
529 #define SSITR_INT (7 << 5)
530 #define SSSR_TNF (1 << 2)
531 #define SSSR_RNE (1 << 3)
532 #define SSSR_TFS (1 << 5)
533 #define SSSR_RFS (1 << 6)
534 #define SSSR_ROR (1 << 7)
535 #define SSSR_PINT (1 << 18)
536 #define SSSR_TINT (1 << 19)
537 #define SSSR_EOC (1 << 20)
538 #define SSSR_TUR (1 << 21)
539 #define SSSR_BCE (1 << 23)
540 #define SSSR_RW 0x00bc0080
542 static void pxa2xx_ssp_int_update(struct pxa2xx_ssp_s
*s
)
546 level
|= s
->ssitr
& SSITR_INT
;
547 level
|= (s
->sssr
& SSSR_BCE
) && (s
->sscr
[1] & SSCR1_EBCEI
);
548 level
|= (s
->sssr
& SSSR_TUR
) && !(s
->sscr
[0] & SSCR0_TIM
);
549 level
|= (s
->sssr
& SSSR_EOC
) && (s
->sssr
& (SSSR_TINT
| SSSR_PINT
));
550 level
|= (s
->sssr
& SSSR_TINT
) && (s
->sscr
[1] & SSCR1_TINTE
);
551 level
|= (s
->sssr
& SSSR_PINT
) && (s
->sscr
[1] & SSCR1_PINTE
);
552 level
|= (s
->sssr
& SSSR_ROR
) && !(s
->sscr
[0] & SSCR0_RIM
);
553 level
|= (s
->sssr
& SSSR_RFS
) && (s
->sscr
[1] & SSCR1_RIE
);
554 level
|= (s
->sssr
& SSSR_TFS
) && (s
->sscr
[1] & SSCR1_TIE
);
555 qemu_set_irq(s
->irq
, !!level
);
558 static void pxa2xx_ssp_fifo_update(struct pxa2xx_ssp_s
*s
)
560 s
->sssr
&= ~(0xf << 12); /* Clear RFL */
561 s
->sssr
&= ~(0xf << 8); /* Clear TFL */
562 s
->sssr
&= ~SSSR_TNF
;
564 s
->sssr
|= ((s
->rx_level
- 1) & 0xf) << 12;
565 if (s
->rx_level
>= SSCR1_RFT(s
->sscr
[1]))
568 s
->sssr
&= ~SSSR_RFS
;
569 if (0 <= SSCR1_TFT(s
->sscr
[1]))
572 s
->sssr
&= ~SSSR_TFS
;
576 s
->sssr
&= ~SSSR_RNE
;
580 pxa2xx_ssp_int_update(s
);
583 static uint32_t pxa2xx_ssp_read(void *opaque
, target_phys_addr_t addr
)
585 struct pxa2xx_ssp_s
*s
= (struct pxa2xx_ssp_s
*) opaque
;
601 return s
->sssr
| s
->ssitr
;
605 if (s
->rx_level
< 1) {
606 printf("%s: SSP Rx Underrun\n", __FUNCTION__
);
610 retval
= s
->rx_fifo
[s
->rx_start
++];
612 pxa2xx_ssp_fifo_update(s
);
623 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
629 static void pxa2xx_ssp_write(void *opaque
, target_phys_addr_t addr
,
632 struct pxa2xx_ssp_s
*s
= (struct pxa2xx_ssp_s
*) opaque
;
637 s
->sscr
[0] = value
& 0xc7ffffff;
638 s
->enable
= value
& SSCR0_SSE
;
639 if (value
& SSCR0_MOD
)
640 printf("%s: Attempt to use network mode\n", __FUNCTION__
);
641 if (s
->enable
&& SSCR0_DSS(value
) < 4)
642 printf("%s: Wrong data size: %i bits\n", __FUNCTION__
,
644 if (!(value
& SSCR0_SSE
)) {
649 pxa2xx_ssp_fifo_update(s
);
654 if (value
& (SSCR1_LBM
| SSCR1_EFWR
))
655 printf("%s: Attempt to use SSP test mode\n", __FUNCTION__
);
656 pxa2xx_ssp_fifo_update(s
);
668 s
->ssitr
= value
& SSITR_INT
;
669 pxa2xx_ssp_int_update(s
);
673 s
->sssr
&= ~(value
& SSSR_RW
);
674 pxa2xx_ssp_int_update(s
);
678 if (SSCR0_UWIRE(s
->sscr
[0])) {
679 if (s
->sscr
[1] & SSCR1_MWDS
)
684 /* Note how 32bits overflow does no harm here */
685 value
&= (1 << SSCR0_DSS(s
->sscr
[0])) - 1;
687 /* Data goes from here to the Tx FIFO and is shifted out from
688 * there directly to the slave, no need to buffer it.
692 s
->writefn(s
->opaque
, value
);
694 if (s
->rx_level
< 0x10) {
696 s
->rx_fifo
[(s
->rx_start
+ s
->rx_level
++) & 0xf] =
697 s
->readfn(s
->opaque
);
699 s
->rx_fifo
[(s
->rx_start
+ s
->rx_level
++) & 0xf] = 0x0;
703 pxa2xx_ssp_fifo_update(s
);
719 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
724 void pxa2xx_ssp_attach(struct pxa2xx_ssp_s
*port
,
725 uint32_t (*readfn
)(void *opaque
),
726 void (*writefn
)(void *opaque
, uint32_t value
), void *opaque
)
729 printf("%s: no such SSP\n", __FUNCTION__
);
733 port
->opaque
= opaque
;
734 port
->readfn
= readfn
;
735 port
->writefn
= writefn
;
738 static CPUReadMemoryFunc
*pxa2xx_ssp_readfn
[] = {
744 static CPUWriteMemoryFunc
*pxa2xx_ssp_writefn
[] = {
750 /* Real-Time Clock */
751 #define RCNR 0x00 /* RTC Counter register */
752 #define RTAR 0x04 /* RTC Alarm register */
753 #define RTSR 0x08 /* RTC Status register */
754 #define RTTR 0x0c /* RTC Timer Trim register */
755 #define RDCR 0x10 /* RTC Day Counter register */
756 #define RYCR 0x14 /* RTC Year Counter register */
757 #define RDAR1 0x18 /* RTC Wristwatch Day Alarm register 1 */
758 #define RYAR1 0x1c /* RTC Wristwatch Year Alarm register 1 */
759 #define RDAR2 0x20 /* RTC Wristwatch Day Alarm register 2 */
760 #define RYAR2 0x24 /* RTC Wristwatch Year Alarm register 2 */
761 #define SWCR 0x28 /* RTC Stopwatch Counter register */
762 #define SWAR1 0x2c /* RTC Stopwatch Alarm register 1 */
763 #define SWAR2 0x30 /* RTC Stopwatch Alarm register 2 */
764 #define RTCPICR 0x34 /* RTC Periodic Interrupt Counter register */
765 #define PIAR 0x38 /* RTC Periodic Interrupt Alarm register */
767 static inline void pxa2xx_rtc_int_update(struct pxa2xx_state_s
*s
)
769 qemu_set_irq(s
->pic
[PXA2XX_PIC_RTCALARM
], !!(s
->rtsr
& 0x2553));
772 static void pxa2xx_rtc_hzupdate(struct pxa2xx_state_s
*s
)
774 int64_t rt
= qemu_get_clock(rt_clock
);
775 s
->last_rcnr
+= ((rt
- s
->last_hz
) << 15) /
776 (1000 * ((s
->rttr
& 0xffff) + 1));
777 s
->last_rdcr
+= ((rt
- s
->last_hz
) << 15) /
778 (1000 * ((s
->rttr
& 0xffff) + 1));
782 static void pxa2xx_rtc_swupdate(struct pxa2xx_state_s
*s
)
784 int64_t rt
= qemu_get_clock(rt_clock
);
785 if (s
->rtsr
& (1 << 12))
786 s
->last_swcr
+= (rt
- s
->last_sw
) / 10;
790 static void pxa2xx_rtc_piupdate(struct pxa2xx_state_s
*s
)
792 int64_t rt
= qemu_get_clock(rt_clock
);
793 if (s
->rtsr
& (1 << 15))
794 s
->last_swcr
+= rt
- s
->last_pi
;
798 static inline void pxa2xx_rtc_alarm_update(struct pxa2xx_state_s
*s
,
801 if ((rtsr
& (1 << 2)) && !(rtsr
& (1 << 0)))
802 qemu_mod_timer(s
->rtc_hz
, s
->last_hz
+
803 (((s
->rtar
- s
->last_rcnr
) * 1000 *
804 ((s
->rttr
& 0xffff) + 1)) >> 15));
806 qemu_del_timer(s
->rtc_hz
);
808 if ((rtsr
& (1 << 5)) && !(rtsr
& (1 << 4)))
809 qemu_mod_timer(s
->rtc_rdal1
, s
->last_hz
+
810 (((s
->rdar1
- s
->last_rdcr
) * 1000 *
811 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
813 qemu_del_timer(s
->rtc_rdal1
);
815 if ((rtsr
& (1 << 7)) && !(rtsr
& (1 << 6)))
816 qemu_mod_timer(s
->rtc_rdal2
, s
->last_hz
+
817 (((s
->rdar2
- s
->last_rdcr
) * 1000 *
818 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
820 qemu_del_timer(s
->rtc_rdal2
);
822 if ((rtsr
& 0x1200) == 0x1200 && !(rtsr
& (1 << 8)))
823 qemu_mod_timer(s
->rtc_swal1
, s
->last_sw
+
824 (s
->swar1
- s
->last_swcr
) * 10); /* TODO: fixup */
826 qemu_del_timer(s
->rtc_swal1
);
828 if ((rtsr
& 0x1800) == 0x1800 && !(rtsr
& (1 << 10)))
829 qemu_mod_timer(s
->rtc_swal2
, s
->last_sw
+
830 (s
->swar2
- s
->last_swcr
) * 10); /* TODO: fixup */
832 qemu_del_timer(s
->rtc_swal2
);
834 if ((rtsr
& 0xc000) == 0xc000 && !(rtsr
& (1 << 13)))
835 qemu_mod_timer(s
->rtc_pi
, s
->last_pi
+
836 (s
->piar
& 0xffff) - s
->last_rtcpicr
);
838 qemu_del_timer(s
->rtc_pi
);
841 static inline void pxa2xx_rtc_hz_tick(void *opaque
)
843 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
845 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
846 pxa2xx_rtc_int_update(s
);
849 static inline void pxa2xx_rtc_rdal1_tick(void *opaque
)
851 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
853 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
854 pxa2xx_rtc_int_update(s
);
857 static inline void pxa2xx_rtc_rdal2_tick(void *opaque
)
859 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
861 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
862 pxa2xx_rtc_int_update(s
);
865 static inline void pxa2xx_rtc_swal1_tick(void *opaque
)
867 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
869 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
870 pxa2xx_rtc_int_update(s
);
873 static inline void pxa2xx_rtc_swal2_tick(void *opaque
)
875 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
876 s
->rtsr
|= (1 << 10);
877 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
878 pxa2xx_rtc_int_update(s
);
881 static inline void pxa2xx_rtc_pi_tick(void *opaque
)
883 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
884 s
->rtsr
|= (1 << 13);
885 pxa2xx_rtc_piupdate(s
);
887 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
888 pxa2xx_rtc_int_update(s
);
891 static uint32_t pxa2xx_rtc_read(void *opaque
, target_phys_addr_t addr
)
893 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
918 return s
->last_rcnr
+ ((qemu_get_clock(rt_clock
) - s
->last_hz
) << 15) /
919 (1000 * ((s
->rttr
& 0xffff) + 1));
921 return s
->last_rdcr
+ ((qemu_get_clock(rt_clock
) - s
->last_hz
) << 15) /
922 (1000 * ((s
->rttr
& 0xffff) + 1));
926 if (s
->rtsr
& (1 << 12))
927 return s
->last_swcr
+ (qemu_get_clock(rt_clock
) - s
->last_sw
) / 10;
931 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
937 static void pxa2xx_rtc_write(void *opaque
, target_phys_addr_t addr
,
940 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
945 if (!(s
->rttr
& (1 << 31))) {
946 pxa2xx_rtc_hzupdate(s
);
948 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
953 if ((s
->rtsr
^ value
) & (1 << 15))
954 pxa2xx_rtc_piupdate(s
);
956 if ((s
->rtsr
^ value
) & (1 << 12))
957 pxa2xx_rtc_swupdate(s
);
959 if (((s
->rtsr
^ value
) & 0x4aac) | (value
& ~0xdaac))
960 pxa2xx_rtc_alarm_update(s
, value
);
962 s
->rtsr
= (value
& 0xdaac) | (s
->rtsr
& ~(value
& ~0xdaac));
963 pxa2xx_rtc_int_update(s
);
968 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
973 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
978 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
983 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
988 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
992 pxa2xx_rtc_swupdate(s
);
995 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1000 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1005 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1009 pxa2xx_rtc_hzupdate(s
);
1010 s
->last_rcnr
= value
;
1011 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1015 pxa2xx_rtc_hzupdate(s
);
1016 s
->last_rdcr
= value
;
1017 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1021 s
->last_rycr
= value
;
1025 pxa2xx_rtc_swupdate(s
);
1026 s
->last_swcr
= value
;
1027 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1031 pxa2xx_rtc_piupdate(s
);
1032 s
->last_rtcpicr
= value
& 0xffff;
1033 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1037 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1041 static void pxa2xx_rtc_reset(struct pxa2xx_state_s
*s
)
1054 tm
= localtime(&ti
);
1055 wom
= ((tm
->tm_mday
- 1) / 7) + 1;
1057 s
->last_rcnr
= (uint32_t) ti
;
1058 s
->last_rdcr
= (wom
<< 20) | ((tm
->tm_wday
+ 1) << 17) |
1059 (tm
->tm_hour
<< 12) | (tm
->tm_min
<< 6) | tm
->tm_sec
;
1060 s
->last_rycr
= ((tm
->tm_year
+ 1900) << 9) |
1061 ((tm
->tm_mon
+ 1) << 5) | tm
->tm_mday
;
1062 s
->last_swcr
= (tm
->tm_hour
<< 19) |
1063 (tm
->tm_min
<< 13) | (tm
->tm_sec
<< 7);
1064 s
->last_rtcpicr
= 0;
1065 s
->last_hz
= s
->last_sw
= s
->last_pi
= qemu_get_clock(rt_clock
);
1067 s
->rtc_hz
= qemu_new_timer(rt_clock
, pxa2xx_rtc_hz_tick
, s
);
1068 s
->rtc_rdal1
= qemu_new_timer(rt_clock
, pxa2xx_rtc_rdal1_tick
, s
);
1069 s
->rtc_rdal2
= qemu_new_timer(rt_clock
, pxa2xx_rtc_rdal2_tick
, s
);
1070 s
->rtc_swal1
= qemu_new_timer(rt_clock
, pxa2xx_rtc_swal1_tick
, s
);
1071 s
->rtc_swal2
= qemu_new_timer(rt_clock
, pxa2xx_rtc_swal2_tick
, s
);
1072 s
->rtc_pi
= qemu_new_timer(rt_clock
, pxa2xx_rtc_pi_tick
, s
);
1075 static CPUReadMemoryFunc
*pxa2xx_rtc_readfn
[] = {
1081 static CPUWriteMemoryFunc
*pxa2xx_rtc_writefn
[] = {
1087 /* PXA Inter-IC Sound Controller */
1088 static void pxa2xx_i2s_reset(struct pxa2xx_i2s_s
*i2s
)
1094 i2s
->control
[0] = 0x00;
1095 i2s
->control
[1] = 0x00;
1100 #define SACR_TFTH(val) ((val >> 8) & 0xf)
1101 #define SACR_RFTH(val) ((val >> 12) & 0xf)
1102 #define SACR_DREC(val) (val & (1 << 3))
1103 #define SACR_DPRL(val) (val & (1 << 4))
1105 static inline void pxa2xx_i2s_update(struct pxa2xx_i2s_s
*i2s
)
1108 rfs
= SACR_RFTH(i2s
->control
[0]) < i2s
->rx_len
&&
1109 !SACR_DREC(i2s
->control
[1]);
1110 tfs
= (i2s
->tx_len
|| i2s
->fifo_len
< SACR_TFTH(i2s
->control
[0])) &&
1111 i2s
->enable
&& !SACR_DPRL(i2s
->control
[1]);
1113 pxa2xx_dma_request(i2s
->dma
, PXA2XX_RX_RQ_I2S
, rfs
);
1114 pxa2xx_dma_request(i2s
->dma
, PXA2XX_TX_RQ_I2S
, tfs
);
1116 i2s
->status
&= 0xe0;
1118 i2s
->status
|= 1 << 1; /* RNE */
1120 i2s
->status
|= 1 << 2; /* BSY */
1122 i2s
->status
|= 1 << 3; /* TFS */
1124 i2s
->status
|= 1 << 4; /* RFS */
1125 if (!(i2s
->tx_len
&& i2s
->enable
))
1126 i2s
->status
|= i2s
->fifo_len
<< 8; /* TFL */
1127 i2s
->status
|= MAX(i2s
->rx_len
, 0xf) << 12; /* RFL */
1129 qemu_set_irq(i2s
->irq
, i2s
->status
& i2s
->mask
);
1132 #define SACR0 0x00 /* Serial Audio Global Control register */
1133 #define SACR1 0x04 /* Serial Audio I2S/MSB-Justified Control register */
1134 #define SASR0 0x0c /* Serial Audio Interface and FIFO Status register */
1135 #define SAIMR 0x14 /* Serial Audio Interrupt Mask register */
1136 #define SAICR 0x18 /* Serial Audio Interrupt Clear register */
1137 #define SADIV 0x60 /* Serial Audio Clock Divider register */
1138 #define SADR 0x80 /* Serial Audio Data register */
1140 static uint32_t pxa2xx_i2s_read(void *opaque
, target_phys_addr_t addr
)
1142 struct pxa2xx_i2s_s
*s
= (struct pxa2xx_i2s_s
*) opaque
;
1147 return s
->control
[0];
1149 return s
->control
[1];
1159 if (s
->rx_len
> 0) {
1161 pxa2xx_i2s_update(s
);
1162 return s
->codec_in(s
->opaque
);
1166 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1172 static void pxa2xx_i2s_write(void *opaque
, target_phys_addr_t addr
,
1175 struct pxa2xx_i2s_s
*s
= (struct pxa2xx_i2s_s
*) opaque
;
1181 if (value
& (1 << 3)) /* RST */
1182 pxa2xx_i2s_reset(s
);
1183 s
->control
[0] = value
& 0xff3d;
1184 if (!s
->enable
&& (value
& 1) && s
->tx_len
) { /* ENB */
1185 for (sample
= s
->fifo
; s
->fifo_len
> 0; s
->fifo_len
--, sample
++)
1186 s
->codec_out(s
->opaque
, *sample
);
1187 s
->status
&= ~(1 << 7); /* I2SOFF */
1189 if (value
& (1 << 4)) /* EFWR */
1190 printf("%s: Attempt to use special function\n", __FUNCTION__
);
1191 s
->enable
= ((value
^ 4) & 5) == 5; /* ENB && !RST*/
1192 pxa2xx_i2s_update(s
);
1195 s
->control
[1] = value
& 0x0039;
1196 if (value
& (1 << 5)) /* ENLBF */
1197 printf("%s: Attempt to use loopback function\n", __FUNCTION__
);
1198 if (value
& (1 << 4)) /* DPRL */
1200 pxa2xx_i2s_update(s
);
1203 s
->mask
= value
& 0x0078;
1204 pxa2xx_i2s_update(s
);
1207 s
->status
&= ~(value
& (3 << 5));
1208 pxa2xx_i2s_update(s
);
1211 s
->clk
= value
& 0x007f;
1214 if (s
->tx_len
&& s
->enable
) {
1216 pxa2xx_i2s_update(s
);
1217 s
->codec_out(s
->opaque
, value
);
1218 } else if (s
->fifo_len
< 16) {
1219 s
->fifo
[s
->fifo_len
++] = value
;
1220 pxa2xx_i2s_update(s
);
1224 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1228 static CPUReadMemoryFunc
*pxa2xx_i2s_readfn
[] = {
1234 static CPUWriteMemoryFunc
*pxa2xx_i2s_writefn
[] = {
1240 static void pxa2xx_i2s_data_req(void *opaque
, int tx
, int rx
)
1242 struct pxa2xx_i2s_s
*s
= (struct pxa2xx_i2s_s
*) opaque
;
1245 /* Signal FIFO errors */
1246 if (s
->enable
&& s
->tx_len
)
1247 s
->status
|= 1 << 5; /* TUR */
1248 if (s
->enable
&& s
->rx_len
)
1249 s
->status
|= 1 << 6; /* ROR */
1251 /* Should be tx - MIN(tx, s->fifo_len) but we don't really need to
1252 * handle the cases where it makes a difference. */
1253 s
->tx_len
= tx
- s
->fifo_len
;
1255 /* Note that is s->codec_out wasn't set, we wouldn't get called. */
1257 for (sample
= s
->fifo
; s
->fifo_len
; s
->fifo_len
--, sample
++)
1258 s
->codec_out(s
->opaque
, *sample
);
1259 pxa2xx_i2s_update(s
);
1262 static struct pxa2xx_i2s_s
*pxa2xx_i2s_init(target_phys_addr_t base
,
1263 qemu_irq irq
, struct pxa2xx_dma_state_s
*dma
)
1266 struct pxa2xx_i2s_s
*s
= (struct pxa2xx_i2s_s
*)
1267 qemu_mallocz(sizeof(struct pxa2xx_i2s_s
));
1272 s
->data_req
= pxa2xx_i2s_data_req
;
1274 pxa2xx_i2s_reset(s
);
1276 iomemtype
= cpu_register_io_memory(0, pxa2xx_i2s_readfn
,
1277 pxa2xx_i2s_writefn
, s
);
1278 cpu_register_physical_memory(s
->base
& 0xfff00000, 0xfffff, iomemtype
);
1283 /* PXA Fast Infra-red Communications Port */
1284 struct pxa2xx_fir_s
{
1285 target_phys_addr_t base
;
1287 struct pxa2xx_dma_state_s
*dma
;
1289 CharDriverState
*chr
;
1296 uint8_t rx_fifo
[64];
1299 static void pxa2xx_fir_reset(struct pxa2xx_fir_s
*s
)
1301 s
->control
[0] = 0x00;
1302 s
->control
[1] = 0x00;
1303 s
->control
[2] = 0x00;
1304 s
->status
[0] = 0x00;
1305 s
->status
[1] = 0x00;
1309 static inline void pxa2xx_fir_update(struct pxa2xx_fir_s
*s
)
1311 static const int tresh
[4] = { 8, 16, 32, 0 };
1313 if ((s
->control
[0] & (1 << 4)) && /* RXE */
1314 s
->rx_len
>= tresh
[s
->control
[2] & 3]) /* TRIG */
1315 s
->status
[0] |= 1 << 4; /* RFS */
1317 s
->status
[0] &= ~(1 << 4); /* RFS */
1318 if (s
->control
[0] & (1 << 3)) /* TXE */
1319 s
->status
[0] |= 1 << 3; /* TFS */
1321 s
->status
[0] &= ~(1 << 3); /* TFS */
1323 s
->status
[1] |= 1 << 2; /* RNE */
1325 s
->status
[1] &= ~(1 << 2); /* RNE */
1326 if (s
->control
[0] & (1 << 4)) /* RXE */
1327 s
->status
[1] |= 1 << 0; /* RSY */
1329 s
->status
[1] &= ~(1 << 0); /* RSY */
1331 intr
|= (s
->control
[0] & (1 << 5)) && /* RIE */
1332 (s
->status
[0] & (1 << 4)); /* RFS */
1333 intr
|= (s
->control
[0] & (1 << 6)) && /* TIE */
1334 (s
->status
[0] & (1 << 3)); /* TFS */
1335 intr
|= (s
->control
[2] & (1 << 4)) && /* TRAIL */
1336 (s
->status
[0] & (1 << 6)); /* EOC */
1337 intr
|= (s
->control
[0] & (1 << 2)) && /* TUS */
1338 (s
->status
[0] & (1 << 1)); /* TUR */
1339 intr
|= s
->status
[0] & 0x25; /* FRE, RAB, EIF */
1341 pxa2xx_dma_request(s
->dma
, PXA2XX_RX_RQ_ICP
, (s
->status
[0] >> 4) & 1);
1342 pxa2xx_dma_request(s
->dma
, PXA2XX_TX_RQ_ICP
, (s
->status
[0] >> 3) & 1);
1344 qemu_set_irq(s
->irq
, intr
&& s
->enable
);
1347 #define ICCR0 0x00 /* FICP Control register 0 */
1348 #define ICCR1 0x04 /* FICP Control register 1 */
1349 #define ICCR2 0x08 /* FICP Control register 2 */
1350 #define ICDR 0x0c /* FICP Data register */
1351 #define ICSR0 0x14 /* FICP Status register 0 */
1352 #define ICSR1 0x18 /* FICP Status register 1 */
1353 #define ICFOR 0x1c /* FICP FIFO Occupancy Status register */
1355 static uint32_t pxa2xx_fir_read(void *opaque
, target_phys_addr_t addr
)
1357 struct pxa2xx_fir_s
*s
= (struct pxa2xx_fir_s
*) opaque
;
1363 return s
->control
[0];
1365 return s
->control
[1];
1367 return s
->control
[2];
1369 s
->status
[0] &= ~0x01;
1370 s
->status
[1] &= ~0x72;
1373 ret
= s
->rx_fifo
[s
->rx_start
++];
1375 pxa2xx_fir_update(s
);
1378 printf("%s: Rx FIFO underrun.\n", __FUNCTION__
);
1381 return s
->status
[0];
1383 return s
->status
[1] | (1 << 3); /* TNF */
1387 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1393 static void pxa2xx_fir_write(void *opaque
, target_phys_addr_t addr
,
1396 struct pxa2xx_fir_s
*s
= (struct pxa2xx_fir_s
*) opaque
;
1402 s
->control
[0] = value
;
1403 if (!(value
& (1 << 4))) /* RXE */
1404 s
->rx_len
= s
->rx_start
= 0;
1405 if (!(value
& (1 << 3))) /* TXE */
1407 s
->enable
= value
& 1; /* ITR */
1410 pxa2xx_fir_update(s
);
1413 s
->control
[1] = value
;
1416 s
->control
[2] = value
& 0x3f;
1417 pxa2xx_fir_update(s
);
1420 if (s
->control
[2] & (1 << 2)) /* TXP */
1424 if (s
->chr
&& s
->enable
&& (s
->control
[0] & (1 << 3))) /* TXE */
1425 qemu_chr_write(s
->chr
, &ch
, 1);
1428 s
->status
[0] &= ~(value
& 0x66);
1429 pxa2xx_fir_update(s
);
1434 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1438 static CPUReadMemoryFunc
*pxa2xx_fir_readfn
[] = {
1444 static CPUWriteMemoryFunc
*pxa2xx_fir_writefn
[] = {
1450 static int pxa2xx_fir_is_empty(void *opaque
)
1452 struct pxa2xx_fir_s
*s
= (struct pxa2xx_fir_s
*) opaque
;
1453 return (s
->rx_len
< 64);
1456 static void pxa2xx_fir_rx(void *opaque
, const uint8_t *buf
, int size
)
1458 struct pxa2xx_fir_s
*s
= (struct pxa2xx_fir_s
*) opaque
;
1459 if (!(s
->control
[0] & (1 << 4))) /* RXE */
1463 s
->status
[1] |= 1 << 4; /* EOF */
1464 if (s
->rx_len
>= 64) {
1465 s
->status
[1] |= 1 << 6; /* ROR */
1469 if (s
->control
[2] & (1 << 3)) /* RXP */
1470 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = *(buf
++);
1472 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = ~*(buf
++);
1475 pxa2xx_fir_update(s
);
1478 static void pxa2xx_fir_event(void *opaque
, int event
)
1482 static struct pxa2xx_fir_s
*pxa2xx_fir_init(target_phys_addr_t base
,
1483 qemu_irq irq
, struct pxa2xx_dma_state_s
*dma
,
1484 CharDriverState
*chr
)
1487 struct pxa2xx_fir_s
*s
= (struct pxa2xx_fir_s
*)
1488 qemu_mallocz(sizeof(struct pxa2xx_fir_s
));
1495 pxa2xx_fir_reset(s
);
1497 iomemtype
= cpu_register_io_memory(0, pxa2xx_fir_readfn
,
1498 pxa2xx_fir_writefn
, s
);
1499 cpu_register_physical_memory(s
->base
, 0xfff, iomemtype
);
1502 qemu_chr_add_handlers(chr
, pxa2xx_fir_is_empty
,
1503 pxa2xx_fir_rx
, pxa2xx_fir_event
, s
);
1508 void pxa2xx_reset(int line
, int level
, void *opaque
)
1510 struct pxa2xx_state_s
*s
= (struct pxa2xx_state_s
*) opaque
;
1511 if (level
&& (s
->pm_regs
[PCFR
>> 2] & 0x10)) { /* GPR_EN */
1513 /* TODO: reset peripherals */
1517 /* Initialise a PXA270 integrated chip (ARM based core). */
1518 struct pxa2xx_state_s
*pxa270_init(DisplayState
*ds
, const char *revision
)
1520 struct pxa2xx_state_s
*s
;
1521 struct pxa2xx_ssp_s
*ssp
;
1523 s
= (struct pxa2xx_state_s
*) qemu_mallocz(sizeof(struct pxa2xx_state_s
));
1525 if (revision
&& strncmp(revision
, "pxa27", 5)) {
1526 fprintf(stderr
, "Machine requires a PXA27x processor.\n");
1530 s
->env
= cpu_init();
1531 cpu_arm_set_model(s
->env
, revision
?: "pxa270");
1533 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->env
);
1535 s
->dma
= pxa27x_dma_init(0x40000000, s
->pic
[PXA2XX_PIC_DMA
]);
1537 pxa27x_timer_init(0x40a00000, &s
->pic
[PXA2XX_PIC_OST_0
],
1538 s
->pic
[PXA27X_PIC_OST_4_11
], s
->env
);
1540 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->env
, s
->pic
, 121);
1542 s
->mmc
= pxa2xx_mmci_init(0x41100000, s
->pic
[PXA2XX_PIC_MMC
], s
->dma
);
1544 for (i
= 0; pxa270_serial
[i
].io_base
; i
++)
1546 serial_mm_init(pxa270_serial
[i
].io_base
, 2,
1547 s
->pic
[pxa270_serial
[i
].irqn
], serial_hds
[i
], 1);
1551 s
->fir
= pxa2xx_fir_init(0x40800000, s
->pic
[PXA2XX_PIC_ICP
],
1552 s
->dma
, serial_hds
[i
]);
1555 s
->lcd
= pxa2xx_lcdc_init(0x44000000, s
->pic
[PXA2XX_PIC_LCD
], ds
);
1557 s
->cm_base
= 0x41300000;
1558 s
->cm_regs
[CCCR
>> 4] = 0x02000210; /* 416.0 MHz */
1559 s
->clkcfg
= 0x00000009; /* Turbo mode active */
1560 iomemtype
= cpu_register_io_memory(0, pxa2xx_cm_readfn
,
1561 pxa2xx_cm_writefn
, s
);
1562 cpu_register_physical_memory(s
->cm_base
, 0xfff, iomemtype
);
1564 cpu_arm_set_cp_io(s
->env
, 14, pxa2xx_cp14_read
, pxa2xx_cp14_write
, s
);
1566 s
->mm_base
= 0x48000000;
1567 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
1568 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
1569 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
1570 iomemtype
= cpu_register_io_memory(0, pxa2xx_mm_readfn
,
1571 pxa2xx_mm_writefn
, s
);
1572 cpu_register_physical_memory(s
->mm_base
, 0xfff, iomemtype
);
1574 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++);
1575 s
->ssp
= (struct pxa2xx_ssp_s
**)
1576 qemu_mallocz(sizeof(struct pxa2xx_ssp_s
*) * i
);
1577 ssp
= (struct pxa2xx_ssp_s
*)
1578 qemu_mallocz(sizeof(struct pxa2xx_ssp_s
) * i
);
1579 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++) {
1580 s
->ssp
[i
] = &ssp
[i
];
1581 ssp
[i
].base
= pxa27x_ssp
[i
].io_base
;
1582 ssp
[i
].irq
= s
->pic
[pxa27x_ssp
[i
].irqn
];
1584 iomemtype
= cpu_register_io_memory(0, pxa2xx_ssp_readfn
,
1585 pxa2xx_ssp_writefn
, &ssp
[i
]);
1586 cpu_register_physical_memory(ssp
[i
].base
, 0xfff, iomemtype
);
1590 usb_ohci_init_pxa(0x4c000000, 3, -1, s
->pic
[PXA2XX_PIC_USBH1
]);
1593 s
->pcmcia
[0] = pxa2xx_pcmcia_init(0x20000000);
1594 s
->pcmcia
[1] = pxa2xx_pcmcia_init(0x30000000);
1596 s
->rtc_base
= 0x40900000;
1597 iomemtype
= cpu_register_io_memory(0, pxa2xx_rtc_readfn
,
1598 pxa2xx_rtc_writefn
, s
);
1599 cpu_register_physical_memory(s
->rtc_base
, 0xfff, iomemtype
);
1600 pxa2xx_rtc_reset(s
);
1602 s
->pm_base
= 0x40f00000;
1603 iomemtype
= cpu_register_io_memory(0, pxa2xx_pm_readfn
,
1604 pxa2xx_pm_writefn
, s
);
1605 cpu_register_physical_memory(s
->pm_base
, 0xfff, iomemtype
);
1607 s
->i2s
= pxa2xx_i2s_init(0x40400000, s
->pic
[PXA2XX_PIC_I2S
], s
->dma
);
1609 /* GPIO1 resets the processor */
1610 /* The handler can be overriden by board-specific code */
1611 pxa2xx_gpio_handler_set(s
->gpio
, 1, pxa2xx_reset
, s
);
1615 /* Initialise a PXA255 integrated chip (ARM based core). */
1616 struct pxa2xx_state_s
*pxa255_init(DisplayState
*ds
)
1618 struct pxa2xx_state_s
*s
;
1619 struct pxa2xx_ssp_s
*ssp
;
1621 s
= (struct pxa2xx_state_s
*) qemu_mallocz(sizeof(struct pxa2xx_state_s
));
1623 s
->env
= cpu_init();
1624 cpu_arm_set_model(s
->env
, "pxa255");
1626 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->env
);
1628 s
->dma
= pxa255_dma_init(0x40000000, s
->pic
[PXA2XX_PIC_DMA
]);
1630 pxa25x_timer_init(0x40a00000, &s
->pic
[PXA2XX_PIC_OST_0
], s
->env
);
1632 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->env
, s
->pic
, 121);
1634 s
->mmc
= pxa2xx_mmci_init(0x41100000, s
->pic
[PXA2XX_PIC_MMC
], s
->dma
);
1636 for (i
= 0; pxa255_serial
[i
].io_base
; i
++)
1638 serial_mm_init(pxa255_serial
[i
].io_base
, 2,
1639 s
->pic
[pxa255_serial
[i
].irqn
], serial_hds
[i
], 1);
1643 s
->fir
= pxa2xx_fir_init(0x40800000, s
->pic
[PXA2XX_PIC_ICP
],
1644 s
->dma
, serial_hds
[i
]);
1647 s
->lcd
= pxa2xx_lcdc_init(0x44000000, s
->pic
[PXA2XX_PIC_LCD
], ds
);
1649 s
->cm_base
= 0x41300000;
1650 s
->cm_regs
[CCCR
>> 4] = 0x02000210; /* 416.0 MHz */
1651 s
->clkcfg
= 0x00000009; /* Turbo mode active */
1652 iomemtype
= cpu_register_io_memory(0, pxa2xx_cm_readfn
,
1653 pxa2xx_cm_writefn
, s
);
1654 cpu_register_physical_memory(s
->cm_base
, 0xfff, iomemtype
);
1656 cpu_arm_set_cp_io(s
->env
, 14, pxa2xx_cp14_read
, pxa2xx_cp14_write
, s
);
1658 s
->mm_base
= 0x48000000;
1659 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
1660 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
1661 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
1662 iomemtype
= cpu_register_io_memory(0, pxa2xx_mm_readfn
,
1663 pxa2xx_mm_writefn
, s
);
1664 cpu_register_physical_memory(s
->mm_base
, 0xfff, iomemtype
);
1666 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++);
1667 s
->ssp
= (struct pxa2xx_ssp_s
**)
1668 qemu_mallocz(sizeof(struct pxa2xx_ssp_s
*) * i
);
1669 ssp
= (struct pxa2xx_ssp_s
*)
1670 qemu_mallocz(sizeof(struct pxa2xx_ssp_s
) * i
);
1671 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++) {
1672 s
->ssp
[i
] = &ssp
[i
];
1673 ssp
[i
].base
= pxa255_ssp
[i
].io_base
;
1674 ssp
[i
].irq
= s
->pic
[pxa255_ssp
[i
].irqn
];
1676 iomemtype
= cpu_register_io_memory(0, pxa2xx_ssp_readfn
,
1677 pxa2xx_ssp_writefn
, &ssp
[i
]);
1678 cpu_register_physical_memory(ssp
[i
].base
, 0xfff, iomemtype
);
1682 usb_ohci_init_pxa(0x4c000000, 3, -1, s
->pic
[PXA2XX_PIC_USBH1
]);
1685 s
->pcmcia
[0] = pxa2xx_pcmcia_init(0x20000000);
1686 s
->pcmcia
[1] = pxa2xx_pcmcia_init(0x30000000);
1688 s
->rtc_base
= 0x40900000;
1689 iomemtype
= cpu_register_io_memory(0, pxa2xx_rtc_readfn
,
1690 pxa2xx_rtc_writefn
, s
);
1691 cpu_register_physical_memory(s
->rtc_base
, 0xfff, iomemtype
);
1692 pxa2xx_rtc_reset(s
);
1694 s
->pm_base
= 0x40f00000;
1695 iomemtype
= cpu_register_io_memory(0, pxa2xx_pm_readfn
,
1696 pxa2xx_pm_writefn
, s
);
1697 cpu_register_physical_memory(s
->pm_base
, 0xfff, iomemtype
);
1699 s
->i2s
= pxa2xx_i2s_init(0x40400000, s
->pic
[PXA2XX_PIC_I2S
], s
->dma
);
1701 /* GPIO1 resets the processor */
1702 /* The handler can be overriden by board-specific code */
1703 pxa2xx_gpio_handler_set(s
->gpio
, 1, pxa2xx_reset
, s
);