root / hw / palm.c @ e616a7e8
History | View | Annotate | Download (8.4 kB)
1 | c3d2689d | balrog | /*
|
---|---|---|---|
2 | c3d2689d | balrog | * PalmOne's (TM) PDAs.
|
3 | c3d2689d | balrog | *
|
4 | c3d2689d | balrog | * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org>
|
5 | c3d2689d | balrog | *
|
6 | c3d2689d | balrog | * This program is free software; you can redistribute it and/or
|
7 | c3d2689d | balrog | * modify it under the terms of the GNU General Public License as
|
8 | c3d2689d | balrog | * published by the Free Software Foundation; either version 2 of
|
9 | c3d2689d | balrog | * the License, or (at your option) any later version.
|
10 | c3d2689d | balrog | *
|
11 | c3d2689d | balrog | * This program is distributed in the hope that it will be useful,
|
12 | c3d2689d | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | c3d2689d | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | c3d2689d | balrog | * GNU General Public License for more details.
|
15 | c3d2689d | balrog | *
|
16 | c3d2689d | balrog | * You should have received a copy of the GNU General Public License
|
17 | c3d2689d | balrog | * along with this program; if not, write to the Free Software
|
18 | c3d2689d | balrog | * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
19 | c3d2689d | balrog | * MA 02111-1307 USA
|
20 | c3d2689d | balrog | */
|
21 | c3d2689d | balrog | #include "vl.h" |
22 | c3d2689d | balrog | |
23 | c3d2689d | balrog | static uint32_t static_readb(void *opaque, target_phys_addr_t offset) |
24 | c3d2689d | balrog | { |
25 | c3d2689d | balrog | uint32_t *val = (uint32_t *) opaque; |
26 | c3d2689d | balrog | return *val >> ((offset & 3) << 3); |
27 | c3d2689d | balrog | } |
28 | c3d2689d | balrog | |
29 | c3d2689d | balrog | static uint32_t static_readh(void *opaque, target_phys_addr_t offset) { |
30 | c3d2689d | balrog | uint32_t *val = (uint32_t *) opaque; |
31 | c3d2689d | balrog | return *val >> ((offset & 1) << 3); |
32 | c3d2689d | balrog | } |
33 | c3d2689d | balrog | |
34 | c3d2689d | balrog | static uint32_t static_readw(void *opaque, target_phys_addr_t offset) { |
35 | c3d2689d | balrog | uint32_t *val = (uint32_t *) opaque; |
36 | c3d2689d | balrog | return *val >> ((offset & 0) << 3); |
37 | c3d2689d | balrog | } |
38 | c3d2689d | balrog | |
39 | c3d2689d | balrog | static void static_write(void *opaque, target_phys_addr_t offset, |
40 | d951f6ff | balrog | uint32_t value) |
41 | d951f6ff | balrog | { |
42 | c3d2689d | balrog | #ifdef SPY
|
43 | c3d2689d | balrog | printf("%s: value %08lx written at " PA_FMT "\n", |
44 | c3d2689d | balrog | __FUNCTION__, value, offset); |
45 | c3d2689d | balrog | #endif
|
46 | c3d2689d | balrog | } |
47 | c3d2689d | balrog | |
48 | c3d2689d | balrog | static CPUReadMemoryFunc *static_readfn[] = {
|
49 | c3d2689d | balrog | static_readb, |
50 | c3d2689d | balrog | static_readh, |
51 | c3d2689d | balrog | static_readw, |
52 | c3d2689d | balrog | }; |
53 | c3d2689d | balrog | |
54 | c3d2689d | balrog | static CPUWriteMemoryFunc *static_writefn[] = {
|
55 | c3d2689d | balrog | static_write, |
56 | c3d2689d | balrog | static_write, |
57 | c3d2689d | balrog | static_write, |
58 | c3d2689d | balrog | }; |
59 | c3d2689d | balrog | |
60 | c3d2689d | balrog | /* Palm Tunsgten|E support */
|
61 | 8e129e07 | balrog | |
62 | 8e129e07 | balrog | /* Shared GPIOs */
|
63 | 8e129e07 | balrog | #define PALMTE_USBDETECT_GPIO 0 |
64 | 8e129e07 | balrog | #define PALMTE_USB_OR_DC_GPIO 1 |
65 | 8e129e07 | balrog | #define PALMTE_TSC_GPIO 4 |
66 | 8e129e07 | balrog | #define PALMTE_PINTDAV_GPIO 6 |
67 | 8e129e07 | balrog | #define PALMTE_MMC_WP_GPIO 8 |
68 | 8e129e07 | balrog | #define PALMTE_MMC_POWER_GPIO 9 |
69 | 8e129e07 | balrog | #define PALMTE_HDQ_GPIO 11 |
70 | 8e129e07 | balrog | #define PALMTE_HEADPHONES_GPIO 14 |
71 | 8e129e07 | balrog | #define PALMTE_SPEAKER_GPIO 15 |
72 | 8e129e07 | balrog | /* MPU private GPIOs */
|
73 | 8e129e07 | balrog | #define PALMTE_DC_GPIO 2 |
74 | 8e129e07 | balrog | #define PALMTE_MMC_SWITCH_GPIO 4 |
75 | 8e129e07 | balrog | #define PALMTE_MMC1_GPIO 6 |
76 | 8e129e07 | balrog | #define PALMTE_MMC2_GPIO 7 |
77 | 8e129e07 | balrog | #define PALMTE_MMC3_GPIO 11 |
78 | 8e129e07 | balrog | |
79 | c3d2689d | balrog | static void palmte_microwire_setup(struct omap_mpu_state_s *cpu) |
80 | c3d2689d | balrog | { |
81 | 3efda49d | balrog | omap_uwire_attach( |
82 | 3efda49d | balrog | cpu->microwire, |
83 | 7fc42b4b | balrog | tsc2102_init( |
84 | 7fc42b4b | balrog | omap_gpio_in_get(cpu->gpio)[PALMTE_PINTDAV_GPIO]), |
85 | 3efda49d | balrog | 0);
|
86 | c3d2689d | balrog | } |
87 | c3d2689d | balrog | |
88 | 38a34e1d | balrog | static struct { |
89 | 38a34e1d | balrog | int row;
|
90 | 38a34e1d | balrog | int column;
|
91 | 38a34e1d | balrog | } palmte_keymap[0x80] = {
|
92 | 38a34e1d | balrog | [0 ... 0x7f] = { -1, -1 }, |
93 | 38a34e1d | balrog | [0x3b] = { 0, 0 }, /* F1 -> Calendar */ |
94 | 38a34e1d | balrog | [0x3c] = { 1, 0 }, /* F2 -> Contacts */ |
95 | 38a34e1d | balrog | [0x3d] = { 2, 0 }, /* F3 -> Tasks List */ |
96 | 38a34e1d | balrog | [0x3e] = { 3, 0 }, /* F4 -> Note Pad */ |
97 | 38a34e1d | balrog | [0x01] = { 4, 0 }, /* Esc -> Power */ |
98 | 38a34e1d | balrog | [0x4b] = { 0, 1 }, /* Left */ |
99 | 38a34e1d | balrog | [0x50] = { 1, 1 }, /* Down */ |
100 | 38a34e1d | balrog | [0x48] = { 2, 1 }, /* Up */ |
101 | 38a34e1d | balrog | [0x4d] = { 3, 1 }, /* Right */ |
102 | 38a34e1d | balrog | [0x4c] = { 4, 1 }, /* Centre */ |
103 | 38a34e1d | balrog | [0x39] = { 4, 1 }, /* Spc -> Centre */ |
104 | 38a34e1d | balrog | }; |
105 | 38a34e1d | balrog | |
106 | 38a34e1d | balrog | static void palmte_button_event(void *opaque, int keycode) |
107 | 38a34e1d | balrog | { |
108 | 38a34e1d | balrog | struct omap_mpu_state_s *cpu = (struct omap_mpu_state_s *) opaque; |
109 | 38a34e1d | balrog | |
110 | 38a34e1d | balrog | if (palmte_keymap[keycode & 0x7f].row != -1) |
111 | 38a34e1d | balrog | omap_mpuio_key(cpu->mpuio, |
112 | 38a34e1d | balrog | palmte_keymap[keycode & 0x7f].row,
|
113 | 38a34e1d | balrog | palmte_keymap[keycode & 0x7f].column,
|
114 | 38a34e1d | balrog | !(keycode & 0x80));
|
115 | 38a34e1d | balrog | } |
116 | 38a34e1d | balrog | |
117 | 7fc42b4b | balrog | static void palmte_onoff_gpios(void *opaque, int line, int level) |
118 | 7fc42b4b | balrog | { |
119 | 7fc42b4b | balrog | switch (line) {
|
120 | 7fc42b4b | balrog | case 0: |
121 | 7fc42b4b | balrog | printf("%s: current to MMC/SD card %sabled.\n",
|
122 | 7fc42b4b | balrog | __FUNCTION__, level ? "dis" : "en"); |
123 | 7fc42b4b | balrog | break;
|
124 | 7fc42b4b | balrog | case 1: |
125 | 7fc42b4b | balrog | printf("%s: internal speaker amplifier %s.\n",
|
126 | 7fc42b4b | balrog | __FUNCTION__, level ? "down" : "on"); |
127 | 7fc42b4b | balrog | break;
|
128 | 7fc42b4b | balrog | |
129 | 7fc42b4b | balrog | /* These LCD & Audio output signals have not been identified yet. */
|
130 | 7fc42b4b | balrog | case 2: |
131 | 7fc42b4b | balrog | case 3: |
132 | 7fc42b4b | balrog | case 4: |
133 | 7fc42b4b | balrog | printf("%s: LCD GPIO%i %s.\n",
|
134 | 7fc42b4b | balrog | __FUNCTION__, line - 1, level ? "high" : "low"); |
135 | 7fc42b4b | balrog | break;
|
136 | 7fc42b4b | balrog | case 5: |
137 | 7fc42b4b | balrog | case 6: |
138 | 7fc42b4b | balrog | printf("%s: Audio GPIO%i %s.\n",
|
139 | 7fc42b4b | balrog | __FUNCTION__, line - 4, level ? "high" : "low"); |
140 | 7fc42b4b | balrog | break;
|
141 | 7fc42b4b | balrog | } |
142 | 7fc42b4b | balrog | } |
143 | 7fc42b4b | balrog | |
144 | 7fc42b4b | balrog | static void palmte_gpio_setup(struct omap_mpu_state_s *cpu) |
145 | 7fc42b4b | balrog | { |
146 | 7fc42b4b | balrog | qemu_irq *misc_gpio; |
147 | 7fc42b4b | balrog | |
148 | 7fc42b4b | balrog | omap_mmc_handlers(cpu->mmc, |
149 | 7fc42b4b | balrog | omap_gpio_in_get(cpu->gpio)[PALMTE_MMC_WP_GPIO], |
150 | 7fc42b4b | balrog | qemu_irq_invert(omap_mpuio_in_get(cpu->mpuio) |
151 | 7fc42b4b | balrog | [PALMTE_MMC_SWITCH_GPIO])); |
152 | 7fc42b4b | balrog | |
153 | 7fc42b4b | balrog | misc_gpio = qemu_allocate_irqs(palmte_onoff_gpios, cpu, 7);
|
154 | 7fc42b4b | balrog | omap_gpio_out_set(cpu->gpio, PALMTE_MMC_POWER_GPIO, misc_gpio[0]);
|
155 | 7fc42b4b | balrog | omap_gpio_out_set(cpu->gpio, PALMTE_SPEAKER_GPIO, misc_gpio[1]);
|
156 | 7fc42b4b | balrog | omap_gpio_out_set(cpu->gpio, 11, misc_gpio[2]); |
157 | 7fc42b4b | balrog | omap_gpio_out_set(cpu->gpio, 12, misc_gpio[3]); |
158 | 7fc42b4b | balrog | omap_gpio_out_set(cpu->gpio, 13, misc_gpio[4]); |
159 | 7fc42b4b | balrog | omap_mpuio_out_set(cpu->mpuio, 1, misc_gpio[5]); |
160 | 7fc42b4b | balrog | omap_mpuio_out_set(cpu->mpuio, 3, misc_gpio[6]); |
161 | 7fc42b4b | balrog | |
162 | 7fc42b4b | balrog | /* Reset some inputs to initial state. */
|
163 | 7fc42b4b | balrog | qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_USBDETECT_GPIO]); |
164 | 7fc42b4b | balrog | qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_USB_OR_DC_GPIO]); |
165 | 7fc42b4b | balrog | qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[4]);
|
166 | 7fc42b4b | balrog | qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_HEADPHONES_GPIO]); |
167 | 7fc42b4b | balrog | qemu_irq_lower(omap_mpuio_in_get(cpu->mpuio)[PALMTE_DC_GPIO]); |
168 | 7fc42b4b | balrog | qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[6]);
|
169 | 7fc42b4b | balrog | qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[7]);
|
170 | 7fc42b4b | balrog | qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[11]);
|
171 | 7fc42b4b | balrog | } |
172 | 7fc42b4b | balrog | |
173 | 6ac0e82d | balrog | static void palmte_init(int ram_size, int vga_ram_size, |
174 | 6ac0e82d | balrog | const char *boot_device, DisplayState *ds, |
175 | 6ac0e82d | balrog | const char **fd_filename, int snapshot, |
176 | c3d2689d | balrog | const char *kernel_filename, const char *kernel_cmdline, |
177 | c3d2689d | balrog | const char *initrd_filename, const char *cpu_model) |
178 | c3d2689d | balrog | { |
179 | c3d2689d | balrog | struct omap_mpu_state_s *cpu;
|
180 | c3d2689d | balrog | int flash_size = 0x00800000; |
181 | c3d2689d | balrog | int sdram_size = 0x02000000; |
182 | c3d2689d | balrog | int io;
|
183 | c3d2689d | balrog | static uint32_t cs0val = 0xffffffff; |
184 | c3d2689d | balrog | static uint32_t cs1val = 0x0000e1a0; |
185 | c3d2689d | balrog | static uint32_t cs2val = 0x0000e1a0; |
186 | c3d2689d | balrog | static uint32_t cs3val = 0xe1a0e1a0; |
187 | c3d2689d | balrog | ram_addr_t phys_flash; |
188 | c3d2689d | balrog | int rom_size, rom_loaded = 0; |
189 | c3d2689d | balrog | |
190 | c3d2689d | balrog | if (ram_size < flash_size + sdram_size + OMAP15XX_SRAM_SIZE) {
|
191 | c3d2689d | balrog | fprintf(stderr, "This architecture uses %i bytes of memory\n",
|
192 | c3d2689d | balrog | flash_size + sdram_size + OMAP15XX_SRAM_SIZE); |
193 | c3d2689d | balrog | exit(1);
|
194 | c3d2689d | balrog | } |
195 | c3d2689d | balrog | |
196 | c3d2689d | balrog | cpu = omap310_mpu_init(sdram_size, ds, cpu_model); |
197 | c3d2689d | balrog | |
198 | c3d2689d | balrog | /* External Flash (EMIFS) */
|
199 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_CS0_BASE, flash_size, |
200 | c3d2689d | balrog | (phys_flash = qemu_ram_alloc(flash_size)) | IO_MEM_ROM); |
201 | c3d2689d | balrog | |
202 | c3d2689d | balrog | io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs0val);
|
203 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_CS0_BASE + flash_size, |
204 | c3d2689d | balrog | OMAP_CS0_SIZE - flash_size, io); |
205 | c3d2689d | balrog | io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs1val);
|
206 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_CS1_BASE, OMAP_CS1_SIZE, io); |
207 | c3d2689d | balrog | io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs2val);
|
208 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_CS2_BASE, OMAP_CS2_SIZE, io); |
209 | c3d2689d | balrog | io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs3val);
|
210 | c3d2689d | balrog | cpu_register_physical_memory(OMAP_CS3_BASE, OMAP_CS3_SIZE, io); |
211 | c3d2689d | balrog | |
212 | c3d2689d | balrog | palmte_microwire_setup(cpu); |
213 | c3d2689d | balrog | |
214 | 38a34e1d | balrog | qemu_add_kbd_event_handler(palmte_button_event, cpu); |
215 | 38a34e1d | balrog | |
216 | 7fc42b4b | balrog | palmte_gpio_setup(cpu); |
217 | 8e129e07 | balrog | |
218 | c3d2689d | balrog | /* Setup initial (reset) machine state */
|
219 | c3d2689d | balrog | if (nb_option_roms) {
|
220 | c3d2689d | balrog | rom_size = get_image_size(option_rom[0]);
|
221 | c3d2689d | balrog | if (rom_size > flash_size)
|
222 | c3d2689d | balrog | fprintf(stderr, "%s: ROM image too big (%x > %x)\n",
|
223 | c3d2689d | balrog | __FUNCTION__, rom_size, flash_size); |
224 | c3d2689d | balrog | else if (rom_size > 0 && load_image(option_rom[0], |
225 | c3d2689d | balrog | phys_ram_base + phys_flash) > 0) {
|
226 | c3d2689d | balrog | rom_loaded = 1;
|
227 | c3d2689d | balrog | cpu->env->regs[15] = 0x00000000; |
228 | c3d2689d | balrog | } else
|
229 | c3d2689d | balrog | fprintf(stderr, "%s: error loading '%s'\n",
|
230 | c3d2689d | balrog | __FUNCTION__, option_rom[0]);
|
231 | c3d2689d | balrog | } |
232 | c3d2689d | balrog | |
233 | c3d2689d | balrog | if (!rom_loaded && !kernel_filename) {
|
234 | c3d2689d | balrog | fprintf(stderr, "Kernel or ROM image must be specified\n");
|
235 | c3d2689d | balrog | exit(1);
|
236 | c3d2689d | balrog | } |
237 | c3d2689d | balrog | |
238 | c3d2689d | balrog | /* Load the kernel. */
|
239 | c3d2689d | balrog | if (kernel_filename) {
|
240 | c3d2689d | balrog | /* Start at bootloader. */
|
241 | c3d2689d | balrog | cpu->env->regs[15] = OMAP_EMIFF_BASE;
|
242 | c3d2689d | balrog | |
243 | c3d2689d | balrog | arm_load_kernel(cpu->env, sdram_size, kernel_filename, kernel_cmdline, |
244 | c3d2689d | balrog | initrd_filename, 0x331, OMAP_EMIFF_BASE);
|
245 | c3d2689d | balrog | } |
246 | c3d2689d | balrog | |
247 | c3d2689d | balrog | dpy_resize(ds, 320, 320); |
248 | c3d2689d | balrog | } |
249 | c3d2689d | balrog | |
250 | c3d2689d | balrog | QEMUMachine palmte_machine = { |
251 | c3d2689d | balrog | "cheetah",
|
252 | c3d2689d | balrog | "Palm Tungsten|E aka. Cheetah PDA (OMAP310)",
|
253 | c3d2689d | balrog | palmte_init, |
254 | c3d2689d | balrog | }; |