Add PalmT|E matrix keypad connected to OMAP GPIOs.
[qemu] / hw / palm.c
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 #ifdef SPY
42     printf("%s: value %08lx written at " PA_FMT "\n",
43                     __FUNCTION__, value, offset);
44 #endif
45 }
46
47 static CPUReadMemoryFunc *static_readfn[] = {
48     static_readb,
49     static_readh,
50     static_readw,
51 };
52
53 static CPUWriteMemoryFunc *static_writefn[] = {
54     static_write,
55     static_write,
56     static_write,
57 };
58
59 /* Palm Tunsgten|E support */
60 static void palmte_microwire_setup(struct omap_mpu_state_s *cpu)
61 {
62 }
63
64 static struct {
65     int row;
66     int column;
67 } palmte_keymap[0x80] = {
68     [0 ... 0x7f] = { -1, -1 },
69     [0x3b] = { 0, 0 },  /* F1   -> Calendar */
70     [0x3c] = { 1, 0 },  /* F2   -> Contacts */
71     [0x3d] = { 2, 0 },  /* F3   -> Tasks List */
72     [0x3e] = { 3, 0 },  /* F4   -> Note Pad */
73     [0x01] = { 4, 0 },  /* Esc  -> Power */
74     [0x4b] = { 0, 1 },  /*         Left */
75     [0x50] = { 1, 1 },  /*         Down */
76     [0x48] = { 2, 1 },  /*         Up */
77     [0x4d] = { 3, 1 },  /*         Right */
78     [0x4c] = { 4, 1 },  /*         Centre */
79     [0x39] = { 4, 1 },  /* Spc  -> Centre */
80 };
81
82 static void palmte_button_event(void *opaque, int keycode)
83 {
84     struct omap_mpu_state_s *cpu = (struct omap_mpu_state_s *) opaque;
85
86     if (palmte_keymap[keycode & 0x7f].row != -1)
87         omap_mpuio_key(cpu->mpuio,
88                         palmte_keymap[keycode & 0x7f].row,
89                         palmte_keymap[keycode & 0x7f].column,
90                         !(keycode & 0x80));
91 }
92
93 static void palmte_init(int ram_size, int vga_ram_size, int boot_device,
94                 DisplayState *ds, const char **fd_filename, int snapshot,
95                 const char *kernel_filename, const char *kernel_cmdline,
96                 const char *initrd_filename, const char *cpu_model)
97 {
98     struct omap_mpu_state_s *cpu;
99     int flash_size = 0x00800000;
100     int sdram_size = 0x02000000;
101     int io;
102     static uint32_t cs0val = 0xffffffff;
103     static uint32_t cs1val = 0x0000e1a0;
104     static uint32_t cs2val = 0x0000e1a0;
105     static uint32_t cs3val = 0xe1a0e1a0;
106     ram_addr_t phys_flash;
107     int rom_size, rom_loaded = 0;
108
109     if (ram_size < flash_size + sdram_size + OMAP15XX_SRAM_SIZE) {
110         fprintf(stderr, "This architecture uses %i bytes of memory\n",
111                         flash_size + sdram_size + OMAP15XX_SRAM_SIZE);
112         exit(1);
113     }
114
115     cpu = omap310_mpu_init(sdram_size, ds, cpu_model);
116
117     /* External Flash (EMIFS) */
118     cpu_register_physical_memory(OMAP_CS0_BASE, flash_size,
119                     (phys_flash = qemu_ram_alloc(flash_size)) | IO_MEM_ROM);
120
121     io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs0val);
122     cpu_register_physical_memory(OMAP_CS0_BASE + flash_size,
123                     OMAP_CS0_SIZE - flash_size, io);
124     io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs1val);
125     cpu_register_physical_memory(OMAP_CS1_BASE, OMAP_CS1_SIZE, io);
126     io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs2val);
127     cpu_register_physical_memory(OMAP_CS2_BASE, OMAP_CS2_SIZE, io);
128     io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs3val);
129     cpu_register_physical_memory(OMAP_CS3_BASE, OMAP_CS3_SIZE, io);
130
131     palmte_microwire_setup(cpu);
132
133     qemu_add_kbd_event_handler(palmte_button_event, cpu);
134
135     /* Setup initial (reset) machine state */
136     if (nb_option_roms) {
137         rom_size = get_image_size(option_rom[0]);
138         if (rom_size > flash_size)
139             fprintf(stderr, "%s: ROM image too big (%x > %x)\n",
140                             __FUNCTION__, rom_size, flash_size);
141         else if (rom_size > 0 && load_image(option_rom[0],
142                                 phys_ram_base + phys_flash) > 0) {
143             rom_loaded = 1;
144             cpu->env->regs[15] = 0x00000000;
145         } else
146             fprintf(stderr, "%s: error loading '%s'\n",
147                             __FUNCTION__, option_rom[0]);
148     }
149
150     if (!rom_loaded && !kernel_filename) {
151         fprintf(stderr, "Kernel or ROM image must be specified\n");
152         exit(1);
153     }
154
155     /* Load the kernel.  */
156     if (kernel_filename) {
157         /* Start at bootloader.  */
158         cpu->env->regs[15] = OMAP_EMIFF_BASE;
159
160         arm_load_kernel(cpu->env, sdram_size, kernel_filename, kernel_cmdline,
161                         initrd_filename, 0x331, OMAP_EMIFF_BASE);
162     }
163
164     dpy_resize(ds, 320, 320);
165 }
166
167 QEMUMachine palmte_machine = {
168     "cheetah",
169     "Palm Tungsten|E aka. Cheetah PDA (OMAP310)",
170     palmte_init,
171 };