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