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/ssi/ssi.h"
25 #include "chardev/char-fe.h"
26 #include "sysemu/blockdev.h"
27 #include "sysemu/qtest.h"
28 #include "qemu/cutils.h"
35 { 0x40100000, PXA2XX_PIC_FFUART
},
36 { 0x40200000, PXA2XX_PIC_BTUART
},
37 { 0x40700000, PXA2XX_PIC_STUART
},
38 { 0x41600000, PXA25X_PIC_HWUART
},
40 }, pxa270_serial
[] = {
41 { 0x40100000, PXA2XX_PIC_FFUART
},
42 { 0x40200000, PXA2XX_PIC_BTUART
},
43 { 0x40700000, PXA2XX_PIC_STUART
},
47 typedef struct PXASSPDef
{
53 static PXASSPDef pxa250_ssp
[] = {
54 { 0x41000000, PXA2XX_PIC_SSP
},
59 static PXASSPDef pxa255_ssp
[] = {
60 { 0x41000000, PXA2XX_PIC_SSP
},
61 { 0x41400000, PXA25X_PIC_NSSP
},
66 static PXASSPDef pxa26x_ssp
[] = {
67 { 0x41000000, PXA2XX_PIC_SSP
},
68 { 0x41400000, PXA25X_PIC_NSSP
},
69 { 0x41500000, PXA26X_PIC_ASSP
},
74 static PXASSPDef pxa27x_ssp
[] = {
75 { 0x41000000, PXA2XX_PIC_SSP
},
76 { 0x41700000, PXA27X_PIC_SSP2
},
77 { 0x41900000, PXA2XX_PIC_SSP3
},
81 #define PMCR 0x00 /* Power Manager Control register */
82 #define PSSR 0x04 /* Power Manager Sleep Status register */
83 #define PSPR 0x08 /* Power Manager Scratch-Pad register */
84 #define PWER 0x0c /* Power Manager Wake-Up Enable register */
85 #define PRER 0x10 /* Power Manager Rising-Edge Detect Enable register */
86 #define PFER 0x14 /* Power Manager Falling-Edge Detect Enable register */
87 #define PEDR 0x18 /* Power Manager Edge-Detect Status register */
88 #define PCFR 0x1c /* Power Manager General Configuration register */
89 #define PGSR0 0x20 /* Power Manager GPIO Sleep-State register 0 */
90 #define PGSR1 0x24 /* Power Manager GPIO Sleep-State register 1 */
91 #define PGSR2 0x28 /* Power Manager GPIO Sleep-State register 2 */
92 #define PGSR3 0x2c /* Power Manager GPIO Sleep-State register 3 */
93 #define RCSR 0x30 /* Reset Controller Status register */
94 #define PSLR 0x34 /* Power Manager Sleep Configuration register */
95 #define PTSR 0x38 /* Power Manager Standby Configuration register */
96 #define PVCR 0x40 /* Power Manager Voltage Change Control register */
97 #define PUCR 0x4c /* Power Manager USIM Card Control/Status register */
98 #define PKWR 0x50 /* Power Manager Keyboard Wake-Up Enable register */
99 #define PKSR 0x54 /* Power Manager Keyboard Level-Detect Status */
100 #define PCMD0 0x80 /* Power Manager I2C Command register File 0 */
101 #define PCMD31 0xfc /* Power Manager I2C Command register File 31 */
103 static uint64_t pxa2xx_pm_read(void *opaque
, hwaddr addr
,
106 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
109 case PMCR
... PCMD31
:
113 return s
->pm_regs
[addr
>> 2];
116 qemu_log_mask(LOG_GUEST_ERROR
,
117 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
124 static void pxa2xx_pm_write(void *opaque
, hwaddr addr
,
125 uint64_t value
, unsigned size
)
127 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
131 /* Clear the write-one-to-clear bits... */
132 s
->pm_regs
[addr
>> 2] &= ~(value
& 0x2a);
133 /* ...and set the plain r/w bits */
134 s
->pm_regs
[addr
>> 2] &= ~0x15;
135 s
->pm_regs
[addr
>> 2] |= value
& 0x15;
138 case PSSR
: /* Read-clean registers */
141 s
->pm_regs
[addr
>> 2] &= ~value
;
144 default: /* Read-write registers */
146 s
->pm_regs
[addr
>> 2] = value
;
149 qemu_log_mask(LOG_GUEST_ERROR
,
150 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
156 static const MemoryRegionOps pxa2xx_pm_ops
= {
157 .read
= pxa2xx_pm_read
,
158 .write
= pxa2xx_pm_write
,
159 .endianness
= DEVICE_NATIVE_ENDIAN
,
162 static const VMStateDescription vmstate_pxa2xx_pm
= {
165 .minimum_version_id
= 0,
166 .fields
= (VMStateField
[]) {
167 VMSTATE_UINT32_ARRAY(pm_regs
, PXA2xxState
, 0x40),
168 VMSTATE_END_OF_LIST()
172 #define CCCR 0x00 /* Core Clock Configuration register */
173 #define CKEN 0x04 /* Clock Enable register */
174 #define OSCC 0x08 /* Oscillator Configuration register */
175 #define CCSR 0x0c /* Core Clock Status register */
177 static uint64_t pxa2xx_cm_read(void *opaque
, hwaddr addr
,
180 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
186 return s
->cm_regs
[addr
>> 2];
189 return s
->cm_regs
[CCCR
>> 2] | (3 << 28);
192 qemu_log_mask(LOG_GUEST_ERROR
,
193 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
200 static void pxa2xx_cm_write(void *opaque
, hwaddr addr
,
201 uint64_t value
, unsigned size
)
203 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
208 s
->cm_regs
[addr
>> 2] = value
;
212 s
->cm_regs
[addr
>> 2] &= ~0x6c;
213 s
->cm_regs
[addr
>> 2] |= value
& 0x6e;
214 if ((value
>> 1) & 1) /* OON */
215 s
->cm_regs
[addr
>> 2] |= 1 << 0; /* Oscillator is now stable */
219 qemu_log_mask(LOG_GUEST_ERROR
,
220 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
226 static const MemoryRegionOps pxa2xx_cm_ops
= {
227 .read
= pxa2xx_cm_read
,
228 .write
= pxa2xx_cm_write
,
229 .endianness
= DEVICE_NATIVE_ENDIAN
,
232 static const VMStateDescription vmstate_pxa2xx_cm
= {
235 .minimum_version_id
= 0,
236 .fields
= (VMStateField
[]) {
237 VMSTATE_UINT32_ARRAY(cm_regs
, PXA2xxState
, 4),
238 VMSTATE_UINT32(clkcfg
, PXA2xxState
),
239 VMSTATE_UINT32(pmnc
, PXA2xxState
),
240 VMSTATE_END_OF_LIST()
244 static uint64_t pxa2xx_clkcfg_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
246 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
250 static void pxa2xx_clkcfg_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
253 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
254 s
->clkcfg
= value
& 0xf;
256 printf("%s: CPU frequency change attempt\n", __func__
);
260 static void pxa2xx_pwrmode_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
263 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
264 static const char *pwrmode
[8] = {
265 "Normal", "Idle", "Deep-idle", "Standby",
266 "Sleep", "reserved (!)", "reserved (!)", "Deep-sleep",
270 printf("%s: CPU voltage change attempt\n", __func__
);
279 if (!(s
->cm_regs
[CCCR
>> 2] & (1U << 31))) { /* CPDIS */
280 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
287 cpu_interrupt(CPU(s
->cpu
), CPU_INTERRUPT_HALT
);
288 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
292 s
->cpu
->env
.uncached_cpsr
= ARM_CPU_MODE_SVC
;
293 s
->cpu
->env
.daif
= PSTATE_A
| PSTATE_F
| PSTATE_I
;
294 s
->cpu
->env
.cp15
.sctlr_ns
= 0;
295 s
->cpu
->env
.cp15
.cpacr_el1
= 0;
296 s
->cpu
->env
.cp15
.ttbr0_el
[1] = 0;
297 s
->cpu
->env
.cp15
.dacr_ns
= 0;
298 s
->pm_regs
[PSSR
>> 2] |= 0x8; /* Set STS */
299 s
->pm_regs
[RCSR
>> 2] |= 0x8; /* Set GPR */
302 * The scratch-pad register is almost universally used
303 * for storing the return address on suspend. For the
304 * lack of a resuming bootloader, perform a jump
305 * directly to that address.
307 memset(s
->cpu
->env
.regs
, 0, 4 * 15);
308 s
->cpu
->env
.regs
[15] = s
->pm_regs
[PSPR
>> 2];
311 buffer
= 0xe59ff000; /* ldr pc, [pc, #0] */
312 cpu_physical_memory_write(0, &buffer
, 4);
313 buffer
= s
->pm_regs
[PSPR
>> 2];
314 cpu_physical_memory_write(8, &buffer
, 4);
318 cpu_interrupt(current_cpu
, CPU_INTERRUPT_HALT
);
324 printf("%s: machine entered %s mode\n", __func__
,
329 static uint64_t pxa2xx_cppmnc_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
331 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
335 static void pxa2xx_cppmnc_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
338 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
342 static uint64_t pxa2xx_cpccnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
344 PXA2xxState
*s
= (PXA2xxState
*)ri
->opaque
;
346 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
352 static const ARMCPRegInfo pxa_cp_reginfo
[] = {
353 /* cp14 crm==1: perf registers */
354 { .name
= "CPPMNC", .cp
= 14, .crn
= 0, .crm
= 1, .opc1
= 0, .opc2
= 0,
355 .access
= PL1_RW
, .type
= ARM_CP_IO
,
356 .readfn
= pxa2xx_cppmnc_read
, .writefn
= pxa2xx_cppmnc_write
},
357 { .name
= "CPCCNT", .cp
= 14, .crn
= 1, .crm
= 1, .opc1
= 0, .opc2
= 0,
358 .access
= PL1_RW
, .type
= ARM_CP_IO
,
359 .readfn
= pxa2xx_cpccnt_read
, .writefn
= arm_cp_write_ignore
},
360 { .name
= "CPINTEN", .cp
= 14, .crn
= 4, .crm
= 1, .opc1
= 0, .opc2
= 0,
361 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
362 { .name
= "CPFLAG", .cp
= 14, .crn
= 5, .crm
= 1, .opc1
= 0, .opc2
= 0,
363 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
364 { .name
= "CPEVTSEL", .cp
= 14, .crn
= 8, .crm
= 1, .opc1
= 0, .opc2
= 0,
365 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
366 /* cp14 crm==2: performance count registers */
367 { .name
= "CPPMN0", .cp
= 14, .crn
= 0, .crm
= 2, .opc1
= 0, .opc2
= 0,
368 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
369 { .name
= "CPPMN1", .cp
= 14, .crn
= 1, .crm
= 2, .opc1
= 0, .opc2
= 0,
370 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
371 { .name
= "CPPMN2", .cp
= 14, .crn
= 2, .crm
= 2, .opc1
= 0, .opc2
= 0,
372 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
373 { .name
= "CPPMN3", .cp
= 14, .crn
= 2, .crm
= 3, .opc1
= 0, .opc2
= 0,
374 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
375 /* cp14 crn==6: CLKCFG */
376 { .name
= "CLKCFG", .cp
= 14, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
377 .access
= PL1_RW
, .type
= ARM_CP_IO
,
378 .readfn
= pxa2xx_clkcfg_read
, .writefn
= pxa2xx_clkcfg_write
},
379 /* cp14 crn==7: PWRMODE */
380 { .name
= "PWRMODE", .cp
= 14, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 0,
381 .access
= PL1_RW
, .type
= ARM_CP_IO
,
382 .readfn
= arm_cp_read_zero
, .writefn
= pxa2xx_pwrmode_write
},
386 static void pxa2xx_setup_cp14(PXA2xxState
*s
)
388 define_arm_cp_regs_with_opaque(s
->cpu
, pxa_cp_reginfo
, s
);
391 #define MDCNFG 0x00 /* SDRAM Configuration register */
392 #define MDREFR 0x04 /* SDRAM Refresh Control register */
393 #define MSC0 0x08 /* Static Memory Control register 0 */
394 #define MSC1 0x0c /* Static Memory Control register 1 */
395 #define MSC2 0x10 /* Static Memory Control register 2 */
396 #define MECR 0x14 /* Expansion Memory Bus Config register */
397 #define SXCNFG 0x1c /* Synchronous Static Memory Config register */
398 #define MCMEM0 0x28 /* PC Card Memory Socket 0 Timing register */
399 #define MCMEM1 0x2c /* PC Card Memory Socket 1 Timing register */
400 #define MCATT0 0x30 /* PC Card Attribute Socket 0 register */
401 #define MCATT1 0x34 /* PC Card Attribute Socket 1 register */
402 #define MCIO0 0x38 /* PC Card I/O Socket 0 Timing register */
403 #define MCIO1 0x3c /* PC Card I/O Socket 1 Timing register */
404 #define MDMRS 0x40 /* SDRAM Mode Register Set Config register */
405 #define BOOT_DEF 0x44 /* Boot-time Default Configuration register */
406 #define ARB_CNTL 0x48 /* Arbiter Control register */
407 #define BSCNTR0 0x4c /* Memory Buffer Strength Control register 0 */
408 #define BSCNTR1 0x50 /* Memory Buffer Strength Control register 1 */
409 #define LCDBSCNTR 0x54 /* LCD Buffer Strength Control register */
410 #define MDMRSLP 0x58 /* Low Power SDRAM Mode Set Config register */
411 #define BSCNTR2 0x5c /* Memory Buffer Strength Control register 2 */
412 #define BSCNTR3 0x60 /* Memory Buffer Strength Control register 3 */
413 #define SA1110 0x64 /* SA-1110 Memory Compatibility register */
415 static uint64_t pxa2xx_mm_read(void *opaque
, hwaddr addr
,
418 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
421 case MDCNFG
... SA1110
:
423 return s
->mm_regs
[addr
>> 2];
426 qemu_log_mask(LOG_GUEST_ERROR
,
427 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
434 static void pxa2xx_mm_write(void *opaque
, hwaddr addr
,
435 uint64_t value
, unsigned size
)
437 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
440 case MDCNFG
... SA1110
:
441 if ((addr
& 3) == 0) {
442 s
->mm_regs
[addr
>> 2] = value
;
447 qemu_log_mask(LOG_GUEST_ERROR
,
448 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
454 static const MemoryRegionOps pxa2xx_mm_ops
= {
455 .read
= pxa2xx_mm_read
,
456 .write
= pxa2xx_mm_write
,
457 .endianness
= DEVICE_NATIVE_ENDIAN
,
460 static const VMStateDescription vmstate_pxa2xx_mm
= {
463 .minimum_version_id
= 0,
464 .fields
= (VMStateField
[]) {
465 VMSTATE_UINT32_ARRAY(mm_regs
, PXA2xxState
, 0x1a),
466 VMSTATE_END_OF_LIST()
470 #define TYPE_PXA2XX_SSP "pxa2xx-ssp"
471 #define PXA2XX_SSP(obj) \
472 OBJECT_CHECK(PXA2xxSSPState, (obj), TYPE_PXA2XX_SSP)
474 /* Synchronous Serial Ports */
477 SysBusDevice parent_obj
;
494 uint32_t rx_fifo
[16];
499 static bool pxa2xx_ssp_vmstate_validate(void *opaque
, int version_id
)
501 PXA2xxSSPState
*s
= opaque
;
503 return s
->rx_start
< sizeof(s
->rx_fifo
);
506 static const VMStateDescription vmstate_pxa2xx_ssp
= {
507 .name
= "pxa2xx-ssp",
509 .minimum_version_id
= 1,
510 .fields
= (VMStateField
[]) {
511 VMSTATE_UINT32(enable
, PXA2xxSSPState
),
512 VMSTATE_UINT32_ARRAY(sscr
, PXA2xxSSPState
, 2),
513 VMSTATE_UINT32(sspsp
, PXA2xxSSPState
),
514 VMSTATE_UINT32(ssto
, PXA2xxSSPState
),
515 VMSTATE_UINT32(ssitr
, PXA2xxSSPState
),
516 VMSTATE_UINT32(sssr
, PXA2xxSSPState
),
517 VMSTATE_UINT8(sstsa
, PXA2xxSSPState
),
518 VMSTATE_UINT8(ssrsa
, PXA2xxSSPState
),
519 VMSTATE_UINT8(ssacd
, PXA2xxSSPState
),
520 VMSTATE_UINT32(rx_level
, PXA2xxSSPState
),
521 VMSTATE_UINT32(rx_start
, PXA2xxSSPState
),
522 VMSTATE_VALIDATE("fifo is 16 bytes", pxa2xx_ssp_vmstate_validate
),
523 VMSTATE_UINT32_ARRAY(rx_fifo
, PXA2xxSSPState
, 16),
524 VMSTATE_END_OF_LIST()
528 #define SSCR0 0x00 /* SSP Control register 0 */
529 #define SSCR1 0x04 /* SSP Control register 1 */
530 #define SSSR 0x08 /* SSP Status register */
531 #define SSITR 0x0c /* SSP Interrupt Test register */
532 #define SSDR 0x10 /* SSP Data register */
533 #define SSTO 0x28 /* SSP Time-Out register */
534 #define SSPSP 0x2c /* SSP Programmable Serial Protocol register */
535 #define SSTSA 0x30 /* SSP TX Time Slot Active register */
536 #define SSRSA 0x34 /* SSP RX Time Slot Active register */
537 #define SSTSS 0x38 /* SSP Time Slot Status register */
538 #define SSACD 0x3c /* SSP Audio Clock Divider register */
540 /* Bitfields for above registers */
541 #define SSCR0_SPI(x) (((x) & 0x30) == 0x00)
542 #define SSCR0_SSP(x) (((x) & 0x30) == 0x10)
543 #define SSCR0_UWIRE(x) (((x) & 0x30) == 0x20)
544 #define SSCR0_PSP(x) (((x) & 0x30) == 0x30)
545 #define SSCR0_SSE (1 << 7)
546 #define SSCR0_RIM (1 << 22)
547 #define SSCR0_TIM (1 << 23)
548 #define SSCR0_MOD (1U << 31)
549 #define SSCR0_DSS(x) (((((x) >> 16) & 0x10) | ((x) & 0xf)) + 1)
550 #define SSCR1_RIE (1 << 0)
551 #define SSCR1_TIE (1 << 1)
552 #define SSCR1_LBM (1 << 2)
553 #define SSCR1_MWDS (1 << 5)
554 #define SSCR1_TFT(x) ((((x) >> 6) & 0xf) + 1)
555 #define SSCR1_RFT(x) ((((x) >> 10) & 0xf) + 1)
556 #define SSCR1_EFWR (1 << 14)
557 #define SSCR1_PINTE (1 << 18)
558 #define SSCR1_TINTE (1 << 19)
559 #define SSCR1_RSRE (1 << 20)
560 #define SSCR1_TSRE (1 << 21)
561 #define SSCR1_EBCEI (1 << 29)
562 #define SSITR_INT (7 << 5)
563 #define SSSR_TNF (1 << 2)
564 #define SSSR_RNE (1 << 3)
565 #define SSSR_TFS (1 << 5)
566 #define SSSR_RFS (1 << 6)
567 #define SSSR_ROR (1 << 7)
568 #define SSSR_PINT (1 << 18)
569 #define SSSR_TINT (1 << 19)
570 #define SSSR_EOC (1 << 20)
571 #define SSSR_TUR (1 << 21)
572 #define SSSR_BCE (1 << 23)
573 #define SSSR_RW 0x00bc0080
575 static void pxa2xx_ssp_int_update(PXA2xxSSPState
*s
)
579 level
|= s
->ssitr
& SSITR_INT
;
580 level
|= (s
->sssr
& SSSR_BCE
) && (s
->sscr
[1] & SSCR1_EBCEI
);
581 level
|= (s
->sssr
& SSSR_TUR
) && !(s
->sscr
[0] & SSCR0_TIM
);
582 level
|= (s
->sssr
& SSSR_EOC
) && (s
->sssr
& (SSSR_TINT
| SSSR_PINT
));
583 level
|= (s
->sssr
& SSSR_TINT
) && (s
->sscr
[1] & SSCR1_TINTE
);
584 level
|= (s
->sssr
& SSSR_PINT
) && (s
->sscr
[1] & SSCR1_PINTE
);
585 level
|= (s
->sssr
& SSSR_ROR
) && !(s
->sscr
[0] & SSCR0_RIM
);
586 level
|= (s
->sssr
& SSSR_RFS
) && (s
->sscr
[1] & SSCR1_RIE
);
587 level
|= (s
->sssr
& SSSR_TFS
) && (s
->sscr
[1] & SSCR1_TIE
);
588 qemu_set_irq(s
->irq
, !!level
);
591 static void pxa2xx_ssp_fifo_update(PXA2xxSSPState
*s
)
593 s
->sssr
&= ~(0xf << 12); /* Clear RFL */
594 s
->sssr
&= ~(0xf << 8); /* Clear TFL */
595 s
->sssr
&= ~SSSR_TFS
;
596 s
->sssr
&= ~SSSR_TNF
;
598 s
->sssr
|= ((s
->rx_level
- 1) & 0xf) << 12;
599 if (s
->rx_level
>= SSCR1_RFT(s
->sscr
[1]))
602 s
->sssr
&= ~SSSR_RFS
;
606 s
->sssr
&= ~SSSR_RNE
;
607 /* TX FIFO is never filled, so it is always in underrun
608 condition if SSP is enabled */
613 pxa2xx_ssp_int_update(s
);
616 static uint64_t pxa2xx_ssp_read(void *opaque
, hwaddr addr
,
619 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
634 return s
->sssr
| s
->ssitr
;
638 if (s
->rx_level
< 1) {
639 printf("%s: SSP Rx Underrun\n", __func__
);
643 retval
= s
->rx_fifo
[s
->rx_start
++];
645 pxa2xx_ssp_fifo_update(s
);
656 qemu_log_mask(LOG_GUEST_ERROR
,
657 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
664 static void pxa2xx_ssp_write(void *opaque
, hwaddr addr
,
665 uint64_t value64
, unsigned size
)
667 PXA2xxSSPState
*s
= (PXA2xxSSPState
*) opaque
;
668 uint32_t value
= value64
;
672 s
->sscr
[0] = value
& 0xc7ffffff;
673 s
->enable
= value
& SSCR0_SSE
;
674 if (value
& SSCR0_MOD
)
675 printf("%s: Attempt to use network mode\n", __func__
);
676 if (s
->enable
&& SSCR0_DSS(value
) < 4)
677 printf("%s: Wrong data size: %i bits\n", __func__
,
679 if (!(value
& SSCR0_SSE
)) {
684 pxa2xx_ssp_fifo_update(s
);
689 if (value
& (SSCR1_LBM
| SSCR1_EFWR
))
690 printf("%s: Attempt to use SSP test mode\n", __func__
);
691 pxa2xx_ssp_fifo_update(s
);
703 s
->ssitr
= value
& SSITR_INT
;
704 pxa2xx_ssp_int_update(s
);
708 s
->sssr
&= ~(value
& SSSR_RW
);
709 pxa2xx_ssp_int_update(s
);
713 if (SSCR0_UWIRE(s
->sscr
[0])) {
714 if (s
->sscr
[1] & SSCR1_MWDS
)
719 /* Note how 32bits overflow does no harm here */
720 value
&= (1 << SSCR0_DSS(s
->sscr
[0])) - 1;
722 /* Data goes from here to the Tx FIFO and is shifted out from
723 * there directly to the slave, no need to buffer it.
727 readval
= ssi_transfer(s
->bus
, value
);
728 if (s
->rx_level
< 0x10) {
729 s
->rx_fifo
[(s
->rx_start
+ s
->rx_level
++) & 0xf] = readval
;
734 pxa2xx_ssp_fifo_update(s
);
750 qemu_log_mask(LOG_GUEST_ERROR
,
751 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
757 static const MemoryRegionOps pxa2xx_ssp_ops
= {
758 .read
= pxa2xx_ssp_read
,
759 .write
= pxa2xx_ssp_write
,
760 .endianness
= DEVICE_NATIVE_ENDIAN
,
763 static void pxa2xx_ssp_reset(DeviceState
*d
)
765 PXA2xxSSPState
*s
= PXA2XX_SSP(d
);
768 s
->sscr
[0] = s
->sscr
[1] = 0;
776 s
->rx_start
= s
->rx_level
= 0;
779 static void pxa2xx_ssp_init(Object
*obj
)
781 DeviceState
*dev
= DEVICE(obj
);
782 PXA2xxSSPState
*s
= PXA2XX_SSP(obj
);
783 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
784 sysbus_init_irq(sbd
, &s
->irq
);
786 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_ssp_ops
, s
,
787 "pxa2xx-ssp", 0x1000);
788 sysbus_init_mmio(sbd
, &s
->iomem
);
790 s
->bus
= ssi_create_bus(dev
, "ssi");
793 /* Real-Time Clock */
794 #define RCNR 0x00 /* RTC Counter register */
795 #define RTAR 0x04 /* RTC Alarm register */
796 #define RTSR 0x08 /* RTC Status register */
797 #define RTTR 0x0c /* RTC Timer Trim register */
798 #define RDCR 0x10 /* RTC Day Counter register */
799 #define RYCR 0x14 /* RTC Year Counter register */
800 #define RDAR1 0x18 /* RTC Wristwatch Day Alarm register 1 */
801 #define RYAR1 0x1c /* RTC Wristwatch Year Alarm register 1 */
802 #define RDAR2 0x20 /* RTC Wristwatch Day Alarm register 2 */
803 #define RYAR2 0x24 /* RTC Wristwatch Year Alarm register 2 */
804 #define SWCR 0x28 /* RTC Stopwatch Counter register */
805 #define SWAR1 0x2c /* RTC Stopwatch Alarm register 1 */
806 #define SWAR2 0x30 /* RTC Stopwatch Alarm register 2 */
807 #define RTCPICR 0x34 /* RTC Periodic Interrupt Counter register */
808 #define PIAR 0x38 /* RTC Periodic Interrupt Alarm register */
810 #define TYPE_PXA2XX_RTC "pxa2xx_rtc"
811 #define PXA2XX_RTC(obj) \
812 OBJECT_CHECK(PXA2xxRTCState, (obj), TYPE_PXA2XX_RTC)
816 SysBusDevice parent_obj
;
834 uint32_t last_rtcpicr
;
839 QEMUTimer
*rtc_rdal1
;
840 QEMUTimer
*rtc_rdal2
;
841 QEMUTimer
*rtc_swal1
;
842 QEMUTimer
*rtc_swal2
;
847 static inline void pxa2xx_rtc_int_update(PXA2xxRTCState
*s
)
849 qemu_set_irq(s
->rtc_irq
, !!(s
->rtsr
& 0x2553));
852 static void pxa2xx_rtc_hzupdate(PXA2xxRTCState
*s
)
854 int64_t rt
= qemu_clock_get_ms(rtc_clock
);
855 s
->last_rcnr
+= ((rt
- s
->last_hz
) << 15) /
856 (1000 * ((s
->rttr
& 0xffff) + 1));
857 s
->last_rdcr
+= ((rt
- s
->last_hz
) << 15) /
858 (1000 * ((s
->rttr
& 0xffff) + 1));
862 static void pxa2xx_rtc_swupdate(PXA2xxRTCState
*s
)
864 int64_t rt
= qemu_clock_get_ms(rtc_clock
);
865 if (s
->rtsr
& (1 << 12))
866 s
->last_swcr
+= (rt
- s
->last_sw
) / 10;
870 static void pxa2xx_rtc_piupdate(PXA2xxRTCState
*s
)
872 int64_t rt
= qemu_clock_get_ms(rtc_clock
);
873 if (s
->rtsr
& (1 << 15))
874 s
->last_swcr
+= rt
- s
->last_pi
;
878 static inline void pxa2xx_rtc_alarm_update(PXA2xxRTCState
*s
,
881 if ((rtsr
& (1 << 2)) && !(rtsr
& (1 << 0)))
882 timer_mod(s
->rtc_hz
, s
->last_hz
+
883 (((s
->rtar
- s
->last_rcnr
) * 1000 *
884 ((s
->rttr
& 0xffff) + 1)) >> 15));
886 timer_del(s
->rtc_hz
);
888 if ((rtsr
& (1 << 5)) && !(rtsr
& (1 << 4)))
889 timer_mod(s
->rtc_rdal1
, s
->last_hz
+
890 (((s
->rdar1
- s
->last_rdcr
) * 1000 *
891 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
893 timer_del(s
->rtc_rdal1
);
895 if ((rtsr
& (1 << 7)) && !(rtsr
& (1 << 6)))
896 timer_mod(s
->rtc_rdal2
, s
->last_hz
+
897 (((s
->rdar2
- s
->last_rdcr
) * 1000 *
898 ((s
->rttr
& 0xffff) + 1)) >> 15)); /* TODO: fixup */
900 timer_del(s
->rtc_rdal2
);
902 if ((rtsr
& 0x1200) == 0x1200 && !(rtsr
& (1 << 8)))
903 timer_mod(s
->rtc_swal1
, s
->last_sw
+
904 (s
->swar1
- s
->last_swcr
) * 10); /* TODO: fixup */
906 timer_del(s
->rtc_swal1
);
908 if ((rtsr
& 0x1800) == 0x1800 && !(rtsr
& (1 << 10)))
909 timer_mod(s
->rtc_swal2
, s
->last_sw
+
910 (s
->swar2
- s
->last_swcr
) * 10); /* TODO: fixup */
912 timer_del(s
->rtc_swal2
);
914 if ((rtsr
& 0xc000) == 0xc000 && !(rtsr
& (1 << 13)))
915 timer_mod(s
->rtc_pi
, s
->last_pi
+
916 (s
->piar
& 0xffff) - s
->last_rtcpicr
);
918 timer_del(s
->rtc_pi
);
921 static inline void pxa2xx_rtc_hz_tick(void *opaque
)
923 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
925 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
926 pxa2xx_rtc_int_update(s
);
929 static inline void pxa2xx_rtc_rdal1_tick(void *opaque
)
931 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
933 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
934 pxa2xx_rtc_int_update(s
);
937 static inline void pxa2xx_rtc_rdal2_tick(void *opaque
)
939 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
941 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
942 pxa2xx_rtc_int_update(s
);
945 static inline void pxa2xx_rtc_swal1_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_swal2_tick(void *opaque
)
955 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
956 s
->rtsr
|= (1 << 10);
957 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
958 pxa2xx_rtc_int_update(s
);
961 static inline void pxa2xx_rtc_pi_tick(void *opaque
)
963 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
964 s
->rtsr
|= (1 << 13);
965 pxa2xx_rtc_piupdate(s
);
967 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
968 pxa2xx_rtc_int_update(s
);
971 static uint64_t pxa2xx_rtc_read(void *opaque
, hwaddr addr
,
974 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
998 return s
->last_rcnr
+
999 ((qemu_clock_get_ms(rtc_clock
) - s
->last_hz
) << 15) /
1000 (1000 * ((s
->rttr
& 0xffff) + 1));
1002 return s
->last_rdcr
+
1003 ((qemu_clock_get_ms(rtc_clock
) - s
->last_hz
) << 15) /
1004 (1000 * ((s
->rttr
& 0xffff) + 1));
1006 return s
->last_rycr
;
1008 if (s
->rtsr
& (1 << 12))
1009 return s
->last_swcr
+
1010 (qemu_clock_get_ms(rtc_clock
) - s
->last_sw
) / 10;
1012 return s
->last_swcr
;
1014 qemu_log_mask(LOG_GUEST_ERROR
,
1015 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1022 static void pxa2xx_rtc_write(void *opaque
, hwaddr addr
,
1023 uint64_t value64
, unsigned size
)
1025 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1026 uint32_t value
= value64
;
1030 if (!(s
->rttr
& (1U << 31))) {
1031 pxa2xx_rtc_hzupdate(s
);
1033 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1038 if ((s
->rtsr
^ value
) & (1 << 15))
1039 pxa2xx_rtc_piupdate(s
);
1041 if ((s
->rtsr
^ value
) & (1 << 12))
1042 pxa2xx_rtc_swupdate(s
);
1044 if (((s
->rtsr
^ value
) & 0x4aac) | (value
& ~0xdaac))
1045 pxa2xx_rtc_alarm_update(s
, value
);
1047 s
->rtsr
= (value
& 0xdaac) | (s
->rtsr
& ~(value
& ~0xdaac));
1048 pxa2xx_rtc_int_update(s
);
1053 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1058 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1063 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1068 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1073 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1077 pxa2xx_rtc_swupdate(s
);
1080 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1085 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1090 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1094 pxa2xx_rtc_hzupdate(s
);
1095 s
->last_rcnr
= value
;
1096 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1100 pxa2xx_rtc_hzupdate(s
);
1101 s
->last_rdcr
= value
;
1102 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1106 s
->last_rycr
= value
;
1110 pxa2xx_rtc_swupdate(s
);
1111 s
->last_swcr
= value
;
1112 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1116 pxa2xx_rtc_piupdate(s
);
1117 s
->last_rtcpicr
= value
& 0xffff;
1118 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1122 qemu_log_mask(LOG_GUEST_ERROR
,
1123 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1128 static const MemoryRegionOps pxa2xx_rtc_ops
= {
1129 .read
= pxa2xx_rtc_read
,
1130 .write
= pxa2xx_rtc_write
,
1131 .endianness
= DEVICE_NATIVE_ENDIAN
,
1134 static void pxa2xx_rtc_init(Object
*obj
)
1136 PXA2xxRTCState
*s
= PXA2XX_RTC(obj
);
1137 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
1144 qemu_get_timedate(&tm
, 0);
1145 wom
= ((tm
.tm_mday
- 1) / 7) + 1;
1147 s
->last_rcnr
= (uint32_t) mktimegm(&tm
);
1148 s
->last_rdcr
= (wom
<< 20) | ((tm
.tm_wday
+ 1) << 17) |
1149 (tm
.tm_hour
<< 12) | (tm
.tm_min
<< 6) | tm
.tm_sec
;
1150 s
->last_rycr
= ((tm
.tm_year
+ 1900) << 9) |
1151 ((tm
.tm_mon
+ 1) << 5) | tm
.tm_mday
;
1152 s
->last_swcr
= (tm
.tm_hour
<< 19) |
1153 (tm
.tm_min
<< 13) | (tm
.tm_sec
<< 7);
1154 s
->last_rtcpicr
= 0;
1155 s
->last_hz
= s
->last_sw
= s
->last_pi
= qemu_clock_get_ms(rtc_clock
);
1157 sysbus_init_irq(dev
, &s
->rtc_irq
);
1159 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_rtc_ops
, s
,
1160 "pxa2xx-rtc", 0x10000);
1161 sysbus_init_mmio(dev
, &s
->iomem
);
1164 static void pxa2xx_rtc_realize(DeviceState
*dev
, Error
**errp
)
1166 PXA2xxRTCState
*s
= PXA2XX_RTC(dev
);
1167 s
->rtc_hz
= timer_new_ms(rtc_clock
, pxa2xx_rtc_hz_tick
, s
);
1168 s
->rtc_rdal1
= timer_new_ms(rtc_clock
, pxa2xx_rtc_rdal1_tick
, s
);
1169 s
->rtc_rdal2
= timer_new_ms(rtc_clock
, pxa2xx_rtc_rdal2_tick
, s
);
1170 s
->rtc_swal1
= timer_new_ms(rtc_clock
, pxa2xx_rtc_swal1_tick
, s
);
1171 s
->rtc_swal2
= timer_new_ms(rtc_clock
, pxa2xx_rtc_swal2_tick
, s
);
1172 s
->rtc_pi
= timer_new_ms(rtc_clock
, pxa2xx_rtc_pi_tick
, s
);
1175 static int pxa2xx_rtc_pre_save(void *opaque
)
1177 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1179 pxa2xx_rtc_hzupdate(s
);
1180 pxa2xx_rtc_piupdate(s
);
1181 pxa2xx_rtc_swupdate(s
);
1186 static int pxa2xx_rtc_post_load(void *opaque
, int version_id
)
1188 PXA2xxRTCState
*s
= (PXA2xxRTCState
*) opaque
;
1190 pxa2xx_rtc_alarm_update(s
, s
->rtsr
);
1195 static const VMStateDescription vmstate_pxa2xx_rtc_regs
= {
1196 .name
= "pxa2xx_rtc",
1198 .minimum_version_id
= 0,
1199 .pre_save
= pxa2xx_rtc_pre_save
,
1200 .post_load
= pxa2xx_rtc_post_load
,
1201 .fields
= (VMStateField
[]) {
1202 VMSTATE_UINT32(rttr
, PXA2xxRTCState
),
1203 VMSTATE_UINT32(rtsr
, PXA2xxRTCState
),
1204 VMSTATE_UINT32(rtar
, PXA2xxRTCState
),
1205 VMSTATE_UINT32(rdar1
, PXA2xxRTCState
),
1206 VMSTATE_UINT32(rdar2
, PXA2xxRTCState
),
1207 VMSTATE_UINT32(ryar1
, PXA2xxRTCState
),
1208 VMSTATE_UINT32(ryar2
, PXA2xxRTCState
),
1209 VMSTATE_UINT32(swar1
, PXA2xxRTCState
),
1210 VMSTATE_UINT32(swar2
, PXA2xxRTCState
),
1211 VMSTATE_UINT32(piar
, PXA2xxRTCState
),
1212 VMSTATE_UINT32(last_rcnr
, PXA2xxRTCState
),
1213 VMSTATE_UINT32(last_rdcr
, PXA2xxRTCState
),
1214 VMSTATE_UINT32(last_rycr
, PXA2xxRTCState
),
1215 VMSTATE_UINT32(last_swcr
, PXA2xxRTCState
),
1216 VMSTATE_UINT32(last_rtcpicr
, PXA2xxRTCState
),
1217 VMSTATE_INT64(last_hz
, PXA2xxRTCState
),
1218 VMSTATE_INT64(last_sw
, PXA2xxRTCState
),
1219 VMSTATE_INT64(last_pi
, PXA2xxRTCState
),
1220 VMSTATE_END_OF_LIST(),
1224 static void pxa2xx_rtc_sysbus_class_init(ObjectClass
*klass
, void *data
)
1226 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1228 dc
->desc
= "PXA2xx RTC Controller";
1229 dc
->vmsd
= &vmstate_pxa2xx_rtc_regs
;
1230 dc
->realize
= pxa2xx_rtc_realize
;
1233 static const TypeInfo pxa2xx_rtc_sysbus_info
= {
1234 .name
= TYPE_PXA2XX_RTC
,
1235 .parent
= TYPE_SYS_BUS_DEVICE
,
1236 .instance_size
= sizeof(PXA2xxRTCState
),
1237 .instance_init
= pxa2xx_rtc_init
,
1238 .class_init
= pxa2xx_rtc_sysbus_class_init
,
1243 #define TYPE_PXA2XX_I2C_SLAVE "pxa2xx-i2c-slave"
1244 #define PXA2XX_I2C_SLAVE(obj) \
1245 OBJECT_CHECK(PXA2xxI2CSlaveState, (obj), TYPE_PXA2XX_I2C_SLAVE)
1247 typedef struct PXA2xxI2CSlaveState
{
1248 I2CSlave parent_obj
;
1250 PXA2xxI2CState
*host
;
1251 } PXA2xxI2CSlaveState
;
1253 #define TYPE_PXA2XX_I2C "pxa2xx_i2c"
1254 #define PXA2XX_I2C(obj) \
1255 OBJECT_CHECK(PXA2xxI2CState, (obj), TYPE_PXA2XX_I2C)
1257 struct PXA2xxI2CState
{
1259 SysBusDevice parent_obj
;
1263 PXA2xxI2CSlaveState
*slave
;
1267 uint32_t region_size
;
1275 #define IBMR 0x80 /* I2C Bus Monitor register */
1276 #define IDBR 0x88 /* I2C Data Buffer register */
1277 #define ICR 0x90 /* I2C Control register */
1278 #define ISR 0x98 /* I2C Status register */
1279 #define ISAR 0xa0 /* I2C Slave Address register */
1281 static void pxa2xx_i2c_update(PXA2xxI2CState
*s
)
1284 level
|= s
->status
& s
->control
& (1 << 10); /* BED */
1285 level
|= (s
->status
& (1 << 7)) && (s
->control
& (1 << 9)); /* IRF */
1286 level
|= (s
->status
& (1 << 6)) && (s
->control
& (1 << 8)); /* ITE */
1287 level
|= s
->status
& (1 << 9); /* SAD */
1288 qemu_set_irq(s
->irq
, !!level
);
1291 /* These are only stubs now. */
1292 static int pxa2xx_i2c_event(I2CSlave
*i2c
, enum i2c_event event
)
1294 PXA2xxI2CSlaveState
*slave
= PXA2XX_I2C_SLAVE(i2c
);
1295 PXA2xxI2CState
*s
= slave
->host
;
1298 case I2C_START_SEND
:
1299 s
->status
|= (1 << 9); /* set SAD */
1300 s
->status
&= ~(1 << 0); /* clear RWM */
1302 case I2C_START_RECV
:
1303 s
->status
|= (1 << 9); /* set SAD */
1304 s
->status
|= 1 << 0; /* set RWM */
1307 s
->status
|= (1 << 4); /* set SSD */
1310 s
->status
|= 1 << 1; /* set ACKNAK */
1313 pxa2xx_i2c_update(s
);
1318 static uint8_t pxa2xx_i2c_rx(I2CSlave
*i2c
)
1320 PXA2xxI2CSlaveState
*slave
= PXA2XX_I2C_SLAVE(i2c
);
1321 PXA2xxI2CState
*s
= slave
->host
;
1323 if ((s
->control
& (1 << 14)) || !(s
->control
& (1 << 6))) {
1327 if (s
->status
& (1 << 0)) { /* RWM */
1328 s
->status
|= 1 << 6; /* set ITE */
1330 pxa2xx_i2c_update(s
);
1335 static int pxa2xx_i2c_tx(I2CSlave
*i2c
, uint8_t data
)
1337 PXA2xxI2CSlaveState
*slave
= PXA2XX_I2C_SLAVE(i2c
);
1338 PXA2xxI2CState
*s
= slave
->host
;
1340 if ((s
->control
& (1 << 14)) || !(s
->control
& (1 << 6))) {
1344 if (!(s
->status
& (1 << 0))) { /* RWM */
1345 s
->status
|= 1 << 7; /* set IRF */
1348 pxa2xx_i2c_update(s
);
1353 static uint64_t pxa2xx_i2c_read(void *opaque
, hwaddr addr
,
1356 PXA2xxI2CState
*s
= (PXA2xxI2CState
*) opaque
;
1364 return s
->status
| (i2c_bus_busy(s
->bus
) << 2);
1366 slave
= I2C_SLAVE(s
->slave
);
1367 return slave
->address
;
1371 if (s
->status
& (1 << 2))
1372 s
->ibmr
^= 3; /* Fake SCL and SDA pin changes */
1377 qemu_log_mask(LOG_GUEST_ERROR
,
1378 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1385 static void pxa2xx_i2c_write(void *opaque
, hwaddr addr
,
1386 uint64_t value64
, unsigned size
)
1388 PXA2xxI2CState
*s
= (PXA2xxI2CState
*) opaque
;
1389 uint32_t value
= value64
;
1395 s
->control
= value
& 0xfff7;
1396 if ((value
& (1 << 3)) && (value
& (1 << 6))) { /* TB and IUE */
1397 /* TODO: slave mode */
1398 if (value
& (1 << 0)) { /* START condition */
1400 s
->status
|= 1 << 0; /* set RWM */
1402 s
->status
&= ~(1 << 0); /* clear RWM */
1403 ack
= !i2c_start_transfer(s
->bus
, s
->data
>> 1, s
->data
& 1);
1405 if (s
->status
& (1 << 0)) { /* RWM */
1406 s
->data
= i2c_recv(s
->bus
);
1407 if (value
& (1 << 2)) /* ACKNAK */
1411 ack
= !i2c_send(s
->bus
, s
->data
);
1414 if (value
& (1 << 1)) /* STOP condition */
1415 i2c_end_transfer(s
->bus
);
1418 if (value
& (1 << 0)) /* START condition */
1419 s
->status
|= 1 << 6; /* set ITE */
1421 if (s
->status
& (1 << 0)) /* RWM */
1422 s
->status
|= 1 << 7; /* set IRF */
1424 s
->status
|= 1 << 6; /* set ITE */
1425 s
->status
&= ~(1 << 1); /* clear ACKNAK */
1427 s
->status
|= 1 << 6; /* set ITE */
1428 s
->status
|= 1 << 10; /* set BED */
1429 s
->status
|= 1 << 1; /* set ACKNAK */
1432 if (!(value
& (1 << 3)) && (value
& (1 << 6))) /* !TB and IUE */
1433 if (value
& (1 << 4)) /* MA */
1434 i2c_end_transfer(s
->bus
);
1435 pxa2xx_i2c_update(s
);
1439 s
->status
&= ~(value
& 0x07f0);
1440 pxa2xx_i2c_update(s
);
1444 i2c_set_slave_address(I2C_SLAVE(s
->slave
), value
& 0x7f);
1448 s
->data
= value
& 0xff;
1452 qemu_log_mask(LOG_GUEST_ERROR
,
1453 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1458 static const MemoryRegionOps pxa2xx_i2c_ops
= {
1459 .read
= pxa2xx_i2c_read
,
1460 .write
= pxa2xx_i2c_write
,
1461 .endianness
= DEVICE_NATIVE_ENDIAN
,
1464 static const VMStateDescription vmstate_pxa2xx_i2c_slave
= {
1465 .name
= "pxa2xx_i2c_slave",
1467 .minimum_version_id
= 1,
1468 .fields
= (VMStateField
[]) {
1469 VMSTATE_I2C_SLAVE(parent_obj
, PXA2xxI2CSlaveState
),
1470 VMSTATE_END_OF_LIST()
1474 static const VMStateDescription vmstate_pxa2xx_i2c
= {
1475 .name
= "pxa2xx_i2c",
1477 .minimum_version_id
= 1,
1478 .fields
= (VMStateField
[]) {
1479 VMSTATE_UINT16(control
, PXA2xxI2CState
),
1480 VMSTATE_UINT16(status
, PXA2xxI2CState
),
1481 VMSTATE_UINT8(ibmr
, PXA2xxI2CState
),
1482 VMSTATE_UINT8(data
, PXA2xxI2CState
),
1483 VMSTATE_STRUCT_POINTER(slave
, PXA2xxI2CState
,
1484 vmstate_pxa2xx_i2c_slave
, PXA2xxI2CSlaveState
),
1485 VMSTATE_END_OF_LIST()
1489 static void pxa2xx_i2c_slave_class_init(ObjectClass
*klass
, void *data
)
1491 I2CSlaveClass
*k
= I2C_SLAVE_CLASS(klass
);
1493 k
->event
= pxa2xx_i2c_event
;
1494 k
->recv
= pxa2xx_i2c_rx
;
1495 k
->send
= pxa2xx_i2c_tx
;
1498 static const TypeInfo pxa2xx_i2c_slave_info
= {
1499 .name
= TYPE_PXA2XX_I2C_SLAVE
,
1500 .parent
= TYPE_I2C_SLAVE
,
1501 .instance_size
= sizeof(PXA2xxI2CSlaveState
),
1502 .class_init
= pxa2xx_i2c_slave_class_init
,
1505 PXA2xxI2CState
*pxa2xx_i2c_init(hwaddr base
,
1506 qemu_irq irq
, uint32_t region_size
)
1509 SysBusDevice
*i2c_dev
;
1513 dev
= qdev_new(TYPE_PXA2XX_I2C
);
1514 qdev_prop_set_uint32(dev
, "size", region_size
+ 1);
1515 qdev_prop_set_uint32(dev
, "offset", base
& region_size
);
1517 i2c_dev
= SYS_BUS_DEVICE(dev
);
1518 sysbus_realize_and_unref(i2c_dev
, &error_fatal
);
1519 sysbus_mmio_map(i2c_dev
, 0, base
& ~region_size
);
1520 sysbus_connect_irq(i2c_dev
, 0, irq
);
1522 s
= PXA2XX_I2C(i2c_dev
);
1523 /* FIXME: Should the slave device really be on a separate bus? */
1524 i2cbus
= i2c_init_bus(dev
, "dummy");
1525 s
->slave
= PXA2XX_I2C_SLAVE(i2c_slave_create_simple(i2cbus
,
1526 TYPE_PXA2XX_I2C_SLAVE
,
1533 static void pxa2xx_i2c_initfn(Object
*obj
)
1535 DeviceState
*dev
= DEVICE(obj
);
1536 PXA2xxI2CState
*s
= PXA2XX_I2C(obj
);
1537 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
1539 s
->bus
= i2c_init_bus(dev
, NULL
);
1541 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_i2c_ops
, s
,
1542 "pxa2xx-i2c", s
->region_size
);
1543 sysbus_init_mmio(sbd
, &s
->iomem
);
1544 sysbus_init_irq(sbd
, &s
->irq
);
1547 I2CBus
*pxa2xx_i2c_bus(PXA2xxI2CState
*s
)
1552 static Property pxa2xx_i2c_properties
[] = {
1553 DEFINE_PROP_UINT32("size", PXA2xxI2CState
, region_size
, 0x10000),
1554 DEFINE_PROP_UINT32("offset", PXA2xxI2CState
, offset
, 0),
1555 DEFINE_PROP_END_OF_LIST(),
1558 static void pxa2xx_i2c_class_init(ObjectClass
*klass
, void *data
)
1560 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1562 dc
->desc
= "PXA2xx I2C Bus Controller";
1563 dc
->vmsd
= &vmstate_pxa2xx_i2c
;
1564 device_class_set_props(dc
, pxa2xx_i2c_properties
);
1567 static const TypeInfo pxa2xx_i2c_info
= {
1568 .name
= TYPE_PXA2XX_I2C
,
1569 .parent
= TYPE_SYS_BUS_DEVICE
,
1570 .instance_size
= sizeof(PXA2xxI2CState
),
1571 .instance_init
= pxa2xx_i2c_initfn
,
1572 .class_init
= pxa2xx_i2c_class_init
,
1575 /* PXA Inter-IC Sound Controller */
1576 static void pxa2xx_i2s_reset(PXA2xxI2SState
*i2s
)
1582 i2s
->control
[0] = 0x00;
1583 i2s
->control
[1] = 0x00;
1588 #define SACR_TFTH(val) ((val >> 8) & 0xf)
1589 #define SACR_RFTH(val) ((val >> 12) & 0xf)
1590 #define SACR_DREC(val) (val & (1 << 3))
1591 #define SACR_DPRL(val) (val & (1 << 4))
1593 static inline void pxa2xx_i2s_update(PXA2xxI2SState
*i2s
)
1596 rfs
= SACR_RFTH(i2s
->control
[0]) < i2s
->rx_len
&&
1597 !SACR_DREC(i2s
->control
[1]);
1598 tfs
= (i2s
->tx_len
|| i2s
->fifo_len
< SACR_TFTH(i2s
->control
[0])) &&
1599 i2s
->enable
&& !SACR_DPRL(i2s
->control
[1]);
1601 qemu_set_irq(i2s
->rx_dma
, rfs
);
1602 qemu_set_irq(i2s
->tx_dma
, tfs
);
1604 i2s
->status
&= 0xe0;
1605 if (i2s
->fifo_len
< 16 || !i2s
->enable
)
1606 i2s
->status
|= 1 << 0; /* TNF */
1608 i2s
->status
|= 1 << 1; /* RNE */
1610 i2s
->status
|= 1 << 2; /* BSY */
1612 i2s
->status
|= 1 << 3; /* TFS */
1614 i2s
->status
|= 1 << 4; /* RFS */
1615 if (!(i2s
->tx_len
&& i2s
->enable
))
1616 i2s
->status
|= i2s
->fifo_len
<< 8; /* TFL */
1617 i2s
->status
|= MAX(i2s
->rx_len
, 0xf) << 12; /* RFL */
1619 qemu_set_irq(i2s
->irq
, i2s
->status
& i2s
->mask
);
1622 #define SACR0 0x00 /* Serial Audio Global Control register */
1623 #define SACR1 0x04 /* Serial Audio I2S/MSB-Justified Control register */
1624 #define SASR0 0x0c /* Serial Audio Interface and FIFO Status register */
1625 #define SAIMR 0x14 /* Serial Audio Interrupt Mask register */
1626 #define SAICR 0x18 /* Serial Audio Interrupt Clear register */
1627 #define SADIV 0x60 /* Serial Audio Clock Divider register */
1628 #define SADR 0x80 /* Serial Audio Data register */
1630 static uint64_t pxa2xx_i2s_read(void *opaque
, hwaddr addr
,
1633 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1637 return s
->control
[0];
1639 return s
->control
[1];
1649 if (s
->rx_len
> 0) {
1651 pxa2xx_i2s_update(s
);
1652 return s
->codec_in(s
->opaque
);
1656 qemu_log_mask(LOG_GUEST_ERROR
,
1657 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1664 static void pxa2xx_i2s_write(void *opaque
, hwaddr addr
,
1665 uint64_t value
, unsigned size
)
1667 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1672 if (value
& (1 << 3)) /* RST */
1673 pxa2xx_i2s_reset(s
);
1674 s
->control
[0] = value
& 0xff3d;
1675 if (!s
->enable
&& (value
& 1) && s
->tx_len
) { /* ENB */
1676 for (sample
= s
->fifo
; s
->fifo_len
> 0; s
->fifo_len
--, sample
++)
1677 s
->codec_out(s
->opaque
, *sample
);
1678 s
->status
&= ~(1 << 7); /* I2SOFF */
1680 if (value
& (1 << 4)) /* EFWR */
1681 printf("%s: Attempt to use special function\n", __func__
);
1682 s
->enable
= (value
& 9) == 1; /* ENB && !RST*/
1683 pxa2xx_i2s_update(s
);
1686 s
->control
[1] = value
& 0x0039;
1687 if (value
& (1 << 5)) /* ENLBF */
1688 printf("%s: Attempt to use loopback function\n", __func__
);
1689 if (value
& (1 << 4)) /* DPRL */
1691 pxa2xx_i2s_update(s
);
1694 s
->mask
= value
& 0x0078;
1695 pxa2xx_i2s_update(s
);
1698 s
->status
&= ~(value
& (3 << 5));
1699 pxa2xx_i2s_update(s
);
1702 s
->clk
= value
& 0x007f;
1705 if (s
->tx_len
&& s
->enable
) {
1707 pxa2xx_i2s_update(s
);
1708 s
->codec_out(s
->opaque
, value
);
1709 } else if (s
->fifo_len
< 16) {
1710 s
->fifo
[s
->fifo_len
++] = value
;
1711 pxa2xx_i2s_update(s
);
1715 qemu_log_mask(LOG_GUEST_ERROR
,
1716 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1721 static const MemoryRegionOps pxa2xx_i2s_ops
= {
1722 .read
= pxa2xx_i2s_read
,
1723 .write
= pxa2xx_i2s_write
,
1724 .endianness
= DEVICE_NATIVE_ENDIAN
,
1727 static const VMStateDescription vmstate_pxa2xx_i2s
= {
1728 .name
= "pxa2xx_i2s",
1730 .minimum_version_id
= 0,
1731 .fields
= (VMStateField
[]) {
1732 VMSTATE_UINT32_ARRAY(control
, PXA2xxI2SState
, 2),
1733 VMSTATE_UINT32(status
, PXA2xxI2SState
),
1734 VMSTATE_UINT32(mask
, PXA2xxI2SState
),
1735 VMSTATE_UINT32(clk
, PXA2xxI2SState
),
1736 VMSTATE_INT32(enable
, PXA2xxI2SState
),
1737 VMSTATE_INT32(rx_len
, PXA2xxI2SState
),
1738 VMSTATE_INT32(tx_len
, PXA2xxI2SState
),
1739 VMSTATE_INT32(fifo_len
, PXA2xxI2SState
),
1740 VMSTATE_END_OF_LIST()
1744 static void pxa2xx_i2s_data_req(void *opaque
, int tx
, int rx
)
1746 PXA2xxI2SState
*s
= (PXA2xxI2SState
*) opaque
;
1749 /* Signal FIFO errors */
1750 if (s
->enable
&& s
->tx_len
)
1751 s
->status
|= 1 << 5; /* TUR */
1752 if (s
->enable
&& s
->rx_len
)
1753 s
->status
|= 1 << 6; /* ROR */
1755 /* Should be tx - MIN(tx, s->fifo_len) but we don't really need to
1756 * handle the cases where it makes a difference. */
1757 s
->tx_len
= tx
- s
->fifo_len
;
1759 /* Note that is s->codec_out wasn't set, we wouldn't get called. */
1761 for (sample
= s
->fifo
; s
->fifo_len
; s
->fifo_len
--, sample
++)
1762 s
->codec_out(s
->opaque
, *sample
);
1763 pxa2xx_i2s_update(s
);
1766 static PXA2xxI2SState
*pxa2xx_i2s_init(MemoryRegion
*sysmem
,
1768 qemu_irq irq
, qemu_irq rx_dma
, qemu_irq tx_dma
)
1770 PXA2xxI2SState
*s
= g_new0(PXA2xxI2SState
, 1);
1775 s
->data_req
= pxa2xx_i2s_data_req
;
1777 pxa2xx_i2s_reset(s
);
1779 memory_region_init_io(&s
->iomem
, NULL
, &pxa2xx_i2s_ops
, s
,
1780 "pxa2xx-i2s", 0x100000);
1781 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
1783 vmstate_register(NULL
, base
, &vmstate_pxa2xx_i2s
, s
);
1788 /* PXA Fast Infra-red Communications Port */
1789 #define TYPE_PXA2XX_FIR "pxa2xx-fir"
1790 #define PXA2XX_FIR(obj) OBJECT_CHECK(PXA2xxFIrState, (obj), TYPE_PXA2XX_FIR)
1792 struct PXA2xxFIrState
{
1794 SysBusDevice parent_obj
;
1809 uint8_t rx_fifo
[64];
1812 static void pxa2xx_fir_reset(DeviceState
*d
)
1814 PXA2xxFIrState
*s
= PXA2XX_FIR(d
);
1816 s
->control
[0] = 0x00;
1817 s
->control
[1] = 0x00;
1818 s
->control
[2] = 0x00;
1819 s
->status
[0] = 0x00;
1820 s
->status
[1] = 0x00;
1824 static inline void pxa2xx_fir_update(PXA2xxFIrState
*s
)
1826 static const int tresh
[4] = { 8, 16, 32, 0 };
1828 if ((s
->control
[0] & (1 << 4)) && /* RXE */
1829 s
->rx_len
>= tresh
[s
->control
[2] & 3]) /* TRIG */
1830 s
->status
[0] |= 1 << 4; /* RFS */
1832 s
->status
[0] &= ~(1 << 4); /* RFS */
1833 if (s
->control
[0] & (1 << 3)) /* TXE */
1834 s
->status
[0] |= 1 << 3; /* TFS */
1836 s
->status
[0] &= ~(1 << 3); /* TFS */
1838 s
->status
[1] |= 1 << 2; /* RNE */
1840 s
->status
[1] &= ~(1 << 2); /* RNE */
1841 if (s
->control
[0] & (1 << 4)) /* RXE */
1842 s
->status
[1] |= 1 << 0; /* RSY */
1844 s
->status
[1] &= ~(1 << 0); /* RSY */
1846 intr
|= (s
->control
[0] & (1 << 5)) && /* RIE */
1847 (s
->status
[0] & (1 << 4)); /* RFS */
1848 intr
|= (s
->control
[0] & (1 << 6)) && /* TIE */
1849 (s
->status
[0] & (1 << 3)); /* TFS */
1850 intr
|= (s
->control
[2] & (1 << 4)) && /* TRAIL */
1851 (s
->status
[0] & (1 << 6)); /* EOC */
1852 intr
|= (s
->control
[0] & (1 << 2)) && /* TUS */
1853 (s
->status
[0] & (1 << 1)); /* TUR */
1854 intr
|= s
->status
[0] & 0x25; /* FRE, RAB, EIF */
1856 qemu_set_irq(s
->rx_dma
, (s
->status
[0] >> 4) & 1);
1857 qemu_set_irq(s
->tx_dma
, (s
->status
[0] >> 3) & 1);
1859 qemu_set_irq(s
->irq
, intr
&& s
->enable
);
1862 #define ICCR0 0x00 /* FICP Control register 0 */
1863 #define ICCR1 0x04 /* FICP Control register 1 */
1864 #define ICCR2 0x08 /* FICP Control register 2 */
1865 #define ICDR 0x0c /* FICP Data register */
1866 #define ICSR0 0x14 /* FICP Status register 0 */
1867 #define ICSR1 0x18 /* FICP Status register 1 */
1868 #define ICFOR 0x1c /* FICP FIFO Occupancy Status register */
1870 static uint64_t pxa2xx_fir_read(void *opaque
, hwaddr addr
,
1873 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1878 return s
->control
[0];
1880 return s
->control
[1];
1882 return s
->control
[2];
1884 s
->status
[0] &= ~0x01;
1885 s
->status
[1] &= ~0x72;
1888 ret
= s
->rx_fifo
[s
->rx_start
++];
1890 pxa2xx_fir_update(s
);
1893 printf("%s: Rx FIFO underrun.\n", __func__
);
1896 return s
->status
[0];
1898 return s
->status
[1] | (1 << 3); /* TNF */
1902 qemu_log_mask(LOG_GUEST_ERROR
,
1903 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
1910 static void pxa2xx_fir_write(void *opaque
, hwaddr addr
,
1911 uint64_t value64
, unsigned size
)
1913 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1914 uint32_t value
= value64
;
1919 s
->control
[0] = value
;
1920 if (!(value
& (1 << 4))) /* RXE */
1921 s
->rx_len
= s
->rx_start
= 0;
1922 if (!(value
& (1 << 3))) { /* TXE */
1925 s
->enable
= value
& 1; /* ITR */
1928 pxa2xx_fir_update(s
);
1931 s
->control
[1] = value
;
1934 s
->control
[2] = value
& 0x3f;
1935 pxa2xx_fir_update(s
);
1938 if (s
->control
[2] & (1 << 2)) { /* TXP */
1943 if (s
->enable
&& (s
->control
[0] & (1 << 3))) { /* TXE */
1944 /* XXX this blocks entire thread. Rewrite to use
1945 * qemu_chr_fe_write and background I/O callbacks */
1946 qemu_chr_fe_write_all(&s
->chr
, &ch
, 1);
1950 s
->status
[0] &= ~(value
& 0x66);
1951 pxa2xx_fir_update(s
);
1956 qemu_log_mask(LOG_GUEST_ERROR
,
1957 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
1962 static const MemoryRegionOps pxa2xx_fir_ops
= {
1963 .read
= pxa2xx_fir_read
,
1964 .write
= pxa2xx_fir_write
,
1965 .endianness
= DEVICE_NATIVE_ENDIAN
,
1968 static int pxa2xx_fir_is_empty(void *opaque
)
1970 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1971 return (s
->rx_len
< 64);
1974 static void pxa2xx_fir_rx(void *opaque
, const uint8_t *buf
, int size
)
1976 PXA2xxFIrState
*s
= (PXA2xxFIrState
*) opaque
;
1977 if (!(s
->control
[0] & (1 << 4))) /* RXE */
1981 s
->status
[1] |= 1 << 4; /* EOF */
1982 if (s
->rx_len
>= 64) {
1983 s
->status
[1] |= 1 << 6; /* ROR */
1987 if (s
->control
[2] & (1 << 3)) /* RXP */
1988 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = *(buf
++);
1990 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
++) & 63] = ~*(buf
++);
1993 pxa2xx_fir_update(s
);
1996 static void pxa2xx_fir_event(void *opaque
, QEMUChrEvent event
)
2000 static void pxa2xx_fir_instance_init(Object
*obj
)
2002 PXA2xxFIrState
*s
= PXA2XX_FIR(obj
);
2003 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
2005 memory_region_init_io(&s
->iomem
, obj
, &pxa2xx_fir_ops
, s
,
2006 "pxa2xx-fir", 0x1000);
2007 sysbus_init_mmio(sbd
, &s
->iomem
);
2008 sysbus_init_irq(sbd
, &s
->irq
);
2009 sysbus_init_irq(sbd
, &s
->rx_dma
);
2010 sysbus_init_irq(sbd
, &s
->tx_dma
);
2013 static void pxa2xx_fir_realize(DeviceState
*dev
, Error
**errp
)
2015 PXA2xxFIrState
*s
= PXA2XX_FIR(dev
);
2017 qemu_chr_fe_set_handlers(&s
->chr
, pxa2xx_fir_is_empty
,
2018 pxa2xx_fir_rx
, pxa2xx_fir_event
, NULL
, s
, NULL
,
2022 static bool pxa2xx_fir_vmstate_validate(void *opaque
, int version_id
)
2024 PXA2xxFIrState
*s
= opaque
;
2026 return s
->rx_start
< ARRAY_SIZE(s
->rx_fifo
);
2029 static const VMStateDescription pxa2xx_fir_vmsd
= {
2030 .name
= "pxa2xx-fir",
2032 .minimum_version_id
= 1,
2033 .fields
= (VMStateField
[]) {
2034 VMSTATE_UINT32(enable
, PXA2xxFIrState
),
2035 VMSTATE_UINT8_ARRAY(control
, PXA2xxFIrState
, 3),
2036 VMSTATE_UINT8_ARRAY(status
, PXA2xxFIrState
, 2),
2037 VMSTATE_UINT32(rx_len
, PXA2xxFIrState
),
2038 VMSTATE_UINT32(rx_start
, PXA2xxFIrState
),
2039 VMSTATE_VALIDATE("fifo is 64 bytes", pxa2xx_fir_vmstate_validate
),
2040 VMSTATE_UINT8_ARRAY(rx_fifo
, PXA2xxFIrState
, 64),
2041 VMSTATE_END_OF_LIST()
2045 static Property pxa2xx_fir_properties
[] = {
2046 DEFINE_PROP_CHR("chardev", PXA2xxFIrState
, chr
),
2047 DEFINE_PROP_END_OF_LIST(),
2050 static void pxa2xx_fir_class_init(ObjectClass
*klass
, void *data
)
2052 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2054 dc
->realize
= pxa2xx_fir_realize
;
2055 dc
->vmsd
= &pxa2xx_fir_vmsd
;
2056 device_class_set_props(dc
, pxa2xx_fir_properties
);
2057 dc
->reset
= pxa2xx_fir_reset
;
2060 static const TypeInfo pxa2xx_fir_info
= {
2061 .name
= TYPE_PXA2XX_FIR
,
2062 .parent
= TYPE_SYS_BUS_DEVICE
,
2063 .instance_size
= sizeof(PXA2xxFIrState
),
2064 .class_init
= pxa2xx_fir_class_init
,
2065 .instance_init
= pxa2xx_fir_instance_init
,
2068 static PXA2xxFIrState
*pxa2xx_fir_init(MemoryRegion
*sysmem
,
2070 qemu_irq irq
, qemu_irq rx_dma
,
2077 dev
= qdev_new(TYPE_PXA2XX_FIR
);
2078 qdev_prop_set_chr(dev
, "chardev", chr
);
2079 sbd
= SYS_BUS_DEVICE(dev
);
2080 sysbus_realize_and_unref(sbd
, &error_fatal
);
2081 sysbus_mmio_map(sbd
, 0, base
);
2082 sysbus_connect_irq(sbd
, 0, irq
);
2083 sysbus_connect_irq(sbd
, 1, rx_dma
);
2084 sysbus_connect_irq(sbd
, 2, tx_dma
);
2085 return PXA2XX_FIR(dev
);
2088 static void pxa2xx_reset(void *opaque
, int line
, int level
)
2090 PXA2xxState
*s
= (PXA2xxState
*) opaque
;
2092 if (level
&& (s
->pm_regs
[PCFR
>> 2] & 0x10)) { /* GPR_EN */
2093 cpu_reset(CPU(s
->cpu
));
2094 /* TODO: reset peripherals */
2098 /* Initialise a PXA270 integrated chip (ARM based core). */
2099 PXA2xxState
*pxa270_init(MemoryRegion
*address_space
,
2100 unsigned int sdram_size
, const char *cpu_type
)
2105 s
= g_new0(PXA2xxState
, 1);
2107 if (strncmp(cpu_type
, "pxa27", 5)) {
2108 error_report("Machine requires a PXA27x processor");
2112 s
->cpu
= ARM_CPU(cpu_create(cpu_type
));
2113 s
->reset
= qemu_allocate_irq(pxa2xx_reset
, s
, 0);
2115 /* SDRAM & Internal Memory Storage */
2116 memory_region_init_ram(&s
->sdram
, NULL
, "pxa270.sdram", sdram_size
,
2118 memory_region_add_subregion(address_space
, PXA2XX_SDRAM_BASE
, &s
->sdram
);
2119 memory_region_init_ram(&s
->internal
, NULL
, "pxa270.internal", 0x40000,
2121 memory_region_add_subregion(address_space
, PXA2XX_INTERNAL_BASE
,
2124 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->cpu
);
2126 s
->dma
= pxa27x_dma_init(0x40000000,
2127 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_DMA
));
2129 sysbus_create_varargs("pxa27x-timer", 0x40a00000,
2130 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 0),
2131 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 1),
2132 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 2),
2133 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 3),
2134 qdev_get_gpio_in(s
->pic
, PXA27X_PIC_OST_4_11
),
2137 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->cpu
, s
->pic
, 121);
2139 dinfo
= drive_get(IF_SD
, 0, 0);
2140 if (!dinfo
&& !qtest_enabled()) {
2141 warn_report("missing SecureDigital device");
2143 s
->mmc
= pxa2xx_mmci_init(address_space
, 0x41100000,
2144 dinfo
? blk_by_legacy_dinfo(dinfo
) : NULL
,
2145 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_MMC
),
2146 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_MMCI
),
2147 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_MMCI
));
2149 for (i
= 0; pxa270_serial
[i
].io_base
; i
++) {
2151 serial_mm_init(address_space
, pxa270_serial
[i
].io_base
, 2,
2152 qdev_get_gpio_in(s
->pic
, pxa270_serial
[i
].irqn
),
2153 14857000 / 16, serial_hd(i
),
2154 DEVICE_NATIVE_ENDIAN
);
2160 s
->fir
= pxa2xx_fir_init(address_space
, 0x40800000,
2161 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_ICP
),
2162 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_ICP
),
2163 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_ICP
),
2166 s
->lcd
= pxa2xx_lcdc_init(address_space
, 0x44000000,
2167 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_LCD
));
2169 s
->cm_base
= 0x41300000;
2170 s
->cm_regs
[CCCR
>> 2] = 0x02000210; /* 416.0 MHz */
2171 s
->clkcfg
= 0x00000009; /* Turbo mode active */
2172 memory_region_init_io(&s
->cm_iomem
, NULL
, &pxa2xx_cm_ops
, s
, "pxa2xx-cm", 0x1000);
2173 memory_region_add_subregion(address_space
, s
->cm_base
, &s
->cm_iomem
);
2174 vmstate_register(NULL
, 0, &vmstate_pxa2xx_cm
, s
);
2176 pxa2xx_setup_cp14(s
);
2178 s
->mm_base
= 0x48000000;
2179 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
2180 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
2181 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
2182 memory_region_init_io(&s
->mm_iomem
, NULL
, &pxa2xx_mm_ops
, s
, "pxa2xx-mm", 0x1000);
2183 memory_region_add_subregion(address_space
, s
->mm_base
, &s
->mm_iomem
);
2184 vmstate_register(NULL
, 0, &vmstate_pxa2xx_mm
, s
);
2186 s
->pm_base
= 0x40f00000;
2187 memory_region_init_io(&s
->pm_iomem
, NULL
, &pxa2xx_pm_ops
, s
, "pxa2xx-pm", 0x100);
2188 memory_region_add_subregion(address_space
, s
->pm_base
, &s
->pm_iomem
);
2189 vmstate_register(NULL
, 0, &vmstate_pxa2xx_pm
, s
);
2191 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++);
2192 s
->ssp
= g_new0(SSIBus
*, i
);
2193 for (i
= 0; pxa27x_ssp
[i
].io_base
; i
++) {
2195 dev
= sysbus_create_simple(TYPE_PXA2XX_SSP
, pxa27x_ssp
[i
].io_base
,
2196 qdev_get_gpio_in(s
->pic
, pxa27x_ssp
[i
].irqn
));
2197 s
->ssp
[i
] = (SSIBus
*)qdev_get_child_bus(dev
, "ssi");
2200 sysbus_create_simple("sysbus-ohci", 0x4c000000,
2201 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_USBH1
));
2203 s
->pcmcia
[0] = pxa2xx_pcmcia_init(address_space
, 0x20000000);
2204 s
->pcmcia
[1] = pxa2xx_pcmcia_init(address_space
, 0x30000000);
2206 sysbus_create_simple(TYPE_PXA2XX_RTC
, 0x40900000,
2207 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_RTCALARM
));
2209 s
->i2c
[0] = pxa2xx_i2c_init(0x40301600,
2210 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2C
), 0xffff);
2211 s
->i2c
[1] = pxa2xx_i2c_init(0x40f00100,
2212 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_PWRI2C
), 0xff);
2214 s
->i2s
= pxa2xx_i2s_init(address_space
, 0x40400000,
2215 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2S
),
2216 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_I2S
),
2217 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_I2S
));
2219 s
->kp
= pxa27x_keypad_init(address_space
, 0x41500000,
2220 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_KEYPAD
));
2222 /* GPIO1 resets the processor */
2223 /* The handler can be overridden by board-specific code */
2224 qdev_connect_gpio_out(s
->gpio
, 1, s
->reset
);
2228 /* Initialise a PXA255 integrated chip (ARM based core). */
2229 PXA2xxState
*pxa255_init(MemoryRegion
*address_space
, unsigned int sdram_size
)
2235 s
= g_new0(PXA2xxState
, 1);
2237 s
->cpu
= ARM_CPU(cpu_create(ARM_CPU_TYPE_NAME("pxa255")));
2238 s
->reset
= qemu_allocate_irq(pxa2xx_reset
, s
, 0);
2240 /* SDRAM & Internal Memory Storage */
2241 memory_region_init_ram(&s
->sdram
, NULL
, "pxa255.sdram", sdram_size
,
2243 memory_region_add_subregion(address_space
, PXA2XX_SDRAM_BASE
, &s
->sdram
);
2244 memory_region_init_ram(&s
->internal
, NULL
, "pxa255.internal",
2245 PXA2XX_INTERNAL_SIZE
, &error_fatal
);
2246 memory_region_add_subregion(address_space
, PXA2XX_INTERNAL_BASE
,
2249 s
->pic
= pxa2xx_pic_init(0x40d00000, s
->cpu
);
2251 s
->dma
= pxa255_dma_init(0x40000000,
2252 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_DMA
));
2254 sysbus_create_varargs("pxa25x-timer", 0x40a00000,
2255 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 0),
2256 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 1),
2257 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 2),
2258 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_OST_0
+ 3),
2261 s
->gpio
= pxa2xx_gpio_init(0x40e00000, s
->cpu
, s
->pic
, 85);
2263 dinfo
= drive_get(IF_SD
, 0, 0);
2264 if (!dinfo
&& !qtest_enabled()) {
2265 warn_report("missing SecureDigital device");
2267 s
->mmc
= pxa2xx_mmci_init(address_space
, 0x41100000,
2268 dinfo
? blk_by_legacy_dinfo(dinfo
) : NULL
,
2269 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_MMC
),
2270 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_MMCI
),
2271 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_MMCI
));
2273 for (i
= 0; pxa255_serial
[i
].io_base
; i
++) {
2275 serial_mm_init(address_space
, pxa255_serial
[i
].io_base
, 2,
2276 qdev_get_gpio_in(s
->pic
, pxa255_serial
[i
].irqn
),
2277 14745600 / 16, serial_hd(i
),
2278 DEVICE_NATIVE_ENDIAN
);
2284 s
->fir
= pxa2xx_fir_init(address_space
, 0x40800000,
2285 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_ICP
),
2286 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_ICP
),
2287 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_ICP
),
2290 s
->lcd
= pxa2xx_lcdc_init(address_space
, 0x44000000,
2291 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_LCD
));
2293 s
->cm_base
= 0x41300000;
2294 s
->cm_regs
[CCCR
>> 2] = 0x00000121; /* from datasheet */
2295 s
->cm_regs
[CKEN
>> 2] = 0x00017def; /* from datasheet */
2297 s
->clkcfg
= 0x00000009; /* Turbo mode active */
2298 memory_region_init_io(&s
->cm_iomem
, NULL
, &pxa2xx_cm_ops
, s
, "pxa2xx-cm", 0x1000);
2299 memory_region_add_subregion(address_space
, s
->cm_base
, &s
->cm_iomem
);
2300 vmstate_register(NULL
, 0, &vmstate_pxa2xx_cm
, s
);
2302 pxa2xx_setup_cp14(s
);
2304 s
->mm_base
= 0x48000000;
2305 s
->mm_regs
[MDMRS
>> 2] = 0x00020002;
2306 s
->mm_regs
[MDREFR
>> 2] = 0x03ca4000;
2307 s
->mm_regs
[MECR
>> 2] = 0x00000001; /* Two PC Card sockets */
2308 memory_region_init_io(&s
->mm_iomem
, NULL
, &pxa2xx_mm_ops
, s
, "pxa2xx-mm", 0x1000);
2309 memory_region_add_subregion(address_space
, s
->mm_base
, &s
->mm_iomem
);
2310 vmstate_register(NULL
, 0, &vmstate_pxa2xx_mm
, s
);
2312 s
->pm_base
= 0x40f00000;
2313 memory_region_init_io(&s
->pm_iomem
, NULL
, &pxa2xx_pm_ops
, s
, "pxa2xx-pm", 0x100);
2314 memory_region_add_subregion(address_space
, s
->pm_base
, &s
->pm_iomem
);
2315 vmstate_register(NULL
, 0, &vmstate_pxa2xx_pm
, s
);
2317 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++);
2318 s
->ssp
= g_new0(SSIBus
*, i
);
2319 for (i
= 0; pxa255_ssp
[i
].io_base
; i
++) {
2321 dev
= sysbus_create_simple(TYPE_PXA2XX_SSP
, pxa255_ssp
[i
].io_base
,
2322 qdev_get_gpio_in(s
->pic
, pxa255_ssp
[i
].irqn
));
2323 s
->ssp
[i
] = (SSIBus
*)qdev_get_child_bus(dev
, "ssi");
2326 s
->pcmcia
[0] = pxa2xx_pcmcia_init(address_space
, 0x20000000);
2327 s
->pcmcia
[1] = pxa2xx_pcmcia_init(address_space
, 0x30000000);
2329 sysbus_create_simple(TYPE_PXA2XX_RTC
, 0x40900000,
2330 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_RTCALARM
));
2332 s
->i2c
[0] = pxa2xx_i2c_init(0x40301600,
2333 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2C
), 0xffff);
2334 s
->i2c
[1] = pxa2xx_i2c_init(0x40f00100,
2335 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_PWRI2C
), 0xff);
2337 s
->i2s
= pxa2xx_i2s_init(address_space
, 0x40400000,
2338 qdev_get_gpio_in(s
->pic
, PXA2XX_PIC_I2S
),
2339 qdev_get_gpio_in(s
->dma
, PXA2XX_RX_RQ_I2S
),
2340 qdev_get_gpio_in(s
->dma
, PXA2XX_TX_RQ_I2S
));
2342 /* GPIO1 resets the processor */
2343 /* The handler can be overridden by board-specific code */
2344 qdev_connect_gpio_out(s
->gpio
, 1, s
->reset
);
2348 static void pxa2xx_ssp_class_init(ObjectClass
*klass
, void *data
)
2350 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2352 dc
->reset
= pxa2xx_ssp_reset
;
2353 dc
->vmsd
= &vmstate_pxa2xx_ssp
;
2356 static const TypeInfo pxa2xx_ssp_info
= {
2357 .name
= TYPE_PXA2XX_SSP
,
2358 .parent
= TYPE_SYS_BUS_DEVICE
,
2359 .instance_size
= sizeof(PXA2xxSSPState
),
2360 .instance_init
= pxa2xx_ssp_init
,
2361 .class_init
= pxa2xx_ssp_class_init
,
2364 static void pxa2xx_register_types(void)
2366 type_register_static(&pxa2xx_i2c_slave_info
);
2367 type_register_static(&pxa2xx_ssp_info
);
2368 type_register_static(&pxa2xx_i2c_info
);
2369 type_register_static(&pxa2xx_rtc_sysbus_info
);
2370 type_register_static(&pxa2xx_fir_info
);
2373 type_init(pxa2xx_register_types
)