2 * PXA270-based Clamshell PDA platforms.
4 * Copyright (c) 2006 Openedhand Ltd.
5 * Written by Andrzej Zaborowski <balrog@zabor.org>
7 * This code is licensed under the GNU GPL v2.
9 * Contributions after 2012-01-13 are licensed under the terms of the
10 * GNU GPL, version 2 or (at your option) any later version.
21 #include "qemu-timer.h"
26 #include "audio/audio.h"
30 #include "exec-memory.h"
33 #define REG_FMT "0x%02lx"
36 #define FLASH_BASE 0x0c000000
37 #define FLASH_ECCLPLB 0x00 /* Line parity 7 - 0 bit */
38 #define FLASH_ECCLPUB 0x04 /* Line parity 15 - 8 bit */
39 #define FLASH_ECCCP 0x08 /* Column parity 5 - 0 bit */
40 #define FLASH_ECCCNTR 0x0c /* ECC byte counter */
41 #define FLASH_ECCCLRR 0x10 /* Clear ECC */
42 #define FLASH_FLASHIO 0x14 /* Flash I/O */
43 #define FLASH_FLASHCTL 0x18 /* Flash Control */
45 #define FLASHCTL_CE0 (1 << 0)
46 #define FLASHCTL_CLE (1 << 1)
47 #define FLASHCTL_ALE (1 << 2)
48 #define FLASHCTL_WP (1 << 3)
49 #define FLASHCTL_CE1 (1 << 4)
50 #define FLASHCTL_RYBY (1 << 5)
51 #define FLASHCTL_NCE (FLASHCTL_CE0 | FLASHCTL_CE1)
63 static uint64_t sl_read(void *opaque
, hwaddr addr
, unsigned size
)
65 SLNANDState
*s
= (SLNANDState
*) opaque
;
69 #define BSHR(byte, from, to) ((s->ecc.lp[byte] >> (from - to)) & (1 << to))
71 return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) |
72 BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7);
74 #define BSHL(byte, from, to) ((s->ecc.lp[byte] << (to - from)) & (1 << to))
76 return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) |
77 BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7);
83 return s
->ecc
.count
& 0xff;
86 nand_getpins(s
->nand
, &ryby
);
88 return s
->ctl
| FLASHCTL_RYBY
;
94 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) |
95 (ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) << 16);
97 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
));
100 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
105 static void sl_write(void *opaque
, hwaddr addr
,
106 uint64_t value
, unsigned size
)
108 SLNANDState
*s
= (SLNANDState
*) opaque
;
112 /* Value is ignored. */
117 s
->ctl
= value
& 0xff & ~FLASHCTL_RYBY
;
118 nand_setpins(s
->nand
,
119 s
->ctl
& FLASHCTL_CLE
,
120 s
->ctl
& FLASHCTL_ALE
,
121 s
->ctl
& FLASHCTL_NCE
,
122 s
->ctl
& FLASHCTL_WP
,
127 nand_setio(s
->nand
, ecc_digest(&s
->ecc
, value
& 0xff));
131 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
140 static const MemoryRegionOps sl_ops
= {
143 .endianness
= DEVICE_NATIVE_ENDIAN
,
146 static void sl_flash_register(PXA2xxState
*cpu
, int size
)
150 dev
= qdev_create(NULL
, "sl-nand");
152 qdev_prop_set_uint8(dev
, "manf_id", NAND_MFR_SAMSUNG
);
153 if (size
== FLASH_128M
)
154 qdev_prop_set_uint8(dev
, "chip_id", 0x73);
155 else if (size
== FLASH_1024M
)
156 qdev_prop_set_uint8(dev
, "chip_id", 0xf1);
158 qdev_init_nofail(dev
);
159 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, FLASH_BASE
);
162 static int sl_nand_init(SysBusDevice
*dev
) {
166 s
= FROM_SYSBUS(SLNANDState
, dev
);
169 nand
= drive_get(IF_MTD
, 0, 0);
170 s
->nand
= nand_init(nand
? nand
->bdrv
: NULL
, s
->manf_id
, s
->chip_id
);
172 memory_region_init_io(&s
->iomem
, &sl_ops
, s
, "sl", 0x40);
173 sysbus_init_mmio(dev
, &s
->iomem
);
180 #define SPITZ_KEY_STROBE_NUM 11
181 #define SPITZ_KEY_SENSE_NUM 7
183 static const int spitz_gpio_key_sense
[SPITZ_KEY_SENSE_NUM
] = {
184 12, 17, 91, 34, 36, 38, 39
187 static const int spitz_gpio_key_strobe
[SPITZ_KEY_STROBE_NUM
] = {
188 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114
191 /* Eighth additional row maps the special keys */
192 static int spitz_keymap
[SPITZ_KEY_SENSE_NUM
+ 1][SPITZ_KEY_STROBE_NUM
] = {
193 { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 },
194 { -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 },
195 { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25, -1 , -1 , -1 },
196 { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26, -1 , 0x36, -1 },
197 { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34, -1 , 0x1c, 0x2a, -1 },
198 { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33, -1 , 0x48, -1 , -1 , 0x38 },
199 { 0x37, 0x3d, -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d, -1 , -1 },
200 { 0x52, 0x43, 0x01, 0x47, 0x49, -1 , -1 , -1 , -1 , -1 , -1 },
203 #define SPITZ_GPIO_AK_INT 13 /* Remote control */
204 #define SPITZ_GPIO_SYNC 16 /* Sync button */
205 #define SPITZ_GPIO_ON_KEY 95 /* Power button */
206 #define SPITZ_GPIO_SWA 97 /* Lid */
207 #define SPITZ_GPIO_SWB 96 /* Tablet mode */
209 /* The special buttons are mapped to unused keys */
210 static const int spitz_gpiomap
[5] = {
211 SPITZ_GPIO_AK_INT
, SPITZ_GPIO_SYNC
, SPITZ_GPIO_ON_KEY
,
212 SPITZ_GPIO_SWA
, SPITZ_GPIO_SWB
,
217 qemu_irq sense
[SPITZ_KEY_SENSE_NUM
];
220 uint16_t keyrow
[SPITZ_KEY_SENSE_NUM
];
221 uint16_t strobe_state
;
222 uint16_t sense_state
;
224 uint16_t pre_map
[0x100];
228 int fifopos
, fifolen
;
230 } SpitzKeyboardState
;
232 static void spitz_keyboard_sense_update(SpitzKeyboardState
*s
)
235 uint16_t strobe
, sense
= 0;
236 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
; i
++) {
237 strobe
= s
->keyrow
[i
] & s
->strobe_state
;
240 if (!(s
->sense_state
& (1 << i
)))
241 qemu_irq_raise(s
->sense
[i
]);
242 } else if (s
->sense_state
& (1 << i
))
243 qemu_irq_lower(s
->sense
[i
]);
246 s
->sense_state
= sense
;
249 static void spitz_keyboard_strobe(void *opaque
, int line
, int level
)
251 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
254 s
->strobe_state
|= 1 << line
;
256 s
->strobe_state
&= ~(1 << line
);
257 spitz_keyboard_sense_update(s
);
260 static void spitz_keyboard_keydown(SpitzKeyboardState
*s
, int keycode
)
262 int spitz_keycode
= s
->keymap
[keycode
& 0x7f];
263 if (spitz_keycode
== -1)
266 /* Handle the additional keys */
267 if ((spitz_keycode
>> 4) == SPITZ_KEY_SENSE_NUM
) {
268 qemu_set_irq(s
->gpiomap
[spitz_keycode
& 0xf], (keycode
< 0x80));
273 s
->keyrow
[spitz_keycode
>> 4] &= ~(1 << (spitz_keycode
& 0xf));
275 s
->keyrow
[spitz_keycode
>> 4] |= 1 << (spitz_keycode
& 0xf);
277 spitz_keyboard_sense_update(s
);
280 #define SHIFT (1 << 7)
281 #define CTRL (1 << 8)
284 #define QUEUE_KEY(c) s->fifo[(s->fifopos + s->fifolen ++) & 0xf] = c
286 static void spitz_keyboard_handler(void *opaque
, int keycode
)
288 SpitzKeyboardState
*s
= opaque
;
292 case 0x2a: /* Left Shift */
298 case 0x36: /* Right Shift */
304 case 0x1d: /* Control */
318 code
= s
->pre_map
[mapcode
= ((s
->modifiers
& 3) ?
320 (keycode
& ~SHIFT
))];
322 if (code
!= mapcode
) {
324 if ((code
& SHIFT
) && !(s
->modifiers
& 1))
325 QUEUE_KEY(0x2a | (keycode
& 0x80));
326 if ((code
& CTRL
) && !(s
->modifiers
& 4))
327 QUEUE_KEY(0x1d | (keycode
& 0x80));
328 if ((code
& FN
) && !(s
->modifiers
& 8))
329 QUEUE_KEY(0x38 | (keycode
& 0x80));
330 if ((code
& FN
) && (s
->modifiers
& 1))
331 QUEUE_KEY(0x2a | (~keycode
& 0x80));
332 if ((code
& FN
) && (s
->modifiers
& 2))
333 QUEUE_KEY(0x36 | (~keycode
& 0x80));
335 if (keycode
& 0x80) {
336 if ((s
->imodifiers
& 1 ) && !(s
->modifiers
& 1))
337 QUEUE_KEY(0x2a | 0x80);
338 if ((s
->imodifiers
& 4 ) && !(s
->modifiers
& 4))
339 QUEUE_KEY(0x1d | 0x80);
340 if ((s
->imodifiers
& 8 ) && !(s
->modifiers
& 8))
341 QUEUE_KEY(0x38 | 0x80);
342 if ((s
->imodifiers
& 0x10) && (s
->modifiers
& 1))
344 if ((s
->imodifiers
& 0x20) && (s
->modifiers
& 2))
348 if ((code
& SHIFT
) && !((s
->modifiers
| s
->imodifiers
) & 1)) {
352 if ((code
& CTRL
) && !((s
->modifiers
| s
->imodifiers
) & 4)) {
356 if ((code
& FN
) && !((s
->modifiers
| s
->imodifiers
) & 8)) {
360 if ((code
& FN
) && (s
->modifiers
& 1) &&
361 !(s
->imodifiers
& 0x10)) {
362 QUEUE_KEY(0x2a | 0x80);
363 s
->imodifiers
|= 0x10;
365 if ((code
& FN
) && (s
->modifiers
& 2) &&
366 !(s
->imodifiers
& 0x20)) {
367 QUEUE_KEY(0x36 | 0x80);
368 s
->imodifiers
|= 0x20;
374 QUEUE_KEY((code
& 0x7f) | (keycode
& 0x80));
377 static void spitz_keyboard_tick(void *opaque
)
379 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
382 spitz_keyboard_keydown(s
, s
->fifo
[s
->fifopos
++]);
384 if (s
->fifopos
>= 16)
388 qemu_mod_timer(s
->kbdtimer
, qemu_get_clock_ns(vm_clock
) +
389 get_ticks_per_sec() / 32);
392 static void spitz_keyboard_pre_map(SpitzKeyboardState
*s
)
395 for (i
= 0; i
< 0x100; i
++)
397 s
->pre_map
[0x02 | SHIFT
] = 0x02 | SHIFT
; /* exclam */
398 s
->pre_map
[0x28 | SHIFT
] = 0x03 | SHIFT
; /* quotedbl */
399 s
->pre_map
[0x04 | SHIFT
] = 0x04 | SHIFT
; /* numbersign */
400 s
->pre_map
[0x05 | SHIFT
] = 0x05 | SHIFT
; /* dollar */
401 s
->pre_map
[0x06 | SHIFT
] = 0x06 | SHIFT
; /* percent */
402 s
->pre_map
[0x08 | SHIFT
] = 0x07 | SHIFT
; /* ampersand */
403 s
->pre_map
[0x28 ] = 0x08 | SHIFT
; /* apostrophe */
404 s
->pre_map
[0x0a | SHIFT
] = 0x09 | SHIFT
; /* parenleft */
405 s
->pre_map
[0x0b | SHIFT
] = 0x0a | SHIFT
; /* parenright */
406 s
->pre_map
[0x29 | SHIFT
] = 0x0b | SHIFT
; /* asciitilde */
407 s
->pre_map
[0x03 | SHIFT
] = 0x0c | SHIFT
; /* at */
408 s
->pre_map
[0xd3 ] = 0x0e | FN
; /* Delete */
409 s
->pre_map
[0x3a ] = 0x0f | FN
; /* Caps_Lock */
410 s
->pre_map
[0x07 | SHIFT
] = 0x11 | FN
; /* asciicircum */
411 s
->pre_map
[0x0d ] = 0x12 | FN
; /* equal */
412 s
->pre_map
[0x0d | SHIFT
] = 0x13 | FN
; /* plus */
413 s
->pre_map
[0x1a ] = 0x14 | FN
; /* bracketleft */
414 s
->pre_map
[0x1b ] = 0x15 | FN
; /* bracketright */
415 s
->pre_map
[0x1a | SHIFT
] = 0x16 | FN
; /* braceleft */
416 s
->pre_map
[0x1b | SHIFT
] = 0x17 | FN
; /* braceright */
417 s
->pre_map
[0x27 ] = 0x22 | FN
; /* semicolon */
418 s
->pre_map
[0x27 | SHIFT
] = 0x23 | FN
; /* colon */
419 s
->pre_map
[0x09 | SHIFT
] = 0x24 | FN
; /* asterisk */
420 s
->pre_map
[0x2b ] = 0x25 | FN
; /* backslash */
421 s
->pre_map
[0x2b | SHIFT
] = 0x26 | FN
; /* bar */
422 s
->pre_map
[0x0c | SHIFT
] = 0x30 | FN
; /* underscore */
423 s
->pre_map
[0x33 | SHIFT
] = 0x33 | FN
; /* less */
424 s
->pre_map
[0x35 ] = 0x33 | SHIFT
; /* slash */
425 s
->pre_map
[0x34 | SHIFT
] = 0x34 | FN
; /* greater */
426 s
->pre_map
[0x35 | SHIFT
] = 0x34 | SHIFT
; /* question */
427 s
->pre_map
[0x49 ] = 0x48 | FN
; /* Page_Up */
428 s
->pre_map
[0x51 ] = 0x50 | FN
; /* Page_Down */
440 static int spitz_keyboard_post_load(void *opaque
, int version_id
)
442 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
444 /* Release all pressed keys */
445 memset(s
->keyrow
, 0, sizeof(s
->keyrow
));
446 spitz_keyboard_sense_update(s
);
455 static void spitz_keyboard_register(PXA2xxState
*cpu
)
459 SpitzKeyboardState
*s
;
461 dev
= sysbus_create_simple("spitz-keyboard", -1, NULL
);
462 s
= FROM_SYSBUS(SpitzKeyboardState
, sysbus_from_qdev(dev
));
464 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
; i
++)
465 qdev_connect_gpio_out(dev
, i
, qdev_get_gpio_in(cpu
->gpio
, spitz_gpio_key_sense
[i
]));
467 for (i
= 0; i
< 5; i
++)
468 s
->gpiomap
[i
] = qdev_get_gpio_in(cpu
->gpio
, spitz_gpiomap
[i
]);
471 s
->gpiomap
[4] = qemu_irq_invert(s
->gpiomap
[4]);
473 for (i
= 0; i
< 5; i
++)
474 qemu_set_irq(s
->gpiomap
[i
], 0);
476 for (i
= 0; i
< SPITZ_KEY_STROBE_NUM
; i
++)
477 qdev_connect_gpio_out(cpu
->gpio
, spitz_gpio_key_strobe
[i
],
478 qdev_get_gpio_in(dev
, i
));
480 qemu_mod_timer(s
->kbdtimer
, qemu_get_clock_ns(vm_clock
));
482 qemu_add_kbd_event_handler(spitz_keyboard_handler
, s
);
485 static int spitz_keyboard_init(SysBusDevice
*dev
)
487 SpitzKeyboardState
*s
;
490 s
= FROM_SYSBUS(SpitzKeyboardState
, dev
);
492 for (i
= 0; i
< 0x80; i
++)
494 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
+ 1; i
++)
495 for (j
= 0; j
< SPITZ_KEY_STROBE_NUM
; j
++)
496 if (spitz_keymap
[i
][j
] != -1)
497 s
->keymap
[spitz_keymap
[i
][j
]] = (i
<< 4) | j
;
499 spitz_keyboard_pre_map(s
);
501 s
->kbdtimer
= qemu_new_timer_ns(vm_clock
, spitz_keyboard_tick
, s
);
502 qdev_init_gpio_in(&dev
->qdev
, spitz_keyboard_strobe
, SPITZ_KEY_STROBE_NUM
);
503 qdev_init_gpio_out(&dev
->qdev
, s
->sense
, SPITZ_KEY_SENSE_NUM
);
508 /* LCD backlight controller */
510 #define LCDTG_RESCTL 0x00
511 #define LCDTG_PHACTRL 0x01
512 #define LCDTG_DUTYCTRL 0x02
513 #define LCDTG_POWERREG0 0x03
514 #define LCDTG_POWERREG1 0x04
515 #define LCDTG_GPOR3 0x05
516 #define LCDTG_PICTRL 0x06
517 #define LCDTG_POLCTRL 0x07
521 uint32_t bl_intensity
;
525 static void spitz_bl_update(SpitzLCDTG
*s
)
527 if (s
->bl_power
&& s
->bl_intensity
)
528 zaurus_printf("LCD Backlight now at %i/63\n", s
->bl_intensity
);
530 zaurus_printf("LCD Backlight now off\n");
533 /* FIXME: Implement GPIO properly and remove this hack. */
534 static SpitzLCDTG
*spitz_lcdtg
;
536 static inline void spitz_bl_bit5(void *opaque
, int line
, int level
)
538 SpitzLCDTG
*s
= spitz_lcdtg
;
539 int prev
= s
->bl_intensity
;
542 s
->bl_intensity
&= ~0x20;
544 s
->bl_intensity
|= 0x20;
546 if (s
->bl_power
&& prev
!= s
->bl_intensity
)
550 static inline void spitz_bl_power(void *opaque
, int line
, int level
)
552 SpitzLCDTG
*s
= spitz_lcdtg
;
553 s
->bl_power
= !!level
;
557 static uint32_t spitz_lcdtg_transfer(SSISlave
*dev
, uint32_t value
)
559 SpitzLCDTG
*s
= FROM_SSI_SLAVE(SpitzLCDTG
, dev
);
567 zaurus_printf("LCD in QVGA mode\n");
569 zaurus_printf("LCD in VGA mode\n");
573 s
->bl_intensity
&= ~0x1f;
574 s
->bl_intensity
|= value
;
579 case LCDTG_POWERREG0
:
580 /* Set common voltage to M62332FP */
586 static int spitz_lcdtg_init(SSISlave
*dev
)
588 SpitzLCDTG
*s
= FROM_SSI_SLAVE(SpitzLCDTG
, dev
);
592 s
->bl_intensity
= 0x20;
599 #define CORGI_SSP_PORT 2
601 #define SPITZ_GPIO_LCDCON_CS 53
602 #define SPITZ_GPIO_ADS7846_CS 14
603 #define SPITZ_GPIO_MAX1111_CS 20
604 #define SPITZ_GPIO_TP_INT 11
606 static DeviceState
*max1111
;
608 /* "Demux" the signal based on current chipselect */
615 static uint32_t corgi_ssp_transfer(SSISlave
*dev
, uint32_t value
)
617 CorgiSSPState
*s
= FROM_SSI_SLAVE(CorgiSSPState
, dev
);
620 for (i
= 0; i
< 3; i
++) {
622 return ssi_transfer(s
->bus
[i
], value
);
628 static void corgi_ssp_gpio_cs(void *opaque
, int line
, int level
)
630 CorgiSSPState
*s
= (CorgiSSPState
*)opaque
;
631 assert(line
>= 0 && line
< 3);
632 s
->enable
[line
] = !level
;
635 #define MAX1111_BATT_VOLT 1
636 #define MAX1111_BATT_TEMP 2
637 #define MAX1111_ACIN_VOLT 3
639 #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */
640 #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */
641 #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */
643 static void spitz_adc_temp_on(void *opaque
, int line
, int level
)
649 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, SPITZ_BATTERY_TEMP
);
651 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
654 static int corgi_ssp_init(SSISlave
*dev
)
656 CorgiSSPState
*s
= FROM_SSI_SLAVE(CorgiSSPState
, dev
);
658 qdev_init_gpio_in(&dev
->qdev
, corgi_ssp_gpio_cs
, 3);
659 s
->bus
[0] = ssi_create_bus(&dev
->qdev
, "ssi0");
660 s
->bus
[1] = ssi_create_bus(&dev
->qdev
, "ssi1");
661 s
->bus
[2] = ssi_create_bus(&dev
->qdev
, "ssi2");
666 static void spitz_ssp_attach(PXA2xxState
*cpu
)
672 mux
= ssi_create_slave(cpu
->ssp
[CORGI_SSP_PORT
- 1], "corgi-ssp");
674 bus
= qdev_get_child_bus(mux
, "ssi0");
675 ssi_create_slave(bus
, "spitz-lcdtg");
677 bus
= qdev_get_child_bus(mux
, "ssi1");
678 dev
= ssi_create_slave(bus
, "ads7846");
679 qdev_connect_gpio_out(dev
, 0,
680 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_TP_INT
));
682 bus
= qdev_get_child_bus(mux
, "ssi2");
683 max1111
= ssi_create_slave(bus
, "max1111");
684 max111x_set_input(max1111
, MAX1111_BATT_VOLT
, SPITZ_BATTERY_VOLT
);
685 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
686 max111x_set_input(max1111
, MAX1111_ACIN_VOLT
, SPITZ_CHARGEON_ACIN
);
688 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_LCDCON_CS
,
689 qdev_get_gpio_in(mux
, 0));
690 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_ADS7846_CS
,
691 qdev_get_gpio_in(mux
, 1));
692 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_MAX1111_CS
,
693 qdev_get_gpio_in(mux
, 2));
698 static void spitz_microdrive_attach(PXA2xxState
*cpu
, int slot
)
703 dinfo
= drive_get(IF_IDE
, 0, 0);
704 if (!dinfo
|| dinfo
->media_cd
)
706 md
= dscm1xxxx_init(dinfo
);
707 pxa2xx_pcmcia_attach(cpu
->pcmcia
[slot
], md
);
710 /* Wm8750 and Max7310 on I2C */
712 #define AKITA_MAX_ADDR 0x18
713 #define SPITZ_WM_ADDRL 0x1b
714 #define SPITZ_WM_ADDRH 0x1a
716 #define SPITZ_GPIO_WM 5
718 static void spitz_wm8750_addr(void *opaque
, int line
, int level
)
720 I2CSlave
*wm
= (I2CSlave
*) opaque
;
722 i2c_set_slave_address(wm
, SPITZ_WM_ADDRH
);
724 i2c_set_slave_address(wm
, SPITZ_WM_ADDRL
);
727 static void spitz_i2c_setup(PXA2xxState
*cpu
)
729 /* Attach the CPU on one end of our I2C bus. */
730 i2c_bus
*bus
= pxa2xx_i2c_bus(cpu
->i2c
[0]);
734 /* Attach a WM8750 to the bus */
735 wm
= i2c_create_slave(bus
, "wm8750", 0);
737 spitz_wm8750_addr(wm
, 0, 0);
738 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_WM
,
739 qemu_allocate_irqs(spitz_wm8750_addr
, wm
, 1)[0]);
740 /* .. and to the sound interface. */
741 cpu
->i2s
->opaque
= wm
;
742 cpu
->i2s
->codec_out
= wm8750_dac_dat
;
743 cpu
->i2s
->codec_in
= wm8750_adc_dat
;
744 wm8750_data_req_set(wm
, cpu
->i2s
->data_req
, cpu
->i2s
);
747 static void spitz_akita_i2c_setup(PXA2xxState
*cpu
)
749 /* Attach a Max7310 to Akita I2C bus. */
750 i2c_create_slave(pxa2xx_i2c_bus(cpu
->i2c
[0]), "max7310",
754 /* Other peripherals */
756 static void spitz_out_switch(void *opaque
, int line
, int level
)
760 zaurus_printf("Charging %s.\n", level
? "off" : "on");
763 zaurus_printf("Discharging %s.\n", level
? "on" : "off");
766 zaurus_printf("Green LED %s.\n", level
? "on" : "off");
769 zaurus_printf("Orange LED %s.\n", level
? "on" : "off");
772 spitz_bl_bit5(opaque
, line
, level
);
775 spitz_bl_power(opaque
, line
, level
);
778 spitz_adc_temp_on(opaque
, line
, level
);
783 #define SPITZ_SCP_LED_GREEN 1
784 #define SPITZ_SCP_JK_B 2
785 #define SPITZ_SCP_CHRG_ON 3
786 #define SPITZ_SCP_MUTE_L 4
787 #define SPITZ_SCP_MUTE_R 5
788 #define SPITZ_SCP_CF_POWER 6
789 #define SPITZ_SCP_LED_ORANGE 7
790 #define SPITZ_SCP_JK_A 8
791 #define SPITZ_SCP_ADC_TEMP_ON 9
792 #define SPITZ_SCP2_IR_ON 1
793 #define SPITZ_SCP2_AKIN_PULLUP 2
794 #define SPITZ_SCP2_BACKLIGHT_CONT 7
795 #define SPITZ_SCP2_BACKLIGHT_ON 8
796 #define SPITZ_SCP2_MIC_BIAS 9
798 static void spitz_scoop_gpio_setup(PXA2xxState
*cpu
,
799 DeviceState
*scp0
, DeviceState
*scp1
)
801 qemu_irq
*outsignals
= qemu_allocate_irqs(spitz_out_switch
, cpu
, 8);
803 qdev_connect_gpio_out(scp0
, SPITZ_SCP_CHRG_ON
, outsignals
[0]);
804 qdev_connect_gpio_out(scp0
, SPITZ_SCP_JK_B
, outsignals
[1]);
805 qdev_connect_gpio_out(scp0
, SPITZ_SCP_LED_GREEN
, outsignals
[2]);
806 qdev_connect_gpio_out(scp0
, SPITZ_SCP_LED_ORANGE
, outsignals
[3]);
809 qdev_connect_gpio_out(scp1
, SPITZ_SCP2_BACKLIGHT_CONT
, outsignals
[4]);
810 qdev_connect_gpio_out(scp1
, SPITZ_SCP2_BACKLIGHT_ON
, outsignals
[5]);
813 qdev_connect_gpio_out(scp0
, SPITZ_SCP_ADC_TEMP_ON
, outsignals
[6]);
816 #define SPITZ_GPIO_HSYNC 22
817 #define SPITZ_GPIO_SD_DETECT 9
818 #define SPITZ_GPIO_SD_WP 81
819 #define SPITZ_GPIO_ON_RESET 89
820 #define SPITZ_GPIO_BAT_COVER 90
821 #define SPITZ_GPIO_CF1_IRQ 105
822 #define SPITZ_GPIO_CF1_CD 94
823 #define SPITZ_GPIO_CF2_IRQ 106
824 #define SPITZ_GPIO_CF2_CD 93
826 static int spitz_hsync
;
828 static void spitz_lcd_hsync_handler(void *opaque
, int line
, int level
)
830 PXA2xxState
*cpu
= (PXA2xxState
*) opaque
;
831 qemu_set_irq(qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_HSYNC
), spitz_hsync
);
835 static void spitz_gpio_setup(PXA2xxState
*cpu
, int slots
)
839 * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
840 * read to satisfy broken guests that poll-wait for hsync.
841 * Simulating a real hsync event would be less practical and
842 * wouldn't guarantee that a guest ever exits the loop.
845 lcd_hsync
= qemu_allocate_irqs(spitz_lcd_hsync_handler
, cpu
, 1)[0];
846 pxa2xx_gpio_read_notifier(cpu
->gpio
, lcd_hsync
);
847 pxa2xx_lcd_vsync_notifier(cpu
->lcd
, lcd_hsync
);
850 pxa2xx_mmci_handlers(cpu
->mmc
,
851 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_SD_WP
),
852 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_SD_DETECT
));
854 /* Battery lock always closed */
855 qemu_irq_raise(qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_BAT_COVER
));
858 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_ON_RESET
, cpu
->reset
);
860 /* PCMCIA signals: card's IRQ and Card-Detect */
862 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[0],
863 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF1_IRQ
),
864 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF1_CD
));
866 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[1],
867 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF2_IRQ
),
868 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF2_CD
));
872 enum spitz_model_e
{ spitz
, akita
, borzoi
, terrier
};
874 #define SPITZ_RAM 0x04000000
875 #define SPITZ_ROM 0x00800000
877 static struct arm_boot_info spitz_binfo
= {
878 .loader_start
= PXA2XX_SDRAM_BASE
,
879 .ram_size
= 0x04000000,
882 static void spitz_common_init(QEMUMachineInitArgs
*args
,
883 enum spitz_model_e model
, int arm_id
)
886 DeviceState
*scp0
, *scp1
= NULL
;
887 MemoryRegion
*address_space_mem
= get_system_memory();
888 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
889 const char *cpu_model
= args
->cpu_model
;
892 cpu_model
= (model
== terrier
) ? "pxa270-c5" : "pxa270-c0";
894 /* Setup CPU & memory */
895 mpu
= pxa270_init(address_space_mem
, spitz_binfo
.ram_size
, cpu_model
);
897 sl_flash_register(mpu
, (model
== spitz
) ? FLASH_128M
: FLASH_1024M
);
899 memory_region_init_ram(rom
, "spitz.rom", SPITZ_ROM
);
900 vmstate_register_ram_global(rom
);
901 memory_region_set_readonly(rom
, true);
902 memory_region_add_subregion(address_space_mem
, 0, rom
);
904 /* Setup peripherals */
905 spitz_keyboard_register(mpu
);
907 spitz_ssp_attach(mpu
);
909 scp0
= sysbus_create_simple("scoop", 0x10800000, NULL
);
910 if (model
!= akita
) {
911 scp1
= sysbus_create_simple("scoop", 0x08800040, NULL
);
914 spitz_scoop_gpio_setup(mpu
, scp0
, scp1
);
916 spitz_gpio_setup(mpu
, (model
== akita
) ? 1 : 2);
918 spitz_i2c_setup(mpu
);
921 spitz_akita_i2c_setup(mpu
);
923 if (model
== terrier
)
924 /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
925 spitz_microdrive_attach(mpu
, 1);
926 else if (model
!= akita
)
927 /* A 4.0 GB microdrive is permanently sitting in CF slot 0. */
928 spitz_microdrive_attach(mpu
, 0);
930 spitz_binfo
.kernel_filename
= args
->kernel_filename
;
931 spitz_binfo
.kernel_cmdline
= args
->kernel_cmdline
;
932 spitz_binfo
.initrd_filename
= args
->initrd_filename
;
933 spitz_binfo
.board_id
= arm_id
;
934 arm_load_kernel(mpu
->cpu
, &spitz_binfo
);
935 sl_bootparam_write(SL_PXA_PARAM_BASE
);
938 static void spitz_init(QEMUMachineInitArgs
*args
)
940 spitz_common_init(args
, spitz
, 0x2c9);
943 static void borzoi_init(QEMUMachineInitArgs
*args
)
945 spitz_common_init(args
, borzoi
, 0x33f);
948 static void akita_init(QEMUMachineInitArgs
*args
)
950 spitz_common_init(args
, akita
, 0x2e8);
953 static void terrier_init(QEMUMachineInitArgs
*args
)
955 spitz_common_init(args
, terrier
, 0x33f);
958 static QEMUMachine akitapda_machine
= {
960 .desc
= "Akita PDA (PXA270)",
964 static QEMUMachine spitzpda_machine
= {
966 .desc
= "Spitz PDA (PXA270)",
970 static QEMUMachine borzoipda_machine
= {
972 .desc
= "Borzoi PDA (PXA270)",
976 static QEMUMachine terrierpda_machine
= {
978 .desc
= "Terrier PDA (PXA270)",
979 .init
= terrier_init
,
982 static void spitz_machine_init(void)
984 qemu_register_machine(&akitapda_machine
);
985 qemu_register_machine(&spitzpda_machine
);
986 qemu_register_machine(&borzoipda_machine
);
987 qemu_register_machine(&terrierpda_machine
);
990 machine_init(spitz_machine_init
);
992 static bool is_version_0(void *opaque
, int version_id
)
994 return version_id
== 0;
997 static VMStateDescription vmstate_sl_nand_info
= {
1000 .minimum_version_id
= 0,
1001 .minimum_version_id_old
= 0,
1002 .fields
= (VMStateField
[]) {
1003 VMSTATE_UINT8(ctl
, SLNANDState
),
1004 VMSTATE_STRUCT(ecc
, SLNANDState
, 0, vmstate_ecc_state
, ECCState
),
1005 VMSTATE_END_OF_LIST(),
1009 static Property sl_nand_properties
[] = {
1010 DEFINE_PROP_UINT8("manf_id", SLNANDState
, manf_id
, NAND_MFR_SAMSUNG
),
1011 DEFINE_PROP_UINT8("chip_id", SLNANDState
, chip_id
, 0xf1),
1012 DEFINE_PROP_END_OF_LIST(),
1015 static void sl_nand_class_init(ObjectClass
*klass
, void *data
)
1017 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1018 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1020 k
->init
= sl_nand_init
;
1021 dc
->vmsd
= &vmstate_sl_nand_info
;
1022 dc
->props
= sl_nand_properties
;
1025 static TypeInfo sl_nand_info
= {
1027 .parent
= TYPE_SYS_BUS_DEVICE
,
1028 .instance_size
= sizeof(SLNANDState
),
1029 .class_init
= sl_nand_class_init
,
1032 static VMStateDescription vmstate_spitz_kbd
= {
1033 .name
= "spitz-keyboard",
1035 .minimum_version_id
= 0,
1036 .minimum_version_id_old
= 0,
1037 .post_load
= spitz_keyboard_post_load
,
1038 .fields
= (VMStateField
[]) {
1039 VMSTATE_UINT16(sense_state
, SpitzKeyboardState
),
1040 VMSTATE_UINT16(strobe_state
, SpitzKeyboardState
),
1041 VMSTATE_UNUSED_TEST(is_version_0
, 5),
1042 VMSTATE_END_OF_LIST(),
1046 static Property spitz_keyboard_properties
[] = {
1047 DEFINE_PROP_END_OF_LIST(),
1050 static void spitz_keyboard_class_init(ObjectClass
*klass
, void *data
)
1052 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1053 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1055 k
->init
= spitz_keyboard_init
;
1056 dc
->vmsd
= &vmstate_spitz_kbd
;
1057 dc
->props
= spitz_keyboard_properties
;
1060 static TypeInfo spitz_keyboard_info
= {
1061 .name
= "spitz-keyboard",
1062 .parent
= TYPE_SYS_BUS_DEVICE
,
1063 .instance_size
= sizeof(SpitzKeyboardState
),
1064 .class_init
= spitz_keyboard_class_init
,
1067 static const VMStateDescription vmstate_corgi_ssp_regs
= {
1068 .name
= "corgi-ssp",
1070 .minimum_version_id
= 2,
1071 .minimum_version_id_old
= 2,
1072 .fields
= (VMStateField
[]) {
1073 VMSTATE_SSI_SLAVE(ssidev
, CorgiSSPState
),
1074 VMSTATE_UINT32_ARRAY(enable
, CorgiSSPState
, 3),
1075 VMSTATE_END_OF_LIST(),
1079 static void corgi_ssp_class_init(ObjectClass
*klass
, void *data
)
1081 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1082 SSISlaveClass
*k
= SSI_SLAVE_CLASS(klass
);
1084 k
->init
= corgi_ssp_init
;
1085 k
->transfer
= corgi_ssp_transfer
;
1086 dc
->vmsd
= &vmstate_corgi_ssp_regs
;
1089 static TypeInfo corgi_ssp_info
= {
1090 .name
= "corgi-ssp",
1091 .parent
= TYPE_SSI_SLAVE
,
1092 .instance_size
= sizeof(CorgiSSPState
),
1093 .class_init
= corgi_ssp_class_init
,
1096 static const VMStateDescription vmstate_spitz_lcdtg_regs
= {
1097 .name
= "spitz-lcdtg",
1099 .minimum_version_id
= 1,
1100 .minimum_version_id_old
= 1,
1101 .fields
= (VMStateField
[]) {
1102 VMSTATE_SSI_SLAVE(ssidev
, SpitzLCDTG
),
1103 VMSTATE_UINT32(bl_intensity
, SpitzLCDTG
),
1104 VMSTATE_UINT32(bl_power
, SpitzLCDTG
),
1105 VMSTATE_END_OF_LIST(),
1109 static void spitz_lcdtg_class_init(ObjectClass
*klass
, void *data
)
1111 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1112 SSISlaveClass
*k
= SSI_SLAVE_CLASS(klass
);
1114 k
->init
= spitz_lcdtg_init
;
1115 k
->transfer
= spitz_lcdtg_transfer
;
1116 dc
->vmsd
= &vmstate_spitz_lcdtg_regs
;
1119 static TypeInfo spitz_lcdtg_info
= {
1120 .name
= "spitz-lcdtg",
1121 .parent
= TYPE_SSI_SLAVE
,
1122 .instance_size
= sizeof(SpitzLCDTG
),
1123 .class_init
= spitz_lcdtg_class_init
,
1126 static void spitz_register_types(void)
1128 type_register_static(&corgi_ssp_info
);
1129 type_register_static(&spitz_lcdtg_info
);
1130 type_register_static(&spitz_keyboard_info
);
1131 type_register_static(&sl_nand_info
);
1134 type_init(spitz_register_types
)