]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/usb/uvisor.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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 #include <sys/module.h>
62 #include <sys/bus.h>
63 #include <sys/conf.h>
64 #include <sys/tty.h>
65 #include <sys/sysctl.h>
66
67 #include <dev/usb/usb.h>
68 #include <dev/usb/usbhid.h>
69
70 #include <dev/usb/usbdi.h>
71 #include <dev/usb/usbdi_util.h>
72 #include "usbdevs.h"
73
74 #include <dev/usb/ucomvar.h>
75
76 #ifdef USB_DEBUG
77 #define DPRINTF(x)      if (uvisordebug) printf x
78 #define DPRINTFN(n,x)   if (uvisordebug>(n)) printf x
79 int uvisordebug = 0;
80 SYSCTL_NODE(_hw_usb, OID_AUTO, uvisor, CTLFLAG_RW, 0, "USB uvisor");
81 SYSCTL_INT(_hw_usb_uvisor, OID_AUTO, debug, CTLFLAG_RW,
82            &uvisordebug, 0, "uvisor debug level");
83 #else
84 #define DPRINTF(x)
85 #define DPRINTFN(n,x)
86 #endif
87
88 #define UVISOR_CONFIG_INDEX     0
89 #define UVISOR_IFACE_INDEX      0
90 #define UVISOR_MODVER           1
91
92 /* From the Linux driver */
93 /*
94  * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that
95  * are available to be transfered to the host for the specified endpoint.
96  * Currently this is not used, and always returns 0x0001
97  */
98 #define UVISOR_REQUEST_BYTES_AVAILABLE          0x01
99
100 /*
101  * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host
102  * is now closing the pipe. An empty packet is sent in response.
103  */
104 #define UVISOR_CLOSE_NOTIFICATION               0x02
105
106 /*
107  * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to
108  * get the endpoints used by the connection.
109  */
110 #define UVISOR_GET_CONNECTION_INFORMATION       0x03
111
112
113 /*
114  * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format
115  */
116 #define UVISOR_MAX_CONN 8
117 struct uvisor_connection_info {
118         uWord   num_ports;
119         struct {
120                 uByte   port_function_id;
121                 uByte   port;
122         } connections[UVISOR_MAX_CONN];
123 };
124 #define UVISOR_CONNECTION_INFO_SIZE 18
125
126 /* struct uvisor_connection_info.connection[x].port defines: */
127 #define UVISOR_ENDPOINT_1               0x01
128 #define UVISOR_ENDPOINT_2               0x02
129
130 /* struct uvisor_connection_info.connection[x].port_function_id defines: */
131 #define UVISOR_FUNCTION_GENERIC         0x00
132 #define UVISOR_FUNCTION_DEBUGGER        0x01
133 #define UVISOR_FUNCTION_HOTSYNC         0x02
134 #define UVISOR_FUNCTION_CONSOLE         0x03
135 #define UVISOR_FUNCTION_REMOTE_FILE_SYS 0x04
136
137 /*
138  * Unknown PalmOS stuff.
139  */
140 #define UVISOR_GET_PALM_INFORMATION             0x04
141 #define UVISOR_GET_PALM_INFORMATION_LEN         0x44
142
143 struct uvisor_palm_connection_info {
144         uByte   num_ports;
145         uByte   endpoint_numbers_different;
146         uWord   reserved1;
147   struct {
148                 uDWord  port_function_id;
149                 uByte   port;
150                 uByte   end_point_info;
151                 uWord   reserved;
152   } connections[UVISOR_MAX_CONN];
153 };
154
155
156 /*
157  * Crank down UVISORBUFSIZE from 1024 to 64 to avoid a problem where
158  * the Palm device and the USB host controller deadlock. The USB host
159  * controller is expecting an early-end-of-transmission packet with 0
160  * data, and the Palm doesn't send one because it's already
161  * communicated the amount of data it's going to send in a header
162  * (which ucom/uvisor are oblivious to). This is the problem that has
163  * been known on the pilot-link lists as the "[Free]BSD USB problem",
164  * but not understood.
165  */
166 #define UVISORIBUFSIZE 64
167 #define UVISOROBUFSIZE 1024
168
169 struct uvisor_softc {
170         struct ucom_softc       sc_ucom;
171         u_int16_t               sc_flags;
172 };
173
174 static usbd_status uvisor_init(struct uvisor_softc *);
175
176 /*static usbd_status clie_3_5_init(struct uvisor_softc *);*/
177
178 static void uvisor_close(void *, int);
179
180 struct ucom_callback uvisor_callback = {
181         NULL,
182         NULL,
183         NULL,
184         NULL,
185         NULL,
186         uvisor_close,
187         NULL,
188         NULL,
189 };
190
191 static device_probe_t uvisor_match;
192 static device_attach_t uvisor_attach;
193 static device_detach_t uvisor_detach;
194 static device_method_t uvisor_methods[] = {
195        /* Device interface */
196        DEVMETHOD(device_probe, uvisor_match),
197        DEVMETHOD(device_attach, uvisor_attach),
198        DEVMETHOD(device_detach, uvisor_detach),
199        { 0, 0 }
200  };
201
202
203 static driver_t uvisor_driver = {
204        "ucom",
205        uvisor_methods,
206        sizeof (struct uvisor_softc)
207 };
208
209 DRIVER_MODULE(uvisor, uhub, uvisor_driver, ucom_devclass, usbd_driver_load, 0);
210 MODULE_DEPEND(uvisor, usb, 1, 1, 1);
211 MODULE_DEPEND(uvisor, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
212 MODULE_VERSION(uvisor, UVISOR_MODVER);
213
214 struct uvisor_type {
215         struct usb_devno        uv_dev;
216         u_int16_t               uv_flags;
217 #define PALM4   0x0001
218 #define VISOR   0x0002
219 #define PALM35  0x0004
220 };
221 static const struct uvisor_type uvisor_devs[] = {
222         {{ USB_VENDOR_ACEECA, USB_PRODUCT_ACEECA_MEZ1000 }, PALM4 },
223         {{ USB_VENDOR_GARMIN, USB_PRODUCT_GARMIN_IQUE_3600 }, PALM4 },
224         {{ USB_VENDOR_FOSSIL, USB_PRODUCT_FOSSIL_WRISTPDA }, PALM4 },
225         {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR }, VISOR },
226         {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO }, PALM4 },
227         {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO600 }, PALM4 },
228         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M500 }, PALM4 },
229         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M505 }, PALM4 },
230         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M515 }, PALM4 },
231         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_I705 }, PALM4 },
232         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M125 }, PALM4 },
233         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M130 }, PALM4 },
234         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_Z }, PALM4 },
235         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_T }, PALM4 },
236         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE }, PALM4 },
237         {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE31 }, PALM4 },
238         {{ USB_VENDOR_SAMSUNG, USB_PRODUCT_SAMSUNG_I500 }, PALM4 }, 
239         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40 }, 0 },
240         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41 }, PALM4 },
241         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_S360 }, PALM4 },
242         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_NX60 }, PALM4 },
243         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_35 }, PALM35 },
244 /*      {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25 }, PALM4 },*/
245 /*      {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TH55 }, PALM4 }, */   /* See PR 80935 */
246         {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TJ37 }, PALM4 },
247         {{ USB_VENDOR_TAPWAVE, USB_PRODUCT_TAPWAVE_ZODIAC }, PALM4 },
248 };
249 #define uvisor_lookup(v, p) ((const struct uvisor_type *)usb_lookup(uvisor_devs, v, p))
250
251
252 static int
253 uvisor_match(device_t self)
254 {
255         struct usb_attach_arg *uaa = device_get_ivars(self);
256
257         if (uaa->iface != NULL)
258                 return (UMATCH_NONE);
259
260         DPRINTFN(20,("uvisor: vendor=0x%x, product=0x%x\n",
261                      uaa->vendor, uaa->product));
262
263         return (uvisor_lookup(uaa->vendor, uaa->product) != NULL ?
264                 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
265 }
266
267 static int
268 uvisor_attach(device_t self)
269 {
270         struct uvisor_softc *sc = device_get_softc(self);
271         struct usb_attach_arg *uaa = device_get_ivars(self);
272         usbd_device_handle dev = uaa->device;
273         usbd_interface_handle iface;
274         usb_interface_descriptor_t *id;
275         usb_endpoint_descriptor_t *ed;
276         int i;
277         usbd_status err;
278         struct ucom_softc *ucom;
279
280         ucom = &sc->sc_ucom;
281         ucom->sc_dev = self;
282         ucom->sc_udev = dev;
283         ucom->sc_iface = uaa->iface;
284
285         DPRINTFN(10,("\nuvisor_attach: sc=%p\n", sc));
286
287         /* Move the device into the configured state. */
288         err = usbd_set_config_index(dev, UVISOR_CONFIG_INDEX, 1);
289         if (err) {
290                 device_printf(self, "failed to set configuration, err=%s\n",
291                     usbd_errstr(err));
292                 goto bad;
293         }
294
295         err = usbd_device2interface_handle(dev, UVISOR_IFACE_INDEX, &iface);
296         if (err) {
297                 device_printf(self, "failed to get interface, err=%s\n",
298                     usbd_errstr(err));
299                 goto bad;
300         }
301
302         sc->sc_flags = uvisor_lookup(uaa->vendor, uaa->product)->uv_flags;
303
304         id = usbd_get_interface_descriptor(iface);
305
306         ucom->sc_udev = dev;
307         ucom->sc_iface = iface;
308
309         ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
310         for (i = 0; i < id->bNumEndpoints; i++) {
311                 int addr, dir, attr;
312                 ed = usbd_interface2endpoint_descriptor(iface, i);
313                 if (ed == NULL) {
314                         device_printf(self,
315                             "could not read endpoint descriptor: %s\n",
316                             usbd_errstr(err));
317                         goto bad;
318                 }
319
320                 addr = ed->bEndpointAddress;
321                 dir = UE_GET_DIR(ed->bEndpointAddress);
322                 attr = ed->bmAttributes & UE_XFERTYPE;
323                 if (dir == UE_DIR_IN && attr == UE_BULK)
324                         ucom->sc_bulkin_no = addr;
325                 else if (dir == UE_DIR_OUT && attr == UE_BULK)
326                         ucom->sc_bulkout_no = addr;
327                 else {
328                         device_printf(self, "unexpected endpoint\n");
329                         goto bad;
330                 }
331         }
332         if (ucom->sc_bulkin_no == -1) {
333                 device_printf(self, "Could not find data bulk in\n");
334                 goto bad;
335         }
336         if (ucom->sc_bulkout_no == -1) {
337                 device_printf(self, "Could not find data bulk out\n");
338                 goto bad;
339         }
340
341         ucom->sc_parent = sc;
342         ucom->sc_portno = UCOM_UNK_PORTNO;
343         /* bulkin, bulkout set above */
344         ucom->sc_ibufsize = UVISORIBUFSIZE;
345         ucom->sc_obufsize = UVISOROBUFSIZE;
346         ucom->sc_ibufsizepad = UVISORIBUFSIZE;
347         ucom->sc_opkthdrlen = 0;
348         ucom->sc_callback = &uvisor_callback;
349
350 #if 0
351         if (uaa->vendor == USB_VENDOR_SONY &&
352             uaa->product == USB_PRODUCT_SONY_CLIE_35)
353                 err = clie_3_5_init(sc);
354         else
355 #endif
356                 err = uvisor_init(sc);
357
358         if (err) {
359                 device_printf(ucom->sc_dev, "init failed, %s\n",
360                     usbd_errstr(err));
361                 goto bad;
362         }
363
364         usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
365           ucom->sc_dev);
366
367         DPRINTF(("uvisor: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no));
368         ucom_attach(&sc->sc_ucom);
369
370         return 0;
371
372 bad:
373         DPRINTF(("uvisor_attach: ATTACH ERROR\n"));
374         ucom->sc_dying = 1;
375         return ENXIO;
376 }
377
378 #if 0
379
380 int
381 uvisor_activate(device_t self, enum devact act)
382 {
383         struct uvisor_softc *sc = (struct uvisor_softc *)self;
384         int rv = 0;
385
386         switch (act) {
387         case DVACT_ACTIVATE:
388                 return (EOPNOTSUPP);
389                 break;
390
391         case DVACT_DEACTIVATE:
392                 if (sc->sc_subdev != NULL)
393                         rv = config_deactivate(sc->sc_subdev);
394                 sc->sc_dying = 1;
395                 break;
396         }
397         return (rv);
398 }
399
400 #endif
401
402 static int
403 uvisor_detach(device_t self)
404 {
405         struct uvisor_softc *sc = device_get_softc(self);
406         int rv = 0;
407
408         DPRINTF(("uvisor_detach: sc=%p\n", sc));
409         sc->sc_ucom.sc_dying = 1;
410         rv = ucom_detach(&sc->sc_ucom);
411
412         usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_ucom.sc_udev,
413           sc->sc_ucom.sc_dev);
414
415         return (rv);
416 }
417
418 usbd_status
419 uvisor_init(struct uvisor_softc *sc)
420 {
421         usbd_status err;
422         usb_device_request_t req;
423         struct uvisor_connection_info coninfo;
424         struct uvisor_palm_connection_info pconinfo;
425         int actlen;
426         uWord avail;
427         char buffer[256];
428
429         if (sc->sc_flags & VISOR) {
430           DPRINTF(("uvisor_init: getting connection info\n"));
431           req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
432           req.bRequest = UVISOR_GET_CONNECTION_INFORMATION;
433           USETW(req.wValue, 0);
434           USETW(req.wIndex, 0);
435           USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
436           err = usbd_do_request_flags(sc->sc_ucom.sc_udev, &req, &coninfo,
437                                       USBD_SHORT_XFER_OK, &actlen,
438                                       USBD_DEFAULT_TIMEOUT);
439           if (err)
440             return (err);
441         }
442 #ifdef USB_DEBUG
443         {
444                 int i, np;
445                 char *string;
446
447                 np = UGETW(coninfo.num_ports);
448                 device_printf(sc->sc_ucom.sc_dev, "Number of ports: %d\n", np);
449                 for (i = 0; i < np; ++i) {
450                         switch (coninfo.connections[i].port_function_id) {
451                         case UVISOR_FUNCTION_GENERIC:
452                                 string = "Generic";
453                                 break;
454                         case UVISOR_FUNCTION_DEBUGGER:
455                                 string = "Debugger";
456                                 break;
457                         case UVISOR_FUNCTION_HOTSYNC:
458                                 string = "HotSync";
459                                 break;
460                         case UVISOR_FUNCTION_REMOTE_FILE_SYS:
461                                 string = "Remote File System";
462                                 break;
463                         default:
464                                 string = "unknown";
465                                 break;
466                         }
467                         device_printf(sc->sc_ucom.sc_dev,
468                             "port %d, is for %s\n",
469                             coninfo.connections[i].port, string);
470                 }
471         }
472 #endif
473
474         if (sc->sc_flags & PALM4) {
475                 int port;
476                 /* Palm OS 4.0 Hack */
477                 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
478                 req.bRequest = UVISOR_GET_PALM_INFORMATION;
479                 USETW(req.wValue, 0);
480                 USETW(req.wIndex, 0);
481                 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
482                 err = usbd_do_request_flags(sc->sc_ucom.sc_udev, &req, &pconinfo,
483                                             USBD_SHORT_XFER_OK, &actlen,
484                                             USBD_DEFAULT_TIMEOUT);
485                 if (err)
486                         return (err);
487
488                 if (pconinfo.endpoint_numbers_different) {
489                         port = pconinfo.connections[0].end_point_info;
490                         sc->sc_ucom.sc_bulkin_no = (port >> 4) | UE_DIR_IN;
491                         sc->sc_ucom.sc_bulkout_no = (port & 0xf) | UE_DIR_OUT;
492                 } else {
493                         port = pconinfo.connections[0].port;
494                         sc->sc_ucom.sc_bulkin_no = port | UE_DIR_IN;
495                         sc->sc_ucom.sc_bulkout_no = port | UE_DIR_OUT;
496                 }
497 #if 0
498                 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
499                 req.bRequest = UVISOR_GET_PALM_INFORMATION;
500                 USETW(req.wValue, 0);
501                 USETW(req.wIndex, 0);
502                 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
503                 err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
504                 if (err)
505                         return (err);
506 #endif
507         }
508
509         if (sc->sc_flags & PALM35) {
510           /* get the config number */
511           DPRINTF(("clie_3_5_init: getting config info\n"));
512           req.bmRequestType = UT_READ;
513           req.bRequest = UR_GET_CONFIG;
514           USETW(req.wValue, 0);
515           USETW(req.wIndex, 0);
516           USETW(req.wLength, 1);
517           err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
518           if (err)
519             return (err);
520   
521           /* get the interface number */
522           DPRINTF(("clie_3_5_init: get the interface number\n"));
523           req.bmRequestType = UT_READ_DEVICE;
524           req.bRequest = UR_GET_INTERFACE;
525           USETW(req.wValue, 0);
526           USETW(req.wIndex, 0);
527           USETW(req.wLength, 1);
528           err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
529           if (err)
530             return (err);
531         }
532
533         DPRINTF(("uvisor_init: getting available bytes\n"));
534         req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
535         req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE;
536         USETW(req.wValue, 0);
537         USETW(req.wIndex, 5);
538         USETW(req.wLength, sizeof avail);
539         err = usbd_do_request(sc->sc_ucom.sc_udev, &req, &avail);
540         if (err)
541                 return (err);
542         DPRINTF(("uvisor_init: avail=%d\n", UGETW(avail)));
543
544         DPRINTF(("uvisor_init: done\n"));
545         return (err);
546 }
547
548 #if 0
549 usbd_status
550 clie_3_5_init(struct uvisor_softc *sc)
551 {
552         usbd_status err;
553         usb_device_request_t req;
554         char buffer[256];
555
556         /*
557          * Note that PEG-300 series devices expect the following two calls.
558          */
559
560         /* get the config number */
561         DPRINTF(("clie_3_5_init: getting config info\n"));
562         req.bmRequestType = UT_READ;
563         req.bRequest = UR_GET_CONFIG;
564         USETW(req.wValue, 0);
565         USETW(req.wIndex, 0);
566         USETW(req.wLength, 1);
567         err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
568         if (err)
569                 return (err);
570
571         /* get the interface number */
572         DPRINTF(("clie_3_5_init: get the interface number\n"));
573         req.bmRequestType = UT_READ_DEVICE;
574         req.bRequest = UR_GET_INTERFACE;
575         USETW(req.wValue, 0);
576         USETW(req.wIndex, 0);
577         USETW(req.wLength, 1);
578         err = usbd_do_request(sc->sc_ucom.sc_udev, &req, buffer);
579         if (err)
580                 return (err);
581
582 #ifdef USB_DEBUG
583         {
584                 struct uvisor_connection_info coninfo;
585                 int i, np;
586                 char *string;
587
588                 np = UGETW(coninfo.num_ports);
589                 DPRINTF(("%s: Number of ports: %d\n", device_get_nameunit(sc->sc_ucom.sc_dev), np));
590                 for (i = 0; i < np; ++i) {
591                         switch (coninfo.connections[i].port_function_id) {
592                         case UVISOR_FUNCTION_GENERIC:
593                                 string = "Generic";
594                                 break;
595                         case UVISOR_FUNCTION_DEBUGGER:
596                                 string = "Debugger";
597                                 break;
598                         case UVISOR_FUNCTION_HOTSYNC:
599                                 string = "HotSync";
600                                 break;
601                         case UVISOR_FUNCTION_REMOTE_FILE_SYS:
602                                 string = "Remote File System";
603                                 break;
604                         default:
605                                 string = "unknown";
606                                 break;  
607                         }
608                         DPRINTF(("%s: port %d, is for %s\n",
609                             device_get_nameunit(sc->sc_ucom.sc_dev), coninfo.connections[i].port,
610                             string));
611                 }
612         }
613 #endif
614
615         DPRINTF(("clie_3_5_init: done\n"));
616         return (err);
617 }
618 #endif
619
620 void
621 uvisor_close(void *addr, int portno)
622 {
623         struct uvisor_softc *sc = addr;
624         usb_device_request_t req;
625         struct uvisor_connection_info coninfo; /* XXX ? */
626         int actlen;
627
628         if (sc->sc_ucom.sc_dying)
629                 return;
630
631         req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
632         req.bRequest = UVISOR_CLOSE_NOTIFICATION;
633         USETW(req.wValue, 0);
634         USETW(req.wIndex, 0);
635         USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
636         (void)usbd_do_request_flags(sc->sc_ucom.sc_udev, &req, &coninfo,
637                                     USBD_SHORT_XFER_OK, &actlen,
638                                     USBD_DEFAULT_TIMEOUT);
639 }