uvisor.c revision 1.47 1 1.47 msaitoh /* $NetBSD: uvisor.c,v 1.47 2016/07/07 06:55:42 msaitoh Exp $ */
2 1.1 augustss
3 1.1 augustss /*
4 1.1 augustss * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 augustss * All rights reserved.
6 1.1 augustss *
7 1.1 augustss * This code is derived from software contributed to The NetBSD Foundation
8 1.6 augustss * by Lennart Augustsson (lennart (at) augustsson.net) at
9 1.1 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.1 augustss */
32 1.1 augustss
33 1.1 augustss /*
34 1.2 hubertf * Handspring Visor (Palmpilot compatible PDA) driver
35 1.1 augustss */
36 1.12 lukem
37 1.12 lukem #include <sys/cdefs.h>
38 1.47 msaitoh __KERNEL_RCSID(0, "$NetBSD: uvisor.c,v 1.47 2016/07/07 06:55:42 msaitoh 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/conf.h>
45 1.1 augustss #include <sys/tty.h>
46 1.1 augustss
47 1.1 augustss #include <dev/usb/usb.h>
48 1.1 augustss
49 1.1 augustss #include <dev/usb/usbdi.h>
50 1.1 augustss #include <dev/usb/usbdi_util.h>
51 1.1 augustss #include <dev/usb/usbdevs.h>
52 1.1 augustss
53 1.1 augustss #include <dev/usb/ucomvar.h>
54 1.1 augustss
55 1.1 augustss #ifdef UVISOR_DEBUG
56 1.1 augustss #define DPRINTF(x) if (uvisordebug) printf x
57 1.1 augustss #define DPRINTFN(n,x) if (uvisordebug>(n)) printf x
58 1.3 augustss int uvisordebug = 0;
59 1.1 augustss #else
60 1.1 augustss #define DPRINTF(x)
61 1.1 augustss #define DPRINTFN(n,x)
62 1.1 augustss #endif
63 1.1 augustss
64 1.1 augustss #define UVISOR_CONFIG_INDEX 0
65 1.1 augustss #define UVISOR_IFACE_INDEX 0
66 1.1 augustss
67 1.1 augustss /* From the Linux driver */
68 1.1 augustss /*
69 1.1 augustss * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that
70 1.1 augustss * are available to be transfered to the host for the specified endpoint.
71 1.1 augustss * Currently this is not used, and always returns 0x0001
72 1.1 augustss */
73 1.1 augustss #define UVISOR_REQUEST_BYTES_AVAILABLE 0x01
74 1.1 augustss
75 1.1 augustss /*
76 1.1 augustss * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host
77 1.1 augustss * is now closing the pipe. An empty packet is sent in response.
78 1.1 augustss */
79 1.1 augustss #define UVISOR_CLOSE_NOTIFICATION 0x02
80 1.1 augustss
81 1.1 augustss /*
82 1.1 augustss * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to
83 1.1 augustss * get the endpoints used by the connection.
84 1.1 augustss */
85 1.1 augustss #define UVISOR_GET_CONNECTION_INFORMATION 0x03
86 1.1 augustss
87 1.1 augustss
88 1.1 augustss /*
89 1.1 augustss * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format
90 1.1 augustss */
91 1.10 augustss #define UVISOR_MAX_CONN 8
92 1.1 augustss struct uvisor_connection_info {
93 1.1 augustss uWord num_ports;
94 1.1 augustss struct {
95 1.1 augustss uByte port_function_id;
96 1.1 augustss uByte port;
97 1.10 augustss } connections[UVISOR_MAX_CONN];
98 1.1 augustss };
99 1.1 augustss #define UVISOR_CONNECTION_INFO_SIZE 18
100 1.1 augustss
101 1.1 augustss /* struct uvisor_connection_info.connection[x].port_function_id defines: */
102 1.1 augustss #define UVISOR_FUNCTION_GENERIC 0x00
103 1.1 augustss #define UVISOR_FUNCTION_DEBUGGER 0x01
104 1.1 augustss #define UVISOR_FUNCTION_HOTSYNC 0x02
105 1.1 augustss #define UVISOR_FUNCTION_CONSOLE 0x03
106 1.1 augustss #define UVISOR_FUNCTION_REMOTE_FILE_SYS 0x04
107 1.1 augustss
108 1.14 augustss /*
109 1.14 augustss * Unknown PalmOS stuff.
110 1.14 augustss */
111 1.14 augustss #define UVISOR_GET_PALM_INFORMATION 0x04
112 1.21 nathanw #define UVISOR_GET_PALM_INFORMATION_LEN 0x44
113 1.14 augustss
114 1.21 nathanw struct uvisor_palm_connection_info {
115 1.21 nathanw uByte num_ports;
116 1.21 nathanw uByte endpoint_numbers_different;
117 1.21 nathanw uWord reserved1;
118 1.21 nathanw struct {
119 1.21 nathanw uDWord port_function_id;
120 1.21 nathanw uByte port;
121 1.21 nathanw uByte end_point_info;
122 1.21 nathanw uWord reserved;
123 1.21 nathanw } connections[UVISOR_MAX_CONN];
124 1.21 nathanw };
125 1.1 augustss
126 1.21 nathanw
127 1.21 nathanw
128 1.21 nathanw #define UVISORIBUFSIZE 64
129 1.4 augustss #define UVISOROBUFSIZE 1024
130 1.4 augustss
131 1.1 augustss struct uvisor_softc {
132 1.43 dyoung device_t sc_dev; /* base device */
133 1.46 skrll struct usbd_device * sc_udev; /* device */
134 1.46 skrll struct usbd_interface * sc_iface; /* interface */
135 1.1 augustss
136 1.43 dyoung device_t sc_subdevs[UVISOR_MAX_CONN];
137 1.10 augustss int sc_numcon;
138 1.1 augustss
139 1.46 skrll uint16_t sc_flags;
140 1.14 augustss
141 1.1 augustss u_char sc_dying;
142 1.1 augustss };
143 1.1 augustss
144 1.16 augustss Static usbd_status uvisor_init(struct uvisor_softc *,
145 1.21 nathanw struct uvisor_connection_info *,
146 1.21 nathanw struct uvisor_palm_connection_info *);
147 1.1 augustss
148 1.7 augustss Static void uvisor_close(void *, int);
149 1.1 augustss
150 1.1 augustss
151 1.1 augustss struct ucom_methods uvisor_methods = {
152 1.46 skrll .ucom_param = NULL,
153 1.46 skrll .ucom_ioctl = NULL,
154 1.46 skrll .ucom_open = NULL,
155 1.46 skrll .ucom_close = uvisor_close,
156 1.46 skrll .ucom_read = NULL,
157 1.46 skrll .ucom_write = NULL,
158 1.46 skrll .ucom_get_status = NULL,
159 1.46 skrll .ucom_set = NULL,
160 1.1 augustss };
161 1.1 augustss
162 1.14 augustss struct uvisor_type {
163 1.14 augustss struct usb_devno uv_dev;
164 1.46 skrll uint16_t uv_flags;
165 1.14 augustss #define PALM4 0x0001
166 1.21 nathanw #define VISOR 0x0002
167 1.21 nathanw
168 1.14 augustss };
169 1.14 augustss static const struct uvisor_type uvisor_devs[] = {
170 1.21 nathanw {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR }, VISOR },
171 1.19 augustss {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO }, PALM4 },
172 1.23 carrel {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO600 }, PALM4 },
173 1.14 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M500 }, PALM4 },
174 1.14 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M505 }, PALM4 },
175 1.17 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M515 }, PALM4 },
176 1.19 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_I705 }, PALM4 },
177 1.14 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M125 }, PALM4 },
178 1.19 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M130 }, PALM4 },
179 1.19 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_Z }, PALM4 },
180 1.20 simonb {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_T }, PALM4 },
181 1.26 mycroft {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE31 }, PALM4 },
182 1.18 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE }, PALM4 },
183 1.14 augustss {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40 }, PALM4 },
184 1.21 nathanw {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41 }, PALM4 },
185 1.19 augustss {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_S360 }, PALM4 },
186 1.19 augustss {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_NX60 }, PALM4 },
187 1.24 augustss {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_35 }, 0 },
188 1.14 augustss /* {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25 }, PALM4 },*/
189 1.14 augustss };
190 1.30 christos #define uvisor_lookup(v, p) ((const struct uvisor_type *)usb_lookup(uvisor_devs, v, p))
191 1.14 augustss
192 1.40 cube int uvisor_match(device_t, cfdata_t, void *);
193 1.37 dyoung void uvisor_attach(device_t, device_t, void *);
194 1.37 dyoung void uvisor_childdet(device_t, device_t);
195 1.37 dyoung int uvisor_detach(device_t, int);
196 1.37 dyoung int uvisor_activate(device_t, enum devact);
197 1.37 dyoung extern struct cfdriver uvisor_cd;
198 1.40 cube CFATTACH_DECL2_NEW(uvisor, sizeof(struct uvisor_softc), uvisor_match,
199 1.37 dyoung uvisor_attach, uvisor_detach, uvisor_activate, NULL, uvisor_childdet);
200 1.1 augustss
201 1.46 skrll int
202 1.43 dyoung uvisor_match(device_t parent, cfdata_t match, void *aux)
203 1.1 augustss {
204 1.43 dyoung struct usb_attach_arg *uaa = aux;
205 1.16 augustss
206 1.1 augustss DPRINTFN(20,("uvisor: vendor=0x%x, product=0x%x\n",
207 1.46 skrll uaa->uaa_vendor, uaa->uaa_product));
208 1.1 augustss
209 1.46 skrll return uvisor_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ?
210 1.46 skrll UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
211 1.1 augustss }
212 1.1 augustss
213 1.46 skrll void
214 1.43 dyoung uvisor_attach(device_t parent, device_t self, void *aux)
215 1.1 augustss {
216 1.43 dyoung struct uvisor_softc *sc = device_private(self);
217 1.43 dyoung struct usb_attach_arg *uaa = aux;
218 1.46 skrll struct usbd_device *dev = uaa->uaa_device;
219 1.46 skrll struct usbd_interface *iface;
220 1.1 augustss usb_interface_descriptor_t *id;
221 1.10 augustss struct uvisor_connection_info coninfo;
222 1.21 nathanw struct uvisor_palm_connection_info palmconinfo;
223 1.1 augustss usb_endpoint_descriptor_t *ed;
224 1.29 augustss char *devinfop;
225 1.40 cube const char *devname = device_xname(self);
226 1.10 augustss int i, j, hasin, hasout, port;
227 1.1 augustss usbd_status err;
228 1.46 skrll struct ucom_attach_args ucaa;
229 1.1 augustss
230 1.1 augustss DPRINTFN(10,("\nuvisor_attach: sc=%p\n", sc));
231 1.1 augustss
232 1.40 cube sc->sc_dev = self;
233 1.40 cube
234 1.41 plunky aprint_naive("\n");
235 1.41 plunky aprint_normal("\n");
236 1.41 plunky
237 1.41 plunky devinfop = usbd_devinfo_alloc(dev, 0);
238 1.41 plunky aprint_normal_dev(self, "%s\n", devinfop);
239 1.41 plunky usbd_devinfo_free(devinfop);
240 1.41 plunky
241 1.1 augustss /* Move the device into the configured state. */
242 1.1 augustss err = usbd_set_config_index(dev, UVISOR_CONFIG_INDEX, 1);
243 1.1 augustss if (err) {
244 1.40 cube aprint_error("\n%s: failed to set configuration, err=%s\n",
245 1.1 augustss devname, usbd_errstr(err));
246 1.1 augustss goto bad;
247 1.1 augustss }
248 1.1 augustss
249 1.1 augustss err = usbd_device2interface_handle(dev, UVISOR_IFACE_INDEX, &iface);
250 1.1 augustss if (err) {
251 1.40 cube aprint_error("\n%s: failed to get interface, err=%s\n",
252 1.1 augustss devname, usbd_errstr(err));
253 1.1 augustss goto bad;
254 1.1 augustss }
255 1.1 augustss
256 1.46 skrll sc->sc_flags = uvisor_lookup(uaa->uaa_vendor, uaa->uaa_product)->uv_flags;
257 1.14 augustss
258 1.21 nathanw if ((sc->sc_flags & (VISOR | PALM4)) == 0) {
259 1.40 cube aprint_error_dev(self,
260 1.40 cube "init failed, device type is neither visor nor palm\n");
261 1.21 nathanw goto bad;
262 1.21 nathanw }
263 1.21 nathanw
264 1.1 augustss id = usbd_get_interface_descriptor(iface);
265 1.3 augustss
266 1.3 augustss sc->sc_udev = dev;
267 1.1 augustss sc->sc_iface = iface;
268 1.1 augustss
269 1.46 skrll ucaa.ucaa_ibufsize = UVISORIBUFSIZE;
270 1.46 skrll ucaa.ucaa_obufsize = UVISOROBUFSIZE;
271 1.46 skrll ucaa.ucaa_ibufsizepad = UVISORIBUFSIZE;
272 1.46 skrll ucaa.ucaa_opkthdrlen = 0;
273 1.46 skrll ucaa.ucaa_device = dev;
274 1.46 skrll ucaa.ucaa_iface = iface;
275 1.46 skrll ucaa.ucaa_methods = &uvisor_methods;
276 1.46 skrll ucaa.ucaa_arg = sc;
277 1.4 augustss
278 1.21 nathanw err = uvisor_init(sc, &coninfo, &palmconinfo);
279 1.1 augustss if (err) {
280 1.40 cube aprint_error_dev(self, "init failed, %s\n", usbd_errstr(err));
281 1.1 augustss goto bad;
282 1.1 augustss }
283 1.1 augustss
284 1.47 msaitoh usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
285 1.9 augustss
286 1.21 nathanw if (sc->sc_flags & VISOR) {
287 1.21 nathanw sc->sc_numcon = UGETW(coninfo.num_ports);
288 1.21 nathanw if (sc->sc_numcon > UVISOR_MAX_CONN)
289 1.21 nathanw sc->sc_numcon = UVISOR_MAX_CONN;
290 1.21 nathanw
291 1.21 nathanw /* Attach a ucom for each connection. */
292 1.21 nathanw for (i = 0; i < sc->sc_numcon; ++i) {
293 1.21 nathanw switch (coninfo.connections[i].port_function_id) {
294 1.21 nathanw case UVISOR_FUNCTION_GENERIC:
295 1.46 skrll ucaa.ucaa_info = "Generic";
296 1.21 nathanw break;
297 1.21 nathanw case UVISOR_FUNCTION_DEBUGGER:
298 1.46 skrll ucaa.ucaa_info = "Debugger";
299 1.21 nathanw break;
300 1.21 nathanw case UVISOR_FUNCTION_HOTSYNC:
301 1.46 skrll ucaa.ucaa_info = "HotSync";
302 1.21 nathanw break;
303 1.21 nathanw case UVISOR_FUNCTION_REMOTE_FILE_SYS:
304 1.46 skrll ucaa.ucaa_info = "Remote File System";
305 1.21 nathanw break;
306 1.21 nathanw default:
307 1.46 skrll ucaa.ucaa_info = "unknown";
308 1.10 augustss break;
309 1.10 augustss }
310 1.21 nathanw port = coninfo.connections[i].port;
311 1.46 skrll ucaa.ucaa_portno = port;
312 1.46 skrll ucaa.ucaa_bulkin = port | UE_DIR_IN;
313 1.46 skrll ucaa.ucaa_bulkout = port | UE_DIR_OUT;
314 1.21 nathanw /* Verify that endpoints exist. */
315 1.21 nathanw hasin = 0;
316 1.21 nathanw hasout = 0;
317 1.21 nathanw for (j = 0; j < id->bNumEndpoints; j++) {
318 1.21 nathanw ed = usbd_interface2endpoint_descriptor(iface, j);
319 1.21 nathanw if (ed == NULL)
320 1.21 nathanw break;
321 1.21 nathanw if (UE_GET_ADDR(ed->bEndpointAddress) == port &&
322 1.21 nathanw (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
323 1.21 nathanw if (UE_GET_DIR(ed->bEndpointAddress)
324 1.21 nathanw == UE_DIR_IN)
325 1.21 nathanw hasin++;
326 1.21 nathanw else
327 1.21 nathanw hasout++;
328 1.21 nathanw }
329 1.21 nathanw }
330 1.21 nathanw if (hasin == 1 && hasout == 1)
331 1.27 drochner sc->sc_subdevs[i] = config_found_sm_loc(self,
332 1.46 skrll "ucombus", NULL, &ucaa,
333 1.27 drochner ucomprint, ucomsubmatch);
334 1.21 nathanw else
335 1.40 cube aprint_error_dev(self,
336 1.40 cube "no proper endpoints for port %d (%d,%d)\n",
337 1.40 cube port, hasin, hasout);
338 1.10 augustss }
339 1.21 nathanw
340 1.21 nathanw } else {
341 1.21 nathanw sc->sc_numcon = palmconinfo.num_ports;
342 1.21 nathanw if (sc->sc_numcon > UVISOR_MAX_CONN)
343 1.21 nathanw sc->sc_numcon = UVISOR_MAX_CONN;
344 1.21 nathanw
345 1.21 nathanw /* Attach a ucom for each connection. */
346 1.21 nathanw for (i = 0; i < sc->sc_numcon; ++i) {
347 1.28 perry /*
348 1.28 perry * XXX this should copy out 4-char string from the
349 1.21 nathanw * XXX port_function_id, but where would the string go?
350 1.46 skrll * XXX ucaa.ucaa_info is a const char *, not an array.
351 1.21 nathanw */
352 1.46 skrll ucaa.ucaa_info = "sync";
353 1.46 skrll ucaa.ucaa_portno = i;
354 1.21 nathanw if (palmconinfo.endpoint_numbers_different) {
355 1.21 nathanw port = palmconinfo.connections[i].end_point_info;
356 1.46 skrll ucaa.ucaa_bulkin = (port >> 4) | UE_DIR_IN;
357 1.46 skrll ucaa.ucaa_bulkout = (port & 0xf) | UE_DIR_OUT;
358 1.21 nathanw } else {
359 1.21 nathanw port = palmconinfo.connections[i].port;
360 1.46 skrll ucaa.ucaa_bulkin = port | UE_DIR_IN;
361 1.46 skrll ucaa.ucaa_bulkout = port | UE_DIR_OUT;
362 1.21 nathanw }
363 1.27 drochner sc->sc_subdevs[i] = config_found_sm_loc(self, "ucombus",
364 1.46 skrll NULL, &ucaa, ucomprint, ucomsubmatch);
365 1.21 nathanw
366 1.28 perry
367 1.21 nathanw }
368 1.10 augustss }
369 1.16 augustss
370 1.43 dyoung return;
371 1.1 augustss
372 1.1 augustss bad:
373 1.1 augustss DPRINTF(("uvisor_attach: ATTACH ERROR\n"));
374 1.1 augustss sc->sc_dying = 1;
375 1.43 dyoung return;
376 1.1 augustss }
377 1.1 augustss
378 1.1 augustss int
379 1.43 dyoung uvisor_activate(device_t self, enum devact act)
380 1.1 augustss {
381 1.40 cube struct uvisor_softc *sc = device_private(self);
382 1.1 augustss
383 1.1 augustss switch (act) {
384 1.1 augustss case DVACT_DEACTIVATE:
385 1.1 augustss sc->sc_dying = 1;
386 1.42 dyoung return 0;
387 1.42 dyoung default:
388 1.42 dyoung return EOPNOTSUPP;
389 1.1 augustss }
390 1.1 augustss }
391 1.1 augustss
392 1.37 dyoung void
393 1.37 dyoung uvisor_childdet(device_t self, device_t child)
394 1.37 dyoung {
395 1.37 dyoung int i;
396 1.37 dyoung struct uvisor_softc *sc = device_private(self);
397 1.37 dyoung
398 1.37 dyoung for (i = 0; i < sc->sc_numcon; i++) {
399 1.37 dyoung if (sc->sc_subdevs[i] == child)
400 1.37 dyoung break;
401 1.37 dyoung }
402 1.37 dyoung KASSERT(i < sc->sc_numcon);
403 1.37 dyoung sc->sc_subdevs[i] = NULL;
404 1.37 dyoung }
405 1.37 dyoung
406 1.1 augustss int
407 1.37 dyoung uvisor_detach(device_t self, int flags)
408 1.1 augustss {
409 1.37 dyoung struct uvisor_softc *sc = device_private(self);
410 1.1 augustss int rv = 0;
411 1.10 augustss int i;
412 1.1 augustss
413 1.1 augustss DPRINTF(("uvisor_detach: sc=%p flags=%d\n", sc, flags));
414 1.1 augustss sc->sc_dying = 1;
415 1.10 augustss for (i = 0; i < sc->sc_numcon; i++) {
416 1.37 dyoung if (sc->sc_subdevs[i] != NULL)
417 1.10 augustss rv |= config_detach(sc->sc_subdevs[i], flags);
418 1.1 augustss }
419 1.9 augustss
420 1.34 drochner if (sc->sc_udev)
421 1.34 drochner usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
422 1.43 dyoung sc->sc_dev);
423 1.9 augustss
424 1.9 augustss
425 1.46 skrll return rv;
426 1.1 augustss }
427 1.1 augustss
428 1.1 augustss usbd_status
429 1.21 nathanw uvisor_init(struct uvisor_softc *sc, struct uvisor_connection_info *ci,
430 1.21 nathanw struct uvisor_palm_connection_info *cpi)
431 1.1 augustss {
432 1.1 augustss usbd_status err;
433 1.1 augustss usb_device_request_t req;
434 1.1 augustss int actlen;
435 1.1 augustss uWord avail;
436 1.14 augustss
437 1.21 nathanw if (sc->sc_flags & VISOR) {
438 1.21 nathanw DPRINTF(("uvisor_init: getting Visor connection info\n"));
439 1.14 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
440 1.21 nathanw req.bRequest = UVISOR_GET_CONNECTION_INFORMATION;
441 1.14 augustss USETW(req.wValue, 0);
442 1.14 augustss USETW(req.wIndex, 0);
443 1.21 nathanw USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
444 1.21 nathanw err = usbd_do_request_flags(sc->sc_udev, &req, ci,
445 1.21 nathanw USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
446 1.14 augustss if (err)
447 1.46 skrll return err;
448 1.21 nathanw }
449 1.21 nathanw
450 1.21 nathanw if (sc->sc_flags & PALM4) {
451 1.21 nathanw DPRINTF(("uvisor_init: getting Palm connection info\n"));
452 1.14 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
453 1.14 augustss req.bRequest = UVISOR_GET_PALM_INFORMATION;
454 1.14 augustss USETW(req.wValue, 0);
455 1.14 augustss USETW(req.wIndex, 0);
456 1.14 augustss USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
457 1.21 nathanw err = usbd_do_request_flags(sc->sc_udev, &req, cpi,
458 1.21 nathanw USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
459 1.14 augustss if (err)
460 1.46 skrll return err;
461 1.14 augustss }
462 1.1 augustss
463 1.1 augustss DPRINTF(("uvisor_init: getting available bytes\n"));
464 1.1 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
465 1.1 augustss req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE;
466 1.1 augustss USETW(req.wValue, 0);
467 1.1 augustss USETW(req.wIndex, 5);
468 1.46 skrll USETW(req.wLength, sizeof(avail));
469 1.1 augustss err = usbd_do_request(sc->sc_udev, &req, &avail);
470 1.1 augustss if (err)
471 1.46 skrll return err;
472 1.1 augustss DPRINTF(("uvisor_init: avail=%d\n", UGETW(avail)));
473 1.1 augustss
474 1.1 augustss DPRINTF(("uvisor_init: done\n"));
475 1.46 skrll return err;
476 1.1 augustss }
477 1.1 augustss
478 1.1 augustss void
479 1.33 christos uvisor_close(void *addr, int portno)
480 1.1 augustss {
481 1.1 augustss struct uvisor_softc *sc = addr;
482 1.1 augustss usb_device_request_t req;
483 1.1 augustss struct uvisor_connection_info coninfo; /* XXX ? */
484 1.1 augustss int actlen;
485 1.3 augustss
486 1.3 augustss if (sc->sc_dying)
487 1.3 augustss return;
488 1.1 augustss
489 1.1 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
490 1.1 augustss req.bRequest = UVISOR_CLOSE_NOTIFICATION;
491 1.1 augustss USETW(req.wValue, 0);
492 1.1 augustss USETW(req.wIndex, 0);
493 1.1 augustss USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
494 1.16 augustss (void)usbd_do_request_flags(sc->sc_udev, &req, &coninfo,
495 1.13 augustss USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
496 1.1 augustss }
497