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