xref: /openbmc/linux/drivers/usb/serial/ftdi_sio.c (revision 4a90f09b20f4622dcbff1f0e1e6bae1704f8ad8c)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * USB FTDI SIO driver
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *	Copyright (C) 1999 - 2001
51da177e4SLinus Torvalds  *	    Greg Kroah-Hartman (greg@kroah.com)
61da177e4SLinus Torvalds  *          Bill Ryder (bryder@sgi.com)
71da177e4SLinus Torvalds  *	Copyright (C) 2002
81da177e4SLinus Torvalds  *	    Kuba Ober (kuba@mareimbrium.org)
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  *	This program is free software; you can redistribute it and/or modify
111da177e4SLinus Torvalds  *	it under the terms of the GNU General Public License as published by
121da177e4SLinus Torvalds  *	the Free Software Foundation; either version 2 of the License, or
131da177e4SLinus Torvalds  *	(at your option) any later version.
141da177e4SLinus Torvalds  *
15464cbb24SAlan Cox  * See Documentation/usb/usb-serial.txt for more information on using this
16464cbb24SAlan Cox  * driver
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
191da177e4SLinus Torvalds  *	and extra documentation
201da177e4SLinus Torvalds  *
21504b55ccSGreg Kroah-Hartman  * Change entries from 2004 and earlier can be found in versions of this
22504b55ccSGreg Kroah-Hartman  * file in kernel versions prior to the 2.6.24 release.
231da177e4SLinus Torvalds  *
241da177e4SLinus Torvalds  */
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds /* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */
271da177e4SLinus Torvalds /* Thanx to FTDI for so kindly providing details of the protocol required */
281da177e4SLinus Torvalds /*   to talk to the device */
29464cbb24SAlan Cox /* Thanx to gkh and the rest of the usb dev group for all code I have
30464cbb24SAlan Cox    assimilated :-) */
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds #include <linux/kernel.h>
331da177e4SLinus Torvalds #include <linux/errno.h>
341da177e4SLinus Torvalds #include <linux/init.h>
351da177e4SLinus Torvalds #include <linux/slab.h>
361da177e4SLinus Torvalds #include <linux/tty.h>
371da177e4SLinus Torvalds #include <linux/tty_driver.h>
381da177e4SLinus Torvalds #include <linux/tty_flip.h>
391da177e4SLinus Torvalds #include <linux/module.h>
401da177e4SLinus Torvalds #include <linux/spinlock.h>
41464cbb24SAlan Cox #include <linux/uaccess.h>
421da177e4SLinus Torvalds #include <linux/usb.h>
431da177e4SLinus Torvalds #include <linux/serial.h>
44a969888cSGreg Kroah-Hartman #include <linux/usb/serial.h>
451da177e4SLinus Torvalds #include "ftdi_sio.h"
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds /*
481da177e4SLinus Torvalds  * Version Information
491da177e4SLinus Torvalds  */
508f977e42SIan Abbott #define DRIVER_VERSION "v1.4.3"
511da177e4SLinus Torvalds #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>"
521da177e4SLinus Torvalds #define DRIVER_DESC "USB FTDI Serial Converters Driver"
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds static int debug;
55fdcb0a0fSIan Abbott static __u16 vendor = FTDI_VID;
56fdcb0a0fSIan Abbott static __u16 product;
571da177e4SLinus Torvalds 
580ffbbe25SOliver Neukum struct ftdi_private {
590ffbbe25SOliver Neukum 	ftdi_chip_type_t chip_type;
60464cbb24SAlan Cox 				/* type of device, either SIO or FT8U232AM */
610ffbbe25SOliver Neukum 	int baud_base;		/* baud base clock for divisor setting */
62464cbb24SAlan Cox 	int custom_divisor;	/* custom_divisor kludge, this is for
63464cbb24SAlan Cox 				   baud_base (different from what goes to the
64464cbb24SAlan Cox 				   chip!) */
650ffbbe25SOliver Neukum 	__u16 last_set_data_urb_value ;
66464cbb24SAlan Cox 				/* the last data state set - needed for doing
67464cbb24SAlan Cox 				 * a break
68464cbb24SAlan Cox 				 */
69464cbb24SAlan Cox 	int write_offset;       /* This is the offset in the usb data block to
70464cbb24SAlan Cox 				 * write the serial data - it varies between
71464cbb24SAlan Cox 				 * devices
720ffbbe25SOliver Neukum 				 */
730ffbbe25SOliver Neukum 	int flags;		/* some ASYNC_xxxx flags are supported */
740ffbbe25SOliver Neukum 	unsigned long last_dtr_rts;	/* saved modem control outputs */
750ffbbe25SOliver Neukum 	wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
760ffbbe25SOliver Neukum 	char prev_status, diff_status;        /* Used for TIOCMIWAIT */
770ffbbe25SOliver Neukum 	__u8 rx_flags;		/* receive state flags (throttling) */
780ffbbe25SOliver Neukum 	spinlock_t rx_lock;	/* spinlock for receive state */
790ffbbe25SOliver Neukum 	struct delayed_work rx_work;
800ffbbe25SOliver Neukum 	struct usb_serial_port *port;
810ffbbe25SOliver Neukum 	int rx_processed;
820ffbbe25SOliver Neukum 	unsigned long rx_bytes;
830ffbbe25SOliver Neukum 
840ffbbe25SOliver Neukum 	__u16 interface;	/* FT2232C port interface (0 for FT232/245) */
850ffbbe25SOliver Neukum 
86464cbb24SAlan Cox 	speed_t force_baud;	/* if non-zero, force the baud rate to
87464cbb24SAlan Cox 				   this value */
88464cbb24SAlan Cox 	int force_rtscts;	/* if non-zero, force RTS-CTS to always
89464cbb24SAlan Cox 				   be enabled */
900ffbbe25SOliver Neukum 
910ffbbe25SOliver Neukum 	spinlock_t tx_lock;	/* spinlock for transmit state */
920ffbbe25SOliver Neukum 	unsigned long tx_bytes;
930ffbbe25SOliver Neukum 	unsigned long tx_outstanding_bytes;
940ffbbe25SOliver Neukum 	unsigned long tx_outstanding_urbs;
950ffbbe25SOliver Neukum };
960ffbbe25SOliver Neukum 
978f977e42SIan Abbott /* struct ftdi_sio_quirk is used by devices requiring special attention. */
988f977e42SIan Abbott struct ftdi_sio_quirk {
99fa91d43bSTony Lindgren 	int (*probe)(struct usb_serial *);
100464cbb24SAlan Cox 	/* Special settings for probed ports. */
101464cbb24SAlan Cox 	void (*port_probe)(struct ftdi_private *);
1028f977e42SIan Abbott };
1038f977e42SIan Abbott 
10420734345SHarald Welte static int   ftdi_jtag_probe(struct usb_serial *serial);
105546d7eecSKevin Vance static int   ftdi_mtxorb_hack_setup(struct usb_serial *serial);
1060ffbbe25SOliver Neukum static void  ftdi_USB_UIRT_setup(struct ftdi_private *priv);
1070ffbbe25SOliver Neukum static void  ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
1088f977e42SIan Abbott 
10920734345SHarald Welte static struct ftdi_sio_quirk ftdi_jtag_quirk = {
11020734345SHarald Welte 	.probe	= ftdi_jtag_probe,
111fa91d43bSTony Lindgren };
112fa91d43bSTony Lindgren 
113546d7eecSKevin Vance static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
114546d7eecSKevin Vance 	.probe  = ftdi_mtxorb_hack_setup,
115546d7eecSKevin Vance };
116546d7eecSKevin Vance 
1178f977e42SIan Abbott static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
1180ffbbe25SOliver Neukum 	.port_probe = ftdi_USB_UIRT_setup,
1198f977e42SIan Abbott };
1208f977e42SIan Abbott 
1218f977e42SIan Abbott static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
1220ffbbe25SOliver Neukum 	.port_probe = ftdi_HE_TIRA1_setup,
1231da177e4SLinus Torvalds };
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds /*
1261da177e4SLinus Torvalds  * The 8U232AM has the same API as the sio except for:
1271da177e4SLinus Torvalds  * - it can support MUCH higher baudrates; up to:
1281da177e4SLinus Torvalds  *   o 921600 for RS232 and 2000000 for RS422/485 at 48MHz
1291da177e4SLinus Torvalds  *   o 230400 at 12MHz
1301da177e4SLinus Torvalds  *   so .. 8U232AM's baudrate setting codes are different
1311da177e4SLinus Torvalds  * - it has a two byte status code.
1321da177e4SLinus Torvalds  * - it returns characters every 16ms (the FTDI does it every 40ms)
1331da177e4SLinus Torvalds  *
1341da177e4SLinus Torvalds  * the bcdDevice value is used to differentiate FT232BM and FT245BM from
1351da177e4SLinus Torvalds  * the earlier FT8U232AM and FT8U232BM.  For now, include all known VID/PID
1361da177e4SLinus Torvalds  * combinations in both tables.
1378f977e42SIan Abbott  * FIXME: perhaps bcdDevice can also identify 12MHz FT8U232AM devices,
1388f977e42SIan Abbott  * but I don't know if those ever went into mass production. [Ian Abbott]
1391da177e4SLinus Torvalds  */
1401da177e4SLinus Torvalds 
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds static struct usb_device_id id_table_combined [] = {
1442011e924SJonathan Davies 	{ USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) },
1452011e924SJonathan Davies 	{ USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
1466e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) },
1476e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) },
1486e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) },
1496e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_3_PID) },
1506e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_4_PID) },
1516e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) },
1526e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) },
1536e1ab3edSPeter Mack 	{ USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) },
15472a9f958SRazvan Gavril 	{ USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) },
1551da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
15669737dfaSLuiz Fernando N. Capitulino 	{ USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) },
157d099321bSLuiz Fernando N. Capitulino 	{ USB_DEVICE(FTDI_VID, FTDI_IPLUS2_PID) },
158fad14a0dSFrank Sievertsen 	{ USB_DEVICE(FTDI_VID, FTDI_DMX4ALL) },
1591da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_SIO_PID) },
1601da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) },
1611da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) },
162d8b21606SGard Spreemann 	{ USB_DEVICE(FTDI_VID, FTDI_232RL_PID) },
1631da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
164c0f8d561SChristophe Mariac 	{ USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
1651da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
1662adb80e9SGuido Scholz 	{ USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) },
1671da177e4SLinus Torvalds 	{ USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
1681da177e4SLinus Torvalds 	{ USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
1691da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_632_PID) },
1701da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_634_PID) },
1711da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_547_PID) },
1721da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_633_PID) },
1731da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_631_PID) },
1741da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_635_PID) },
1751da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_640_PID) },
1761da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_XF_642_PID) },
1771da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) },
1781da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) },
1791da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) },
1808f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MTXORB_0_PID) },
1818f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MTXORB_1_PID) },
1828f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MTXORB_2_PID) },
1838f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MTXORB_3_PID) },
1848f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) },
1858f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
1868f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
187ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) },
188ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) },
189ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) },
190ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0103_PID) },
191ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0104_PID) },
192ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0105_PID) },
193ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0106_PID) },
194ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0107_PID) },
195ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0108_PID) },
196ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0109_PID) },
197ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010A_PID) },
198ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010B_PID) },
199ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010C_PID) },
200ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010D_PID) },
201ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010E_PID) },
202ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_010F_PID) },
203ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0110_PID) },
204ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0111_PID) },
205ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0112_PID) },
206ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0113_PID) },
207ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0114_PID) },
208ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0115_PID) },
209ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0116_PID) },
210ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0117_PID) },
211ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0118_PID) },
212ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0119_PID) },
213ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011A_PID) },
214ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011B_PID) },
215ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011C_PID) },
216ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011D_PID) },
217ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011E_PID) },
218ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_011F_PID) },
219ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0120_PID) },
220ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0121_PID) },
221ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0122_PID) },
222ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0123_PID) },
223ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0124_PID) },
224ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0125_PID) },
225ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0126_PID) },
226ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0127_PID),
227546d7eecSKevin Vance 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
228ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0128_PID) },
229ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0129_PID) },
230ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012A_PID) },
231ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012B_PID) },
232ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012C_PID),
233ebb3770cSRay Molenkamp 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
234ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012D_PID) },
235ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012E_PID) },
236ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_012F_PID) },
237ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0130_PID) },
238ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0131_PID) },
239ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0132_PID) },
240ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0133_PID) },
241ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0134_PID) },
242ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0135_PID) },
243ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0136_PID) },
244ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0137_PID) },
245ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0138_PID) },
246ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0139_PID) },
247ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013A_PID) },
248ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013B_PID) },
249ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013C_PID) },
250ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013D_PID) },
251ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013E_PID) },
252ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_013F_PID) },
253ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0140_PID) },
254ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0141_PID) },
255ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0142_PID) },
256ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0143_PID) },
257ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0144_PID) },
258ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0145_PID) },
259ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0146_PID) },
260ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0147_PID) },
261ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0148_PID) },
262ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0149_PID) },
263ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014A_PID) },
264ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014B_PID) },
265ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014C_PID) },
266ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014D_PID) },
267ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014E_PID) },
268ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_014F_PID) },
269ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0150_PID) },
270ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0151_PID) },
271ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0152_PID) },
272ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0153_PID),
273ebb3770cSRay Molenkamp 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
274ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0154_PID),
275ebb3770cSRay Molenkamp 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
276ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0155_PID),
277ebb3770cSRay Molenkamp 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
278ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0156_PID),
279ebb3770cSRay Molenkamp 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
280ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0157_PID),
281ebb3770cSRay Molenkamp 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
282ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0158_PID),
283ebb3770cSRay Molenkamp 		.driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
284ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0159_PID) },
285ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015A_PID) },
286ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015B_PID) },
287ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015C_PID) },
288ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015D_PID) },
289ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015E_PID) },
290ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_015F_PID) },
291ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0160_PID) },
292ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0161_PID) },
293ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0162_PID) },
294ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0163_PID) },
295ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0164_PID) },
296ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0165_PID) },
297ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0166_PID) },
298ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0167_PID) },
299ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0168_PID) },
300ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0169_PID) },
301ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016A_PID) },
302ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016B_PID) },
303ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016C_PID) },
304ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016D_PID) },
305ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016E_PID) },
306ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_016F_PID) },
307ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0170_PID) },
308ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0171_PID) },
309ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0172_PID) },
310ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0173_PID) },
311ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0174_PID) },
312ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0175_PID) },
313ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0176_PID) },
314ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0177_PID) },
315ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0178_PID) },
316ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0179_PID) },
317ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017A_PID) },
318ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017B_PID) },
319ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017C_PID) },
320ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017D_PID) },
321ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017E_PID) },
322ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_017F_PID) },
323ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0180_PID) },
324ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0181_PID) },
325ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0182_PID) },
326ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0183_PID) },
327ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0184_PID) },
328ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0185_PID) },
329ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0186_PID) },
330ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0187_PID) },
331ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0188_PID) },
332ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0189_PID) },
333ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018A_PID) },
334ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018B_PID) },
335ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018C_PID) },
336ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018D_PID) },
337ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018E_PID) },
338ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_018F_PID) },
339ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0190_PID) },
340ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0191_PID) },
341ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0192_PID) },
342ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0193_PID) },
343ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0194_PID) },
344ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0195_PID) },
345ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0196_PID) },
346ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0197_PID) },
347ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0198_PID) },
348ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0199_PID) },
349ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019A_PID) },
350ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019B_PID) },
351ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019C_PID) },
352ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019D_PID) },
353ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019E_PID) },
354ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_019F_PID) },
355ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A0_PID) },
356ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A1_PID) },
357ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A2_PID) },
358ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A3_PID) },
359ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A4_PID) },
360ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A5_PID) },
361ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A6_PID) },
362ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A7_PID) },
363ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A8_PID) },
364ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01A9_PID) },
365ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AA_PID) },
366ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AB_PID) },
367ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AC_PID) },
368ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AD_PID) },
369ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AE_PID) },
370ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01AF_PID) },
371ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B0_PID) },
372ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B1_PID) },
373ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B2_PID) },
374ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B3_PID) },
375ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B4_PID) },
376ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B5_PID) },
377ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B6_PID) },
378ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B7_PID) },
379ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B8_PID) },
380ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01B9_PID) },
381ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BA_PID) },
382ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BB_PID) },
383ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BC_PID) },
384ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BD_PID) },
385ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BE_PID) },
386ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01BF_PID) },
387ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C0_PID) },
388ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C1_PID) },
389ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C2_PID) },
390ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C3_PID) },
391ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C4_PID) },
392ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C5_PID) },
393ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C6_PID) },
394ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C7_PID) },
395ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C8_PID) },
396ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01C9_PID) },
397ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CA_PID) },
398ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CB_PID) },
399ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CC_PID) },
400ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CD_PID) },
401ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CE_PID) },
402ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01CF_PID) },
403ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D0_PID) },
404ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D1_PID) },
405ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D2_PID) },
406ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D3_PID) },
407ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D4_PID) },
408ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D5_PID) },
409ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D6_PID) },
410ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D7_PID) },
411ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D8_PID) },
412ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01D9_PID) },
413ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DA_PID) },
414ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DB_PID) },
415ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DC_PID) },
416ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DD_PID) },
417ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DE_PID) },
418ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01DF_PID) },
419ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E0_PID) },
420ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E1_PID) },
421ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E2_PID) },
422ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E3_PID) },
423ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E4_PID) },
424ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E5_PID) },
425ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E6_PID) },
426ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E7_PID) },
427ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E8_PID) },
428ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01E9_PID) },
429ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EA_PID) },
430ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EB_PID) },
431ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EC_PID) },
432ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01ED_PID) },
433ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EE_PID) },
434ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01EF_PID) },
435ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F0_PID) },
436ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F1_PID) },
437ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F2_PID) },
438ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F3_PID) },
439ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F4_PID) },
440ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F5_PID) },
441ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F6_PID) },
442ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F7_PID) },
443ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F8_PID) },
444ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01F9_PID) },
445ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FA_PID) },
446ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FB_PID) },
447ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FC_PID) },
448ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) },
449ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) },
450ebb3770cSRay Molenkamp 	{ USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) },
4518f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
4521da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
453274a4bbcSDave Platt 	{ USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
454868e440dSJelle Foks 	{ USB_DEVICE(FTDI_VID, FTDI_USBX_707_PID) },
4551da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) },
4561da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
4571da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) },
4581da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) },
459a1484827SJustin Carlson 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2106_PID) },
4601da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) },
4611da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) },
4621da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) },
4631da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_2_PID) },
4641da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_1_PID) },
4651da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_2_PID) },
4661da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_1_PID) },
4671da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_2_PID) },
4681da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_3_PID) },
4691da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_4_PID) },
4701da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_1_PID) },
4711da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_2_PID) },
4721da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_3_PID) },
4731da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_4_PID) },
4741da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_1_PID) },
4751da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_2_PID) },
4761da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_3_PID) },
4771da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_4_PID) },
4781da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_1_PID) },
4791da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_2_PID) },
4801da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_3_PID) },
4811da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_4_PID) },
4821da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_5_PID) },
4831da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_6_PID) },
4841da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_7_PID) },
4851da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_8_PID) },
4861da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_1_PID) },
4871da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_2_PID) },
4881da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_3_PID) },
4891da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_4_PID) },
4901da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_5_PID) },
4911da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_6_PID) },
4921da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_7_PID) },
4931da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_8_PID) },
4941da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_1_PID) },
4951da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_2_PID) },
4961da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_3_PID) },
4971da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_4_PID) },
4981da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_5_PID) },
4991da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_6_PID) },
5001da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_7_PID) },
5011da177e4SLinus Torvalds 	{ USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) },
5021da177e4SLinus Torvalds 	{ USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) },
5031da177e4SLinus Torvalds 	{ USB_DEVICE(OCT_VID, OCT_US101_PID) },
5048f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID),
5058f977e42SIan Abbott 		.driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk },
5068f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID),
5078f977e42SIan Abbott 		.driver_info = (kernel_ulong_t)&ftdi_USB_UIRT_quirk },
5081da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) },
5091da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, PROTEGO_R2X0) },
5101da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) },
5111da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) },
5128f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E808_PID) },
5138f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E809_PID) },
5148f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80A_PID) },
5158f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80B_PID) },
5168f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80C_PID) },
5178f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80D_PID) },
5188f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80E_PID) },
5198f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80F_PID) },
5208f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E888_PID) },
5218f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E889_PID) },
5228f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88A_PID) },
5238f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88B_PID) },
5248f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88C_PID) },
5258f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88D_PID) },
5268f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88E_PID) },
5278f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) },
5281da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) },
52947900743SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) },
530e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_UR100_PID) },
531e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) },
532207c47e1SThomas Riewe 	{ USB_DEVICE(FTDI_VID, FTDI_PYRAMID_PID) },
533bde62185SMartin Hagelin 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) },
5344eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_US485_PID) },
5354eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_PICPRO_PID) },
5364eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_PCMCIA_PID) },
5374eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_PK1_PID) },
5384eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_RS232MON_PID) },
5394eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_APP70_PID) },
5404eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) },
5414eaf60e0SThomas Schleusener 	{ USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) },
542e6ac4a40SIan Abbott 	/*
54342f8aa94SPeter Stark 	 * Due to many user requests for multiple ELV devices we enable
54442f8aa94SPeter Stark 	 * them by default.
545e6ac4a40SIan Abbott 	 */
54642f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) },
54742f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) },
54842f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) },
54942f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) },
55042f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) },
55142f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) },
55242f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) },
55342f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) },
55442f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) },
55542f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) },
55642f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) },
55742f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) },
55842f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) },
55942f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) },
56042f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) },
56142f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) },
56242f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) },
56342f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) },
5644ae897dfSSven Andersen 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_EM1010PC_PID) },
56542f8aa94SPeter Stark 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) },
566b5894a50SAndré Schenk 	{ USB_DEVICE(FTDI_VID, FTDI_ELV_HS485_PID) },
5678f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
5688f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
5698f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
5708f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, LINX_FUTURE_1_PID) },
5718f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) },
5721da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
5731da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
574ec434e9bSJan Capek 	{ USB_DEVICE(FTDI_VID, FTDI_CCSMACHX_2_PID) },
5751da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) },
5761da177e4SLinus Torvalds 	{ USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) },
5771da177e4SLinus Torvalds 	{ USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) },
5781da177e4SLinus Torvalds 	{ USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) },
579e6ac4a40SIan Abbott 	{ USB_DEVICE(FALCOM_VID, FALCOM_SAMBA_PID) },
5801da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) },
581ef31fec0SMichael Olberg 	{ USB_DEVICE(TTI_VID, TTI_QL355P_PID) },
5826f92872cSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) },
5831da177e4SLinus Torvalds 	{ USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) },
5841da177e4SLinus Torvalds 	{ USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) },
5851da177e4SLinus Torvalds 	{ USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) },
5861da177e4SLinus Torvalds 	{ USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) },
5876f92872cSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
5886f92872cSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
589e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_0_PID) },
590e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_1_PID) },
591e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_2_PID) },
592e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_3_PID) },
593e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_4_PID) },
594e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_5_PID) },
595e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_6_PID) },
596e6ac4a40SIan Abbott 	{ USB_DEVICE(FTDI_VID, XSENS_CONVERTER_7_PID) },
5976f92872cSIan Abbott 	{ USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) },
5988f977e42SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) },
59934d1a8aaSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_KW_PID) },
60034d1a8aaSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_YS_PID) },
6019b1513d9SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) },
6029b1513d9SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) },
60334d1a8aaSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_IC_PID) },
60434d1a8aaSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_DB9_PID) },
60534d1a8aaSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_RS232_PID) },
60634d1a8aaSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_MHAM_Y9_PID) },
607740a4282SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_VCP_PID) },
608740a4282SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_D2XX_PID) },
6099b1513d9SIan Abbott 	{ USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) },
610c1f8ea7dSSøren Hauberg 	{ USB_DEVICE(EVOLUTION_VID, EVO_HYBRID_PID) },
611c1f8ea7dSSøren Hauberg 	{ USB_DEVICE(EVOLUTION_VID, EVO_RCM4_PID) },
612c9c7746dSRui Santos 	{ USB_DEVICE(FTDI_VID, FTDI_ARTEMIS_PID) },
613c9c7746dSRui Santos 	{ USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16_PID) },
61409c280a2SRui Santos 	{ USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) },
615c9c7746dSRui Santos 	{ USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) },
61609c280a2SRui Santos 	{ USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) },
61734910434SFranco Lanza 	{ USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16IC_PID) },
618b4723ae3SIan Abbott 	{ USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) },
619b4723ae3SIan Abbott 	{ USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) },
620effac8beSPavel Fedin 	{ USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) },
621641adaaeSLouis Nyffenegger 	{ USB_DEVICE(FTDI_VID, FTDI_TTUSB_PID) },
6227e1c0b86SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_ECLO_COM_1WIRE_PID) },
623a94b52acSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) },
624a94b52acSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) },
625ce40d290SWouter Paesen 	{ USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) },
626cdd3b156SNathan Bronson 	{ USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) },
6277e0258fdSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) },
628bf58fbd5SA. Maitland Bottoms 	{ USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) },
62962a13db3SFolkert van Heusden 	{ USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) },
63020a0f47eSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) },
631eb79b4fdSIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_YEI_SERVOCENTER31_PID) },
63248437486SD. Peter Siddons 	{ USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) },
633e1979fefSColin Leroy 	{ USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) },
634eaede2cbSRalf Schlatterbeck 	{ USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) },
6359978f9e1SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13M_PID) },
6369978f9e1SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) },
6379978f9e1SIan Abbott 	{ USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) },
63840c36092SKjell Myksvoll 	{ USB_DEVICE(ELEKTOR_VID, ELEKTOR_FT323R_PID) },
639822c7ef4SMicke Prag 	{ USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
640762e92faSNeil \"Superna\" ARMSTRONG 	{ USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) },
641a5f62399SLex Ross 	{ USB_DEVICE(FTDI_VID, FTDI_PHI_FISCO_PID) },
642d7fde2d6SPierre Castella 	{ USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
6434bb0ef19SEd Beroset 	{ USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) },
64411171d1bSMirko Bordignon 	{ USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) },
645fa91d43bSTony Lindgren 	{ USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
64620734345SHarald Welte 		.driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
64720734345SHarald Welte 	{ USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID),
64820734345SHarald Welte 		.driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
64920734345SHarald Welte 	{ USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
65020734345SHarald Welte 		.driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
651a00c3cadSFrederik Kriewitz 	{ USB_DEVICE(FTDI_VID, LMI_LM3S_DEVEL_BOARD_PID),
652a00c3cadSFrederik Kriewitz 		.driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
653a00c3cadSFrederik Kriewitz 	{ USB_DEVICE(FTDI_VID, LMI_LM3S_EVAL_BOARD_PID),
654a00c3cadSFrederik Kriewitz 		.driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
65526ab7053SAtsushi Nemoto 	{ USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
6562542335cSJon K Hellan 	{ USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) },
657a18f80b4SJaroslav Kysela 	{ USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO4x4_PID) },
65896285cb8SGaetan Carlier 	{ USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DGQG_PID) },
65996285cb8SGaetan Carlier 	{ USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DUSB_PID) },
660fdcb0a0fSIan Abbott 	{ },					/* Optional parameter entry */
6611da177e4SLinus Torvalds 	{ }					/* Terminating entry */
6621da177e4SLinus Torvalds };
6631da177e4SLinus Torvalds 
6641da177e4SLinus Torvalds MODULE_DEVICE_TABLE(usb, id_table_combined);
6651da177e4SLinus Torvalds 
6661da177e4SLinus Torvalds static struct usb_driver ftdi_driver = {
6671da177e4SLinus Torvalds 	.name =		"ftdi_sio",
6681da177e4SLinus Torvalds 	.probe =	usb_serial_probe,
6691da177e4SLinus Torvalds 	.disconnect =	usb_serial_disconnect,
6701da177e4SLinus Torvalds 	.id_table =	id_table_combined,
671ba9dc657SGreg Kroah-Hartman 	.no_dynamic_id =	1,
6721da177e4SLinus Torvalds };
6731da177e4SLinus Torvalds 
6744c4c9432SArjan van de Ven static const char *ftdi_chip_name[] = {
6751da177e4SLinus Torvalds 	[SIO] = "SIO",	/* the serial part of FT8U100AX */
6761da177e4SLinus Torvalds 	[FT8U232AM] = "FT8U232AM",
6771da177e4SLinus Torvalds 	[FT232BM] = "FT232BM",
6781da177e4SLinus Torvalds 	[FT2232C] = "FT2232C",
679d8b21606SGard Spreemann 	[FT232RL] = "FT232RL",
6801da177e4SLinus Torvalds };
6811da177e4SLinus Torvalds 
6821da177e4SLinus Torvalds 
6831da177e4SLinus Torvalds /* Constants for read urb and write urb */
6841da177e4SLinus Torvalds #define BUFSZ 512
6851da177e4SLinus Torvalds #define PKTSZ 64
6861da177e4SLinus Torvalds 
6871da177e4SLinus Torvalds /* rx_flags */
6881da177e4SLinus Torvalds #define THROTTLED		0x01
6891da177e4SLinus Torvalds #define ACTUALLY_THROTTLED	0x02
6901da177e4SLinus Torvalds 
6911da177e4SLinus Torvalds /* Used for TIOCMIWAIT */
6921da177e4SLinus Torvalds #define FTDI_STATUS_B0_MASK	(FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
6931da177e4SLinus Torvalds #define FTDI_STATUS_B1_MASK	(FTDI_RS_BI)
6941da177e4SLinus Torvalds /* End TIOCMIWAIT */
6951da177e4SLinus Torvalds 
6961da177e4SLinus Torvalds #define FTDI_IMPL_ASYNC_FLAGS = (ASYNC_SPD_HI | ASYNC_SPD_VHI \
697bbc5d276SRoel Kluin  | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP)
6981da177e4SLinus Torvalds 
6991da177e4SLinus Torvalds /* function prototypes for a FTDI serial converter */
700464cbb24SAlan Cox static int  ftdi_sio_probe(struct usb_serial *serial,
701464cbb24SAlan Cox 					const struct usb_device_id *id);
7021da177e4SLinus Torvalds static void ftdi_shutdown(struct usb_serial *serial);
70312bdbe03SJim Radford static int  ftdi_sio_port_probe(struct usb_serial_port *port);
70412bdbe03SJim Radford static int  ftdi_sio_port_remove(struct usb_serial_port *port);
705464cbb24SAlan Cox static int  ftdi_open(struct tty_struct *tty,
706464cbb24SAlan Cox 			struct usb_serial_port *port, struct file *filp);
707464cbb24SAlan Cox static void ftdi_close(struct tty_struct *tty,
708464cbb24SAlan Cox 			struct usb_serial_port *port, struct file *filp);
709464cbb24SAlan Cox static int  ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
710464cbb24SAlan Cox 			const unsigned char *buf, int count);
71195da310eSAlan Cox static int  ftdi_write_room(struct tty_struct *tty);
71295da310eSAlan Cox static int  ftdi_chars_in_buffer(struct tty_struct *tty);
7137d12e780SDavid Howells static void ftdi_write_bulk_callback(struct urb *urb);
7147d12e780SDavid Howells static void ftdi_read_bulk_callback(struct urb *urb);
715c4028958SDavid Howells static void ftdi_process_read(struct work_struct *work);
716464cbb24SAlan Cox static void ftdi_set_termios(struct tty_struct *tty,
717464cbb24SAlan Cox 			struct usb_serial_port *port, struct ktermios *old);
71895da310eSAlan Cox static int  ftdi_tiocmget(struct tty_struct *tty, struct file *file);
719464cbb24SAlan Cox static int  ftdi_tiocmset(struct tty_struct *tty, struct file *file,
720464cbb24SAlan Cox 			unsigned int set, unsigned int clear);
721464cbb24SAlan Cox static int  ftdi_ioctl(struct tty_struct *tty, struct file *file,
722464cbb24SAlan Cox 			unsigned int cmd, unsigned long arg);
72395da310eSAlan Cox static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
72495da310eSAlan Cox static void ftdi_throttle(struct tty_struct *tty);
72595da310eSAlan Cox static void ftdi_unthrottle(struct tty_struct *tty);
7261da177e4SLinus Torvalds 
7271da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base);
7281da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_to_divisor(int baud);
7291da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base);
7301da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_to_divisor(int baud);
7311da177e4SLinus Torvalds 
732ea65370dSGreg Kroah-Hartman static struct usb_serial_driver ftdi_sio_device = {
73318fcac35SGreg Kroah-Hartman 	.driver = {
7341da177e4SLinus Torvalds 		.owner =	THIS_MODULE,
735269bda1cSGreg Kroah-Hartman 		.name =		"ftdi_sio",
73618fcac35SGreg Kroah-Hartman 	},
737269bda1cSGreg Kroah-Hartman 	.description =		"FTDI USB Serial Device",
738d9b1b787SJohannes Hölzl 	.usb_driver = 		&ftdi_driver ,
7398f977e42SIan Abbott 	.id_table =		id_table_combined,
7401da177e4SLinus Torvalds 	.num_ports =		1,
7418f977e42SIan Abbott 	.probe =		ftdi_sio_probe,
74212bdbe03SJim Radford 	.port_probe =		ftdi_sio_port_probe,
74312bdbe03SJim Radford 	.port_remove =		ftdi_sio_port_remove,
7441da177e4SLinus Torvalds 	.open =			ftdi_open,
7451da177e4SLinus Torvalds 	.close =		ftdi_close,
7461da177e4SLinus Torvalds 	.throttle =		ftdi_throttle,
7471da177e4SLinus Torvalds 	.unthrottle =		ftdi_unthrottle,
7481da177e4SLinus Torvalds 	.write =		ftdi_write,
7491da177e4SLinus Torvalds 	.write_room =		ftdi_write_room,
7501da177e4SLinus Torvalds 	.chars_in_buffer =	ftdi_chars_in_buffer,
7511da177e4SLinus Torvalds 	.read_bulk_callback =	ftdi_read_bulk_callback,
7521da177e4SLinus Torvalds 	.write_bulk_callback =	ftdi_write_bulk_callback,
7531da177e4SLinus Torvalds 	.tiocmget =             ftdi_tiocmget,
7541da177e4SLinus Torvalds 	.tiocmset =             ftdi_tiocmset,
7551da177e4SLinus Torvalds 	.ioctl =		ftdi_ioctl,
7561da177e4SLinus Torvalds 	.set_termios =		ftdi_set_termios,
7571da177e4SLinus Torvalds 	.break_ctl =		ftdi_break_ctl,
7581da177e4SLinus Torvalds 	.shutdown =		ftdi_shutdown,
7591da177e4SLinus Torvalds };
7601da177e4SLinus Torvalds 
7611da177e4SLinus Torvalds 
7621da177e4SLinus Torvalds #define WDR_TIMEOUT 5000 /* default urb timeout */
763279e1545SIan Abbott #define WDR_SHORT_TIMEOUT 1000	/* shorter urb timeout */
7641da177e4SLinus Torvalds 
7651da177e4SLinus Torvalds /* High and low are for DTR, RTS etc etc */
7661da177e4SLinus Torvalds #define HIGH 1
7671da177e4SLinus Torvalds #define LOW 0
7681da177e4SLinus Torvalds 
76922465400SIan Abbott /* number of outstanding urbs to prevent userspace DoS from happening */
77022465400SIan Abbott #define URB_UPPER_LIMIT	42
77122465400SIan Abbott 
7721da177e4SLinus Torvalds /*
7731da177e4SLinus Torvalds  * ***************************************************************************
774fa91d43bSTony Lindgren  * Utility functions
7751da177e4SLinus Torvalds  * ***************************************************************************
7761da177e4SLinus Torvalds  */
7771da177e4SLinus Torvalds 
7781da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
7791da177e4SLinus Torvalds {
7801da177e4SLinus Torvalds 	unsigned short int divisor;
781464cbb24SAlan Cox 	/* divisor shifted 3 bits to the left */
782464cbb24SAlan Cox 	int divisor3 = base / 2 / baud;
783464cbb24SAlan Cox 	if ((divisor3 & 0x7) == 7)
784464cbb24SAlan Cox 		divisor3++; /* round x.7/8 up to x+1 */
7851da177e4SLinus Torvalds 	divisor = divisor3 >> 3;
7861da177e4SLinus Torvalds 	divisor3 &= 0x7;
787464cbb24SAlan Cox 	if (divisor3 == 1)
788464cbb24SAlan Cox 		divisor |= 0xc000;
789464cbb24SAlan Cox 	else if (divisor3 >= 4)
790464cbb24SAlan Cox 		divisor |= 0x4000;
791464cbb24SAlan Cox 	else if (divisor3 != 0)
792464cbb24SAlan Cox 		divisor |= 0x8000;
793464cbb24SAlan Cox 	else if (divisor == 1)
794464cbb24SAlan Cox 		divisor = 0;	/* special case for maximum baud rate */
7951da177e4SLinus Torvalds 	return divisor;
7961da177e4SLinus Torvalds }
7971da177e4SLinus Torvalds 
7981da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_to_divisor(int baud)
7991da177e4SLinus Torvalds {
800464cbb24SAlan Cox 	 return ftdi_232am_baud_base_to_divisor(baud, 48000000);
8011da177e4SLinus Torvalds }
8021da177e4SLinus Torvalds 
8031da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
8041da177e4SLinus Torvalds {
8051da177e4SLinus Torvalds 	static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
8061da177e4SLinus Torvalds 	__u32 divisor;
807464cbb24SAlan Cox 	/* divisor shifted 3 bits to the left */
808464cbb24SAlan Cox 	int divisor3 = base / 2 / baud;
8091da177e4SLinus Torvalds 	divisor = divisor3 >> 3;
8101da177e4SLinus Torvalds 	divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
8111da177e4SLinus Torvalds 	/* Deal with special cases for highest baud rates. */
812464cbb24SAlan Cox 	if (divisor == 1)
813464cbb24SAlan Cox 		divisor = 0;
814464cbb24SAlan Cox 	else if (divisor == 0x4001)
815464cbb24SAlan Cox 		divisor = 1;
8161da177e4SLinus Torvalds 	return divisor;
8171da177e4SLinus Torvalds }
8181da177e4SLinus Torvalds 
8191da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_to_divisor(int baud)
8201da177e4SLinus Torvalds {
821464cbb24SAlan Cox 	 return ftdi_232bm_baud_base_to_divisor(baud, 48000000);
8221da177e4SLinus Torvalds }
8231da177e4SLinus Torvalds 
82474ede0ffSIan Abbott #define set_mctrl(port, set)		update_mctrl((port), (set), 0)
82574ede0ffSIan Abbott #define clear_mctrl(port, clear)	update_mctrl((port), 0, (clear))
82674ede0ffSIan Abbott 
827464cbb24SAlan Cox static int update_mctrl(struct usb_serial_port *port, unsigned int set,
828464cbb24SAlan Cox 							unsigned int clear)
8291da177e4SLinus Torvalds {
8301da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
8311da177e4SLinus Torvalds 	char *buf;
83274ede0ffSIan Abbott 	unsigned urb_value;
8331da177e4SLinus Torvalds 	int rv;
8341da177e4SLinus Torvalds 
83574ede0ffSIan Abbott 	if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) {
836441b62c1SHarvey Harrison 		dbg("%s - DTR|RTS not being set|cleared", __func__);
83774ede0ffSIan Abbott 		return 0;	/* no change */
8381da177e4SLinus Torvalds 	}
83974ede0ffSIan Abbott 
84074ede0ffSIan Abbott 	buf = kmalloc(1, GFP_NOIO);
8419b0f2582SAlan Cox 	if (!buf)
84274ede0ffSIan Abbott 		return -ENOMEM;
84374ede0ffSIan Abbott 
84474ede0ffSIan Abbott 	clear &= ~set;	/* 'set' takes precedence over 'clear' */
84574ede0ffSIan Abbott 	urb_value = 0;
84674ede0ffSIan Abbott 	if (clear & TIOCM_DTR)
84774ede0ffSIan Abbott 		urb_value |= FTDI_SIO_SET_DTR_LOW;
84874ede0ffSIan Abbott 	if (clear & TIOCM_RTS)
84974ede0ffSIan Abbott 		urb_value |= FTDI_SIO_SET_RTS_LOW;
85074ede0ffSIan Abbott 	if (set & TIOCM_DTR)
85174ede0ffSIan Abbott 		urb_value |= FTDI_SIO_SET_DTR_HIGH;
85274ede0ffSIan Abbott 	if (set & TIOCM_RTS)
85374ede0ffSIan Abbott 		urb_value |= FTDI_SIO_SET_RTS_HIGH;
8541da177e4SLinus Torvalds 	rv = usb_control_msg(port->serial->dev,
8551da177e4SLinus Torvalds 			       usb_sndctrlpipe(port->serial->dev, 0),
8561da177e4SLinus Torvalds 			       FTDI_SIO_SET_MODEM_CTRL_REQUEST,
8571da177e4SLinus Torvalds 			       FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
85874ede0ffSIan Abbott 			       urb_value, priv->interface,
8591da177e4SLinus Torvalds 			       buf, 0, WDR_TIMEOUT);
8601da177e4SLinus Torvalds 
8611da177e4SLinus Torvalds 	kfree(buf);
86274ede0ffSIan Abbott 	if (rv < 0) {
86343b11d33SAlan Cox 		dbg("%s Error from MODEM_CTRL urb: DTR %s, RTS %s",
864441b62c1SHarvey Harrison 				__func__,
86574ede0ffSIan Abbott 				(set & TIOCM_DTR) ? "HIGH" :
86674ede0ffSIan Abbott 				(clear & TIOCM_DTR) ? "LOW" : "unchanged",
86774ede0ffSIan Abbott 				(set & TIOCM_RTS) ? "HIGH" :
86874ede0ffSIan Abbott 				(clear & TIOCM_RTS) ? "LOW" : "unchanged");
8691da177e4SLinus Torvalds 	} else {
870441b62c1SHarvey Harrison 		dbg("%s - DTR %s, RTS %s", __func__,
87174ede0ffSIan Abbott 				(set & TIOCM_DTR) ? "HIGH" :
87274ede0ffSIan Abbott 				(clear & TIOCM_DTR) ? "LOW" : "unchanged",
87374ede0ffSIan Abbott 				(set & TIOCM_RTS) ? "HIGH" :
87474ede0ffSIan Abbott 				(clear & TIOCM_RTS) ? "LOW" : "unchanged");
8759b0f2582SAlan Cox 		/* FIXME: locking on last_dtr_rts */
87674ede0ffSIan Abbott 		priv->last_dtr_rts = (priv->last_dtr_rts & ~clear) | set;
8771da177e4SLinus Torvalds 	}
8781da177e4SLinus Torvalds 	return rv;
8791da177e4SLinus Torvalds }
8801da177e4SLinus Torvalds 
8811da177e4SLinus Torvalds 
882464cbb24SAlan Cox static __u32 get_ftdi_divisor(struct tty_struct *tty,
883464cbb24SAlan Cox 						struct usb_serial_port *port)
8841da177e4SLinus Torvalds { /* get_ftdi_divisor */
8851da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
8861da177e4SLinus Torvalds 	__u32 div_value = 0;
8871da177e4SLinus Torvalds 	int div_okay = 1;
8881da177e4SLinus Torvalds 	int baud;
8891da177e4SLinus Torvalds 
8901da177e4SLinus Torvalds 	/*
891464cbb24SAlan Cox 	 * The logic involved in setting the baudrate can be cleanly split into
892464cbb24SAlan Cox 	 * 3 steps.
8931da177e4SLinus Torvalds 	 * 1. Standard baud rates are set in tty->termios->c_cflag
894464cbb24SAlan Cox 	 * 2. If these are not enough, you can set any speed using alt_speed as
895464cbb24SAlan Cox 	 * follows:
8961da177e4SLinus Torvalds 	 *    - set tty->termios->c_cflag speed to B38400
8971da177e4SLinus Torvalds 	 *    - set your real speed in tty->alt_speed; it gets ignored when
8981da177e4SLinus Torvalds 	 *      alt_speed==0, (or)
899464cbb24SAlan Cox 	 *    - call TIOCSSERIAL ioctl with (struct serial_struct) set as
900464cbb24SAlan Cox 	 *	follows:
901464cbb24SAlan Cox 	 *      flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP],
902464cbb24SAlan Cox 	 *	this just sets alt_speed to (HI: 57600, VHI: 115200,
903464cbb24SAlan Cox 	 *	SHI: 230400, WARP: 460800)
9041da177e4SLinus Torvalds 	 * ** Steps 1, 2 are done courtesy of tty_get_baud_rate
9051da177e4SLinus Torvalds 	 * 3. You can also set baud rate by setting custom divisor as follows
9061da177e4SLinus Torvalds 	 *    - set tty->termios->c_cflag speed to B38400
907464cbb24SAlan Cox 	 *    - call TIOCSSERIAL ioctl with (struct serial_struct) set as
908464cbb24SAlan Cox 	 *	follows:
9091da177e4SLinus Torvalds 	 *      o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
9101da177e4SLinus Torvalds 	 *      o custom_divisor set to baud_base / your_new_baudrate
911464cbb24SAlan Cox 	 * ** Step 3 is done courtesy of code borrowed from serial.c
912464cbb24SAlan Cox 	 *    I should really spend some time and separate + move this common
913464cbb24SAlan Cox 	 *    code to serial.c, it is replicated in nearly every serial driver
914464cbb24SAlan Cox 	 *    you see.
9151da177e4SLinus Torvalds 	 */
9161da177e4SLinus Torvalds 
917464cbb24SAlan Cox 	/* 1. Get the baud rate from the tty settings, this observes
918464cbb24SAlan Cox 	      alt_speed hack */
9191da177e4SLinus Torvalds 
92095da310eSAlan Cox 	baud = tty_get_baud_rate(tty);
921441b62c1SHarvey Harrison 	dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud);
9221da177e4SLinus Torvalds 
923464cbb24SAlan Cox 	/* 2. Observe async-compatible custom_divisor hack, update baudrate
924464cbb24SAlan Cox 	   if needed */
9251da177e4SLinus Torvalds 
9261da177e4SLinus Torvalds 	if (baud == 38400 &&
9271da177e4SLinus Torvalds 	    ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
9281da177e4SLinus Torvalds 	     (priv->custom_divisor)) {
9291da177e4SLinus Torvalds 		baud = priv->baud_base / priv->custom_divisor;
930464cbb24SAlan Cox 		dbg("%s - custom divisor %d sets baud rate to %d",
931464cbb24SAlan Cox 				__func__, priv->custom_divisor, baud);
9321da177e4SLinus Torvalds 	}
9331da177e4SLinus Torvalds 
9341da177e4SLinus Torvalds 	/* 3. Convert baudrate to device-specific divisor */
9351da177e4SLinus Torvalds 
936464cbb24SAlan Cox 	if (!baud)
937464cbb24SAlan Cox 		baud = 9600;
9381da177e4SLinus Torvalds 	switch (priv->chip_type) {
9391da177e4SLinus Torvalds 	case SIO: /* SIO chip */
9401da177e4SLinus Torvalds 		switch (baud) {
9411da177e4SLinus Torvalds 		case 300: div_value = ftdi_sio_b300; break;
9421da177e4SLinus Torvalds 		case 600: div_value = ftdi_sio_b600; break;
9431da177e4SLinus Torvalds 		case 1200: div_value = ftdi_sio_b1200; break;
9441da177e4SLinus Torvalds 		case 2400: div_value = ftdi_sio_b2400; break;
9451da177e4SLinus Torvalds 		case 4800: div_value = ftdi_sio_b4800; break;
9461da177e4SLinus Torvalds 		case 9600: div_value = ftdi_sio_b9600; break;
9471da177e4SLinus Torvalds 		case 19200: div_value = ftdi_sio_b19200; break;
9481da177e4SLinus Torvalds 		case 38400: div_value = ftdi_sio_b38400; break;
9491da177e4SLinus Torvalds 		case 57600: div_value = ftdi_sio_b57600;  break;
9501da177e4SLinus Torvalds 		case 115200: div_value = ftdi_sio_b115200; break;
9511da177e4SLinus Torvalds 		} /* baud */
9521da177e4SLinus Torvalds 		if (div_value == 0) {
953464cbb24SAlan Cox 			dbg("%s - Baudrate (%d) requested is not supported",
954464cbb24SAlan Cox 							__func__,  baud);
9551da177e4SLinus Torvalds 			div_value = ftdi_sio_b9600;
956669a6db1SAlan Cox 			baud = 9600;
9571da177e4SLinus Torvalds 			div_okay = 0;
9581da177e4SLinus Torvalds 		}
9591da177e4SLinus Torvalds 		break;
9601da177e4SLinus Torvalds 	case FT8U232AM: /* 8U232AM chip */
9611da177e4SLinus Torvalds 		if (baud <= 3000000) {
9621da177e4SLinus Torvalds 			div_value = ftdi_232am_baud_to_divisor(baud);
9631da177e4SLinus Torvalds 		} else {
964441b62c1SHarvey Harrison 			dbg("%s - Baud rate too high!", __func__);
965669a6db1SAlan Cox 			baud = 9600;
9661da177e4SLinus Torvalds 			div_value = ftdi_232am_baud_to_divisor(9600);
9671da177e4SLinus Torvalds 			div_okay = 0;
9681da177e4SLinus Torvalds 		}
9691da177e4SLinus Torvalds 		break;
9701da177e4SLinus Torvalds 	case FT232BM: /* FT232BM chip */
9711da177e4SLinus Torvalds 	case FT2232C: /* FT2232C chip */
9723b009c63SDavid Brownell 	case FT232RL:
9731da177e4SLinus Torvalds 		if (baud <= 3000000) {
9741da177e4SLinus Torvalds 			div_value = ftdi_232bm_baud_to_divisor(baud);
9751da177e4SLinus Torvalds 		} else {
976441b62c1SHarvey Harrison 			dbg("%s - Baud rate too high!", __func__);
9771da177e4SLinus Torvalds 			div_value = ftdi_232bm_baud_to_divisor(9600);
9781da177e4SLinus Torvalds 			div_okay = 0;
979669a6db1SAlan Cox 			baud = 9600;
9801da177e4SLinus Torvalds 		}
9811da177e4SLinus Torvalds 		break;
9821da177e4SLinus Torvalds 	} /* priv->chip_type */
9831da177e4SLinus Torvalds 
9841da177e4SLinus Torvalds 	if (div_okay) {
9851da177e4SLinus Torvalds 		dbg("%s - Baud rate set to %d (divisor 0x%lX) on chip %s",
986441b62c1SHarvey Harrison 			__func__, baud, (unsigned long)div_value,
9871da177e4SLinus Torvalds 			ftdi_chip_name[priv->chip_type]);
9881da177e4SLinus Torvalds 	}
9891da177e4SLinus Torvalds 
99095da310eSAlan Cox 	tty_encode_baud_rate(tty, baud, baud);
991464cbb24SAlan Cox 	return div_value;
9921da177e4SLinus Torvalds }
9931da177e4SLinus Torvalds 
99495da310eSAlan Cox static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
99595da310eSAlan Cox {
99695da310eSAlan Cox 	struct ftdi_private *priv = usb_get_serial_port_data(port);
99795da310eSAlan Cox 	char *buf;
99895da310eSAlan Cox 	__u16 urb_value;
99995da310eSAlan Cox 	__u16 urb_index;
100095da310eSAlan Cox 	__u32 urb_index_value;
100195da310eSAlan Cox 	int rv;
100295da310eSAlan Cox 
100395da310eSAlan Cox 	buf = kmalloc(1, GFP_NOIO);
100495da310eSAlan Cox 	if (!buf)
100595da310eSAlan Cox 		return -ENOMEM;
100695da310eSAlan Cox 
100795da310eSAlan Cox 	urb_index_value = get_ftdi_divisor(tty, port);
100895da310eSAlan Cox 	urb_value = (__u16)urb_index_value;
100995da310eSAlan Cox 	urb_index = (__u16)(urb_index_value >> 16);
101095da310eSAlan Cox 	if (priv->interface) {	/* FT2232C */
101195da310eSAlan Cox 		urb_index = (__u16)((urb_index << 8) | priv->interface);
101295da310eSAlan Cox 	}
101395da310eSAlan Cox 
101495da310eSAlan Cox 	rv = usb_control_msg(port->serial->dev,
101595da310eSAlan Cox 			    usb_sndctrlpipe(port->serial->dev, 0),
101695da310eSAlan Cox 			    FTDI_SIO_SET_BAUDRATE_REQUEST,
101795da310eSAlan Cox 			    FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
101895da310eSAlan Cox 			    urb_value, urb_index,
101995da310eSAlan Cox 			    buf, 0, WDR_SHORT_TIMEOUT);
102095da310eSAlan Cox 
102195da310eSAlan Cox 	kfree(buf);
102295da310eSAlan Cox 	return rv;
102395da310eSAlan Cox }
102495da310eSAlan Cox 
102595da310eSAlan Cox 
10261da177e4SLinus Torvalds 
1027464cbb24SAlan Cox static int get_serial_info(struct usb_serial_port *port,
1028464cbb24SAlan Cox 				struct serial_struct __user *retinfo)
10291da177e4SLinus Torvalds {
10301da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
10311da177e4SLinus Torvalds 	struct serial_struct tmp;
10321da177e4SLinus Torvalds 
10331da177e4SLinus Torvalds 	if (!retinfo)
10341da177e4SLinus Torvalds 		return -EFAULT;
10351da177e4SLinus Torvalds 	memset(&tmp, 0, sizeof(tmp));
10361da177e4SLinus Torvalds 	tmp.flags = priv->flags;
10371da177e4SLinus Torvalds 	tmp.baud_base = priv->baud_base;
10381da177e4SLinus Torvalds 	tmp.custom_divisor = priv->custom_divisor;
10391da177e4SLinus Torvalds 	if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
10401da177e4SLinus Torvalds 		return -EFAULT;
10411da177e4SLinus Torvalds 	return 0;
10421da177e4SLinus Torvalds } /* get_serial_info */
10431da177e4SLinus Torvalds 
10441da177e4SLinus Torvalds 
104595da310eSAlan Cox static int set_serial_info(struct tty_struct *tty,
104695da310eSAlan Cox 	struct usb_serial_port *port, struct serial_struct __user *newinfo)
10471da177e4SLinus Torvalds { /* set_serial_info */
10481da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
10491da177e4SLinus Torvalds 	struct serial_struct new_serial;
10501da177e4SLinus Torvalds 	struct ftdi_private old_priv;
10511da177e4SLinus Torvalds 
10521da177e4SLinus Torvalds 	if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
10531da177e4SLinus Torvalds 		return -EFAULT;
10541da177e4SLinus Torvalds 	old_priv = *priv;
10551da177e4SLinus Torvalds 
10561da177e4SLinus Torvalds 	/* Do error checking and permission checking */
10571da177e4SLinus Torvalds 
10581da177e4SLinus Torvalds 	if (!capable(CAP_SYS_ADMIN)) {
10591da177e4SLinus Torvalds 		if (((new_serial.flags & ~ASYNC_USR_MASK) !=
10601da177e4SLinus Torvalds 		     (priv->flags & ~ASYNC_USR_MASK)))
10611da177e4SLinus Torvalds 			return -EPERM;
10621da177e4SLinus Torvalds 		priv->flags = ((priv->flags & ~ASYNC_USR_MASK) |
10631da177e4SLinus Torvalds 			       (new_serial.flags & ASYNC_USR_MASK));
10641da177e4SLinus Torvalds 		priv->custom_divisor = new_serial.custom_divisor;
10651da177e4SLinus Torvalds 		goto check_and_exit;
10661da177e4SLinus Torvalds 	}
10671da177e4SLinus Torvalds 
10681da177e4SLinus Torvalds 	if ((new_serial.baud_base != priv->baud_base) &&
10691da177e4SLinus Torvalds 	    (new_serial.baud_base < 9600))
10701da177e4SLinus Torvalds 		return -EINVAL;
10711da177e4SLinus Torvalds 
10721da177e4SLinus Torvalds 	/* Make the changes - these are privileged changes! */
10731da177e4SLinus Torvalds 
10741da177e4SLinus Torvalds 	priv->flags = ((priv->flags & ~ASYNC_FLAGS) |
10751da177e4SLinus Torvalds 					(new_serial.flags & ASYNC_FLAGS));
10761da177e4SLinus Torvalds 	priv->custom_divisor = new_serial.custom_divisor;
10771da177e4SLinus Torvalds 
107895da310eSAlan Cox 	tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
10791da177e4SLinus Torvalds 
10801da177e4SLinus Torvalds check_and_exit:
10811da177e4SLinus Torvalds 	if ((old_priv.flags & ASYNC_SPD_MASK) !=
10821da177e4SLinus Torvalds 	     (priv->flags & ASYNC_SPD_MASK)) {
10831da177e4SLinus Torvalds 		if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
108495da310eSAlan Cox 			tty->alt_speed = 57600;
10851da177e4SLinus Torvalds 		else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
108695da310eSAlan Cox 			tty->alt_speed = 115200;
10871da177e4SLinus Torvalds 		else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
108895da310eSAlan Cox 			tty->alt_speed = 230400;
10891da177e4SLinus Torvalds 		else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
109095da310eSAlan Cox 			tty->alt_speed = 460800;
10911da177e4SLinus Torvalds 		else
109295da310eSAlan Cox 			tty->alt_speed = 0;
10931da177e4SLinus Torvalds 	}
10941da177e4SLinus Torvalds 	if (((old_priv.flags & ASYNC_SPD_MASK) !=
10951da177e4SLinus Torvalds 	     (priv->flags & ASYNC_SPD_MASK)) ||
10961da177e4SLinus Torvalds 	    (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
10971da177e4SLinus Torvalds 	     (old_priv.custom_divisor != priv->custom_divisor))) {
109895da310eSAlan Cox 		change_speed(tty, port);
10991da177e4SLinus Torvalds 	}
110095da310eSAlan Cox 	return 0;
11011da177e4SLinus Torvalds 
11021da177e4SLinus Torvalds } /* set_serial_info */
11031da177e4SLinus Torvalds 
11041da177e4SLinus Torvalds 
11058f977e42SIan Abbott /* Determine type of FTDI chip based on USB config and descriptor. */
11068f977e42SIan Abbott static void ftdi_determine_type(struct usb_serial_port *port)
11078f977e42SIan Abbott {
11088f977e42SIan Abbott 	struct ftdi_private *priv = usb_get_serial_port_data(port);
11098f977e42SIan Abbott 	struct usb_serial *serial = port->serial;
11108f977e42SIan Abbott 	struct usb_device *udev = serial->dev;
11118f977e42SIan Abbott 	unsigned version;
11128f977e42SIan Abbott 	unsigned interfaces;
11138f977e42SIan Abbott 
11148f977e42SIan Abbott 	/* Assume it is not the original SIO device for now. */
1115f5e09b7cSIan Abbott 	priv->baud_base = 48000000 / 2;
11168f977e42SIan Abbott 	priv->write_offset = 0;
11178f977e42SIan Abbott 
11188f977e42SIan Abbott 	version = le16_to_cpu(udev->descriptor.bcdDevice);
11198f977e42SIan Abbott 	interfaces = udev->actconfig->desc.bNumInterfaces;
1120441b62c1SHarvey Harrison 	dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __func__,
11218f977e42SIan Abbott 			version, interfaces);
11228f977e42SIan Abbott 	if (interfaces > 1) {
11238f977e42SIan Abbott 		int inter;
11248f977e42SIan Abbott 
11258f977e42SIan Abbott 		/* Multiple interfaces.  Assume FT2232C. */
11268f977e42SIan Abbott 		priv->chip_type = FT2232C;
11278f977e42SIan Abbott 		/* Determine interface code. */
11288f977e42SIan Abbott 		inter = serial->interface->altsetting->desc.bInterfaceNumber;
1129464cbb24SAlan Cox 		if (inter == 0)
11308f977e42SIan Abbott 			priv->interface = PIT_SIOA;
1131464cbb24SAlan Cox 		else
11328f977e42SIan Abbott 			priv->interface = PIT_SIOB;
11338f977e42SIan Abbott 		/* BM-type devices have a bug where bcdDevice gets set
11348f977e42SIan Abbott 		 * to 0x200 when iSerialNumber is 0.  */
11358f977e42SIan Abbott 		if (version < 0x500) {
11368f977e42SIan Abbott 			dbg("%s: something fishy - bcdDevice too low for multi-interface device",
1137441b62c1SHarvey Harrison 					__func__);
11388f977e42SIan Abbott 		}
11398f977e42SIan Abbott 	} else if (version < 0x200) {
11408f977e42SIan Abbott 		/* Old device.  Assume its the original SIO. */
11418f977e42SIan Abbott 		priv->chip_type = SIO;
11428f977e42SIan Abbott 		priv->baud_base = 12000000 / 16;
11438f977e42SIan Abbott 		priv->write_offset = 1;
11448f977e42SIan Abbott 	} else if (version < 0x400) {
11458f977e42SIan Abbott 		/* Assume its an FT8U232AM (or FT8U245AM) */
11468f977e42SIan Abbott 		/* (It might be a BM because of the iSerialNumber bug,
11478f977e42SIan Abbott 		 * but it will still work as an AM device.) */
11488f977e42SIan Abbott 		priv->chip_type = FT8U232AM;
11493b009c63SDavid Brownell 	} else if (version < 0x600) {
11508f977e42SIan Abbott 		/* Assume its an FT232BM (or FT245BM) */
11518f977e42SIan Abbott 		priv->chip_type = FT232BM;
11523b009c63SDavid Brownell 	} else {
11533b009c63SDavid Brownell 		/* Assume its an FT232R  */
11543b009c63SDavid Brownell 		priv->chip_type = FT232RL;
11558f977e42SIan Abbott 	}
11568f977e42SIan Abbott 	info("Detected %s", ftdi_chip_name[priv->chip_type]);
11578f977e42SIan Abbott }
11588f977e42SIan Abbott 
11598f977e42SIan Abbott 
11601da177e4SLinus Torvalds /*
11611da177e4SLinus Torvalds  * ***************************************************************************
11621da177e4SLinus Torvalds  * Sysfs Attribute
11631da177e4SLinus Torvalds  * ***************************************************************************
11641da177e4SLinus Torvalds  */
11651da177e4SLinus Torvalds 
1166464cbb24SAlan Cox static ssize_t show_latency_timer(struct device *dev,
1167464cbb24SAlan Cox 				struct device_attribute *attr, char *buf)
11681da177e4SLinus Torvalds {
11691da177e4SLinus Torvalds 	struct usb_serial_port *port = to_usb_serial_port(dev);
11701da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
117112bdbe03SJim Radford 	struct usb_device *udev = port->serial->dev;
11721da177e4SLinus Torvalds 	unsigned short latency = 0;
11731da177e4SLinus Torvalds 	int rv = 0;
11741da177e4SLinus Torvalds 
11751da177e4SLinus Torvalds 
1176441b62c1SHarvey Harrison 	dbg("%s", __func__);
11771da177e4SLinus Torvalds 
11781da177e4SLinus Torvalds 	rv = usb_control_msg(udev,
11791da177e4SLinus Torvalds 			     usb_rcvctrlpipe(udev, 0),
11801da177e4SLinus Torvalds 			     FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
11811da177e4SLinus Torvalds 			     FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
11821da177e4SLinus Torvalds 			     0, priv->interface,
11831da177e4SLinus Torvalds 			     (char *) &latency, 1, WDR_TIMEOUT);
11841da177e4SLinus Torvalds 
11851da177e4SLinus Torvalds 	if (rv < 0) {
1186898eb71cSJoe Perches 		dev_err(dev, "Unable to read latency timer: %i\n", rv);
11871da177e4SLinus Torvalds 		return -EIO;
11881da177e4SLinus Torvalds 	}
11891da177e4SLinus Torvalds 	return sprintf(buf, "%i\n", latency);
11901da177e4SLinus Torvalds }
11911da177e4SLinus Torvalds 
11921da177e4SLinus Torvalds /* Write a new value of the latency timer, in units of milliseconds. */
1193464cbb24SAlan Cox static ssize_t store_latency_timer(struct device *dev,
1194464cbb24SAlan Cox 			struct device_attribute *attr, const char *valbuf,
11951da177e4SLinus Torvalds 			size_t count)
11961da177e4SLinus Torvalds {
11971da177e4SLinus Torvalds 	struct usb_serial_port *port = to_usb_serial_port(dev);
11981da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
119912bdbe03SJim Radford 	struct usb_device *udev = port->serial->dev;
12001da177e4SLinus Torvalds 	char buf[1];
12011da177e4SLinus Torvalds 	int v = simple_strtoul(valbuf, NULL, 10);
12021da177e4SLinus Torvalds 	int rv = 0;
12031da177e4SLinus Torvalds 
1204441b62c1SHarvey Harrison 	dbg("%s: setting latency timer = %i", __func__, v);
12051da177e4SLinus Torvalds 
12061da177e4SLinus Torvalds 	rv = usb_control_msg(udev,
12071da177e4SLinus Torvalds 			     usb_sndctrlpipe(udev, 0),
12081da177e4SLinus Torvalds 			     FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
12091da177e4SLinus Torvalds 			     FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
12101da177e4SLinus Torvalds 			     v, priv->interface,
12111da177e4SLinus Torvalds 			     buf, 0, WDR_TIMEOUT);
12121da177e4SLinus Torvalds 
12131da177e4SLinus Torvalds 	if (rv < 0) {
1214898eb71cSJoe Perches 		dev_err(dev, "Unable to write latency timer: %i\n", rv);
12151da177e4SLinus Torvalds 		return -EIO;
12161da177e4SLinus Torvalds 	}
12171da177e4SLinus Torvalds 
12181da177e4SLinus Torvalds 	return count;
12191da177e4SLinus Torvalds }
12201da177e4SLinus Torvalds 
12211da177e4SLinus Torvalds /* Write an event character directly to the FTDI register.  The ASCII
12221da177e4SLinus Torvalds    value is in the low 8 bits, with the enable bit in the 9th bit. */
1223464cbb24SAlan Cox static ssize_t store_event_char(struct device *dev,
1224464cbb24SAlan Cox 	struct device_attribute *attr, const char *valbuf, size_t count)
12251da177e4SLinus Torvalds {
12261da177e4SLinus Torvalds 	struct usb_serial_port *port = to_usb_serial_port(dev);
12271da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
122812bdbe03SJim Radford 	struct usb_device *udev = port->serial->dev;
12291da177e4SLinus Torvalds 	char buf[1];
12301da177e4SLinus Torvalds 	int v = simple_strtoul(valbuf, NULL, 10);
12311da177e4SLinus Torvalds 	int rv = 0;
12321da177e4SLinus Torvalds 
1233441b62c1SHarvey Harrison 	dbg("%s: setting event char = %i", __func__, v);
12341da177e4SLinus Torvalds 
12351da177e4SLinus Torvalds 	rv = usb_control_msg(udev,
12361da177e4SLinus Torvalds 			     usb_sndctrlpipe(udev, 0),
12371da177e4SLinus Torvalds 			     FTDI_SIO_SET_EVENT_CHAR_REQUEST,
12381da177e4SLinus Torvalds 			     FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE,
12391da177e4SLinus Torvalds 			     v, priv->interface,
12401da177e4SLinus Torvalds 			     buf, 0, WDR_TIMEOUT);
12411da177e4SLinus Torvalds 
12421da177e4SLinus Torvalds 	if (rv < 0) {
12431da177e4SLinus Torvalds 		dbg("Unable to write event character: %i", rv);
12441da177e4SLinus Torvalds 		return -EIO;
12451da177e4SLinus Torvalds 	}
12461da177e4SLinus Torvalds 
12471da177e4SLinus Torvalds 	return count;
12481da177e4SLinus Torvalds }
12491da177e4SLinus Torvalds 
1250464cbb24SAlan Cox static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer,
1251464cbb24SAlan Cox 							store_latency_timer);
12521da177e4SLinus Torvalds static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char);
12531da177e4SLinus Torvalds 
125412bdbe03SJim Radford static int create_sysfs_attrs(struct usb_serial_port *port)
12551da177e4SLinus Torvalds {
125612bdbe03SJim Radford 	struct ftdi_private *priv = usb_get_serial_port_data(port);
125713f4db9eSGreg Kroah-Hartman 	int retval = 0;
12581da177e4SLinus Torvalds 
1259441b62c1SHarvey Harrison 	dbg("%s", __func__);
12601da177e4SLinus Torvalds 
12611da177e4SLinus Torvalds 	/* XXX I've no idea if the original SIO supports the event_char
12621da177e4SLinus Torvalds 	 * sysfs parameter, so I'm playing it safe.  */
12631da177e4SLinus Torvalds 	if (priv->chip_type != SIO) {
12641da177e4SLinus Torvalds 		dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]);
126512bdbe03SJim Radford 		retval = device_create_file(&port->dev, &dev_attr_event_char);
126613f4db9eSGreg Kroah-Hartman 		if ((!retval) &&
126797cd49ebSStepan Moskovchenko 		    (priv->chip_type == FT232BM ||
126897cd49ebSStepan Moskovchenko 		     priv->chip_type == FT2232C ||
126997cd49ebSStepan Moskovchenko 		     priv->chip_type == FT232RL)) {
127012bdbe03SJim Radford 			retval = device_create_file(&port->dev,
127113f4db9eSGreg Kroah-Hartman 						    &dev_attr_latency_timer);
12721da177e4SLinus Torvalds 		}
12731da177e4SLinus Torvalds 	}
127413f4db9eSGreg Kroah-Hartman 	return retval;
12751da177e4SLinus Torvalds }
12761da177e4SLinus Torvalds 
127712bdbe03SJim Radford static void remove_sysfs_attrs(struct usb_serial_port *port)
12781da177e4SLinus Torvalds {
127912bdbe03SJim Radford 	struct ftdi_private *priv = usb_get_serial_port_data(port);
12801da177e4SLinus Torvalds 
1281441b62c1SHarvey Harrison 	dbg("%s", __func__);
12821da177e4SLinus Torvalds 
12831da177e4SLinus Torvalds 	/* XXX see create_sysfs_attrs */
12841da177e4SLinus Torvalds 	if (priv->chip_type != SIO) {
128512bdbe03SJim Radford 		device_remove_file(&port->dev, &dev_attr_event_char);
1286ed6e5282SAndrew M. Bishop 		if (priv->chip_type == FT232BM ||
1287ed6e5282SAndrew M. Bishop 		    priv->chip_type == FT2232C ||
1288ed6e5282SAndrew M. Bishop 		    priv->chip_type == FT232RL) {
128912bdbe03SJim Radford 			device_remove_file(&port->dev, &dev_attr_latency_timer);
12901da177e4SLinus Torvalds 		}
12911da177e4SLinus Torvalds 	}
12921da177e4SLinus Torvalds 
12931da177e4SLinus Torvalds }
12941da177e4SLinus Torvalds 
12951da177e4SLinus Torvalds /*
12961da177e4SLinus Torvalds  * ***************************************************************************
12971da177e4SLinus Torvalds  * FTDI driver specific functions
12981da177e4SLinus Torvalds  * ***************************************************************************
12991da177e4SLinus Torvalds  */
13001da177e4SLinus Torvalds 
13018f977e42SIan Abbott /* Probe function to check for special devices */
1302464cbb24SAlan Cox static int ftdi_sio_probe(struct usb_serial *serial,
1303464cbb24SAlan Cox 					const struct usb_device_id *id)
13048f977e42SIan Abbott {
1305464cbb24SAlan Cox 	struct ftdi_sio_quirk *quirk =
1306464cbb24SAlan Cox 				(struct ftdi_sio_quirk *)id->driver_info;
1307fa91d43bSTony Lindgren 
1308fa91d43bSTony Lindgren 	if (quirk && quirk->probe) {
1309fa91d43bSTony Lindgren 		int ret = quirk->probe(serial);
1310fa91d43bSTony Lindgren 		if (ret != 0)
1311fa91d43bSTony Lindgren 			return ret;
1312fa91d43bSTony Lindgren 	}
1313fa91d43bSTony Lindgren 
13148f977e42SIan Abbott 	usb_set_serial_data(serial, (void *)id->driver_info);
13158f977e42SIan Abbott 
1316fa91d43bSTony Lindgren 	return 0;
13178f977e42SIan Abbott }
13188f977e42SIan Abbott 
131912bdbe03SJim Radford static int ftdi_sio_port_probe(struct usb_serial_port *port)
13201da177e4SLinus Torvalds {
13211da177e4SLinus Torvalds 	struct ftdi_private *priv;
13220ffbbe25SOliver Neukum 	struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial);
13230ffbbe25SOliver Neukum 
13241da177e4SLinus Torvalds 
1325441b62c1SHarvey Harrison 	dbg("%s", __func__);
13261da177e4SLinus Torvalds 
132780b6ca48SEric Sesterhenn 	priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
13281da177e4SLinus Torvalds 	if (!priv) {
1329464cbb24SAlan Cox 		err("%s- kmalloc(%Zd) failed.", __func__,
1330464cbb24SAlan Cox 					sizeof(struct ftdi_private));
13311da177e4SLinus Torvalds 		return -ENOMEM;
13321da177e4SLinus Torvalds 	}
13331da177e4SLinus Torvalds 
13341da177e4SLinus Torvalds 	spin_lock_init(&priv->rx_lock);
133522465400SIan Abbott 	spin_lock_init(&priv->tx_lock);
13361da177e4SLinus Torvalds 	init_waitqueue_head(&priv->delta_msr_wait);
13371da177e4SLinus Torvalds 	/* This will push the characters through immediately rather
13381da177e4SLinus Torvalds 	   than queue a task to deliver them */
13391da177e4SLinus Torvalds 	priv->flags = ASYNC_LOW_LATENCY;
13401da177e4SLinus Torvalds 
13410ffbbe25SOliver Neukum 	if (quirk && quirk->port_probe)
13420ffbbe25SOliver Neukum 		quirk->port_probe(priv);
13430ffbbe25SOliver Neukum 
13441da177e4SLinus Torvalds 	/* Increase the size of read buffers */
13451da177e4SLinus Torvalds 	kfree(port->bulk_in_buffer);
13461da177e4SLinus Torvalds 	port->bulk_in_buffer = kmalloc(BUFSZ, GFP_KERNEL);
13471da177e4SLinus Torvalds 	if (!port->bulk_in_buffer) {
13481da177e4SLinus Torvalds 		kfree(priv);
13491da177e4SLinus Torvalds 		return -ENOMEM;
13501da177e4SLinus Torvalds 	}
13511da177e4SLinus Torvalds 	if (port->read_urb) {
13521da177e4SLinus Torvalds 		port->read_urb->transfer_buffer = port->bulk_in_buffer;
13531da177e4SLinus Torvalds 		port->read_urb->transfer_buffer_length = BUFSZ;
13541da177e4SLinus Torvalds 	}
13551da177e4SLinus Torvalds 
1356c4028958SDavid Howells 	INIT_DELAYED_WORK(&priv->rx_work, ftdi_process_read);
1357c4028958SDavid Howells 	priv->port = port;
135876854ceaSIan Abbott 
13591da177e4SLinus Torvalds 	/* Free port's existing write urb and transfer buffer. */
13601da177e4SLinus Torvalds 	if (port->write_urb) {
13611da177e4SLinus Torvalds 		usb_free_urb(port->write_urb);
13621da177e4SLinus Torvalds 		port->write_urb = NULL;
13631da177e4SLinus Torvalds 	}
13641da177e4SLinus Torvalds 	kfree(port->bulk_out_buffer);
13651da177e4SLinus Torvalds 	port->bulk_out_buffer = NULL;
13661da177e4SLinus Torvalds 
136712bdbe03SJim Radford 	usb_set_serial_port_data(port, priv);
13681da177e4SLinus Torvalds 
136912bdbe03SJim Radford 	ftdi_determine_type(port);
137012bdbe03SJim Radford 	create_sysfs_attrs(port);
137112bdbe03SJim Radford 	return 0;
13721da177e4SLinus Torvalds }
13731da177e4SLinus Torvalds 
13748f977e42SIan Abbott /* Setup for the USB-UIRT device, which requires hardwired
13758f977e42SIan Abbott  * baudrate (38400 gets mapped to 312500) */
13761da177e4SLinus Torvalds /* Called from usbserial:serial_probe */
13770ffbbe25SOliver Neukum static void ftdi_USB_UIRT_setup(struct ftdi_private *priv)
13781da177e4SLinus Torvalds {
1379441b62c1SHarvey Harrison 	dbg("%s", __func__);
13801da177e4SLinus Torvalds 
13811da177e4SLinus Torvalds 	priv->flags |= ASYNC_SPD_CUST;
13821da177e4SLinus Torvalds 	priv->custom_divisor = 77;
1383669a6db1SAlan Cox 	priv->force_baud = 38400;
13848f977e42SIan Abbott } /* ftdi_USB_UIRT_setup */
13851da177e4SLinus Torvalds 
13868f977e42SIan Abbott /* Setup for the HE-TIRA1 device, which requires hardwired
13878f977e42SIan Abbott  * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled.  */
1388464cbb24SAlan Cox 
13890ffbbe25SOliver Neukum static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv)
13908f977e42SIan Abbott {
1391441b62c1SHarvey Harrison 	dbg("%s", __func__);
13921da177e4SLinus Torvalds 
13931da177e4SLinus Torvalds 	priv->flags |= ASYNC_SPD_CUST;
13941da177e4SLinus Torvalds 	priv->custom_divisor = 240;
1395669a6db1SAlan Cox 	priv->force_baud = 38400;
13961da177e4SLinus Torvalds 	priv->force_rtscts = 1;
13978f977e42SIan Abbott } /* ftdi_HE_TIRA1_setup */
13981da177e4SLinus Torvalds 
1399fa91d43bSTony Lindgren /*
140020734345SHarald Welte  * First port on JTAG adaptors such as Olimex arm-usb-ocd or the FIC/OpenMoko
140120734345SHarald Welte  * Neo1973 Debug Board is reserved for JTAG interface and can be accessed from
140220734345SHarald Welte  * userspace using openocd.
1403fa91d43bSTony Lindgren  */
140420734345SHarald Welte static int ftdi_jtag_probe(struct usb_serial *serial)
1405fa91d43bSTony Lindgren {
1406fa91d43bSTony Lindgren 	struct usb_device *udev = serial->dev;
1407fa91d43bSTony Lindgren 	struct usb_interface *interface = serial->interface;
1408fa91d43bSTony Lindgren 
1409441b62c1SHarvey Harrison 	dbg("%s", __func__);
1410fa91d43bSTony Lindgren 
1411fa91d43bSTony Lindgren 	if (interface == udev->actconfig->interface[0]) {
141220734345SHarald Welte 		info("Ignoring serial port reserved for JTAG");
1413fa91d43bSTony Lindgren 		return -ENODEV;
1414fa91d43bSTony Lindgren 	}
1415fa91d43bSTony Lindgren 
1416fa91d43bSTony Lindgren 	return 0;
1417fa91d43bSTony Lindgren }
14181da177e4SLinus Torvalds 
1419546d7eecSKevin Vance /*
1420546d7eecSKevin Vance  * The Matrix Orbital VK204-25-USB has an invalid IN endpoint.
1421546d7eecSKevin Vance  * We have to correct it if we want to read from it.
1422546d7eecSKevin Vance  */
1423546d7eecSKevin Vance static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
1424546d7eecSKevin Vance {
1425546d7eecSKevin Vance 	struct usb_host_endpoint *ep = serial->dev->ep_in[1];
1426546d7eecSKevin Vance 	struct usb_endpoint_descriptor *ep_desc = &ep->desc;
1427546d7eecSKevin Vance 
1428546d7eecSKevin Vance 	if (ep->enabled && ep_desc->wMaxPacketSize == 0) {
1429fd05e720SAl Viro 		ep_desc->wMaxPacketSize = cpu_to_le16(0x40);
1430546d7eecSKevin Vance 		info("Fixing invalid wMaxPacketSize on read pipe");
1431546d7eecSKevin Vance 	}
1432546d7eecSKevin Vance 
1433546d7eecSKevin Vance 	return 0;
1434546d7eecSKevin Vance }
1435546d7eecSKevin Vance 
14361da177e4SLinus Torvalds /* ftdi_shutdown is called from usbserial:usb_serial_disconnect
14371da177e4SLinus Torvalds  *   it is called when the usb device is disconnected
14381da177e4SLinus Torvalds  *
14391da177e4SLinus Torvalds  *   usbserial:usb_serial_disconnect
14401da177e4SLinus Torvalds  *      calls __serial_close for each open of the port
14411da177e4SLinus Torvalds  *      shutdown is called then (ie ftdi_shutdown)
14421da177e4SLinus Torvalds  */
14431da177e4SLinus Torvalds static void ftdi_shutdown(struct usb_serial *serial)
144412bdbe03SJim Radford {
1445441b62c1SHarvey Harrison 	dbg("%s", __func__);
144612bdbe03SJim Radford }
14471da177e4SLinus Torvalds 
144812bdbe03SJim Radford static int ftdi_sio_port_remove(struct usb_serial_port *port)
144912bdbe03SJim Radford {
14501da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
14511da177e4SLinus Torvalds 
1452441b62c1SHarvey Harrison 	dbg("%s", __func__);
14531da177e4SLinus Torvalds 
145412bdbe03SJim Radford 	remove_sysfs_attrs(port);
14551da177e4SLinus Torvalds 
14561da177e4SLinus Torvalds 	/* all open ports are closed at this point
14571da177e4SLinus Torvalds 	 *    (by usbserial.c:__serial_close, which calls ftdi_close)
14581da177e4SLinus Torvalds 	 */
14591da177e4SLinus Torvalds 
14601da177e4SLinus Torvalds 	if (priv) {
14611da177e4SLinus Torvalds 		usb_set_serial_port_data(port, NULL);
14621da177e4SLinus Torvalds 		kfree(priv);
14631da177e4SLinus Torvalds 	}
14641da177e4SLinus Torvalds 
146512bdbe03SJim Radford 	return 0;
146612bdbe03SJim Radford }
14671da177e4SLinus Torvalds 
146895da310eSAlan Cox static int ftdi_open(struct tty_struct *tty,
146995da310eSAlan Cox 			struct usb_serial_port *port, struct file *filp)
14701da177e4SLinus Torvalds { /* ftdi_open */
14711da177e4SLinus Torvalds 	struct usb_device *dev = port->serial->dev;
14721da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
14731da177e4SLinus Torvalds 	unsigned long flags;
14741da177e4SLinus Torvalds 
14751da177e4SLinus Torvalds 	int result = 0;
14761da177e4SLinus Torvalds 	char buf[1]; /* Needed for the usb_control_msg I think */
14771da177e4SLinus Torvalds 
1478441b62c1SHarvey Harrison 	dbg("%s", __func__);
14791da177e4SLinus Torvalds 
148022465400SIan Abbott 	spin_lock_irqsave(&priv->tx_lock, flags);
148122465400SIan Abbott 	priv->tx_bytes = 0;
148222465400SIan Abbott 	spin_unlock_irqrestore(&priv->tx_lock, flags);
148322465400SIan Abbott 	spin_lock_irqsave(&priv->rx_lock, flags);
148422465400SIan Abbott 	priv->rx_bytes = 0;
148522465400SIan Abbott 	spin_unlock_irqrestore(&priv->rx_lock, flags);
148622465400SIan Abbott 
148795da310eSAlan Cox 	if (tty)
148895da310eSAlan Cox 		tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
14891da177e4SLinus Torvalds 
14901da177e4SLinus Torvalds 	/* No error checking for this (will get errors later anyway) */
14911da177e4SLinus Torvalds 	/* See ftdi_sio.h for description of what is reset */
14921da177e4SLinus Torvalds 	usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
14931da177e4SLinus Torvalds 			FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE,
14941da177e4SLinus Torvalds 			FTDI_SIO_RESET_SIO,
14951da177e4SLinus Torvalds 			priv->interface, buf, 0, WDR_TIMEOUT);
14961da177e4SLinus Torvalds 
14971da177e4SLinus Torvalds 	/* Termios defaults are set by usb_serial_init. We don't change
14981da177e4SLinus Torvalds 	   port->tty->termios - this would loose speed settings, etc.
14991da177e4SLinus Torvalds 	   This is same behaviour as serial.c/rs_open() - Kuba */
15001da177e4SLinus Torvalds 
15011da177e4SLinus Torvalds 	/* ftdi_set_termios  will send usb control messages */
150295da310eSAlan Cox 	if (tty)
150395da310eSAlan Cox 		ftdi_set_termios(tty, port, tty->termios);
15041da177e4SLinus Torvalds 
15051da177e4SLinus Torvalds 	/* FIXME: Flow control might be enabled, so it should be checked -
15061da177e4SLinus Torvalds 	   we have no control of defaults! */
15071da177e4SLinus Torvalds 	/* Turn on RTS and DTR since we are not flow controlling by default */
150874ede0ffSIan Abbott 	set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
15091da177e4SLinus Torvalds 
15101da177e4SLinus Torvalds 	/* Not throttled */
15111da177e4SLinus Torvalds 	spin_lock_irqsave(&priv->rx_lock, flags);
15121da177e4SLinus Torvalds 	priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
15131da177e4SLinus Torvalds 	spin_unlock_irqrestore(&priv->rx_lock, flags);
15141da177e4SLinus Torvalds 
15151da177e4SLinus Torvalds 	/* Start reading from the device */
151676854ceaSIan Abbott 	priv->rx_processed = 0;
15171da177e4SLinus Torvalds 	usb_fill_bulk_urb(port->read_urb, dev,
15181da177e4SLinus Torvalds 			usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
1519464cbb24SAlan Cox 			port->read_urb->transfer_buffer,
1520464cbb24SAlan Cox 				port->read_urb->transfer_buffer_length,
15211da177e4SLinus Torvalds 			ftdi_read_bulk_callback, port);
15221da177e4SLinus Torvalds 	result = usb_submit_urb(port->read_urb, GFP_KERNEL);
15231da177e4SLinus Torvalds 	if (result)
1524464cbb24SAlan Cox 		err("%s - failed submitting read urb, error %d",
1525464cbb24SAlan Cox 							__func__, result);
15261da177e4SLinus Torvalds 
15271da177e4SLinus Torvalds 
15281da177e4SLinus Torvalds 	return result;
15291da177e4SLinus Torvalds } /* ftdi_open */
15301da177e4SLinus Torvalds 
15311da177e4SLinus Torvalds 
15321da177e4SLinus Torvalds 
15331da177e4SLinus Torvalds /*
15341da177e4SLinus Torvalds  * usbserial:__serial_close  only calls ftdi_close if the point is open
15351da177e4SLinus Torvalds  *
15361da177e4SLinus Torvalds  *   This only gets called when it is the last close
15371da177e4SLinus Torvalds  *
15381da177e4SLinus Torvalds  *
15391da177e4SLinus Torvalds  */
15401da177e4SLinus Torvalds 
154195da310eSAlan Cox static void ftdi_close(struct tty_struct *tty,
154295da310eSAlan Cox 			struct usb_serial_port *port, struct file *filp)
15431da177e4SLinus Torvalds { /* ftdi_close */
154495da310eSAlan Cox 	unsigned int c_cflag = tty->termios->c_cflag;
15451da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
15461da177e4SLinus Torvalds 	char buf[1];
15471da177e4SLinus Torvalds 
1548441b62c1SHarvey Harrison 	dbg("%s", __func__);
15491da177e4SLinus Torvalds 
155095bef012SOliver Neukum 	mutex_lock(&port->serial->disc_mutex);
155195bef012SOliver Neukum 	if (c_cflag & HUPCL && !port->serial->disconnected) {
15521da177e4SLinus Torvalds 		/* Disable flow control */
15531da177e4SLinus Torvalds 		if (usb_control_msg(port->serial->dev,
15541da177e4SLinus Torvalds 				    usb_sndctrlpipe(port->serial->dev, 0),
15551da177e4SLinus Torvalds 				    FTDI_SIO_SET_FLOW_CTRL_REQUEST,
15561da177e4SLinus Torvalds 				    FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
15571da177e4SLinus Torvalds 				    0, priv->interface, buf, 0,
15581da177e4SLinus Torvalds 				    WDR_TIMEOUT) < 0) {
15591da177e4SLinus Torvalds 			err("error from flowcontrol urb");
15601da177e4SLinus Torvalds 		}
15611da177e4SLinus Torvalds 
156274ede0ffSIan Abbott 		/* drop RTS and DTR */
156374ede0ffSIan Abbott 		clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
15641da177e4SLinus Torvalds 	} /* Note change no line if hupcl is off */
156595bef012SOliver Neukum 	mutex_unlock(&port->serial->disc_mutex);
15661da177e4SLinus Torvalds 
156776854ceaSIan Abbott 	/* cancel any scheduled reading */
156876854ceaSIan Abbott 	cancel_delayed_work(&priv->rx_work);
156976854ceaSIan Abbott 	flush_scheduled_work();
157076854ceaSIan Abbott 
15711da177e4SLinus Torvalds 	/* shutdown our bulk read */
15721da177e4SLinus Torvalds 	usb_kill_urb(port->read_urb);
15731da177e4SLinus Torvalds } /* ftdi_close */
15741da177e4SLinus Torvalds 
15751da177e4SLinus Torvalds 
15761da177e4SLinus Torvalds 
15771da177e4SLinus Torvalds /* The SIO requires the first byte to have:
15781da177e4SLinus Torvalds  *  B0 1
15791da177e4SLinus Torvalds  *  B1 0
15801da177e4SLinus Torvalds  *  B2..7 length of message excluding byte 0
15811da177e4SLinus Torvalds  *
15821da177e4SLinus Torvalds  * The new devices do not require this byte
15831da177e4SLinus Torvalds  */
158495da310eSAlan Cox static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
15851da177e4SLinus Torvalds 			   const unsigned char *buf, int count)
15861da177e4SLinus Torvalds { /* ftdi_write */
15871da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
15881da177e4SLinus Torvalds 	struct urb *urb;
15891da177e4SLinus Torvalds 	unsigned char *buffer;
15901da177e4SLinus Torvalds 	int data_offset ;       /* will be 1 for the SIO and 0 otherwise */
15911da177e4SLinus Torvalds 	int status;
15921da177e4SLinus Torvalds 	int transfer_size;
159322465400SIan Abbott 	unsigned long flags;
15941da177e4SLinus Torvalds 
1595441b62c1SHarvey Harrison 	dbg("%s port %d, %d bytes", __func__, port->number, count);
15961da177e4SLinus Torvalds 
15971da177e4SLinus Torvalds 	if (count == 0) {
15981da177e4SLinus Torvalds 		dbg("write request of 0 bytes");
15991da177e4SLinus Torvalds 		return 0;
16001da177e4SLinus Torvalds 	}
160122465400SIan Abbott 	spin_lock_irqsave(&priv->tx_lock, flags);
160222465400SIan Abbott 	if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) {
160322465400SIan Abbott 		spin_unlock_irqrestore(&priv->tx_lock, flags);
1604441b62c1SHarvey Harrison 		dbg("%s - write limit hit\n", __func__);
160522465400SIan Abbott 		return 0;
160622465400SIan Abbott 	}
160762127a58SOliver Neukum 	priv->tx_outstanding_urbs++;
160822465400SIan Abbott 	spin_unlock_irqrestore(&priv->tx_lock, flags);
16091da177e4SLinus Torvalds 
16101da177e4SLinus Torvalds 	data_offset = priv->write_offset;
16111da177e4SLinus Torvalds 	dbg("data_offset set to %d", data_offset);
16121da177e4SLinus Torvalds 
16131da177e4SLinus Torvalds 	/* Determine total transfer size */
16141da177e4SLinus Torvalds 	transfer_size = count;
16151da177e4SLinus Torvalds 	if (data_offset > 0) {
16161da177e4SLinus Torvalds 		/* Original sio needs control bytes too... */
16171da177e4SLinus Torvalds 		transfer_size += (data_offset *
16181da177e4SLinus Torvalds 				((count + (PKTSZ - 1 - data_offset)) /
16191da177e4SLinus Torvalds 				 (PKTSZ - data_offset)));
16201da177e4SLinus Torvalds 	}
16211da177e4SLinus Torvalds 
16221da177e4SLinus Torvalds 	buffer = kmalloc(transfer_size, GFP_ATOMIC);
16231da177e4SLinus Torvalds 	if (!buffer) {
1624441b62c1SHarvey Harrison 		err("%s ran out of kernel memory for urb ...", __func__);
162562127a58SOliver Neukum 		count = -ENOMEM;
162662127a58SOliver Neukum 		goto error_no_buffer;
16271da177e4SLinus Torvalds 	}
16281da177e4SLinus Torvalds 
16291da177e4SLinus Torvalds 	urb = usb_alloc_urb(0, GFP_ATOMIC);
16301da177e4SLinus Torvalds 	if (!urb) {
1631441b62c1SHarvey Harrison 		err("%s - no more free urbs", __func__);
163262127a58SOliver Neukum 		count = -ENOMEM;
163362127a58SOliver Neukum 		goto error_no_urb;
16341da177e4SLinus Torvalds 	}
16351da177e4SLinus Torvalds 
16361da177e4SLinus Torvalds 	/* Copy data */
16371da177e4SLinus Torvalds 	if (data_offset > 0) {
1638464cbb24SAlan Cox 		/* Original sio requires control byte at start of
1639464cbb24SAlan Cox 		   each packet. */
16401da177e4SLinus Torvalds 		int user_pktsz = PKTSZ - data_offset;
16411da177e4SLinus Torvalds 		int todo = count;
16421da177e4SLinus Torvalds 		unsigned char *first_byte = buffer;
16431da177e4SLinus Torvalds 		const unsigned char *current_position = buf;
16441da177e4SLinus Torvalds 
16451da177e4SLinus Torvalds 		while (todo > 0) {
1646464cbb24SAlan Cox 			if (user_pktsz > todo)
16471da177e4SLinus Torvalds 				user_pktsz = todo;
16481da177e4SLinus Torvalds 			/* Write the control byte at the front of the packet*/
16491da177e4SLinus Torvalds 			*first_byte = 1 | ((user_pktsz) << 2);
16501da177e4SLinus Torvalds 			/* Copy data for packet */
16511da177e4SLinus Torvalds 			memcpy(first_byte + data_offset,
16521da177e4SLinus Torvalds 				current_position, user_pktsz);
16531da177e4SLinus Torvalds 			first_byte += user_pktsz + data_offset;
16541da177e4SLinus Torvalds 			current_position += user_pktsz;
16551da177e4SLinus Torvalds 			todo -= user_pktsz;
16561da177e4SLinus Torvalds 		}
16571da177e4SLinus Torvalds 	} else {
16581da177e4SLinus Torvalds 		/* No control byte required. */
16591da177e4SLinus Torvalds 		/* Copy in the data to send */
16601da177e4SLinus Torvalds 		memcpy(buffer, buf, count);
16611da177e4SLinus Torvalds 	}
16621da177e4SLinus Torvalds 
1663464cbb24SAlan Cox 	usb_serial_debug_data(debug, &port->dev, __func__,
1664464cbb24SAlan Cox 						transfer_size, buffer);
16651da177e4SLinus Torvalds 
16661da177e4SLinus Torvalds 	/* fill the buffer and send it */
16671da177e4SLinus Torvalds 	usb_fill_bulk_urb(urb, port->serial->dev,
1668464cbb24SAlan Cox 			usb_sndbulkpipe(port->serial->dev,
1669464cbb24SAlan Cox 					port->bulk_out_endpointAddress),
16701da177e4SLinus Torvalds 			buffer, transfer_size,
16711da177e4SLinus Torvalds 			ftdi_write_bulk_callback, port);
16721da177e4SLinus Torvalds 
16731da177e4SLinus Torvalds 	status = usb_submit_urb(urb, GFP_ATOMIC);
16741da177e4SLinus Torvalds 	if (status) {
1675464cbb24SAlan Cox 		err("%s - failed submitting write urb, error %d",
1676464cbb24SAlan Cox 							__func__, status);
16771da177e4SLinus Torvalds 		count = status;
167862127a58SOliver Neukum 		goto error;
167922465400SIan Abbott 	} else {
168022465400SIan Abbott 		spin_lock_irqsave(&priv->tx_lock, flags);
168122465400SIan Abbott 		priv->tx_outstanding_bytes += count;
168222465400SIan Abbott 		priv->tx_bytes += count;
168322465400SIan Abbott 		spin_unlock_irqrestore(&priv->tx_lock, flags);
16841da177e4SLinus Torvalds 	}
16851da177e4SLinus Torvalds 
16861da177e4SLinus Torvalds 	/* we are done with this urb, so let the host driver
16871da177e4SLinus Torvalds 	 * really free it when it is finished with it */
16881da177e4SLinus Torvalds 	usb_free_urb(urb);
16891da177e4SLinus Torvalds 
1690441b62c1SHarvey Harrison 	dbg("%s write returning: %d", __func__, count);
16911da177e4SLinus Torvalds 	return count;
169262127a58SOliver Neukum error:
169362127a58SOliver Neukum 	usb_free_urb(urb);
169462127a58SOliver Neukum error_no_urb:
169562127a58SOliver Neukum 	kfree(buffer);
169662127a58SOliver Neukum error_no_buffer:
169762127a58SOliver Neukum 	spin_lock_irqsave(&priv->tx_lock, flags);
169862127a58SOliver Neukum 	priv->tx_outstanding_urbs--;
169962127a58SOliver Neukum 	spin_unlock_irqrestore(&priv->tx_lock, flags);
170062127a58SOliver Neukum 	return count;
17011da177e4SLinus Torvalds } /* ftdi_write */
17021da177e4SLinus Torvalds 
17031da177e4SLinus Torvalds 
17041da177e4SLinus Torvalds /* This function may get called when the device is closed */
17051da177e4SLinus Torvalds 
17067d12e780SDavid Howells static void ftdi_write_bulk_callback(struct urb *urb)
17071da177e4SLinus Torvalds {
170822465400SIan Abbott 	unsigned long flags;
1709cdc97792SMing Lei 	struct usb_serial_port *port = urb->context;
171022465400SIan Abbott 	struct ftdi_private *priv;
171122465400SIan Abbott 	int data_offset;       /* will be 1 for the SIO and 0 otherwise */
171222465400SIan Abbott 	unsigned long countback;
17130fb0aa18SGreg Kroah-Hartman 	int status = urb->status;
17141da177e4SLinus Torvalds 
17151da177e4SLinus Torvalds 	/* free up the transfer buffer, as usb_free_urb() does not do this */
17161da177e4SLinus Torvalds 	kfree(urb->transfer_buffer);
17171da177e4SLinus Torvalds 
1718441b62c1SHarvey Harrison 	dbg("%s - port %d", __func__, port->number);
17191da177e4SLinus Torvalds 
17200fb0aa18SGreg Kroah-Hartman 	if (status) {
17210fb0aa18SGreg Kroah-Hartman 		dbg("nonzero write bulk status received: %d", status);
17221da177e4SLinus Torvalds 		return;
17231da177e4SLinus Torvalds 	}
17241da177e4SLinus Torvalds 
172522465400SIan Abbott 	priv = usb_get_serial_port_data(port);
172622465400SIan Abbott 	if (!priv) {
1727441b62c1SHarvey Harrison 		dbg("%s - bad port private data pointer - exiting", __func__);
172822465400SIan Abbott 		return;
172922465400SIan Abbott 	}
173022465400SIan Abbott 	/* account for transferred data */
173122465400SIan Abbott 	countback = urb->actual_length;
173222465400SIan Abbott 	data_offset = priv->write_offset;
173322465400SIan Abbott 	if (data_offset > 0) {
173422465400SIan Abbott 		/* Subtract the control bytes */
1735dfa5ec79SJulia Lawall 		countback -= (data_offset * DIV_ROUND_UP(countback, PKTSZ));
173622465400SIan Abbott 	}
173722465400SIan Abbott 	spin_lock_irqsave(&priv->tx_lock, flags);
173822465400SIan Abbott 	--priv->tx_outstanding_urbs;
173922465400SIan Abbott 	priv->tx_outstanding_bytes -= countback;
174022465400SIan Abbott 	spin_unlock_irqrestore(&priv->tx_lock, flags);
174122465400SIan Abbott 
1742cf2c7481SPete Zaitcev 	usb_serial_port_softint(port);
17431da177e4SLinus Torvalds } /* ftdi_write_bulk_callback */
17441da177e4SLinus Torvalds 
17451da177e4SLinus Torvalds 
174695da310eSAlan Cox static int ftdi_write_room(struct tty_struct *tty)
17471da177e4SLinus Torvalds {
174895da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
174922465400SIan Abbott 	struct ftdi_private *priv = usb_get_serial_port_data(port);
175022465400SIan Abbott 	int room;
175122465400SIan Abbott 	unsigned long flags;
175222465400SIan Abbott 
1753441b62c1SHarvey Harrison 	dbg("%s - port %d", __func__, port->number);
17541da177e4SLinus Torvalds 
175522465400SIan Abbott 	spin_lock_irqsave(&priv->tx_lock, flags);
175622465400SIan Abbott 	if (priv->tx_outstanding_urbs < URB_UPPER_LIMIT) {
17571da177e4SLinus Torvalds 		/*
17581da177e4SLinus Torvalds 		 * We really can take anything the user throws at us
17591da177e4SLinus Torvalds 		 * but let's pick a nice big number to tell the tty
17601da177e4SLinus Torvalds 		 * layer that we have lots of free space
17611da177e4SLinus Torvalds 		 */
176222465400SIan Abbott 		room = 2048;
176322465400SIan Abbott 	} else {
176422465400SIan Abbott 		room = 0;
176522465400SIan Abbott 	}
176622465400SIan Abbott 	spin_unlock_irqrestore(&priv->tx_lock, flags);
176722465400SIan Abbott 	return room;
176895da310eSAlan Cox }
17691da177e4SLinus Torvalds 
177095da310eSAlan Cox static int ftdi_chars_in_buffer(struct tty_struct *tty)
177195da310eSAlan Cox {
177295da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
177322465400SIan Abbott 	struct ftdi_private *priv = usb_get_serial_port_data(port);
177422465400SIan Abbott 	int buffered;
177522465400SIan Abbott 	unsigned long flags;
177622465400SIan Abbott 
1777441b62c1SHarvey Harrison 	dbg("%s - port %d", __func__, port->number);
17781da177e4SLinus Torvalds 
177922465400SIan Abbott 	spin_lock_irqsave(&priv->tx_lock, flags);
178022465400SIan Abbott 	buffered = (int)priv->tx_outstanding_bytes;
178122465400SIan Abbott 	spin_unlock_irqrestore(&priv->tx_lock, flags);
178222465400SIan Abbott 	if (buffered < 0) {
1783441b62c1SHarvey Harrison 		err("%s outstanding tx bytes is negative!", __func__);
178422465400SIan Abbott 		buffered = 0;
178522465400SIan Abbott 	}
178622465400SIan Abbott 	return buffered;
178795da310eSAlan Cox }
17881da177e4SLinus Torvalds 
17897d12e780SDavid Howells static void ftdi_read_bulk_callback(struct urb *urb)
179095da310eSAlan Cox {
1791cdc97792SMing Lei 	struct usb_serial_port *port = urb->context;
17921da177e4SLinus Torvalds 	struct tty_struct *tty;
17931da177e4SLinus Torvalds 	struct ftdi_private *priv;
179422465400SIan Abbott 	unsigned long countread;
179522465400SIan Abbott 	unsigned long flags;
17960fb0aa18SGreg Kroah-Hartman 	int status = urb->status;
17971da177e4SLinus Torvalds 
17981da177e4SLinus Torvalds 	if (urb->number_of_packets > 0) {
1799464cbb24SAlan Cox 		err("%s transfer_buffer_length %d actual_length %d number of packets %d",
1800464cbb24SAlan Cox 				__func__,
1801464cbb24SAlan Cox 				urb->transfer_buffer_length,
1802464cbb24SAlan Cox 				urb->actual_length, urb->number_of_packets);
1803441b62c1SHarvey Harrison 		err("%s transfer_flags %x ", __func__, urb->transfer_flags);
18041da177e4SLinus Torvalds 	}
18051da177e4SLinus Torvalds 
1806441b62c1SHarvey Harrison 	dbg("%s - port %d", __func__, port->number);
18071da177e4SLinus Torvalds 
180895da310eSAlan Cox 	if (port->port.count <= 0)
18091da177e4SLinus Torvalds 		return;
18101da177e4SLinus Torvalds 
1811*4a90f09bSAlan Cox 	tty = tty_port_tty_get(&port->port);
18121da177e4SLinus Torvalds 	if (!tty) {
1813441b62c1SHarvey Harrison 		dbg("%s - bad tty pointer - exiting", __func__);
18141da177e4SLinus Torvalds 		return;
18151da177e4SLinus Torvalds 	}
18161da177e4SLinus Torvalds 
18171da177e4SLinus Torvalds 	priv = usb_get_serial_port_data(port);
18181da177e4SLinus Torvalds 	if (!priv) {
1819441b62c1SHarvey Harrison 		dbg("%s - bad port private data pointer - exiting", __func__);
1820*4a90f09bSAlan Cox 		goto out;
18211da177e4SLinus Torvalds 	}
18221da177e4SLinus Torvalds 
1823464cbb24SAlan Cox 	if (urb != port->read_urb)
1824441b62c1SHarvey Harrison 		err("%s - Not my urb!", __func__);
18251da177e4SLinus Torvalds 
18260fb0aa18SGreg Kroah-Hartman 	if (status) {
1827464cbb24SAlan Cox 		/* This will happen at close every time so it is a dbg not an
1828464cbb24SAlan Cox 		   err */
1829464cbb24SAlan Cox 		dbg("(this is ok on close) nonzero read bulk status received: %d", status);
1830*4a90f09bSAlan Cox 		goto out;
18311da177e4SLinus Torvalds 	}
18321da177e4SLinus Torvalds 
183322465400SIan Abbott 	/* count data bytes, but not status bytes */
183422465400SIan Abbott 	countread = urb->actual_length;
1835dfa5ec79SJulia Lawall 	countread -= 2 * DIV_ROUND_UP(countread, PKTSZ);
183622465400SIan Abbott 	spin_lock_irqsave(&priv->rx_lock, flags);
183722465400SIan Abbott 	priv->rx_bytes += countread;
183822465400SIan Abbott 	spin_unlock_irqrestore(&priv->rx_lock, flags);
183922465400SIan Abbott 
1840c4028958SDavid Howells 	ftdi_process_read(&priv->rx_work.work);
1841*4a90f09bSAlan Cox out:
1842*4a90f09bSAlan Cox 	tty_kref_put(tty);
18431da177e4SLinus Torvalds } /* ftdi_read_bulk_callback */
18441da177e4SLinus Torvalds 
18451da177e4SLinus Torvalds 
1846c4028958SDavid Howells static void ftdi_process_read(struct work_struct *work)
18471da177e4SLinus Torvalds { /* ftdi_process_read */
1848c4028958SDavid Howells 	struct ftdi_private *priv =
1849c4028958SDavid Howells 		container_of(work, struct ftdi_private, rx_work.work);
1850c4028958SDavid Howells 	struct usb_serial_port *port = priv->port;
18511da177e4SLinus Torvalds 	struct urb *urb;
18521da177e4SLinus Torvalds 	struct tty_struct *tty;
18531da177e4SLinus Torvalds 	char error_flag;
18541da177e4SLinus Torvalds 	unsigned char *data;
18551da177e4SLinus Torvalds 
18561da177e4SLinus Torvalds 	int i;
18571da177e4SLinus Torvalds 	int result;
18581da177e4SLinus Torvalds 	int need_flip;
18591da177e4SLinus Torvalds 	int packet_offset;
186076854ceaSIan Abbott 	unsigned long flags;
18611da177e4SLinus Torvalds 
1862441b62c1SHarvey Harrison 	dbg("%s - port %d", __func__, port->number);
18631da177e4SLinus Torvalds 
186495da310eSAlan Cox 	if (port->port.count <= 0)
18651da177e4SLinus Torvalds 		return;
18661da177e4SLinus Torvalds 
1867*4a90f09bSAlan Cox 	tty = tty_port_tty_get(&port->port);
18681da177e4SLinus Torvalds 	if (!tty) {
1869441b62c1SHarvey Harrison 		dbg("%s - bad tty pointer - exiting", __func__);
18701da177e4SLinus Torvalds 		return;
18711da177e4SLinus Torvalds 	}
18721da177e4SLinus Torvalds 
18731da177e4SLinus Torvalds 	priv = usb_get_serial_port_data(port);
18741da177e4SLinus Torvalds 	if (!priv) {
1875441b62c1SHarvey Harrison 		dbg("%s - bad port private data pointer - exiting", __func__);
1876*4a90f09bSAlan Cox 		goto out;
18771da177e4SLinus Torvalds 	}
18781da177e4SLinus Torvalds 
18791da177e4SLinus Torvalds 	urb = port->read_urb;
18801da177e4SLinus Torvalds 	if (!urb) {
1881441b62c1SHarvey Harrison 		dbg("%s - bad read_urb pointer - exiting", __func__);
1882*4a90f09bSAlan Cox 		goto out;
18831da177e4SLinus Torvalds 	}
18841da177e4SLinus Torvalds 
18851da177e4SLinus Torvalds 	data = urb->transfer_buffer;
18861da177e4SLinus Torvalds 
188776854ceaSIan Abbott 	if (priv->rx_processed) {
1888441b62c1SHarvey Harrison 		dbg("%s - already processed: %d bytes, %d remain", __func__,
188976854ceaSIan Abbott 				priv->rx_processed,
189076854ceaSIan Abbott 				urb->actual_length - priv->rx_processed);
189176854ceaSIan Abbott 	} else {
18921da177e4SLinus Torvalds 		/* The first two bytes of every read packet are status */
1893464cbb24SAlan Cox 		if (urb->actual_length > 2)
1894464cbb24SAlan Cox 			usb_serial_debug_data(debug, &port->dev, __func__,
1895464cbb24SAlan Cox 						urb->actual_length, data);
1896464cbb24SAlan Cox 		else
18971da177e4SLinus Torvalds 			dbg("Status only: %03oo %03oo", data[0], data[1]);
18981da177e4SLinus Torvalds 	}
18991da177e4SLinus Torvalds 
19001da177e4SLinus Torvalds 
19011da177e4SLinus Torvalds 	/* TO DO -- check for hung up line and handle appropriately: */
19021da177e4SLinus Torvalds 	/*   send hangup  */
19031da177e4SLinus Torvalds 	/* See acm.c - you do a tty_hangup  - eg tty_hangup(tty) */
19041da177e4SLinus Torvalds 	/* if CD is dropped and the line is not CLOCAL then we should hangup */
19051da177e4SLinus Torvalds 
19061da177e4SLinus Torvalds 	need_flip = 0;
1907464cbb24SAlan Cox 	for (packet_offset = priv->rx_processed;
1908464cbb24SAlan Cox 		packet_offset < urb->actual_length; packet_offset += PKTSZ) {
190976854ceaSIan Abbott 		int length;
191076854ceaSIan Abbott 
1911464cbb24SAlan Cox 		/* Compare new line status to the old one, signal if different/
1912464cbb24SAlan Cox 		   N.B. packet may be processed more than once, but differences
1913464cbb24SAlan Cox 		   are only processed once.  */
19141da177e4SLinus Torvalds 		if (priv != NULL) {
1915464cbb24SAlan Cox 			char new_status = data[packet_offset + 0] &
1916464cbb24SAlan Cox 							FTDI_STATUS_B0_MASK;
19171da177e4SLinus Torvalds 			if (new_status != priv->prev_status) {
1918464cbb24SAlan Cox 				priv->diff_status |=
1919464cbb24SAlan Cox 					new_status ^ priv->prev_status;
19201da177e4SLinus Torvalds 				wake_up_interruptible(&priv->delta_msr_wait);
19211da177e4SLinus Torvalds 				priv->prev_status = new_status;
19221da177e4SLinus Torvalds 			}
19231da177e4SLinus Torvalds 		}
19241da177e4SLinus Torvalds 
192576854ceaSIan Abbott 		length = min(PKTSZ, urb->actual_length-packet_offset)-2;
192676854ceaSIan Abbott 		if (length < 0) {
1927441b62c1SHarvey Harrison 			err("%s - bad packet length: %d", __func__, length+2);
192876854ceaSIan Abbott 			length = 0;
192976854ceaSIan Abbott 		}
193076854ceaSIan Abbott 
193176854ceaSIan Abbott 		if (priv->rx_flags & THROTTLED) {
1932441b62c1SHarvey Harrison 			dbg("%s - throttled", __func__);
193376854ceaSIan Abbott 			break;
193476854ceaSIan Abbott 		}
193533f0f88fSAlan Cox 		if (tty_buffer_request_room(tty, length) < length) {
1936464cbb24SAlan Cox 			/* break out & wait for throttling/unthrottling to
1937464cbb24SAlan Cox 			   happen */
1938441b62c1SHarvey Harrison 			dbg("%s - receive room low", __func__);
193976854ceaSIan Abbott 			break;
194076854ceaSIan Abbott 		}
194176854ceaSIan Abbott 
19421da177e4SLinus Torvalds 		/* Handle errors and break */
19431da177e4SLinus Torvalds 		error_flag = TTY_NORMAL;
1944464cbb24SAlan Cox 		/* Although the device uses a bitmask and hence can have
1945464cbb24SAlan Cox 		   multiple errors on a packet - the order here sets the
1946464cbb24SAlan Cox 		   priority the error is returned to the tty layer  */
19471da177e4SLinus Torvalds 
19481da177e4SLinus Torvalds 		if (data[packet_offset+1] & FTDI_RS_OE) {
19491da177e4SLinus Torvalds 			error_flag = TTY_OVERRUN;
19501da177e4SLinus Torvalds 			dbg("OVERRRUN error");
19511da177e4SLinus Torvalds 		}
19521da177e4SLinus Torvalds 		if (data[packet_offset+1] & FTDI_RS_BI) {
19531da177e4SLinus Torvalds 			error_flag = TTY_BREAK;
19541da177e4SLinus Torvalds 			dbg("BREAK received");
19551da177e4SLinus Torvalds 		}
19561da177e4SLinus Torvalds 		if (data[packet_offset+1] & FTDI_RS_PE) {
19571da177e4SLinus Torvalds 			error_flag = TTY_PARITY;
19581da177e4SLinus Torvalds 			dbg("PARITY error");
19591da177e4SLinus Torvalds 		}
19601da177e4SLinus Torvalds 		if (data[packet_offset+1] & FTDI_RS_FE) {
19611da177e4SLinus Torvalds 			error_flag = TTY_FRAME;
19621da177e4SLinus Torvalds 			dbg("FRAMING error");
19631da177e4SLinus Torvalds 		}
196476854ceaSIan Abbott 		if (length > 0) {
196576854ceaSIan Abbott 			for (i = 2; i < length+2; i++) {
19661da177e4SLinus Torvalds 				/* Note that the error flag is duplicated for
19671da177e4SLinus Torvalds 				   every character received since we don't know
19681da177e4SLinus Torvalds 				   which character it applied to */
1969464cbb24SAlan Cox 				tty_insert_flip_char(tty,
1970464cbb24SAlan Cox 					data[packet_offset + i], error_flag);
19711da177e4SLinus Torvalds 			}
19721da177e4SLinus Torvalds 			need_flip = 1;
19731da177e4SLinus Torvalds 		}
19741da177e4SLinus Torvalds 
19751da177e4SLinus Torvalds #ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
19761da177e4SLinus Torvalds 		/* if a parity error is detected you get status packets forever
19771da177e4SLinus Torvalds 		   until a character is sent without a parity error.
1978464cbb24SAlan Cox 		   This doesn't work well since the application receives a
1979464cbb24SAlan Cox 		   never ending stream of bad data - even though new data
1980464cbb24SAlan Cox 		   hasn't been sent. Therefore I (bill) have taken this out.
19811da177e4SLinus Torvalds 		   However - this might make sense for framing errors and so on
19821da177e4SLinus Torvalds 		   so I am leaving the code in for now.
19831da177e4SLinus Torvalds 		*/
19841da177e4SLinus Torvalds 		else {
19851da177e4SLinus Torvalds 			if (error_flag != TTY_NORMAL) {
19861da177e4SLinus Torvalds 				dbg("error_flag is not normal");
1987464cbb24SAlan Cox 				/* In this case it is just status - if that is
1988464cbb24SAlan Cox 				   an error send a bad character */
1989464cbb24SAlan Cox 				if (tty->flip.count >= TTY_FLIPBUF_SIZE)
19901da177e4SLinus Torvalds 					tty_flip_buffer_push(tty);
19911da177e4SLinus Torvalds 				tty_insert_flip_char(tty, 0xff, error_flag);
19921da177e4SLinus Torvalds 				need_flip = 1;
19931da177e4SLinus Torvalds 			}
19941da177e4SLinus Torvalds 		}
19951da177e4SLinus Torvalds #endif
19961da177e4SLinus Torvalds 	} /* "for(packet_offset=0..." */
19971da177e4SLinus Torvalds 
19981da177e4SLinus Torvalds 	/* Low latency */
1999464cbb24SAlan Cox 	if (need_flip)
20001da177e4SLinus Torvalds 		tty_flip_buffer_push(tty);
20011da177e4SLinus Torvalds 
200276854ceaSIan Abbott 	if (packet_offset < urb->actual_length) {
200376854ceaSIan Abbott 		/* not completely processed - record progress */
200476854ceaSIan Abbott 		priv->rx_processed = packet_offset;
200576854ceaSIan Abbott 		dbg("%s - incomplete, %d bytes processed, %d remain",
2006441b62c1SHarvey Harrison 				__func__, packet_offset,
200776854ceaSIan Abbott 				urb->actual_length - packet_offset);
200876854ceaSIan Abbott 		/* check if we were throttled while processing */
200976854ceaSIan Abbott 		spin_lock_irqsave(&priv->rx_lock, flags);
201076854ceaSIan Abbott 		if (priv->rx_flags & THROTTLED) {
201176854ceaSIan Abbott 			priv->rx_flags |= ACTUALLY_THROTTLED;
201276854ceaSIan Abbott 			spin_unlock_irqrestore(&priv->rx_lock, flags);
201376854ceaSIan Abbott 			dbg("%s - deferring remainder until unthrottled",
2014441b62c1SHarvey Harrison 					__func__);
201576854ceaSIan Abbott 			return;
201676854ceaSIan Abbott 		}
201776854ceaSIan Abbott 		spin_unlock_irqrestore(&priv->rx_lock, flags);
201876854ceaSIan Abbott 		/* if the port is closed stop trying to read */
2019464cbb24SAlan Cox 		if (port->port.count > 0)
202076854ceaSIan Abbott 			/* delay processing of remainder */
202176854ceaSIan Abbott 			schedule_delayed_work(&priv->rx_work, 1);
2022464cbb24SAlan Cox 		else
2023441b62c1SHarvey Harrison 			dbg("%s - port is closed", __func__);
2024*4a90f09bSAlan Cox 		goto out;
202576854ceaSIan Abbott 	}
202676854ceaSIan Abbott 
202776854ceaSIan Abbott 	/* urb is completely processed */
202876854ceaSIan Abbott 	priv->rx_processed = 0;
202976854ceaSIan Abbott 
20301da177e4SLinus Torvalds 	/* if the port is closed stop trying to read */
203195da310eSAlan Cox 	if (port->port.count > 0) {
20321da177e4SLinus Torvalds 		/* Continue trying to always read  */
20331da177e4SLinus Torvalds 		usb_fill_bulk_urb(port->read_urb, port->serial->dev,
2034464cbb24SAlan Cox 			usb_rcvbulkpipe(port->serial->dev,
2035464cbb24SAlan Cox 					port->bulk_in_endpointAddress),
2036464cbb24SAlan Cox 			port->read_urb->transfer_buffer,
2037464cbb24SAlan Cox 			port->read_urb->transfer_buffer_length,
20381da177e4SLinus Torvalds 			ftdi_read_bulk_callback, port);
20391da177e4SLinus Torvalds 
20401da177e4SLinus Torvalds 		result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
20411da177e4SLinus Torvalds 		if (result)
2042464cbb24SAlan Cox 			err("%s - failed resubmitting read urb, error %d",
2043464cbb24SAlan Cox 							__func__, result);
20441da177e4SLinus Torvalds 	}
2045*4a90f09bSAlan Cox out:
2046*4a90f09bSAlan Cox 	tty_kref_put(tty);
20471da177e4SLinus Torvalds } /* ftdi_process_read */
20481da177e4SLinus Torvalds 
20491da177e4SLinus Torvalds 
205095da310eSAlan Cox static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
20511da177e4SLinus Torvalds {
205295da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
20531da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
20541da177e4SLinus Torvalds 	__u16 urb_value = 0;
20551da177e4SLinus Torvalds 	char buf[1];
20561da177e4SLinus Torvalds 
20571da177e4SLinus Torvalds 	/* break_state = -1 to turn on break, and 0 to turn off break */
20581da177e4SLinus Torvalds 	/* see drivers/char/tty_io.c to see it used */
20591da177e4SLinus Torvalds 	/* last_set_data_urb_value NEVER has the break bit set in it */
20601da177e4SLinus Torvalds 
2061464cbb24SAlan Cox 	if (break_state)
20621da177e4SLinus Torvalds 		urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;
2063464cbb24SAlan Cox 	else
20641da177e4SLinus Torvalds 		urb_value = priv->last_set_data_urb_value;
20651da177e4SLinus Torvalds 
2066464cbb24SAlan Cox 	if (usb_control_msg(port->serial->dev,
2067464cbb24SAlan Cox 			usb_sndctrlpipe(port->serial->dev, 0),
20681da177e4SLinus Torvalds 			FTDI_SIO_SET_DATA_REQUEST,
20691da177e4SLinus Torvalds 			FTDI_SIO_SET_DATA_REQUEST_TYPE,
20701da177e4SLinus Torvalds 			urb_value , priv->interface,
20711da177e4SLinus Torvalds 			buf, 0, WDR_TIMEOUT) < 0) {
2072464cbb24SAlan Cox 		err("%s FAILED to enable/disable break state (state was %d)",
2073464cbb24SAlan Cox 							__func__, break_state);
20741da177e4SLinus Torvalds 	}
20751da177e4SLinus Torvalds 
2076464cbb24SAlan Cox 	dbg("%s break state is %d - urb is %d", __func__,
2077464cbb24SAlan Cox 						break_state, urb_value);
20781da177e4SLinus Torvalds 
20791da177e4SLinus Torvalds }
20801da177e4SLinus Torvalds 
20811da177e4SLinus Torvalds 
20821da177e4SLinus Torvalds /* old_termios contains the original termios settings and tty->termios contains
20831da177e4SLinus Torvalds  * the new setting to be used
20841da177e4SLinus Torvalds  * WARNING: set_termios calls this with old_termios in kernel space
20851da177e4SLinus Torvalds  */
20861da177e4SLinus Torvalds 
208795da310eSAlan Cox static void ftdi_set_termios(struct tty_struct *tty,
208895da310eSAlan Cox 		struct usb_serial_port *port, struct ktermios *old_termios)
20891da177e4SLinus Torvalds { /* ftdi_termios */
20901da177e4SLinus Torvalds 	struct usb_device *dev = port->serial->dev;
20911da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
209295da310eSAlan Cox 	struct ktermios *termios = tty->termios;
2093669a6db1SAlan Cox 	unsigned int cflag = termios->c_cflag;
20941da177e4SLinus Torvalds 	__u16 urb_value; /* will hold the new flags */
20951da177e4SLinus Torvalds 	char buf[1]; /* Perhaps I should dynamically alloc this? */
20961da177e4SLinus Torvalds 
2097464cbb24SAlan Cox 	/* Added for xon/xoff support */
2098669a6db1SAlan Cox 	unsigned int iflag = termios->c_iflag;
20991da177e4SLinus Torvalds 	unsigned char vstop;
21001da177e4SLinus Torvalds 	unsigned char vstart;
21011da177e4SLinus Torvalds 
2102441b62c1SHarvey Harrison 	dbg("%s", __func__);
21031da177e4SLinus Torvalds 
2104464cbb24SAlan Cox 	/* Force baud rate if this device requires it, unless it is set to
2105464cbb24SAlan Cox 	   B0. */
2106669a6db1SAlan Cox 	if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) {
2107441b62c1SHarvey Harrison 		dbg("%s: forcing baud rate for this device", __func__);
210895da310eSAlan Cox 		tty_encode_baud_rate(tty, priv->force_baud,
2109bd5e47ccSAndrew Morton 					priv->force_baud);
21101da177e4SLinus Torvalds 	}
21111da177e4SLinus Torvalds 
21121da177e4SLinus Torvalds 	/* Force RTS-CTS if this device requires it. */
21131da177e4SLinus Torvalds 	if (priv->force_rtscts) {
2114441b62c1SHarvey Harrison 		dbg("%s: forcing rtscts for this device", __func__);
2115669a6db1SAlan Cox 		termios->c_cflag |= CRTSCTS;
21161da177e4SLinus Torvalds 	}
21171da177e4SLinus Torvalds 
2118669a6db1SAlan Cox 	cflag = termios->c_cflag;
21191da177e4SLinus Torvalds 
21201da177e4SLinus Torvalds 	/* FIXME -For this cut I don't care if the line is really changing or
21211da177e4SLinus Torvalds 	   not  - so just do the change regardless  - should be able to
21221da177e4SLinus Torvalds 	   compare old_termios and tty->termios */
21231da177e4SLinus Torvalds 	/* NOTE These routines can get interrupted by
2124464cbb24SAlan Cox 	   ftdi_sio_read_bulk_callback  - need to examine what this means -
2125464cbb24SAlan Cox 	   don't see any problems yet */
21261da177e4SLinus Torvalds 
21271da177e4SLinus Torvalds 	/* Set number of data bits, parity, stop bits */
21281da177e4SLinus Torvalds 
2129669a6db1SAlan Cox 	termios->c_cflag &= ~CMSPAR;
2130669a6db1SAlan Cox 
21311da177e4SLinus Torvalds 	urb_value = 0;
21321da177e4SLinus Torvalds 	urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 :
21331da177e4SLinus Torvalds 		      FTDI_SIO_SET_DATA_STOP_BITS_1);
21341da177e4SLinus Torvalds 	urb_value |= (cflag & PARENB ?
21351da177e4SLinus Torvalds 		      (cflag & PARODD ? FTDI_SIO_SET_DATA_PARITY_ODD :
21361da177e4SLinus Torvalds 		       FTDI_SIO_SET_DATA_PARITY_EVEN) :
21371da177e4SLinus Torvalds 		      FTDI_SIO_SET_DATA_PARITY_NONE);
21381da177e4SLinus Torvalds 	if (cflag & CSIZE) {
21391da177e4SLinus Torvalds 		switch (cflag & CSIZE) {
21401da177e4SLinus Torvalds 		case CS5: urb_value |= 5; dbg("Setting CS5"); break;
21411da177e4SLinus Torvalds 		case CS6: urb_value |= 6; dbg("Setting CS6"); break;
21421da177e4SLinus Torvalds 		case CS7: urb_value |= 7; dbg("Setting CS7"); break;
21431da177e4SLinus Torvalds 		case CS8: urb_value |= 8; dbg("Setting CS8"); break;
21441da177e4SLinus Torvalds 		default:
21451da177e4SLinus Torvalds 			err("CSIZE was set but not CS5-CS8");
21461da177e4SLinus Torvalds 		}
21471da177e4SLinus Torvalds 	}
21481da177e4SLinus Torvalds 
2149464cbb24SAlan Cox 	/* This is needed by the break command since it uses the same command
2150464cbb24SAlan Cox 	   - but is or'ed with this value  */
21511da177e4SLinus Torvalds 	priv->last_set_data_urb_value = urb_value;
21521da177e4SLinus Torvalds 
21531da177e4SLinus Torvalds 	if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
21541da177e4SLinus Torvalds 			    FTDI_SIO_SET_DATA_REQUEST,
21551da177e4SLinus Torvalds 			    FTDI_SIO_SET_DATA_REQUEST_TYPE,
21561da177e4SLinus Torvalds 			    urb_value , priv->interface,
2157279e1545SIan Abbott 			    buf, 0, WDR_SHORT_TIMEOUT) < 0) {
2158441b62c1SHarvey Harrison 		err("%s FAILED to set databits/stopbits/parity", __func__);
21591da177e4SLinus Torvalds 	}
21601da177e4SLinus Torvalds 
21611da177e4SLinus Torvalds 	/* Now do the baudrate */
21621da177e4SLinus Torvalds 	if ((cflag & CBAUD) == B0) {
21631da177e4SLinus Torvalds 		/* Disable flow control */
21641da177e4SLinus Torvalds 		if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
21651da177e4SLinus Torvalds 				    FTDI_SIO_SET_FLOW_CTRL_REQUEST,
21661da177e4SLinus Torvalds 				    FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
21671da177e4SLinus Torvalds 				    0, priv->interface,
21681da177e4SLinus Torvalds 				    buf, 0, WDR_TIMEOUT) < 0) {
2169441b62c1SHarvey Harrison 			err("%s error from disable flowcontrol urb", __func__);
21701da177e4SLinus Torvalds 		}
21711da177e4SLinus Torvalds 		/* Drop RTS and DTR */
217274ede0ffSIan Abbott 		clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
21731da177e4SLinus Torvalds 	} else {
21741da177e4SLinus Torvalds 		/* set the baudrate determined before */
2175464cbb24SAlan Cox 		if (change_speed(tty, port))
2176441b62c1SHarvey Harrison 			err("%s urb failed to set baudrate", __func__);
217772a755fcSPeter Favrholdt 		/* Ensure RTS and DTR are raised when baudrate changed from 0 */
2178464cbb24SAlan Cox 		if (!old_termios || (old_termios->c_cflag & CBAUD) == B0)
217974ede0ffSIan Abbott 			set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
21801da177e4SLinus Torvalds 	}
21811da177e4SLinus Torvalds 
21821da177e4SLinus Torvalds 	/* Set flow control */
21831da177e4SLinus Torvalds 	/* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */
21841da177e4SLinus Torvalds 	if (cflag & CRTSCTS) {
2185441b62c1SHarvey Harrison 		dbg("%s Setting to CRTSCTS flow control", __func__);
21861da177e4SLinus Torvalds 		if (usb_control_msg(dev,
21871da177e4SLinus Torvalds 				    usb_sndctrlpipe(dev, 0),
21881da177e4SLinus Torvalds 				    FTDI_SIO_SET_FLOW_CTRL_REQUEST,
21891da177e4SLinus Torvalds 				    FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
21901da177e4SLinus Torvalds 				    0 , (FTDI_SIO_RTS_CTS_HS | priv->interface),
21911da177e4SLinus Torvalds 				    buf, 0, WDR_TIMEOUT) < 0) {
21921da177e4SLinus Torvalds 			err("urb failed to set to rts/cts flow control");
21931da177e4SLinus Torvalds 		}
21941da177e4SLinus Torvalds 
21951da177e4SLinus Torvalds 	} else {
21961da177e4SLinus Torvalds 		/*
21971da177e4SLinus Torvalds 		 * Xon/Xoff code
21981da177e4SLinus Torvalds 		 *
2199464cbb24SAlan Cox 		 * Check the IXOFF status in the iflag component of the
2200464cbb24SAlan Cox 		 * termios structure. If IXOFF is not set, the pre-xon/xoff
2201464cbb24SAlan Cox 		 * code is executed.
22021da177e4SLinus Torvalds 		 */
22031da177e4SLinus Torvalds 		if (iflag & IXOFF) {
2204464cbb24SAlan Cox 			dbg("%s  request to enable xonxoff iflag=%04x",
2205464cbb24SAlan Cox 							__func__, iflag);
2206464cbb24SAlan Cox 			/* Try to enable the XON/XOFF on the ftdi_sio
2207464cbb24SAlan Cox 			 * Set the vstart and vstop -- could have been done up
2208464cbb24SAlan Cox 			 * above where a lot of other dereferencing is done but
2209464cbb24SAlan Cox 			 * that would be very inefficient as vstart and vstop
2210464cbb24SAlan Cox 			 * are not always needed.
2211464cbb24SAlan Cox 			 */
2212669a6db1SAlan Cox 			vstart = termios->c_cc[VSTART];
2213669a6db1SAlan Cox 			vstop = termios->c_cc[VSTOP];
22141da177e4SLinus Torvalds 			urb_value = (vstop << 8) | (vstart);
22151da177e4SLinus Torvalds 
22161da177e4SLinus Torvalds 			if (usb_control_msg(dev,
22171da177e4SLinus Torvalds 					    usb_sndctrlpipe(dev, 0),
22181da177e4SLinus Torvalds 					    FTDI_SIO_SET_FLOW_CTRL_REQUEST,
22191da177e4SLinus Torvalds 					    FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
22201da177e4SLinus Torvalds 					    urb_value , (FTDI_SIO_XON_XOFF_HS
22211da177e4SLinus Torvalds 							 | priv->interface),
22221da177e4SLinus Torvalds 					    buf, 0, WDR_TIMEOUT) < 0) {
22231da177e4SLinus Torvalds 				err("urb failed to set to xon/xoff flow control");
22241da177e4SLinus Torvalds 			}
22251da177e4SLinus Torvalds 		} else {
2226464cbb24SAlan Cox 			/* else clause to only run if cflag ! CRTSCTS and iflag
2227464cbb24SAlan Cox 			 * ! XOFF. CHECKME Assuming XON/XOFF handled by tty
2228464cbb24SAlan Cox 			 * stack - not by device */
2229441b62c1SHarvey Harrison 			dbg("%s Turning off hardware flow control", __func__);
22301da177e4SLinus Torvalds 			if (usb_control_msg(dev,
22311da177e4SLinus Torvalds 					    usb_sndctrlpipe(dev, 0),
22321da177e4SLinus Torvalds 					    FTDI_SIO_SET_FLOW_CTRL_REQUEST,
22331da177e4SLinus Torvalds 					    FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
22341da177e4SLinus Torvalds 					    0, priv->interface,
22351da177e4SLinus Torvalds 					    buf, 0, WDR_TIMEOUT) < 0) {
22361da177e4SLinus Torvalds 				err("urb failed to clear flow control");
22371da177e4SLinus Torvalds 			}
22381da177e4SLinus Torvalds 		}
22391da177e4SLinus Torvalds 
22401da177e4SLinus Torvalds 	}
22411da177e4SLinus Torvalds 	return;
224295da310eSAlan Cox }
22431da177e4SLinus Torvalds 
224495da310eSAlan Cox static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
22451da177e4SLinus Torvalds {
224695da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
22471da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
22481da177e4SLinus Torvalds 	unsigned char buf[2];
22491da177e4SLinus Torvalds 	int ret;
22501da177e4SLinus Torvalds 
2251441b62c1SHarvey Harrison 	dbg("%s TIOCMGET", __func__);
22521da177e4SLinus Torvalds 	switch (priv->chip_type) {
22531da177e4SLinus Torvalds 	case SIO:
22541da177e4SLinus Torvalds 		/* Request the status from the device */
2255464cbb24SAlan Cox 		ret = usb_control_msg(port->serial->dev,
22561da177e4SLinus Torvalds 			   usb_rcvctrlpipe(port->serial->dev, 0),
22571da177e4SLinus Torvalds 			   FTDI_SIO_GET_MODEM_STATUS_REQUEST,
22581da177e4SLinus Torvalds 			   FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
22591da177e4SLinus Torvalds 			   0, 0,
2260464cbb24SAlan Cox 			   buf, 1, WDR_TIMEOUT);
2261464cbb24SAlan Cox 		if (ret < 0) {
226243b11d33SAlan Cox 			dbg("%s Could not get modem status of device - err: %d", __func__,
22631da177e4SLinus Torvalds 			    ret);
2264464cbb24SAlan Cox 			return ret;
22651da177e4SLinus Torvalds 		}
22661da177e4SLinus Torvalds 		break;
22671da177e4SLinus Torvalds 	case FT8U232AM:
22681da177e4SLinus Torvalds 	case FT232BM:
22691da177e4SLinus Torvalds 	case FT2232C:
2270ed6e5282SAndrew M. Bishop 	case FT232RL:
2271464cbb24SAlan Cox 		/* the 8U232AM returns a two byte value (the sio is a 1 byte
2272464cbb24SAlan Cox 		   value) - in the same format as the data returned from the in
2273464cbb24SAlan Cox 		   point */
2274464cbb24SAlan Cox 		ret = usb_control_msg(port->serial->dev,
22751da177e4SLinus Torvalds 				   usb_rcvctrlpipe(port->serial->dev, 0),
22761da177e4SLinus Torvalds 				   FTDI_SIO_GET_MODEM_STATUS_REQUEST,
22771da177e4SLinus Torvalds 				   FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
22781da177e4SLinus Torvalds 				   0, priv->interface,
2279464cbb24SAlan Cox 				   buf, 2, WDR_TIMEOUT);
2280464cbb24SAlan Cox 		if (ret < 0) {
228143b11d33SAlan Cox 			dbg("%s Could not get modem status of device - err: %d", __func__,
22821da177e4SLinus Torvalds 			    ret);
2283464cbb24SAlan Cox 			return ret;
22841da177e4SLinus Torvalds 		}
22851da177e4SLinus Torvalds 		break;
22861da177e4SLinus Torvalds 	default:
22871da177e4SLinus Torvalds 		return -EFAULT;
22881da177e4SLinus Torvalds 		break;
22891da177e4SLinus Torvalds 	}
22901da177e4SLinus Torvalds 
22911da177e4SLinus Torvalds 	return  (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) |
22921da177e4SLinus Torvalds 		(buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) |
22931da177e4SLinus Torvalds 		(buf[0]  & FTDI_SIO_RI_MASK  ? TIOCM_RI  : 0) |
22941da177e4SLinus Torvalds 		(buf[0]  & FTDI_SIO_RLSD_MASK ? TIOCM_CD  : 0) |
22951da177e4SLinus Torvalds 		priv->last_dtr_rts;
22961da177e4SLinus Torvalds }
22971da177e4SLinus Torvalds 
229895da310eSAlan Cox static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
229995da310eSAlan Cox 			unsigned int set, unsigned int clear)
23001da177e4SLinus Torvalds {
230195da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
2302441b62c1SHarvey Harrison 	dbg("%s TIOCMSET", __func__);
230374ede0ffSIan Abbott 	return update_mctrl(port, set, clear);
23041da177e4SLinus Torvalds }
23051da177e4SLinus Torvalds 
23061da177e4SLinus Torvalds 
2307464cbb24SAlan Cox static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2308464cbb24SAlan Cox 					unsigned int cmd, unsigned long arg)
23091da177e4SLinus Torvalds {
231095da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
23111da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
23121da177e4SLinus Torvalds 
2313441b62c1SHarvey Harrison 	dbg("%s cmd 0x%04x", __func__, cmd);
23141da177e4SLinus Torvalds 
23151da177e4SLinus Torvalds 	/* Based on code from acm.c and others */
23161da177e4SLinus Torvalds 	switch (cmd) {
23171da177e4SLinus Torvalds 
23181da177e4SLinus Torvalds 	case TIOCGSERIAL: /* gets serial port data */
2319464cbb24SAlan Cox 		return get_serial_info(port,
2320464cbb24SAlan Cox 					(struct serial_struct __user *) arg);
23211da177e4SLinus Torvalds 
23221da177e4SLinus Torvalds 	case TIOCSSERIAL: /* sets serial port data */
2323464cbb24SAlan Cox 		return set_serial_info(tty, port,
2324464cbb24SAlan Cox 					(struct serial_struct __user *) arg);
23251da177e4SLinus Torvalds 
23261da177e4SLinus Torvalds 	/*
23271da177e4SLinus Torvalds 	 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
23281da177e4SLinus Torvalds 	 * - mask passed in arg for lines of interest
23291da177e4SLinus Torvalds 	 *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
23301da177e4SLinus Torvalds 	 * Caller should use TIOCGICOUNT to see which one it was.
23311da177e4SLinus Torvalds 	 *
23321da177e4SLinus Torvalds 	 * This code is borrowed from linux/drivers/char/serial.c
23331da177e4SLinus Torvalds 	 */
23341da177e4SLinus Torvalds 	case TIOCMIWAIT:
23351da177e4SLinus Torvalds 		while (priv != NULL) {
23361da177e4SLinus Torvalds 			interruptible_sleep_on(&priv->delta_msr_wait);
23371da177e4SLinus Torvalds 			/* see if a signal did it */
23381da177e4SLinus Torvalds 			if (signal_pending(current))
23391da177e4SLinus Torvalds 				return -ERESTARTSYS;
23401da177e4SLinus Torvalds 			else {
23411da177e4SLinus Torvalds 				char diff = priv->diff_status;
23421da177e4SLinus Torvalds 
2343464cbb24SAlan Cox 				if (diff == 0)
23441da177e4SLinus Torvalds 					return -EIO; /* no change => error */
23451da177e4SLinus Torvalds 
23461da177e4SLinus Torvalds 				/* Consume all events */
23471da177e4SLinus Torvalds 				priv->diff_status = 0;
23481da177e4SLinus Torvalds 
2349464cbb24SAlan Cox 				/* Return 0 if caller wanted to know about
2350464cbb24SAlan Cox 				   these bits */
23511da177e4SLinus Torvalds 				if (((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
23521da177e4SLinus Torvalds 				    ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
23531da177e4SLinus Torvalds 				    ((arg & TIOCM_CD)  && (diff & FTDI_RS0_RLSD)) ||
23541da177e4SLinus Torvalds 				    ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS))) {
23551da177e4SLinus Torvalds 					return 0;
23561da177e4SLinus Torvalds 				}
23571da177e4SLinus Torvalds 				/*
2358464cbb24SAlan Cox 				 * Otherwise caller can't care less about what
2359464cbb24SAlan Cox 				 * happened,and so we continue to wait for more
2360464cbb24SAlan Cox 				 * events.
23611da177e4SLinus Torvalds 				 */
23621da177e4SLinus Torvalds 			}
23631da177e4SLinus Torvalds 		}
236495da310eSAlan Cox 		return 0;
23651da177e4SLinus Torvalds 	default:
23661da177e4SLinus Torvalds 		break;
23671da177e4SLinus Torvalds 	}
2368464cbb24SAlan Cox 	/* This is not necessarily an error - turns out the higher layers
2369464cbb24SAlan Cox 	 * will do some ioctls themselves (see comment above)
23701da177e4SLinus Torvalds 	 */
2371441b62c1SHarvey Harrison 	dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd);
237295da310eSAlan Cox 	return -ENOIOCTLCMD;
237395da310eSAlan Cox }
23741da177e4SLinus Torvalds 
237595da310eSAlan Cox static void ftdi_throttle(struct tty_struct *tty)
23761da177e4SLinus Torvalds {
237795da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
23781da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
23791da177e4SLinus Torvalds 	unsigned long flags;
23801da177e4SLinus Torvalds 
2381441b62c1SHarvey Harrison 	dbg("%s - port %d", __func__, port->number);
23821da177e4SLinus Torvalds 
23831da177e4SLinus Torvalds 	spin_lock_irqsave(&priv->rx_lock, flags);
23841da177e4SLinus Torvalds 	priv->rx_flags |= THROTTLED;
23851da177e4SLinus Torvalds 	spin_unlock_irqrestore(&priv->rx_lock, flags);
23861da177e4SLinus Torvalds }
23871da177e4SLinus Torvalds 
23881da177e4SLinus Torvalds 
238995da310eSAlan Cox static void ftdi_unthrottle(struct tty_struct *tty)
23901da177e4SLinus Torvalds {
239195da310eSAlan Cox 	struct usb_serial_port *port = tty->driver_data;
23921da177e4SLinus Torvalds 	struct ftdi_private *priv = usb_get_serial_port_data(port);
23931da177e4SLinus Torvalds 	int actually_throttled;
23941da177e4SLinus Torvalds 	unsigned long flags;
23951da177e4SLinus Torvalds 
2396441b62c1SHarvey Harrison 	dbg("%s - port %d", __func__, port->number);
23971da177e4SLinus Torvalds 
23981da177e4SLinus Torvalds 	spin_lock_irqsave(&priv->rx_lock, flags);
23991da177e4SLinus Torvalds 	actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
24001da177e4SLinus Torvalds 	priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
24011da177e4SLinus Torvalds 	spin_unlock_irqrestore(&priv->rx_lock, flags);
24021da177e4SLinus Torvalds 
24031da177e4SLinus Torvalds 	if (actually_throttled)
2404c4028958SDavid Howells 		schedule_delayed_work(&priv->rx_work, 0);
24051da177e4SLinus Torvalds }
24061da177e4SLinus Torvalds 
24071da177e4SLinus Torvalds static int __init ftdi_init(void)
24081da177e4SLinus Torvalds {
24091da177e4SLinus Torvalds 	int retval;
24101da177e4SLinus Torvalds 
2411441b62c1SHarvey Harrison 	dbg("%s", __func__);
2412fdcb0a0fSIan Abbott 	if (vendor > 0 && product > 0) {
2413fdcb0a0fSIan Abbott 		/* Add user specified VID/PID to reserved element of table. */
2414fdcb0a0fSIan Abbott 		int i;
2415fdcb0a0fSIan Abbott 		for (i = 0; id_table_combined[i].idVendor; i++)
2416fdcb0a0fSIan Abbott 			;
2417fdcb0a0fSIan Abbott 		id_table_combined[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
2418fdcb0a0fSIan Abbott 		id_table_combined[i].idVendor = vendor;
2419fdcb0a0fSIan Abbott 		id_table_combined[i].idProduct = product;
2420fdcb0a0fSIan Abbott 	}
24218f977e42SIan Abbott 	retval = usb_serial_register(&ftdi_sio_device);
24221da177e4SLinus Torvalds 	if (retval)
24238f977e42SIan Abbott 		goto failed_sio_register;
24241da177e4SLinus Torvalds 	retval = usb_register(&ftdi_driver);
24251da177e4SLinus Torvalds 	if (retval)
24261da177e4SLinus Torvalds 		goto failed_usb_register;
24271da177e4SLinus Torvalds 
24281da177e4SLinus Torvalds 	info(DRIVER_VERSION ":" DRIVER_DESC);
24291da177e4SLinus Torvalds 	return 0;
24301da177e4SLinus Torvalds failed_usb_register:
24318f977e42SIan Abbott 	usb_serial_deregister(&ftdi_sio_device);
24328f977e42SIan Abbott failed_sio_register:
24331da177e4SLinus Torvalds 	return retval;
24341da177e4SLinus Torvalds }
24351da177e4SLinus Torvalds 
24361da177e4SLinus Torvalds 
24371da177e4SLinus Torvalds static void __exit ftdi_exit(void)
24381da177e4SLinus Torvalds {
24391da177e4SLinus Torvalds 
2440441b62c1SHarvey Harrison 	dbg("%s", __func__);
24411da177e4SLinus Torvalds 
24421da177e4SLinus Torvalds 	usb_deregister(&ftdi_driver);
24438f977e42SIan Abbott 	usb_serial_deregister(&ftdi_sio_device);
24441da177e4SLinus Torvalds 
24451da177e4SLinus Torvalds }
24461da177e4SLinus Torvalds 
24471da177e4SLinus Torvalds 
24481da177e4SLinus Torvalds module_init(ftdi_init);
24491da177e4SLinus Torvalds module_exit(ftdi_exit);
24501da177e4SLinus Torvalds 
24511da177e4SLinus Torvalds MODULE_AUTHOR(DRIVER_AUTHOR);
24521da177e4SLinus Torvalds MODULE_DESCRIPTION(DRIVER_DESC);
24531da177e4SLinus Torvalds MODULE_LICENSE("GPL");
24541da177e4SLinus Torvalds 
24551da177e4SLinus Torvalds module_param(debug, bool, S_IRUGO | S_IWUSR);
24561da177e4SLinus Torvalds MODULE_PARM_DESC(debug, "Debug enabled or not");
2457fdcb0a0fSIan Abbott module_param(vendor, ushort, 0);
2458fdcb0a0fSIan Abbott MODULE_PARM_DESC(vendor, "User specified vendor ID (default="
2459fdcb0a0fSIan Abbott 		__MODULE_STRING(FTDI_VID)")");
2460fdcb0a0fSIan Abbott module_param(product, ushort, 0);
2461fdcb0a0fSIan Abbott MODULE_PARM_DESC(vendor, "User specified product ID");
24621da177e4SLinus Torvalds 
2463