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