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.
10 #include "qemu/osdep.h"
11 #include "qemu-common.h"
12 #include "qemu/error-report.h"
13 #include "qemu/module.h"
14 #include "qapi/error.h"
16 #include "hw/sysbus.h"
17 #include "migration/vmstate.h"
18 #include "hw/arm/pxa.h"
19 #include "sysemu/sysemu.h"
20 #include "hw/char/serial.h"
21 #include "hw/i2c/i2c.h"
23 #include "hw/qdev-properties.h"
24 #include "hw/qdev-properties-system.h"
25 #include "hw/ssi/ssi.h"
27 #include "chardev/char-fe.h"
28 #include "sysemu/blockdev.h"
29 #include "sysemu/qtest.h"
30 #include "qemu/cutils.h"
32 #include "qom/object.h"
38 { 0x40100000, PXA2XX_PIC_FFUART
},
39 { 0x40200000, PXA2XX_PIC_BTUART
},
40 { 0x40700000, PXA2XX_PIC_STUART
},
41 { 0x41600000, PXA25X_PIC_HWUART
},
43 }, pxa270_serial
[] = {
44 { 0x40100000, PXA2XX_PIC_FFUART
},
45 { 0x40200000, PXA2XX_PIC_BTUART
},
46 { 0x40700000, PXA2XX_PIC_STUART
},
50 typedef struct PXASSPDef
{
56 static PXASSPDef pxa250_ssp
[] = {
57 { 0x41000000, PXA2XX_PIC_SSP
},
62 static PXASSPDef pxa255_ssp
[] = {
63 { 0x41000000, PXA2XX_PIC_SSP
},
64 { 0x41400000, PXA25X_PIC_NSSP
},
69 static PXASSPDef pxa26x_ssp
[] = {
70 { 0x41000000, PXA2XX_PIC_SSP
},
71 { 0x41400000, PXA25X_PIC_NSSP
},
72 { 0x41500000, PXA26X_PIC_ASSP
},
77 static PXASSPDef pxa27x_ssp
[] = {
78 { 0x41000000, PXA2XX_PIC_SSP
},
79 { 0x41700000, PXA27X_PIC_SSP2
},
80 { 0x41900000, PXA2XX_PIC_SSP3
},
84 #define PMCR 0x00 /* Power Manager Control register */
85 #define PSSR 0x04 /* Power Manager Sleep Status register */
86 #define PSPR 0x08 /* Power Manager Scratch-Pad register */
87 #define PWER 0x0c /* Power Manager Wake-Up Enable register */
88 #define PRER 0x10 /* Power Manager Rising-Edge Detect Enable register */
89 #define PFER 0x14 /* Power Manager Falling-Edge Detect Enable register */
90 #define PEDR 0x18 /* Power Manager Edge-Detect Status register */
91 #define PCFR 0x1c /* Power Manager General Configuration register */
92 #define PGSR0 0x20 /* Power Manager GPIO Sleep-State register 0 */
93 #define PGSR1 0x24 /* Power Manager GPIO Sleep-State register 1 */
94 #define PGSR2 0x28 /* Power Manager GPIO Sleep-State register 2 */
95 #define PGSR3 0x2c /* Power Manager GPIO Sleep-State register 3 */
96 #define RCSR 0x30 /* Reset Controller Status register */
97 #define PSLR 0x34 /* Power Manager Sleep Configuration register */
98 #define PTSR 0x38 /* Power Manager Standby Configuration register */
99 #define PVCR 0x40 /* Power Manager Voltage Change Control register */
100 #define PUCR 0x4c /* Power Manager USIM Card Control/Status register */
101 #define PKWR 0x50 /* Power Manager Keyboard Wake-Up Enable register */
102 #define PKSR 0x54 /* Power Manager Keyboard Level-Detect Status */
103 #define PCMD0 0x80 /* Power Manager I2C Command register File 0 */
104 #define PCMD31 0xfc /* Power Manager I2C Command register File 31 */
106 static uint64_t pxa2xx_pm_read(void *opaque
, hwaddr addr
,
109 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
112 case PMCR
... PCMD31
:
116 return s
->pm_regs
[addr
>> 2];
119 qemu_log_mask(LOG_GUEST_ERROR
,
120 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
127 static void pxa2xx_pm_write(void *opaque
, hwaddr addr
,
128 uint64_t value
, unsigned size
)
130 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
134 /* Clear the write-one-to-clear bits... */
135 s
->pm_regs
[addr
>> 2] &= ~(value
& 0x2a);
136 /* ...and set the plain r/w bits */
137 s
->pm_regs
[addr
>> 2] &= ~0x15;
138 s
->pm_regs
[addr
>> 2] |= value
& 0x15;
141 case PSSR
: /* Read-clean registers */
144 s
->pm_regs
[addr
>> 2] &= ~value
;
147 default: /* Read-write registers */
149 s
->pm_regs
[addr
>> 2] = value
;
152 qemu_log_mask(LOG_GUEST_ERROR
,
153 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
159 static const MemoryRegionOps pxa2xx_pm_ops
= {
160 .read
= pxa2xx_pm_read
,
161 .write
= pxa2xx_pm_write
,
162 .endianness
= DEVICE_NATIVE_ENDIAN
,
165 static const VMStateDescription vmstate_pxa2xx_pm
= {
168 .minimum_version_id
= 0,
169 .fields
= (VMStateField
[]) {
170 VMSTATE_UINT32_ARRAY(pm_regs
, PXA2xxState
, 0x40),
171 VMSTATE_END_OF_LIST()
175 #define CCCR 0x00 /* Core Clock Configuration register */
176 #define CKEN 0x04 /* Clock Enable register */
177 #define OSCC 0x08 /* Oscillator Configuration register */
178 #define CCSR 0x0c /* Core Clock Status register */
180 static uint64_t pxa2xx_cm_read(void *opaque
, hwaddr addr
,
183 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
189 return s
->cm_regs
[addr
>> 2];
192 return s
->cm_regs
[CCCR
>> 2] | (3 << 28);
195 qemu_log_mask(LOG_GUEST_ERROR
,
196 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
203 static void pxa2xx_cm_write(void *opaque
, hwaddr addr
,
204 uint64_t value
, unsigned size
)
206 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
211 s
->cm_regs
[addr
>> 2] = value
;
215 s
->cm_regs
[addr
>> 2] &= ~0x6c;
216 s
->cm_regs
[addr
>> 2] |= value
& 0x6e;
217 if ((value
>> 1) & 1) /* OON */
218 s
->cm_regs
[addr
>> 2] |= 1 << 0; /* Oscillator is now stable */
222 qemu_log_mask(LOG_GUEST_ERROR
,
223 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
229 static const MemoryRegionOps pxa2xx_cm_ops
= {
230 .read
= pxa2xx_cm_read
,
231 .write
= pxa2xx_cm_write
,
232 .endianness
= DEVICE_NATIVE_ENDIAN
,
235 static const VMStateDescription vmstate_pxa2xx_cm
= {
238 .minimum_version_id
= 0,
239 .fields
= (VMStateField
[]) {
240 VMSTATE_UINT32_ARRAY(cm_regs
, PXA2xxState
, 4),
241 VMSTATE_UINT32(clkcfg
, PXA2xxState
),
242 VMSTATE_UINT32(pmnc
, PXA2xxState
),
243 VMSTATE_END_OF_LIST()
247 static uint64_t pxa2xx_clkcfg_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
249 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
253 static void pxa2xx_clkcfg_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
256 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
257 s
->clkcfg
= value
& 0xf;
259 printf("%s: CPU frequency change attempt\n", __func__
);
263 static void pxa2xx_pwrmode_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
266 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
267 static const char *pwrmode
[8] = {
268 "Normal", "Idle", "Deep-idle", "Standby",
269 "Sleep", "reserved (!)", "reserved (!)", "Deep-sleep",
273 printf("%s: CPU voltage change attempt\n", __func__
);
282 if (!(s
->cm_regs
[CCCR
>> 2] & (1U << 31))) { /* CPDIS */
283 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
290 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
291 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
295 s
->cpu
->env
.uncached_cpsr
= ARM_CPU_MODE_SVC
;
296 s
->cpu
->env
.daif
= PSTATE_A
| PSTATE_F
| PSTATE_I
;
297 s
->cpu
->env
.cp15
.sctlr_ns
= 0;
298 s
->cpu
->env
.cp15
.cpacr_el1
= 0;
299 s
->cpu
->env
.cp15
.ttbr0_el
[1] = 0;
300 s
->cpu
->env
.cp15
.dacr_ns
= 0;
301 s
->pm_regs
[PSSR
>> 2] |= 0x8; /* Set STS */
302 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
305 * The scratch-pad register is almost universally used
306 * for storing the return address on suspend. For the
307 * lack of a resuming bootloader, perform a jump
308 * directly to that address.
310 memset(s
->cpu
->env
.regs
, 0, 4 * 15);
311 s
->cpu
->env
.regs
[15] = s
->pm_regs
[PSPR
>> 2];
314 buffer
= 0xe59ff000; /* ldr pc, [pc, #0] */
315 cpu_physical_memory_write(0, &buffer
, 4);
316 buffer
= s
->pm_regs
[PSPR
>> 2];
317 cpu_physical_memory_write(8, &buffer
, 4);
321 cpu_interrupt(current_cpu
, CPU_INTERRUPT_HALT
);
327 printf("%s: machine entered %s mode\n", __func__
,
332 static uint64_t pxa2xx_cppmnc_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
334 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
338 static void pxa2xx_cppmnc_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
341 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
345 static uint64_t pxa2xx_cpccnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
347 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
349 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
355 static const ARMCPRegInfo pxa_cp_reginfo
[] = {
356 /* cp14 crm==1: perf registers */
357 { .name
= "CPPMNC", .cp
= 14, .crn
= 0, .crm
= 1, .opc1
= 0, .opc2
= 0,
358 .access
= PL1_RW
, .type
= ARM_CP_IO
,
359 .readfn
= pxa2xx_cppmnc_read
, .writefn
= pxa2xx_cppmnc_write
},
360 { .name
= "CPCCNT", .cp
= 14, .crn
= 1, .crm
= 1, .opc1
= 0, .opc2
= 0,
361 .access
= PL1_RW
, .type
= ARM_CP_IO
,
362 .readfn
= pxa2xx_cpccnt_read
, .writefn
= arm_cp_write_ignore
},
363 { .name
= "CPINTEN", .cp
= 14, .crn
= 4, .crm
= 1, .opc1
= 0, .opc2
= 0,
364 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
365 { .name
= "CPFLAG", .cp
= 14, .crn
= 5, .crm
= 1, .opc1
= 0, .opc2
= 0,
366 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
367 { .name
= "CPEVTSEL", .cp
= 14, .crn
= 8, .crm
= 1, .opc1
= 0, .opc2
= 0,
368 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
369 /* cp14 crm==2: performance count registers */
370 { .name
= "CPPMN0", .cp
= 14, .crn
= 0, .crm
= 2, .opc1
= 0, .opc2
= 0,
371 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
372 { .name
= "CPPMN1", .cp
= 14, .crn
= 1, .crm
= 2, .opc1
= 0, .opc2
= 0,
373 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
374 { .name
= "CPPMN2", .cp
= 14, .crn
= 2, .crm
= 2, .opc1
= 0, .opc2
= 0,
375 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
376 { .name
= "CPPMN3", .cp
= 14, .crn
= 2, .crm
= 3, .opc1
= 0, .opc2
= 0,
377 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
378 /* cp14 crn==6: CLKCFG */
379 { .name
= "CLKCFG", .cp
= 14, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
380 .access
= PL1_RW
, .type
= ARM_CP_IO
,
381 .readfn
= pxa2xx_clkcfg_read
, .writefn
= pxa2xx_clkcfg_write
},
382 /* cp14 crn==7: PWRMODE */
383 { .name
= "PWRMODE", .cp
= 14, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 0,
384 .access
= PL1_RW
, .type
= ARM_CP_IO
,
385 .readfn
= arm_cp_read_zero
, .writefn
= pxa2xx_pwrmode_write
},
389 static void pxa2xx_setup_cp14(PXA2xxState
*s
)
391 define_arm_cp_regs_with_opaque(s
->cpu
, pxa_cp_reginfo
, s
);
394 #define MDCNFG 0x00 /* SDRAM Configuration register */
395 #define MDREFR 0x04 /* SDRAM Refresh Control register */
396 #define MSC0 0x08 /* Static Memory Control register 0 */
397 #define MSC1 0x0c /* Static Memory Control register 1 */
398 #define MSC2 0x10 /* Static Memory Control register 2 */
399 #define MECR 0x14 /* Expansion Memory Bus Config register */
400 #define SXCNFG 0x1c /* Synchronous Static Memory Config register */
401 #define MCMEM0 0x28 /* PC Card Memory Socket 0 Timing register */
402 #define MCMEM1 0x2c /* PC Card Memory Socket 1 Timing register */
403 #define MCATT0 0x30 /* PC Card Attribute Socket 0 register */
404 #define MCATT1 0x34 /* PC Card Attribute Socket 1 register */
405 #define MCIO0 0x38 /* PC Card I/O Socket 0 Timing register */
406 #define MCIO1 0x3c /* PC Card I/O Socket 1 Timing register */
407 #define MDMRS 0x40 /* SDRAM Mode Register Set Config register */
408 #define BOOT_DEF 0x44 /* Boot-time Default Configuration register */
409 #define ARB_CNTL 0x48 /* Arbiter Control register */
410 #define BSCNTR0 0x4c /* Memory Buffer Strength Control register 0 */
411 #define BSCNTR1 0x50 /* Memory Buffer Strength Control register 1 */
412 #define LCDBSCNTR 0x54 /* LCD Buffer Strength Control register */
413 #define MDMRSLP 0x58 /* Low Power SDRAM Mode Set Config register */
414 #define BSCNTR2 0x5c /* Memory Buffer Strength Control register 2 */
415 #define BSCNTR3 0x60 /* Memory Buffer Strength Control register 3 */
416 #define SA1110 0x64 /* SA-1110 Memory Compatibility register */
418 static uint64_t pxa2xx_mm_read(void *opaque
, hwaddr addr
,
421 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
424 case MDCNFG
... SA1110
:
426 return s
->mm_regs
[addr
>> 2];
429 qemu_log_mask(LOG_GUEST_ERROR
,
430 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
437 static void pxa2xx_mm_write(void *opaque
, hwaddr addr
,
438 uint64_t value
, unsigned size
)
440 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
443 case MDCNFG
... SA1110
:
444 if ((addr
& 3) == 0) {
445 s
->mm_regs
[addr
>> 2] = value
;
450 qemu_log_mask(LOG_GUEST_ERROR
,
451 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
457 static const MemoryRegionOps pxa2xx_mm_ops
= {
458 .read
= pxa2xx_mm_read
,
459 .write
= pxa2xx_mm_write
,
460 .endianness
= DEVICE_NATIVE_ENDIAN
,
463 static const VMStateDescription vmstate_pxa2xx_mm
= {
466 .minimum_version_id
= 0,
467 .fields
= (VMStateField
[]) {
468 VMSTATE_UINT32_ARRAY(mm_regs
, PXA2xxState
, 0x1a),
469 VMSTATE_END_OF_LIST()
473 #define TYPE_PXA2XX_SSP "pxa2xx-ssp"
474 OBJECT_DECLARE_SIMPLE_TYPE(PXA2xxSSPState
, PXA2XX_SSP
)
476 /* Synchronous Serial Ports */
477 struct PXA2xxSSPState
{
479 SysBusDevice parent_obj
;
496 uint32_t rx_fifo
[16];
501 static bool pxa2xx_ssp_vmstate_validate(void *opaque
, int version_id
)
503 PXA2xxSSPState
*s
= opaque
;
505 return s
->rx_start
< sizeof(s
->rx_fifo
);
508 static const VMStateDescription vmstate_pxa2xx_ssp
= {
509 .name
= "pxa2xx-ssp",
511 .minimum_version_id
= 1,
512 .fields
= (VMStateField
[]) {
513 VMSTATE_UINT32(enable
, PXA2xxSSPState
),
514 VMSTATE_UINT32_ARRAY(sscr
, PXA2xxSSPState
, 2),
515 VMSTATE_UINT32(sspsp
, PXA2xxSSPState
),
516 VMSTATE_UINT32(ssto
, PXA2xxSSPState
),
517 VMSTATE_UINT32(ssitr
, PXA2xxSSPState
),
518 VMSTATE_UINT32(sssr
, PXA2xxSSPState
),
519 VMSTATE_UINT8(sstsa
, PXA2xxSSPState
),
520 VMSTATE_UINT8(ssrsa
, PXA2xxSSPState
),
521 VMSTATE_UINT8(ssacd
, PXA2xxSSPState
),
522 VMSTATE_UINT32(rx_level
, PXA2xxSSPState
),
523 VMSTATE_UINT32(rx_start
, PXA2xxSSPState
),
524 VMSTATE_VALIDATE("fifo is 16 bytes", pxa2xx_ssp_vmstate_validate
),
525 VMSTATE_UINT32_ARRAY(rx_fifo
, PXA2xxSSPState
, 16),
526 VMSTATE_END_OF_LIST()
530 #define SSCR0 0x00 /* SSP Control register 0 */
531 #define SSCR1 0x04 /* SSP Control register 1 */
532 #define SSSR 0x08 /* SSP Status register */
533 #define SSITR 0x0c /* SSP Interrupt Test register */
534 #define SSDR 0x10 /* SSP Data register */
535 #define SSTO 0x28 /* SSP Time-Out register */
536 #define SSPSP 0x2c /* SSP Programmable Serial Protocol register */
537 #define SSTSA 0x30 /* SSP TX Time Slot Active register */
538 #define SSRSA 0x34 /* SSP RX Time Slot Active register */
539 #define SSTSS 0x38 /* SSP Time Slot Status register */
540 #define SSACD 0x3c /* SSP Audio Clock Divider register */
542 /* Bitfields for above registers */
543 #define SSCR0_SPI(x) (((x) & 0x30) == 0x00)
544 #define SSCR0_SSP(x) (((x) & 0x30) == 0x10)
545 #define SSCR0_UWIRE(x) (((x) & 0x30) == 0x20)
546 #define SSCR0_PSP(x) (((x) & 0x30) == 0x30)
547 #define SSCR0_SSE (1 << 7)
548 #define SSCR0_RIM (1 << 22)
549 #define SSCR0_TIM (1 << 23)
550 #define SSCR0_MOD (1U << 31)
551 #define SSCR0_DSS(x) (((((x) >> 16) & 0x10) | ((x) & 0xf)) + 1)
552 #define SSCR1_RIE (1 << 0)
553 #define SSCR1_TIE (1 << 1)
554 #define SSCR1_LBM (1 << 2)
555 #define SSCR1_MWDS (1 << 5)
556 #define SSCR1_TFT(x) ((((x) >> 6) & 0xf) + 1)
557 #define SSCR1_RFT(x) ((((x) >> 10) & 0xf) + 1)
558 #define SSCR1_EFWR (1 << 14)
559 #define SSCR1_PINTE (1 << 18)
560 #define SSCR1_TINTE (1 << 19)
561 #define SSCR1_RSRE (1 << 20)
562 #define SSCR1_TSRE (1 << 21)
563 #define SSCR1_EBCEI (1 << 29)
564 #define SSITR_INT (7 << 5)
565 #define SSSR_TNF (1 << 2)
566 #define SSSR_RNE (1 << 3)
567 #define SSSR_TFS (1 << 5)
568 #define SSSR_RFS (1 << 6)
569 #define SSSR_ROR (1 << 7)
570 #define SSSR_PINT (1 << 18)
571 #define SSSR_TINT (1 << 19)
572 #define SSSR_EOC (1 << 20)
573 #define SSSR_TUR (1 << 21)
574 #define SSSR_BCE (1 << 23)
575 #define SSSR_RW 0x00bc0080
577 static void pxa2xx_ssp_int_update(PXA2xxSSPState
*s
)
581 level
|= s
->ssitr
& SSITR_INT
;
582 level
|= (s
->sssr
& SSSR_BCE
) && (s
->sscr
[1] & SSCR1_EBCEI
);
583 level
|= (s
->sssr
& SSSR_TUR
) && !(s
->sscr
[0] & SSCR0_TIM
);
584 level
|= (s
->sssr
& SSSR_EOC
) && (s
->sssr
& (SSSR_TINT
| SSSR_PINT
));
585 level
|= (s
->sssr
& SSSR_TINT
) && (s
->sscr
[1] & SSCR1_TINTE
);
586 level
|= (s
->sssr
& SSSR_PINT
) && (s
->sscr
[1] & SSCR1_PINTE
);
587 level
|= (s
->sssr
& SSSR_ROR
) && !(s
->sscr
[0] & SSCR0_RIM
);
588 level
|= (s
->sssr
& SSSR_RFS
) && (s
->sscr
[1] & SSCR1_RIE
);
589 level
|= (s
->sssr
& SSSR_TFS
) && (s
->sscr
[1] & SSCR1_TIE
);
590 qemu_set_irq(s
->irq
, !!level
);
593 static void pxa2xx_ssp_fifo_update(PXA2xxSSPState
*s
)
595 s
->sssr
&= ~(0xf << 12); /* Clear RFL */
596 s
->sssr
&= ~(0xf << 8); /* Clear TFL */
597 s
->sssr
&= ~SSSR_TFS
;
598 s
->sssr
&= ~SSSR_TNF
;
600 s
->sssr
|= ((s
->rx_level
- 1) & 0xf) << 12;
601 if (s
->rx_level
>= SSCR1_RFT(s
->sscr
[1]))
604 s
->sssr
&= ~SSSR_RFS
;
608 s
->sssr
&= ~SSSR_RNE
;
609 /* TX FIFO is never filled, so it is always in underrun
610 condition if SSP is enabled */
615 pxa2xx_ssp_int_update(s
);
618 static uint64_t pxa2xx_ssp_read(void *opaque
, hwaddr addr
,
621 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
636 return s
->sssr
| s
->ssitr
;
640 if (s
->rx_level
< 1) {
641 printf("%s: SSP Rx Underrun\n", __func__
);
645 retval
= s
->rx_fifo
[s
->rx_start
++];
647 pxa2xx_ssp_fifo_update(s
);
658 qemu_log_mask(LOG_GUEST_ERROR
,
659 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
666 static void pxa2xx_ssp_write(void *opaque
, hwaddr addr
,
667 uint64_t value64
, unsigned size
)
669 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
670 uint32_t value
= value64
;
674 s
->sscr
[0] = value
& 0xc7ffffff;
675 s
->enable
= value
& SSCR0_SSE
;
676 if (value
& SSCR0_MOD
)
677 printf("%s: Attempt to use network mode\n", __func__
);
678 if (s
->enable
&& SSCR0_DSS(value
) < 4)
679 printf("%s: Wrong data size: %u bits\n", __func__
,
681 if (!(value
& SSCR0_SSE
)) {
686 pxa2xx_ssp_fifo_update(s
);
691 if (value
& (SSCR1_LBM
| SSCR1_EFWR
))
692 printf("%s: Attempt to use SSP test mode\n", __func__
);
693 pxa2xx_ssp_fifo_update(s
);
705 s
->ssitr
= value
& SSITR_INT
;
706 pxa2xx_ssp_int_update(s
);
710 s
->sssr
&= ~(value
& SSSR_RW
);
711 pxa2xx_ssp_int_update(s
);
715 if (SSCR0_UWIRE(s
->sscr
[0])) {
716 if (s
->sscr
[1] & SSCR1_MWDS
)
721 /* Note how 32bits overflow does no harm here */
722 value
&= (1 << SSCR0_DSS(s
->sscr
[0])) - 1;
724 /* Data goes from here to the Tx FIFO and is shifted out from
725 * there directly to the slave, no need to buffer it.
729 readval
= ssi_transfer(s
->bus
, value
);
730 if (s
->rx_level
< 0x10) {
731 s
->rx_fifo
[(s
->rx_start
+ s
->rx_level
++) & 0xf] = readval
;
736 pxa2xx_ssp_fifo_update(s
);
752 qemu_log_mask(LOG_GUEST_ERROR
,
753 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
759 static const MemoryRegionOps pxa2xx_ssp_ops
= {
760 .read
= pxa2xx_ssp_read
,
761 .write
= pxa2xx_ssp_write
,
762 .endianness
= DEVICE_NATIVE_ENDIAN
,
765 static void pxa2xx_ssp_reset(DeviceState
*d
)
767 PXA2xxSSPState
*s
= PXA2XX_SSP(d
);
770 s
->sscr
[0] = s
->sscr
[1] = 0;
778 s
->rx_start
= s
->rx_level
= 0;
781 static void pxa2xx_ssp_init(Object
*obj
)
783 DeviceState
*dev
= DEVICE(obj
);
784 PXA2xxSSPState
*s
= PXA2XX_SSP(obj
);
785 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
786 sysbus_init_irq(sbd
, &s
->irq
);
788 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_ssp_ops
, s
,
789 "pxa2xx-ssp", 0x1000);
790 sysbus_init_mmio(sbd
, &s
->iomem
);
792 s
->bus
= ssi_create_bus(dev
, "ssi");
795 /* Real-Time Clock */
796 #define RCNR 0x00 /* RTC Counter register */
797 #define RTAR 0x04 /* RTC Alarm register */
798 #define RTSR 0x08 /* RTC Status register */
799 #define RTTR 0x0c /* RTC Timer Trim register */
800 #define RDCR 0x10 /* RTC Day Counter register */
801 #define RYCR 0x14 /* RTC Year Counter register */
802 #define RDAR1 0x18 /* RTC Wristwatch Day Alarm register 1 */
803 #define RYAR1 0x1c /* RTC Wristwatch Year Alarm register 1 */
804 #define RDAR2 0x20 /* RTC Wristwatch Day Alarm register 2 */
805 #define RYAR2 0x24 /* RTC Wristwatch Year Alarm register 2 */
806 #define SWCR 0x28 /* RTC Stopwatch Counter register */
807 #define SWAR1 0x2c /* RTC Stopwatch Alarm register 1 */
808 #define SWAR2 0x30 /* RTC Stopwatch Alarm register 2 */
809 #define RTCPICR 0x34 /* RTC Periodic Interrupt Counter register */
810 #define PIAR 0x38 /* RTC Periodic Interrupt Alarm register */
812 #define TYPE_PXA2XX_RTC "pxa2xx_rtc"
813 OBJECT_DECLARE_SIMPLE_TYPE(PXA2xxRTCState
, PXA2XX_RTC
)
815 struct PXA2xxRTCState
{
817 SysBusDevice parent_obj
;
835 uint32_t last_rtcpicr
;
840 QEMUTimer
*rtc_rdal1
;
841 QEMUTimer
*rtc_rdal2
;
842 QEMUTimer
*rtc_swal1
;
843 QEMUTimer
*rtc_swal2
;
848 static inline void pxa2xx_rtc_int_update(PXA2xxRTCState
*s
)
850 qemu_set_irq(s
->rtc_irq
, !!(s
->rtsr
& 0x2553));
853 static void pxa2xx_rtc_hzupdate(PXA2xxRTCState
*s
)
855 int64_t rt
= qemu_clock_get_ms(rtc_clock
);
856 s
->last_rcnr
+= ((rt
- s
->last_hz
) << 15) /
857 (1000 * ((s
->rttr
& 0xffff) + 1));
858 s
->last_rdcr
+= ((rt
- s
->last_hz
) << 15) /
859 (1000 * ((s
->rttr
& 0xffff) + 1));
863 static void pxa2xx_rtc_swupdate(PXA2xxRTCState
*s
)
865 int64_t rt
= qemu_clock_get_ms(rtc_clock
);
866 if (s
->rtsr
& (1 << 12))
867 s
->last_swcr
+= (rt
- s
->last_sw
) / 10;
871 static void pxa2xx_rtc_piupdate(PXA2xxRTCState
*s
)
873 int64_t rt
= qemu_clock_get_ms(rtc_clock
);
874 if (s
->rtsr
& (1 << 15))
875 s
->last_swcr
+= rt
- s
->last_pi
;
879 static inline void pxa2xx_rtc_alarm_update(PXA2xxRTCState
*s
,
882 if ((rtsr
& (1 << 2)) && !(rtsr
& (1 << 0)))
883 timer_mod(s
->rtc_hz
, s
->last_hz
+
884 (((s
->rtar
- s
->last_rcnr
) * 1000 *
885 ((s
->rttr
& 0xffff) + 1)) >> 15));
887 timer_del(s
->rtc_hz
);
889 if ((rtsr
& (1 << 5)) && !(rtsr
& (1 << 4)))
890 timer_mod(s
->rtc_rdal1
, s
->last_hz
+
891 (((s
->rdar1
- s
->last_rdcr
) * 1000 *
892 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
894 timer_del(s
->rtc_rdal1
);
896 if ((rtsr
& (1 << 7)) && !(rtsr
& (1 << 6)))
897 timer_mod(s
->rtc_rdal2
, s
->last_hz
+
898 (((s
->rdar2
- s
->last_rdcr
) * 1000 *
899 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
901 timer_del(s
->rtc_rdal2
);
903 if ((rtsr
& 0x1200) == 0x1200 && !(rtsr
& (1 << 8)))
904 timer_mod(s
->rtc_swal1
, s
->last_sw
+
905 (s
->swar1
- s
->last_swcr
) * 10); /* TODO: fixup */
907 timer_del(s
->rtc_swal1
);
909 if ((rtsr
& 0x1800) == 0x1800 && !(rtsr
& (1 << 10)))
910 timer_mod(s
->rtc_swal2
, s
->last_sw
+
911 (s
->swar2
- s
->last_swcr
) * 10); /* TODO: fixup */
913 timer_del(s
->rtc_swal2
);
915 if ((rtsr
& 0xc000) == 0xc000 && !(rtsr
& (1 << 13)))
916 timer_mod(s
->rtc_pi
, s
->last_pi
+
917 (s
->piar
& 0xffff) - s
->last_rtcpicr
);
919 timer_del(s
->rtc_pi
);
922 static inline void pxa2xx_rtc_hz_tick(void *opaque
)
924 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
926 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
927 pxa2xx_rtc_int_update(s
);
930 static inline void pxa2xx_rtc_rdal1_tick(void *opaque
)
932 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
934 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
935 pxa2xx_rtc_int_update(s
);
938 static inline void pxa2xx_rtc_rdal2_tick(void *opaque
)
940 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
942 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
943 pxa2xx_rtc_int_update(s
);
946 static inline void pxa2xx_rtc_swal1_tick(void *opaque
)
948 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
950 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
951 pxa2xx_rtc_int_update(s
);
954 static inline void pxa2xx_rtc_swal2_tick(void *opaque
)
956 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
957 s
->rtsr
|= (1 << 10);
958 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
959 pxa2xx_rtc_int_update(s
);
962 static inline void pxa2xx_rtc_pi_tick(void *opaque
)
964 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
965 s
->rtsr
|= (1 << 13);
966 pxa2xx_rtc_piupdate(s
);
968 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
969 pxa2xx_rtc_int_update(s
);
972 static uint64_t pxa2xx_rtc_read(void *opaque
, hwaddr addr
,
975 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
999 return s
->last_rcnr
+
1000 ((qemu_clock_get_ms(rtc_clock
) - s
->last_hz
) << 15) /
1001 (1000 * ((s
->rttr
& 0xffff) + 1));
1003 return s
->last_rdcr
+
1004 ((qemu_clock_get_ms(rtc_clock
) - s
->last_hz
) << 15) /
1005 (1000 * ((s
->rttr
& 0xffff) + 1));
1007 return s
->last_rycr
;
1009 if (s
->rtsr
& (1 << 12))
1010 return s
->last_swcr
+
1011 (qemu_clock_get_ms(rtc_clock
) - s
->last_sw
) / 10;
1013 return s
->last_swcr
;
1015 qemu_log_mask(LOG_GUEST_ERROR
,
1016 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1023 static void pxa2xx_rtc_write(void *opaque
, hwaddr addr
,
1024 uint64_t value64
, unsigned size
)
1026 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1027 uint32_t value
= value64
;
1031 if (!(s
->rttr
& (1U << 31))) {
1032 pxa2xx_rtc_hzupdate(s
);
1034 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1039 if ((s
->rtsr
^ value
) & (1 << 15))
1040 pxa2xx_rtc_piupdate(s
);
1042 if ((s
->rtsr
^ value
) & (1 << 12))
1043 pxa2xx_rtc_swupdate(s
);
1045 if (((s
->rtsr
^ value
) & 0x4aac) | (value
& ~0xdaac))
1046 pxa2xx_rtc_alarm_update(s
, value
);
1048 s
->rtsr
= (value
& 0xdaac) | (s
->rtsr
& ~(value
& ~0xdaac));
1049 pxa2xx_rtc_int_update(s
);
1054 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1059 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1064 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1069 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1074 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1078 pxa2xx_rtc_swupdate(s
);
1081 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1086 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1091 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1095 pxa2xx_rtc_hzupdate(s
);
1096 s
->last_rcnr
= value
;
1097 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1101 pxa2xx_rtc_hzupdate(s
);
1102 s
->last_rdcr
= value
;
1103 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1107 s
->last_rycr
= value
;
1111 pxa2xx_rtc_swupdate(s
);
1112 s
->last_swcr
= value
;
1113 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1117 pxa2xx_rtc_piupdate(s
);
1118 s
->last_rtcpicr
= value
& 0xffff;
1119 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1123 qemu_log_mask(LOG_GUEST_ERROR
,
1124 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1129 static const MemoryRegionOps pxa2xx_rtc_ops
= {
1130 .read
= pxa2xx_rtc_read
,
1131 .write
= pxa2xx_rtc_write
,
1132 .endianness
= DEVICE_NATIVE_ENDIAN
,
1135 static void pxa2xx_rtc_init(Object
*obj
)
1137 PXA2xxRTCState
*s
= PXA2XX_RTC(obj
);
1138 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
1145 qemu_get_timedate(&tm
, 0);
1146 wom
= ((tm
.tm_mday
- 1) / 7) + 1;
1148 s
->last_rcnr
= (uint32_t) mktimegm(&tm
);
1149 s
->last_rdcr
= (wom
<< 20) | ((tm
.tm_wday
+ 1) << 17) |
1150 (tm
.tm_hour
<< 12) | (tm
.tm_min
<< 6) | tm
.tm_sec
;
1151 s
->last_rycr
= ((tm
.tm_year
+ 1900) << 9) |
1152 ((tm
.tm_mon
+ 1) << 5) | tm
.tm_mday
;
1153 s
->last_swcr
= (tm
.tm_hour
<< 19) |
1154 (tm
.tm_min
<< 13) | (tm
.tm_sec
<< 7);
1155 s
->last_rtcpicr
= 0;
1156 s
->last_hz
= s
->last_sw
= s
->last_pi
= qemu_clock_get_ms(rtc_clock
);
1158 sysbus_init_irq(dev
, &s
->rtc_irq
);
1160 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_rtc_ops
, s
,
1161 "pxa2xx-rtc", 0x10000);
1162 sysbus_init_mmio(dev
, &s
->iomem
);
1165 static void pxa2xx_rtc_realize(DeviceState
*dev
, Error
**errp
)
1167 PXA2xxRTCState
*s
= PXA2XX_RTC(dev
);
1168 s
->rtc_hz
= timer_new_ms(rtc_clock
, pxa2xx_rtc_hz_tick
, s
);
1169 s
->rtc_rdal1
= timer_new_ms(rtc_clock
, pxa2xx_rtc_rdal1_tick
, s
);
1170 s
->rtc_rdal2
= timer_new_ms(rtc_clock
, pxa2xx_rtc_rdal2_tick
, s
);
1171 s
->rtc_swal1
= timer_new_ms(rtc_clock
, pxa2xx_rtc_swal1_tick
, s
);
1172 s
->rtc_swal2
= timer_new_ms(rtc_clock
, pxa2xx_rtc_swal2_tick
, s
);
1173 s
->rtc_pi
= timer_new_ms(rtc_clock
, pxa2xx_rtc_pi_tick
, s
);
1176 static int pxa2xx_rtc_pre_save(void *opaque
)
1178 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1180 pxa2xx_rtc_hzupdate(s
);
1181 pxa2xx_rtc_piupdate(s
);
1182 pxa2xx_rtc_swupdate(s
);
1187 static int pxa2xx_rtc_post_load(void *opaque
, int version_id
)
1189 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1191 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1196 static const VMStateDescription vmstate_pxa2xx_rtc_regs
= {
1197 .name
= "pxa2xx_rtc",
1199 .minimum_version_id
= 0,
1200 .pre_save
= pxa2xx_rtc_pre_save
,
1201 .post_load
= pxa2xx_rtc_post_load
,
1202 .fields
= (VMStateField
[]) {
1203 VMSTATE_UINT32(rttr
, PXA2xxRTCState
),
1204 VMSTATE_UINT32(rtsr
, PXA2xxRTCState
),
1205 VMSTATE_UINT32(rtar
, PXA2xxRTCState
),
1206 VMSTATE_UINT32(rdar1
, PXA2xxRTCState
),
1207 VMSTATE_UINT32(rdar2
, PXA2xxRTCState
),
1208 VMSTATE_UINT32(ryar1
, PXA2xxRTCState
),
1209 VMSTATE_UINT32(ryar2
, PXA2xxRTCState
),
1210 VMSTATE_UINT32(swar1
, PXA2xxRTCState
),
1211 VMSTATE_UINT32(swar2
, PXA2xxRTCState
),
1212 VMSTATE_UINT32(piar
, PXA2xxRTCState
),
1213 VMSTATE_UINT32(last_rcnr
, PXA2xxRTCState
),
1214 VMSTATE_UINT32(last_rdcr
, PXA2xxRTCState
),
1215 VMSTATE_UINT32(last_rycr
, PXA2xxRTCState
),
1216 VMSTATE_UINT32(last_swcr
, PXA2xxRTCState
),
1217 VMSTATE_UINT32(last_rtcpicr
, PXA2xxRTCState
),
1218 VMSTATE_INT64(last_hz
, PXA2xxRTCState
),
1219 VMSTATE_INT64(last_sw
, PXA2xxRTCState
),
1220 VMSTATE_INT64(last_pi
, PXA2xxRTCState
),
1221 VMSTATE_END_OF_LIST(),
1225 static void pxa2xx_rtc_sysbus_class_init(ObjectClass
*klass
, void *data
)
1227 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1229 dc
->desc
= "PXA2xx RTC Controller";
1230 dc
->vmsd
= &vmstate_pxa2xx_rtc_regs
;
1231 dc
->realize
= pxa2xx_rtc_realize
;
1234 static const TypeInfo pxa2xx_rtc_sysbus_info
= {
1235 .name
= TYPE_PXA2XX_RTC
,
1236 .parent
= TYPE_SYS_BUS_DEVICE
,
1237 .instance_size
= sizeof(PXA2xxRTCState
),
1238 .instance_init
= pxa2xx_rtc_init
,
1239 .class_init
= pxa2xx_rtc_sysbus_class_init
,
1244 #define TYPE_PXA2XX_I2C_SLAVE "pxa2xx-i2c-slave"
1245 OBJECT_DECLARE_SIMPLE_TYPE(PXA2xxI2CSlaveState
, PXA2XX_I2C_SLAVE
)
1247 struct PXA2xxI2CSlaveState
{
1248 I2CSlave parent_obj
;
1250 PXA2xxI2CState
*host
;
1253 struct PXA2xxI2CState
{
1255 SysBusDevice parent_obj
;
1259 PXA2xxI2CSlaveState
*slave
;
1263 uint32_t region_size
;
1271 #define IBMR 0x80 /* I2C Bus Monitor register */
1272 #define IDBR 0x88 /* I2C Data Buffer register */
1273 #define ICR 0x90 /* I2C Control register */
1274 #define ISR 0x98 /* I2C Status register */
1275 #define ISAR 0xa0 /* I2C Slave Address register */
1277 static void pxa2xx_i2c_update(PXA2xxI2CState
*s
)
1280 level
|= s
->status
& s
->control
& (1 << 10); /* BED */
1281 level
|= (s
->status
& (1 << 7)) && (s
->control
& (1 << 9)); /* IRF */
1282 level
|= (s
->status
& (1 << 6)) && (s
->control
& (1 << 8)); /* ITE */
1283 level
|= s
->status
& (1 << 9); /* SAD */
1284 qemu_set_irq(s
->irq
, !!level
);
1287 /* These are only stubs now. */
1288 static int pxa2xx_i2c_event(I2CSlave
*i2c
, enum i2c_event event
)
1290 PXA2xxI2CSlaveState
*slave
= PXA2XX_I2C_SLAVE(i2c
);
1291 PXA2xxI2CState
*s
= slave
->host
;
1294 case I2C_START_SEND
:
1295 s
->status
|= (1 << 9); /* set SAD */
1296 s
->status
&= ~(1 << 0); /* clear RWM */
1298 case I2C_START_RECV
:
1299 s
->status
|= (1 << 9); /* set SAD */
1300 s
->status
|= 1 << 0; /* set RWM */
1303 s
->status
|= (1 << 4); /* set SSD */
1306 s
->status
|= 1 << 1; /* set ACKNAK */
1309 pxa2xx_i2c_update(s
);
1314 static uint8_t pxa2xx_i2c_rx(I2CSlave
*i2c
)
1316 PXA2xxI2CSlaveState
*slave
= PXA2XX_I2C_SLAVE(i2c
);
1317 PXA2xxI2CState
*s
= slave
->host
;
1319 if ((s
->control
& (1 << 14)) || !(s
->control
& (1 << 6))) {
1323 if (s
->status
& (1 << 0)) { /* RWM */
1324 s
->status
|= 1 << 6; /* set ITE */
1326 pxa2xx_i2c_update(s
);
1331 static int pxa2xx_i2c_tx(I2CSlave
*i2c
, uint8_t data
)
1333 PXA2xxI2CSlaveState
*slave
= PXA2XX_I2C_SLAVE(i2c
);
1334 PXA2xxI2CState
*s
= slave
->host
;
1336 if ((s
->control
& (1 << 14)) || !(s
->control
& (1 << 6))) {
1340 if (!(s
->status
& (1 << 0))) { /* RWM */
1341 s
->status
|= 1 << 7; /* set IRF */
1344 pxa2xx_i2c_update(s
);
1349 static uint64_t pxa2xx_i2c_read(void *opaque
, hwaddr addr
,
1352 PXA2xxI2CState
*s
= (PXA2xxI2CState
*) opaque
;
1360 return s
->status
| (i2c_bus_busy(s
->bus
) << 2);
1362 slave
= I2C_SLAVE(s
->slave
);
1363 return slave
->address
;
1367 if (s
->status
& (1 << 2))
1368 s
->ibmr
^= 3; /* Fake SCL and SDA pin changes */
1373 qemu_log_mask(LOG_GUEST_ERROR
,
1374 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1381 static void pxa2xx_i2c_write(void *opaque
, hwaddr addr
,
1382 uint64_t value64
, unsigned size
)
1384 PXA2xxI2CState
*s
= (PXA2xxI2CState
*) opaque
;
1385 uint32_t value
= value64
;
1391 s
->control
= value
& 0xfff7;
1392 if ((value
& (1 << 3)) && (value
& (1 << 6))) { /* TB and IUE */
1393 /* TODO: slave mode */
1394 if (value
& (1 << 0)) { /* START condition */
1396 s
->status
|= 1 << 0; /* set RWM */
1398 s
->status
&= ~(1 << 0); /* clear RWM */
1399 ack
= !i2c_start_transfer(s
->bus
, s
->data
>> 1, s
->data
& 1);
1401 if (s
->status
& (1 << 0)) { /* RWM */
1402 s
->data
= i2c_recv(s
->bus
);
1403 if (value
& (1 << 2)) /* ACKNAK */
1407 ack
= !i2c_send(s
->bus
, s
->data
);
1410 if (value
& (1 << 1)) /* STOP condition */
1411 i2c_end_transfer(s
->bus
);
1414 if (value
& (1 << 0)) /* START condition */
1415 s
->status
|= 1 << 6; /* set ITE */
1417 if (s
->status
& (1 << 0)) /* RWM */
1418 s
->status
|= 1 << 7; /* set IRF */
1420 s
->status
|= 1 << 6; /* set ITE */
1421 s
->status
&= ~(1 << 1); /* clear ACKNAK */
1423 s
->status
|= 1 << 6; /* set ITE */
1424 s
->status
|= 1 << 10; /* set BED */
1425 s
->status
|= 1 << 1; /* set ACKNAK */
1428 if (!(value
& (1 << 3)) && (value
& (1 << 6))) /* !TB and IUE */
1429 if (value
& (1 << 4)) /* MA */
1430 i2c_end_transfer(s
->bus
);
1431 pxa2xx_i2c_update(s
);
1435 s
->status
&= ~(value
& 0x07f0);
1436 pxa2xx_i2c_update(s
);
1440 i2c_slave_set_address(I2C_SLAVE(s
->slave
), value
& 0x7f);
1444 s
->data
= value
& 0xff;
1448 qemu_log_mask(LOG_GUEST_ERROR
,
1449 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1454 static const MemoryRegionOps pxa2xx_i2c_ops
= {
1455 .read
= pxa2xx_i2c_read
,
1456 .write
= pxa2xx_i2c_write
,
1457 .endianness
= DEVICE_NATIVE_ENDIAN
,
1460 static const VMStateDescription vmstate_pxa2xx_i2c_slave
= {
1461 .name
= "pxa2xx_i2c_slave",
1463 .minimum_version_id
= 1,
1464 .fields
= (VMStateField
[]) {
1465 VMSTATE_I2C_SLAVE(parent_obj
, PXA2xxI2CSlaveState
),
1466 VMSTATE_END_OF_LIST()
1470 static const VMStateDescription vmstate_pxa2xx_i2c
= {
1471 .name
= "pxa2xx_i2c",
1473 .minimum_version_id
= 1,
1474 .fields
= (VMStateField
[]) {
1475 VMSTATE_UINT16(control
, PXA2xxI2CState
),
1476 VMSTATE_UINT16(status
, PXA2xxI2CState
),
1477 VMSTATE_UINT8(ibmr
, PXA2xxI2CState
),
1478 VMSTATE_UINT8(data
, PXA2xxI2CState
),
1479 VMSTATE_STRUCT_POINTER(slave
, PXA2xxI2CState
,
1480 vmstate_pxa2xx_i2c_slave
, PXA2xxI2CSlaveState
),
1481 VMSTATE_END_OF_LIST()
1485 static void pxa2xx_i2c_slave_class_init(ObjectClass
*klass
, void *data
)
1487 I2CSlaveClass
*k
= I2C_SLAVE_CLASS(klass
);
1489 k
->event
= pxa2xx_i2c_event
;
1490 k
->recv
= pxa2xx_i2c_rx
;
1491 k
->send
= pxa2xx_i2c_tx
;
1494 static const TypeInfo pxa2xx_i2c_slave_info
= {
1495 .name
= TYPE_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(hwaddr base
,
1502 qemu_irq irq
, uint32_t region_size
)
1505 SysBusDevice
*i2c_dev
;
1509 dev
= qdev_new(TYPE_PXA2XX_I2C
);
1510 qdev_prop_set_uint32(dev
, "size", region_size
+ 1);
1511 qdev_prop_set_uint32(dev
, "offset", base
& region_size
);
1513 i2c_dev
= SYS_BUS_DEVICE(dev
);
1514 sysbus_realize_and_unref(i2c_dev
, &error_fatal
);
1515 sysbus_mmio_map(i2c_dev
, 0, base
& ~region_size
);
1516 sysbus_connect_irq(i2c_dev
, 0, irq
);
1518 s
= PXA2XX_I2C(i2c_dev
);
1519 /* FIXME: Should the slave device really be on a separate bus? */
1520 i2cbus
= i2c_init_bus(dev
, "dummy");
1521 s
->slave
= PXA2XX_I2C_SLAVE(i2c_slave_create_simple(i2cbus
,
1522 TYPE_PXA2XX_I2C_SLAVE
,
1529 static void pxa2xx_i2c_initfn(Object
*obj
)
1531 DeviceState
*dev
= DEVICE(obj
);
1532 PXA2xxI2CState
*s
= PXA2XX_I2C(obj
);
1533 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
1535 s
->bus
= i2c_init_bus(dev
, NULL
);
1537 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_i2c_ops
, s
,
1538 "pxa2xx-i2c", s
->region_size
);
1539 sysbus_init_mmio(sbd
, &s
->iomem
);
1540 sysbus_init_irq(sbd
, &s
->irq
);
1543 I2CBus
*pxa2xx_i2c_bus(PXA2xxI2CState
*s
)
1548 static Property pxa2xx_i2c_properties
[] = {
1549 DEFINE_PROP_UINT32("size", PXA2xxI2CState
, region_size
, 0x10000),
1550 DEFINE_PROP_UINT32("offset", PXA2xxI2CState
, offset
, 0),
1551 DEFINE_PROP_END_OF_LIST(),
1554 static void pxa2xx_i2c_class_init(ObjectClass
*klass
, void *data
)
1556 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1558 dc
->desc
= "PXA2xx I2C Bus Controller";
1559 dc
->vmsd
= &vmstate_pxa2xx_i2c
;
1560 device_class_set_props(dc
, pxa2xx_i2c_properties
);
1563 static const TypeInfo pxa2xx_i2c_info
= {
1564 .name
= TYPE_PXA2XX_I2C
,
1565 .parent
= TYPE_SYS_BUS_DEVICE
,
1566 .instance_size
= sizeof(PXA2xxI2CState
),
1567 .instance_init
= pxa2xx_i2c_initfn
,
1568 .class_init
= pxa2xx_i2c_class_init
,
1571 /* PXA Inter-IC Sound Controller */
1572 static void pxa2xx_i2s_reset(PXA2xxI2SState
*i2s
)
1578 i2s
->control
[0] = 0x00;
1579 i2s
->control
[1] = 0x00;
1584 #define SACR_TFTH(val) ((val >> 8) & 0xf)
1585 #define SACR_RFTH(val) ((val >> 12) & 0xf)
1586 #define SACR_DREC(val) (val & (1 << 3))
1587 #define SACR_DPRL(val) (val & (1 << 4))
1589 static inline void pxa2xx_i2s_update(PXA2xxI2SState
*i2s
)
1592 rfs
= SACR_RFTH(i2s
->control
[0]) < i2s
->rx_len
&&
1593 !SACR_DREC(i2s
->control
[1]);
1594 tfs
= (i2s
->tx_len
|| i2s
->fifo_len
< SACR_TFTH(i2s
->control
[0])) &&
1595 i2s
->enable
&& !SACR_DPRL(i2s
->control
[1]);
1597 qemu_set_irq(i2s
->rx_dma
, rfs
);
1598 qemu_set_irq(i2s
->tx_dma
, tfs
);
1600 i2s
->status
&= 0xe0;
1601 if (i2s
->fifo_len
< 16 || !i2s
->enable
)
1602 i2s
->status
|= 1 << 0; /* TNF */
1604 i2s
->status
|= 1 << 1; /* RNE */
1606 i2s
->status
|= 1 << 2; /* BSY */
1608 i2s
->status
|= 1 << 3; /* TFS */
1610 i2s
->status
|= 1 << 4; /* RFS */
1611 if (!(i2s
->tx_len
&& i2s
->enable
))
1612 i2s
->status
|= i2s
->fifo_len
<< 8; /* TFL */
1613 i2s
->status
|= MAX(i2s
->rx_len
, 0xf) << 12; /* RFL */
1615 qemu_set_irq(i2s
->irq
, i2s
->status
& i2s
->mask
);
1618 #define SACR0 0x00 /* Serial Audio Global Control register */
1619 #define SACR1 0x04 /* Serial Audio I2S/MSB-Justified Control register */
1620 #define SASR0 0x0c /* Serial Audio Interface and FIFO Status register */
1621 #define SAIMR 0x14 /* Serial Audio Interrupt Mask register */
1622 #define SAICR 0x18 /* Serial Audio Interrupt Clear register */
1623 #define SADIV 0x60 /* Serial Audio Clock Divider register */
1624 #define SADR 0x80 /* Serial Audio Data register */
1626 static uint64_t pxa2xx_i2s_read(void *opaque
, hwaddr addr
,
1629 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1633 return s
->control
[0];
1635 return s
->control
[1];
1645 if (s
->rx_len
> 0) {
1647 pxa2xx_i2s_update(s
);
1648 return s
->codec_in(s
->opaque
);
1652 qemu_log_mask(LOG_GUEST_ERROR
,
1653 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1660 static void pxa2xx_i2s_write(void *opaque
, hwaddr addr
,
1661 uint64_t value
, unsigned size
)
1663 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1668 if (value
& (1 << 3)) /* RST */
1669 pxa2xx_i2s_reset(s
);
1670 s
->control
[0] = value
& 0xff3d;
1671 if (!s
->enable
&& (value
& 1) && s
->tx_len
) { /* ENB */
1672 for (sample
= s
->fifo
; s
->fifo_len
> 0; s
->fifo_len
--, sample
++)
1673 s
->codec_out(s
->opaque
, *sample
);
1674 s
->status
&= ~(1 << 7); /* I2SOFF */
1676 if (value
& (1 << 4)) /* EFWR */
1677 printf("%s: Attempt to use special function\n", __func__
);
1678 s
->enable
= (value
& 9) == 1; /* ENB && !RST*/
1679 pxa2xx_i2s_update(s
);
1682 s
->control
[1] = value
& 0x0039;
1683 if (value
& (1 << 5)) /* ENLBF */
1684 printf("%s: Attempt to use loopback function\n", __func__
);
1685 if (value
& (1 << 4)) /* DPRL */
1687 pxa2xx_i2s_update(s
);
1690 s
->mask
= value
& 0x0078;
1691 pxa2xx_i2s_update(s
);
1694 s
->status
&= ~(value
& (3 << 5));
1695 pxa2xx_i2s_update(s
);
1698 s
->clk
= value
& 0x007f;
1701 if (s
->tx_len
&& s
->enable
) {
1703 pxa2xx_i2s_update(s
);
1704 s
->codec_out(s
->opaque
, value
);
1705 } else if (s
->fifo_len
< 16) {
1706 s
->fifo
[s
->fifo_len
++] = value
;
1707 pxa2xx_i2s_update(s
);
1711 qemu_log_mask(LOG_GUEST_ERROR
,
1712 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1717 static const MemoryRegionOps pxa2xx_i2s_ops
= {
1718 .read
= pxa2xx_i2s_read
,
1719 .write
= pxa2xx_i2s_write
,
1720 .endianness
= DEVICE_NATIVE_ENDIAN
,
1723 static const VMStateDescription vmstate_pxa2xx_i2s
= {
1724 .name
= "pxa2xx_i2s",
1726 .minimum_version_id
= 0,
1727 .fields
= (VMStateField
[]) {
1728 VMSTATE_UINT32_ARRAY(control
, PXA2xxI2SState
, 2),
1729 VMSTATE_UINT32(status
, PXA2xxI2SState
),
1730 VMSTATE_UINT32(mask
, PXA2xxI2SState
),
1731 VMSTATE_UINT32(clk
, PXA2xxI2SState
),
1732 VMSTATE_INT32(enable
, PXA2xxI2SState
),
1733 VMSTATE_INT32(rx_len
, PXA2xxI2SState
),
1734 VMSTATE_INT32(tx_len
, PXA2xxI2SState
),
1735 VMSTATE_INT32(fifo_len
, PXA2xxI2SState
),
1736 VMSTATE_END_OF_LIST()
1740 static void pxa2xx_i2s_data_req(void *opaque
, int tx
, int rx
)
1742 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1745 /* Signal FIFO errors */
1746 if (s
->enable
&& s
->tx_len
)
1747 s
->status
|= 1 << 5; /* TUR */
1748 if (s
->enable
&& s
->rx_len
)
1749 s
->status
|= 1 << 6; /* ROR */
1751 /* Should be tx - MIN(tx, s->fifo_len) but we don't really need to
1752 * handle the cases where it makes a difference. */
1753 s
->tx_len
= tx
- s
->fifo_len
;
1755 /* Note that is s->codec_out wasn't set, we wouldn't get called. */
1757 for (sample
= s
->fifo
; s
->fifo_len
; s
->fifo_len
--, sample
++)
1758 s
->codec_out(s
->opaque
, *sample
);
1759 pxa2xx_i2s_update(s
);
1762 static PXA2xxI2SState
*pxa2xx_i2s_init(MemoryRegion
*sysmem
,
1764 qemu_irq irq
, qemu_irq rx_dma
, qemu_irq tx_dma
)
1766 PXA2xxI2SState
*s
= g_new0(PXA2xxI2SState
, 1);
1771 s
->data_req
= pxa2xx_i2s_data_req
;
1773 pxa2xx_i2s_reset(s
);
1775 memory_region_init_io(&s
->iomem
, NULL
, &pxa2xx_i2s_ops
, s
,
1776 "pxa2xx-i2s", 0x100000);
1777 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
1779 vmstate_register(NULL
, base
, &vmstate_pxa2xx_i2s
, s
);
1784 /* PXA Fast Infra-red Communications Port */
1785 struct PXA2xxFIrState
{
1787 SysBusDevice parent_obj
;
1802 uint8_t rx_fifo
[64];
1805 static void pxa2xx_fir_reset(DeviceState
*d
)
1807 PXA2xxFIrState
*s
= PXA2XX_FIR(d
);
1809 s
->control
[0] = 0x00;
1810 s
->control
[1] = 0x00;
1811 s
->control
[2] = 0x00;
1812 s
->status
[0] = 0x00;
1813 s
->status
[1] = 0x00;
1817 static inline void pxa2xx_fir_update(PXA2xxFIrState
*s
)
1819 static const int tresh
[4] = { 8, 16, 32, 0 };
1821 if ((s
->control
[0] & (1 << 4)) && /* RXE */
1822 s
->rx_len
>= tresh
[s
->control
[2] & 3]) /* TRIG */
1823 s
->status
[0] |= 1 << 4; /* RFS */
1825 s
->status
[0] &= ~(1 << 4); /* RFS */
1826 if (s
->control
[0] & (1 << 3)) /* TXE */
1827 s
->status
[0] |= 1 << 3; /* TFS */
1829 s
->status
[0] &= ~(1 << 3); /* TFS */
1831 s
->status
[1] |= 1 << 2; /* RNE */
1833 s
->status
[1] &= ~(1 << 2); /* RNE */
1834 if (s
->control
[0] & (1 << 4)) /* RXE */
1835 s
->status
[1] |= 1 << 0; /* RSY */
1837 s
->status
[1] &= ~(1 << 0); /* RSY */
1839 intr
|= (s
->control
[0] & (1 << 5)) && /* RIE */
1840 (s
->status
[0] & (1 << 4)); /* RFS */
1841 intr
|= (s
->control
[0] & (1 << 6)) && /* TIE */
1842 (s
->status
[0] & (1 << 3)); /* TFS */
1843 intr
|= (s
->control
[2] & (1 << 4)) && /* TRAIL */
1844 (s
->status
[0] & (1 << 6)); /* EOC */
1845 intr
|= (s
->control
[0] & (1 << 2)) && /* TUS */
1846 (s
->status
[0] & (1 << 1)); /* TUR */
1847 intr
|= s
->status
[0] & 0x25; /* FRE, RAB, EIF */
1849 qemu_set_irq(s
->rx_dma
, (s
->status
[0] >> 4) & 1);
1850 qemu_set_irq(s
->tx_dma
, (s
->status
[0] >> 3) & 1);
1852 qemu_set_irq(s
->irq
, intr
&& s
->enable
);
1855 #define ICCR0 0x00 /* FICP Control register 0 */
1856 #define ICCR1 0x04 /* FICP Control register 1 */
1857 #define ICCR2 0x08 /* FICP Control register 2 */
1858 #define ICDR 0x0c /* FICP Data register */
1859 #define ICSR0 0x14 /* FICP Status register 0 */
1860 #define ICSR1 0x18 /* FICP Status register 1 */
1861 #define ICFOR 0x1c /* FICP FIFO Occupancy Status register */
1863 static uint64_t pxa2xx_fir_read(void *opaque
, hwaddr addr
,
1866 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1871 return s
->control
[0];
1873 return s
->control
[1];
1875 return s
->control
[2];
1877 s
->status
[0] &= ~0x01;
1878 s
->status
[1] &= ~0x72;
1881 ret
= s
->rx_fifo
[s
->rx_start
++];
1883 pxa2xx_fir_update(s
);
1886 printf("%s: Rx FIFO underrun.\n", __func__
);
1889 return s
->status
[0];
1891 return s
->status
[1] | (1 << 3); /* TNF */
1895 qemu_log_mask(LOG_GUEST_ERROR
,
1896 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1903 static void pxa2xx_fir_write(void *opaque
, hwaddr addr
,
1904 uint64_t value64
, unsigned size
)
1906 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1907 uint32_t value
= value64
;
1912 s
->control
[0] = value
;
1913 if (!(value
& (1 << 4))) /* RXE */
1914 s
->rx_len
= s
->rx_start
= 0;
1915 if (!(value
& (1 << 3))) { /* TXE */
1918 s
->enable
= value
& 1; /* ITR */
1921 pxa2xx_fir_update(s
);
1924 s
->control
[1] = value
;
1927 s
->control
[2] = value
& 0x3f;
1928 pxa2xx_fir_update(s
);
1931 if (s
->control
[2] & (1 << 2)) { /* TXP */
1936 if (s
->enable
&& (s
->control
[0] & (1 << 3))) { /* TXE */
1937 /* XXX this blocks entire thread. Rewrite to use
1938 * qemu_chr_fe_write and background I/O callbacks */
1939 qemu_chr_fe_write_all(&s
->chr
, &ch
, 1);
1943 s
->status
[0] &= ~(value
& 0x66);
1944 pxa2xx_fir_update(s
);
1949 qemu_log_mask(LOG_GUEST_ERROR
,
1950 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1955 static const MemoryRegionOps pxa2xx_fir_ops
= {
1956 .read
= pxa2xx_fir_read
,
1957 .write
= pxa2xx_fir_write
,
1958 .endianness
= DEVICE_NATIVE_ENDIAN
,
1961 static int pxa2xx_fir_is_empty(void *opaque
)
1963 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1964 return (s
->rx_len
< 64);
1967 static void pxa2xx_fir_rx(void *opaque
, const uint8_t *buf
, int size
)
1969 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1970 if (!(s
->control
[0] & (1 << 4))) /* RXE */
1974 s
->status
[1] |= 1 << 4; /* EOF */
1975 if (s
->rx_len
>= 64) {
1976 s
->status
[1] |= 1 << 6; /* ROR */
1980 if (s
->control
[2] & (1 << 3)) /* RXP */
1981 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = *(buf
++);
1983 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = ~*(buf
++);
1986 pxa2xx_fir_update(s
);
1989 static void pxa2xx_fir_event(void *opaque
, QEMUChrEvent event
)
1993 static void pxa2xx_fir_instance_init(Object
*obj
)
1995 PXA2xxFIrState
*s
= PXA2XX_FIR(obj
);
1996 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
1998 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_fir_ops
, s
,
1999 "pxa2xx-fir", 0x1000);
2000 sysbus_init_mmio(sbd
, &s
->iomem
);
2001 sysbus_init_irq(sbd
, &s
->irq
);
2002 sysbus_init_irq(sbd
, &s
->rx_dma
);
2003 sysbus_init_irq(sbd
, &s
->tx_dma
);
2006 static void pxa2xx_fir_realize(DeviceState
*dev
, Error
**errp
)
2008 PXA2xxFIrState
*s
= PXA2XX_FIR(dev
);
2010 qemu_chr_fe_set_handlers(&s
->chr
, pxa2xx_fir_is_empty
,
2011 pxa2xx_fir_rx
, pxa2xx_fir_event
, NULL
, s
, NULL
,
2015 static bool pxa2xx_fir_vmstate_validate(void *opaque
, int version_id
)
2017 PXA2xxFIrState
*s
= opaque
;
2019 return s
->rx_start
< ARRAY_SIZE(s
->rx_fifo
);
2022 static const VMStateDescription pxa2xx_fir_vmsd
= {
2023 .name
= "pxa2xx-fir",
2025 .minimum_version_id
= 1,
2026 .fields
= (VMStateField
[]) {
2027 VMSTATE_UINT32(enable
, PXA2xxFIrState
),
2028 VMSTATE_UINT8_ARRAY(control
, PXA2xxFIrState
, 3),
2029 VMSTATE_UINT8_ARRAY(status
, PXA2xxFIrState
, 2),
2030 VMSTATE_UINT32(rx_len
, PXA2xxFIrState
),
2031 VMSTATE_UINT32(rx_start
, PXA2xxFIrState
),
2032 VMSTATE_VALIDATE("fifo is 64 bytes", pxa2xx_fir_vmstate_validate
),
2033 VMSTATE_UINT8_ARRAY(rx_fifo
, PXA2xxFIrState
, 64),
2034 VMSTATE_END_OF_LIST()
2038 static Property pxa2xx_fir_properties
[] = {
2039 DEFINE_PROP_CHR("chardev", PXA2xxFIrState
, chr
),
2040 DEFINE_PROP_END_OF_LIST(),
2043 static void pxa2xx_fir_class_init(ObjectClass
*klass
, void *data
)
2045 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2047 dc
->realize
= pxa2xx_fir_realize
;
2048 dc
->vmsd
= &pxa2xx_fir_vmsd
;
2049 device_class_set_props(dc
, pxa2xx_fir_properties
);
2050 dc
->reset
= pxa2xx_fir_reset
;
2053 static const TypeInfo pxa2xx_fir_info
= {
2054 .name
= TYPE_PXA2XX_FIR
,
2055 .parent
= TYPE_SYS_BUS_DEVICE
,
2056 .instance_size
= sizeof(PXA2xxFIrState
),
2057 .class_init
= pxa2xx_fir_class_init
,
2058 .instance_init
= pxa2xx_fir_instance_init
,
2061 static PXA2xxFIrState
*pxa2xx_fir_init(MemoryRegion
*sysmem
,
2063 qemu_irq irq
, qemu_irq rx_dma
,
2070 dev
= qdev_new(TYPE_PXA2XX_FIR
);
2071 qdev_prop_set_chr(dev
, "chardev", chr
);
2072 sbd
= SYS_BUS_DEVICE(dev
);
2073 sysbus_realize_and_unref(sbd
, &error_fatal
);
2074 sysbus_mmio_map(sbd
, 0, base
);
2075 sysbus_connect_irq(sbd
, 0, irq
);
2076 sysbus_connect_irq(sbd
, 1, rx_dma
);
2077 sysbus_connect_irq(sbd
, 2, tx_dma
);
2078 return PXA2XX_FIR(dev
);
2081 static void pxa2xx_reset(void *opaque
, int line
, int level
)
2083 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
2085 if (level
&& (s
->pm_regs
[PCFR
>> 2] & 0x10)) { /* GPR_EN */
2086 cpu_reset(CPU(s
->cpu
));
2087 /* TODO: reset peripherals */
2091 /* Initialise a PXA270 integrated chip (ARM based core). */
2092 PXA2xxState
*pxa270_init(MemoryRegion
*address_space
,
2093 unsigned int sdram_size
, const char *cpu_type
)
2098 s
= g_new0(PXA2xxState
, 1);
2100 if (strncmp(cpu_type
, "pxa27", 5)) {
2101 error_report("Machine requires a PXA27x processor");
2105 s
->cpu
= ARM_CPU(cpu_create(cpu_type
));
2106 s
->reset
= qemu_allocate_irq(pxa2xx_reset
, s
, 0);
2108 /* SDRAM & Internal Memory Storage */
2109 memory_region_init_ram(&s
->sdram
, NULL
, "pxa270.sdram", sdram_size
,
2111 memory_region_add_subregion(address_space
, PXA2XX_SDRAM_BASE
, &s
->sdram
);
2112 memory_region_init_ram(&s
->internal
, NULL
, "pxa270.internal", 0x40000,
2114 memory_region_add_subregion(address_space
, PXA2XX_INTERNAL_BASE
,
2117 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->cpu
);
2119 s
->dma
= pxa27x_dma_init(0x40000000,
2120 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_DMA
));
2122 sysbus_create_varargs("pxa27x-timer", 0x40a00000,
2123 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 0),
2124 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 1),
2125 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 2),
2126 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 3),
2127 qdev_get_gpio_in(s
->pic
, PXA27X_PIC_OST_4_11
),
2130 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->cpu
, s
->pic
, 121);
2132 s
->mmc
= pxa2xx_mmci_init(address_space
, 0x41100000,
2133 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_MMC
),
2134 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_MMCI
),
2135 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_MMCI
));
2136 dinfo
= drive_get(IF_SD
, 0, 0);
2138 DeviceState
*carddev
;
2140 /* Create and plug in the sd card */
2141 carddev
= qdev_new(TYPE_SD_CARD
);
2142 qdev_prop_set_drive_err(carddev
, "drive",
2143 blk_by_legacy_dinfo(dinfo
), &error_fatal
);
2144 qdev_realize_and_unref(carddev
, qdev_get_child_bus(DEVICE(s
->mmc
),
2147 } else if (!qtest_enabled()) {
2148 warn_report("missing SecureDigital device");
2151 for (i
= 0; pxa270_serial
[i
].io_base
; i
++) {
2153 serial_mm_init(address_space
, pxa270_serial
[i
].io_base
, 2,
2154 qdev_get_gpio_in(s
->pic
, pxa270_serial
[i
].irqn
),
2155 14857000 / 16, serial_hd(i
),
2156 DEVICE_NATIVE_ENDIAN
);
2162 s
->fir
= pxa2xx_fir_init(address_space
, 0x40800000,
2163 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_ICP
),
2164 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_ICP
),
2165 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_ICP
),
2168 s
->lcd
= pxa2xx_lcdc_init(address_space
, 0x44000000,
2169 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_LCD
));
2171 s
->cm_base
= 0x41300000;
2172 s
->cm_regs
[CCCR
>> 2] = 0x02000210; /* 416.0 MHz */
2173 s
->clkcfg
= 0x00000009; /* Turbo mode active */
2174 memory_region_init_io(&s
->cm_iomem
, NULL
, &pxa2xx_cm_ops
, s
, "pxa2xx-cm", 0x1000);
2175 memory_region_add_subregion(address_space
, s
->cm_base
, &s
->cm_iomem
);
2176 vmstate_register(NULL
, 0, &vmstate_pxa2xx_cm
, s
);
2178 pxa2xx_setup_cp14(s
);
2180 s
->mm_base
= 0x48000000;
2181 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
2182 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
2183 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
2184 memory_region_init_io(&s
->mm_iomem
, NULL
, &pxa2xx_mm_ops
, s
, "pxa2xx-mm", 0x1000);
2185 memory_region_add_subregion(address_space
, s
->mm_base
, &s
->mm_iomem
);
2186 vmstate_register(NULL
, 0, &vmstate_pxa2xx_mm
, s
);
2188 s
->pm_base
= 0x40f00000;
2189 memory_region_init_io(&s
->pm_iomem
, NULL
, &pxa2xx_pm_ops
, s
, "pxa2xx-pm", 0x100);
2190 memory_region_add_subregion(address_space
, s
->pm_base
, &s
->pm_iomem
);
2191 vmstate_register(NULL
, 0, &vmstate_pxa2xx_pm
, s
);
2193 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++);
2194 s
->ssp
= g_new0(SSIBus
*, i
);
2195 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++) {
2197 dev
= sysbus_create_simple(TYPE_PXA2XX_SSP
, pxa27x_ssp
[i
].io_base
,
2198 qdev_get_gpio_in(s
->pic
, pxa27x_ssp
[i
].irqn
));
2199 s
->ssp
[i
] = (SSIBus
*)qdev_get_child_bus(dev
, "ssi");
2202 sysbus_create_simple("sysbus-ohci", 0x4c000000,
2203 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_USBH1
));
2205 s
->pcmcia
[0] = pxa2xx_pcmcia_init(address_space
, 0x20000000);
2206 s
->pcmcia
[1] = pxa2xx_pcmcia_init(address_space
, 0x30000000);
2208 sysbus_create_simple(TYPE_PXA2XX_RTC
, 0x40900000,
2209 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_RTCALARM
));
2211 s
->i2c
[0] = pxa2xx_i2c_init(0x40301600,
2212 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2C
), 0xffff);
2213 s
->i2c
[1] = pxa2xx_i2c_init(0x40f00100,
2214 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_PWRI2C
), 0xff);
2216 s
->i2s
= pxa2xx_i2s_init(address_space
, 0x40400000,
2217 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2S
),
2218 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_I2S
),
2219 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_I2S
));
2221 s
->kp
= pxa27x_keypad_init(address_space
, 0x41500000,
2222 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_KEYPAD
));
2224 /* GPIO1 resets the processor */
2225 /* The handler can be overridden by board-specific code */
2226 qdev_connect_gpio_out(s
->gpio
, 1, s
->reset
);
2230 /* Initialise a PXA255 integrated chip (ARM based core). */
2231 PXA2xxState
*pxa255_init(MemoryRegion
*address_space
, unsigned int sdram_size
)
2237 s
= g_new0(PXA2xxState
, 1);
2239 s
->cpu
= ARM_CPU(cpu_create(ARM_CPU_TYPE_NAME("pxa255")));
2240 s
->reset
= qemu_allocate_irq(pxa2xx_reset
, s
, 0);
2242 /* SDRAM & Internal Memory Storage */
2243 memory_region_init_ram(&s
->sdram
, NULL
, "pxa255.sdram", sdram_size
,
2245 memory_region_add_subregion(address_space
, PXA2XX_SDRAM_BASE
, &s
->sdram
);
2246 memory_region_init_ram(&s
->internal
, NULL
, "pxa255.internal",
2247 PXA2XX_INTERNAL_SIZE
, &error_fatal
);
2248 memory_region_add_subregion(address_space
, PXA2XX_INTERNAL_BASE
,
2251 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->cpu
);
2253 s
->dma
= pxa255_dma_init(0x40000000,
2254 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_DMA
));
2256 sysbus_create_varargs("pxa25x-timer", 0x40a00000,
2257 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 0),
2258 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 1),
2259 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 2),
2260 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 3),
2263 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->cpu
, s
->pic
, 85);
2265 s
->mmc
= pxa2xx_mmci_init(address_space
, 0x41100000,
2266 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_MMC
),
2267 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_MMCI
),
2268 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_MMCI
));
2269 dinfo
= drive_get(IF_SD
, 0, 0);
2271 DeviceState
*carddev
;
2273 /* Create and plug in the sd card */
2274 carddev
= qdev_new(TYPE_SD_CARD
);
2275 qdev_prop_set_drive_err(carddev
, "drive",
2276 blk_by_legacy_dinfo(dinfo
), &error_fatal
);
2277 qdev_realize_and_unref(carddev
, qdev_get_child_bus(DEVICE(s
->mmc
),
2280 } else if (!qtest_enabled()) {
2281 warn_report("missing SecureDigital device");
2284 for (i
= 0; pxa255_serial
[i
].io_base
; i
++) {
2286 serial_mm_init(address_space
, pxa255_serial
[i
].io_base
, 2,
2287 qdev_get_gpio_in(s
->pic
, pxa255_serial
[i
].irqn
),
2288 14745600 / 16, serial_hd(i
),
2289 DEVICE_NATIVE_ENDIAN
);
2295 s
->fir
= pxa2xx_fir_init(address_space
, 0x40800000,
2296 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_ICP
),
2297 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_ICP
),
2298 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_ICP
),
2301 s
->lcd
= pxa2xx_lcdc_init(address_space
, 0x44000000,
2302 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_LCD
));
2304 s
->cm_base
= 0x41300000;
2305 s
->cm_regs
[CCCR
>> 2] = 0x00000121; /* from datasheet */
2306 s
->cm_regs
[CKEN
>> 2] = 0x00017def; /* from datasheet */
2308 s
->clkcfg
= 0x00000009; /* Turbo mode active */
2309 memory_region_init_io(&s
->cm_iomem
, NULL
, &pxa2xx_cm_ops
, s
, "pxa2xx-cm", 0x1000);
2310 memory_region_add_subregion(address_space
, s
->cm_base
, &s
->cm_iomem
);
2311 vmstate_register(NULL
, 0, &vmstate_pxa2xx_cm
, s
);
2313 pxa2xx_setup_cp14(s
);
2315 s
->mm_base
= 0x48000000;
2316 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
2317 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
2318 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
2319 memory_region_init_io(&s
->mm_iomem
, NULL
, &pxa2xx_mm_ops
, s
, "pxa2xx-mm", 0x1000);
2320 memory_region_add_subregion(address_space
, s
->mm_base
, &s
->mm_iomem
);
2321 vmstate_register(NULL
, 0, &vmstate_pxa2xx_mm
, s
);
2323 s
->pm_base
= 0x40f00000;
2324 memory_region_init_io(&s
->pm_iomem
, NULL
, &pxa2xx_pm_ops
, s
, "pxa2xx-pm", 0x100);
2325 memory_region_add_subregion(address_space
, s
->pm_base
, &s
->pm_iomem
);
2326 vmstate_register(NULL
, 0, &vmstate_pxa2xx_pm
, s
);
2328 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++);
2329 s
->ssp
= g_new0(SSIBus
*, i
);
2330 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++) {
2332 dev
= sysbus_create_simple(TYPE_PXA2XX_SSP
, pxa255_ssp
[i
].io_base
,
2333 qdev_get_gpio_in(s
->pic
, pxa255_ssp
[i
].irqn
));
2334 s
->ssp
[i
] = (SSIBus
*)qdev_get_child_bus(dev
, "ssi");
2337 s
->pcmcia
[0] = pxa2xx_pcmcia_init(address_space
, 0x20000000);
2338 s
->pcmcia
[1] = pxa2xx_pcmcia_init(address_space
, 0x30000000);
2340 sysbus_create_simple(TYPE_PXA2XX_RTC
, 0x40900000,
2341 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_RTCALARM
));
2343 s
->i2c
[0] = pxa2xx_i2c_init(0x40301600,
2344 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2C
), 0xffff);
2345 s
->i2c
[1] = pxa2xx_i2c_init(0x40f00100,
2346 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_PWRI2C
), 0xff);
2348 s
->i2s
= pxa2xx_i2s_init(address_space
, 0x40400000,
2349 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2S
),
2350 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_I2S
),
2351 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_I2S
));
2353 /* GPIO1 resets the processor */
2354 /* The handler can be overridden by board-specific code */
2355 qdev_connect_gpio_out(s
->gpio
, 1, s
->reset
);
2359 static void pxa2xx_ssp_class_init(ObjectClass
*klass
, void *data
)
2361 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2363 dc
->reset
= pxa2xx_ssp_reset
;
2364 dc
->vmsd
= &vmstate_pxa2xx_ssp
;
2367 static const TypeInfo pxa2xx_ssp_info
= {
2368 .name
= TYPE_PXA2XX_SSP
,
2369 .parent
= TYPE_SYS_BUS_DEVICE
,
2370 .instance_size
= sizeof(PXA2xxSSPState
),
2371 .instance_init
= pxa2xx_ssp_init
,
2372 .class_init
= pxa2xx_ssp_class_init
,
2375 static void pxa2xx_register_types(void)
2377 type_register_static(&pxa2xx_i2c_slave_info
);
2378 type_register_static(&pxa2xx_ssp_info
);
2379 type_register_static(&pxa2xx_i2c_info
);
2380 type_register_static(&pxa2xx_rtc_sysbus_info
);
2381 type_register_static(&pxa2xx_fir_info
);
2384 type_init(pxa2xx_register_types
)