1 /* $NetBSD: pckbc_isa.c,v 1.24 2008/03/15 13:23:25 cube Exp $ */
5 * Matthias Drochner. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: pckbc_isa.c,v 1.24 2008/03/15 13:23:25 cube Exp $");
31 #include "opt_pckbc.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <sys/device.h>
38 #include <sys/malloc.h>
39 #include <sys/errno.h>
40 #include <sys/queue.h>
44 #include <dev/isa/isareg.h>
45 #include <dev/isa/isavar.h>
47 #include <dev/ic/i8042reg.h>
48 #include <dev/ic/pckbcvar.h>
50 int pckbc_isa_match(device_t
, cfdata_t
, void *);
51 void pckbc_isa_attach(device_t
, device_t
, void *);
53 struct pckbc_isa_softc
{
54 struct pckbc_softc sc_pckbc
;
56 isa_chipset_tag_t sc_ic
;
57 int sc_irq
[PCKBC_NSLOTS
];
60 CFATTACH_DECL_NEW(pckbc_isa
, sizeof(struct pckbc_isa_softc
),
61 pckbc_isa_match
, pckbc_isa_attach
, NULL
, NULL
);
63 void pckbc_isa_intr_establish(struct pckbc_softc
*, pckbc_slot_t
);
66 pckbc_isa_match(device_t parent
, cfdata_t match
, void *aux
)
68 struct isa_attach_args
*ia
= aux
;
69 bus_space_tag_t iot
= ia
->ia_iot
;
70 bus_space_handle_t ioh_d
, ioh_c
;
73 if (ISA_DIRECT_CONFIG(ia
))
76 /* If values are hardwired to something that they can't be, punt. */
78 (ia
->ia_io
[0].ir_addr
!= ISA_UNKNOWN_PORT
&&
79 ia
->ia_io
[0].ir_addr
!= IO_KBD
))
82 if (ia
->ia_niomem
> 0 &&
83 (ia
->ia_iomem
[0].ir_addr
!= ISA_UNKNOWN_IOMEM
))
86 if (ia
->ia_nirq
< 1 ||
87 (ia
->ia_irq
[0].ir_irq
!= ISA_UNKNOWN_IRQ
&&
88 ia
->ia_irq
[0].ir_irq
!= 1 /*XXX*/))
91 if (ia
->ia_ndrq
> 0 &&
92 (ia
->ia_drq
[0].ir_drq
!= ISA_UNKNOWN_DRQ
))
95 if (pckbc_is_console(iot
, IO_KBD
) == 0) {
96 struct pckbc_internal t
;
98 if (bus_space_map(iot
, IO_KBD
+ KBDATAP
, 1, 0, &ioh_d
))
100 if (bus_space_map(iot
, IO_KBD
+ KBCMDP
, 1, 0, &ioh_c
)) {
101 bus_space_unmap(iot
, ioh_d
, 1);
105 memset(&t
, 0, sizeof(t
));
111 (void) pckbc_poll_data1(&t
, PCKBC_KBD_SLOT
);
114 if (pckbc_send_cmd(iot
, ioh_c
, KBC_SELFTEST
) == 0) {
118 res
= pckbc_poll_data1(&t
, PCKBC_KBD_SLOT
);
122 aprint_verbose("kbc selftest: %x\n", res
);
126 #endif /* PCKBCNOTEST */
128 bus_space_unmap(iot
, ioh_d
, 1);
129 bus_space_unmap(iot
, ioh_c
, 1);
133 ia
->ia_io
[0].ir_addr
= IO_KBD
;
134 ia
->ia_io
[0].ir_size
= 5;
145 pckbc_isa_attach(device_t parent
, device_t self
, void *aux
)
147 struct pckbc_isa_softc
*isc
= device_private(self
);
148 struct pckbc_softc
*sc
= &isc
->sc_pckbc
;
149 struct isa_attach_args
*ia
= aux
;
150 struct pckbc_internal
*t
;
152 bus_space_handle_t ioh_d
, ioh_c
;
155 isc
->sc_ic
= ia
->ia_ic
;
158 switch (ia
->ia_nirq
) {
160 /* Both channels use the same IRQ. */
161 isc
->sc_irq
[PCKBC_KBD_SLOT
] =
162 isc
->sc_irq
[PCKBC_AUX_SLOT
] = ia
->ia_irq
[0].ir_irq
;
166 /* First IRQ is kbd, second IRQ is aux port. */
167 isc
->sc_irq
[PCKBC_KBD_SLOT
] = ia
->ia_irq
[0].ir_irq
;
168 isc
->sc_irq
[PCKBC_AUX_SLOT
] = ia
->ia_irq
[1].ir_irq
;
172 /* Set up IRQs for "normal" ISA. */
173 isc
->sc_irq
[PCKBC_KBD_SLOT
] = 1;
174 isc
->sc_irq
[PCKBC_AUX_SLOT
] = 12;
178 sc
->intr_establish
= pckbc_isa_intr_establish
;
180 if (pckbc_is_console(iot
, IO_KBD
)) {
184 pckbc_console_attached
= 1;
185 /* t->t_cmdbyte was initialized by cnattach */
187 if (bus_space_map(iot
, IO_KBD
+ KBDATAP
, 1, 0, &ioh_d
) ||
188 bus_space_map(iot
, IO_KBD
+ KBCMDP
, 1, 0, &ioh_c
))
189 panic("pckbc_attach: couldn't map");
191 t
= malloc(sizeof(struct pckbc_internal
), M_DEVBUF
,
197 t
->t_cmdbyte
= KC8_CPU
; /* Enable ports */
198 callout_init(&t
->t_cleanup
, 0);
206 if (!pmf_device_register(self
, NULL
, pckbc_resume
))
207 aprint_error_dev(self
, "couldn't establish power handler\n");
209 /* Finish off the attach. */
214 pckbc_isa_intr_establish(struct pckbc_softc
*sc
, pckbc_slot_t slot
)
216 struct pckbc_isa_softc
*isc
= (void *) sc
;
219 rv
= isa_intr_establish(isc
->sc_ic
, isc
->sc_irq
[slot
], IST_EDGE
,
220 IPL_TTY
, pckbcintr
, sc
);
222 aprint_error_dev(sc
->sc_dv
,
223 "unable to establish interrupt for %s slot\n",
224 pckbc_slot_names
[slot
]);
226 aprint_normal_dev(sc
->sc_dv
, "using irq %d for %s slot\n",
227 isc
->sc_irq
[slot
], pckbc_slot_names
[slot
]);