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