]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/usb/serial/ftdi_sio.c
USB: ftdi_sio: Add USB Product Id for ELV HS485
[karo-tx-linux.git] / drivers / usb / serial / ftdi_sio.c
1 /*
2  * USB FTDI SIO driver
3  *
4  *      Copyright (C) 1999 - 2001
5  *          Greg Kroah-Hartman (greg@kroah.com)
6  *          Bill Ryder (bryder@sgi.com)
7  *      Copyright (C) 2002
8  *          Kuba Ober (kuba@mareimbrium.org)
9  *
10  *      This program is free software; you can redistribute it and/or modify
11  *      it under the terms of the GNU General Public License as published by
12  *      the Free Software Foundation; either version 2 of the License, or
13  *      (at your option) any later version.
14  *
15  * See Documentation/usb/usb-serial.txt for more information on using this driver
16  *
17  * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
18  *      and extra documentation
19  *
20  * Change entries from 2004 and earlier can be found in versions of this
21  * file in kernel versions prior to the 2.6.24 release.
22  *
23  */
24
25 /* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */
26 /* Thanx to FTDI for so kindly providing details of the protocol required */
27 /*   to talk to the device */
28 /* Thanx to gkh and the rest of the usb dev group for all code I have assimilated :-) */
29
30 #include <linux/kernel.h>
31 #include <linux/errno.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/tty.h>
35 #include <linux/tty_driver.h>
36 #include <linux/tty_flip.h>
37 #include <linux/module.h>
38 #include <linux/spinlock.h>
39 #include <asm/uaccess.h>
40 #include <linux/usb.h>
41 #include <linux/serial.h>
42 #include <linux/usb/serial.h>
43 #include "ftdi_sio.h"
44
45 /*
46  * Version Information
47  */
48 #define DRIVER_VERSION "v1.4.3"
49 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>"
50 #define DRIVER_DESC "USB FTDI Serial Converters Driver"
51
52 static int debug;
53 static __u16 vendor = FTDI_VID;
54 static __u16 product;
55
56 struct ftdi_private {
57         ftdi_chip_type_t chip_type;
58                                 /* type of the device, either SIO or FT8U232AM */
59         int baud_base;          /* baud base clock for divisor setting */
60         int custom_divisor;     /* custom_divisor kludge, this is for baud_base (different from what goes to the chip!) */
61         __u16 last_set_data_urb_value ;
62                                 /* the last data state set - needed for doing a break */
63         int write_offset;       /* This is the offset in the usb data block to write the serial data -
64                                  * it is different between devices
65                                  */
66         int flags;              /* some ASYNC_xxxx flags are supported */
67         unsigned long last_dtr_rts;     /* saved modem control outputs */
68         wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
69         char prev_status, diff_status;        /* Used for TIOCMIWAIT */
70         __u8 rx_flags;          /* receive state flags (throttling) */
71         spinlock_t rx_lock;     /* spinlock for receive state */
72         struct delayed_work rx_work;
73         struct usb_serial_port *port;
74         int rx_processed;
75         unsigned long rx_bytes;
76
77         __u16 interface;        /* FT2232C port interface (0 for FT232/245) */
78
79         speed_t force_baud;     /* if non-zero, force the baud rate to this value */
80         int force_rtscts;       /* if non-zero, force RTS-CTS to always be enabled */
81
82         spinlock_t tx_lock;     /* spinlock for transmit state */
83         unsigned long tx_bytes;
84         unsigned long tx_outstanding_bytes;
85         unsigned long tx_outstanding_urbs;
86 };
87
88 /* struct ftdi_sio_quirk is used by devices requiring special attention. */
89 struct ftdi_sio_quirk {
90         int (*probe)(struct usb_serial *);
91         void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */
92 };
93
94 static int   ftdi_jtag_probe            (struct usb_serial *serial);
95 static int   ftdi_mtxorb_hack_setup     (struct usb_serial *serial);
96 static void  ftdi_USB_UIRT_setup        (struct ftdi_private *priv);
97 static void  ftdi_HE_TIRA1_setup        (struct ftdi_private *priv);
98
99 static struct ftdi_sio_quirk ftdi_jtag_quirk = {
100         .probe  = ftdi_jtag_probe,
101 };
102
103 static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
104         .probe  = ftdi_mtxorb_hack_setup,
105 };
106
107 static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
108         .port_probe = ftdi_USB_UIRT_setup,
109 };
110
111 static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
112         .port_probe = ftdi_HE_TIRA1_setup,
113 };
114
115 /*
116  * The 8U232AM has the same API as the sio except for:
117  * - it can support MUCH higher baudrates; up to:
118  *   o 921600 for RS232 and 2000000 for RS422/485 at 48MHz
119  *   o 230400 at 12MHz
120  *   so .. 8U232AM's baudrate setting codes are different
121  * - it has a two byte status code.
122  * - it returns characters every 16ms (the FTDI does it every 40ms)
123  *
124  * the bcdDevice value is used to differentiate FT232BM and FT245BM from
125  * the earlier FT8U232AM and FT8U232BM.  For now, include all known VID/PID
126  * combinations in both tables.
127  * FIXME: perhaps bcdDevice can also identify 12MHz FT8U232AM devices,
128  * but I don't know if those ever went into mass production. [Ian Abbott]
129  */
130
131
132
133 static struct usb_device_id id_table_combined [] = {
134         { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) },
135         { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
136         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) },
137         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) },
138         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) },
139         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_3_PID) },
140         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_4_PID) },
141         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) },
142         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) },
143         { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) },
144         { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) },
145         { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
146         { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) },
147         { USB_DEVICE(FTDI_VID, FTDI_IPLUS2_PID) },
148         { USB_DEVICE(FTDI_VID, FTDI_DMX4ALL) },
149         { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) },
150         { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) },
151         { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) },
152         { USB_DEVICE(FTDI_VID, FTDI_232RL_PID) },
153         { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
154         { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
155         { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
156         { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) },
157         { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
158         { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
159         { USB_DEVICE(FTDI_VID, FTDI_XF_632_PID) },
160         { USB_DEVICE(FTDI_VID, FTDI_XF_634_PID) },
161         { USB_DEVICE(FTDI_VID, FTDI_XF_547_PID) },
162         { USB_DEVICE(FTDI_VID, FTDI_XF_633_PID) },
163         { USB_DEVICE(FTDI_VID, FTDI_XF_631_PID) },
164         { USB_DEVICE(FTDI_VID, FTDI_XF_635_PID) },
165         { USB_DEVICE(FTDI_VID, FTDI_XF_640_PID) },
166         { USB_DEVICE(FTDI_VID, FTDI_XF_642_PID) },
167         { USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) },
168         { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) },
169         { USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) },
170         { USB_DEVICE(FTDI_VID, FTDI_MTXORB_0_PID) },
171         { USB_DEVICE(FTDI_VID, FTDI_MTXORB_1_PID) },
172         { USB_DEVICE(FTDI_VID, FTDI_MTXORB_2_PID) },
173         { USB_DEVICE(FTDI_VID, FTDI_MTXORB_3_PID) },
174         { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) },
175         { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
176         { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
177         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0100_PID) },
178         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0101_PID) },
179         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0102_PID) },
180         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0103_PID) },
181         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0104_PID) },
182         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0105_PID) },
183         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0106_PID) },
184         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0107_PID) },
185         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0108_PID) },
186         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0109_PID) },
187         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010A_PID) },
188         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010B_PID) },
189         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010C_PID) },
190         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010D_PID) },
191         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010E_PID) },
192         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_010F_PID) },
193         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0110_PID) },
194         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0111_PID) },
195         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0112_PID) },
196         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0113_PID) },
197         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0114_PID) },
198         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0115_PID) },
199         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0116_PID) },
200         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0117_PID) },
201         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0118_PID) },
202         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0119_PID) },
203         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011A_PID) },
204         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011B_PID) },
205         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011C_PID) },
206         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011D_PID) },
207         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011E_PID) },
208         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_011F_PID) },
209         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0120_PID) },
210         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0121_PID) },
211         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0122_PID) },
212         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0123_PID) },
213         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0124_PID) },
214         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0125_PID) },
215         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0126_PID) },
216         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0127_PID),
217                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
218         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0128_PID) },
219         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0129_PID) },
220         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012A_PID) },
221         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012B_PID) },
222         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012C_PID),
223                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
224         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012D_PID) },
225         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012E_PID) },
226         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_012F_PID) },
227         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0130_PID) },
228         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0131_PID) },
229         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0132_PID) },
230         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0133_PID) },
231         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0134_PID) },
232         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0135_PID) },
233         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0136_PID) },
234         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0137_PID) },
235         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0138_PID) },
236         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0139_PID) },
237         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013A_PID) },
238         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013B_PID) },
239         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013C_PID) },
240         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013D_PID) },
241         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013E_PID) },
242         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_013F_PID) },
243         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0140_PID) },
244         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0141_PID) },
245         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0142_PID) },
246         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0143_PID) },
247         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0144_PID) },
248         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0145_PID) },
249         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0146_PID) },
250         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0147_PID) },
251         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0148_PID) },
252         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0149_PID) },
253         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014A_PID) },
254         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014B_PID) },
255         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014C_PID) },
256         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014D_PID) },
257         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014E_PID) },
258         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_014F_PID) },
259         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0150_PID) },
260         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0151_PID) },
261         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0152_PID) },
262         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0153_PID),
263                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
264         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0154_PID),
265                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
266         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0155_PID),
267                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
268         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0156_PID),
269                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
270         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0157_PID),
271                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
272         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0158_PID),
273                 .driver_info = (kernel_ulong_t)&ftdi_mtxorb_hack_quirk },
274         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0159_PID) },
275         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015A_PID) },
276         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015B_PID) },
277         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015C_PID) },
278         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015D_PID) },
279         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015E_PID) },
280         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_015F_PID) },
281         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0160_PID) },
282         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0161_PID) },
283         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0162_PID) },
284         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0163_PID) },
285         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0164_PID) },
286         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0165_PID) },
287         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0166_PID) },
288         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0167_PID) },
289         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0168_PID) },
290         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0169_PID) },
291         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016A_PID) },
292         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016B_PID) },
293         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016C_PID) },
294         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016D_PID) },
295         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016E_PID) },
296         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_016F_PID) },
297         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0170_PID) },
298         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0171_PID) },
299         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0172_PID) },
300         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0173_PID) },
301         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0174_PID) },
302         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0175_PID) },
303         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0176_PID) },
304         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0177_PID) },
305         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0178_PID) },
306         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0179_PID) },
307         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017A_PID) },
308         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017B_PID) },
309         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017C_PID) },
310         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017D_PID) },
311         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017E_PID) },
312         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_017F_PID) },
313         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0180_PID) },
314         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0181_PID) },
315         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0182_PID) },
316         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0183_PID) },
317         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0184_PID) },
318         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0185_PID) },
319         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0186_PID) },
320         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0187_PID) },
321         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0188_PID) },
322         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0189_PID) },
323         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018A_PID) },
324         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018B_PID) },
325         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018C_PID) },
326         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018D_PID) },
327         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018E_PID) },
328         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_018F_PID) },
329         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0190_PID) },
330         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0191_PID) },
331         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0192_PID) },
332         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0193_PID) },
333         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0194_PID) },
334         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0195_PID) },
335         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0196_PID) },
336         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0197_PID) },
337         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0198_PID) },
338         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_0199_PID) },
339         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019A_PID) },
340         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019B_PID) },
341         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019C_PID) },
342         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019D_PID) },
343         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019E_PID) },
344         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_019F_PID) },
345         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A0_PID) },
346         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A1_PID) },
347         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A2_PID) },
348         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A3_PID) },
349         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A4_PID) },
350         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A5_PID) },
351         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A6_PID) },
352         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A7_PID) },
353         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A8_PID) },
354         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01A9_PID) },
355         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AA_PID) },
356         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AB_PID) },
357         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AC_PID) },
358         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AD_PID) },
359         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AE_PID) },
360         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01AF_PID) },
361         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B0_PID) },
362         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B1_PID) },
363         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B2_PID) },
364         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B3_PID) },
365         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B4_PID) },
366         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B5_PID) },
367         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B6_PID) },
368         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B7_PID) },
369         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B8_PID) },
370         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01B9_PID) },
371         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BA_PID) },
372         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BB_PID) },
373         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BC_PID) },
374         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BD_PID) },
375         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BE_PID) },
376         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01BF_PID) },
377         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C0_PID) },
378         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C1_PID) },
379         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C2_PID) },
380         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C3_PID) },
381         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C4_PID) },
382         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C5_PID) },
383         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C6_PID) },
384         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C7_PID) },
385         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C8_PID) },
386         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01C9_PID) },
387         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CA_PID) },
388         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CB_PID) },
389         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CC_PID) },
390         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CD_PID) },
391         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CE_PID) },
392         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01CF_PID) },
393         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D0_PID) },
394         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D1_PID) },
395         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D2_PID) },
396         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D3_PID) },
397         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D4_PID) },
398         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D5_PID) },
399         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D6_PID) },
400         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D7_PID) },
401         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D8_PID) },
402         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01D9_PID) },
403         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DA_PID) },
404         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DB_PID) },
405         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DC_PID) },
406         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DD_PID) },
407         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DE_PID) },
408         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01DF_PID) },
409         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E0_PID) },
410         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E1_PID) },
411         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E2_PID) },
412         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E3_PID) },
413         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E4_PID) },
414         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E5_PID) },
415         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E6_PID) },
416         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E7_PID) },
417         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E8_PID) },
418         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01E9_PID) },
419         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EA_PID) },
420         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EB_PID) },
421         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EC_PID) },
422         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01ED_PID) },
423         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EE_PID) },
424         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01EF_PID) },
425         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F0_PID) },
426         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F1_PID) },
427         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F2_PID) },
428         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F3_PID) },
429         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F4_PID) },
430         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F5_PID) },
431         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F6_PID) },
432         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F7_PID) },
433         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F8_PID) },
434         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01F9_PID) },
435         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FA_PID) },
436         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FB_PID) },
437         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FC_PID) },
438         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FD_PID) },
439         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FE_PID) },
440         { USB_DEVICE(MTXORB_VID,MTXORB_FTDI_RANGE_01FF_PID) },
441         { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
442         { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
443         { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
444         { USB_DEVICE(FTDI_VID, FTDI_USBX_707_PID) },
445         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) },
446         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
447         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) },
448         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) },
449         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2106_PID) },
450         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) },
451         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) },
452         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) },
453         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_2_PID) },
454         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_1_PID) },
455         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_2_PID) },
456         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_1_PID) },
457         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_2_PID) },
458         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_3_PID) },
459         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_4_PID) },
460         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_1_PID) },
461         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_2_PID) },
462         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_3_PID) },
463         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_4_PID) },
464         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_1_PID) },
465         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_2_PID) },
466         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_3_PID) },
467         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_4_PID) },
468         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_1_PID) },
469         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_2_PID) },
470         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_3_PID) },
471         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_4_PID) },
472         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_5_PID) },
473         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_6_PID) },
474         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_7_PID) },
475         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_8_PID) },
476         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_1_PID) },
477         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_2_PID) },
478         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_3_PID) },
479         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_4_PID) },
480         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_5_PID) },
481         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_6_PID) },
482         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_7_PID) },
483         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_8_PID) },
484         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_1_PID) },
485         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_2_PID) },
486         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_3_PID) },
487         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_4_PID) },
488         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_5_PID) },
489         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_6_PID) },
490         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_7_PID) },
491         { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) },
492         { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) },
493         { USB_DEVICE(OCT_VID, OCT_US101_PID) },
494         { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID),
495                 .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk },
496         { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID),
497                 .driver_info = (kernel_ulong_t)&ftdi_USB_UIRT_quirk },
498         { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) },
499         { USB_DEVICE(FTDI_VID, PROTEGO_R2X0) },
500         { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) },
501         { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) },
502         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E808_PID) },
503         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E809_PID) },
504         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80A_PID) },
505         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80B_PID) },
506         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80C_PID) },
507         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80D_PID) },
508         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80E_PID) },
509         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80F_PID) },
510         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E888_PID) },
511         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E889_PID) },
512         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88A_PID) },
513         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88B_PID) },
514         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88C_PID) },
515         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88D_PID) },
516         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88E_PID) },
517         { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) },
518         { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) },
519         { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) },
520         { USB_DEVICE(FTDI_VID, FTDI_ELV_UR100_PID) },
521         { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) },
522         { USB_DEVICE(FTDI_VID, FTDI_PYRAMID_PID) },
523         { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) },
524         { USB_DEVICE(FTDI_VID, FTDI_IBS_US485_PID) },
525         { USB_DEVICE(FTDI_VID, FTDI_IBS_PICPRO_PID) },
526         { USB_DEVICE(FTDI_VID, FTDI_IBS_PCMCIA_PID) },
527         { USB_DEVICE(FTDI_VID, FTDI_IBS_PK1_PID) },
528         { USB_DEVICE(FTDI_VID, FTDI_IBS_RS232MON_PID) },
529         { USB_DEVICE(FTDI_VID, FTDI_IBS_APP70_PID) },
530         { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) },
531         { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) },
532         /*
533          * Due to many user requests for multiple ELV devices we enable
534          * them by default.
535          */
536         { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) },
537         { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) },
538         { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) },
539         { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) },
540         { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) },
541         { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) },
542         { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) },
543         { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) },
544         { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) },
545         { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) },
546         { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) },
547         { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) },
548         { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) },
549         { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) },
550         { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) },
551         { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) },
552         { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) },
553         { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) },
554         { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1010PC_PID) },
555         { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) },
556         { USB_DEVICE(FTDI_VID, FTDI_ELV_HS485_PID) },
557         { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
558         { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
559         { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
560         { USB_DEVICE(FTDI_VID, LINX_FUTURE_1_PID) },
561         { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) },
562         { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
563         { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
564         { USB_DEVICE(FTDI_VID, FTDI_CCSMACHX_2_PID) },
565         { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) },
566         { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) },
567         { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) },
568         { USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) },
569         { USB_DEVICE(FALCOM_VID, FALCOM_SAMBA_PID) },
570         { USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) },
571         { USB_DEVICE(TTI_VID, TTI_QL355P_PID) },
572         { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) },
573         { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) },
574         { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) },
575         { USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) },
576         { USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) },
577         { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
578         { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
579         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_0_PID) },
580         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_1_PID) },
581         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_2_PID) },
582         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_3_PID) },
583         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_4_PID) },
584         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_5_PID) },
585         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_6_PID) },
586         { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_7_PID) },
587         { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) },
588         { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) },
589         { USB_DEVICE(FTDI_VID, FTDI_MHAM_KW_PID) },
590         { USB_DEVICE(FTDI_VID, FTDI_MHAM_YS_PID) },
591         { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) },
592         { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) },
593         { USB_DEVICE(FTDI_VID, FTDI_MHAM_IC_PID) },
594         { USB_DEVICE(FTDI_VID, FTDI_MHAM_DB9_PID) },
595         { USB_DEVICE(FTDI_VID, FTDI_MHAM_RS232_PID) },
596         { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y9_PID) },
597         { USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_VCP_PID) },
598         { USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_D2XX_PID) },
599         { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) },
600         { USB_DEVICE(EVOLUTION_VID, EVO_HYBRID_PID) },
601         { USB_DEVICE(EVOLUTION_VID, EVO_RCM4_PID) },
602         { USB_DEVICE(FTDI_VID, FTDI_ARTEMIS_PID) },
603         { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16_PID) },
604         { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) },
605         { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) },
606         { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) },
607         { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16IC_PID) },
608         { USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) },
609         { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) },
610         { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) },
611         { USB_DEVICE(FTDI_VID, FTDI_TTUSB_PID) },
612         { USB_DEVICE(FTDI_VID, FTDI_ECLO_COM_1WIRE_PID) },
613         { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) },
614         { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) },
615         { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) },
616         { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) },
617         { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) },
618         { USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) },
619         { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) },
620         { USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) },
621         { USB_DEVICE(FTDI_VID, FTDI_YEI_SERVOCENTER31_PID) },
622         { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) },
623         { USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) },
624         { USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) },
625         { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13M_PID) },
626         { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) },
627         { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) },
628         { USB_DEVICE(ELEKTOR_VID, ELEKTOR_FT323R_PID) },
629         { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
630         { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) },
631         { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
632         { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) },
633         { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) },
634         { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
635                 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
636         { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID),
637                 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
638         { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
639                 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
640         { USB_DEVICE(FTDI_VID, LMI_LM3S_DEVEL_BOARD_PID),
641                 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
642         { USB_DEVICE(FTDI_VID, LMI_LM3S_EVAL_BOARD_PID),
643                 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
644         { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
645         { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) },
646         { },                                    /* Optional parameter entry */
647         { }                                     /* Terminating entry */
648 };
649
650 MODULE_DEVICE_TABLE (usb, id_table_combined);
651
652 static struct usb_driver ftdi_driver = {
653         .name =         "ftdi_sio",
654         .probe =        usb_serial_probe,
655         .disconnect =   usb_serial_disconnect,
656         .id_table =     id_table_combined,
657         .no_dynamic_id =        1,
658 };
659
660 static const char *ftdi_chip_name[] = {
661         [SIO] = "SIO",  /* the serial part of FT8U100AX */
662         [FT8U232AM] = "FT8U232AM",
663         [FT232BM] = "FT232BM",
664         [FT2232C] = "FT2232C",
665         [FT232RL] = "FT232RL",
666 };
667
668
669 /* Constants for read urb and write urb */
670 #define BUFSZ 512
671 #define PKTSZ 64
672
673 /* rx_flags */
674 #define THROTTLED               0x01
675 #define ACTUALLY_THROTTLED      0x02
676
677 /* Used for TIOCMIWAIT */
678 #define FTDI_STATUS_B0_MASK     (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
679 #define FTDI_STATUS_B1_MASK     (FTDI_RS_BI)
680 /* End TIOCMIWAIT */
681
682 #define FTDI_IMPL_ASYNC_FLAGS = (ASYNC_SPD_HI | ASYNC_SPD_VHI \
683  | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP)
684
685 /* function prototypes for a FTDI serial converter */
686 static int  ftdi_sio_probe      (struct usb_serial *serial, const struct usb_device_id *id);
687 static void ftdi_shutdown               (struct usb_serial *serial);
688 static int  ftdi_sio_port_probe (struct usb_serial_port *port);
689 static int  ftdi_sio_port_remove        (struct usb_serial_port *port);
690 static int  ftdi_open                   (struct usb_serial_port *port, struct file *filp);
691 static void ftdi_close                  (struct usb_serial_port *port, struct file *filp);
692 static int  ftdi_write                  (struct usb_serial_port *port, const unsigned char *buf, int count);
693 static int  ftdi_write_room             (struct usb_serial_port *port);
694 static int  ftdi_chars_in_buffer        (struct usb_serial_port *port);
695 static void ftdi_write_bulk_callback    (struct urb *urb);
696 static void ftdi_read_bulk_callback     (struct urb *urb);
697 static void ftdi_process_read           (struct work_struct *work);
698 static void ftdi_set_termios            (struct usb_serial_port *port, struct ktermios * old);
699 static int  ftdi_tiocmget               (struct usb_serial_port *port, struct file *file);
700 static int  ftdi_tiocmset               (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear);
701 static int  ftdi_ioctl                  (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
702 static void ftdi_break_ctl              (struct usb_serial_port *port, int break_state );
703 static void ftdi_throttle               (struct usb_serial_port *port);
704 static void ftdi_unthrottle             (struct usb_serial_port *port);
705
706 static unsigned short int ftdi_232am_baud_base_to_divisor (int baud, int base);
707 static unsigned short int ftdi_232am_baud_to_divisor (int baud);
708 static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base);
709 static __u32 ftdi_232bm_baud_to_divisor (int baud);
710
711 static struct usb_serial_driver ftdi_sio_device = {
712         .driver = {
713                 .owner =        THIS_MODULE,
714                 .name =         "ftdi_sio",
715         },
716         .description =          "FTDI USB Serial Device",
717         .usb_driver =           &ftdi_driver ,
718         .id_table =             id_table_combined,
719         .num_ports =            1,
720         .probe =                ftdi_sio_probe,
721         .port_probe =           ftdi_sio_port_probe,
722         .port_remove =          ftdi_sio_port_remove,
723         .open =                 ftdi_open,
724         .close =                ftdi_close,
725         .throttle =             ftdi_throttle,
726         .unthrottle =           ftdi_unthrottle,
727         .write =                ftdi_write,
728         .write_room =           ftdi_write_room,
729         .chars_in_buffer =      ftdi_chars_in_buffer,
730         .read_bulk_callback =   ftdi_read_bulk_callback,
731         .write_bulk_callback =  ftdi_write_bulk_callback,
732         .tiocmget =             ftdi_tiocmget,
733         .tiocmset =             ftdi_tiocmset,
734         .ioctl =                ftdi_ioctl,
735         .set_termios =          ftdi_set_termios,
736         .break_ctl =            ftdi_break_ctl,
737         .shutdown =             ftdi_shutdown,
738 };
739
740
741 #define WDR_TIMEOUT 5000 /* default urb timeout */
742 #define WDR_SHORT_TIMEOUT 1000  /* shorter urb timeout */
743
744 /* High and low are for DTR, RTS etc etc */
745 #define HIGH 1
746 #define LOW 0
747
748 /* number of outstanding urbs to prevent userspace DoS from happening */
749 #define URB_UPPER_LIMIT 42
750
751 /*
752  * ***************************************************************************
753  * Utility functions
754  * ***************************************************************************
755  */
756
757 static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
758 {
759         unsigned short int divisor;
760         int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left
761         if ((divisor3 & 0x7) == 7) divisor3 ++; // round x.7/8 up to x+1
762         divisor = divisor3 >> 3;
763         divisor3 &= 0x7;
764         if (divisor3 == 1) divisor |= 0xc000; else // 0.125
765         if (divisor3 >= 4) divisor |= 0x4000; else // 0.5
766         if (divisor3 != 0) divisor |= 0x8000;      // 0.25
767         if (divisor == 1) divisor = 0;  /* special case for maximum baud rate */
768         return divisor;
769 }
770
771 static unsigned short int ftdi_232am_baud_to_divisor(int baud)
772 {
773          return(ftdi_232am_baud_base_to_divisor(baud, 48000000));
774 }
775
776 static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
777 {
778         static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
779         __u32 divisor;
780         int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left
781         divisor = divisor3 >> 3;
782         divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
783         /* Deal with special cases for highest baud rates. */
784         if (divisor == 1) divisor = 0; else     // 1.0
785         if (divisor == 0x4001) divisor = 1;     // 1.5
786         return divisor;
787 }
788
789 static __u32 ftdi_232bm_baud_to_divisor(int baud)
790 {
791          return(ftdi_232bm_baud_base_to_divisor(baud, 48000000));
792 }
793
794 #define set_mctrl(port, set)            update_mctrl((port), (set), 0)
795 #define clear_mctrl(port, clear)        update_mctrl((port), 0, (clear))
796
797 static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned int clear)
798 {
799         struct ftdi_private *priv = usb_get_serial_port_data(port);
800         char *buf;
801         unsigned urb_value;
802         int rv;
803
804         if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) {
805                 dbg("%s - DTR|RTS not being set|cleared", __func__);
806                 return 0;       /* no change */
807         }
808
809         buf = kmalloc(1, GFP_NOIO);
810         if (!buf)
811                 return -ENOMEM;
812
813         clear &= ~set;  /* 'set' takes precedence over 'clear' */
814         urb_value = 0;
815         if (clear & TIOCM_DTR)
816                 urb_value |= FTDI_SIO_SET_DTR_LOW;
817         if (clear & TIOCM_RTS)
818                 urb_value |= FTDI_SIO_SET_RTS_LOW;
819         if (set & TIOCM_DTR)
820                 urb_value |= FTDI_SIO_SET_DTR_HIGH;
821         if (set & TIOCM_RTS)
822                 urb_value |= FTDI_SIO_SET_RTS_HIGH;
823         rv = usb_control_msg(port->serial->dev,
824                                usb_sndctrlpipe(port->serial->dev, 0),
825                                FTDI_SIO_SET_MODEM_CTRL_REQUEST,
826                                FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
827                                urb_value, priv->interface,
828                                buf, 0, WDR_TIMEOUT);
829
830         kfree(buf);
831         if (rv < 0) {
832                 err("%s Error from MODEM_CTRL urb: DTR %s, RTS %s",
833                                 __func__,
834                                 (set & TIOCM_DTR) ? "HIGH" :
835                                 (clear & TIOCM_DTR) ? "LOW" : "unchanged",
836                                 (set & TIOCM_RTS) ? "HIGH" :
837                                 (clear & TIOCM_RTS) ? "LOW" : "unchanged");
838         } else {
839                 dbg("%s - DTR %s, RTS %s", __func__,
840                                 (set & TIOCM_DTR) ? "HIGH" :
841                                 (clear & TIOCM_DTR) ? "LOW" : "unchanged",
842                                 (set & TIOCM_RTS) ? "HIGH" :
843                                 (clear & TIOCM_RTS) ? "LOW" : "unchanged");
844                 /* FIXME: locking on last_dtr_rts */
845                 priv->last_dtr_rts = (priv->last_dtr_rts & ~clear) | set;
846         }
847         return rv;
848 }
849
850
851 static __u32 get_ftdi_divisor(struct usb_serial_port * port);
852
853
854 static int change_speed(struct usb_serial_port *port)
855 {
856         struct ftdi_private *priv = usb_get_serial_port_data(port);
857         char *buf;
858         __u16 urb_value;
859         __u16 urb_index;
860         __u32 urb_index_value;
861         int rv;
862
863         buf = kmalloc(1, GFP_NOIO);
864         if (!buf)
865                 return -ENOMEM;
866
867         urb_index_value = get_ftdi_divisor(port);
868         urb_value = (__u16)urb_index_value;
869         urb_index = (__u16)(urb_index_value >> 16);
870         if (priv->interface) {  /* FT2232C */
871                 urb_index = (__u16)((urb_index << 8) | priv->interface);
872         }
873
874         rv = usb_control_msg(port->serial->dev,
875                             usb_sndctrlpipe(port->serial->dev, 0),
876                             FTDI_SIO_SET_BAUDRATE_REQUEST,
877                             FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
878                             urb_value, urb_index,
879                             buf, 0, WDR_SHORT_TIMEOUT);
880
881         kfree(buf);
882         return rv;
883 }
884
885
886 static __u32 get_ftdi_divisor(struct usb_serial_port * port)
887 { /* get_ftdi_divisor */
888         struct ftdi_private *priv = usb_get_serial_port_data(port);
889         __u32 div_value = 0;
890         int div_okay = 1;
891         int baud;
892
893         /*
894          * The logic involved in setting the baudrate can be cleanly split in 3 steps.
895          * Obtaining the actual baud rate is a little tricky since unix traditionally
896          * somehow ignored the possibility to set non-standard baud rates.
897          * 1. Standard baud rates are set in tty->termios->c_cflag
898          * 2. If these are not enough, you can set any speed using alt_speed as follows:
899          *    - set tty->termios->c_cflag speed to B38400
900          *    - set your real speed in tty->alt_speed; it gets ignored when
901          *      alt_speed==0, (or)
902          *    - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows:
903          *      flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP], this just
904          *      sets alt_speed to (HI: 57600, VHI: 115200, SHI: 230400, WARP: 460800)
905          * ** Steps 1, 2 are done courtesy of tty_get_baud_rate
906          * 3. You can also set baud rate by setting custom divisor as follows
907          *    - set tty->termios->c_cflag speed to B38400
908          *    - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows:
909          *      o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
910          *      o custom_divisor set to baud_base / your_new_baudrate
911          * ** Step 3 is done courtesy of code borrowed from serial.c - I should really
912          *    spend some time and separate+move this common code to serial.c, it is
913          *    replicated in nearly every serial driver you see.
914          */
915
916         /* 1. Get the baud rate from the tty settings, this observes alt_speed hack */
917
918         baud = tty_get_baud_rate(port->tty);
919         dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud);
920
921         /* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */
922
923         if (baud == 38400 &&
924             ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
925              (priv->custom_divisor)) {
926                 baud = priv->baud_base / priv->custom_divisor;
927                 dbg("%s - custom divisor %d sets baud rate to %d", __func__, priv->custom_divisor, baud);
928         }
929
930         /* 3. Convert baudrate to device-specific divisor */
931
932         if (!baud) baud = 9600;
933         switch(priv->chip_type) {
934         case SIO: /* SIO chip */
935                 switch(baud) {
936                 case 300: div_value = ftdi_sio_b300; break;
937                 case 600: div_value = ftdi_sio_b600; break;
938                 case 1200: div_value = ftdi_sio_b1200; break;
939                 case 2400: div_value = ftdi_sio_b2400; break;
940                 case 4800: div_value = ftdi_sio_b4800; break;
941                 case 9600: div_value = ftdi_sio_b9600; break;
942                 case 19200: div_value = ftdi_sio_b19200; break;
943                 case 38400: div_value = ftdi_sio_b38400; break;
944                 case 57600: div_value = ftdi_sio_b57600;  break;
945                 case 115200: div_value = ftdi_sio_b115200; break;
946                 } /* baud */
947                 if (div_value == 0) {
948                         dbg("%s - Baudrate (%d) requested is not supported", __func__,  baud);
949                         div_value = ftdi_sio_b9600;
950                         baud = 9600;
951                         div_okay = 0;
952                 }
953                 break;
954         case FT8U232AM: /* 8U232AM chip */
955                 if (baud <= 3000000) {
956                         div_value = ftdi_232am_baud_to_divisor(baud);
957                 } else {
958                         dbg("%s - Baud rate too high!", __func__);
959                         baud = 9600;
960                         div_value = ftdi_232am_baud_to_divisor(9600);
961                         div_okay = 0;
962                 }
963                 break;
964         case FT232BM: /* FT232BM chip */
965         case FT2232C: /* FT2232C chip */
966         case FT232RL:
967                 if (baud <= 3000000) {
968                         div_value = ftdi_232bm_baud_to_divisor(baud);
969                 } else {
970                         dbg("%s - Baud rate too high!", __func__);
971                         div_value = ftdi_232bm_baud_to_divisor(9600);
972                         div_okay = 0;
973                         baud = 9600;
974                 }
975                 break;
976         } /* priv->chip_type */
977
978         if (div_okay) {
979                 dbg("%s - Baud rate set to %d (divisor 0x%lX) on chip %s",
980                         __func__, baud, (unsigned long)div_value,
981                         ftdi_chip_name[priv->chip_type]);
982         }
983
984         tty_encode_baud_rate(port->tty, baud, baud);
985         return(div_value);
986 }
987
988
989 static int get_serial_info(struct usb_serial_port * port, struct serial_struct __user * retinfo)
990 {
991         struct ftdi_private *priv = usb_get_serial_port_data(port);
992         struct serial_struct tmp;
993
994         if (!retinfo)
995                 return -EFAULT;
996         memset(&tmp, 0, sizeof(tmp));
997         tmp.flags = priv->flags;
998         tmp.baud_base = priv->baud_base;
999         tmp.custom_divisor = priv->custom_divisor;
1000         if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1001                 return -EFAULT;
1002         return 0;
1003 } /* get_serial_info */
1004
1005
1006 static int set_serial_info(struct usb_serial_port * port, struct serial_struct __user * newinfo)
1007 { /* set_serial_info */
1008         struct ftdi_private *priv = usb_get_serial_port_data(port);
1009         struct serial_struct new_serial;
1010         struct ftdi_private old_priv;
1011
1012         if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
1013                 return -EFAULT;
1014         old_priv = * priv;
1015
1016         /* Do error checking and permission checking */
1017
1018         if (!capable(CAP_SYS_ADMIN)) {
1019                 if (((new_serial.flags & ~ASYNC_USR_MASK) !=
1020                      (priv->flags & ~ASYNC_USR_MASK)))
1021                         return -EPERM;
1022                 priv->flags = ((priv->flags & ~ASYNC_USR_MASK) |
1023                                (new_serial.flags & ASYNC_USR_MASK));
1024                 priv->custom_divisor = new_serial.custom_divisor;
1025                 goto check_and_exit;
1026         }
1027
1028         if ((new_serial.baud_base != priv->baud_base) &&
1029             (new_serial.baud_base < 9600))
1030                 return -EINVAL;
1031
1032         /* Make the changes - these are privileged changes! */
1033
1034         priv->flags = ((priv->flags & ~ASYNC_FLAGS) |
1035                        (new_serial.flags & ASYNC_FLAGS));
1036         priv->custom_divisor = new_serial.custom_divisor;
1037
1038         port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1039
1040 check_and_exit:
1041         if ((old_priv.flags & ASYNC_SPD_MASK) !=
1042              (priv->flags & ASYNC_SPD_MASK)) {
1043                 if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1044                         port->tty->alt_speed = 57600;
1045                 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1046                         port->tty->alt_speed = 115200;
1047                 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1048                         port->tty->alt_speed = 230400;
1049                 else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1050                         port->tty->alt_speed = 460800;
1051                 else
1052                         port->tty->alt_speed = 0;
1053         }
1054         if (((old_priv.flags & ASYNC_SPD_MASK) !=
1055              (priv->flags & ASYNC_SPD_MASK)) ||
1056             (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
1057              (old_priv.custom_divisor != priv->custom_divisor))) {
1058                 change_speed(port);
1059         }
1060
1061         return (0);
1062
1063 } /* set_serial_info */
1064
1065
1066 /* Determine type of FTDI chip based on USB config and descriptor. */
1067 static void ftdi_determine_type(struct usb_serial_port *port)
1068 {
1069         struct ftdi_private *priv = usb_get_serial_port_data(port);
1070         struct usb_serial *serial = port->serial;
1071         struct usb_device *udev = serial->dev;
1072         unsigned version;
1073         unsigned interfaces;
1074
1075         /* Assume it is not the original SIO device for now. */
1076         priv->baud_base = 48000000 / 2;
1077         priv->write_offset = 0;
1078
1079         version = le16_to_cpu(udev->descriptor.bcdDevice);
1080         interfaces = udev->actconfig->desc.bNumInterfaces;
1081         dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __func__,
1082                         version, interfaces);
1083         if (interfaces > 1) {
1084                 int inter;
1085
1086                 /* Multiple interfaces.  Assume FT2232C. */
1087                 priv->chip_type = FT2232C;
1088                 /* Determine interface code. */
1089                 inter = serial->interface->altsetting->desc.bInterfaceNumber;
1090                 if (inter == 0) {
1091                         priv->interface = PIT_SIOA;
1092                 } else {
1093                         priv->interface = PIT_SIOB;
1094                 }
1095                 /* BM-type devices have a bug where bcdDevice gets set
1096                  * to 0x200 when iSerialNumber is 0.  */
1097                 if (version < 0x500) {
1098                         dbg("%s: something fishy - bcdDevice too low for multi-interface device",
1099                                         __func__);
1100                 }
1101         } else if (version < 0x200) {
1102                 /* Old device.  Assume its the original SIO. */
1103                 priv->chip_type = SIO;
1104                 priv->baud_base = 12000000 / 16;
1105                 priv->write_offset = 1;
1106         } else if (version < 0x400) {
1107                 /* Assume its an FT8U232AM (or FT8U245AM) */
1108                 /* (It might be a BM because of the iSerialNumber bug,
1109                  * but it will still work as an AM device.) */
1110                 priv->chip_type = FT8U232AM;
1111         } else if (version < 0x600) {
1112                 /* Assume its an FT232BM (or FT245BM) */
1113                 priv->chip_type = FT232BM;
1114         } else {
1115                 /* Assume its an FT232R  */
1116                 priv->chip_type = FT232RL;
1117         }
1118         info("Detected %s", ftdi_chip_name[priv->chip_type]);
1119 }
1120
1121
1122 /*
1123  * ***************************************************************************
1124  * Sysfs Attribute
1125  * ***************************************************************************
1126  */
1127
1128 static ssize_t show_latency_timer(struct device *dev, struct device_attribute *attr, char *buf)
1129 {
1130         struct usb_serial_port *port = to_usb_serial_port(dev);
1131         struct ftdi_private *priv = usb_get_serial_port_data(port);
1132         struct usb_device *udev = port->serial->dev;
1133         unsigned short latency = 0;
1134         int rv = 0;
1135
1136
1137         dbg("%s",__func__);
1138
1139         rv = usb_control_msg(udev,
1140                              usb_rcvctrlpipe(udev, 0),
1141                              FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1142                              FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
1143                              0, priv->interface,
1144                              (char*) &latency, 1, WDR_TIMEOUT);
1145
1146         if (rv < 0) {
1147                 dev_err(dev, "Unable to read latency timer: %i\n", rv);
1148                 return -EIO;
1149         }
1150         return sprintf(buf, "%i\n", latency);
1151 }
1152
1153 /* Write a new value of the latency timer, in units of milliseconds. */
1154 static ssize_t store_latency_timer(struct device *dev, struct device_attribute *attr, const char *valbuf,
1155                                    size_t count)
1156 {
1157         struct usb_serial_port *port = to_usb_serial_port(dev);
1158         struct ftdi_private *priv = usb_get_serial_port_data(port);
1159         struct usb_device *udev = port->serial->dev;
1160         char buf[1];
1161         int v = simple_strtoul(valbuf, NULL, 10);
1162         int rv = 0;
1163
1164         dbg("%s: setting latency timer = %i", __func__, v);
1165
1166         rv = usb_control_msg(udev,
1167                              usb_sndctrlpipe(udev, 0),
1168                              FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
1169                              FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
1170                              v, priv->interface,
1171                              buf, 0, WDR_TIMEOUT);
1172
1173         if (rv < 0) {
1174                 dev_err(dev, "Unable to write latency timer: %i\n", rv);
1175                 return -EIO;
1176         }
1177
1178         return count;
1179 }
1180
1181 /* Write an event character directly to the FTDI register.  The ASCII
1182    value is in the low 8 bits, with the enable bit in the 9th bit. */
1183 static ssize_t store_event_char(struct device *dev, struct device_attribute *attr, const char *valbuf,
1184                                 size_t count)
1185 {
1186         struct usb_serial_port *port = to_usb_serial_port(dev);
1187         struct ftdi_private *priv = usb_get_serial_port_data(port);
1188         struct usb_device *udev = port->serial->dev;
1189         char buf[1];
1190         int v = simple_strtoul(valbuf, NULL, 10);
1191         int rv = 0;
1192
1193         dbg("%s: setting event char = %i", __func__, v);
1194
1195         rv = usb_control_msg(udev,
1196                              usb_sndctrlpipe(udev, 0),
1197                              FTDI_SIO_SET_EVENT_CHAR_REQUEST,
1198                              FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE,
1199                              v, priv->interface,
1200                              buf, 0, WDR_TIMEOUT);
1201
1202         if (rv < 0) {
1203                 dbg("Unable to write event character: %i", rv);
1204                 return -EIO;
1205         }
1206
1207         return count;
1208 }
1209
1210 static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer);
1211 static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char);
1212
1213 static int create_sysfs_attrs(struct usb_serial_port *port)
1214 {
1215         struct ftdi_private *priv = usb_get_serial_port_data(port);
1216         int retval = 0;
1217
1218         dbg("%s",__func__);
1219
1220         /* XXX I've no idea if the original SIO supports the event_char
1221          * sysfs parameter, so I'm playing it safe.  */
1222         if (priv->chip_type != SIO) {
1223                 dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]);
1224                 retval = device_create_file(&port->dev, &dev_attr_event_char);
1225                 if ((!retval) &&
1226                     (priv->chip_type == FT232BM ||
1227                      priv->chip_type == FT2232C ||
1228                      priv->chip_type == FT232RL)) {
1229                         retval = device_create_file(&port->dev,
1230                                                     &dev_attr_latency_timer);
1231                 }
1232         }
1233         return retval;
1234 }
1235
1236 static void remove_sysfs_attrs(struct usb_serial_port *port)
1237 {
1238         struct ftdi_private *priv = usb_get_serial_port_data(port);
1239
1240         dbg("%s",__func__);
1241
1242         /* XXX see create_sysfs_attrs */
1243         if (priv->chip_type != SIO) {
1244                 device_remove_file(&port->dev, &dev_attr_event_char);
1245                 if (priv->chip_type == FT232BM ||
1246                     priv->chip_type == FT2232C ||
1247                     priv->chip_type == FT232RL) {
1248                         device_remove_file(&port->dev, &dev_attr_latency_timer);
1249                 }
1250         }
1251
1252 }
1253
1254 /*
1255  * ***************************************************************************
1256  * FTDI driver specific functions
1257  * ***************************************************************************
1258  */
1259
1260 /* Probe function to check for special devices */
1261 static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id)
1262 {
1263         struct ftdi_sio_quirk *quirk = (struct ftdi_sio_quirk *)id->driver_info;
1264
1265         if (quirk && quirk->probe) {
1266                 int ret = quirk->probe(serial);
1267                 if (ret != 0)
1268                         return ret;
1269         }
1270
1271         usb_set_serial_data(serial, (void *)id->driver_info);
1272
1273         return 0;
1274 }
1275
1276 static int ftdi_sio_port_probe(struct usb_serial_port *port)
1277 {
1278         struct ftdi_private *priv;
1279         struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial);
1280
1281
1282         dbg("%s",__func__);
1283
1284         priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
1285         if (!priv){
1286                 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct ftdi_private));
1287                 return -ENOMEM;
1288         }
1289
1290         spin_lock_init(&priv->rx_lock);
1291         spin_lock_init(&priv->tx_lock);
1292         init_waitqueue_head(&priv->delta_msr_wait);
1293         /* This will push the characters through immediately rather
1294            than queue a task to deliver them */
1295         priv->flags = ASYNC_LOW_LATENCY;
1296
1297         if (quirk && quirk->port_probe)
1298                 quirk->port_probe(priv);
1299
1300         /* Increase the size of read buffers */
1301         kfree(port->bulk_in_buffer);
1302         port->bulk_in_buffer = kmalloc (BUFSZ, GFP_KERNEL);
1303         if (!port->bulk_in_buffer) {
1304                 kfree (priv);
1305                 return -ENOMEM;
1306         }
1307         if (port->read_urb) {
1308                 port->read_urb->transfer_buffer = port->bulk_in_buffer;
1309                 port->read_urb->transfer_buffer_length = BUFSZ;
1310         }
1311
1312         INIT_DELAYED_WORK(&priv->rx_work, ftdi_process_read);
1313         priv->port = port;
1314
1315         /* Free port's existing write urb and transfer buffer. */
1316         if (port->write_urb) {
1317                 usb_free_urb (port->write_urb);
1318                 port->write_urb = NULL;
1319         }
1320         kfree(port->bulk_out_buffer);
1321         port->bulk_out_buffer = NULL;
1322
1323         usb_set_serial_port_data(port, priv);
1324
1325         ftdi_determine_type (port);
1326         create_sysfs_attrs(port);
1327         return 0;
1328 }
1329
1330 /* Setup for the USB-UIRT device, which requires hardwired
1331  * baudrate (38400 gets mapped to 312500) */
1332 /* Called from usbserial:serial_probe */
1333 static void ftdi_USB_UIRT_setup (struct ftdi_private *priv)
1334 {
1335         dbg("%s",__func__);
1336
1337         priv->flags |= ASYNC_SPD_CUST;
1338         priv->custom_divisor = 77;
1339         priv->force_baud = 38400;
1340 } /* ftdi_USB_UIRT_setup */
1341
1342 /* Setup for the HE-TIRA1 device, which requires hardwired
1343  * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled.  */
1344 static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv)
1345 {
1346         dbg("%s",__func__);
1347
1348         priv->flags |= ASYNC_SPD_CUST;
1349         priv->custom_divisor = 240;
1350         priv->force_baud = 38400;
1351         priv->force_rtscts = 1;
1352 } /* ftdi_HE_TIRA1_setup */
1353
1354 /*
1355  * First port on JTAG adaptors such as Olimex arm-usb-ocd or the FIC/OpenMoko
1356  * Neo1973 Debug Board is reserved for JTAG interface and can be accessed from
1357  * userspace using openocd.
1358  */
1359 static int ftdi_jtag_probe(struct usb_serial *serial)
1360 {
1361         struct usb_device *udev = serial->dev;
1362         struct usb_interface *interface = serial->interface;
1363
1364         dbg("%s",__func__);
1365
1366         if (interface == udev->actconfig->interface[0]) {
1367                 info("Ignoring serial port reserved for JTAG");
1368                 return -ENODEV;
1369         }
1370
1371         return 0;
1372 }
1373
1374 /*
1375  * The Matrix Orbital VK204-25-USB has an invalid IN endpoint.
1376  * We have to correct it if we want to read from it.
1377  */
1378 static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
1379 {
1380         struct usb_host_endpoint *ep = serial->dev->ep_in[1];
1381         struct usb_endpoint_descriptor *ep_desc = &ep->desc;
1382
1383         if (ep->enabled && ep_desc->wMaxPacketSize == 0) {
1384                 ep_desc->wMaxPacketSize = cpu_to_le16(0x40);
1385                 info("Fixing invalid wMaxPacketSize on read pipe");
1386         }
1387
1388         return 0;
1389 }
1390
1391 /* ftdi_shutdown is called from usbserial:usb_serial_disconnect
1392  *   it is called when the usb device is disconnected
1393  *
1394  *   usbserial:usb_serial_disconnect
1395  *      calls __serial_close for each open of the port
1396  *      shutdown is called then (ie ftdi_shutdown)
1397  */
1398 static void ftdi_shutdown (struct usb_serial *serial)
1399 {
1400         dbg("%s", __func__);
1401 }
1402
1403 static int ftdi_sio_port_remove(struct usb_serial_port *port)
1404 {
1405         struct ftdi_private *priv = usb_get_serial_port_data(port);
1406
1407         dbg("%s", __func__);
1408
1409         remove_sysfs_attrs(port);
1410
1411         /* all open ports are closed at this point
1412          *    (by usbserial.c:__serial_close, which calls ftdi_close)
1413          */
1414
1415         if (priv) {
1416                 usb_set_serial_port_data(port, NULL);
1417                 kfree(priv);
1418         }
1419
1420         return 0;
1421 }
1422
1423 static int  ftdi_open (struct usb_serial_port *port, struct file *filp)
1424 { /* ftdi_open */
1425         struct usb_device *dev = port->serial->dev;
1426         struct ftdi_private *priv = usb_get_serial_port_data(port);
1427         unsigned long flags;
1428
1429         int result = 0;
1430         char buf[1]; /* Needed for the usb_control_msg I think */
1431
1432         dbg("%s", __func__);
1433
1434         spin_lock_irqsave(&priv->tx_lock, flags);
1435         priv->tx_bytes = 0;
1436         spin_unlock_irqrestore(&priv->tx_lock, flags);
1437         spin_lock_irqsave(&priv->rx_lock, flags);
1438         priv->rx_bytes = 0;
1439         spin_unlock_irqrestore(&priv->rx_lock, flags);
1440
1441         if (port->tty)
1442                 port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1443
1444         /* No error checking for this (will get errors later anyway) */
1445         /* See ftdi_sio.h for description of what is reset */
1446         usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1447                         FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE,
1448                         FTDI_SIO_RESET_SIO,
1449                         priv->interface, buf, 0, WDR_TIMEOUT);
1450
1451         /* Termios defaults are set by usb_serial_init. We don't change
1452            port->tty->termios - this would loose speed settings, etc.
1453            This is same behaviour as serial.c/rs_open() - Kuba */
1454
1455         /* ftdi_set_termios  will send usb control messages */
1456         if (port->tty)
1457                 ftdi_set_termios(port, port->tty->termios);
1458
1459         /* FIXME: Flow control might be enabled, so it should be checked -
1460            we have no control of defaults! */
1461         /* Turn on RTS and DTR since we are not flow controlling by default */
1462         set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1463
1464         /* Not throttled */
1465         spin_lock_irqsave(&priv->rx_lock, flags);
1466         priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
1467         spin_unlock_irqrestore(&priv->rx_lock, flags);
1468
1469         /* Start reading from the device */
1470         priv->rx_processed = 0;
1471         usb_fill_bulk_urb(port->read_urb, dev,
1472                       usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
1473                       port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
1474                       ftdi_read_bulk_callback, port);
1475         result = usb_submit_urb(port->read_urb, GFP_KERNEL);
1476         if (result)
1477                 err("%s - failed submitting read urb, error %d", __func__, result);
1478
1479
1480         return result;
1481 } /* ftdi_open */
1482
1483
1484
1485 /*
1486  * usbserial:__serial_close  only calls ftdi_close if the point is open
1487  *
1488  *   This only gets called when it is the last close
1489  *
1490  *
1491  */
1492
1493 static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1494 { /* ftdi_close */
1495         unsigned int c_cflag = port->tty->termios->c_cflag;
1496         struct ftdi_private *priv = usb_get_serial_port_data(port);
1497         char buf[1];
1498
1499         dbg("%s", __func__);
1500
1501         mutex_lock(&port->serial->disc_mutex);
1502         if (c_cflag & HUPCL && !port->serial->disconnected){
1503                 /* Disable flow control */
1504                 if (usb_control_msg(port->serial->dev,
1505                                     usb_sndctrlpipe(port->serial->dev, 0),
1506                                     FTDI_SIO_SET_FLOW_CTRL_REQUEST,
1507                                     FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
1508                                     0, priv->interface, buf, 0,
1509                                     WDR_TIMEOUT) < 0) {
1510                         err("error from flowcontrol urb");
1511                 }
1512
1513                 /* drop RTS and DTR */
1514                 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1515         } /* Note change no line if hupcl is off */
1516         mutex_unlock(&port->serial->disc_mutex);
1517
1518         /* cancel any scheduled reading */
1519         cancel_delayed_work(&priv->rx_work);
1520         flush_scheduled_work();
1521
1522         /* shutdown our bulk read */
1523         usb_kill_urb(port->read_urb);
1524 } /* ftdi_close */
1525
1526
1527
1528 /* The SIO requires the first byte to have:
1529  *  B0 1
1530  *  B1 0
1531  *  B2..7 length of message excluding byte 0
1532  *
1533  * The new devices do not require this byte
1534  */
1535 static int ftdi_write (struct usb_serial_port *port,
1536                            const unsigned char *buf, int count)
1537 { /* ftdi_write */
1538         struct ftdi_private *priv = usb_get_serial_port_data(port);
1539         struct urb *urb;
1540         unsigned char *buffer;
1541         int data_offset ;       /* will be 1 for the SIO and 0 otherwise */
1542         int status;
1543         int transfer_size;
1544         unsigned long flags;
1545
1546         dbg("%s port %d, %d bytes", __func__, port->number, count);
1547
1548         if (count == 0) {
1549                 dbg("write request of 0 bytes");
1550                 return 0;
1551         }
1552         spin_lock_irqsave(&priv->tx_lock, flags);
1553         if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) {
1554                 spin_unlock_irqrestore(&priv->tx_lock, flags);
1555                 dbg("%s - write limit hit\n", __func__);
1556                 return 0;
1557         }
1558         priv->tx_outstanding_urbs++;
1559         spin_unlock_irqrestore(&priv->tx_lock, flags);
1560
1561         data_offset = priv->write_offset;
1562         dbg("data_offset set to %d",data_offset);
1563
1564         /* Determine total transfer size */
1565         transfer_size = count;
1566         if (data_offset > 0) {
1567                 /* Original sio needs control bytes too... */
1568                 transfer_size += (data_offset *
1569                                 ((count + (PKTSZ - 1 - data_offset)) /
1570                                  (PKTSZ - data_offset)));
1571         }
1572
1573         buffer = kmalloc (transfer_size, GFP_ATOMIC);
1574         if (!buffer) {
1575                 err("%s ran out of kernel memory for urb ...", __func__);
1576                 count = -ENOMEM;
1577                 goto error_no_buffer;
1578         }
1579
1580         urb = usb_alloc_urb(0, GFP_ATOMIC);
1581         if (!urb) {
1582                 err("%s - no more free urbs", __func__);
1583                 count = -ENOMEM;
1584                 goto error_no_urb;
1585         }
1586
1587         /* Copy data */
1588         if (data_offset > 0) {
1589                 /* Original sio requires control byte at start of each packet. */
1590                 int user_pktsz = PKTSZ - data_offset;
1591                 int todo = count;
1592                 unsigned char *first_byte = buffer;
1593                 const unsigned char *current_position = buf;
1594
1595                 while (todo > 0) {
1596                         if (user_pktsz > todo) {
1597                                 user_pktsz = todo;
1598                         }
1599                         /* Write the control byte at the front of the packet*/
1600                         *first_byte = 1 | ((user_pktsz) << 2);
1601                         /* Copy data for packet */
1602                         memcpy (first_byte + data_offset,
1603                                 current_position, user_pktsz);
1604                         first_byte += user_pktsz + data_offset;
1605                         current_position += user_pktsz;
1606                         todo -= user_pktsz;
1607                 }
1608         } else {
1609                 /* No control byte required. */
1610                 /* Copy in the data to send */
1611                 memcpy (buffer, buf, count);
1612         }
1613
1614         usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, buffer);
1615
1616         /* fill the buffer and send it */
1617         usb_fill_bulk_urb(urb, port->serial->dev,
1618                       usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
1619                       buffer, transfer_size,
1620                       ftdi_write_bulk_callback, port);
1621
1622         status = usb_submit_urb(urb, GFP_ATOMIC);
1623         if (status) {
1624                 err("%s - failed submitting write urb, error %d", __func__, status);
1625                 count = status;
1626                 goto error;
1627         } else {
1628                 spin_lock_irqsave(&priv->tx_lock, flags);
1629                 priv->tx_outstanding_bytes += count;
1630                 priv->tx_bytes += count;
1631                 spin_unlock_irqrestore(&priv->tx_lock, flags);
1632         }
1633
1634         /* we are done with this urb, so let the host driver
1635          * really free it when it is finished with it */
1636         usb_free_urb(urb);
1637
1638         dbg("%s write returning: %d", __func__, count);
1639         return count;
1640 error:
1641         usb_free_urb(urb);
1642 error_no_urb:
1643         kfree (buffer);
1644 error_no_buffer:
1645         spin_lock_irqsave(&priv->tx_lock, flags);
1646         priv->tx_outstanding_urbs--;
1647         spin_unlock_irqrestore(&priv->tx_lock, flags);
1648         return count;
1649 } /* ftdi_write */
1650
1651
1652 /* This function may get called when the device is closed */
1653
1654 static void ftdi_write_bulk_callback (struct urb *urb)
1655 {
1656         unsigned long flags;
1657         struct usb_serial_port *port = urb->context;
1658         struct ftdi_private *priv;
1659         int data_offset;       /* will be 1 for the SIO and 0 otherwise */
1660         unsigned long countback;
1661         int status = urb->status;
1662
1663         /* free up the transfer buffer, as usb_free_urb() does not do this */
1664         kfree (urb->transfer_buffer);
1665
1666         dbg("%s - port %d", __func__, port->number);
1667
1668         if (status) {
1669                 dbg("nonzero write bulk status received: %d", status);
1670                 return;
1671         }
1672
1673         priv = usb_get_serial_port_data(port);
1674         if (!priv) {
1675                 dbg("%s - bad port private data pointer - exiting", __func__);
1676                 return;
1677         }
1678         /* account for transferred data */
1679         countback = urb->actual_length;
1680         data_offset = priv->write_offset;
1681         if (data_offset > 0) {
1682                 /* Subtract the control bytes */
1683                 countback -= (data_offset * DIV_ROUND_UP(countback, PKTSZ));
1684         }
1685         spin_lock_irqsave(&priv->tx_lock, flags);
1686         --priv->tx_outstanding_urbs;
1687         priv->tx_outstanding_bytes -= countback;
1688         spin_unlock_irqrestore(&priv->tx_lock, flags);
1689
1690         usb_serial_port_softint(port);
1691 } /* ftdi_write_bulk_callback */
1692
1693
1694 static int ftdi_write_room( struct usb_serial_port *port )
1695 {
1696         struct ftdi_private *priv = usb_get_serial_port_data(port);
1697         int room;
1698         unsigned long flags;
1699
1700         dbg("%s - port %d", __func__, port->number);
1701
1702         spin_lock_irqsave(&priv->tx_lock, flags);
1703         if (priv->tx_outstanding_urbs < URB_UPPER_LIMIT) {
1704                 /*
1705                  * We really can take anything the user throws at us
1706                  * but let's pick a nice big number to tell the tty
1707                  * layer that we have lots of free space
1708                  */
1709                 room = 2048;
1710         } else {
1711                 room = 0;
1712         }
1713         spin_unlock_irqrestore(&priv->tx_lock, flags);
1714         return room;
1715 } /* ftdi_write_room */
1716
1717
1718 static int ftdi_chars_in_buffer (struct usb_serial_port *port)
1719 { /* ftdi_chars_in_buffer */
1720         struct ftdi_private *priv = usb_get_serial_port_data(port);
1721         int buffered;
1722         unsigned long flags;
1723
1724         dbg("%s - port %d", __func__, port->number);
1725
1726         spin_lock_irqsave(&priv->tx_lock, flags);
1727         buffered = (int)priv->tx_outstanding_bytes;
1728         spin_unlock_irqrestore(&priv->tx_lock, flags);
1729         if (buffered < 0) {
1730                 err("%s outstanding tx bytes is negative!", __func__);
1731                 buffered = 0;
1732         }
1733         return buffered;
1734 } /* ftdi_chars_in_buffer */
1735
1736
1737
1738 static void ftdi_read_bulk_callback (struct urb *urb)
1739 { /* ftdi_read_bulk_callback */
1740         struct usb_serial_port *port = urb->context;
1741         struct tty_struct *tty;
1742         struct ftdi_private *priv;
1743         unsigned long countread;
1744         unsigned long flags;
1745         int status = urb->status;
1746
1747         if (urb->number_of_packets > 0) {
1748                 err("%s transfer_buffer_length %d actual_length %d number of packets %d",__func__,
1749                     urb->transfer_buffer_length, urb->actual_length, urb->number_of_packets );
1750                 err("%s transfer_flags %x ", __func__,urb->transfer_flags );
1751         }
1752
1753         dbg("%s - port %d", __func__, port->number);
1754
1755         if (port->open_count <= 0)
1756                 return;
1757
1758         tty = port->tty;
1759         if (!tty) {
1760                 dbg("%s - bad tty pointer - exiting",__func__);
1761                 return;
1762         }
1763
1764         priv = usb_get_serial_port_data(port);
1765         if (!priv) {
1766                 dbg("%s - bad port private data pointer - exiting", __func__);
1767                 return;
1768         }
1769
1770         if (urb != port->read_urb) {
1771                 err("%s - Not my urb!", __func__);
1772         }
1773
1774         if (status) {
1775                 /* This will happen at close every time so it is a dbg not an err */
1776                 dbg("(this is ok on close) nonzero read bulk status received: "
1777                     "%d", status);
1778                 return;
1779         }
1780
1781         /* count data bytes, but not status bytes */
1782         countread = urb->actual_length;
1783         countread -= 2 * DIV_ROUND_UP(countread, PKTSZ);
1784         spin_lock_irqsave(&priv->rx_lock, flags);
1785         priv->rx_bytes += countread;
1786         spin_unlock_irqrestore(&priv->rx_lock, flags);
1787
1788         ftdi_process_read(&priv->rx_work.work);
1789
1790 } /* ftdi_read_bulk_callback */
1791
1792
1793 static void ftdi_process_read (struct work_struct *work)
1794 { /* ftdi_process_read */
1795         struct ftdi_private *priv =
1796                 container_of(work, struct ftdi_private, rx_work.work);
1797         struct usb_serial_port *port = priv->port;
1798         struct urb *urb;
1799         struct tty_struct *tty;
1800         char error_flag;
1801         unsigned char *data;
1802
1803         int i;
1804         int result;
1805         int need_flip;
1806         int packet_offset;
1807         unsigned long flags;
1808
1809         dbg("%s - port %d", __func__, port->number);
1810
1811         if (port->open_count <= 0)
1812                 return;
1813
1814         tty = port->tty;
1815         if (!tty) {
1816                 dbg("%s - bad tty pointer - exiting",__func__);
1817                 return;
1818         }
1819
1820         priv = usb_get_serial_port_data(port);
1821         if (!priv) {
1822                 dbg("%s - bad port private data pointer - exiting", __func__);
1823                 return;
1824         }
1825
1826         urb = port->read_urb;
1827         if (!urb) {
1828                 dbg("%s - bad read_urb pointer - exiting", __func__);
1829                 return;
1830         }
1831
1832         data = urb->transfer_buffer;
1833
1834         if (priv->rx_processed) {
1835                 dbg("%s - already processed: %d bytes, %d remain", __func__,
1836                                 priv->rx_processed,
1837                                 urb->actual_length - priv->rx_processed);
1838         } else {
1839                 /* The first two bytes of every read packet are status */
1840                 if (urb->actual_length > 2) {
1841                         usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
1842                 } else {
1843                         dbg("Status only: %03oo %03oo",data[0],data[1]);
1844                 }
1845         }
1846
1847
1848         /* TO DO -- check for hung up line and handle appropriately: */
1849         /*   send hangup  */
1850         /* See acm.c - you do a tty_hangup  - eg tty_hangup(tty) */
1851         /* if CD is dropped and the line is not CLOCAL then we should hangup */
1852
1853         need_flip = 0;
1854         for (packet_offset = priv->rx_processed; packet_offset < urb->actual_length; packet_offset += PKTSZ) {
1855                 int length;
1856
1857                 /* Compare new line status to the old one, signal if different */
1858                 /* N.B. packet may be processed more than once, but differences
1859                  * are only processed once.  */
1860                 if (priv != NULL) {
1861                         char new_status = data[packet_offset+0] & FTDI_STATUS_B0_MASK;
1862                         if (new_status != priv->prev_status) {
1863                                 priv->diff_status |= new_status ^ priv->prev_status;
1864                                 wake_up_interruptible(&priv->delta_msr_wait);
1865                                 priv->prev_status = new_status;
1866                         }
1867                 }
1868
1869                 length = min(PKTSZ, urb->actual_length-packet_offset)-2;
1870                 if (length < 0) {
1871                         err("%s - bad packet length: %d", __func__, length+2);
1872                         length = 0;
1873                 }
1874
1875                 if (priv->rx_flags & THROTTLED) {
1876                         dbg("%s - throttled", __func__);
1877                         break;
1878                 }
1879                 if (tty_buffer_request_room(tty, length) < length) {
1880                         /* break out & wait for throttling/unthrottling to happen */
1881                         dbg("%s - receive room low", __func__);
1882                         break;
1883                 }
1884
1885                 /* Handle errors and break */
1886                 error_flag = TTY_NORMAL;
1887                 /* Although the device uses a bitmask and hence can have multiple */
1888                 /* errors on a packet - the order here sets the priority the */
1889                 /* error is returned to the tty layer  */
1890
1891                 if ( data[packet_offset+1] & FTDI_RS_OE ) {
1892                         error_flag = TTY_OVERRUN;
1893                         dbg("OVERRRUN error");
1894                 }
1895                 if ( data[packet_offset+1] & FTDI_RS_BI ) {
1896                         error_flag = TTY_BREAK;
1897                         dbg("BREAK received");
1898                 }
1899                 if ( data[packet_offset+1] & FTDI_RS_PE ) {
1900                         error_flag = TTY_PARITY;
1901                         dbg("PARITY error");
1902                 }
1903                 if ( data[packet_offset+1] & FTDI_RS_FE ) {
1904                         error_flag = TTY_FRAME;
1905                         dbg("FRAMING error");
1906                 }
1907                 if (length > 0) {
1908                         for (i = 2; i < length+2; i++) {
1909                                 /* Note that the error flag is duplicated for
1910                                    every character received since we don't know
1911                                    which character it applied to */
1912                                 tty_insert_flip_char(tty, data[packet_offset+i], error_flag);
1913                         }
1914                         need_flip = 1;
1915                 }
1916
1917 #ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
1918                 /* if a parity error is detected you get status packets forever
1919                    until a character is sent without a parity error.
1920                    This doesn't work well since the application receives a never
1921                    ending stream of bad data - even though new data hasn't been sent.
1922                    Therefore I (bill) have taken this out.
1923                    However - this might make sense for framing errors and so on
1924                    so I am leaving the code in for now.
1925                 */
1926                 else {
1927                         if (error_flag != TTY_NORMAL){
1928                                 dbg("error_flag is not normal");
1929                                 /* In this case it is just status - if that is an error send a bad character */
1930                                 if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
1931                                         tty_flip_buffer_push(tty);
1932                                 }
1933                                 tty_insert_flip_char(tty, 0xff, error_flag);
1934                                 need_flip = 1;
1935                         }
1936                 }
1937 #endif
1938         } /* "for(packet_offset=0..." */
1939
1940         /* Low latency */
1941         if (need_flip) {
1942                 tty_flip_buffer_push(tty);
1943         }
1944
1945         if (packet_offset < urb->actual_length) {
1946                 /* not completely processed - record progress */
1947                 priv->rx_processed = packet_offset;
1948                 dbg("%s - incomplete, %d bytes processed, %d remain",
1949                                 __func__, packet_offset,
1950                                 urb->actual_length - packet_offset);
1951                 /* check if we were throttled while processing */
1952                 spin_lock_irqsave(&priv->rx_lock, flags);
1953                 if (priv->rx_flags & THROTTLED) {
1954                         priv->rx_flags |= ACTUALLY_THROTTLED;
1955                         spin_unlock_irqrestore(&priv->rx_lock, flags);
1956                         dbg("%s - deferring remainder until unthrottled",
1957                                         __func__);
1958                         return;
1959                 }
1960                 spin_unlock_irqrestore(&priv->rx_lock, flags);
1961                 /* if the port is closed stop trying to read */
1962                 if (port->open_count > 0){
1963                         /* delay processing of remainder */
1964                         schedule_delayed_work(&priv->rx_work, 1);
1965                 } else {
1966                         dbg("%s - port is closed", __func__);
1967                 }
1968                 return;
1969         }
1970
1971         /* urb is completely processed */
1972         priv->rx_processed = 0;
1973
1974         /* if the port is closed stop trying to read */
1975         if (port->open_count > 0){
1976                 /* Continue trying to always read  */
1977                 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
1978                               usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
1979                               port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
1980                               ftdi_read_bulk_callback, port);
1981
1982                 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1983                 if (result)
1984                         err("%s - failed resubmitting read urb, error %d", __func__, result);
1985         }
1986
1987         return;
1988 } /* ftdi_process_read */
1989
1990
1991 static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
1992 {
1993         struct ftdi_private *priv = usb_get_serial_port_data(port);
1994         __u16 urb_value = 0;
1995         char buf[1];
1996
1997         /* break_state = -1 to turn on break, and 0 to turn off break */
1998         /* see drivers/char/tty_io.c to see it used */
1999         /* last_set_data_urb_value NEVER has the break bit set in it */
2000
2001         if (break_state) {
2002                 urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;
2003         } else {
2004                 urb_value = priv->last_set_data_urb_value;
2005         }
2006
2007
2008         if (usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0),
2009                             FTDI_SIO_SET_DATA_REQUEST,
2010                             FTDI_SIO_SET_DATA_REQUEST_TYPE,
2011                             urb_value , priv->interface,
2012                             buf, 0, WDR_TIMEOUT) < 0) {
2013                 err("%s FAILED to enable/disable break state (state was %d)", __func__,break_state);
2014         }
2015
2016         dbg("%s break state is %d - urb is %d", __func__,break_state, urb_value);
2017
2018 }
2019
2020
2021 /* old_termios contains the original termios settings and tty->termios contains
2022  * the new setting to be used
2023  * WARNING: set_termios calls this with old_termios in kernel space
2024  */
2025
2026 static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
2027 { /* ftdi_termios */
2028         struct usb_device *dev = port->serial->dev;
2029         struct ftdi_private *priv = usb_get_serial_port_data(port);
2030         struct ktermios *termios = port->tty->termios;
2031         unsigned int cflag = termios->c_cflag;
2032         __u16 urb_value; /* will hold the new flags */
2033         char buf[1]; /* Perhaps I should dynamically alloc this? */
2034
2035         // Added for xon/xoff support
2036         unsigned int iflag = termios->c_iflag;
2037         unsigned char vstop;
2038         unsigned char vstart;
2039
2040         dbg("%s", __func__);
2041
2042         /* Force baud rate if this device requires it, unless it is set to B0. */
2043         if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) {
2044                 dbg("%s: forcing baud rate for this device", __func__);
2045                 tty_encode_baud_rate(port->tty, priv->force_baud,
2046                                         priv->force_baud);
2047         }
2048
2049         /* Force RTS-CTS if this device requires it. */
2050         if (priv->force_rtscts) {
2051                 dbg("%s: forcing rtscts for this device", __func__);
2052                 termios->c_cflag |= CRTSCTS;
2053         }
2054
2055         cflag = termios->c_cflag;
2056
2057         /* FIXME -For this cut I don't care if the line is really changing or
2058            not  - so just do the change regardless  - should be able to
2059            compare old_termios and tty->termios */
2060         /* NOTE These routines can get interrupted by
2061            ftdi_sio_read_bulk_callback  - need to examine what this
2062            means - don't see any problems yet */
2063
2064         /* Set number of data bits, parity, stop bits */
2065
2066         termios->c_cflag &= ~CMSPAR;
2067
2068         urb_value = 0;
2069         urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 :
2070                       FTDI_SIO_SET_DATA_STOP_BITS_1);
2071         urb_value |= (cflag & PARENB ?
2072                       (cflag & PARODD ? FTDI_SIO_SET_DATA_PARITY_ODD :
2073                        FTDI_SIO_SET_DATA_PARITY_EVEN) :
2074                       FTDI_SIO_SET_DATA_PARITY_NONE);
2075         if (cflag & CSIZE) {
2076                 switch (cflag & CSIZE) {
2077                 case CS5: urb_value |= 5; dbg("Setting CS5"); break;
2078                 case CS6: urb_value |= 6; dbg("Setting CS6"); break;
2079                 case CS7: urb_value |= 7; dbg("Setting CS7"); break;
2080                 case CS8: urb_value |= 8; dbg("Setting CS8"); break;
2081                 default:
2082                         err("CSIZE was set but not CS5-CS8");
2083                 }
2084         }
2085
2086         /* This is needed by the break command since it uses the same command - but is
2087          *  or'ed with this value  */
2088         priv->last_set_data_urb_value = urb_value;
2089
2090         if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
2091                             FTDI_SIO_SET_DATA_REQUEST,
2092                             FTDI_SIO_SET_DATA_REQUEST_TYPE,
2093                             urb_value , priv->interface,
2094                             buf, 0, WDR_SHORT_TIMEOUT) < 0) {
2095                 err("%s FAILED to set databits/stopbits/parity", __func__);
2096         }
2097
2098         /* Now do the baudrate */
2099         if ((cflag & CBAUD) == B0 ) {
2100                 /* Disable flow control */
2101                 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
2102                                     FTDI_SIO_SET_FLOW_CTRL_REQUEST,
2103                                     FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2104                                     0, priv->interface,
2105                                     buf, 0, WDR_TIMEOUT) < 0) {
2106                         err("%s error from disable flowcontrol urb", __func__);
2107                 }
2108                 /* Drop RTS and DTR */
2109                 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2110         } else {
2111                 /* set the baudrate determined before */
2112                 if (change_speed(port)) {
2113                         err("%s urb failed to set baudrate", __func__);
2114                 }
2115                 /* Ensure RTS and DTR are raised when baudrate changed from 0 */
2116                 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) {
2117                         set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2118                 }
2119         }
2120
2121         /* Set flow control */
2122         /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */
2123         if (cflag & CRTSCTS) {
2124                 dbg("%s Setting to CRTSCTS flow control", __func__);
2125                 if (usb_control_msg(dev,
2126                                     usb_sndctrlpipe(dev, 0),
2127                                     FTDI_SIO_SET_FLOW_CTRL_REQUEST,
2128                                     FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2129                                     0 , (FTDI_SIO_RTS_CTS_HS | priv->interface),
2130                                     buf, 0, WDR_TIMEOUT) < 0) {
2131                         err("urb failed to set to rts/cts flow control");
2132                 }
2133
2134         } else {
2135                 /*
2136                  * Xon/Xoff code
2137                  *
2138                  * Check the IXOFF status in the iflag component of the termios structure
2139                  * if IXOFF is not set, the pre-xon/xoff code is executed.
2140                 */
2141                 if (iflag & IXOFF) {
2142                         dbg("%s  request to enable xonxoff iflag=%04x",__func__,iflag);
2143                         // Try to enable the XON/XOFF on the ftdi_sio
2144                         // Set the vstart and vstop -- could have been done up above where
2145                         // a lot of other dereferencing is done but that would be very
2146                         // inefficient as vstart and vstop are not always needed
2147                         vstart = termios->c_cc[VSTART];
2148                         vstop = termios->c_cc[VSTOP];
2149                         urb_value=(vstop << 8) | (vstart);
2150
2151                         if (usb_control_msg(dev,
2152                                             usb_sndctrlpipe(dev, 0),
2153                                             FTDI_SIO_SET_FLOW_CTRL_REQUEST,
2154                                             FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2155                                             urb_value , (FTDI_SIO_XON_XOFF_HS
2156                                                          | priv->interface),
2157                                             buf, 0, WDR_TIMEOUT) < 0) {
2158                                 err("urb failed to set to xon/xoff flow control");
2159                         }
2160                 } else {
2161                         /* else clause to only run if cfag ! CRTSCTS and iflag ! XOFF */
2162                         /* CHECKME Assuming XON/XOFF handled by tty stack - not by device */
2163                         dbg("%s Turning off hardware flow control", __func__);
2164                         if (usb_control_msg(dev,
2165                                             usb_sndctrlpipe(dev, 0),
2166                                             FTDI_SIO_SET_FLOW_CTRL_REQUEST,
2167                                             FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2168                                             0, priv->interface,
2169                                             buf, 0, WDR_TIMEOUT) < 0) {
2170                                 err("urb failed to clear flow control");
2171                         }
2172                 }
2173
2174         }
2175         return;
2176 } /* ftdi_termios */
2177
2178
2179 static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
2180 {
2181         struct ftdi_private *priv = usb_get_serial_port_data(port);
2182         unsigned char buf[2];
2183         int ret;
2184
2185         dbg("%s TIOCMGET", __func__);
2186         switch (priv->chip_type) {
2187         case SIO:
2188                 /* Request the status from the device */
2189                 if ((ret = usb_control_msg(port->serial->dev,
2190                                            usb_rcvctrlpipe(port->serial->dev, 0),
2191                                            FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2192                                            FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2193                                            0, 0,
2194                                            buf, 1, WDR_TIMEOUT)) < 0 ) {
2195                         err("%s Could not get modem status of device - err: %d", __func__,
2196                             ret);
2197                         return(ret);
2198                 }
2199                 break;
2200         case FT8U232AM:
2201         case FT232BM:
2202         case FT2232C:
2203         case FT232RL:
2204                 /* the 8U232AM returns a two byte value (the sio is a 1 byte value) - in the same
2205                    format as the data returned from the in point */
2206                 if ((ret = usb_control_msg(port->serial->dev,
2207                                            usb_rcvctrlpipe(port->serial->dev, 0),
2208                                            FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2209                                            FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2210                                            0, priv->interface,
2211                                            buf, 2, WDR_TIMEOUT)) < 0 ) {
2212                         err("%s Could not get modem status of device - err: %d", __func__,
2213                             ret);
2214                         return(ret);
2215                 }
2216                 break;
2217         default:
2218                 return -EFAULT;
2219                 break;
2220         }
2221
2222         return  (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) |
2223                 (buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) |
2224                 (buf[0]  & FTDI_SIO_RI_MASK  ? TIOCM_RI  : 0) |
2225                 (buf[0]  & FTDI_SIO_RLSD_MASK ? TIOCM_CD  : 0) |
2226                 priv->last_dtr_rts;
2227 }
2228
2229 static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear)
2230 {
2231         dbg("%s TIOCMSET", __func__);
2232         return update_mctrl(port, set, clear);
2233 }
2234
2235
2236 static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
2237 {
2238         struct ftdi_private *priv = usb_get_serial_port_data(port);
2239
2240         dbg("%s cmd 0x%04x", __func__, cmd);
2241
2242         /* Based on code from acm.c and others */
2243         switch (cmd) {
2244
2245         case TIOCGSERIAL: /* gets serial port data */
2246                 return get_serial_info(port, (struct serial_struct __user *) arg);
2247
2248         case TIOCSSERIAL: /* sets serial port data */
2249                 return set_serial_info(port, (struct serial_struct __user *) arg);
2250
2251         /*
2252          * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
2253          * - mask passed in arg for lines of interest
2254          *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2255          * Caller should use TIOCGICOUNT to see which one it was.
2256          *
2257          * This code is borrowed from linux/drivers/char/serial.c
2258          */
2259         case TIOCMIWAIT:
2260                 while (priv != NULL) {
2261                         interruptible_sleep_on(&priv->delta_msr_wait);
2262                         /* see if a signal did it */
2263                         if (signal_pending(current))
2264                                 return -ERESTARTSYS;
2265                         else {
2266                                 char diff = priv->diff_status;
2267
2268                                 if (diff == 0) {
2269                                         return -EIO; /* no change => error */
2270                                 }
2271
2272                                 /* Consume all events */
2273                                 priv->diff_status = 0;
2274
2275                                 /* Return 0 if caller wanted to know about these bits */
2276                                 if ( ((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
2277                                      ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
2278                                      ((arg & TIOCM_CD)  && (diff & FTDI_RS0_RLSD)) ||
2279                                      ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS)) ) {
2280                                         return 0;
2281                                 }
2282                                 /*
2283                                  * Otherwise caller can't care less about what happened,
2284                                  * and so we continue to wait for more events.
2285                                  */
2286                         }
2287                 }
2288                 return(0);
2289                 break;
2290         default:
2291                 break;
2292
2293         }
2294
2295
2296         /* This is not necessarily an error - turns out the higher layers will do
2297          *  some ioctls itself (see comment above)
2298          */
2299         dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd);
2300
2301         return(-ENOIOCTLCMD);
2302 } /* ftdi_ioctl */
2303
2304
2305 static void ftdi_throttle (struct usb_serial_port *port)
2306 {
2307         struct ftdi_private *priv = usb_get_serial_port_data(port);
2308         unsigned long flags;
2309
2310         dbg("%s - port %d", __func__, port->number);
2311
2312         spin_lock_irqsave(&priv->rx_lock, flags);
2313         priv->rx_flags |= THROTTLED;
2314         spin_unlock_irqrestore(&priv->rx_lock, flags);
2315 }
2316
2317
2318 static void ftdi_unthrottle (struct usb_serial_port *port)
2319 {
2320         struct ftdi_private *priv = usb_get_serial_port_data(port);
2321         int actually_throttled;
2322         unsigned long flags;
2323
2324         dbg("%s - port %d", __func__, port->number);
2325
2326         spin_lock_irqsave(&priv->rx_lock, flags);
2327         actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
2328         priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
2329         spin_unlock_irqrestore(&priv->rx_lock, flags);
2330
2331         if (actually_throttled)
2332                 schedule_delayed_work(&priv->rx_work, 0);
2333 }
2334
2335 static int __init ftdi_init (void)
2336 {
2337         int retval;
2338
2339         dbg("%s", __func__);
2340         if (vendor > 0 && product > 0) {
2341                 /* Add user specified VID/PID to reserved element of table. */
2342                 int i;
2343                 for (i = 0; id_table_combined[i].idVendor; i++)
2344                         ;
2345                 id_table_combined[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
2346                 id_table_combined[i].idVendor = vendor;
2347                 id_table_combined[i].idProduct = product;
2348         }
2349         retval = usb_serial_register(&ftdi_sio_device);
2350         if (retval)
2351                 goto failed_sio_register;
2352         retval = usb_register(&ftdi_driver);
2353         if (retval)
2354                 goto failed_usb_register;
2355
2356         info(DRIVER_VERSION ":" DRIVER_DESC);
2357         return 0;
2358 failed_usb_register:
2359         usb_serial_deregister(&ftdi_sio_device);
2360 failed_sio_register:
2361         return retval;
2362 }
2363
2364
2365 static void __exit ftdi_exit (void)
2366 {
2367
2368         dbg("%s", __func__);
2369
2370         usb_deregister (&ftdi_driver);
2371         usb_serial_deregister (&ftdi_sio_device);
2372
2373 }
2374
2375
2376 module_init(ftdi_init);
2377 module_exit(ftdi_exit);
2378
2379 MODULE_AUTHOR( DRIVER_AUTHOR );
2380 MODULE_DESCRIPTION( DRIVER_DESC );
2381 MODULE_LICENSE("GPL");
2382
2383 module_param(debug, bool, S_IRUGO | S_IWUSR);
2384 MODULE_PARM_DESC(debug, "Debug enabled or not");
2385 module_param(vendor, ushort, 0);
2386 MODULE_PARM_DESC(vendor, "User specified vendor ID (default="
2387                 __MODULE_STRING(FTDI_VID)")");
2388 module_param(product, ushort, 0);
2389 MODULE_PARM_DESC(vendor, "User specified product ID");
2390