Rev 1702 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1702 | Rev 1734 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Martin Decky |
2 | * Copyright (C) 2006 Martin Decky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup ppc32 |
29 | /** @addtogroup ppc32 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/drivers/cuda.h> |
35 | #include <arch/drivers/cuda.h> |
36 | #include <arch/asm.h> |
36 | #include <arch/asm.h> |
37 | #include <console/console.h> |
37 | #include <console/console.h> |
38 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
39 | #include <arch/drivers/pic.h> |
39 | #include <arch/drivers/pic.h> |
40 | #include <sysinfo/sysinfo.h> |
40 | #include <sysinfo/sysinfo.h> |
41 | #include <interrupt.h> |
41 | #include <interrupt.h> |
42 | #include <stdarg.h> |
42 | #include <stdarg.h> |
43 | 43 | ||
44 | #define SPECIAL '?' |
44 | #define SPECIAL '?' |
45 | 45 | ||
46 | #define PACKET_ADB 0x00 |
46 | #define PACKET_ADB 0x00 |
47 | #define PACKET_CUDA 0x01 |
47 | #define PACKET_CUDA 0x01 |
48 | 48 | ||
49 | #define CUDA_POWERDOWN 0x0a |
49 | #define CUDA_POWERDOWN 0x0a |
50 | 50 | ||
51 | #define RS 0x200 |
51 | #define RS 0x200 |
52 | #define B (0 * RS) |
52 | #define B (0 * RS) |
53 | #define A (1 * RS) |
53 | #define A (1 * RS) |
54 | #define SR (10 * RS) |
54 | #define SR (10 * RS) |
55 | #define ACR (11 * RS) |
55 | #define ACR (11 * RS) |
56 | 56 | ||
57 | #define SR_OUT 0x10 |
57 | #define SR_OUT 0x10 |
58 | #define TACK 0x10 |
58 | #define TACK 0x10 |
59 | #define TIP 0x20 |
59 | #define TIP 0x20 |
60 | 60 | ||
61 | 61 | ||
62 | static volatile __u8 *cuda = NULL; |
62 | static volatile __u8 *cuda = NULL; |
- | 63 | static iroutine vector; |
|
63 | 64 | ||
64 | 65 | ||
65 | static char lchars[0x80] = { |
66 | static char lchars[0x80] = { |
66 | 'a', |
67 | 'a', |
67 | 's', |
68 | 's', |
68 | 'd', |
69 | 'd', |
69 | 'f', |
70 | 'f', |
70 | 'h', |
71 | 'h', |
71 | 'g', |
72 | 'g', |
72 | 'z', |
73 | 'z', |
73 | 'x', |
74 | 'x', |
74 | 'c', |
75 | 'c', |
75 | 'v', |
76 | 'v', |
76 | SPECIAL, |
77 | SPECIAL, |
77 | 'b', |
78 | 'b', |
78 | 'q', |
79 | 'q', |
79 | 'w', |
80 | 'w', |
80 | 'e', |
81 | 'e', |
81 | 'r', |
82 | 'r', |
82 | 'y', |
83 | 'y', |
83 | 't', |
84 | 't', |
84 | '1', |
85 | '1', |
85 | '2', |
86 | '2', |
86 | '3', |
87 | '3', |
87 | '4', |
88 | '4', |
88 | '6', |
89 | '6', |
89 | '5', |
90 | '5', |
90 | '=', |
91 | '=', |
91 | '9', |
92 | '9', |
92 | '7', |
93 | '7', |
93 | '-', |
94 | '-', |
94 | '8', |
95 | '8', |
95 | '0', |
96 | '0', |
96 | ']', |
97 | ']', |
97 | 'o', |
98 | 'o', |
98 | 'u', |
99 | 'u', |
99 | '[', |
100 | '[', |
100 | 'i', |
101 | 'i', |
101 | 'p', |
102 | 'p', |
102 | '\n', /* Enter */ |
103 | '\n', /* Enter */ |
103 | 'l', |
104 | 'l', |
104 | 'j', |
105 | 'j', |
105 | '\'', |
106 | '\'', |
106 | 'k', |
107 | 'k', |
107 | ';', |
108 | ';', |
108 | '\\', |
109 | '\\', |
109 | ',', |
110 | ',', |
110 | '/', |
111 | '/', |
111 | 'n', |
112 | 'n', |
112 | 'm', |
113 | 'm', |
113 | '.', |
114 | '.', |
114 | '\t', /* Tab */ |
115 | '\t', /* Tab */ |
115 | ' ', |
116 | ' ', |
116 | '`', |
117 | '`', |
117 | '\b', /* Backspace */ |
118 | '\b', /* Backspace */ |
118 | SPECIAL, |
119 | SPECIAL, |
119 | SPECIAL, /* Escape */ |
120 | SPECIAL, /* Escape */ |
120 | SPECIAL, /* Ctrl */ |
121 | SPECIAL, /* Ctrl */ |
121 | SPECIAL, /* Alt */ |
122 | SPECIAL, /* Alt */ |
122 | SPECIAL, /* Shift */ |
123 | SPECIAL, /* Shift */ |
123 | SPECIAL, /* Caps-Lock */ |
124 | SPECIAL, /* Caps-Lock */ |
124 | SPECIAL, /* RAlt */ |
125 | SPECIAL, /* RAlt */ |
125 | SPECIAL, /* Left */ |
126 | SPECIAL, /* Left */ |
126 | SPECIAL, /* Right */ |
127 | SPECIAL, /* Right */ |
127 | SPECIAL, /* Down */ |
128 | SPECIAL, /* Down */ |
128 | SPECIAL, /* Up */ |
129 | SPECIAL, /* Up */ |
129 | SPECIAL, |
130 | SPECIAL, |
130 | SPECIAL, |
131 | SPECIAL, |
131 | '.', /* Keypad . */ |
132 | '.', /* Keypad . */ |
132 | SPECIAL, |
133 | SPECIAL, |
133 | '*', /* Keypad * */ |
134 | '*', /* Keypad * */ |
134 | SPECIAL, |
135 | SPECIAL, |
135 | '+', /* Keypad + */ |
136 | '+', /* Keypad + */ |
136 | SPECIAL, |
137 | SPECIAL, |
137 | SPECIAL, /* NumLock */ |
138 | SPECIAL, /* NumLock */ |
138 | SPECIAL, |
139 | SPECIAL, |
139 | SPECIAL, |
140 | SPECIAL, |
140 | SPECIAL, |
141 | SPECIAL, |
141 | '/', /* Keypad / */ |
142 | '/', /* Keypad / */ |
142 | '\n', /* Keypad Enter */ |
143 | '\n', /* Keypad Enter */ |
143 | SPECIAL, |
144 | SPECIAL, |
144 | '-', /* Keypad - */ |
145 | '-', /* Keypad - */ |
145 | SPECIAL, |
146 | SPECIAL, |
146 | SPECIAL, |
147 | SPECIAL, |
147 | SPECIAL, |
148 | SPECIAL, |
148 | '0', /* Keypad 0 */ |
149 | '0', /* Keypad 0 */ |
149 | '1', /* Keypad 1 */ |
150 | '1', /* Keypad 1 */ |
150 | '2', /* Keypad 2 */ |
151 | '2', /* Keypad 2 */ |
151 | '3', /* Keypad 3 */ |
152 | '3', /* Keypad 3 */ |
152 | '4', /* Keypad 4 */ |
153 | '4', /* Keypad 4 */ |
153 | '5', /* Keypad 5 */ |
154 | '5', /* Keypad 5 */ |
154 | '6', /* Keypad 6 */ |
155 | '6', /* Keypad 6 */ |
155 | '7', /* Keypad 7 */ |
156 | '7', /* Keypad 7 */ |
156 | SPECIAL, |
157 | SPECIAL, |
157 | '8', /* Keypad 8 */ |
158 | '8', /* Keypad 8 */ |
158 | '9', /* Keypad 9 */ |
159 | '9', /* Keypad 9 */ |
159 | SPECIAL, |
160 | SPECIAL, |
160 | SPECIAL, |
161 | SPECIAL, |
161 | SPECIAL, |
162 | SPECIAL, |
162 | SPECIAL, /* F5 */ |
163 | SPECIAL, /* F5 */ |
163 | SPECIAL, /* F6 */ |
164 | SPECIAL, /* F6 */ |
164 | SPECIAL, /* F7 */ |
165 | SPECIAL, /* F7 */ |
165 | SPECIAL, /* F3 */ |
166 | SPECIAL, /* F3 */ |
166 | SPECIAL, /* F8 */ |
167 | SPECIAL, /* F8 */ |
167 | SPECIAL, /* F9 */ |
168 | SPECIAL, /* F9 */ |
168 | SPECIAL, |
169 | SPECIAL, |
169 | SPECIAL, /* F11 */ |
170 | SPECIAL, /* F11 */ |
170 | SPECIAL, |
171 | SPECIAL, |
171 | SPECIAL, /* F13 */ |
172 | SPECIAL, /* F13 */ |
172 | SPECIAL, |
173 | SPECIAL, |
173 | SPECIAL, /* ScrollLock */ |
174 | SPECIAL, /* ScrollLock */ |
174 | SPECIAL, |
175 | SPECIAL, |
175 | SPECIAL, /* F10 */ |
176 | SPECIAL, /* F10 */ |
176 | SPECIAL, |
177 | SPECIAL, |
177 | SPECIAL, /* F12 */ |
178 | SPECIAL, /* F12 */ |
178 | SPECIAL, |
179 | SPECIAL, |
179 | SPECIAL, /* Pause */ |
180 | SPECIAL, /* Pause */ |
180 | SPECIAL, /* Insert */ |
181 | SPECIAL, /* Insert */ |
181 | SPECIAL, /* Home */ |
182 | SPECIAL, /* Home */ |
182 | SPECIAL, /* PageUp */ |
183 | SPECIAL, /* PageUp */ |
183 | SPECIAL, /* Delete */ |
184 | SPECIAL, /* Delete */ |
184 | SPECIAL, /* F4 */ |
185 | SPECIAL, /* F4 */ |
185 | SPECIAL, /* End */ |
186 | SPECIAL, /* End */ |
186 | SPECIAL, /* F2 */ |
187 | SPECIAL, /* F2 */ |
187 | SPECIAL, /* PageDown */ |
188 | SPECIAL, /* PageDown */ |
188 | SPECIAL /* F1 */ |
189 | SPECIAL /* F1 */ |
189 | }; |
190 | }; |
190 | 191 | ||
191 | 192 | ||
192 | void send_packet(const __u8 kind, index_t count, ...); |
193 | void send_packet(const __u8 kind, index_t count, ...); |
193 | 194 | ||
194 | 195 | ||
195 | static void receive_packet(__u8 *kind, index_t count, __u8 data[]) |
196 | static void receive_packet(__u8 *kind, index_t count, __u8 data[]) |
196 | { |
197 | { |
197 | cuda[B] = cuda[B] & ~TIP; |
198 | cuda[B] = cuda[B] & ~TIP; |
198 | *kind = cuda[SR]; |
199 | *kind = cuda[SR]; |
199 | 200 | ||
200 | index_t i; |
201 | index_t i; |
201 | for (i = 0; i < count; i++) |
202 | for (i = 0; i < count; i++) |
202 | data[i] = cuda[SR]; |
203 | data[i] = cuda[SR]; |
203 | 204 | ||
204 | cuda[B] = cuda[B] | TIP; |
205 | cuda[B] = cuda[B] | TIP; |
205 | } |
206 | } |
206 | 207 | ||
207 | 208 | ||
208 | /* Called from getc(). */ |
209 | /* Called from getc(). */ |
209 | static void cuda_resume(chardev_t *d) |
210 | static void cuda_resume(chardev_t *d) |
210 | { |
211 | { |
211 | } |
212 | } |
212 | 213 | ||
213 | 214 | ||
214 | /* Called from getc(). */ |
215 | /* Called from getc(). */ |
215 | static void cuda_suspend(chardev_t *d) |
216 | static void cuda_suspend(chardev_t *d) |
216 | { |
217 | { |
217 | } |
218 | } |
218 | 219 | ||
219 | 220 | ||
220 | static char key_read(chardev_t *d) |
221 | static char key_read(chardev_t *d) |
221 | { |
222 | { |
222 | char ch; |
223 | char ch; |
223 | 224 | ||
224 | ch = 0; |
225 | ch = 0; |
225 | return ch; |
226 | return ch; |
226 | } |
227 | } |
227 | 228 | ||
228 | 229 | ||
229 | static chardev_t kbrd; |
230 | static chardev_t kbrd; |
230 | static chardev_operations_t ops = { |
231 | static chardev_operations_t ops = { |
231 | .suspend = cuda_suspend, |
232 | .suspend = cuda_suspend, |
232 | .resume = cuda_resume, |
233 | .resume = cuda_resume, |
233 | .read = key_read |
234 | .read = key_read |
234 | }; |
235 | }; |
235 | 236 | ||
236 | 237 | ||
237 | int cuda_get_scancode(void) |
238 | int cuda_get_scancode(void) |
238 | { |
239 | { |
239 | __u8 kind; |
240 | __u8 kind; |
240 | __u8 data[4]; |
241 | __u8 data[4]; |
241 | 242 | ||
242 | receive_packet(&kind, 4, data); |
243 | receive_packet(&kind, 4, data); |
243 | 244 | ||
244 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
245 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
245 | return data[2]; |
246 | return data[2]; |
246 | 247 | ||
247 | return -1; |
248 | return -1; |
248 | } |
249 | } |
249 | 250 | ||
250 | static void cuda_irq(int n, istate_t *istate) |
251 | static void cuda_irq(int n, istate_t *istate) |
251 | { |
252 | { |
252 | int scan_code = cuda_get_scancode(); |
253 | int scan_code = cuda_get_scancode(); |
253 | 254 | ||
254 | if (scan_code != -1) { |
255 | if (scan_code != -1) { |
255 | __u8 scancode = (__u8) scan_code; |
256 | __u8 scancode = (__u8) scan_code; |
256 | if ((scancode & 0x80) != 0x80) |
257 | if ((scancode & 0x80) != 0x80) |
257 | chardev_push_character(&kbrd, lchars[scancode & 0x7f]); |
258 | chardev_push_character(&kbrd, lchars[scancode & 0x7f]); |
258 | } |
259 | } |
259 | } |
260 | } |
260 | 261 | ||
261 | 262 | ||
- | 263 | /** Initialize keyboard and service interrupts using kernel routine */ |
|
- | 264 | void cuda_grab(void) |
|
- | 265 | { |
|
- | 266 | vector = int_register(CUDA_IRQ, "cuda", cuda_irq); |
|
- | 267 | } |
|
- | 268 | ||
- | 269 | ||
- | 270 | /** Resume the former interrupt vector */ |
|
- | 271 | void cuda_release(void) |
|
- | 272 | { |
|
- | 273 | if (vector) |
|
- | 274 | int_register(CUDA_IRQ, "user_interrupt", vector); |
|
- | 275 | } |
|
- | 276 | ||
- | 277 | ||
262 | void cuda_init(__address base, size_t size) |
278 | void cuda_init(__address base, size_t size) |
263 | { |
279 | { |
264 | cuda = (__u8 *) hw_map(base, size); |
280 | cuda = (__u8 *) hw_map(base, size); |
265 | 281 | ||
266 | int_register(CUDA_IRQ, "cuda", cuda_irq); |
282 | int_register(CUDA_IRQ, "cuda", cuda_irq); |
267 | pic_enable_interrupt(CUDA_IRQ); |
283 | pic_enable_interrupt(CUDA_IRQ); |
268 | 284 | ||
269 | chardev_initialize("cuda_kbd", &kbrd, &ops); |
285 | chardev_initialize("cuda_kbd", &kbrd, &ops); |
270 | stdin = &kbrd; |
286 | stdin = &kbrd; |
271 | 287 | ||
272 | sysinfo_set_item_val("cuda", NULL, true); |
288 | sysinfo_set_item_val("cuda", NULL, true); |
273 | sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ); |
289 | sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ); |
274 | } |
290 | } |
275 | 291 | ||
276 | 292 | ||
277 | void send_packet(const __u8 kind, index_t count, ...) |
293 | void send_packet(const __u8 kind, index_t count, ...) |
278 | { |
294 | { |
279 | index_t i; |
295 | index_t i; |
280 | va_list va; |
296 | va_list va; |
281 | 297 | ||
282 | cuda[B] = cuda[B] | TIP; |
298 | cuda[B] = cuda[B] | TIP; |
283 | cuda[ACR] = cuda[ACR] | SR_OUT; |
299 | cuda[ACR] = cuda[ACR] | SR_OUT; |
284 | cuda[SR] = kind; |
300 | cuda[SR] = kind; |
285 | cuda[B] = cuda[B] & ~TIP; |
301 | cuda[B] = cuda[B] & ~TIP; |
286 | 302 | ||
287 | va_start(va, count); |
303 | va_start(va, count); |
288 | 304 | ||
289 | for (i = 0; i < count; i++) { |
305 | for (i = 0; i < count; i++) { |
290 | cuda[ACR] = cuda[ACR] | SR_OUT; |
306 | cuda[ACR] = cuda[ACR] | SR_OUT; |
291 | cuda[SR] = va_arg(va, int); |
307 | cuda[SR] = va_arg(va, int); |
292 | cuda[B] = cuda[B] | TACK; |
308 | cuda[B] = cuda[B] | TACK; |
293 | } |
309 | } |
294 | 310 | ||
295 | va_end(va); |
311 | va_end(va); |
296 | 312 | ||
297 | cuda[B] = cuda[B] | TIP; |
313 | cuda[B] = cuda[B] | TIP; |
298 | } |
314 | } |
299 | 315 | ||
300 | 316 | ||
301 | void cpu_halt(void) { |
317 | void cpu_halt(void) { |
302 | #ifdef CONFIG_POWEROFF |
318 | #ifdef CONFIG_POWEROFF |
303 | send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN); |
319 | send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN); |
304 | #endif |
320 | #endif |
305 | asm volatile ( |
321 | asm volatile ( |
306 | "b 0\n" |
322 | "b 0\n" |
307 | ); |
323 | ); |
308 | } |
324 | } |
309 | 325 | ||
310 | /** @} |
326 | /** @} |
311 | */ |
327 | */ |
312 | - | ||
313 | 328 |