pckbc_isa.c revision 1.5 1 1.5 lukem /* $NetBSD: pckbc_isa.c,v 1.5 2001/11/13 08:01:28 lukem Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1998
5 1.1 thorpej * Matthias Drochner. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
16 1.1 thorpej * must display the following acknowledgement:
17 1.1 thorpej * This product includes software developed for the NetBSD Project
18 1.1 thorpej * by Matthias Drochner.
19 1.1 thorpej * 4. The name of the author may not be used to endorse or promote products
20 1.1 thorpej * derived from this software without specific prior written permission.
21 1.1 thorpej *
22 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 thorpej */
33 1.5 lukem
34 1.5 lukem #include <sys/cdefs.h>
35 1.5 lukem __KERNEL_RCSID(0, "$NetBSD: pckbc_isa.c,v 1.5 2001/11/13 08:01:28 lukem Exp $");
36 1.1 thorpej
37 1.1 thorpej #include <sys/param.h>
38 1.1 thorpej #include <sys/systm.h>
39 1.1 thorpej #include <sys/kernel.h>
40 1.1 thorpej #include <sys/proc.h>
41 1.1 thorpej #include <sys/device.h>
42 1.1 thorpej #include <sys/malloc.h>
43 1.1 thorpej #include <sys/errno.h>
44 1.1 thorpej #include <sys/queue.h>
45 1.1 thorpej #include <sys/lock.h>
46 1.1 thorpej
47 1.1 thorpej #include <machine/bus.h>
48 1.1 thorpej
49 1.1 thorpej #include <dev/isa/isareg.h>
50 1.1 thorpej #include <dev/isa/isavar.h>
51 1.1 thorpej
52 1.1 thorpej #include <dev/ic/i8042reg.h>
53 1.1 thorpej #include <dev/ic/pckbcvar.h>
54 1.1 thorpej
55 1.1 thorpej int pckbc_isa_match __P((struct device *, struct cfdata *, void *));
56 1.1 thorpej void pckbc_isa_attach __P((struct device *, struct device *, void *));
57 1.1 thorpej
58 1.1 thorpej struct pckbc_isa_softc {
59 1.1 thorpej struct pckbc_softc sc_pckbc;
60 1.1 thorpej
61 1.1 thorpej isa_chipset_tag_t sc_ic;
62 1.1 thorpej int sc_irq[PCKBC_NSLOTS];
63 1.1 thorpej };
64 1.1 thorpej
65 1.1 thorpej struct cfattach pckbc_isa_ca = {
66 1.1 thorpej sizeof(struct pckbc_isa_softc), pckbc_isa_match, pckbc_isa_attach,
67 1.1 thorpej };
68 1.1 thorpej
69 1.1 thorpej void pckbc_isa_intr_establish __P((struct pckbc_softc *, pckbc_slot_t));
70 1.1 thorpej
71 1.1 thorpej int
72 1.1 thorpej pckbc_isa_match(parent, match, aux)
73 1.1 thorpej struct device *parent;
74 1.1 thorpej struct cfdata *match;
75 1.1 thorpej void *aux;
76 1.1 thorpej {
77 1.1 thorpej struct isa_attach_args *ia = aux;
78 1.1 thorpej bus_space_tag_t iot = ia->ia_iot;
79 1.1 thorpej bus_space_handle_t ioh_d, ioh_c;
80 1.1 thorpej int res, ok = 1;
81 1.1 thorpej
82 1.1 thorpej /* If values are hardwired to something that they can't be, punt. */
83 1.1 thorpej if ((ia->ia_iobase != IOBASEUNK && ia->ia_iobase != IO_KBD) ||
84 1.1 thorpej ia->ia_maddr != MADDRUNK ||
85 1.1 thorpej (ia->ia_irq != IRQUNK && ia->ia_irq != 1 /* XXX */) ||
86 1.1 thorpej ia->ia_drq != DRQUNK)
87 1.1 thorpej return (0);
88 1.1 thorpej
89 1.1 thorpej if (pckbc_is_console(iot, IO_KBD) == 0) {
90 1.4 jdolecek struct pckbc_internal t;
91 1.4 jdolecek
92 1.1 thorpej if (bus_space_map(iot, IO_KBD + KBDATAP, 1, 0, &ioh_d))
93 1.1 thorpej return (0);
94 1.1 thorpej if (bus_space_map(iot, IO_KBD + KBCMDP, 1, 0, &ioh_c)) {
95 1.1 thorpej bus_space_unmap(iot, ioh_d, 1);
96 1.1 thorpej return (0);
97 1.1 thorpej }
98 1.1 thorpej
99 1.4 jdolecek memset(&t, 0, sizeof(t));
100 1.4 jdolecek t.t_iot = iot;
101 1.4 jdolecek t.t_ioh_d = ioh_d;
102 1.4 jdolecek t.t_ioh_c = ioh_c;
103 1.4 jdolecek
104 1.1 thorpej /* flush KBC */
105 1.4 jdolecek (void) pckbc_poll_data1(&t, PCKBC_KBD_SLOT, 0);
106 1.1 thorpej
107 1.1 thorpej /* KBC selftest */
108 1.1 thorpej if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0) {
109 1.1 thorpej ok = 0;
110 1.1 thorpej goto out;
111 1.1 thorpej }
112 1.4 jdolecek res = pckbc_poll_data1(&t, PCKBC_KBD_SLOT, 0);
113 1.1 thorpej if (res != 0x55) {
114 1.1 thorpej printf("kbc selftest: %x\n", res);
115 1.1 thorpej ok = 0;
116 1.1 thorpej }
117 1.1 thorpej out:
118 1.1 thorpej bus_space_unmap(iot, ioh_d, 1);
119 1.1 thorpej bus_space_unmap(iot, ioh_c, 1);
120 1.1 thorpej }
121 1.1 thorpej
122 1.1 thorpej if (ok) {
123 1.1 thorpej ia->ia_iobase = IO_KBD;
124 1.1 thorpej ia->ia_iosize = 5;
125 1.1 thorpej ia->ia_msize = 0x0;
126 1.1 thorpej }
127 1.1 thorpej return (ok);
128 1.1 thorpej }
129 1.1 thorpej
130 1.1 thorpej void
131 1.1 thorpej pckbc_isa_attach(parent, self, aux)
132 1.1 thorpej struct device *parent, *self;
133 1.1 thorpej void *aux;
134 1.1 thorpej {
135 1.1 thorpej struct pckbc_isa_softc *isc = (void *)self;
136 1.1 thorpej struct pckbc_softc *sc = &isc->sc_pckbc;
137 1.1 thorpej struct isa_attach_args *ia = aux;
138 1.1 thorpej struct pckbc_internal *t;
139 1.1 thorpej bus_space_tag_t iot;
140 1.1 thorpej bus_space_handle_t ioh_d, ioh_c;
141 1.1 thorpej
142 1.1 thorpej isc->sc_ic = ia->ia_ic;
143 1.1 thorpej iot = ia->ia_iot;
144 1.1 thorpej
145 1.1 thorpej /*
146 1.1 thorpej * Set up IRQs for "normal" ISA.
147 1.1 thorpej *
148 1.1 thorpej * XXX The "aux" slot is different (9) on the Alpha AXP150 Jensen.
149 1.1 thorpej */
150 1.1 thorpej isc->sc_irq[PCKBC_KBD_SLOT] = 1;
151 1.1 thorpej isc->sc_irq[PCKBC_AUX_SLOT] = 12;
152 1.1 thorpej
153 1.1 thorpej sc->intr_establish = pckbc_isa_intr_establish;
154 1.1 thorpej
155 1.1 thorpej if (pckbc_is_console(iot, IO_KBD)) {
156 1.1 thorpej t = &pckbc_consdata;
157 1.1 thorpej ioh_d = t->t_ioh_d;
158 1.1 thorpej ioh_c = t->t_ioh_c;
159 1.1 thorpej pckbc_console_attached = 1;
160 1.1 thorpej /* t->t_cmdbyte was initialized by cnattach */
161 1.1 thorpej } else {
162 1.1 thorpej if (bus_space_map(iot, IO_KBD + KBDATAP, 1, 0, &ioh_d) ||
163 1.1 thorpej bus_space_map(iot, IO_KBD + KBCMDP, 1, 0, &ioh_c))
164 1.1 thorpej panic("pckbc_attach: couldn't map");
165 1.1 thorpej
166 1.1 thorpej t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
167 1.3 thorpej memset(t, 0, sizeof(struct pckbc_internal));
168 1.1 thorpej t->t_iot = iot;
169 1.1 thorpej t->t_ioh_d = ioh_d;
170 1.1 thorpej t->t_ioh_c = ioh_c;
171 1.1 thorpej t->t_addr = IO_KBD;
172 1.1 thorpej t->t_cmdbyte = KC8_CPU; /* Enable ports */
173 1.2 thorpej callout_init(&t->t_cleanup);
174 1.1 thorpej }
175 1.1 thorpej
176 1.1 thorpej t->t_sc = sc;
177 1.1 thorpej sc->id = t;
178 1.1 thorpej
179 1.1 thorpej printf("\n");
180 1.1 thorpej
181 1.1 thorpej /* Finish off the attach. */
182 1.1 thorpej pckbc_attach(sc);
183 1.1 thorpej }
184 1.1 thorpej
185 1.1 thorpej void
186 1.1 thorpej pckbc_isa_intr_establish(sc, slot)
187 1.1 thorpej struct pckbc_softc *sc;
188 1.1 thorpej pckbc_slot_t slot;
189 1.1 thorpej {
190 1.1 thorpej struct pckbc_isa_softc *isc = (void *) sc;
191 1.1 thorpej void *rv;
192 1.1 thorpej
193 1.1 thorpej rv = isa_intr_establish(isc->sc_ic, isc->sc_irq[slot], IST_EDGE,
194 1.1 thorpej IPL_TTY, pckbcintr, sc);
195 1.1 thorpej if (rv == NULL) {
196 1.1 thorpej printf("%s: unable to establish interrupt for %s slot\n",
197 1.1 thorpej sc->sc_dv.dv_xname, pckbc_slot_names[slot]);
198 1.1 thorpej } else {
199 1.1 thorpej printf("%s: using irq %d for %s slot\n", sc->sc_dv.dv_xname,
200 1.1 thorpej isc->sc_irq[slot], pckbc_slot_names[slot]);
201 1.1 thorpej }
202 1.1 thorpej }
203