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