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