1 /* $NetBSD: pckbc_pnpbios.c,v 1.16 2008/04/28 20:23:25 martin Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * PNPBIOS attachment for the PC Keyboard Controller driver.
35 * This is a little wonky. The keyboard controller actually
36 * has 2 PNPBIOS nodes: one for the controller and the keyboard
37 * interrupt, and one for the aux port (mouse) interrupt.
39 * For this reason, we actually attach *two* instances of this
40 * driver. After both of them have been found, then we attach
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: pckbc_pnpbios.c,v 1.16 2008/04/28 20:23:25 martin Exp $");
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
51 #include <sys/device.h>
52 #include <sys/malloc.h>
53 #include <sys/errno.h>
54 #include <sys/queue.h>
57 #include <dev/isa/isareg.h>
58 #include <dev/isa/isavar.h>
60 #include <dev/ic/i8042reg.h>
61 #include <dev/ic/pckbcvar.h>
63 #include <i386/pnpbios/pnpbiosvar.h>
65 int pckbc_pnpbios_match(device_t
, cfdata_t
, void *);
66 void pckbc_pnpbios_attach(device_t
, device_t
, void *);
68 struct pckbc_pnpbios_softc
{
69 struct pckbc_softc sc_pckbc
;
71 isa_chipset_tag_t sc_ic
;
77 /* Save first port: */
78 static struct pckbc_pnpbios_softc
*first
;
80 extern struct cfdriver pckbc_cd
;
82 CFATTACH_DECL_NEW(pckbc_pnpbios
, sizeof(struct pckbc_pnpbios_softc
),
83 pckbc_pnpbios_match
, pckbc_pnpbios_attach
, NULL
, NULL
);
85 void pckbc_pnpbios_intr_establish(struct pckbc_softc
*, pckbc_slot_t
);
86 static void pckbc_pnpbios_finish_attach(device_t
);
89 pckbc_pnpbios_match(device_t parent
, cfdata_t match
, void *aux
)
91 struct pnpbiosdev_attach_args
*aa
= aux
;
93 if (strcmp(aa
->idstr
, "PNP0303") == 0 ||
94 strcmp(aa
->idstr
, "PNP0320") == 0) /* Japanese 106 */
95 return (1); /* plus more? */
96 if (strcmp(aa
->idstr
, "PNP0F13") == 0)
103 pckbc_pnpbios_attach(device_t parent
, device_t self
, void *aux
)
105 struct pckbc_pnpbios_softc
*psc
= device_private(self
);
106 struct pckbc_softc
*sc
= &psc
->sc_pckbc
;
107 struct pckbc_internal
*t
;
108 struct pnpbiosdev_attach_args
*aa
= aux
;
110 bus_space_handle_t ioh_d
, ioh_c
;
115 if (strncmp(aa
->idstr
, "PNP03", 5) == 0) {
116 psc
->sc_slot
= PCKBC_KBD_SLOT
;
117 peer
= PCKBC_AUX_SLOT
;
118 } else if (strcmp(aa
->idstr
, "PNP0F13") == 0) {
119 psc
->sc_slot
= PCKBC_AUX_SLOT
;
120 peer
= PCKBC_KBD_SLOT
;
122 aprint_error(": unknown port!\n");
123 panic("pckbc_pnpbios_attach: impossible");
126 aprint_normal(": %s port\n", pckbc_slot_names
[psc
->sc_slot
]);
128 if (pnpbios_getirqnum(aa
->pbt
, aa
->resc
, 0, &psc
->sc_irq
,
129 &psc
->sc_ist
) != 0) {
130 aprint_error_dev(self
, "unable to get IRQ number or type\n");
139 if (!first
->sc_pckbc
.id
) {
141 if (pnpbios_getiobase(aa
->pbt
, aa
->resc
, 0, &iot
, &iobase
))
144 if (pckbc_is_console(iot
, iobase
)) {
148 pckbc_console_attached
= 1;
149 /* t->t_cmdbyte was initialized by cnattach */
151 if (pnpbios_io_map(aa
->pbt
, aa
->resc
, 0,
153 pnpbios_io_map(aa
->pbt
, aa
->resc
, 1,
155 panic("pckbc_pnpbios_attach: couldn't map");
157 t
= malloc(sizeof(struct pckbc_internal
),
159 memset(t
, 0, sizeof(*t
));
164 t
->t_cmdbyte
= KC8_CPU
; /* Enable ports */
165 callout_init(&t
->t_cleanup
, 0);
168 t
->t_sc
= &first
->sc_pckbc
;
169 first
->sc_pckbc
.id
= t
;
171 first
->sc_pckbc
.intr_establish
= pckbc_pnpbios_intr_establish
;
172 config_defer(first
->sc_pckbc
.sc_dv
,
173 pckbc_pnpbios_finish_attach
);
178 pckbc_pnpbios_finish_attach(device_t dv
)
181 pckbc_attach(device_private(dv
));
185 pckbc_pnpbios_intr_establish(struct pckbc_softc
*sc
,
188 struct pckbc_pnpbios_softc
*psc
;
189 isa_chipset_tag_t ic
= NULL
;
195 * Note we're always called with sc == first.
197 for (i
= 0; i
< pckbc_cd
.cd_ndevs
; i
++) {
198 psc
= device_lookup_private(&pckbc_cd
, i
);
199 if (psc
&& psc
->sc_slot
== slot
) {
206 if (i
< pckbc_cd
.cd_ndevs
)
207 rv
= isa_intr_establish(ic
, irq
, ist
, IPL_TTY
, pckbcintr
, sc
);
209 aprint_error_dev(sc
->sc_dv
,
210 "unable to establish interrupt for %s slot\n",
211 pckbc_slot_names
[slot
]);
213 aprint_normal_dev(sc
->sc_dv
, "using irq %d for %s slot\n",
214 irq
, pckbc_slot_names
[slot
]);