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.
18 #include "qemu-timer.h"
23 #include "audio/audio.h"
29 #define REG_FMT "0x%02lx"
32 #define FLASH_BASE 0x0c000000
33 #define FLASH_ECCLPLB 0x00 /* Line parity 7 - 0 bit */
34 #define FLASH_ECCLPUB 0x04 /* Line parity 15 - 8 bit */
35 #define FLASH_ECCCP 0x08 /* Column parity 5 - 0 bit */
36 #define FLASH_ECCCNTR 0x0c /* ECC byte counter */
37 #define FLASH_ECCCLRR 0x10 /* Clear ECC */
38 #define FLASH_FLASHIO 0x14 /* Flash I/O */
39 #define FLASH_FLASHCTL 0x18 /* Flash Control */
41 #define FLASHCTL_CE0 (1 << 0)
42 #define FLASHCTL_CLE (1 << 1)
43 #define FLASHCTL_ALE (1 << 2)
44 #define FLASHCTL_WP (1 << 3)
45 #define FLASHCTL_CE1 (1 << 4)
46 #define FLASHCTL_RYBY (1 << 5)
47 #define FLASHCTL_NCE (FLASHCTL_CE0 | FLASHCTL_CE1)
55 static uint32_t sl_readb(void *opaque
, target_phys_addr_t addr
)
57 SLNANDState
*s
= (SLNANDState
*) opaque
;
61 #define BSHR(byte, from, to) ((s->ecc.lp[byte] >> (from - to)) & (1 << to))
63 return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) |
64 BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7);
66 #define BSHL(byte, from, to) ((s->ecc.lp[byte] << (to - from)) & (1 << to))
68 return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) |
69 BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7);
75 return s
->ecc
.count
& 0xff;
78 nand_getpins(s
->nand
, &ryby
);
80 return s
->ctl
| FLASHCTL_RYBY
;
85 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
));
88 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
93 static uint32_t sl_readl(void *opaque
, target_phys_addr_t addr
)
95 SLNANDState
*s
= (SLNANDState
*) opaque
;
97 if (addr
== FLASH_FLASHIO
)
98 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) |
99 (ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) << 16);
101 return sl_readb(opaque
, addr
);
104 static void sl_writeb(void *opaque
, target_phys_addr_t addr
,
107 SLNANDState
*s
= (SLNANDState
*) opaque
;
111 /* Value is ignored. */
116 s
->ctl
= value
& 0xff & ~FLASHCTL_RYBY
;
117 nand_setpins(s
->nand
,
118 s
->ctl
& FLASHCTL_CLE
,
119 s
->ctl
& FLASHCTL_ALE
,
120 s
->ctl
& FLASHCTL_NCE
,
121 s
->ctl
& FLASHCTL_WP
,
126 nand_setio(s
->nand
, ecc_digest(&s
->ecc
, value
& 0xff));
130 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
134 static void sl_save(QEMUFile
*f
, void *opaque
)
136 SLNANDState
*s
= (SLNANDState
*) opaque
;
138 qemu_put_8s(f
, &s
->ctl
);
142 static int sl_load(QEMUFile
*f
, void *opaque
, int version_id
)
144 SLNANDState
*s
= (SLNANDState
*) opaque
;
146 qemu_get_8s(f
, &s
->ctl
);
157 static void sl_flash_register(PXA2xxState
*cpu
, int size
)
161 CPUReadMemoryFunc
* const sl_readfn
[] = {
166 CPUWriteMemoryFunc
* const sl_writefn
[] = {
172 s
= (SLNANDState
*) qemu_mallocz(sizeof(SLNANDState
));
174 if (size
== FLASH_128M
)
175 s
->nand
= nand_init(NAND_MFR_SAMSUNG
, 0x73);
176 else if (size
== FLASH_1024M
)
177 s
->nand
= nand_init(NAND_MFR_SAMSUNG
, 0xf1);
179 iomemtype
= cpu_register_io_memory(sl_readfn
,
180 sl_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
181 cpu_register_physical_memory(FLASH_BASE
, 0x40, iomemtype
);
183 register_savevm(NULL
, "sl_flash", 0, 0, sl_save
, sl_load
, s
);
188 #define SPITZ_KEY_STROBE_NUM 11
189 #define SPITZ_KEY_SENSE_NUM 7
191 static const int spitz_gpio_key_sense
[SPITZ_KEY_SENSE_NUM
] = {
192 12, 17, 91, 34, 36, 38, 39
195 static const int spitz_gpio_key_strobe
[SPITZ_KEY_STROBE_NUM
] = {
196 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114
199 /* Eighth additional row maps the special keys */
200 static int spitz_keymap
[SPITZ_KEY_SENSE_NUM
+ 1][SPITZ_KEY_STROBE_NUM
] = {
201 { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 },
202 { -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 },
203 { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25, -1 , -1 , -1 },
204 { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26, -1 , 0x36, -1 },
205 { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34, -1 , 0x1c, 0x2a, -1 },
206 { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33, -1 , 0x48, -1 , -1 , 0x38 },
207 { 0x37, 0x3d, -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d, -1 , -1 },
208 { 0x52, 0x43, 0x01, 0x47, 0x49, -1 , -1 , -1 , -1 , -1 , -1 },
211 #define SPITZ_GPIO_AK_INT 13 /* Remote control */
212 #define SPITZ_GPIO_SYNC 16 /* Sync button */
213 #define SPITZ_GPIO_ON_KEY 95 /* Power button */
214 #define SPITZ_GPIO_SWA 97 /* Lid */
215 #define SPITZ_GPIO_SWB 96 /* Tablet mode */
217 /* The special buttons are mapped to unused keys */
218 static const int spitz_gpiomap
[5] = {
219 SPITZ_GPIO_AK_INT
, SPITZ_GPIO_SYNC
, SPITZ_GPIO_ON_KEY
,
220 SPITZ_GPIO_SWA
, SPITZ_GPIO_SWB
,
222 static int spitz_gpio_invert
[5] = { 0, 0, 0, 0, 0, };
225 qemu_irq sense
[SPITZ_KEY_SENSE_NUM
];
229 uint16_t keyrow
[SPITZ_KEY_SENSE_NUM
];
230 uint16_t strobe_state
;
231 uint16_t sense_state
;
233 uint16_t pre_map
[0x100];
237 int fifopos
, fifolen
;
239 } SpitzKeyboardState
;
241 static void spitz_keyboard_sense_update(SpitzKeyboardState
*s
)
244 uint16_t strobe
, sense
= 0;
245 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
; i
++) {
246 strobe
= s
->keyrow
[i
] & s
->strobe_state
;
249 if (!(s
->sense_state
& (1 << i
)))
250 qemu_irq_raise(s
->sense
[i
]);
251 } else if (s
->sense_state
& (1 << i
))
252 qemu_irq_lower(s
->sense
[i
]);
255 s
->sense_state
= sense
;
258 static void spitz_keyboard_strobe(void *opaque
, int line
, int level
)
260 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
263 s
->strobe_state
|= 1 << line
;
265 s
->strobe_state
&= ~(1 << line
);
266 spitz_keyboard_sense_update(s
);
269 static void spitz_keyboard_keydown(SpitzKeyboardState
*s
, int keycode
)
271 int spitz_keycode
= s
->keymap
[keycode
& 0x7f];
272 if (spitz_keycode
== -1)
275 /* Handle the additional keys */
276 if ((spitz_keycode
>> 4) == SPITZ_KEY_SENSE_NUM
) {
277 qemu_set_irq(s
->gpiomap
[spitz_keycode
& 0xf], (keycode
< 0x80) ^
278 spitz_gpio_invert
[spitz_keycode
& 0xf]);
283 s
->keyrow
[spitz_keycode
>> 4] &= ~(1 << (spitz_keycode
& 0xf));
285 s
->keyrow
[spitz_keycode
>> 4] |= 1 << (spitz_keycode
& 0xf);
287 spitz_keyboard_sense_update(s
);
290 #define SHIFT (1 << 7)
291 #define CTRL (1 << 8)
294 #define QUEUE_KEY(c) s->fifo[(s->fifopos + s->fifolen ++) & 0xf] = c
296 static void spitz_keyboard_handler(SpitzKeyboardState
*s
, int keycode
)
301 case 0x2a: /* Left Shift */
307 case 0x36: /* Right Shift */
313 case 0x1d: /* Control */
327 code
= s
->pre_map
[mapcode
= ((s
->modifiers
& 3) ?
329 (keycode
& ~SHIFT
))];
331 if (code
!= mapcode
) {
333 if ((code
& SHIFT
) && !(s
->modifiers
& 1))
334 QUEUE_KEY(0x2a | (keycode
& 0x80));
335 if ((code
& CTRL
) && !(s
->modifiers
& 4))
336 QUEUE_KEY(0x1d | (keycode
& 0x80));
337 if ((code
& FN
) && !(s
->modifiers
& 8))
338 QUEUE_KEY(0x38 | (keycode
& 0x80));
339 if ((code
& FN
) && (s
->modifiers
& 1))
340 QUEUE_KEY(0x2a | (~keycode
& 0x80));
341 if ((code
& FN
) && (s
->modifiers
& 2))
342 QUEUE_KEY(0x36 | (~keycode
& 0x80));
344 if (keycode
& 0x80) {
345 if ((s
->imodifiers
& 1 ) && !(s
->modifiers
& 1))
346 QUEUE_KEY(0x2a | 0x80);
347 if ((s
->imodifiers
& 4 ) && !(s
->modifiers
& 4))
348 QUEUE_KEY(0x1d | 0x80);
349 if ((s
->imodifiers
& 8 ) && !(s
->modifiers
& 8))
350 QUEUE_KEY(0x38 | 0x80);
351 if ((s
->imodifiers
& 0x10) && (s
->modifiers
& 1))
353 if ((s
->imodifiers
& 0x20) && (s
->modifiers
& 2))
357 if ((code
& SHIFT
) && !((s
->modifiers
| s
->imodifiers
) & 1)) {
361 if ((code
& CTRL
) && !((s
->modifiers
| s
->imodifiers
) & 4)) {
365 if ((code
& FN
) && !((s
->modifiers
| s
->imodifiers
) & 8)) {
369 if ((code
& FN
) && (s
->modifiers
& 1) &&
370 !(s
->imodifiers
& 0x10)) {
371 QUEUE_KEY(0x2a | 0x80);
372 s
->imodifiers
|= 0x10;
374 if ((code
& FN
) && (s
->modifiers
& 2) &&
375 !(s
->imodifiers
& 0x20)) {
376 QUEUE_KEY(0x36 | 0x80);
377 s
->imodifiers
|= 0x20;
383 QUEUE_KEY((code
& 0x7f) | (keycode
& 0x80));
386 static void spitz_keyboard_tick(void *opaque
)
388 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
391 spitz_keyboard_keydown(s
, s
->fifo
[s
->fifopos
++]);
393 if (s
->fifopos
>= 16)
397 qemu_mod_timer(s
->kbdtimer
, qemu_get_clock(vm_clock
) +
398 get_ticks_per_sec() / 32);
401 static void spitz_keyboard_pre_map(SpitzKeyboardState
*s
)
404 for (i
= 0; i
< 0x100; i
++)
406 s
->pre_map
[0x02 | SHIFT
] = 0x02 | SHIFT
; /* exclam */
407 s
->pre_map
[0x28 | SHIFT
] = 0x03 | SHIFT
; /* quotedbl */
408 s
->pre_map
[0x04 | SHIFT
] = 0x04 | SHIFT
; /* numbersign */
409 s
->pre_map
[0x05 | SHIFT
] = 0x05 | SHIFT
; /* dollar */
410 s
->pre_map
[0x06 | SHIFT
] = 0x06 | SHIFT
; /* percent */
411 s
->pre_map
[0x08 | SHIFT
] = 0x07 | SHIFT
; /* ampersand */
412 s
->pre_map
[0x28 ] = 0x08 | SHIFT
; /* apostrophe */
413 s
->pre_map
[0x0a | SHIFT
] = 0x09 | SHIFT
; /* parenleft */
414 s
->pre_map
[0x0b | SHIFT
] = 0x0a | SHIFT
; /* parenright */
415 s
->pre_map
[0x29 | SHIFT
] = 0x0b | SHIFT
; /* asciitilde */
416 s
->pre_map
[0x03 | SHIFT
] = 0x0c | SHIFT
; /* at */
417 s
->pre_map
[0xd3 ] = 0x0e | FN
; /* Delete */
418 s
->pre_map
[0x3a ] = 0x0f | FN
; /* Caps_Lock */
419 s
->pre_map
[0x07 | SHIFT
] = 0x11 | FN
; /* asciicircum */
420 s
->pre_map
[0x0d ] = 0x12 | FN
; /* equal */
421 s
->pre_map
[0x0d | SHIFT
] = 0x13 | FN
; /* plus */
422 s
->pre_map
[0x1a ] = 0x14 | FN
; /* bracketleft */
423 s
->pre_map
[0x1b ] = 0x15 | FN
; /* bracketright */
424 s
->pre_map
[0x1a | SHIFT
] = 0x16 | FN
; /* braceleft */
425 s
->pre_map
[0x1b | SHIFT
] = 0x17 | FN
; /* braceright */
426 s
->pre_map
[0x27 ] = 0x22 | FN
; /* semicolon */
427 s
->pre_map
[0x27 | SHIFT
] = 0x23 | FN
; /* colon */
428 s
->pre_map
[0x09 | SHIFT
] = 0x24 | FN
; /* asterisk */
429 s
->pre_map
[0x2b ] = 0x25 | FN
; /* backslash */
430 s
->pre_map
[0x2b | SHIFT
] = 0x26 | FN
; /* bar */
431 s
->pre_map
[0x0c | SHIFT
] = 0x30 | FN
; /* underscore */
432 s
->pre_map
[0x33 | SHIFT
] = 0x33 | FN
; /* less */
433 s
->pre_map
[0x35 ] = 0x33 | SHIFT
; /* slash */
434 s
->pre_map
[0x34 | SHIFT
] = 0x34 | FN
; /* greater */
435 s
->pre_map
[0x35 | SHIFT
] = 0x34 | SHIFT
; /* question */
436 s
->pre_map
[0x49 ] = 0x48 | FN
; /* Page_Up */
437 s
->pre_map
[0x51 ] = 0x50 | FN
; /* Page_Down */
443 s
->kbdtimer
= qemu_new_timer(vm_clock
, spitz_keyboard_tick
, s
);
444 spitz_keyboard_tick(s
);
451 static void spitz_keyboard_save(QEMUFile
*f
, void *opaque
)
453 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
456 qemu_put_be16s(f
, &s
->sense_state
);
457 qemu_put_be16s(f
, &s
->strobe_state
);
458 for (i
= 0; i
< 5; i
++)
459 qemu_put_byte(f
, spitz_gpio_invert
[i
]);
462 static int spitz_keyboard_load(QEMUFile
*f
, void *opaque
, int version_id
)
464 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
467 qemu_get_be16s(f
, &s
->sense_state
);
468 qemu_get_be16s(f
, &s
->strobe_state
);
469 for (i
= 0; i
< 5; i
++)
470 spitz_gpio_invert
[i
] = qemu_get_byte(f
);
472 /* Release all pressed keys */
473 memset(s
->keyrow
, 0, sizeof(s
->keyrow
));
474 spitz_keyboard_sense_update(s
);
483 static void spitz_keyboard_register(PXA2xxState
*cpu
)
486 SpitzKeyboardState
*s
;
488 s
= (SpitzKeyboardState
*)
489 qemu_mallocz(sizeof(SpitzKeyboardState
));
490 memset(s
, 0, sizeof(SpitzKeyboardState
));
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 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
; i
++)
500 s
->sense
[i
] = pxa2xx_gpio_in_get(cpu
->gpio
)[spitz_gpio_key_sense
[i
]];
502 for (i
= 0; i
< 5; i
++)
503 s
->gpiomap
[i
] = pxa2xx_gpio_in_get(cpu
->gpio
)[spitz_gpiomap
[i
]];
505 s
->strobe
= qemu_allocate_irqs(spitz_keyboard_strobe
, s
,
506 SPITZ_KEY_STROBE_NUM
);
507 for (i
= 0; i
< SPITZ_KEY_STROBE_NUM
; i
++)
508 pxa2xx_gpio_out_set(cpu
->gpio
, spitz_gpio_key_strobe
[i
], s
->strobe
[i
]);
510 spitz_keyboard_pre_map(s
);
511 qemu_add_kbd_event_handler((QEMUPutKBDEvent
*) spitz_keyboard_handler
, s
);
513 register_savevm(NULL
, "spitz_keyboard", 0, 0,
514 spitz_keyboard_save
, spitz_keyboard_load
, s
);
517 /* LCD backlight controller */
519 #define LCDTG_RESCTL 0x00
520 #define LCDTG_PHACTRL 0x01
521 #define LCDTG_DUTYCTRL 0x02
522 #define LCDTG_POWERREG0 0x03
523 #define LCDTG_POWERREG1 0x04
524 #define LCDTG_GPOR3 0x05
525 #define LCDTG_PICTRL 0x06
526 #define LCDTG_POLCTRL 0x07
534 static void spitz_bl_update(SpitzLCDTG
*s
)
536 if (s
->bl_power
&& s
->bl_intensity
)
537 zaurus_printf("LCD Backlight now at %i/63\n", s
->bl_intensity
);
539 zaurus_printf("LCD Backlight now off\n");
542 /* FIXME: Implement GPIO properly and remove this hack. */
543 static SpitzLCDTG
*spitz_lcdtg
;
545 static inline void spitz_bl_bit5(void *opaque
, int line
, int level
)
547 SpitzLCDTG
*s
= spitz_lcdtg
;
548 int prev
= s
->bl_intensity
;
551 s
->bl_intensity
&= ~0x20;
553 s
->bl_intensity
|= 0x20;
555 if (s
->bl_power
&& prev
!= s
->bl_intensity
)
559 static inline void spitz_bl_power(void *opaque
, int line
, int level
)
561 SpitzLCDTG
*s
= spitz_lcdtg
;
562 s
->bl_power
= !!level
;
566 static uint32_t spitz_lcdtg_transfer(SSISlave
*dev
, uint32_t value
)
568 SpitzLCDTG
*s
= FROM_SSI_SLAVE(SpitzLCDTG
, dev
);
576 zaurus_printf("LCD in QVGA mode\n");
578 zaurus_printf("LCD in VGA mode\n");
582 s
->bl_intensity
&= ~0x1f;
583 s
->bl_intensity
|= value
;
588 case LCDTG_POWERREG0
:
589 /* Set common voltage to M62332FP */
595 static void spitz_lcdtg_save(QEMUFile
*f
, void *opaque
)
597 SpitzLCDTG
*s
= (SpitzLCDTG
*)opaque
;
598 qemu_put_be32(f
, s
->bl_intensity
);
599 qemu_put_be32(f
, s
->bl_power
);
602 static int spitz_lcdtg_load(QEMUFile
*f
, void *opaque
, int version_id
)
604 SpitzLCDTG
*s
= (SpitzLCDTG
*)opaque
;
605 s
->bl_intensity
= qemu_get_be32(f
);
606 s
->bl_power
= qemu_get_be32(f
);
610 static int spitz_lcdtg_init(SSISlave
*dev
)
612 SpitzLCDTG
*s
= FROM_SSI_SLAVE(SpitzLCDTG
, dev
);
616 s
->bl_intensity
= 0x20;
618 register_savevm(&dev
->qdev
, "spitz-lcdtg", -1, 1,
619 spitz_lcdtg_save
, spitz_lcdtg_load
, s
);
625 #define CORGI_SSP_PORT 2
627 #define SPITZ_GPIO_LCDCON_CS 53
628 #define SPITZ_GPIO_ADS7846_CS 14
629 #define SPITZ_GPIO_MAX1111_CS 20
630 #define SPITZ_GPIO_TP_INT 11
632 static DeviceState
*max1111
;
634 /* "Demux" the signal based on current chipselect */
641 static uint32_t corgi_ssp_transfer(SSISlave
*dev
, uint32_t value
)
643 CorgiSSPState
*s
= FROM_SSI_SLAVE(CorgiSSPState
, dev
);
646 for (i
= 0; i
< 3; i
++) {
648 return ssi_transfer(s
->bus
[i
], value
);
654 static void corgi_ssp_gpio_cs(void *opaque
, int line
, int level
)
656 CorgiSSPState
*s
= (CorgiSSPState
*)opaque
;
657 assert(line
>= 0 && line
< 3);
658 s
->enable
[line
] = !level
;
661 #define MAX1111_BATT_VOLT 1
662 #define MAX1111_BATT_TEMP 2
663 #define MAX1111_ACIN_VOLT 3
665 #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */
666 #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */
667 #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */
669 static void spitz_adc_temp_on(void *opaque
, int line
, int level
)
675 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, SPITZ_BATTERY_TEMP
);
677 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
680 static void spitz_ssp_save(QEMUFile
*f
, void *opaque
)
682 CorgiSSPState
*s
= (CorgiSSPState
*)opaque
;
685 for (i
= 0; i
< 3; i
++) {
686 qemu_put_be32(f
, s
->enable
[i
]);
690 static int spitz_ssp_load(QEMUFile
*f
, void *opaque
, int version_id
)
692 CorgiSSPState
*s
= (CorgiSSPState
*)opaque
;
695 if (version_id
!= 1) {
698 for (i
= 0; i
< 3; i
++) {
699 s
->enable
[i
] = qemu_get_be32(f
);
704 static int corgi_ssp_init(SSISlave
*dev
)
706 CorgiSSPState
*s
= FROM_SSI_SLAVE(CorgiSSPState
, dev
);
708 qdev_init_gpio_in(&dev
->qdev
, corgi_ssp_gpio_cs
, 3);
709 s
->bus
[0] = ssi_create_bus(&dev
->qdev
, "ssi0");
710 s
->bus
[1] = ssi_create_bus(&dev
->qdev
, "ssi1");
711 s
->bus
[2] = ssi_create_bus(&dev
->qdev
, "ssi2");
713 register_savevm(&dev
->qdev
, "spitz_ssp", -1, 1,
714 spitz_ssp_save
, spitz_ssp_load
, s
);
718 static void spitz_ssp_attach(PXA2xxState
*cpu
)
724 mux
= ssi_create_slave(cpu
->ssp
[CORGI_SSP_PORT
- 1], "corgi-ssp");
726 bus
= qdev_get_child_bus(mux
, "ssi0");
727 ssi_create_slave(bus
, "spitz-lcdtg");
729 bus
= qdev_get_child_bus(mux
, "ssi1");
730 dev
= ssi_create_slave(bus
, "ads7846");
731 qdev_connect_gpio_out(dev
, 0,
732 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_TP_INT
]);
734 bus
= qdev_get_child_bus(mux
, "ssi2");
735 max1111
= ssi_create_slave(bus
, "max1111");
736 max111x_set_input(max1111
, MAX1111_BATT_VOLT
, SPITZ_BATTERY_VOLT
);
737 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
738 max111x_set_input(max1111
, MAX1111_ACIN_VOLT
, SPITZ_CHARGEON_ACIN
);
740 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_LCDCON_CS
,
741 qdev_get_gpio_in(mux
, 0));
742 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_ADS7846_CS
,
743 qdev_get_gpio_in(mux
, 1));
744 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_MAX1111_CS
,
745 qdev_get_gpio_in(mux
, 2));
750 static void spitz_microdrive_attach(PXA2xxState
*cpu
, int slot
)
753 BlockDriverState
*bs
;
756 dinfo
= drive_get(IF_IDE
, 0, 0);
760 if (bdrv_is_inserted(bs
) && !bdrv_is_removable(bs
)) {
761 md
= dscm1xxxx_init(dinfo
);
762 pxa2xx_pcmcia_attach(cpu
->pcmcia
[slot
], md
);
766 /* Wm8750 and Max7310 on I2C */
768 #define AKITA_MAX_ADDR 0x18
769 #define SPITZ_WM_ADDRL 0x1b
770 #define SPITZ_WM_ADDRH 0x1a
772 #define SPITZ_GPIO_WM 5
774 static void spitz_wm8750_addr(void *opaque
, int line
, int level
)
776 i2c_slave
*wm
= (i2c_slave
*) opaque
;
778 i2c_set_slave_address(wm
, SPITZ_WM_ADDRH
);
780 i2c_set_slave_address(wm
, SPITZ_WM_ADDRL
);
783 static void spitz_i2c_setup(PXA2xxState
*cpu
)
785 /* Attach the CPU on one end of our I2C bus. */
786 i2c_bus
*bus
= pxa2xx_i2c_bus(cpu
->i2c
[0]);
790 /* Attach a WM8750 to the bus */
791 wm
= i2c_create_slave(bus
, "wm8750", 0);
793 spitz_wm8750_addr(wm
, 0, 0);
794 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_WM
,
795 qemu_allocate_irqs(spitz_wm8750_addr
, wm
, 1)[0]);
796 /* .. and to the sound interface. */
797 cpu
->i2s
->opaque
= wm
;
798 cpu
->i2s
->codec_out
= wm8750_dac_dat
;
799 cpu
->i2s
->codec_in
= wm8750_adc_dat
;
800 wm8750_data_req_set(wm
, cpu
->i2s
->data_req
, cpu
->i2s
);
803 static void spitz_akita_i2c_setup(PXA2xxState
*cpu
)
805 /* Attach a Max7310 to Akita I2C bus. */
806 i2c_create_slave(pxa2xx_i2c_bus(cpu
->i2c
[0]), "max7310",
810 /* Other peripherals */
812 static void spitz_out_switch(void *opaque
, int line
, int level
)
816 zaurus_printf("Charging %s.\n", level
? "off" : "on");
819 zaurus_printf("Discharging %s.\n", level
? "on" : "off");
822 zaurus_printf("Green LED %s.\n", level
? "on" : "off");
825 zaurus_printf("Orange LED %s.\n", level
? "on" : "off");
828 spitz_bl_bit5(opaque
, line
, level
);
831 spitz_bl_power(opaque
, line
, level
);
834 spitz_adc_temp_on(opaque
, line
, level
);
839 #define SPITZ_SCP_LED_GREEN 1
840 #define SPITZ_SCP_JK_B 2
841 #define SPITZ_SCP_CHRG_ON 3
842 #define SPITZ_SCP_MUTE_L 4
843 #define SPITZ_SCP_MUTE_R 5
844 #define SPITZ_SCP_CF_POWER 6
845 #define SPITZ_SCP_LED_ORANGE 7
846 #define SPITZ_SCP_JK_A 8
847 #define SPITZ_SCP_ADC_TEMP_ON 9
848 #define SPITZ_SCP2_IR_ON 1
849 #define SPITZ_SCP2_AKIN_PULLUP 2
850 #define SPITZ_SCP2_BACKLIGHT_CONT 7
851 #define SPITZ_SCP2_BACKLIGHT_ON 8
852 #define SPITZ_SCP2_MIC_BIAS 9
854 static void spitz_scoop_gpio_setup(PXA2xxState
*cpu
,
855 DeviceState
*scp0
, DeviceState
*scp1
)
857 qemu_irq
*outsignals
= qemu_allocate_irqs(spitz_out_switch
, cpu
, 8);
859 qdev_connect_gpio_out(scp0
, SPITZ_SCP_CHRG_ON
, outsignals
[0]);
860 qdev_connect_gpio_out(scp0
, SPITZ_SCP_JK_B
, outsignals
[1]);
861 qdev_connect_gpio_out(scp0
, SPITZ_SCP_LED_GREEN
, outsignals
[2]);
862 qdev_connect_gpio_out(scp0
, SPITZ_SCP_LED_ORANGE
, outsignals
[3]);
865 qdev_connect_gpio_out(scp1
, SPITZ_SCP2_BACKLIGHT_CONT
, outsignals
[4]);
866 qdev_connect_gpio_out(scp1
, SPITZ_SCP2_BACKLIGHT_ON
, outsignals
[5]);
869 qdev_connect_gpio_out(scp0
, SPITZ_SCP_ADC_TEMP_ON
, outsignals
[6]);
872 #define SPITZ_GPIO_HSYNC 22
873 #define SPITZ_GPIO_SD_DETECT 9
874 #define SPITZ_GPIO_SD_WP 81
875 #define SPITZ_GPIO_ON_RESET 89
876 #define SPITZ_GPIO_BAT_COVER 90
877 #define SPITZ_GPIO_CF1_IRQ 105
878 #define SPITZ_GPIO_CF1_CD 94
879 #define SPITZ_GPIO_CF2_IRQ 106
880 #define SPITZ_GPIO_CF2_CD 93
882 static int spitz_hsync
;
884 static void spitz_lcd_hsync_handler(void *opaque
, int line
, int level
)
886 PXA2xxState
*cpu
= (PXA2xxState
*) opaque
;
887 qemu_set_irq(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_HSYNC
], spitz_hsync
);
891 static void spitz_gpio_setup(PXA2xxState
*cpu
, int slots
)
895 * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
896 * read to satisfy broken guests that poll-wait for hsync.
897 * Simulating a real hsync event would be less practical and
898 * wouldn't guarantee that a guest ever exits the loop.
901 lcd_hsync
= qemu_allocate_irqs(spitz_lcd_hsync_handler
, cpu
, 1)[0];
902 pxa2xx_gpio_read_notifier(cpu
->gpio
, lcd_hsync
);
903 pxa2xx_lcd_vsync_notifier(cpu
->lcd
, lcd_hsync
);
906 pxa2xx_mmci_handlers(cpu
->mmc
,
907 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SD_WP
],
908 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SD_DETECT
]);
910 /* Battery lock always closed */
911 qemu_irq_raise(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_BAT_COVER
]);
914 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_ON_RESET
, cpu
->reset
);
916 /* PCMCIA signals: card's IRQ and Card-Detect */
918 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[0],
919 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF1_IRQ
],
920 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF1_CD
]);
922 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[1],
923 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF2_IRQ
],
924 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF2_CD
]);
926 /* Initialise the screen rotation related signals */
927 spitz_gpio_invert
[3] = 0; /* Always open */
928 if (graphic_rotate
) { /* Tablet mode */
929 spitz_gpio_invert
[4] = 0;
930 } else { /* Portrait mode */
931 spitz_gpio_invert
[4] = 1;
933 qemu_set_irq(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SWA
],
934 spitz_gpio_invert
[3]);
935 qemu_set_irq(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SWB
],
936 spitz_gpio_invert
[4]);
940 enum spitz_model_e
{ spitz
, akita
, borzoi
, terrier
};
942 #define SPITZ_RAM 0x04000000
943 #define SPITZ_ROM 0x00800000
945 static struct arm_boot_info spitz_binfo
= {
946 .loader_start
= PXA2XX_SDRAM_BASE
,
947 .ram_size
= 0x04000000,
950 static void spitz_common_init(ram_addr_t ram_size
,
951 const char *kernel_filename
,
952 const char *kernel_cmdline
, const char *initrd_filename
,
953 const char *cpu_model
, enum spitz_model_e model
, int arm_id
)
956 DeviceState
*scp0
, *scp1
= NULL
;
959 cpu_model
= (model
== terrier
) ? "pxa270-c5" : "pxa270-c0";
961 /* Setup CPU & memory */
962 cpu
= pxa270_init(spitz_binfo
.ram_size
, cpu_model
);
964 sl_flash_register(cpu
, (model
== spitz
) ? FLASH_128M
: FLASH_1024M
);
966 cpu_register_physical_memory(0, SPITZ_ROM
,
967 qemu_ram_alloc(NULL
, "spitz.rom", SPITZ_ROM
) | IO_MEM_ROM
);
969 /* Setup peripherals */
970 spitz_keyboard_register(cpu
);
972 spitz_ssp_attach(cpu
);
974 scp0
= sysbus_create_simple("scoop", 0x10800000, NULL
);
975 if (model
!= akita
) {
976 scp1
= sysbus_create_simple("scoop", 0x08800040, NULL
);
979 spitz_scoop_gpio_setup(cpu
, scp0
, scp1
);
981 spitz_gpio_setup(cpu
, (model
== akita
) ? 1 : 2);
983 spitz_i2c_setup(cpu
);
986 spitz_akita_i2c_setup(cpu
);
988 if (model
== terrier
)
989 /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
990 spitz_microdrive_attach(cpu
, 1);
991 else if (model
!= akita
)
992 /* A 4.0 GB microdrive is permanently sitting in CF slot 0. */
993 spitz_microdrive_attach(cpu
, 0);
995 spitz_binfo
.kernel_filename
= kernel_filename
;
996 spitz_binfo
.kernel_cmdline
= kernel_cmdline
;
997 spitz_binfo
.initrd_filename
= initrd_filename
;
998 spitz_binfo
.board_id
= arm_id
;
999 arm_load_kernel(cpu
->env
, &spitz_binfo
);
1000 sl_bootparam_write(SL_PXA_PARAM_BASE
);
1003 static void spitz_init(ram_addr_t ram_size
,
1004 const char *boot_device
,
1005 const char *kernel_filename
, const char *kernel_cmdline
,
1006 const char *initrd_filename
, const char *cpu_model
)
1008 spitz_common_init(ram_size
, kernel_filename
,
1009 kernel_cmdline
, initrd_filename
, cpu_model
, spitz
, 0x2c9);
1012 static void borzoi_init(ram_addr_t ram_size
,
1013 const char *boot_device
,
1014 const char *kernel_filename
, const char *kernel_cmdline
,
1015 const char *initrd_filename
, const char *cpu_model
)
1017 spitz_common_init(ram_size
, kernel_filename
,
1018 kernel_cmdline
, initrd_filename
, cpu_model
, borzoi
, 0x33f);
1021 static void akita_init(ram_addr_t ram_size
,
1022 const char *boot_device
,
1023 const char *kernel_filename
, const char *kernel_cmdline
,
1024 const char *initrd_filename
, const char *cpu_model
)
1026 spitz_common_init(ram_size
, kernel_filename
,
1027 kernel_cmdline
, initrd_filename
, cpu_model
, akita
, 0x2e8);
1030 static void terrier_init(ram_addr_t ram_size
,
1031 const char *boot_device
,
1032 const char *kernel_filename
, const char *kernel_cmdline
,
1033 const char *initrd_filename
, const char *cpu_model
)
1035 spitz_common_init(ram_size
, kernel_filename
,
1036 kernel_cmdline
, initrd_filename
, cpu_model
, terrier
, 0x33f);
1039 static QEMUMachine akitapda_machine
= {
1041 .desc
= "Akita PDA (PXA270)",
1045 static QEMUMachine spitzpda_machine
= {
1047 .desc
= "Spitz PDA (PXA270)",
1051 static QEMUMachine borzoipda_machine
= {
1053 .desc
= "Borzoi PDA (PXA270)",
1054 .init
= borzoi_init
,
1057 static QEMUMachine terrierpda_machine
= {
1059 .desc
= "Terrier PDA (PXA270)",
1060 .init
= terrier_init
,
1063 static void spitz_machine_init(void)
1065 qemu_register_machine(&akitapda_machine
);
1066 qemu_register_machine(&spitzpda_machine
);
1067 qemu_register_machine(&borzoipda_machine
);
1068 qemu_register_machine(&terrierpda_machine
);
1071 machine_init(spitz_machine_init
);
1073 static SSISlaveInfo corgi_ssp_info
= {
1074 .qdev
.name
= "corgi-ssp",
1075 .qdev
.size
= sizeof(CorgiSSPState
),
1076 .init
= corgi_ssp_init
,
1077 .transfer
= corgi_ssp_transfer
1080 static SSISlaveInfo spitz_lcdtg_info
= {
1081 .qdev
.name
= "spitz-lcdtg",
1082 .qdev
.size
= sizeof(SpitzLCDTG
),
1083 .init
= spitz_lcdtg_init
,
1084 .transfer
= spitz_lcdtg_transfer
1087 static void spitz_register_devices(void)
1089 ssi_register_slave(&corgi_ssp_info
);
1090 ssi_register_slave(&spitz_lcdtg_info
);
1093 device_init(spitz_register_devices
)