Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / newsmips / dev / kb_hb.c
blobacab00b104b3d175167349688e9df650dc170039
1 /* $NetBSD: kb_hb.c,v 1.11 2007/03/04 06:00:26 christos Exp $ */
3 /*-
4 * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
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
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: kb_hb.c,v 1.11 2007/03/04 06:00:26 christos Exp $");
32 #include <sys/param.h>
33 #include <sys/device.h>
34 #include <sys/systm.h>
36 #include <dev/wscons/wsconsio.h>
37 #include <dev/wscons/wskbdvar.h>
38 #include <dev/wscons/wsksymdef.h>
39 #include <dev/wscons/wsksymvar.h>
41 #include <machine/adrsmap.h>
43 #include <newsmips/dev/hbvar.h>
45 struct kbreg {
46 volatile uint8_t kb_data;
47 volatile uint8_t kb_stat;
48 volatile uint8_t kb_reset;
49 volatile uint8_t kb_init;
52 struct kb_hb_softc {
53 device_t sc_dev;
54 struct kbreg *sc_reg;
55 struct device *sc_wskbddev;
58 int kb_hb_match(device_t, cfdata_t, void *);
59 void kb_hb_attach(device_t, device_t, void *);
60 int kb_hb_intr(void *);
62 void kb_hb_cnattach(void);
63 void kb_hb_cngetc(void *, u_int *, int *);
64 void kb_hb_cnpollc(void *, int);
66 int kb_hb_enable(void *, int);
67 void kb_hb_setleds(void *, int);
68 int kb_hb_ioctl(void *, u_long, void *, int, struct lwp *);
70 extern struct wscons_keydesc newskb_keydesctab[];
72 CFATTACH_DECL_NEW(kb_hb, sizeof(struct kb_hb_softc),
73 kb_hb_match, kb_hb_attach, NULL, NULL);
75 struct wskbd_accessops kb_hb_accessops = {
76 kb_hb_enable,
77 kb_hb_setleds,
78 kb_hb_ioctl
81 struct wskbd_consops kb_hb_consops = {
82 kb_hb_cngetc,
83 kb_hb_cnpollc
86 struct wskbd_mapdata kb_hb_keymapdata = {
87 newskb_keydesctab,
88 KB_JP
91 int
92 kb_hb_match(device_t parent, cfdata_t cf, void *aux)
94 struct hb_attach_args *ha = aux;
96 if (strcmp(ha->ha_name, "kb") == 0)
97 return 1;
99 return 0;
102 void
103 kb_hb_attach(device_t parent, device_t self, void *aux)
105 struct kb_hb_softc *sc = device_private(self);
106 struct hb_attach_args *ha = aux;
107 struct kbreg *reg;
108 volatile uint32_t *dipsw = (void *)DIP_SWITCH;
109 struct wskbddev_attach_args aa;
110 int intr, cons;
112 sc->sc_dev = self;
114 reg = (struct kbreg *)ha->ha_addr;
115 intr = ha->ha_level;
117 if (intr == -1)
118 intr = 2;
120 sc->sc_reg = reg;
121 reg->kb_reset = 0x01;
122 reg->kb_init = 0xf0; /* 9600 bps */
124 aprint_normal(" level %d", intr);
125 cons = 0;
126 if (*dipsw & 7) {
127 cons = 1;
128 aprint_normal(" (console)");
130 aprint_normal("\n");
132 hb_intr_establish(intr, INTEN0_KBDINT, IPL_TTY, kb_hb_intr, sc);
134 aa.console = cons;
135 aa.keymap = &kb_hb_keymapdata;
136 aa.accessops = &kb_hb_accessops;
137 aa.accesscookie = sc;
138 sc->sc_wskbddev = config_found(self, &aa, wskbddevprint);
142 kb_hb_intr(void *v)
144 struct kb_hb_softc *sc = v;
145 struct kbreg *reg = sc->sc_reg;
146 volatile uint8_t *ien = (void *)INTEN0;
147 int code, type, release, val;
148 int rv = 0;
150 *ien &= ~RX_KBINTE;
152 while (reg->kb_stat & RX_KBRDY) {
153 code = reg->kb_data;
154 release = code & 0x80;
155 val = code & 0x7f;
156 type = release ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
157 if (sc->sc_wskbddev)
158 wskbd_input(sc->sc_wskbddev, type, val);
159 rv = 1;
162 *ien |= RX_KBINTE;
163 return rv;
166 void
167 kb_hb_cnattach(void)
169 volatile uint32_t *dipsw = (void *)DIP_SWITCH;
171 if (*dipsw & 7)
172 wskbd_cnattach(&kb_hb_consops, (void *)KEYB_DATA,
173 &kb_hb_keymapdata);
176 void
177 kb_hb_cngetc(void *v, u_int *type, int *data)
179 struct kbreg *reg = v;
180 volatile uint8_t *ien = (void *)INTEN0;
181 int code, release, ointr;
183 ointr = *ien & RX_KBINTE;
184 *ien &= ~RX_KBINTE;
186 /* Wait for key data. */
187 while ((reg->kb_stat & RX_KBRDY) == 0);
189 code = reg->kb_data;
190 release = code & 0x80;
191 *data = code & 0x7f;
192 *type = release ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
194 *ien |= ointr;
197 void
198 kb_hb_cnpollc(void *v, int on)
203 kb_hb_enable(void *v, int on)
206 return 0;
209 void
210 kb_hb_setleds(void *v, int on)
215 kb_hb_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
218 switch (cmd) {
220 case WSKBDIO_GTYPE:
221 *(int *)data = 0; /* XXX */
222 return 0;
223 case WSKBDIO_SETLEDS:
224 return 0;
225 case WSKBDIO_GETLEDS:
226 *(int *)data = 0;
227 return 0;
230 return EPASSTHROUGH;