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