xref: /netbsd-src/sys/arch/news68k/dev/kb.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: kb.c,v 1.6 2004/09/04 13:43:11 tsutsui Exp $	*/
2 
3 /*
4  * Copyright (c) 2001 Izumi Tsutsui.
5  * Copyright (c) 2000 Tsubai Masanari.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: kb.c,v 1.6 2004/09/04 13:43:11 tsutsui Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 
38 #include <dev/wscons/wsconsio.h>
39 #include <dev/wscons/wskbdvar.h>
40 #include <dev/wscons/wsksymdef.h>
41 #include <dev/wscons/wsksymvar.h>
42 
43 #include <machine/bus.h>
44 
45 #include <arch/news68k/dev/kbvar.h>
46 
47 /* #define KB_DEBUG */
48 
49 void	kb_cngetc(void *, u_int *, int *);
50 void	kb_cnpollc(void *, int);
51 int	kb_enable(void *, int);
52 void	kb_set_leds(void *, int);
53 int	kb_ioctl(void *, u_long, caddr_t, int, struct proc *);
54 
55 extern struct wscons_keydesc newskb_keydesctab[];
56 
57 struct wskbd_accessops kb_accessops = {
58 	kb_enable,
59 	kb_set_leds,
60 	kb_ioctl,
61 };
62 
63 struct wskbd_consops kb_consops = {
64 	kb_cngetc,
65 	kb_cnpollc,
66 };
67 
68 struct wskbd_mapdata kb_keymapdata = {
69 	newskb_keydesctab,
70 	KB_JP,
71 };
72 
73 void
74 kb_intr(struct kb_softc *sc)
75 {
76 	struct console_softc *kb_conssc = sc->sc_conssc;
77 	bus_space_tag_t bt = sc->sc_bt;
78 	bus_space_handle_t bh = sc->sc_bh;
79 	bus_size_t offset = sc->sc_offset;
80 	int key, val;
81 	u_int type;
82 
83 	kb_conssc->cs_nkeyevents++;
84 
85 	key = bus_space_read_1(bt, bh, offset);
86 	type = (key & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
87 	val = key & 0x7f;
88 
89 #ifdef KB_DEBUG
90 	printf("kb_intr: key=%02x, type=%d, val=%02x\n", key, type, val);
91 #endif
92 	kb_conssc->cs_key = key;
93 	kb_conssc->cs_type = type;
94 	kb_conssc->cs_val = val;
95 
96 	if (!kb_conssc->cs_polling)
97 		wskbd_input(sc->sc_wskbddev, type, val);
98 }
99 
100 int
101 kb_cnattach(struct console_softc *conssc_p)
102 {
103 
104 	wskbd_cnattach(&kb_consops, conssc_p, &kb_keymapdata);
105 	return 0;
106 }
107 
108 void
109 kb_cngetc(void *v, u_int *type, int *data)
110 {
111 	struct console_softc *conssc = v;
112 	u_int nkey;
113 
114 	/* set to polling mode */
115 	conssc->cs_polling = 1;
116 
117 	/* wait until any keyevent occur */
118 	nkey = conssc->cs_nkeyevents;
119 	while (conssc->cs_nkeyevents == nkey)
120 		;
121 
122 	/* get last keyevent */
123 	*data = conssc->cs_val;
124 	*type = conssc->cs_type;
125 
126 	conssc->cs_polling = 0;
127 }
128 
129 void
130 kb_cnpollc(void *v, int on)
131 {
132 }
133 
134 int
135 kb_enable(void *v, int on)
136 {
137 
138 	return 0;
139 }
140 
141 void
142 kb_set_leds(void *v, int on)
143 {
144 }
145 
146 int
147 kb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
148 {
149 #if 0
150 	struct console_softc *cs = v;
151 #endif
152 
153 	switch (cmd) {
154 	case WSKBDIO_GTYPE:
155 		*(int *)data = 0;	/* XXX */
156 		return 0;
157 	case WSKBDIO_SETLEDS:
158 		return 0;
159 	case WSKBDIO_GETLEDS:
160 		*(int *)data = 0;
161 		return 0;
162 	case WSKBDIO_COMPLEXBELL:
163 		return 0;
164 	}
165 
166 	return EPASSTHROUGH;
167 }
168