kb_ap.c revision 1.5 1 1.5 lukem /* $NetBSD: kb_ap.c,v 1.5 2003/07/15 02:59:28 lukem Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*-
4 1.1 tsubai * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
5 1.1 tsubai *
6 1.1 tsubai * Redistribution and use in source and binary forms, with or without
7 1.1 tsubai * modification, are permitted provided that the following conditions
8 1.1 tsubai * are met:
9 1.1 tsubai * 1. Redistributions of source code must retain the above copyright
10 1.1 tsubai * notice, this list of conditions and the following disclaimer.
11 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 tsubai * notice, this list of conditions and the following disclaimer in the
13 1.1 tsubai * documentation and/or other materials provided with the distribution.
14 1.1 tsubai * 3. The name of the author may not be used to endorse or promote products
15 1.1 tsubai * derived from this software without specific prior written permission.
16 1.1 tsubai *
17 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 tsubai */
28 1.5 lukem
29 1.5 lukem #include <sys/cdefs.h>
30 1.5 lukem __KERNEL_RCSID(0, "$NetBSD: kb_ap.c,v 1.5 2003/07/15 02:59:28 lukem Exp $");
31 1.1 tsubai
32 1.1 tsubai #include <sys/param.h>
33 1.1 tsubai #include <sys/systm.h>
34 1.1 tsubai #include <sys/device.h>
35 1.1 tsubai
36 1.1 tsubai #include <dev/wscons/wsconsio.h>
37 1.1 tsubai #include <dev/wscons/wskbdvar.h>
38 1.1 tsubai #include <dev/wscons/wsksymdef.h>
39 1.1 tsubai
40 1.1 tsubai #include <machine/adrsmap.h>
41 1.1 tsubai #include <newsmips/apbus/apbusvar.h>
42 1.1 tsubai
43 1.1 tsubai struct kbreg {
44 1.1 tsubai u_int kb_rx_data;
45 1.1 tsubai u_int kb_rx_stat;
46 1.1 tsubai u_int kb_rx_intr_en;
47 1.1 tsubai u_int kb_rx_reset;
48 1.1 tsubai u_int kb_rx_speed;
49 1.1 tsubai
50 1.1 tsubai u_int ms_rx_data;
51 1.1 tsubai u_int ms_rx_stat;
52 1.1 tsubai u_int ms_rx_intr_en;
53 1.1 tsubai u_int ms_rx_reset;
54 1.1 tsubai u_int ms_rx_speed;
55 1.1 tsubai
56 1.1 tsubai u_int kb_buzzf;
57 1.1 tsubai u_int kb_buzz;
58 1.1 tsubai
59 1.1 tsubai u_int kb_tx_data;
60 1.1 tsubai u_int kb_tx_stat;
61 1.1 tsubai u_int kb_tx_intr_en;
62 1.1 tsubai u_int kb_tx_reset;
63 1.1 tsubai u_int kb_tx_speed;
64 1.1 tsubai };
65 1.1 tsubai
66 1.1 tsubai struct kb_ap_softc {
67 1.1 tsubai struct device sc_dev;
68 1.1 tsubai volatile struct kbreg *sc_reg;
69 1.1 tsubai struct device *sc_wskbddev;
70 1.1 tsubai };
71 1.1 tsubai
72 1.1 tsubai int kb_ap_match(struct device *, struct cfdata *, void *);
73 1.1 tsubai void kb_ap_attach(struct device *, struct device *, void *);
74 1.1 tsubai int kb_ap_intr(void *);
75 1.1 tsubai
76 1.1 tsubai void kb_ap_cnattach(void);
77 1.1 tsubai void kb_ap_cngetc(void *, u_int *, int *);
78 1.1 tsubai void kb_ap_cnpollc(void *, int);
79 1.1 tsubai
80 1.1 tsubai int kb_ap_enable(void *, int);
81 1.1 tsubai void kb_ap_setleds(void *, int);
82 1.1 tsubai int kb_ap_ioctl(void *, u_long, caddr_t, int, struct proc *);
83 1.1 tsubai
84 1.1 tsubai extern struct wscons_keydesc newskb_keydesctab[];
85 1.1 tsubai
86 1.4 thorpej CFATTACH_DECL(kb_ap, sizeof(struct kb_ap_softc),
87 1.4 thorpej kb_ap_match, kb_ap_attach, NULL, NULL);
88 1.1 tsubai
89 1.1 tsubai struct wskbd_accessops kb_ap_accessops = {
90 1.1 tsubai kb_ap_enable,
91 1.1 tsubai kb_ap_setleds,
92 1.1 tsubai kb_ap_ioctl,
93 1.1 tsubai };
94 1.1 tsubai
95 1.1 tsubai struct wskbd_consops kb_ap_consops = {
96 1.1 tsubai kb_ap_cngetc,
97 1.1 tsubai kb_ap_cnpollc,
98 1.1 tsubai };
99 1.1 tsubai
100 1.1 tsubai struct wskbd_mapdata kb_ap_keymapdata = {
101 1.1 tsubai newskb_keydesctab,
102 1.1 tsubai KB_JP,
103 1.1 tsubai };
104 1.1 tsubai
105 1.1 tsubai int
106 1.1 tsubai kb_ap_match(parent, cf, aux)
107 1.1 tsubai struct device *parent;
108 1.1 tsubai struct cfdata *cf;
109 1.1 tsubai void *aux;
110 1.1 tsubai {
111 1.1 tsubai struct apbus_attach_args *apa = aux;
112 1.1 tsubai
113 1.1 tsubai if (strcmp(apa->apa_name, "kb") == 0)
114 1.1 tsubai return 1;
115 1.1 tsubai
116 1.1 tsubai return 0;
117 1.1 tsubai }
118 1.1 tsubai
119 1.1 tsubai void
120 1.1 tsubai kb_ap_attach(parent, self, aux)
121 1.1 tsubai struct device *parent, *self;
122 1.1 tsubai void *aux;
123 1.1 tsubai {
124 1.1 tsubai struct kb_ap_softc *sc = (void *)self;
125 1.1 tsubai struct apbus_attach_args *apa = aux;
126 1.1 tsubai volatile struct kbreg *reg = (void *)apa->apa_hwbase;
127 1.1 tsubai volatile int *dipsw = (void *)NEWS5000_DIP_SWITCH;
128 1.1 tsubai struct wskbddev_attach_args waa;
129 1.1 tsubai int cons = 0;
130 1.1 tsubai
131 1.1 tsubai printf(" slot%d addr 0x%lx", apa->apa_slotno, apa->apa_hwbase);
132 1.1 tsubai
133 1.1 tsubai sc->sc_reg = reg;
134 1.1 tsubai
135 1.1 tsubai if (*dipsw & 7) {
136 1.1 tsubai printf(" (console)");
137 1.1 tsubai cons = 1;
138 1.1 tsubai }
139 1.1 tsubai printf("\n");
140 1.1 tsubai
141 1.1 tsubai reg->kb_rx_reset = 0x03;
142 1.1 tsubai reg->kb_tx_reset = 0x03;
143 1.1 tsubai
144 1.1 tsubai reg->kb_rx_speed = 0x04;
145 1.1 tsubai reg->kb_tx_speed = 0x04;
146 1.1 tsubai
147 1.1 tsubai reg->kb_rx_intr_en = 1;
148 1.1 tsubai reg->kb_tx_intr_en = 0;
149 1.1 tsubai
150 1.1 tsubai apbus_intr_establish(1, NEWS5000_INT1_KBD, 0, kb_ap_intr, sc,
151 1.1 tsubai "", apa->apa_ctlnum);
152 1.1 tsubai
153 1.1 tsubai waa.console = cons;
154 1.1 tsubai waa.keymap = &kb_ap_keymapdata;
155 1.1 tsubai waa.accessops = &kb_ap_accessops;
156 1.1 tsubai waa.accesscookie = sc;
157 1.1 tsubai
158 1.1 tsubai sc->sc_wskbddev = config_found(self, &waa, wskbddevprint);
159 1.1 tsubai }
160 1.1 tsubai
161 1.1 tsubai int
162 1.1 tsubai kb_ap_intr(v)
163 1.1 tsubai void *v;
164 1.1 tsubai {
165 1.1 tsubai struct kb_ap_softc *sc = v;
166 1.1 tsubai volatile struct kbreg *reg = sc->sc_reg;
167 1.1 tsubai int key, val, type, release;
168 1.1 tsubai int rv = 0;
169 1.1 tsubai
170 1.1 tsubai while (reg->kb_rx_stat & RX_KBRDY) {
171 1.1 tsubai key = reg->kb_rx_data;
172 1.1 tsubai val = key & 0x7f;
173 1.1 tsubai release = key & 0x80;
174 1.1 tsubai type = release ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
175 1.1 tsubai
176 1.1 tsubai if (sc->sc_wskbddev)
177 1.1 tsubai wskbd_input(sc->sc_wskbddev, type, val);
178 1.1 tsubai
179 1.1 tsubai rv = 1;
180 1.1 tsubai }
181 1.1 tsubai
182 1.1 tsubai return rv;
183 1.1 tsubai }
184 1.1 tsubai
185 1.1 tsubai void
186 1.1 tsubai kb_ap_cnattach()
187 1.1 tsubai {
188 1.1 tsubai wskbd_cnattach(&kb_ap_consops, (void *)0xbf900000, &kb_ap_keymapdata);
189 1.1 tsubai }
190 1.1 tsubai
191 1.1 tsubai void
192 1.1 tsubai kb_ap_cngetc(v, type, data)
193 1.1 tsubai void *v;
194 1.1 tsubai u_int *type;
195 1.1 tsubai int *data;
196 1.1 tsubai {
197 1.1 tsubai volatile struct kbreg *reg = v;
198 1.1 tsubai int key, release, ointr;
199 1.1 tsubai
200 1.1 tsubai /* Disable keyboard interrupt. */
201 1.1 tsubai ointr = reg->kb_rx_intr_en;
202 1.1 tsubai reg->kb_rx_intr_en = 0;
203 1.1 tsubai
204 1.1 tsubai /* Wait for key data. */
205 1.1 tsubai while ((reg->kb_rx_stat & RX_KBRDY) == 0);
206 1.1 tsubai
207 1.1 tsubai key = reg->kb_rx_data;
208 1.1 tsubai release = key & 0x80;
209 1.1 tsubai *data = key & 0x7f;
210 1.1 tsubai *type = release ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
211 1.1 tsubai
212 1.1 tsubai reg->kb_rx_intr_en = ointr;
213 1.1 tsubai }
214 1.1 tsubai
215 1.1 tsubai void
216 1.1 tsubai kb_ap_cnpollc(v, on)
217 1.1 tsubai void *v;
218 1.1 tsubai int on;
219 1.1 tsubai {
220 1.1 tsubai }
221 1.1 tsubai
222 1.1 tsubai int
223 1.1 tsubai kb_ap_enable(v, on)
224 1.1 tsubai void *v;
225 1.1 tsubai int on;
226 1.1 tsubai {
227 1.1 tsubai return 0;
228 1.1 tsubai }
229 1.1 tsubai
230 1.1 tsubai void
231 1.1 tsubai kb_ap_setleds(v, on)
232 1.1 tsubai void *v;
233 1.1 tsubai int on;
234 1.1 tsubai {
235 1.1 tsubai }
236 1.1 tsubai
237 1.1 tsubai int
238 1.1 tsubai kb_ap_ioctl(v, cmd, data, flag, p)
239 1.1 tsubai void *v;
240 1.1 tsubai u_long cmd;
241 1.1 tsubai caddr_t data;
242 1.1 tsubai int flag;
243 1.1 tsubai struct proc *p;
244 1.1 tsubai {
245 1.1 tsubai switch (cmd) {
246 1.1 tsubai case WSKBDIO_GTYPE:
247 1.1 tsubai *(int *)data = 0; /* XXX */
248 1.1 tsubai return 0;
249 1.1 tsubai case WSKBDIO_SETLEDS:
250 1.1 tsubai return 0;
251 1.1 tsubai case WSKBDIO_GETLEDS:
252 1.1 tsubai *(int *)data = 0;
253 1.1 tsubai return 0;
254 1.1 tsubai }
255 1.1 tsubai
256 1.2 atatat return EPASSTHROUGH;
257 1.1 tsubai }
258