tests/qemu-iotests: Rework the checks and spots using GNU sed
[qemu.git] / hw / arm / spitz.c
blob5aab0b8565745bb7227826aa4dcc4acd01fca99a
1 /*
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.
9 * Contributions after 2012-01-13 are licensed under the terms of the
10 * GNU GPL, version 2 or (at your option) any later version.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "hw/arm/pxa.h"
16 #include "hw/arm/boot.h"
17 #include "sysemu/runstate.h"
18 #include "sysemu/sysemu.h"
19 #include "hw/pcmcia.h"
20 #include "hw/qdev-properties.h"
21 #include "hw/i2c/i2c.h"
22 #include "hw/irq.h"
23 #include "hw/ssi/ssi.h"
24 #include "hw/block/flash.h"
25 #include "qemu/timer.h"
26 #include "qemu/log.h"
27 #include "hw/arm/sharpsl.h"
28 #include "ui/console.h"
29 #include "hw/audio/wm8750.h"
30 #include "audio/audio.h"
31 #include "hw/boards.h"
32 #include "hw/sysbus.h"
33 #include "hw/adc/max111x.h"
34 #include "migration/vmstate.h"
35 #include "exec/address-spaces.h"
36 #include "cpu.h"
37 #include "qom/object.h"
39 enum spitz_model_e { spitz, akita, borzoi, terrier };
41 struct SpitzMachineClass {
42 MachineClass parent;
43 enum spitz_model_e model;
44 int arm_id;
47 struct SpitzMachineState {
48 MachineState parent;
49 PXA2xxState *mpu;
50 DeviceState *mux;
51 DeviceState *lcdtg;
52 DeviceState *ads7846;
53 DeviceState *max1111;
54 DeviceState *scp0;
55 DeviceState *scp1;
56 DeviceState *misc_gpio;
59 #define TYPE_SPITZ_MACHINE "spitz-common"
60 OBJECT_DECLARE_TYPE(SpitzMachineState, SpitzMachineClass, SPITZ_MACHINE)
62 #define zaurus_printf(format, ...) \
63 fprintf(stderr, "%s: " format, __func__, ##__VA_ARGS__)
65 /* Spitz Flash */
66 #define FLASH_BASE 0x0c000000
67 #define FLASH_ECCLPLB 0x00 /* Line parity 7 - 0 bit */
68 #define FLASH_ECCLPUB 0x04 /* Line parity 15 - 8 bit */
69 #define FLASH_ECCCP 0x08 /* Column parity 5 - 0 bit */
70 #define FLASH_ECCCNTR 0x0c /* ECC byte counter */
71 #define FLASH_ECCCLRR 0x10 /* Clear ECC */
72 #define FLASH_FLASHIO 0x14 /* Flash I/O */
73 #define FLASH_FLASHCTL 0x18 /* Flash Control */
75 #define FLASHCTL_CE0 (1 << 0)
76 #define FLASHCTL_CLE (1 << 1)
77 #define FLASHCTL_ALE (1 << 2)
78 #define FLASHCTL_WP (1 << 3)
79 #define FLASHCTL_CE1 (1 << 4)
80 #define FLASHCTL_RYBY (1 << 5)
81 #define FLASHCTL_NCE (FLASHCTL_CE0 | FLASHCTL_CE1)
83 #define TYPE_SL_NAND "sl-nand"
84 OBJECT_DECLARE_SIMPLE_TYPE(SLNANDState, SL_NAND)
86 struct SLNANDState {
87 SysBusDevice parent_obj;
89 MemoryRegion iomem;
90 DeviceState *nand;
91 uint8_t ctl;
92 uint8_t manf_id;
93 uint8_t chip_id;
94 ECCState ecc;
97 static uint64_t sl_read(void *opaque, hwaddr addr, unsigned size)
99 SLNANDState *s = (SLNANDState *) opaque;
100 int ryby;
102 switch (addr) {
103 #define BSHR(byte, from, to) ((s->ecc.lp[byte] >> (from - to)) & (1 << to))
104 case FLASH_ECCLPLB:
105 return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) |
106 BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7);
108 #define BSHL(byte, from, to) ((s->ecc.lp[byte] << (to - from)) & (1 << to))
109 case FLASH_ECCLPUB:
110 return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) |
111 BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7);
113 case FLASH_ECCCP:
114 return s->ecc.cp;
116 case FLASH_ECCCNTR:
117 return s->ecc.count & 0xff;
119 case FLASH_FLASHCTL:
120 nand_getpins(s->nand, &ryby);
121 if (ryby)
122 return s->ctl | FLASHCTL_RYBY;
123 else
124 return s->ctl;
126 case FLASH_FLASHIO:
127 if (size == 4) {
128 return ecc_digest(&s->ecc, nand_getio(s->nand)) |
129 (ecc_digest(&s->ecc, nand_getio(s->nand)) << 16);
131 return ecc_digest(&s->ecc, nand_getio(s->nand));
133 default:
134 qemu_log_mask(LOG_GUEST_ERROR,
135 "sl_read: bad register offset 0x%02" HWADDR_PRIx "\n",
136 addr);
138 return 0;
141 static void sl_write(void *opaque, hwaddr addr,
142 uint64_t value, unsigned size)
144 SLNANDState *s = (SLNANDState *) opaque;
146 switch (addr) {
147 case FLASH_ECCCLRR:
148 /* Value is ignored. */
149 ecc_reset(&s->ecc);
150 break;
152 case FLASH_FLASHCTL:
153 s->ctl = value & 0xff & ~FLASHCTL_RYBY;
154 nand_setpins(s->nand,
155 s->ctl & FLASHCTL_CLE,
156 s->ctl & FLASHCTL_ALE,
157 s->ctl & FLASHCTL_NCE,
158 s->ctl & FLASHCTL_WP,
160 break;
162 case FLASH_FLASHIO:
163 nand_setio(s->nand, ecc_digest(&s->ecc, value & 0xff));
164 break;
166 default:
167 qemu_log_mask(LOG_GUEST_ERROR,
168 "sl_write: bad register offset 0x%02" HWADDR_PRIx "\n",
169 addr);
173 enum {
174 FLASH_128M,
175 FLASH_1024M,
178 static const MemoryRegionOps sl_ops = {
179 .read = sl_read,
180 .write = sl_write,
181 .endianness = DEVICE_NATIVE_ENDIAN,
184 static void sl_flash_register(PXA2xxState *cpu, int size)
186 DeviceState *dev;
188 dev = qdev_new(TYPE_SL_NAND);
190 qdev_prop_set_uint8(dev, "manf_id", NAND_MFR_SAMSUNG);
191 if (size == FLASH_128M)
192 qdev_prop_set_uint8(dev, "chip_id", 0x73);
193 else if (size == FLASH_1024M)
194 qdev_prop_set_uint8(dev, "chip_id", 0xf1);
196 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
197 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, FLASH_BASE);
200 static void sl_nand_init(Object *obj)
202 SLNANDState *s = SL_NAND(obj);
203 SysBusDevice *dev = SYS_BUS_DEVICE(obj);
205 s->ctl = 0;
207 memory_region_init_io(&s->iomem, obj, &sl_ops, s, "sl", 0x40);
208 sysbus_init_mmio(dev, &s->iomem);
211 static void sl_nand_realize(DeviceState *dev, Error **errp)
213 SLNANDState *s = SL_NAND(dev);
214 DriveInfo *nand;
216 /* FIXME use a qdev drive property instead of drive_get() */
217 nand = drive_get(IF_MTD, 0, 0);
218 s->nand = nand_init(nand ? blk_by_legacy_dinfo(nand) : NULL,
219 s->manf_id, s->chip_id);
222 /* Spitz Keyboard */
224 #define SPITZ_KEY_STROBE_NUM 11
225 #define SPITZ_KEY_SENSE_NUM 7
227 static const int spitz_gpio_key_sense[SPITZ_KEY_SENSE_NUM] = {
228 12, 17, 91, 34, 36, 38, 39
231 static const int spitz_gpio_key_strobe[SPITZ_KEY_STROBE_NUM] = {
232 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114
235 /* Eighth additional row maps the special keys */
236 static int spitz_keymap[SPITZ_KEY_SENSE_NUM + 1][SPITZ_KEY_STROBE_NUM] = {
237 { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 },
238 { -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 },
239 { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25, -1 , -1 , -1 },
240 { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26, -1 , 0x36, -1 },
241 { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34, -1 , 0x1c, 0x2a, -1 },
242 { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33, -1 , 0x48, -1 , -1 , 0x38 },
243 { 0x37, 0x3d, -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d, -1 , -1 },
244 { 0x52, 0x43, 0x01, 0x47, 0x49, -1 , -1 , -1 , -1 , -1 , -1 },
247 #define SPITZ_GPIO_AK_INT 13 /* Remote control */
248 #define SPITZ_GPIO_SYNC 16 /* Sync button */
249 #define SPITZ_GPIO_ON_KEY 95 /* Power button */
250 #define SPITZ_GPIO_SWA 97 /* Lid */
251 #define SPITZ_GPIO_SWB 96 /* Tablet mode */
253 /* The special buttons are mapped to unused keys */
254 static const int spitz_gpiomap[5] = {
255 SPITZ_GPIO_AK_INT, SPITZ_GPIO_SYNC, SPITZ_GPIO_ON_KEY,
256 SPITZ_GPIO_SWA, SPITZ_GPIO_SWB,
259 #define TYPE_SPITZ_KEYBOARD "spitz-keyboard"
260 OBJECT_DECLARE_SIMPLE_TYPE(SpitzKeyboardState, SPITZ_KEYBOARD)
262 struct SpitzKeyboardState {
263 SysBusDevice parent_obj;
265 qemu_irq sense[SPITZ_KEY_SENSE_NUM];
266 qemu_irq gpiomap[5];
267 int keymap[0x80];
268 uint16_t keyrow[SPITZ_KEY_SENSE_NUM];
269 uint16_t strobe_state;
270 uint16_t sense_state;
272 uint16_t pre_map[0x100];
273 uint16_t modifiers;
274 uint16_t imodifiers;
275 uint8_t fifo[16];
276 int fifopos, fifolen;
277 QEMUTimer *kbdtimer;
280 static void spitz_keyboard_sense_update(SpitzKeyboardState *s)
282 int i;
283 uint16_t strobe, sense = 0;
284 for (i = 0; i < SPITZ_KEY_SENSE_NUM; i ++) {
285 strobe = s->keyrow[i] & s->strobe_state;
286 if (strobe) {
287 sense |= 1 << i;
288 if (!(s->sense_state & (1 << i)))
289 qemu_irq_raise(s->sense[i]);
290 } else if (s->sense_state & (1 << i))
291 qemu_irq_lower(s->sense[i]);
294 s->sense_state = sense;
297 static void spitz_keyboard_strobe(void *opaque, int line, int level)
299 SpitzKeyboardState *s = (SpitzKeyboardState *) opaque;
301 if (level)
302 s->strobe_state |= 1 << line;
303 else
304 s->strobe_state &= ~(1 << line);
305 spitz_keyboard_sense_update(s);
308 static void spitz_keyboard_keydown(SpitzKeyboardState *s, int keycode)
310 int spitz_keycode = s->keymap[keycode & 0x7f];
311 if (spitz_keycode == -1)
312 return;
314 /* Handle the additional keys */
315 if ((spitz_keycode >> 4) == SPITZ_KEY_SENSE_NUM) {
316 qemu_set_irq(s->gpiomap[spitz_keycode & 0xf], (keycode < 0x80));
317 return;
320 if (keycode & 0x80)
321 s->keyrow[spitz_keycode >> 4] &= ~(1 << (spitz_keycode & 0xf));
322 else
323 s->keyrow[spitz_keycode >> 4] |= 1 << (spitz_keycode & 0xf);
325 spitz_keyboard_sense_update(s);
328 #define SPITZ_MOD_SHIFT (1 << 7)
329 #define SPITZ_MOD_CTRL (1 << 8)
330 #define SPITZ_MOD_FN (1 << 9)
332 #define QUEUE_KEY(c) s->fifo[(s->fifopos + s->fifolen ++) & 0xf] = c
334 static void spitz_keyboard_handler(void *opaque, int keycode)
336 SpitzKeyboardState *s = opaque;
337 uint16_t code;
338 int mapcode;
339 switch (keycode) {
340 case 0x2a: /* Left Shift */
341 s->modifiers |= 1;
342 break;
343 case 0xaa:
344 s->modifiers &= ~1;
345 break;
346 case 0x36: /* Right Shift */
347 s->modifiers |= 2;
348 break;
349 case 0xb6:
350 s->modifiers &= ~2;
351 break;
352 case 0x1d: /* Control */
353 s->modifiers |= 4;
354 break;
355 case 0x9d:
356 s->modifiers &= ~4;
357 break;
358 case 0x38: /* Alt */
359 s->modifiers |= 8;
360 break;
361 case 0xb8:
362 s->modifiers &= ~8;
363 break;
366 code = s->pre_map[mapcode = ((s->modifiers & 3) ?
367 (keycode | SPITZ_MOD_SHIFT) :
368 (keycode & ~SPITZ_MOD_SHIFT))];
370 if (code != mapcode) {
371 #if 0
372 if ((code & SPITZ_MOD_SHIFT) && !(s->modifiers & 1)) {
373 QUEUE_KEY(0x2a | (keycode & 0x80));
375 if ((code & SPITZ_MOD_CTRL) && !(s->modifiers & 4)) {
376 QUEUE_KEY(0x1d | (keycode & 0x80));
378 if ((code & SPITZ_MOD_FN) && !(s->modifiers & 8)) {
379 QUEUE_KEY(0x38 | (keycode & 0x80));
381 if ((code & SPITZ_MOD_FN) && (s->modifiers & 1)) {
382 QUEUE_KEY(0x2a | (~keycode & 0x80));
384 if ((code & SPITZ_MOD_FN) && (s->modifiers & 2)) {
385 QUEUE_KEY(0x36 | (~keycode & 0x80));
387 #else
388 if (keycode & 0x80) {
389 if ((s->imodifiers & 1 ) && !(s->modifiers & 1))
390 QUEUE_KEY(0x2a | 0x80);
391 if ((s->imodifiers & 4 ) && !(s->modifiers & 4))
392 QUEUE_KEY(0x1d | 0x80);
393 if ((s->imodifiers & 8 ) && !(s->modifiers & 8))
394 QUEUE_KEY(0x38 | 0x80);
395 if ((s->imodifiers & 0x10) && (s->modifiers & 1))
396 QUEUE_KEY(0x2a);
397 if ((s->imodifiers & 0x20) && (s->modifiers & 2))
398 QUEUE_KEY(0x36);
399 s->imodifiers = 0;
400 } else {
401 if ((code & SPITZ_MOD_SHIFT) &&
402 !((s->modifiers | s->imodifiers) & 1)) {
403 QUEUE_KEY(0x2a);
404 s->imodifiers |= 1;
406 if ((code & SPITZ_MOD_CTRL) &&
407 !((s->modifiers | s->imodifiers) & 4)) {
408 QUEUE_KEY(0x1d);
409 s->imodifiers |= 4;
411 if ((code & SPITZ_MOD_FN) &&
412 !((s->modifiers | s->imodifiers) & 8)) {
413 QUEUE_KEY(0x38);
414 s->imodifiers |= 8;
416 if ((code & SPITZ_MOD_FN) && (s->modifiers & 1) &&
417 !(s->imodifiers & 0x10)) {
418 QUEUE_KEY(0x2a | 0x80);
419 s->imodifiers |= 0x10;
421 if ((code & SPITZ_MOD_FN) && (s->modifiers & 2) &&
422 !(s->imodifiers & 0x20)) {
423 QUEUE_KEY(0x36 | 0x80);
424 s->imodifiers |= 0x20;
427 #endif
430 QUEUE_KEY((code & 0x7f) | (keycode & 0x80));
433 static void spitz_keyboard_tick(void *opaque)
435 SpitzKeyboardState *s = (SpitzKeyboardState *) opaque;
437 if (s->fifolen) {
438 spitz_keyboard_keydown(s, s->fifo[s->fifopos ++]);
439 s->fifolen --;
440 if (s->fifopos >= 16)
441 s->fifopos = 0;
444 timer_mod(s->kbdtimer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
445 NANOSECONDS_PER_SECOND / 32);
448 static void spitz_keyboard_pre_map(SpitzKeyboardState *s)
450 int i;
451 for (i = 0; i < 0x100; i ++)
452 s->pre_map[i] = i;
453 s->pre_map[0x02 | SPITZ_MOD_SHIFT] = 0x02 | SPITZ_MOD_SHIFT; /* exclam */
454 s->pre_map[0x28 | SPITZ_MOD_SHIFT] = 0x03 | SPITZ_MOD_SHIFT; /* quotedbl */
455 s->pre_map[0x04 | SPITZ_MOD_SHIFT] = 0x04 | SPITZ_MOD_SHIFT; /* # */
456 s->pre_map[0x05 | SPITZ_MOD_SHIFT] = 0x05 | SPITZ_MOD_SHIFT; /* dollar */
457 s->pre_map[0x06 | SPITZ_MOD_SHIFT] = 0x06 | SPITZ_MOD_SHIFT; /* percent */
458 s->pre_map[0x08 | SPITZ_MOD_SHIFT] = 0x07 | SPITZ_MOD_SHIFT; /* ampersand */
459 s->pre_map[0x28] = 0x08 | SPITZ_MOD_SHIFT; /* ' */
460 s->pre_map[0x0a | SPITZ_MOD_SHIFT] = 0x09 | SPITZ_MOD_SHIFT; /* ( */
461 s->pre_map[0x0b | SPITZ_MOD_SHIFT] = 0x0a | SPITZ_MOD_SHIFT; /* ) */
462 s->pre_map[0x29 | SPITZ_MOD_SHIFT] = 0x0b | SPITZ_MOD_SHIFT; /* tilde */
463 s->pre_map[0x03 | SPITZ_MOD_SHIFT] = 0x0c | SPITZ_MOD_SHIFT; /* at */
464 s->pre_map[0xd3] = 0x0e | SPITZ_MOD_FN; /* Delete */
465 s->pre_map[0x3a] = 0x0f | SPITZ_MOD_FN; /* Caps_Lock */
466 s->pre_map[0x07 | SPITZ_MOD_SHIFT] = 0x11 | SPITZ_MOD_FN; /* ^ */
467 s->pre_map[0x0d] = 0x12 | SPITZ_MOD_FN; /* equal */
468 s->pre_map[0x0d | SPITZ_MOD_SHIFT] = 0x13 | SPITZ_MOD_FN; /* plus */
469 s->pre_map[0x1a] = 0x14 | SPITZ_MOD_FN; /* [ */
470 s->pre_map[0x1b] = 0x15 | SPITZ_MOD_FN; /* ] */
471 s->pre_map[0x1a | SPITZ_MOD_SHIFT] = 0x16 | SPITZ_MOD_FN; /* { */
472 s->pre_map[0x1b | SPITZ_MOD_SHIFT] = 0x17 | SPITZ_MOD_FN; /* } */
473 s->pre_map[0x27] = 0x22 | SPITZ_MOD_FN; /* semicolon */
474 s->pre_map[0x27 | SPITZ_MOD_SHIFT] = 0x23 | SPITZ_MOD_FN; /* colon */
475 s->pre_map[0x09 | SPITZ_MOD_SHIFT] = 0x24 | SPITZ_MOD_FN; /* asterisk */
476 s->pre_map[0x2b] = 0x25 | SPITZ_MOD_FN; /* backslash */
477 s->pre_map[0x2b | SPITZ_MOD_SHIFT] = 0x26 | SPITZ_MOD_FN; /* bar */
478 s->pre_map[0x0c | SPITZ_MOD_SHIFT] = 0x30 | SPITZ_MOD_FN; /* _ */
479 s->pre_map[0x33 | SPITZ_MOD_SHIFT] = 0x33 | SPITZ_MOD_FN; /* less */
480 s->pre_map[0x35] = 0x33 | SPITZ_MOD_SHIFT; /* slash */
481 s->pre_map[0x34 | SPITZ_MOD_SHIFT] = 0x34 | SPITZ_MOD_FN; /* greater */
482 s->pre_map[0x35 | SPITZ_MOD_SHIFT] = 0x34 | SPITZ_MOD_SHIFT; /* question */
483 s->pre_map[0x49] = 0x48 | SPITZ_MOD_FN; /* Page_Up */
484 s->pre_map[0x51] = 0x50 | SPITZ_MOD_FN; /* Page_Down */
486 s->modifiers = 0;
487 s->imodifiers = 0;
488 s->fifopos = 0;
489 s->fifolen = 0;
492 #undef SPITZ_MOD_SHIFT
493 #undef SPITZ_MOD_CTRL
494 #undef SPITZ_MOD_FN
496 static int spitz_keyboard_post_load(void *opaque, int version_id)
498 SpitzKeyboardState *s = (SpitzKeyboardState *) opaque;
500 /* Release all pressed keys */
501 memset(s->keyrow, 0, sizeof(s->keyrow));
502 spitz_keyboard_sense_update(s);
503 s->modifiers = 0;
504 s->imodifiers = 0;
505 s->fifopos = 0;
506 s->fifolen = 0;
508 return 0;
511 static void spitz_keyboard_register(PXA2xxState *cpu)
513 int i;
514 DeviceState *dev;
515 SpitzKeyboardState *s;
517 dev = sysbus_create_simple(TYPE_SPITZ_KEYBOARD, -1, NULL);
518 s = SPITZ_KEYBOARD(dev);
520 for (i = 0; i < SPITZ_KEY_SENSE_NUM; i ++)
521 qdev_connect_gpio_out(dev, i, qdev_get_gpio_in(cpu->gpio, spitz_gpio_key_sense[i]));
523 for (i = 0; i < 5; i ++)
524 s->gpiomap[i] = qdev_get_gpio_in(cpu->gpio, spitz_gpiomap[i]);
526 if (!graphic_rotate)
527 s->gpiomap[4] = qemu_irq_invert(s->gpiomap[4]);
529 for (i = 0; i < 5; i++)
530 qemu_set_irq(s->gpiomap[i], 0);
532 for (i = 0; i < SPITZ_KEY_STROBE_NUM; i ++)
533 qdev_connect_gpio_out(cpu->gpio, spitz_gpio_key_strobe[i],
534 qdev_get_gpio_in(dev, i));
536 timer_mod(s->kbdtimer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
538 qemu_add_kbd_event_handler(spitz_keyboard_handler, s);
541 static void spitz_keyboard_init(Object *obj)
543 DeviceState *dev = DEVICE(obj);
544 SpitzKeyboardState *s = SPITZ_KEYBOARD(obj);
545 int i, j;
547 for (i = 0; i < 0x80; i ++)
548 s->keymap[i] = -1;
549 for (i = 0; i < SPITZ_KEY_SENSE_NUM + 1; i ++)
550 for (j = 0; j < SPITZ_KEY_STROBE_NUM; j ++)
551 if (spitz_keymap[i][j] != -1)
552 s->keymap[spitz_keymap[i][j]] = (i << 4) | j;
554 spitz_keyboard_pre_map(s);
556 qdev_init_gpio_in(dev, spitz_keyboard_strobe, SPITZ_KEY_STROBE_NUM);
557 qdev_init_gpio_out(dev, s->sense, SPITZ_KEY_SENSE_NUM);
560 static void spitz_keyboard_realize(DeviceState *dev, Error **errp)
562 SpitzKeyboardState *s = SPITZ_KEYBOARD(dev);
563 s->kbdtimer = timer_new_ns(QEMU_CLOCK_VIRTUAL, spitz_keyboard_tick, s);
566 /* LCD backlight controller */
568 #define LCDTG_RESCTL 0x00
569 #define LCDTG_PHACTRL 0x01
570 #define LCDTG_DUTYCTRL 0x02
571 #define LCDTG_POWERREG0 0x03
572 #define LCDTG_POWERREG1 0x04
573 #define LCDTG_GPOR3 0x05
574 #define LCDTG_PICTRL 0x06
575 #define LCDTG_POLCTRL 0x07
577 #define TYPE_SPITZ_LCDTG "spitz-lcdtg"
578 OBJECT_DECLARE_SIMPLE_TYPE(SpitzLCDTG, SPITZ_LCDTG)
580 struct SpitzLCDTG {
581 SSIPeripheral ssidev;
582 uint32_t bl_intensity;
583 uint32_t bl_power;
586 static void spitz_bl_update(SpitzLCDTG *s)
588 if (s->bl_power && s->bl_intensity)
589 zaurus_printf("LCD Backlight now at %u/63\n", s->bl_intensity);
590 else
591 zaurus_printf("LCD Backlight now off\n");
594 static inline void spitz_bl_bit5(void *opaque, int line, int level)
596 SpitzLCDTG *s = opaque;
597 int prev = s->bl_intensity;
599 if (level)
600 s->bl_intensity &= ~0x20;
601 else
602 s->bl_intensity |= 0x20;
604 if (s->bl_power && prev != s->bl_intensity)
605 spitz_bl_update(s);
608 static inline void spitz_bl_power(void *opaque, int line, int level)
610 SpitzLCDTG *s = opaque;
611 s->bl_power = !!level;
612 spitz_bl_update(s);
615 static uint32_t spitz_lcdtg_transfer(SSIPeripheral *dev, uint32_t value)
617 SpitzLCDTG *s = SPITZ_LCDTG(dev);
618 int addr;
619 addr = value >> 5;
620 value &= 0x1f;
622 switch (addr) {
623 case LCDTG_RESCTL:
624 if (value)
625 zaurus_printf("LCD in QVGA mode\n");
626 else
627 zaurus_printf("LCD in VGA mode\n");
628 break;
630 case LCDTG_DUTYCTRL:
631 s->bl_intensity &= ~0x1f;
632 s->bl_intensity |= value;
633 if (s->bl_power)
634 spitz_bl_update(s);
635 break;
637 case LCDTG_POWERREG0:
638 /* Set common voltage to M62332FP */
639 break;
641 return 0;
644 static void spitz_lcdtg_realize(SSIPeripheral *ssi, Error **errp)
646 SpitzLCDTG *s = SPITZ_LCDTG(ssi);
647 DeviceState *dev = DEVICE(s);
649 s->bl_power = 0;
650 s->bl_intensity = 0x20;
652 qdev_init_gpio_in_named(dev, spitz_bl_bit5, "bl_bit5", 1);
653 qdev_init_gpio_in_named(dev, spitz_bl_power, "bl_power", 1);
656 /* SSP devices */
658 #define CORGI_SSP_PORT 2
660 #define SPITZ_GPIO_LCDCON_CS 53
661 #define SPITZ_GPIO_ADS7846_CS 14
662 #define SPITZ_GPIO_MAX1111_CS 20
663 #define SPITZ_GPIO_TP_INT 11
665 #define TYPE_CORGI_SSP "corgi-ssp"
666 OBJECT_DECLARE_SIMPLE_TYPE(CorgiSSPState, CORGI_SSP)
668 /* "Demux" the signal based on current chipselect */
669 struct CorgiSSPState {
670 SSIPeripheral ssidev;
671 SSIBus *bus[3];
672 uint32_t enable[3];
675 static uint32_t corgi_ssp_transfer(SSIPeripheral *dev, uint32_t value)
677 CorgiSSPState *s = CORGI_SSP(dev);
678 int i;
680 for (i = 0; i < 3; i++) {
681 if (s->enable[i]) {
682 return ssi_transfer(s->bus[i], value);
685 return 0;
688 static void corgi_ssp_gpio_cs(void *opaque, int line, int level)
690 CorgiSSPState *s = (CorgiSSPState *)opaque;
691 assert(line >= 0 && line < 3);
692 s->enable[line] = !level;
695 #define MAX1111_BATT_VOLT 1
696 #define MAX1111_BATT_TEMP 2
697 #define MAX1111_ACIN_VOLT 3
699 #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */
700 #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */
701 #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */
703 static void corgi_ssp_realize(SSIPeripheral *d, Error **errp)
705 DeviceState *dev = DEVICE(d);
706 CorgiSSPState *s = CORGI_SSP(d);
708 qdev_init_gpio_in(dev, corgi_ssp_gpio_cs, 3);
709 s->bus[0] = ssi_create_bus(dev, "ssi0");
710 s->bus[1] = ssi_create_bus(dev, "ssi1");
711 s->bus[2] = ssi_create_bus(dev, "ssi2");
714 static void spitz_ssp_attach(SpitzMachineState *sms)
716 void *bus;
718 sms->mux = ssi_create_peripheral(sms->mpu->ssp[CORGI_SSP_PORT - 1],
719 TYPE_CORGI_SSP);
721 bus = qdev_get_child_bus(sms->mux, "ssi0");
722 sms->lcdtg = ssi_create_peripheral(bus, TYPE_SPITZ_LCDTG);
724 bus = qdev_get_child_bus(sms->mux, "ssi1");
725 sms->ads7846 = ssi_create_peripheral(bus, "ads7846");
726 qdev_connect_gpio_out(sms->ads7846, 0,
727 qdev_get_gpio_in(sms->mpu->gpio, SPITZ_GPIO_TP_INT));
729 bus = qdev_get_child_bus(sms->mux, "ssi2");
730 sms->max1111 = qdev_new(TYPE_MAX_1111);
731 qdev_prop_set_uint8(sms->max1111, "input1" /* BATT_VOLT */,
732 SPITZ_BATTERY_VOLT);
733 qdev_prop_set_uint8(sms->max1111, "input2" /* BATT_TEMP */, 0);
734 qdev_prop_set_uint8(sms->max1111, "input3" /* ACIN_VOLT */,
735 SPITZ_CHARGEON_ACIN);
736 ssi_realize_and_unref(sms->max1111, bus, &error_fatal);
738 qdev_connect_gpio_out(sms->mpu->gpio, SPITZ_GPIO_LCDCON_CS,
739 qdev_get_gpio_in(sms->mux, 0));
740 qdev_connect_gpio_out(sms->mpu->gpio, SPITZ_GPIO_ADS7846_CS,
741 qdev_get_gpio_in(sms->mux, 1));
742 qdev_connect_gpio_out(sms->mpu->gpio, SPITZ_GPIO_MAX1111_CS,
743 qdev_get_gpio_in(sms->mux, 2));
746 /* CF Microdrive */
748 static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
750 PCMCIACardState *md;
751 DriveInfo *dinfo;
753 dinfo = drive_get(IF_IDE, 0, 0);
754 if (!dinfo || dinfo->media_cd)
755 return;
756 md = dscm1xxxx_init(dinfo);
757 pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
760 /* Wm8750 and Max7310 on I2C */
762 #define AKITA_MAX_ADDR 0x18
763 #define SPITZ_WM_ADDRL 0x1b
764 #define SPITZ_WM_ADDRH 0x1a
766 #define SPITZ_GPIO_WM 5
768 static void spitz_wm8750_addr(void *opaque, int line, int level)
770 I2CSlave *wm = (I2CSlave *) opaque;
771 if (level)
772 i2c_slave_set_address(wm, SPITZ_WM_ADDRH);
773 else
774 i2c_slave_set_address(wm, SPITZ_WM_ADDRL);
777 static void spitz_i2c_setup(PXA2xxState *cpu)
779 /* Attach the CPU on one end of our I2C bus. */
780 I2CBus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
782 DeviceState *wm;
784 /* Attach a WM8750 to the bus */
785 wm = DEVICE(i2c_slave_create_simple(bus, TYPE_WM8750, 0));
787 spitz_wm8750_addr(wm, 0, 0);
788 qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_WM,
789 qemu_allocate_irq(spitz_wm8750_addr, wm, 0));
790 /* .. and to the sound interface. */
791 cpu->i2s->opaque = wm;
792 cpu->i2s->codec_out = wm8750_dac_dat;
793 cpu->i2s->codec_in = wm8750_adc_dat;
794 wm8750_data_req_set(wm, cpu->i2s->data_req, cpu->i2s);
797 static void spitz_akita_i2c_setup(PXA2xxState *cpu)
799 /* Attach a Max7310 to Akita I2C bus. */
800 i2c_slave_create_simple(pxa2xx_i2c_bus(cpu->i2c[0]), "max7310",
801 AKITA_MAX_ADDR);
804 /* Other peripherals */
807 * Encapsulation of some miscellaneous GPIO line behaviour for the Spitz boards.
809 * QEMU interface:
810 * + named GPIO inputs "green-led", "orange-led", "charging", "discharging":
811 * these currently just print messages that the line has been signalled
812 * + named GPIO input "adc-temp-on": set to cause the battery-temperature
813 * value to be passed to the max111x ADC
814 * + named GPIO output "adc-temp": the ADC value, to be wired up to the max111x
816 #define TYPE_SPITZ_MISC_GPIO "spitz-misc-gpio"
817 OBJECT_DECLARE_SIMPLE_TYPE(SpitzMiscGPIOState, SPITZ_MISC_GPIO)
819 struct SpitzMiscGPIOState {
820 SysBusDevice parent_obj;
822 qemu_irq adc_value;
825 static void spitz_misc_charging(void *opaque, int n, int level)
827 zaurus_printf("Charging %s.\n", level ? "off" : "on");
830 static void spitz_misc_discharging(void *opaque, int n, int level)
832 zaurus_printf("Discharging %s.\n", level ? "off" : "on");
835 static void spitz_misc_green_led(void *opaque, int n, int level)
837 zaurus_printf("Green LED %s.\n", level ? "off" : "on");
840 static void spitz_misc_orange_led(void *opaque, int n, int level)
842 zaurus_printf("Orange LED %s.\n", level ? "off" : "on");
845 static void spitz_misc_adc_temp(void *opaque, int n, int level)
847 SpitzMiscGPIOState *s = SPITZ_MISC_GPIO(opaque);
848 int batt_temp = level ? SPITZ_BATTERY_TEMP : 0;
850 qemu_set_irq(s->adc_value, batt_temp);
853 static void spitz_misc_gpio_init(Object *obj)
855 SpitzMiscGPIOState *s = SPITZ_MISC_GPIO(obj);
856 DeviceState *dev = DEVICE(obj);
858 qdev_init_gpio_in_named(dev, spitz_misc_charging, "charging", 1);
859 qdev_init_gpio_in_named(dev, spitz_misc_discharging, "discharging", 1);
860 qdev_init_gpio_in_named(dev, spitz_misc_green_led, "green-led", 1);
861 qdev_init_gpio_in_named(dev, spitz_misc_orange_led, "orange-led", 1);
862 qdev_init_gpio_in_named(dev, spitz_misc_adc_temp, "adc-temp-on", 1);
864 qdev_init_gpio_out_named(dev, &s->adc_value, "adc-temp", 1);
867 #define SPITZ_SCP_LED_GREEN 1
868 #define SPITZ_SCP_JK_B 2
869 #define SPITZ_SCP_CHRG_ON 3
870 #define SPITZ_SCP_MUTE_L 4
871 #define SPITZ_SCP_MUTE_R 5
872 #define SPITZ_SCP_CF_POWER 6
873 #define SPITZ_SCP_LED_ORANGE 7
874 #define SPITZ_SCP_JK_A 8
875 #define SPITZ_SCP_ADC_TEMP_ON 9
876 #define SPITZ_SCP2_IR_ON 1
877 #define SPITZ_SCP2_AKIN_PULLUP 2
878 #define SPITZ_SCP2_BACKLIGHT_CONT 7
879 #define SPITZ_SCP2_BACKLIGHT_ON 8
880 #define SPITZ_SCP2_MIC_BIAS 9
882 static void spitz_scoop_gpio_setup(SpitzMachineState *sms)
884 DeviceState *miscdev = sysbus_create_simple(TYPE_SPITZ_MISC_GPIO, -1, NULL);
886 sms->misc_gpio = miscdev;
888 qdev_connect_gpio_out(sms->scp0, SPITZ_SCP_CHRG_ON,
889 qdev_get_gpio_in_named(miscdev, "charging", 0));
890 qdev_connect_gpio_out(sms->scp0, SPITZ_SCP_JK_B,
891 qdev_get_gpio_in_named(miscdev, "discharging", 0));
892 qdev_connect_gpio_out(sms->scp0, SPITZ_SCP_LED_GREEN,
893 qdev_get_gpio_in_named(miscdev, "green-led", 0));
894 qdev_connect_gpio_out(sms->scp0, SPITZ_SCP_LED_ORANGE,
895 qdev_get_gpio_in_named(miscdev, "orange-led", 0));
896 qdev_connect_gpio_out(sms->scp0, SPITZ_SCP_ADC_TEMP_ON,
897 qdev_get_gpio_in_named(miscdev, "adc-temp-on", 0));
898 qdev_connect_gpio_out_named(miscdev, "adc-temp", 0,
899 qdev_get_gpio_in(sms->max1111, MAX1111_BATT_TEMP));
901 if (sms->scp1) {
902 qdev_connect_gpio_out(sms->scp1, SPITZ_SCP2_BACKLIGHT_CONT,
903 qdev_get_gpio_in_named(sms->lcdtg, "bl_bit5", 0));
904 qdev_connect_gpio_out(sms->scp1, SPITZ_SCP2_BACKLIGHT_ON,
905 qdev_get_gpio_in_named(sms->lcdtg, "bl_power", 0));
909 #define SPITZ_GPIO_HSYNC 22
910 #define SPITZ_GPIO_SD_DETECT 9
911 #define SPITZ_GPIO_SD_WP 81
912 #define SPITZ_GPIO_ON_RESET 89
913 #define SPITZ_GPIO_BAT_COVER 90
914 #define SPITZ_GPIO_CF1_IRQ 105
915 #define SPITZ_GPIO_CF1_CD 94
916 #define SPITZ_GPIO_CF2_IRQ 106
917 #define SPITZ_GPIO_CF2_CD 93
919 static int spitz_hsync;
921 static void spitz_lcd_hsync_handler(void *opaque, int line, int level)
923 PXA2xxState *cpu = (PXA2xxState *) opaque;
924 qemu_set_irq(qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_HSYNC), spitz_hsync);
925 spitz_hsync ^= 1;
928 static void spitz_reset(void *opaque, int line, int level)
930 if (level) {
931 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
935 static void spitz_gpio_setup(PXA2xxState *cpu, int slots)
937 qemu_irq lcd_hsync;
938 qemu_irq reset;
941 * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
942 * read to satisfy broken guests that poll-wait for hsync.
943 * Simulating a real hsync event would be less practical and
944 * wouldn't guarantee that a guest ever exits the loop.
946 spitz_hsync = 0;
947 lcd_hsync = qemu_allocate_irq(spitz_lcd_hsync_handler, cpu, 0);
948 pxa2xx_gpio_read_notifier(cpu->gpio, lcd_hsync);
949 pxa2xx_lcd_vsync_notifier(cpu->lcd, lcd_hsync);
951 /* MMC/SD host */
952 pxa2xx_mmci_handlers(cpu->mmc,
953 qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_SD_WP),
954 qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_SD_DETECT));
956 /* Battery lock always closed */
957 qemu_irq_raise(qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_BAT_COVER));
959 /* Handle reset */
960 reset = qemu_allocate_irq(spitz_reset, cpu, 0);
961 qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_ON_RESET, reset);
963 /* PCMCIA signals: card's IRQ and Card-Detect */
964 if (slots >= 1)
965 pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[0],
966 qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_IRQ),
967 qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_CD));
968 if (slots >= 2)
969 pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[1],
970 qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_IRQ),
971 qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_CD));
974 /* Board init. */
975 #define SPITZ_RAM 0x04000000
976 #define SPITZ_ROM 0x00800000
978 static struct arm_boot_info spitz_binfo = {
979 .loader_start = PXA2XX_SDRAM_BASE,
980 .ram_size = 0x04000000,
983 static void spitz_common_init(MachineState *machine)
985 SpitzMachineClass *smc = SPITZ_MACHINE_GET_CLASS(machine);
986 SpitzMachineState *sms = SPITZ_MACHINE(machine);
987 enum spitz_model_e model = smc->model;
988 PXA2xxState *mpu;
989 MemoryRegion *address_space_mem = get_system_memory();
990 MemoryRegion *rom = g_new(MemoryRegion, 1);
992 /* Setup CPU & memory */
993 mpu = pxa270_init(address_space_mem, spitz_binfo.ram_size,
994 machine->cpu_type);
995 sms->mpu = mpu;
997 sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
999 memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
1000 memory_region_add_subregion(address_space_mem, 0, rom);
1002 /* Setup peripherals */
1003 spitz_keyboard_register(mpu);
1005 spitz_ssp_attach(sms);
1007 sms->scp0 = sysbus_create_simple("scoop", 0x10800000, NULL);
1008 if (model != akita) {
1009 sms->scp1 = sysbus_create_simple("scoop", 0x08800040, NULL);
1010 } else {
1011 sms->scp1 = NULL;
1014 spitz_scoop_gpio_setup(sms);
1016 spitz_gpio_setup(mpu, (model == akita) ? 1 : 2);
1018 spitz_i2c_setup(mpu);
1020 if (model == akita)
1021 spitz_akita_i2c_setup(mpu);
1023 if (model == terrier)
1024 /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
1025 spitz_microdrive_attach(mpu, 1);
1026 else if (model != akita)
1027 /* A 4.0 GB microdrive is permanently sitting in CF slot 0. */
1028 spitz_microdrive_attach(mpu, 0);
1030 spitz_binfo.board_id = smc->arm_id;
1031 arm_load_kernel(mpu->cpu, machine, &spitz_binfo);
1032 sl_bootparam_write(SL_PXA_PARAM_BASE);
1035 static void spitz_common_class_init(ObjectClass *oc, void *data)
1037 MachineClass *mc = MACHINE_CLASS(oc);
1039 mc->block_default_type = IF_IDE;
1040 mc->ignore_memory_transaction_failures = true;
1041 mc->init = spitz_common_init;
1044 static const TypeInfo spitz_common_info = {
1045 .name = TYPE_SPITZ_MACHINE,
1046 .parent = TYPE_MACHINE,
1047 .abstract = true,
1048 .instance_size = sizeof(SpitzMachineState),
1049 .class_size = sizeof(SpitzMachineClass),
1050 .class_init = spitz_common_class_init,
1053 static void akitapda_class_init(ObjectClass *oc, void *data)
1055 MachineClass *mc = MACHINE_CLASS(oc);
1056 SpitzMachineClass *smc = SPITZ_MACHINE_CLASS(oc);
1058 mc->desc = "Sharp SL-C1000 (Akita) PDA (PXA270)";
1059 mc->default_cpu_type = ARM_CPU_TYPE_NAME("pxa270-c0");
1060 smc->model = akita;
1061 smc->arm_id = 0x2e8;
1064 static const TypeInfo akitapda_type = {
1065 .name = MACHINE_TYPE_NAME("akita"),
1066 .parent = TYPE_SPITZ_MACHINE,
1067 .class_init = akitapda_class_init,
1070 static void spitzpda_class_init(ObjectClass *oc, void *data)
1072 MachineClass *mc = MACHINE_CLASS(oc);
1073 SpitzMachineClass *smc = SPITZ_MACHINE_CLASS(oc);
1075 mc->desc = "Sharp SL-C3000 (Spitz) PDA (PXA270)";
1076 mc->default_cpu_type = ARM_CPU_TYPE_NAME("pxa270-c0");
1077 smc->model = spitz;
1078 smc->arm_id = 0x2c9;
1081 static const TypeInfo spitzpda_type = {
1082 .name = MACHINE_TYPE_NAME("spitz"),
1083 .parent = TYPE_SPITZ_MACHINE,
1084 .class_init = spitzpda_class_init,
1087 static void borzoipda_class_init(ObjectClass *oc, void *data)
1089 MachineClass *mc = MACHINE_CLASS(oc);
1090 SpitzMachineClass *smc = SPITZ_MACHINE_CLASS(oc);
1092 mc->desc = "Sharp SL-C3100 (Borzoi) PDA (PXA270)";
1093 mc->default_cpu_type = ARM_CPU_TYPE_NAME("pxa270-c0");
1094 smc->model = borzoi;
1095 smc->arm_id = 0x33f;
1098 static const TypeInfo borzoipda_type = {
1099 .name = MACHINE_TYPE_NAME("borzoi"),
1100 .parent = TYPE_SPITZ_MACHINE,
1101 .class_init = borzoipda_class_init,
1104 static void terrierpda_class_init(ObjectClass *oc, void *data)
1106 MachineClass *mc = MACHINE_CLASS(oc);
1107 SpitzMachineClass *smc = SPITZ_MACHINE_CLASS(oc);
1109 mc->desc = "Sharp SL-C3200 (Terrier) PDA (PXA270)";
1110 mc->default_cpu_type = ARM_CPU_TYPE_NAME("pxa270-c5");
1111 smc->model = terrier;
1112 smc->arm_id = 0x33f;
1115 static const TypeInfo terrierpda_type = {
1116 .name = MACHINE_TYPE_NAME("terrier"),
1117 .parent = TYPE_SPITZ_MACHINE,
1118 .class_init = terrierpda_class_init,
1121 static void spitz_machine_init(void)
1123 type_register_static(&spitz_common_info);
1124 type_register_static(&akitapda_type);
1125 type_register_static(&spitzpda_type);
1126 type_register_static(&borzoipda_type);
1127 type_register_static(&terrierpda_type);
1130 type_init(spitz_machine_init)
1132 static bool is_version_0(void *opaque, int version_id)
1134 return version_id == 0;
1137 static const VMStateDescription vmstate_sl_nand_info = {
1138 .name = "sl-nand",
1139 .version_id = 0,
1140 .minimum_version_id = 0,
1141 .fields = (VMStateField[]) {
1142 VMSTATE_UINT8(ctl, SLNANDState),
1143 VMSTATE_STRUCT(ecc, SLNANDState, 0, vmstate_ecc_state, ECCState),
1144 VMSTATE_END_OF_LIST(),
1148 static Property sl_nand_properties[] = {
1149 DEFINE_PROP_UINT8("manf_id", SLNANDState, manf_id, NAND_MFR_SAMSUNG),
1150 DEFINE_PROP_UINT8("chip_id", SLNANDState, chip_id, 0xf1),
1151 DEFINE_PROP_END_OF_LIST(),
1154 static void sl_nand_class_init(ObjectClass *klass, void *data)
1156 DeviceClass *dc = DEVICE_CLASS(klass);
1158 dc->vmsd = &vmstate_sl_nand_info;
1159 device_class_set_props(dc, sl_nand_properties);
1160 dc->realize = sl_nand_realize;
1161 /* Reason: init() method uses drive_get() */
1162 dc->user_creatable = false;
1165 static const TypeInfo sl_nand_info = {
1166 .name = TYPE_SL_NAND,
1167 .parent = TYPE_SYS_BUS_DEVICE,
1168 .instance_size = sizeof(SLNANDState),
1169 .instance_init = sl_nand_init,
1170 .class_init = sl_nand_class_init,
1173 static const VMStateDescription vmstate_spitz_kbd = {
1174 .name = "spitz-keyboard",
1175 .version_id = 1,
1176 .minimum_version_id = 0,
1177 .post_load = spitz_keyboard_post_load,
1178 .fields = (VMStateField[]) {
1179 VMSTATE_UINT16(sense_state, SpitzKeyboardState),
1180 VMSTATE_UINT16(strobe_state, SpitzKeyboardState),
1181 VMSTATE_UNUSED_TEST(is_version_0, 5),
1182 VMSTATE_END_OF_LIST(),
1186 static void spitz_keyboard_class_init(ObjectClass *klass, void *data)
1188 DeviceClass *dc = DEVICE_CLASS(klass);
1190 dc->vmsd = &vmstate_spitz_kbd;
1191 dc->realize = spitz_keyboard_realize;
1194 static const TypeInfo spitz_keyboard_info = {
1195 .name = TYPE_SPITZ_KEYBOARD,
1196 .parent = TYPE_SYS_BUS_DEVICE,
1197 .instance_size = sizeof(SpitzKeyboardState),
1198 .instance_init = spitz_keyboard_init,
1199 .class_init = spitz_keyboard_class_init,
1202 static const VMStateDescription vmstate_corgi_ssp_regs = {
1203 .name = "corgi-ssp",
1204 .version_id = 2,
1205 .minimum_version_id = 2,
1206 .fields = (VMStateField[]) {
1207 VMSTATE_SSI_PERIPHERAL(ssidev, CorgiSSPState),
1208 VMSTATE_UINT32_ARRAY(enable, CorgiSSPState, 3),
1209 VMSTATE_END_OF_LIST(),
1213 static void corgi_ssp_class_init(ObjectClass *klass, void *data)
1215 DeviceClass *dc = DEVICE_CLASS(klass);
1216 SSIPeripheralClass *k = SSI_PERIPHERAL_CLASS(klass);
1218 k->realize = corgi_ssp_realize;
1219 k->transfer = corgi_ssp_transfer;
1220 dc->vmsd = &vmstate_corgi_ssp_regs;
1223 static const TypeInfo corgi_ssp_info = {
1224 .name = TYPE_CORGI_SSP,
1225 .parent = TYPE_SSI_PERIPHERAL,
1226 .instance_size = sizeof(CorgiSSPState),
1227 .class_init = corgi_ssp_class_init,
1230 static const VMStateDescription vmstate_spitz_lcdtg_regs = {
1231 .name = "spitz-lcdtg",
1232 .version_id = 1,
1233 .minimum_version_id = 1,
1234 .fields = (VMStateField[]) {
1235 VMSTATE_SSI_PERIPHERAL(ssidev, SpitzLCDTG),
1236 VMSTATE_UINT32(bl_intensity, SpitzLCDTG),
1237 VMSTATE_UINT32(bl_power, SpitzLCDTG),
1238 VMSTATE_END_OF_LIST(),
1242 static void spitz_lcdtg_class_init(ObjectClass *klass, void *data)
1244 DeviceClass *dc = DEVICE_CLASS(klass);
1245 SSIPeripheralClass *k = SSI_PERIPHERAL_CLASS(klass);
1247 k->realize = spitz_lcdtg_realize;
1248 k->transfer = spitz_lcdtg_transfer;
1249 dc->vmsd = &vmstate_spitz_lcdtg_regs;
1252 static const TypeInfo spitz_lcdtg_info = {
1253 .name = TYPE_SPITZ_LCDTG,
1254 .parent = TYPE_SSI_PERIPHERAL,
1255 .instance_size = sizeof(SpitzLCDTG),
1256 .class_init = spitz_lcdtg_class_init,
1259 static const TypeInfo spitz_misc_gpio_info = {
1260 .name = TYPE_SPITZ_MISC_GPIO,
1261 .parent = TYPE_SYS_BUS_DEVICE,
1262 .instance_size = sizeof(SpitzMiscGPIOState),
1263 .instance_init = spitz_misc_gpio_init,
1265 * No class_init required: device has no internal state so does not
1266 * need to set up reset or vmstate, and does not have a realize method.
1270 static void spitz_register_types(void)
1272 type_register_static(&corgi_ssp_info);
1273 type_register_static(&spitz_lcdtg_info);
1274 type_register_static(&spitz_keyboard_info);
1275 type_register_static(&sl_nand_info);
1276 type_register_static(&spitz_misc_gpio_info);
1279 type_init(spitz_register_types)