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 licensed under the GPL.
16 #include "qemu-char.h"
20 target_phys_addr_t io_base
;
23 { 0x40100000, PXA2XX_PIC_FFUART
},
24 { 0x40200000, PXA2XX_PIC_BTUART
},
25 { 0x40700000, PXA2XX_PIC_STUART
},
26 { 0x41600000, PXA25X_PIC_HWUART
},
28 }, pxa270_serial
[] = {
29 { 0x40100000, PXA2XX_PIC_FFUART
},
30 { 0x40200000, PXA2XX_PIC_BTUART
},
31 { 0x40700000, PXA2XX_PIC_STUART
},
35 typedef struct PXASSPDef
{
36 target_phys_addr_t io_base
;
41 static PXASSPDef pxa250_ssp
[] = {
42 { 0x41000000, PXA2XX_PIC_SSP
},
47 static PXASSPDef pxa255_ssp
[] = {
48 { 0x41000000, PXA2XX_PIC_SSP
},
49 { 0x41400000, PXA25X_PIC_NSSP
},
54 static PXASSPDef pxa26x_ssp
[] = {
55 { 0x41000000, PXA2XX_PIC_SSP
},
56 { 0x41400000, PXA25X_PIC_NSSP
},
57 { 0x41500000, PXA26X_PIC_ASSP
},
62 static PXASSPDef pxa27x_ssp
[] = {
63 { 0x41000000, PXA2XX_PIC_SSP
},
64 { 0x41700000, PXA27X_PIC_SSP2
},
65 { 0x41900000, PXA2XX_PIC_SSP3
},
69 #define PMCR 0x00 /* Power Manager Control register */
70 #define PSSR 0x04 /* Power Manager Sleep Status register */
71 #define PSPR 0x08 /* Power Manager Scratch-Pad register */
72 #define PWER 0x0c /* Power Manager Wake-Up Enable register */
73 #define PRER 0x10 /* Power Manager Rising-Edge Detect Enable register */
74 #define PFER 0x14 /* Power Manager Falling-Edge Detect Enable register */
75 #define PEDR 0x18 /* Power Manager Edge-Detect Status register */
76 #define PCFR 0x1c /* Power Manager General Configuration register */
77 #define PGSR0 0x20 /* Power Manager GPIO Sleep-State register 0 */
78 #define PGSR1 0x24 /* Power Manager GPIO Sleep-State register 1 */
79 #define PGSR2 0x28 /* Power Manager GPIO Sleep-State register 2 */
80 #define PGSR3 0x2c /* Power Manager GPIO Sleep-State register 3 */
81 #define RCSR 0x30 /* Reset Controller Status register */
82 #define PSLR 0x34 /* Power Manager Sleep Configuration register */
83 #define PTSR 0x38 /* Power Manager Standby Configuration register */
84 #define PVCR 0x40 /* Power Manager Voltage Change Control register */
85 #define PUCR 0x4c /* Power Manager USIM Card Control/Status register */
86 #define PKWR 0x50 /* Power Manager Keyboard Wake-Up Enable register */
87 #define PKSR 0x54 /* Power Manager Keyboard Level-Detect Status */
88 #define PCMD0 0x80 /* Power Manager I2C Command register File 0 */
89 #define PCMD31 0xfc /* Power Manager I2C Command register File 31 */
91 static uint64_t pxa2xx_pm_read(void *opaque
, target_phys_addr_t addr
,
94 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
101 return s
->pm_regs
[addr
>> 2];
104 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
110 static void pxa2xx_pm_write(void *opaque
, target_phys_addr_t addr
,
111 uint64_t value
, unsigned size
)
113 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
117 /* Clear the write-one-to-clear bits... */
118 s
->pm_regs
[addr
>> 2] &= ~(value
& 0x2a);
119 /* ...and set the plain r/w bits */
120 s
->pm_regs
[addr
>> 2] &= ~0x15;
121 s
->pm_regs
[addr
>> 2] |= value
& 0x15;
124 case PSSR
: /* Read-clean registers */
127 s
->pm_regs
[addr
>> 2] &= ~value
;
130 default: /* Read-write registers */
132 s
->pm_regs
[addr
>> 2] = value
;
136 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
141 static const MemoryRegionOps pxa2xx_pm_ops
= {
142 .read
= pxa2xx_pm_read
,
143 .write
= pxa2xx_pm_write
,
144 .endianness
= DEVICE_NATIVE_ENDIAN
,
147 static const VMStateDescription vmstate_pxa2xx_pm
= {
150 .minimum_version_id
= 0,
151 .minimum_version_id_old
= 0,
152 .fields
= (VMStateField
[]) {
153 VMSTATE_UINT32_ARRAY(pm_regs
, PXA2xxState
, 0x40),
154 VMSTATE_END_OF_LIST()
158 #define CCCR 0x00 /* Core Clock Configuration register */
159 #define CKEN 0x04 /* Clock Enable register */
160 #define OSCC 0x08 /* Oscillator Configuration register */
161 #define CCSR 0x0c /* Core Clock Status register */
163 static uint64_t pxa2xx_cm_read(void *opaque
, target_phys_addr_t addr
,
166 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
172 return s
->cm_regs
[addr
>> 2];
175 return s
->cm_regs
[CCCR
>> 2] | (3 << 28);
178 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
184 static void pxa2xx_cm_write(void *opaque
, target_phys_addr_t addr
,
185 uint64_t value
, unsigned size
)
187 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
192 s
->cm_regs
[addr
>> 2] = value
;
196 s
->cm_regs
[addr
>> 2] &= ~0x6c;
197 s
->cm_regs
[addr
>> 2] |= value
& 0x6e;
198 if ((value
>> 1) & 1) /* OON */
199 s
->cm_regs
[addr
>> 2] |= 1 << 0; /* Oscillator is now stable */
203 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
208 static const MemoryRegionOps pxa2xx_cm_ops
= {
209 .read
= pxa2xx_cm_read
,
210 .write
= pxa2xx_cm_write
,
211 .endianness
= DEVICE_NATIVE_ENDIAN
,
214 static const VMStateDescription vmstate_pxa2xx_cm
= {
217 .minimum_version_id
= 0,
218 .minimum_version_id_old
= 0,
219 .fields
= (VMStateField
[]) {
220 VMSTATE_UINT32_ARRAY(cm_regs
, PXA2xxState
, 4),
221 VMSTATE_UINT32(clkcfg
, PXA2xxState
),
222 VMSTATE_UINT32(pmnc
, PXA2xxState
),
223 VMSTATE_END_OF_LIST()
227 static uint32_t pxa2xx_clkpwr_read(void *opaque
, int op2
, int reg
, int crm
)
229 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
232 case 6: /* Clock Configuration register */
235 case 7: /* Power Mode register */
239 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
245 static void pxa2xx_clkpwr_write(void *opaque
, int op2
, int reg
, int crm
,
248 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
249 static const char *pwrmode
[8] = {
250 "Normal", "Idle", "Deep-idle", "Standby",
251 "Sleep", "reserved (!)", "reserved (!)", "Deep-sleep",
255 case 6: /* Clock Configuration register */
256 s
->clkcfg
= value
& 0xf;
258 printf("%s: CPU frequency change attempt\n", __FUNCTION__
);
261 case 7: /* Power Mode register */
263 printf("%s: CPU voltage change attempt\n", __FUNCTION__
);
271 if (!(s
->cm_regs
[CCCR
>> 2] & (1 << 31))) { /* CPDIS */
272 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
279 cpu_interrupt(s
->env
, CPU_INTERRUPT_HALT
);
280 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
284 s
->env
->uncached_cpsr
=
285 ARM_CPU_MODE_SVC
| CPSR_A
| CPSR_F
| CPSR_I
;
286 s
->env
->cp15
.c1_sys
= 0;
287 s
->env
->cp15
.c1_coproc
= 0;
288 s
->env
->cp15
.c2_base0
= 0;
290 s
->pm_regs
[PSSR
>> 2] |= 0x8; /* Set STS */
291 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
294 * The scratch-pad register is almost universally used
295 * for storing the return address on suspend. For the
296 * lack of a resuming bootloader, perform a jump
297 * directly to that address.
299 memset(s
->env
->regs
, 0, 4 * 15);
300 s
->env
->regs
[15] = s
->pm_regs
[PSPR
>> 2];
303 buffer
= 0xe59ff000; /* ldr pc, [pc, #0] */
304 cpu_physical_memory_write(0, &buffer
, 4);
305 buffer
= s
->pm_regs
[PSPR
>> 2];
306 cpu_physical_memory_write(8, &buffer
, 4);
310 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_HALT
);
316 printf("%s: machine entered %s mode\n", __FUNCTION__
,
322 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
327 /* Performace Monitoring Registers */
328 #define CPPMNC 0 /* Performance Monitor Control register */
329 #define CPCCNT 1 /* Clock Counter register */
330 #define CPINTEN 4 /* Interrupt Enable register */
331 #define CPFLAG 5 /* Overflow Flag register */
332 #define CPEVTSEL 8 /* Event Selection register */
334 #define CPPMN0 0 /* Performance Count register 0 */
335 #define CPPMN1 1 /* Performance Count register 1 */
336 #define CPPMN2 2 /* Performance Count register 2 */
337 #define CPPMN3 3 /* Performance Count register 3 */
339 static uint32_t pxa2xx_perf_read(void *opaque
, int op2
, int reg
, int crm
)
341 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
348 return qemu_get_clock_ns(vm_clock
);
357 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
363 static void pxa2xx_perf_write(void *opaque
, int op2
, int reg
, int crm
,
366 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
380 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
385 static uint32_t pxa2xx_cp14_read(void *opaque
, int op2
, int reg
, int crm
)
389 return pxa2xx_clkpwr_read(opaque
, op2
, reg
, crm
);
391 return pxa2xx_perf_read(opaque
, op2
, reg
, crm
);
402 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
408 static void pxa2xx_cp14_write(void *opaque
, int op2
, int reg
, int crm
,
413 pxa2xx_clkpwr_write(opaque
, op2
, reg
, crm
, value
);
416 pxa2xx_perf_write(opaque
, op2
, reg
, crm
, value
);
428 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
433 #define MDCNFG 0x00 /* SDRAM Configuration register */
434 #define MDREFR 0x04 /* SDRAM Refresh Control register */
435 #define MSC0 0x08 /* Static Memory Control register 0 */
436 #define MSC1 0x0c /* Static Memory Control register 1 */
437 #define MSC2 0x10 /* Static Memory Control register 2 */
438 #define MECR 0x14 /* Expansion Memory Bus Config register */
439 #define SXCNFG 0x1c /* Synchronous Static Memory Config register */
440 #define MCMEM0 0x28 /* PC Card Memory Socket 0 Timing register */
441 #define MCMEM1 0x2c /* PC Card Memory Socket 1 Timing register */
442 #define MCATT0 0x30 /* PC Card Attribute Socket 0 register */
443 #define MCATT1 0x34 /* PC Card Attribute Socket 1 register */
444 #define MCIO0 0x38 /* PC Card I/O Socket 0 Timing register */
445 #define MCIO1 0x3c /* PC Card I/O Socket 1 Timing register */
446 #define MDMRS 0x40 /* SDRAM Mode Register Set Config register */
447 #define BOOT_DEF 0x44 /* Boot-time Default Configuration register */
448 #define ARB_CNTL 0x48 /* Arbiter Control register */
449 #define BSCNTR0 0x4c /* Memory Buffer Strength Control register 0 */
450 #define BSCNTR1 0x50 /* Memory Buffer Strength Control register 1 */
451 #define LCDBSCNTR 0x54 /* LCD Buffer Strength Control register */
452 #define MDMRSLP 0x58 /* Low Power SDRAM Mode Set Config register */
453 #define BSCNTR2 0x5c /* Memory Buffer Strength Control register 2 */
454 #define BSCNTR3 0x60 /* Memory Buffer Strength Control register 3 */
455 #define SA1110 0x64 /* SA-1110 Memory Compatibility register */
457 static uint64_t pxa2xx_mm_read(void *opaque
, target_phys_addr_t addr
,
460 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
463 case MDCNFG
... SA1110
:
465 return s
->mm_regs
[addr
>> 2];
468 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
474 static void pxa2xx_mm_write(void *opaque
, target_phys_addr_t addr
,
475 uint64_t value
, unsigned size
)
477 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
480 case MDCNFG
... SA1110
:
481 if ((addr
& 3) == 0) {
482 s
->mm_regs
[addr
>> 2] = value
;
487 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
492 static const MemoryRegionOps pxa2xx_mm_ops
= {
493 .read
= pxa2xx_mm_read
,
494 .write
= pxa2xx_mm_write
,
495 .endianness
= DEVICE_NATIVE_ENDIAN
,
498 static const VMStateDescription vmstate_pxa2xx_mm
= {
501 .minimum_version_id
= 0,
502 .minimum_version_id_old
= 0,
503 .fields
= (VMStateField
[]) {
504 VMSTATE_UINT32_ARRAY(mm_regs
, PXA2xxState
, 0x1a),
505 VMSTATE_END_OF_LIST()
509 /* Synchronous Serial Ports */
526 uint32_t rx_fifo
[16];
531 #define SSCR0 0x00 /* SSP Control register 0 */
532 #define SSCR1 0x04 /* SSP Control register 1 */
533 #define SSSR 0x08 /* SSP Status register */
534 #define SSITR 0x0c /* SSP Interrupt Test register */
535 #define SSDR 0x10 /* SSP Data register */
536 #define SSTO 0x28 /* SSP Time-Out register */
537 #define SSPSP 0x2c /* SSP Programmable Serial Protocol register */
538 #define SSTSA 0x30 /* SSP TX Time Slot Active register */
539 #define SSRSA 0x34 /* SSP RX Time Slot Active register */
540 #define SSTSS 0x38 /* SSP Time Slot Status register */
541 #define SSACD 0x3c /* SSP Audio Clock Divider register */
543 /* Bitfields for above registers */
544 #define SSCR0_SPI(x) (((x) & 0x30) == 0x00)
545 #define SSCR0_SSP(x) (((x) & 0x30) == 0x10)
546 #define SSCR0_UWIRE(x) (((x) & 0x30) == 0x20)
547 #define SSCR0_PSP(x) (((x) & 0x30) == 0x30)
548 #define SSCR0_SSE (1 << 7)
549 #define SSCR0_RIM (1 << 22)
550 #define SSCR0_TIM (1 << 23)
551 #define SSCR0_MOD (1 << 31)
552 #define SSCR0_DSS(x) (((((x) >> 16) & 0x10) | ((x) & 0xf)) + 1)
553 #define SSCR1_RIE (1 << 0)
554 #define SSCR1_TIE (1 << 1)
555 #define SSCR1_LBM (1 << 2)
556 #define SSCR1_MWDS (1 << 5)
557 #define SSCR1_TFT(x) ((((x) >> 6) & 0xf) + 1)
558 #define SSCR1_RFT(x) ((((x) >> 10) & 0xf) + 1)
559 #define SSCR1_EFWR (1 << 14)
560 #define SSCR1_PINTE (1 << 18)
561 #define SSCR1_TINTE (1 << 19)
562 #define SSCR1_RSRE (1 << 20)
563 #define SSCR1_TSRE (1 << 21)
564 #define SSCR1_EBCEI (1 << 29)
565 #define SSITR_INT (7 << 5)
566 #define SSSR_TNF (1 << 2)
567 #define SSSR_RNE (1 << 3)
568 #define SSSR_TFS (1 << 5)
569 #define SSSR_RFS (1 << 6)
570 #define SSSR_ROR (1 << 7)
571 #define SSSR_PINT (1 << 18)
572 #define SSSR_TINT (1 << 19)
573 #define SSSR_EOC (1 << 20)
574 #define SSSR_TUR (1 << 21)
575 #define SSSR_BCE (1 << 23)
576 #define SSSR_RW 0x00bc0080
578 static void pxa2xx_ssp_int_update(PXA2xxSSPState
*s
)
582 level
|= s
->ssitr
& SSITR_INT
;
583 level
|= (s
->sssr
& SSSR_BCE
) && (s
->sscr
[1] & SSCR1_EBCEI
);
584 level
|= (s
->sssr
& SSSR_TUR
) && !(s
->sscr
[0] & SSCR0_TIM
);
585 level
|= (s
->sssr
& SSSR_EOC
) && (s
->sssr
& (SSSR_TINT
| SSSR_PINT
));
586 level
|= (s
->sssr
& SSSR_TINT
) && (s
->sscr
[1] & SSCR1_TINTE
);
587 level
|= (s
->sssr
& SSSR_PINT
) && (s
->sscr
[1] & SSCR1_PINTE
);
588 level
|= (s
->sssr
& SSSR_ROR
) && !(s
->sscr
[0] & SSCR0_RIM
);
589 level
|= (s
->sssr
& SSSR_RFS
) && (s
->sscr
[1] & SSCR1_RIE
);
590 level
|= (s
->sssr
& SSSR_TFS
) && (s
->sscr
[1] & SSCR1_TIE
);
591 qemu_set_irq(s
->irq
, !!level
);
594 static void pxa2xx_ssp_fifo_update(PXA2xxSSPState
*s
)
596 s
->sssr
&= ~(0xf << 12); /* Clear RFL */
597 s
->sssr
&= ~(0xf << 8); /* Clear TFL */
598 s
->sssr
&= ~SSSR_TFS
;
599 s
->sssr
&= ~SSSR_TNF
;
601 s
->sssr
|= ((s
->rx_level
- 1) & 0xf) << 12;
602 if (s
->rx_level
>= SSCR1_RFT(s
->sscr
[1]))
605 s
->sssr
&= ~SSSR_RFS
;
609 s
->sssr
&= ~SSSR_RNE
;
610 /* TX FIFO is never filled, so it is always in underrun
611 condition if SSP is enabled */
616 pxa2xx_ssp_int_update(s
);
619 static uint64_t pxa2xx_ssp_read(void *opaque
, target_phys_addr_t addr
,
622 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
637 return s
->sssr
| s
->ssitr
;
641 if (s
->rx_level
< 1) {
642 printf("%s: SSP Rx Underrun\n", __FUNCTION__
);
646 retval
= s
->rx_fifo
[s
->rx_start
++];
648 pxa2xx_ssp_fifo_update(s
);
659 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
665 static void pxa2xx_ssp_write(void *opaque
, target_phys_addr_t addr
,
666 uint64_t value64
, unsigned size
)
668 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
669 uint32_t value
= value64
;
673 s
->sscr
[0] = value
& 0xc7ffffff;
674 s
->enable
= value
& SSCR0_SSE
;
675 if (value
& SSCR0_MOD
)
676 printf("%s: Attempt to use network mode\n", __FUNCTION__
);
677 if (s
->enable
&& SSCR0_DSS(value
) < 4)
678 printf("%s: Wrong data size: %i bits\n", __FUNCTION__
,
680 if (!(value
& SSCR0_SSE
)) {
685 pxa2xx_ssp_fifo_update(s
);
690 if (value
& (SSCR1_LBM
| SSCR1_EFWR
))
691 printf("%s: Attempt to use SSP test mode\n", __FUNCTION__
);
692 pxa2xx_ssp_fifo_update(s
);
704 s
->ssitr
= value
& SSITR_INT
;
705 pxa2xx_ssp_int_update(s
);
709 s
->sssr
&= ~(value
& SSSR_RW
);
710 pxa2xx_ssp_int_update(s
);
714 if (SSCR0_UWIRE(s
->sscr
[0])) {
715 if (s
->sscr
[1] & SSCR1_MWDS
)
720 /* Note how 32bits overflow does no harm here */
721 value
&= (1 << SSCR0_DSS(s
->sscr
[0])) - 1;
723 /* Data goes from here to the Tx FIFO and is shifted out from
724 * there directly to the slave, no need to buffer it.
728 readval
= ssi_transfer(s
->bus
, value
);
729 if (s
->rx_level
< 0x10) {
730 s
->rx_fifo
[(s
->rx_start
+ s
->rx_level
++) & 0xf] = readval
;
735 pxa2xx_ssp_fifo_update(s
);
751 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
756 static const MemoryRegionOps pxa2xx_ssp_ops
= {
757 .read
= pxa2xx_ssp_read
,
758 .write
= pxa2xx_ssp_write
,
759 .endianness
= DEVICE_NATIVE_ENDIAN
,
762 static void pxa2xx_ssp_save(QEMUFile
*f
, void *opaque
)
764 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
767 qemu_put_be32(f
, s
->enable
);
769 qemu_put_be32s(f
, &s
->sscr
[0]);
770 qemu_put_be32s(f
, &s
->sscr
[1]);
771 qemu_put_be32s(f
, &s
->sspsp
);
772 qemu_put_be32s(f
, &s
->ssto
);
773 qemu_put_be32s(f
, &s
->ssitr
);
774 qemu_put_be32s(f
, &s
->sssr
);
775 qemu_put_8s(f
, &s
->sstsa
);
776 qemu_put_8s(f
, &s
->ssrsa
);
777 qemu_put_8s(f
, &s
->ssacd
);
779 qemu_put_byte(f
, s
->rx_level
);
780 for (i
= 0; i
< s
->rx_level
; i
++)
781 qemu_put_byte(f
, s
->rx_fifo
[(s
->rx_start
+ i
) & 0xf]);
784 static int pxa2xx_ssp_load(QEMUFile
*f
, void *opaque
, int version_id
)
786 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
789 s
->enable
= qemu_get_be32(f
);
791 qemu_get_be32s(f
, &s
->sscr
[0]);
792 qemu_get_be32s(f
, &s
->sscr
[1]);
793 qemu_get_be32s(f
, &s
->sspsp
);
794 qemu_get_be32s(f
, &s
->ssto
);
795 qemu_get_be32s(f
, &s
->ssitr
);
796 qemu_get_be32s(f
, &s
->sssr
);
797 qemu_get_8s(f
, &s
->sstsa
);
798 qemu_get_8s(f
, &s
->ssrsa
);
799 qemu_get_8s(f
, &s
->ssacd
);
801 s
->rx_level
= qemu_get_byte(f
);
803 for (i
= 0; i
< s
->rx_level
; i
++)
804 s
->rx_fifo
[i
] = qemu_get_byte(f
);
809 static int pxa2xx_ssp_init(SysBusDevice
*dev
)
811 PXA2xxSSPState
*s
= FROM_SYSBUS(PXA2xxSSPState
, dev
);
813 sysbus_init_irq(dev
, &s
->irq
);
815 memory_region_init_io(&s
->iomem
, &pxa2xx_ssp_ops
, s
, "pxa2xx-ssp", 0x1000);
816 sysbus_init_mmio(dev
, &s
->iomem
);
817 register_savevm(&dev
->qdev
, "pxa2xx_ssp", -1, 0,
818 pxa2xx_ssp_save
, pxa2xx_ssp_load
, s
);
820 s
->bus
= ssi_create_bus(&dev
->qdev
, "ssi");
824 /* Real-Time Clock */
825 #define RCNR 0x00 /* RTC Counter register */
826 #define RTAR 0x04 /* RTC Alarm register */
827 #define RTSR 0x08 /* RTC Status register */
828 #define RTTR 0x0c /* RTC Timer Trim register */
829 #define RDCR 0x10 /* RTC Day Counter register */
830 #define RYCR 0x14 /* RTC Year Counter register */
831 #define RDAR1 0x18 /* RTC Wristwatch Day Alarm register 1 */
832 #define RYAR1 0x1c /* RTC Wristwatch Year Alarm register 1 */
833 #define RDAR2 0x20 /* RTC Wristwatch Day Alarm register 2 */
834 #define RYAR2 0x24 /* RTC Wristwatch Year Alarm register 2 */
835 #define SWCR 0x28 /* RTC Stopwatch Counter register */
836 #define SWAR1 0x2c /* RTC Stopwatch Alarm register 1 */
837 #define SWAR2 0x30 /* RTC Stopwatch Alarm register 2 */
838 #define RTCPICR 0x34 /* RTC Periodic Interrupt Counter register */
839 #define PIAR 0x38 /* RTC Periodic Interrupt Alarm register */
858 uint32_t last_rtcpicr
;
863 QEMUTimer
*rtc_rdal1
;
864 QEMUTimer
*rtc_rdal2
;
865 QEMUTimer
*rtc_swal1
;
866 QEMUTimer
*rtc_swal2
;
871 static inline void pxa2xx_rtc_int_update(PXA2xxRTCState
*s
)
873 qemu_set_irq(s
->rtc_irq
, !!(s
->rtsr
& 0x2553));
876 static void pxa2xx_rtc_hzupdate(PXA2xxRTCState
*s
)
878 int64_t rt
= qemu_get_clock_ms(rt_clock
);
879 s
->last_rcnr
+= ((rt
- s
->last_hz
) << 15) /
880 (1000 * ((s
->rttr
& 0xffff) + 1));
881 s
->last_rdcr
+= ((rt
- s
->last_hz
) << 15) /
882 (1000 * ((s
->rttr
& 0xffff) + 1));
886 static void pxa2xx_rtc_swupdate(PXA2xxRTCState
*s
)
888 int64_t rt
= qemu_get_clock_ms(rt_clock
);
889 if (s
->rtsr
& (1 << 12))
890 s
->last_swcr
+= (rt
- s
->last_sw
) / 10;
894 static void pxa2xx_rtc_piupdate(PXA2xxRTCState
*s
)
896 int64_t rt
= qemu_get_clock_ms(rt_clock
);
897 if (s
->rtsr
& (1 << 15))
898 s
->last_swcr
+= rt
- s
->last_pi
;
902 static inline void pxa2xx_rtc_alarm_update(PXA2xxRTCState
*s
,
905 if ((rtsr
& (1 << 2)) && !(rtsr
& (1 << 0)))
906 qemu_mod_timer(s
->rtc_hz
, s
->last_hz
+
907 (((s
->rtar
- s
->last_rcnr
) * 1000 *
908 ((s
->rttr
& 0xffff) + 1)) >> 15));
910 qemu_del_timer(s
->rtc_hz
);
912 if ((rtsr
& (1 << 5)) && !(rtsr
& (1 << 4)))
913 qemu_mod_timer(s
->rtc_rdal1
, s
->last_hz
+
914 (((s
->rdar1
- s
->last_rdcr
) * 1000 *
915 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
917 qemu_del_timer(s
->rtc_rdal1
);
919 if ((rtsr
& (1 << 7)) && !(rtsr
& (1 << 6)))
920 qemu_mod_timer(s
->rtc_rdal2
, s
->last_hz
+
921 (((s
->rdar2
- s
->last_rdcr
) * 1000 *
922 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
924 qemu_del_timer(s
->rtc_rdal2
);
926 if ((rtsr
& 0x1200) == 0x1200 && !(rtsr
& (1 << 8)))
927 qemu_mod_timer(s
->rtc_swal1
, s
->last_sw
+
928 (s
->swar1
- s
->last_swcr
) * 10); /* TODO: fixup */
930 qemu_del_timer(s
->rtc_swal1
);
932 if ((rtsr
& 0x1800) == 0x1800 && !(rtsr
& (1 << 10)))
933 qemu_mod_timer(s
->rtc_swal2
, s
->last_sw
+
934 (s
->swar2
- s
->last_swcr
) * 10); /* TODO: fixup */
936 qemu_del_timer(s
->rtc_swal2
);
938 if ((rtsr
& 0xc000) == 0xc000 && !(rtsr
& (1 << 13)))
939 qemu_mod_timer(s
->rtc_pi
, s
->last_pi
+
940 (s
->piar
& 0xffff) - s
->last_rtcpicr
);
942 qemu_del_timer(s
->rtc_pi
);
945 static inline void pxa2xx_rtc_hz_tick(void *opaque
)
947 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
949 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
950 pxa2xx_rtc_int_update(s
);
953 static inline void pxa2xx_rtc_rdal1_tick(void *opaque
)
955 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
957 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
958 pxa2xx_rtc_int_update(s
);
961 static inline void pxa2xx_rtc_rdal2_tick(void *opaque
)
963 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
965 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
966 pxa2xx_rtc_int_update(s
);
969 static inline void pxa2xx_rtc_swal1_tick(void *opaque
)
971 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
973 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
974 pxa2xx_rtc_int_update(s
);
977 static inline void pxa2xx_rtc_swal2_tick(void *opaque
)
979 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
980 s
->rtsr
|= (1 << 10);
981 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
982 pxa2xx_rtc_int_update(s
);
985 static inline void pxa2xx_rtc_pi_tick(void *opaque
)
987 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
988 s
->rtsr
|= (1 << 13);
989 pxa2xx_rtc_piupdate(s
);
991 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
992 pxa2xx_rtc_int_update(s
);
995 static uint64_t pxa2xx_rtc_read(void *opaque
, target_phys_addr_t addr
,
998 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1022 return s
->last_rcnr
+ ((qemu_get_clock_ms(rt_clock
) - s
->last_hz
) << 15) /
1023 (1000 * ((s
->rttr
& 0xffff) + 1));
1025 return s
->last_rdcr
+ ((qemu_get_clock_ms(rt_clock
) - s
->last_hz
) << 15) /
1026 (1000 * ((s
->rttr
& 0xffff) + 1));
1028 return s
->last_rycr
;
1030 if (s
->rtsr
& (1 << 12))
1031 return s
->last_swcr
+ (qemu_get_clock_ms(rt_clock
) - s
->last_sw
) / 10;
1033 return s
->last_swcr
;
1035 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1041 static void pxa2xx_rtc_write(void *opaque
, target_phys_addr_t addr
,
1042 uint64_t value64
, unsigned size
)
1044 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1045 uint32_t value
= value64
;
1049 if (!(s
->rttr
& (1 << 31))) {
1050 pxa2xx_rtc_hzupdate(s
);
1052 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1057 if ((s
->rtsr
^ value
) & (1 << 15))
1058 pxa2xx_rtc_piupdate(s
);
1060 if ((s
->rtsr
^ value
) & (1 << 12))
1061 pxa2xx_rtc_swupdate(s
);
1063 if (((s
->rtsr
^ value
) & 0x4aac) | (value
& ~0xdaac))
1064 pxa2xx_rtc_alarm_update(s
, value
);
1066 s
->rtsr
= (value
& 0xdaac) | (s
->rtsr
& ~(value
& ~0xdaac));
1067 pxa2xx_rtc_int_update(s
);
1072 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1077 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1082 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1087 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1092 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1096 pxa2xx_rtc_swupdate(s
);
1099 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1104 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1109 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1113 pxa2xx_rtc_hzupdate(s
);
1114 s
->last_rcnr
= value
;
1115 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1119 pxa2xx_rtc_hzupdate(s
);
1120 s
->last_rdcr
= value
;
1121 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1125 s
->last_rycr
= value
;
1129 pxa2xx_rtc_swupdate(s
);
1130 s
->last_swcr
= value
;
1131 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1135 pxa2xx_rtc_piupdate(s
);
1136 s
->last_rtcpicr
= value
& 0xffff;
1137 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1141 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1145 static const MemoryRegionOps pxa2xx_rtc_ops
= {
1146 .read
= pxa2xx_rtc_read
,
1147 .write
= pxa2xx_rtc_write
,
1148 .endianness
= DEVICE_NATIVE_ENDIAN
,
1151 static int pxa2xx_rtc_init(SysBusDevice
*dev
)
1153 PXA2xxRTCState
*s
= FROM_SYSBUS(PXA2xxRTCState
, dev
);
1160 qemu_get_timedate(&tm
, 0);
1161 wom
= ((tm
.tm_mday
- 1) / 7) + 1;
1163 s
->last_rcnr
= (uint32_t) mktimegm(&tm
);
1164 s
->last_rdcr
= (wom
<< 20) | ((tm
.tm_wday
+ 1) << 17) |
1165 (tm
.tm_hour
<< 12) | (tm
.tm_min
<< 6) | tm
.tm_sec
;
1166 s
->last_rycr
= ((tm
.tm_year
+ 1900) << 9) |
1167 ((tm
.tm_mon
+ 1) << 5) | tm
.tm_mday
;
1168 s
->last_swcr
= (tm
.tm_hour
<< 19) |
1169 (tm
.tm_min
<< 13) | (tm
.tm_sec
<< 7);
1170 s
->last_rtcpicr
= 0;
1171 s
->last_hz
= s
->last_sw
= s
->last_pi
= qemu_get_clock_ms(rt_clock
);
1173 s
->rtc_hz
= qemu_new_timer_ms(rt_clock
, pxa2xx_rtc_hz_tick
, s
);
1174 s
->rtc_rdal1
= qemu_new_timer_ms(rt_clock
, pxa2xx_rtc_rdal1_tick
, s
);
1175 s
->rtc_rdal2
= qemu_new_timer_ms(rt_clock
, pxa2xx_rtc_rdal2_tick
, s
);
1176 s
->rtc_swal1
= qemu_new_timer_ms(rt_clock
, pxa2xx_rtc_swal1_tick
, s
);
1177 s
->rtc_swal2
= qemu_new_timer_ms(rt_clock
, pxa2xx_rtc_swal2_tick
, s
);
1178 s
->rtc_pi
= qemu_new_timer_ms(rt_clock
, pxa2xx_rtc_pi_tick
, s
);
1180 sysbus_init_irq(dev
, &s
->rtc_irq
);
1182 memory_region_init_io(&s
->iomem
, &pxa2xx_rtc_ops
, s
, "pxa2xx-rtc", 0x10000);
1183 sysbus_init_mmio(dev
, &s
->iomem
);
1188 static void pxa2xx_rtc_pre_save(void *opaque
)
1190 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1192 pxa2xx_rtc_hzupdate(s
);
1193 pxa2xx_rtc_piupdate(s
);
1194 pxa2xx_rtc_swupdate(s
);
1197 static int pxa2xx_rtc_post_load(void *opaque
, int version_id
)
1199 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1201 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1206 static const VMStateDescription vmstate_pxa2xx_rtc_regs
= {
1207 .name
= "pxa2xx_rtc",
1209 .minimum_version_id
= 0,
1210 .minimum_version_id_old
= 0,
1211 .pre_save
= pxa2xx_rtc_pre_save
,
1212 .post_load
= pxa2xx_rtc_post_load
,
1213 .fields
= (VMStateField
[]) {
1214 VMSTATE_UINT32(rttr
, PXA2xxRTCState
),
1215 VMSTATE_UINT32(rtsr
, PXA2xxRTCState
),
1216 VMSTATE_UINT32(rtar
, PXA2xxRTCState
),
1217 VMSTATE_UINT32(rdar1
, PXA2xxRTCState
),
1218 VMSTATE_UINT32(rdar2
, PXA2xxRTCState
),
1219 VMSTATE_UINT32(ryar1
, PXA2xxRTCState
),
1220 VMSTATE_UINT32(ryar2
, PXA2xxRTCState
),
1221 VMSTATE_UINT32(swar1
, PXA2xxRTCState
),
1222 VMSTATE_UINT32(swar2
, PXA2xxRTCState
),
1223 VMSTATE_UINT32(piar
, PXA2xxRTCState
),
1224 VMSTATE_UINT32(last_rcnr
, PXA2xxRTCState
),
1225 VMSTATE_UINT32(last_rdcr
, PXA2xxRTCState
),
1226 VMSTATE_UINT32(last_rycr
, PXA2xxRTCState
),
1227 VMSTATE_UINT32(last_swcr
, PXA2xxRTCState
),
1228 VMSTATE_UINT32(last_rtcpicr
, PXA2xxRTCState
),
1229 VMSTATE_INT64(last_hz
, PXA2xxRTCState
),
1230 VMSTATE_INT64(last_sw
, PXA2xxRTCState
),
1231 VMSTATE_INT64(last_pi
, PXA2xxRTCState
),
1232 VMSTATE_END_OF_LIST(),
1236 static void pxa2xx_rtc_sysbus_class_init(ObjectClass
*klass
, void *data
)
1238 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1239 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1241 k
->init
= pxa2xx_rtc_init
;
1242 dc
->desc
= "PXA2xx RTC Controller";
1243 dc
->vmsd
= &vmstate_pxa2xx_rtc_regs
;
1246 static TypeInfo pxa2xx_rtc_sysbus_info
= {
1247 .name
= "pxa2xx_rtc",
1248 .parent
= TYPE_SYS_BUS_DEVICE
,
1249 .instance_size
= sizeof(PXA2xxRTCState
),
1250 .class_init
= pxa2xx_rtc_sysbus_class_init
,
1256 PXA2xxI2CState
*host
;
1257 } PXA2xxI2CSlaveState
;
1259 struct PXA2xxI2CState
{
1260 SysBusDevice busdev
;
1262 PXA2xxI2CSlaveState
*slave
;
1266 uint32_t region_size
;
1274 #define IBMR 0x80 /* I2C Bus Monitor register */
1275 #define IDBR 0x88 /* I2C Data Buffer register */
1276 #define ICR 0x90 /* I2C Control register */
1277 #define ISR 0x98 /* I2C Status register */
1278 #define ISAR 0xa0 /* I2C Slave Address register */
1280 static void pxa2xx_i2c_update(PXA2xxI2CState
*s
)
1283 level
|= s
->status
& s
->control
& (1 << 10); /* BED */
1284 level
|= (s
->status
& (1 << 7)) && (s
->control
& (1 << 9)); /* IRF */
1285 level
|= (s
->status
& (1 << 6)) && (s
->control
& (1 << 8)); /* ITE */
1286 level
|= s
->status
& (1 << 9); /* SAD */
1287 qemu_set_irq(s
->irq
, !!level
);
1290 /* These are only stubs now. */
1291 static void pxa2xx_i2c_event(I2CSlave
*i2c
, enum i2c_event event
)
1293 PXA2xxI2CSlaveState
*slave
= FROM_I2C_SLAVE(PXA2xxI2CSlaveState
, i2c
);
1294 PXA2xxI2CState
*s
= slave
->host
;
1297 case I2C_START_SEND
:
1298 s
->status
|= (1 << 9); /* set SAD */
1299 s
->status
&= ~(1 << 0); /* clear RWM */
1301 case I2C_START_RECV
:
1302 s
->status
|= (1 << 9); /* set SAD */
1303 s
->status
|= 1 << 0; /* set RWM */
1306 s
->status
|= (1 << 4); /* set SSD */
1309 s
->status
|= 1 << 1; /* set ACKNAK */
1312 pxa2xx_i2c_update(s
);
1315 static int pxa2xx_i2c_rx(I2CSlave
*i2c
)
1317 PXA2xxI2CSlaveState
*slave
= FROM_I2C_SLAVE(PXA2xxI2CSlaveState
, i2c
);
1318 PXA2xxI2CState
*s
= slave
->host
;
1319 if ((s
->control
& (1 << 14)) || !(s
->control
& (1 << 6)))
1322 if (s
->status
& (1 << 0)) { /* RWM */
1323 s
->status
|= 1 << 6; /* set ITE */
1325 pxa2xx_i2c_update(s
);
1330 static int pxa2xx_i2c_tx(I2CSlave
*i2c
, uint8_t data
)
1332 PXA2xxI2CSlaveState
*slave
= FROM_I2C_SLAVE(PXA2xxI2CSlaveState
, i2c
);
1333 PXA2xxI2CState
*s
= slave
->host
;
1334 if ((s
->control
& (1 << 14)) || !(s
->control
& (1 << 6)))
1337 if (!(s
->status
& (1 << 0))) { /* RWM */
1338 s
->status
|= 1 << 7; /* set IRF */
1341 pxa2xx_i2c_update(s
);
1346 static uint64_t pxa2xx_i2c_read(void *opaque
, target_phys_addr_t addr
,
1349 PXA2xxI2CState
*s
= (PXA2xxI2CState
*) opaque
;
1356 return s
->status
| (i2c_bus_busy(s
->bus
) << 2);
1358 return s
->slave
->i2c
.address
;
1362 if (s
->status
& (1 << 2))
1363 s
->ibmr
^= 3; /* Fake SCL and SDA pin changes */
1368 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1374 static void pxa2xx_i2c_write(void *opaque
, target_phys_addr_t addr
,
1375 uint64_t value64
, unsigned size
)
1377 PXA2xxI2CState
*s
= (PXA2xxI2CState
*) opaque
;
1378 uint32_t value
= value64
;
1384 s
->control
= value
& 0xfff7;
1385 if ((value
& (1 << 3)) && (value
& (1 << 6))) { /* TB and IUE */
1386 /* TODO: slave mode */
1387 if (value
& (1 << 0)) { /* START condition */
1389 s
->status
|= 1 << 0; /* set RWM */
1391 s
->status
&= ~(1 << 0); /* clear RWM */
1392 ack
= !i2c_start_transfer(s
->bus
, s
->data
>> 1, s
->data
& 1);
1394 if (s
->status
& (1 << 0)) { /* RWM */
1395 s
->data
= i2c_recv(s
->bus
);
1396 if (value
& (1 << 2)) /* ACKNAK */
1400 ack
= !i2c_send(s
->bus
, s
->data
);
1403 if (value
& (1 << 1)) /* STOP condition */
1404 i2c_end_transfer(s
->bus
);
1407 if (value
& (1 << 0)) /* START condition */
1408 s
->status
|= 1 << 6; /* set ITE */
1410 if (s
->status
& (1 << 0)) /* RWM */
1411 s
->status
|= 1 << 7; /* set IRF */
1413 s
->status
|= 1 << 6; /* set ITE */
1414 s
->status
&= ~(1 << 1); /* clear ACKNAK */
1416 s
->status
|= 1 << 6; /* set ITE */
1417 s
->status
|= 1 << 10; /* set BED */
1418 s
->status
|= 1 << 1; /* set ACKNAK */
1421 if (!(value
& (1 << 3)) && (value
& (1 << 6))) /* !TB and IUE */
1422 if (value
& (1 << 4)) /* MA */
1423 i2c_end_transfer(s
->bus
);
1424 pxa2xx_i2c_update(s
);
1428 s
->status
&= ~(value
& 0x07f0);
1429 pxa2xx_i2c_update(s
);
1433 i2c_set_slave_address(&s
->slave
->i2c
, value
& 0x7f);
1437 s
->data
= value
& 0xff;
1441 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1445 static const MemoryRegionOps pxa2xx_i2c_ops
= {
1446 .read
= pxa2xx_i2c_read
,
1447 .write
= pxa2xx_i2c_write
,
1448 .endianness
= DEVICE_NATIVE_ENDIAN
,
1451 static const VMStateDescription vmstate_pxa2xx_i2c_slave
= {
1452 .name
= "pxa2xx_i2c_slave",
1454 .minimum_version_id
= 1,
1455 .minimum_version_id_old
= 1,
1456 .fields
= (VMStateField
[]) {
1457 VMSTATE_I2C_SLAVE(i2c
, PXA2xxI2CSlaveState
),
1458 VMSTATE_END_OF_LIST()
1462 static const VMStateDescription vmstate_pxa2xx_i2c
= {
1463 .name
= "pxa2xx_i2c",
1465 .minimum_version_id
= 1,
1466 .minimum_version_id_old
= 1,
1467 .fields
= (VMStateField
[]) {
1468 VMSTATE_UINT16(control
, PXA2xxI2CState
),
1469 VMSTATE_UINT16(status
, PXA2xxI2CState
),
1470 VMSTATE_UINT8(ibmr
, PXA2xxI2CState
),
1471 VMSTATE_UINT8(data
, PXA2xxI2CState
),
1472 VMSTATE_STRUCT_POINTER(slave
, PXA2xxI2CState
,
1473 vmstate_pxa2xx_i2c_slave
, PXA2xxI2CSlaveState
*),
1474 VMSTATE_END_OF_LIST()
1478 static int pxa2xx_i2c_slave_init(I2CSlave
*i2c
)
1480 /* Nothing to do. */
1484 static void pxa2xx_i2c_slave_class_init(ObjectClass
*klass
, void *data
)
1486 I2CSlaveClass
*k
= I2C_SLAVE_CLASS(klass
);
1488 k
->init
= pxa2xx_i2c_slave_init
;
1489 k
->event
= pxa2xx_i2c_event
;
1490 k
->recv
= pxa2xx_i2c_rx
;
1491 k
->send
= pxa2xx_i2c_tx
;
1494 static TypeInfo pxa2xx_i2c_slave_info
= {
1495 .name
= "pxa2xx-i2c-slave",
1496 .parent
= TYPE_I2C_SLAVE
,
1497 .instance_size
= sizeof(PXA2xxI2CSlaveState
),
1498 .class_init
= pxa2xx_i2c_slave_class_init
,
1501 PXA2xxI2CState
*pxa2xx_i2c_init(target_phys_addr_t base
,
1502 qemu_irq irq
, uint32_t region_size
)
1505 SysBusDevice
*i2c_dev
;
1508 i2c_dev
= sysbus_from_qdev(qdev_create(NULL
, "pxa2xx_i2c"));
1509 qdev_prop_set_uint32(&i2c_dev
->qdev
, "size", region_size
+ 1);
1510 qdev_prop_set_uint32(&i2c_dev
->qdev
, "offset",
1511 base
- (base
& (~region_size
) & TARGET_PAGE_MASK
));
1513 qdev_init_nofail(&i2c_dev
->qdev
);
1515 sysbus_mmio_map(i2c_dev
, 0, base
& ~region_size
);
1516 sysbus_connect_irq(i2c_dev
, 0, irq
);
1518 s
= FROM_SYSBUS(PXA2xxI2CState
, i2c_dev
);
1519 /* FIXME: Should the slave device really be on a separate bus? */
1520 dev
= i2c_create_slave(i2c_init_bus(NULL
, "dummy"), "pxa2xx-i2c-slave", 0);
1521 s
->slave
= FROM_I2C_SLAVE(PXA2xxI2CSlaveState
, I2C_SLAVE_FROM_QDEV(dev
));
1527 static int pxa2xx_i2c_initfn(SysBusDevice
*dev
)
1529 PXA2xxI2CState
*s
= FROM_SYSBUS(PXA2xxI2CState
, dev
);
1531 s
->bus
= i2c_init_bus(&dev
->qdev
, "i2c");
1533 memory_region_init_io(&s
->iomem
, &pxa2xx_i2c_ops
, s
,
1534 "pxa2xx-i2x", s
->region_size
);
1535 sysbus_init_mmio(dev
, &s
->iomem
);
1536 sysbus_init_irq(dev
, &s
->irq
);
1541 i2c_bus
*pxa2xx_i2c_bus(PXA2xxI2CState
*s
)
1546 static Property pxa2xx_i2c_properties
[] = {
1547 DEFINE_PROP_UINT32("size", PXA2xxI2CState
, region_size
, 0x10000),
1548 DEFINE_PROP_UINT32("offset", PXA2xxI2CState
, offset
, 0),
1549 DEFINE_PROP_END_OF_LIST(),
1552 static void pxa2xx_i2c_class_init(ObjectClass
*klass
, void *data
)
1554 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1555 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1557 k
->init
= pxa2xx_i2c_initfn
;
1558 dc
->desc
= "PXA2xx I2C Bus Controller";
1559 dc
->vmsd
= &vmstate_pxa2xx_i2c
;
1560 dc
->props
= pxa2xx_i2c_properties
;
1563 static TypeInfo pxa2xx_i2c_info
= {
1564 .name
= "pxa2xx_i2c",
1565 .parent
= TYPE_SYS_BUS_DEVICE
,
1566 .instance_size
= sizeof(PXA2xxI2CState
),
1567 .class_init
= pxa2xx_i2c_class_init
,
1570 /* PXA Inter-IC Sound Controller */
1571 static void pxa2xx_i2s_reset(PXA2xxI2SState
*i2s
)
1577 i2s
->control
[0] = 0x00;
1578 i2s
->control
[1] = 0x00;
1583 #define SACR_TFTH(val) ((val >> 8) & 0xf)
1584 #define SACR_RFTH(val) ((val >> 12) & 0xf)
1585 #define SACR_DREC(val) (val & (1 << 3))
1586 #define SACR_DPRL(val) (val & (1 << 4))
1588 static inline void pxa2xx_i2s_update(PXA2xxI2SState
*i2s
)
1591 rfs
= SACR_RFTH(i2s
->control
[0]) < i2s
->rx_len
&&
1592 !SACR_DREC(i2s
->control
[1]);
1593 tfs
= (i2s
->tx_len
|| i2s
->fifo_len
< SACR_TFTH(i2s
->control
[0])) &&
1594 i2s
->enable
&& !SACR_DPRL(i2s
->control
[1]);
1596 qemu_set_irq(i2s
->rx_dma
, rfs
);
1597 qemu_set_irq(i2s
->tx_dma
, tfs
);
1599 i2s
->status
&= 0xe0;
1600 if (i2s
->fifo_len
< 16 || !i2s
->enable
)
1601 i2s
->status
|= 1 << 0; /* TNF */
1603 i2s
->status
|= 1 << 1; /* RNE */
1605 i2s
->status
|= 1 << 2; /* BSY */
1607 i2s
->status
|= 1 << 3; /* TFS */
1609 i2s
->status
|= 1 << 4; /* RFS */
1610 if (!(i2s
->tx_len
&& i2s
->enable
))
1611 i2s
->status
|= i2s
->fifo_len
<< 8; /* TFL */
1612 i2s
->status
|= MAX(i2s
->rx_len
, 0xf) << 12; /* RFL */
1614 qemu_set_irq(i2s
->irq
, i2s
->status
& i2s
->mask
);
1617 #define SACR0 0x00 /* Serial Audio Global Control register */
1618 #define SACR1 0x04 /* Serial Audio I2S/MSB-Justified Control register */
1619 #define SASR0 0x0c /* Serial Audio Interface and FIFO Status register */
1620 #define SAIMR 0x14 /* Serial Audio Interrupt Mask register */
1621 #define SAICR 0x18 /* Serial Audio Interrupt Clear register */
1622 #define SADIV 0x60 /* Serial Audio Clock Divider register */
1623 #define SADR 0x80 /* Serial Audio Data register */
1625 static uint64_t pxa2xx_i2s_read(void *opaque
, target_phys_addr_t addr
,
1628 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1632 return s
->control
[0];
1634 return s
->control
[1];
1644 if (s
->rx_len
> 0) {
1646 pxa2xx_i2s_update(s
);
1647 return s
->codec_in(s
->opaque
);
1651 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1657 static void pxa2xx_i2s_write(void *opaque
, target_phys_addr_t addr
,
1658 uint64_t value
, unsigned size
)
1660 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1665 if (value
& (1 << 3)) /* RST */
1666 pxa2xx_i2s_reset(s
);
1667 s
->control
[0] = value
& 0xff3d;
1668 if (!s
->enable
&& (value
& 1) && s
->tx_len
) { /* ENB */
1669 for (sample
= s
->fifo
; s
->fifo_len
> 0; s
->fifo_len
--, sample
++)
1670 s
->codec_out(s
->opaque
, *sample
);
1671 s
->status
&= ~(1 << 7); /* I2SOFF */
1673 if (value
& (1 << 4)) /* EFWR */
1674 printf("%s: Attempt to use special function\n", __FUNCTION__
);
1675 s
->enable
= (value
& 9) == 1; /* ENB && !RST*/
1676 pxa2xx_i2s_update(s
);
1679 s
->control
[1] = value
& 0x0039;
1680 if (value
& (1 << 5)) /* ENLBF */
1681 printf("%s: Attempt to use loopback function\n", __FUNCTION__
);
1682 if (value
& (1 << 4)) /* DPRL */
1684 pxa2xx_i2s_update(s
);
1687 s
->mask
= value
& 0x0078;
1688 pxa2xx_i2s_update(s
);
1691 s
->status
&= ~(value
& (3 << 5));
1692 pxa2xx_i2s_update(s
);
1695 s
->clk
= value
& 0x007f;
1698 if (s
->tx_len
&& s
->enable
) {
1700 pxa2xx_i2s_update(s
);
1701 s
->codec_out(s
->opaque
, value
);
1702 } else if (s
->fifo_len
< 16) {
1703 s
->fifo
[s
->fifo_len
++] = value
;
1704 pxa2xx_i2s_update(s
);
1708 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1712 static const MemoryRegionOps pxa2xx_i2s_ops
= {
1713 .read
= pxa2xx_i2s_read
,
1714 .write
= pxa2xx_i2s_write
,
1715 .endianness
= DEVICE_NATIVE_ENDIAN
,
1718 static const VMStateDescription vmstate_pxa2xx_i2s
= {
1719 .name
= "pxa2xx_i2s",
1721 .minimum_version_id
= 0,
1722 .minimum_version_id_old
= 0,
1723 .fields
= (VMStateField
[]) {
1724 VMSTATE_UINT32_ARRAY(control
, PXA2xxI2SState
, 2),
1725 VMSTATE_UINT32(status
, PXA2xxI2SState
),
1726 VMSTATE_UINT32(mask
, PXA2xxI2SState
),
1727 VMSTATE_UINT32(clk
, PXA2xxI2SState
),
1728 VMSTATE_INT32(enable
, PXA2xxI2SState
),
1729 VMSTATE_INT32(rx_len
, PXA2xxI2SState
),
1730 VMSTATE_INT32(tx_len
, PXA2xxI2SState
),
1731 VMSTATE_INT32(fifo_len
, PXA2xxI2SState
),
1732 VMSTATE_END_OF_LIST()
1736 static void pxa2xx_i2s_data_req(void *opaque
, int tx
, int rx
)
1738 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1741 /* Signal FIFO errors */
1742 if (s
->enable
&& s
->tx_len
)
1743 s
->status
|= 1 << 5; /* TUR */
1744 if (s
->enable
&& s
->rx_len
)
1745 s
->status
|= 1 << 6; /* ROR */
1747 /* Should be tx - MIN(tx, s->fifo_len) but we don't really need to
1748 * handle the cases where it makes a difference. */
1749 s
->tx_len
= tx
- s
->fifo_len
;
1751 /* Note that is s->codec_out wasn't set, we wouldn't get called. */
1753 for (sample
= s
->fifo
; s
->fifo_len
; s
->fifo_len
--, sample
++)
1754 s
->codec_out(s
->opaque
, *sample
);
1755 pxa2xx_i2s_update(s
);
1758 static PXA2xxI2SState
*pxa2xx_i2s_init(MemoryRegion
*sysmem
,
1759 target_phys_addr_t base
,
1760 qemu_irq irq
, qemu_irq rx_dma
, qemu_irq tx_dma
)
1762 PXA2xxI2SState
*s
= (PXA2xxI2SState
*)
1763 g_malloc0(sizeof(PXA2xxI2SState
));
1768 s
->data_req
= pxa2xx_i2s_data_req
;
1770 pxa2xx_i2s_reset(s
);
1772 memory_region_init_io(&s
->iomem
, &pxa2xx_i2s_ops
, s
,
1773 "pxa2xx-i2s", 0x100000);
1774 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
1776 vmstate_register(NULL
, base
, &vmstate_pxa2xx_i2s
, s
);
1781 /* PXA Fast Infra-red Communications Port */
1782 struct PXA2xxFIrState
{
1788 CharDriverState
*chr
;
1795 uint8_t rx_fifo
[64];
1798 static void pxa2xx_fir_reset(PXA2xxFIrState
*s
)
1800 s
->control
[0] = 0x00;
1801 s
->control
[1] = 0x00;
1802 s
->control
[2] = 0x00;
1803 s
->status
[0] = 0x00;
1804 s
->status
[1] = 0x00;
1808 static inline void pxa2xx_fir_update(PXA2xxFIrState
*s
)
1810 static const int tresh
[4] = { 8, 16, 32, 0 };
1812 if ((s
->control
[0] & (1 << 4)) && /* RXE */
1813 s
->rx_len
>= tresh
[s
->control
[2] & 3]) /* TRIG */
1814 s
->status
[0] |= 1 << 4; /* RFS */
1816 s
->status
[0] &= ~(1 << 4); /* RFS */
1817 if (s
->control
[0] & (1 << 3)) /* TXE */
1818 s
->status
[0] |= 1 << 3; /* TFS */
1820 s
->status
[0] &= ~(1 << 3); /* TFS */
1822 s
->status
[1] |= 1 << 2; /* RNE */
1824 s
->status
[1] &= ~(1 << 2); /* RNE */
1825 if (s
->control
[0] & (1 << 4)) /* RXE */
1826 s
->status
[1] |= 1 << 0; /* RSY */
1828 s
->status
[1] &= ~(1 << 0); /* RSY */
1830 intr
|= (s
->control
[0] & (1 << 5)) && /* RIE */
1831 (s
->status
[0] & (1 << 4)); /* RFS */
1832 intr
|= (s
->control
[0] & (1 << 6)) && /* TIE */
1833 (s
->status
[0] & (1 << 3)); /* TFS */
1834 intr
|= (s
->control
[2] & (1 << 4)) && /* TRAIL */
1835 (s
->status
[0] & (1 << 6)); /* EOC */
1836 intr
|= (s
->control
[0] & (1 << 2)) && /* TUS */
1837 (s
->status
[0] & (1 << 1)); /* TUR */
1838 intr
|= s
->status
[0] & 0x25; /* FRE, RAB, EIF */
1840 qemu_set_irq(s
->rx_dma
, (s
->status
[0] >> 4) & 1);
1841 qemu_set_irq(s
->tx_dma
, (s
->status
[0] >> 3) & 1);
1843 qemu_set_irq(s
->irq
, intr
&& s
->enable
);
1846 #define ICCR0 0x00 /* FICP Control register 0 */
1847 #define ICCR1 0x04 /* FICP Control register 1 */
1848 #define ICCR2 0x08 /* FICP Control register 2 */
1849 #define ICDR 0x0c /* FICP Data register */
1850 #define ICSR0 0x14 /* FICP Status register 0 */
1851 #define ICSR1 0x18 /* FICP Status register 1 */
1852 #define ICFOR 0x1c /* FICP FIFO Occupancy Status register */
1854 static uint64_t pxa2xx_fir_read(void *opaque
, target_phys_addr_t addr
,
1857 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1862 return s
->control
[0];
1864 return s
->control
[1];
1866 return s
->control
[2];
1868 s
->status
[0] &= ~0x01;
1869 s
->status
[1] &= ~0x72;
1872 ret
= s
->rx_fifo
[s
->rx_start
++];
1874 pxa2xx_fir_update(s
);
1877 printf("%s: Rx FIFO underrun.\n", __FUNCTION__
);
1880 return s
->status
[0];
1882 return s
->status
[1] | (1 << 3); /* TNF */
1886 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1892 static void pxa2xx_fir_write(void *opaque
, target_phys_addr_t addr
,
1893 uint64_t value64
, unsigned size
)
1895 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1896 uint32_t value
= value64
;
1901 s
->control
[0] = value
;
1902 if (!(value
& (1 << 4))) /* RXE */
1903 s
->rx_len
= s
->rx_start
= 0;
1904 if (!(value
& (1 << 3))) { /* TXE */
1907 s
->enable
= value
& 1; /* ITR */
1910 pxa2xx_fir_update(s
);
1913 s
->control
[1] = value
;
1916 s
->control
[2] = value
& 0x3f;
1917 pxa2xx_fir_update(s
);
1920 if (s
->control
[2] & (1 << 2)) /* TXP */
1924 if (s
->chr
&& s
->enable
&& (s
->control
[0] & (1 << 3))) /* TXE */
1925 qemu_chr_fe_write(s
->chr
, &ch
, 1);
1928 s
->status
[0] &= ~(value
& 0x66);
1929 pxa2xx_fir_update(s
);
1934 printf("%s: Bad register " REG_FMT
"\n", __FUNCTION__
, addr
);
1938 static const MemoryRegionOps pxa2xx_fir_ops
= {
1939 .read
= pxa2xx_fir_read
,
1940 .write
= pxa2xx_fir_write
,
1941 .endianness
= DEVICE_NATIVE_ENDIAN
,
1944 static int pxa2xx_fir_is_empty(void *opaque
)
1946 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1947 return (s
->rx_len
< 64);
1950 static void pxa2xx_fir_rx(void *opaque
, const uint8_t *buf
, int size
)
1952 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1953 if (!(s
->control
[0] & (1 << 4))) /* RXE */
1957 s
->status
[1] |= 1 << 4; /* EOF */
1958 if (s
->rx_len
>= 64) {
1959 s
->status
[1] |= 1 << 6; /* ROR */
1963 if (s
->control
[2] & (1 << 3)) /* RXP */
1964 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = *(buf
++);
1966 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = ~*(buf
++);
1969 pxa2xx_fir_update(s
);
1972 static void pxa2xx_fir_event(void *opaque
, int event
)
1976 static void pxa2xx_fir_save(QEMUFile
*f
, void *opaque
)
1978 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1981 qemu_put_be32(f
, s
->enable
);
1983 qemu_put_8s(f
, &s
->control
[0]);
1984 qemu_put_8s(f
, &s
->control
[1]);
1985 qemu_put_8s(f
, &s
->control
[2]);
1986 qemu_put_8s(f
, &s
->status
[0]);
1987 qemu_put_8s(f
, &s
->status
[1]);
1989 qemu_put_byte(f
, s
->rx_len
);
1990 for (i
= 0; i
< s
->rx_len
; i
++)
1991 qemu_put_byte(f
, s
->rx_fifo
[(s
->rx_start
+ i
) & 63]);
1994 static int pxa2xx_fir_load(QEMUFile
*f
, void *opaque
, int version_id
)
1996 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1999 s
->enable
= qemu_get_be32(f
);
2001 qemu_get_8s(f
, &s
->control
[0]);
2002 qemu_get_8s(f
, &s
->control
[1]);
2003 qemu_get_8s(f
, &s
->control
[2]);
2004 qemu_get_8s(f
, &s
->status
[0]);
2005 qemu_get_8s(f
, &s
->status
[1]);
2007 s
->rx_len
= qemu_get_byte(f
);
2009 for (i
= 0; i
< s
->rx_len
; i
++)
2010 s
->rx_fifo
[i
] = qemu_get_byte(f
);
2015 static PXA2xxFIrState
*pxa2xx_fir_init(MemoryRegion
*sysmem
,
2016 target_phys_addr_t base
,
2017 qemu_irq irq
, qemu_irq rx_dma
, qemu_irq tx_dma
,
2018 CharDriverState
*chr
)
2020 PXA2xxFIrState
*s
= (PXA2xxFIrState
*)
2021 g_malloc0(sizeof(PXA2xxFIrState
));
2028 pxa2xx_fir_reset(s
);
2030 memory_region_init_io(&s
->iomem
, &pxa2xx_fir_ops
, s
, "pxa2xx-fir", 0x1000);
2031 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
2034 qemu_chr_add_handlers(chr
, pxa2xx_fir_is_empty
,
2035 pxa2xx_fir_rx
, pxa2xx_fir_event
, s
);
2037 register_savevm(NULL
, "pxa2xx_fir", 0, 0, pxa2xx_fir_save
,
2038 pxa2xx_fir_load
, s
);
2043 static void pxa2xx_reset(void *opaque
, int line
, int level
)
2045 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
2047 if (level
&& (s
->pm_regs
[PCFR
>> 2] & 0x10)) { /* GPR_EN */
2049 /* TODO: reset peripherals */
2053 /* Initialise a PXA270 integrated chip (ARM based core). */
2054 PXA2xxState
*pxa270_init(MemoryRegion
*address_space
,
2055 unsigned int sdram_size
, const char *revision
)
2060 s
= (PXA2xxState
*) g_malloc0(sizeof(PXA2xxState
));
2062 if (revision
&& strncmp(revision
, "pxa27", 5)) {
2063 fprintf(stderr
, "Machine requires a PXA27x processor.\n");
2067 revision
= "pxa270";
2069 s
->env
= cpu_init(revision
);
2071 fprintf(stderr
, "Unable to find CPU definition\n");
2074 s
->reset
= qemu_allocate_irqs(pxa2xx_reset
, s
, 1)[0];
2076 /* SDRAM & Internal Memory Storage */
2077 memory_region_init_ram(&s
->sdram
, "pxa270.sdram", sdram_size
);
2078 vmstate_register_ram_global(&s
->sdram
);
2079 memory_region_add_subregion(address_space
, PXA2XX_SDRAM_BASE
, &s
->sdram
);
2080 memory_region_init_ram(&s
->internal
, "pxa270.internal", 0x40000);
2081 vmstate_register_ram_global(&s
->internal
);
2082 memory_region_add_subregion(address_space
, PXA2XX_INTERNAL_BASE
,
2085 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->env
);
2087 s
->dma
= pxa27x_dma_init(0x40000000,
2088 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_DMA
));
2090 sysbus_create_varargs("pxa27x-timer", 0x40a00000,
2091 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 0),
2092 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 1),
2093 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 2),
2094 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 3),
2095 qdev_get_gpio_in(s
->pic
, PXA27X_PIC_OST_4_11
),
2098 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->env
, s
->pic
, 121);
2100 dinfo
= drive_get(IF_SD
, 0, 0);
2102 fprintf(stderr
, "qemu: missing SecureDigital device\n");
2105 s
->mmc
= pxa2xx_mmci_init(address_space
, 0x41100000, dinfo
->bdrv
,
2106 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_MMC
),
2107 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_MMCI
),
2108 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_MMCI
));
2110 for (i
= 0; pxa270_serial
[i
].io_base
; i
++) {
2111 if (serial_hds
[i
]) {
2112 serial_mm_init(address_space
, pxa270_serial
[i
].io_base
, 2,
2113 qdev_get_gpio_in(s
->pic
, pxa270_serial
[i
].irqn
),
2114 14857000 / 16, serial_hds
[i
],
2115 DEVICE_NATIVE_ENDIAN
);
2121 s
->fir
= pxa2xx_fir_init(address_space
, 0x40800000,
2122 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_ICP
),
2123 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_ICP
),
2124 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_ICP
),
2127 s
->lcd
= pxa2xx_lcdc_init(address_space
, 0x44000000,
2128 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_LCD
));
2130 s
->cm_base
= 0x41300000;
2131 s
->cm_regs
[CCCR
>> 2] = 0x02000210; /* 416.0 MHz */
2132 s
->clkcfg
= 0x00000009; /* Turbo mode active */
2133 memory_region_init_io(&s
->cm_iomem
, &pxa2xx_cm_ops
, s
, "pxa2xx-cm", 0x1000);
2134 memory_region_add_subregion(address_space
, s
->cm_base
, &s
->cm_iomem
);
2135 vmstate_register(NULL
, 0, &vmstate_pxa2xx_cm
, s
);
2137 cpu_arm_set_cp_io(s
->env
, 14, pxa2xx_cp14_read
, pxa2xx_cp14_write
, s
);
2139 s
->mm_base
= 0x48000000;
2140 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
2141 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
2142 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
2143 memory_region_init_io(&s
->mm_iomem
, &pxa2xx_mm_ops
, s
, "pxa2xx-mm", 0x1000);
2144 memory_region_add_subregion(address_space
, s
->mm_base
, &s
->mm_iomem
);
2145 vmstate_register(NULL
, 0, &vmstate_pxa2xx_mm
, s
);
2147 s
->pm_base
= 0x40f00000;
2148 memory_region_init_io(&s
->pm_iomem
, &pxa2xx_pm_ops
, s
, "pxa2xx-pm", 0x100);
2149 memory_region_add_subregion(address_space
, s
->pm_base
, &s
->pm_iomem
);
2150 vmstate_register(NULL
, 0, &vmstate_pxa2xx_pm
, s
);
2152 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++);
2153 s
->ssp
= (SSIBus
**)g_malloc0(sizeof(SSIBus
*) * i
);
2154 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++) {
2156 dev
= sysbus_create_simple("pxa2xx-ssp", pxa27x_ssp
[i
].io_base
,
2157 qdev_get_gpio_in(s
->pic
, pxa27x_ssp
[i
].irqn
));
2158 s
->ssp
[i
] = (SSIBus
*)qdev_get_child_bus(dev
, "ssi");
2162 sysbus_create_simple("sysbus-ohci", 0x4c000000,
2163 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_USBH1
));
2166 s
->pcmcia
[0] = pxa2xx_pcmcia_init(address_space
, 0x20000000);
2167 s
->pcmcia
[1] = pxa2xx_pcmcia_init(address_space
, 0x30000000);
2169 sysbus_create_simple("pxa2xx_rtc", 0x40900000,
2170 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_RTCALARM
));
2172 s
->i2c
[0] = pxa2xx_i2c_init(0x40301600,
2173 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2C
), 0xffff);
2174 s
->i2c
[1] = pxa2xx_i2c_init(0x40f00100,
2175 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_PWRI2C
), 0xff);
2177 s
->i2s
= pxa2xx_i2s_init(address_space
, 0x40400000,
2178 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2S
),
2179 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_I2S
),
2180 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_I2S
));
2182 s
->kp
= pxa27x_keypad_init(address_space
, 0x41500000,
2183 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_KEYPAD
));
2185 /* GPIO1 resets the processor */
2186 /* The handler can be overridden by board-specific code */
2187 qdev_connect_gpio_out(s
->gpio
, 1, s
->reset
);
2191 /* Initialise a PXA255 integrated chip (ARM based core). */
2192 PXA2xxState
*pxa255_init(MemoryRegion
*address_space
, unsigned int sdram_size
)
2198 s
= (PXA2xxState
*) g_malloc0(sizeof(PXA2xxState
));
2200 s
->env
= cpu_init("pxa255");
2202 fprintf(stderr
, "Unable to find CPU definition\n");
2205 s
->reset
= qemu_allocate_irqs(pxa2xx_reset
, s
, 1)[0];
2207 /* SDRAM & Internal Memory Storage */
2208 memory_region_init_ram(&s
->sdram
, "pxa255.sdram", sdram_size
);
2209 vmstate_register_ram_global(&s
->sdram
);
2210 memory_region_add_subregion(address_space
, PXA2XX_SDRAM_BASE
, &s
->sdram
);
2211 memory_region_init_ram(&s
->internal
, "pxa255.internal",
2212 PXA2XX_INTERNAL_SIZE
);
2213 vmstate_register_ram_global(&s
->internal
);
2214 memory_region_add_subregion(address_space
, PXA2XX_INTERNAL_BASE
,
2217 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->env
);
2219 s
->dma
= pxa255_dma_init(0x40000000,
2220 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_DMA
));
2222 sysbus_create_varargs("pxa25x-timer", 0x40a00000,
2223 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 0),
2224 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 1),
2225 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 2),
2226 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 3),
2229 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->env
, s
->pic
, 85);
2231 dinfo
= drive_get(IF_SD
, 0, 0);
2233 fprintf(stderr
, "qemu: missing SecureDigital device\n");
2236 s
->mmc
= pxa2xx_mmci_init(address_space
, 0x41100000, dinfo
->bdrv
,
2237 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_MMC
),
2238 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_MMCI
),
2239 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_MMCI
));
2241 for (i
= 0; pxa255_serial
[i
].io_base
; i
++) {
2242 if (serial_hds
[i
]) {
2243 serial_mm_init(address_space
, pxa255_serial
[i
].io_base
, 2,
2244 qdev_get_gpio_in(s
->pic
, pxa255_serial
[i
].irqn
),
2245 14745600 / 16, serial_hds
[i
],
2246 DEVICE_NATIVE_ENDIAN
);
2252 s
->fir
= pxa2xx_fir_init(address_space
, 0x40800000,
2253 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_ICP
),
2254 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_ICP
),
2255 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_ICP
),
2258 s
->lcd
= pxa2xx_lcdc_init(address_space
, 0x44000000,
2259 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_LCD
));
2261 s
->cm_base
= 0x41300000;
2262 s
->cm_regs
[CCCR
>> 2] = 0x02000210; /* 416.0 MHz */
2263 s
->clkcfg
= 0x00000009; /* Turbo mode active */
2264 memory_region_init_io(&s
->cm_iomem
, &pxa2xx_cm_ops
, s
, "pxa2xx-cm", 0x1000);
2265 memory_region_add_subregion(address_space
, s
->cm_base
, &s
->cm_iomem
);
2266 vmstate_register(NULL
, 0, &vmstate_pxa2xx_cm
, s
);
2268 cpu_arm_set_cp_io(s
->env
, 14, pxa2xx_cp14_read
, pxa2xx_cp14_write
, s
);
2270 s
->mm_base
= 0x48000000;
2271 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
2272 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
2273 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
2274 memory_region_init_io(&s
->mm_iomem
, &pxa2xx_mm_ops
, s
, "pxa2xx-mm", 0x1000);
2275 memory_region_add_subregion(address_space
, s
->mm_base
, &s
->mm_iomem
);
2276 vmstate_register(NULL
, 0, &vmstate_pxa2xx_mm
, s
);
2278 s
->pm_base
= 0x40f00000;
2279 memory_region_init_io(&s
->pm_iomem
, &pxa2xx_pm_ops
, s
, "pxa2xx-pm", 0x100);
2280 memory_region_add_subregion(address_space
, s
->pm_base
, &s
->pm_iomem
);
2281 vmstate_register(NULL
, 0, &vmstate_pxa2xx_pm
, s
);
2283 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++);
2284 s
->ssp
= (SSIBus
**)g_malloc0(sizeof(SSIBus
*) * i
);
2285 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++) {
2287 dev
= sysbus_create_simple("pxa2xx-ssp", pxa255_ssp
[i
].io_base
,
2288 qdev_get_gpio_in(s
->pic
, pxa255_ssp
[i
].irqn
));
2289 s
->ssp
[i
] = (SSIBus
*)qdev_get_child_bus(dev
, "ssi");
2293 sysbus_create_simple("sysbus-ohci", 0x4c000000,
2294 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_USBH1
));
2297 s
->pcmcia
[0] = pxa2xx_pcmcia_init(address_space
, 0x20000000);
2298 s
->pcmcia
[1] = pxa2xx_pcmcia_init(address_space
, 0x30000000);
2300 sysbus_create_simple("pxa2xx_rtc", 0x40900000,
2301 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_RTCALARM
));
2303 s
->i2c
[0] = pxa2xx_i2c_init(0x40301600,
2304 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2C
), 0xffff);
2305 s
->i2c
[1] = pxa2xx_i2c_init(0x40f00100,
2306 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_PWRI2C
), 0xff);
2308 s
->i2s
= pxa2xx_i2s_init(address_space
, 0x40400000,
2309 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2S
),
2310 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_I2S
),
2311 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_I2S
));
2313 /* GPIO1 resets the processor */
2314 /* The handler can be overridden by board-specific code */
2315 qdev_connect_gpio_out(s
->gpio
, 1, s
->reset
);
2319 static void pxa2xx_ssp_class_init(ObjectClass
*klass
, void *data
)
2321 SysBusDeviceClass
*sdc
= SYS_BUS_DEVICE_CLASS(klass
);
2323 sdc
->init
= pxa2xx_ssp_init
;
2326 static TypeInfo pxa2xx_ssp_info
= {
2327 .name
= "pxa2xx-ssp",
2328 .parent
= TYPE_SYS_BUS_DEVICE
,
2329 .instance_size
= sizeof(PXA2xxSSPState
),
2330 .class_init
= pxa2xx_ssp_class_init
,
2333 static void pxa2xx_register_devices(void)
2335 type_register_static(&pxa2xx_i2c_slave_info
);
2336 type_register_static(&pxa2xx_ssp_info
);
2337 type_register_static(&pxa2xx_i2c_info
);
2338 type_register_static(&pxa2xx_rtc_sysbus_info
);
2341 device_init(pxa2xx_register_devices
)