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.
12 #define spitz_printf(format, ...) \
13 fprintf(stderr, "%s: " format, __FUNCTION__, ##__VA_ARGS__)
15 #define REG_FMT "0x%02lx"
18 #define FLASH_BASE 0x0c000000
19 #define FLASH_ECCLPLB 0x00 /* Line parity 7 - 0 bit */
20 #define FLASH_ECCLPUB 0x04 /* Line parity 15 - 8 bit */
21 #define FLASH_ECCCP 0x08 /* Column parity 5 - 0 bit */
22 #define FLASH_ECCCNTR 0x0c /* ECC byte counter */
23 #define FLASH_ECCCLRR 0x10 /* Clear ECC */
24 #define FLASH_FLASHIO 0x14 /* Flash I/O */
25 #define FLASH_FLASHCTL 0x18 /* Flash Control */
27 #define FLASHCTL_CE0 (1 << 0)
28 #define FLASHCTL_CLE (1 << 1)
29 #define FLASHCTL_ALE (1 << 2)
30 #define FLASHCTL_WP (1 << 3)
31 #define FLASHCTL_CE1 (1 << 4)
32 #define FLASHCTL_RYBY (1 << 5)
33 #define FLASHCTL_NCE (FLASHCTL_CE0 | FLASHCTL_CE1)
36 target_phys_addr_t target_base
;
37 struct nand_flash_s
*nand
;
39 struct ecc_state_s ecc
;
42 static uint32_t sl_readb(void *opaque
, target_phys_addr_t addr
)
44 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
46 addr
-= s
->target_base
;
49 #define BSHR(byte, from, to) ((s->ecc.lp[byte] >> (from - to)) & (1 << to))
51 return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) |
52 BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7);
54 #define BSHL(byte, from, to) ((s->ecc.lp[byte] << (to - from)) & (1 << to))
56 return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) |
57 BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7);
63 return s
->ecc
.count
& 0xff;
66 nand_getpins(s
->nand
, &ryby
);
68 return s
->ctl
| FLASHCTL_RYBY
;
73 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
));
76 spitz_printf("Bad register offset " REG_FMT
"\n", addr
);
81 static uint32_t sl_readl(void *opaque
, target_phys_addr_t addr
)
83 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
84 addr
-= s
->target_base
;
86 if (addr
== FLASH_FLASHIO
)
87 return ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) |
88 (ecc_digest(&s
->ecc
, nand_getio(s
->nand
)) << 16);
90 return sl_readb(opaque
, addr
);
93 static void sl_writeb(void *opaque
, target_phys_addr_t addr
,
96 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
97 addr
-= s
->target_base
;
101 /* Value is ignored. */
106 s
->ctl
= value
& 0xff & ~FLASHCTL_RYBY
;
107 nand_setpins(s
->nand
,
108 s
->ctl
& FLASHCTL_CLE
,
109 s
->ctl
& FLASHCTL_ALE
,
110 s
->ctl
& FLASHCTL_NCE
,
111 s
->ctl
& FLASHCTL_WP
,
116 nand_setio(s
->nand
, ecc_digest(&s
->ecc
, value
& 0xff));
120 spitz_printf("Bad register offset " REG_FMT
"\n", addr
);
124 static void sl_save(QEMUFile
*f
, void *opaque
)
126 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
128 qemu_put_8s(f
, &s
->ctl
);
132 static int sl_load(QEMUFile
*f
, void *opaque
, int version_id
)
134 struct sl_nand_s
*s
= (struct sl_nand_s
*) opaque
;
136 qemu_get_8s(f
, &s
->ctl
);
147 static void sl_flash_register(struct pxa2xx_state_s
*cpu
, int size
)
151 CPUReadMemoryFunc
*sl_readfn
[] = {
156 CPUWriteMemoryFunc
*sl_writefn
[] = {
162 s
= (struct sl_nand_s
*) qemu_mallocz(sizeof(struct sl_nand_s
));
163 s
->target_base
= FLASH_BASE
;
165 if (size
== FLASH_128M
)
166 s
->nand
= nand_init(NAND_MFR_SAMSUNG
, 0x73);
167 else if (size
== FLASH_1024M
)
168 s
->nand
= nand_init(NAND_MFR_SAMSUNG
, 0xf1);
170 iomemtype
= cpu_register_io_memory(0, sl_readfn
,
172 cpu_register_physical_memory(s
->target_base
, 0x40, iomemtype
);
174 register_savevm("sl_flash", 0, 0, sl_save
, sl_load
, s
);
179 #define SPITZ_KEY_STROBE_NUM 11
180 #define SPITZ_KEY_SENSE_NUM 7
182 static const int spitz_gpio_key_sense
[SPITZ_KEY_SENSE_NUM
] = {
183 12, 17, 91, 34, 36, 38, 39
186 static const int spitz_gpio_key_strobe
[SPITZ_KEY_STROBE_NUM
] = {
187 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114
190 /* Eighth additional row maps the special keys */
191 static int spitz_keymap
[SPITZ_KEY_SENSE_NUM
+ 1][SPITZ_KEY_STROBE_NUM
] = {
192 { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 },
193 { -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 },
194 { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25, -1 , -1 , -1 },
195 { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26, -1 , 0x36, -1 },
196 { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34, -1 , 0x1c, 0x2a, -1 },
197 { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33, -1 , 0x48, -1 , -1 , 0x38 },
198 { 0x37, 0x3d, -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d, -1 , -1 },
199 { 0x52, 0x43, 0x01, 0x47, 0x49, -1 , -1 , -1 , -1 , -1 , -1 },
202 #define SPITZ_GPIO_AK_INT 13 /* Remote control */
203 #define SPITZ_GPIO_SYNC 16 /* Sync button */
204 #define SPITZ_GPIO_ON_KEY 95 /* Power button */
205 #define SPITZ_GPIO_SWA 97 /* Lid */
206 #define SPITZ_GPIO_SWB 96 /* Tablet mode */
208 /* The special buttons are mapped to unused keys */
209 static const int spitz_gpiomap
[5] = {
210 SPITZ_GPIO_AK_INT
, SPITZ_GPIO_SYNC
, SPITZ_GPIO_ON_KEY
,
211 SPITZ_GPIO_SWA
, SPITZ_GPIO_SWB
,
213 static int spitz_gpio_invert
[5] = { 0, 0, 0, 0, 0, };
215 struct spitz_keyboard_s
{
216 struct pxa2xx_state_s
*cpu
;
218 uint16_t keyrow
[SPITZ_KEY_SENSE_NUM
];
219 uint16_t strobe_state
;
220 uint16_t sense_state
;
222 uint16_t pre_map
[0x100];
226 int fifopos
, fifolen
;
230 static void spitz_keyboard_sense_update(struct spitz_keyboard_s
*s
)
233 uint16_t strobe
, sense
= 0;
234 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
; i
++) {
235 strobe
= s
->keyrow
[i
] & s
->strobe_state
;
238 if (!(s
->sense_state
& (1 << i
)))
239 pxa2xx_gpio_set(s
->cpu
->gpio
, spitz_gpio_key_sense
[i
], 1);
240 } else if (s
->sense_state
& (1 << i
))
241 pxa2xx_gpio_set(s
->cpu
->gpio
, spitz_gpio_key_sense
[i
], 0);
244 s
->sense_state
= sense
;
247 static void spitz_keyboard_strobe(int line
, int level
,
248 struct spitz_keyboard_s
*s
)
251 for (i
= 0; i
< SPITZ_KEY_STROBE_NUM
; i
++)
252 if (spitz_gpio_key_strobe
[i
] == line
) {
254 s
->strobe_state
|= 1 << i
;
256 s
->strobe_state
&= ~(1 << i
);
258 spitz_keyboard_sense_update(s
);
263 static void spitz_keyboard_keydown(struct spitz_keyboard_s
*s
, int keycode
)
265 int spitz_keycode
= s
->keymap
[keycode
& 0x7f];
266 if (spitz_keycode
== -1)
269 /* Handle the additional keys */
270 if ((spitz_keycode
>> 4) == SPITZ_KEY_SENSE_NUM
) {
271 pxa2xx_gpio_set(s
->cpu
->gpio
, spitz_gpiomap
[spitz_keycode
& 0xf],
273 spitz_gpio_invert
[spitz_keycode
& 0xf]);
278 s
->keyrow
[spitz_keycode
>> 4] &= ~(1 << (spitz_keycode
& 0xf));
280 s
->keyrow
[spitz_keycode
>> 4] |= 1 << (spitz_keycode
& 0xf);
282 spitz_keyboard_sense_update(s
);
285 #define SHIFT (1 << 7)
286 #define CTRL (1 << 8)
289 #define QUEUE_KEY(c) s->fifo[(s->fifopos + s->fifolen ++) & 0xf] = c
291 static void spitz_keyboard_handler(struct spitz_keyboard_s
*s
, int keycode
)
296 case 0x2a: /* Left Shift */
302 case 0x36: /* Right Shift */
308 case 0x1d: /* Control */
322 code
= s
->pre_map
[mapcode
= ((s
->modifiers
& 3) ?
324 (keycode
& ~SHIFT
))];
326 if (code
!= mapcode
) {
328 if ((code
& SHIFT
) && !(s
->modifiers
& 1))
329 QUEUE_KEY(0x2a | (keycode
& 0x80));
330 if ((code
& CTRL
) && !(s
->modifiers
& 4))
331 QUEUE_KEY(0x1d | (keycode
& 0x80));
332 if ((code
& FN
) && !(s
->modifiers
& 8))
333 QUEUE_KEY(0x38 | (keycode
& 0x80));
334 if ((code
& FN
) && (s
->modifiers
& 1))
335 QUEUE_KEY(0x2a | (~keycode
& 0x80));
336 if ((code
& FN
) && (s
->modifiers
& 2))
337 QUEUE_KEY(0x36 | (~keycode
& 0x80));
339 if (keycode
& 0x80) {
340 if ((s
->imodifiers
& 1 ) && !(s
->modifiers
& 1))
341 QUEUE_KEY(0x2a | 0x80);
342 if ((s
->imodifiers
& 4 ) && !(s
->modifiers
& 4))
343 QUEUE_KEY(0x1d | 0x80);
344 if ((s
->imodifiers
& 8 ) && !(s
->modifiers
& 8))
345 QUEUE_KEY(0x38 | 0x80);
346 if ((s
->imodifiers
& 0x10) && (s
->modifiers
& 1))
348 if ((s
->imodifiers
& 0x20) && (s
->modifiers
& 2))
352 if ((code
& SHIFT
) && !((s
->modifiers
| s
->imodifiers
) & 1)) {
356 if ((code
& CTRL
) && !((s
->modifiers
| s
->imodifiers
) & 4)) {
360 if ((code
& FN
) && !((s
->modifiers
| s
->imodifiers
) & 8)) {
364 if ((code
& FN
) && (s
->modifiers
& 1) &&
365 !(s
->imodifiers
& 0x10)) {
366 QUEUE_KEY(0x2a | 0x80);
367 s
->imodifiers
|= 0x10;
369 if ((code
& FN
) && (s
->modifiers
& 2) &&
370 !(s
->imodifiers
& 0x20)) {
371 QUEUE_KEY(0x36 | 0x80);
372 s
->imodifiers
|= 0x20;
378 QUEUE_KEY((code
& 0x7f) | (keycode
& 0x80));
381 static void spitz_keyboard_tick(void *opaque
)
383 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) opaque
;
386 spitz_keyboard_keydown(s
, s
->fifo
[s
->fifopos
++]);
388 if (s
->fifopos
>= 16)
392 qemu_mod_timer(s
->kbdtimer
, qemu_get_clock(vm_clock
) + ticks_per_sec
/ 32);
395 static void spitz_keyboard_pre_map(struct spitz_keyboard_s
*s
)
398 for (i
= 0; i
< 0x100; i
++)
400 s
->pre_map
[0x02 | SHIFT
] = 0x02 | SHIFT
; /* exclam */
401 s
->pre_map
[0x28 | SHIFT
] = 0x03 | SHIFT
; /* quotedbl */
402 s
->pre_map
[0x04 | SHIFT
] = 0x04 | SHIFT
; /* numbersign */
403 s
->pre_map
[0x05 | SHIFT
] = 0x05 | SHIFT
; /* dollar */
404 s
->pre_map
[0x06 | SHIFT
] = 0x06 | SHIFT
; /* percent */
405 s
->pre_map
[0x08 | SHIFT
] = 0x07 | SHIFT
; /* ampersand */
406 s
->pre_map
[0x28 ] = 0x08 | SHIFT
; /* apostrophe */
407 s
->pre_map
[0x0a | SHIFT
] = 0x09 | SHIFT
; /* parenleft */
408 s
->pre_map
[0x0b | SHIFT
] = 0x0a | SHIFT
; /* parenright */
409 s
->pre_map
[0x29 | SHIFT
] = 0x0b | SHIFT
; /* asciitilde */
410 s
->pre_map
[0x03 | SHIFT
] = 0x0c | SHIFT
; /* at */
411 s
->pre_map
[0xd3 ] = 0x0e | FN
; /* Delete */
412 s
->pre_map
[0x3a ] = 0x0f | FN
; /* Caps_Lock */
413 s
->pre_map
[0x07 | SHIFT
] = 0x11 | FN
; /* asciicircum */
414 s
->pre_map
[0x0d ] = 0x12 | FN
; /* equal */
415 s
->pre_map
[0x0d | SHIFT
] = 0x13 | FN
; /* plus */
416 s
->pre_map
[0x1a ] = 0x14 | FN
; /* bracketleft */
417 s
->pre_map
[0x1b ] = 0x15 | FN
; /* bracketright */
418 s
->pre_map
[0x1a | SHIFT
] = 0x16 | FN
; /* braceleft */
419 s
->pre_map
[0x1b | SHIFT
] = 0x17 | FN
; /* braceright */
420 s
->pre_map
[0x27 ] = 0x22 | FN
; /* semicolon */
421 s
->pre_map
[0x27 | SHIFT
] = 0x23 | FN
; /* colon */
422 s
->pre_map
[0x09 | SHIFT
] = 0x24 | FN
; /* asterisk */
423 s
->pre_map
[0x2b ] = 0x25 | FN
; /* backslash */
424 s
->pre_map
[0x2b | SHIFT
] = 0x26 | FN
; /* bar */
425 s
->pre_map
[0x0c | SHIFT
] = 0x30 | FN
; /* underscore */
426 s
->pre_map
[0x33 | SHIFT
] = 0x33 | FN
; /* less */
427 s
->pre_map
[0x35 ] = 0x33 | SHIFT
; /* slash */
428 s
->pre_map
[0x34 | SHIFT
] = 0x34 | FN
; /* greater */
429 s
->pre_map
[0x35 | SHIFT
] = 0x34 | SHIFT
; /* question */
430 s
->pre_map
[0x49 ] = 0x48 | FN
; /* Page_Up */
431 s
->pre_map
[0x51 ] = 0x50 | FN
; /* Page_Down */
437 s
->kbdtimer
= qemu_new_timer(vm_clock
, spitz_keyboard_tick
, s
);
438 spitz_keyboard_tick(s
);
445 static void spitz_keyboard_save(QEMUFile
*f
, void *opaque
)
447 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) opaque
;
450 qemu_put_be16s(f
, &s
->sense_state
);
451 qemu_put_be16s(f
, &s
->strobe_state
);
452 for (i
= 0; i
< 5; i
++)
453 qemu_put_byte(f
, spitz_gpio_invert
[i
]);
456 static int spitz_keyboard_load(QEMUFile
*f
, void *opaque
, int version_id
)
458 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) opaque
;
461 qemu_get_be16s(f
, &s
->sense_state
);
462 qemu_get_be16s(f
, &s
->strobe_state
);
463 for (i
= 0; i
< 5; i
++)
464 spitz_gpio_invert
[i
] = qemu_get_byte(f
);
466 /* Release all pressed keys */
467 memset(s
->keyrow
, 0, sizeof(s
->keyrow
));
468 spitz_keyboard_sense_update(s
);
477 static void spitz_keyboard_register(struct pxa2xx_state_s
*cpu
)
480 struct spitz_keyboard_s
*s
;
482 s
= (struct spitz_keyboard_s
*)
483 qemu_mallocz(sizeof(struct spitz_keyboard_s
));
484 memset(s
, 0, sizeof(struct spitz_keyboard_s
));
487 for (i
= 0; i
< 0x80; i
++)
489 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
+ 1; i
++)
490 for (j
= 0; j
< SPITZ_KEY_STROBE_NUM
; j
++)
491 if (spitz_keymap
[i
][j
] != -1)
492 s
->keymap
[spitz_keymap
[i
][j
]] = (i
<< 4) | j
;
494 for (i
= 0; i
< SPITZ_KEY_STROBE_NUM
; i
++)
495 pxa2xx_gpio_handler_set(cpu
->gpio
, spitz_gpio_key_strobe
[i
],
496 (gpio_handler_t
) spitz_keyboard_strobe
, s
);
498 spitz_keyboard_pre_map(s
);
499 qemu_add_kbd_event_handler((QEMUPutKBDEvent
*) spitz_keyboard_handler
, s
);
501 register_savevm("spitz_keyboard", 0, 0,
502 spitz_keyboard_save
, spitz_keyboard_load
, s
);
507 struct scoop_info_s
{
508 target_phys_addr_t target_base
;
528 #define SCOOP_MCR 0x00
529 #define SCOOP_CDR 0x04
530 #define SCOOP_CSR 0x08
531 #define SCOOP_CPR 0x0c
532 #define SCOOP_CCR 0x10
533 #define SCOOP_IRR_IRM 0x14
534 #define SCOOP_IMR 0x18
535 #define SCOOP_ISR 0x1c
536 #define SCOOP_GPCR 0x20
537 #define SCOOP_GPWR 0x24
538 #define SCOOP_GPRR 0x28
540 static inline void scoop_gpio_handler_update(struct scoop_info_s
*s
) {
541 uint32_t level
, diff
;
543 level
= s
->gpio_level
& s
->gpio_dir
;
545 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
547 if (s
->handler
[bit
].fn
)
548 s
->handler
[bit
].fn(bit
, (level
>> bit
) & 1,
549 s
->handler
[bit
].opaque
);
552 s
->prev_level
= level
;
555 static uint32_t scoop_readb(void *opaque
, target_phys_addr_t addr
)
557 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
558 addr
-= s
->target_base
;
580 return s
->gpio_level
;
584 spitz_printf("Bad register offset " REG_FMT
"\n", addr
);
590 static void scoop_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
592 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
593 addr
-= s
->target_base
;
622 scoop_gpio_handler_update(s
);
625 s
->gpio_level
= value
& s
->gpio_dir
;
626 scoop_gpio_handler_update(s
);
632 spitz_printf("Bad register offset " REG_FMT
"\n", addr
);
636 CPUReadMemoryFunc
*scoop_readfn
[] = {
641 CPUWriteMemoryFunc
*scoop_writefn
[] = {
647 static inline void scoop_gpio_set(struct scoop_info_s
*s
, int line
, int level
)
650 spitz_printf("No GPIO pin %i\n", line
);
655 s
->gpio_level
|= (1 << line
);
657 s
->gpio_level
&= ~(1 << line
);
660 static inline void scoop_gpio_handler_set(struct scoop_info_s
*s
, int line
,
661 gpio_handler_t handler
, void *opaque
) {
663 spitz_printf("No GPIO pin %i\n", line
);
667 s
->handler
[line
].fn
= handler
;
668 s
->handler
[line
].opaque
= opaque
;
671 static void scoop_save(QEMUFile
*f
, void *opaque
)
673 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
674 qemu_put_be16s(f
, &s
->status
);
675 qemu_put_be16s(f
, &s
->power
);
676 qemu_put_be32s(f
, &s
->gpio_level
);
677 qemu_put_be32s(f
, &s
->gpio_dir
);
678 qemu_put_be32s(f
, &s
->prev_level
);
679 qemu_put_be16s(f
, &s
->mcr
);
680 qemu_put_be16s(f
, &s
->cdr
);
681 qemu_put_be16s(f
, &s
->ccr
);
682 qemu_put_be16s(f
, &s
->irr
);
683 qemu_put_be16s(f
, &s
->imr
);
684 qemu_put_be16s(f
, &s
->isr
);
685 qemu_put_be16s(f
, &s
->gprr
);
688 static int scoop_load(QEMUFile
*f
, void *opaque
, int version_id
)
690 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
691 qemu_get_be16s(f
, &s
->status
);
692 qemu_get_be16s(f
, &s
->power
);
693 qemu_get_be32s(f
, &s
->gpio_level
);
694 qemu_get_be32s(f
, &s
->gpio_dir
);
695 qemu_get_be32s(f
, &s
->prev_level
);
696 qemu_get_be16s(f
, &s
->mcr
);
697 qemu_get_be16s(f
, &s
->cdr
);
698 qemu_get_be16s(f
, &s
->ccr
);
699 qemu_get_be16s(f
, &s
->irr
);
700 qemu_get_be16s(f
, &s
->imr
);
701 qemu_get_be16s(f
, &s
->isr
);
702 qemu_get_be16s(f
, &s
->gprr
);
707 static struct scoop_info_s
*spitz_scoop_init(struct pxa2xx_state_s
*cpu
,
710 struct scoop_info_s
*s
;
712 s
= (struct scoop_info_s
*)
713 qemu_mallocz(sizeof(struct scoop_info_s
) * 2);
714 memset(s
, 0, sizeof(struct scoop_info_s
) * count
);
715 s
[0].target_base
= 0x10800000;
716 s
[1].target_base
= 0x08800040;
722 iomemtype
= cpu_register_io_memory(0, scoop_readfn
,
723 scoop_writefn
, &s
[0]);
724 cpu_register_physical_memory(s
[0].target_base
, 0x1000, iomemtype
);
725 register_savevm("scoop", 0, 0, scoop_save
, scoop_load
, &s
[0]);
730 iomemtype
= cpu_register_io_memory(0, scoop_readfn
,
731 scoop_writefn
, &s
[1]);
732 cpu_register_physical_memory(s
[1].target_base
, 0x1000, iomemtype
);
733 register_savevm("scoop", 1, 0, scoop_save
, scoop_load
, &s
[1]);
738 /* LCD backlight controller */
740 #define LCDTG_RESCTL 0x00
741 #define LCDTG_PHACTRL 0x01
742 #define LCDTG_DUTYCTRL 0x02
743 #define LCDTG_POWERREG0 0x03
744 #define LCDTG_POWERREG1 0x04
745 #define LCDTG_GPOR3 0x05
746 #define LCDTG_PICTRL 0x06
747 #define LCDTG_POLCTRL 0x07
749 static int bl_intensity
, bl_power
;
751 static void spitz_bl_update(struct pxa2xx_state_s
*s
)
753 if (bl_power
&& bl_intensity
)
754 spitz_printf("LCD Backlight now at %i/63\n", bl_intensity
);
756 spitz_printf("LCD Backlight now off\n");
759 static void spitz_bl_bit5(int line
, int level
, void *opaque
)
761 int prev
= bl_intensity
;
764 bl_intensity
&= ~0x20;
766 bl_intensity
|= 0x20;
768 if (bl_power
&& prev
!= bl_intensity
)
769 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
772 static void spitz_bl_power(int line
, int level
, void *opaque
)
775 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
778 static void spitz_lcdtg_dac_put(void *opaque
, uint8_t cmd
)
787 spitz_printf("LCD in QVGA mode\n");
789 spitz_printf("LCD in VGA mode\n");
793 bl_intensity
&= ~0x1f;
794 bl_intensity
|= value
;
796 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
799 case LCDTG_POWERREG0
:
800 /* Set common voltage to M62332FP */
807 #define CORGI_SSP_PORT 2
809 #define SPITZ_GPIO_LCDCON_CS 53
810 #define SPITZ_GPIO_ADS7846_CS 14
811 #define SPITZ_GPIO_MAX1111_CS 20
812 #define SPITZ_GPIO_TP_INT 11
814 static int lcd_en
, ads_en
, max_en
;
815 static struct max111x_s
*max1111
;
816 static struct ads7846_state_s
*ads7846
;
818 /* "Demux" the signal based on current chipselect */
819 static uint32_t corgi_ssp_read(void *opaque
)
824 return ads7846_read(ads7846
);
826 return max111x_read(max1111
);
830 static void corgi_ssp_write(void *opaque
, uint32_t value
)
833 spitz_lcdtg_dac_put(opaque
, value
);
835 ads7846_write(ads7846
, value
);
837 max111x_write(max1111
, value
);
840 static void corgi_ssp_gpio_cs(int line
, int level
, struct pxa2xx_state_s
*s
)
842 if (line
== SPITZ_GPIO_LCDCON_CS
)
844 else if (line
== SPITZ_GPIO_ADS7846_CS
)
846 else if (line
== SPITZ_GPIO_MAX1111_CS
)
850 #define MAX1111_BATT_VOLT 1
851 #define MAX1111_BATT_TEMP 2
852 #define MAX1111_ACIN_VOLT 3
854 #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */
855 #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */
856 #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */
858 static void spitz_adc_temp_on(int line
, int level
, void *opaque
)
864 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, SPITZ_BATTERY_TEMP
);
866 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
869 static void spitz_pendown_set(void *opaque
, int line
, int level
)
871 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
872 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_TP_INT
, level
);
875 static void spitz_ssp_save(QEMUFile
*f
, void *opaque
)
877 qemu_put_be32(f
, lcd_en
);
878 qemu_put_be32(f
, ads_en
);
879 qemu_put_be32(f
, max_en
);
880 qemu_put_be32(f
, bl_intensity
);
881 qemu_put_be32(f
, bl_power
);
884 static int spitz_ssp_load(QEMUFile
*f
, void *opaque
, int version_id
)
886 lcd_en
= qemu_get_be32(f
);
887 ads_en
= qemu_get_be32(f
);
888 max_en
= qemu_get_be32(f
);
889 bl_intensity
= qemu_get_be32(f
);
890 bl_power
= qemu_get_be32(f
);
895 static void spitz_ssp_attach(struct pxa2xx_state_s
*cpu
)
897 lcd_en
= ads_en
= max_en
= 0;
899 ads7846
= ads7846_init(qemu_allocate_irqs(spitz_pendown_set
, cpu
, 1)[0]);
901 max1111
= max1111_init(0);
902 max111x_set_input(max1111
, MAX1111_BATT_VOLT
, SPITZ_BATTERY_VOLT
);
903 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
904 max111x_set_input(max1111
, MAX1111_ACIN_VOLT
, SPITZ_CHARGEON_ACIN
);
906 pxa2xx_ssp_attach(cpu
->ssp
[CORGI_SSP_PORT
- 1], corgi_ssp_read
,
907 corgi_ssp_write
, cpu
);
909 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_LCDCON_CS
,
910 (gpio_handler_t
) corgi_ssp_gpio_cs
, cpu
);
911 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_ADS7846_CS
,
912 (gpio_handler_t
) corgi_ssp_gpio_cs
, cpu
);
913 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_MAX1111_CS
,
914 (gpio_handler_t
) corgi_ssp_gpio_cs
, cpu
);
919 register_savevm("spitz_ssp", 0, 0, spitz_ssp_save
, spitz_ssp_load
, cpu
);
924 static void spitz_microdrive_attach(struct pxa2xx_state_s
*cpu
)
926 struct pcmcia_card_s
*md
;
927 BlockDriverState
*bs
= bs_table
[0];
929 if (bs
&& bdrv_is_inserted(bs
) && !bdrv_is_removable(bs
)) {
930 md
= dscm1xxxx_init(bs
);
931 pxa2xx_pcmcia_attach(cpu
->pcmcia
[1], md
);
935 /* Wm8750 and Max7310 on I2C */
937 #define AKITA_MAX_ADDR 0x18
938 #define SPITZ_WM_ADDRL 0x1b
939 #define SPITZ_WM_ADDRH 0x1a
941 #define SPITZ_GPIO_WM 5
944 static void spitz_wm8750_addr(int line
, int level
, void *opaque
)
946 i2c_slave
*wm
= (i2c_slave
*) opaque
;
948 i2c_set_slave_address(wm
, SPITZ_WM_ADDRH
);
950 i2c_set_slave_address(wm
, SPITZ_WM_ADDRL
);
954 static void spitz_i2c_setup(struct pxa2xx_state_s
*cpu
)
956 /* Attach the CPU on one end of our I2C bus. */
957 i2c_bus
*bus
= pxa2xx_i2c_bus(cpu
->i2c
[0]);
966 /* Attach a WM8750 to the bus */
967 wm
= wm8750_init(bus
, audio
);
969 spitz_wm8750_addr(0, 0, wm
);
970 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_WM
, spitz_wm8750_addr
, wm
);
971 /* .. and to the sound interface. */
972 cpu
->i2s
->opaque
= wm
;
973 cpu
->i2s
->codec_out
= wm8750_dac_dat
;
974 cpu
->i2s
->codec_in
= wm8750_adc_dat
;
975 wm8750_data_req_set(wm
, cpu
->i2s
->data_req
, cpu
->i2s
);
979 static void spitz_akita_i2c_setup(struct pxa2xx_state_s
*cpu
)
981 /* Attach a Max7310 to Akita I2C bus. */
982 i2c_set_slave_address(max7310_init(pxa2xx_i2c_bus(cpu
->i2c
[0])),
986 /* Other peripherals */
988 static void spitz_charge_switch(int line
, int level
, void *opaque
)
990 spitz_printf("Charging %s.\n", level
? "off" : "on");
993 static void spitz_discharge_switch(int line
, int level
, void *opaque
)
995 spitz_printf("Discharging %s.\n", level
? "on" : "off");
998 static void spitz_greenled_switch(int line
, int level
, void *opaque
)
1000 spitz_printf("Green LED %s.\n", level
? "on" : "off");
1003 static void spitz_orangeled_switch(int line
, int level
, void *opaque
)
1005 spitz_printf("Orange LED %s.\n", level
? "on" : "off");
1008 #define SPITZ_SCP_LED_GREEN 1
1009 #define SPITZ_SCP_JK_B 2
1010 #define SPITZ_SCP_CHRG_ON 3
1011 #define SPITZ_SCP_MUTE_L 4
1012 #define SPITZ_SCP_MUTE_R 5
1013 #define SPITZ_SCP_CF_POWER 6
1014 #define SPITZ_SCP_LED_ORANGE 7
1015 #define SPITZ_SCP_JK_A 8
1016 #define SPITZ_SCP_ADC_TEMP_ON 9
1017 #define SPITZ_SCP2_IR_ON 1
1018 #define SPITZ_SCP2_AKIN_PULLUP 2
1019 #define SPITZ_SCP2_BACKLIGHT_CONT 7
1020 #define SPITZ_SCP2_BACKLIGHT_ON 8
1021 #define SPITZ_SCP2_MIC_BIAS 9
1023 static void spitz_scoop_gpio_setup(struct pxa2xx_state_s
*cpu
,
1024 struct scoop_info_s
*scp
, int num
)
1026 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_CHRG_ON
,
1027 spitz_charge_switch
, cpu
);
1028 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_JK_B
,
1029 spitz_discharge_switch
, cpu
);
1030 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_LED_GREEN
,
1031 spitz_greenled_switch
, cpu
);
1032 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_LED_ORANGE
,
1033 spitz_orangeled_switch
, cpu
);
1036 scoop_gpio_handler_set(&scp
[1], SPITZ_SCP2_BACKLIGHT_CONT
,
1037 spitz_bl_bit5
, cpu
);
1038 scoop_gpio_handler_set(&scp
[1], SPITZ_SCP2_BACKLIGHT_ON
,
1039 spitz_bl_power
, cpu
);
1042 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_ADC_TEMP_ON
,
1043 spitz_adc_temp_on
, cpu
);
1046 #define SPITZ_GPIO_HSYNC 22
1047 #define SPITZ_GPIO_SD_DETECT 9
1048 #define SPITZ_GPIO_SD_WP 81
1049 #define SPITZ_GPIO_ON_RESET 89
1050 #define SPITZ_GPIO_BAT_COVER 90
1051 #define SPITZ_GPIO_CF1_IRQ 105
1052 #define SPITZ_GPIO_CF1_CD 94
1053 #define SPITZ_GPIO_CF2_IRQ 106
1054 #define SPITZ_GPIO_CF2_CD 93
1058 static void spitz_lcd_hsync_handler(void *opaque
)
1060 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1061 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_HSYNC
, spitz_hsync
);
1065 static void spitz_mmc_coverswitch_change(void *opaque
, int in
)
1067 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1068 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SD_DETECT
, in
);
1071 static void spitz_mmc_writeprotect_change(void *opaque
, int wp
)
1073 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1074 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SD_WP
, wp
);
1077 static void spitz_pcmcia_cb(void *opaque
, int line
, int level
)
1079 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1080 static const int gpio_map
[] = {
1081 SPITZ_GPIO_CF1_IRQ
, SPITZ_GPIO_CF1_CD
,
1082 SPITZ_GPIO_CF2_IRQ
, SPITZ_GPIO_CF2_CD
,
1084 pxa2xx_gpio_set(cpu
->gpio
, gpio_map
[line
], level
);
1087 static void spitz_gpio_setup(struct pxa2xx_state_s
*cpu
, int slots
)
1089 qemu_irq
*pcmcia_cb
;
1091 * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
1092 * read to satisfy broken guests that poll-wait for hsync.
1093 * Simulating a real hsync event would be less practical and
1094 * wouldn't guarantee that a guest ever exits the loop.
1097 pxa2xx_gpio_read_notifier(cpu
->gpio
, spitz_lcd_hsync_handler
, cpu
);
1098 pxa2xx_lcd_vsync_cb(cpu
->lcd
, spitz_lcd_hsync_handler
, cpu
);
1101 pxa2xx_mmci_handlers(cpu
->mmc
, cpu
, spitz_mmc_writeprotect_change
,
1102 spitz_mmc_coverswitch_change
);
1104 /* Battery lock always closed */
1105 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_BAT_COVER
, 1);
1108 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_ON_RESET
, pxa2xx_reset
, cpu
);
1110 /* PCMCIA signals: card's IRQ and Card-Detect */
1111 pcmcia_cb
= qemu_allocate_irqs(spitz_pcmcia_cb
, cpu
, slots
* 2);
1113 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[0], pcmcia_cb
[0], pcmcia_cb
[1]);
1115 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[1], pcmcia_cb
[2], pcmcia_cb
[3]);
1117 /* Initialise the screen rotation related signals */
1118 spitz_gpio_invert
[3] = 0; /* Always open */
1119 if (graphic_rotate
) { /* Tablet mode */
1120 spitz_gpio_invert
[4] = 0;
1121 } else { /* Portrait mode */
1122 spitz_gpio_invert
[4] = 1;
1124 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SWA
, spitz_gpio_invert
[3]);
1125 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SWB
, spitz_gpio_invert
[4]);
1128 /* Write the bootloader parameters memory area. */
1130 #define MAGIC_CHG(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | a)
1132 struct __attribute__ ((__packed__
)) sl_param_info
{
1133 uint32_t comadj_keyword
;
1136 uint32_t uuid_keyword
;
1139 uint32_t touch_keyword
;
1145 uint32_t adadj_keyword
;
1148 uint32_t phad_keyword
;
1150 } spitz_bootparam
= {
1151 .comadj_keyword
= MAGIC_CHG('C', 'M', 'A', 'D'),
1153 .uuid_keyword
= MAGIC_CHG('U', 'U', 'I', 'D'),
1155 .touch_keyword
= MAGIC_CHG('T', 'U', 'C', 'H'),
1157 .adadj_keyword
= MAGIC_CHG('B', 'V', 'A', 'D'),
1159 .phad_keyword
= MAGIC_CHG('P', 'H', 'A', 'D'),
1163 static void sl_bootparam_write(uint32_t ptr
)
1165 memcpy(phys_ram_base
+ ptr
, &spitz_bootparam
,
1166 sizeof(struct sl_param_info
));
1169 #define SL_PXA_PARAM_BASE 0xa0000a00
1172 enum spitz_model_e
{ spitz
, akita
, borzoi
, terrier
};
1174 static void spitz_common_init(int ram_size
, int vga_ram_size
,
1175 DisplayState
*ds
, const char *kernel_filename
,
1176 const char *kernel_cmdline
, const char *initrd_filename
,
1177 const char *cpu_model
, enum spitz_model_e model
, int arm_id
)
1179 uint32_t spitz_ram
= 0x04000000;
1180 uint32_t spitz_rom
= 0x00800000;
1181 struct pxa2xx_state_s
*cpu
;
1182 struct scoop_info_s
*scp
;
1185 cpu_model
= (model
== terrier
) ? "pxa270-c5" : "pxa270-c0";
1187 /* Setup CPU & memory */
1188 if (ram_size
< spitz_ram
+ spitz_rom
+ PXA2XX_INTERNAL_SIZE
) {
1189 fprintf(stderr
, "This platform requires %i bytes of memory\n",
1190 spitz_ram
+ spitz_rom
+ PXA2XX_INTERNAL_SIZE
);
1193 cpu
= pxa270_init(spitz_ram
, ds
, cpu_model
);
1195 sl_flash_register(cpu
, (model
== spitz
) ? FLASH_128M
: FLASH_1024M
);
1197 cpu_register_physical_memory(0, spitz_rom
,
1198 qemu_ram_alloc(spitz_rom
) | IO_MEM_ROM
);
1200 /* Setup peripherals */
1201 spitz_keyboard_register(cpu
);
1203 spitz_ssp_attach(cpu
);
1205 scp
= spitz_scoop_init(cpu
, (model
== akita
) ? 1 : 2);
1207 spitz_scoop_gpio_setup(cpu
, scp
, (model
== akita
) ? 1 : 2);
1209 spitz_gpio_setup(cpu
, (model
== akita
) ? 1 : 2);
1211 spitz_i2c_setup(cpu
);
1214 spitz_akita_i2c_setup(cpu
);
1216 if (model
== terrier
)
1217 /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
1218 spitz_microdrive_attach(cpu
);
1219 else if (model
!= akita
)
1220 /* A 4.0 GB microdrive is permanently sitting in CF slot 1. */
1221 spitz_microdrive_attach(cpu
);
1223 /* Setup initial (reset) machine state */
1224 cpu
->env
->regs
[15] = PXA2XX_SDRAM_BASE
;
1226 arm_load_kernel(cpu
->env
, spitz_ram
, kernel_filename
, kernel_cmdline
,
1227 initrd_filename
, arm_id
, PXA2XX_SDRAM_BASE
);
1228 sl_bootparam_write(SL_PXA_PARAM_BASE
- PXA2XX_SDRAM_BASE
);
1231 static void spitz_init(int ram_size
, int vga_ram_size
, int boot_device
,
1232 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1233 const char *kernel_filename
, const char *kernel_cmdline
,
1234 const char *initrd_filename
, const char *cpu_model
)
1236 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1237 kernel_cmdline
, initrd_filename
, cpu_model
, spitz
, 0x2c9);
1240 static void borzoi_init(int ram_size
, int vga_ram_size
, int boot_device
,
1241 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1242 const char *kernel_filename
, const char *kernel_cmdline
,
1243 const char *initrd_filename
, const char *cpu_model
)
1245 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1246 kernel_cmdline
, initrd_filename
, cpu_model
, borzoi
, 0x33f);
1249 static void akita_init(int ram_size
, int vga_ram_size
, int boot_device
,
1250 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1251 const char *kernel_filename
, const char *kernel_cmdline
,
1252 const char *initrd_filename
, const char *cpu_model
)
1254 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1255 kernel_cmdline
, initrd_filename
, cpu_model
, akita
, 0x2e8);
1258 static void terrier_init(int ram_size
, int vga_ram_size
, int boot_device
,
1259 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1260 const char *kernel_filename
, const char *kernel_cmdline
,
1261 const char *initrd_filename
, const char *cpu_model
)
1263 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1264 kernel_cmdline
, initrd_filename
, cpu_model
, terrier
, 0x33f);
1267 QEMUMachine akitapda_machine
= {
1269 "Akita PDA (PXA270)",
1273 QEMUMachine spitzpda_machine
= {
1275 "Spitz PDA (PXA270)",
1279 QEMUMachine borzoipda_machine
= {
1281 "Borzoi PDA (PXA270)",
1285 QEMUMachine terrierpda_machine
= {
1287 "Terrier PDA (PXA270)",