pckbc_jazzio.c revision 1.10 1 /* $NetBSD: pckbc_jazzio.c,v 1.10 2004/03/13 17:31:33 bjh21 Exp $ */
2 /* NetBSD: pckbc_isa.c,v 1.2 2000/03/23 07:01:35 thorpej Exp */
3
4 /*
5 * Copyright (c) 1998
6 * Matthias Drochner. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed for the NetBSD Project
19 * by Matthias Drochner.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.10 2004/03/13 17:31:33 bjh21 Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/proc.h>
42 #include <sys/device.h>
43 #include <sys/malloc.h>
44 #include <sys/errno.h>
45 #include <sys/queue.h>
46 #include <sys/lock.h>
47
48 #include <machine/autoconf.h>
49 #include <machine/bus.h>
50 #include <arc/jazz/pica.h>
51 #include <arc/jazz/jazziovar.h>
52
53 #include <dev/ic/i8042reg.h>
54 #include <dev/ic/pckbcvar.h>
55 #include <arc/jazz/pckbc_jazzioreg.h>
56
57 #define PMS_INTR 7 /* XXX - should be obtained from firmware */
58 #define PICA_KBCMDP (PICA_SYS_KBD + JAZZIO_KBCMDP)
59
60 int pckbc_jazzio_match __P((struct device *, struct cfdata *, void *));
61 void pckbc_jazzio_attach __P((struct device *, struct device *, void *));
62 void pckbc_jazzio_intr_establish __P((struct pckbc_softc *, pckbc_slot_t));
63
64 struct pckbc_jazzio_softc {
65 struct pckbc_softc sc_pckbc;
66
67 int sc_intr[PCKBC_NSLOTS];
68 };
69
70 CFATTACH_DECL(pckbc_jazzio, sizeof(struct pckbc_jazzio_softc),
71 pckbc_jazzio_match, pckbc_jazzio_attach, NULL, NULL);
72
73 int
74 pckbc_jazzio_match(parent, match, aux)
75 struct device *parent;
76 struct cfdata *match;
77 void *aux;
78 {
79 struct jazzio_attach_args *ja = aux;
80 bus_space_tag_t iot = ja->ja_bust;
81 bus_space_handle_t ioh_d, ioh_c;
82 bus_addr_t addr = ja->ja_addr;
83 int res, ok = 1;
84
85 if (strcmp(ja->ja_name, "I8742") != 0)
86 return (0);
87
88 if (pckbc_is_console(iot, addr) == 0) {
89 struct pckbc_internal t;
90
91 if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d))
92 return (0);
93 if (bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c)) {
94 bus_space_unmap(iot, ioh_d, 1);
95 return (0);
96 }
97
98 memset(&t, 0, sizeof(t));
99 t.t_iot = iot;
100 t.t_ioh_d = ioh_d;
101 t.t_ioh_c = ioh_c;
102
103 /* flush KBC */
104 (void) pckbc_poll_data1(&t, PCKBC_KBD_SLOT);
105
106 /* KBC selftest */
107 if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0) {
108 ok = 0;
109 goto out;
110 }
111 res = pckbc_poll_data1(&t, PCKBC_KBD_SLOT);
112 if (res != 0x55) {
113 printf("kbc selftest: %x\n", res);
114 ok = 0;
115 }
116 out:
117 bus_space_unmap(iot, ioh_d, 1);
118 bus_space_unmap(iot, ioh_c, 1);
119 }
120
121 return (ok);
122 }
123
124 void
125 pckbc_jazzio_attach(parent, self, aux)
126 struct device *parent, *self;
127 void *aux;
128 {
129 struct jazzio_attach_args *ja = aux;
130 struct pckbc_jazzio_softc *jsc = (void *)self;
131 struct pckbc_softc *sc = &jsc->sc_pckbc;
132 struct pckbc_internal *t;
133 bus_space_tag_t iot = ja->ja_bust;
134 bus_space_handle_t ioh_d, ioh_c;
135 bus_addr_t addr = ja->ja_addr;
136
137 sc->intr_establish = pckbc_jazzio_intr_establish;
138
139 /*
140 * To establish interrupt handler
141 *
142 * XXX handcrafting "aux" slot...
143 */
144 jsc->sc_intr[PCKBC_KBD_SLOT] = ja->ja_intr;
145 jsc->sc_intr[PCKBC_AUX_SLOT] = PMS_INTR; /* XXX */
146
147 if (pckbc_is_console(iot, addr)) {
148 t = &pckbc_consdata;
149 ioh_d = t->t_ioh_d;
150 ioh_c = t->t_ioh_c;
151 pckbc_console_attached = 1;
152 /* t->t_cmdbyte was initialized by cnattach */
153 } else {
154 if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d) ||
155 bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c))
156 panic("pckbc_attach: couldn't map");
157
158 t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
159 bzero(t, sizeof(struct pckbc_internal));
160 t->t_iot = iot;
161 t->t_ioh_d = ioh_d;
162 t->t_ioh_c = ioh_c;
163 t->t_addr = addr;
164 t->t_cmdbyte = KC8_CPU; /* Enable ports */
165 callout_init(&t->t_cleanup);
166 }
167
168 t->t_sc = sc;
169 sc->id = t;
170
171 printf("\n");
172
173 /* Finish off the attach. */
174 pckbc_attach(sc);
175 }
176
177 void
178 pckbc_jazzio_intr_establish(sc, slot)
179 struct pckbc_softc *sc;
180 pckbc_slot_t slot;
181 {
182 struct pckbc_jazzio_softc *jsc = (void *) sc;
183
184 jazzio_intr_establish(jsc->sc_intr[slot], pckbcintr, sc);
185 }
186