]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/uvisor.c
This commit was generated by cvs2svn to compensate for changes in r169691,
[FreeBSD/FreeBSD.git] / sys / dev / usb / uvisor.c
1 /*      $NetBSD: uvisor.c,v 1.9 2001/01/23 14:04:14 augustss Exp $      */
2 /*      $FreeBSD$       */
3
4 /* Also already merged from NetBSD:
5  *      $NetBSD: uvisor.c,v 1.12 2001/11/13 06:24:57 lukem Exp $
6  *      $NetBSD: uvisor.c,v 1.13 2002/02/11 15:11:49 augustss Exp $
7  *      $NetBSD: uvisor.c,v 1.14 2002/02/27 23:00:03 augustss Exp $
8  *      $NetBSD: uvisor.c,v 1.15 2002/06/16 15:01:31 augustss Exp $
9  *      $NetBSD: uvisor.c,v 1.16 2002/07/11 21:14:36 augustss Exp $
10  *      $NetBSD: uvisor.c,v 1.17 2002/08/13 11:38:15 augustss Exp $
11  *      $NetBSD: uvisor.c,v 1.18 2003/02/05 00:50:14 augustss Exp $
12  *      $NetBSD: uvisor.c,v 1.19 2003/02/07 18:12:37 augustss Exp $
13  *      $NetBSD: uvisor.c,v 1.20 2003/04/11 01:30:10 simonb Exp $
14  */
15
16
17 /*-
18  * Copyright (c) 2000 The NetBSD Foundation, Inc.
19  * All rights reserved.
20  *
21  * This code is derived from software contributed to The NetBSD Foundation
22  * by Lennart Augustsson (lennart@augustsson.net) at
23  * Carlstedt Research & Technology.
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  *    notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  *    notice, this list of conditions and the following disclaimer in the
32  *    documentation and/or other materials provided with the distribution.
33  * 3. All advertising materials mentioning features or use of this software
34  *    must display the following acknowledgement:
35  *        This product includes software developed by the NetBSD
36  *        Foundation, Inc. and its contributors.
37  * 4. Neither the name of The NetBSD Foundation nor the names of its
38  *    contributors may be used to endorse or promote products derived
39  *    from this software without specific prior written permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
42  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
43  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
45  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51  * POSSIBILITY OF SUCH DAMAGE.
52  */
53
54 /*
55  * Handspring Visor (Palmpilot compatible PDA) driver
56  */
57
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/kernel.h>
61 #if defined(__NetBSD__) || defined(__OpenBSD__)
62 #include <sys/device.h>
63 #elif defined(__FreeBSD__)
64 #include <sys/module.h>
65 #include <sys/bus.h>
66 #endif
67 #include <sys/conf.h>
68 #include <sys/tty.h>
69 #include <sys/sysctl.h>
70
71 #include <dev/usb/usb.h>
72 #include <dev/usb/usbhid.h>
73
74 #include <dev/usb/usbdi.h>
75 #include <dev/usb/usbdi_util.h>
76 #include "usbdevs.h"
77
78 #include <dev/usb/ucomvar.h>
79
80 #ifdef USB_DEBUG
81 #define DPRINTF(x)      if (uvisordebug) printf x
82 #define DPRINTFN(n,x)   if (uvisordebug>(n)) printf x
83 int uvisordebug = 0;
84 SYSCTL_NODE(_hw_usb, OID_AUTO, uvisor, CTLFLAG_RW, 0, "USB uvisor");
85 SYSCTL_INT(_hw_usb_uvisor, OID_AUTO, debug, CTLFLAG_RW,
86            &uvisordebug, 0, "uvisor debug level");
87 #else
88 #define DPRINTF(x)
89 #define DPRINTFN(n,x)
90 #endif
91
92 #define UVISOR_CONFIG_INDEX     0
93 #define UVISOR_IFACE_INDEX      0
94 #define UVISOR_MODVER           1
95
96 /* From the Linux driver */
97 /*
98  * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that
99  * are available to be transfered to the host for the specified endpoint.
100  * Currently this is not used, and always returns 0x0001
101  */
102 #define UVISOR_REQUEST_BYTES_AVAILABLE          0x01
103
104 /*
105  * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host
106  * is now closing the pipe. An empty packet is sent in response.
107  */
108 #define UVISOR_CLOSE_NOTIFICATION               0x02
109
110 /*
111  * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to
112  * get the endpoints used by the connection.
113  */
114 #define UVISOR_GET_CONNECTION_INFORMATION       0x03
115
116
117 /*
118  * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format
119  */
120 #define UVISOR_MAX_CONN 8
121 struct uvisor_connection_info {
122         uWord   num_ports;
123         struct {
124                 uByte   port_function_id;
125                 uByte   port;
126         } connections[UVISOR_MAX_CONN];
127 };
128 #define UVISOR_CONNECTION_INFO_SIZE 18
129
130 /* struct uvisor_connection_info.connection[x].port defines: */
131 #define UVISOR_ENDPOINT_1               0x01
132 #define UVISOR_ENDPOINT_2               0x02
133
134 /* struct uvisor_connection_info.connection[x].port_function_id defines: */
135 #define UVISOR_FUNCTION_GENERIC         0x00
136 #define UVISOR_FUNCTION_DEBUGGER        0x01
137 #define UVISOR_FUNCTION_HOTSYNC         0x02
138 #define UVISOR_FUNCTION_CONSOLE         0x03
139 #define UVISOR_FUNCTION_REMOTE_FILE_SYS 0x04
140
141 /*
142  * Unknown PalmOS stuff.
143  */
144 #define UVISOR_GET_PALM_INFORMATION             0x04
145 #define UVISOR_GET_PALM_INFORMATION_LEN         0x44
146
147 struct uvisor_palm_connection_info {
148         uByte   num_ports;
149         uByte   endpoint_numbers_different;
150         uWord   reserved1;
151   struct {
152                 uDWord  port_function_id;
153                 uByte   port;
154                 uByte   end_point_info;
155                 uWord   reserved;
156   } connections[UVISOR_MAX_CONN];
157 };
158
159
160 /*
161  * Crank down UVISORBUFSIZE from 1024 to 64 to avoid a problem where
162  * the Palm device and the USB host controller deadlock. The USB host
163  * controller is expecting an early-end-of-transmission packet with 0
164  * data, and the Palm doesn't send one because it's already
165  * communicated the amount of data it's going to send in a header
166  * (which ucom/uvisor are oblivious to). This is the problem that has
167  * been known on the pilot-link lists as the "[Free]BSD USB problem",
168  * but not understood.
169  */
170 #define UVISORIBUFSIZE 64
171 #define UVISOROBUFSIZE 1024
172
173 struct uvisor_softc {
174         struct ucom_softc       sc_ucom;
175         u_int16_t               sc_flags;
176 };
177
178 static usbd_status uvisor_init(struct uvisor_softc *);
179
180 /*static usbd_status clie_3_5_init(struct uvisor_softc *);*/
181
182 static void uvisor_close(void *, int);
183
184 struct ucom_callback uvisor_callback = {
185         NULL,
186         NULL,
187         NULL,
188         NULL,
189         NULL,
190         uvisor_close,
191         NULL,
192         NULL,
193 };
194
195 static device_probe_t uvisor_match;
196 static device_attach_t uvisor_attach;
197 static device_detach_t uvisor_detach;
198 static device_method_t uvisor_methods[] = {
199        /* Device interface */
200        DEVMETHOD(device_probe, uvisor_match),
201        DEVMETHOD(device_attach, uvisor_attach),
202        DEVMETHOD(device_detach, uvisor_detach),
203        { 0, 0 }
204  };
205
206
207 static driver_t uvisor_driver = {
208        "ucom",
209        uvisor_methods,
210        sizeof (struct uvisor_softc)
211 };
212
213 DRIVER_MODULE(uvisor, uhub, uvisor_driver, ucom_devclass, usbd_driver_load, 0);
214 MODULE_DEPEND(uvisor, usb, 1, 1, 1);
215 MODULE_DEPEND(uvisor, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
216 MODULE_VERSION(uvisor, UVISOR_MODVER);
217
218 struct uvisor_type {
219         struct usb_devno        uv_dev;
220         u_int16_t               uv_flags;
221 #define PALM4   0x0001
222 #define VISOR   0x0002
223 #define PALM35  0x0004
224 };
225 static const struct uvisor_type uvisor_devs[] = {
226         {{ USB_VENDOR_ACEECA, USB_PRODUCT_ACEECA_MEZ1000 }, PALM4 },
227         {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR }, VISOR },
228         {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO }, PALM4 },
229         {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO600 }, PALM4 },
230         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M500 }, PALM4 },
231         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M505 }, PALM4 },
232         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M515 }, PALM4 },
233         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_I705 }, PALM4 },
234         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M125 }, PALM4 },
235         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M130 }, PALM4 },
236         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_Z }, PALM4 },
237         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_T }, PALM4 },
238         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE }, PALM4 },
239         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE31 }, PALM4 },
240         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40 }, 0 },
241         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41 }, PALM4 },
242         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_S360 }, PALM4 },
243         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_NX60 }, PALM4 },
244         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_35 }, PALM35 },
245 /*      {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25 }, PALM4 },*/
246         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TJ37 }, PALM4 },
247 };
248 #define uvisor_lookup(v, p) ((const struct uvisor_type *)usb_lookup(uvisor_devs, v, p))
249
250
251 USB_MATCH(uvisor)
252 {
253         USB_MATCH_START(uvisor, uaa);
254
255         if (uaa->iface != NULL)
256                 return (UMATCH_NONE);
257
258         DPRINTFN(20,("uvisor: vendor=0x%x, product=0x%x\n",
259                      uaa->vendor, uaa->product));
260
261         return (uvisor_lookup(uaa->vendor, uaa->product) != NULL ?
262                 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
263 }
264
265 USB_ATTACH(uvisor)
266 {
267         USB_ATTACH_START(uvisor, sc, uaa);
268         usbd_device_handle dev = uaa->device;
269         usbd_interface_handle iface;
270         usb_interface_descriptor_t *id;
271         usb_endpoint_descriptor_t *ed;
272         char *devinfo;
273         const char *devname;
274         int i;
275         usbd_status err;
276         struct ucom_softc *ucom;
277
278         devinfo = malloc(1024, M_USBDEV, M_WAITOK);
279         ucom = &sc->sc_ucom;
280         bzero(sc, sizeof (struct uvisor_softc));
281         usbd_devinfo(dev, 0, devinfo);
282         ucom->sc_dev = self;
283         device_set_desc_copy(self, devinfo);
284
285         ucom->sc_udev = dev;
286         ucom->sc_iface = uaa->iface;
287
288         devname = device_get_nameunit(ucom->sc_dev);
289         printf("%s: %s\n", devname, devinfo);
290         free(devinfo, M_USBDEV);
291
292         DPRINTFN(10,("\nuvisor_attach: sc=%p\n", sc));
293
294         /* Move the device into the configured state. */
295         err = usbd_set_config_index(dev, UVISOR_CONFIG_INDEX, 1);
296         if (err) {
297                 printf("\n%s: failed to set configuration, err=%s\n",
298                        devname, usbd_errstr(err));
299                 goto bad;
300         }
301
302         err = usbd_device2interface_handle(dev, UVISOR_IFACE_INDEX, &iface);
303         if (err) {
304                 printf("\n%s: failed to get interface, err=%s\n",
305                        devname, usbd_errstr(err));
306                 goto bad;
307         }
308
309         printf("%s: %s\n", devname, devinfo);
310
311         sc->sc_flags = uvisor_lookup(uaa->vendor, uaa->product)->uv_flags;
312
313         id = usbd_get_interface_descriptor(iface);
314
315         ucom->sc_udev = dev;
316         ucom->sc_iface = iface;
317
318         ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
319         for (i = 0; i < id->bNumEndpoints; i++) {
320                 int addr, dir, attr;
321                 ed = usbd_interface2endpoint_descriptor(iface, i);
322                 if (ed == NULL) {
323                         printf("%s: could not read endpoint descriptor"
324                                ": %s\n", devname, usbd_errstr(err));
325                         goto bad;
326                 }
327
328                 addr = ed->bEndpointAddress;
329                 dir = UE_GET_DIR(ed->bEndpointAddress);
330                 attr = ed->bmAttributes & UE_XFERTYPE;
331                 if (dir == UE_DIR_IN && attr == UE_BULK)
332                         ucom->sc_bulkin_no = addr;
333                 else if (dir == UE_DIR_OUT && attr == UE_BULK)
334                         ucom->sc_bulkout_no = addr;
335                 else {
336                         printf("%s: unexpected endpoint\n", devname);
337                         goto bad;
338                 }
339         }
340         if (ucom->sc_bulkin_no == -1) {
341                 printf("%s: Could not find data bulk in\n",
342                        device_get_nameunit(ucom->sc_dev));
343                 goto bad;
344         }
345         if (ucom->sc_bulkout_no == -1) {
346                 printf("%s: Could not find data bulk out\n",
347                        device_get_nameunit(ucom->sc_dev));
348                 goto bad;
349         }
350
351         ucom->sc_parent = sc;
352         ucom->sc_portno = UCOM_UNK_PORTNO;
353         /* bulkin, bulkout set above */
354         ucom->sc_ibufsize = UVISORIBUFSIZE;
355         ucom->sc_obufsize = UVISOROBUFSIZE;
356         ucom->sc_ibufsizepad = UVISORIBUFSIZE;
357         ucom->sc_opkthdrlen = 0;
358         ucom->sc_callback = &uvisor_callback;
359
360 #if 0
361         if (uaa->vendor == USB_VENDOR_SONY &&
362             uaa->product == USB_PRODUCT_SONY_CLIE_35)
363                 err = clie_3_5_init(sc);
364         else
365 #endif
366                 err = uvisor_init(sc);
367
368         if (err) {
369                 printf("%s: init failed, %s\n", device_get_nameunit(ucom->sc_dev),
370                        usbd_errstr(err));
371                 goto bad;
372         }
373
374         usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
375                            USBDEV(ucom->sc_dev));
376
377         DPRINTF(("uvisor: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no));
378         ucom_attach(&sc->sc_ucom);
379
380         USB_ATTACH_SUCCESS_RETURN;
381
382 bad:
383         DPRINTF(("uvisor_attach: ATTACH ERROR\n"));
384         ucom->sc_dying = 1;
385         USB_ATTACH_ERROR_RETURN;
386 }
387
388 #if 0
389
390 int
391 uvisor_activate(device_t self, enum devact act)
392 {
393         struct uvisor_softc *sc = (struct uvisor_softc *)self;
394         int rv = 0;
395
396         switch (act) {
397         case DVACT_ACTIVATE:
398                 return (EOPNOTSUPP);
399                 break;
400
401         case DVACT_DEACTIVATE:
402                 if (sc->sc_subdev != NULL)
403                         rv = config_deactivate(sc->sc_subdev);
404                 sc->sc_dying = 1;
405                 break;
406         }
407         return (rv);
408 }
409
410 #endif
411
412 USB_DETACH(uvisor)
413 {
414         USB_DETACH_START(uvisor, sc);
415         int rv = 0;
416
417         DPRINTF(("uvisor_detach: sc=%p\n", sc));
418         sc->sc_ucom.sc_dying = 1;
419         rv = ucom_detach(&sc->sc_ucom);
420
421         usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_ucom.sc_udev,
422                            USBDEV(sc->sc_ucom.sc_dev));
423
424         return (rv);
425 }
426
427 usbd_status
428 uvisor_init(struct uvisor_softc *sc)
429 {
430         usbd_status err;
431         usb_device_request_t req;
432         struct uvisor_connection_info coninfo;
433         struct uvisor_palm_connection_info pconinfo;
434         int actlen;
435         uWord avail;
436         char buffer[256];
437
438         if (sc->sc_flags & VISOR) {
439           DPRINTF(("uvisor_init: getting connection info\n"));
440           req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
441           req.bRequest = UVISOR_GET_CONNECTION_INFORMATION;
442           USETW(req.wValue, 0);
443           USETW(req.wIndex, 0);
444           USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
445           err = usbd_do_request_flags(sc->sc_ucom.sc_udev, &req, &coninfo,
446                                       USBD_SHORT_XFER_OK, &actlen,
447                                       USBD_DEFAULT_TIMEOUT);
448           if (err)
449             return (err);
450         }
451 #ifdef USB_DEBUG
452         {
453                 int i, np;
454                 char *string;
455
456                 np = UGETW(coninfo.num_ports);
457                 printf("%s: Number of ports: %d\n", device_get_nameunit(sc->sc_ucom.sc_dev), np);
458                 for (i = 0; i < np; ++i) {
459                         switch (coninfo.connections[i].port_function_id) {
460                         case UVISOR_FUNCTION_GENERIC:
461                                 string = "Generic";
462                                 break;
463                         case UVISOR_FUNCTION_DEBUGGER:
464                                 string = "Debugger";
465                                 break;
466                         case UVISOR_FUNCTION_HOTSYNC:
467                                 string = "HotSync";
468                                 break;
469                         case UVISOR_FUNCTION_REMOTE_FILE_SYS:
470                                 string = "Remote File System";
471                                 break;
472                         default:
473                                 string = "unknown";
474                                 break;
475                         }
476                         printf("%s: port %d, is for %s\n",
477                             device_get_nameunit(sc->sc_ucom.sc_dev), coninfo.connections[i].port,
478                             string);
479                 }
480         }
481 #endif
482
483         if (sc->sc_flags & PALM4) {
484                 int port;
485                 /* Palm OS 4.0 Hack */
486                 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
487                 req.bRequest = UVISOR_GET_PALM_INFORMATION;
488                 USETW(req.wValue, 0);
489                 USETW(req.wIndex, 0);
490                 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
491                 err = usbd_do_request_flags(sc->sc_ucom.sc_udev, &req, &pconinfo,
492                                             USBD_SHORT_XFER_OK, &actlen,
493                                             USBD_DEFAULT_TIMEOUT);
494                 if (err)
495                         return (err);
496
497                 if (pconinfo.endpoint_numbers_different) {
498                         port = pconinfo.connections[0].end_point_info;
499                         sc->sc_ucom.sc_bulkin_no = (port >> 4) | UE_DIR_IN;
500                         sc->sc_ucom.sc_bulkout_no = (port & 0xf) | UE_DIR_OUT;
501                 } else {
502                         port = pconinfo.connections[0].port;
503                         sc->sc_ucom.sc_bulkin_no = port | UE_DIR_IN;
504                         sc->sc_ucom.sc_bulkout_no = port | UE_DIR_OUT;
505                 }
506 #if 0
507                 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
508                 req.bRequest = UVISOR_GET_PALM_INFORMATION;
509                 USETW(req.wValue, 0);
510                 USETW(req.wIndex, 0);
511                 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
512                 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
513                 if (err)
514                         return (err);
515 #endif
516         }
517
518         if (sc->sc_flags & PALM35) {
519           /* get the config number */
520           DPRINTF(("clie_3_5_init: getting config info\n"));
521           req.bmRequestType = UT_READ;
522           req.bRequest = UR_GET_CONFIG;
523           USETW(req.wValue, 0);
524           USETW(req.wIndex, 0);
525           USETW(req.wLength, 1);
526           err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
527           if (err)
528             return (err);
529   
530           /* get the interface number */
531           DPRINTF(("clie_3_5_init: get the interface number\n"));
532           req.bmRequestType = UT_READ_DEVICE;
533           req.bRequest = UR_GET_INTERFACE;
534           USETW(req.wValue, 0);
535           USETW(req.wIndex, 0);
536           USETW(req.wLength, 1);
537           err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
538           if (err)
539             return (err);
540         }
541
542         DPRINTF(("uvisor_init: getting available bytes\n"));
543         req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
544         req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE;
545         USETW(req.wValue, 0);
546         USETW(req.wIndex, 5);
547         USETW(req.wLength, sizeof avail);
548         err = usbd_do_request(sc->sc_ucom.sc_udev, &req, &avail);
549         if (err)
550                 return (err);
551         DPRINTF(("uvisor_init: avail=%d\n", UGETW(avail)));
552
553         DPRINTF(("uvisor_init: done\n"));
554         return (err);
555 }
556
557 #if 0
558 usbd_status
559 clie_3_5_init(struct uvisor_softc *sc)
560 {
561         usbd_status err;
562         usb_device_request_t req;
563         char buffer[256];
564
565         /*
566          * Note that PEG-300 series devices expect the following two calls.
567          */
568
569         /* get the config number */
570         DPRINTF(("clie_3_5_init: getting config info\n"));
571         req.bmRequestType = UT_READ;
572         req.bRequest = UR_GET_CONFIG;
573         USETW(req.wValue, 0);
574         USETW(req.wIndex, 0);
575         USETW(req.wLength, 1);
576         err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
577         if (err)
578                 return (err);
579
580         /* get the interface number */
581         DPRINTF(("clie_3_5_init: get the interface number\n"));
582         req.bmRequestType = UT_READ_DEVICE;
583         req.bRequest = UR_GET_INTERFACE;
584         USETW(req.wValue, 0);
585         USETW(req.wIndex, 0);
586         USETW(req.wLength, 1);
587         err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
588         if (err)
589                 return (err);
590
591 #ifdef USB_DEBUG
592         {
593                 struct uvisor_connection_info coninfo;
594                 int i, np;
595                 char *string;
596
597                 np = UGETW(coninfo.num_ports);
598                 DPRINTF(("%s: Number of ports: %d\n", device_get_nameunit(sc->sc_ucom.sc_dev), np));
599                 for (i = 0; i < np; ++i) {
600                         switch (coninfo.connections[i].port_function_id) {
601                         case UVISOR_FUNCTION_GENERIC:
602                                 string = "Generic";
603                                 break;
604                         case UVISOR_FUNCTION_DEBUGGER:
605                                 string = "Debugger";
606                                 break;
607                         case UVISOR_FUNCTION_HOTSYNC:
608                                 string = "HotSync";
609                                 break;
610                         case UVISOR_FUNCTION_REMOTE_FILE_SYS:
611                                 string = "Remote File System";
612                                 break;
613                         default:
614                                 string = "unknown";
615                                 break;  
616                         }
617                         DPRINTF(("%s: port %d, is for %s\n",
618                             device_get_nameunit(sc->sc_ucom.sc_dev), coninfo.connections[i].port,
619                             string));
620                 }
621         }
622 #endif
623
624         DPRINTF(("clie_3_5_init: done\n"));
625         return (err);
626 }
627 #endif
628
629 void
630 uvisor_close(void *addr, int portno)
631 {
632         struct uvisor_softc *sc = addr;
633         usb_device_request_t req;
634         struct uvisor_connection_info coninfo; /* XXX ? */
635         int actlen;
636
637         if (sc->sc_ucom.sc_dying)
638                 return;
639
640         req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
641         req.bRequest = UVISOR_CLOSE_NOTIFICATION;
642         USETW(req.wValue, 0);
643         USETW(req.wIndex, 0);
644         USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
645         (void)usbd_do_request_flags(sc->sc_ucom.sc_udev, &req, &coninfo,
646                                     USBD_SHORT_XFER_OK, &actlen,
647                                     USBD_DEFAULT_TIMEOUT);
648 }