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)
58 static uint32_t sl_readb(void *opaque
, target_phys_addr_t addr
)
60 SLNANDState
*s
= (SLNANDState
*) opaque
;
64 #define BSHR(byte, from, to) ((s->ecc.lp[byte] >> (from - to)) & (1 << to))
66 return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) |
67 BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7);
69 #define BSHL(byte, from, to) ((s->ecc.lp[byte] << (to - from)) & (1 << to))
71 return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) |
72 BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7);
78 return s
->ecc
.count
& 0xff;
81 nand_getpins(s
->nand
, &ryby
);
83 return s
->ctl
| FLASHCTL_RYBY
;
88 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
));
91 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
96 static uint32_t sl_readl(void *opaque
, target_phys_addr_t addr
)
98 SLNANDState
*s
= (SLNANDState
*) opaque
;
100 if (addr
== FLASH_FLASHIO
)
101 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) |
102 (ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) << 16);
104 return sl_readb(opaque
, addr
);
107 static void sl_writeb(void *opaque
, target_phys_addr_t addr
,
110 SLNANDState
*s
= (SLNANDState
*) opaque
;
114 /* Value is ignored. */
119 s
->ctl
= value
& 0xff & ~FLASHCTL_RYBY
;
120 nand_setpins(s
->nand
,
121 s
->ctl
& FLASHCTL_CLE
,
122 s
->ctl
& FLASHCTL_ALE
,
123 s
->ctl
& FLASHCTL_NCE
,
124 s
->ctl
& FLASHCTL_WP
,
129 nand_setio(s
->nand
, ecc_digest(&s
->ecc
, value
& 0xff));
133 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
142 static CPUReadMemoryFunc
* const sl_readfn
[] = {
147 static CPUWriteMemoryFunc
* const sl_writefn
[] = {
153 static void sl_flash_register(PXA2xxState
*cpu
, int size
)
157 dev
= qdev_create(NULL
, "sl-nand");
159 qdev_prop_set_uint8(dev
, "manf_id", NAND_MFR_SAMSUNG
);
160 if (size
== FLASH_128M
)
161 qdev_prop_set_uint8(dev
, "chip_id", 0x73);
162 else if (size
== FLASH_1024M
)
163 qdev_prop_set_uint8(dev
, "chip_id", 0xf1);
165 qdev_init_nofail(dev
);
166 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, FLASH_BASE
);
169 static int sl_nand_init(SysBusDevice
*dev
) {
174 s
= FROM_SYSBUS(SLNANDState
, dev
);
177 nand
= drive_get(IF_MTD
, 0, 0);
178 s
->nand
= nand_init(nand
? nand
->bdrv
: NULL
, s
->manf_id
, s
->chip_id
);
180 iomemtype
= cpu_register_io_memory(sl_readfn
,
181 sl_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
183 sysbus_init_mmio(dev
, 0x40, iomemtype
);
190 #define SPITZ_KEY_STROBE_NUM 11
191 #define SPITZ_KEY_SENSE_NUM 7
193 static const int spitz_gpio_key_sense
[SPITZ_KEY_SENSE_NUM
] = {
194 12, 17, 91, 34, 36, 38, 39
197 static const int spitz_gpio_key_strobe
[SPITZ_KEY_STROBE_NUM
] = {
198 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114
201 /* Eighth additional row maps the special keys */
202 static int spitz_keymap
[SPITZ_KEY_SENSE_NUM
+ 1][SPITZ_KEY_STROBE_NUM
] = {
203 { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 },
204 { -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 },
205 { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25, -1 , -1 , -1 },
206 { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26, -1 , 0x36, -1 },
207 { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34, -1 , 0x1c, 0x2a, -1 },
208 { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33, -1 , 0x48, -1 , -1 , 0x38 },
209 { 0x37, 0x3d, -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d, -1 , -1 },
210 { 0x52, 0x43, 0x01, 0x47, 0x49, -1 , -1 , -1 , -1 , -1 , -1 },
213 #define SPITZ_GPIO_AK_INT 13 /* Remote control */
214 #define SPITZ_GPIO_SYNC 16 /* Sync button */
215 #define SPITZ_GPIO_ON_KEY 95 /* Power button */
216 #define SPITZ_GPIO_SWA 97 /* Lid */
217 #define SPITZ_GPIO_SWB 96 /* Tablet mode */
219 /* The special buttons are mapped to unused keys */
220 static const int spitz_gpiomap
[5] = {
221 SPITZ_GPIO_AK_INT
, SPITZ_GPIO_SYNC
, SPITZ_GPIO_ON_KEY
,
222 SPITZ_GPIO_SWA
, SPITZ_GPIO_SWB
,
227 qemu_irq sense
[SPITZ_KEY_SENSE_NUM
];
230 uint16_t keyrow
[SPITZ_KEY_SENSE_NUM
];
231 uint16_t strobe_state
;
232 uint16_t sense_state
;
234 uint16_t pre_map
[0x100];
238 int fifopos
, fifolen
;
240 } SpitzKeyboardState
;
242 static void spitz_keyboard_sense_update(SpitzKeyboardState
*s
)
245 uint16_t strobe
, sense
= 0;
246 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
; i
++) {
247 strobe
= s
->keyrow
[i
] & s
->strobe_state
;
250 if (!(s
->sense_state
& (1 << i
)))
251 qemu_irq_raise(s
->sense
[i
]);
252 } else if (s
->sense_state
& (1 << i
))
253 qemu_irq_lower(s
->sense
[i
]);
256 s
->sense_state
= sense
;
259 static void spitz_keyboard_strobe(void *opaque
, int line
, int level
)
261 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
264 s
->strobe_state
|= 1 << line
;
266 s
->strobe_state
&= ~(1 << line
);
267 spitz_keyboard_sense_update(s
);
270 static void spitz_keyboard_keydown(SpitzKeyboardState
*s
, int keycode
)
272 int spitz_keycode
= s
->keymap
[keycode
& 0x7f];
273 if (spitz_keycode
== -1)
276 /* Handle the additional keys */
277 if ((spitz_keycode
>> 4) == SPITZ_KEY_SENSE_NUM
) {
278 qemu_set_irq(s
->gpiomap
[spitz_keycode
& 0xf], (keycode
< 0x80));
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(void *opaque
, int keycode
)
298 SpitzKeyboardState
*s
= opaque
;
302 case 0x2a: /* Left Shift */
308 case 0x36: /* Right Shift */
314 case 0x1d: /* Control */
328 code
= s
->pre_map
[mapcode
= ((s
->modifiers
& 3) ?
330 (keycode
& ~SHIFT
))];
332 if (code
!= mapcode
) {
334 if ((code
& SHIFT
) && !(s
->modifiers
& 1))
335 QUEUE_KEY(0x2a | (keycode
& 0x80));
336 if ((code
& CTRL
) && !(s
->modifiers
& 4))
337 QUEUE_KEY(0x1d | (keycode
& 0x80));
338 if ((code
& FN
) && !(s
->modifiers
& 8))
339 QUEUE_KEY(0x38 | (keycode
& 0x80));
340 if ((code
& FN
) && (s
->modifiers
& 1))
341 QUEUE_KEY(0x2a | (~keycode
& 0x80));
342 if ((code
& FN
) && (s
->modifiers
& 2))
343 QUEUE_KEY(0x36 | (~keycode
& 0x80));
345 if (keycode
& 0x80) {
346 if ((s
->imodifiers
& 1 ) && !(s
->modifiers
& 1))
347 QUEUE_KEY(0x2a | 0x80);
348 if ((s
->imodifiers
& 4 ) && !(s
->modifiers
& 4))
349 QUEUE_KEY(0x1d | 0x80);
350 if ((s
->imodifiers
& 8 ) && !(s
->modifiers
& 8))
351 QUEUE_KEY(0x38 | 0x80);
352 if ((s
->imodifiers
& 0x10) && (s
->modifiers
& 1))
354 if ((s
->imodifiers
& 0x20) && (s
->modifiers
& 2))
358 if ((code
& SHIFT
) && !((s
->modifiers
| s
->imodifiers
) & 1)) {
362 if ((code
& CTRL
) && !((s
->modifiers
| s
->imodifiers
) & 4)) {
366 if ((code
& FN
) && !((s
->modifiers
| s
->imodifiers
) & 8)) {
370 if ((code
& FN
) && (s
->modifiers
& 1) &&
371 !(s
->imodifiers
& 0x10)) {
372 QUEUE_KEY(0x2a | 0x80);
373 s
->imodifiers
|= 0x10;
375 if ((code
& FN
) && (s
->modifiers
& 2) &&
376 !(s
->imodifiers
& 0x20)) {
377 QUEUE_KEY(0x36 | 0x80);
378 s
->imodifiers
|= 0x20;
384 QUEUE_KEY((code
& 0x7f) | (keycode
& 0x80));
387 static void spitz_keyboard_tick(void *opaque
)
389 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
392 spitz_keyboard_keydown(s
, s
->fifo
[s
->fifopos
++]);
394 if (s
->fifopos
>= 16)
398 qemu_mod_timer(s
->kbdtimer
, qemu_get_clock_ns(vm_clock
) +
399 get_ticks_per_sec() / 32);
402 static void spitz_keyboard_pre_map(SpitzKeyboardState
*s
)
405 for (i
= 0; i
< 0x100; i
++)
407 s
->pre_map
[0x02 | SHIFT
] = 0x02 | SHIFT
; /* exclam */
408 s
->pre_map
[0x28 | SHIFT
] = 0x03 | SHIFT
; /* quotedbl */
409 s
->pre_map
[0x04 | SHIFT
] = 0x04 | SHIFT
; /* numbersign */
410 s
->pre_map
[0x05 | SHIFT
] = 0x05 | SHIFT
; /* dollar */
411 s
->pre_map
[0x06 | SHIFT
] = 0x06 | SHIFT
; /* percent */
412 s
->pre_map
[0x08 | SHIFT
] = 0x07 | SHIFT
; /* ampersand */
413 s
->pre_map
[0x28 ] = 0x08 | SHIFT
; /* apostrophe */
414 s
->pre_map
[0x0a | SHIFT
] = 0x09 | SHIFT
; /* parenleft */
415 s
->pre_map
[0x0b | SHIFT
] = 0x0a | SHIFT
; /* parenright */
416 s
->pre_map
[0x29 | SHIFT
] = 0x0b | SHIFT
; /* asciitilde */
417 s
->pre_map
[0x03 | SHIFT
] = 0x0c | SHIFT
; /* at */
418 s
->pre_map
[0xd3 ] = 0x0e | FN
; /* Delete */
419 s
->pre_map
[0x3a ] = 0x0f | FN
; /* Caps_Lock */
420 s
->pre_map
[0x07 | SHIFT
] = 0x11 | FN
; /* asciicircum */
421 s
->pre_map
[0x0d ] = 0x12 | FN
; /* equal */
422 s
->pre_map
[0x0d | SHIFT
] = 0x13 | FN
; /* plus */
423 s
->pre_map
[0x1a ] = 0x14 | FN
; /* bracketleft */
424 s
->pre_map
[0x1b ] = 0x15 | FN
; /* bracketright */
425 s
->pre_map
[0x1a | SHIFT
] = 0x16 | FN
; /* braceleft */
426 s
->pre_map
[0x1b | SHIFT
] = 0x17 | FN
; /* braceright */
427 s
->pre_map
[0x27 ] = 0x22 | FN
; /* semicolon */
428 s
->pre_map
[0x27 | SHIFT
] = 0x23 | FN
; /* colon */
429 s
->pre_map
[0x09 | SHIFT
] = 0x24 | FN
; /* asterisk */
430 s
->pre_map
[0x2b ] = 0x25 | FN
; /* backslash */
431 s
->pre_map
[0x2b | SHIFT
] = 0x26 | FN
; /* bar */
432 s
->pre_map
[0x0c | SHIFT
] = 0x30 | FN
; /* underscore */
433 s
->pre_map
[0x33 | SHIFT
] = 0x33 | FN
; /* less */
434 s
->pre_map
[0x35 ] = 0x33 | SHIFT
; /* slash */
435 s
->pre_map
[0x34 | SHIFT
] = 0x34 | FN
; /* greater */
436 s
->pre_map
[0x35 | SHIFT
] = 0x34 | SHIFT
; /* question */
437 s
->pre_map
[0x49 ] = 0x48 | FN
; /* Page_Up */
438 s
->pre_map
[0x51 ] = 0x50 | FN
; /* Page_Down */
450 static int spitz_keyboard_post_load(void *opaque
, int version_id
)
452 SpitzKeyboardState
*s
= (SpitzKeyboardState
*) opaque
;
454 /* Release all pressed keys */
455 memset(s
->keyrow
, 0, sizeof(s
->keyrow
));
456 spitz_keyboard_sense_update(s
);
465 static void spitz_keyboard_register(PXA2xxState
*cpu
)
469 SpitzKeyboardState
*s
;
471 dev
= sysbus_create_simple("spitz-keyboard", -1, NULL
);
472 s
= FROM_SYSBUS(SpitzKeyboardState
, sysbus_from_qdev(dev
));
474 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
; i
++)
475 qdev_connect_gpio_out(dev
, i
, qdev_get_gpio_in(cpu
->gpio
, spitz_gpio_key_sense
[i
]));
477 for (i
= 0; i
< 5; i
++)
478 s
->gpiomap
[i
] = qdev_get_gpio_in(cpu
->gpio
, spitz_gpiomap
[i
]);
481 s
->gpiomap
[4] = qemu_irq_invert(s
->gpiomap
[4]);
483 for (i
= 0; i
< 5; i
++)
484 qemu_set_irq(s
->gpiomap
[i
], 0);
486 for (i
= 0; i
< SPITZ_KEY_STROBE_NUM
; i
++)
487 qdev_connect_gpio_out(cpu
->gpio
, spitz_gpio_key_strobe
[i
],
488 qdev_get_gpio_in(dev
, i
));
490 qemu_mod_timer(s
->kbdtimer
, qemu_get_clock_ns(vm_clock
));
492 qemu_add_kbd_event_handler(spitz_keyboard_handler
, s
);
495 static int spitz_keyboard_init(SysBusDevice
*dev
)
497 SpitzKeyboardState
*s
;
500 s
= FROM_SYSBUS(SpitzKeyboardState
, dev
);
502 for (i
= 0; i
< 0x80; i
++)
504 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
+ 1; i
++)
505 for (j
= 0; j
< SPITZ_KEY_STROBE_NUM
; j
++)
506 if (spitz_keymap
[i
][j
] != -1)
507 s
->keymap
[spitz_keymap
[i
][j
]] = (i
<< 4) | j
;
509 spitz_keyboard_pre_map(s
);
511 s
->kbdtimer
= qemu_new_timer_ns(vm_clock
, spitz_keyboard_tick
, s
);
512 qdev_init_gpio_in(&dev
->qdev
, spitz_keyboard_strobe
, SPITZ_KEY_STROBE_NUM
);
513 qdev_init_gpio_out(&dev
->qdev
, s
->sense
, SPITZ_KEY_SENSE_NUM
);
518 /* LCD backlight controller */
520 #define LCDTG_RESCTL 0x00
521 #define LCDTG_PHACTRL 0x01
522 #define LCDTG_DUTYCTRL 0x02
523 #define LCDTG_POWERREG0 0x03
524 #define LCDTG_POWERREG1 0x04
525 #define LCDTG_GPOR3 0x05
526 #define LCDTG_PICTRL 0x06
527 #define LCDTG_POLCTRL 0x07
531 uint32_t bl_intensity
;
535 static void spitz_bl_update(SpitzLCDTG
*s
)
537 if (s
->bl_power
&& s
->bl_intensity
)
538 zaurus_printf("LCD Backlight now at %i/63\n", s
->bl_intensity
);
540 zaurus_printf("LCD Backlight now off\n");
543 /* FIXME: Implement GPIO properly and remove this hack. */
544 static SpitzLCDTG
*spitz_lcdtg
;
546 static inline void spitz_bl_bit5(void *opaque
, int line
, int level
)
548 SpitzLCDTG
*s
= spitz_lcdtg
;
549 int prev
= s
->bl_intensity
;
552 s
->bl_intensity
&= ~0x20;
554 s
->bl_intensity
|= 0x20;
556 if (s
->bl_power
&& prev
!= s
->bl_intensity
)
560 static inline void spitz_bl_power(void *opaque
, int line
, int level
)
562 SpitzLCDTG
*s
= spitz_lcdtg
;
563 s
->bl_power
= !!level
;
567 static uint32_t spitz_lcdtg_transfer(SSISlave
*dev
, uint32_t value
)
569 SpitzLCDTG
*s
= FROM_SSI_SLAVE(SpitzLCDTG
, dev
);
577 zaurus_printf("LCD in QVGA mode\n");
579 zaurus_printf("LCD in VGA mode\n");
583 s
->bl_intensity
&= ~0x1f;
584 s
->bl_intensity
|= value
;
589 case LCDTG_POWERREG0
:
590 /* Set common voltage to M62332FP */
596 static int spitz_lcdtg_init(SSISlave
*dev
)
598 SpitzLCDTG
*s
= FROM_SSI_SLAVE(SpitzLCDTG
, dev
);
602 s
->bl_intensity
= 0x20;
609 #define CORGI_SSP_PORT 2
611 #define SPITZ_GPIO_LCDCON_CS 53
612 #define SPITZ_GPIO_ADS7846_CS 14
613 #define SPITZ_GPIO_MAX1111_CS 20
614 #define SPITZ_GPIO_TP_INT 11
616 static DeviceState
*max1111
;
618 /* "Demux" the signal based on current chipselect */
625 static uint32_t corgi_ssp_transfer(SSISlave
*dev
, uint32_t value
)
627 CorgiSSPState
*s
= FROM_SSI_SLAVE(CorgiSSPState
, dev
);
630 for (i
= 0; i
< 3; i
++) {
632 return ssi_transfer(s
->bus
[i
], value
);
638 static void corgi_ssp_gpio_cs(void *opaque
, int line
, int level
)
640 CorgiSSPState
*s
= (CorgiSSPState
*)opaque
;
641 assert(line
>= 0 && line
< 3);
642 s
->enable
[line
] = !level
;
645 #define MAX1111_BATT_VOLT 1
646 #define MAX1111_BATT_TEMP 2
647 #define MAX1111_ACIN_VOLT 3
649 #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */
650 #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */
651 #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */
653 static void spitz_adc_temp_on(void *opaque
, int line
, int level
)
659 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, SPITZ_BATTERY_TEMP
);
661 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
664 static int corgi_ssp_init(SSISlave
*dev
)
666 CorgiSSPState
*s
= FROM_SSI_SLAVE(CorgiSSPState
, dev
);
668 qdev_init_gpio_in(&dev
->qdev
, corgi_ssp_gpio_cs
, 3);
669 s
->bus
[0] = ssi_create_bus(&dev
->qdev
, "ssi0");
670 s
->bus
[1] = ssi_create_bus(&dev
->qdev
, "ssi1");
671 s
->bus
[2] = ssi_create_bus(&dev
->qdev
, "ssi2");
676 static void spitz_ssp_attach(PXA2xxState
*cpu
)
682 mux
= ssi_create_slave(cpu
->ssp
[CORGI_SSP_PORT
- 1], "corgi-ssp");
684 bus
= qdev_get_child_bus(mux
, "ssi0");
685 ssi_create_slave(bus
, "spitz-lcdtg");
687 bus
= qdev_get_child_bus(mux
, "ssi1");
688 dev
= ssi_create_slave(bus
, "ads7846");
689 qdev_connect_gpio_out(dev
, 0,
690 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_TP_INT
));
692 bus
= qdev_get_child_bus(mux
, "ssi2");
693 max1111
= ssi_create_slave(bus
, "max1111");
694 max111x_set_input(max1111
, MAX1111_BATT_VOLT
, SPITZ_BATTERY_VOLT
);
695 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
696 max111x_set_input(max1111
, MAX1111_ACIN_VOLT
, SPITZ_CHARGEON_ACIN
);
698 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_LCDCON_CS
,
699 qdev_get_gpio_in(mux
, 0));
700 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_ADS7846_CS
,
701 qdev_get_gpio_in(mux
, 1));
702 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_MAX1111_CS
,
703 qdev_get_gpio_in(mux
, 2));
708 static void spitz_microdrive_attach(PXA2xxState
*cpu
, int slot
)
713 dinfo
= drive_get(IF_IDE
, 0, 0);
714 if (!dinfo
|| dinfo
->media_cd
)
716 md
= dscm1xxxx_init(dinfo
);
717 pxa2xx_pcmcia_attach(cpu
->pcmcia
[slot
], md
);
720 /* Wm8750 and Max7310 on I2C */
722 #define AKITA_MAX_ADDR 0x18
723 #define SPITZ_WM_ADDRL 0x1b
724 #define SPITZ_WM_ADDRH 0x1a
726 #define SPITZ_GPIO_WM 5
728 static void spitz_wm8750_addr(void *opaque
, int line
, int level
)
730 i2c_slave
*wm
= (i2c_slave
*) opaque
;
732 i2c_set_slave_address(wm
, SPITZ_WM_ADDRH
);
734 i2c_set_slave_address(wm
, SPITZ_WM_ADDRL
);
737 static void spitz_i2c_setup(PXA2xxState
*cpu
)
739 /* Attach the CPU on one end of our I2C bus. */
740 i2c_bus
*bus
= pxa2xx_i2c_bus(cpu
->i2c
[0]);
744 /* Attach a WM8750 to the bus */
745 wm
= i2c_create_slave(bus
, "wm8750", 0);
747 spitz_wm8750_addr(wm
, 0, 0);
748 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_WM
,
749 qemu_allocate_irqs(spitz_wm8750_addr
, wm
, 1)[0]);
750 /* .. and to the sound interface. */
751 cpu
->i2s
->opaque
= wm
;
752 cpu
->i2s
->codec_out
= wm8750_dac_dat
;
753 cpu
->i2s
->codec_in
= wm8750_adc_dat
;
754 wm8750_data_req_set(wm
, cpu
->i2s
->data_req
, cpu
->i2s
);
757 static void spitz_akita_i2c_setup(PXA2xxState
*cpu
)
759 /* Attach a Max7310 to Akita I2C bus. */
760 i2c_create_slave(pxa2xx_i2c_bus(cpu
->i2c
[0]), "max7310",
764 /* Other peripherals */
766 static void spitz_out_switch(void *opaque
, int line
, int level
)
770 zaurus_printf("Charging %s.\n", level
? "off" : "on");
773 zaurus_printf("Discharging %s.\n", level
? "on" : "off");
776 zaurus_printf("Green LED %s.\n", level
? "on" : "off");
779 zaurus_printf("Orange LED %s.\n", level
? "on" : "off");
782 spitz_bl_bit5(opaque
, line
, level
);
785 spitz_bl_power(opaque
, line
, level
);
788 spitz_adc_temp_on(opaque
, line
, level
);
793 #define SPITZ_SCP_LED_GREEN 1
794 #define SPITZ_SCP_JK_B 2
795 #define SPITZ_SCP_CHRG_ON 3
796 #define SPITZ_SCP_MUTE_L 4
797 #define SPITZ_SCP_MUTE_R 5
798 #define SPITZ_SCP_CF_POWER 6
799 #define SPITZ_SCP_LED_ORANGE 7
800 #define SPITZ_SCP_JK_A 8
801 #define SPITZ_SCP_ADC_TEMP_ON 9
802 #define SPITZ_SCP2_IR_ON 1
803 #define SPITZ_SCP2_AKIN_PULLUP 2
804 #define SPITZ_SCP2_BACKLIGHT_CONT 7
805 #define SPITZ_SCP2_BACKLIGHT_ON 8
806 #define SPITZ_SCP2_MIC_BIAS 9
808 static void spitz_scoop_gpio_setup(PXA2xxState
*cpu
,
809 DeviceState
*scp0
, DeviceState
*scp1
)
811 qemu_irq
*outsignals
= qemu_allocate_irqs(spitz_out_switch
, cpu
, 8);
813 qdev_connect_gpio_out(scp0
, SPITZ_SCP_CHRG_ON
, outsignals
[0]);
814 qdev_connect_gpio_out(scp0
, SPITZ_SCP_JK_B
, outsignals
[1]);
815 qdev_connect_gpio_out(scp0
, SPITZ_SCP_LED_GREEN
, outsignals
[2]);
816 qdev_connect_gpio_out(scp0
, SPITZ_SCP_LED_ORANGE
, outsignals
[3]);
819 qdev_connect_gpio_out(scp1
, SPITZ_SCP2_BACKLIGHT_CONT
, outsignals
[4]);
820 qdev_connect_gpio_out(scp1
, SPITZ_SCP2_BACKLIGHT_ON
, outsignals
[5]);
823 qdev_connect_gpio_out(scp0
, SPITZ_SCP_ADC_TEMP_ON
, outsignals
[6]);
826 #define SPITZ_GPIO_HSYNC 22
827 #define SPITZ_GPIO_SD_DETECT 9
828 #define SPITZ_GPIO_SD_WP 81
829 #define SPITZ_GPIO_ON_RESET 89
830 #define SPITZ_GPIO_BAT_COVER 90
831 #define SPITZ_GPIO_CF1_IRQ 105
832 #define SPITZ_GPIO_CF1_CD 94
833 #define SPITZ_GPIO_CF2_IRQ 106
834 #define SPITZ_GPIO_CF2_CD 93
836 static int spitz_hsync
;
838 static void spitz_lcd_hsync_handler(void *opaque
, int line
, int level
)
840 PXA2xxState
*cpu
= (PXA2xxState
*) opaque
;
841 qemu_set_irq(qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_HSYNC
), spitz_hsync
);
845 static void spitz_gpio_setup(PXA2xxState
*cpu
, int slots
)
849 * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
850 * read to satisfy broken guests that poll-wait for hsync.
851 * Simulating a real hsync event would be less practical and
852 * wouldn't guarantee that a guest ever exits the loop.
855 lcd_hsync
= qemu_allocate_irqs(spitz_lcd_hsync_handler
, cpu
, 1)[0];
856 pxa2xx_gpio_read_notifier(cpu
->gpio
, lcd_hsync
);
857 pxa2xx_lcd_vsync_notifier(cpu
->lcd
, lcd_hsync
);
860 pxa2xx_mmci_handlers(cpu
->mmc
,
861 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_SD_WP
),
862 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_SD_DETECT
));
864 /* Battery lock always closed */
865 qemu_irq_raise(qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_BAT_COVER
));
868 qdev_connect_gpio_out(cpu
->gpio
, SPITZ_GPIO_ON_RESET
, cpu
->reset
);
870 /* PCMCIA signals: card's IRQ and Card-Detect */
872 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[0],
873 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF1_IRQ
),
874 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF1_CD
));
876 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[1],
877 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF2_IRQ
),
878 qdev_get_gpio_in(cpu
->gpio
, SPITZ_GPIO_CF2_CD
));
882 enum spitz_model_e
{ spitz
, akita
, borzoi
, terrier
};
884 #define SPITZ_RAM 0x04000000
885 #define SPITZ_ROM 0x00800000
887 static struct arm_boot_info spitz_binfo
= {
888 .loader_start
= PXA2XX_SDRAM_BASE
,
889 .ram_size
= 0x04000000,
892 static void spitz_common_init(ram_addr_t ram_size
,
893 const char *kernel_filename
,
894 const char *kernel_cmdline
, const char *initrd_filename
,
895 const char *cpu_model
, enum spitz_model_e model
, int arm_id
)
898 DeviceState
*scp0
, *scp1
= NULL
;
901 cpu_model
= (model
== terrier
) ? "pxa270-c5" : "pxa270-c0";
903 /* Setup CPU & memory */
904 cpu
= pxa270_init(spitz_binfo
.ram_size
, cpu_model
);
906 sl_flash_register(cpu
, (model
== spitz
) ? FLASH_128M
: FLASH_1024M
);
908 cpu_register_physical_memory(0, SPITZ_ROM
,
909 qemu_ram_alloc(NULL
, "spitz.rom", SPITZ_ROM
) | IO_MEM_ROM
);
911 /* Setup peripherals */
912 spitz_keyboard_register(cpu
);
914 spitz_ssp_attach(cpu
);
916 scp0
= sysbus_create_simple("scoop", 0x10800000, NULL
);
917 if (model
!= akita
) {
918 scp1
= sysbus_create_simple("scoop", 0x08800040, NULL
);
921 spitz_scoop_gpio_setup(cpu
, scp0
, scp1
);
923 spitz_gpio_setup(cpu
, (model
== akita
) ? 1 : 2);
925 spitz_i2c_setup(cpu
);
928 spitz_akita_i2c_setup(cpu
);
930 if (model
== terrier
)
931 /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
932 spitz_microdrive_attach(cpu
, 1);
933 else if (model
!= akita
)
934 /* A 4.0 GB microdrive is permanently sitting in CF slot 0. */
935 spitz_microdrive_attach(cpu
, 0);
937 spitz_binfo
.kernel_filename
= kernel_filename
;
938 spitz_binfo
.kernel_cmdline
= kernel_cmdline
;
939 spitz_binfo
.initrd_filename
= initrd_filename
;
940 spitz_binfo
.board_id
= arm_id
;
941 arm_load_kernel(cpu
->env
, &spitz_binfo
);
942 sl_bootparam_write(SL_PXA_PARAM_BASE
);
945 static void spitz_init(ram_addr_t ram_size
,
946 const char *boot_device
,
947 const char *kernel_filename
, const char *kernel_cmdline
,
948 const char *initrd_filename
, const char *cpu_model
)
950 spitz_common_init(ram_size
, kernel_filename
,
951 kernel_cmdline
, initrd_filename
, cpu_model
, spitz
, 0x2c9);
954 static void borzoi_init(ram_addr_t ram_size
,
955 const char *boot_device
,
956 const char *kernel_filename
, const char *kernel_cmdline
,
957 const char *initrd_filename
, const char *cpu_model
)
959 spitz_common_init(ram_size
, kernel_filename
,
960 kernel_cmdline
, initrd_filename
, cpu_model
, borzoi
, 0x33f);
963 static void akita_init(ram_addr_t ram_size
,
964 const char *boot_device
,
965 const char *kernel_filename
, const char *kernel_cmdline
,
966 const char *initrd_filename
, const char *cpu_model
)
968 spitz_common_init(ram_size
, kernel_filename
,
969 kernel_cmdline
, initrd_filename
, cpu_model
, akita
, 0x2e8);
972 static void terrier_init(ram_addr_t ram_size
,
973 const char *boot_device
,
974 const char *kernel_filename
, const char *kernel_cmdline
,
975 const char *initrd_filename
, const char *cpu_model
)
977 spitz_common_init(ram_size
, kernel_filename
,
978 kernel_cmdline
, initrd_filename
, cpu_model
, terrier
, 0x33f);
981 static QEMUMachine akitapda_machine
= {
983 .desc
= "Akita PDA (PXA270)",
987 static QEMUMachine spitzpda_machine
= {
989 .desc
= "Spitz PDA (PXA270)",
993 static QEMUMachine borzoipda_machine
= {
995 .desc
= "Borzoi PDA (PXA270)",
999 static QEMUMachine terrierpda_machine
= {
1001 .desc
= "Terrier PDA (PXA270)",
1002 .init
= terrier_init
,
1005 static void spitz_machine_init(void)
1007 qemu_register_machine(&akitapda_machine
);
1008 qemu_register_machine(&spitzpda_machine
);
1009 qemu_register_machine(&borzoipda_machine
);
1010 qemu_register_machine(&terrierpda_machine
);
1013 machine_init(spitz_machine_init
);
1015 static bool is_version_0(void *opaque
, int version_id
)
1017 return version_id
== 0;
1020 static VMStateDescription vmstate_sl_nand_info
= {
1023 .minimum_version_id
= 0,
1024 .minimum_version_id_old
= 0,
1025 .fields
= (VMStateField
[]) {
1026 VMSTATE_UINT8(ctl
, SLNANDState
),
1027 VMSTATE_STRUCT(ecc
, SLNANDState
, 0, vmstate_ecc_state
, ECCState
),
1028 VMSTATE_END_OF_LIST(),
1032 static SysBusDeviceInfo sl_nand_info
= {
1033 .init
= sl_nand_init
,
1034 .qdev
.name
= "sl-nand",
1035 .qdev
.size
= sizeof(SLNANDState
),
1036 .qdev
.vmsd
= &vmstate_sl_nand_info
,
1037 .qdev
.props
= (Property
[]) {
1038 DEFINE_PROP_UINT8("manf_id", SLNANDState
, manf_id
, NAND_MFR_SAMSUNG
),
1039 DEFINE_PROP_UINT8("chip_id", SLNANDState
, chip_id
, 0xf1),
1040 DEFINE_PROP_END_OF_LIST(),
1044 static VMStateDescription vmstate_spitz_kbd
= {
1045 .name
= "spitz-keyboard",
1047 .minimum_version_id
= 0,
1048 .minimum_version_id_old
= 0,
1049 .post_load
= spitz_keyboard_post_load
,
1050 .fields
= (VMStateField
[]) {
1051 VMSTATE_UINT16(sense_state
, SpitzKeyboardState
),
1052 VMSTATE_UINT16(strobe_state
, SpitzKeyboardState
),
1053 VMSTATE_UNUSED_TEST(is_version_0
, 5),
1054 VMSTATE_END_OF_LIST(),
1058 static SysBusDeviceInfo spitz_keyboard_info
= {
1059 .init
= spitz_keyboard_init
,
1060 .qdev
.name
= "spitz-keyboard",
1061 .qdev
.size
= sizeof(SpitzKeyboardState
),
1062 .qdev
.vmsd
= &vmstate_spitz_kbd
,
1063 .qdev
.props
= (Property
[]) {
1064 DEFINE_PROP_END_OF_LIST(),
1068 static const VMStateDescription vmstate_corgi_ssp_regs
= {
1069 .name
= "corgi-ssp",
1071 .minimum_version_id
= 1,
1072 .minimum_version_id_old
= 1,
1073 .fields
= (VMStateField
[]) {
1074 VMSTATE_UINT32_ARRAY(enable
, CorgiSSPState
, 3),
1075 VMSTATE_END_OF_LIST(),
1079 static SSISlaveInfo corgi_ssp_info
= {
1080 .qdev
.name
= "corgi-ssp",
1081 .qdev
.size
= sizeof(CorgiSSPState
),
1082 .qdev
.vmsd
= &vmstate_corgi_ssp_regs
,
1083 .init
= corgi_ssp_init
,
1084 .transfer
= corgi_ssp_transfer
1087 static const VMStateDescription vmstate_spitz_lcdtg_regs
= {
1088 .name
= "spitz-lcdtg",
1090 .minimum_version_id
= 1,
1091 .minimum_version_id_old
= 1,
1092 .fields
= (VMStateField
[]) {
1093 VMSTATE_UINT32(bl_intensity
, SpitzLCDTG
),
1094 VMSTATE_UINT32(bl_power
, SpitzLCDTG
),
1095 VMSTATE_END_OF_LIST(),
1099 static SSISlaveInfo spitz_lcdtg_info
= {
1100 .qdev
.name
= "spitz-lcdtg",
1101 .qdev
.size
= sizeof(SpitzLCDTG
),
1102 .qdev
.vmsd
= &vmstate_spitz_lcdtg_regs
,
1103 .init
= spitz_lcdtg_init
,
1104 .transfer
= spitz_lcdtg_transfer
1107 static void spitz_register_devices(void)
1109 ssi_register_slave(&corgi_ssp_info
);
1110 ssi_register_slave(&spitz_lcdtg_info
);
1111 sysbus_register_withprop(&spitz_keyboard_info
);
1112 sysbus_register_withprop(&sl_nand_info
);
1115 device_init(spitz_register_devices
)