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