1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
5 * All rights reserved.
6 *
7 * Based on dev/usb/input/ukbd.c
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD: releng/12.0/sys/arm/versatile/pl050.c 326258 2017-11-27 15:04:10Z pfg $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/bus.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/malloc.h>
40 #include <sys/rman.h>
41 #include <sys/proc.h>
42 #include <sys/sched.h>
43 #include <sys/kdb.h>
44
45 #include <machine/bus.h>
46 #include <machine/cpu.h>
47 #include <machine/intr.h>
48
49 #include <dev/ofw/openfirm.h>
50 #include <dev/ofw/ofw_bus.h>
51 #include <dev/ofw/ofw_bus_subr.h>
52
53 #include <sys/ioccom.h>
54 #include <sys/filio.h>
55 #include <sys/tty.h>
56 #include <sys/kbio.h>
57
58 #include <dev/kbd/kbdreg.h>
59
60 #include <machine/bus.h>
61
62 #include <dev/kbd/kbdtables.h>
63
64 #define KMI_LOCK() mtx_lock(&Giant)
65 #define KMI_UNLOCK() mtx_unlock(&Giant)
66
67 #ifdef INVARIANTS
68 /*
69 * Assert that the lock is held in all contexts
70 * where the code can be executed.
71 */
72 #define KMI_LOCK_ASSERT() mtx_assert(&Giant, MA_OWNED)
73 /*
74 * Assert that the lock is held in the contexts
75 * where it really has to be so.
76 */
77 #define KMI_CTX_LOCK_ASSERT() \
78 do { \
79 if (!kdb_active && panicstr == NULL) \
80 mtx_assert(&Giant, MA_OWNED); \
81 } while (0)
82 #else
83 #define KMI_LOCK_ASSERT() (void)0
84 #define KMI_CTX_LOCK_ASSERT() (void)0
85 #endif
86
87 #define KMICR 0x00
88 #define KMICR_TYPE_NONPS2 (1 << 5)
89 #define KMICR_RXINTREN (1 << 4)
90 #define KMICR_TXINTREN (1 << 3)
91 #define KMICR_EN (1 << 2)
92 #define KMICR_FKMID (1 << 1)
93 #define KMICR_FKMIC (1 << 0)
94 #define KMISTAT 0x04
95 #define KMISTAT_TXEMPTY (1 << 6)
96 #define KMISTAT_TXBUSY (1 << 5)
97 #define KMISTAT_RXFULL (1 << 4)
98 #define KMISTAT_RXBUSY (1 << 3)
99 #define KMISTAT_RXPARITY (1 << 2)
100 #define KMISTAT_KMIC (1 << 1)
101 #define KMISTAT_KMID (1 << 0)
102 #define KMIDATA 0x08
103 #define KMICLKDIV 0x0C
104 #define KMIIR 0x10
105 #define KMIIR_TXINTR (1 << 1)
106 #define KMIIR_RXINTR (1 << 0)
107
108 #define KMI_DRIVER_NAME "kmi"
109 #define KMI_NFKEY (sizeof(fkey_tab)/sizeof(fkey_tab[0])) /* units */
110
111 #define SET_SCANCODE_SET 0xf0
112
113 struct kmi_softc {
114 device_t sc_dev;
115 keyboard_t sc_kbd;
116 keymap_t sc_keymap;
117 accentmap_t sc_accmap;
118 fkeytab_t sc_fkeymap[KMI_NFKEY];
119
120 struct resource* sc_mem_res;
121 struct resource* sc_irq_res;
122 void* sc_intr_hl;
123
124 int sc_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
125 int sc_state; /* shift/lock key state */
126 int sc_accents; /* accent key index (> 0) */
127 uint32_t sc_flags; /* flags */
128 #define KMI_FLAG_COMPOSE 0x00000001
129 #define KMI_FLAG_POLLING 0x00000002
130
131 struct thread *sc_poll_thread;
132 };
133
134 /* Read/Write macros for Timer used as timecounter */
135 #define pl050_kmi_read_4(sc, reg) \
136 bus_read_4((sc)->sc_mem_res, (reg))
137
138 #define pl050_kmi_write_4(sc, reg, val) \
139 bus_write_4((sc)->sc_mem_res, (reg), (val))
140
141 /* prototypes */
142 static void kmi_set_leds(struct kmi_softc *, uint8_t);
143 static int kmi_set_typematic(keyboard_t *, int);
144 static uint32_t kmi_read_char(keyboard_t *, int);
145 static void kmi_clear_state(keyboard_t *);
146 static int kmi_ioctl(keyboard_t *, u_long, caddr_t);
147 static int kmi_enable(keyboard_t *);
148 static int kmi_disable(keyboard_t *);
149
150 static int kmi_attached = 0;
151
152 /* early keyboard probe, not supported */
153 static int
154 kmi_configure(int flags)
155 {
156 return (0);
157 }
158
159 /* detect a keyboard, not used */
160 static int
161 kmi_probe(int unit, void *arg, int flags)
162 {
163 return (ENXIO);
164 }
165
166 /* reset and initialize the device, not used */
167 static int
168 kmi_init(int unit, keyboard_t **kbdp, void *arg, int flags)
169 {
170 return (ENXIO);
171 }
172
173 /* test the interface to the device, not used */
174 static int
175 kmi_test_if(keyboard_t *kbd)
176 {
177 return (0);
178 }
179
180 /* finish using this keyboard, not used */
181 static int
182 kmi_term(keyboard_t *kbd)
183 {
184 return (ENXIO);
185 }
186
187 /* keyboard interrupt routine, not used */
188 static int
189 kmi_intr(keyboard_t *kbd, void *arg)
190 {
191
192 return (0);
193 }
194
195 /* lock the access to the keyboard, not used */
196 static int
197 kmi_lock(keyboard_t *kbd, int lock)
198 {
199 return (1);
200 }
201
202 /*
203 * Enable the access to the device; until this function is called,
204 * the client cannot read from the keyboard.
205 */
206 static int
207 kmi_enable(keyboard_t *kbd)
208 {
209
210 KMI_LOCK();
211 KBD_ACTIVATE(kbd);
212 KMI_UNLOCK();
213
214 return (0);
215 }
216
217 /* disallow the access to the device */
218 static int
219 kmi_disable(keyboard_t *kbd)
220 {
221
222 KMI_LOCK();
223 KBD_DEACTIVATE(kbd);
224 KMI_UNLOCK();
225
226 return (0);
227 }
228
229 /* check if data is waiting */
230 static int
231 kmi_check(keyboard_t *kbd)
232 {
233 struct kmi_softc *sc = kbd->kb_data;
234 uint32_t reg;
235
236 KMI_CTX_LOCK_ASSERT();
237
238 if (!KBD_IS_ACTIVE(kbd))
239 return (0);
240
241 reg = pl050_kmi_read_4(sc, KMIIR);
242 return (reg & KMIIR_RXINTR);
243 }
244
245 /* check if char is waiting */
246 static int
247 kmi_check_char_locked(keyboard_t *kbd)
248 {
249 KMI_CTX_LOCK_ASSERT();
250
251 if (!KBD_IS_ACTIVE(kbd))
252 return (0);
253
254 return (kmi_check(kbd));
255 }
256
257 static int
258 kmi_check_char(keyboard_t *kbd)
259 {
260 int result;
261
262 KMI_LOCK();
263 result = kmi_check_char_locked(kbd);
264 KMI_UNLOCK();
265
266 return (result);
267 }
268
269 /* read one byte from the keyboard if it's allowed */
270 /* Currently unused. */
271 static int
272 kmi_read(keyboard_t *kbd, int wait)
273 {
274 KMI_CTX_LOCK_ASSERT();
275
276 if (!KBD_IS_ACTIVE(kbd))
277 return (-1);
278
279 ++(kbd->kb_count);
280 printf("Implement ME: %s\n", __func__);
281 return (0);
282 }
283
284 /* read char from the keyboard */
285 static uint32_t
286 kmi_read_char_locked(keyboard_t *kbd, int wait)
287 {
288 struct kmi_softc *sc = kbd->kb_data;
289 uint32_t reg, data;
290
291 KMI_CTX_LOCK_ASSERT();
292
293 if (!KBD_IS_ACTIVE(kbd))
294 return (NOKEY);
295
296 reg = pl050_kmi_read_4(sc, KMIIR);
297 if (reg & KMIIR_RXINTR) {
298 data = pl050_kmi_read_4(sc, KMIDATA);
299 return (data);
300 }
301
302 ++kbd->kb_count;
303 return (NOKEY);
304 }
305
306 /* Currently wait is always false. */
307 static uint32_t
308 kmi_read_char(keyboard_t *kbd, int wait)
309 {
310 uint32_t keycode;
311
312 KMI_LOCK();
313 keycode = kmi_read_char_locked(kbd, wait);
314 KMI_UNLOCK();
315
316 return (keycode);
317 }
318
319 /* some useful control functions */
320 static int
321 kmi_ioctl_locked(keyboard_t *kbd, u_long cmd, caddr_t arg)
322 {
323 struct kmi_softc *sc = kbd->kb_data;
324 int i;
325 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
326 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
327 int ival;
328
329 #endif
330
331 KMI_LOCK_ASSERT();
332
333 switch (cmd) {
334 case KDGKBMODE: /* get keyboard mode */
335 *(int *)arg = sc->sc_mode;
336 break;
337 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
338 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
339 case _IO('K', 7):
340 ival = IOCPARM_IVAL(arg);
341 arg = (caddr_t)&ival;
342 /* FALLTHROUGH */
343 #endif
344 case KDSKBMODE: /* set keyboard mode */
345 switch (*(int *)arg) {
346 case K_XLATE:
347 if (sc->sc_mode != K_XLATE) {
348 /* make lock key state and LED state match */
349 sc->sc_state &= ~LOCK_MASK;
350 sc->sc_state |= KBD_LED_VAL(kbd);
351 }
352 /* FALLTHROUGH */
353 case K_RAW:
354 case K_CODE:
355 if (sc->sc_mode != *(int *)arg) {
356 if ((sc->sc_flags & KMI_FLAG_POLLING) == 0)
357 kmi_clear_state(kbd);
358 sc->sc_mode = *(int *)arg;
359 }
360 break;
361 default:
362 return (EINVAL);
363 }
364 break;
365
366 case KDGETLED: /* get keyboard LED */
367 *(int *)arg = KBD_LED_VAL(kbd);
368 break;
369 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
370 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
371 case _IO('K', 66):
372 ival = IOCPARM_IVAL(arg);
373 arg = (caddr_t)&ival;
374 /* FALLTHROUGH */
375 #endif
376 case KDSETLED: /* set keyboard LED */
377 /* NOTE: lock key state in "sc_state" won't be changed */
378 if (*(int *)arg & ~LOCK_MASK)
379 return (EINVAL);
380
381 i = *(int *)arg;
382
383 /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
384 if (sc->sc_mode == K_XLATE &&
385 kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
386 if (i & ALKED)
387 i |= CLKED;
388 else
389 i &= ~CLKED;
390 }
391 if (KBD_HAS_DEVICE(kbd))
392 kmi_set_leds(sc, i);
393
394 KBD_LED_VAL(kbd) = *(int *)arg;
395 break;
396 case KDGKBSTATE: /* get lock key state */
397 *(int *)arg = sc->sc_state & LOCK_MASK;
398 break;
399 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
400 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
401 case _IO('K', 20):
402 ival = IOCPARM_IVAL(arg);
403 arg = (caddr_t)&ival;
404 /* FALLTHROUGH */
405 #endif
406 case KDSKBSTATE: /* set lock key state */
407 if (*(int *)arg & ~LOCK_MASK) {
408 return (EINVAL);
409 }
410 sc->sc_state &= ~LOCK_MASK;
411 sc->sc_state |= *(int *)arg;
412
413 /* set LEDs and quit */
414 return (kmi_ioctl(kbd, KDSETLED, arg));
415
416 case KDSETREPEAT: /* set keyboard repeat rate (new
417 * interface) */
418 if (!KBD_HAS_DEVICE(kbd)) {
419 return (0);
420 }
421 if (((int *)arg)[1] < 0) {
422 return (EINVAL);
423 }
424 if (((int *)arg)[0] < 0) {
425 return (EINVAL);
426 }
427 if (((int *)arg)[0] < 200) /* fastest possible value */
428 kbd->kb_delay1 = 200;
429 else
430 kbd->kb_delay1 = ((int *)arg)[0];
431 kbd->kb_delay2 = ((int *)arg)[1];
432 return (0);
433
434 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
435 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
436 case _IO('K', 67):
437 ival = IOCPARM_IVAL(arg);
438 arg = (caddr_t)&ival;
439 /* FALLTHROUGH */
440 #endif
441 case KDSETRAD: /* set keyboard repeat rate (old
442 * interface) */
443 return (kmi_set_typematic(kbd, *(int *)arg));
444
445 case PIO_KEYMAP: /* set keyboard translation table */
446 case OPIO_KEYMAP: /* set keyboard translation table
447 * (compat) */
448 case PIO_KEYMAPENT: /* set keyboard translation table
449 * entry */
450 case PIO_DEADKEYMAP: /* set accent key translation table */
451 sc->sc_accents = 0;
452 /* FALLTHROUGH */
453 default:
454 return (genkbd_commonioctl(kbd, cmd, arg));
455 }
456
457 return (0);
458 }
459
460 static int
461 kmi_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
462 {
463 int result;
464
465 /*
466 * XXX KDGKBSTATE, KDSKBSTATE and KDSETLED can be called from any
467 * context where printf(9) can be called, which among other things
468 * includes interrupt filters and threads with any kinds of locks
469 * already held. For this reason it would be dangerous to acquire
470 * the Giant here unconditionally. On the other hand we have to
471 * have it to handle the ioctl.
472 * So we make our best effort to auto-detect whether we can grab
473 * the Giant or not. Blame syscons(4) for this.
474 */
475 switch (cmd) {
476 case KDGKBSTATE:
477 case KDSKBSTATE:
478 case KDSETLED:
479 if (!mtx_owned(&Giant) && !SCHEDULER_STOPPED())
480 return (EDEADLK); /* best I could come up with */
481 /* FALLTHROUGH */
482 default:
483 KMI_LOCK();
484 result = kmi_ioctl_locked(kbd, cmd, arg);
485 KMI_UNLOCK();
486 return (result);
487 }
488 }
489
490 /* clear the internal state of the keyboard */
491 static void
492 kmi_clear_state(keyboard_t *kbd)
493 {
494 struct kmi_softc *sc = kbd->kb_data;
495
496 KMI_CTX_LOCK_ASSERT();
497
498 sc->sc_flags &= ~(KMI_FLAG_COMPOSE | KMI_FLAG_POLLING);
499 sc->sc_state &= LOCK_MASK; /* preserve locking key state */
500 sc->sc_accents = 0;
501 }
502
503 /* save the internal state, not used */
504 static int
505 kmi_get_state(keyboard_t *kbd, void *buf, size_t len)
506 {
507 return (len == 0) ? 1 : -1;
508 }
509
510 /* set the internal state, not used */
511 static int
512 kmi_set_state(keyboard_t *kbd, void *buf, size_t len)
513 {
514 return (EINVAL);
515 }
516
517 static int
518 kmi_poll(keyboard_t *kbd, int on)
519 {
520 struct kmi_softc *sc = kbd->kb_data;
521
522 KMI_LOCK();
523 if (on) {
524 sc->sc_flags |= KMI_FLAG_POLLING;
525 sc->sc_poll_thread = curthread;
526 } else {
527 sc->sc_flags &= ~KMI_FLAG_POLLING;
528 }
529 KMI_UNLOCK();
530
531 return (0);
532 }
533
534 /* local functions */
535
536 static void
537 kmi_set_leds(struct kmi_softc *sc, uint8_t leds)
538 {
539
540 KMI_LOCK_ASSERT();
541
542 /* start transfer, if not already started */
543 printf("Implement me: %s\n", __func__);
544 }
545
546 static int
547 kmi_set_typematic(keyboard_t *kbd, int code)
548 {
549 static const int delays[] = {250, 500, 750, 1000};
550 static const int rates[] = {34, 38, 42, 46, 50, 55, 59, 63,
551 68, 76, 84, 92, 100, 110, 118, 126,
552 136, 152, 168, 184, 200, 220, 236, 252,
553 272, 304, 336, 368, 400, 440, 472, 504};
554
555 if (code & ~0x7f) {
556 return (EINVAL);
557 }
558 kbd->kb_delay1 = delays[(code >> 5) & 3];
559 kbd->kb_delay2 = rates[code & 0x1f];
560 return (0);
561 }
562
563 static keyboard_switch_t kmisw = {
564 .probe = &kmi_probe,
565 .init = &kmi_init,
566 .term = &kmi_term,
567 .intr = &kmi_intr,
568 .test_if = &kmi_test_if,
569 .enable = &kmi_enable,
570 .disable = &kmi_disable,
571 .read = &kmi_read,
572 .check = &kmi_check,
573 .read_char = &kmi_read_char,
574 .check_char = &kmi_check_char,
575 .ioctl = &kmi_ioctl,
576 .lock = &kmi_lock,
577 .clear_state = &kmi_clear_state,
578 .get_state = &kmi_get_state,
579 .set_state = &kmi_set_state,
580 .get_fkeystr = &genkbd_get_fkeystr,
581 .poll = &kmi_poll,
582 .diag = &genkbd_diag,
583 };
584
585 KEYBOARD_DRIVER(kmi, kmisw, kmi_configure);
586
587 static void
588 pl050_kmi_intr(void *arg)
589 {
590 struct kmi_softc *sc = arg;
591 uint32_t c;
592
593 KMI_CTX_LOCK_ASSERT();
594
595 if ((sc->sc_flags & KMI_FLAG_POLLING) != 0)
596 return;
597
598 if (KBD_IS_ACTIVE(&sc->sc_kbd) &&
599 KBD_IS_BUSY(&sc->sc_kbd)) {
600 /* let the callback function process the input */
601 (sc->sc_kbd.kb_callback.kc_func) (&sc->sc_kbd, KBDIO_KEYINPUT,
602 sc->sc_kbd.kb_callback.kc_arg);
603 } else {
604 /* read and discard the input, no one is waiting for it */
605 do {
606 c = kmi_read_char_locked(&sc->sc_kbd, 0);
607 } while (c != NOKEY);
608 }
609
610 }
611
612 static int
613 pl050_kmi_probe(device_t dev)
614 {
615
616 if (!ofw_bus_status_okay(dev))
617 return (ENXIO);
618
619 /*
620 * PL050 is plain PS2 port that pushes bytes to/from computer
621 * VersatilePB has two such ports and QEMU simulates keyboard
622 * connected to port #0 and mouse connected to port #1. This
623 * information can't be obtained from device tree so we just
624 * hardcode this knowledge here. We attach keyboard driver to
625 * port #0 and ignore port #1
626 */
627 if (kmi_attached)
628 return (ENXIO);
629
630 if (ofw_bus_is_compatible(dev, "arm,pl050")) {
631 device_set_desc(dev, "PL050 Keyboard/Mouse Interface");
632 return (BUS_PROBE_DEFAULT);
633 }
634
635 return (ENXIO);
636 }
637
638 static int
639 pl050_kmi_attach(device_t dev)
640 {
641 struct kmi_softc *sc = device_get_softc(dev);
642 keyboard_t *kbd;
643 int rid;
644 int i;
645 uint32_t ack;
646
647 sc->sc_dev = dev;
648 kbd = &sc->sc_kbd;
649 rid = 0;
650
651 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
652 if (sc->sc_mem_res == NULL) {
653 device_printf(dev, "could not allocate memory resource\n");
654 return (ENXIO);
655 }
656
657 /* Request the IRQ resources */
658 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
659 if (sc->sc_irq_res == NULL) {
660 device_printf(dev, "Error: could not allocate irq resources\n");
661 return (ENXIO);
662 }
663
664 /* Setup and enable the timer */
665 if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_CLK,
666 NULL, pl050_kmi_intr, sc,
667 &sc->sc_intr_hl) != 0) {
668 bus_release_resource(dev, SYS_RES_IRQ, rid,
669 sc->sc_irq_res);
670 device_printf(dev, "Unable to setup the clock irq handler.\n");
671 return (ENXIO);
672 }
673
674 /* TODO: clock & divisor */
675
676 pl050_kmi_write_4(sc, KMICR, KMICR_EN);
677
678 pl050_kmi_write_4(sc, KMIDATA, SET_SCANCODE_SET);
679 /* read out ACK */
680 ack = pl050_kmi_read_4(sc, KMIDATA);
681 /* Set Scan Code set 1 (XT) */
682 pl050_kmi_write_4(sc, KMIDATA, 1);
683 /* read out ACK */
684 ack = pl050_kmi_read_4(sc, KMIDATA);
685
686 pl050_kmi_write_4(sc, KMICR, KMICR_EN | KMICR_RXINTREN);
687
688 kbd_init_struct(kbd, KMI_DRIVER_NAME, KB_OTHER,
689 device_get_unit(dev), 0, 0, 0);
690 kbd->kb_data = (void *)sc;
691
692 sc->sc_keymap = key_map;
693 sc->sc_accmap = accent_map;
694 for (i = 0; i < KMI_NFKEY; i++) {
695 sc->sc_fkeymap[i] = fkey_tab[i];
696 }
697
698 kbd_set_maps(kbd, &sc->sc_keymap, &sc->sc_accmap,
699 sc->sc_fkeymap, KMI_NFKEY);
700
701 KBD_FOUND_DEVICE(kbd);
702 kmi_clear_state(kbd);
703 KBD_PROBE_DONE(kbd);
704
705 KBD_INIT_DONE(kbd);
706
707 if (kbd_register(kbd) < 0) {
708 goto detach;
709 }
710 KBD_CONFIG_DONE(kbd);
711
712 #ifdef KBD_INSTALL_CDEV
713 if (kbd_attach(kbd)) {
714 goto detach;
715 }
716 #endif
717
718 if (bootverbose) {
719 genkbd_diag(kbd, bootverbose);
720 }
721 kmi_attached = 1;
722 return (0);
723
724 detach:
725 return (ENXIO);
726
727 }
728
729 static device_method_t pl050_kmi_methods[] = {
730 DEVMETHOD(device_probe, pl050_kmi_probe),
731 DEVMETHOD(device_attach, pl050_kmi_attach),
732 { 0, 0 }
733 };
734
735 static driver_t pl050_kmi_driver = {
736 "kmi",
737 pl050_kmi_methods,
738 sizeof(struct kmi_softc),
739 };
740
741 static devclass_t pl050_kmi_devclass;
742
743 DRIVER_MODULE(pl050_kmi, simplebus, pl050_kmi_driver, pl050_kmi_devclass, 0, 0);
Cache object: 17482cff30a76898d9c3c1fc3a6badd8
|