2 * $NetBSD: uftdi.c,v 1.13 2002/09/23 05:51:23 simonb Exp $
3 * $FreeBSD: src/sys/dev/usb/uftdi.c,v 1.37 2007/06/22 05:53:05 imp Exp $
4 * $DragonFly: src/sys/dev/usbmisc/uftdi/uftdi.c,v 1.22 2007/11/05 19:09:43 hasso Exp $
8 * Copyright (c) 2000 The NetBSD Foundation, Inc.
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Lennart Augustsson (lennart@augustsson.net).
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the NetBSD
25 * Foundation, Inc. and its contributors.
26 * 4. Neither the name of The NetBSD Foundation nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
44 * FTDI FT8U100AX serial adapter driver
47 #include <sys/cdefs.h>
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/malloc.h>
53 #include <sys/module.h>
55 #include <sys/ioccom.h>
56 #include <sys/fcntl.h>
61 #include <sys/select.h>
63 #include <sys/sysctl.h>
65 #include <bus/usb/usb.h>
66 #include <bus/usb/usbhid.h>
68 #include <bus/usb/usbdi.h>
69 #include <bus/usb/usbdi_util.h>
71 #include "../ucom/ucomvar.h"
76 static int uftdidebug = 0;
77 SYSCTL_NODE(_hw_usb, OID_AUTO, uftdi, CTLFLAG_RW, 0, "USB uftdi");
78 SYSCTL_INT(_hw_usb_uftdi, OID_AUTO, debug, CTLFLAG_RW,
79 &uftdidebug, 0, "uftdi debug level");
80 #define DPRINTF(x) do { \
85 #define DPRINTFN(n, x) do { \
86 if (uftdidebug > (n)) \
95 #define UFTDI_CONFIG_INDEX 0
96 #define UFTDI_IFACE_INDEX 0
99 * These are the maximum number of bytes transferred per frame.
100 * The output buffer size cannot be increased due to the size encoding.
102 #define UFTDIIBUFSIZE 64
103 #define UFTDIOBUFSIZE 64
106 struct ucom_softc sc_ucom;
107 usbd_interface_handle sc_iface; /* interface */
108 enum uftdi_type sc_type;
115 static void uftdi_get_status(void *, int portno, u_char *lsr, u_char *msr);
116 static void uftdi_set(void *, int, int, int);
117 static int uftdi_param(void *, int, struct termios *);
118 static int uftdi_open(void *sc, int portno);
119 static void uftdi_read(void *sc, int portno, u_char **ptr,u_int32_t *count);
120 static void uftdi_write(void *sc, int portno, u_char *to, u_char *from,
122 static void uftdi_break(void *sc, int portno, int onoff);
123 static int uftdi_8u232am_getrate(speed_t speed, int *rate);
125 struct ucom_callback uftdi_callback = {
136 static const struct usb_devno uftdi_devs[] = {
137 /* FTDI chips defaults */
138 { USB_DEVICE(0x0403, 0x0232) }, /* FT232 serial converter */
139 { USB_DEVICE(0x0403, 0x6001) }, /* FT232 serial converter */
140 { USB_DEVICE(0x0403, 0x6006) }, /* FT232 serial converter */
141 { USB_DEVICE(0x0403, 0x6007) }, /* FT232 serial converter */
142 { USB_DEVICE(0x0403, 0x6008) }, /* FT232 serial converter */
143 { USB_DEVICE(0x0403, 0x6009) }, /* FT232 serial converter */
144 { USB_DEVICE(0x0403, 0x6010) }, /* FT2232 dual port serial converter */
145 { USB_DEVICE(0x0403, 0x8372) }, /* FTDI 8U100AX USB hub controller */
147 /* RR-CirKits products */
148 { USB_DEVICE(0x0403, 0xc7d0) }, /* LocoBuffer USB */
150 /* DMX4ALL products */
151 { USB_DEVICE(0x0403, 0xc850) }, /* DMX interface */
154 { USB_DEVICE(0x0403, 0xc990) }, /* RDR 4X7 series card reader */
155 { USB_DEVICE(0x0403, 0xc991) }, /* RDR 4X7 series card reader */
156 { USB_DEVICE(0x0403, 0xc992) }, /* RDR 4X7 series card reader */
157 { USB_DEVICE(0x0403, 0xc993) }, /* RDR 4X7 series card reader */
158 { USB_DEVICE(0x0403, 0xc994) }, /* RDR 4X7 series card reader */
159 { USB_DEVICE(0x0403, 0xc995) }, /* RDR 4X7 series card reader */
160 { USB_DEVICE(0x0403, 0xc996) }, /* RDR 4X7 series card reader */
161 { USB_DEVICE(0x0403, 0xc997) }, /* RDR 4X7 series card reader */
164 { USB_DEVICE(0x0403, 0xca81) }, /* Sirius To PC Interface */
166 /* Starting Point Systems products */
167 { USB_DEVICE(0x0403, 0xcaa0) }, /* µChameleon */
169 /* Tactrix products */
170 { USB_DEVICE(0x0403, 0xcc48) }, /* OpenPort 1.3 Mitsubishi */
171 { USB_DEVICE(0x0403, 0xcc49) }, /* OpenPort 1.3 Subaru */
172 { USB_DEVICE(0x0403, 0xcc4a) }, /* OpenPort 1.3 Universal */
174 /* Plus GSM products */
175 { USB_DEVICE(0x0403, 0xd070) }, /* Plus GSM iPlus */
177 /* Xsens Technologies BV products */
178 { USB_DEVICE(0x0403, 0xd388) }, /* Serial interface */
179 { USB_DEVICE(0x0403, 0xd389) }, /* Serial interface */
180 { USB_DEVICE(0x0403, 0xd38a) }, /* Serial interface */
181 { USB_DEVICE(0x0403, 0xd38b) }, /* Serial interface */
182 { USB_DEVICE(0x0403, 0xd38c) }, /* Serial interface */
183 { USB_DEVICE(0x0403, 0xd38d) }, /* Serial interface */
184 { USB_DEVICE(0x0403, 0xd38e) }, /* Serial interface */
185 { USB_DEVICE(0x0403, 0xd38f) }, /* Serial interface */
187 /* Eurami Group products */
188 { USB_DEVICE(0x0403, 0xd678) }, /* Gamma Scout Online */
190 /* Westrex International products */
191 { USB_DEVICE(0x0403, 0xdc00) }, /* Model 777 */
192 { USB_DEVICE(0x0403, 0xdc01) }, /* Model 8900F */
194 /* ACG Identification GmbH products */
195 { USB_DEVICE(0x0403, 0xdd20) }, /* HF Dual ISO Reader (RFID) */
197 /* Artemis products */
198 { USB_DEVICE(0x0403, 0xdf28) }, /* CCD camera */
200 /* ATIK Instruments products */
201 { USB_DEVICE(0x0403, 0xdf30) }, /* ATK-16 Grayscale Camera */
202 { USB_DEVICE(0x0403, 0xdf31) }, /* ATK-16HR Grayscale Camera */
203 { USB_DEVICE(0x0403, 0xdf32) }, /* ATK-16C Colour Camera */
204 { USB_DEVICE(0x0403, 0xdf33) }, /* ATK-16HRC Colour Camera */
206 /* Yost Engineering, Inc. products */
207 { USB_DEVICE(0x0403, 0xe050) }, /* ServoCenter3.1 USB */
209 /* EVER Sp. products */
210 { USB_DEVICE(0x0403, 0xe520) }, /* Eco Pro UPS */
212 /* Active Robots products */
213 { USB_DEVICE(0x0403, 0xe548) }, /* Active Robots comms board */
215 /* Pyramid Computer GmbH products */
216 { USB_DEVICE(0x0403, 0xe6c8) }, /* Pyramid Appliance Display */
218 /* Gude Analog- und Digitalsysteme GmbH products */
219 { USB_DEVICE(0x0403, 0xe808) }, /* USB to serial */
220 { USB_DEVICE(0x0403, 0xe809) }, /* USB to serial */
221 { USB_DEVICE(0x0403, 0xe80a) }, /* USB to serial */
222 { USB_DEVICE(0x0403, 0xe80b) }, /* USB to serial */
223 { USB_DEVICE(0x0403, 0xe80c) }, /* USB to serial */
224 { USB_DEVICE(0x0403, 0xe80d) }, /* USB to serial */
225 { USB_DEVICE(0x0403, 0xe80e) }, /* USB to serial */
226 { USB_DEVICE(0x0403, 0xe80f) }, /* USB to serial */
227 { USB_DEVICE(0x0403, 0xe888) }, /* Expert ISDN Control USB */
228 { USB_DEVICE(0x0403, 0xe889) }, /* USB-RS232 OptoBridge */
229 { USB_DEVICE(0x0403, 0xe88a) }, /* Expert mouseCLOCK USB II */
230 { USB_DEVICE(0x0403, 0xe88b) }, /* Precision Clock MSF USB */
231 { USB_DEVICE(0x0403, 0xe88c) }, /* Expert mouseCLOCK USB II HBG */
232 { USB_DEVICE(0x0403, 0xe88d) }, /* USB to serial */
233 { USB_DEVICE(0x0403, 0xe88e) }, /* USB to serial */
234 { USB_DEVICE(0x0403, 0xe88f) }, /* USB to serial */
236 /* Eclo, Lda. products */
237 { USB_DEVICE(0x0403, 0xea90) }, /* COM to 1-Wire USB adaptor */
239 /* Coastal ChipWorks products */
240 { USB_DEVICE(0x0403, 0xebe0) }, /* TNC-X USB to packet-radio adapter */
242 /* Teratronik products */
243 { USB_DEVICE(0x0403, 0xec88) }, /* Teratronik VCP device */
245 /* MaxStream products */
246 { USB_DEVICE(0x0403, 0xee18) }, /* PKG-U RF modem */
248 /* microHAM products */
249 { USB_DEVICE(0x0403, 0xeee8) }, /* USB-KW interface */
250 { USB_DEVICE(0x0403, 0xeee9) }, /* USB-YS interface */
251 { USB_DEVICE(0x0403, 0xeeea) }, /* USB-Y6 interface */
252 { USB_DEVICE(0x0403, 0xeeeb) }, /* USB-Y8 interface */
253 { USB_DEVICE(0x0403, 0xeeec) }, /* USB-IC interface */
254 { USB_DEVICE(0x0403, 0xeeed) }, /* USB-DB9 interface */
255 { USB_DEVICE(0x0403, 0xeeee) }, /* USB-RS232 interface */
256 { USB_DEVICE(0x0403, 0xeeef) }, /* USB-Y9 interface */
259 { USB_DEVICE(0x0403, 0xf06e) }, /* ALC 8500 Expert */
260 { USB_DEVICE(0x0403, 0xf06f) }, /* FHZ 1000 PC */
262 /* Perle Systems products */
263 { USB_DEVICE(0x0403, 0xf0c0) }, /* UltraPort USB */
265 /* ACT Solutions products */
266 { USB_DEVICE(0x0403, 0xf2d0) }, /* HomePro ZWave */
268 /* 4n-galaxy.de products */
269 { USB_DEVICE(0x0403, 0xf3c0) }, /* Galaxy USB to serial */
270 { USB_DEVICE(0x0403, 0xf3c1) }, /* Galaxy USB to serial */
272 /* Linx Technologies products */
273 { USB_DEVICE(0x0403, 0xf448) }, /* Linx SDM-USB-QS-S */
274 { USB_DEVICE(0x0403, 0xf449) }, /* Linx Master Development 2.0 */
275 { USB_DEVICE(0x0403, 0xf44a) }, /* Linx USB to serial */
276 { USB_DEVICE(0x0403, 0xf44b) }, /* Linx USB to serial */
277 { USB_DEVICE(0x0403, 0xf44c) }, /* Linx USB to serial */
279 /* Suunto Oy products */
280 { USB_DEVICE(0x0403, 0xf680) }, /* Suunto Sports instrument */
283 { USB_DEVICE(0x0403, 0xf850) }, /* USB-UIRT */
285 /* CCS Inc. products */
286 { USB_DEVICE(0x0403, 0xf9d0) }, /* ICD-U20 */
287 { USB_DEVICE(0x0403, 0xf9d1) }, /* ICD-U40 */
288 { USB_DEVICE(0x0403, 0xf9d2) }, /* MACH-X */
290 /* Matrix Orbital LCD displays */
291 { USB_DEVICE(0x0403, 0xfa00) }, /* USB Serial */
292 { USB_DEVICE(0x0403, 0xfa01) }, /* MX2 or MX3 LCD */
293 { USB_DEVICE(0x0403, 0xfa02) }, /* MX4 or MX5 LCD */
294 { USB_DEVICE(0x0403, 0xfa03) }, /* LK202-24 LCD */
295 { USB_DEVICE(0x0403, 0xfa04) }, /* LK204-24 LCD */
296 { USB_DEVICE(0x0403, 0xfa05) }, /* USB Serial */
297 { USB_DEVICE(0x0403, 0xfa06) }, /* USB Serial */
299 /* Home Electronics products */
300 { USB_DEVICE(0x0403, 0xfa78) }, /* Tira-1 */
303 { USB_DEVICE(0x0403, 0xfa88) }, /* DAC-2 */
305 /* Inside.fr products */
306 { USB_DEVICE(0x0403, 0xfad0) }, /* Accesso contactless reader */
308 /* Thorlabs GmbH products */
309 { USB_DEVICE(0x0403, 0xfaf0) }, /* Motors controller */
312 { USB_DEVICE(0x0403, 0xfb58) }, /* UR 100 */
313 { USB_DEVICE(0x0403, 0xfb5a) }, /* UM 100 */
314 { USB_DEVICE(0x0403, 0xfb5b) }, /* UO 100 */
316 /* Crystalfontz products */
317 { USB_DEVICE(0x0403, 0xfc08) }, /* CFA-632 LCD */
318 { USB_DEVICE(0x0403, 0xfc09) }, /* CFA-634 LCD */
319 { USB_DEVICE(0x0403, 0xfc0a) }, /* CFA-547 LCD */
320 { USB_DEVICE(0x0403, 0xfc0b) }, /* CFA-633 LCD */
321 { USB_DEVICE(0x0403, 0xfc0c) }, /* CFA-631 LCD */
322 { USB_DEVICE(0x0403, 0xfc0d) }, /* CFA-635 LCD */
323 { USB_DEVICE(0x0403, 0xfc0e) }, /* CFA-640 LCD */
324 { USB_DEVICE(0x0403, 0xfc0f) }, /* CFA-642 LCD */
326 /* IRTrans GmbH products */
327 { USB_DEVICE(0x0403, 0xfc60) }, /* Irtrans device */
329 /* Sony Ericsson products */
330 { USB_DEVICE(0x0403, 0xfc82) }, /* DSS-20 SyncStation */
332 /* RM Michaelides Software & Elektronik GmbH products */
333 { USB_DEVICE(0x0403, 0xfd60) }, /* CANview USB */
335 /* Video Networks Limited / Homechoice products */
336 { USB_DEVICE(0x0403, 0xfe38) }, /* Homechoice broadband modem */
338 /* AlphaMicro Components products */
339 { USB_DEVICE(0x0403, 0xff00) }, /* AMC-232USB01 */
341 /* Thought Technology Ltd. products */
342 { USB_DEVICE(0x0403, 0xff20) }, /* TT-USB */
344 /* IBS elektronik products */
345 { USB_DEVICE(0x0403, 0xff38) }, /* US485 interface */
346 { USB_DEVICE(0x0403, 0xff39) }, /* PIC-Programmer */
347 { USB_DEVICE(0x0403, 0xff3a) }, /* PCMCIA SRAM-cards reader */
348 { USB_DEVICE(0x0403, 0xff3b) }, /* Particel counter PK1 */
349 { USB_DEVICE(0x0403, 0xff3c) }, /* RS232 - Monitor */
350 { USB_DEVICE(0x0403, 0xff3d) }, /* APP 70 dust monitoring */
351 { USB_DEVICE(0x0403, 0xff3e) }, /* PEDO-Modem */
352 { USB_DEVICE(0x0403, 0xff3f) }, /* Future device */
354 /* Lawicel products */
355 { USB_DEVICE(0x0403, 0xffa8) }, /* CANUSB device */
357 /* Melco, Inc products */
358 { USB_DEVICE(0x0411, 0x00b3) }, /* PC-OP-RS1 RemoteStation */
360 /* B&B Electronics products */
361 { USB_DEVICE(0x0856, 0xac01) }, /* USOTL4 */
362 { USB_DEVICE(0x0856, 0xac02) }, /* USTL4 */
363 { USB_DEVICE(0x0856, 0xac03) }, /* USO9ML2 */
364 { USB_DEVICE(0x0856, 0xac11) }, /* USOPTL4 */
365 { USB_DEVICE(0x0856, 0xac12) }, /* USPTL4 */
366 { USB_DEVICE(0x0856, 0xac16) }, /* USO9ML2DR-2 */
367 { USB_DEVICE(0x0856, 0xac17) }, /* USO9ML2DR */
368 { USB_DEVICE(0x0856, 0xac18) }, /* USOPTL4DR-2 */
369 { USB_DEVICE(0x0856, 0xac19) }, /* USOPTL4DR */
370 { USB_DEVICE(0x0856, 0xac25) }, /* 485USB9F-2W */
371 { USB_DEVICE(0x0856, 0xac26) }, /* 485USB9F-4W */
372 { USB_DEVICE(0x0856, 0xac27) }, /* 232USB9M */
374 /* Interpid Control Systems products */
375 { USB_DEVICE(0x093c, 0x0601) }, /* ValueCAN */
376 { USB_DEVICE(0x093c, 0x0701) }, /* NeoVI Blue */
378 /* ID TECH products */
379 { USB_DEVICE(0x0acd, 0x0300) }, /* USB to serial adapter */
381 /* Omnidirectional Control Technology products */
382 { USB_DEVICE(0x0b39, 0x0421) }, /* USB to serial */
384 /* Icom, Inc. products */
385 { USB_DEVICE(0x0c26, 0x0004) }, /* ID-1 */
386 { USB_DEVICE(0x0c26, 0x0009) }, /* ID-RP2C service 1 */
387 { USB_DEVICE(0x0c26, 0x000a) }, /* ID-RP2C service 2 */
388 { USB_DEVICE(0x0c26, 0x000b) }, /* ID-RP2D */
389 { USB_DEVICE(0x0c26, 0x000c) }, /* ID-RP2V service T */
390 { USB_DEVICE(0x0c26, 0x000d) }, /* ID-RP2V service R */
391 { USB_DEVICE(0x0c26, 0x0011) }, /* ID-RP4000V service R */
392 { USB_DEVICE(0x0c26, 0x0011) }, /* ID-RP4000V service T */
393 { USB_DEVICE(0x0c26, 0x0012) }, /* ID-RP2000V service T */
394 { USB_DEVICE(0x0c26, 0x0013) }, /* ID-RP2000V service R */
396 /* Sealevel products */
397 { USB_DEVICE(0x0c52, 0X2811) }, /* SeaLINK+8/232 (2801) Port 1 */
398 { USB_DEVICE(0x0c52, 0X2812) }, /* SeaLINK+8/485 (2802) Port 1 */
399 { USB_DEVICE(0x0c52, 0X2813) }, /* SeaLINK+8 (2803) Port 1 */
400 { USB_DEVICE(0x0c52, 0X2821) }, /* SeaLINK+8/232 (2801) Port 2 */
401 { USB_DEVICE(0x0c52, 0X2822) }, /* SeaLINK+8/485 (2802) Port 2 */
402 { USB_DEVICE(0x0c52, 0X2823) }, /* SeaLINK+8 (2803) Port 2 */
403 { USB_DEVICE(0x0c52, 0X2831) }, /* SeaLINK+8/232 (2801) Port 3 */
404 { USB_DEVICE(0x0c52, 0X2832) }, /* SeaLINK+8/485 (2802) Port 3 */
405 { USB_DEVICE(0x0c52, 0X2833) }, /* SeaLINK+8 (2803) Port 3 */
406 { USB_DEVICE(0x0c52, 0X2841) }, /* SeaLINK+8/232 (2801) Port 4 */
407 { USB_DEVICE(0x0c52, 0X2842) }, /* SeaLINK+8/485 (2802) Port 4 */
408 { USB_DEVICE(0x0c52, 0X2843) }, /* SeaLINK+8 (2803) Port 4 */
409 { USB_DEVICE(0x0c52, 0X2851) }, /* SeaLINK+8/232 (2801) Port 5 */
410 { USB_DEVICE(0x0c52, 0X2852) }, /* SeaLINK+8/485 (2802) Port 5 */
411 { USB_DEVICE(0x0c52, 0X2853) }, /* SeaLINK+8 (2803) Port 5 */
412 { USB_DEVICE(0x0c52, 0X2861) }, /* SeaLINK+8/232 (2801) Port 6 */
413 { USB_DEVICE(0x0c52, 0X2862) }, /* SeaLINK+8/485 (2802) Port 6 */
414 { USB_DEVICE(0x0c52, 0X2863) }, /* SeaLINK+8 (2803) Port 6 */
415 { USB_DEVICE(0x0c52, 0X2871) }, /* SeaLINK+8/232 (2801) Port 7 */
416 { USB_DEVICE(0x0c52, 0X2872) }, /* SeaLINK+8/485 (2802) Port 7 */
417 { USB_DEVICE(0x0c52, 0X2873) }, /* SeaLINK+8 (2803) Port 7 */
418 { USB_DEVICE(0x0c52, 0X2881) }, /* SeaLINK+8/232 (2801) Port 8 */
419 { USB_DEVICE(0x0c52, 0X2882) }, /* SeaLINK+8/485 (2802) Port 8 */
420 { USB_DEVICE(0x0c52, 0X2883) }, /* SeaLINK+8 (2803) Port 8 */
421 { USB_DEVICE(0x0c52, 0x2101) }, /* SeaLINK+232 (2101/2105) */
422 { USB_DEVICE(0x0c52, 0x2102) }, /* SeaLINK+485 (2102) */
423 { USB_DEVICE(0x0c52, 0x2103) }, /* SeaLINK+232I (2103) */
424 { USB_DEVICE(0x0c52, 0x2104) }, /* SeaLINK+485I (2104) */
425 { USB_DEVICE(0x0c52, 0x2211) }, /* SeaPORT+2/232 (2201) Port 1 */
426 { USB_DEVICE(0x0c52, 0x2212) }, /* SeaPORT+2/485 (2202) Port 1 */
427 { USB_DEVICE(0x0c52, 0x2213) }, /* SeaPORT+2 (2203) Port 1 */
428 { USB_DEVICE(0x0c52, 0x2221) }, /* SeaPORT+2/232 (2201) Port 2 */
429 { USB_DEVICE(0x0c52, 0x2222) }, /* SeaPORT+2/485 (2202) Port 2 */
430 { USB_DEVICE(0x0c52, 0x2223) }, /* SeaPORT+2 (2203) Port 2 */
431 { USB_DEVICE(0x0c52, 0x2411) }, /* SeaPORT+4/232 (2401) Port 1 */
432 { USB_DEVICE(0x0c52, 0x2412) }, /* SeaPORT+4/485 (2402) Port 1 */
433 { USB_DEVICE(0x0c52, 0x2413) }, /* SeaPORT+4 (2403) Port 1 */
434 { USB_DEVICE(0x0c52, 0x2421) }, /* SeaPORT+4/232 (2401) Port 2 */
435 { USB_DEVICE(0x0c52, 0x2422) }, /* SeaPORT+4/485 (2402) Port 2 */
436 { USB_DEVICE(0x0c52, 0x2423) }, /* SeaPORT+4 (2403) Port 2 */
437 { USB_DEVICE(0x0c52, 0x2431) }, /* SeaPORT+4/232 (2401) Port 3 */
438 { USB_DEVICE(0x0c52, 0x2432) }, /* SeaPORT+4/485 (2402) Port 3 */
439 { USB_DEVICE(0x0c52, 0x2433) }, /* SeaPORT+4 (2403) Port 3 */
440 { USB_DEVICE(0x0c52, 0x2441) }, /* SeaPORT+4/232 (2401) Port 4 */
441 { USB_DEVICE(0x0c52, 0x2442) }, /* SeaPORT+4/485 (2402) Port 4 */
442 { USB_DEVICE(0x0c52, 0x2443) }, /* SeaPORT+4 (2403) Port 4 */
443 { USB_DEVICE(0x0c52, 0x9020) }, /* SeaLINK+422 (2106) */
445 /* Posiflex Technologies products */
446 { USB_DEVICE(0x0d3a, 0x0300) }, /* PP7000 series printer */
447 { USB_DEVICE(0x0d3a, 0x0400) }, /* PP7000 series printer */
449 /* Kobil Systems products */
450 { USB_DEVICE(0x0d46, 0x2020) }, /* Konverter for B1 */
451 { USB_DEVICE(0x0d46, 0x2021) }, /* Konverter for KAAN */
453 /* Falcom Wireless Communications products */
454 { USB_DEVICE(0x0f94, 0x0001) }, /* Twist USB GPRS modem */
455 { USB_DEVICE(0x0f94, 0x0005) }, /* Samba USB GPRS modem */
457 /* Thurlby Thandar Instruments products */
458 { USB_DEVICE(0x103e, 0x03e8) }, /* QL355P power supply */
460 /* InterBiometrics products */
461 { USB_DEVICE(0x1209, 0x1002) }, /* IO Board */
462 { USB_DEVICE(0x1209, 0x1006) }, /* Mini IO Board */
464 /* Testo AG products */
465 { USB_DEVICE(0x128d, 0x0001) }, /* 175/177 USB interface */
466 { USB_DEVICE(0x128d, 0x0002) }, /* 330 USB interface */
467 { USB_DEVICE(0x128d, 0x0003) }, /* 435/635/735 USB interface */
468 { USB_DEVICE(0x128d, 0x0004) }, /* 845 USB interface */
469 { USB_DEVICE(0x128d, 0x0005) }, /* Service adapter */
470 { USB_DEVICE(0x128d, 0x0006) }, /* 580 USB interface */
471 { USB_DEVICE(0x128d, 0x0007) }, /* 174 USB interface */
472 { USB_DEVICE(0x128d, 0x0009) }, /* 556/560 USB interface */
473 { USB_DEVICE(0x128d, 0x000a) }, /* USB adapter */
474 { USB_DEVICE(0x128d, 0xf001) }, /* USB to serial converter */
476 /* Mobility products */
477 { USB_DEVICE(0x1342, 0x0202) }, /* EasiDock 200 serial port */
479 /* Papouch s.r.o. products */
480 { USB_DEVICE(0x5050, 0x0100) }, /* SB485 USB-485/422 Converter */
481 { USB_DEVICE(0x5050, 0x0101) }, /* AP485 USB-RS485 Converter */
482 { USB_DEVICE(0x5050, 0x0102) }, /* SB422 USB-RS422 Converter */
483 { USB_DEVICE(0x5050, 0x0103) }, /* SB485 USB-485/422 Converter */
484 { USB_DEVICE(0x5050, 0x0104) }, /* AP485 USB-RS485 Converter */
485 { USB_DEVICE(0x5050, 0x0105) }, /* SB422 USB-RS422 Converter */
486 { USB_DEVICE(0x5050, 0x0106) }, /* SB485S USB-485/422 Converter */
487 { USB_DEVICE(0x5050, 0x0107) }, /* SB485C USB-485/422 Converter */
488 { USB_DEVICE(0x5050, 0x0200) }, /* USB Device */
489 { USB_DEVICE(0x5050, 0x0300) }, /* LEC USB Converter */
490 { USB_DEVICE(0x5050, 0x0301) }, /* SB232 USB-RS232 Converter */
491 { USB_DEVICE(0x5050, 0x0400) }, /* TMU Thermometer */
492 { USB_DEVICE(0x5050, 0x0500) }, /* IRAmp Duplex */
493 { USB_DEVICE(0x5050, 0x0700) }, /* DRAK5 */
494 { USB_DEVICE(0x5050, 0x0800) }, /* QUIDO USB 8/8 */
495 { USB_DEVICE(0x5050, 0x0900) }, /* QUIDO USB 4/4 */
496 { USB_DEVICE(0x5050, 0x0A00) }, /* QUIDO USB 2/2 */
497 { USB_DEVICE(0x5050, 0x0B00) }, /* QUIDO USB 10/1 */
498 { USB_DEVICE(0x5050, 0x0C00) }, /* QUIDO USB 30/3 */
499 { USB_DEVICE(0x5050, 0x0D00) }, /* QUIDO USB 60(100)/3 */
500 { USB_DEVICE(0x5050, 0x0E00) }, /* QUIDO USB 2/16 */
501 { USB_DEVICE(0x5050, 0x0F00) }, /* QUIDO USB 3/32 */
502 { USB_DEVICE(0x5050, 0x1000) }, /* DRAK6 USB */
503 { USB_DEVICE(0x5050, 0x8000) }, /* UPS-USB Stavovy Adapter */
504 { USB_DEVICE(0x5050, 0x8001) }, /* MU Controller */
505 { USB_DEVICE(0x5050, 0x8002) }, /* SimuKey */
506 { USB_DEVICE(0x5050, 0x8003) }, /* AD4USB */
507 { USB_DEVICE(0x5050, 0x8004) }, /* GOLIATH MUX */
508 { USB_DEVICE(0x5050, 0x8005) }, /* GOLIATH MSR */
510 /* Evolution Robotics, Inc. products */
511 { USB_DEVICE(0xdeee, 0x0300) }, /* ER1 Control Module */
512 { USB_DEVICE(0xdeee, 0x0302) }, /* RCM4 interface */
513 { USB_DEVICE(0xdeee, 0x0303) }, /* RCM4 interface */
517 uftdi_match(device_t self)
519 struct usb_attach_arg *uaa = device_get_ivars(self);
521 if (uaa->iface == NULL)
522 return (UMATCH_NONE);
524 if (usb_lookup(uftdi_devs, uaa->vendor, uaa->product) != NULL)
525 return (UMATCH_VENDOR_IFACESUBCLASS);
527 return (UMATCH_NONE);
531 uftdi_attach(device_t self)
533 struct uftdi_softc *sc = device_get_softc(self);
534 struct usb_attach_arg *uaa = device_get_ivars(self);
535 usbd_device_handle dev = uaa->device;
536 usbd_interface_handle iface;
537 usb_interface_descriptor_t *id;
538 usb_endpoint_descriptor_t *ed;
541 struct ucom_softc *ucom = &sc->sc_ucom;
542 DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
543 devinfo = kmalloc(1024, M_USBDEV, M_INTWAIT);
548 usbd_devinfo(dev, 0, devinfo);
549 device_printf(ucom->sc_dev, "%s\n", devinfo);
550 kfree(devinfo, M_USBDEV);
553 id = usbd_get_interface_descriptor(iface);
554 ucom->sc_iface = iface;
556 if (uaa->release < 0x0200) {
557 sc->sc_type = UFTDI_TYPE_SIO;
560 sc->sc_type = UFTDI_TYPE_8U232AM;
564 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
566 for (i = 0; i < id->bNumEndpoints; i++) {
568 ed = usbd_interface2endpoint_descriptor(iface, i);
570 device_printf(ucom->sc_dev,
571 "could not read endpoint descriptor\n");
575 addr = ed->bEndpointAddress;
576 dir = UE_GET_DIR(ed->bEndpointAddress);
577 attr = ed->bmAttributes & UE_XFERTYPE;
578 if (dir == UE_DIR_IN && attr == UE_BULK)
579 ucom->sc_bulkin_no = addr;
580 else if (dir == UE_DIR_OUT && attr == UE_BULK)
581 ucom->sc_bulkout_no = addr;
583 device_printf(ucom->sc_dev, "unexpected endpoint\n");
587 if (ucom->sc_bulkin_no == -1) {
588 device_printf(ucom->sc_dev, "Could not find data bulk in\n");
591 if (ucom->sc_bulkout_no == -1) {
592 device_printf(ucom->sc_dev, "Could not find data bulk out\n");
595 ucom->sc_parent = sc;
596 ucom->sc_portno = FTDI_PIT_SIOA + id->bInterfaceNumber;
597 /* bulkin, bulkout set above */
599 ucom->sc_ibufsize = UFTDIIBUFSIZE;
600 ucom->sc_obufsize = UFTDIOBUFSIZE - sc->sc_hdrlen;
601 ucom->sc_ibufsizepad = UFTDIIBUFSIZE;
602 ucom->sc_opkthdrlen = sc->sc_hdrlen;
605 ucom->sc_callback = &uftdi_callback;
607 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
610 DPRINTF(("uftdi: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no));
611 ucom_attach(&sc->sc_ucom);
615 DPRINTF(("uftdi_attach: ATTACH ERROR\n"));
621 uftdi_activate(device_t self, enum devact act)
623 struct uftdi_softc *sc = (struct uftdi_softc *)self;
630 case DVACT_DEACTIVATE:
631 if (sc->sc_subdev != NULL)
632 rv = config_deactivate(sc->sc_subdev);
633 sc->sc_ucom.sc_dying = 1;
641 uftdi_detach(device_t self)
643 struct uftdi_softc *sc = device_get_softc(self);
647 DPRINTF(("uftdi_detach: sc=%p\n", sc));
648 sc->sc_ucom.sc_dying = 1;
649 rv = ucom_detach(&sc->sc_ucom);
655 uftdi_open(void *vsc, int portno)
657 struct uftdi_softc *sc = vsc;
658 struct ucom_softc *ucom = &sc->sc_ucom;
659 usb_device_request_t req;
663 DPRINTF(("uftdi_open: sc=%p\n", sc));
668 /* Perform a full reset on the device */
669 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
670 req.bRequest = FTDI_SIO_RESET;
671 USETW(req.wValue, FTDI_SIO_RESET_SIO);
672 USETW(req.wIndex, portno);
673 USETW(req.wLength, 0);
674 err = usbd_do_request(ucom->sc_udev, &req, NULL);
678 /* Set 9600 baud, 2 stop bits, no parity, 8 bits */
680 t.c_cflag = CSTOPB | CS8;
681 (void)uftdi_param(sc, portno, &t);
683 /* Turn on RTS/CTS flow control */
684 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
685 req.bRequest = FTDI_SIO_SET_FLOW_CTRL;
686 USETW(req.wValue, 0);
687 USETW2(req.wIndex, FTDI_SIO_RTS_CTS_HS, portno);
688 USETW(req.wLength, 0);
689 err = usbd_do_request(ucom->sc_udev, &req, NULL);
697 uftdi_read(void *vsc, int portno, u_char **ptr, u_int32_t *count)
699 struct uftdi_softc *sc = vsc;
702 DPRINTFN(15,("uftdi_read: sc=%p, port=%d count=%d\n", sc, portno,
705 msr = FTDI_GET_MSR(*ptr);
706 lsr = FTDI_GET_LSR(*ptr);
710 DPRINTFN(10,("uftdi_read: sc=%p, port=%d count=%d data[0]="
711 "0x%02x\n", sc, portno, *count, (*ptr)[2]));
714 if (sc->sc_msr != msr ||
715 (sc->sc_lsr & FTDI_LSR_MASK) != (lsr & FTDI_LSR_MASK)) {
716 DPRINTF(("uftdi_read: status change msr=0x%02x(0x%02x) "
717 "lsr=0x%02x(0x%02x)\n", msr, sc->sc_msr,
721 ucom_status_change(&sc->sc_ucom);
724 /* Pick up status and adjust data part. */
730 uftdi_write(void *vsc, int portno, u_char *to, u_char *from, u_int32_t *count)
732 struct uftdi_softc *sc = vsc;
734 DPRINTFN(10,("uftdi_write: sc=%p, port=%d count=%u data[0]=0x%02x\n",
735 vsc, portno, *count, from[0]));
737 /* Make length tag and copy data */
738 if (sc->sc_hdrlen > 0)
739 *to = FTDI_OUT_TAG(*count, portno);
741 memcpy(to + sc->sc_hdrlen, from, *count);
742 *count += sc->sc_hdrlen;
746 uftdi_set(void *vsc, int portno, int reg, int onoff)
748 struct uftdi_softc *sc = vsc;
749 struct ucom_softc *ucom = vsc;
750 usb_device_request_t req;
753 DPRINTF(("uftdi_set: sc=%p, port=%d reg=%d onoff=%d\n", vsc, portno,
758 ctl = onoff ? FTDI_SIO_SET_DTR_HIGH : FTDI_SIO_SET_DTR_LOW;
761 ctl = onoff ? FTDI_SIO_SET_RTS_HIGH : FTDI_SIO_SET_RTS_LOW;
764 uftdi_break(sc, portno, onoff);
769 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
770 req.bRequest = FTDI_SIO_MODEM_CTRL;
771 USETW(req.wValue, ctl);
772 USETW(req.wIndex, portno);
773 USETW(req.wLength, 0);
774 DPRINTFN(2,("uftdi_set: reqtype=0x%02x req=0x%02x value=0x%04x "
775 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
776 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
777 (void)usbd_do_request(ucom->sc_udev, &req, NULL);
781 uftdi_param(void *vsc, int portno, struct termios *t)
783 struct uftdi_softc *sc = vsc;
784 struct ucom_softc *ucom = &sc->sc_ucom;
785 usb_device_request_t req;
787 int rate=0, data, flow;
789 DPRINTF(("uftdi_param: sc=%p\n", sc));
794 switch (sc->sc_type) {
796 switch (t->c_ospeed) {
797 case 300: rate = ftdi_sio_b300; break;
798 case 600: rate = ftdi_sio_b600; break;
799 case 1200: rate = ftdi_sio_b1200; break;
800 case 2400: rate = ftdi_sio_b2400; break;
801 case 4800: rate = ftdi_sio_b4800; break;
802 case 9600: rate = ftdi_sio_b9600; break;
803 case 19200: rate = ftdi_sio_b19200; break;
804 case 38400: rate = ftdi_sio_b38400; break;
805 case 57600: rate = ftdi_sio_b57600; break;
806 case 115200: rate = ftdi_sio_b115200; break;
812 case UFTDI_TYPE_8U232AM:
813 if (uftdi_8u232am_getrate(t->c_ospeed, &rate) == -1)
817 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
818 req.bRequest = FTDI_SIO_SET_BAUD_RATE;
819 USETW(req.wValue, rate);
820 USETW(req.wIndex, portno);
821 USETW(req.wLength, 0);
822 DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
823 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
824 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
825 err = usbd_do_request(ucom->sc_udev, &req, NULL);
829 if (ISSET(t->c_cflag, CSTOPB))
830 data = FTDI_SIO_SET_DATA_STOP_BITS_2;
832 data = FTDI_SIO_SET_DATA_STOP_BITS_1;
833 if (ISSET(t->c_cflag, PARENB)) {
834 if (ISSET(t->c_cflag, PARODD))
835 data |= FTDI_SIO_SET_DATA_PARITY_ODD;
837 data |= FTDI_SIO_SET_DATA_PARITY_EVEN;
839 data |= FTDI_SIO_SET_DATA_PARITY_NONE;
840 switch (ISSET(t->c_cflag, CSIZE)) {
842 data |= FTDI_SIO_SET_DATA_BITS(5);
845 data |= FTDI_SIO_SET_DATA_BITS(6);
848 data |= FTDI_SIO_SET_DATA_BITS(7);
851 data |= FTDI_SIO_SET_DATA_BITS(8);
856 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
857 req.bRequest = FTDI_SIO_SET_DATA;
858 USETW(req.wValue, data);
859 USETW(req.wIndex, portno);
860 USETW(req.wLength, 0);
861 DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
862 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
863 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
864 err = usbd_do_request(ucom->sc_udev, &req, NULL);
868 if (ISSET(t->c_cflag, CRTSCTS)) {
869 flow = FTDI_SIO_RTS_CTS_HS;
870 USETW(req.wValue, 0);
871 } else if (ISSET(t->c_iflag, IXON|IXOFF)) {
872 flow = FTDI_SIO_XON_XOFF_HS;
873 USETW2(req.wValue, t->c_cc[VSTOP], t->c_cc[VSTART]);
875 flow = FTDI_SIO_DISABLE_FLOW_CTRL;
876 USETW(req.wValue, 0);
878 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
879 req.bRequest = FTDI_SIO_SET_FLOW_CTRL;
880 USETW2(req.wIndex, flow, portno);
881 USETW(req.wLength, 0);
882 err = usbd_do_request(ucom->sc_udev, &req, NULL);
890 uftdi_get_status(void *vsc, int portno, u_char *lsr, u_char *msr)
892 struct uftdi_softc *sc = vsc;
894 DPRINTF(("uftdi_status: msr=0x%02x lsr=0x%02x\n",
895 sc->sc_msr, sc->sc_lsr));
904 uftdi_break(void *vsc, int portno, int onoff)
906 struct uftdi_softc *sc = vsc;
907 struct ucom_softc *ucom = vsc;
909 usb_device_request_t req;
912 DPRINTF(("uftdi_break: sc=%p, port=%d onoff=%d\n", vsc, portno,
916 data = sc->last_lcr | FTDI_SIO_SET_BREAK;
921 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
922 req.bRequest = FTDI_SIO_SET_DATA;
923 USETW(req.wValue, data);
924 USETW(req.wIndex, portno);
925 USETW(req.wLength, 0);
926 (void)usbd_do_request(ucom->sc_udev, &req, NULL);
930 uftdi_8u232am_getrate(speed_t speed, int *rate)
932 /* Table of the nearest even powers-of-2 for values 0..15. */
933 static const unsigned char roundoff[16] = {
934 0, 2, 2, 4, 4, 4, 8, 8,
935 8, 8, 8, 8, 16, 16, 16, 16,
938 unsigned int d, freq;
944 /* Special cases for 2M and 3M. */
945 if (speed >= 3000000 * 100 / 103 &&
946 speed <= 3000000 * 100 / 97) {
950 if (speed >= 2000000 * 100 / 103 &&
951 speed <= 2000000 * 100 / 97) {
956 d = (FTDI_8U232AM_FREQ << 4) / speed;
957 d = (d & ~15) + roundoff[d & 15];
959 if (d < FTDI_8U232AM_MIN_DIV)
960 d = FTDI_8U232AM_MIN_DIV;
961 else if (d > FTDI_8U232AM_MAX_DIV)
962 d = FTDI_8U232AM_MAX_DIV;
965 * Calculate the frequency needed for d to exactly divide down
966 * to our target speed, and check that the actual frequency is
970 if (freq < (quad_t)(FTDI_8U232AM_FREQ << 4) * 100 / 103 ||
971 freq > (quad_t)(FTDI_8U232AM_FREQ << 4) * 100 / 97)
975 * Pack the divisor into the resultant value. The lower
976 * 14-bits hold the integral part, while the upper 2 bits
977 * encode the fractional component: either 0, 0.5, 0.25, or
992 static device_method_t uftdi_methods[] = {
993 /* Device interface */
994 DEVMETHOD(device_probe, uftdi_match),
995 DEVMETHOD(device_attach, uftdi_attach),
996 DEVMETHOD(device_detach, uftdi_detach),
1001 static driver_t uftdi_driver = {
1004 sizeof (struct uftdi_softc)
1007 DRIVER_MODULE(uftdi, uhub, uftdi_driver, ucom_devclass, usbd_driver_load, 0);
1008 MODULE_DEPEND(uftdi, usb, 1, 1, 1);
1009 MODULE_DEPEND(uftdi, ucom,UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);