adb_bt.c revision 1.1.4.2 1 1.1.4.2 ad /* $NetBSD: adb_bt.c,v 1.1.4.2 2007/06/09 21:37:12 ad Exp $ */
2 1.1.4.2 ad
3 1.1.4.2 ad /*-
4 1.1.4.2 ad * Copyright (c) 2006 Michael Lorenz
5 1.1.4.2 ad * All rights reserved.
6 1.1.4.2 ad *
7 1.1.4.2 ad * Redistribution and use in source and binary forms, with or without
8 1.1.4.2 ad * modification, are permitted provided that the following conditions
9 1.1.4.2 ad * are met:
10 1.1.4.2 ad * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 ad * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.4.2 ad * notice, this list of conditions and the following disclaimer in the
14 1.1.4.2 ad * documentation and/or other materials provided with the distribution.
15 1.1.4.2 ad * 3. Neither the name of The NetBSD Foundation nor the names of its
16 1.1.4.2 ad * contributors may be used to endorse or promote products derived
17 1.1.4.2 ad * from this software without specific prior written permission.
18 1.1.4.2 ad *
19 1.1.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.4.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.4.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.4.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.4.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.4.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.4.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.4.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.4.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.4.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.4.2 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.1.4.2 ad */
31 1.1.4.2 ad
32 1.1.4.2 ad #include <sys/cdefs.h>
33 1.1.4.2 ad __KERNEL_RCSID(0, "$NetBSD: adb_bt.c,v 1.1.4.2 2007/06/09 21:37:12 ad Exp $");
34 1.1.4.2 ad
35 1.1.4.2 ad #include <sys/param.h>
36 1.1.4.2 ad #include <sys/systm.h>
37 1.1.4.2 ad #include <sys/kernel.h>
38 1.1.4.2 ad #include <sys/device.h>
39 1.1.4.2 ad #include <sys/proc.h>
40 1.1.4.2 ad
41 1.1.4.2 ad #include <dev/wscons/wsconsio.h>
42 1.1.4.2 ad #include <dev/wscons/wskbdvar.h>
43 1.1.4.2 ad #include <dev/wscons/wsksymdef.h>
44 1.1.4.2 ad #include <dev/wscons/wsksymvar.h>
45 1.1.4.2 ad #include <dev/wscons/wsmousevar.h>
46 1.1.4.2 ad
47 1.1.4.2 ad #include <dev/sysmon/sysmonvar.h>
48 1.1.4.2 ad #include <dev/sysmon/sysmon_taskq.h>
49 1.1.4.2 ad
50 1.1.4.2 ad #include <machine/autoconf.h>
51 1.1.4.2 ad #include <machine/keyboard.h>
52 1.1.4.2 ad #include <machine/adbsys.h>
53 1.1.4.2 ad
54 1.1.4.2 ad #include <dev/adb/adbvar.h>
55 1.1.4.2 ad #include <dev/adb/adb_keymap.h>
56 1.1.4.2 ad
57 1.1.4.2 ad #include "opt_wsdisplay_compat.h"
58 1.1.4.2 ad #include "adbdebug.h"
59 1.1.4.2 ad
60 1.1.4.2 ad #ifdef ADBBT_DEBUG
61 1.1.4.2 ad #define DPRINTF printf
62 1.1.4.2 ad #else
63 1.1.4.2 ad #define DPRINTF while (0) printf
64 1.1.4.2 ad #endif
65 1.1.4.2 ad
66 1.1.4.2 ad #define BT_VOL_UP 0x06
67 1.1.4.2 ad #define BT_VOL_DOWN 0x07
68 1.1.4.2 ad #define BT_VOL_MUTE 0x08
69 1.1.4.2 ad #define BT_BRT_UP 0x09
70 1.1.4.2 ad #define BT_BRT_DOWN 0x0a
71 1.1.4.2 ad #define BT_EJECT 0x0b
72 1.1.4.2 ad #define BT_F7 0x0c
73 1.1.4.2 ad #define BT_NUMLOCK 0x7f
74 1.1.4.2 ad
75 1.1.4.2 ad static int adbbt_match(struct device *, struct cfdata *, void *);
76 1.1.4.2 ad static void adbbt_attach(struct device *, struct device *, void *);
77 1.1.4.2 ad
78 1.1.4.2 ad struct adbbt_softc {
79 1.1.4.2 ad struct device sc_dev;
80 1.1.4.2 ad struct adb_device *sc_adbdev;
81 1.1.4.2 ad struct adb_bus_accessops *sc_ops;
82 1.1.4.2 ad struct device *sc_wskbddev;
83 1.1.4.2 ad int sc_msg_len;
84 1.1.4.2 ad int sc_event;
85 1.1.4.2 ad int sc_poll;
86 1.1.4.2 ad int sc_polled_chars;
87 1.1.4.2 ad int sc_rawkbd;
88 1.1.4.2 ad uint8_t sc_buffer[16];
89 1.1.4.2 ad uint8_t sc_pollbuf[16];
90 1.1.4.2 ad uint8_t sc_trans[16];
91 1.1.4.2 ad uint8_t sc_us;
92 1.1.4.2 ad };
93 1.1.4.2 ad
94 1.1.4.2 ad /* Driver definition. */
95 1.1.4.2 ad CFATTACH_DECL(adbbt, sizeof(struct adbbt_softc),
96 1.1.4.2 ad adbbt_match, adbbt_attach, NULL, NULL);
97 1.1.4.2 ad
98 1.1.4.2 ad extern struct cfdriver adbbt_cd;
99 1.1.4.2 ad
100 1.1.4.2 ad static int adbbt_enable(void *, int);
101 1.1.4.2 ad static void adbbt_set_leds(void *, int);
102 1.1.4.2 ad static int adbbt_ioctl(void *, u_long, void *, int, struct lwp *);
103 1.1.4.2 ad static void adbbt_handler(void *, int, uint8_t *);
104 1.1.4.2 ad
105 1.1.4.2 ad struct wskbd_accessops adbbt_accessops = {
106 1.1.4.2 ad adbbt_enable,
107 1.1.4.2 ad adbbt_set_leds,
108 1.1.4.2 ad adbbt_ioctl,
109 1.1.4.2 ad };
110 1.1.4.2 ad
111 1.1.4.2 ad struct wskbd_mapdata adbbt_keymapdata = {
112 1.1.4.2 ad akbd_keydesctab,
113 1.1.4.2 ad #ifdef AKBD_LAYOUT
114 1.1.4.2 ad AKBD_LAYOUT,
115 1.1.4.2 ad #else
116 1.1.4.2 ad KB_US,
117 1.1.4.2 ad #endif
118 1.1.4.2 ad };
119 1.1.4.2 ad
120 1.1.4.2 ad static int
121 1.1.4.2 ad adbbt_match(parent, cf, aux)
122 1.1.4.2 ad struct device *parent;
123 1.1.4.2 ad struct cfdata *cf;
124 1.1.4.2 ad void *aux;
125 1.1.4.2 ad {
126 1.1.4.2 ad struct adb_attach_args *aaa = aux;
127 1.1.4.2 ad
128 1.1.4.2 ad if ((aaa->dev->original_addr == ADBADDR_MISC) &&
129 1.1.4.2 ad (aaa->dev->handler_id == 0x1f))
130 1.1.4.2 ad return 100;
131 1.1.4.2 ad else
132 1.1.4.2 ad return 0;
133 1.1.4.2 ad }
134 1.1.4.2 ad
135 1.1.4.2 ad static void
136 1.1.4.2 ad adbbt_attach(struct device *parent, struct device *self, void *aux)
137 1.1.4.2 ad {
138 1.1.4.2 ad struct adbbt_softc *sc = (struct adbbt_softc *)self;
139 1.1.4.2 ad struct adb_attach_args *aaa = aux;
140 1.1.4.2 ad struct wskbddev_attach_args a;
141 1.1.4.2 ad
142 1.1.4.2 ad sc->sc_ops = aaa->ops;
143 1.1.4.2 ad sc->sc_adbdev = aaa->dev;
144 1.1.4.2 ad sc->sc_adbdev->cookie = sc;
145 1.1.4.2 ad sc->sc_adbdev->handler = adbbt_handler;
146 1.1.4.2 ad sc->sc_us = ADBTALK(sc->sc_adbdev->current_addr, 0);
147 1.1.4.2 ad
148 1.1.4.2 ad sc->sc_msg_len = 0;
149 1.1.4.2 ad sc->sc_rawkbd = 0;
150 1.1.4.2 ad sc->sc_trans[6] = 96; /* F5 */
151 1.1.4.2 ad sc->sc_trans[7] = 118; /* F4 */
152 1.1.4.2 ad sc->sc_trans[8] = 99; /* F3 */
153 1.1.4.2 ad sc->sc_trans[9] = 120; /* F2 */
154 1.1.4.2 ad sc->sc_trans[10] = 122; /* F1 */
155 1.1.4.2 ad sc->sc_trans[11] = 111; /* F12 */
156 1.1.4.2 ad
157 1.1.4.2 ad printf(" addr %d: button device\n", sc->sc_adbdev->current_addr);
158 1.1.4.2 ad
159 1.1.4.2 ad a.console = 0;
160 1.1.4.2 ad a.keymap = &adbbt_keymapdata;
161 1.1.4.2 ad a.accessops = &adbbt_accessops;
162 1.1.4.2 ad a.accesscookie = sc;
163 1.1.4.2 ad
164 1.1.4.2 ad sc->sc_wskbddev = config_found_ia(self, "wskbddev", &a, wskbddevprint);
165 1.1.4.2 ad }
166 1.1.4.2 ad
167 1.1.4.2 ad static void
168 1.1.4.2 ad adbbt_handler(void *cookie, int len, uint8_t *data)
169 1.1.4.2 ad {
170 1.1.4.2 ad struct adbbt_softc *sc = cookie;
171 1.1.4.2 ad int type;
172 1.1.4.2 ad uint8_t k, keyval, scancode;
173 1.1.4.2 ad
174 1.1.4.2 ad #ifdef ADBBT_DEBUG
175 1.1.4.2 ad int i;
176 1.1.4.2 ad printf("%s: %02x - ", sc->sc_dev.dv_xname, sc->sc_us);
177 1.1.4.2 ad for (i = 0; i < len; i++) {
178 1.1.4.2 ad printf(" %02x", data[i]);
179 1.1.4.2 ad }
180 1.1.4.2 ad printf("\n");
181 1.1.4.2 ad #endif
182 1.1.4.2 ad k = data[2];
183 1.1.4.2 ad keyval = ADBK_KEYVAL(k);
184 1.1.4.2 ad if ((keyval < 6) || (keyval > 0x0c))
185 1.1.4.2 ad return;
186 1.1.4.2 ad scancode = sc->sc_trans[keyval];
187 1.1.4.2 ad
188 1.1.4.2 ad #ifdef WSDISPLAY_COMPAT_RAWKBD
189 1.1.4.2 ad if (sc->sc_rawkbd) {
190 1.1.4.2 ad char cbuf[2];
191 1.1.4.2 ad int s;
192 1.1.4.2 ad
193 1.1.4.2 ad cbuf[0] = scancode | (k & 0x80);
194 1.1.4.2 ad
195 1.1.4.2 ad s = spltty();
196 1.1.4.2 ad wskbd_rawinput(sc->sc_wskbddev, cbuf, 1);
197 1.1.4.2 ad splx(s);
198 1.1.4.2 ad } else {
199 1.1.4.2 ad #endif
200 1.1.4.2 ad
201 1.1.4.2 ad /* normal event */
202 1.1.4.2 ad type = ADBK_PRESS(k) ?
203 1.1.4.2 ad WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
204 1.1.4.2 ad wskbd_input(sc->sc_wskbddev, type, scancode);
205 1.1.4.2 ad #ifdef WSDISPLAY_COMPAT_RAWKBD
206 1.1.4.2 ad }
207 1.1.4.2 ad #endif
208 1.1.4.2 ad }
209 1.1.4.2 ad
210 1.1.4.2 ad static void
211 1.1.4.2 ad adbbt_set_leds(void *cookie, int leds)
212 1.1.4.2 ad {
213 1.1.4.2 ad /* we have no LEDs */
214 1.1.4.2 ad }
215 1.1.4.2 ad
216 1.1.4.2 ad static int
217 1.1.4.2 ad adbbt_enable(void *v, int on)
218 1.1.4.2 ad {
219 1.1.4.2 ad return 0;
220 1.1.4.2 ad }
221 1.1.4.2 ad
222 1.1.4.2 ad static int
223 1.1.4.2 ad adbbt_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
224 1.1.4.2 ad {
225 1.1.4.2 ad #ifdef WSDISPLAY_COMPAT_RAWKBD
226 1.1.4.2 ad struct adbbt_softc *sc = (struct adbbt_softc *) v;
227 1.1.4.2 ad #endif
228 1.1.4.2 ad
229 1.1.4.2 ad switch (cmd) {
230 1.1.4.2 ad
231 1.1.4.2 ad case WSKBDIO_GTYPE:
232 1.1.4.2 ad *(int *)data = WSKBD_TYPE_ADB;
233 1.1.4.2 ad return 0;
234 1.1.4.2 ad #ifdef WSDISPLAY_COMPAT_RAWKBD
235 1.1.4.2 ad case WSKBDIO_SETMODE:
236 1.1.4.2 ad sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
237 1.1.4.2 ad return 0;
238 1.1.4.2 ad #endif
239 1.1.4.2 ad }
240 1.1.4.2 ad
241 1.1.4.2 ad return EPASSTHROUGH;
242 1.1.4.2 ad }
243