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.
17 #include "qemu-timer.h"
22 #include "audio/audio.h"
26 #if TARGET_PHYS_ADDR_BITS == 32
27 #define REG_FMT "0x%02x"
29 #define REG_FMT "0x%02lx"
33 #define FLASH_BASE 0x0c000000
34 #define FLASH_ECCLPLB 0x00 /* Line parity 7 - 0 bit */
35 #define FLASH_ECCLPUB 0x04 /* Line parity 15 - 8 bit */
36 #define FLASH_ECCCP 0x08 /* Column parity 5 - 0 bit */
37 #define FLASH_ECCCNTR 0x0c /* ECC byte counter */
38 #define FLASH_ECCCLRR 0x10 /* Clear ECC */
39 #define FLASH_FLASHIO 0x14 /* Flash I/O */
40 #define FLASH_FLASHCTL 0x18 /* Flash Control */
42 #define FLASHCTL_CE0 (1 << 0)
43 #define FLASHCTL_CLE (1 << 1)
44 #define FLASHCTL_ALE (1 << 2)
45 #define FLASHCTL_WP (1 << 3)
46 #define FLASHCTL_CE1 (1 << 4)
47 #define FLASHCTL_RYBY (1 << 5)
48 #define FLASHCTL_NCE (FLASHCTL_CE0 | FLASHCTL_CE1)
51 struct nand_flash_s
*nand
;
53 struct ecc_state_s ecc
;
56 static uint32_t sl_readb(void *opaque
, target_phys_addr_t addr
)
58 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
62 #define BSHR(byte, from, to) ((s->ecc.lp[byte] >> (from - to)) & (1 << to))
64 return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) |
65 BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7);
67 #define BSHL(byte, from, to) ((s->ecc.lp[byte] << (to - from)) & (1 << to))
69 return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) |
70 BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7);
76 return s
->ecc
.count
& 0xff;
79 nand_getpins(s
->nand
, &ryby
);
81 return s
->ctl
| FLASHCTL_RYBY
;
86 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
));
89 zaurus_printf("Bad register offset " REG_FMT
"\n", addr
);
94 static uint32_t sl_readl(void *opaque
, target_phys_addr_t addr
)
96 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
98 if (addr
== FLASH_FLASHIO
)
99 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) |
100 (ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) << 16);
102 return sl_readb(opaque
, addr
);
105 static void sl_writeb(void *opaque
, target_phys_addr_t addr
,
108 struct sl_nand_s
*s
= (struct sl_nand_s
*) 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", addr
);
135 static void sl_save(QEMUFile
*f
, void *opaque
)
137 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
139 qemu_put_8s(f
, &s
->ctl
);
143 static int sl_load(QEMUFile
*f
, void *opaque
, int version_id
)
145 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
147 qemu_get_8s(f
, &s
->ctl
);
158 static void sl_flash_register(struct pxa2xx_state_s
*cpu
, int size
)
162 CPUReadMemoryFunc
*sl_readfn
[] = {
167 CPUWriteMemoryFunc
*sl_writefn
[] = {
173 s
= (struct sl_nand_s
*) qemu_mallocz(sizeof(struct sl_nand_s
));
175 if (size
== FLASH_128M
)
176 s
->nand
= nand_init(NAND_MFR_SAMSUNG
, 0x73);
177 else if (size
== FLASH_1024M
)
178 s
->nand
= nand_init(NAND_MFR_SAMSUNG
, 0xf1);
180 iomemtype
= cpu_register_io_memory(0, sl_readfn
,
182 cpu_register_physical_memory(FLASH_BASE
, 0x40, iomemtype
);
184 register_savevm("sl_flash", 0, 0, sl_save
, sl_load
, s
);
189 #define SPITZ_KEY_STROBE_NUM 11
190 #define SPITZ_KEY_SENSE_NUM 7
192 static const int spitz_gpio_key_sense
[SPITZ_KEY_SENSE_NUM
] = {
193 12, 17, 91, 34, 36, 38, 39
196 static const int spitz_gpio_key_strobe
[SPITZ_KEY_STROBE_NUM
] = {
197 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114
200 /* Eighth additional row maps the special keys */
201 static int spitz_keymap
[SPITZ_KEY_SENSE_NUM
+ 1][SPITZ_KEY_STROBE_NUM
] = {
202 { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 },
203 { -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 },
204 { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25, -1 , -1 , -1 },
205 { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26, -1 , 0x36, -1 },
206 { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34, -1 , 0x1c, 0x2a, -1 },
207 { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33, -1 , 0x48, -1 , -1 , 0x38 },
208 { 0x37, 0x3d, -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d, -1 , -1 },
209 { 0x52, 0x43, 0x01, 0x47, 0x49, -1 , -1 , -1 , -1 , -1 , -1 },
212 #define SPITZ_GPIO_AK_INT 13 /* Remote control */
213 #define SPITZ_GPIO_SYNC 16 /* Sync button */
214 #define SPITZ_GPIO_ON_KEY 95 /* Power button */
215 #define SPITZ_GPIO_SWA 97 /* Lid */
216 #define SPITZ_GPIO_SWB 96 /* Tablet mode */
218 /* The special buttons are mapped to unused keys */
219 static const int spitz_gpiomap
[5] = {
220 SPITZ_GPIO_AK_INT
, SPITZ_GPIO_SYNC
, SPITZ_GPIO_ON_KEY
,
221 SPITZ_GPIO_SWA
, SPITZ_GPIO_SWB
,
223 static int spitz_gpio_invert
[5] = { 0, 0, 0, 0, 0, };
225 struct spitz_keyboard_s
{
226 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
;
242 static void spitz_keyboard_sense_update(struct spitz_keyboard_s
*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 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) 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(struct spitz_keyboard_s
*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) ^
279 spitz_gpio_invert
[spitz_keycode
& 0xf]);
284 s
->keyrow
[spitz_keycode
>> 4] &= ~(1 << (spitz_keycode
& 0xf));
286 s
->keyrow
[spitz_keycode
>> 4] |= 1 << (spitz_keycode
& 0xf);
288 spitz_keyboard_sense_update(s
);
291 #define SHIFT (1 << 7)
292 #define CTRL (1 << 8)
295 #define QUEUE_KEY(c) s->fifo[(s->fifopos + s->fifolen ++) & 0xf] = c
297 static void spitz_keyboard_handler(struct spitz_keyboard_s
*s
, int keycode
)
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 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) opaque
;
392 spitz_keyboard_keydown(s
, s
->fifo
[s
->fifopos
++]);
394 if (s
->fifopos
>= 16)
398 qemu_mod_timer(s
->kbdtimer
, qemu_get_clock(vm_clock
) + ticks_per_sec
/ 32);
401 static void spitz_keyboard_pre_map(struct spitz_keyboard_s
*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 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) 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 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) 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(struct pxa2xx_state_s
*cpu
)
486 struct spitz_keyboard_s
*s
;
488 s
= (struct spitz_keyboard_s
*)
489 qemu_mallocz(sizeof(struct spitz_keyboard_s
));
490 memset(s
, 0, sizeof(struct spitz_keyboard_s
));
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("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
528 static int bl_intensity
, bl_power
;
530 static void spitz_bl_update(struct pxa2xx_state_s
*s
)
532 if (bl_power
&& bl_intensity
)
533 zaurus_printf("LCD Backlight now at %i/63\n", bl_intensity
);
535 zaurus_printf("LCD Backlight now off\n");
538 static inline void spitz_bl_bit5(void *opaque
, int line
, int level
)
540 int prev
= bl_intensity
;
543 bl_intensity
&= ~0x20;
545 bl_intensity
|= 0x20;
547 if (bl_power
&& prev
!= bl_intensity
)
548 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
551 static inline void spitz_bl_power(void *opaque
, int line
, int level
)
554 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
557 static void spitz_lcdtg_dac_put(void *opaque
, uint8_t cmd
)
566 zaurus_printf("LCD in QVGA mode\n");
568 zaurus_printf("LCD in VGA mode\n");
572 bl_intensity
&= ~0x1f;
573 bl_intensity
|= value
;
575 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
578 case LCDTG_POWERREG0
:
579 /* Set common voltage to M62332FP */
586 #define CORGI_SSP_PORT 2
588 #define SPITZ_GPIO_LCDCON_CS 53
589 #define SPITZ_GPIO_ADS7846_CS 14
590 #define SPITZ_GPIO_MAX1111_CS 20
591 #define SPITZ_GPIO_TP_INT 11
593 static int lcd_en
, ads_en
, max_en
;
594 static struct max111x_s
*max1111
;
595 static struct ads7846_state_s
*ads7846
;
597 /* "Demux" the signal based on current chipselect */
598 static uint32_t corgi_ssp_read(void *opaque
)
603 return ads7846_read(ads7846
);
605 return max111x_read(max1111
);
609 static void corgi_ssp_write(void *opaque
, uint32_t value
)
612 spitz_lcdtg_dac_put(opaque
, value
);
614 ads7846_write(ads7846
, value
);
616 max111x_write(max1111
, value
);
619 static void corgi_ssp_gpio_cs(void *opaque
, int line
, int level
)
634 #define MAX1111_BATT_VOLT 1
635 #define MAX1111_BATT_TEMP 2
636 #define MAX1111_ACIN_VOLT 3
638 #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */
639 #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */
640 #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */
642 static void spitz_adc_temp_on(void *opaque
, int line
, int level
)
648 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, SPITZ_BATTERY_TEMP
);
650 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
653 static void spitz_ssp_save(QEMUFile
*f
, void *opaque
)
655 qemu_put_be32(f
, lcd_en
);
656 qemu_put_be32(f
, ads_en
);
657 qemu_put_be32(f
, max_en
);
658 qemu_put_be32(f
, bl_intensity
);
659 qemu_put_be32(f
, bl_power
);
662 static int spitz_ssp_load(QEMUFile
*f
, void *opaque
, int version_id
)
664 lcd_en
= qemu_get_be32(f
);
665 ads_en
= qemu_get_be32(f
);
666 max_en
= qemu_get_be32(f
);
667 bl_intensity
= qemu_get_be32(f
);
668 bl_power
= qemu_get_be32(f
);
673 static void spitz_ssp_attach(struct pxa2xx_state_s
*cpu
)
675 qemu_irq
*chipselects
;
677 lcd_en
= ads_en
= max_en
= 0;
679 ads7846
= ads7846_init(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_TP_INT
]);
681 max1111
= max1111_init(0);
682 max111x_set_input(max1111
, MAX1111_BATT_VOLT
, SPITZ_BATTERY_VOLT
);
683 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
684 max111x_set_input(max1111
, MAX1111_ACIN_VOLT
, SPITZ_CHARGEON_ACIN
);
686 pxa2xx_ssp_attach(cpu
->ssp
[CORGI_SSP_PORT
- 1], corgi_ssp_read
,
687 corgi_ssp_write
, cpu
);
689 chipselects
= qemu_allocate_irqs(corgi_ssp_gpio_cs
, cpu
, 3);
690 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_LCDCON_CS
, chipselects
[0]);
691 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_ADS7846_CS
, chipselects
[1]);
692 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_MAX1111_CS
, chipselects
[2]);
697 register_savevm("spitz_ssp", 0, 0, spitz_ssp_save
, spitz_ssp_load
, cpu
);
702 static void spitz_microdrive_attach(struct pxa2xx_state_s
*cpu
, int slot
)
704 struct pcmcia_card_s
*md
;
706 BlockDriverState
*bs
;
708 index
= drive_get_index(IF_IDE
, 0, 0);
711 bs
= drives_table
[index
].bdrv
;
712 if (bdrv_is_inserted(bs
) && !bdrv_is_removable(bs
)) {
713 md
= dscm1xxxx_init(bs
);
714 pxa2xx_pcmcia_attach(cpu
->pcmcia
[slot
], md
);
718 /* Wm8750 and Max7310 on I2C */
720 #define AKITA_MAX_ADDR 0x18
721 #define SPITZ_WM_ADDRL 0x1b
722 #define SPITZ_WM_ADDRH 0x1a
724 #define SPITZ_GPIO_WM 5
727 static void spitz_wm8750_addr(void *opaque
, int line
, int level
)
729 i2c_slave
*wm
= (i2c_slave
*) opaque
;
731 i2c_set_slave_address(wm
, SPITZ_WM_ADDRH
);
733 i2c_set_slave_address(wm
, SPITZ_WM_ADDRL
);
737 static void spitz_i2c_setup(struct pxa2xx_state_s
*cpu
)
739 /* Attach the CPU on one end of our I2C bus. */
740 i2c_bus
*bus
= pxa2xx_i2c_bus(cpu
->i2c
[0]);
749 /* Attach a WM8750 to the bus */
750 wm
= wm8750_init(bus
, audio
);
752 spitz_wm8750_addr(wm
, 0, 0);
753 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_WM
,
754 qemu_allocate_irqs(spitz_wm8750_addr
, wm
, 1)[0]);
755 /* .. and to the sound interface. */
756 cpu
->i2s
->opaque
= wm
;
757 cpu
->i2s
->codec_out
= wm8750_dac_dat
;
758 cpu
->i2s
->codec_in
= wm8750_adc_dat
;
759 wm8750_data_req_set(wm
, cpu
->i2s
->data_req
, cpu
->i2s
);
763 static void spitz_akita_i2c_setup(struct pxa2xx_state_s
*cpu
)
765 /* Attach a Max7310 to Akita I2C bus. */
766 i2c_set_slave_address(max7310_init(pxa2xx_i2c_bus(cpu
->i2c
[0])),
770 /* Other peripherals */
772 static void spitz_out_switch(void *opaque
, int line
, int level
)
776 zaurus_printf("Charging %s.\n", level
? "off" : "on");
779 zaurus_printf("Discharging %s.\n", level
? "on" : "off");
782 zaurus_printf("Green LED %s.\n", level
? "on" : "off");
785 zaurus_printf("Orange LED %s.\n", level
? "on" : "off");
788 spitz_bl_bit5(opaque
, line
, level
);
791 spitz_bl_power(opaque
, line
, level
);
794 spitz_adc_temp_on(opaque
, line
, level
);
799 #define SPITZ_SCP_LED_GREEN 1
800 #define SPITZ_SCP_JK_B 2
801 #define SPITZ_SCP_CHRG_ON 3
802 #define SPITZ_SCP_MUTE_L 4
803 #define SPITZ_SCP_MUTE_R 5
804 #define SPITZ_SCP_CF_POWER 6
805 #define SPITZ_SCP_LED_ORANGE 7
806 #define SPITZ_SCP_JK_A 8
807 #define SPITZ_SCP_ADC_TEMP_ON 9
808 #define SPITZ_SCP2_IR_ON 1
809 #define SPITZ_SCP2_AKIN_PULLUP 2
810 #define SPITZ_SCP2_BACKLIGHT_CONT 7
811 #define SPITZ_SCP2_BACKLIGHT_ON 8
812 #define SPITZ_SCP2_MIC_BIAS 9
814 static void spitz_scoop_gpio_setup(struct pxa2xx_state_s
*cpu
,
815 struct scoop_info_s
*scp0
, struct scoop_info_s
*scp1
)
817 qemu_irq
*outsignals
= qemu_allocate_irqs(spitz_out_switch
, cpu
, 8);
819 scoop_gpio_out_set(scp0
, SPITZ_SCP_CHRG_ON
, outsignals
[0]);
820 scoop_gpio_out_set(scp0
, SPITZ_SCP_JK_B
, outsignals
[1]);
821 scoop_gpio_out_set(scp0
, SPITZ_SCP_LED_GREEN
, outsignals
[2]);
822 scoop_gpio_out_set(scp0
, SPITZ_SCP_LED_ORANGE
, outsignals
[3]);
825 scoop_gpio_out_set(scp1
, SPITZ_SCP2_BACKLIGHT_CONT
, outsignals
[4]);
826 scoop_gpio_out_set(scp1
, SPITZ_SCP2_BACKLIGHT_ON
, outsignals
[5]);
829 scoop_gpio_out_set(scp0
, SPITZ_SCP_ADC_TEMP_ON
, outsignals
[6]);
832 #define SPITZ_GPIO_HSYNC 22
833 #define SPITZ_GPIO_SD_DETECT 9
834 #define SPITZ_GPIO_SD_WP 81
835 #define SPITZ_GPIO_ON_RESET 89
836 #define SPITZ_GPIO_BAT_COVER 90
837 #define SPITZ_GPIO_CF1_IRQ 105
838 #define SPITZ_GPIO_CF1_CD 94
839 #define SPITZ_GPIO_CF2_IRQ 106
840 #define SPITZ_GPIO_CF2_CD 93
842 static int spitz_hsync
;
844 static void spitz_lcd_hsync_handler(void *opaque
, int line
, int level
)
846 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
847 qemu_set_irq(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_HSYNC
], spitz_hsync
);
851 static void spitz_gpio_setup(struct pxa2xx_state_s
*cpu
, int slots
)
855 * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
856 * read to satisfy broken guests that poll-wait for hsync.
857 * Simulating a real hsync event would be less practical and
858 * wouldn't guarantee that a guest ever exits the loop.
861 lcd_hsync
= qemu_allocate_irqs(spitz_lcd_hsync_handler
, cpu
, 1)[0];
862 pxa2xx_gpio_read_notifier(cpu
->gpio
, lcd_hsync
);
863 pxa2xx_lcd_vsync_notifier(cpu
->lcd
, lcd_hsync
);
866 pxa2xx_mmci_handlers(cpu
->mmc
,
867 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SD_WP
],
868 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SD_DETECT
]);
870 /* Battery lock always closed */
871 qemu_irq_raise(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_BAT_COVER
]);
874 pxa2xx_gpio_out_set(cpu
->gpio
, SPITZ_GPIO_ON_RESET
, cpu
->reset
);
876 /* PCMCIA signals: card's IRQ and Card-Detect */
878 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[0],
879 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF1_IRQ
],
880 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF1_CD
]);
882 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[1],
883 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF2_IRQ
],
884 pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_CF2_CD
]);
886 /* Initialise the screen rotation related signals */
887 spitz_gpio_invert
[3] = 0; /* Always open */
888 if (graphic_rotate
) { /* Tablet mode */
889 spitz_gpio_invert
[4] = 0;
890 } else { /* Portrait mode */
891 spitz_gpio_invert
[4] = 1;
893 qemu_set_irq(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SWA
],
894 spitz_gpio_invert
[3]);
895 qemu_set_irq(pxa2xx_gpio_in_get(cpu
->gpio
)[SPITZ_GPIO_SWB
],
896 spitz_gpio_invert
[4]);
900 enum spitz_model_e
{ spitz
, akita
, borzoi
, terrier
};
902 #define SPITZ_RAM 0x04000000
903 #define SPITZ_ROM 0x00800000
905 static struct arm_boot_info spitz_binfo
= {
906 .loader_start
= PXA2XX_SDRAM_BASE
,
907 .ram_size
= 0x04000000,
910 static void spitz_common_init(ram_addr_t ram_size
, int vga_ram_size
,
911 const char *kernel_filename
,
912 const char *kernel_cmdline
, const char *initrd_filename
,
913 const char *cpu_model
, enum spitz_model_e model
, int arm_id
)
915 struct pxa2xx_state_s
*cpu
;
916 struct scoop_info_s
*scp0
, *scp1
= NULL
;
919 cpu_model
= (model
== terrier
) ? "pxa270-c5" : "pxa270-c0";
921 /* Setup CPU & memory */
922 if (ram_size
< SPITZ_RAM
+ SPITZ_ROM
+ PXA2XX_INTERNAL_SIZE
) {
923 fprintf(stderr
, "This platform requires %i bytes of memory\n",
924 SPITZ_RAM
+ SPITZ_ROM
+ PXA2XX_INTERNAL_SIZE
);
927 cpu
= pxa270_init(spitz_binfo
.ram_size
, cpu_model
);
929 sl_flash_register(cpu
, (model
== spitz
) ? FLASH_128M
: FLASH_1024M
);
931 cpu_register_physical_memory(0, SPITZ_ROM
,
932 qemu_ram_alloc(SPITZ_ROM
) | IO_MEM_ROM
);
934 /* Setup peripherals */
935 spitz_keyboard_register(cpu
);
937 spitz_ssp_attach(cpu
);
939 scp0
= scoop_init(cpu
, 0, 0x10800000);
940 if (model
!= akita
) {
941 scp1
= scoop_init(cpu
, 1, 0x08800040);
944 spitz_scoop_gpio_setup(cpu
, scp0
, scp1
);
946 spitz_gpio_setup(cpu
, (model
== akita
) ? 1 : 2);
948 spitz_i2c_setup(cpu
);
951 spitz_akita_i2c_setup(cpu
);
953 if (model
== terrier
)
954 /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
955 spitz_microdrive_attach(cpu
, 1);
956 else if (model
!= akita
)
957 /* A 4.0 GB microdrive is permanently sitting in CF slot 0. */
958 spitz_microdrive_attach(cpu
, 0);
960 /* Setup initial (reset) machine state */
961 cpu
->env
->regs
[15] = spitz_binfo
.loader_start
;
963 spitz_binfo
.kernel_filename
= kernel_filename
;
964 spitz_binfo
.kernel_cmdline
= kernel_cmdline
;
965 spitz_binfo
.initrd_filename
= initrd_filename
;
966 spitz_binfo
.board_id
= arm_id
;
967 arm_load_kernel(cpu
->env
, &spitz_binfo
);
968 sl_bootparam_write(SL_PXA_PARAM_BASE
- PXA2XX_SDRAM_BASE
);
971 static void spitz_init(ram_addr_t ram_size
, int vga_ram_size
,
972 const char *boot_device
,
973 const char *kernel_filename
, const char *kernel_cmdline
,
974 const char *initrd_filename
, const char *cpu_model
)
976 spitz_common_init(ram_size
, vga_ram_size
, kernel_filename
,
977 kernel_cmdline
, initrd_filename
, cpu_model
, spitz
, 0x2c9);
980 static void borzoi_init(ram_addr_t ram_size
, int vga_ram_size
,
981 const char *boot_device
,
982 const char *kernel_filename
, const char *kernel_cmdline
,
983 const char *initrd_filename
, const char *cpu_model
)
985 spitz_common_init(ram_size
, vga_ram_size
, kernel_filename
,
986 kernel_cmdline
, initrd_filename
, cpu_model
, borzoi
, 0x33f);
989 static void akita_init(ram_addr_t ram_size
, int vga_ram_size
,
990 const char *boot_device
,
991 const char *kernel_filename
, const char *kernel_cmdline
,
992 const char *initrd_filename
, const char *cpu_model
)
994 spitz_common_init(ram_size
, vga_ram_size
, kernel_filename
,
995 kernel_cmdline
, initrd_filename
, cpu_model
, akita
, 0x2e8);
998 static void terrier_init(ram_addr_t ram_size
, int vga_ram_size
,
999 const char *boot_device
,
1000 const char *kernel_filename
, const char *kernel_cmdline
,
1001 const char *initrd_filename
, const char *cpu_model
)
1003 spitz_common_init(ram_size
, vga_ram_size
, kernel_filename
,
1004 kernel_cmdline
, initrd_filename
, cpu_model
, terrier
, 0x33f);
1007 QEMUMachine akitapda_machine
= {
1009 .desc
= "Akita PDA (PXA270)",
1011 .ram_require
= SPITZ_RAM
+ SPITZ_ROM
+ PXA2XX_INTERNAL_SIZE
+ RAMSIZE_FIXED
,
1014 QEMUMachine spitzpda_machine
= {
1016 .desc
= "Spitz PDA (PXA270)",
1018 .ram_require
= SPITZ_RAM
+ SPITZ_ROM
+ PXA2XX_INTERNAL_SIZE
+ RAMSIZE_FIXED
,
1021 QEMUMachine borzoipda_machine
= {
1023 .desc
= "Borzoi PDA (PXA270)",
1024 .init
= borzoi_init
,
1025 .ram_require
= SPITZ_RAM
+ SPITZ_ROM
+ PXA2XX_INTERNAL_SIZE
+ RAMSIZE_FIXED
,
1028 QEMUMachine terrierpda_machine
= {
1030 .desc
= "Terrier PDA (PXA270)",
1031 .init
= terrier_init
,
1032 .ram_require
= SPITZ_RAM
+ SPITZ_ROM
+ PXA2XX_INTERNAL_SIZE
+ RAMSIZE_FIXED
,