2 * PXA270-based Intel Mainstone platforms.
4 * Copyright (c) 2007 by Armin Kuster <akuster@kama-aina.net> or
7 * Code based on spitz platform by Andrzej Zaborowski <balrog@zabor.org>
9 * This code is licensed under the GNU GPL v2.
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.
14 #include "qemu/osdep.h"
15 #include "qapi/error.h"
17 #include "hw/arm/pxa.h"
18 #include "hw/arm/arm.h"
20 #include "hw/devices.h"
21 #include "hw/boards.h"
22 #include "hw/block/flash.h"
23 #include "sysemu/block-backend.h"
24 #include "hw/sysbus.h"
25 #include "exec/address-spaces.h"
26 #include "sysemu/qtest.h"
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
38 #define ETHERNET_IRQ 3
44 #define S0_STSCHG_IRQ 10
47 #define S1_STSCHG_IRQ 14
50 static const struct keymap map
[0xE0] = {
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 [0x34] = {4,0}, /* . */
77 [0x15] = {4,2}, /* y */
78 [0x2c] = {4,3}, /* z */
79 [0x35] = {4,4}, /* / */
80 [0xc7] = {5,0}, /* Home */
81 [0x2a] = {5,1}, /* shift */
83 * There are two matrix positions which map to space,
84 * but QEMU can only use one of them for the reverse
85 * mapping, so simply use the second one.
87 /* [0x39] = {5,2}, space */
88 [0x39] = {5,3}, /* space */
90 * Matrix position {5,4} and other keys are missing here.
91 * TODO: Compare with Linux code and test real hardware.
93 [0x1c] = {5,4}, /* enter */
94 [0x0e] = {5,5}, /* backspace */
95 [0xc8] = {6,0}, /* up */
96 [0xd0] = {6,1}, /* down */
97 [0xcb] = {6,2}, /* left */
98 [0xcd] = {6,3}, /* right */
101 enum mainstone_model_e
{ mainstone
};
103 #define MAINSTONE_RAM 0x04000000
104 #define MAINSTONE_ROM 0x00800000
105 #define MAINSTONE_FLASH 0x02000000
107 static struct arm_boot_info mainstone_binfo
= {
108 .loader_start
= PXA2XX_SDRAM_BASE
,
109 .ram_size
= 0x04000000,
112 static void mainstone_common_init(MemoryRegion
*address_space_mem
,
113 MachineState
*machine
,
114 enum mainstone_model_e model
, int arm_id
)
116 uint32_t sector_len
= 256 * 1024;
117 hwaddr mainstone_flash_base
[] = { MST_FLASH_0
, MST_FLASH_1
};
119 DeviceState
*mst_irq
;
123 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
124 const char *cpu_model
= machine
->cpu_model
;
127 cpu_model
= "pxa270-c5";
129 /* Setup CPU & memory */
130 mpu
= pxa270_init(address_space_mem
, mainstone_binfo
.ram_size
, cpu_model
);
131 memory_region_init_ram(rom
, NULL
, "mainstone.rom", MAINSTONE_ROM
,
133 vmstate_register_ram_global(rom
);
134 memory_region_set_readonly(rom
, true);
135 memory_region_add_subregion(address_space_mem
, 0, rom
);
137 #ifdef TARGET_WORDS_BIGENDIAN
142 /* There are two 32MiB flash devices on the board */
143 for (i
= 0; i
< 2; i
++) {
144 dinfo
= drive_get(IF_PFLASH
, 0, i
);
146 if (qtest_enabled()) {
149 fprintf(stderr
, "Two flash images must be given with the "
150 "'pflash' parameter\n");
154 if (!pflash_cfi01_register(mainstone_flash_base
[i
], NULL
,
155 i
? "mainstone.flash1" : "mainstone.flash0",
157 blk_by_legacy_dinfo(dinfo
),
158 sector_len
, MAINSTONE_FLASH
/ sector_len
,
159 4, 0, 0, 0, 0, be
)) {
160 fprintf(stderr
, "qemu: Error registering flash memory.\n");
165 mst_irq
= sysbus_create_simple("mainstone-fpga", MST_FPGA_PHYS
,
166 qdev_get_gpio_in(mpu
->gpio
, 0));
169 pxa27x_register_keypad(mpu
->kp
, map
, 0xe0);
172 pxa2xx_mmci_handlers(mpu
->mmc
, NULL
, qdev_get_gpio_in(mst_irq
, MMC_IRQ
));
174 pxa2xx_pcmcia_set_irq_cb(mpu
->pcmcia
[0],
175 qdev_get_gpio_in(mst_irq
, S0_IRQ
),
176 qdev_get_gpio_in(mst_irq
, S0_CD_IRQ
));
177 pxa2xx_pcmcia_set_irq_cb(mpu
->pcmcia
[1],
178 qdev_get_gpio_in(mst_irq
, S1_IRQ
),
179 qdev_get_gpio_in(mst_irq
, S1_CD_IRQ
));
181 smc91c111_init(&nd_table
[0], MST_ETH_PHYS
,
182 qdev_get_gpio_in(mst_irq
, ETHERNET_IRQ
));
184 mainstone_binfo
.kernel_filename
= machine
->kernel_filename
;
185 mainstone_binfo
.kernel_cmdline
= machine
->kernel_cmdline
;
186 mainstone_binfo
.initrd_filename
= machine
->initrd_filename
;
187 mainstone_binfo
.board_id
= arm_id
;
188 arm_load_kernel(mpu
->cpu
, &mainstone_binfo
);
191 static void mainstone_init(MachineState
*machine
)
193 mainstone_common_init(get_system_memory(), machine
, mainstone
, 0x196);
196 static void mainstone2_machine_init(MachineClass
*mc
)
198 mc
->desc
= "Mainstone II (PXA27x)";
199 mc
->init
= mainstone_init
;
202 DEFINE_MACHINE("mainstone", mainstone2_machine_init
)