1 /* $NetBSD: kb_hb.c,v 1.11 2007/03/04 06:00:26 christos Exp $ */
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
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>
46 volatile uint8_t kb_data
;
47 volatile uint8_t kb_stat
;
48 volatile uint8_t kb_reset
;
49 volatile uint8_t kb_init
;
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
= {
81 struct wskbd_consops kb_hb_consops
= {
86 struct wskbd_mapdata kb_hb_keymapdata
= {
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)
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
;
108 volatile uint32_t *dipsw
= (void *)DIP_SWITCH
;
109 struct wskbddev_attach_args aa
;
114 reg
= (struct kbreg
*)ha
->ha_addr
;
121 reg
->kb_reset
= 0x01;
122 reg
->kb_init
= 0xf0; /* 9600 bps */
124 aprint_normal(" level %d", intr
);
128 aprint_normal(" (console)");
132 hb_intr_establish(intr
, INTEN0_KBDINT
, IPL_TTY
, kb_hb_intr
, sc
);
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
);
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
;
152 while (reg
->kb_stat
& RX_KBRDY
) {
154 release
= code
& 0x80;
156 type
= release
? WSCONS_EVENT_KEY_UP
: WSCONS_EVENT_KEY_DOWN
;
158 wskbd_input(sc
->sc_wskbddev
, type
, val
);
169 volatile uint32_t *dipsw
= (void *)DIP_SWITCH
;
172 wskbd_cnattach(&kb_hb_consops
, (void *)KEYB_DATA
,
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
;
186 /* Wait for key data. */
187 while ((reg
->kb_stat
& RX_KBRDY
) == 0);
190 release
= code
& 0x80;
192 *type
= release
? WSCONS_EVENT_KEY_UP
: WSCONS_EVENT_KEY_DOWN
;
198 kb_hb_cnpollc(void *v
, int on
)
203 kb_hb_enable(void *v
, int on
)
210 kb_hb_setleds(void *v
, int on
)
215 kb_hb_ioctl(void *v
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
221 *(int *)data
= 0; /* XXX */
223 case WSKBDIO_SETLEDS
:
225 case WSKBDIO_GETLEDS
: