]> Git Repo - qemu.git/blame - hw/arm/z2.c
hw/usb/tusb6010: Convert away from old_mmio
[qemu.git] / hw / arm / z2.c
CommitLineData
3bf11207
VK
1/*
2 * PXA270-based Zipit Z2 device
3 *
4 * Copyright (c) 2011 by Vasily Khoruzhick <[email protected]>
5 *
6 * Code is based on mainstone platform.
7 *
8 * This code is licensed under the GNU GPL v2.
6b620ca3
PB
9 *
10 * Contributions after 2012-01-13 are licensed under the terms of the
11 * GNU GPL, version 2 or (at your option) any later version.
3bf11207
VK
12 */
13
12b16722 14#include "qemu/osdep.h"
83c9f4ca 15#include "hw/hw.h"
0d09e41a 16#include "hw/arm/pxa.h"
bd2be150
PM
17#include "hw/arm/arm.h"
18#include "hw/devices.h"
0d09e41a 19#include "hw/i2c/i2c.h"
8fd06719 20#include "hw/ssi/ssi.h"
83c9f4ca 21#include "hw/boards.h"
9c17d615 22#include "sysemu/sysemu.h"
0d09e41a 23#include "hw/block/flash.h"
fa1d36df 24#include "sysemu/block-backend.h"
28ecbaee 25#include "ui/console.h"
7ab14c5a 26#include "hw/audio/wm8750.h"
3bf11207 27#include "audio/audio.h"
022c62cb 28#include "exec/address-spaces.h"
e25ac5f6 29#include "sysemu/qtest.h"
ba1ba5cc 30#include "cpu.h"
3bf11207
VK
31
32#ifdef DEBUG_Z2
33#define DPRINTF(fmt, ...) \
34 printf(fmt, ## __VA_ARGS__)
35#else
36#define DPRINTF(fmt, ...)
37#endif
38
52975c31 39static const struct keymap map[0x100] = {
3bf11207
VK
40 [0 ... 0xff] = { -1, -1 },
41 [0x3b] = {0, 0}, /* Option = F1 */
42 [0xc8] = {0, 1}, /* Up */
43 [0xd0] = {0, 2}, /* Down */
44 [0xcb] = {0, 3}, /* Left */
45 [0xcd] = {0, 4}, /* Right */
46 [0xcf] = {0, 5}, /* End */
47 [0x0d] = {0, 6}, /* KPPLUS */
48 [0xc7] = {1, 0}, /* Home */
49 [0x10] = {1, 1}, /* Q */
50 [0x17] = {1, 2}, /* I */
51 [0x22] = {1, 3}, /* G */
52 [0x2d] = {1, 4}, /* X */
53 [0x1c] = {1, 5}, /* Enter */
54 [0x0c] = {1, 6}, /* KPMINUS */
55 [0xc9] = {2, 0}, /* PageUp */
56 [0x11] = {2, 1}, /* W */
57 [0x18] = {2, 2}, /* O */
58 [0x23] = {2, 3}, /* H */
59 [0x2e] = {2, 4}, /* C */
60 [0x38] = {2, 5}, /* LeftAlt */
61 [0xd1] = {3, 0}, /* PageDown */
62 [0x12] = {3, 1}, /* E */
63 [0x19] = {3, 2}, /* P */
64 [0x24] = {3, 3}, /* J */
65 [0x2f] = {3, 4}, /* V */
66 [0x2a] = {3, 5}, /* LeftShift */
67 [0x01] = {4, 0}, /* Esc */
68 [0x13] = {4, 1}, /* R */
69 [0x1e] = {4, 2}, /* A */
70 [0x25] = {4, 3}, /* K */
71 [0x30] = {4, 4}, /* B */
72 [0x1d] = {4, 5}, /* LeftCtrl */
73 [0x0f] = {5, 0}, /* Tab */
74 [0x14] = {5, 1}, /* T */
75 [0x1f] = {5, 2}, /* S */
76 [0x26] = {5, 3}, /* L */
77 [0x31] = {5, 4}, /* N */
78 [0x39] = {5, 5}, /* Space */
79 [0x3c] = {6, 0}, /* Stop = F2 */
80 [0x15] = {6, 1}, /* Y */
81 [0x20] = {6, 2}, /* D */
82 [0x0e] = {6, 3}, /* Backspace */
83 [0x32] = {6, 4}, /* M */
84 [0x33] = {6, 5}, /* Comma */
85 [0x3d] = {7, 0}, /* Play = F3 */
86 [0x16] = {7, 1}, /* U */
87 [0x21] = {7, 2}, /* F */
88 [0x2c] = {7, 3}, /* Z */
89 [0x27] = {7, 4}, /* Semicolon */
90 [0x34] = {7, 5}, /* Dot */
91};
92
93#define Z2_RAM_SIZE 0x02000000
94#define Z2_FLASH_BASE 0x00000000
95#define Z2_FLASH_SIZE 0x00800000
96
97static struct arm_boot_info z2_binfo = {
98 .loader_start = PXA2XX_SDRAM_BASE,
99 .ram_size = Z2_RAM_SIZE,
100};
101
102#define Z2_GPIO_SD_DETECT 96
103#define Z2_GPIO_AC_IN 0
104#define Z2_GPIO_KEY_ON 1
105#define Z2_GPIO_LCD_CS 88
106
107typedef struct {
108 SSISlave ssidev;
109 int32_t selected;
110 int32_t enabled;
111 uint8_t buf[3];
112 uint32_t cur_reg;
113 int pos;
114} ZipitLCD;
115
116static uint32_t zipit_lcd_transfer(SSISlave *dev, uint32_t value)
117{
118 ZipitLCD *z = FROM_SSI_SLAVE(ZipitLCD, dev);
119 uint16_t val;
120 if (z->selected) {
121 z->buf[z->pos] = value & 0xff;
122 z->pos++;
123 }
124 if (z->pos == 3) {
125 switch (z->buf[0]) {
126 case 0x74:
127 DPRINTF("%s: reg: 0x%.2x\n", __func__, z->buf[2]);
128 z->cur_reg = z->buf[2];
129 break;
130 case 0x76:
131 val = z->buf[1] << 8 | z->buf[2];
132 DPRINTF("%s: value: 0x%.4x\n", __func__, val);
133 if (z->cur_reg == 0x22 && val == 0x0000) {
134 z->enabled = 1;
135 printf("%s: LCD enabled\n", __func__);
136 } else if (z->cur_reg == 0x10 && val == 0x0000) {
137 z->enabled = 0;
138 printf("%s: LCD disabled\n", __func__);
139 }
140 break;
141 default:
142 DPRINTF("%s: unknown command!\n", __func__);
143 break;
144 }
145 z->pos = 0;
146 }
147 return 0;
148}
149
150static void z2_lcd_cs(void *opaque, int line, int level)
151{
152 ZipitLCD *z2_lcd = opaque;
153 z2_lcd->selected = !level;
154}
155
7673bb4c 156static void zipit_lcd_realize(SSISlave *dev, Error **errp)
3bf11207
VK
157{
158 ZipitLCD *z = FROM_SSI_SLAVE(ZipitLCD, dev);
159 z->selected = 0;
160 z->enabled = 0;
161 z->pos = 0;
3bf11207
VK
162}
163
164static VMStateDescription vmstate_zipit_lcd_state = {
165 .name = "zipit-lcd",
66530953
PC
166 .version_id = 2,
167 .minimum_version_id = 2,
3bf11207 168 .fields = (VMStateField[]) {
66530953 169 VMSTATE_SSI_SLAVE(ssidev, ZipitLCD),
3bf11207
VK
170 VMSTATE_INT32(selected, ZipitLCD),
171 VMSTATE_INT32(enabled, ZipitLCD),
172 VMSTATE_BUFFER(buf, ZipitLCD),
173 VMSTATE_UINT32(cur_reg, ZipitLCD),
174 VMSTATE_INT32(pos, ZipitLCD),
175 VMSTATE_END_OF_LIST(),
176 }
177};
178
cd6c4cf2
AL
179static void zipit_lcd_class_init(ObjectClass *klass, void *data)
180{
39bffca2 181 DeviceClass *dc = DEVICE_CLASS(klass);
cd6c4cf2
AL
182 SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
183
7673bb4c 184 k->realize = zipit_lcd_realize;
cd6c4cf2 185 k->transfer = zipit_lcd_transfer;
39bffca2 186 dc->vmsd = &vmstate_zipit_lcd_state;
cd6c4cf2
AL
187}
188
8c43a6f0 189static const TypeInfo zipit_lcd_info = {
39bffca2
AL
190 .name = "zipit-lcd",
191 .parent = TYPE_SSI_SLAVE,
192 .instance_size = sizeof(ZipitLCD),
193 .class_init = zipit_lcd_class_init,
3bf11207
VK
194};
195
a5f96db7
AF
196#define TYPE_AER915 "aer915"
197#define AER915(obj) OBJECT_CHECK(AER915State, (obj), TYPE_AER915)
198
199typedef struct AER915State {
200 I2CSlave parent_obj;
201
3bf11207
VK
202 int len;
203 uint8_t buf[3];
204} AER915State;
205
9e07bdf8 206static int aer915_send(I2CSlave *i2c, uint8_t data)
3bf11207 207{
a5f96db7
AF
208 AER915State *s = AER915(i2c);
209
3bf11207
VK
210 s->buf[s->len] = data;
211 if (s->len++ > 2) {
212 DPRINTF("%s: message too long (%i bytes)\n",
213 __func__, s->len);
214 return 1;
215 }
216
217 if (s->len == 2) {
218 DPRINTF("%s: reg %d value 0x%02x\n", __func__,
219 s->buf[0], s->buf[1]);
220 }
221
222 return 0;
223}
224
d307c28c 225static int aer915_event(I2CSlave *i2c, enum i2c_event event)
3bf11207 226{
a5f96db7
AF
227 AER915State *s = AER915(i2c);
228
3bf11207
VK
229 switch (event) {
230 case I2C_START_SEND:
231 s->len = 0;
232 break;
233 case I2C_START_RECV:
234 if (s->len != 1) {
235 DPRINTF("%s: short message!?\n", __func__);
236 }
237 break;
238 case I2C_FINISH:
239 break;
240 default:
241 break;
242 }
d307c28c
CM
243
244 return 0;
3bf11207
VK
245}
246
9e07bdf8 247static int aer915_recv(I2CSlave *slave)
3bf11207 248{
a5f96db7 249 AER915State *s = AER915(slave);
3bf11207 250 int retval = 0x00;
3bf11207
VK
251
252 switch (s->buf[0]) {
253 /* Return hardcoded battery voltage,
254 * 0xf0 means ~4.1V
255 */
256 case 0x02:
257 retval = 0xf0;
258 break;
259 /* Return 0x00 for other regs,
260 * we don't know what they are for,
261 * anyway they return 0x00 on real hardware.
262 */
263 default:
264 break;
265 }
266
267 return retval;
268}
269
3bf11207
VK
270static VMStateDescription vmstate_aer915_state = {
271 .name = "aer915",
272 .version_id = 1,
273 .minimum_version_id = 1,
3bf11207
VK
274 .fields = (VMStateField[]) {
275 VMSTATE_INT32(len, AER915State),
276 VMSTATE_BUFFER(buf, AER915State),
277 VMSTATE_END_OF_LIST(),
278 }
279};
280
b5ea9327
AL
281static void aer915_class_init(ObjectClass *klass, void *data)
282{
39bffca2 283 DeviceClass *dc = DEVICE_CLASS(klass);
b5ea9327
AL
284 I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
285
b5ea9327
AL
286 k->event = aer915_event;
287 k->recv = aer915_recv;
288 k->send = aer915_send;
39bffca2 289 dc->vmsd = &vmstate_aer915_state;
b5ea9327
AL
290}
291
8c43a6f0 292static const TypeInfo aer915_info = {
a5f96db7 293 .name = TYPE_AER915,
39bffca2
AL
294 .parent = TYPE_I2C_SLAVE,
295 .instance_size = sizeof(AER915State),
296 .class_init = aer915_class_init,
3bf11207
VK
297};
298
3ef96221 299static void z2_init(MachineState *machine)
3bf11207 300{
3ef96221
MA
301 const char *kernel_filename = machine->kernel_filename;
302 const char *kernel_cmdline = machine->kernel_cmdline;
303 const char *initrd_filename = machine->initrd_filename;
a6dc4c2d 304 MemoryRegion *address_space_mem = get_system_memory();
3bf11207 305 uint32_t sector_len = 0x10000;
5c6f4f17 306 PXA2xxState *mpu;
3bf11207 307 DriveInfo *dinfo;
01e0451a 308 int be;
3bf11207 309 void *z2_lcd;
a5c82852 310 I2CBus *bus;
3bf11207
VK
311 DeviceState *wm;
312
3bf11207 313 /* Setup CPU & memory */
ba1ba5cc 314 mpu = pxa270_init(address_space_mem, z2_binfo.ram_size, machine->cpu_type);
3bf11207
VK
315
316#ifdef TARGET_WORDS_BIGENDIAN
01e0451a 317 be = 1;
3bf11207 318#else
01e0451a 319 be = 0;
3bf11207
VK
320#endif
321 dinfo = drive_get(IF_PFLASH, 0, 0);
e25ac5f6 322 if (!dinfo && !qtest_enabled()) {
c0dbca36
AF
323 error_report("Flash image must be given with the "
324 "'pflash' parameter");
3bf11207
VK
325 exit(1);
326 }
327
01e0451a 328 if (!pflash_cfi01_register(Z2_FLASH_BASE,
cfe5f011 329 NULL, "z2.flash0", Z2_FLASH_SIZE,
4be74634 330 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
fa1d36df
MA
331 sector_len, Z2_FLASH_SIZE / sector_len,
332 4, 0, 0, 0, 0, be)) {
c0dbca36 333 error_report("Error registering flash memory");
3bf11207
VK
334 exit(1);
335 }
336
337 /* setup keypad */
5c6f4f17 338 pxa27x_register_keypad(mpu->kp, map, 0x100);
3bf11207
VK
339
340 /* MMC/SD host */
5c6f4f17 341 pxa2xx_mmci_handlers(mpu->mmc,
3bf11207 342 NULL,
5c6f4f17 343 qdev_get_gpio_in(mpu->gpio, Z2_GPIO_SD_DETECT));
3bf11207 344
39bffca2
AL
345 type_register_static(&zipit_lcd_info);
346 type_register_static(&aer915_info);
5c6f4f17
AF
347 z2_lcd = ssi_create_slave(mpu->ssp[1], "zipit-lcd");
348 bus = pxa2xx_i2c_bus(mpu->i2c[0]);
a5f96db7 349 i2c_create_slave(bus, TYPE_AER915, 0x55);
7ab14c5a 350 wm = i2c_create_slave(bus, TYPE_WM8750, 0x1b);
5c6f4f17
AF
351 mpu->i2s->opaque = wm;
352 mpu->i2s->codec_out = wm8750_dac_dat;
353 mpu->i2s->codec_in = wm8750_adc_dat;
354 wm8750_data_req_set(wm, mpu->i2s->data_req, mpu->i2s);
3bf11207 355
5c6f4f17 356 qdev_connect_gpio_out(mpu->gpio, Z2_GPIO_LCD_CS,
f3c7d038 357 qemu_allocate_irq(z2_lcd_cs, z2_lcd, 0));
3bf11207 358
dacecf54
PM
359 z2_binfo.kernel_filename = kernel_filename;
360 z2_binfo.kernel_cmdline = kernel_cmdline;
361 z2_binfo.initrd_filename = initrd_filename;
362 z2_binfo.board_id = 0x6dd;
363 arm_load_kernel(mpu->cpu, &z2_binfo);
3bf11207
VK
364}
365
e264d29d 366static void z2_machine_init(MachineClass *mc)
3bf11207 367{
e264d29d
EH
368 mc->desc = "Zipit Z2 (PXA27x)";
369 mc->init = z2_init;
4672cbd7 370 mc->ignore_memory_transaction_failures = true;
ba1ba5cc 371 mc->default_cpu_type = ARM_CPU_TYPE_NAME("pxa270-c5");
3bf11207
VK
372}
373
e264d29d 374DEFINE_MACHINE("z2", z2_machine_init)
This page took 0.62293 seconds and 4 git commands to generate.