m38813c.c revision 1.3.2.2 1 1.3.2.2 bouyer /* $NetBSD: m38813c.c,v 1.3.2.2 2000/11/20 20:46:02 bouyer Exp $ */
2 1.3.2.2 bouyer
3 1.3.2.2 bouyer /*
4 1.3.2.2 bouyer * Copyright (c) 1999, 2000, by UCHIYAMA Yasushi
5 1.3.2.2 bouyer * All rights reserved.
6 1.3.2.2 bouyer *
7 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
8 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
9 1.3.2.2 bouyer * are met:
10 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
11 1.3.2.2 bouyer * notice, this list of conditions and the following disclaimer.
12 1.3.2.2 bouyer * 2. The name of the developer may NOT be used to endorse or promote products
13 1.3.2.2 bouyer * derived from this software without specific prior written permission.
14 1.3.2.2 bouyer *
15 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.3.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.3.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.3.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.3.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.3.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.3.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.3.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.3.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.3.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.3.2.2 bouyer * SUCH DAMAGE.
26 1.3.2.2 bouyer *
27 1.3.2.2 bouyer */
28 1.3.2.2 bouyer
29 1.3.2.2 bouyer /*
30 1.3.2.2 bouyer * Device driver for MITUBISHI M38813 controller
31 1.3.2.2 bouyer */
32 1.3.2.2 bouyer
33 1.3.2.2 bouyer #include "opt_tx39_debug.h"
34 1.3.2.2 bouyer #include "opt_use_poll.h"
35 1.3.2.2 bouyer
36 1.3.2.2 bouyer #include <sys/param.h>
37 1.3.2.2 bouyer #include <sys/systm.h>
38 1.3.2.2 bouyer #include <sys/device.h>
39 1.3.2.2 bouyer
40 1.3.2.2 bouyer #include <machine/bus.h>
41 1.3.2.2 bouyer #include <machine/intr.h>
42 1.3.2.2 bouyer
43 1.3.2.2 bouyer #include <hpcmips/tx/tx39var.h>
44 1.3.2.2 bouyer #include <hpcmips/tx/txcsbusvar.h>
45 1.3.2.2 bouyer
46 1.3.2.2 bouyer #include <hpcmips/dev/m38813cvar.h>
47 1.3.2.2 bouyer #include <hpcmips/dev/hpckbdvar.h>
48 1.3.2.2 bouyer
49 1.3.2.2 bouyer struct m38813c_chip {
50 1.3.2.2 bouyer bus_space_tag_t scc_cst;
51 1.3.2.2 bouyer bus_space_handle_t scc_csh;
52 1.3.2.2 bouyer int scc_enabled;
53 1.3.2.2 bouyer int t_lastchar;
54 1.3.2.2 bouyer int t_extended;
55 1.3.2.2 bouyer int t_extended1;
56 1.3.2.2 bouyer
57 1.3.2.2 bouyer struct hpckbd_ic_if scc_if;
58 1.3.2.2 bouyer struct hpckbd_if *scc_hpckbd;
59 1.3.2.2 bouyer };
60 1.3.2.2 bouyer
61 1.3.2.2 bouyer struct m38813c_softc {
62 1.3.2.2 bouyer struct device sc_dev;
63 1.3.2.2 bouyer struct m38813c_chip *sc_chip;
64 1.3.2.2 bouyer tx_chipset_tag_t sc_tc;
65 1.3.2.2 bouyer void *sc_ih;
66 1.3.2.2 bouyer };
67 1.3.2.2 bouyer
68 1.3.2.2 bouyer int m38813c_match __P((struct device*, struct cfdata*, void*));
69 1.3.2.2 bouyer void m38813c_attach __P((struct device*, struct device*, void*));
70 1.3.2.2 bouyer int m38813c_intr __P((void*));
71 1.3.2.2 bouyer int m38813c_poll __P((void*));
72 1.3.2.2 bouyer void m38813c_ifsetup __P((struct m38813c_chip*));
73 1.3.2.2 bouyer int m38813c_input_establish __P((void*, struct hpckbd_if*));
74 1.3.2.2 bouyer
75 1.3.2.2 bouyer struct m38813c_chip m38813c_chip;
76 1.3.2.2 bouyer
77 1.3.2.2 bouyer struct cfattach m38813c_ca = {
78 1.3.2.2 bouyer sizeof(struct m38813c_softc), m38813c_match, m38813c_attach
79 1.3.2.2 bouyer };
80 1.3.2.2 bouyer
81 1.3.2.2 bouyer int
82 1.3.2.2 bouyer m38813c_match(parent, cf, aux)
83 1.3.2.2 bouyer struct device *parent;
84 1.3.2.2 bouyer struct cfdata *cf;
85 1.3.2.2 bouyer void *aux;
86 1.3.2.2 bouyer {
87 1.3.2.2 bouyer return 1;
88 1.3.2.2 bouyer }
89 1.3.2.2 bouyer
90 1.3.2.2 bouyer void
91 1.3.2.2 bouyer m38813c_attach(parent, self, aux)
92 1.3.2.2 bouyer struct device *parent;
93 1.3.2.2 bouyer struct device *self;
94 1.3.2.2 bouyer void *aux;
95 1.3.2.2 bouyer {
96 1.3.2.2 bouyer struct cs_attach_args *ca = aux;
97 1.3.2.2 bouyer struct m38813c_softc *sc = (void*)self;
98 1.3.2.2 bouyer struct hpckbd_attach_args haa;
99 1.3.2.2 bouyer
100 1.3.2.2 bouyer sc->sc_tc = ca->ca_tc;
101 1.3.2.2 bouyer sc->sc_chip = &m38813c_chip;
102 1.3.2.2 bouyer sc->sc_chip->scc_cst = ca->ca_csio.cstag;
103 1.3.2.2 bouyer
104 1.3.2.2 bouyer if (bus_space_map(sc->sc_chip->scc_cst, ca->ca_csio.csbase,
105 1.3.2.2 bouyer ca->ca_csio.cssize, 0, &sc->sc_chip->scc_csh)) {
106 1.3.2.2 bouyer printf(": can't map i/o space\n");
107 1.3.2.2 bouyer }
108 1.3.2.2 bouyer
109 1.3.2.2 bouyer #ifndef USE_POLL
110 1.3.2.2 bouyer #error options USE_POLL requied.
111 1.3.2.2 bouyer #endif
112 1.3.2.2 bouyer if (!(sc->sc_ih = tx39_poll_establish(sc->sc_tc, 1,
113 1.3.2.2 bouyer IPL_TTY, m38813c_intr,
114 1.3.2.2 bouyer sc))) {
115 1.3.2.2 bouyer printf(": can't establish interrupt\n");
116 1.3.2.2 bouyer }
117 1.3.2.2 bouyer
118 1.3.2.2 bouyer printf("\n");
119 1.3.2.2 bouyer
120 1.3.2.2 bouyer /* setup upper interface */
121 1.3.2.2 bouyer m38813c_ifsetup(sc->sc_chip);
122 1.3.2.2 bouyer
123 1.3.2.2 bouyer haa.haa_ic = &sc->sc_chip->scc_if;
124 1.3.2.2 bouyer
125 1.3.2.2 bouyer config_found(self, &haa, hpckbd_print);
126 1.3.2.2 bouyer }
127 1.3.2.2 bouyer
128 1.3.2.2 bouyer void
129 1.3.2.2 bouyer m38813c_ifsetup(scc)
130 1.3.2.2 bouyer struct m38813c_chip *scc;
131 1.3.2.2 bouyer {
132 1.3.2.2 bouyer scc->scc_if.hii_ctx = scc;
133 1.3.2.2 bouyer
134 1.3.2.2 bouyer scc->scc_if.hii_establish = m38813c_input_establish;
135 1.3.2.2 bouyer scc->scc_if.hii_poll = m38813c_intr;
136 1.3.2.2 bouyer }
137 1.3.2.2 bouyer
138 1.3.2.2 bouyer int
139 1.3.2.2 bouyer m38813c_cnattach(addr)
140 1.3.2.2 bouyer paddr_t addr;
141 1.3.2.2 bouyer {
142 1.3.2.2 bouyer struct m38813c_chip *scc = &m38813c_chip;
143 1.3.2.2 bouyer
144 1.3.2.2 bouyer scc->scc_csh = MIPS_PHYS_TO_KSEG1(addr);
145 1.3.2.2 bouyer
146 1.3.2.2 bouyer m38813c_ifsetup(scc);
147 1.3.2.2 bouyer
148 1.3.2.2 bouyer hpckbd_cnattach(&scc->scc_if);
149 1.3.2.2 bouyer
150 1.3.2.2 bouyer return 0;
151 1.3.2.2 bouyer }
152 1.3.2.2 bouyer
153 1.3.2.2 bouyer int
154 1.3.2.2 bouyer m38813c_input_establish(ic, kbdif)
155 1.3.2.2 bouyer void *ic;
156 1.3.2.2 bouyer struct hpckbd_if *kbdif;
157 1.3.2.2 bouyer {
158 1.3.2.2 bouyer struct m38813c_chip *scc = ic;
159 1.3.2.2 bouyer
160 1.3.2.2 bouyer /* save lower interface */
161 1.3.2.2 bouyer scc->scc_hpckbd = kbdif;
162 1.3.2.2 bouyer
163 1.3.2.2 bouyer scc->scc_enabled = 1;
164 1.3.2.2 bouyer
165 1.3.2.2 bouyer return 0;
166 1.3.2.2 bouyer }
167 1.3.2.2 bouyer
168 1.3.2.2 bouyer #define KBR_EXTENDED0 0xE0 /* extended key sequence */
169 1.3.2.2 bouyer #define KBR_EXTENDED1 0xE1 /* extended key sequence */
170 1.3.2.2 bouyer
171 1.3.2.2 bouyer int
172 1.3.2.2 bouyer m38813c_intr(arg)
173 1.3.2.2 bouyer void *arg;
174 1.3.2.2 bouyer {
175 1.3.2.2 bouyer struct m38813c_softc *sc = arg;
176 1.3.2.2 bouyer
177 1.3.2.2 bouyer return m38813c_poll(sc->sc_chip);
178 1.3.2.2 bouyer }
179 1.3.2.2 bouyer
180 1.3.2.2 bouyer int
181 1.3.2.2 bouyer m38813c_poll(arg)
182 1.3.2.2 bouyer void *arg;
183 1.3.2.2 bouyer {
184 1.3.2.2 bouyer struct m38813c_chip *scc = arg;
185 1.3.2.2 bouyer bus_space_tag_t t = scc->scc_cst;
186 1.3.2.2 bouyer bus_space_handle_t h = scc->scc_csh;
187 1.3.2.2 bouyer int datain, type, key;
188 1.3.2.2 bouyer
189 1.3.2.2 bouyer if (!scc->scc_enabled) {
190 1.3.2.2 bouyer return 0;
191 1.3.2.2 bouyer }
192 1.3.2.2 bouyer
193 1.3.2.2 bouyer datain= bus_space_read_1(t, h, 0);
194 1.3.2.2 bouyer
195 1.3.2.2 bouyer hpckbd_input_hook(scc->scc_hpckbd);
196 1.3.2.2 bouyer
197 1.3.2.2 bouyer if (datain == KBR_EXTENDED0) {
198 1.3.2.2 bouyer scc->t_extended = 1;
199 1.3.2.2 bouyer return 0;
200 1.3.2.2 bouyer } else if (datain == KBR_EXTENDED1) {
201 1.3.2.2 bouyer scc->t_extended1 = 2;
202 1.3.2.2 bouyer return 0;
203 1.3.2.2 bouyer }
204 1.3.2.2 bouyer
205 1.3.2.2 bouyer /* map extended keys to (unused) codes 128-254 */
206 1.3.2.2 bouyer key = (datain & 0x7f) | (scc->t_extended ? 0x80 : 0);
207 1.3.2.2 bouyer scc->t_extended = 0;
208 1.3.2.2 bouyer
209 1.3.2.2 bouyer /*
210 1.3.2.2 bouyer * process BREAK key (EXT1 1D 45 EXT1 9D C5):
211 1.3.2.2 bouyer * map to (unused) code 7F
212 1.3.2.2 bouyer */
213 1.3.2.2 bouyer if (scc->t_extended1 == 2 && (datain == 0x1d || datain == 0x9d)) {
214 1.3.2.2 bouyer scc->t_extended1 = 1;
215 1.3.2.2 bouyer return 0;
216 1.3.2.2 bouyer } else if (scc->t_extended1 == 1 &&
217 1.3.2.2 bouyer (datain == 0x45 || datain == 0xc5)) {
218 1.3.2.2 bouyer scc->t_extended1 = 0;
219 1.3.2.2 bouyer key = 0x7f;
220 1.3.2.2 bouyer } else if (scc->t_extended1 > 0) {
221 1.3.2.2 bouyer scc->t_extended1 = 0;
222 1.3.2.2 bouyer }
223 1.3.2.2 bouyer
224 1.3.2.2 bouyer if (datain & 0x80) {
225 1.3.2.2 bouyer scc->t_lastchar = 0;
226 1.3.2.2 bouyer type = 0;
227 1.3.2.2 bouyer } else {
228 1.3.2.2 bouyer /* Always ignore typematic keys */
229 1.3.2.2 bouyer if (key == scc->t_lastchar)
230 1.3.2.2 bouyer return 0;
231 1.3.2.2 bouyer scc->t_lastchar = key;
232 1.3.2.2 bouyer type = 1;
233 1.3.2.2 bouyer }
234 1.3.2.2 bouyer
235 1.3.2.2 bouyer hpckbd_input(scc->scc_hpckbd, type, key);
236 1.3.2.2 bouyer
237 1.3.2.2 bouyer return 0;
238 1.3.2.2 bouyer }
239