uvisor.c revision 1.21 1 1.21 nathanw /* $NetBSD: uvisor.c,v 1.21 2003/08/03 21:59:26 nathanw 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 * 3. All advertising materials mentioning features or use of this software
20 1.1 augustss * must display the following acknowledgement:
21 1.1 augustss * This product includes software developed by the NetBSD
22 1.1 augustss * Foundation, Inc. and its contributors.
23 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 augustss * contributors may be used to endorse or promote products derived
25 1.1 augustss * from this software without specific prior written permission.
26 1.1 augustss *
27 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
38 1.1 augustss */
39 1.1 augustss
40 1.1 augustss /*
41 1.2 hubertf * Handspring Visor (Palmpilot compatible PDA) driver
42 1.1 augustss */
43 1.12 lukem
44 1.12 lukem #include <sys/cdefs.h>
45 1.21 nathanw __KERNEL_RCSID(0, "$NetBSD: uvisor.c,v 1.21 2003/08/03 21:59:26 nathanw Exp $");
46 1.1 augustss
47 1.1 augustss #include <sys/param.h>
48 1.1 augustss #include <sys/systm.h>
49 1.1 augustss #include <sys/kernel.h>
50 1.1 augustss #include <sys/device.h>
51 1.1 augustss #include <sys/conf.h>
52 1.1 augustss #include <sys/tty.h>
53 1.1 augustss
54 1.1 augustss #include <dev/usb/usb.h>
55 1.1 augustss #include <dev/usb/usbhid.h>
56 1.1 augustss
57 1.1 augustss #include <dev/usb/usbdi.h>
58 1.1 augustss #include <dev/usb/usbdi_util.h>
59 1.1 augustss #include <dev/usb/usbdevs.h>
60 1.1 augustss
61 1.1 augustss #include <dev/usb/ucomvar.h>
62 1.1 augustss
63 1.1 augustss #ifdef UVISOR_DEBUG
64 1.1 augustss #define DPRINTF(x) if (uvisordebug) printf x
65 1.1 augustss #define DPRINTFN(n,x) if (uvisordebug>(n)) printf x
66 1.3 augustss int uvisordebug = 0;
67 1.1 augustss #else
68 1.1 augustss #define DPRINTF(x)
69 1.1 augustss #define DPRINTFN(n,x)
70 1.1 augustss #endif
71 1.1 augustss
72 1.1 augustss #define UVISOR_CONFIG_INDEX 0
73 1.1 augustss #define UVISOR_IFACE_INDEX 0
74 1.1 augustss
75 1.1 augustss /* From the Linux driver */
76 1.1 augustss /*
77 1.1 augustss * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that
78 1.1 augustss * are available to be transfered to the host for the specified endpoint.
79 1.1 augustss * Currently this is not used, and always returns 0x0001
80 1.1 augustss */
81 1.1 augustss #define UVISOR_REQUEST_BYTES_AVAILABLE 0x01
82 1.1 augustss
83 1.1 augustss /*
84 1.1 augustss * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host
85 1.1 augustss * is now closing the pipe. An empty packet is sent in response.
86 1.1 augustss */
87 1.1 augustss #define UVISOR_CLOSE_NOTIFICATION 0x02
88 1.1 augustss
89 1.1 augustss /*
90 1.1 augustss * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to
91 1.1 augustss * get the endpoints used by the connection.
92 1.1 augustss */
93 1.1 augustss #define UVISOR_GET_CONNECTION_INFORMATION 0x03
94 1.1 augustss
95 1.1 augustss
96 1.1 augustss /*
97 1.1 augustss * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format
98 1.1 augustss */
99 1.10 augustss #define UVISOR_MAX_CONN 8
100 1.1 augustss struct uvisor_connection_info {
101 1.1 augustss uWord num_ports;
102 1.1 augustss struct {
103 1.1 augustss uByte port_function_id;
104 1.1 augustss uByte port;
105 1.10 augustss } connections[UVISOR_MAX_CONN];
106 1.1 augustss };
107 1.1 augustss #define UVISOR_CONNECTION_INFO_SIZE 18
108 1.1 augustss
109 1.1 augustss /* struct uvisor_connection_info.connection[x].port_function_id defines: */
110 1.1 augustss #define UVISOR_FUNCTION_GENERIC 0x00
111 1.1 augustss #define UVISOR_FUNCTION_DEBUGGER 0x01
112 1.1 augustss #define UVISOR_FUNCTION_HOTSYNC 0x02
113 1.1 augustss #define UVISOR_FUNCTION_CONSOLE 0x03
114 1.1 augustss #define UVISOR_FUNCTION_REMOTE_FILE_SYS 0x04
115 1.1 augustss
116 1.14 augustss /*
117 1.14 augustss * Unknown PalmOS stuff.
118 1.14 augustss */
119 1.14 augustss #define UVISOR_GET_PALM_INFORMATION 0x04
120 1.21 nathanw #define UVISOR_GET_PALM_INFORMATION_LEN 0x44
121 1.14 augustss
122 1.21 nathanw struct uvisor_palm_connection_info {
123 1.21 nathanw uByte num_ports;
124 1.21 nathanw uByte endpoint_numbers_different;
125 1.21 nathanw uWord reserved1;
126 1.21 nathanw struct {
127 1.21 nathanw uDWord port_function_id;
128 1.21 nathanw uByte port;
129 1.21 nathanw uByte end_point_info;
130 1.21 nathanw uWord reserved;
131 1.21 nathanw } connections[UVISOR_MAX_CONN];
132 1.21 nathanw };
133 1.1 augustss
134 1.21 nathanw
135 1.21 nathanw
136 1.21 nathanw #define UVISORIBUFSIZE 64
137 1.4 augustss #define UVISOROBUFSIZE 1024
138 1.4 augustss
139 1.1 augustss struct uvisor_softc {
140 1.1 augustss USBBASEDEVICE sc_dev; /* base device */
141 1.1 augustss usbd_device_handle sc_udev; /* device */
142 1.1 augustss usbd_interface_handle sc_iface; /* interface */
143 1.1 augustss
144 1.10 augustss device_ptr_t sc_subdevs[UVISOR_MAX_CONN];
145 1.10 augustss int sc_numcon;
146 1.1 augustss
147 1.14 augustss u_int16_t sc_flags;
148 1.14 augustss
149 1.1 augustss u_char sc_dying;
150 1.1 augustss };
151 1.1 augustss
152 1.16 augustss Static usbd_status uvisor_init(struct uvisor_softc *,
153 1.21 nathanw struct uvisor_connection_info *,
154 1.21 nathanw struct uvisor_palm_connection_info *);
155 1.1 augustss
156 1.7 augustss Static void uvisor_close(void *, int);
157 1.1 augustss
158 1.1 augustss
159 1.1 augustss struct ucom_methods uvisor_methods = {
160 1.1 augustss NULL,
161 1.1 augustss NULL,
162 1.1 augustss NULL,
163 1.1 augustss NULL,
164 1.1 augustss NULL,
165 1.1 augustss uvisor_close,
166 1.5 augustss NULL,
167 1.5 augustss NULL,
168 1.1 augustss };
169 1.1 augustss
170 1.14 augustss struct uvisor_type {
171 1.14 augustss struct usb_devno uv_dev;
172 1.14 augustss u_int16_t uv_flags;
173 1.14 augustss #define PALM4 0x0001
174 1.21 nathanw #define VISOR 0x0002
175 1.21 nathanw
176 1.14 augustss };
177 1.14 augustss static const struct uvisor_type uvisor_devs[] = {
178 1.21 nathanw {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR }, VISOR },
179 1.19 augustss {{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO }, PALM4 },
180 1.14 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M500 }, PALM4 },
181 1.14 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M505 }, PALM4 },
182 1.17 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M515 }, PALM4 },
183 1.19 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_I705 }, PALM4 },
184 1.14 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M125 }, PALM4 },
185 1.19 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_M130 }, PALM4 },
186 1.19 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_Z }, PALM4 },
187 1.20 simonb {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_T }, PALM4 },
188 1.18 augustss {{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE }, PALM4 },
189 1.14 augustss {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40 }, PALM4 },
190 1.21 nathanw {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41 }, PALM4 },
191 1.19 augustss {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_S360 }, PALM4 },
192 1.19 augustss {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_NX60 }, PALM4 },
193 1.14 augustss /* {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25 }, PALM4 },*/
194 1.14 augustss };
195 1.14 augustss #define uvisor_lookup(v, p) ((struct uvisor_type *)usb_lookup(uvisor_devs, v, p))
196 1.14 augustss
197 1.1 augustss USB_DECLARE_DRIVER(uvisor);
198 1.1 augustss
199 1.1 augustss USB_MATCH(uvisor)
200 1.1 augustss {
201 1.1 augustss USB_MATCH_START(uvisor, uaa);
202 1.16 augustss
203 1.1 augustss if (uaa->iface != NULL)
204 1.1 augustss return (UMATCH_NONE);
205 1.1 augustss
206 1.1 augustss DPRINTFN(20,("uvisor: vendor=0x%x, product=0x%x\n",
207 1.1 augustss uaa->vendor, uaa->product));
208 1.1 augustss
209 1.14 augustss return (uvisor_lookup(uaa->vendor, uaa->product) != NULL ?
210 1.14 augustss UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
211 1.1 augustss }
212 1.1 augustss
213 1.1 augustss USB_ATTACH(uvisor)
214 1.1 augustss {
215 1.1 augustss USB_ATTACH_START(uvisor, sc, uaa);
216 1.1 augustss usbd_device_handle dev = uaa->device;
217 1.1 augustss usbd_interface_handle iface;
218 1.1 augustss usb_interface_descriptor_t *id;
219 1.10 augustss struct uvisor_connection_info coninfo;
220 1.21 nathanw struct uvisor_palm_connection_info palmconinfo;
221 1.1 augustss usb_endpoint_descriptor_t *ed;
222 1.1 augustss char devinfo[1024];
223 1.1 augustss char *devname = USBDEVNAME(sc->sc_dev);
224 1.10 augustss int i, j, hasin, hasout, port;
225 1.1 augustss usbd_status err;
226 1.1 augustss struct ucom_attach_args uca;
227 1.1 augustss
228 1.1 augustss DPRINTFN(10,("\nuvisor_attach: sc=%p\n", sc));
229 1.1 augustss
230 1.1 augustss /* Move the device into the configured state. */
231 1.1 augustss err = usbd_set_config_index(dev, UVISOR_CONFIG_INDEX, 1);
232 1.1 augustss if (err) {
233 1.1 augustss printf("\n%s: failed to set configuration, err=%s\n",
234 1.1 augustss devname, usbd_errstr(err));
235 1.1 augustss goto bad;
236 1.1 augustss }
237 1.1 augustss
238 1.1 augustss err = usbd_device2interface_handle(dev, UVISOR_IFACE_INDEX, &iface);
239 1.1 augustss if (err) {
240 1.1 augustss printf("\n%s: failed to get interface, err=%s\n",
241 1.1 augustss devname, usbd_errstr(err));
242 1.1 augustss goto bad;
243 1.1 augustss }
244 1.1 augustss
245 1.1 augustss usbd_devinfo(dev, 0, devinfo);
246 1.1 augustss USB_ATTACH_SETUP;
247 1.1 augustss printf("%s: %s\n", devname, devinfo);
248 1.1 augustss
249 1.14 augustss sc->sc_flags = uvisor_lookup(uaa->vendor, uaa->product)->uv_flags;
250 1.14 augustss
251 1.21 nathanw if ((sc->sc_flags & (VISOR | PALM4)) == 0) {
252 1.21 nathanw printf("%s: init failed, device type is neither visor nor palm\n",
253 1.21 nathanw USBDEVNAME(sc->sc_dev));
254 1.21 nathanw goto bad;
255 1.21 nathanw }
256 1.21 nathanw
257 1.1 augustss id = usbd_get_interface_descriptor(iface);
258 1.3 augustss
259 1.3 augustss sc->sc_udev = dev;
260 1.1 augustss sc->sc_iface = iface;
261 1.1 augustss
262 1.4 augustss uca.ibufsize = UVISORIBUFSIZE;
263 1.4 augustss uca.obufsize = UVISOROBUFSIZE;
264 1.5 augustss uca.ibufsizepad = UVISORIBUFSIZE;
265 1.8 augustss uca.opkthdrlen = 0;
266 1.4 augustss uca.device = dev;
267 1.4 augustss uca.iface = iface;
268 1.4 augustss uca.methods = &uvisor_methods;
269 1.4 augustss uca.arg = sc;
270 1.4 augustss
271 1.21 nathanw err = uvisor_init(sc, &coninfo, &palmconinfo);
272 1.1 augustss if (err) {
273 1.1 augustss printf("%s: init failed, %s\n", USBDEVNAME(sc->sc_dev),
274 1.1 augustss usbd_errstr(err));
275 1.1 augustss goto bad;
276 1.1 augustss }
277 1.1 augustss
278 1.9 augustss usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
279 1.9 augustss USBDEV(sc->sc_dev));
280 1.9 augustss
281 1.21 nathanw if (sc->sc_flags & VISOR) {
282 1.21 nathanw sc->sc_numcon = UGETW(coninfo.num_ports);
283 1.21 nathanw if (sc->sc_numcon > UVISOR_MAX_CONN)
284 1.21 nathanw sc->sc_numcon = UVISOR_MAX_CONN;
285 1.21 nathanw
286 1.21 nathanw /* Attach a ucom for each connection. */
287 1.21 nathanw for (i = 0; i < sc->sc_numcon; ++i) {
288 1.21 nathanw switch (coninfo.connections[i].port_function_id) {
289 1.21 nathanw case UVISOR_FUNCTION_GENERIC:
290 1.21 nathanw uca.info = "Generic";
291 1.21 nathanw break;
292 1.21 nathanw case UVISOR_FUNCTION_DEBUGGER:
293 1.21 nathanw uca.info = "Debugger";
294 1.21 nathanw break;
295 1.21 nathanw case UVISOR_FUNCTION_HOTSYNC:
296 1.21 nathanw uca.info = "HotSync";
297 1.21 nathanw break;
298 1.21 nathanw case UVISOR_FUNCTION_REMOTE_FILE_SYS:
299 1.21 nathanw uca.info = "Remote File System";
300 1.21 nathanw break;
301 1.21 nathanw default:
302 1.21 nathanw uca.info = "unknown";
303 1.10 augustss break;
304 1.10 augustss }
305 1.21 nathanw port = coninfo.connections[i].port;
306 1.21 nathanw uca.portno = port;
307 1.21 nathanw uca.bulkin = port | UE_DIR_IN;
308 1.21 nathanw uca.bulkout = port | UE_DIR_OUT;
309 1.21 nathanw /* Verify that endpoints exist. */
310 1.21 nathanw hasin = 0;
311 1.21 nathanw hasout = 0;
312 1.21 nathanw for (j = 0; j < id->bNumEndpoints; j++) {
313 1.21 nathanw ed = usbd_interface2endpoint_descriptor(iface, j);
314 1.21 nathanw if (ed == NULL)
315 1.21 nathanw break;
316 1.21 nathanw if (UE_GET_ADDR(ed->bEndpointAddress) == port &&
317 1.21 nathanw (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
318 1.21 nathanw if (UE_GET_DIR(ed->bEndpointAddress)
319 1.21 nathanw == UE_DIR_IN)
320 1.21 nathanw hasin++;
321 1.21 nathanw else
322 1.21 nathanw hasout++;
323 1.21 nathanw }
324 1.21 nathanw }
325 1.21 nathanw if (hasin == 1 && hasout == 1)
326 1.21 nathanw sc->sc_subdevs[i] = config_found_sm(self, &uca,
327 1.21 nathanw ucomprint, ucomsubmatch);
328 1.21 nathanw else
329 1.21 nathanw printf("%s: no proper endpoints for port %d (%d,%d)\n",
330 1.21 nathanw USBDEVNAME(sc->sc_dev), port, hasin, hasout);
331 1.10 augustss }
332 1.21 nathanw
333 1.21 nathanw } else {
334 1.21 nathanw sc->sc_numcon = palmconinfo.num_ports;
335 1.21 nathanw if (sc->sc_numcon > UVISOR_MAX_CONN)
336 1.21 nathanw sc->sc_numcon = UVISOR_MAX_CONN;
337 1.21 nathanw
338 1.21 nathanw /* Attach a ucom for each connection. */
339 1.21 nathanw for (i = 0; i < sc->sc_numcon; ++i) {
340 1.21 nathanw /*
341 1.21 nathanw * XXX this should copy out 4-char string from the
342 1.21 nathanw * XXX port_function_id, but where would the string go?
343 1.21 nathanw * XXX uca.info is a const char *, not an array.
344 1.21 nathanw */
345 1.21 nathanw uca.info = "sync";
346 1.21 nathanw uca.portno = i;
347 1.21 nathanw if (palmconinfo.endpoint_numbers_different) {
348 1.21 nathanw port = palmconinfo.connections[i].end_point_info;
349 1.21 nathanw uca.bulkin = (port >> 4) | UE_DIR_IN;
350 1.21 nathanw uca.bulkout = (port & 0xf) | UE_DIR_OUT;
351 1.21 nathanw } else {
352 1.21 nathanw port = palmconinfo.connections[i].port;
353 1.21 nathanw uca.bulkin = port | UE_DIR_IN;
354 1.21 nathanw uca.bulkout = port | UE_DIR_OUT;
355 1.21 nathanw }
356 1.10 augustss sc->sc_subdevs[i] = config_found_sm(self, &uca,
357 1.10 augustss ucomprint, ucomsubmatch);
358 1.21 nathanw
359 1.21 nathanw
360 1.21 nathanw }
361 1.10 augustss }
362 1.16 augustss
363 1.1 augustss USB_ATTACH_SUCCESS_RETURN;
364 1.1 augustss
365 1.1 augustss bad:
366 1.1 augustss DPRINTF(("uvisor_attach: ATTACH ERROR\n"));
367 1.1 augustss sc->sc_dying = 1;
368 1.1 augustss USB_ATTACH_ERROR_RETURN;
369 1.1 augustss }
370 1.1 augustss
371 1.1 augustss int
372 1.7 augustss uvisor_activate(device_ptr_t self, enum devact act)
373 1.1 augustss {
374 1.1 augustss struct uvisor_softc *sc = (struct uvisor_softc *)self;
375 1.1 augustss int rv = 0;
376 1.10 augustss int i;
377 1.1 augustss
378 1.1 augustss switch (act) {
379 1.1 augustss case DVACT_ACTIVATE:
380 1.1 augustss return (EOPNOTSUPP);
381 1.1 augustss break;
382 1.1 augustss
383 1.1 augustss case DVACT_DEACTIVATE:
384 1.10 augustss for (i = 0; i < sc->sc_numcon; i++)
385 1.10 augustss if (sc->sc_subdevs[i] != NULL)
386 1.10 augustss rv = config_deactivate(sc->sc_subdevs[i]);
387 1.1 augustss sc->sc_dying = 1;
388 1.1 augustss break;
389 1.1 augustss }
390 1.1 augustss return (rv);
391 1.1 augustss }
392 1.1 augustss
393 1.1 augustss int
394 1.7 augustss uvisor_detach(device_ptr_t self, int flags)
395 1.1 augustss {
396 1.1 augustss struct uvisor_softc *sc = (struct uvisor_softc *)self;
397 1.1 augustss int rv = 0;
398 1.10 augustss int i;
399 1.1 augustss
400 1.1 augustss DPRINTF(("uvisor_detach: sc=%p flags=%d\n", sc, flags));
401 1.1 augustss sc->sc_dying = 1;
402 1.10 augustss for (i = 0; i < sc->sc_numcon; i++) {
403 1.10 augustss if (sc->sc_subdevs[i] != NULL) {
404 1.10 augustss rv |= config_detach(sc->sc_subdevs[i], flags);
405 1.10 augustss sc->sc_subdevs[i] = NULL;
406 1.10 augustss }
407 1.1 augustss }
408 1.9 augustss
409 1.9 augustss usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
410 1.9 augustss USBDEV(sc->sc_dev));
411 1.9 augustss
412 1.9 augustss
413 1.10 augustss return (rv);
414 1.1 augustss }
415 1.1 augustss
416 1.1 augustss usbd_status
417 1.21 nathanw uvisor_init(struct uvisor_softc *sc, struct uvisor_connection_info *ci,
418 1.21 nathanw struct uvisor_palm_connection_info *cpi)
419 1.1 augustss {
420 1.1 augustss usbd_status err;
421 1.1 augustss usb_device_request_t req;
422 1.1 augustss int actlen;
423 1.1 augustss uWord avail;
424 1.14 augustss
425 1.21 nathanw if (sc->sc_flags & VISOR) {
426 1.21 nathanw DPRINTF(("uvisor_init: getting Visor connection info\n"));
427 1.14 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
428 1.21 nathanw req.bRequest = UVISOR_GET_CONNECTION_INFORMATION;
429 1.14 augustss USETW(req.wValue, 0);
430 1.14 augustss USETW(req.wIndex, 0);
431 1.21 nathanw USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
432 1.21 nathanw err = usbd_do_request_flags(sc->sc_udev, &req, ci,
433 1.21 nathanw USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
434 1.14 augustss if (err)
435 1.14 augustss return (err);
436 1.21 nathanw }
437 1.21 nathanw
438 1.21 nathanw if (sc->sc_flags & PALM4) {
439 1.21 nathanw DPRINTF(("uvisor_init: getting Palm connection info\n"));
440 1.14 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
441 1.14 augustss req.bRequest = UVISOR_GET_PALM_INFORMATION;
442 1.14 augustss USETW(req.wValue, 0);
443 1.14 augustss USETW(req.wIndex, 0);
444 1.14 augustss USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
445 1.21 nathanw err = usbd_do_request_flags(sc->sc_udev, &req, cpi,
446 1.21 nathanw USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
447 1.14 augustss if (err)
448 1.14 augustss return (err);
449 1.14 augustss }
450 1.1 augustss
451 1.1 augustss DPRINTF(("uvisor_init: getting available bytes\n"));
452 1.1 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
453 1.1 augustss req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE;
454 1.1 augustss USETW(req.wValue, 0);
455 1.1 augustss USETW(req.wIndex, 5);
456 1.1 augustss USETW(req.wLength, sizeof avail);
457 1.1 augustss err = usbd_do_request(sc->sc_udev, &req, &avail);
458 1.1 augustss if (err)
459 1.1 augustss return (err);
460 1.1 augustss DPRINTF(("uvisor_init: avail=%d\n", UGETW(avail)));
461 1.1 augustss
462 1.1 augustss DPRINTF(("uvisor_init: done\n"));
463 1.1 augustss return (err);
464 1.1 augustss }
465 1.1 augustss
466 1.1 augustss void
467 1.7 augustss uvisor_close(void *addr, int portno)
468 1.1 augustss {
469 1.1 augustss struct uvisor_softc *sc = addr;
470 1.1 augustss usb_device_request_t req;
471 1.1 augustss struct uvisor_connection_info coninfo; /* XXX ? */
472 1.1 augustss int actlen;
473 1.3 augustss
474 1.3 augustss if (sc->sc_dying)
475 1.3 augustss return;
476 1.1 augustss
477 1.1 augustss req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
478 1.1 augustss req.bRequest = UVISOR_CLOSE_NOTIFICATION;
479 1.1 augustss USETW(req.wValue, 0);
480 1.1 augustss USETW(req.wIndex, 0);
481 1.1 augustss USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
482 1.16 augustss (void)usbd_do_request_flags(sc->sc_udev, &req, &coninfo,
483 1.13 augustss USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
484 1.1 augustss }
485