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