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 $
7 * Copyright (c) 2000 The NetBSD Foundation, Inc.
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Lennart Augustsson (lennart@augustsson.net).
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the NetBSD
24 * Foundation, Inc. and its contributors.
25 * 4. Neither the name of The NetBSD Foundation nor the names of its
26 * contributors may be used to endorse or promote products derived
27 * from this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
43 * FTDI FT8U100AX serial adapter driver
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/module.h>
52 #include <sys/fcntl.h>
57 #include <sys/select.h>
59 #include <sys/sysctl.h>
61 #include <bus/usb/usb.h>
62 #include <bus/usb/usbhid.h>
64 #include <bus/usb/usbdi.h>
65 #include <bus/usb/usbdi_util.h>
67 #include "../ucom/ucomvar.h"
72 static int uftdidebug = 0;
73 SYSCTL_NODE(_hw_usb, OID_AUTO, uftdi, CTLFLAG_RW, 0, "USB uftdi");
74 SYSCTL_INT(_hw_usb_uftdi, OID_AUTO, debug, CTLFLAG_RW,
75 &uftdidebug, 0, "uftdi debug level");
76 #define DPRINTF(x) do { \
81 #define DPRINTFN(n, x) do { \
82 if (uftdidebug > (n)) \
91 #define UFTDI_CONFIG_INDEX 0
92 #define UFTDI_IFACE_INDEX 0
95 * These are the maximum number of bytes transferred per frame.
96 * The output buffer size cannot be increased due to the size encoding.
98 #define UFTDIIBUFSIZE 64
99 #define UFTDIOBUFSIZE 64
102 struct ucom_softc sc_ucom;
103 usbd_interface_handle sc_iface; /* interface */
104 enum uftdi_type sc_type;
111 static void uftdi_get_status(void *, int portno, u_char *lsr, u_char *msr);
112 static void uftdi_set(void *, int, int, int);
113 static int uftdi_param(void *, int, struct termios *);
114 static int uftdi_open(void *sc, int portno);
115 static void uftdi_read(void *sc, int portno, u_char **ptr,u_int32_t *count);
116 static void uftdi_write(void *sc, int portno, u_char *to, u_char *from,
118 static void uftdi_break(void *sc, int portno, int onoff);
119 static int uftdi_8u232am_getrate(speed_t speed, int *rate);
121 struct ucom_callback uftdi_callback = {
132 static const struct usb_devno uftdi_devs[] = {
133 /* FTDI chips defaults */
134 { USB_DEVICE(0x0403, 0x0232) }, /* FT232 serial converter */
135 { USB_DEVICE(0x0403, 0x6001) }, /* FT232 serial converter */
136 { USB_DEVICE(0x0403, 0x6006) }, /* FT232 serial converter */
137 { USB_DEVICE(0x0403, 0x6007) }, /* FT232 serial converter */
138 { USB_DEVICE(0x0403, 0x6008) }, /* FT232 serial converter */
139 { USB_DEVICE(0x0403, 0x6009) }, /* FT232 serial converter */
140 { USB_DEVICE(0x0403, 0x6010) }, /* FT2232 dual port serial converter */
141 { USB_DEVICE(0x0403, 0x8372) }, /* FTDI 8U100AX USB hub controller */
143 /* RR-CirKits products */
144 { USB_DEVICE(0x0403, 0xc7d0) }, /* LocoBuffer USB */
146 /* DMX4ALL products */
147 { USB_DEVICE(0x0403, 0xc850) }, /* DMX interface */
150 { USB_DEVICE(0x0403, 0xc990) }, /* RDR 4X7 series card reader */
151 { USB_DEVICE(0x0403, 0xc991) }, /* RDR 4X7 series card reader */
152 { USB_DEVICE(0x0403, 0xc992) }, /* RDR 4X7 series card reader */
153 { USB_DEVICE(0x0403, 0xc993) }, /* RDR 4X7 series card reader */
154 { USB_DEVICE(0x0403, 0xc994) }, /* RDR 4X7 series card reader */
155 { USB_DEVICE(0x0403, 0xc995) }, /* RDR 4X7 series card reader */
156 { USB_DEVICE(0x0403, 0xc996) }, /* RDR 4X7 series card reader */
157 { USB_DEVICE(0x0403, 0xc997) }, /* RDR 4X7 series card reader */
160 { USB_DEVICE(0x0403, 0xca81) }, /* Sirius To PC Interface */
162 /* Starting Point Systems products */
163 { USB_DEVICE(0x0403, 0xcaa0) }, /* µChameleon */
165 /* Tactrix products */
166 { USB_DEVICE(0x0403, 0xcc48) }, /* OpenPort 1.3 Mitsubishi */
167 { USB_DEVICE(0x0403, 0xcc49) }, /* OpenPort 1.3 Subaru */
168 { USB_DEVICE(0x0403, 0xcc4a) }, /* OpenPort 1.3 Universal */
170 /* Plus GSM products */
171 { USB_DEVICE(0x0403, 0xd070) }, /* Plus GSM iPlus */
173 /* Xsens Technologies BV products */
174 { USB_DEVICE(0x0403, 0xd388) }, /* Serial interface */
175 { USB_DEVICE(0x0403, 0xd389) }, /* Serial interface */
176 { USB_DEVICE(0x0403, 0xd38a) }, /* Serial interface */
177 { USB_DEVICE(0x0403, 0xd38b) }, /* Serial interface */
178 { USB_DEVICE(0x0403, 0xd38c) }, /* Serial interface */
179 { USB_DEVICE(0x0403, 0xd38d) }, /* Serial interface */
180 { USB_DEVICE(0x0403, 0xd38e) }, /* Serial interface */
181 { USB_DEVICE(0x0403, 0xd38f) }, /* Serial interface */
183 /* Eurami Group products */
184 { USB_DEVICE(0x0403, 0xd678) }, /* Gamma Scout Online */
186 /* Westrex International products */
187 { USB_DEVICE(0x0403, 0xdc00) }, /* Model 777 */
188 { USB_DEVICE(0x0403, 0xdc01) }, /* Model 8900F */
190 /* ACG Identification GmbH products */
191 { USB_DEVICE(0x0403, 0xdd20) }, /* HF Dual ISO Reader (RFID) */
193 /* Artemis products */
194 { USB_DEVICE(0x0403, 0xdf28) }, /* CCD camera */
196 /* ATIK Instruments products */
197 { USB_DEVICE(0x0403, 0xdf30) }, /* ATK-16 Grayscale Camera */
198 { USB_DEVICE(0x0403, 0xdf31) }, /* ATK-16HR Grayscale Camera */
199 { USB_DEVICE(0x0403, 0xdf32) }, /* ATK-16C Colour Camera */
200 { USB_DEVICE(0x0403, 0xdf33) }, /* ATK-16HRC Colour Camera */
202 /* Yost Engineering, Inc. products */
203 { USB_DEVICE(0x0403, 0xe050) }, /* ServoCenter3.1 USB */
205 /* EVER Sp. products */
206 { USB_DEVICE(0x0403, 0xe520) }, /* Eco Pro UPS */
208 /* Active Robots products */
209 { USB_DEVICE(0x0403, 0xe548) }, /* Active Robots comms board */
211 /* Pyramid Computer GmbH products */
212 { USB_DEVICE(0x0403, 0xe6c8) }, /* Pyramid Appliance Display */
214 /* Gude Analog- und Digitalsysteme GmbH products */
215 { USB_DEVICE(0x0403, 0xe808) }, /* USB to serial */
216 { USB_DEVICE(0x0403, 0xe809) }, /* USB to serial */
217 { USB_DEVICE(0x0403, 0xe80a) }, /* USB to serial */
218 { USB_DEVICE(0x0403, 0xe80b) }, /* USB to serial */
219 { USB_DEVICE(0x0403, 0xe80c) }, /* USB to serial */
220 { USB_DEVICE(0x0403, 0xe80d) }, /* USB to serial */
221 { USB_DEVICE(0x0403, 0xe80e) }, /* USB to serial */
222 { USB_DEVICE(0x0403, 0xe80f) }, /* USB to serial */
223 { USB_DEVICE(0x0403, 0xe888) }, /* Expert ISDN Control USB */
224 { USB_DEVICE(0x0403, 0xe889) }, /* USB-RS232 OptoBridge */
225 { USB_DEVICE(0x0403, 0xe88a) }, /* Expert mouseCLOCK USB II */
226 { USB_DEVICE(0x0403, 0xe88b) }, /* Precision Clock MSF USB */
227 { USB_DEVICE(0x0403, 0xe88c) }, /* Expert mouseCLOCK USB II HBG */
228 { USB_DEVICE(0x0403, 0xe88d) }, /* USB to serial */
229 { USB_DEVICE(0x0403, 0xe88e) }, /* USB to serial */
230 { USB_DEVICE(0x0403, 0xe88f) }, /* USB to serial */
232 /* Eclo, Lda. products */
233 { USB_DEVICE(0x0403, 0xea90) }, /* COM to 1-Wire USB adaptor */
235 /* Coastal ChipWorks products */
236 { USB_DEVICE(0x0403, 0xebe0) }, /* TNC-X USB to packet-radio adapter */
238 /* Teratronik products */
239 { USB_DEVICE(0x0403, 0xec88) }, /* Teratronik VCP device */
241 /* MaxStream products */
242 { USB_DEVICE(0x0403, 0xee18) }, /* PKG-U RF modem */
244 /* microHAM products */
245 { USB_DEVICE(0x0403, 0xeee8) }, /* USB-KW interface */
246 { USB_DEVICE(0x0403, 0xeee9) }, /* USB-YS interface */
247 { USB_DEVICE(0x0403, 0xeeea) }, /* USB-Y6 interface */
248 { USB_DEVICE(0x0403, 0xeeeb) }, /* USB-Y8 interface */
249 { USB_DEVICE(0x0403, 0xeeec) }, /* USB-IC interface */
250 { USB_DEVICE(0x0403, 0xeeed) }, /* USB-DB9 interface */
251 { USB_DEVICE(0x0403, 0xeeee) }, /* USB-RS232 interface */
252 { USB_DEVICE(0x0403, 0xeeef) }, /* USB-Y9 interface */
255 { USB_DEVICE(0x0403, 0xf06e) }, /* ALC 8500 Expert */
256 { USB_DEVICE(0x0403, 0xf06f) }, /* FHZ 1000 PC */
258 /* Perle Systems products */
259 { USB_DEVICE(0x0403, 0xf0c0) }, /* UltraPort USB */
261 /* ACT Solutions products */
262 { USB_DEVICE(0x0403, 0xf2d0) }, /* HomePro ZWave */
264 /* 4n-galaxy.de products */
265 { USB_DEVICE(0x0403, 0xf3c0) }, /* Galaxy USB to serial */
266 { USB_DEVICE(0x0403, 0xf3c1) }, /* Galaxy USB to serial */
268 /* Linx Technologies products */
269 { USB_DEVICE(0x0403, 0xf448) }, /* Linx SDM-USB-QS-S */
270 { USB_DEVICE(0x0403, 0xf449) }, /* Linx Master Development 2.0 */
271 { USB_DEVICE(0x0403, 0xf44a) }, /* Linx USB to serial */
272 { USB_DEVICE(0x0403, 0xf44b) }, /* Linx USB to serial */
273 { USB_DEVICE(0x0403, 0xf44c) }, /* Linx USB to serial */
275 /* Suunto Oy products */
276 { USB_DEVICE(0x0403, 0xf680) }, /* Suunto Sports instrument */
279 { USB_DEVICE(0x0403, 0xf850) }, /* USB-UIRT */
281 /* CCS Inc. products */
282 { USB_DEVICE(0x0403, 0xf9d0) }, /* ICD-U20 */
283 { USB_DEVICE(0x0403, 0xf9d1) }, /* ICD-U40 */
284 { USB_DEVICE(0x0403, 0xf9d2) }, /* MACH-X */
286 /* Matrix Orbital LCD displays */
287 { USB_DEVICE(0x0403, 0xfa00) }, /* USB Serial */
288 { USB_DEVICE(0x0403, 0xfa01) }, /* MX2 or MX3 LCD */
289 { USB_DEVICE(0x0403, 0xfa02) }, /* MX4 or MX5 LCD */
290 { USB_DEVICE(0x0403, 0xfa03) }, /* LK202-24 LCD */
291 { USB_DEVICE(0x0403, 0xfa04) }, /* LK204-24 LCD */
292 { USB_DEVICE(0x0403, 0xfa05) }, /* USB Serial */
293 { USB_DEVICE(0x0403, 0xfa06) }, /* USB Serial */
295 /* Home Electronics products */
296 { USB_DEVICE(0x0403, 0xfa78) }, /* Tira-1 */
299 { USB_DEVICE(0x0403, 0xfa88) }, /* DAC-2 */
301 /* Inside.fr products */
302 { USB_DEVICE(0x0403, 0xfad0) }, /* Accesso contactless reader */
304 /* Thorlabs GmbH products */
305 { USB_DEVICE(0x0403, 0xfaf0) }, /* Motors controller */
308 { USB_DEVICE(0x0403, 0xfb58) }, /* UR 100 */
309 { USB_DEVICE(0x0403, 0xfb5a) }, /* UM 100 */
310 { USB_DEVICE(0x0403, 0xfb5b) }, /* UO 100 */
312 /* Crystalfontz products */
313 { USB_DEVICE(0x0403, 0xfc08) }, /* CFA-632 LCD */
314 { USB_DEVICE(0x0403, 0xfc09) }, /* CFA-634 LCD */
315 { USB_DEVICE(0x0403, 0xfc0a) }, /* CFA-547 LCD */
316 { USB_DEVICE(0x0403, 0xfc0b) }, /* CFA-633 LCD */
317 { USB_DEVICE(0x0403, 0xfc0c) }, /* CFA-631 LCD */
318 { USB_DEVICE(0x0403, 0xfc0d) }, /* CFA-635 LCD */
319 { USB_DEVICE(0x0403, 0xfc0e) }, /* CFA-640 LCD */
320 { USB_DEVICE(0x0403, 0xfc0f) }, /* CFA-642 LCD */
322 /* IRTrans GmbH products */
323 { USB_DEVICE(0x0403, 0xfc60) }, /* Irtrans device */
325 /* Sony Ericsson products */
326 { USB_DEVICE(0x0403, 0xfc82) }, /* DSS-20 SyncStation */
328 /* RM Michaelides Software & Elektronik GmbH products */
329 { USB_DEVICE(0x0403, 0xfd60) }, /* CANview USB */
331 /* Video Networks Limited / Homechoice products */
332 { USB_DEVICE(0x0403, 0xfe38) }, /* Homechoice broadband modem */
334 /* AlphaMicro Components products */
335 { USB_DEVICE(0x0403, 0xff00) }, /* AMC-232USB01 */
337 /* Thought Technology Ltd. products */
338 { USB_DEVICE(0x0403, 0xff20) }, /* TT-USB */
340 /* IBS elektronik products */
341 { USB_DEVICE(0x0403, 0xff38) }, /* US485 interface */
342 { USB_DEVICE(0x0403, 0xff39) }, /* PIC-Programmer */
343 { USB_DEVICE(0x0403, 0xff3a) }, /* PCMCIA SRAM-cards reader */
344 { USB_DEVICE(0x0403, 0xff3b) }, /* Particel counter PK1 */
345 { USB_DEVICE(0x0403, 0xff3c) }, /* RS232 - Monitor */
346 { USB_DEVICE(0x0403, 0xff3d) }, /* APP 70 dust monitoring */
347 { USB_DEVICE(0x0403, 0xff3e) }, /* PEDO-Modem */
348 { USB_DEVICE(0x0403, 0xff3f) }, /* Future device */
350 /* Lawicel products */
351 { USB_DEVICE(0x0403, 0xffa8) }, /* CANUSB device */
353 /* Melco, Inc products */
354 { USB_DEVICE(0x0411, 0x00b3) }, /* PC-OP-RS1 RemoteStation */
356 /* B&B Electronics products */
357 { USB_DEVICE(0x0856, 0xac01) }, /* USOTL4 */
358 { USB_DEVICE(0x0856, 0xac02) }, /* USTL4 */
359 { USB_DEVICE(0x0856, 0xac03) }, /* USO9ML2 */
360 { USB_DEVICE(0x0856, 0xac11) }, /* USOPTL4 */
361 { USB_DEVICE(0x0856, 0xac12) }, /* USPTL4 */
362 { USB_DEVICE(0x0856, 0xac16) }, /* USO9ML2DR-2 */
363 { USB_DEVICE(0x0856, 0xac17) }, /* USO9ML2DR */
364 { USB_DEVICE(0x0856, 0xac18) }, /* USOPTL4DR-2 */
365 { USB_DEVICE(0x0856, 0xac19) }, /* USOPTL4DR */
366 { USB_DEVICE(0x0856, 0xac25) }, /* 485USB9F-2W */
367 { USB_DEVICE(0x0856, 0xac26) }, /* 485USB9F-4W */
368 { USB_DEVICE(0x0856, 0xac27) }, /* 232USB9M */
370 /* Interpid Control Systems products */
371 { USB_DEVICE(0x093c, 0x0601) }, /* ValueCAN */
372 { USB_DEVICE(0x093c, 0x0701) }, /* NeoVI Blue */
374 /* ID TECH products */
375 { USB_DEVICE(0x0acd, 0x0300) }, /* USB to serial adapter */
377 /* Omnidirectional Control Technology products */
378 { USB_DEVICE(0x0b39, 0x0421) }, /* USB to serial */
380 /* Icom, Inc. products */
381 { USB_DEVICE(0x0c26, 0x0004) }, /* ID-1 */
382 { USB_DEVICE(0x0c26, 0x0009) }, /* ID-RP2C service 1 */
383 { USB_DEVICE(0x0c26, 0x000a) }, /* ID-RP2C service 2 */
384 { USB_DEVICE(0x0c26, 0x000b) }, /* ID-RP2D */
385 { USB_DEVICE(0x0c26, 0x000c) }, /* ID-RP2V service T */
386 { USB_DEVICE(0x0c26, 0x000d) }, /* ID-RP2V service R */
387 { USB_DEVICE(0x0c26, 0x0011) }, /* ID-RP4000V service R */
388 { USB_DEVICE(0x0c26, 0x0011) }, /* ID-RP4000V service T */
389 { USB_DEVICE(0x0c26, 0x0012) }, /* ID-RP2000V service T */
390 { USB_DEVICE(0x0c26, 0x0013) }, /* ID-RP2000V service R */
392 /* Sealevel products */
393 { USB_DEVICE(0x0c52, 0X2811) }, /* SeaLINK+8/232 (2801) Port 1 */
394 { USB_DEVICE(0x0c52, 0X2812) }, /* SeaLINK+8/485 (2802) Port 1 */
395 { USB_DEVICE(0x0c52, 0X2813) }, /* SeaLINK+8 (2803) Port 1 */
396 { USB_DEVICE(0x0c52, 0X2821) }, /* SeaLINK+8/232 (2801) Port 2 */
397 { USB_DEVICE(0x0c52, 0X2822) }, /* SeaLINK+8/485 (2802) Port 2 */
398 { USB_DEVICE(0x0c52, 0X2823) }, /* SeaLINK+8 (2803) Port 2 */
399 { USB_DEVICE(0x0c52, 0X2831) }, /* SeaLINK+8/232 (2801) Port 3 */
400 { USB_DEVICE(0x0c52, 0X2832) }, /* SeaLINK+8/485 (2802) Port 3 */
401 { USB_DEVICE(0x0c52, 0X2833) }, /* SeaLINK+8 (2803) Port 3 */
402 { USB_DEVICE(0x0c52, 0X2841) }, /* SeaLINK+8/232 (2801) Port 4 */
403 { USB_DEVICE(0x0c52, 0X2842) }, /* SeaLINK+8/485 (2802) Port 4 */
404 { USB_DEVICE(0x0c52, 0X2843) }, /* SeaLINK+8 (2803) Port 4 */
405 { USB_DEVICE(0x0c52, 0X2851) }, /* SeaLINK+8/232 (2801) Port 5 */
406 { USB_DEVICE(0x0c52, 0X2852) }, /* SeaLINK+8/485 (2802) Port 5 */
407 { USB_DEVICE(0x0c52, 0X2853) }, /* SeaLINK+8 (2803) Port 5 */
408 { USB_DEVICE(0x0c52, 0X2861) }, /* SeaLINK+8/232 (2801) Port 6 */
409 { USB_DEVICE(0x0c52, 0X2862) }, /* SeaLINK+8/485 (2802) Port 6 */
410 { USB_DEVICE(0x0c52, 0X2863) }, /* SeaLINK+8 (2803) Port 6 */
411 { USB_DEVICE(0x0c52, 0X2871) }, /* SeaLINK+8/232 (2801) Port 7 */
412 { USB_DEVICE(0x0c52, 0X2872) }, /* SeaLINK+8/485 (2802) Port 7 */
413 { USB_DEVICE(0x0c52, 0X2873) }, /* SeaLINK+8 (2803) Port 7 */
414 { USB_DEVICE(0x0c52, 0X2881) }, /* SeaLINK+8/232 (2801) Port 8 */
415 { USB_DEVICE(0x0c52, 0X2882) }, /* SeaLINK+8/485 (2802) Port 8 */
416 { USB_DEVICE(0x0c52, 0X2883) }, /* SeaLINK+8 (2803) Port 8 */
417 { USB_DEVICE(0x0c52, 0x2101) }, /* SeaLINK+232 (2101/2105) */
418 { USB_DEVICE(0x0c52, 0x2102) }, /* SeaLINK+485 (2102) */
419 { USB_DEVICE(0x0c52, 0x2103) }, /* SeaLINK+232I (2103) */
420 { USB_DEVICE(0x0c52, 0x2104) }, /* SeaLINK+485I (2104) */
421 { USB_DEVICE(0x0c52, 0x2211) }, /* SeaPORT+2/232 (2201) Port 1 */
422 { USB_DEVICE(0x0c52, 0x2212) }, /* SeaPORT+2/485 (2202) Port 1 */
423 { USB_DEVICE(0x0c52, 0x2213) }, /* SeaPORT+2 (2203) Port 1 */
424 { USB_DEVICE(0x0c52, 0x2221) }, /* SeaPORT+2/232 (2201) Port 2 */
425 { USB_DEVICE(0x0c52, 0x2222) }, /* SeaPORT+2/485 (2202) Port 2 */
426 { USB_DEVICE(0x0c52, 0x2223) }, /* SeaPORT+2 (2203) Port 2 */
427 { USB_DEVICE(0x0c52, 0x2411) }, /* SeaPORT+4/232 (2401) Port 1 */
428 { USB_DEVICE(0x0c52, 0x2412) }, /* SeaPORT+4/485 (2402) Port 1 */
429 { USB_DEVICE(0x0c52, 0x2413) }, /* SeaPORT+4 (2403) Port 1 */
430 { USB_DEVICE(0x0c52, 0x2421) }, /* SeaPORT+4/232 (2401) Port 2 */
431 { USB_DEVICE(0x0c52, 0x2422) }, /* SeaPORT+4/485 (2402) Port 2 */
432 { USB_DEVICE(0x0c52, 0x2423) }, /* SeaPORT+4 (2403) Port 2 */
433 { USB_DEVICE(0x0c52, 0x2431) }, /* SeaPORT+4/232 (2401) Port 3 */
434 { USB_DEVICE(0x0c52, 0x2432) }, /* SeaPORT+4/485 (2402) Port 3 */
435 { USB_DEVICE(0x0c52, 0x2433) }, /* SeaPORT+4 (2403) Port 3 */
436 { USB_DEVICE(0x0c52, 0x2441) }, /* SeaPORT+4/232 (2401) Port 4 */
437 { USB_DEVICE(0x0c52, 0x2442) }, /* SeaPORT+4/485 (2402) Port 4 */
438 { USB_DEVICE(0x0c52, 0x2443) }, /* SeaPORT+4 (2403) Port 4 */
439 { USB_DEVICE(0x0c52, 0x9020) }, /* SeaLINK+422 (2106) */
441 /* Posiflex Technologies products */
442 { USB_DEVICE(0x0d3a, 0x0300) }, /* PP7000 series printer */
443 { USB_DEVICE(0x0d3a, 0x0400) }, /* PP7000 series printer */
445 /* Kobil Systems products */
446 { USB_DEVICE(0x0d46, 0x2020) }, /* Konverter for B1 */
447 { USB_DEVICE(0x0d46, 0x2021) }, /* Konverter for KAAN */
449 /* Falcom Wireless Communications products */
450 { USB_DEVICE(0x0f94, 0x0001) }, /* Twist USB GPRS modem */
451 { USB_DEVICE(0x0f94, 0x0005) }, /* Samba USB GPRS modem */
453 /* Thurlby Thandar Instruments products */
454 { USB_DEVICE(0x103e, 0x03e8) }, /* QL355P power supply */
456 /* InterBiometrics products */
457 { USB_DEVICE(0x1209, 0x1002) }, /* IO Board */
458 { USB_DEVICE(0x1209, 0x1006) }, /* Mini IO Board */
460 /* Testo AG products */
461 { USB_DEVICE(0x128d, 0x0001) }, /* 175/177 USB interface */
462 { USB_DEVICE(0x128d, 0x0002) }, /* 330 USB interface */
463 { USB_DEVICE(0x128d, 0x0003) }, /* 435/635/735 USB interface */
464 { USB_DEVICE(0x128d, 0x0004) }, /* 845 USB interface */
465 { USB_DEVICE(0x128d, 0x0005) }, /* Service adapter */
466 { USB_DEVICE(0x128d, 0x0006) }, /* 580 USB interface */
467 { USB_DEVICE(0x128d, 0x0007) }, /* 174 USB interface */
468 { USB_DEVICE(0x128d, 0x0009) }, /* 556/560 USB interface */
469 { USB_DEVICE(0x128d, 0x000a) }, /* USB adapter */
470 { USB_DEVICE(0x128d, 0xf001) }, /* USB to serial converter */
472 /* Mobility products */
473 { USB_DEVICE(0x1342, 0x0202) }, /* EasiDock 200 serial port */
475 /* Papouch s.r.o. products */
476 { USB_DEVICE(0x5050, 0x0100) }, /* SB485 USB-485/422 Converter */
477 { USB_DEVICE(0x5050, 0x0101) }, /* AP485 USB-RS485 Converter */
478 { USB_DEVICE(0x5050, 0x0102) }, /* SB422 USB-RS422 Converter */
479 { USB_DEVICE(0x5050, 0x0103) }, /* SB485 USB-485/422 Converter */
480 { USB_DEVICE(0x5050, 0x0104) }, /* AP485 USB-RS485 Converter */
481 { USB_DEVICE(0x5050, 0x0105) }, /* SB422 USB-RS422 Converter */
482 { USB_DEVICE(0x5050, 0x0106) }, /* SB485S USB-485/422 Converter */
483 { USB_DEVICE(0x5050, 0x0107) }, /* SB485C USB-485/422 Converter */
484 { USB_DEVICE(0x5050, 0x0200) }, /* USB Device */
485 { USB_DEVICE(0x5050, 0x0300) }, /* LEC USB Converter */
486 { USB_DEVICE(0x5050, 0x0301) }, /* SB232 USB-RS232 Converter */
487 { USB_DEVICE(0x5050, 0x0400) }, /* TMU Thermometer */
488 { USB_DEVICE(0x5050, 0x0500) }, /* IRAmp Duplex */
489 { USB_DEVICE(0x5050, 0x0700) }, /* DRAK5 */
490 { USB_DEVICE(0x5050, 0x0800) }, /* QUIDO USB 8/8 */
491 { USB_DEVICE(0x5050, 0x0900) }, /* QUIDO USB 4/4 */
492 { USB_DEVICE(0x5050, 0x0A00) }, /* QUIDO USB 2/2 */
493 { USB_DEVICE(0x5050, 0x0B00) }, /* QUIDO USB 10/1 */
494 { USB_DEVICE(0x5050, 0x0C00) }, /* QUIDO USB 30/3 */
495 { USB_DEVICE(0x5050, 0x0D00) }, /* QUIDO USB 60(100)/3 */
496 { USB_DEVICE(0x5050, 0x0E00) }, /* QUIDO USB 2/16 */
497 { USB_DEVICE(0x5050, 0x0F00) }, /* QUIDO USB 3/32 */
498 { USB_DEVICE(0x5050, 0x1000) }, /* DRAK6 USB */
499 { USB_DEVICE(0x5050, 0x8000) }, /* UPS-USB Stavovy Adapter */
500 { USB_DEVICE(0x5050, 0x8001) }, /* MU Controller */
501 { USB_DEVICE(0x5050, 0x8002) }, /* SimuKey */
502 { USB_DEVICE(0x5050, 0x8003) }, /* AD4USB */
503 { USB_DEVICE(0x5050, 0x8004) }, /* GOLIATH MUX */
504 { USB_DEVICE(0x5050, 0x8005) }, /* GOLIATH MSR */
506 /* Evolution Robotics, Inc. products */
507 { USB_DEVICE(0xdeee, 0x0300) }, /* ER1 Control Module */
508 { USB_DEVICE(0xdeee, 0x0302) }, /* RCM4 interface */
509 { USB_DEVICE(0xdeee, 0x0303) }, /* RCM4 interface */
513 uftdi_match(device_t self)
515 struct usb_attach_arg *uaa = device_get_ivars(self);
517 if (uaa->iface == NULL)
518 return (UMATCH_NONE);
520 if (usb_lookup(uftdi_devs, uaa->vendor, uaa->product) != NULL)
521 return (UMATCH_VENDOR_IFACESUBCLASS);
523 return (UMATCH_NONE);
527 uftdi_attach(device_t self)
529 struct uftdi_softc *sc = device_get_softc(self);
530 struct usb_attach_arg *uaa = device_get_ivars(self);
531 usbd_device_handle dev = uaa->device;
532 usbd_interface_handle iface;
533 usb_interface_descriptor_t *id;
534 usb_endpoint_descriptor_t *ed;
536 struct ucom_softc *ucom = &sc->sc_ucom;
537 DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
543 id = usbd_get_interface_descriptor(iface);
544 ucom->sc_iface = iface;
546 if (uaa->release < 0x0200) {
547 sc->sc_type = UFTDI_TYPE_SIO;
550 sc->sc_type = UFTDI_TYPE_8U232AM;
554 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
556 for (i = 0; i < id->bNumEndpoints; i++) {
558 ed = usbd_interface2endpoint_descriptor(iface, i);
560 device_printf(ucom->sc_dev,
561 "could not read endpoint descriptor\n");
565 addr = ed->bEndpointAddress;
566 dir = UE_GET_DIR(ed->bEndpointAddress);
567 attr = ed->bmAttributes & UE_XFERTYPE;
568 if (dir == UE_DIR_IN && attr == UE_BULK)
569 ucom->sc_bulkin_no = addr;
570 else if (dir == UE_DIR_OUT && attr == UE_BULK)
571 ucom->sc_bulkout_no = addr;
573 device_printf(ucom->sc_dev, "unexpected endpoint\n");
577 if (ucom->sc_bulkin_no == -1) {
578 device_printf(ucom->sc_dev, "Could not find data bulk in\n");
581 if (ucom->sc_bulkout_no == -1) {
582 device_printf(ucom->sc_dev, "Could not find data bulk out\n");
585 ucom->sc_parent = sc;
586 ucom->sc_portno = FTDI_PIT_SIOA + id->bInterfaceNumber;
587 /* bulkin, bulkout set above */
589 ucom->sc_ibufsize = UFTDIIBUFSIZE;
590 ucom->sc_obufsize = UFTDIOBUFSIZE - sc->sc_hdrlen;
591 ucom->sc_ibufsizepad = UFTDIIBUFSIZE;
592 ucom->sc_opkthdrlen = sc->sc_hdrlen;
595 ucom->sc_callback = &uftdi_callback;
597 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
600 DPRINTF(("uftdi: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no));
601 ucom_attach(&sc->sc_ucom);
605 DPRINTF(("uftdi_attach: ATTACH ERROR\n"));
611 uftdi_activate(device_t self, enum devact act)
613 struct uftdi_softc *sc = (struct uftdi_softc *)self;
620 case DVACT_DEACTIVATE:
621 if (sc->sc_subdev != NULL)
622 rv = config_deactivate(sc->sc_subdev);
623 sc->sc_ucom.sc_dying = 1;
631 uftdi_detach(device_t self)
633 struct uftdi_softc *sc = device_get_softc(self);
637 DPRINTF(("uftdi_detach: sc=%p\n", sc));
638 sc->sc_ucom.sc_dying = 1;
639 rv = ucom_detach(&sc->sc_ucom);
645 uftdi_open(void *vsc, int portno)
647 struct uftdi_softc *sc = vsc;
648 struct ucom_softc *ucom = &sc->sc_ucom;
649 usb_device_request_t req;
653 DPRINTF(("uftdi_open: sc=%p\n", sc));
658 /* Perform a full reset on the device */
659 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
660 req.bRequest = FTDI_SIO_RESET;
661 USETW(req.wValue, FTDI_SIO_RESET_SIO);
662 USETW(req.wIndex, portno);
663 USETW(req.wLength, 0);
664 err = usbd_do_request(ucom->sc_udev, &req, NULL);
668 /* Set 9600 baud, 2 stop bits, no parity, 8 bits */
670 t.c_cflag = CSTOPB | CS8;
671 (void)uftdi_param(sc, portno, &t);
673 /* Turn on RTS/CTS flow control */
674 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
675 req.bRequest = FTDI_SIO_SET_FLOW_CTRL;
676 USETW(req.wValue, 0);
677 USETW2(req.wIndex, FTDI_SIO_RTS_CTS_HS, portno);
678 USETW(req.wLength, 0);
679 err = usbd_do_request(ucom->sc_udev, &req, NULL);
687 uftdi_read(void *vsc, int portno, u_char **ptr, u_int32_t *count)
689 struct uftdi_softc *sc = vsc;
692 DPRINTFN(15,("uftdi_read: sc=%p, port=%d count=%d\n", sc, portno,
695 msr = FTDI_GET_MSR(*ptr);
696 lsr = FTDI_GET_LSR(*ptr);
700 DPRINTFN(10,("uftdi_read: sc=%p, port=%d count=%d data[0]="
701 "0x%02x\n", sc, portno, *count, (*ptr)[2]));
704 if (sc->sc_msr != msr ||
705 (sc->sc_lsr & FTDI_LSR_MASK) != (lsr & FTDI_LSR_MASK)) {
706 DPRINTF(("uftdi_read: status change msr=0x%02x(0x%02x) "
707 "lsr=0x%02x(0x%02x)\n", msr, sc->sc_msr,
711 ucom_status_change(&sc->sc_ucom);
714 /* Pick up status and adjust data part. */
720 uftdi_write(void *vsc, int portno, u_char *to, u_char *from, u_int32_t *count)
722 struct uftdi_softc *sc = vsc;
724 DPRINTFN(10,("uftdi_write: sc=%p, port=%d count=%u data[0]=0x%02x\n",
725 vsc, portno, *count, from[0]));
727 /* Make length tag and copy data */
728 if (sc->sc_hdrlen > 0)
729 *to = FTDI_OUT_TAG(*count, portno);
731 memcpy(to + sc->sc_hdrlen, from, *count);
732 *count += sc->sc_hdrlen;
736 uftdi_set(void *vsc, int portno, int reg, int onoff)
738 struct uftdi_softc *sc = vsc;
739 struct ucom_softc *ucom = vsc;
740 usb_device_request_t req;
743 DPRINTF(("uftdi_set: sc=%p, port=%d reg=%d onoff=%d\n", vsc, portno,
748 ctl = onoff ? FTDI_SIO_SET_DTR_HIGH : FTDI_SIO_SET_DTR_LOW;
751 ctl = onoff ? FTDI_SIO_SET_RTS_HIGH : FTDI_SIO_SET_RTS_LOW;
754 uftdi_break(sc, portno, onoff);
759 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
760 req.bRequest = FTDI_SIO_MODEM_CTRL;
761 USETW(req.wValue, ctl);
762 USETW(req.wIndex, portno);
763 USETW(req.wLength, 0);
764 DPRINTFN(2,("uftdi_set: reqtype=0x%02x req=0x%02x value=0x%04x "
765 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
766 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
767 (void)usbd_do_request(ucom->sc_udev, &req, NULL);
771 uftdi_param(void *vsc, int portno, struct termios *t)
773 struct uftdi_softc *sc = vsc;
774 struct ucom_softc *ucom = &sc->sc_ucom;
775 usb_device_request_t req;
777 int rate=0, data, flow;
779 DPRINTF(("uftdi_param: sc=%p\n", sc));
784 switch (sc->sc_type) {
786 switch (t->c_ospeed) {
787 case 300: rate = ftdi_sio_b300; break;
788 case 600: rate = ftdi_sio_b600; break;
789 case 1200: rate = ftdi_sio_b1200; break;
790 case 2400: rate = ftdi_sio_b2400; break;
791 case 4800: rate = ftdi_sio_b4800; break;
792 case 9600: rate = ftdi_sio_b9600; break;
793 case 19200: rate = ftdi_sio_b19200; break;
794 case 38400: rate = ftdi_sio_b38400; break;
795 case 57600: rate = ftdi_sio_b57600; break;
796 case 115200: rate = ftdi_sio_b115200; break;
802 case UFTDI_TYPE_8U232AM:
803 if (uftdi_8u232am_getrate(t->c_ospeed, &rate) == -1)
807 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
808 req.bRequest = FTDI_SIO_SET_BAUD_RATE;
809 USETW(req.wValue, rate);
810 USETW(req.wIndex, portno);
811 USETW(req.wLength, 0);
812 DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
813 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
814 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
815 err = usbd_do_request(ucom->sc_udev, &req, NULL);
819 if (ISSET(t->c_cflag, CSTOPB))
820 data = FTDI_SIO_SET_DATA_STOP_BITS_2;
822 data = FTDI_SIO_SET_DATA_STOP_BITS_1;
823 if (ISSET(t->c_cflag, PARENB)) {
824 if (ISSET(t->c_cflag, PARODD))
825 data |= FTDI_SIO_SET_DATA_PARITY_ODD;
827 data |= FTDI_SIO_SET_DATA_PARITY_EVEN;
829 data |= FTDI_SIO_SET_DATA_PARITY_NONE;
830 switch (ISSET(t->c_cflag, CSIZE)) {
832 data |= FTDI_SIO_SET_DATA_BITS(5);
835 data |= FTDI_SIO_SET_DATA_BITS(6);
838 data |= FTDI_SIO_SET_DATA_BITS(7);
841 data |= FTDI_SIO_SET_DATA_BITS(8);
846 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
847 req.bRequest = FTDI_SIO_SET_DATA;
848 USETW(req.wValue, data);
849 USETW(req.wIndex, portno);
850 USETW(req.wLength, 0);
851 DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
852 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
853 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
854 err = usbd_do_request(ucom->sc_udev, &req, NULL);
858 if (ISSET(t->c_cflag, CRTSCTS)) {
859 flow = FTDI_SIO_RTS_CTS_HS;
860 USETW(req.wValue, 0);
861 } else if (ISSET(t->c_iflag, IXON|IXOFF)) {
862 flow = FTDI_SIO_XON_XOFF_HS;
863 USETW2(req.wValue, t->c_cc[VSTOP], t->c_cc[VSTART]);
865 flow = FTDI_SIO_DISABLE_FLOW_CTRL;
866 USETW(req.wValue, 0);
868 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
869 req.bRequest = FTDI_SIO_SET_FLOW_CTRL;
870 USETW2(req.wIndex, flow, portno);
871 USETW(req.wLength, 0);
872 err = usbd_do_request(ucom->sc_udev, &req, NULL);
880 uftdi_get_status(void *vsc, int portno, u_char *lsr, u_char *msr)
882 struct uftdi_softc *sc = vsc;
884 DPRINTF(("uftdi_status: msr=0x%02x lsr=0x%02x\n",
885 sc->sc_msr, sc->sc_lsr));
894 uftdi_break(void *vsc, int portno, int onoff)
896 struct uftdi_softc *sc = vsc;
897 struct ucom_softc *ucom = vsc;
899 usb_device_request_t req;
902 DPRINTF(("uftdi_break: sc=%p, port=%d onoff=%d\n", vsc, portno,
906 data = sc->last_lcr | FTDI_SIO_SET_BREAK;
911 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
912 req.bRequest = FTDI_SIO_SET_DATA;
913 USETW(req.wValue, data);
914 USETW(req.wIndex, portno);
915 USETW(req.wLength, 0);
916 (void)usbd_do_request(ucom->sc_udev, &req, NULL);
920 uftdi_8u232am_getrate(speed_t speed, int *rate)
922 /* Table of the nearest even powers-of-2 for values 0..15. */
923 static const unsigned char roundoff[16] = {
924 0, 2, 2, 4, 4, 4, 8, 8,
925 8, 8, 8, 8, 16, 16, 16, 16,
928 unsigned int d, freq;
934 /* Special cases for 2M and 3M. */
935 if (speed >= 3000000 * 100 / 103 &&
936 speed <= 3000000 * 100 / 97) {
940 if (speed >= 2000000 * 100 / 103 &&
941 speed <= 2000000 * 100 / 97) {
946 d = (FTDI_8U232AM_FREQ << 4) / speed;
947 d = (d & ~15) + roundoff[d & 15];
949 if (d < FTDI_8U232AM_MIN_DIV)
950 d = FTDI_8U232AM_MIN_DIV;
951 else if (d > FTDI_8U232AM_MAX_DIV)
952 d = FTDI_8U232AM_MAX_DIV;
955 * Calculate the frequency needed for d to exactly divide down
956 * to our target speed, and check that the actual frequency is
960 if (freq < (quad_t)(FTDI_8U232AM_FREQ << 4) * 100 / 103 ||
961 freq > (quad_t)(FTDI_8U232AM_FREQ << 4) * 100 / 97)
965 * Pack the divisor into the resultant value. The lower
966 * 14-bits hold the integral part, while the upper 2 bits
967 * encode the fractional component: either 0, 0.5, 0.25, or
982 static device_method_t uftdi_methods[] = {
983 /* Device interface */
984 DEVMETHOD(device_probe, uftdi_match),
985 DEVMETHOD(device_attach, uftdi_attach),
986 DEVMETHOD(device_detach, uftdi_detach),
991 static driver_t uftdi_driver = {
994 sizeof (struct uftdi_softc)
997 DRIVER_MODULE(uftdi, uhub, uftdi_driver, ucom_devclass, usbd_driver_load, NULL);
998 MODULE_DEPEND(uftdi, usb, 1, 1, 1);
999 MODULE_DEPEND(uftdi, ucom,UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);