spitz.c 33.0 KB
Newer Older
1 2 3 4 5 6 7
/*
 * PXA270-based Clamshell PDA platforms.
 *
 * Copyright (c) 2006 Openedhand Ltd.
 * Written by Andrzej Zaborowski <balrog@zabor.org>
 *
 * This code is licensed under the GNU GPL v2.
8 9 10
 *
 * Contributions after 2012-01-13 are licensed under the terms of the
 * GNU GPL, version 2 or (at your option) any later version.
11 12
 */

13
#include "hw/hw.h"
P
Paolo Bonzini 已提交
14
#include "hw/arm/pxa.h"
15
#include "hw/arm/arm.h"
16
#include "sysemu/sysemu.h"
17
#include "hw/pcmcia.h"
P
Paolo Bonzini 已提交
18
#include "hw/i2c/i2c.h"
19
#include "hw/ssi.h"
P
Paolo Bonzini 已提交
20
#include "hw/block/flash.h"
21
#include "qemu/timer.h"
22
#include "hw/devices.h"
P
Paolo Bonzini 已提交
23
#include "hw/arm/sharpsl.h"
24
#include "ui/console.h"
25
#include "block/block.h"
P
pbrook 已提交
26
#include "audio/audio.h"
27
#include "hw/boards.h"
28
#include "sysemu/block-backend.h"
29
#include "sysemu/blockdev.h"
30
#include "hw/sysbus.h"
31
#include "exec/address-spaces.h"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

#undef REG_FMT
#define REG_FMT			"0x%02lx"

/* Spitz Flash */
#define FLASH_BASE		0x0c000000
#define FLASH_ECCLPLB		0x00	/* Line parity 7 - 0 bit */
#define FLASH_ECCLPUB		0x04	/* Line parity 15 - 8 bit */
#define FLASH_ECCCP		0x08	/* Column parity 5 - 0 bit */
#define FLASH_ECCCNTR		0x0c	/* ECC byte counter */
#define FLASH_ECCCLRR		0x10	/* Clear ECC */
#define FLASH_FLASHIO		0x14	/* Flash I/O */
#define FLASH_FLASHCTL		0x18	/* Flash Control */

#define FLASHCTL_CE0		(1 << 0)
#define FLASHCTL_CLE		(1 << 1)
#define FLASHCTL_ALE		(1 << 2)
#define FLASHCTL_WP		(1 << 3)
#define FLASHCTL_CE1		(1 << 4)
#define FLASHCTL_RYBY		(1 << 5)
#define FLASHCTL_NCE		(FLASHCTL_CE0 | FLASHCTL_CE1)

54 55 56
#define TYPE_SL_NAND "sl-nand"
#define SL_NAND(obj) OBJECT_CHECK(SLNANDState, (obj), TYPE_SL_NAND)

P
Paul Brook 已提交
57
typedef struct {
58 59
    SysBusDevice parent_obj;

A
Avi Kivity 已提交
60
    MemoryRegion iomem;
J
Juha Riihimäki 已提交
61
    DeviceState *nand;
62
    uint8_t ctl;
63 64
    uint8_t manf_id;
    uint8_t chip_id;
P
Paul Brook 已提交
65 66
    ECCState ecc;
} SLNANDState;
67

A
Avi Kivity 已提交
68
static uint64_t sl_read(void *opaque, hwaddr addr, unsigned size)
69
{
P
Paul Brook 已提交
70
    SLNANDState *s = (SLNANDState *) opaque;
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    int ryby;

    switch (addr) {
#define BSHR(byte, from, to)	((s->ecc.lp[byte] >> (from - to)) & (1 << to))
    case FLASH_ECCLPLB:
        return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) |
                BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7);

#define BSHL(byte, from, to)	((s->ecc.lp[byte] << (to - from)) & (1 << to))
    case FLASH_ECCLPUB:
        return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) |
                BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7);

    case FLASH_ECCCP:
        return s->ecc.cp;

    case FLASH_ECCCNTR:
        return s->ecc.count & 0xff;

    case FLASH_FLASHCTL:
        nand_getpins(s->nand, &ryby);
        if (ryby)
            return s->ctl | FLASHCTL_RYBY;
        else
            return s->ctl;

    case FLASH_FLASHIO:
A
Avi Kivity 已提交
98 99 100 101
        if (size == 4) {
            return ecc_digest(&s->ecc, nand_getio(s->nand)) |
                (ecc_digest(&s->ecc, nand_getio(s->nand)) << 16);
        }
102 103 104
        return ecc_digest(&s->ecc, nand_getio(s->nand));

    default:
B
Blue Swirl 已提交
105
        zaurus_printf("Bad register offset " REG_FMT "\n", (unsigned long)addr);
106 107 108 109
    }
    return 0;
}

A
Avi Kivity 已提交
110
static void sl_write(void *opaque, hwaddr addr,
A
Avi Kivity 已提交
111
                     uint64_t value, unsigned size)
112
{
P
Paul Brook 已提交
113
    SLNANDState *s = (SLNANDState *) opaque;
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

    switch (addr) {
    case FLASH_ECCCLRR:
        /* Value is ignored.  */
        ecc_reset(&s->ecc);
        break;

    case FLASH_FLASHCTL:
        s->ctl = value & 0xff & ~FLASHCTL_RYBY;
        nand_setpins(s->nand,
                        s->ctl & FLASHCTL_CLE,
                        s->ctl & FLASHCTL_ALE,
                        s->ctl & FLASHCTL_NCE,
                        s->ctl & FLASHCTL_WP,
                        0);
        break;

    case FLASH_FLASHIO:
        nand_setio(s->nand, ecc_digest(&s->ecc, value & 0xff));
        break;

    default:
B
Blue Swirl 已提交
136
        zaurus_printf("Bad register offset " REG_FMT "\n", (unsigned long)addr);
137 138 139 140 141 142 143 144
    }
}

enum {
    FLASH_128M,
    FLASH_1024M,
};

A
Avi Kivity 已提交
145 146 147 148
static const MemoryRegionOps sl_ops = {
    .read = sl_read,
    .write = sl_write,
    .endianness = DEVICE_NATIVE_ENDIAN,
149 150
};

P
Paul Brook 已提交
151
static void sl_flash_register(PXA2xxState *cpu, int size)
152
{
153 154
    DeviceState *dev;

155
    dev = qdev_create(NULL, TYPE_SL_NAND);
156 157 158 159 160 161 162 163

    qdev_prop_set_uint8(dev, "manf_id", NAND_MFR_SAMSUNG);
    if (size == FLASH_128M)
        qdev_prop_set_uint8(dev, "chip_id", 0x73);
    else if (size == FLASH_1024M)
        qdev_prop_set_uint8(dev, "chip_id", 0xf1);

    qdev_init_nofail(dev);
164
    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, FLASH_BASE);
165 166
}

167 168 169
static int sl_nand_init(SysBusDevice *dev)
{
    SLNANDState *s = SL_NAND(dev);
170
    DriveInfo *nand;
171

172
    s->ctl = 0;
173
    nand = drive_get(IF_MTD, 0, 0);
174 175
    s->nand = nand_init(nand ? blk_bs(blk_by_legacy_dinfo(nand)) : NULL,
                        s->manf_id, s->chip_id);
176

177
    memory_region_init_io(&s->iomem, OBJECT(s), &sl_ops, s, "sl", 0x40);
178
    sysbus_init_mmio(dev, &s->iomem);
179 180

    return 0;
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
}

/* Spitz Keyboard */

#define SPITZ_KEY_STROBE_NUM	11
#define SPITZ_KEY_SENSE_NUM	7

static const int spitz_gpio_key_sense[SPITZ_KEY_SENSE_NUM] = {
    12, 17, 91, 34, 36, 38, 39
};

static const int spitz_gpio_key_strobe[SPITZ_KEY_STROBE_NUM] = {
    88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114
};

/* Eighth additional row maps the special keys */
static int spitz_keymap[SPITZ_KEY_SENSE_NUM + 1][SPITZ_KEY_STROBE_NUM] = {
    { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 },
    {  -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 },
    { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25,  -1 ,  -1 ,  -1  },
    { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26,  -1 , 0x36,  -1  },
    { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34,  -1 , 0x1c, 0x2a,  -1  },
203 204
    { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33,  -1 , 0x48,  -1 ,  -1 , 0x38 },
    { 0x37, 0x3d,  -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d,  -1 ,  -1  },
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    { 0x52, 0x43, 0x01, 0x47, 0x49,  -1 ,  -1 ,  -1 ,  -1 ,  -1 ,  -1  },
};

#define SPITZ_GPIO_AK_INT	13	/* Remote control */
#define SPITZ_GPIO_SYNC		16	/* Sync button */
#define SPITZ_GPIO_ON_KEY	95	/* Power button */
#define SPITZ_GPIO_SWA		97	/* Lid */
#define SPITZ_GPIO_SWB		96	/* Tablet mode */

/* The special buttons are mapped to unused keys */
static const int spitz_gpiomap[5] = {
    SPITZ_GPIO_AK_INT, SPITZ_GPIO_SYNC, SPITZ_GPIO_ON_KEY,
    SPITZ_GPIO_SWA, SPITZ_GPIO_SWB,
};

220 221 222 223
#define TYPE_SPITZ_KEYBOARD "spitz-keyboard"
#define SPITZ_KEYBOARD(obj) \
    OBJECT_CHECK(SpitzKeyboardState, (obj), TYPE_SPITZ_KEYBOARD)

P
Paul Brook 已提交
224
typedef struct {
225 226
    SysBusDevice parent_obj;

227 228
    qemu_irq sense[SPITZ_KEY_SENSE_NUM];
    qemu_irq gpiomap[5];
229 230 231 232 233 234 235 236 237 238 239
    int keymap[0x80];
    uint16_t keyrow[SPITZ_KEY_SENSE_NUM];
    uint16_t strobe_state;
    uint16_t sense_state;

    uint16_t pre_map[0x100];
    uint16_t modifiers;
    uint16_t imodifiers;
    uint8_t fifo[16];
    int fifopos, fifolen;
    QEMUTimer *kbdtimer;
P
Paul Brook 已提交
240
} SpitzKeyboardState;
241

P
Paul Brook 已提交
242
static void spitz_keyboard_sense_update(SpitzKeyboardState *s)
243 244 245 246 247 248 249 250
{
    int i;
    uint16_t strobe, sense = 0;
    for (i = 0; i < SPITZ_KEY_SENSE_NUM; i ++) {
        strobe = s->keyrow[i] & s->strobe_state;
        if (strobe) {
            sense |= 1 << i;
            if (!(s->sense_state & (1 << i)))
251
                qemu_irq_raise(s->sense[i]);
252
        } else if (s->sense_state & (1 << i))
253
            qemu_irq_lower(s->sense[i]);
254 255 256 257 258
    }

    s->sense_state = sense;
}

259
static void spitz_keyboard_strobe(void *opaque, int line, int level)
260
{
P
Paul Brook 已提交
261
    SpitzKeyboardState *s = (SpitzKeyboardState *) opaque;
262 263 264 265 266 267

    if (level)
        s->strobe_state |= 1 << line;
    else
        s->strobe_state &= ~(1 << line);
    spitz_keyboard_sense_update(s);
268 269
}

P
Paul Brook 已提交
270
static void spitz_keyboard_keydown(SpitzKeyboardState *s, int keycode)
271 272 273 274 275 276 277
{
    int spitz_keycode = s->keymap[keycode & 0x7f];
    if (spitz_keycode == -1)
        return;

    /* Handle the additional keys */
    if ((spitz_keycode >> 4) == SPITZ_KEY_SENSE_NUM) {
278
        qemu_set_irq(s->gpiomap[spitz_keycode & 0xf], (keycode < 0x80));
279 280 281 282 283 284 285 286 287 288 289
        return;
    }

    if (keycode & 0x80)
        s->keyrow[spitz_keycode >> 4] &= ~(1 << (spitz_keycode & 0xf));
    else
        s->keyrow[spitz_keycode >> 4] |= 1 << (spitz_keycode & 0xf);

    spitz_keyboard_sense_update(s);
}

290 291 292
#define SPITZ_MOD_SHIFT   (1 << 7)
#define SPITZ_MOD_CTRL    (1 << 8)
#define SPITZ_MOD_FN      (1 << 9)
293 294 295

#define QUEUE_KEY(c)	s->fifo[(s->fifopos + s->fifolen ++) & 0xf] = c

296
static void spitz_keyboard_handler(void *opaque, int keycode)
297
{
298
    SpitzKeyboardState *s = opaque;
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
    uint16_t code;
    int mapcode;
    switch (keycode) {
    case 0x2a:	/* Left Shift */
        s->modifiers |= 1;
        break;
    case 0xaa:
        s->modifiers &= ~1;
        break;
    case 0x36:	/* Right Shift */
        s->modifiers |= 2;
        break;
    case 0xb6:
        s->modifiers &= ~2;
        break;
    case 0x1d:	/* Control */
        s->modifiers |= 4;
        break;
    case 0x9d:
        s->modifiers &= ~4;
        break;
    case 0x38:	/* Alt */
        s->modifiers |= 8;
        break;
    case 0xb8:
        s->modifiers &= ~8;
        break;
    }

    code = s->pre_map[mapcode = ((s->modifiers & 3) ?
329 330
            (keycode | SPITZ_MOD_SHIFT) :
            (keycode & ~SPITZ_MOD_SHIFT))];
331 332 333

    if (code != mapcode) {
#if 0
334
        if ((code & SPITZ_MOD_SHIFT) && !(s->modifiers & 1)) {
335
            QUEUE_KEY(0x2a | (keycode & 0x80));
336 337
        }
        if ((code & SPITZ_MOD_CTRL) && !(s->modifiers & 4)) {
338
            QUEUE_KEY(0x1d | (keycode & 0x80));
339 340
        }
        if ((code & SPITZ_MOD_FN) && !(s->modifiers & 8)) {
341
            QUEUE_KEY(0x38 | (keycode & 0x80));
342 343
        }
        if ((code & SPITZ_MOD_FN) && (s->modifiers & 1)) {
344
            QUEUE_KEY(0x2a | (~keycode & 0x80));
345 346
        }
        if ((code & SPITZ_MOD_FN) && (s->modifiers & 2)) {
347
            QUEUE_KEY(0x36 | (~keycode & 0x80));
348
        }
349 350 351 352 353 354 355 356 357 358 359 360 361 362
#else
        if (keycode & 0x80) {
            if ((s->imodifiers & 1   ) && !(s->modifiers & 1))
                QUEUE_KEY(0x2a | 0x80);
            if ((s->imodifiers & 4   ) && !(s->modifiers & 4))
                QUEUE_KEY(0x1d | 0x80);
            if ((s->imodifiers & 8   ) && !(s->modifiers & 8))
                QUEUE_KEY(0x38 | 0x80);
            if ((s->imodifiers & 0x10) && (s->modifiers & 1))
                QUEUE_KEY(0x2a);
            if ((s->imodifiers & 0x20) && (s->modifiers & 2))
                QUEUE_KEY(0x36);
            s->imodifiers = 0;
        } else {
363 364
            if ((code & SPITZ_MOD_SHIFT) &&
                !((s->modifiers | s->imodifiers) & 1)) {
365 366 367
                QUEUE_KEY(0x2a);
                s->imodifiers |= 1;
            }
368 369
            if ((code & SPITZ_MOD_CTRL) &&
                !((s->modifiers | s->imodifiers) & 4)) {
370 371 372
                QUEUE_KEY(0x1d);
                s->imodifiers |= 4;
            }
373 374
            if ((code & SPITZ_MOD_FN) &&
                !((s->modifiers | s->imodifiers) & 8)) {
375 376 377
                QUEUE_KEY(0x38);
                s->imodifiers |= 8;
            }
378
            if ((code & SPITZ_MOD_FN) && (s->modifiers & 1) &&
379 380 381 382
                            !(s->imodifiers & 0x10)) {
                QUEUE_KEY(0x2a | 0x80);
                s->imodifiers |= 0x10;
            }
383
            if ((code & SPITZ_MOD_FN) && (s->modifiers & 2) &&
384 385 386 387 388 389 390 391 392 393 394 395 396
                            !(s->imodifiers & 0x20)) {
                QUEUE_KEY(0x36 | 0x80);
                s->imodifiers |= 0x20;
            }
        }
#endif
    }

    QUEUE_KEY((code & 0x7f) | (keycode & 0x80));
}

static void spitz_keyboard_tick(void *opaque)
{
P
Paul Brook 已提交
397
    SpitzKeyboardState *s = (SpitzKeyboardState *) opaque;
398 399 400 401 402 403 404 405

    if (s->fifolen) {
        spitz_keyboard_keydown(s, s->fifo[s->fifopos ++]);
        s->fifolen --;
        if (s->fifopos >= 16)
            s->fifopos = 0;
    }

406
    timer_mod(s->kbdtimer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
407
                   get_ticks_per_sec() / 32);
408 409
}

P
Paul Brook 已提交
410
static void spitz_keyboard_pre_map(SpitzKeyboardState *s)
411 412 413 414
{
    int i;
    for (i = 0; i < 0x100; i ++)
        s->pre_map[i] = i;
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
    s->pre_map[0x02 | SPITZ_MOD_SHIFT] = 0x02 | SPITZ_MOD_SHIFT; /* exclam */
    s->pre_map[0x28 | SPITZ_MOD_SHIFT] = 0x03 | SPITZ_MOD_SHIFT; /* quotedbl */
    s->pre_map[0x04 | SPITZ_MOD_SHIFT] = 0x04 | SPITZ_MOD_SHIFT; /* # */
    s->pre_map[0x05 | SPITZ_MOD_SHIFT] = 0x05 | SPITZ_MOD_SHIFT; /* dollar */
    s->pre_map[0x06 | SPITZ_MOD_SHIFT] = 0x06 | SPITZ_MOD_SHIFT; /* percent */
    s->pre_map[0x08 | SPITZ_MOD_SHIFT] = 0x07 | SPITZ_MOD_SHIFT; /* ampersand */
    s->pre_map[0x28]                   = 0x08 | SPITZ_MOD_SHIFT; /* ' */
    s->pre_map[0x0a | SPITZ_MOD_SHIFT] = 0x09 | SPITZ_MOD_SHIFT; /* ( */
    s->pre_map[0x0b | SPITZ_MOD_SHIFT] = 0x0a | SPITZ_MOD_SHIFT; /* ) */
    s->pre_map[0x29 | SPITZ_MOD_SHIFT] = 0x0b | SPITZ_MOD_SHIFT; /* tilde */
    s->pre_map[0x03 | SPITZ_MOD_SHIFT] = 0x0c | SPITZ_MOD_SHIFT; /* at */
    s->pre_map[0xd3]                   = 0x0e | SPITZ_MOD_FN;    /* Delete */
    s->pre_map[0x3a]                   = 0x0f | SPITZ_MOD_FN;    /* Caps_Lock */
    s->pre_map[0x07 | SPITZ_MOD_SHIFT] = 0x11 | SPITZ_MOD_FN;    /* ^ */
    s->pre_map[0x0d]                   = 0x12 | SPITZ_MOD_FN;    /* equal */
    s->pre_map[0x0d | SPITZ_MOD_SHIFT] = 0x13 | SPITZ_MOD_FN;    /* plus */
    s->pre_map[0x1a]                   = 0x14 | SPITZ_MOD_FN;    /* [ */
    s->pre_map[0x1b]                   = 0x15 | SPITZ_MOD_FN;    /* ] */
    s->pre_map[0x1a | SPITZ_MOD_SHIFT] = 0x16 | SPITZ_MOD_FN;    /* { */
    s->pre_map[0x1b | SPITZ_MOD_SHIFT] = 0x17 | SPITZ_MOD_FN;    /* } */
    s->pre_map[0x27]                   = 0x22 | SPITZ_MOD_FN;    /* semicolon */
    s->pre_map[0x27 | SPITZ_MOD_SHIFT] = 0x23 | SPITZ_MOD_FN;    /* colon */
    s->pre_map[0x09 | SPITZ_MOD_SHIFT] = 0x24 | SPITZ_MOD_FN;    /* asterisk */
    s->pre_map[0x2b]                   = 0x25 | SPITZ_MOD_FN;    /* backslash */
    s->pre_map[0x2b | SPITZ_MOD_SHIFT] = 0x26 | SPITZ_MOD_FN;    /* bar */
    s->pre_map[0x0c | SPITZ_MOD_SHIFT] = 0x30 | SPITZ_MOD_FN;    /* _ */
    s->pre_map[0x33 | SPITZ_MOD_SHIFT] = 0x33 | SPITZ_MOD_FN;    /* less */
    s->pre_map[0x35]                   = 0x33 | SPITZ_MOD_SHIFT; /* slash */
    s->pre_map[0x34 | SPITZ_MOD_SHIFT] = 0x34 | SPITZ_MOD_FN;    /* greater */
    s->pre_map[0x35 | SPITZ_MOD_SHIFT] = 0x34 | SPITZ_MOD_SHIFT; /* question */
    s->pre_map[0x49]                   = 0x48 | SPITZ_MOD_FN;    /* Page_Up */
    s->pre_map[0x51]                   = 0x50 | SPITZ_MOD_FN;    /* Page_Down */
447 448 449 450 451 452 453

    s->modifiers = 0;
    s->imodifiers = 0;
    s->fifopos = 0;
    s->fifolen = 0;
}

454 455 456
#undef SPITZ_MOD_SHIFT
#undef SPITZ_MOD_CTRL
#undef SPITZ_MOD_FN
457

458
static int spitz_keyboard_post_load(void *opaque, int version_id)
459
{
P
Paul Brook 已提交
460
    SpitzKeyboardState *s = (SpitzKeyboardState *) opaque;
461 462 463 464 465 466 467 468 469 470 471 472

    /* Release all pressed keys */
    memset(s->keyrow, 0, sizeof(s->keyrow));
    spitz_keyboard_sense_update(s);
    s->modifiers = 0;
    s->imodifiers = 0;
    s->fifopos = 0;
    s->fifolen = 0;

    return 0;
}

P
Paul Brook 已提交
473
static void spitz_keyboard_register(PXA2xxState *cpu)
474
{
475 476
    int i;
    DeviceState *dev;
P
Paul Brook 已提交
477
    SpitzKeyboardState *s;
478

479 480
    dev = sysbus_create_simple(TYPE_SPITZ_KEYBOARD, -1, NULL);
    s = SPITZ_KEYBOARD(dev);
481

482
    for (i = 0; i < SPITZ_KEY_SENSE_NUM; i ++)
483
        qdev_connect_gpio_out(dev, i, qdev_get_gpio_in(cpu->gpio, spitz_gpio_key_sense[i]));
484 485

    for (i = 0; i < 5; i ++)
486
        s->gpiomap[i] = qdev_get_gpio_in(cpu->gpio, spitz_gpiomap[i]);
487

488 489 490 491 492 493
    if (!graphic_rotate)
        s->gpiomap[4] = qemu_irq_invert(s->gpiomap[4]);

    for (i = 0; i < 5; i++)
        qemu_set_irq(s->gpiomap[i], 0);

494
    for (i = 0; i < SPITZ_KEY_STROBE_NUM; i ++)
495
        qdev_connect_gpio_out(cpu->gpio, spitz_gpio_key_strobe[i],
496 497
                qdev_get_gpio_in(dev, i));

498
    timer_mod(s->kbdtimer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
499 500 501 502

    qemu_add_kbd_event_handler(spitz_keyboard_handler, s);
}

503
static int spitz_keyboard_init(SysBusDevice *sbd)
504
{
505 506
    DeviceState *dev = DEVICE(sbd);
    SpitzKeyboardState *s = SPITZ_KEYBOARD(dev);
507 508 509 510 511 512 513 514
    int i, j;

    for (i = 0; i < 0x80; i ++)
        s->keymap[i] = -1;
    for (i = 0; i < SPITZ_KEY_SENSE_NUM + 1; i ++)
        for (j = 0; j < SPITZ_KEY_STROBE_NUM; j ++)
            if (spitz_keymap[i][j] != -1)
                s->keymap[spitz_keymap[i][j]] = (i << 4) | j;
515 516

    spitz_keyboard_pre_map(s);
517

518
    s->kbdtimer = timer_new_ns(QEMU_CLOCK_VIRTUAL, spitz_keyboard_tick, s);
519 520
    qdev_init_gpio_in(dev, spitz_keyboard_strobe, SPITZ_KEY_STROBE_NUM);
    qdev_init_gpio_out(dev, s->sense, SPITZ_KEY_SENSE_NUM);
521 522

    return 0;
523 524 525 526 527 528 529 530 531 532 533 534 535
}

/* LCD backlight controller */

#define LCDTG_RESCTL	0x00
#define LCDTG_PHACTRL	0x01
#define LCDTG_DUTYCTRL	0x02
#define LCDTG_POWERREG0	0x03
#define LCDTG_POWERREG1	0x04
#define LCDTG_GPOR3	0x05
#define LCDTG_PICTRL	0x06
#define LCDTG_POLCTRL	0x07

P
Paul Brook 已提交
536 537
typedef struct {
    SSISlave ssidev;
538 539
    uint32_t bl_intensity;
    uint32_t bl_power;
P
Paul Brook 已提交
540
} SpitzLCDTG;
541

P
Paul Brook 已提交
542
static void spitz_bl_update(SpitzLCDTG *s)
543
{
P
Paul Brook 已提交
544 545
    if (s->bl_power && s->bl_intensity)
        zaurus_printf("LCD Backlight now at %i/63\n", s->bl_intensity);
546
    else
547
        zaurus_printf("LCD Backlight now off\n");
548 549
}

P
Paul Brook 已提交
550 551 552
/* FIXME: Implement GPIO properly and remove this hack.  */
static SpitzLCDTG *spitz_lcdtg;

553
static inline void spitz_bl_bit5(void *opaque, int line, int level)
554
{
P
Paul Brook 已提交
555 556
    SpitzLCDTG *s = spitz_lcdtg;
    int prev = s->bl_intensity;
557 558

    if (level)
P
Paul Brook 已提交
559
        s->bl_intensity &= ~0x20;
560
    else
P
Paul Brook 已提交
561
        s->bl_intensity |= 0x20;
562

P
Paul Brook 已提交
563 564
    if (s->bl_power && prev != s->bl_intensity)
        spitz_bl_update(s);
565 566
}

567
static inline void spitz_bl_power(void *opaque, int line, int level)
568
{
P
Paul Brook 已提交
569 570 571
    SpitzLCDTG *s = spitz_lcdtg;
    s->bl_power = !!level;
    spitz_bl_update(s);
572 573
}

P
Paul Brook 已提交
574
static uint32_t spitz_lcdtg_transfer(SSISlave *dev, uint32_t value)
575
{
P
Paul Brook 已提交
576 577 578 579
    SpitzLCDTG *s = FROM_SSI_SLAVE(SpitzLCDTG, dev);
    int addr;
    addr = value >> 5;
    value &= 0x1f;
580 581 582 583

    switch (addr) {
    case LCDTG_RESCTL:
        if (value)
584
            zaurus_printf("LCD in QVGA mode\n");
585
        else
586
            zaurus_printf("LCD in VGA mode\n");
587 588 589
        break;

    case LCDTG_DUTYCTRL:
P
Paul Brook 已提交
590 591 592 593
        s->bl_intensity &= ~0x1f;
        s->bl_intensity |= value;
        if (s->bl_power)
            spitz_bl_update(s);
594 595 596 597 598 599
        break;

    case LCDTG_POWERREG0:
        /* Set common voltage to M62332FP */
        break;
    }
P
Paul Brook 已提交
600 601 602
    return 0;
}

603
static int spitz_lcdtg_init(SSISlave *dev)
P
Paul Brook 已提交
604 605 606 607 608 609 610
{
    SpitzLCDTG *s = FROM_SSI_SLAVE(SpitzLCDTG, dev);

    spitz_lcdtg = s;
    s->bl_power = 0;
    s->bl_intensity = 0x20;

611
    return 0;
612 613 614 615 616 617 618 619 620 621 622
}

/* SSP devices */

#define CORGI_SSP_PORT		2

#define SPITZ_GPIO_LCDCON_CS	53
#define SPITZ_GPIO_ADS7846_CS	14
#define SPITZ_GPIO_MAX1111_CS	20
#define SPITZ_GPIO_TP_INT	11

P
Paul Brook 已提交
623
static DeviceState *max1111;
624 625

/* "Demux" the signal based on current chipselect */
P
Paul Brook 已提交
626 627 628
typedef struct {
    SSISlave ssidev;
    SSIBus *bus[3];
629
    uint32_t enable[3];
P
Paul Brook 已提交
630
} CorgiSSPState;
631

P
Paul Brook 已提交
632
static uint32_t corgi_ssp_transfer(SSISlave *dev, uint32_t value)
633
{
P
Paul Brook 已提交
634 635 636 637 638 639 640 641 642
    CorgiSSPState *s = FROM_SSI_SLAVE(CorgiSSPState, dev);
    int i;

    for (i = 0; i < 3; i++) {
        if (s->enable[i]) {
            return ssi_transfer(s->bus[i], value);
        }
    }
    return 0;
643 644
}

645
static void corgi_ssp_gpio_cs(void *opaque, int line, int level)
646
{
P
Paul Brook 已提交
647 648 649
    CorgiSSPState *s = (CorgiSSPState *)opaque;
    assert(line >= 0 && line < 3);
    s->enable[line] = !level;
650 651 652 653 654 655 656 657 658 659
}

#define MAX1111_BATT_VOLT	1
#define MAX1111_BATT_TEMP	2
#define MAX1111_ACIN_VOLT	3

#define SPITZ_BATTERY_TEMP	0xe0	/* About 2.9V */
#define SPITZ_BATTERY_VOLT	0xd0	/* About 4.0V */
#define SPITZ_CHARGEON_ACIN	0x80	/* About 5.0V */

660
static void spitz_adc_temp_on(void *opaque, int line, int level)
661 662 663 664 665 666 667 668 669 670
{
    if (!max1111)
        return;

    if (level)
        max111x_set_input(max1111, MAX1111_BATT_TEMP, SPITZ_BATTERY_TEMP);
    else
        max111x_set_input(max1111, MAX1111_BATT_TEMP, 0);
}

671
static int corgi_ssp_init(SSISlave *d)
P
Paul Brook 已提交
672
{
673 674
    DeviceState *dev = DEVICE(d);
    CorgiSSPState *s = FROM_SSI_SLAVE(CorgiSSPState, d);
P
Paul Brook 已提交
675

676 677 678 679
    qdev_init_gpio_in(dev, corgi_ssp_gpio_cs, 3);
    s->bus[0] = ssi_create_bus(dev, "ssi0");
    s->bus[1] = ssi_create_bus(dev, "ssi1");
    s->bus[2] = ssi_create_bus(dev, "ssi2");
P
Paul Brook 已提交
680

681
    return 0;
P
Paul Brook 已提交
682 683
}

P
Paul Brook 已提交
684
static void spitz_ssp_attach(PXA2xxState *cpu)
685
{
P
Paul Brook 已提交
686 687 688 689 690
    DeviceState *mux;
    DeviceState *dev;
    void *bus;

    mux = ssi_create_slave(cpu->ssp[CORGI_SSP_PORT - 1], "corgi-ssp");
691

P
Paul Brook 已提交
692
    bus = qdev_get_child_bus(mux, "ssi0");
693
    ssi_create_slave(bus, "spitz-lcdtg");
694

P
Paul Brook 已提交
695 696 697
    bus = qdev_get_child_bus(mux, "ssi1");
    dev = ssi_create_slave(bus, "ads7846");
    qdev_connect_gpio_out(dev, 0,
698
                          qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_TP_INT));
699

P
Paul Brook 已提交
700 701
    bus = qdev_get_child_bus(mux, "ssi2");
    max1111 = ssi_create_slave(bus, "max1111");
702 703 704 705
    max111x_set_input(max1111, MAX1111_BATT_VOLT, SPITZ_BATTERY_VOLT);
    max111x_set_input(max1111, MAX1111_BATT_TEMP, 0);
    max111x_set_input(max1111, MAX1111_ACIN_VOLT, SPITZ_CHARGEON_ACIN);

706
    qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_LCDCON_CS,
P
Paul Brook 已提交
707
                        qdev_get_gpio_in(mux, 0));
708
    qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_ADS7846_CS,
P
Paul Brook 已提交
709
                        qdev_get_gpio_in(mux, 1));
710
    qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_MAX1111_CS,
P
Paul Brook 已提交
711
                        qdev_get_gpio_in(mux, 2));
712 713 714 715
}

/* CF Microdrive */

P
Paul Brook 已提交
716
static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
717
{
P
Paul Brook 已提交
718
    PCMCIACardState *md;
G
Gerd Hoffmann 已提交
719
    DriveInfo *dinfo;
720

G
Gerd Hoffmann 已提交
721
    dinfo = drive_get(IF_IDE, 0, 0);
722
    if (!dinfo || dinfo->media_cd)
T
ths 已提交
723
        return;
724 725
    md = dscm1xxxx_init(dinfo);
    pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
726 727
}

728 729 730
/* Wm8750 and Max7310 on I2C */

#define AKITA_MAX_ADDR	0x18
731 732
#define SPITZ_WM_ADDRL	0x1b
#define SPITZ_WM_ADDRH	0x1a
733 734 735

#define SPITZ_GPIO_WM	5

736
static void spitz_wm8750_addr(void *opaque, int line, int level)
737
{
738
    I2CSlave *wm = (I2CSlave *) opaque;
739 740 741 742 743 744
    if (level)
        i2c_set_slave_address(wm, SPITZ_WM_ADDRH);
    else
        i2c_set_slave_address(wm, SPITZ_WM_ADDRL);
}

P
Paul Brook 已提交
745
static void spitz_i2c_setup(PXA2xxState *cpu)
746 747
{
    /* Attach the CPU on one end of our I2C bus.  */
A
Andreas Färber 已提交
748
    I2CBus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
749

P
Paul Brook 已提交
750
    DeviceState *wm;
751 752

    /* Attach a WM8750 to the bus */
P
Paul Brook 已提交
753
    wm = i2c_create_slave(bus, "wm8750", 0);
754

755
    spitz_wm8750_addr(wm, 0, 0);
756
    qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_WM,
757
                          qemu_allocate_irq(spitz_wm8750_addr, wm, 0));
758 759 760 761 762 763 764
    /* .. and to the sound interface.  */
    cpu->i2s->opaque = wm;
    cpu->i2s->codec_out = wm8750_dac_dat;
    cpu->i2s->codec_in = wm8750_adc_dat;
    wm8750_data_req_set(wm, cpu->i2s->data_req, cpu->i2s);
}

P
Paul Brook 已提交
765
static void spitz_akita_i2c_setup(PXA2xxState *cpu)
766 767
{
    /* Attach a Max7310 to Akita I2C bus.  */
P
Paul Brook 已提交
768 769
    i2c_create_slave(pxa2xx_i2c_bus(cpu->i2c[0]), "max7310",
                     AKITA_MAX_ADDR);
770 771
}

772 773
/* Other peripherals */

774
static void spitz_out_switch(void *opaque, int line, int level)
775
{
776 777
    switch (line) {
    case 0:
778
        zaurus_printf("Charging %s.\n", level ? "off" : "on");
779 780
        break;
    case 1:
781
        zaurus_printf("Discharging %s.\n", level ? "on" : "off");
782 783
        break;
    case 2:
784
        zaurus_printf("Green LED %s.\n", level ? "on" : "off");
785 786
        break;
    case 3:
787
        zaurus_printf("Orange LED %s.\n", level ? "on" : "off");
788 789 790 791 792 793 794 795 796 797 798
        break;
    case 4:
        spitz_bl_bit5(opaque, line, level);
        break;
    case 5:
        spitz_bl_power(opaque, line, level);
        break;
    case 6:
        spitz_adc_temp_on(opaque, line, level);
        break;
    }
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
}

#define SPITZ_SCP_LED_GREEN		1
#define SPITZ_SCP_JK_B			2
#define SPITZ_SCP_CHRG_ON		3
#define SPITZ_SCP_MUTE_L		4
#define SPITZ_SCP_MUTE_R		5
#define SPITZ_SCP_CF_POWER		6
#define SPITZ_SCP_LED_ORANGE		7
#define SPITZ_SCP_JK_A			8
#define SPITZ_SCP_ADC_TEMP_ON		9
#define SPITZ_SCP2_IR_ON		1
#define SPITZ_SCP2_AKIN_PULLUP		2
#define SPITZ_SCP2_BACKLIGHT_CONT	7
#define SPITZ_SCP2_BACKLIGHT_ON		8
#define SPITZ_SCP2_MIC_BIAS		9

P
Paul Brook 已提交
816
static void spitz_scoop_gpio_setup(PXA2xxState *cpu,
817
                DeviceState *scp0, DeviceState *scp1)
818
{
819 820
    qemu_irq *outsignals = qemu_allocate_irqs(spitz_out_switch, cpu, 8);

821 822 823 824
    qdev_connect_gpio_out(scp0, SPITZ_SCP_CHRG_ON, outsignals[0]);
    qdev_connect_gpio_out(scp0, SPITZ_SCP_JK_B, outsignals[1]);
    qdev_connect_gpio_out(scp0, SPITZ_SCP_LED_GREEN, outsignals[2]);
    qdev_connect_gpio_out(scp0, SPITZ_SCP_LED_ORANGE, outsignals[3]);
825

826
    if (scp1) {
827 828
        qdev_connect_gpio_out(scp1, SPITZ_SCP2_BACKLIGHT_CONT, outsignals[4]);
        qdev_connect_gpio_out(scp1, SPITZ_SCP2_BACKLIGHT_ON, outsignals[5]);
829 830
    }

831
    qdev_connect_gpio_out(scp0, SPITZ_SCP_ADC_TEMP_ON, outsignals[6]);
832 833 834 835 836 837 838 839 840 841 842 843
}

#define SPITZ_GPIO_HSYNC		22
#define SPITZ_GPIO_SD_DETECT		9
#define SPITZ_GPIO_SD_WP		81
#define SPITZ_GPIO_ON_RESET		89
#define SPITZ_GPIO_BAT_COVER		90
#define SPITZ_GPIO_CF1_IRQ		105
#define SPITZ_GPIO_CF1_CD		94
#define SPITZ_GPIO_CF2_IRQ		106
#define SPITZ_GPIO_CF2_CD		93

844
static int spitz_hsync;
845

846
static void spitz_lcd_hsync_handler(void *opaque, int line, int level)
847
{
P
Paul Brook 已提交
848
    PXA2xxState *cpu = (PXA2xxState *) opaque;
849
    qemu_set_irq(qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_HSYNC), spitz_hsync);
850 851 852
    spitz_hsync ^= 1;
}

P
Paul Brook 已提交
853
static void spitz_gpio_setup(PXA2xxState *cpu, int slots)
854
{
855
    qemu_irq lcd_hsync;
856 857 858 859 860 861 862
    /*
     * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
     * read to satisfy broken guests that poll-wait for hsync.
     * Simulating a real hsync event would be less practical and
     * wouldn't guarantee that a guest ever exits the loop.
     */
    spitz_hsync = 0;
863
    lcd_hsync = qemu_allocate_irq(spitz_lcd_hsync_handler, cpu, 0);
864 865
    pxa2xx_gpio_read_notifier(cpu->gpio, lcd_hsync);
    pxa2xx_lcd_vsync_notifier(cpu->lcd, lcd_hsync);
866 867

    /* MMC/SD host */
868
    pxa2xx_mmci_handlers(cpu->mmc,
869 870
                    qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_SD_WP),
                    qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_SD_DETECT));
871 872

    /* Battery lock always closed */
873
    qemu_irq_raise(qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_BAT_COVER));
874 875

    /* Handle reset */
876
    qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_ON_RESET, cpu->reset);
877 878 879

    /* PCMCIA signals: card's IRQ and Card-Detect */
    if (slots >= 1)
880
        pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[0],
881 882
                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_IRQ),
                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_CD));
883
    if (slots >= 2)
884
        pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[1],
885 886
                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_IRQ),
                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_CD));
887 888 889 890 891
}

/* Board init.  */
enum spitz_model_e { spitz, akita, borzoi, terrier };

892 893 894
#define SPITZ_RAM	0x04000000
#define SPITZ_ROM	0x00800000

895 896 897 898 899
static struct arm_boot_info spitz_binfo = {
    .loader_start = PXA2XX_SDRAM_BASE,
    .ram_size = 0x04000000,
};

900
static void spitz_common_init(MachineState *machine,
901
                              enum spitz_model_e model, int arm_id)
902
{
903
    PXA2xxState *mpu;
904
    DeviceState *scp0, *scp1 = NULL;
905
    MemoryRegion *address_space_mem = get_system_memory();
A
Avi Kivity 已提交
906
    MemoryRegion *rom = g_new(MemoryRegion, 1);
907
    const char *cpu_model = machine->cpu_model;
908

909 910
    if (!cpu_model)
        cpu_model = (model == terrier) ? "pxa270-c5" : "pxa270-c0";
911

912
    /* Setup CPU & memory */
913
    mpu = pxa270_init(address_space_mem, spitz_binfo.ram_size, cpu_model);
914

915
    sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
916

917
    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_abort);
918
    vmstate_register_ram_global(rom);
A
Avi Kivity 已提交
919 920
    memory_region_set_readonly(rom, true);
    memory_region_add_subregion(address_space_mem, 0, rom);
921 922

    /* Setup peripherals */
923
    spitz_keyboard_register(mpu);
924

925
    spitz_ssp_attach(mpu);
926

927
    scp0 = sysbus_create_simple("scoop", 0x10800000, NULL);
928
    if (model != akita) {
929
        scp1 = sysbus_create_simple("scoop", 0x08800040, NULL);
930
    }
931

932
    spitz_scoop_gpio_setup(mpu, scp0, scp1);
933

934
    spitz_gpio_setup(mpu, (model == akita) ? 1 : 2);
935

936
    spitz_i2c_setup(mpu);
937 938

    if (model == akita)
939
        spitz_akita_i2c_setup(mpu);
940

941
    if (model == terrier)
942
        /* A 6.0 GB microdrive is permanently sitting in CF slot 1.  */
943
        spitz_microdrive_attach(mpu, 1);
944
    else if (model != akita)
B
balrog 已提交
945
        /* A 4.0 GB microdrive is permanently sitting in CF slot 0.  */
946
        spitz_microdrive_attach(mpu, 0);
947

948 949 950
    spitz_binfo.kernel_filename = machine->kernel_filename;
    spitz_binfo.kernel_cmdline = machine->kernel_cmdline;
    spitz_binfo.initrd_filename = machine->initrd_filename;
951
    spitz_binfo.board_id = arm_id;
952
    arm_load_kernel(mpu->cpu, &spitz_binfo);
P
pbrook 已提交
953
    sl_bootparam_write(SL_PXA_PARAM_BASE);
954 955
}

956
static void spitz_init(MachineState *machine)
957
{
958
    spitz_common_init(machine, spitz, 0x2c9);
959 960
}

961
static void borzoi_init(MachineState *machine)
962
{
963
    spitz_common_init(machine, borzoi, 0x33f);
964 965
}

966
static void akita_init(MachineState *machine)
967
{
968
    spitz_common_init(machine, akita, 0x2e8);
969 970
}

971
static void terrier_init(MachineState *machine)
972
{
973
    spitz_common_init(machine, terrier, 0x33f);
974 975
}

976
static QEMUMachine akitapda_machine = {
977 978 979
    .name = "akita",
    .desc = "Akita PDA (PXA270)",
    .init = akita_init,
980 981
};

982
static QEMUMachine spitzpda_machine = {
983 984 985
    .name = "spitz",
    .desc = "Spitz PDA (PXA270)",
    .init = spitz_init,
986 987
};

988
static QEMUMachine borzoipda_machine = {
989 990 991
    .name = "borzoi",
    .desc = "Borzoi PDA (PXA270)",
    .init = borzoi_init,
992 993
};

994
static QEMUMachine terrierpda_machine = {
995 996 997
    .name = "terrier",
    .desc = "Terrier PDA (PXA270)",
    .init = terrier_init,
998
};
P
Paul Brook 已提交
999

1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
static void spitz_machine_init(void)
{
    qemu_register_machine(&akitapda_machine);
    qemu_register_machine(&spitzpda_machine);
    qemu_register_machine(&borzoipda_machine);
    qemu_register_machine(&terrierpda_machine);
}

machine_init(spitz_machine_init);

1010 1011 1012 1013 1014
static bool is_version_0(void *opaque, int version_id)
{
    return version_id == 0;
}

1015 1016 1017 1018
static VMStateDescription vmstate_sl_nand_info = {
    .name = "sl-nand",
    .version_id = 0,
    .minimum_version_id = 0,
1019
    .fields = (VMStateField[]) {
1020 1021 1022 1023 1024 1025
        VMSTATE_UINT8(ctl, SLNANDState),
        VMSTATE_STRUCT(ecc, SLNANDState, 0, vmstate_ecc_state, ECCState),
        VMSTATE_END_OF_LIST(),
    },
};

1026 1027 1028 1029 1030 1031 1032 1033
static Property sl_nand_properties[] = {
    DEFINE_PROP_UINT8("manf_id", SLNANDState, manf_id, NAND_MFR_SAMSUNG),
    DEFINE_PROP_UINT8("chip_id", SLNANDState, chip_id, 0xf1),
    DEFINE_PROP_END_OF_LIST(),
};

static void sl_nand_class_init(ObjectClass *klass, void *data)
{
1034
    DeviceClass *dc = DEVICE_CLASS(klass);
1035 1036 1037
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);

    k->init = sl_nand_init;
1038 1039
    dc->vmsd = &vmstate_sl_nand_info;
    dc->props = sl_nand_properties;
1040 1041
}

1042
static const TypeInfo sl_nand_info = {
1043
    .name          = TYPE_SL_NAND,
1044 1045 1046
    .parent        = TYPE_SYS_BUS_DEVICE,
    .instance_size = sizeof(SLNANDState),
    .class_init    = sl_nand_class_init,
1047 1048
};

1049 1050 1051 1052 1053
static VMStateDescription vmstate_spitz_kbd = {
    .name = "spitz-keyboard",
    .version_id = 1,
    .minimum_version_id = 0,
    .post_load = spitz_keyboard_post_load,
1054
    .fields = (VMStateField[]) {
1055 1056 1057 1058 1059 1060 1061
        VMSTATE_UINT16(sense_state, SpitzKeyboardState),
        VMSTATE_UINT16(strobe_state, SpitzKeyboardState),
        VMSTATE_UNUSED_TEST(is_version_0, 5),
        VMSTATE_END_OF_LIST(),
    },
};

1062 1063 1064 1065 1066 1067
static Property spitz_keyboard_properties[] = {
    DEFINE_PROP_END_OF_LIST(),
};

static void spitz_keyboard_class_init(ObjectClass *klass, void *data)
{
1068
    DeviceClass *dc = DEVICE_CLASS(klass);
1069 1070 1071
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);

    k->init = spitz_keyboard_init;
1072 1073
    dc->vmsd = &vmstate_spitz_kbd;
    dc->props = spitz_keyboard_properties;
1074 1075
}

1076
static const TypeInfo spitz_keyboard_info = {
1077
    .name          = TYPE_SPITZ_KEYBOARD,
1078 1079 1080
    .parent        = TYPE_SYS_BUS_DEVICE,
    .instance_size = sizeof(SpitzKeyboardState),
    .class_init    = spitz_keyboard_class_init,
1081 1082
};

1083 1084
static const VMStateDescription vmstate_corgi_ssp_regs = {
    .name = "corgi-ssp",
1085 1086
    .version_id = 2,
    .minimum_version_id = 2,
1087
    .fields = (VMStateField[]) {
1088
        VMSTATE_SSI_SLAVE(ssidev, CorgiSSPState),
1089 1090 1091 1092 1093
        VMSTATE_UINT32_ARRAY(enable, CorgiSSPState, 3),
        VMSTATE_END_OF_LIST(),
    }
};

1094 1095
static void corgi_ssp_class_init(ObjectClass *klass, void *data)
{
1096
    DeviceClass *dc = DEVICE_CLASS(klass);
1097 1098 1099 1100
    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);

    k->init = corgi_ssp_init;
    k->transfer = corgi_ssp_transfer;
1101
    dc->vmsd = &vmstate_corgi_ssp_regs;
1102 1103
}

1104
static const TypeInfo corgi_ssp_info = {
1105 1106 1107 1108
    .name          = "corgi-ssp",
    .parent        = TYPE_SSI_SLAVE,
    .instance_size = sizeof(CorgiSSPState),
    .class_init    = corgi_ssp_class_init,
P
Paul Brook 已提交
1109 1110
};

1111 1112 1113 1114
static const VMStateDescription vmstate_spitz_lcdtg_regs = {
    .name = "spitz-lcdtg",
    .version_id = 1,
    .minimum_version_id = 1,
1115
    .fields = (VMStateField[]) {
1116
        VMSTATE_SSI_SLAVE(ssidev, SpitzLCDTG),
1117 1118 1119 1120 1121 1122
        VMSTATE_UINT32(bl_intensity, SpitzLCDTG),
        VMSTATE_UINT32(bl_power, SpitzLCDTG),
        VMSTATE_END_OF_LIST(),
    }
};

1123 1124
static void spitz_lcdtg_class_init(ObjectClass *klass, void *data)
{
1125
    DeviceClass *dc = DEVICE_CLASS(klass);
1126 1127 1128 1129
    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);

    k->init = spitz_lcdtg_init;
    k->transfer = spitz_lcdtg_transfer;
1130
    dc->vmsd = &vmstate_spitz_lcdtg_regs;
1131 1132
}

1133
static const TypeInfo spitz_lcdtg_info = {
1134 1135 1136 1137
    .name          = "spitz-lcdtg",
    .parent        = TYPE_SSI_SLAVE,
    .instance_size = sizeof(SpitzLCDTG),
    .class_init    = spitz_lcdtg_class_init,
P
Paul Brook 已提交
1138 1139
};

A
Andreas Färber 已提交
1140
static void spitz_register_types(void)
P
Paul Brook 已提交
1141
{
1142 1143 1144 1145
    type_register_static(&corgi_ssp_info);
    type_register_static(&spitz_lcdtg_info);
    type_register_static(&spitz_keyboard_info);
    type_register_static(&sl_nand_info);
P
Paul Brook 已提交
1146 1147
}

A
Andreas Färber 已提交
1148
type_init(spitz_register_types)