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 , 0x3d },
198 { 0x37, 0x38, -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
[0x27 ] = 0x22 | FN
; /* semicolon */
419 s
->pre_map
[0x27 | SHIFT
] = 0x23 | FN
; /* colon */
420 s
->pre_map
[0x09 | SHIFT
] = 0x24 | FN
; /* asterisk */
421 s
->pre_map
[0x2b ] = 0x25 | FN
; /* backslash */
422 s
->pre_map
[0x2b | SHIFT
] = 0x26 | FN
; /* bar */
423 s
->pre_map
[0x0c | SHIFT
] = 0x30 | FN
; /* underscore */
424 s
->pre_map
[0x35 ] = 0x33 | SHIFT
; /* slash */
425 s
->pre_map
[0x35 | SHIFT
] = 0x34 | SHIFT
; /* question */
426 s
->pre_map
[0x49 ] = 0x48 | FN
; /* Page_Up */
427 s
->pre_map
[0x51 ] = 0x50 | FN
; /* Page_Down */
433 s
->kbdtimer
= qemu_new_timer(vm_clock
, spitz_keyboard_tick
, s
);
434 spitz_keyboard_tick(s
);
441 static void spitz_keyboard_save(QEMUFile
*f
, void *opaque
)
443 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) opaque
;
446 qemu_put_be16s(f
, &s
->sense_state
);
447 qemu_put_be16s(f
, &s
->strobe_state
);
448 for (i
= 0; i
< 5; i
++)
449 qemu_put_byte(f
, spitz_gpio_invert
[i
]);
452 static int spitz_keyboard_load(QEMUFile
*f
, void *opaque
, int version_id
)
454 struct spitz_keyboard_s
*s
= (struct spitz_keyboard_s
*) opaque
;
457 qemu_get_be16s(f
, &s
->sense_state
);
458 qemu_get_be16s(f
, &s
->strobe_state
);
459 for (i
= 0; i
< 5; i
++)
460 spitz_gpio_invert
[i
] = qemu_get_byte(f
);
462 /* Release all pressed keys */
463 memset(s
->keyrow
, 0, sizeof(s
->keyrow
));
464 spitz_keyboard_sense_update(s
);
473 static void spitz_keyboard_register(struct pxa2xx_state_s
*cpu
)
476 struct spitz_keyboard_s
*s
;
478 s
= (struct spitz_keyboard_s
*)
479 qemu_mallocz(sizeof(struct spitz_keyboard_s
));
480 memset(s
, 0, sizeof(struct spitz_keyboard_s
));
483 for (i
= 0; i
< 0x80; i
++)
485 for (i
= 0; i
< SPITZ_KEY_SENSE_NUM
+ 1; i
++)
486 for (j
= 0; j
< SPITZ_KEY_STROBE_NUM
; j
++)
487 if (spitz_keymap
[i
][j
] != -1)
488 s
->keymap
[spitz_keymap
[i
][j
]] = (i
<< 4) | j
;
490 for (i
= 0; i
< SPITZ_KEY_STROBE_NUM
; i
++)
491 pxa2xx_gpio_handler_set(cpu
->gpio
, spitz_gpio_key_strobe
[i
],
492 (gpio_handler_t
) spitz_keyboard_strobe
, s
);
494 spitz_keyboard_pre_map(s
);
495 qemu_add_kbd_event_handler((QEMUPutKBDEvent
*) spitz_keyboard_handler
, s
);
497 register_savevm("spitz_keyboard", 0, 0,
498 spitz_keyboard_save
, spitz_keyboard_load
, s
);
503 struct scoop_info_s
{
504 target_phys_addr_t target_base
;
524 #define SCOOP_MCR 0x00
525 #define SCOOP_CDR 0x04
526 #define SCOOP_CSR 0x08
527 #define SCOOP_CPR 0x0c
528 #define SCOOP_CCR 0x10
529 #define SCOOP_IRR_IRM 0x14
530 #define SCOOP_IMR 0x18
531 #define SCOOP_ISR 0x1c
532 #define SCOOP_GPCR 0x20
533 #define SCOOP_GPWR 0x24
534 #define SCOOP_GPRR 0x28
536 static inline void scoop_gpio_handler_update(struct scoop_info_s
*s
) {
537 uint32_t level
, diff
;
539 level
= s
->gpio_level
& s
->gpio_dir
;
541 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
543 if (s
->handler
[bit
].fn
)
544 s
->handler
[bit
].fn(bit
, (level
>> bit
) & 1,
545 s
->handler
[bit
].opaque
);
548 s
->prev_level
= level
;
551 static uint32_t scoop_readb(void *opaque
, target_phys_addr_t addr
)
553 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
554 addr
-= s
->target_base
;
576 return s
->gpio_level
;
580 spitz_printf("Bad register offset " REG_FMT
"\n", addr
);
586 static void scoop_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
588 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
589 addr
-= s
->target_base
;
618 scoop_gpio_handler_update(s
);
621 s
->gpio_level
= value
& s
->gpio_dir
;
622 scoop_gpio_handler_update(s
);
628 spitz_printf("Bad register offset " REG_FMT
"\n", addr
);
632 CPUReadMemoryFunc
*scoop_readfn
[] = {
637 CPUWriteMemoryFunc
*scoop_writefn
[] = {
643 static inline void scoop_gpio_set(struct scoop_info_s
*s
, int line
, int level
)
646 spitz_printf("No GPIO pin %i\n", line
);
651 s
->gpio_level
|= (1 << line
);
653 s
->gpio_level
&= ~(1 << line
);
656 static inline void scoop_gpio_handler_set(struct scoop_info_s
*s
, int line
,
657 gpio_handler_t handler
, void *opaque
) {
659 spitz_printf("No GPIO pin %i\n", line
);
663 s
->handler
[line
].fn
= handler
;
664 s
->handler
[line
].opaque
= opaque
;
667 static void scoop_save(QEMUFile
*f
, void *opaque
)
669 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
670 qemu_put_be16s(f
, &s
->status
);
671 qemu_put_be16s(f
, &s
->power
);
672 qemu_put_be32s(f
, &s
->gpio_level
);
673 qemu_put_be32s(f
, &s
->gpio_dir
);
674 qemu_put_be32s(f
, &s
->prev_level
);
675 qemu_put_be16s(f
, &s
->mcr
);
676 qemu_put_be16s(f
, &s
->cdr
);
677 qemu_put_be16s(f
, &s
->ccr
);
678 qemu_put_be16s(f
, &s
->irr
);
679 qemu_put_be16s(f
, &s
->imr
);
680 qemu_put_be16s(f
, &s
->isr
);
681 qemu_put_be16s(f
, &s
->gprr
);
684 static int scoop_load(QEMUFile
*f
, void *opaque
, int version_id
)
686 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
687 qemu_get_be16s(f
, &s
->status
);
688 qemu_get_be16s(f
, &s
->power
);
689 qemu_get_be32s(f
, &s
->gpio_level
);
690 qemu_get_be32s(f
, &s
->gpio_dir
);
691 qemu_get_be32s(f
, &s
->prev_level
);
692 qemu_get_be16s(f
, &s
->mcr
);
693 qemu_get_be16s(f
, &s
->cdr
);
694 qemu_get_be16s(f
, &s
->ccr
);
695 qemu_get_be16s(f
, &s
->irr
);
696 qemu_get_be16s(f
, &s
->imr
);
697 qemu_get_be16s(f
, &s
->isr
);
698 qemu_get_be16s(f
, &s
->gprr
);
703 static struct scoop_info_s
*spitz_scoop_init(struct pxa2xx_state_s
*cpu
,
706 struct scoop_info_s
*s
;
708 s
= (struct scoop_info_s
*)
709 qemu_mallocz(sizeof(struct scoop_info_s
) * 2);
710 memset(s
, 0, sizeof(struct scoop_info_s
) * count
);
711 s
[0].target_base
= 0x10800000;
712 s
[1].target_base
= 0x08800040;
718 iomemtype
= cpu_register_io_memory(0, scoop_readfn
,
719 scoop_writefn
, &s
[0]);
720 cpu_register_physical_memory(s
[0].target_base
, 0x1000, iomemtype
);
721 register_savevm("scoop", 0, 0, scoop_save
, scoop_load
, &s
[0]);
726 iomemtype
= cpu_register_io_memory(0, scoop_readfn
,
727 scoop_writefn
, &s
[1]);
728 cpu_register_physical_memory(s
[1].target_base
, 0x1000, iomemtype
);
729 register_savevm("scoop", 1, 0, scoop_save
, scoop_load
, &s
[1]);
734 /* LCD backlight controller */
736 #define LCDTG_RESCTL 0x00
737 #define LCDTG_PHACTRL 0x01
738 #define LCDTG_DUTYCTRL 0x02
739 #define LCDTG_POWERREG0 0x03
740 #define LCDTG_POWERREG1 0x04
741 #define LCDTG_GPOR3 0x05
742 #define LCDTG_PICTRL 0x06
743 #define LCDTG_POLCTRL 0x07
745 static int bl_intensity
, bl_power
;
747 static void spitz_bl_update(struct pxa2xx_state_s
*s
)
749 if (bl_power
&& bl_intensity
)
750 spitz_printf("LCD Backlight now at %i/63\n", bl_intensity
);
752 spitz_printf("LCD Backlight now off\n");
755 static void spitz_bl_bit5(int line
, int level
, void *opaque
)
757 int prev
= bl_intensity
;
760 bl_intensity
&= ~0x20;
762 bl_intensity
|= 0x20;
764 if (bl_power
&& prev
!= bl_intensity
)
765 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
768 static void spitz_bl_power(int line
, int level
, void *opaque
)
771 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
774 static void spitz_lcdtg_dac_put(void *opaque
, uint8_t cmd
)
783 spitz_printf("LCD in QVGA mode\n");
785 spitz_printf("LCD in VGA mode\n");
789 bl_intensity
&= ~0x1f;
790 bl_intensity
|= value
;
792 spitz_bl_update((struct pxa2xx_state_s
*) opaque
);
795 case LCDTG_POWERREG0
:
796 /* Set common voltage to M62332FP */
803 #define CORGI_SSP_PORT 2
805 #define SPITZ_GPIO_LCDCON_CS 53
806 #define SPITZ_GPIO_ADS7846_CS 14
807 #define SPITZ_GPIO_MAX1111_CS 20
808 #define SPITZ_GPIO_TP_INT 11
810 static int lcd_en
, ads_en
, max_en
;
811 static struct max111x_s
*max1111
;
812 static struct ads7846_state_s
*ads7846
;
814 /* "Demux" the signal based on current chipselect */
815 static uint32_t corgi_ssp_read(void *opaque
)
820 return ads7846_read(ads7846
);
822 return max111x_read(max1111
);
826 static void corgi_ssp_write(void *opaque
, uint32_t value
)
829 spitz_lcdtg_dac_put(opaque
, value
);
831 ads7846_write(ads7846
, value
);
833 max111x_write(max1111
, value
);
836 static void corgi_ssp_gpio_cs(int line
, int level
, struct pxa2xx_state_s
*s
)
838 if (line
== SPITZ_GPIO_LCDCON_CS
)
840 else if (line
== SPITZ_GPIO_ADS7846_CS
)
842 else if (line
== SPITZ_GPIO_MAX1111_CS
)
846 #define MAX1111_BATT_VOLT 1
847 #define MAX1111_BATT_TEMP 2
848 #define MAX1111_ACIN_VOLT 3
850 #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */
851 #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */
852 #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */
854 static void spitz_adc_temp_on(int line
, int level
, void *opaque
)
860 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, SPITZ_BATTERY_TEMP
);
862 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
865 static void spitz_pendown_set(void *opaque
, int line
, int level
)
867 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
868 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_TP_INT
, level
);
871 static void spitz_ssp_save(QEMUFile
*f
, void *opaque
)
873 qemu_put_be32(f
, lcd_en
);
874 qemu_put_be32(f
, ads_en
);
875 qemu_put_be32(f
, max_en
);
876 qemu_put_be32(f
, bl_intensity
);
877 qemu_put_be32(f
, bl_power
);
880 static int spitz_ssp_load(QEMUFile
*f
, void *opaque
, int version_id
)
882 lcd_en
= qemu_get_be32(f
);
883 ads_en
= qemu_get_be32(f
);
884 max_en
= qemu_get_be32(f
);
885 bl_intensity
= qemu_get_be32(f
);
886 bl_power
= qemu_get_be32(f
);
891 static void spitz_ssp_attach(struct pxa2xx_state_s
*cpu
)
893 lcd_en
= ads_en
= max_en
= 0;
895 ads7846
= ads7846_init(qemu_allocate_irqs(spitz_pendown_set
, cpu
, 1)[0]);
897 max1111
= max1111_init(0);
898 max111x_set_input(max1111
, MAX1111_BATT_VOLT
, SPITZ_BATTERY_VOLT
);
899 max111x_set_input(max1111
, MAX1111_BATT_TEMP
, 0);
900 max111x_set_input(max1111
, MAX1111_ACIN_VOLT
, SPITZ_CHARGEON_ACIN
);
902 pxa2xx_ssp_attach(cpu
->ssp
[CORGI_SSP_PORT
- 1], corgi_ssp_read
,
903 corgi_ssp_write
, cpu
);
905 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_LCDCON_CS
,
906 (gpio_handler_t
) corgi_ssp_gpio_cs
, cpu
);
907 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_ADS7846_CS
,
908 (gpio_handler_t
) corgi_ssp_gpio_cs
, cpu
);
909 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_MAX1111_CS
,
910 (gpio_handler_t
) corgi_ssp_gpio_cs
, cpu
);
915 register_savevm("spitz_ssp", 0, 0, spitz_ssp_save
, spitz_ssp_load
, cpu
);
920 static void spitz_microdrive_attach(struct pxa2xx_state_s
*cpu
)
922 struct pcmcia_card_s
*md
;
923 BlockDriverState
*bs
= bs_table
[0];
925 if (bs
&& bdrv_is_inserted(bs
) && !bdrv_is_removable(bs
)) {
926 md
= dscm1xxxx_init(bs
);
927 pxa2xx_pcmcia_attach(cpu
->pcmcia
[1], md
);
931 /* Wm8750 and Max7310 on I2C */
933 #define AKITA_MAX_ADDR 0x18
934 #define SPITZ_WM_ADDRL 0x1b
935 #define SPITZ_WM_ADDRH 0x1a
937 #define SPITZ_GPIO_WM 5
940 static void spitz_wm8750_addr(int line
, int level
, void *opaque
)
942 i2c_slave
*wm
= (i2c_slave
*) opaque
;
944 i2c_set_slave_address(wm
, SPITZ_WM_ADDRH
);
946 i2c_set_slave_address(wm
, SPITZ_WM_ADDRL
);
950 static void spitz_i2c_setup(struct pxa2xx_state_s
*cpu
)
952 /* Attach the CPU on one end of our I2C bus. */
953 i2c_bus
*bus
= pxa2xx_i2c_bus(cpu
->i2c
[0]);
962 /* Attach a WM8750 to the bus */
963 wm
= wm8750_init(bus
, audio
);
965 spitz_wm8750_addr(0, 0, wm
);
966 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_WM
, spitz_wm8750_addr
, wm
);
967 /* .. and to the sound interface. */
968 cpu
->i2s
->opaque
= wm
;
969 cpu
->i2s
->codec_out
= wm8750_dac_dat
;
970 cpu
->i2s
->codec_in
= wm8750_adc_dat
;
971 wm8750_data_req_set(wm
, cpu
->i2s
->data_req
, cpu
->i2s
);
975 static void spitz_akita_i2c_setup(struct pxa2xx_state_s
*cpu
)
977 /* Attach a Max7310 to Akita I2C bus. */
978 i2c_set_slave_address(max7310_init(pxa2xx_i2c_bus(cpu
->i2c
[0])),
982 /* Other peripherals */
984 static void spitz_charge_switch(int line
, int level
, void *opaque
)
986 spitz_printf("Charging %s.\n", level
? "off" : "on");
989 static void spitz_discharge_switch(int line
, int level
, void *opaque
)
991 spitz_printf("Discharging %s.\n", level
? "on" : "off");
994 static void spitz_greenled_switch(int line
, int level
, void *opaque
)
996 spitz_printf("Green LED %s.\n", level
? "on" : "off");
999 static void spitz_orangeled_switch(int line
, int level
, void *opaque
)
1001 spitz_printf("Orange LED %s.\n", level
? "on" : "off");
1004 #define SPITZ_SCP_LED_GREEN 1
1005 #define SPITZ_SCP_JK_B 2
1006 #define SPITZ_SCP_CHRG_ON 3
1007 #define SPITZ_SCP_MUTE_L 4
1008 #define SPITZ_SCP_MUTE_R 5
1009 #define SPITZ_SCP_CF_POWER 6
1010 #define SPITZ_SCP_LED_ORANGE 7
1011 #define SPITZ_SCP_JK_A 8
1012 #define SPITZ_SCP_ADC_TEMP_ON 9
1013 #define SPITZ_SCP2_IR_ON 1
1014 #define SPITZ_SCP2_AKIN_PULLUP 2
1015 #define SPITZ_SCP2_BACKLIGHT_CONT 7
1016 #define SPITZ_SCP2_BACKLIGHT_ON 8
1017 #define SPITZ_SCP2_MIC_BIAS 9
1019 static void spitz_scoop_gpio_setup(struct pxa2xx_state_s
*cpu
,
1020 struct scoop_info_s
*scp
, int num
)
1022 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_CHRG_ON
,
1023 spitz_charge_switch
, cpu
);
1024 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_JK_B
,
1025 spitz_discharge_switch
, cpu
);
1026 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_LED_GREEN
,
1027 spitz_greenled_switch
, cpu
);
1028 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_LED_ORANGE
,
1029 spitz_orangeled_switch
, cpu
);
1032 scoop_gpio_handler_set(&scp
[1], SPITZ_SCP2_BACKLIGHT_CONT
,
1033 spitz_bl_bit5
, cpu
);
1034 scoop_gpio_handler_set(&scp
[1], SPITZ_SCP2_BACKLIGHT_ON
,
1035 spitz_bl_power
, cpu
);
1038 scoop_gpio_handler_set(&scp
[0], SPITZ_SCP_ADC_TEMP_ON
,
1039 spitz_adc_temp_on
, cpu
);
1042 #define SPITZ_GPIO_HSYNC 22
1043 #define SPITZ_GPIO_SD_DETECT 9
1044 #define SPITZ_GPIO_SD_WP 81
1045 #define SPITZ_GPIO_ON_RESET 89
1046 #define SPITZ_GPIO_BAT_COVER 90
1047 #define SPITZ_GPIO_CF1_IRQ 105
1048 #define SPITZ_GPIO_CF1_CD 94
1049 #define SPITZ_GPIO_CF2_IRQ 106
1050 #define SPITZ_GPIO_CF2_CD 93
1054 static void spitz_lcd_hsync_handler(void *opaque
)
1056 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1057 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_HSYNC
, spitz_hsync
);
1061 static void spitz_mmc_coverswitch_change(void *opaque
, int in
)
1063 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1064 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SD_DETECT
, in
);
1067 static void spitz_mmc_writeprotect_change(void *opaque
, int wp
)
1069 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1070 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SD_WP
, wp
);
1073 static void spitz_pcmcia_cb(void *opaque
, int line
, int level
)
1075 struct pxa2xx_state_s
*cpu
= (struct pxa2xx_state_s
*) opaque
;
1076 static const int gpio_map
[] = {
1077 SPITZ_GPIO_CF1_IRQ
, SPITZ_GPIO_CF1_CD
,
1078 SPITZ_GPIO_CF2_IRQ
, SPITZ_GPIO_CF2_CD
,
1080 pxa2xx_gpio_set(cpu
->gpio
, gpio_map
[line
], level
);
1083 static void spitz_gpio_setup(struct pxa2xx_state_s
*cpu
, int slots
)
1085 qemu_irq
*pcmcia_cb
;
1087 * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
1088 * read to satisfy broken guests that poll-wait for hsync.
1089 * Simulating a real hsync event would be less practical and
1090 * wouldn't guarantee that a guest ever exits the loop.
1093 pxa2xx_gpio_read_notifier(cpu
->gpio
, spitz_lcd_hsync_handler
, cpu
);
1094 pxa2xx_lcd_vsync_cb(cpu
->lcd
, spitz_lcd_hsync_handler
, cpu
);
1097 pxa2xx_mmci_handlers(cpu
->mmc
, cpu
, spitz_mmc_writeprotect_change
,
1098 spitz_mmc_coverswitch_change
);
1100 /* Battery lock always closed */
1101 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_BAT_COVER
, 1);
1104 pxa2xx_gpio_handler_set(cpu
->gpio
, SPITZ_GPIO_ON_RESET
, pxa2xx_reset
, cpu
);
1106 /* PCMCIA signals: card's IRQ and Card-Detect */
1107 pcmcia_cb
= qemu_allocate_irqs(spitz_pcmcia_cb
, cpu
, slots
* 2);
1109 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[0], pcmcia_cb
[0], pcmcia_cb
[1]);
1111 pxa2xx_pcmcia_set_irq_cb(cpu
->pcmcia
[1], pcmcia_cb
[2], pcmcia_cb
[3]);
1113 /* Initialise the screen rotation related signals */
1114 spitz_gpio_invert
[3] = 0; /* Always open */
1115 if (graphic_rotate
) { /* Tablet mode */
1116 spitz_gpio_invert
[4] = 0;
1117 } else { /* Portrait mode */
1118 spitz_gpio_invert
[4] = 1;
1120 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SWA
, spitz_gpio_invert
[3]);
1121 pxa2xx_gpio_set(cpu
->gpio
, SPITZ_GPIO_SWB
, spitz_gpio_invert
[4]);
1124 /* Write the bootloader parameters memory area. */
1126 #define MAGIC_CHG(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | a)
1128 struct __attribute__ ((__packed__
)) sl_param_info
{
1129 uint32_t comadj_keyword
;
1132 uint32_t uuid_keyword
;
1135 uint32_t touch_keyword
;
1141 uint32_t adadj_keyword
;
1144 uint32_t phad_keyword
;
1146 } spitz_bootparam
= {
1147 .comadj_keyword
= MAGIC_CHG('C', 'M', 'A', 'D'),
1149 .uuid_keyword
= MAGIC_CHG('U', 'U', 'I', 'D'),
1151 .touch_keyword
= MAGIC_CHG('T', 'U', 'C', 'H'),
1153 .adadj_keyword
= MAGIC_CHG('B', 'V', 'A', 'D'),
1155 .phad_keyword
= MAGIC_CHG('P', 'H', 'A', 'D'),
1159 static void sl_bootparam_write(uint32_t ptr
)
1161 memcpy(phys_ram_base
+ ptr
, &spitz_bootparam
,
1162 sizeof(struct sl_param_info
));
1165 #define SL_PXA_PARAM_BASE 0xa0000a00
1168 enum spitz_model_e
{ spitz
, akita
, borzoi
, terrier
};
1170 static void spitz_common_init(int ram_size
, int vga_ram_size
,
1171 DisplayState
*ds
, const char *kernel_filename
,
1172 const char *kernel_cmdline
, const char *initrd_filename
,
1173 const char *cpu_model
, enum spitz_model_e model
, int arm_id
)
1175 uint32_t spitz_ram
= 0x04000000;
1176 uint32_t spitz_rom
= 0x00800000;
1177 struct pxa2xx_state_s
*cpu
;
1178 struct scoop_info_s
*scp
;
1181 cpu_model
= (model
== terrier
) ? "pxa270-c5" : "pxa270-c0";
1183 /* Setup CPU & memory */
1184 if (ram_size
< spitz_ram
+ spitz_rom
+ PXA2XX_INTERNAL_SIZE
) {
1185 fprintf(stderr
, "This platform requires %i bytes of memory\n",
1186 spitz_ram
+ spitz_rom
+ PXA2XX_INTERNAL_SIZE
);
1189 cpu
= pxa270_init(spitz_ram
, ds
, cpu_model
);
1191 sl_flash_register(cpu
, (model
== spitz
) ? FLASH_128M
: FLASH_1024M
);
1193 cpu_register_physical_memory(0, spitz_rom
,
1194 qemu_ram_alloc(spitz_rom
) | IO_MEM_ROM
);
1196 /* Setup peripherals */
1197 spitz_keyboard_register(cpu
);
1199 spitz_ssp_attach(cpu
);
1201 scp
= spitz_scoop_init(cpu
, (model
== akita
) ? 1 : 2);
1203 spitz_scoop_gpio_setup(cpu
, scp
, (model
== akita
) ? 1 : 2);
1205 spitz_gpio_setup(cpu
, (model
== akita
) ? 1 : 2);
1207 spitz_i2c_setup(cpu
);
1210 spitz_akita_i2c_setup(cpu
);
1212 if (model
== terrier
)
1213 /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
1214 spitz_microdrive_attach(cpu
);
1215 else if (model
!= akita
)
1216 /* A 4.0 GB microdrive is permanently sitting in CF slot 1. */
1217 spitz_microdrive_attach(cpu
);
1219 /* Setup initial (reset) machine state */
1220 cpu
->env
->regs
[15] = PXA2XX_SDRAM_BASE
;
1222 arm_load_kernel(cpu
->env
, spitz_ram
, kernel_filename
, kernel_cmdline
,
1223 initrd_filename
, arm_id
, PXA2XX_SDRAM_BASE
);
1224 sl_bootparam_write(SL_PXA_PARAM_BASE
- PXA2XX_SDRAM_BASE
);
1227 static void spitz_init(int ram_size
, int vga_ram_size
, int boot_device
,
1228 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1229 const char *kernel_filename
, const char *kernel_cmdline
,
1230 const char *initrd_filename
, const char *cpu_model
)
1232 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1233 kernel_cmdline
, initrd_filename
, cpu_model
, spitz
, 0x2c9);
1236 static void borzoi_init(int ram_size
, int vga_ram_size
, int boot_device
,
1237 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1238 const char *kernel_filename
, const char *kernel_cmdline
,
1239 const char *initrd_filename
, const char *cpu_model
)
1241 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1242 kernel_cmdline
, initrd_filename
, cpu_model
, borzoi
, 0x33f);
1245 static void akita_init(int ram_size
, int vga_ram_size
, int boot_device
,
1246 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1247 const char *kernel_filename
, const char *kernel_cmdline
,
1248 const char *initrd_filename
, const char *cpu_model
)
1250 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1251 kernel_cmdline
, initrd_filename
, cpu_model
, akita
, 0x2e8);
1254 static void terrier_init(int ram_size
, int vga_ram_size
, int boot_device
,
1255 DisplayState
*ds
, const char **fd_filename
, int snapshot
,
1256 const char *kernel_filename
, const char *kernel_cmdline
,
1257 const char *initrd_filename
, const char *cpu_model
)
1259 spitz_common_init(ram_size
, vga_ram_size
, ds
, kernel_filename
,
1260 kernel_cmdline
, initrd_filename
, cpu_model
, terrier
, 0x33f);
1263 QEMUMachine akitapda_machine
= {
1265 "Akita PDA (PXA270)",
1269 QEMUMachine spitzpda_machine
= {
1271 "Spitz PDA (PXA270)",
1275 QEMUMachine borzoipda_machine
= {
1277 "Borzoi PDA (PXA270)",
1281 QEMUMachine terrierpda_machine
= {
1283 "Terrier PDA (PXA270)",