Rev 1633 | Rev 1734 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1633 | Rev 1702 | ||
---|---|---|---|
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 |
|
- | 30 | * @{ |
|
- | 31 | */ |
|
- | 32 | /** @file |
|
- | 33 | */ |
|
- | 34 | ||
29 | #include <arch/drivers/cuda.h> |
35 | #include <arch/drivers/cuda.h> |
30 | #include <arch/asm.h> |
36 | #include <arch/asm.h> |
31 | #include <console/console.h> |
37 | #include <console/console.h> |
32 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
33 | #include <arch/drivers/pic.h> |
39 | #include <arch/drivers/pic.h> |
34 | #include <sysinfo/sysinfo.h> |
40 | #include <sysinfo/sysinfo.h> |
35 | #include <interrupt.h> |
41 | #include <interrupt.h> |
36 | #include <stdarg.h> |
42 | #include <stdarg.h> |
37 | 43 | ||
38 | #define SPECIAL '?' |
44 | #define SPECIAL '?' |
39 | 45 | ||
40 | #define PACKET_ADB 0x00 |
46 | #define PACKET_ADB 0x00 |
41 | #define PACKET_CUDA 0x01 |
47 | #define PACKET_CUDA 0x01 |
42 | 48 | ||
43 | #define CUDA_POWERDOWN 0x0a |
49 | #define CUDA_POWERDOWN 0x0a |
44 | 50 | ||
45 | #define RS 0x200 |
51 | #define RS 0x200 |
46 | #define B (0 * RS) |
52 | #define B (0 * RS) |
47 | #define A (1 * RS) |
53 | #define A (1 * RS) |
48 | #define SR (10 * RS) |
54 | #define SR (10 * RS) |
49 | #define ACR (11 * RS) |
55 | #define ACR (11 * RS) |
50 | 56 | ||
51 | #define SR_OUT 0x10 |
57 | #define SR_OUT 0x10 |
52 | #define TACK 0x10 |
58 | #define TACK 0x10 |
53 | #define TIP 0x20 |
59 | #define TIP 0x20 |
54 | 60 | ||
55 | 61 | ||
56 | static volatile __u8 *cuda = NULL; |
62 | static volatile __u8 *cuda = NULL; |
57 | 63 | ||
58 | 64 | ||
59 | static char lchars[0x80] = { |
65 | static char lchars[0x80] = { |
60 | 'a', |
66 | 'a', |
61 | 's', |
67 | 's', |
62 | 'd', |
68 | 'd', |
63 | 'f', |
69 | 'f', |
64 | 'h', |
70 | 'h', |
65 | 'g', |
71 | 'g', |
66 | 'z', |
72 | 'z', |
67 | 'x', |
73 | 'x', |
68 | 'c', |
74 | 'c', |
69 | 'v', |
75 | 'v', |
70 | SPECIAL, |
76 | SPECIAL, |
71 | 'b', |
77 | 'b', |
72 | 'q', |
78 | 'q', |
73 | 'w', |
79 | 'w', |
74 | 'e', |
80 | 'e', |
75 | 'r', |
81 | 'r', |
76 | 'y', |
82 | 'y', |
77 | 't', |
83 | 't', |
78 | '1', |
84 | '1', |
79 | '2', |
85 | '2', |
80 | '3', |
86 | '3', |
81 | '4', |
87 | '4', |
82 | '6', |
88 | '6', |
83 | '5', |
89 | '5', |
84 | '=', |
90 | '=', |
85 | '9', |
91 | '9', |
86 | '7', |
92 | '7', |
87 | '-', |
93 | '-', |
88 | '8', |
94 | '8', |
89 | '0', |
95 | '0', |
90 | ']', |
96 | ']', |
91 | 'o', |
97 | 'o', |
92 | 'u', |
98 | 'u', |
93 | '[', |
99 | '[', |
94 | 'i', |
100 | 'i', |
95 | 'p', |
101 | 'p', |
96 | '\n', /* Enter */ |
102 | '\n', /* Enter */ |
97 | 'l', |
103 | 'l', |
98 | 'j', |
104 | 'j', |
99 | '\'', |
105 | '\'', |
100 | 'k', |
106 | 'k', |
101 | ';', |
107 | ';', |
102 | '\\', |
108 | '\\', |
103 | ',', |
109 | ',', |
104 | '/', |
110 | '/', |
105 | 'n', |
111 | 'n', |
106 | 'm', |
112 | 'm', |
107 | '.', |
113 | '.', |
108 | '\t', /* Tab */ |
114 | '\t', /* Tab */ |
109 | ' ', |
115 | ' ', |
110 | '`', |
116 | '`', |
111 | '\b', /* Backspace */ |
117 | '\b', /* Backspace */ |
112 | SPECIAL, |
118 | SPECIAL, |
113 | SPECIAL, /* Escape */ |
119 | SPECIAL, /* Escape */ |
114 | SPECIAL, /* Ctrl */ |
120 | SPECIAL, /* Ctrl */ |
115 | SPECIAL, /* Alt */ |
121 | SPECIAL, /* Alt */ |
116 | SPECIAL, /* Shift */ |
122 | SPECIAL, /* Shift */ |
117 | SPECIAL, /* Caps-Lock */ |
123 | SPECIAL, /* Caps-Lock */ |
118 | SPECIAL, /* RAlt */ |
124 | SPECIAL, /* RAlt */ |
119 | SPECIAL, /* Left */ |
125 | SPECIAL, /* Left */ |
120 | SPECIAL, /* Right */ |
126 | SPECIAL, /* Right */ |
121 | SPECIAL, /* Down */ |
127 | SPECIAL, /* Down */ |
122 | SPECIAL, /* Up */ |
128 | SPECIAL, /* Up */ |
123 | SPECIAL, |
129 | SPECIAL, |
124 | SPECIAL, |
130 | SPECIAL, |
125 | '.', /* Keypad . */ |
131 | '.', /* Keypad . */ |
126 | SPECIAL, |
132 | SPECIAL, |
127 | '*', /* Keypad * */ |
133 | '*', /* Keypad * */ |
128 | SPECIAL, |
134 | SPECIAL, |
129 | '+', /* Keypad + */ |
135 | '+', /* Keypad + */ |
130 | SPECIAL, |
136 | SPECIAL, |
131 | SPECIAL, /* NumLock */ |
137 | SPECIAL, /* NumLock */ |
132 | SPECIAL, |
138 | SPECIAL, |
133 | SPECIAL, |
139 | SPECIAL, |
134 | SPECIAL, |
140 | SPECIAL, |
135 | '/', /* Keypad / */ |
141 | '/', /* Keypad / */ |
136 | '\n', /* Keypad Enter */ |
142 | '\n', /* Keypad Enter */ |
137 | SPECIAL, |
143 | SPECIAL, |
138 | '-', /* Keypad - */ |
144 | '-', /* Keypad - */ |
139 | SPECIAL, |
145 | SPECIAL, |
140 | SPECIAL, |
146 | SPECIAL, |
141 | SPECIAL, |
147 | SPECIAL, |
142 | '0', /* Keypad 0 */ |
148 | '0', /* Keypad 0 */ |
143 | '1', /* Keypad 1 */ |
149 | '1', /* Keypad 1 */ |
144 | '2', /* Keypad 2 */ |
150 | '2', /* Keypad 2 */ |
145 | '3', /* Keypad 3 */ |
151 | '3', /* Keypad 3 */ |
146 | '4', /* Keypad 4 */ |
152 | '4', /* Keypad 4 */ |
147 | '5', /* Keypad 5 */ |
153 | '5', /* Keypad 5 */ |
148 | '6', /* Keypad 6 */ |
154 | '6', /* Keypad 6 */ |
149 | '7', /* Keypad 7 */ |
155 | '7', /* Keypad 7 */ |
150 | SPECIAL, |
156 | SPECIAL, |
151 | '8', /* Keypad 8 */ |
157 | '8', /* Keypad 8 */ |
152 | '9', /* Keypad 9 */ |
158 | '9', /* Keypad 9 */ |
153 | SPECIAL, |
159 | SPECIAL, |
154 | SPECIAL, |
160 | SPECIAL, |
155 | SPECIAL, |
161 | SPECIAL, |
156 | SPECIAL, /* F5 */ |
162 | SPECIAL, /* F5 */ |
157 | SPECIAL, /* F6 */ |
163 | SPECIAL, /* F6 */ |
158 | SPECIAL, /* F7 */ |
164 | SPECIAL, /* F7 */ |
159 | SPECIAL, /* F3 */ |
165 | SPECIAL, /* F3 */ |
160 | SPECIAL, /* F8 */ |
166 | SPECIAL, /* F8 */ |
161 | SPECIAL, /* F9 */ |
167 | SPECIAL, /* F9 */ |
162 | SPECIAL, |
168 | SPECIAL, |
163 | SPECIAL, /* F11 */ |
169 | SPECIAL, /* F11 */ |
164 | SPECIAL, |
170 | SPECIAL, |
165 | SPECIAL, /* F13 */ |
171 | SPECIAL, /* F13 */ |
166 | SPECIAL, |
172 | SPECIAL, |
167 | SPECIAL, /* ScrollLock */ |
173 | SPECIAL, /* ScrollLock */ |
168 | SPECIAL, |
174 | SPECIAL, |
169 | SPECIAL, /* F10 */ |
175 | SPECIAL, /* F10 */ |
170 | SPECIAL, |
176 | SPECIAL, |
171 | SPECIAL, /* F12 */ |
177 | SPECIAL, /* F12 */ |
172 | SPECIAL, |
178 | SPECIAL, |
173 | SPECIAL, /* Pause */ |
179 | SPECIAL, /* Pause */ |
174 | SPECIAL, /* Insert */ |
180 | SPECIAL, /* Insert */ |
175 | SPECIAL, /* Home */ |
181 | SPECIAL, /* Home */ |
176 | SPECIAL, /* PageUp */ |
182 | SPECIAL, /* PageUp */ |
177 | SPECIAL, /* Delete */ |
183 | SPECIAL, /* Delete */ |
178 | SPECIAL, /* F4 */ |
184 | SPECIAL, /* F4 */ |
179 | SPECIAL, /* End */ |
185 | SPECIAL, /* End */ |
180 | SPECIAL, /* F2 */ |
186 | SPECIAL, /* F2 */ |
181 | SPECIAL, /* PageDown */ |
187 | SPECIAL, /* PageDown */ |
182 | SPECIAL /* F1 */ |
188 | SPECIAL /* F1 */ |
183 | }; |
189 | }; |
184 | 190 | ||
185 | 191 | ||
186 | void send_packet(const __u8 kind, index_t count, ...); |
192 | void send_packet(const __u8 kind, index_t count, ...); |
187 | 193 | ||
188 | 194 | ||
189 | static void receive_packet(__u8 *kind, index_t count, __u8 data[]) |
195 | static void receive_packet(__u8 *kind, index_t count, __u8 data[]) |
190 | { |
196 | { |
191 | cuda[B] = cuda[B] & ~TIP; |
197 | cuda[B] = cuda[B] & ~TIP; |
192 | *kind = cuda[SR]; |
198 | *kind = cuda[SR]; |
193 | 199 | ||
194 | index_t i; |
200 | index_t i; |
195 | for (i = 0; i < count; i++) |
201 | for (i = 0; i < count; i++) |
196 | data[i] = cuda[SR]; |
202 | data[i] = cuda[SR]; |
197 | 203 | ||
198 | cuda[B] = cuda[B] | TIP; |
204 | cuda[B] = cuda[B] | TIP; |
199 | } |
205 | } |
200 | 206 | ||
201 | 207 | ||
202 | /* Called from getc(). */ |
208 | /* Called from getc(). */ |
203 | static void cuda_resume(chardev_t *d) |
209 | static void cuda_resume(chardev_t *d) |
204 | { |
210 | { |
205 | } |
211 | } |
206 | 212 | ||
207 | 213 | ||
208 | /* Called from getc(). */ |
214 | /* Called from getc(). */ |
209 | static void cuda_suspend(chardev_t *d) |
215 | static void cuda_suspend(chardev_t *d) |
210 | { |
216 | { |
211 | } |
217 | } |
212 | 218 | ||
213 | 219 | ||
214 | static char key_read(chardev_t *d) |
220 | static char key_read(chardev_t *d) |
215 | { |
221 | { |
216 | char ch; |
222 | char ch; |
217 | 223 | ||
218 | ch = 0; |
224 | ch = 0; |
219 | return ch; |
225 | return ch; |
220 | } |
226 | } |
221 | 227 | ||
222 | 228 | ||
223 | static chardev_t kbrd; |
229 | static chardev_t kbrd; |
224 | static chardev_operations_t ops = { |
230 | static chardev_operations_t ops = { |
225 | .suspend = cuda_suspend, |
231 | .suspend = cuda_suspend, |
226 | .resume = cuda_resume, |
232 | .resume = cuda_resume, |
227 | .read = key_read |
233 | .read = key_read |
228 | }; |
234 | }; |
229 | 235 | ||
230 | 236 | ||
231 | int cuda_get_scancode(void) |
237 | int cuda_get_scancode(void) |
232 | { |
238 | { |
233 | __u8 kind; |
239 | __u8 kind; |
234 | __u8 data[4]; |
240 | __u8 data[4]; |
235 | 241 | ||
236 | receive_packet(&kind, 4, data); |
242 | receive_packet(&kind, 4, data); |
237 | 243 | ||
238 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
244 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
239 | return data[2]; |
245 | return data[2]; |
240 | 246 | ||
241 | return -1; |
247 | return -1; |
242 | } |
248 | } |
243 | 249 | ||
244 | static void cuda_irq(int n, istate_t *istate) |
250 | static void cuda_irq(int n, istate_t *istate) |
245 | { |
251 | { |
246 | int scan_code = cuda_get_scancode(); |
252 | int scan_code = cuda_get_scancode(); |
247 | 253 | ||
248 | if (scan_code != -1) { |
254 | if (scan_code != -1) { |
249 | __u8 scancode = (__u8) scan_code; |
255 | __u8 scancode = (__u8) scan_code; |
250 | if ((scancode & 0x80) != 0x80) |
256 | if ((scancode & 0x80) != 0x80) |
251 | chardev_push_character(&kbrd, lchars[scancode & 0x7f]); |
257 | chardev_push_character(&kbrd, lchars[scancode & 0x7f]); |
252 | } |
258 | } |
253 | } |
259 | } |
254 | 260 | ||
255 | 261 | ||
256 | void cuda_init(__address base, size_t size) |
262 | void cuda_init(__address base, size_t size) |
257 | { |
263 | { |
258 | cuda = (__u8 *) hw_map(base, size); |
264 | cuda = (__u8 *) hw_map(base, size); |
259 | 265 | ||
260 | int_register(CUDA_IRQ, "cuda", cuda_irq); |
266 | int_register(CUDA_IRQ, "cuda", cuda_irq); |
261 | pic_enable_interrupt(CUDA_IRQ); |
267 | pic_enable_interrupt(CUDA_IRQ); |
262 | 268 | ||
263 | chardev_initialize("cuda_kbd", &kbrd, &ops); |
269 | chardev_initialize("cuda_kbd", &kbrd, &ops); |
264 | stdin = &kbrd; |
270 | stdin = &kbrd; |
265 | 271 | ||
266 | sysinfo_set_item_val("cuda", NULL, true); |
272 | sysinfo_set_item_val("cuda", NULL, true); |
267 | sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ); |
273 | sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ); |
268 | } |
274 | } |
269 | 275 | ||
270 | 276 | ||
271 | void send_packet(const __u8 kind, index_t count, ...) |
277 | void send_packet(const __u8 kind, index_t count, ...) |
272 | { |
278 | { |
273 | index_t i; |
279 | index_t i; |
274 | va_list va; |
280 | va_list va; |
275 | 281 | ||
276 | cuda[B] = cuda[B] | TIP; |
282 | cuda[B] = cuda[B] | TIP; |
277 | cuda[ACR] = cuda[ACR] | SR_OUT; |
283 | cuda[ACR] = cuda[ACR] | SR_OUT; |
278 | cuda[SR] = kind; |
284 | cuda[SR] = kind; |
279 | cuda[B] = cuda[B] & ~TIP; |
285 | cuda[B] = cuda[B] & ~TIP; |
280 | 286 | ||
281 | va_start(va, count); |
287 | va_start(va, count); |
282 | 288 | ||
283 | for (i = 0; i < count; i++) { |
289 | for (i = 0; i < count; i++) { |
284 | cuda[ACR] = cuda[ACR] | SR_OUT; |
290 | cuda[ACR] = cuda[ACR] | SR_OUT; |
285 | cuda[SR] = va_arg(va, int); |
291 | cuda[SR] = va_arg(va, int); |
286 | cuda[B] = cuda[B] | TACK; |
292 | cuda[B] = cuda[B] | TACK; |
287 | } |
293 | } |
288 | 294 | ||
289 | va_end(va); |
295 | va_end(va); |
290 | 296 | ||
291 | cuda[B] = cuda[B] | TIP; |
297 | cuda[B] = cuda[B] | TIP; |
292 | } |
298 | } |
293 | 299 | ||
294 | 300 | ||
295 | void cpu_halt(void) { |
301 | void cpu_halt(void) { |
296 | #ifdef CONFIG_POWEROFF |
302 | #ifdef CONFIG_POWEROFF |
297 | send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN); |
303 | send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN); |
298 | #endif |
304 | #endif |
299 | asm volatile ( |
305 | asm volatile ( |
300 | "b 0\n" |
306 | "b 0\n" |
301 | ); |
307 | ); |
302 | } |
308 | } |
- | 309 | ||
- | 310 | /** @} |
|
- | 311 | */ |
|
- | 312 | ||
303 | 313 |