Deleted Added
sdiff udiff text old ( 162711 ) new ( 163890 )
full compact
1/*-
2 * Copyright (c) 2003 Jake Burkholder.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/uart/uart_kbd_sun.c 162711 2006-09-27 19:57:02Z ru $");
29
30#include "opt_compat.h"
31#include "opt_kbd.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/bus.h>
36#include <sys/interrupt.h>
37#include <sys/kbio.h>
38#include <sys/kernel.h>
39#include <sys/malloc.h>
40#include <sys/ktr.h>
41
42#include <machine/bus.h>
43#include <machine/resource.h>
44
45#include <sys/rman.h>
46
47#include <dev/kbd/kbdreg.h>
48
49#include <dev/uart/uart.h>
50#include <dev/uart/uart_bus.h>
51#include <dev/uart/uart_cpu.h>
52
53#include <dev/uart/uart_kbd_sun.h>
54#include <dev/uart/uart_kbd_sun_tables.h>
55
56#include "uart_if.h"
57
58#define SUNKBD_BUF_SIZE 128
59
60#define TODO printf("%s: unimplemented", __func__)
61
62struct sunkbd_softc {
63 keyboard_t sc_kbd;
64 struct uart_softc *sc_uart;
65 struct uart_devinfo *sc_sysdev;
66
67 struct callout sc_repeat_callout;
68 int sc_repeat_key;
69
70 int sc_accents;
71 int sc_mode;
72 int sc_polling;
73 int sc_repeating;
74 int sc_state;
75};
76
77static int sunkbd_configure(int flags);
78static int sunkbd_probe_keyboard(struct uart_devinfo *di);
79
80static int sunkbd_probe(int unit, void *arg, int flags);
81static int sunkbd_init(int unit, keyboard_t **kbdp, void *arg, int flags);
82static int sunkbd_term(keyboard_t *kbd);

--- 9 unchanged lines hidden (view full) ---

92static int sunkbd_lock(keyboard_t *kbd, int lock);
93static void sunkbd_clear_state(keyboard_t *kbd);
94static int sunkbd_get_state(keyboard_t *kbd, void *buf, size_t len);
95static int sunkbd_set_state(keyboard_t *kbd, void *buf, size_t len);
96static int sunkbd_poll_mode(keyboard_t *kbd, int on);
97static void sunkbd_diag(keyboard_t *kbd, int level);
98
99static void sunkbd_repeat(void *v);
100
101static keyboard_switch_t sunkbdsw = {
102 sunkbd_probe,
103 sunkbd_init,
104 sunkbd_term,
105 sunkbd_intr,
106 sunkbd_test_if,
107 sunkbd_enable,

--- 12 unchanged lines hidden (view full) ---

120 sunkbd_diag
121};
122
123KEYBOARD_DRIVER(sunkbd, sunkbdsw, sunkbd_configure);
124
125static struct sunkbd_softc sunkbd_softc;
126static struct uart_devinfo uart_keyboard;
127
128static fkeytab_t fkey_tab[96] = {
129/* 01-04 */ {"\033[M", 3}, {"\033[N", 3}, {"\033[O", 3}, {"\033[P", 3},
130/* 05-08 */ {"\033[Q", 3}, {"\033[R", 3}, {"\033[S", 3}, {"\033[T", 3},
131/* 09-12 */ {"\033[U", 3}, {"\033[V", 3}, {"\033[W", 3}, {"\033[X", 3},
132/* 13-16 */ {"\033[Y", 3}, {"\033[Z", 3}, {"\033[a", 3}, {"\033[b", 3},
133/* 17-20 */ {"\033[c", 3}, {"\033[d", 3}, {"\033[e", 3}, {"\033[f", 3},
134/* 21-24 */ {"\033[g", 3}, {"\033[h", 3}, {"\033[i", 3}, {"\033[j", 3},
135/* 25-28 */ {"\033[k", 3}, {"\033[l", 3}, {"\033[m", 3}, {"\033[n", 3},
136/* 29-32 */ {"\033[o", 3}, {"\033[p", 3}, {"\033[q", 3}, {"\033[r", 3},
137/* 33-36 */ {"\033[s", 3}, {"\033[t", 3}, {"\033[u", 3}, {"\033[v", 3},
138/* 37-40 */ {"\033[w", 3}, {"\033[x", 3}, {"\033[y", 3}, {"\033[z", 3},
139/* 41-44 */ {"\033[@", 3}, {"\033[[", 3}, {"\033[\\",3}, {"\033[]", 3},
140/* 45-48 */ {"\033[^", 3}, {"\033[_", 3}, {"\033[`", 3}, {"\033[{", 3},
141/* 49-52 */ {"\033[H", 3}, {"\033[A", 3}, {"\033[I", 3}, {"-" , 1},
142/* 53-56 */ {"\033[D", 3}, {"\033[E", 3}, {"\033[C", 3}, {"+" , 1},
143/* 57-60 */ {"\033[F", 3}, {"\033[B", 3}, {"\033[G", 3}, {"\033[L", 3},
144/* 61-64 */ {"\177", 1}, {"\033[J", 3}, {"\033[~", 3}, {"\033[}", 3},
145/* 65-68 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} ,
146/* 69-72 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} ,
147/* 73-76 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} ,
148/* 77-80 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} ,
149/* 81-84 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} ,
150/* 85-88 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} ,
151/* 89-92 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} ,
152/* 93-96 */ {"", 0} , {"", 0} , {"", 0} , {"", 0}
153};
154
155static int
156sunkbd_probe_keyboard(struct uart_devinfo *di)
157{
158 int tries;
159
160 for (tries = 5; tries != 0; tries--) {
161 int ltries;
162
163 uart_putc(di, SKBD_CMD_RESET);
164 for (ltries = 1000; ltries != 0; ltries--) {
165 if (uart_poll(di) == SKBD_RSP_RESET)
166 break;
167 DELAY(1000);
168 }
169 if (ltries == 0)
170 continue;
171 for (ltries = 1000; ltries != 0; ltries--) {
172 if (uart_poll(di) == SKBD_RSP_IDLE)
173 break;
174 DELAY(1000);
175 }
176 if (ltries == 0)
177 continue;
178 uart_putc(di, SKBD_CMD_LAYOUT);
179 if (uart_getc(di) != SKBD_RSP_LAYOUT)
180 break;
181 return (uart_getc(di));
182 }
183 return (-1);
184}
185
186static int sunkbd_attach(struct uart_softc *sc);
187static void sunkbd_uart_intr(void *arg);
188
189static int

--- 17 unchanged lines hidden (view full) ---

207 if (uart_probe(&uart_keyboard))
208 return (0);
209 uart_init(&uart_keyboard);
210
211 uart_keyboard.type = UART_DEV_KEYBOARD;
212 uart_keyboard.attach = sunkbd_attach;
213 uart_add_sysdev(&uart_keyboard);
214
215 if (sunkbd_probe_keyboard(&uart_keyboard) == -1)
216 return (0);
217
218 sc = &sunkbd_softc;
219 callout_init(&sc->sc_repeat_callout, 0);
220 sc->sc_repeat_key = -1;
221 sc->sc_repeating = 0;
222
223 kbd_init_struct(&sc->sc_kbd, "sunkbd", KB_OTHER, 0, 0, 0, 0);
224 kbd_set_maps(&sc->sc_kbd, &keymap_sun_us_unix_kbd,
225 &accentmap_sun_us_unix_kbd, fkey_tab,
226 sizeof(fkey_tab) / sizeof(fkey_tab[0]));
227 sc->sc_mode = K_XLATE;
228 kbd_register(&sc->sc_kbd);
229
230 sc->sc_sysdev = &uart_keyboard;
231
232 found:
233 /* Return number of found keyboards. */
234 return (1);

--- 44 unchanged lines hidden (view full) ---

279 return;
280
281 if (pend & SER_INT_RXREADY) {
282 if (KBD_IS_ACTIVE(&sc->sc_kbd) && KBD_IS_BUSY(&sc->sc_kbd)) {
283 sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd,
284 KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg);
285 }
286 }
287
288}
289
290static int
291sunkbd_probe(int unit, void *arg, int flags)
292{
293 TODO;
294 return (0);
295}
296
297static int
298sunkbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
299{
300 TODO;
301 return (0);
302}
303
304static int
305sunkbd_term(keyboard_t *kbd)
306{
307 TODO;
308 return (0);
309}
310
311static int
312sunkbd_intr(keyboard_t *kbd, void *arg)
313{
314 TODO;
315 return (0);
316}
317
318static int
319sunkbd_test_if(keyboard_t *kbd)
320{
321 TODO;
322 return (0);
323}
324
325static int
326sunkbd_enable(keyboard_t *kbd)
327{
328 KBD_ACTIVATE(kbd);
329 return (0);
330}
331
332static int
333sunkbd_disable(keyboard_t *kbd)
334{
335 KBD_DEACTIVATE(kbd);
336 return (0);
337}
338
339static int
340sunkbd_read(keyboard_t *kbd, int wait)
341{
342 TODO;
343 return (0);
344}
345
346static int
347sunkbd_check(keyboard_t *kbd)
348{
349 TODO;
350 return (0);
351}
352
353static u_int
354sunkbd_read_char(keyboard_t *kbd, int wait)
355{
356 struct sunkbd_softc *sc;
357 int action;
358 int key;
359
360 sc = (struct sunkbd_softc *)kbd;
361 if (sc->sc_repeating) {
362 sc->sc_repeating = 0;
363 callout_reset(&sc->sc_repeat_callout, hz / 10,
364 sunkbd_repeat, sc);
365 key = sc->sc_repeat_key;
366 if (sc->sc_mode == K_RAW)
367 return (key);
368 else
369 return genkbd_keyaction(kbd, key & 0x7f, key & 0x80,
370 &sc->sc_state, &sc->sc_accents);
371 }
372
373 for (;;) {
374 /* XXX compose */
375
376 if (sc->sc_uart != NULL && !uart_rx_empty(sc->sc_uart)) {
377 key = uart_rx_get(sc->sc_uart);
378 } else if (sc->sc_polling != 0 && sc->sc_sysdev != NULL) {
379 if (wait)
380 key = uart_getc(sc->sc_sysdev);
381 else if ((key = uart_poll(sc->sc_sysdev)) == -1)
382 return (NOKEY);
383 } else {
384 return (NOKEY);
385 }
386
387 switch (key) {
388 case SKBD_RSP_IDLE:
389 break;
390 default:
391 ++kbd->kb_count;
392
393 if ((key & 0x80) == 0) {
394 callout_reset(&sc->sc_repeat_callout, hz / 2,
395 sunkbd_repeat, sc);
396 sc->sc_repeat_key = key;
397 } else {
398 if (sc->sc_repeat_key == (key & 0x7f)) {
399 callout_stop(&sc->sc_repeat_callout);
400 sc->sc_repeat_key = -1;
401 }
402 }
403
404 if (sc->sc_mode == K_RAW)
405 return (key);
406
407 action = genkbd_keyaction(kbd, key & 0x7f, key & 0x80,
408 &sc->sc_state, &sc->sc_accents);
409 if (action != NOKEY)
410 return (action);
411 break;
412 }
413 }
414 return (0);
415}
416
417static int
418sunkbd_check_char(keyboard_t *kbd)
419{
420 TODO;
421 return (0);
422}
423
424static int
425sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data)
426{
427 struct sunkbd_softc *sc;
428 int error;
429#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5)
430 int ival;
431#endif
432
433 sc = (struct sunkbd_softc *)kbd;
434 error = 0;
435 switch (cmd) {
436 case KDGKBMODE:

--- 35 unchanged lines hidden (view full) ---

472 data = (caddr_t)&ival;
473 /* FALLTHROUGH */
474#endif
475 case KDSETLED:
476 if (*(int *)data & ~LOCK_MASK) {
477 error = EINVAL;
478 break;
479 }
480 if (sc->sc_uart == NULL)
481 break;
482 sc->sc_uart->sc_txdatasz = 2;
483 sc->sc_uart->sc_txbuf[0] = SKBD_CMD_SETLED;
484 sc->sc_uart->sc_txbuf[1] = 0;
485 if (*(int *)data & CLKED)
486 sc->sc_uart->sc_txbuf[1] |= SKBD_LED_CAPSLOCK;
487 if (*(int *)data & NLKED)
488 sc->sc_uart->sc_txbuf[1] |= SKBD_LED_NUMLOCK;
489 if (*(int *)data & SLKED)
490 sc->sc_uart->sc_txbuf[1] |= SKBD_LED_SCROLLLOCK;
491 UART_TRANSMIT(sc->sc_uart);
492 KBD_LED_VAL(kbd) = *(int *)data;
493 break;
494 case KDGKBSTATE:
495 *(int *)data = sc->sc_state & LOCK_MASK;
496 break;
497#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5)
498 case _IO('K', 20):
499 ival = IOCPARM_IVAL(data);

--- 19 unchanged lines hidden (view full) ---

519 return (genkbd_commonioctl(kbd, cmd, data));
520 }
521 return (error);
522}
523
524static int
525sunkbd_lock(keyboard_t *kbd, int lock)
526{
527 TODO;
528 return (0);
529}
530
531static void
532sunkbd_clear_state(keyboard_t *kbd)
533{
534 /* TODO; */
535}
536
537static int
538sunkbd_get_state(keyboard_t *kbd, void *buf, size_t len)
539{
540 TODO;
541 return (0);
542}
543
544static int
545sunkbd_set_state(keyboard_t *kbd, void *buf, size_t len)
546{
547 TODO;
548 return (0);
549}
550
551static int
552sunkbd_poll_mode(keyboard_t *kbd, int on)
553{
554 struct sunkbd_softc *sc;

--- 4 unchanged lines hidden (view full) ---

559 else
560 sc->sc_polling--;
561 return (0);
562}
563
564static void
565sunkbd_diag(keyboard_t *kbd, int level)
566{
567 TODO;
568}
569
570static void
571sunkbd_repeat(void *v)
572{
573 struct sunkbd_softc *sc = v;
574
575 if (KBD_IS_ACTIVE(&sc->sc_kbd) && KBD_IS_BUSY(&sc->sc_kbd)) {
576 if (sc->sc_repeat_key != -1) {
577 sc->sc_repeating = 1;
578 sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd,
579 KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg);
580 }
581 }
582}