Merge remote-tracking branch 'remotes/sstabellini/tags/xen-20171026-tag' into staging
[qemu.git] / hw / arm / palm.c
bloba1f55d79b4ed19f009a7d0aa538ab63437d922b1
1 /*
2 * PalmOne's (TM) PDAs.
4 * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
20 #include "qapi/error.h"
21 #include "hw/hw.h"
22 #include "audio/audio.h"
23 #include "sysemu/sysemu.h"
24 #include "sysemu/qtest.h"
25 #include "ui/console.h"
26 #include "hw/arm/omap.h"
27 #include "hw/boards.h"
28 #include "hw/arm/arm.h"
29 #include "hw/devices.h"
30 #include "hw/loader.h"
31 #include "exec/address-spaces.h"
32 #include "cpu.h"
34 static uint64_t static_read(void *opaque, hwaddr offset, unsigned size)
36 uint32_t *val = (uint32_t *)opaque;
37 uint32_t sizemask = 7 >> size;
39 return *val >> ((offset & sizemask) << 3);
42 static void static_write(void *opaque, hwaddr offset, uint64_t value,
43 unsigned size)
45 #ifdef SPY
46 printf("%s: value %08lx written at " PA_FMT "\n",
47 __FUNCTION__, value, offset);
48 #endif
51 static const MemoryRegionOps static_ops = {
52 .read = static_read,
53 .write = static_write,
54 .valid.min_access_size = 1,
55 .valid.max_access_size = 4,
56 .endianness = DEVICE_NATIVE_ENDIAN,
59 /* Palm Tunsgten|E support */
61 /* Shared GPIOs */
62 #define PALMTE_USBDETECT_GPIO 0
63 #define PALMTE_USB_OR_DC_GPIO 1
64 #define PALMTE_TSC_GPIO 4
65 #define PALMTE_PINTDAV_GPIO 6
66 #define PALMTE_MMC_WP_GPIO 8
67 #define PALMTE_MMC_POWER_GPIO 9
68 #define PALMTE_HDQ_GPIO 11
69 #define PALMTE_HEADPHONES_GPIO 14
70 #define PALMTE_SPEAKER_GPIO 15
71 /* MPU private GPIOs */
72 #define PALMTE_DC_GPIO 2
73 #define PALMTE_MMC_SWITCH_GPIO 4
74 #define PALMTE_MMC1_GPIO 6
75 #define PALMTE_MMC2_GPIO 7
76 #define PALMTE_MMC3_GPIO 11
78 static MouseTransformInfo palmte_pointercal = {
79 .x = 320,
80 .y = 320,
81 .a = { -5909, 8, 22465308, 104, 7644, -1219972, 65536 },
84 static void palmte_microwire_setup(struct omap_mpu_state_s *cpu)
86 uWireSlave *tsc;
88 tsc = tsc2102_init(qdev_get_gpio_in(cpu->gpio, PALMTE_PINTDAV_GPIO));
90 omap_uwire_attach(cpu->microwire, tsc, 0);
91 omap_mcbsp_i2s_attach(cpu->mcbsp1, tsc210x_codec(tsc));
93 tsc210x_set_transform(tsc, &palmte_pointercal);
96 static struct {
97 int row;
98 int column;
99 } palmte_keymap[0x80] = {
100 [0 ... 0x7f] = { -1, -1 },
101 [0x3b] = { 0, 0 }, /* F1 -> Calendar */
102 [0x3c] = { 1, 0 }, /* F2 -> Contacts */
103 [0x3d] = { 2, 0 }, /* F3 -> Tasks List */
104 [0x3e] = { 3, 0 }, /* F4 -> Note Pad */
105 [0x01] = { 4, 0 }, /* Esc -> Power */
106 [0x4b] = { 0, 1 }, /* Left */
107 [0x50] = { 1, 1 }, /* Down */
108 [0x48] = { 2, 1 }, /* Up */
109 [0x4d] = { 3, 1 }, /* Right */
110 [0x4c] = { 4, 1 }, /* Centre */
111 [0x39] = { 4, 1 }, /* Spc -> Centre */
114 static void palmte_button_event(void *opaque, int keycode)
116 struct omap_mpu_state_s *cpu = (struct omap_mpu_state_s *) opaque;
118 if (palmte_keymap[keycode & 0x7f].row != -1)
119 omap_mpuio_key(cpu->mpuio,
120 palmte_keymap[keycode & 0x7f].row,
121 palmte_keymap[keycode & 0x7f].column,
122 !(keycode & 0x80));
125 static void palmte_onoff_gpios(void *opaque, int line, int level)
127 switch (line) {
128 case 0:
129 printf("%s: current to MMC/SD card %sabled.\n",
130 __FUNCTION__, level ? "dis" : "en");
131 break;
132 case 1:
133 printf("%s: internal speaker amplifier %s.\n",
134 __FUNCTION__, level ? "down" : "on");
135 break;
137 /* These LCD & Audio output signals have not been identified yet. */
138 case 2:
139 case 3:
140 case 4:
141 printf("%s: LCD GPIO%i %s.\n",
142 __FUNCTION__, line - 1, level ? "high" : "low");
143 break;
144 case 5:
145 case 6:
146 printf("%s: Audio GPIO%i %s.\n",
147 __FUNCTION__, line - 4, level ? "high" : "low");
148 break;
152 static void palmte_gpio_setup(struct omap_mpu_state_s *cpu)
154 qemu_irq *misc_gpio;
156 omap_mmc_handlers(cpu->mmc,
157 qdev_get_gpio_in(cpu->gpio, PALMTE_MMC_WP_GPIO),
158 qemu_irq_invert(omap_mpuio_in_get(cpu->mpuio)
159 [PALMTE_MMC_SWITCH_GPIO]));
161 misc_gpio = qemu_allocate_irqs(palmte_onoff_gpios, cpu, 7);
162 qdev_connect_gpio_out(cpu->gpio, PALMTE_MMC_POWER_GPIO, misc_gpio[0]);
163 qdev_connect_gpio_out(cpu->gpio, PALMTE_SPEAKER_GPIO, misc_gpio[1]);
164 qdev_connect_gpio_out(cpu->gpio, 11, misc_gpio[2]);
165 qdev_connect_gpio_out(cpu->gpio, 12, misc_gpio[3]);
166 qdev_connect_gpio_out(cpu->gpio, 13, misc_gpio[4]);
167 omap_mpuio_out_set(cpu->mpuio, 1, misc_gpio[5]);
168 omap_mpuio_out_set(cpu->mpuio, 3, misc_gpio[6]);
170 /* Reset some inputs to initial state. */
171 qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USBDETECT_GPIO));
172 qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USB_OR_DC_GPIO));
173 qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, 4));
174 qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_HEADPHONES_GPIO));
175 qemu_irq_lower(omap_mpuio_in_get(cpu->mpuio)[PALMTE_DC_GPIO]);
176 qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[6]);
177 qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[7]);
178 qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[11]);
181 static struct arm_boot_info palmte_binfo = {
182 .loader_start = OMAP_EMIFF_BASE,
183 .ram_size = 0x02000000,
184 .board_id = 0x331,
187 static void palmte_init(MachineState *machine)
189 const char *kernel_filename = machine->kernel_filename;
190 const char *kernel_cmdline = machine->kernel_cmdline;
191 const char *initrd_filename = machine->initrd_filename;
192 MemoryRegion *address_space_mem = get_system_memory();
193 struct omap_mpu_state_s *mpu;
194 int flash_size = 0x00800000;
195 int sdram_size = palmte_binfo.ram_size;
196 static uint32_t cs0val = 0xffffffff;
197 static uint32_t cs1val = 0x0000e1a0;
198 static uint32_t cs2val = 0x0000e1a0;
199 static uint32_t cs3val = 0xe1a0e1a0;
200 int rom_size, rom_loaded = 0;
201 MemoryRegion *flash = g_new(MemoryRegion, 1);
202 MemoryRegion *cs = g_new(MemoryRegion, 4);
204 mpu = omap310_mpu_init(address_space_mem, sdram_size, machine->cpu_type);
206 /* External Flash (EMIFS) */
207 memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
208 &error_fatal);
209 memory_region_set_readonly(flash, true);
210 memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
212 memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
213 OMAP_CS0_SIZE - flash_size);
214 memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE + flash_size,
215 &cs[0]);
216 memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val, "palmte-cs1",
217 OMAP_CS1_SIZE);
218 memory_region_add_subregion(address_space_mem, OMAP_CS1_BASE, &cs[1]);
219 memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val, "palmte-cs2",
220 OMAP_CS2_SIZE);
221 memory_region_add_subregion(address_space_mem, OMAP_CS2_BASE, &cs[2]);
222 memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val, "palmte-cs3",
223 OMAP_CS3_SIZE);
224 memory_region_add_subregion(address_space_mem, OMAP_CS3_BASE, &cs[3]);
226 palmte_microwire_setup(mpu);
228 qemu_add_kbd_event_handler(palmte_button_event, mpu);
230 palmte_gpio_setup(mpu);
232 /* Setup initial (reset) machine state */
233 if (nb_option_roms) {
234 rom_size = get_image_size(option_rom[0].name);
235 if (rom_size > flash_size) {
236 fprintf(stderr, "%s: ROM image too big (%x > %x)\n",
237 __FUNCTION__, rom_size, flash_size);
238 rom_size = 0;
240 if (rom_size > 0) {
241 rom_size = load_image_targphys(option_rom[0].name, OMAP_CS0_BASE,
242 flash_size);
243 rom_loaded = 1;
245 if (rom_size < 0) {
246 fprintf(stderr, "%s: error loading '%s'\n",
247 __FUNCTION__, option_rom[0].name);
251 if (!rom_loaded && !kernel_filename && !qtest_enabled()) {
252 fprintf(stderr, "Kernel or ROM image must be specified\n");
253 exit(1);
256 /* Load the kernel. */
257 palmte_binfo.kernel_filename = kernel_filename;
258 palmte_binfo.kernel_cmdline = kernel_cmdline;
259 palmte_binfo.initrd_filename = initrd_filename;
260 arm_load_kernel(mpu->cpu, &palmte_binfo);
263 static void palmte_machine_init(MachineClass *mc)
265 mc->desc = "Palm Tungsten|E aka. Cheetah PDA (OMAP310)";
266 mc->init = palmte_init;
267 mc->ignore_memory_transaction_failures = true;
268 mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
271 DEFINE_MACHINE("cheetah", palmte_machine_init)