root / hw / spitz.c @ 444ce241
History | View | Annotate | Download (36.8 kB)
1 | b00052e4 | balrog | /*
|
---|---|---|---|
2 | b00052e4 | balrog | * PXA270-based Clamshell PDA platforms.
|
3 | b00052e4 | balrog | *
|
4 | b00052e4 | balrog | * Copyright (c) 2006 Openedhand Ltd.
|
5 | b00052e4 | balrog | * Written by Andrzej Zaborowski <balrog@zabor.org>
|
6 | b00052e4 | balrog | *
|
7 | b00052e4 | balrog | * This code is licensed under the GNU GPL v2.
|
8 | b00052e4 | balrog | */
|
9 | b00052e4 | balrog | |
10 | b00052e4 | balrog | #include "vl.h" |
11 | b00052e4 | balrog | |
12 | b00052e4 | balrog | #define spitz_printf(format, ...) \
|
13 | b00052e4 | balrog | fprintf(stderr, "%s: " format, __FUNCTION__, ##__VA_ARGS__) |
14 | b00052e4 | balrog | #undef REG_FMT
|
15 | 444ce241 | bellard | #if TARGET_PHYS_ADDR_BITS == 32 |
16 | 444ce241 | bellard | #define REG_FMT "0x%02x" |
17 | 444ce241 | bellard | #else
|
18 | b00052e4 | balrog | #define REG_FMT "0x%02lx" |
19 | 444ce241 | bellard | #endif
|
20 | b00052e4 | balrog | |
21 | b00052e4 | balrog | /* Spitz Flash */
|
22 | b00052e4 | balrog | #define FLASH_BASE 0x0c000000 |
23 | b00052e4 | balrog | #define FLASH_ECCLPLB 0x00 /* Line parity 7 - 0 bit */ |
24 | b00052e4 | balrog | #define FLASH_ECCLPUB 0x04 /* Line parity 15 - 8 bit */ |
25 | b00052e4 | balrog | #define FLASH_ECCCP 0x08 /* Column parity 5 - 0 bit */ |
26 | b00052e4 | balrog | #define FLASH_ECCCNTR 0x0c /* ECC byte counter */ |
27 | b00052e4 | balrog | #define FLASH_ECCCLRR 0x10 /* Clear ECC */ |
28 | b00052e4 | balrog | #define FLASH_FLASHIO 0x14 /* Flash I/O */ |
29 | b00052e4 | balrog | #define FLASH_FLASHCTL 0x18 /* Flash Control */ |
30 | b00052e4 | balrog | |
31 | b00052e4 | balrog | #define FLASHCTL_CE0 (1 << 0) |
32 | b00052e4 | balrog | #define FLASHCTL_CLE (1 << 1) |
33 | b00052e4 | balrog | #define FLASHCTL_ALE (1 << 2) |
34 | b00052e4 | balrog | #define FLASHCTL_WP (1 << 3) |
35 | b00052e4 | balrog | #define FLASHCTL_CE1 (1 << 4) |
36 | b00052e4 | balrog | #define FLASHCTL_RYBY (1 << 5) |
37 | b00052e4 | balrog | #define FLASHCTL_NCE (FLASHCTL_CE0 | FLASHCTL_CE1)
|
38 | b00052e4 | balrog | |
39 | b00052e4 | balrog | struct sl_nand_s {
|
40 | b00052e4 | balrog | target_phys_addr_t target_base; |
41 | b00052e4 | balrog | struct nand_flash_s *nand;
|
42 | b00052e4 | balrog | uint8_t ctl; |
43 | b00052e4 | balrog | struct ecc_state_s ecc;
|
44 | b00052e4 | balrog | }; |
45 | b00052e4 | balrog | |
46 | b00052e4 | balrog | static uint32_t sl_readb(void *opaque, target_phys_addr_t addr) |
47 | b00052e4 | balrog | { |
48 | b00052e4 | balrog | struct sl_nand_s *s = (struct sl_nand_s *) opaque; |
49 | b00052e4 | balrog | int ryby;
|
50 | b00052e4 | balrog | addr -= s->target_base; |
51 | b00052e4 | balrog | |
52 | b00052e4 | balrog | switch (addr) {
|
53 | b00052e4 | balrog | #define BSHR(byte, from, to) ((s->ecc.lp[byte] >> (from - to)) & (1 << to)) |
54 | b00052e4 | balrog | case FLASH_ECCLPLB:
|
55 | b00052e4 | balrog | return BSHR(0, 4, 0) | BSHR(0, 5, 2) | BSHR(0, 6, 4) | BSHR(0, 7, 6) | |
56 | b00052e4 | balrog | BSHR(1, 4, 1) | BSHR(1, 5, 3) | BSHR(1, 6, 5) | BSHR(1, 7, 7); |
57 | b00052e4 | balrog | |
58 | b00052e4 | balrog | #define BSHL(byte, from, to) ((s->ecc.lp[byte] << (to - from)) & (1 << to)) |
59 | b00052e4 | balrog | case FLASH_ECCLPUB:
|
60 | b00052e4 | balrog | return BSHL(0, 0, 0) | BSHL(0, 1, 2) | BSHL(0, 2, 4) | BSHL(0, 3, 6) | |
61 | b00052e4 | balrog | BSHL(1, 0, 1) | BSHL(1, 1, 3) | BSHL(1, 2, 5) | BSHL(1, 3, 7); |
62 | b00052e4 | balrog | |
63 | b00052e4 | balrog | case FLASH_ECCCP:
|
64 | b00052e4 | balrog | return s->ecc.cp;
|
65 | b00052e4 | balrog | |
66 | b00052e4 | balrog | case FLASH_ECCCNTR:
|
67 | b00052e4 | balrog | return s->ecc.count & 0xff; |
68 | b00052e4 | balrog | |
69 | b00052e4 | balrog | case FLASH_FLASHCTL:
|
70 | b00052e4 | balrog | nand_getpins(s->nand, &ryby); |
71 | b00052e4 | balrog | if (ryby)
|
72 | b00052e4 | balrog | return s->ctl | FLASHCTL_RYBY;
|
73 | b00052e4 | balrog | else
|
74 | b00052e4 | balrog | return s->ctl;
|
75 | b00052e4 | balrog | |
76 | b00052e4 | balrog | case FLASH_FLASHIO:
|
77 | b00052e4 | balrog | return ecc_digest(&s->ecc, nand_getio(s->nand));
|
78 | b00052e4 | balrog | |
79 | b00052e4 | balrog | default:
|
80 | b00052e4 | balrog | spitz_printf("Bad register offset " REG_FMT "\n", addr); |
81 | b00052e4 | balrog | } |
82 | b00052e4 | balrog | return 0; |
83 | b00052e4 | balrog | } |
84 | b00052e4 | balrog | |
85 | a5236105 | balrog | static uint32_t sl_readl(void *opaque, target_phys_addr_t addr) |
86 | a5236105 | balrog | { |
87 | a5236105 | balrog | struct sl_nand_s *s = (struct sl_nand_s *) opaque; |
88 | a5236105 | balrog | addr -= s->target_base; |
89 | a5236105 | balrog | |
90 | a5236105 | balrog | if (addr == FLASH_FLASHIO)
|
91 | a5236105 | balrog | return ecc_digest(&s->ecc, nand_getio(s->nand)) |
|
92 | a5236105 | balrog | (ecc_digest(&s->ecc, nand_getio(s->nand)) << 16);
|
93 | a5236105 | balrog | |
94 | a5236105 | balrog | return sl_readb(opaque, addr);
|
95 | a5236105 | balrog | } |
96 | a5236105 | balrog | |
97 | b00052e4 | balrog | static void sl_writeb(void *opaque, target_phys_addr_t addr, |
98 | b00052e4 | balrog | uint32_t value) |
99 | b00052e4 | balrog | { |
100 | b00052e4 | balrog | struct sl_nand_s *s = (struct sl_nand_s *) opaque; |
101 | b00052e4 | balrog | addr -= s->target_base; |
102 | b00052e4 | balrog | |
103 | b00052e4 | balrog | switch (addr) {
|
104 | b00052e4 | balrog | case FLASH_ECCCLRR:
|
105 | b00052e4 | balrog | /* Value is ignored. */
|
106 | b00052e4 | balrog | ecc_reset(&s->ecc); |
107 | b00052e4 | balrog | break;
|
108 | b00052e4 | balrog | |
109 | b00052e4 | balrog | case FLASH_FLASHCTL:
|
110 | b00052e4 | balrog | s->ctl = value & 0xff & ~FLASHCTL_RYBY;
|
111 | b00052e4 | balrog | nand_setpins(s->nand, |
112 | b00052e4 | balrog | s->ctl & FLASHCTL_CLE, |
113 | b00052e4 | balrog | s->ctl & FLASHCTL_ALE, |
114 | b00052e4 | balrog | s->ctl & FLASHCTL_NCE, |
115 | b00052e4 | balrog | s->ctl & FLASHCTL_WP, |
116 | b00052e4 | balrog | 0);
|
117 | b00052e4 | balrog | break;
|
118 | b00052e4 | balrog | |
119 | b00052e4 | balrog | case FLASH_FLASHIO:
|
120 | b00052e4 | balrog | nand_setio(s->nand, ecc_digest(&s->ecc, value & 0xff));
|
121 | b00052e4 | balrog | break;
|
122 | b00052e4 | balrog | |
123 | b00052e4 | balrog | default:
|
124 | b00052e4 | balrog | spitz_printf("Bad register offset " REG_FMT "\n", addr); |
125 | b00052e4 | balrog | } |
126 | b00052e4 | balrog | } |
127 | b00052e4 | balrog | |
128 | aa941b94 | balrog | static void sl_save(QEMUFile *f, void *opaque) |
129 | aa941b94 | balrog | { |
130 | aa941b94 | balrog | struct sl_nand_s *s = (struct sl_nand_s *) opaque; |
131 | aa941b94 | balrog | |
132 | aa941b94 | balrog | qemu_put_8s(f, &s->ctl); |
133 | aa941b94 | balrog | ecc_put(f, &s->ecc); |
134 | aa941b94 | balrog | } |
135 | aa941b94 | balrog | |
136 | aa941b94 | balrog | static int sl_load(QEMUFile *f, void *opaque, int version_id) |
137 | aa941b94 | balrog | { |
138 | aa941b94 | balrog | struct sl_nand_s *s = (struct sl_nand_s *) opaque; |
139 | aa941b94 | balrog | |
140 | aa941b94 | balrog | qemu_get_8s(f, &s->ctl); |
141 | aa941b94 | balrog | ecc_get(f, &s->ecc); |
142 | aa941b94 | balrog | |
143 | aa941b94 | balrog | return 0; |
144 | aa941b94 | balrog | } |
145 | aa941b94 | balrog | |
146 | b00052e4 | balrog | enum {
|
147 | b00052e4 | balrog | FLASH_128M, |
148 | b00052e4 | balrog | FLASH_1024M, |
149 | b00052e4 | balrog | }; |
150 | b00052e4 | balrog | |
151 | b00052e4 | balrog | static void sl_flash_register(struct pxa2xx_state_s *cpu, int size) |
152 | b00052e4 | balrog | { |
153 | b00052e4 | balrog | int iomemtype;
|
154 | b00052e4 | balrog | struct sl_nand_s *s;
|
155 | b00052e4 | balrog | CPUReadMemoryFunc *sl_readfn[] = { |
156 | b00052e4 | balrog | sl_readb, |
157 | b00052e4 | balrog | sl_readb, |
158 | a5236105 | balrog | sl_readl, |
159 | b00052e4 | balrog | }; |
160 | b00052e4 | balrog | CPUWriteMemoryFunc *sl_writefn[] = { |
161 | b00052e4 | balrog | sl_writeb, |
162 | b00052e4 | balrog | sl_writeb, |
163 | b00052e4 | balrog | sl_writeb, |
164 | b00052e4 | balrog | }; |
165 | b00052e4 | balrog | |
166 | b00052e4 | balrog | s = (struct sl_nand_s *) qemu_mallocz(sizeof(struct sl_nand_s)); |
167 | b00052e4 | balrog | s->target_base = FLASH_BASE; |
168 | b00052e4 | balrog | s->ctl = 0;
|
169 | b00052e4 | balrog | if (size == FLASH_128M)
|
170 | b00052e4 | balrog | s->nand = nand_init(NAND_MFR_SAMSUNG, 0x73);
|
171 | b00052e4 | balrog | else if (size == FLASH_1024M) |
172 | b00052e4 | balrog | s->nand = nand_init(NAND_MFR_SAMSUNG, 0xf1);
|
173 | b00052e4 | balrog | |
174 | b00052e4 | balrog | iomemtype = cpu_register_io_memory(0, sl_readfn,
|
175 | b00052e4 | balrog | sl_writefn, s); |
176 | b00052e4 | balrog | cpu_register_physical_memory(s->target_base, 0x40, iomemtype);
|
177 | aa941b94 | balrog | |
178 | aa941b94 | balrog | register_savevm("sl_flash", 0, 0, sl_save, sl_load, s); |
179 | b00052e4 | balrog | } |
180 | b00052e4 | balrog | |
181 | b00052e4 | balrog | /* Spitz Keyboard */
|
182 | b00052e4 | balrog | |
183 | b00052e4 | balrog | #define SPITZ_KEY_STROBE_NUM 11 |
184 | b00052e4 | balrog | #define SPITZ_KEY_SENSE_NUM 7 |
185 | b00052e4 | balrog | |
186 | b00052e4 | balrog | static const int spitz_gpio_key_sense[SPITZ_KEY_SENSE_NUM] = { |
187 | b00052e4 | balrog | 12, 17, 91, 34, 36, 38, 39 |
188 | b00052e4 | balrog | }; |
189 | b00052e4 | balrog | |
190 | b00052e4 | balrog | static const int spitz_gpio_key_strobe[SPITZ_KEY_STROBE_NUM] = { |
191 | b00052e4 | balrog | 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114 |
192 | b00052e4 | balrog | }; |
193 | b00052e4 | balrog | |
194 | b00052e4 | balrog | /* Eighth additional row maps the special keys */
|
195 | b00052e4 | balrog | static int spitz_keymap[SPITZ_KEY_SENSE_NUM + 1][SPITZ_KEY_STROBE_NUM] = { |
196 | b00052e4 | balrog | { 0x1d, 0x02, 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0e, 0x3f, 0x40 }, |
197 | b00052e4 | balrog | { -1 , 0x03, 0x05, 0x13, 0x15, 0x09, 0x17, 0x18, 0x19, 0x41, 0x42 }, |
198 | b00052e4 | balrog | { 0x0f, 0x10, 0x12, 0x14, 0x22, 0x16, 0x24, 0x25, -1 , -1 , -1 }, |
199 | b00052e4 | balrog | { 0x3c, 0x11, 0x1f, 0x21, 0x2f, 0x23, 0x32, 0x26, -1 , 0x36, -1 }, |
200 | b00052e4 | balrog | { 0x3b, 0x1e, 0x20, 0x2e, 0x30, 0x31, 0x34, -1 , 0x1c, 0x2a, -1 }, |
201 | 2b76bdc9 | balrog | { 0x44, 0x2c, 0x2d, 0x0c, 0x39, 0x33, -1 , 0x48, -1 , -1 , 0x38 }, |
202 | 2b76bdc9 | balrog | { 0x37, 0x3d, -1 , 0x45, 0x57, 0x58, 0x4b, 0x50, 0x4d, -1 , -1 }, |
203 | b00052e4 | balrog | { 0x52, 0x43, 0x01, 0x47, 0x49, -1 , -1 , -1 , -1 , -1 , -1 }, |
204 | b00052e4 | balrog | }; |
205 | b00052e4 | balrog | |
206 | b00052e4 | balrog | #define SPITZ_GPIO_AK_INT 13 /* Remote control */ |
207 | b00052e4 | balrog | #define SPITZ_GPIO_SYNC 16 /* Sync button */ |
208 | b00052e4 | balrog | #define SPITZ_GPIO_ON_KEY 95 /* Power button */ |
209 | b00052e4 | balrog | #define SPITZ_GPIO_SWA 97 /* Lid */ |
210 | b00052e4 | balrog | #define SPITZ_GPIO_SWB 96 /* Tablet mode */ |
211 | b00052e4 | balrog | |
212 | b00052e4 | balrog | /* The special buttons are mapped to unused keys */
|
213 | b00052e4 | balrog | static const int spitz_gpiomap[5] = { |
214 | b00052e4 | balrog | SPITZ_GPIO_AK_INT, SPITZ_GPIO_SYNC, SPITZ_GPIO_ON_KEY, |
215 | b00052e4 | balrog | SPITZ_GPIO_SWA, SPITZ_GPIO_SWB, |
216 | b00052e4 | balrog | }; |
217 | b00052e4 | balrog | static int spitz_gpio_invert[5] = { 0, 0, 0, 0, 0, }; |
218 | b00052e4 | balrog | |
219 | b00052e4 | balrog | struct spitz_keyboard_s {
|
220 | b00052e4 | balrog | struct pxa2xx_state_s *cpu;
|
221 | b00052e4 | balrog | int keymap[0x80]; |
222 | b00052e4 | balrog | uint16_t keyrow[SPITZ_KEY_SENSE_NUM]; |
223 | b00052e4 | balrog | uint16_t strobe_state; |
224 | b00052e4 | balrog | uint16_t sense_state; |
225 | b00052e4 | balrog | |
226 | b00052e4 | balrog | uint16_t pre_map[0x100];
|
227 | b00052e4 | balrog | uint16_t modifiers; |
228 | b00052e4 | balrog | uint16_t imodifiers; |
229 | b00052e4 | balrog | uint8_t fifo[16];
|
230 | b00052e4 | balrog | int fifopos, fifolen;
|
231 | b00052e4 | balrog | QEMUTimer *kbdtimer; |
232 | b00052e4 | balrog | }; |
233 | b00052e4 | balrog | |
234 | b00052e4 | balrog | static void spitz_keyboard_sense_update(struct spitz_keyboard_s *s) |
235 | b00052e4 | balrog | { |
236 | b00052e4 | balrog | int i;
|
237 | b00052e4 | balrog | uint16_t strobe, sense = 0;
|
238 | b00052e4 | balrog | for (i = 0; i < SPITZ_KEY_SENSE_NUM; i ++) { |
239 | b00052e4 | balrog | strobe = s->keyrow[i] & s->strobe_state; |
240 | b00052e4 | balrog | if (strobe) {
|
241 | b00052e4 | balrog | sense |= 1 << i;
|
242 | b00052e4 | balrog | if (!(s->sense_state & (1 << i))) |
243 | b00052e4 | balrog | pxa2xx_gpio_set(s->cpu->gpio, spitz_gpio_key_sense[i], 1);
|
244 | b00052e4 | balrog | } else if (s->sense_state & (1 << i)) |
245 | b00052e4 | balrog | pxa2xx_gpio_set(s->cpu->gpio, spitz_gpio_key_sense[i], 0);
|
246 | b00052e4 | balrog | } |
247 | b00052e4 | balrog | |
248 | b00052e4 | balrog | s->sense_state = sense; |
249 | b00052e4 | balrog | } |
250 | b00052e4 | balrog | |
251 | b00052e4 | balrog | static void spitz_keyboard_strobe(int line, int level, |
252 | b00052e4 | balrog | struct spitz_keyboard_s *s)
|
253 | b00052e4 | balrog | { |
254 | b00052e4 | balrog | int i;
|
255 | b00052e4 | balrog | for (i = 0; i < SPITZ_KEY_STROBE_NUM; i ++) |
256 | b00052e4 | balrog | if (spitz_gpio_key_strobe[i] == line) {
|
257 | b00052e4 | balrog | if (level)
|
258 | b00052e4 | balrog | s->strobe_state |= 1 << i;
|
259 | b00052e4 | balrog | else
|
260 | b00052e4 | balrog | s->strobe_state &= ~(1 << i);
|
261 | b00052e4 | balrog | |
262 | b00052e4 | balrog | spitz_keyboard_sense_update(s); |
263 | b00052e4 | balrog | break;
|
264 | b00052e4 | balrog | } |
265 | b00052e4 | balrog | } |
266 | b00052e4 | balrog | |
267 | b00052e4 | balrog | static void spitz_keyboard_keydown(struct spitz_keyboard_s *s, int keycode) |
268 | b00052e4 | balrog | { |
269 | b00052e4 | balrog | int spitz_keycode = s->keymap[keycode & 0x7f]; |
270 | b00052e4 | balrog | if (spitz_keycode == -1) |
271 | b00052e4 | balrog | return;
|
272 | b00052e4 | balrog | |
273 | b00052e4 | balrog | /* Handle the additional keys */
|
274 | b00052e4 | balrog | if ((spitz_keycode >> 4) == SPITZ_KEY_SENSE_NUM) { |
275 | b00052e4 | balrog | pxa2xx_gpio_set(s->cpu->gpio, spitz_gpiomap[spitz_keycode & 0xf],
|
276 | b00052e4 | balrog | (keycode < 0x80) ^
|
277 | b00052e4 | balrog | spitz_gpio_invert[spitz_keycode & 0xf]);
|
278 | b00052e4 | balrog | return;
|
279 | b00052e4 | balrog | } |
280 | b00052e4 | balrog | |
281 | b00052e4 | balrog | if (keycode & 0x80) |
282 | b00052e4 | balrog | s->keyrow[spitz_keycode >> 4] &= ~(1 << (spitz_keycode & 0xf)); |
283 | b00052e4 | balrog | else
|
284 | b00052e4 | balrog | s->keyrow[spitz_keycode >> 4] |= 1 << (spitz_keycode & 0xf); |
285 | b00052e4 | balrog | |
286 | b00052e4 | balrog | spitz_keyboard_sense_update(s); |
287 | b00052e4 | balrog | } |
288 | b00052e4 | balrog | |
289 | b00052e4 | balrog | #define SHIFT (1 << 7) |
290 | b00052e4 | balrog | #define CTRL (1 << 8) |
291 | b00052e4 | balrog | #define FN (1 << 9) |
292 | b00052e4 | balrog | |
293 | b00052e4 | balrog | #define QUEUE_KEY(c) s->fifo[(s->fifopos + s->fifolen ++) & 0xf] = c |
294 | b00052e4 | balrog | |
295 | b00052e4 | balrog | static void spitz_keyboard_handler(struct spitz_keyboard_s *s, int keycode) |
296 | b00052e4 | balrog | { |
297 | b00052e4 | balrog | uint16_t code; |
298 | b00052e4 | balrog | int mapcode;
|
299 | b00052e4 | balrog | switch (keycode) {
|
300 | b00052e4 | balrog | case 0x2a: /* Left Shift */ |
301 | b00052e4 | balrog | s->modifiers |= 1;
|
302 | b00052e4 | balrog | break;
|
303 | b00052e4 | balrog | case 0xaa: |
304 | b00052e4 | balrog | s->modifiers &= ~1;
|
305 | b00052e4 | balrog | break;
|
306 | b00052e4 | balrog | case 0x36: /* Right Shift */ |
307 | b00052e4 | balrog | s->modifiers |= 2;
|
308 | b00052e4 | balrog | break;
|
309 | b00052e4 | balrog | case 0xb6: |
310 | b00052e4 | balrog | s->modifiers &= ~2;
|
311 | b00052e4 | balrog | break;
|
312 | b00052e4 | balrog | case 0x1d: /* Control */ |
313 | b00052e4 | balrog | s->modifiers |= 4;
|
314 | b00052e4 | balrog | break;
|
315 | b00052e4 | balrog | case 0x9d: |
316 | b00052e4 | balrog | s->modifiers &= ~4;
|
317 | b00052e4 | balrog | break;
|
318 | b00052e4 | balrog | case 0x38: /* Alt */ |
319 | b00052e4 | balrog | s->modifiers |= 8;
|
320 | b00052e4 | balrog | break;
|
321 | b00052e4 | balrog | case 0xb8: |
322 | b00052e4 | balrog | s->modifiers &= ~8;
|
323 | b00052e4 | balrog | break;
|
324 | b00052e4 | balrog | } |
325 | b00052e4 | balrog | |
326 | b00052e4 | balrog | code = s->pre_map[mapcode = ((s->modifiers & 3) ?
|
327 | b00052e4 | balrog | (keycode | SHIFT) : |
328 | b00052e4 | balrog | (keycode & ~SHIFT))]; |
329 | b00052e4 | balrog | |
330 | b00052e4 | balrog | if (code != mapcode) {
|
331 | b00052e4 | balrog | #if 0
|
332 | b00052e4 | balrog | if ((code & SHIFT) && !(s->modifiers & 1))
|
333 | b00052e4 | balrog | QUEUE_KEY(0x2a | (keycode & 0x80));
|
334 | b00052e4 | balrog | if ((code & CTRL ) && !(s->modifiers & 4))
|
335 | b00052e4 | balrog | QUEUE_KEY(0x1d | (keycode & 0x80));
|
336 | b00052e4 | balrog | if ((code & FN ) && !(s->modifiers & 8))
|
337 | b00052e4 | balrog | QUEUE_KEY(0x38 | (keycode & 0x80));
|
338 | b00052e4 | balrog | if ((code & FN ) && (s->modifiers & 1))
|
339 | b00052e4 | balrog | QUEUE_KEY(0x2a | (~keycode & 0x80));
|
340 | b00052e4 | balrog | if ((code & FN ) && (s->modifiers & 2))
|
341 | b00052e4 | balrog | QUEUE_KEY(0x36 | (~keycode & 0x80));
|
342 | b00052e4 | balrog | #else
|
343 | b00052e4 | balrog | if (keycode & 0x80) { |
344 | b00052e4 | balrog | if ((s->imodifiers & 1 ) && !(s->modifiers & 1)) |
345 | b00052e4 | balrog | QUEUE_KEY(0x2a | 0x80); |
346 | b00052e4 | balrog | if ((s->imodifiers & 4 ) && !(s->modifiers & 4)) |
347 | b00052e4 | balrog | QUEUE_KEY(0x1d | 0x80); |
348 | b00052e4 | balrog | if ((s->imodifiers & 8 ) && !(s->modifiers & 8)) |
349 | b00052e4 | balrog | QUEUE_KEY(0x38 | 0x80); |
350 | b00052e4 | balrog | if ((s->imodifiers & 0x10) && (s->modifiers & 1)) |
351 | b00052e4 | balrog | QUEUE_KEY(0x2a);
|
352 | b00052e4 | balrog | if ((s->imodifiers & 0x20) && (s->modifiers & 2)) |
353 | b00052e4 | balrog | QUEUE_KEY(0x36);
|
354 | b00052e4 | balrog | s->imodifiers = 0;
|
355 | b00052e4 | balrog | } else {
|
356 | b00052e4 | balrog | if ((code & SHIFT) && !((s->modifiers | s->imodifiers) & 1)) { |
357 | b00052e4 | balrog | QUEUE_KEY(0x2a);
|
358 | b00052e4 | balrog | s->imodifiers |= 1;
|
359 | b00052e4 | balrog | } |
360 | b00052e4 | balrog | if ((code & CTRL ) && !((s->modifiers | s->imodifiers) & 4)) { |
361 | b00052e4 | balrog | QUEUE_KEY(0x1d);
|
362 | b00052e4 | balrog | s->imodifiers |= 4;
|
363 | b00052e4 | balrog | } |
364 | b00052e4 | balrog | if ((code & FN ) && !((s->modifiers | s->imodifiers) & 8)) { |
365 | b00052e4 | balrog | QUEUE_KEY(0x38);
|
366 | b00052e4 | balrog | s->imodifiers |= 8;
|
367 | b00052e4 | balrog | } |
368 | b00052e4 | balrog | if ((code & FN ) && (s->modifiers & 1) && |
369 | b00052e4 | balrog | !(s->imodifiers & 0x10)) {
|
370 | b00052e4 | balrog | QUEUE_KEY(0x2a | 0x80); |
371 | b00052e4 | balrog | s->imodifiers |= 0x10;
|
372 | b00052e4 | balrog | } |
373 | b00052e4 | balrog | if ((code & FN ) && (s->modifiers & 2) && |
374 | b00052e4 | balrog | !(s->imodifiers & 0x20)) {
|
375 | b00052e4 | balrog | QUEUE_KEY(0x36 | 0x80); |
376 | b00052e4 | balrog | s->imodifiers |= 0x20;
|
377 | b00052e4 | balrog | } |
378 | b00052e4 | balrog | } |
379 | b00052e4 | balrog | #endif
|
380 | b00052e4 | balrog | } |
381 | b00052e4 | balrog | |
382 | b00052e4 | balrog | QUEUE_KEY((code & 0x7f) | (keycode & 0x80)); |
383 | b00052e4 | balrog | } |
384 | b00052e4 | balrog | |
385 | b00052e4 | balrog | static void spitz_keyboard_tick(void *opaque) |
386 | b00052e4 | balrog | { |
387 | b00052e4 | balrog | struct spitz_keyboard_s *s = (struct spitz_keyboard_s *) opaque; |
388 | b00052e4 | balrog | |
389 | b00052e4 | balrog | if (s->fifolen) {
|
390 | b00052e4 | balrog | spitz_keyboard_keydown(s, s->fifo[s->fifopos ++]); |
391 | b00052e4 | balrog | s->fifolen --; |
392 | b00052e4 | balrog | if (s->fifopos >= 16) |
393 | b00052e4 | balrog | s->fifopos = 0;
|
394 | b00052e4 | balrog | } |
395 | b00052e4 | balrog | |
396 | b00052e4 | balrog | qemu_mod_timer(s->kbdtimer, qemu_get_clock(vm_clock) + ticks_per_sec / 32);
|
397 | b00052e4 | balrog | } |
398 | b00052e4 | balrog | |
399 | b00052e4 | balrog | static void spitz_keyboard_pre_map(struct spitz_keyboard_s *s) |
400 | b00052e4 | balrog | { |
401 | b00052e4 | balrog | int i;
|
402 | b00052e4 | balrog | for (i = 0; i < 0x100; i ++) |
403 | b00052e4 | balrog | s->pre_map[i] = i; |
404 | b00052e4 | balrog | s->pre_map[0x02 | SHIFT ] = 0x02 | SHIFT; /* exclam */ |
405 | b00052e4 | balrog | s->pre_map[0x28 | SHIFT ] = 0x03 | SHIFT; /* quotedbl */ |
406 | b00052e4 | balrog | s->pre_map[0x04 | SHIFT ] = 0x04 | SHIFT; /* numbersign */ |
407 | b00052e4 | balrog | s->pre_map[0x05 | SHIFT ] = 0x05 | SHIFT; /* dollar */ |
408 | b00052e4 | balrog | s->pre_map[0x06 | SHIFT ] = 0x06 | SHIFT; /* percent */ |
409 | b00052e4 | balrog | s->pre_map[0x08 | SHIFT ] = 0x07 | SHIFT; /* ampersand */ |
410 | b00052e4 | balrog | s->pre_map[0x28 ] = 0x08 | SHIFT; /* apostrophe */ |
411 | b00052e4 | balrog | s->pre_map[0x0a | SHIFT ] = 0x09 | SHIFT; /* parenleft */ |
412 | b00052e4 | balrog | s->pre_map[0x0b | SHIFT ] = 0x0a | SHIFT; /* parenright */ |
413 | b00052e4 | balrog | s->pre_map[0x29 | SHIFT ] = 0x0b | SHIFT; /* asciitilde */ |
414 | b00052e4 | balrog | s->pre_map[0x03 | SHIFT ] = 0x0c | SHIFT; /* at */ |
415 | b00052e4 | balrog | s->pre_map[0xd3 ] = 0x0e | FN; /* Delete */ |
416 | b00052e4 | balrog | s->pre_map[0x3a ] = 0x0f | FN; /* Caps_Lock */ |
417 | b00052e4 | balrog | s->pre_map[0x07 | SHIFT ] = 0x11 | FN; /* asciicircum */ |
418 | b00052e4 | balrog | s->pre_map[0x0d ] = 0x12 | FN; /* equal */ |
419 | b00052e4 | balrog | s->pre_map[0x0d | SHIFT ] = 0x13 | FN; /* plus */ |
420 | b00052e4 | balrog | s->pre_map[0x1a ] = 0x14 | FN; /* bracketleft */ |
421 | b00052e4 | balrog | s->pre_map[0x1b ] = 0x15 | FN; /* bracketright */ |
422 | 2b76bdc9 | balrog | s->pre_map[0x1a | SHIFT ] = 0x16 | FN; /* braceleft */ |
423 | 2b76bdc9 | balrog | s->pre_map[0x1b | SHIFT ] = 0x17 | FN; /* braceright */ |
424 | b00052e4 | balrog | s->pre_map[0x27 ] = 0x22 | FN; /* semicolon */ |
425 | b00052e4 | balrog | s->pre_map[0x27 | SHIFT ] = 0x23 | FN; /* colon */ |
426 | b00052e4 | balrog | s->pre_map[0x09 | SHIFT ] = 0x24 | FN; /* asterisk */ |
427 | b00052e4 | balrog | s->pre_map[0x2b ] = 0x25 | FN; /* backslash */ |
428 | b00052e4 | balrog | s->pre_map[0x2b | SHIFT ] = 0x26 | FN; /* bar */ |
429 | b00052e4 | balrog | s->pre_map[0x0c | SHIFT ] = 0x30 | FN; /* underscore */ |
430 | 2b76bdc9 | balrog | s->pre_map[0x33 | SHIFT ] = 0x33 | FN; /* less */ |
431 | b00052e4 | balrog | s->pre_map[0x35 ] = 0x33 | SHIFT; /* slash */ |
432 | 2b76bdc9 | balrog | s->pre_map[0x34 | SHIFT ] = 0x34 | FN; /* greater */ |
433 | b00052e4 | balrog | s->pre_map[0x35 | SHIFT ] = 0x34 | SHIFT; /* question */ |
434 | b00052e4 | balrog | s->pre_map[0x49 ] = 0x48 | FN; /* Page_Up */ |
435 | b00052e4 | balrog | s->pre_map[0x51 ] = 0x50 | FN; /* Page_Down */ |
436 | b00052e4 | balrog | |
437 | b00052e4 | balrog | s->modifiers = 0;
|
438 | b00052e4 | balrog | s->imodifiers = 0;
|
439 | b00052e4 | balrog | s->fifopos = 0;
|
440 | b00052e4 | balrog | s->fifolen = 0;
|
441 | b00052e4 | balrog | s->kbdtimer = qemu_new_timer(vm_clock, spitz_keyboard_tick, s); |
442 | b00052e4 | balrog | spitz_keyboard_tick(s); |
443 | b00052e4 | balrog | } |
444 | b00052e4 | balrog | |
445 | b00052e4 | balrog | #undef SHIFT
|
446 | b00052e4 | balrog | #undef CTRL
|
447 | b00052e4 | balrog | #undef FN
|
448 | b00052e4 | balrog | |
449 | aa941b94 | balrog | static void spitz_keyboard_save(QEMUFile *f, void *opaque) |
450 | aa941b94 | balrog | { |
451 | aa941b94 | balrog | struct spitz_keyboard_s *s = (struct spitz_keyboard_s *) opaque; |
452 | aa941b94 | balrog | int i;
|
453 | aa941b94 | balrog | |
454 | aa941b94 | balrog | qemu_put_be16s(f, &s->sense_state); |
455 | aa941b94 | balrog | qemu_put_be16s(f, &s->strobe_state); |
456 | aa941b94 | balrog | for (i = 0; i < 5; i ++) |
457 | aa941b94 | balrog | qemu_put_byte(f, spitz_gpio_invert[i]); |
458 | aa941b94 | balrog | } |
459 | aa941b94 | balrog | |
460 | aa941b94 | balrog | static int spitz_keyboard_load(QEMUFile *f, void *opaque, int version_id) |
461 | aa941b94 | balrog | { |
462 | aa941b94 | balrog | struct spitz_keyboard_s *s = (struct spitz_keyboard_s *) opaque; |
463 | aa941b94 | balrog | int i;
|
464 | aa941b94 | balrog | |
465 | aa941b94 | balrog | qemu_get_be16s(f, &s->sense_state); |
466 | aa941b94 | balrog | qemu_get_be16s(f, &s->strobe_state); |
467 | aa941b94 | balrog | for (i = 0; i < 5; i ++) |
468 | aa941b94 | balrog | spitz_gpio_invert[i] = qemu_get_byte(f); |
469 | aa941b94 | balrog | |
470 | aa941b94 | balrog | /* Release all pressed keys */
|
471 | aa941b94 | balrog | memset(s->keyrow, 0, sizeof(s->keyrow)); |
472 | aa941b94 | balrog | spitz_keyboard_sense_update(s); |
473 | aa941b94 | balrog | s->modifiers = 0;
|
474 | aa941b94 | balrog | s->imodifiers = 0;
|
475 | aa941b94 | balrog | s->fifopos = 0;
|
476 | aa941b94 | balrog | s->fifolen = 0;
|
477 | aa941b94 | balrog | |
478 | aa941b94 | balrog | return 0; |
479 | aa941b94 | balrog | } |
480 | aa941b94 | balrog | |
481 | b00052e4 | balrog | static void spitz_keyboard_register(struct pxa2xx_state_s *cpu) |
482 | b00052e4 | balrog | { |
483 | b00052e4 | balrog | int i, j;
|
484 | b00052e4 | balrog | struct spitz_keyboard_s *s;
|
485 | b00052e4 | balrog | |
486 | b00052e4 | balrog | s = (struct spitz_keyboard_s *)
|
487 | b00052e4 | balrog | qemu_mallocz(sizeof(struct spitz_keyboard_s)); |
488 | b00052e4 | balrog | memset(s, 0, sizeof(struct spitz_keyboard_s)); |
489 | b00052e4 | balrog | s->cpu = cpu; |
490 | b00052e4 | balrog | |
491 | b00052e4 | balrog | for (i = 0; i < 0x80; i ++) |
492 | b00052e4 | balrog | s->keymap[i] = -1;
|
493 | b00052e4 | balrog | for (i = 0; i < SPITZ_KEY_SENSE_NUM + 1; i ++) |
494 | b00052e4 | balrog | for (j = 0; j < SPITZ_KEY_STROBE_NUM; j ++) |
495 | b00052e4 | balrog | if (spitz_keymap[i][j] != -1) |
496 | b00052e4 | balrog | s->keymap[spitz_keymap[i][j]] = (i << 4) | j;
|
497 | b00052e4 | balrog | |
498 | b00052e4 | balrog | for (i = 0; i < SPITZ_KEY_STROBE_NUM; i ++) |
499 | b00052e4 | balrog | pxa2xx_gpio_handler_set(cpu->gpio, spitz_gpio_key_strobe[i], |
500 | b00052e4 | balrog | (gpio_handler_t) spitz_keyboard_strobe, s); |
501 | b00052e4 | balrog | |
502 | b00052e4 | balrog | spitz_keyboard_pre_map(s); |
503 | b00052e4 | balrog | qemu_add_kbd_event_handler((QEMUPutKBDEvent *) spitz_keyboard_handler, s); |
504 | aa941b94 | balrog | |
505 | aa941b94 | balrog | register_savevm("spitz_keyboard", 0, 0, |
506 | aa941b94 | balrog | spitz_keyboard_save, spitz_keyboard_load, s); |
507 | b00052e4 | balrog | } |
508 | b00052e4 | balrog | |
509 | b00052e4 | balrog | /* SCOOP devices */
|
510 | b00052e4 | balrog | |
511 | b00052e4 | balrog | struct scoop_info_s {
|
512 | b00052e4 | balrog | target_phys_addr_t target_base; |
513 | b00052e4 | balrog | uint16_t status; |
514 | b00052e4 | balrog | uint16_t power; |
515 | b00052e4 | balrog | uint32_t gpio_level; |
516 | b00052e4 | balrog | uint32_t gpio_dir; |
517 | b00052e4 | balrog | uint32_t prev_level; |
518 | b00052e4 | balrog | struct {
|
519 | b00052e4 | balrog | gpio_handler_t fn; |
520 | b00052e4 | balrog | void *opaque;
|
521 | b00052e4 | balrog | } handler[16];
|
522 | b00052e4 | balrog | |
523 | b00052e4 | balrog | uint16_t mcr; |
524 | b00052e4 | balrog | uint16_t cdr; |
525 | b00052e4 | balrog | uint16_t ccr; |
526 | b00052e4 | balrog | uint16_t irr; |
527 | b00052e4 | balrog | uint16_t imr; |
528 | b00052e4 | balrog | uint16_t isr; |
529 | b00052e4 | balrog | uint16_t gprr; |
530 | b00052e4 | balrog | }; |
531 | b00052e4 | balrog | |
532 | b00052e4 | balrog | #define SCOOP_MCR 0x00 |
533 | b00052e4 | balrog | #define SCOOP_CDR 0x04 |
534 | b00052e4 | balrog | #define SCOOP_CSR 0x08 |
535 | b00052e4 | balrog | #define SCOOP_CPR 0x0c |
536 | b00052e4 | balrog | #define SCOOP_CCR 0x10 |
537 | b00052e4 | balrog | #define SCOOP_IRR_IRM 0x14 |
538 | b00052e4 | balrog | #define SCOOP_IMR 0x18 |
539 | b00052e4 | balrog | #define SCOOP_ISR 0x1c |
540 | b00052e4 | balrog | #define SCOOP_GPCR 0x20 |
541 | b00052e4 | balrog | #define SCOOP_GPWR 0x24 |
542 | b00052e4 | balrog | #define SCOOP_GPRR 0x28 |
543 | b00052e4 | balrog | |
544 | b00052e4 | balrog | static inline void scoop_gpio_handler_update(struct scoop_info_s *s) { |
545 | b00052e4 | balrog | uint32_t level, diff; |
546 | b00052e4 | balrog | int bit;
|
547 | b00052e4 | balrog | level = s->gpio_level & s->gpio_dir; |
548 | b00052e4 | balrog | |
549 | b00052e4 | balrog | for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) { |
550 | b00052e4 | balrog | bit = ffs(diff) - 1;
|
551 | b00052e4 | balrog | if (s->handler[bit].fn)
|
552 | b00052e4 | balrog | s->handler[bit].fn(bit, (level >> bit) & 1,
|
553 | b00052e4 | balrog | s->handler[bit].opaque); |
554 | b00052e4 | balrog | } |
555 | b00052e4 | balrog | |
556 | b00052e4 | balrog | s->prev_level = level; |
557 | b00052e4 | balrog | } |
558 | b00052e4 | balrog | |
559 | b00052e4 | balrog | static uint32_t scoop_readb(void *opaque, target_phys_addr_t addr) |
560 | b00052e4 | balrog | { |
561 | b00052e4 | balrog | struct scoop_info_s *s = (struct scoop_info_s *) opaque; |
562 | b00052e4 | balrog | addr -= s->target_base; |
563 | b00052e4 | balrog | |
564 | b00052e4 | balrog | switch (addr) {
|
565 | b00052e4 | balrog | case SCOOP_MCR:
|
566 | b00052e4 | balrog | return s->mcr;
|
567 | b00052e4 | balrog | case SCOOP_CDR:
|
568 | b00052e4 | balrog | return s->cdr;
|
569 | b00052e4 | balrog | case SCOOP_CSR:
|
570 | b00052e4 | balrog | return s->status;
|
571 | b00052e4 | balrog | case SCOOP_CPR:
|
572 | b00052e4 | balrog | return s->power;
|
573 | b00052e4 | balrog | case SCOOP_CCR:
|
574 | b00052e4 | balrog | return s->ccr;
|
575 | b00052e4 | balrog | case SCOOP_IRR_IRM:
|
576 | b00052e4 | balrog | return s->irr;
|
577 | b00052e4 | balrog | case SCOOP_IMR:
|
578 | b00052e4 | balrog | return s->imr;
|
579 | b00052e4 | balrog | case SCOOP_ISR:
|
580 | b00052e4 | balrog | return s->isr;
|
581 | b00052e4 | balrog | case SCOOP_GPCR:
|
582 | b00052e4 | balrog | return s->gpio_dir;
|
583 | b00052e4 | balrog | case SCOOP_GPWR:
|
584 | b00052e4 | balrog | return s->gpio_level;
|
585 | b00052e4 | balrog | case SCOOP_GPRR:
|
586 | b00052e4 | balrog | return s->gprr;
|
587 | b00052e4 | balrog | default:
|
588 | b00052e4 | balrog | spitz_printf("Bad register offset " REG_FMT "\n", addr); |
589 | b00052e4 | balrog | } |
590 | b00052e4 | balrog | |
591 | b00052e4 | balrog | return 0; |
592 | b00052e4 | balrog | } |
593 | b00052e4 | balrog | |
594 | b00052e4 | balrog | static void scoop_writeb(void *opaque, target_phys_addr_t addr, uint32_t value) |
595 | b00052e4 | balrog | { |
596 | b00052e4 | balrog | struct scoop_info_s *s = (struct scoop_info_s *) opaque; |
597 | b00052e4 | balrog | addr -= s->target_base; |
598 | b00052e4 | balrog | value &= 0xffff;
|
599 | b00052e4 | balrog | |
600 | b00052e4 | balrog | switch (addr) {
|
601 | b00052e4 | balrog | case SCOOP_MCR:
|
602 | b00052e4 | balrog | s->mcr = value; |
603 | b00052e4 | balrog | break;
|
604 | b00052e4 | balrog | case SCOOP_CDR:
|
605 | b00052e4 | balrog | s->cdr = value; |
606 | b00052e4 | balrog | break;
|
607 | b00052e4 | balrog | case SCOOP_CPR:
|
608 | b00052e4 | balrog | s->power = value; |
609 | b00052e4 | balrog | if (value & 0x80) |
610 | b00052e4 | balrog | s->power |= 0x8040;
|
611 | b00052e4 | balrog | break;
|
612 | b00052e4 | balrog | case SCOOP_CCR:
|
613 | b00052e4 | balrog | s->ccr = value; |
614 | b00052e4 | balrog | break;
|
615 | b00052e4 | balrog | case SCOOP_IRR_IRM:
|
616 | b00052e4 | balrog | s->irr = value; |
617 | b00052e4 | balrog | break;
|
618 | b00052e4 | balrog | case SCOOP_IMR:
|
619 | b00052e4 | balrog | s->imr = value; |
620 | b00052e4 | balrog | break;
|
621 | b00052e4 | balrog | case SCOOP_ISR:
|
622 | b00052e4 | balrog | s->isr = value; |
623 | b00052e4 | balrog | break;
|
624 | b00052e4 | balrog | case SCOOP_GPCR:
|
625 | b00052e4 | balrog | s->gpio_dir = value; |
626 | b00052e4 | balrog | scoop_gpio_handler_update(s); |
627 | b00052e4 | balrog | break;
|
628 | b00052e4 | balrog | case SCOOP_GPWR:
|
629 | b00052e4 | balrog | s->gpio_level = value & s->gpio_dir; |
630 | b00052e4 | balrog | scoop_gpio_handler_update(s); |
631 | b00052e4 | balrog | break;
|
632 | b00052e4 | balrog | case SCOOP_GPRR:
|
633 | b00052e4 | balrog | s->gprr = value; |
634 | b00052e4 | balrog | break;
|
635 | b00052e4 | balrog | default:
|
636 | b00052e4 | balrog | spitz_printf("Bad register offset " REG_FMT "\n", addr); |
637 | b00052e4 | balrog | } |
638 | b00052e4 | balrog | } |
639 | b00052e4 | balrog | |
640 | b00052e4 | balrog | CPUReadMemoryFunc *scoop_readfn[] = { |
641 | b00052e4 | balrog | scoop_readb, |
642 | b00052e4 | balrog | scoop_readb, |
643 | b00052e4 | balrog | scoop_readb, |
644 | b00052e4 | balrog | }; |
645 | b00052e4 | balrog | CPUWriteMemoryFunc *scoop_writefn[] = { |
646 | b00052e4 | balrog | scoop_writeb, |
647 | b00052e4 | balrog | scoop_writeb, |
648 | b00052e4 | balrog | scoop_writeb, |
649 | b00052e4 | balrog | }; |
650 | b00052e4 | balrog | |
651 | b00052e4 | balrog | static inline void scoop_gpio_set(struct scoop_info_s *s, int line, int level) |
652 | b00052e4 | balrog | { |
653 | b00052e4 | balrog | if (line >= 16) { |
654 | b00052e4 | balrog | spitz_printf("No GPIO pin %i\n", line);
|
655 | b00052e4 | balrog | return;
|
656 | b00052e4 | balrog | } |
657 | b00052e4 | balrog | |
658 | b00052e4 | balrog | if (level)
|
659 | b00052e4 | balrog | s->gpio_level |= (1 << line);
|
660 | b00052e4 | balrog | else
|
661 | b00052e4 | balrog | s->gpio_level &= ~(1 << line);
|
662 | b00052e4 | balrog | } |
663 | b00052e4 | balrog | |
664 | b00052e4 | balrog | static inline void scoop_gpio_handler_set(struct scoop_info_s *s, int line, |
665 | b00052e4 | balrog | gpio_handler_t handler, void *opaque) {
|
666 | b00052e4 | balrog | if (line >= 16) { |
667 | b00052e4 | balrog | spitz_printf("No GPIO pin %i\n", line);
|
668 | b00052e4 | balrog | return;
|
669 | b00052e4 | balrog | } |
670 | b00052e4 | balrog | |
671 | b00052e4 | balrog | s->handler[line].fn = handler; |
672 | b00052e4 | balrog | s->handler[line].opaque = opaque; |
673 | b00052e4 | balrog | } |
674 | b00052e4 | balrog | |
675 | aa941b94 | balrog | static void scoop_save(QEMUFile *f, void *opaque) |
676 | aa941b94 | balrog | { |
677 | aa941b94 | balrog | struct scoop_info_s *s = (struct scoop_info_s *) opaque; |
678 | aa941b94 | balrog | qemu_put_be16s(f, &s->status); |
679 | aa941b94 | balrog | qemu_put_be16s(f, &s->power); |
680 | aa941b94 | balrog | qemu_put_be32s(f, &s->gpio_level); |
681 | aa941b94 | balrog | qemu_put_be32s(f, &s->gpio_dir); |
682 | aa941b94 | balrog | qemu_put_be32s(f, &s->prev_level); |
683 | aa941b94 | balrog | qemu_put_be16s(f, &s->mcr); |
684 | aa941b94 | balrog | qemu_put_be16s(f, &s->cdr); |
685 | aa941b94 | balrog | qemu_put_be16s(f, &s->ccr); |
686 | aa941b94 | balrog | qemu_put_be16s(f, &s->irr); |
687 | aa941b94 | balrog | qemu_put_be16s(f, &s->imr); |
688 | aa941b94 | balrog | qemu_put_be16s(f, &s->isr); |
689 | aa941b94 | balrog | qemu_put_be16s(f, &s->gprr); |
690 | aa941b94 | balrog | } |
691 | aa941b94 | balrog | |
692 | aa941b94 | balrog | static int scoop_load(QEMUFile *f, void *opaque, int version_id) |
693 | aa941b94 | balrog | { |
694 | aa941b94 | balrog | struct scoop_info_s *s = (struct scoop_info_s *) opaque; |
695 | aa941b94 | balrog | qemu_get_be16s(f, &s->status); |
696 | aa941b94 | balrog | qemu_get_be16s(f, &s->power); |
697 | aa941b94 | balrog | qemu_get_be32s(f, &s->gpio_level); |
698 | aa941b94 | balrog | qemu_get_be32s(f, &s->gpio_dir); |
699 | aa941b94 | balrog | qemu_get_be32s(f, &s->prev_level); |
700 | aa941b94 | balrog | qemu_get_be16s(f, &s->mcr); |
701 | aa941b94 | balrog | qemu_get_be16s(f, &s->cdr); |
702 | aa941b94 | balrog | qemu_get_be16s(f, &s->ccr); |
703 | aa941b94 | balrog | qemu_get_be16s(f, &s->irr); |
704 | aa941b94 | balrog | qemu_get_be16s(f, &s->imr); |
705 | aa941b94 | balrog | qemu_get_be16s(f, &s->isr); |
706 | aa941b94 | balrog | qemu_get_be16s(f, &s->gprr); |
707 | aa941b94 | balrog | |
708 | aa941b94 | balrog | return 0; |
709 | aa941b94 | balrog | } |
710 | aa941b94 | balrog | |
711 | b00052e4 | balrog | static struct scoop_info_s *spitz_scoop_init(struct pxa2xx_state_s *cpu, |
712 | b00052e4 | balrog | int count) {
|
713 | b00052e4 | balrog | int iomemtype;
|
714 | b00052e4 | balrog | struct scoop_info_s *s;
|
715 | b00052e4 | balrog | |
716 | b00052e4 | balrog | s = (struct scoop_info_s *)
|
717 | b00052e4 | balrog | qemu_mallocz(sizeof(struct scoop_info_s) * 2); |
718 | b00052e4 | balrog | memset(s, 0, sizeof(struct scoop_info_s) * count); |
719 | b00052e4 | balrog | s[0].target_base = 0x10800000; |
720 | b00052e4 | balrog | s[1].target_base = 0x08800040; |
721 | b00052e4 | balrog | |
722 | b00052e4 | balrog | /* Ready */
|
723 | b00052e4 | balrog | s[0].status = 0x02; |
724 | b00052e4 | balrog | s[1].status = 0x02; |
725 | b00052e4 | balrog | |
726 | b00052e4 | balrog | iomemtype = cpu_register_io_memory(0, scoop_readfn,
|
727 | b00052e4 | balrog | scoop_writefn, &s[0]);
|
728 | 187337f8 | pbrook | cpu_register_physical_memory(s[0].target_base, 0x1000, iomemtype); |
729 | aa941b94 | balrog | register_savevm("scoop", 0, 0, scoop_save, scoop_load, &s[0]); |
730 | b00052e4 | balrog | |
731 | b00052e4 | balrog | if (count < 2) |
732 | b00052e4 | balrog | return s;
|
733 | b00052e4 | balrog | |
734 | b00052e4 | balrog | iomemtype = cpu_register_io_memory(0, scoop_readfn,
|
735 | b00052e4 | balrog | scoop_writefn, &s[1]);
|
736 | 187337f8 | pbrook | cpu_register_physical_memory(s[1].target_base, 0x1000, iomemtype); |
737 | aa941b94 | balrog | register_savevm("scoop", 1, 0, scoop_save, scoop_load, &s[1]); |
738 | b00052e4 | balrog | |
739 | b00052e4 | balrog | return s;
|
740 | b00052e4 | balrog | } |
741 | b00052e4 | balrog | |
742 | b00052e4 | balrog | /* LCD backlight controller */
|
743 | b00052e4 | balrog | |
744 | b00052e4 | balrog | #define LCDTG_RESCTL 0x00 |
745 | b00052e4 | balrog | #define LCDTG_PHACTRL 0x01 |
746 | b00052e4 | balrog | #define LCDTG_DUTYCTRL 0x02 |
747 | b00052e4 | balrog | #define LCDTG_POWERREG0 0x03 |
748 | b00052e4 | balrog | #define LCDTG_POWERREG1 0x04 |
749 | b00052e4 | balrog | #define LCDTG_GPOR3 0x05 |
750 | b00052e4 | balrog | #define LCDTG_PICTRL 0x06 |
751 | b00052e4 | balrog | #define LCDTG_POLCTRL 0x07 |
752 | b00052e4 | balrog | |
753 | b00052e4 | balrog | static int bl_intensity, bl_power; |
754 | b00052e4 | balrog | |
755 | b00052e4 | balrog | static void spitz_bl_update(struct pxa2xx_state_s *s) |
756 | b00052e4 | balrog | { |
757 | b00052e4 | balrog | if (bl_power && bl_intensity)
|
758 | b00052e4 | balrog | spitz_printf("LCD Backlight now at %i/63\n", bl_intensity);
|
759 | b00052e4 | balrog | else
|
760 | b00052e4 | balrog | spitz_printf("LCD Backlight now off\n");
|
761 | b00052e4 | balrog | } |
762 | b00052e4 | balrog | |
763 | b00052e4 | balrog | static void spitz_bl_bit5(int line, int level, void *opaque) |
764 | b00052e4 | balrog | { |
765 | b00052e4 | balrog | int prev = bl_intensity;
|
766 | b00052e4 | balrog | |
767 | b00052e4 | balrog | if (level)
|
768 | b00052e4 | balrog | bl_intensity &= ~0x20;
|
769 | b00052e4 | balrog | else
|
770 | b00052e4 | balrog | bl_intensity |= 0x20;
|
771 | b00052e4 | balrog | |
772 | b00052e4 | balrog | if (bl_power && prev != bl_intensity)
|
773 | b00052e4 | balrog | spitz_bl_update((struct pxa2xx_state_s *) opaque);
|
774 | b00052e4 | balrog | } |
775 | b00052e4 | balrog | |
776 | b00052e4 | balrog | static void spitz_bl_power(int line, int level, void *opaque) |
777 | b00052e4 | balrog | { |
778 | b00052e4 | balrog | bl_power = !!level; |
779 | b00052e4 | balrog | spitz_bl_update((struct pxa2xx_state_s *) opaque);
|
780 | b00052e4 | balrog | } |
781 | b00052e4 | balrog | |
782 | b00052e4 | balrog | static void spitz_lcdtg_dac_put(void *opaque, uint8_t cmd) |
783 | b00052e4 | balrog | { |
784 | b00052e4 | balrog | int addr, value;
|
785 | b00052e4 | balrog | addr = cmd >> 5;
|
786 | b00052e4 | balrog | value = cmd & 0x1f;
|
787 | b00052e4 | balrog | |
788 | b00052e4 | balrog | switch (addr) {
|
789 | b00052e4 | balrog | case LCDTG_RESCTL:
|
790 | b00052e4 | balrog | if (value)
|
791 | b00052e4 | balrog | spitz_printf("LCD in QVGA mode\n");
|
792 | b00052e4 | balrog | else
|
793 | b00052e4 | balrog | spitz_printf("LCD in VGA mode\n");
|
794 | b00052e4 | balrog | break;
|
795 | b00052e4 | balrog | |
796 | b00052e4 | balrog | case LCDTG_DUTYCTRL:
|
797 | b00052e4 | balrog | bl_intensity &= ~0x1f;
|
798 | b00052e4 | balrog | bl_intensity |= value; |
799 | b00052e4 | balrog | if (bl_power)
|
800 | b00052e4 | balrog | spitz_bl_update((struct pxa2xx_state_s *) opaque);
|
801 | b00052e4 | balrog | break;
|
802 | b00052e4 | balrog | |
803 | b00052e4 | balrog | case LCDTG_POWERREG0:
|
804 | b00052e4 | balrog | /* Set common voltage to M62332FP */
|
805 | b00052e4 | balrog | break;
|
806 | b00052e4 | balrog | } |
807 | b00052e4 | balrog | } |
808 | b00052e4 | balrog | |
809 | b00052e4 | balrog | /* SSP devices */
|
810 | b00052e4 | balrog | |
811 | b00052e4 | balrog | #define CORGI_SSP_PORT 2 |
812 | b00052e4 | balrog | |
813 | b00052e4 | balrog | #define SPITZ_GPIO_LCDCON_CS 53 |
814 | b00052e4 | balrog | #define SPITZ_GPIO_ADS7846_CS 14 |
815 | b00052e4 | balrog | #define SPITZ_GPIO_MAX1111_CS 20 |
816 | b00052e4 | balrog | #define SPITZ_GPIO_TP_INT 11 |
817 | b00052e4 | balrog | |
818 | b00052e4 | balrog | static int lcd_en, ads_en, max_en; |
819 | b00052e4 | balrog | static struct max111x_s *max1111; |
820 | b00052e4 | balrog | static struct ads7846_state_s *ads7846; |
821 | b00052e4 | balrog | |
822 | b00052e4 | balrog | /* "Demux" the signal based on current chipselect */
|
823 | b00052e4 | balrog | static uint32_t corgi_ssp_read(void *opaque) |
824 | b00052e4 | balrog | { |
825 | b00052e4 | balrog | if (lcd_en)
|
826 | b00052e4 | balrog | return 0; |
827 | b00052e4 | balrog | if (ads_en)
|
828 | b00052e4 | balrog | return ads7846_read(ads7846);
|
829 | b00052e4 | balrog | if (max_en)
|
830 | b00052e4 | balrog | return max111x_read(max1111);
|
831 | b00052e4 | balrog | return 0; |
832 | b00052e4 | balrog | } |
833 | b00052e4 | balrog | |
834 | b00052e4 | balrog | static void corgi_ssp_write(void *opaque, uint32_t value) |
835 | b00052e4 | balrog | { |
836 | b00052e4 | balrog | if (lcd_en)
|
837 | b00052e4 | balrog | spitz_lcdtg_dac_put(opaque, value); |
838 | b00052e4 | balrog | if (ads_en)
|
839 | b00052e4 | balrog | ads7846_write(ads7846, value); |
840 | b00052e4 | balrog | if (max_en)
|
841 | b00052e4 | balrog | max111x_write(max1111, value); |
842 | b00052e4 | balrog | } |
843 | b00052e4 | balrog | |
844 | b00052e4 | balrog | static void corgi_ssp_gpio_cs(int line, int level, struct pxa2xx_state_s *s) |
845 | b00052e4 | balrog | { |
846 | b00052e4 | balrog | if (line == SPITZ_GPIO_LCDCON_CS)
|
847 | b00052e4 | balrog | lcd_en = !level; |
848 | b00052e4 | balrog | else if (line == SPITZ_GPIO_ADS7846_CS) |
849 | b00052e4 | balrog | ads_en = !level; |
850 | b00052e4 | balrog | else if (line == SPITZ_GPIO_MAX1111_CS) |
851 | b00052e4 | balrog | max_en = !level; |
852 | b00052e4 | balrog | } |
853 | b00052e4 | balrog | |
854 | b00052e4 | balrog | #define MAX1111_BATT_VOLT 1 |
855 | b00052e4 | balrog | #define MAX1111_BATT_TEMP 2 |
856 | b00052e4 | balrog | #define MAX1111_ACIN_VOLT 3 |
857 | b00052e4 | balrog | |
858 | b00052e4 | balrog | #define SPITZ_BATTERY_TEMP 0xe0 /* About 2.9V */ |
859 | b00052e4 | balrog | #define SPITZ_BATTERY_VOLT 0xd0 /* About 4.0V */ |
860 | b00052e4 | balrog | #define SPITZ_CHARGEON_ACIN 0x80 /* About 5.0V */ |
861 | b00052e4 | balrog | |
862 | b00052e4 | balrog | static void spitz_adc_temp_on(int line, int level, void *opaque) |
863 | b00052e4 | balrog | { |
864 | b00052e4 | balrog | if (!max1111)
|
865 | b00052e4 | balrog | return;
|
866 | b00052e4 | balrog | |
867 | b00052e4 | balrog | if (level)
|
868 | b00052e4 | balrog | max111x_set_input(max1111, MAX1111_BATT_TEMP, SPITZ_BATTERY_TEMP); |
869 | b00052e4 | balrog | else
|
870 | b00052e4 | balrog | max111x_set_input(max1111, MAX1111_BATT_TEMP, 0);
|
871 | b00052e4 | balrog | } |
872 | b00052e4 | balrog | |
873 | b00052e4 | balrog | static void spitz_pendown_set(void *opaque, int line, int level) |
874 | b00052e4 | balrog | { |
875 | b00052e4 | balrog | struct pxa2xx_state_s *cpu = (struct pxa2xx_state_s *) opaque; |
876 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, SPITZ_GPIO_TP_INT, level); |
877 | b00052e4 | balrog | } |
878 | b00052e4 | balrog | |
879 | aa941b94 | balrog | static void spitz_ssp_save(QEMUFile *f, void *opaque) |
880 | aa941b94 | balrog | { |
881 | aa941b94 | balrog | qemu_put_be32(f, lcd_en); |
882 | aa941b94 | balrog | qemu_put_be32(f, ads_en); |
883 | aa941b94 | balrog | qemu_put_be32(f, max_en); |
884 | aa941b94 | balrog | qemu_put_be32(f, bl_intensity); |
885 | aa941b94 | balrog | qemu_put_be32(f, bl_power); |
886 | aa941b94 | balrog | } |
887 | aa941b94 | balrog | |
888 | aa941b94 | balrog | static int spitz_ssp_load(QEMUFile *f, void *opaque, int version_id) |
889 | aa941b94 | balrog | { |
890 | aa941b94 | balrog | lcd_en = qemu_get_be32(f); |
891 | aa941b94 | balrog | ads_en = qemu_get_be32(f); |
892 | aa941b94 | balrog | max_en = qemu_get_be32(f); |
893 | aa941b94 | balrog | bl_intensity = qemu_get_be32(f); |
894 | aa941b94 | balrog | bl_power = qemu_get_be32(f); |
895 | aa941b94 | balrog | |
896 | aa941b94 | balrog | return 0; |
897 | aa941b94 | balrog | } |
898 | aa941b94 | balrog | |
899 | b00052e4 | balrog | static void spitz_ssp_attach(struct pxa2xx_state_s *cpu) |
900 | b00052e4 | balrog | { |
901 | b00052e4 | balrog | lcd_en = ads_en = max_en = 0;
|
902 | b00052e4 | balrog | |
903 | b00052e4 | balrog | ads7846 = ads7846_init(qemu_allocate_irqs(spitz_pendown_set, cpu, 1)[0]); |
904 | b00052e4 | balrog | |
905 | b00052e4 | balrog | max1111 = max1111_init(0);
|
906 | b00052e4 | balrog | max111x_set_input(max1111, MAX1111_BATT_VOLT, SPITZ_BATTERY_VOLT); |
907 | b00052e4 | balrog | max111x_set_input(max1111, MAX1111_BATT_TEMP, 0);
|
908 | b00052e4 | balrog | max111x_set_input(max1111, MAX1111_ACIN_VOLT, SPITZ_CHARGEON_ACIN); |
909 | b00052e4 | balrog | |
910 | b00052e4 | balrog | pxa2xx_ssp_attach(cpu->ssp[CORGI_SSP_PORT - 1], corgi_ssp_read,
|
911 | b00052e4 | balrog | corgi_ssp_write, cpu); |
912 | b00052e4 | balrog | |
913 | b00052e4 | balrog | pxa2xx_gpio_handler_set(cpu->gpio, SPITZ_GPIO_LCDCON_CS, |
914 | b00052e4 | balrog | (gpio_handler_t) corgi_ssp_gpio_cs, cpu); |
915 | b00052e4 | balrog | pxa2xx_gpio_handler_set(cpu->gpio, SPITZ_GPIO_ADS7846_CS, |
916 | b00052e4 | balrog | (gpio_handler_t) corgi_ssp_gpio_cs, cpu); |
917 | b00052e4 | balrog | pxa2xx_gpio_handler_set(cpu->gpio, SPITZ_GPIO_MAX1111_CS, |
918 | b00052e4 | balrog | (gpio_handler_t) corgi_ssp_gpio_cs, cpu); |
919 | b00052e4 | balrog | |
920 | b00052e4 | balrog | bl_intensity = 0x20;
|
921 | b00052e4 | balrog | bl_power = 0;
|
922 | aa941b94 | balrog | |
923 | aa941b94 | balrog | register_savevm("spitz_ssp", 0, 0, spitz_ssp_save, spitz_ssp_load, cpu); |
924 | b00052e4 | balrog | } |
925 | b00052e4 | balrog | |
926 | b00052e4 | balrog | /* CF Microdrive */
|
927 | b00052e4 | balrog | |
928 | b00052e4 | balrog | static void spitz_microdrive_attach(struct pxa2xx_state_s *cpu) |
929 | b00052e4 | balrog | { |
930 | b00052e4 | balrog | struct pcmcia_card_s *md;
|
931 | b00052e4 | balrog | BlockDriverState *bs = bs_table[0];
|
932 | b00052e4 | balrog | |
933 | b00052e4 | balrog | if (bs && bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
|
934 | b00052e4 | balrog | md = dscm1xxxx_init(bs); |
935 | bf5ee248 | balrog | pxa2xx_pcmcia_attach(cpu->pcmcia[1], md);
|
936 | b00052e4 | balrog | } |
937 | b00052e4 | balrog | } |
938 | b00052e4 | balrog | |
939 | adb86c37 | balrog | /* Wm8750 and Max7310 on I2C */
|
940 | adb86c37 | balrog | |
941 | adb86c37 | balrog | #define AKITA_MAX_ADDR 0x18 |
942 | 611d7189 | balrog | #define SPITZ_WM_ADDRL 0x1b |
943 | 611d7189 | balrog | #define SPITZ_WM_ADDRH 0x1a |
944 | adb86c37 | balrog | |
945 | adb86c37 | balrog | #define SPITZ_GPIO_WM 5 |
946 | adb86c37 | balrog | |
947 | adb86c37 | balrog | #ifdef HAS_AUDIO
|
948 | adb86c37 | balrog | static void spitz_wm8750_addr(int line, int level, void *opaque) |
949 | adb86c37 | balrog | { |
950 | adb86c37 | balrog | i2c_slave *wm = (i2c_slave *) opaque; |
951 | adb86c37 | balrog | if (level)
|
952 | adb86c37 | balrog | i2c_set_slave_address(wm, SPITZ_WM_ADDRH); |
953 | adb86c37 | balrog | else
|
954 | adb86c37 | balrog | i2c_set_slave_address(wm, SPITZ_WM_ADDRL); |
955 | adb86c37 | balrog | } |
956 | adb86c37 | balrog | #endif
|
957 | adb86c37 | balrog | |
958 | adb86c37 | balrog | static void spitz_i2c_setup(struct pxa2xx_state_s *cpu) |
959 | adb86c37 | balrog | { |
960 | adb86c37 | balrog | /* Attach the CPU on one end of our I2C bus. */
|
961 | adb86c37 | balrog | i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
|
962 | adb86c37 | balrog | |
963 | adb86c37 | balrog | #ifdef HAS_AUDIO
|
964 | adb86c37 | balrog | AudioState *audio; |
965 | adb86c37 | balrog | i2c_slave *wm; |
966 | adb86c37 | balrog | |
967 | adb86c37 | balrog | audio = AUD_init(); |
968 | adb86c37 | balrog | if (!audio)
|
969 | adb86c37 | balrog | return;
|
970 | adb86c37 | balrog | /* Attach a WM8750 to the bus */
|
971 | adb86c37 | balrog | wm = wm8750_init(bus, audio); |
972 | adb86c37 | balrog | |
973 | adb86c37 | balrog | spitz_wm8750_addr(0, 0, wm); |
974 | adb86c37 | balrog | pxa2xx_gpio_handler_set(cpu->gpio, SPITZ_GPIO_WM, spitz_wm8750_addr, wm); |
975 | adb86c37 | balrog | /* .. and to the sound interface. */
|
976 | adb86c37 | balrog | cpu->i2s->opaque = wm; |
977 | adb86c37 | balrog | cpu->i2s->codec_out = wm8750_dac_dat; |
978 | adb86c37 | balrog | cpu->i2s->codec_in = wm8750_adc_dat; |
979 | adb86c37 | balrog | wm8750_data_req_set(wm, cpu->i2s->data_req, cpu->i2s); |
980 | adb86c37 | balrog | #endif
|
981 | adb86c37 | balrog | } |
982 | adb86c37 | balrog | |
983 | adb86c37 | balrog | static void spitz_akita_i2c_setup(struct pxa2xx_state_s *cpu) |
984 | adb86c37 | balrog | { |
985 | adb86c37 | balrog | /* Attach a Max7310 to Akita I2C bus. */
|
986 | adb86c37 | balrog | i2c_set_slave_address(max7310_init(pxa2xx_i2c_bus(cpu->i2c[0])),
|
987 | adb86c37 | balrog | AKITA_MAX_ADDR); |
988 | adb86c37 | balrog | } |
989 | adb86c37 | balrog | |
990 | b00052e4 | balrog | /* Other peripherals */
|
991 | b00052e4 | balrog | |
992 | b00052e4 | balrog | static void spitz_charge_switch(int line, int level, void *opaque) |
993 | b00052e4 | balrog | { |
994 | b00052e4 | balrog | spitz_printf("Charging %s.\n", level ? "off" : "on"); |
995 | b00052e4 | balrog | } |
996 | b00052e4 | balrog | |
997 | b00052e4 | balrog | static void spitz_discharge_switch(int line, int level, void *opaque) |
998 | b00052e4 | balrog | { |
999 | b00052e4 | balrog | spitz_printf("Discharging %s.\n", level ? "on" : "off"); |
1000 | b00052e4 | balrog | } |
1001 | b00052e4 | balrog | |
1002 | b00052e4 | balrog | static void spitz_greenled_switch(int line, int level, void *opaque) |
1003 | b00052e4 | balrog | { |
1004 | b00052e4 | balrog | spitz_printf("Green LED %s.\n", level ? "on" : "off"); |
1005 | b00052e4 | balrog | } |
1006 | b00052e4 | balrog | |
1007 | b00052e4 | balrog | static void spitz_orangeled_switch(int line, int level, void *opaque) |
1008 | b00052e4 | balrog | { |
1009 | b00052e4 | balrog | spitz_printf("Orange LED %s.\n", level ? "on" : "off"); |
1010 | b00052e4 | balrog | } |
1011 | b00052e4 | balrog | |
1012 | b00052e4 | balrog | #define SPITZ_SCP_LED_GREEN 1 |
1013 | b00052e4 | balrog | #define SPITZ_SCP_JK_B 2 |
1014 | b00052e4 | balrog | #define SPITZ_SCP_CHRG_ON 3 |
1015 | b00052e4 | balrog | #define SPITZ_SCP_MUTE_L 4 |
1016 | b00052e4 | balrog | #define SPITZ_SCP_MUTE_R 5 |
1017 | b00052e4 | balrog | #define SPITZ_SCP_CF_POWER 6 |
1018 | b00052e4 | balrog | #define SPITZ_SCP_LED_ORANGE 7 |
1019 | b00052e4 | balrog | #define SPITZ_SCP_JK_A 8 |
1020 | b00052e4 | balrog | #define SPITZ_SCP_ADC_TEMP_ON 9 |
1021 | b00052e4 | balrog | #define SPITZ_SCP2_IR_ON 1 |
1022 | b00052e4 | balrog | #define SPITZ_SCP2_AKIN_PULLUP 2 |
1023 | b00052e4 | balrog | #define SPITZ_SCP2_BACKLIGHT_CONT 7 |
1024 | b00052e4 | balrog | #define SPITZ_SCP2_BACKLIGHT_ON 8 |
1025 | b00052e4 | balrog | #define SPITZ_SCP2_MIC_BIAS 9 |
1026 | b00052e4 | balrog | |
1027 | b00052e4 | balrog | static void spitz_scoop_gpio_setup(struct pxa2xx_state_s *cpu, |
1028 | b00052e4 | balrog | struct scoop_info_s *scp, int num) |
1029 | b00052e4 | balrog | { |
1030 | b00052e4 | balrog | scoop_gpio_handler_set(&scp[0], SPITZ_SCP_CHRG_ON,
|
1031 | b00052e4 | balrog | spitz_charge_switch, cpu); |
1032 | b00052e4 | balrog | scoop_gpio_handler_set(&scp[0], SPITZ_SCP_JK_B,
|
1033 | b00052e4 | balrog | spitz_discharge_switch, cpu); |
1034 | b00052e4 | balrog | scoop_gpio_handler_set(&scp[0], SPITZ_SCP_LED_GREEN,
|
1035 | b00052e4 | balrog | spitz_greenled_switch, cpu); |
1036 | b00052e4 | balrog | scoop_gpio_handler_set(&scp[0], SPITZ_SCP_LED_ORANGE,
|
1037 | b00052e4 | balrog | spitz_orangeled_switch, cpu); |
1038 | b00052e4 | balrog | |
1039 | b00052e4 | balrog | if (num >= 2) { |
1040 | b00052e4 | balrog | scoop_gpio_handler_set(&scp[1], SPITZ_SCP2_BACKLIGHT_CONT,
|
1041 | b00052e4 | balrog | spitz_bl_bit5, cpu); |
1042 | b00052e4 | balrog | scoop_gpio_handler_set(&scp[1], SPITZ_SCP2_BACKLIGHT_ON,
|
1043 | b00052e4 | balrog | spitz_bl_power, cpu); |
1044 | b00052e4 | balrog | } |
1045 | b00052e4 | balrog | |
1046 | b00052e4 | balrog | scoop_gpio_handler_set(&scp[0], SPITZ_SCP_ADC_TEMP_ON,
|
1047 | b00052e4 | balrog | spitz_adc_temp_on, cpu); |
1048 | b00052e4 | balrog | } |
1049 | b00052e4 | balrog | |
1050 | b00052e4 | balrog | #define SPITZ_GPIO_HSYNC 22 |
1051 | b00052e4 | balrog | #define SPITZ_GPIO_SD_DETECT 9 |
1052 | b00052e4 | balrog | #define SPITZ_GPIO_SD_WP 81 |
1053 | b00052e4 | balrog | #define SPITZ_GPIO_ON_RESET 89 |
1054 | b00052e4 | balrog | #define SPITZ_GPIO_BAT_COVER 90 |
1055 | b00052e4 | balrog | #define SPITZ_GPIO_CF1_IRQ 105 |
1056 | b00052e4 | balrog | #define SPITZ_GPIO_CF1_CD 94 |
1057 | b00052e4 | balrog | #define SPITZ_GPIO_CF2_IRQ 106 |
1058 | b00052e4 | balrog | #define SPITZ_GPIO_CF2_CD 93 |
1059 | b00052e4 | balrog | |
1060 | b00052e4 | balrog | int spitz_hsync;
|
1061 | b00052e4 | balrog | |
1062 | b00052e4 | balrog | static void spitz_lcd_hsync_handler(void *opaque) |
1063 | b00052e4 | balrog | { |
1064 | b00052e4 | balrog | struct pxa2xx_state_s *cpu = (struct pxa2xx_state_s *) opaque; |
1065 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, SPITZ_GPIO_HSYNC, spitz_hsync); |
1066 | b00052e4 | balrog | spitz_hsync ^= 1;
|
1067 | b00052e4 | balrog | } |
1068 | b00052e4 | balrog | |
1069 | b00052e4 | balrog | static void spitz_mmc_coverswitch_change(void *opaque, int in) |
1070 | b00052e4 | balrog | { |
1071 | b00052e4 | balrog | struct pxa2xx_state_s *cpu = (struct pxa2xx_state_s *) opaque; |
1072 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, SPITZ_GPIO_SD_DETECT, in); |
1073 | b00052e4 | balrog | } |
1074 | b00052e4 | balrog | |
1075 | b00052e4 | balrog | static void spitz_mmc_writeprotect_change(void *opaque, int wp) |
1076 | b00052e4 | balrog | { |
1077 | b00052e4 | balrog | struct pxa2xx_state_s *cpu = (struct pxa2xx_state_s *) opaque; |
1078 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, SPITZ_GPIO_SD_WP, wp); |
1079 | b00052e4 | balrog | } |
1080 | b00052e4 | balrog | |
1081 | b00052e4 | balrog | static void spitz_pcmcia_cb(void *opaque, int line, int level) |
1082 | b00052e4 | balrog | { |
1083 | b00052e4 | balrog | struct pxa2xx_state_s *cpu = (struct pxa2xx_state_s *) opaque; |
1084 | b00052e4 | balrog | static const int gpio_map[] = { |
1085 | b00052e4 | balrog | SPITZ_GPIO_CF1_IRQ, SPITZ_GPIO_CF1_CD, |
1086 | b00052e4 | balrog | SPITZ_GPIO_CF2_IRQ, SPITZ_GPIO_CF2_CD, |
1087 | b00052e4 | balrog | }; |
1088 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, gpio_map[line], level); |
1089 | b00052e4 | balrog | } |
1090 | b00052e4 | balrog | |
1091 | b00052e4 | balrog | static void spitz_gpio_setup(struct pxa2xx_state_s *cpu, int slots) |
1092 | b00052e4 | balrog | { |
1093 | b00052e4 | balrog | qemu_irq *pcmcia_cb; |
1094 | b00052e4 | balrog | /*
|
1095 | b00052e4 | balrog | * Bad hack: We toggle the LCD hsync GPIO on every GPIO status
|
1096 | b00052e4 | balrog | * read to satisfy broken guests that poll-wait for hsync.
|
1097 | b00052e4 | balrog | * Simulating a real hsync event would be less practical and
|
1098 | b00052e4 | balrog | * wouldn't guarantee that a guest ever exits the loop.
|
1099 | b00052e4 | balrog | */
|
1100 | b00052e4 | balrog | spitz_hsync = 0;
|
1101 | b00052e4 | balrog | pxa2xx_gpio_read_notifier(cpu->gpio, spitz_lcd_hsync_handler, cpu); |
1102 | b00052e4 | balrog | pxa2xx_lcd_vsync_cb(cpu->lcd, spitz_lcd_hsync_handler, cpu); |
1103 | b00052e4 | balrog | |
1104 | b00052e4 | balrog | /* MMC/SD host */
|
1105 | b00052e4 | balrog | pxa2xx_mmci_handlers(cpu->mmc, cpu, spitz_mmc_writeprotect_change, |
1106 | b00052e4 | balrog | spitz_mmc_coverswitch_change); |
1107 | b00052e4 | balrog | |
1108 | b00052e4 | balrog | /* Battery lock always closed */
|
1109 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, SPITZ_GPIO_BAT_COVER, 1);
|
1110 | b00052e4 | balrog | |
1111 | b00052e4 | balrog | /* Handle reset */
|
1112 | b00052e4 | balrog | pxa2xx_gpio_handler_set(cpu->gpio, SPITZ_GPIO_ON_RESET, pxa2xx_reset, cpu); |
1113 | b00052e4 | balrog | |
1114 | b00052e4 | balrog | /* PCMCIA signals: card's IRQ and Card-Detect */
|
1115 | b00052e4 | balrog | pcmcia_cb = qemu_allocate_irqs(spitz_pcmcia_cb, cpu, slots * 2);
|
1116 | b00052e4 | balrog | if (slots >= 1) |
1117 | b00052e4 | balrog | pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[0], pcmcia_cb[0], pcmcia_cb[1]); |
1118 | b00052e4 | balrog | if (slots >= 2) |
1119 | b00052e4 | balrog | pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[1], pcmcia_cb[2], pcmcia_cb[3]); |
1120 | b00052e4 | balrog | |
1121 | b00052e4 | balrog | /* Initialise the screen rotation related signals */
|
1122 | b00052e4 | balrog | spitz_gpio_invert[3] = 0; /* Always open */ |
1123 | b00052e4 | balrog | if (graphic_rotate) { /* Tablet mode */ |
1124 | b00052e4 | balrog | spitz_gpio_invert[4] = 0; |
1125 | b00052e4 | balrog | } else { /* Portrait mode */ |
1126 | b00052e4 | balrog | spitz_gpio_invert[4] = 1; |
1127 | b00052e4 | balrog | } |
1128 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, SPITZ_GPIO_SWA, spitz_gpio_invert[3]);
|
1129 | b00052e4 | balrog | pxa2xx_gpio_set(cpu->gpio, SPITZ_GPIO_SWB, spitz_gpio_invert[4]);
|
1130 | b00052e4 | balrog | } |
1131 | b00052e4 | balrog | |
1132 | b00052e4 | balrog | /* Write the bootloader parameters memory area. */
|
1133 | b00052e4 | balrog | |
1134 | b00052e4 | balrog | #define MAGIC_CHG(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | a) |
1135 | b00052e4 | balrog | |
1136 | b00052e4 | balrog | struct __attribute__ ((__packed__)) sl_param_info {
|
1137 | b00052e4 | balrog | uint32_t comadj_keyword; |
1138 | b00052e4 | balrog | int32_t comadj; |
1139 | b00052e4 | balrog | |
1140 | b00052e4 | balrog | uint32_t uuid_keyword; |
1141 | b00052e4 | balrog | char uuid[16]; |
1142 | b00052e4 | balrog | |
1143 | b00052e4 | balrog | uint32_t touch_keyword; |
1144 | b00052e4 | balrog | int32_t touch_xp; |
1145 | b00052e4 | balrog | int32_t touch_yp; |
1146 | b00052e4 | balrog | int32_t touch_xd; |
1147 | b00052e4 | balrog | int32_t touch_yd; |
1148 | b00052e4 | balrog | |
1149 | b00052e4 | balrog | uint32_t adadj_keyword; |
1150 | b00052e4 | balrog | int32_t adadj; |
1151 | b00052e4 | balrog | |
1152 | b00052e4 | balrog | uint32_t phad_keyword; |
1153 | b00052e4 | balrog | int32_t phadadj; |
1154 | b00052e4 | balrog | } spitz_bootparam = { |
1155 | b00052e4 | balrog | .comadj_keyword = MAGIC_CHG('C', 'M', 'A', 'D'), |
1156 | b00052e4 | balrog | .comadj = 125,
|
1157 | b00052e4 | balrog | .uuid_keyword = MAGIC_CHG('U', 'U', 'I', 'D'), |
1158 | b00052e4 | balrog | .uuid = { -1 },
|
1159 | b00052e4 | balrog | .touch_keyword = MAGIC_CHG('T', 'U', 'C', 'H'), |
1160 | b00052e4 | balrog | .touch_xp = -1,
|
1161 | b00052e4 | balrog | .adadj_keyword = MAGIC_CHG('B', 'V', 'A', 'D'), |
1162 | b00052e4 | balrog | .adadj = -1,
|
1163 | b00052e4 | balrog | .phad_keyword = MAGIC_CHG('P', 'H', 'A', 'D'), |
1164 | b00052e4 | balrog | .phadadj = 0x01,
|
1165 | b00052e4 | balrog | }; |
1166 | b00052e4 | balrog | |
1167 | b00052e4 | balrog | static void sl_bootparam_write(uint32_t ptr) |
1168 | b00052e4 | balrog | { |
1169 | b00052e4 | balrog | memcpy(phys_ram_base + ptr, &spitz_bootparam, |
1170 | b00052e4 | balrog | sizeof(struct sl_param_info)); |
1171 | b00052e4 | balrog | } |
1172 | b00052e4 | balrog | |
1173 | b00052e4 | balrog | #define SL_PXA_PARAM_BASE 0xa0000a00 |
1174 | b00052e4 | balrog | |
1175 | b00052e4 | balrog | /* Board init. */
|
1176 | b00052e4 | balrog | enum spitz_model_e { spitz, akita, borzoi, terrier };
|
1177 | b00052e4 | balrog | |
1178 | b00052e4 | balrog | static void spitz_common_init(int ram_size, int vga_ram_size, |
1179 | b00052e4 | balrog | DisplayState *ds, const char *kernel_filename, |
1180 | b00052e4 | balrog | const char *kernel_cmdline, const char *initrd_filename, |
1181 | 4207117c | balrog | const char *cpu_model, enum spitz_model_e model, int arm_id) |
1182 | b00052e4 | balrog | { |
1183 | b00052e4 | balrog | uint32_t spitz_ram = 0x04000000;
|
1184 | b00052e4 | balrog | uint32_t spitz_rom = 0x00800000;
|
1185 | b00052e4 | balrog | struct pxa2xx_state_s *cpu;
|
1186 | b00052e4 | balrog | struct scoop_info_s *scp;
|
1187 | b00052e4 | balrog | |
1188 | 4207117c | balrog | if (!cpu_model)
|
1189 | 4207117c | balrog | cpu_model = (model == terrier) ? "pxa270-c5" : "pxa270-c0"; |
1190 | b00052e4 | balrog | |
1191 | d95b2f8d | balrog | /* Setup CPU & memory */
|
1192 | a07dec22 | balrog | if (ram_size < spitz_ram + spitz_rom + PXA2XX_INTERNAL_SIZE) {
|
1193 | b00052e4 | balrog | fprintf(stderr, "This platform requires %i bytes of memory\n",
|
1194 | a07dec22 | balrog | spitz_ram + spitz_rom + PXA2XX_INTERNAL_SIZE); |
1195 | b00052e4 | balrog | exit(1);
|
1196 | b00052e4 | balrog | } |
1197 | d95b2f8d | balrog | cpu = pxa270_init(spitz_ram, ds, cpu_model); |
1198 | b00052e4 | balrog | |
1199 | b00052e4 | balrog | sl_flash_register(cpu, (model == spitz) ? FLASH_128M : FLASH_1024M); |
1200 | b00052e4 | balrog | |
1201 | d95b2f8d | balrog | cpu_register_physical_memory(0, spitz_rom,
|
1202 | d95b2f8d | balrog | qemu_ram_alloc(spitz_rom) | IO_MEM_ROM); |
1203 | b00052e4 | balrog | |
1204 | b00052e4 | balrog | /* Setup peripherals */
|
1205 | b00052e4 | balrog | spitz_keyboard_register(cpu); |
1206 | b00052e4 | balrog | |
1207 | b00052e4 | balrog | spitz_ssp_attach(cpu); |
1208 | b00052e4 | balrog | |
1209 | b00052e4 | balrog | scp = spitz_scoop_init(cpu, (model == akita) ? 1 : 2); |
1210 | b00052e4 | balrog | |
1211 | b00052e4 | balrog | spitz_scoop_gpio_setup(cpu, scp, (model == akita) ? 1 : 2); |
1212 | b00052e4 | balrog | |
1213 | b00052e4 | balrog | spitz_gpio_setup(cpu, (model == akita) ? 1 : 2); |
1214 | b00052e4 | balrog | |
1215 | adb86c37 | balrog | spitz_i2c_setup(cpu); |
1216 | adb86c37 | balrog | |
1217 | adb86c37 | balrog | if (model == akita)
|
1218 | adb86c37 | balrog | spitz_akita_i2c_setup(cpu); |
1219 | adb86c37 | balrog | |
1220 | b00052e4 | balrog | if (model == terrier)
|
1221 | bf5ee248 | balrog | /* A 6.0 GB microdrive is permanently sitting in CF slot 1. */
|
1222 | b00052e4 | balrog | spitz_microdrive_attach(cpu); |
1223 | b00052e4 | balrog | else if (model != akita) |
1224 | bf5ee248 | balrog | /* A 4.0 GB microdrive is permanently sitting in CF slot 1. */
|
1225 | b00052e4 | balrog | spitz_microdrive_attach(cpu); |
1226 | b00052e4 | balrog | |
1227 | b00052e4 | balrog | /* Setup initial (reset) machine state */
|
1228 | d95b2f8d | balrog | cpu->env->regs[15] = PXA2XX_SDRAM_BASE;
|
1229 | b00052e4 | balrog | |
1230 | d95b2f8d | balrog | arm_load_kernel(cpu->env, spitz_ram, kernel_filename, kernel_cmdline, |
1231 | d95b2f8d | balrog | initrd_filename, arm_id, PXA2XX_SDRAM_BASE); |
1232 | d95b2f8d | balrog | sl_bootparam_write(SL_PXA_PARAM_BASE - PXA2XX_SDRAM_BASE); |
1233 | b00052e4 | balrog | } |
1234 | b00052e4 | balrog | |
1235 | 6ac0e82d | balrog | static void spitz_init(int ram_size, int vga_ram_size, |
1236 | 6ac0e82d | balrog | const char *boot_device, DisplayState *ds, |
1237 | 6ac0e82d | balrog | const char **fd_filename, int snapshot, |
1238 | b00052e4 | balrog | const char *kernel_filename, const char *kernel_cmdline, |
1239 | b00052e4 | balrog | const char *initrd_filename, const char *cpu_model) |
1240 | b00052e4 | balrog | { |
1241 | b00052e4 | balrog | spitz_common_init(ram_size, vga_ram_size, ds, kernel_filename, |
1242 | 4207117c | balrog | kernel_cmdline, initrd_filename, cpu_model, spitz, 0x2c9);
|
1243 | b00052e4 | balrog | } |
1244 | b00052e4 | balrog | |
1245 | 6ac0e82d | balrog | static void borzoi_init(int ram_size, int vga_ram_size, |
1246 | 6ac0e82d | balrog | const char *boot_device, DisplayState *ds, |
1247 | 6ac0e82d | balrog | const char **fd_filename, int snapshot, |
1248 | b00052e4 | balrog | const char *kernel_filename, const char *kernel_cmdline, |
1249 | b00052e4 | balrog | const char *initrd_filename, const char *cpu_model) |
1250 | b00052e4 | balrog | { |
1251 | b00052e4 | balrog | spitz_common_init(ram_size, vga_ram_size, ds, kernel_filename, |
1252 | 4207117c | balrog | kernel_cmdline, initrd_filename, cpu_model, borzoi, 0x33f);
|
1253 | b00052e4 | balrog | } |
1254 | b00052e4 | balrog | |
1255 | 6ac0e82d | balrog | static void akita_init(int ram_size, int vga_ram_size, |
1256 | 6ac0e82d | balrog | const char *boot_device, DisplayState *ds, |
1257 | 6ac0e82d | balrog | const char **fd_filename, int snapshot, |
1258 | b00052e4 | balrog | const char *kernel_filename, const char *kernel_cmdline, |
1259 | b00052e4 | balrog | const char *initrd_filename, const char *cpu_model) |
1260 | b00052e4 | balrog | { |
1261 | b00052e4 | balrog | spitz_common_init(ram_size, vga_ram_size, ds, kernel_filename, |
1262 | 4207117c | balrog | kernel_cmdline, initrd_filename, cpu_model, akita, 0x2e8);
|
1263 | b00052e4 | balrog | } |
1264 | b00052e4 | balrog | |
1265 | 6ac0e82d | balrog | static void terrier_init(int ram_size, int vga_ram_size, |
1266 | 6ac0e82d | balrog | const char *boot_device, DisplayState *ds, |
1267 | 6ac0e82d | balrog | const char **fd_filename, int snapshot, |
1268 | b00052e4 | balrog | const char *kernel_filename, const char *kernel_cmdline, |
1269 | b00052e4 | balrog | const char *initrd_filename, const char *cpu_model) |
1270 | b00052e4 | balrog | { |
1271 | b00052e4 | balrog | spitz_common_init(ram_size, vga_ram_size, ds, kernel_filename, |
1272 | 4207117c | balrog | kernel_cmdline, initrd_filename, cpu_model, terrier, 0x33f);
|
1273 | b00052e4 | balrog | } |
1274 | b00052e4 | balrog | |
1275 | b00052e4 | balrog | QEMUMachine akitapda_machine = { |
1276 | b00052e4 | balrog | "akita",
|
1277 | b00052e4 | balrog | "Akita PDA (PXA270)",
|
1278 | b00052e4 | balrog | akita_init, |
1279 | b00052e4 | balrog | }; |
1280 | b00052e4 | balrog | |
1281 | b00052e4 | balrog | QEMUMachine spitzpda_machine = { |
1282 | b00052e4 | balrog | "spitz",
|
1283 | b00052e4 | balrog | "Spitz PDA (PXA270)",
|
1284 | b00052e4 | balrog | spitz_init, |
1285 | b00052e4 | balrog | }; |
1286 | b00052e4 | balrog | |
1287 | b00052e4 | balrog | QEMUMachine borzoipda_machine = { |
1288 | b00052e4 | balrog | "borzoi",
|
1289 | b00052e4 | balrog | "Borzoi PDA (PXA270)",
|
1290 | b00052e4 | balrog | borzoi_init, |
1291 | b00052e4 | balrog | }; |
1292 | b00052e4 | balrog | |
1293 | b00052e4 | balrog | QEMUMachine terrierpda_machine = { |
1294 | b00052e4 | balrog | "terrier",
|
1295 | b00052e4 | balrog | "Terrier PDA (PXA270)",
|
1296 | b00052e4 | balrog | terrier_init, |
1297 | b00052e4 | balrog | }; |