pckbc_jazzio.c revision 1.17 1 /* $NetBSD: pckbc_jazzio.c,v 1.17 2008/01/05 00:31:53 ad 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 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.17 2008/01/05 00:31:53 ad Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/proc.h>
36 #include <sys/device.h>
37 #include <sys/malloc.h>
38 #include <sys/errno.h>
39 #include <sys/queue.h>
40 #include <sys/bus.h>
41
42 #include <machine/autoconf.h>
43 #include <arc/jazz/pica.h>
44 #include <arc/jazz/jazziovar.h>
45
46 #include <dev/ic/i8042reg.h>
47 #include <dev/ic/pckbcvar.h>
48 #include <arc/jazz/pckbc_jazzioreg.h>
49
50 #define PMS_INTR 7 /* XXX - should be obtained from firmware */
51 #define PICA_KBCMDP (PICA_SYS_KBD + JAZZIO_KBCMDP)
52
53 int pckbc_jazzio_match(struct device *, struct cfdata *, void *);
54 void pckbc_jazzio_attach(struct device *, struct device *, void *);
55 void pckbc_jazzio_intr_establish(struct pckbc_softc *, pckbc_slot_t);
56
57 struct pckbc_jazzio_softc {
58 struct pckbc_softc sc_pckbc;
59
60 int sc_intr[PCKBC_NSLOTS];
61 };
62
63 CFATTACH_DECL(pckbc_jazzio, sizeof(struct pckbc_jazzio_softc),
64 pckbc_jazzio_match, pckbc_jazzio_attach, NULL, NULL);
65
66 int
67 pckbc_jazzio_match(parent, match, aux)
68 struct device *parent;
69 struct cfdata *match;
70 void *aux;
71 {
72 struct jazzio_attach_args *ja = aux;
73 bus_space_tag_t iot = ja->ja_bust;
74 bus_space_handle_t ioh_d, ioh_c;
75 bus_addr_t addr = ja->ja_addr;
76 int res, ok = 1;
77
78 if (strcmp(ja->ja_name, "I8742") != 0)
79 return 0;
80
81 if (pckbc_is_console(iot, addr) == 0) {
82 struct pckbc_internal t;
83
84 if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d))
85 return 0;
86 if (bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c)) {
87 bus_space_unmap(iot, ioh_d, 1);
88 return 0;
89 }
90
91 memset(&t, 0, sizeof(t));
92 t.t_iot = iot;
93 t.t_ioh_d = ioh_d;
94 t.t_ioh_c = ioh_c;
95
96 /* flush KBC */
97 (void)pckbc_poll_data1(&t, PCKBC_KBD_SLOT);
98
99 /* KBC selftest */
100 if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0) {
101 ok = 0;
102 goto out;
103 }
104 res = pckbc_poll_data1(&t, PCKBC_KBD_SLOT);
105 if (res != 0x55) {
106 printf("kbc selftest: %x\n", res);
107 ok = 0;
108 }
109 out:
110 bus_space_unmap(iot, ioh_d, 1);
111 bus_space_unmap(iot, ioh_c, 1);
112 }
113
114 return ok;
115 }
116
117 void
118 pckbc_jazzio_attach(struct device *parent, struct device *self, void *aux)
119 {
120 struct jazzio_attach_args *ja = aux;
121 struct pckbc_jazzio_softc *jsc = (void *)self;
122 struct pckbc_softc *sc = &jsc->sc_pckbc;
123 struct pckbc_internal *t;
124 bus_space_tag_t iot = ja->ja_bust;
125 bus_space_handle_t ioh_d, ioh_c;
126 bus_addr_t addr = ja->ja_addr;
127
128 sc->intr_establish = pckbc_jazzio_intr_establish;
129
130 /*
131 * To establish interrupt handler
132 *
133 * XXX handcrafting "aux" slot...
134 */
135 jsc->sc_intr[PCKBC_KBD_SLOT] = ja->ja_intr;
136 jsc->sc_intr[PCKBC_AUX_SLOT] = PMS_INTR; /* XXX */
137
138 if (pckbc_is_console(iot, addr)) {
139 t = &pckbc_consdata;
140 ioh_d = t->t_ioh_d;
141 ioh_c = t->t_ioh_c;
142 pckbc_console_attached = 1;
143 /* t->t_cmdbyte was initialized by cnattach */
144 } else {
145 if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d) ||
146 bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c))
147 panic("pckbc_attach: couldn't map");
148
149 t = malloc(sizeof(struct pckbc_internal), M_DEVBUF,
150 M_WAITOK | M_ZERO);
151 t->t_iot = iot;
152 t->t_ioh_d = ioh_d;
153 t->t_ioh_c = ioh_c;
154 t->t_addr = addr;
155 t->t_cmdbyte = KC8_CPU; /* Enable ports */
156 callout_init(&t->t_cleanup, 0);
157 }
158
159 t->t_sc = sc;
160 sc->id = t;
161
162 printf("\n");
163
164 /* Finish off the attach. */
165 pckbc_attach(sc);
166 }
167
168 void
169 pckbc_jazzio_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
170 {
171 struct pckbc_jazzio_softc *jsc = (void *) sc;
172
173 jazzio_intr_establish(jsc->sc_intr[slot], pckbcintr, sc);
174 }
175