Deleted Added
full compact
uvisor.c (192499) uvisor.c (192502)
1/* $NetBSD: uvisor.c,v 1.9 2001/01/23 14:04:14 augustss Exp $ */
1/* $NetBSD: uvisor.c,v 1.9 2001/01/23 14:04:14 augustss Exp $ */
2/* $FreeBSD: head/sys/dev/usb/serial/uvisor.c 192499 2009-05-21 00:04:17Z thompsa $ */
2/* $FreeBSD: head/sys/dev/usb/serial/uvisor.c 192502 2009-05-21 01:48:42Z thompsa $ */
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 * Copyright (c) 2000 The NetBSD Foundation, Inc.
18 * All rights reserved.
19 *
20 * This code is derived from software contributed to The NetBSD Foundation
21 * by Lennart Augustsson (lennart@augustsson.net) at
22 * Carlstedt Research & Technology.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. All advertising materials mentioning features or use of this software
33 * must display the following acknowledgement:
34 * This product includes software developed by the NetBSD
35 * Foundation, Inc. and its contributors.
36 * 4. Neither the name of The NetBSD Foundation nor the names of its
37 * contributors may be used to endorse or promote products derived
38 * from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
41 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
42 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
44 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50 * POSSIBILITY OF SUCH DAMAGE.
51 */
52
53/*
54 * Handspring Visor (Palmpilot compatible PDA) driver
55 */
56
57#include "usbdevs.h"
58#include <dev/usb/usb.h>
59#include <dev/usb/usb_mfunc.h>
60#include <dev/usb/usb_error.h>
61#include <dev/usb/usb_cdc.h>
62#include <dev/usb/usb_ioctl.h>
63
64#define USB_DEBUG_VAR uvisor_debug
65
66#include <dev/usb/usb_core.h>
67#include <dev/usb/usb_debug.h>
68#include <dev/usb/usb_process.h>
69#include <dev/usb/usb_request.h>
70#include <dev/usb/usb_lookup.h>
71#include <dev/usb/usb_util.h>
72#include <dev/usb/usb_busdma.h>
73
74#include <dev/usb/serial/usb_serial.h>
75
76#if USB_DEBUG
77static int uvisor_debug = 0;
78
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 * Copyright (c) 2000 The NetBSD Foundation, Inc.
18 * All rights reserved.
19 *
20 * This code is derived from software contributed to The NetBSD Foundation
21 * by Lennart Augustsson (lennart@augustsson.net) at
22 * Carlstedt Research & Technology.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. All advertising materials mentioning features or use of this software
33 * must display the following acknowledgement:
34 * This product includes software developed by the NetBSD
35 * Foundation, Inc. and its contributors.
36 * 4. Neither the name of The NetBSD Foundation nor the names of its
37 * contributors may be used to endorse or promote products derived
38 * from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
41 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
42 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
44 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50 * POSSIBILITY OF SUCH DAMAGE.
51 */
52
53/*
54 * Handspring Visor (Palmpilot compatible PDA) driver
55 */
56
57#include "usbdevs.h"
58#include <dev/usb/usb.h>
59#include <dev/usb/usb_mfunc.h>
60#include <dev/usb/usb_error.h>
61#include <dev/usb/usb_cdc.h>
62#include <dev/usb/usb_ioctl.h>
63
64#define USB_DEBUG_VAR uvisor_debug
65
66#include <dev/usb/usb_core.h>
67#include <dev/usb/usb_debug.h>
68#include <dev/usb/usb_process.h>
69#include <dev/usb/usb_request.h>
70#include <dev/usb/usb_lookup.h>
71#include <dev/usb/usb_util.h>
72#include <dev/usb/usb_busdma.h>
73
74#include <dev/usb/serial/usb_serial.h>
75
76#if USB_DEBUG
77static int uvisor_debug = 0;
78
79SYSCTL_NODE(_hw_usb2, OID_AUTO, uvisor, CTLFLAG_RW, 0, "USB uvisor");
80SYSCTL_INT(_hw_usb2_uvisor, OID_AUTO, debug, CTLFLAG_RW,
79SYSCTL_NODE(_hw_usb, OID_AUTO, uvisor, CTLFLAG_RW, 0, "USB uvisor");
80SYSCTL_INT(_hw_usb_uvisor, OID_AUTO, debug, CTLFLAG_RW,
81 &uvisor_debug, 0, "Debug level");
82#endif
83
84#define UVISOR_CONFIG_INDEX 0
85#define UVISOR_IFACE_INDEX 0
86#define UVISOR_BUFSIZE 1024 /* bytes */
87
88/* From the Linux driver */
89/*
90 * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that
91 * are available to be transfered to the host for the specified endpoint.
92 * Currently this is not used, and always returns 0x0001
93 */
94#define UVISOR_REQUEST_BYTES_AVAILABLE 0x01
95
96/*
97 * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host
98 * is now closing the pipe. An empty packet is sent in response.
99 */
100#define UVISOR_CLOSE_NOTIFICATION 0x02
101
102/*
103 * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to
104 * get the endpoints used by the connection.
105 */
106#define UVISOR_GET_CONNECTION_INFORMATION 0x03
107
108/*
109 * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format
110 */
111#define UVISOR_MAX_CONN 8
112struct uvisor_connection_info {
113 uWord num_ports;
114 struct {
115 uByte port_function_id;
116 uByte port;
117 } __packed connections[UVISOR_MAX_CONN];
118} __packed;
119
120#define UVISOR_CONNECTION_INFO_SIZE 18
121
122/* struct uvisor_connection_info.connection[x].port defines: */
123#define UVISOR_ENDPOINT_1 0x01
124#define UVISOR_ENDPOINT_2 0x02
125
126/* struct uvisor_connection_info.connection[x].port_function_id defines: */
127#define UVISOR_FUNCTION_GENERIC 0x00
128#define UVISOR_FUNCTION_DEBUGGER 0x01
129#define UVISOR_FUNCTION_HOTSYNC 0x02
130#define UVISOR_FUNCTION_CONSOLE 0x03
131#define UVISOR_FUNCTION_REMOTE_FILE_SYS 0x04
132
133/*
134 * Unknown PalmOS stuff.
135 */
136#define UVISOR_GET_PALM_INFORMATION 0x04
137#define UVISOR_GET_PALM_INFORMATION_LEN 0x44
138
139struct uvisor_palm_connection_info {
140 uByte num_ports;
141 uByte endpoint_numbers_different;
142 uWord reserved1;
143 struct {
144 uDWord port_function_id;
145 uByte port;
146 uByte end_point_info;
147 uWord reserved;
148 } __packed connections[UVISOR_MAX_CONN];
149} __packed;
150
151enum {
152 UVISOR_BULK_DT_WR,
153 UVISOR_BULK_DT_RD,
154 UVISOR_N_TRANSFER,
155};
156
157struct uvisor_softc {
158 struct usb2_com_super_softc sc_super_ucom;
159 struct usb2_com_softc sc_ucom;
160
161 struct usb2_xfer *sc_xfer[UVISOR_N_TRANSFER];
162 struct usb2_device *sc_udev;
163 struct mtx sc_mtx;
164
165 uint16_t sc_flag;
166#define UVISOR_FLAG_PALM4 0x0001
167#define UVISOR_FLAG_VISOR 0x0002
168#define UVISOR_FLAG_PALM35 0x0004
169#define UVISOR_FLAG_SEND_NOTIFY 0x0008
170
171 uint8_t sc_iface_no;
172 uint8_t sc_iface_index;
173};
174
175/* prototypes */
176
177static device_probe_t uvisor_probe;
178static device_attach_t uvisor_attach;
179static device_detach_t uvisor_detach;
180
181static usb2_callback_t uvisor_write_callback;
182static usb2_callback_t uvisor_read_callback;
183
184static usb2_error_t uvisor_init(struct uvisor_softc *, struct usb2_device *,
185 struct usb2_config *);
186static void uvisor_cfg_open(struct usb2_com_softc *);
187static void uvisor_cfg_close(struct usb2_com_softc *);
188static void uvisor_start_read(struct usb2_com_softc *);
189static void uvisor_stop_read(struct usb2_com_softc *);
190static void uvisor_start_write(struct usb2_com_softc *);
191static void uvisor_stop_write(struct usb2_com_softc *);
192
193static const struct usb2_config uvisor_config[UVISOR_N_TRANSFER] = {
194
195 [UVISOR_BULK_DT_WR] = {
196 .type = UE_BULK,
197 .endpoint = UE_ADDR_ANY,
198 .direction = UE_DIR_OUT,
199 .bufsize = UVISOR_BUFSIZE, /* bytes */
200 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
201 .callback = &uvisor_write_callback,
202 },
203
204 [UVISOR_BULK_DT_RD] = {
205 .type = UE_BULK,
206 .endpoint = UE_ADDR_ANY,
207 .direction = UE_DIR_IN,
208 .bufsize = UVISOR_BUFSIZE, /* bytes */
209 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
210 .callback = &uvisor_read_callback,
211 },
212};
213
214static const struct usb2_com_callback uvisor_callback = {
215 .usb2_com_cfg_open = &uvisor_cfg_open,
216 .usb2_com_cfg_close = &uvisor_cfg_close,
217 .usb2_com_start_read = &uvisor_start_read,
218 .usb2_com_stop_read = &uvisor_stop_read,
219 .usb2_com_start_write = &uvisor_start_write,
220 .usb2_com_stop_write = &uvisor_stop_write,
221};
222
223static device_method_t uvisor_methods[] = {
224 DEVMETHOD(device_probe, uvisor_probe),
225 DEVMETHOD(device_attach, uvisor_attach),
226 DEVMETHOD(device_detach, uvisor_detach),
227 {0, 0}
228};
229
230static devclass_t uvisor_devclass;
231
232static driver_t uvisor_driver = {
233 .name = "uvisor",
234 .methods = uvisor_methods,
235 .size = sizeof(struct uvisor_softc),
236};
237
238DRIVER_MODULE(uvisor, uhub, uvisor_driver, uvisor_devclass, NULL, 0);
239MODULE_DEPEND(uvisor, ucom, 1, 1, 1);
240MODULE_DEPEND(uvisor, usb, 1, 1, 1);
241
242static const struct usb2_device_id uvisor_devs[] = {
243 {USB_VPI(USB_VENDOR_ACEECA, USB_PRODUCT_ACEECA_MEZ1000, UVISOR_FLAG_PALM4)},
244 {USB_VPI(USB_VENDOR_GARMIN, USB_PRODUCT_GARMIN_IQUE_3600, UVISOR_FLAG_PALM4)},
245 {USB_VPI(USB_VENDOR_FOSSIL, USB_PRODUCT_FOSSIL_WRISTPDA, UVISOR_FLAG_PALM4)},
246 {USB_VPI(USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR, UVISOR_FLAG_VISOR)},
247 {USB_VPI(USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO, UVISOR_FLAG_PALM4)},
248 {USB_VPI(USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO600, UVISOR_FLAG_PALM4)},
249 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M500, UVISOR_FLAG_PALM4)},
250 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M505, UVISOR_FLAG_PALM4)},
251 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M515, UVISOR_FLAG_PALM4)},
252 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_I705, UVISOR_FLAG_PALM4)},
253 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M125, UVISOR_FLAG_PALM4)},
254 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M130, UVISOR_FLAG_PALM4)},
255 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_Z, UVISOR_FLAG_PALM4)},
256 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_T, UVISOR_FLAG_PALM4)},
257 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE, UVISOR_FLAG_PALM4)},
258 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE31, UVISOR_FLAG_PALM4)},
259 {USB_VPI(USB_VENDOR_SAMSUNG, USB_PRODUCT_SAMSUNG_I500, UVISOR_FLAG_PALM4)},
260 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40, 0)},
261 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41, UVISOR_FLAG_PALM4)},
262 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_S360, UVISOR_FLAG_PALM4)},
263 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_NX60, UVISOR_FLAG_PALM4)},
264 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_35, UVISOR_FLAG_PALM35)},
265/* {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25, UVISOR_FLAG_PALM4 )}, */
266 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TJ37, UVISOR_FLAG_PALM4)},
267/* {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TH55, UVISOR_FLAG_PALM4 )}, See PR 80935 */
268 {USB_VPI(USB_VENDOR_TAPWAVE, USB_PRODUCT_TAPWAVE_ZODIAC, UVISOR_FLAG_PALM4)},
269};
270
271static int
272uvisor_probe(device_t dev)
273{
274 struct usb2_attach_arg *uaa = device_get_ivars(dev);
275
276 if (uaa->usb_mode != USB_MODE_HOST) {
277 return (ENXIO);
278 }
279 if (uaa->info.bConfigIndex != UVISOR_CONFIG_INDEX) {
280 return (ENXIO);
281 }
282 if (uaa->info.bIfaceIndex != UVISOR_IFACE_INDEX) {
283 return (ENXIO);
284 }
285 return (usb2_lookup_id_by_uaa(uvisor_devs, sizeof(uvisor_devs), uaa));
286}
287
288static int
289uvisor_attach(device_t dev)
290{
291 struct usb2_attach_arg *uaa = device_get_ivars(dev);
292 struct uvisor_softc *sc = device_get_softc(dev);
293 struct usb2_config uvisor_config_copy[UVISOR_N_TRANSFER];
294 int error;
295
296 DPRINTF("sc=%p\n", sc);
297 bcopy(uvisor_config, uvisor_config_copy,
298 sizeof(uvisor_config_copy));
299 device_set_usb2_desc(dev);
300
301 mtx_init(&sc->sc_mtx, "uvisor", NULL, MTX_DEF);
302
303 sc->sc_udev = uaa->device;
304
305 /* configure the device */
306
307 sc->sc_flag = USB_GET_DRIVER_INFO(uaa);
308 sc->sc_iface_no = uaa->info.bIfaceNum;
309 sc->sc_iface_index = UVISOR_IFACE_INDEX;
310
311 error = uvisor_init(sc, uaa->device, uvisor_config_copy);
312
313 if (error) {
314 DPRINTF("init failed, error=%s\n",
315 usb2_errstr(error));
316 goto detach;
317 }
318 error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index,
319 sc->sc_xfer, uvisor_config_copy, UVISOR_N_TRANSFER,
320 sc, &sc->sc_mtx);
321 if (error) {
322 DPRINTF("could not allocate all pipes\n");
323 goto detach;
324 }
325 /* clear stall at first run */
326 mtx_lock(&sc->sc_mtx);
327 usb2_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_WR]);
328 usb2_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_RD]);
329 mtx_unlock(&sc->sc_mtx);
330
331 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
332 &uvisor_callback, &sc->sc_mtx);
333 if (error) {
334 DPRINTF("usb2_com_attach failed\n");
335 goto detach;
336 }
337 return (0);
338
339detach:
340 uvisor_detach(dev);
341 return (ENXIO);
342}
343
344static int
345uvisor_detach(device_t dev)
346{
347 struct uvisor_softc *sc = device_get_softc(dev);
348
349 DPRINTF("sc=%p\n", sc);
350
351 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1);
352 usb2_transfer_unsetup(sc->sc_xfer, UVISOR_N_TRANSFER);
353 mtx_destroy(&sc->sc_mtx);
354
355 return (0);
356}
357
358static usb2_error_t
359uvisor_init(struct uvisor_softc *sc, struct usb2_device *udev, struct usb2_config *config)
360{
361 usb2_error_t err = 0;
362 struct usb2_device_request req;
363 struct uvisor_connection_info coninfo;
364 struct uvisor_palm_connection_info pconinfo;
365 uint16_t actlen;
366 uWord wAvail;
367 uint8_t buffer[256];
368
369 if (sc->sc_flag & UVISOR_FLAG_VISOR) {
370 DPRINTF("getting connection info\n");
371 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
372 req.bRequest = UVISOR_GET_CONNECTION_INFORMATION;
373 USETW(req.wValue, 0);
374 USETW(req.wIndex, 0);
375 USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
376 err = usb2_do_request_flags(udev, NULL,
377 &req, &coninfo, USB_SHORT_XFER_OK,
378 &actlen, USB_DEFAULT_TIMEOUT);
379
380 if (err) {
381 goto done;
382 }
383 }
384#if USB_DEBUG
385 if (sc->sc_flag & UVISOR_FLAG_VISOR) {
386 uint16_t i, np;
387 const char *desc;
388
389 np = UGETW(coninfo.num_ports);
390 if (np > UVISOR_MAX_CONN) {
391 np = UVISOR_MAX_CONN;
392 }
393 DPRINTF("Number of ports: %d\n", np);
394
395 for (i = 0; i < np; ++i) {
396 switch (coninfo.connections[i].port_function_id) {
397 case UVISOR_FUNCTION_GENERIC:
398 desc = "Generic";
399 break;
400 case UVISOR_FUNCTION_DEBUGGER:
401 desc = "Debugger";
402 break;
403 case UVISOR_FUNCTION_HOTSYNC:
404 desc = "HotSync";
405 break;
406 case UVISOR_FUNCTION_REMOTE_FILE_SYS:
407 desc = "Remote File System";
408 break;
409 default:
410 desc = "unknown";
411 break;
412 }
413 DPRINTF("Port %d is for %s\n",
414 coninfo.connections[i].port, desc);
415 }
416 }
417#endif
418
419 if (sc->sc_flag & UVISOR_FLAG_PALM4) {
420 uint8_t port;
421
422 /* Palm OS 4.0 Hack */
423 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
424 req.bRequest = UVISOR_GET_PALM_INFORMATION;
425 USETW(req.wValue, 0);
426 USETW(req.wIndex, 0);
427 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
428
429 err = usb2_do_request_flags
430 (udev, NULL, &req, &pconinfo, USB_SHORT_XFER_OK,
431 &actlen, USB_DEFAULT_TIMEOUT);
432
433 if (err) {
434 goto done;
435 }
436 if (actlen < 12) {
437 DPRINTF("too little data\n");
438 err = USB_ERR_INVAL;
439 goto done;
440 }
441 if (pconinfo.endpoint_numbers_different) {
442 port = pconinfo.connections[0].end_point_info;
443 config[0].endpoint = (port & 0xF); /* output */
444 config[1].endpoint = (port >> 4); /* input */
445 } else {
446 port = pconinfo.connections[0].port;
447 config[0].endpoint = (port & 0xF); /* output */
448 config[1].endpoint = (port & 0xF); /* input */
449 }
450#if 0
451 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
452 req.bRequest = UVISOR_GET_PALM_INFORMATION;
453 USETW(req.wValue, 0);
454 USETW(req.wIndex, 0);
455 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
456 err = usb2_do_request(udev, &req, buffer);
457 if (err) {
458 goto done;
459 }
460#endif
461 }
462 if (sc->sc_flag & UVISOR_FLAG_PALM35) {
463 /* get the config number */
464 DPRINTF("getting config info\n");
465 req.bmRequestType = UT_READ;
466 req.bRequest = UR_GET_CONFIG;
467 USETW(req.wValue, 0);
468 USETW(req.wIndex, 0);
469 USETW(req.wLength, 1);
470
471 err = usb2_do_request(udev, NULL, &req, buffer);
472 if (err) {
473 goto done;
474 }
475 /* get the interface number */
476 DPRINTF("get the interface number\n");
477 req.bmRequestType = UT_READ_DEVICE;
478 req.bRequest = UR_GET_INTERFACE;
479 USETW(req.wValue, 0);
480 USETW(req.wIndex, 0);
481 USETW(req.wLength, 1);
482 err = usb2_do_request(udev, NULL, &req, buffer);
483 if (err) {
484 goto done;
485 }
486 }
487 DPRINTF("getting available bytes\n");
488 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
489 req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE;
490 USETW(req.wValue, 0);
491 USETW(req.wIndex, 5);
492 USETW(req.wLength, sizeof(wAvail));
493 err = usb2_do_request(udev, NULL, &req, &wAvail);
494 if (err) {
495 goto done;
496 }
497 DPRINTF("avail=%d\n", UGETW(wAvail));
498
499 DPRINTF("done\n");
500done:
501 return (err);
502}
503
504static void
505uvisor_cfg_open(struct usb2_com_softc *ucom)
506{
507 return;
508}
509
510static void
511uvisor_cfg_close(struct usb2_com_softc *ucom)
512{
513 struct uvisor_softc *sc = ucom->sc_parent;
514 uint8_t buffer[UVISOR_CONNECTION_INFO_SIZE];
515 struct usb2_device_request req;
516 usb2_error_t err;
517
518 req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
519 req.bRequest = UVISOR_CLOSE_NOTIFICATION;
520 USETW(req.wValue, 0);
521 USETW(req.wIndex, 0);
522 USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
523
524 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
525 &req, buffer, 0, 1000);
526 if (err) {
527 DPRINTFN(0, "close notification failed, error=%s\n",
528 usb2_errstr(err));
529 }
530}
531
532static void
533uvisor_start_read(struct usb2_com_softc *ucom)
534{
535 struct uvisor_softc *sc = ucom->sc_parent;
536
537 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_RD]);
538}
539
540static void
541uvisor_stop_read(struct usb2_com_softc *ucom)
542{
543 struct uvisor_softc *sc = ucom->sc_parent;
544
545 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_RD]);
546}
547
548static void
549uvisor_start_write(struct usb2_com_softc *ucom)
550{
551 struct uvisor_softc *sc = ucom->sc_parent;
552
553 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_WR]);
554}
555
556static void
557uvisor_stop_write(struct usb2_com_softc *ucom)
558{
559 struct uvisor_softc *sc = ucom->sc_parent;
560
561 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_WR]);
562}
563
564static void
565uvisor_write_callback(struct usb2_xfer *xfer)
566{
567 struct uvisor_softc *sc = xfer->priv_sc;
568 uint32_t actlen;
569
570 switch (USB_GET_STATE(xfer)) {
571 case USB_ST_SETUP:
572 case USB_ST_TRANSFERRED:
573tr_setup:
574 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
575 UVISOR_BUFSIZE, &actlen)) {
576
577 xfer->frlengths[0] = actlen;
578 usb2_start_hardware(xfer);
579 }
580 return;
581
582 default: /* Error */
583 if (xfer->error != USB_ERR_CANCELLED) {
584 /* try to clear stall first */
585 xfer->flags.stall_pipe = 1;
586 goto tr_setup;
587 }
588 return;
589 }
590}
591
592static void
593uvisor_read_callback(struct usb2_xfer *xfer)
594{
595 struct uvisor_softc *sc = xfer->priv_sc;
596
597 switch (USB_GET_STATE(xfer)) {
598 case USB_ST_TRANSFERRED:
599 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
600
601 case USB_ST_SETUP:
602tr_setup:
603 xfer->frlengths[0] = xfer->max_data_length;
604 usb2_start_hardware(xfer);
605 return;
606
607 default: /* Error */
608 if (xfer->error != USB_ERR_CANCELLED) {
609 /* try to clear stall first */
610 xfer->flags.stall_pipe = 1;
611 goto tr_setup;
612 }
613 return;
614 }
615}
81 &uvisor_debug, 0, "Debug level");
82#endif
83
84#define UVISOR_CONFIG_INDEX 0
85#define UVISOR_IFACE_INDEX 0
86#define UVISOR_BUFSIZE 1024 /* bytes */
87
88/* From the Linux driver */
89/*
90 * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that
91 * are available to be transfered to the host for the specified endpoint.
92 * Currently this is not used, and always returns 0x0001
93 */
94#define UVISOR_REQUEST_BYTES_AVAILABLE 0x01
95
96/*
97 * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host
98 * is now closing the pipe. An empty packet is sent in response.
99 */
100#define UVISOR_CLOSE_NOTIFICATION 0x02
101
102/*
103 * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to
104 * get the endpoints used by the connection.
105 */
106#define UVISOR_GET_CONNECTION_INFORMATION 0x03
107
108/*
109 * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format
110 */
111#define UVISOR_MAX_CONN 8
112struct uvisor_connection_info {
113 uWord num_ports;
114 struct {
115 uByte port_function_id;
116 uByte port;
117 } __packed connections[UVISOR_MAX_CONN];
118} __packed;
119
120#define UVISOR_CONNECTION_INFO_SIZE 18
121
122/* struct uvisor_connection_info.connection[x].port defines: */
123#define UVISOR_ENDPOINT_1 0x01
124#define UVISOR_ENDPOINT_2 0x02
125
126/* struct uvisor_connection_info.connection[x].port_function_id defines: */
127#define UVISOR_FUNCTION_GENERIC 0x00
128#define UVISOR_FUNCTION_DEBUGGER 0x01
129#define UVISOR_FUNCTION_HOTSYNC 0x02
130#define UVISOR_FUNCTION_CONSOLE 0x03
131#define UVISOR_FUNCTION_REMOTE_FILE_SYS 0x04
132
133/*
134 * Unknown PalmOS stuff.
135 */
136#define UVISOR_GET_PALM_INFORMATION 0x04
137#define UVISOR_GET_PALM_INFORMATION_LEN 0x44
138
139struct uvisor_palm_connection_info {
140 uByte num_ports;
141 uByte endpoint_numbers_different;
142 uWord reserved1;
143 struct {
144 uDWord port_function_id;
145 uByte port;
146 uByte end_point_info;
147 uWord reserved;
148 } __packed connections[UVISOR_MAX_CONN];
149} __packed;
150
151enum {
152 UVISOR_BULK_DT_WR,
153 UVISOR_BULK_DT_RD,
154 UVISOR_N_TRANSFER,
155};
156
157struct uvisor_softc {
158 struct usb2_com_super_softc sc_super_ucom;
159 struct usb2_com_softc sc_ucom;
160
161 struct usb2_xfer *sc_xfer[UVISOR_N_TRANSFER];
162 struct usb2_device *sc_udev;
163 struct mtx sc_mtx;
164
165 uint16_t sc_flag;
166#define UVISOR_FLAG_PALM4 0x0001
167#define UVISOR_FLAG_VISOR 0x0002
168#define UVISOR_FLAG_PALM35 0x0004
169#define UVISOR_FLAG_SEND_NOTIFY 0x0008
170
171 uint8_t sc_iface_no;
172 uint8_t sc_iface_index;
173};
174
175/* prototypes */
176
177static device_probe_t uvisor_probe;
178static device_attach_t uvisor_attach;
179static device_detach_t uvisor_detach;
180
181static usb2_callback_t uvisor_write_callback;
182static usb2_callback_t uvisor_read_callback;
183
184static usb2_error_t uvisor_init(struct uvisor_softc *, struct usb2_device *,
185 struct usb2_config *);
186static void uvisor_cfg_open(struct usb2_com_softc *);
187static void uvisor_cfg_close(struct usb2_com_softc *);
188static void uvisor_start_read(struct usb2_com_softc *);
189static void uvisor_stop_read(struct usb2_com_softc *);
190static void uvisor_start_write(struct usb2_com_softc *);
191static void uvisor_stop_write(struct usb2_com_softc *);
192
193static const struct usb2_config uvisor_config[UVISOR_N_TRANSFER] = {
194
195 [UVISOR_BULK_DT_WR] = {
196 .type = UE_BULK,
197 .endpoint = UE_ADDR_ANY,
198 .direction = UE_DIR_OUT,
199 .bufsize = UVISOR_BUFSIZE, /* bytes */
200 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
201 .callback = &uvisor_write_callback,
202 },
203
204 [UVISOR_BULK_DT_RD] = {
205 .type = UE_BULK,
206 .endpoint = UE_ADDR_ANY,
207 .direction = UE_DIR_IN,
208 .bufsize = UVISOR_BUFSIZE, /* bytes */
209 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
210 .callback = &uvisor_read_callback,
211 },
212};
213
214static const struct usb2_com_callback uvisor_callback = {
215 .usb2_com_cfg_open = &uvisor_cfg_open,
216 .usb2_com_cfg_close = &uvisor_cfg_close,
217 .usb2_com_start_read = &uvisor_start_read,
218 .usb2_com_stop_read = &uvisor_stop_read,
219 .usb2_com_start_write = &uvisor_start_write,
220 .usb2_com_stop_write = &uvisor_stop_write,
221};
222
223static device_method_t uvisor_methods[] = {
224 DEVMETHOD(device_probe, uvisor_probe),
225 DEVMETHOD(device_attach, uvisor_attach),
226 DEVMETHOD(device_detach, uvisor_detach),
227 {0, 0}
228};
229
230static devclass_t uvisor_devclass;
231
232static driver_t uvisor_driver = {
233 .name = "uvisor",
234 .methods = uvisor_methods,
235 .size = sizeof(struct uvisor_softc),
236};
237
238DRIVER_MODULE(uvisor, uhub, uvisor_driver, uvisor_devclass, NULL, 0);
239MODULE_DEPEND(uvisor, ucom, 1, 1, 1);
240MODULE_DEPEND(uvisor, usb, 1, 1, 1);
241
242static const struct usb2_device_id uvisor_devs[] = {
243 {USB_VPI(USB_VENDOR_ACEECA, USB_PRODUCT_ACEECA_MEZ1000, UVISOR_FLAG_PALM4)},
244 {USB_VPI(USB_VENDOR_GARMIN, USB_PRODUCT_GARMIN_IQUE_3600, UVISOR_FLAG_PALM4)},
245 {USB_VPI(USB_VENDOR_FOSSIL, USB_PRODUCT_FOSSIL_WRISTPDA, UVISOR_FLAG_PALM4)},
246 {USB_VPI(USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR, UVISOR_FLAG_VISOR)},
247 {USB_VPI(USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO, UVISOR_FLAG_PALM4)},
248 {USB_VPI(USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO600, UVISOR_FLAG_PALM4)},
249 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M500, UVISOR_FLAG_PALM4)},
250 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M505, UVISOR_FLAG_PALM4)},
251 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M515, UVISOR_FLAG_PALM4)},
252 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_I705, UVISOR_FLAG_PALM4)},
253 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M125, UVISOR_FLAG_PALM4)},
254 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_M130, UVISOR_FLAG_PALM4)},
255 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_Z, UVISOR_FLAG_PALM4)},
256 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_T, UVISOR_FLAG_PALM4)},
257 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE, UVISOR_FLAG_PALM4)},
258 {USB_VPI(USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE31, UVISOR_FLAG_PALM4)},
259 {USB_VPI(USB_VENDOR_SAMSUNG, USB_PRODUCT_SAMSUNG_I500, UVISOR_FLAG_PALM4)},
260 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40, 0)},
261 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41, UVISOR_FLAG_PALM4)},
262 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_S360, UVISOR_FLAG_PALM4)},
263 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_NX60, UVISOR_FLAG_PALM4)},
264 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_35, UVISOR_FLAG_PALM35)},
265/* {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25, UVISOR_FLAG_PALM4 )}, */
266 {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TJ37, UVISOR_FLAG_PALM4)},
267/* {USB_VPI(USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TH55, UVISOR_FLAG_PALM4 )}, See PR 80935 */
268 {USB_VPI(USB_VENDOR_TAPWAVE, USB_PRODUCT_TAPWAVE_ZODIAC, UVISOR_FLAG_PALM4)},
269};
270
271static int
272uvisor_probe(device_t dev)
273{
274 struct usb2_attach_arg *uaa = device_get_ivars(dev);
275
276 if (uaa->usb_mode != USB_MODE_HOST) {
277 return (ENXIO);
278 }
279 if (uaa->info.bConfigIndex != UVISOR_CONFIG_INDEX) {
280 return (ENXIO);
281 }
282 if (uaa->info.bIfaceIndex != UVISOR_IFACE_INDEX) {
283 return (ENXIO);
284 }
285 return (usb2_lookup_id_by_uaa(uvisor_devs, sizeof(uvisor_devs), uaa));
286}
287
288static int
289uvisor_attach(device_t dev)
290{
291 struct usb2_attach_arg *uaa = device_get_ivars(dev);
292 struct uvisor_softc *sc = device_get_softc(dev);
293 struct usb2_config uvisor_config_copy[UVISOR_N_TRANSFER];
294 int error;
295
296 DPRINTF("sc=%p\n", sc);
297 bcopy(uvisor_config, uvisor_config_copy,
298 sizeof(uvisor_config_copy));
299 device_set_usb2_desc(dev);
300
301 mtx_init(&sc->sc_mtx, "uvisor", NULL, MTX_DEF);
302
303 sc->sc_udev = uaa->device;
304
305 /* configure the device */
306
307 sc->sc_flag = USB_GET_DRIVER_INFO(uaa);
308 sc->sc_iface_no = uaa->info.bIfaceNum;
309 sc->sc_iface_index = UVISOR_IFACE_INDEX;
310
311 error = uvisor_init(sc, uaa->device, uvisor_config_copy);
312
313 if (error) {
314 DPRINTF("init failed, error=%s\n",
315 usb2_errstr(error));
316 goto detach;
317 }
318 error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index,
319 sc->sc_xfer, uvisor_config_copy, UVISOR_N_TRANSFER,
320 sc, &sc->sc_mtx);
321 if (error) {
322 DPRINTF("could not allocate all pipes\n");
323 goto detach;
324 }
325 /* clear stall at first run */
326 mtx_lock(&sc->sc_mtx);
327 usb2_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_WR]);
328 usb2_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_RD]);
329 mtx_unlock(&sc->sc_mtx);
330
331 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
332 &uvisor_callback, &sc->sc_mtx);
333 if (error) {
334 DPRINTF("usb2_com_attach failed\n");
335 goto detach;
336 }
337 return (0);
338
339detach:
340 uvisor_detach(dev);
341 return (ENXIO);
342}
343
344static int
345uvisor_detach(device_t dev)
346{
347 struct uvisor_softc *sc = device_get_softc(dev);
348
349 DPRINTF("sc=%p\n", sc);
350
351 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1);
352 usb2_transfer_unsetup(sc->sc_xfer, UVISOR_N_TRANSFER);
353 mtx_destroy(&sc->sc_mtx);
354
355 return (0);
356}
357
358static usb2_error_t
359uvisor_init(struct uvisor_softc *sc, struct usb2_device *udev, struct usb2_config *config)
360{
361 usb2_error_t err = 0;
362 struct usb2_device_request req;
363 struct uvisor_connection_info coninfo;
364 struct uvisor_palm_connection_info pconinfo;
365 uint16_t actlen;
366 uWord wAvail;
367 uint8_t buffer[256];
368
369 if (sc->sc_flag & UVISOR_FLAG_VISOR) {
370 DPRINTF("getting connection info\n");
371 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
372 req.bRequest = UVISOR_GET_CONNECTION_INFORMATION;
373 USETW(req.wValue, 0);
374 USETW(req.wIndex, 0);
375 USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
376 err = usb2_do_request_flags(udev, NULL,
377 &req, &coninfo, USB_SHORT_XFER_OK,
378 &actlen, USB_DEFAULT_TIMEOUT);
379
380 if (err) {
381 goto done;
382 }
383 }
384#if USB_DEBUG
385 if (sc->sc_flag & UVISOR_FLAG_VISOR) {
386 uint16_t i, np;
387 const char *desc;
388
389 np = UGETW(coninfo.num_ports);
390 if (np > UVISOR_MAX_CONN) {
391 np = UVISOR_MAX_CONN;
392 }
393 DPRINTF("Number of ports: %d\n", np);
394
395 for (i = 0; i < np; ++i) {
396 switch (coninfo.connections[i].port_function_id) {
397 case UVISOR_FUNCTION_GENERIC:
398 desc = "Generic";
399 break;
400 case UVISOR_FUNCTION_DEBUGGER:
401 desc = "Debugger";
402 break;
403 case UVISOR_FUNCTION_HOTSYNC:
404 desc = "HotSync";
405 break;
406 case UVISOR_FUNCTION_REMOTE_FILE_SYS:
407 desc = "Remote File System";
408 break;
409 default:
410 desc = "unknown";
411 break;
412 }
413 DPRINTF("Port %d is for %s\n",
414 coninfo.connections[i].port, desc);
415 }
416 }
417#endif
418
419 if (sc->sc_flag & UVISOR_FLAG_PALM4) {
420 uint8_t port;
421
422 /* Palm OS 4.0 Hack */
423 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
424 req.bRequest = UVISOR_GET_PALM_INFORMATION;
425 USETW(req.wValue, 0);
426 USETW(req.wIndex, 0);
427 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
428
429 err = usb2_do_request_flags
430 (udev, NULL, &req, &pconinfo, USB_SHORT_XFER_OK,
431 &actlen, USB_DEFAULT_TIMEOUT);
432
433 if (err) {
434 goto done;
435 }
436 if (actlen < 12) {
437 DPRINTF("too little data\n");
438 err = USB_ERR_INVAL;
439 goto done;
440 }
441 if (pconinfo.endpoint_numbers_different) {
442 port = pconinfo.connections[0].end_point_info;
443 config[0].endpoint = (port & 0xF); /* output */
444 config[1].endpoint = (port >> 4); /* input */
445 } else {
446 port = pconinfo.connections[0].port;
447 config[0].endpoint = (port & 0xF); /* output */
448 config[1].endpoint = (port & 0xF); /* input */
449 }
450#if 0
451 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
452 req.bRequest = UVISOR_GET_PALM_INFORMATION;
453 USETW(req.wValue, 0);
454 USETW(req.wIndex, 0);
455 USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN);
456 err = usb2_do_request(udev, &req, buffer);
457 if (err) {
458 goto done;
459 }
460#endif
461 }
462 if (sc->sc_flag & UVISOR_FLAG_PALM35) {
463 /* get the config number */
464 DPRINTF("getting config info\n");
465 req.bmRequestType = UT_READ;
466 req.bRequest = UR_GET_CONFIG;
467 USETW(req.wValue, 0);
468 USETW(req.wIndex, 0);
469 USETW(req.wLength, 1);
470
471 err = usb2_do_request(udev, NULL, &req, buffer);
472 if (err) {
473 goto done;
474 }
475 /* get the interface number */
476 DPRINTF("get the interface number\n");
477 req.bmRequestType = UT_READ_DEVICE;
478 req.bRequest = UR_GET_INTERFACE;
479 USETW(req.wValue, 0);
480 USETW(req.wIndex, 0);
481 USETW(req.wLength, 1);
482 err = usb2_do_request(udev, NULL, &req, buffer);
483 if (err) {
484 goto done;
485 }
486 }
487 DPRINTF("getting available bytes\n");
488 req.bmRequestType = UT_READ_VENDOR_ENDPOINT;
489 req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE;
490 USETW(req.wValue, 0);
491 USETW(req.wIndex, 5);
492 USETW(req.wLength, sizeof(wAvail));
493 err = usb2_do_request(udev, NULL, &req, &wAvail);
494 if (err) {
495 goto done;
496 }
497 DPRINTF("avail=%d\n", UGETW(wAvail));
498
499 DPRINTF("done\n");
500done:
501 return (err);
502}
503
504static void
505uvisor_cfg_open(struct usb2_com_softc *ucom)
506{
507 return;
508}
509
510static void
511uvisor_cfg_close(struct usb2_com_softc *ucom)
512{
513 struct uvisor_softc *sc = ucom->sc_parent;
514 uint8_t buffer[UVISOR_CONNECTION_INFO_SIZE];
515 struct usb2_device_request req;
516 usb2_error_t err;
517
518 req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
519 req.bRequest = UVISOR_CLOSE_NOTIFICATION;
520 USETW(req.wValue, 0);
521 USETW(req.wIndex, 0);
522 USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
523
524 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
525 &req, buffer, 0, 1000);
526 if (err) {
527 DPRINTFN(0, "close notification failed, error=%s\n",
528 usb2_errstr(err));
529 }
530}
531
532static void
533uvisor_start_read(struct usb2_com_softc *ucom)
534{
535 struct uvisor_softc *sc = ucom->sc_parent;
536
537 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_RD]);
538}
539
540static void
541uvisor_stop_read(struct usb2_com_softc *ucom)
542{
543 struct uvisor_softc *sc = ucom->sc_parent;
544
545 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_RD]);
546}
547
548static void
549uvisor_start_write(struct usb2_com_softc *ucom)
550{
551 struct uvisor_softc *sc = ucom->sc_parent;
552
553 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_WR]);
554}
555
556static void
557uvisor_stop_write(struct usb2_com_softc *ucom)
558{
559 struct uvisor_softc *sc = ucom->sc_parent;
560
561 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_WR]);
562}
563
564static void
565uvisor_write_callback(struct usb2_xfer *xfer)
566{
567 struct uvisor_softc *sc = xfer->priv_sc;
568 uint32_t actlen;
569
570 switch (USB_GET_STATE(xfer)) {
571 case USB_ST_SETUP:
572 case USB_ST_TRANSFERRED:
573tr_setup:
574 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
575 UVISOR_BUFSIZE, &actlen)) {
576
577 xfer->frlengths[0] = actlen;
578 usb2_start_hardware(xfer);
579 }
580 return;
581
582 default: /* Error */
583 if (xfer->error != USB_ERR_CANCELLED) {
584 /* try to clear stall first */
585 xfer->flags.stall_pipe = 1;
586 goto tr_setup;
587 }
588 return;
589 }
590}
591
592static void
593uvisor_read_callback(struct usb2_xfer *xfer)
594{
595 struct uvisor_softc *sc = xfer->priv_sc;
596
597 switch (USB_GET_STATE(xfer)) {
598 case USB_ST_TRANSFERRED:
599 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
600
601 case USB_ST_SETUP:
602tr_setup:
603 xfer->frlengths[0] = xfer->max_data_length;
604 usb2_start_hardware(xfer);
605 return;
606
607 default: /* Error */
608 if (xfer->error != USB_ERR_CANCELLED) {
609 /* try to clear stall first */
610 xfer->flags.stall_pipe = 1;
611 goto tr_setup;
612 }
613 return;
614 }
615}