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