|
1 /* |
|
2 * PalmOne's (TM) PDAs. |
|
3 * |
|
4 * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org> |
|
5 * |
|
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. |
|
10 * |
|
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. |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License |
|
17 * along with this program; if not, write to the Free Software |
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
|
19 * MA 02111-1307 USA |
|
20 */ |
|
21 #include "hw.h" |
|
22 #include "audio/audio.h" |
|
23 #include "sysemu.h" |
|
24 #include "console.h" |
|
25 #include "gui.h" |
|
26 #include "omap.h" |
|
27 #include "boards.h" |
|
28 #include "arm-misc.h" |
|
29 #include "devices.h" |
|
30 |
|
31 static uint32_t static_readb(void *opaque, target_phys_addr_t offset) |
|
32 { |
|
33 uint32_t *val = (uint32_t *) opaque; |
|
34 return *val >> ((offset & 3) << 3); |
|
35 } |
|
36 |
|
37 static uint32_t static_readh(void *opaque, target_phys_addr_t offset) |
|
38 { |
|
39 uint32_t *val = (uint32_t *) opaque; |
|
40 return *val >> ((offset & 1) << 3); |
|
41 } |
|
42 |
|
43 static uint32_t static_readw(void *opaque, target_phys_addr_t offset) |
|
44 { |
|
45 uint32_t *val = (uint32_t *) opaque; |
|
46 return *val >> ((offset & 0) << 3); |
|
47 } |
|
48 |
|
49 static void static_write(void *opaque, target_phys_addr_t offset, |
|
50 uint32_t value) |
|
51 { |
|
52 #ifdef SPY |
|
53 printf("%s: value %08lx written at " PA_FMT "\n", |
|
54 __FUNCTION__, value, offset); |
|
55 #endif |
|
56 } |
|
57 |
|
58 static CPUReadMemoryFunc *static_readfn[] = { |
|
59 static_readb, |
|
60 static_readh, |
|
61 static_readw, |
|
62 }; |
|
63 |
|
64 static CPUWriteMemoryFunc *static_writefn[] = { |
|
65 static_write, |
|
66 static_write, |
|
67 static_write, |
|
68 }; |
|
69 |
|
70 /* Palm Tunsgten|E support */ |
|
71 |
|
72 /* Shared GPIOs */ |
|
73 #define PALMTE_USBDETECT_GPIO 0 |
|
74 #define PALMTE_USB_OR_DC_GPIO 1 |
|
75 #define PALMTE_TSC_GPIO 4 |
|
76 #define PALMTE_PINTDAV_GPIO 6 |
|
77 #define PALMTE_MMC_WP_GPIO 8 |
|
78 #define PALMTE_MMC_POWER_GPIO 9 |
|
79 #define PALMTE_HDQ_GPIO 11 |
|
80 #define PALMTE_HEADPHONES_GPIO 14 |
|
81 #define PALMTE_SPEAKER_GPIO 15 |
|
82 /* MPU private GPIOs */ |
|
83 #define PALMTE_DC_GPIO 2 |
|
84 #define PALMTE_MMC_SWITCH_GPIO 4 |
|
85 #define PALMTE_MMC1_GPIO 6 |
|
86 #define PALMTE_MMC2_GPIO 7 |
|
87 #define PALMTE_MMC3_GPIO 11 |
|
88 |
|
89 static struct mouse_transform_info_s palmte_pointercal = { |
|
90 .x = 320, |
|
91 .y = 320, |
|
92 .a = { -5909, 8, 22465308, 104, 7644, -1219972, 65536 }, |
|
93 }; |
|
94 |
|
95 static void palmte_microwire_setup(struct omap_mpu_state_s *cpu) |
|
96 { |
|
97 struct uwire_slave_s *tsc; |
|
98 AudioState *audio = 0; |
|
99 |
|
100 #ifdef HAS_AUDIO |
|
101 audio = AUD_init(); |
|
102 #endif |
|
103 |
|
104 tsc = tsc2102_init(omap_gpio_in_get(cpu->gpio)[PALMTE_PINTDAV_GPIO], |
|
105 audio); |
|
106 |
|
107 omap_uwire_attach(cpu->microwire, tsc, 0); |
|
108 omap_mcbsp_i2s_attach(cpu->mcbsp1, tsc210x_codec(tsc)); |
|
109 |
|
110 tsc210x_set_transform(tsc, &palmte_pointercal); |
|
111 } |
|
112 |
|
113 static struct { |
|
114 int row; |
|
115 int column; |
|
116 } palmte_keymap[0x80] = { |
|
117 [0 ... 0x7f] = { -1, -1 }, |
|
118 [0x3b] = { 0, 0 }, /* F1 -> Calendar */ |
|
119 [0x3c] = { 1, 0 }, /* F2 -> Contacts */ |
|
120 [0x3d] = { 2, 0 }, /* F3 -> Tasks List */ |
|
121 [0x3e] = { 3, 0 }, /* F4 -> Note Pad */ |
|
122 [0x01] = { 4, 0 }, /* Esc -> Power */ |
|
123 [0x4b] = { 0, 1 }, /* Left */ |
|
124 [0x50] = { 1, 1 }, /* Down */ |
|
125 [0x48] = { 2, 1 }, /* Up */ |
|
126 [0x4d] = { 3, 1 }, /* Right */ |
|
127 [0x4c] = { 4, 1 }, /* Centre */ |
|
128 [0x39] = { 4, 1 }, /* Spc -> Centre */ |
|
129 }; |
|
130 |
|
131 static void palmte_button_event(void *opaque, int keycode) |
|
132 { |
|
133 struct omap_mpu_state_s *cpu = (struct omap_mpu_state_s *) opaque; |
|
134 |
|
135 if (palmte_keymap[keycode & 0x7f].row != -1) |
|
136 omap_mpuio_key(cpu->mpuio, |
|
137 palmte_keymap[keycode & 0x7f].row, |
|
138 palmte_keymap[keycode & 0x7f].column, |
|
139 !(keycode & 0x80)); |
|
140 } |
|
141 |
|
142 static void palmte_onoff_gpios(void *opaque, int line, int level) |
|
143 { |
|
144 switch (line) { |
|
145 case 0: |
|
146 printf("%s: current to MMC/SD card %sabled.\n", |
|
147 __FUNCTION__, level ? "dis" : "en"); |
|
148 break; |
|
149 case 1: |
|
150 printf("%s: internal speaker amplifier %s.\n", |
|
151 __FUNCTION__, level ? "down" : "on"); |
|
152 break; |
|
153 |
|
154 /* These LCD & Audio output signals have not been identified yet. */ |
|
155 case 2: |
|
156 case 3: |
|
157 case 4: |
|
158 printf("%s: LCD GPIO%i %s.\n", |
|
159 __FUNCTION__, line - 1, level ? "high" : "low"); |
|
160 break; |
|
161 case 5: |
|
162 case 6: |
|
163 printf("%s: Audio GPIO%i %s.\n", |
|
164 __FUNCTION__, line - 4, level ? "high" : "low"); |
|
165 break; |
|
166 } |
|
167 } |
|
168 |
|
169 static void palmte_gpio_setup(struct omap_mpu_state_s *cpu) |
|
170 { |
|
171 qemu_irq *misc_gpio; |
|
172 |
|
173 omap_mmc_handlers(cpu->mmc, |
|
174 omap_gpio_in_get(cpu->gpio)[PALMTE_MMC_WP_GPIO], |
|
175 qemu_irq_invert(omap_mpuio_in_get(cpu->mpuio) |
|
176 [PALMTE_MMC_SWITCH_GPIO])); |
|
177 |
|
178 misc_gpio = qemu_allocate_irqs(palmte_onoff_gpios, cpu, 7); |
|
179 omap_gpio_out_set(cpu->gpio, PALMTE_MMC_POWER_GPIO, misc_gpio[0]); |
|
180 omap_gpio_out_set(cpu->gpio, PALMTE_SPEAKER_GPIO, misc_gpio[1]); |
|
181 omap_gpio_out_set(cpu->gpio, 11, misc_gpio[2]); |
|
182 omap_gpio_out_set(cpu->gpio, 12, misc_gpio[3]); |
|
183 omap_gpio_out_set(cpu->gpio, 13, misc_gpio[4]); |
|
184 omap_mpuio_out_set(cpu->mpuio, 1, misc_gpio[5]); |
|
185 omap_mpuio_out_set(cpu->mpuio, 3, misc_gpio[6]); |
|
186 |
|
187 /* Reset some inputs to initial state. */ |
|
188 qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_USBDETECT_GPIO]); |
|
189 qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_USB_OR_DC_GPIO]); |
|
190 qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[4]); |
|
191 qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_HEADPHONES_GPIO]); |
|
192 qemu_irq_lower(omap_mpuio_in_get(cpu->mpuio)[PALMTE_DC_GPIO]); |
|
193 qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[6]); |
|
194 qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[7]); |
|
195 qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[11]); |
|
196 } |
|
197 |
|
198 static struct arm_boot_info palmte_binfo = { |
|
199 .loader_start = OMAP_EMIFF_BASE, |
|
200 .ram_size = 0x02000000, |
|
201 .board_id = 0x331, |
|
202 }; |
|
203 |
|
204 static void palmte_init(ram_addr_t ram_size, int vga_ram_size, |
|
205 const char *boot_device, DisplayState *ds, |
|
206 const char *kernel_filename, const char *kernel_cmdline, |
|
207 const char *initrd_filename, const char *cpu_model) |
|
208 { |
|
209 struct omap_mpu_state_s *cpu; |
|
210 int flash_size = 0x00800000; |
|
211 int sdram_size = palmte_binfo.ram_size; |
|
212 int io; |
|
213 static uint32_t cs0val = 0xffffffff; |
|
214 static uint32_t cs1val = 0x0000e1a0; |
|
215 static uint32_t cs2val = 0x0000e1a0; |
|
216 static uint32_t cs3val = 0xe1a0e1a0; |
|
217 ram_addr_t phys_flash; |
|
218 int rom_size, rom_loaded = 0; |
|
219 |
|
220 if (ram_size < flash_size + sdram_size + OMAP15XX_SRAM_SIZE) { |
|
221 fprintf(stderr, "This architecture uses %i bytes of memory\n", |
|
222 flash_size + sdram_size + OMAP15XX_SRAM_SIZE); |
|
223 exit(1); |
|
224 } |
|
225 |
|
226 cpu = omap310_mpu_init(sdram_size, ds, cpu_model); |
|
227 |
|
228 /* External Flash (EMIFS) */ |
|
229 cpu_register_physical_memory(OMAP_CS0_BASE, flash_size, |
|
230 (phys_flash = qemu_ram_alloc(flash_size)) | IO_MEM_ROM); |
|
231 |
|
232 io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs0val); |
|
233 cpu_register_physical_memory(OMAP_CS0_BASE + flash_size, |
|
234 OMAP_CS0_SIZE - flash_size, io); |
|
235 io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs1val); |
|
236 cpu_register_physical_memory(OMAP_CS1_BASE, OMAP_CS1_SIZE, io); |
|
237 io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs2val); |
|
238 cpu_register_physical_memory(OMAP_CS2_BASE, OMAP_CS2_SIZE, io); |
|
239 io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs3val); |
|
240 cpu_register_physical_memory(OMAP_CS3_BASE, OMAP_CS3_SIZE, io); |
|
241 |
|
242 palmte_microwire_setup(cpu); |
|
243 |
|
244 gui_register_dev_key_callback(palmte_button_event, cpu); |
|
245 |
|
246 palmte_gpio_setup(cpu); |
|
247 |
|
248 /* Setup initial (reset) machine state */ |
|
249 if (nb_option_roms) { |
|
250 rom_size = get_image_size(option_rom[0]); |
|
251 if (rom_size > flash_size) |
|
252 fprintf(stderr, "%s: ROM image too big (%x > %x)\n", |
|
253 __FUNCTION__, rom_size, flash_size); |
|
254 /* FIXME: This is broken if it spans multiple RAM regions. */ |
|
255 else if (rom_size > 0 && load_image(option_rom[0], |
|
256 host_ram_addr(phys_flash)) > 0) { |
|
257 rom_loaded = 1; |
|
258 cpu->env->regs[15] = 0x00000000; |
|
259 } else |
|
260 fprintf(stderr, "%s: error loading '%s'\n", |
|
261 __FUNCTION__, option_rom[0]); |
|
262 } |
|
263 |
|
264 if (!rom_loaded && !kernel_filename) { |
|
265 fprintf(stderr, "Kernel or ROM image must be specified\n"); |
|
266 exit(1); |
|
267 } |
|
268 |
|
269 /* Load the kernel. */ |
|
270 if (kernel_filename) { |
|
271 /* Start at bootloader. */ |
|
272 cpu->env->regs[15] = palmte_binfo.loader_start; |
|
273 |
|
274 palmte_binfo.kernel_filename = kernel_filename; |
|
275 palmte_binfo.kernel_cmdline = kernel_cmdline; |
|
276 palmte_binfo.initrd_filename = initrd_filename; |
|
277 arm_load_kernel(cpu->env, &palmte_binfo); |
|
278 } |
|
279 |
|
280 #if 0 |
|
281 /* FIXME: We shouldn't really be doing this here. The LCD controller |
|
282 will set the size once configured, so this just sets an initial |
|
283 size until the guest activates the display. */ |
|
284 /*dpy_resize(ds, 320, 320);*/ |
|
285 DFG TODO: FIXED? |
|
286 #endif |
|
287 } |
|
288 |
|
289 QEMUMachine palmte_machine = { |
|
290 .name = "cheetah", |
|
291 .desc = "Palm Tungsten|E aka. Cheetah PDA (OMAP310)", |
|
292 .init = palmte_init, |
|
293 .ram_require = (0x02000000 + 0x00800000 + OMAP15XX_SRAM_SIZE) | |
|
294 RAMSIZE_FIXED, |
|
295 }; |