ums.c revision 1.89 1 1.89 skrll /* $NetBSD: ums.c,v 1.89 2016/04/23 10:15:32 skrll Exp $ */
2 1.1 augustss
3 1.1 augustss /*
4 1.1 augustss * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 augustss * All rights reserved.
6 1.1 augustss *
7 1.11 augustss * This code is derived from software contributed to The NetBSD Foundation
8 1.43 augustss * by Lennart Augustsson (lennart (at) augustsson.net) at
9 1.11 augustss * Carlstedt Research & Technology.
10 1.1 augustss *
11 1.1 augustss * Redistribution and use in source and binary forms, with or without
12 1.1 augustss * modification, are permitted provided that the following conditions
13 1.1 augustss * are met:
14 1.1 augustss * 1. Redistributions of source code must retain the above copyright
15 1.1 augustss * notice, this list of conditions and the following disclaimer.
16 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 augustss * notice, this list of conditions and the following disclaimer in the
18 1.1 augustss * documentation and/or other materials provided with the distribution.
19 1.1 augustss *
20 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
31 1.20 augustss */
32 1.20 augustss
33 1.20 augustss /*
34 1.60 augustss * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
35 1.1 augustss */
36 1.52 lukem
37 1.52 lukem #include <sys/cdefs.h>
38 1.89 skrll __KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.89 2016/04/23 10:15:32 skrll Exp $");
39 1.1 augustss
40 1.1 augustss #include <sys/param.h>
41 1.1 augustss #include <sys/systm.h>
42 1.1 augustss #include <sys/kernel.h>
43 1.1 augustss #include <sys/device.h>
44 1.1 augustss #include <sys/ioctl.h>
45 1.1 augustss #include <sys/file.h>
46 1.1 augustss #include <sys/select.h>
47 1.1 augustss #include <sys/proc.h>
48 1.1 augustss #include <sys/vnode.h>
49 1.1 augustss #include <sys/poll.h>
50 1.1 augustss
51 1.1 augustss #include <dev/usb/usb.h>
52 1.1 augustss #include <dev/usb/usbhid.h>
53 1.1 augustss
54 1.1 augustss #include <dev/usb/usbdi.h>
55 1.1 augustss #include <dev/usb/usbdi_util.h>
56 1.1 augustss #include <dev/usb/usbdevs.h>
57 1.1 augustss #include <dev/usb/usb_quirks.h>
58 1.53 augustss #include <dev/usb/uhidev.h>
59 1.1 augustss #include <dev/usb/hid.h>
60 1.1 augustss
61 1.3 augustss #include <dev/wscons/wsconsio.h>
62 1.3 augustss #include <dev/wscons/wsmousevar.h>
63 1.3 augustss
64 1.86 christos #ifdef UMS_DEBUG
65 1.81 dyoung #define DPRINTF(x) if (umsdebug) printf x
66 1.81 dyoung #define DPRINTFN(n,x) if (umsdebug>(n)) printf x
67 1.1 augustss int umsdebug = 0;
68 1.1 augustss #else
69 1.1 augustss #define DPRINTF(x)
70 1.1 augustss #define DPRINTFN(n,x)
71 1.1 augustss #endif
72 1.1 augustss
73 1.27 augustss #define UMS_BUT(i) ((i) == 1 || (i) == 2 ? 3 - (i) : i)
74 1.27 augustss
75 1.27 augustss #define UMSUNIT(s) (minor(s))
76 1.16 augustss
77 1.16 augustss #define PS2LBUTMASK x01
78 1.16 augustss #define PS2RBUTMASK x02
79 1.16 augustss #define PS2MBUTMASK x04
80 1.1 augustss #define PS2BUTMASK 0x0f
81 1.1 augustss
82 1.61 jmcneill #define MAX_BUTTONS 31 /* must not exceed size of sc_buttons */
83 1.53 augustss
84 1.1 augustss struct ums_softc {
85 1.53 augustss struct uhidev sc_hdev;
86 1.53 augustss
87 1.63 augustss struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_w;
88 1.53 augustss struct hid_location sc_loc_btn[MAX_BUTTONS];
89 1.1 augustss
90 1.16 augustss int sc_enabled;
91 1.3 augustss
92 1.84 christos u_int flags; /* device configuration */
93 1.84 christos #define UMS_Z 0x001 /* z direction available */
94 1.84 christos #define UMS_SPUR_BUT_UP 0x002 /* spurious button up events */
95 1.84 christos #define UMS_REVZ 0x004 /* Z-axis is reversed */
96 1.84 christos #define UMS_W 0x008 /* w direction/tilt available */
97 1.84 christos #define UMS_ABS 0x010 /* absolute position, touchpanel */
98 1.84 christos #define UMS_TIP_SWITCH 0x020 /* digitizer tip switch */
99 1.84 christos #define UMS_SEC_TIP_SWITCH 0x040 /* digitizer secondary tip switch */
100 1.84 christos #define UMS_BARREL_SWITCH 0x080 /* digitizer barrel switch */
101 1.84 christos #define UMS_ERASER 0x100 /* digitizer eraser */
102 1.35 augustss
103 1.16 augustss int nbuttons;
104 1.16 augustss
105 1.89 skrll uint32_t sc_buttons; /* mouse button status */
106 1.71 dyoung device_t sc_wsmousedev;
107 1.28 augustss
108 1.28 augustss char sc_dying;
109 1.1 augustss };
110 1.1 augustss
111 1.84 christos static const struct {
112 1.84 christos u_int feature;
113 1.84 christos u_int flag;
114 1.84 christos } digbut[] = {
115 1.84 christos { HUD_TIP_SWITCH, UMS_TIP_SWITCH },
116 1.84 christos { HUD_SEC_TIP_SWITCH, UMS_SEC_TIP_SWITCH },
117 1.84 christos { HUD_BARREL_SWITCH, UMS_BARREL_SWITCH },
118 1.84 christos { HUD_ERASER, UMS_ERASER },
119 1.84 christos };
120 1.84 christos
121 1.2 augustss #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
122 1.2 augustss
123 1.89 skrll Static void ums_intr(struct uhidev *, void *, u_int);
124 1.1 augustss
125 1.44 augustss Static int ums_enable(void *);
126 1.44 augustss Static void ums_disable(void *);
127 1.89 skrll Static int ums_ioctl(void *, u_long, void *, int, struct lwp *);
128 1.3 augustss
129 1.3 augustss const struct wsmouse_accessops ums_accessops = {
130 1.3 augustss ums_enable,
131 1.3 augustss ums_ioctl,
132 1.3 augustss ums_disable,
133 1.3 augustss };
134 1.3 augustss
135 1.73 cube int ums_match(device_t, cfdata_t, void *);
136 1.71 dyoung void ums_attach(device_t, device_t, void *);
137 1.71 dyoung void ums_childdet(device_t, device_t);
138 1.71 dyoung int ums_detach(device_t, int);
139 1.71 dyoung int ums_activate(device_t, enum devact);
140 1.71 dyoung extern struct cfdriver ums_cd;
141 1.73 cube CFATTACH_DECL2_NEW(ums, sizeof(struct ums_softc), ums_match, ums_attach,
142 1.71 dyoung ums_detach, ums_activate, NULL, ums_childdet);
143 1.1 augustss
144 1.53 augustss int
145 1.73 cube ums_match(device_t parent, cfdata_t match, void *aux)
146 1.1 augustss {
147 1.53 augustss struct uhidev_attach_arg *uha = aux;
148 1.53 augustss int size;
149 1.1 augustss void *desc;
150 1.57 augustss
151 1.79 jakllsch /*
152 1.79 jakllsch * Some (older) Griffin PowerMate knobs may masquerade as a
153 1.79 jakllsch * mouse, avoid treating them as such, they have only one axis.
154 1.79 jakllsch */
155 1.89 skrll if (uha->uiaa->uiaa_vendor == USB_VENDOR_GRIFFIN &&
156 1.89 skrll uha->uiaa->uiaa_product == USB_PRODUCT_GRIFFIN_POWERMATE)
157 1.89 skrll return UMATCH_NONE;
158 1.79 jakllsch
159 1.53 augustss uhidev_get_report_desc(uha->parent, &desc, &size);
160 1.53 augustss if (!hid_is_collection(desc, size, uha->reportid,
161 1.78 jakllsch HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)) &&
162 1.78 jakllsch !hid_is_collection(desc, size, uha->reportid,
163 1.84 christos HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER)) &&
164 1.84 christos !hid_is_collection(desc, size, uha->reportid,
165 1.89 skrll HID_USAGE2(HUP_DIGITIZERS, 0x0002)))
166 1.89 skrll return UMATCH_NONE;
167 1.1 augustss
168 1.89 skrll return UMATCH_IFACECLASS;
169 1.1 augustss }
170 1.1 augustss
171 1.53 augustss void
172 1.73 cube ums_attach(device_t parent, device_t self, void *aux)
173 1.1 augustss {
174 1.73 cube struct ums_softc *sc = device_private(self);
175 1.53 augustss struct uhidev_attach_arg *uha = aux;
176 1.3 augustss struct wsmousedev_attach_args a;
177 1.1 augustss int size;
178 1.1 augustss void *desc;
179 1.89 skrll uint32_t flags, quirks;
180 1.75 rafal int i, hl;
181 1.75 rafal struct hid_location *zloc;
182 1.84 christos bool isdigitizer;
183 1.1 augustss
184 1.69 jmcneill aprint_naive("\n");
185 1.69 jmcneill
186 1.73 cube sc->sc_hdev.sc_dev = self;
187 1.53 augustss sc->sc_hdev.sc_intr = ums_intr;
188 1.53 augustss sc->sc_hdev.sc_parent = uha->parent;
189 1.53 augustss sc->sc_hdev.sc_report_id = uha->reportid;
190 1.1 augustss
191 1.53 augustss quirks = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
192 1.35 augustss if (quirks & UQ_MS_REVZ)
193 1.35 augustss sc->flags |= UMS_REVZ;
194 1.35 augustss if (quirks & UQ_SPUR_BUT_UP)
195 1.35 augustss sc->flags |= UMS_SPUR_BUT_UP;
196 1.24 augustss
197 1.53 augustss uhidev_get_report_desc(uha->parent, &desc, &size);
198 1.16 augustss
199 1.84 christos isdigitizer = hid_is_collection(desc, size, uha->reportid,
200 1.84 christos HID_USAGE2(HUP_DIGITIZERS, 0x0002));
201 1.84 christos
202 1.70 jmcneill if (!pmf_device_register(self, NULL, NULL))
203 1.70 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
204 1.70 jmcneill
205 1.2 augustss if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
206 1.53 augustss uha->reportid, hid_input, &sc->sc_loc_x, &flags)) {
207 1.69 jmcneill aprint_error("\n%s: mouse has no X report\n",
208 1.81 dyoung device_xname(sc->sc_hdev.sc_dev));
209 1.81 dyoung return;
210 1.16 augustss }
211 1.77 mbalmer switch (flags & MOUSE_FLAGS_MASK) {
212 1.77 mbalmer case 0:
213 1.77 mbalmer sc->flags |= UMS_ABS;
214 1.77 mbalmer break;
215 1.77 mbalmer case HIO_RELATIVE:
216 1.77 mbalmer break;
217 1.77 mbalmer default:
218 1.69 jmcneill aprint_error("\n%s: X report 0x%04x not supported\n",
219 1.81 dyoung device_xname(sc->sc_hdev.sc_dev), flags);
220 1.81 dyoung return;
221 1.1 augustss }
222 1.10 augustss
223 1.2 augustss if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
224 1.53 augustss uha->reportid, hid_input, &sc->sc_loc_y, &flags)) {
225 1.69 jmcneill aprint_error("\n%s: mouse has no Y report\n",
226 1.81 dyoung device_xname(sc->sc_hdev.sc_dev));
227 1.81 dyoung return;
228 1.16 augustss }
229 1.77 mbalmer switch (flags & MOUSE_FLAGS_MASK) {
230 1.77 mbalmer case 0:
231 1.77 mbalmer sc->flags |= UMS_ABS;
232 1.77 mbalmer break;
233 1.77 mbalmer case HIO_RELATIVE:
234 1.77 mbalmer break;
235 1.77 mbalmer default:
236 1.69 jmcneill aprint_error("\n%s: Y report 0x%04x not supported\n",
237 1.81 dyoung device_xname(sc->sc_hdev.sc_dev), flags);
238 1.81 dyoung return;
239 1.1 augustss }
240 1.10 augustss
241 1.63 augustss /* Try the wheel first as the Z activator since it's tradition. */
242 1.85 christos hl = hid_locate(desc,
243 1.85 christos size,
244 1.85 christos HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
245 1.85 christos uha->reportid,
246 1.85 christos hid_input,
247 1.85 christos &sc->sc_loc_z,
248 1.75 rafal &flags);
249 1.75 rafal
250 1.75 rafal zloc = &sc->sc_loc_z;
251 1.75 rafal if (hl) {
252 1.77 mbalmer if ((flags & MOUSE_FLAGS_MASK) != HIO_RELATIVE) {
253 1.69 jmcneill aprint_verbose("\n%s: Wheel report 0x%04x not "
254 1.81 dyoung "supported\n", device_xname(sc->sc_hdev.sc_dev),
255 1.69 jmcneill flags);
256 1.16 augustss sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */
257 1.16 augustss } else {
258 1.16 augustss sc->flags |= UMS_Z;
259 1.37 augustss /* Wheels need the Z axis reversed. */
260 1.63 augustss sc->flags ^= UMS_REVZ;
261 1.75 rafal /* Put Z on the W coordinate */
262 1.75 rafal zloc = &sc->sc_loc_w;
263 1.63 augustss }
264 1.75 rafal }
265 1.75 rafal
266 1.85 christos hl = hid_locate(desc,
267 1.85 christos size,
268 1.75 rafal HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
269 1.75 rafal uha->reportid,
270 1.75 rafal hid_input,
271 1.75 rafal zloc,
272 1.75 rafal &flags);
273 1.75 rafal
274 1.75 rafal /*
275 1.75 rafal * The horizontal component of the scrollball can also be given by
276 1.75 rafal * Application Control Pan in the Consumer page, so if we didnt see
277 1.75 rafal * any Z then check that.
278 1.75 rafal */
279 1.75 rafal if (!hl) {
280 1.85 christos hl = hid_locate(desc,
281 1.85 christos size,
282 1.85 christos HID_USAGE2(HUP_CONSUMER, HUC_AC_PAN),
283 1.75 rafal uha->reportid,
284 1.75 rafal hid_input,
285 1.75 rafal zloc,
286 1.75 rafal &flags);
287 1.75 rafal }
288 1.75 rafal
289 1.75 rafal if (hl) {
290 1.77 mbalmer if ((flags & MOUSE_FLAGS_MASK) != HIO_RELATIVE) {
291 1.69 jmcneill aprint_verbose("\n%s: Z report 0x%04x not supported\n",
292 1.81 dyoung device_xname(sc->sc_hdev.sc_dev), flags);
293 1.75 rafal zloc->size = 0; /* Bad Z coord, ignore it */
294 1.63 augustss } else {
295 1.75 rafal if (sc->flags & UMS_Z)
296 1.75 rafal sc->flags |= UMS_W;
297 1.75 rafal else
298 1.75 rafal sc->flags |= UMS_Z;
299 1.16 augustss }
300 1.6 augustss }
301 1.6 augustss
302 1.89 skrll if (uha->uiaa->uiaa_vendor == USB_VENDOR_MICROSOFT) {
303 1.88 christos int fixpos;
304 1.88 christos /*
305 1.88 christos * The Microsoft Wireless Laser Mouse 6000 v2.0 and the
306 1.88 christos * Microsoft Comfort Mouse 2.0 report a bad position for
307 1.88 christos * the wheel and wheel tilt controls -- should be in bytes
308 1.88 christos * 3 & 4 of the report. Fix this if necessary.
309 1.88 christos */
310 1.89 skrll switch (uha->uiaa->uiaa_product) {
311 1.88 christos case USB_PRODUCT_MICROSOFT_24GHZ_XCVR10:
312 1.88 christos case USB_PRODUCT_MICROSOFT_24GHZ_XCVR20:
313 1.88 christos fixpos = 24;
314 1.88 christos break;
315 1.88 christos case USB_PRODUCT_MICROSOFT_CM6000:
316 1.88 christos fixpos = 40;
317 1.88 christos break;
318 1.88 christos default:
319 1.88 christos fixpos = 0;
320 1.88 christos break;
321 1.88 christos }
322 1.88 christos if (fixpos) {
323 1.88 christos if ((sc->flags & UMS_Z) && sc->sc_loc_z.pos == 0)
324 1.88 christos sc->sc_loc_z.pos = fixpos;
325 1.88 christos if ((sc->flags & UMS_W) && sc->sc_loc_w.pos == 0)
326 1.88 christos sc->sc_loc_w.pos = sc->sc_loc_z.pos + 8;
327 1.88 christos }
328 1.75 rafal }
329 1.63 augustss
330 1.21 augustss /* figure out the number of buttons */
331 1.21 augustss for (i = 1; i <= MAX_BUTTONS; i++)
332 1.16 augustss if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
333 1.84 christos uha->reportid, hid_input, &sc->sc_loc_btn[i - 1], 0))
334 1.16 augustss break;
335 1.84 christos
336 1.84 christos if (isdigitizer) {
337 1.84 christos for (size_t j = 0; j < __arraycount(digbut); j++) {
338 1.85 christos if (hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS,
339 1.84 christos digbut[j].feature), uha->reportid, hid_input,
340 1.84 christos &sc->sc_loc_btn[i - 1], 0)) {
341 1.84 christos if (i <= MAX_BUTTONS) {
342 1.84 christos i++;
343 1.84 christos sc->flags |= digbut[j].flag;
344 1.84 christos } else
345 1.84 christos aprint_error_dev(self,
346 1.84 christos "ran out of buttons\n");
347 1.84 christos }
348 1.84 christos }
349 1.84 christos }
350 1.16 augustss sc->nbuttons = i - 1;
351 1.16 augustss
352 1.84 christos aprint_normal(": %d button%s%s%s%s%s%s%s%s%s\n",
353 1.45 augustss sc->nbuttons, sc->nbuttons == 1 ? "" : "s",
354 1.75 rafal sc->flags & UMS_W ? ", W" : "",
355 1.75 rafal sc->flags & UMS_Z ? " and Z dir" : "",
356 1.84 christos sc->flags & UMS_W ? "s" : "",
357 1.84 christos isdigitizer ? " digitizer" : "",
358 1.84 christos sc->flags & UMS_TIP_SWITCH ? ", tip" : "",
359 1.84 christos sc->flags & UMS_SEC_TIP_SWITCH ? ", sec tip" : "",
360 1.84 christos sc->flags & UMS_BARREL_SWITCH ? ", barrel" : "",
361 1.84 christos sc->flags & UMS_ERASER ? ", eraser" : "");
362 1.3 augustss
363 1.86 christos #ifdef UMS_DEBUG
364 1.16 augustss DPRINTF(("ums_attach: sc=%p\n", sc));
365 1.57 augustss DPRINTF(("ums_attach: X\t%d/%d\n",
366 1.16 augustss sc->sc_loc_x.pos, sc->sc_loc_x.size));
367 1.57 augustss DPRINTF(("ums_attach: Y\t%d/%d\n",
368 1.48 augustss sc->sc_loc_y.pos, sc->sc_loc_y.size));
369 1.16 augustss if (sc->flags & UMS_Z)
370 1.57 augustss DPRINTF(("ums_attach: Z\t%d/%d\n",
371 1.16 augustss sc->sc_loc_z.pos, sc->sc_loc_z.size));
372 1.75 rafal if (sc->flags & UMS_W)
373 1.75 rafal DPRINTF(("ums_attach: W\t%d/%d\n",
374 1.75 rafal sc->sc_loc_w.pos, sc->sc_loc_w.size));
375 1.16 augustss for (i = 1; i <= sc->nbuttons; i++) {
376 1.16 augustss DPRINTF(("ums_attach: B%d\t%d/%d\n",
377 1.16 augustss i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
378 1.16 augustss }
379 1.16 augustss #endif
380 1.16 augustss
381 1.3 augustss a.accessops = &ums_accessops;
382 1.3 augustss a.accesscookie = sc;
383 1.3 augustss
384 1.47 augustss sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
385 1.40 augustss
386 1.81 dyoung return;
387 1.16 augustss }
388 1.16 augustss
389 1.25 augustss int
390 1.81 dyoung ums_activate(device_t self, enum devact act)
391 1.16 augustss {
392 1.73 cube struct ums_softc *sc = device_private(self);
393 1.28 augustss
394 1.28 augustss switch (act) {
395 1.28 augustss case DVACT_DEACTIVATE:
396 1.28 augustss sc->sc_dying = 1;
397 1.76 dyoung return 0;
398 1.76 dyoung default:
399 1.76 dyoung return EOPNOTSUPP;
400 1.28 augustss }
401 1.1 augustss }
402 1.1 augustss
403 1.71 dyoung void
404 1.71 dyoung ums_childdet(device_t self, device_t child)
405 1.71 dyoung {
406 1.71 dyoung struct ums_softc *sc = device_private(self);
407 1.71 dyoung
408 1.71 dyoung KASSERT(sc->sc_wsmousedev == child);
409 1.71 dyoung sc->sc_wsmousedev = NULL;
410 1.71 dyoung }
411 1.71 dyoung
412 1.53 augustss int
413 1.71 dyoung ums_detach(device_t self, int flags)
414 1.1 augustss {
415 1.71 dyoung struct ums_softc *sc = device_private(self);
416 1.25 augustss int rv = 0;
417 1.8 augustss
418 1.25 augustss DPRINTF(("ums_detach: sc=%p flags=%d\n", sc, flags));
419 1.33 augustss
420 1.51 augustss /* No need to do reference counting of ums, wsmouse has all the goo. */
421 1.51 augustss if (sc->sc_wsmousedev != NULL)
422 1.51 augustss rv = config_detach(sc->sc_wsmousedev, flags);
423 1.40 augustss
424 1.70 jmcneill pmf_device_deregister(self);
425 1.70 jmcneill
426 1.89 skrll return rv;
427 1.1 augustss }
428 1.1 augustss
429 1.1 augustss void
430 1.67 christos ums_intr(struct uhidev *addr, void *ibuf, u_int len)
431 1.1 augustss {
432 1.53 augustss struct ums_softc *sc = (struct ums_softc *)addr;
433 1.63 augustss int dx, dy, dz, dw;
434 1.89 skrll uint32_t buttons = 0;
435 1.77 mbalmer int i, flags, s;
436 1.54 augustss
437 1.54 augustss DPRINTFN(5,("ums_intr: len=%d\n", len));
438 1.21 augustss
439 1.77 mbalmer flags = WSMOUSE_INPUT_DELTA; /* equals 0 */
440 1.77 mbalmer
441 1.1 augustss dx = hid_get_data(ibuf, &sc->sc_loc_x);
442 1.77 mbalmer if (sc->flags & UMS_ABS) {
443 1.77 mbalmer flags |= (WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
444 1.77 mbalmer dy = hid_get_data(ibuf, &sc->sc_loc_y);
445 1.77 mbalmer } else
446 1.77 mbalmer dy = -hid_get_data(ibuf, &sc->sc_loc_y);
447 1.6 augustss dz = hid_get_data(ibuf, &sc->sc_loc_z);
448 1.63 augustss dw = hid_get_data(ibuf, &sc->sc_loc_w);
449 1.77 mbalmer
450 1.35 augustss if (sc->flags & UMS_REVZ)
451 1.24 augustss dz = -dz;
452 1.16 augustss for (i = 0; i < sc->nbuttons; i++)
453 1.16 augustss if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
454 1.16 augustss buttons |= (1 << UMS_BUT(i));
455 1.4 augustss
456 1.63 augustss if (dx != 0 || dy != 0 || dz != 0 || dw != 0 ||
457 1.63 augustss buttons != sc->sc_buttons) {
458 1.63 augustss DPRINTFN(10, ("ums_intr: x:%d y:%d z:%d w:%d buttons:0x%x\n",
459 1.63 augustss dx, dy, dz, dw, buttons));
460 1.4 augustss sc->sc_buttons = buttons;
461 1.35 augustss if (sc->sc_wsmousedev != NULL) {
462 1.23 augustss s = spltty();
463 1.77 mbalmer wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, dz,
464 1.77 mbalmer dw, flags);
465 1.23 augustss splx(s);
466 1.23 augustss }
467 1.1 augustss }
468 1.1 augustss }
469 1.3 augustss
470 1.42 augustss Static int
471 1.44 augustss ums_enable(void *v)
472 1.3 augustss {
473 1.3 augustss struct ums_softc *sc = v;
474 1.87 mlelstv int error;
475 1.16 augustss
476 1.25 augustss DPRINTFN(1,("ums_enable: sc=%p\n", sc));
477 1.28 augustss
478 1.28 augustss if (sc->sc_dying)
479 1.89 skrll return EIO;
480 1.28 augustss
481 1.3 augustss if (sc->sc_enabled)
482 1.89 skrll return EBUSY;
483 1.3 augustss
484 1.3 augustss sc->sc_enabled = 1;
485 1.4 augustss sc->sc_buttons = 0;
486 1.3 augustss
487 1.87 mlelstv error = uhidev_open(&sc->sc_hdev);
488 1.87 mlelstv if (error)
489 1.87 mlelstv sc->sc_enabled = 0;
490 1.87 mlelstv
491 1.87 mlelstv return error;
492 1.3 augustss }
493 1.3 augustss
494 1.42 augustss Static void
495 1.44 augustss ums_disable(void *v)
496 1.3 augustss {
497 1.3 augustss struct ums_softc *sc = v;
498 1.25 augustss
499 1.25 augustss DPRINTFN(1,("ums_disable: sc=%p\n", sc));
500 1.25 augustss #ifdef DIAGNOSTIC
501 1.25 augustss if (!sc->sc_enabled) {
502 1.25 augustss printf("ums_disable: not enabled\n");
503 1.25 augustss return;
504 1.25 augustss }
505 1.25 augustss #endif
506 1.3 augustss
507 1.87 mlelstv if (sc->sc_enabled) {
508 1.87 mlelstv sc->sc_enabled = 0;
509 1.87 mlelstv uhidev_close(&sc->sc_hdev);
510 1.87 mlelstv }
511 1.3 augustss }
512 1.3 augustss
513 1.42 augustss Static int
514 1.68 christos ums_ioctl(void *v, u_long cmd, void *data, int flag,
515 1.67 christos struct lwp * p)
516 1.16 augustss
517 1.3 augustss {
518 1.77 mbalmer struct ums_softc *sc = v;
519 1.77 mbalmer
520 1.3 augustss switch (cmd) {
521 1.3 augustss case WSMOUSEIO_GTYPE:
522 1.77 mbalmer if (sc->flags & UMS_ABS)
523 1.77 mbalmer *(u_int *)data = WSMOUSE_TYPE_TPANEL;
524 1.77 mbalmer else
525 1.77 mbalmer *(u_int *)data = WSMOUSE_TYPE_USB;
526 1.89 skrll return 0;
527 1.3 augustss }
528 1.16 augustss
529 1.89 skrll return EPASSTHROUGH;
530 1.3 augustss }
531