xref: /openbmc/qemu/hw/arm/mainstone.c (revision acb0ef58)
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.
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.
13  */
14 #include "hw/hw.h"
15 #include "hw/arm/pxa.h"
16 #include "hw/arm/arm.h"
17 #include "net/net.h"
18 #include "hw/devices.h"
19 #include "hw/boards.h"
20 #include "hw/block/flash.h"
21 #include "sysemu/blockdev.h"
22 #include "hw/sysbus.h"
23 #include "exec/address-spaces.h"
24 #include "sysemu/qtest.h"
25 
26 /* Device addresses */
27 #define MST_FPGA_PHYS	0x08000000
28 #define MST_ETH_PHYS	0x10000300
29 #define MST_FLASH_0		0x00000000
30 #define MST_FLASH_1		0x04000000
31 
32 /* IRQ definitions */
33 #define MMC_IRQ       0
34 #define USIM_IRQ      1
35 #define USBC_IRQ      2
36 #define ETHERNET_IRQ  3
37 #define AC97_IRQ      4
38 #define PEN_IRQ       5
39 #define MSINS_IRQ     6
40 #define EXBRD_IRQ     7
41 #define S0_CD_IRQ     9
42 #define S0_STSCHG_IRQ 10
43 #define S0_IRQ        11
44 #define S1_CD_IRQ     13
45 #define S1_STSCHG_IRQ 14
46 #define S1_IRQ        15
47 
48 static const struct keymap map[0xE0] = {
49     [0 ... 0xDF] = { -1, -1 },
50     [0x1e] = {0,0}, /* a */
51     [0x30] = {0,1}, /* b */
52     [0x2e] = {0,2}, /* c */
53     [0x20] = {0,3}, /* d */
54     [0x12] = {0,4}, /* e */
55     [0x21] = {0,5}, /* f */
56     [0x22] = {1,0}, /* g */
57     [0x23] = {1,1}, /* h */
58     [0x17] = {1,2}, /* i */
59     [0x24] = {1,3}, /* j */
60     [0x25] = {1,4}, /* k */
61     [0x26] = {1,5}, /* l */
62     [0x32] = {2,0}, /* m */
63     [0x31] = {2,1}, /* n */
64     [0x18] = {2,2}, /* o */
65     [0x19] = {2,3}, /* p */
66     [0x10] = {2,4}, /* q */
67     [0x13] = {2,5}, /* r */
68     [0x1f] = {3,0}, /* s */
69     [0x14] = {3,1}, /* t */
70     [0x16] = {3,2}, /* u */
71     [0x2f] = {3,3}, /* v */
72     [0x11] = {3,4}, /* w */
73     [0x2d] = {3,5}, /* x */
74     [0x15] = {4,2}, /* y */
75     [0x2c] = {4,3}, /* z */
76     [0xc7] = {5,0}, /* Home */
77     [0x2a] = {5,1}, /* shift */
78     /*
79      * There are two matrix positions which map to space,
80      * but QEMU can only use one of them for the reverse
81      * mapping, so simply use the second one.
82      */
83     /* [0x39] = {5,2}, space */
84     [0x39] = {5,3}, /* space */
85     /*
86      * Matrix position {5,4} and other keys are missing here.
87      * TODO: Compare with Linux code and test real hardware.
88      */
89     [0x1c] = {5,5}, /* enter (TODO: might be wrong) */
90     [0xc8] = {6,0}, /* up */
91     [0xd0] = {6,1}, /* down */
92     [0xcb] = {6,2}, /* left */
93     [0xcd] = {6,3}, /* right */
94 };
95 
96 enum mainstone_model_e { mainstone };
97 
98 #define MAINSTONE_RAM	0x04000000
99 #define MAINSTONE_ROM	0x00800000
100 #define MAINSTONE_FLASH	0x02000000
101 
102 static struct arm_boot_info mainstone_binfo = {
103     .loader_start = PXA2XX_SDRAM_BASE,
104     .ram_size = 0x04000000,
105 };
106 
107 static void mainstone_common_init(MemoryRegion *address_space_mem,
108                                   MachineState *machine,
109                                   enum mainstone_model_e model, int arm_id)
110 {
111     uint32_t sector_len = 256 * 1024;
112     hwaddr mainstone_flash_base[] = { MST_FLASH_0, MST_FLASH_1 };
113     PXA2xxState *mpu;
114     DeviceState *mst_irq;
115     DriveInfo *dinfo;
116     int i;
117     int be;
118     MemoryRegion *rom = g_new(MemoryRegion, 1);
119     const char *cpu_model = machine->cpu_model;
120 
121     if (!cpu_model)
122         cpu_model = "pxa270-c5";
123 
124     /* Setup CPU & memory */
125     mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size, cpu_model);
126     memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM);
127     vmstate_register_ram_global(rom);
128     memory_region_set_readonly(rom, true);
129     memory_region_add_subregion(address_space_mem, 0, rom);
130 
131 #ifdef TARGET_WORDS_BIGENDIAN
132     be = 1;
133 #else
134     be = 0;
135 #endif
136     /* There are two 32MiB flash devices on the board */
137     for (i = 0; i < 2; i ++) {
138         dinfo = drive_get(IF_PFLASH, 0, i);
139         if (!dinfo) {
140             if (qtest_enabled()) {
141                 break;
142             }
143             fprintf(stderr, "Two flash images must be given with the "
144                     "'pflash' parameter\n");
145             exit(1);
146         }
147 
148         if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
149                                    i ? "mainstone.flash1" : "mainstone.flash0",
150                                    MAINSTONE_FLASH,
151                                    dinfo->bdrv, sector_len,
152                                    MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0,
153                                    be)) {
154             fprintf(stderr, "qemu: Error registering flash memory.\n");
155             exit(1);
156         }
157     }
158 
159     mst_irq = sysbus_create_simple("mainstone-fpga", MST_FPGA_PHYS,
160                     qdev_get_gpio_in(mpu->gpio, 0));
161 
162     /* setup keypad */
163     pxa27x_register_keypad(mpu->kp, map, 0xe0);
164 
165     /* MMC/SD host */
166     pxa2xx_mmci_handlers(mpu->mmc, NULL, qdev_get_gpio_in(mst_irq, MMC_IRQ));
167 
168     pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[0],
169             qdev_get_gpio_in(mst_irq, S0_IRQ),
170             qdev_get_gpio_in(mst_irq, S0_CD_IRQ));
171     pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[1],
172             qdev_get_gpio_in(mst_irq, S1_IRQ),
173             qdev_get_gpio_in(mst_irq, S1_CD_IRQ));
174 
175     smc91c111_init(&nd_table[0], MST_ETH_PHYS,
176                     qdev_get_gpio_in(mst_irq, ETHERNET_IRQ));
177 
178     mainstone_binfo.kernel_filename = machine->kernel_filename;
179     mainstone_binfo.kernel_cmdline = machine->kernel_cmdline;
180     mainstone_binfo.initrd_filename = machine->initrd_filename;
181     mainstone_binfo.board_id = arm_id;
182     arm_load_kernel(mpu->cpu, &mainstone_binfo);
183 }
184 
185 static void mainstone_init(MachineState *machine)
186 {
187     mainstone_common_init(get_system_memory(), machine, mainstone, 0x196);
188 }
189 
190 static QEMUMachine mainstone2_machine = {
191     .name = "mainstone",
192     .desc = "Mainstone II (PXA27x)",
193     .init = mainstone_init,
194 };
195 
196 static void mainstone_machine_init(void)
197 {
198     qemu_register_machine(&mainstone2_machine);
199 }
200 
201 machine_init(mainstone_machine_init);
202