]> git.proxmox.com Git - mirror_qemu.git/blame - hw/arm/mainstone.c
include/qemu/osdep.h: Don't include qapi/error.h
[mirror_qemu.git] / hw / arm / mainstone.c
CommitLineData
ef056e43
AZ
1/*
2 * PXA270-based Intel Mainstone platforms.
3 *
4 * Copyright (c) 2007 by Armin Kuster <akuster@kama-aina.net> or
5 * <akuster@mvista.com>
6 *
7 * Code based on spitz platform by Andrzej Zaborowski <balrog@zabor.org>
8 *
9 * This code is licensed under the GNU GPL v2.
6b620ca3
PB
10 *
11 * Contributions after 2012-01-13 are licensed under the terms of the
12 * GNU GPL, version 2 or (at your option) any later version.
ef056e43 13 */
12b16722 14#include "qemu/osdep.h"
da34e65c 15#include "qapi/error.h"
83c9f4ca 16#include "hw/hw.h"
0d09e41a 17#include "hw/arm/pxa.h"
bd2be150 18#include "hw/arm/arm.h"
1422e32d 19#include "net/net.h"
bd2be150 20#include "hw/devices.h"
83c9f4ca 21#include "hw/boards.h"
0d09e41a 22#include "hw/block/flash.h"
fa1d36df 23#include "sysemu/block-backend.h"
83c9f4ca 24#include "hw/sysbus.h"
022c62cb 25#include "exec/address-spaces.h"
d2f7c496 26#include "sysemu/qtest.h"
ef056e43 27
459505a2
DES
28/* Device addresses */
29#define MST_FPGA_PHYS 0x08000000
30#define MST_ETH_PHYS 0x10000300
31#define MST_FLASH_0 0x00000000
32#define MST_FLASH_1 0x04000000
33
34/* IRQ definitions */
35#define MMC_IRQ 0
36#define USIM_IRQ 1
37#define USBC_IRQ 2
38#define ETHERNET_IRQ 3
39#define AC97_IRQ 4
40#define PEN_IRQ 5
41#define MSINS_IRQ 6
42#define EXBRD_IRQ 7
43#define S0_CD_IRQ 9
44#define S0_STSCHG_IRQ 10
45#define S0_IRQ 11
46#define S1_CD_IRQ 13
47#define S1_STSCHG_IRQ 14
48#define S1_IRQ 15
49
52975c31 50static const struct keymap map[0xE0] = {
bd464c2e
AZ
51 [0 ... 0xDF] = { -1, -1 },
52 [0x1e] = {0,0}, /* a */
53 [0x30] = {0,1}, /* b */
54 [0x2e] = {0,2}, /* c */
55 [0x20] = {0,3}, /* d */
56 [0x12] = {0,4}, /* e */
57 [0x21] = {0,5}, /* f */
58 [0x22] = {1,0}, /* g */
59 [0x23] = {1,1}, /* h */
60 [0x17] = {1,2}, /* i */
61 [0x24] = {1,3}, /* j */
62 [0x25] = {1,4}, /* k */
63 [0x26] = {1,5}, /* l */
64 [0x32] = {2,0}, /* m */
65 [0x31] = {2,1}, /* n */
66 [0x18] = {2,2}, /* o */
67 [0x19] = {2,3}, /* p */
68 [0x10] = {2,4}, /* q */
69 [0x13] = {2,5}, /* r */
70 [0x1f] = {3,0}, /* s */
71 [0x14] = {3,1}, /* t */
72 [0x16] = {3,2}, /* u */
73 [0x2f] = {3,3}, /* v */
74 [0x11] = {3,4}, /* w */
75 [0x2d] = {3,5}, /* x */
76 [0x15] = {4,2}, /* y */
77 [0x2c] = {4,3}, /* z */
78 [0xc7] = {5,0}, /* Home */
79 [0x2a] = {5,1}, /* shift */
7dbc1158
SW
80 /*
81 * There are two matrix positions which map to space,
82 * but QEMU can only use one of them for the reverse
83 * mapping, so simply use the second one.
84 */
85 /* [0x39] = {5,2}, space */
bd464c2e 86 [0x39] = {5,3}, /* space */
7dbc1158
SW
87 /*
88 * Matrix position {5,4} and other keys are missing here.
89 * TODO: Compare with Linux code and test real hardware.
90 */
91 [0x1c] = {5,5}, /* enter (TODO: might be wrong) */
bd464c2e
AZ
92 [0xc8] = {6,0}, /* up */
93 [0xd0] = {6,1}, /* down */
94 [0xcb] = {6,2}, /* left */
95 [0xcd] = {6,3}, /* right */
96};
97
ef056e43
AZ
98enum mainstone_model_e { mainstone };
99
7fb4fdcf
AZ
100#define MAINSTONE_RAM 0x04000000
101#define MAINSTONE_ROM 0x00800000
102#define MAINSTONE_FLASH 0x02000000
103
f93eb9ff
AZ
104static struct arm_boot_info mainstone_binfo = {
105 .loader_start = PXA2XX_SDRAM_BASE,
106 .ram_size = 0x04000000,
107};
108
02e5c167 109static void mainstone_common_init(MemoryRegion *address_space_mem,
3ef96221 110 MachineState *machine,
6efa6d50 111 enum mainstone_model_e model, int arm_id)
ef056e43 112{
6d1f1778 113 uint32_t sector_len = 256 * 1024;
a8170e5e 114 hwaddr mainstone_flash_base[] = { MST_FLASH_0, MST_FLASH_1 };
1c88de67 115 PXA2xxState *mpu;
cb380f61 116 DeviceState *mst_irq;
751c6a17
GH
117 DriveInfo *dinfo;
118 int i;
01e0451a 119 int be;
02e5c167 120 MemoryRegion *rom = g_new(MemoryRegion, 1);
3ef96221 121 const char *cpu_model = machine->cpu_model;
ef056e43
AZ
122
123 if (!cpu_model)
124 cpu_model = "pxa270-c5";
125
126 /* Setup CPU & memory */
1c88de67 127 mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size, cpu_model);
49946538 128 memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
f8ed85ac 129 &error_fatal);
c5705a77 130 vmstate_register_ram_global(rom);
02e5c167
AK
131 memory_region_set_readonly(rom, true);
132 memory_region_add_subregion(address_space_mem, 0, rom);
ef056e43 133
3d08ff69 134#ifdef TARGET_WORDS_BIGENDIAN
01e0451a 135 be = 1;
3d08ff69 136#else
01e0451a 137 be = 0;
3d08ff69 138#endif
e4bcb14c 139 /* There are two 32MiB flash devices on the board */
6d1f1778 140 for (i = 0; i < 2; i ++) {
751c6a17
GH
141 dinfo = drive_get(IF_PFLASH, 0, i);
142 if (!dinfo) {
d2f7c496
AF
143 if (qtest_enabled()) {
144 break;
145 }
6d1f1778
AZ
146 fprintf(stderr, "Two flash images must be given with the "
147 "'pflash' parameter\n");
148 exit(1);
149 }
150
cfe5f011
AK
151 if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
152 i ? "mainstone.flash1" : "mainstone.flash0",
153 MAINSTONE_FLASH,
4be74634 154 blk_by_legacy_dinfo(dinfo),
fa1d36df
MA
155 sector_len, MAINSTONE_FLASH / sector_len,
156 4, 0, 0, 0, 0, be)) {
6d1f1778
AZ
157 fprintf(stderr, "qemu: Error registering flash memory.\n");
158 exit(1);
159 }
e4bcb14c 160 }
7233b355 161
cb380f61 162 mst_irq = sysbus_create_simple("mainstone-fpga", MST_FPGA_PHYS,
1c88de67 163 qdev_get_gpio_in(mpu->gpio, 0));
f1de1334 164
bd464c2e 165 /* setup keypad */
1c88de67 166 pxa27x_register_keypad(mpu->kp, map, 0xe0);
bd464c2e 167
f1de1334 168 /* MMC/SD host */
1c88de67 169 pxa2xx_mmci_handlers(mpu->mmc, NULL, qdev_get_gpio_in(mst_irq, MMC_IRQ));
f1de1334 170
1c88de67 171 pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[0],
b651fc6f
DES
172 qdev_get_gpio_in(mst_irq, S0_IRQ),
173 qdev_get_gpio_in(mst_irq, S0_CD_IRQ));
1c88de67 174 pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[1],
b651fc6f
DES
175 qdev_get_gpio_in(mst_irq, S1_IRQ),
176 qdev_get_gpio_in(mst_irq, S1_CD_IRQ));
177
cb380f61
DES
178 smc91c111_init(&nd_table[0], MST_ETH_PHYS,
179 qdev_get_gpio_in(mst_irq, ETHERNET_IRQ));
ef056e43 180
3ef96221
MA
181 mainstone_binfo.kernel_filename = machine->kernel_filename;
182 mainstone_binfo.kernel_cmdline = machine->kernel_cmdline;
183 mainstone_binfo.initrd_filename = machine->initrd_filename;
f93eb9ff 184 mainstone_binfo.board_id = arm_id;
3aaa8dfa 185 arm_load_kernel(mpu->cpu, &mainstone_binfo);
ef056e43
AZ
186}
187
3ef96221 188static void mainstone_init(MachineState *machine)
ef056e43 189{
3ef96221 190 mainstone_common_init(get_system_memory(), machine, mainstone, 0x196);
ef056e43
AZ
191}
192
e264d29d 193static void mainstone2_machine_init(MachineClass *mc)
f80f9ec9 194{
e264d29d
EH
195 mc->desc = "Mainstone II (PXA27x)";
196 mc->init = mainstone_init;
f80f9ec9
AL
197}
198
e264d29d 199DEFINE_MACHINE("mainstone", mainstone2_machine_init)