11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * USB FTDI SIO driver 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1999 - 2001 51da177e4SLinus Torvalds * Greg Kroah-Hartman (greg@kroah.com) 61da177e4SLinus Torvalds * Bill Ryder (bryder@sgi.com) 71da177e4SLinus Torvalds * Copyright (C) 2002 81da177e4SLinus Torvalds * Kuba Ober (kuba@mareimbrium.org) 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 111da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 121da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 131da177e4SLinus Torvalds * (at your option) any later version. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * See Documentation/usb/usb-serial.txt for more information on using this driver 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * See http://ftdi-usb-sio.sourceforge.net for upto date testing info 181da177e4SLinus Torvalds * and extra documentation 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * (21/Jul/2004) Ian Abbott 211da177e4SLinus Torvalds * Incorporated Steven Turner's code to add support for the FT2232C chip. 221da177e4SLinus Torvalds * The prelimilary port to the 2.6 kernel was by Rus V. Brushkoff. I have 231da177e4SLinus Torvalds * fixed a couple of things. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * (27/May/2004) Ian Abbott 261da177e4SLinus Torvalds * Improved throttling code, mostly stolen from the WhiteHEAT driver. 271da177e4SLinus Torvalds * 281da177e4SLinus Torvalds * (26/Mar/2004) Jan Capek 291da177e4SLinus Torvalds * Added PID's for ICD-U20/ICD-U40 - incircuit PIC debuggers from CCS Inc. 301da177e4SLinus Torvalds * 311da177e4SLinus Torvalds * (09/Feb/2004) Ian Abbott 321da177e4SLinus Torvalds * Changed full name of USB-UIRT device to avoid "/" character. 331da177e4SLinus Torvalds * Added FTDI's alternate PID (0x6006) for FT232/245 devices. 341da177e4SLinus Torvalds * Added PID for "ELV USB Module UO100" from Stefan Frings. 351da177e4SLinus Torvalds * 361da177e4SLinus Torvalds * (21/Oct/2003) Ian Abbott 371da177e4SLinus Torvalds * Renamed some VID/PID macros for Matrix Orbital and Perle Systems 381da177e4SLinus Torvalds * devices. Removed Matrix Orbital and Perle Systems devices from the 391da177e4SLinus Torvalds * 8U232AM device table, but left them in the FT232BM table, as they are 401da177e4SLinus Torvalds * known to use only FT232BM. 411da177e4SLinus Torvalds * 421da177e4SLinus Torvalds * (17/Oct/2003) Scott Allen 431da177e4SLinus Torvalds * Added vid/pid for Perle Systems UltraPort USB serial converters 441da177e4SLinus Torvalds * 451da177e4SLinus Torvalds * (21/Sep/2003) Ian Abbott 461da177e4SLinus Torvalds * Added VID/PID for Omnidirectional Control Technology US101 USB to 471da177e4SLinus Torvalds * RS-232 adapter (also rebadged as Dick Smith Electronics XH6381). 481da177e4SLinus Torvalds * VID/PID supplied by Donald Gordon. 491da177e4SLinus Torvalds * 501da177e4SLinus Torvalds * (19/Aug/2003) Ian Abbott 511da177e4SLinus Torvalds * Freed urb's transfer buffer in write bulk callback. 521da177e4SLinus Torvalds * Omitted some paranoid checks in write bulk callback that don't matter. 531da177e4SLinus Torvalds * Scheduled work in write bulk callback regardless of port's open count. 541da177e4SLinus Torvalds * 551da177e4SLinus Torvalds * (05/Aug/2003) Ian Abbott 561da177e4SLinus Torvalds * Added VID/PID for ID TECH IDT1221U USB to RS-232 adapter. 571da177e4SLinus Torvalds * VID/PID provided by Steve Briggs. 581da177e4SLinus Torvalds * 591da177e4SLinus Torvalds * (23/Jul/2003) Ian Abbott 601da177e4SLinus Torvalds * Added PIDs for CrystalFontz 547, 633, 631, 635, 640 and 640 from 611da177e4SLinus Torvalds * Wayne Wylupski. 621da177e4SLinus Torvalds * 631da177e4SLinus Torvalds * (10/Jul/2003) David Glance 641da177e4SLinus Torvalds * Added PID for DSS-20 SyncStation cradle for Sony-Ericsson P800. 651da177e4SLinus Torvalds * 661da177e4SLinus Torvalds * (27/Jun/2003) Ian Abbott 671da177e4SLinus Torvalds * Reworked the urb handling logic. We have no more pool, but dynamically 681da177e4SLinus Torvalds * allocate the urb and the transfer buffer on the fly. In testing this 691da177e4SLinus Torvalds * does not incure any measurable overhead. This also relies on the fact 701da177e4SLinus Torvalds * that we have proper reference counting logic for urbs. I nicked this 711da177e4SLinus Torvalds * from Greg KH's Visor driver. 721da177e4SLinus Torvalds * 731da177e4SLinus Torvalds * (23/Jun/2003) Ian Abbott 741da177e4SLinus Torvalds * Reduced flip buffer pushes and corrected a data length test in 751da177e4SLinus Torvalds * ftdi_read_bulk_callback. 761da177e4SLinus Torvalds * Defererence pointers after any paranoid checks, not before. 771da177e4SLinus Torvalds * 781da177e4SLinus Torvalds * (21/Jun/2003) Erik Nygren 79093cf723SSteven Cole * Added support for Home Electronics Tira-1 IR transceiver using FT232BM chip. 801da177e4SLinus Torvalds * See <http://www.home-electro.com/tira1.htm>. Only operates properly 811da177e4SLinus Torvalds * at 100000 and RTS-CTS, so set custom divisor mode on startup. 821da177e4SLinus Torvalds * Also force the Tira-1 and USB-UIRT to only use their custom baud rates. 831da177e4SLinus Torvalds * 841da177e4SLinus Torvalds * (18/Jun/2003) Ian Abbott 851da177e4SLinus Torvalds * Added Device ID of the USB relais from Rudolf Gugler (backported from 861da177e4SLinus Torvalds * Philipp G�hring's patch for 2.5.x kernel). 871da177e4SLinus Torvalds * Moved read transfer buffer reallocation into startup function. 881da177e4SLinus Torvalds * Free existing write urb and transfer buffer in startup function. 891da177e4SLinus Torvalds * Only use urbs in write urb pool that were successfully allocated. 901da177e4SLinus Torvalds * Moved some constant macros out of functions. 911da177e4SLinus Torvalds * Minor whitespace and comment changes. 921da177e4SLinus Torvalds * 931da177e4SLinus Torvalds * (12/Jun/2003) David Norwood 94093cf723SSteven Cole * Added support for USB-UIRT IR transceiver using 8U232AM chip. 951da177e4SLinus Torvalds * See <http://home.earthlink.net/~jrhees/USBUIRT/index.htm>. Only 961da177e4SLinus Torvalds * operates properly at 312500, so set custom divisor mode on startup. 971da177e4SLinus Torvalds * 981da177e4SLinus Torvalds * (12/Jun/2003) Ian Abbott 991da177e4SLinus Torvalds * Added Sealevel SeaLINK+ 210x, 220x, 240x, 280x vid/pids from Tuan Hoang 1001da177e4SLinus Torvalds * - I've eliminated some that don't seem to exist! 1011da177e4SLinus Torvalds * Added Home Electronics Tira-1 IR transceiver pid from Chris Horn 1021da177e4SLinus Torvalds * Some whitespace/coding-style cleanups 1031da177e4SLinus Torvalds * 1041da177e4SLinus Torvalds * (11/Jun/2003) Ian Abbott 1051da177e4SLinus Torvalds * Fixed unsafe spinlock usage in ftdi_write 1061da177e4SLinus Torvalds * 1071da177e4SLinus Torvalds * (24/Feb/2003) Richard Shooter 1081da177e4SLinus Torvalds * Increase read buffer size to improve read speeds at higher baud rates 1091da177e4SLinus Torvalds * (specifically tested with up to 1Mb/sec at 1.5M baud) 1101da177e4SLinus Torvalds * 1111da177e4SLinus Torvalds * (23/Feb/2003) John Wilkins 1121da177e4SLinus Torvalds * Added Xon/xoff flow control (activating support in the ftdi device) 1131da177e4SLinus Torvalds * Added vid/pid for Videonetworks/Homechoice (UK ISP) 1141da177e4SLinus Torvalds * 1151da177e4SLinus Torvalds * (23/Feb/2003) Bill Ryder 1161da177e4SLinus Torvalds * Added matrix orb device vid/pids from Wayne Wylupski 1171da177e4SLinus Torvalds * 1181da177e4SLinus Torvalds * (19/Feb/2003) Ian Abbott 1191da177e4SLinus Torvalds * For TIOCSSERIAL, set alt_speed to 0 when ASYNC_SPD_MASK value has 1201da177e4SLinus Torvalds * changed to something other than ASYNC_SPD_HI, ASYNC_SPD_VHI, 1211da177e4SLinus Torvalds * ASYNC_SPD_SHI or ASYNC_SPD_WARP. Also, unless ASYNC_SPD_CUST is in 1221da177e4SLinus Torvalds * force, don't bother changing baud rate when custom_divisor has changed. 1231da177e4SLinus Torvalds * 1241da177e4SLinus Torvalds * (18/Feb/2003) Ian Abbott 1251da177e4SLinus Torvalds * Fixed TIOCMGET handling to include state of DTR and RTS, the state 1261da177e4SLinus Torvalds * of which are now saved by set_dtr() and set_rts(). 1271da177e4SLinus Torvalds * Fixed improper storage class for buf in set_dtr() and set_rts(). 1281da177e4SLinus Torvalds * Added FT232BM chip type and support for its extra baud rates (compared 1291da177e4SLinus Torvalds * to FT8U232AM). 1301da177e4SLinus Torvalds * Took account of special case divisor values for highest baud rates of 1311da177e4SLinus Torvalds * FT8U232AM and FT232BM. 1321da177e4SLinus Torvalds * For TIOCSSERIAL, forced alt_speed to 0 when ASYNC_SPD_CUST kludge used, 1331da177e4SLinus Torvalds * as previous alt_speed setting is now stale. 1341da177e4SLinus Torvalds * Moved startup code common between the startup routines for the 1351da177e4SLinus Torvalds * different chip types into a common subroutine. 1361da177e4SLinus Torvalds * 1371da177e4SLinus Torvalds * (17/Feb/2003) Bill Ryder 1381da177e4SLinus Torvalds * Added write urb buffer pool on a per device basis 1391da177e4SLinus Torvalds * Added more checking for open file on callbacks (fixed OOPS) 1401da177e4SLinus Torvalds * Added CrystalFontz 632 and 634 PIDs 1411da177e4SLinus Torvalds * (thanx to CrystalFontz for the sample devices - they flushed out 1421da177e4SLinus Torvalds * some driver bugs) 1431da177e4SLinus Torvalds * Minor debugging message changes 1441da177e4SLinus Torvalds * Added throttle, unthrottle and chars_in_buffer functions 1451da177e4SLinus Torvalds * Fixed FTDI_SIO (the original device) bug 1461da177e4SLinus Torvalds * Fixed some shutdown handling 1471da177e4SLinus Torvalds * 1481da177e4SLinus Torvalds * 1491da177e4SLinus Torvalds * 1501da177e4SLinus Torvalds * 1511da177e4SLinus Torvalds * (07/Jun/2002) Kuba Ober 1521da177e4SLinus Torvalds * Changed FTDI_SIO_BASE_BAUD_TO_DIVISOR macro into ftdi_baud_to_divisor 1531da177e4SLinus Torvalds * function. It was getting too complex. 1541da177e4SLinus Torvalds * Fix the divisor calculation logic which was setting divisor of 0.125 1551da177e4SLinus Torvalds * instead of 0.5 for fractional parts of divisor equal to 5/8, 6/8, 7/8. 1561da177e4SLinus Torvalds * Also make it bump up the divisor to next integer in case of 7/8 - it's 1571da177e4SLinus Torvalds * a better approximation. 1581da177e4SLinus Torvalds * 1591da177e4SLinus Torvalds * (25/Jul/2002) Bill Ryder inserted Dmitri's TIOCMIWAIT patch 1601da177e4SLinus Torvalds * Not tested by me but it doesn't break anything I use. 1611da177e4SLinus Torvalds * 1621da177e4SLinus Torvalds * (04/Jan/2002) Kuba Ober 1631da177e4SLinus Torvalds * Implemented 38400 baudrate kludge, where it can be substituted with other 1641da177e4SLinus Torvalds * values. That's the only way to set custom baudrates. 1651da177e4SLinus Torvalds * Implemented TIOCSSERIAL, TIOCGSERIAL ioctl's so that setserial is happy. 1661da177e4SLinus Torvalds * FIXME: both baudrate things should eventually go to usbserial.c as other 1671da177e4SLinus Torvalds * devices may need that functionality too. Actually, it can probably be 1681da177e4SLinus Torvalds * merged in serial.c somehow - too many drivers repeat this code over 1691da177e4SLinus Torvalds * and over. 1701da177e4SLinus Torvalds * Fixed baudrate forgetfulness - open() used to reset baudrate to 9600 every time. 1711da177e4SLinus Torvalds * Divisors for baudrates are calculated by a macro. 1721da177e4SLinus Torvalds * Small code cleanups. Ugly whitespace changes for Plato's sake only ;-]. 1731da177e4SLinus Torvalds * 1741da177e4SLinus Torvalds * (04/Nov/2001) Bill Ryder 1751da177e4SLinus Torvalds * Fixed bug in read_bulk_callback where incorrect urb buffer was used. 1761da177e4SLinus Torvalds * Cleaned up write offset calculation 1771da177e4SLinus Torvalds * Added write_room since default values can be incorrect for sio 1781da177e4SLinus Torvalds * Changed write_bulk_callback to use same queue_task as other drivers 1791da177e4SLinus Torvalds * (the previous version caused panics) 1801da177e4SLinus Torvalds * Removed port iteration code since the device only has one I/O port and it 1811da177e4SLinus Torvalds * was wrong anyway. 1821da177e4SLinus Torvalds * 1831da177e4SLinus Torvalds * (31/May/2001) gkh 1841da177e4SLinus Torvalds * Switched from using spinlock to a semaphore, which fixes lots of problems. 1851da177e4SLinus Torvalds * 1861da177e4SLinus Torvalds * (23/May/2001) Bill Ryder 1871da177e4SLinus Torvalds * Added runtime debug patch (thanx Tyson D Sawyer). 1881da177e4SLinus Torvalds * Cleaned up comments for 8U232 1891da177e4SLinus Torvalds * Added parity, framing and overrun error handling 1901da177e4SLinus Torvalds * Added receive break handling. 1911da177e4SLinus Torvalds * 1921da177e4SLinus Torvalds * (04/08/2001) gb 1931da177e4SLinus Torvalds * Identify version on module load. 1941da177e4SLinus Torvalds * 1951da177e4SLinus Torvalds * (18/March/2001) Bill Ryder 1961da177e4SLinus Torvalds * (Not released) 1971da177e4SLinus Torvalds * Added send break handling. (requires kernel patch too) 1981da177e4SLinus Torvalds * Fixed 8U232AM hardware RTS/CTS etc status reporting. 1991da177e4SLinus Torvalds * Added flipbuf fix copied from generic device 2001da177e4SLinus Torvalds * 2011da177e4SLinus Torvalds * (12/3/2000) Bill Ryder 2021da177e4SLinus Torvalds * Added support for 8U232AM device. 2031da177e4SLinus Torvalds * Moved PID and VIDs into header file only. 2041da177e4SLinus Torvalds * Turned on low-latency for the tty (device will do high baudrates) 2051da177e4SLinus Torvalds * Added shutdown routine to close files when device removed. 2061da177e4SLinus Torvalds * More debug and error message cleanups. 2071da177e4SLinus Torvalds * 2081da177e4SLinus Torvalds * (11/13/2000) Bill Ryder 2091da177e4SLinus Torvalds * Added spinlock protected open code and close code. 2101da177e4SLinus Torvalds * Multiple opens work (sort of - see webpage mentioned above). 2111da177e4SLinus Torvalds * Cleaned up comments. Removed multiple PID/VID definitions. 2121da177e4SLinus Torvalds * Factorised cts/dtr code 2131da177e4SLinus Torvalds * Made use of __FUNCTION__ in dbg's 2141da177e4SLinus Torvalds * 2151da177e4SLinus Torvalds * (11/01/2000) Adam J. Richter 2161da177e4SLinus Torvalds * usb_device_id table support 2171da177e4SLinus Torvalds * 2181da177e4SLinus Torvalds * (10/05/2000) gkh 2191da177e4SLinus Torvalds * Fixed bug with urb->dev not being set properly, now that the usb 2201da177e4SLinus Torvalds * core needs it. 2211da177e4SLinus Torvalds * 2221da177e4SLinus Torvalds * (09/11/2000) gkh 2231da177e4SLinus Torvalds * Removed DEBUG #ifdefs with call to usb_serial_debug_data 2241da177e4SLinus Torvalds * 2251da177e4SLinus Torvalds * (07/19/2000) gkh 2261da177e4SLinus Torvalds * Added module_init and module_exit functions to handle the fact that this 2271da177e4SLinus Torvalds * driver is a loadable module now. 2281da177e4SLinus Torvalds * 2291da177e4SLinus Torvalds * (04/04/2000) Bill Ryder 2301da177e4SLinus Torvalds * Fixed bugs in TCGET/TCSET ioctls (by removing them - they are 2311da177e4SLinus Torvalds * handled elsewhere in the tty io driver chain). 2321da177e4SLinus Torvalds * 2331da177e4SLinus Torvalds * (03/30/2000) Bill Ryder 2341da177e4SLinus Torvalds * Implemented lots of ioctls 2351da177e4SLinus Torvalds * Fixed a race condition in write 2361da177e4SLinus Torvalds * Changed some dbg's to errs 2371da177e4SLinus Torvalds * 2381da177e4SLinus Torvalds * (03/26/2000) gkh 2391da177e4SLinus Torvalds * Split driver up into device specific pieces. 2401da177e4SLinus Torvalds * 2411da177e4SLinus Torvalds */ 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds /* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */ 2441da177e4SLinus Torvalds /* Thanx to FTDI for so kindly providing details of the protocol required */ 2451da177e4SLinus Torvalds /* to talk to the device */ 2461da177e4SLinus Torvalds /* Thanx to gkh and the rest of the usb dev group for all code I have assimilated :-) */ 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds #include <linux/config.h> 2491da177e4SLinus Torvalds #include <linux/kernel.h> 2501da177e4SLinus Torvalds #include <linux/errno.h> 2511da177e4SLinus Torvalds #include <linux/init.h> 2521da177e4SLinus Torvalds #include <linux/slab.h> 2531da177e4SLinus Torvalds #include <linux/tty.h> 2541da177e4SLinus Torvalds #include <linux/tty_driver.h> 2551da177e4SLinus Torvalds #include <linux/tty_flip.h> 2561da177e4SLinus Torvalds #include <linux/module.h> 2571da177e4SLinus Torvalds #include <linux/spinlock.h> 2581da177e4SLinus Torvalds #include <asm/uaccess.h> 2591da177e4SLinus Torvalds #include <linux/usb.h> 2601da177e4SLinus Torvalds #include <linux/serial.h> 2611da177e4SLinus Torvalds #include "usb-serial.h" 2621da177e4SLinus Torvalds #include "ftdi_sio.h" 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds /* 2651da177e4SLinus Torvalds * Version Information 2661da177e4SLinus Torvalds */ 2678f977e42SIan Abbott #define DRIVER_VERSION "v1.4.3" 2681da177e4SLinus Torvalds #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>" 2691da177e4SLinus Torvalds #define DRIVER_DESC "USB FTDI Serial Converters Driver" 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds static int debug; 272fdcb0a0fSIan Abbott static __u16 vendor = FTDI_VID; 273fdcb0a0fSIan Abbott static __u16 product; 2741da177e4SLinus Torvalds 2758f977e42SIan Abbott /* struct ftdi_sio_quirk is used by devices requiring special attention. */ 2768f977e42SIan Abbott struct ftdi_sio_quirk { 2778f977e42SIan Abbott void (*setup)(struct usb_serial *); /* Special settings during startup. */ 2788f977e42SIan Abbott }; 2798f977e42SIan Abbott 2808f977e42SIan Abbott static void ftdi_USB_UIRT_setup (struct usb_serial *serial); 2818f977e42SIan Abbott static void ftdi_HE_TIRA1_setup (struct usb_serial *serial); 2828f977e42SIan Abbott 2838f977e42SIan Abbott static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = { 2848f977e42SIan Abbott .setup = ftdi_USB_UIRT_setup, 2858f977e42SIan Abbott }; 2868f977e42SIan Abbott 2878f977e42SIan Abbott static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = { 2888f977e42SIan Abbott .setup = ftdi_HE_TIRA1_setup, 2891da177e4SLinus Torvalds }; 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds /* 2921da177e4SLinus Torvalds * The 8U232AM has the same API as the sio except for: 2931da177e4SLinus Torvalds * - it can support MUCH higher baudrates; up to: 2941da177e4SLinus Torvalds * o 921600 for RS232 and 2000000 for RS422/485 at 48MHz 2951da177e4SLinus Torvalds * o 230400 at 12MHz 2961da177e4SLinus Torvalds * so .. 8U232AM's baudrate setting codes are different 2971da177e4SLinus Torvalds * - it has a two byte status code. 2981da177e4SLinus Torvalds * - it returns characters every 16ms (the FTDI does it every 40ms) 2991da177e4SLinus Torvalds * 3001da177e4SLinus Torvalds * the bcdDevice value is used to differentiate FT232BM and FT245BM from 3011da177e4SLinus Torvalds * the earlier FT8U232AM and FT8U232BM. For now, include all known VID/PID 3021da177e4SLinus Torvalds * combinations in both tables. 3038f977e42SIan Abbott * FIXME: perhaps bcdDevice can also identify 12MHz FT8U232AM devices, 3048f977e42SIan Abbott * but I don't know if those ever went into mass production. [Ian Abbott] 3051da177e4SLinus Torvalds */ 3061da177e4SLinus Torvalds 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds static struct usb_device_id id_table_combined [] = { 31072a9f958SRazvan Gavril { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) }, 3111da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, 31269737dfaSLuiz Fernando N. Capitulino { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) }, 3131da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) }, 3141da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) }, 3151da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) }, 3161da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) }, 3171da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, 3181da177e4SLinus Torvalds { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, 3191da177e4SLinus Torvalds { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, 3201da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_632_PID) }, 3211da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_634_PID) }, 3221da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_547_PID) }, 3231da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_633_PID) }, 3241da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_631_PID) }, 3251da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_635_PID) }, 3261da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_640_PID) }, 3271da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_XF_642_PID) }, 3281da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) }, 3291da177e4SLinus Torvalds { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) }, 3301da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) }, 3318f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MTXORB_0_PID) }, 3328f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MTXORB_1_PID) }, 3338f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MTXORB_2_PID) }, 3348f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MTXORB_3_PID) }, 3358f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) }, 3368f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) }, 3378f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) }, 3388f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, 3391da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 3401da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) }, 3411da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, 3421da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) }, 3431da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) }, 3441da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) }, 3451da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) }, 3461da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) }, 3471da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_2_PID) }, 3481da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_1_PID) }, 3491da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2203_2_PID) }, 3501da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_1_PID) }, 3511da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_2_PID) }, 3521da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_3_PID) }, 3531da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2401_4_PID) }, 3541da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_1_PID) }, 3551da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_2_PID) }, 3561da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_3_PID) }, 3571da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2402_4_PID) }, 3581da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_1_PID) }, 3591da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_2_PID) }, 3601da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_3_PID) }, 3611da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2403_4_PID) }, 3621da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_1_PID) }, 3631da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_2_PID) }, 3641da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_3_PID) }, 3651da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_4_PID) }, 3661da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_5_PID) }, 3671da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_6_PID) }, 3681da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_7_PID) }, 3691da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2801_8_PID) }, 3701da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_1_PID) }, 3711da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_2_PID) }, 3721da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_3_PID) }, 3731da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_4_PID) }, 3741da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_5_PID) }, 3751da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_6_PID) }, 3761da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_7_PID) }, 3771da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2802_8_PID) }, 3781da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_1_PID) }, 3791da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_2_PID) }, 3801da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_3_PID) }, 3811da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_4_PID) }, 3821da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_5_PID) }, 3831da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_6_PID) }, 3841da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_7_PID) }, 3851da177e4SLinus Torvalds { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) }, 3861da177e4SLinus Torvalds { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) }, 3871da177e4SLinus Torvalds { USB_DEVICE(OCT_VID, OCT_US101_PID) }, 3888f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID), 3898f977e42SIan Abbott .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk }, 3908f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID), 3918f977e42SIan Abbott .driver_info = (kernel_ulong_t)&ftdi_USB_UIRT_quirk }, 3921da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) }, 3931da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, PROTEGO_R2X0) }, 3941da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) }, 3951da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) }, 3968f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E808_PID) }, 3978f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E809_PID) }, 3988f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80A_PID) }, 3998f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80B_PID) }, 4008f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80C_PID) }, 4018f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80D_PID) }, 4028f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80E_PID) }, 4038f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80F_PID) }, 4048f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E888_PID) }, 4058f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E889_PID) }, 4068f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88A_PID) }, 4078f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88B_PID) }, 4088f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88C_PID) }, 4098f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88D_PID) }, 4108f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88E_PID) }, 4118f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) }, 4121da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) }, 41347900743SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) }, 414e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_ELV_UR100_PID) }, 415e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) }, 416207c47e1SThomas Riewe { USB_DEVICE(FTDI_VID, FTDI_PYRAMID_PID) }, 417bde62185SMartin Hagelin { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) }, 418e6ac4a40SIan Abbott /* 419e6ac4a40SIan Abbott * These will probably use user-space drivers. Uncomment them if 420e6ac4a40SIan Abbott * you need them or use the user-specified vendor/product module 421e6ac4a40SIan Abbott * parameters (see ftdi_sio.h for the numbers). Make a fuss if 422e6ac4a40SIan Abbott * you think the driver should recognize any of them by default. 423e6ac4a40SIan Abbott */ 424e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) }, */ 425e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) }, */ 426e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) }, */ 427e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) }, */ 428e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) }, */ 429e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) }, */ 430e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) }, */ 431e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) }, */ 432e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, */ 433e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, */ 434e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, */ 435e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, */ 436e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, */ 437e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, */ 438e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) }, */ 439e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) }, */ 440e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, */ 441e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) }, */ 442e6ac4a40SIan Abbott /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, */ 4438f977e42SIan Abbott { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) }, 4448f977e42SIan Abbott { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) }, 4458f977e42SIan Abbott { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) }, 4468f977e42SIan Abbott { USB_DEVICE(FTDI_VID, LINX_FUTURE_1_PID) }, 4478f977e42SIan Abbott { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) }, 4481da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) }, 4491da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) }, 4501da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) }, 4511da177e4SLinus Torvalds { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) }, 4521da177e4SLinus Torvalds { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) }, 4531da177e4SLinus Torvalds { USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) }, 454e6ac4a40SIan Abbott { USB_DEVICE(FALCOM_VID, FALCOM_SAMBA_PID) }, 4551da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) }, 4566f92872cSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) }, 4571da177e4SLinus Torvalds { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) }, 4581da177e4SLinus Torvalds { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) }, 4591da177e4SLinus Torvalds { USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) }, 4601da177e4SLinus Torvalds { USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) }, 4616f92872cSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_0_PID) }, 4626f92872cSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) }, 4636f92872cSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) }, 464e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_0_PID) }, 465e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_1_PID) }, 466e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_2_PID) }, 467e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_3_PID) }, 468e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_4_PID) }, 469e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_5_PID) }, 470e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_6_PID) }, 471e6ac4a40SIan Abbott { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_7_PID) }, 4726f92872cSIan Abbott { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) }, 4738f977e42SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) }, 47434d1a8aaSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_KW_PID) }, 47534d1a8aaSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_YS_PID) }, 4769b1513d9SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) }, 4779b1513d9SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) }, 47834d1a8aaSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_IC_PID) }, 47934d1a8aaSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_DB9_PID) }, 48034d1a8aaSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_RS232_PID) }, 48134d1a8aaSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y9_PID) }, 482740a4282SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_VCP_PID) }, 483740a4282SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_TERATRONIK_D2XX_PID) }, 4849b1513d9SIan Abbott { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) }, 485c9c7746dSRui Santos { USB_DEVICE(FTDI_VID, FTDI_ARTEMIS_PID) }, 486c9c7746dSRui Santos { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16_PID) }, 48709c280a2SRui Santos { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) }, 488c9c7746dSRui Santos { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) }, 48909c280a2SRui Santos { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) }, 490b4723ae3SIan Abbott { USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) }, 491b4723ae3SIan Abbott { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) }, 492effac8beSPavel Fedin { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) }, 493641adaaeSLouis Nyffenegger { USB_DEVICE(FTDI_VID, FTDI_TTUSB_PID) }, 4947e1c0b86SIan Abbott { USB_DEVICE(FTDI_VID, FTDI_ECLO_COM_1WIRE_PID) }, 495a94b52acSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) }, 496a94b52acSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) }, 497ce40d290SWouter Paesen { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) }, 498cdd3b156SNathan Bronson { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) }, 4997e0258fdSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) }, 500bf58fbd5SA. Maitland Bottoms { USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) }, 50162a13db3SFolkert van Heusden { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) }, 50220a0f47eSIan Abbott { USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) }, 503fdcb0a0fSIan Abbott { }, /* Optional parameter entry */ 5041da177e4SLinus Torvalds { } /* Terminating entry */ 5051da177e4SLinus Torvalds }; 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds MODULE_DEVICE_TABLE (usb, id_table_combined); 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds static struct usb_driver ftdi_driver = { 5101da177e4SLinus Torvalds .name = "ftdi_sio", 5111da177e4SLinus Torvalds .probe = usb_serial_probe, 5121da177e4SLinus Torvalds .disconnect = usb_serial_disconnect, 5131da177e4SLinus Torvalds .id_table = id_table_combined, 514ba9dc657SGreg Kroah-Hartman .no_dynamic_id = 1, 5151da177e4SLinus Torvalds }; 5161da177e4SLinus Torvalds 5174c4c9432SArjan van de Ven static const char *ftdi_chip_name[] = { 5181da177e4SLinus Torvalds [SIO] = "SIO", /* the serial part of FT8U100AX */ 5191da177e4SLinus Torvalds [FT8U232AM] = "FT8U232AM", 5201da177e4SLinus Torvalds [FT232BM] = "FT232BM", 5211da177e4SLinus Torvalds [FT2232C] = "FT2232C", 5221da177e4SLinus Torvalds }; 5231da177e4SLinus Torvalds 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds /* Constants for read urb and write urb */ 5261da177e4SLinus Torvalds #define BUFSZ 512 5271da177e4SLinus Torvalds #define PKTSZ 64 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds /* rx_flags */ 5301da177e4SLinus Torvalds #define THROTTLED 0x01 5311da177e4SLinus Torvalds #define ACTUALLY_THROTTLED 0x02 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds struct ftdi_private { 5341da177e4SLinus Torvalds ftdi_chip_type_t chip_type; 5351da177e4SLinus Torvalds /* type of the device, either SIO or FT8U232AM */ 5361da177e4SLinus Torvalds int baud_base; /* baud base clock for divisor setting */ 5371da177e4SLinus Torvalds int custom_divisor; /* custom_divisor kludge, this is for baud_base (different from what goes to the chip!) */ 5381da177e4SLinus Torvalds __u16 last_set_data_urb_value ; 5391da177e4SLinus Torvalds /* the last data state set - needed for doing a break */ 5401da177e4SLinus Torvalds int write_offset; /* This is the offset in the usb data block to write the serial data - 5411da177e4SLinus Torvalds * it is different between devices 5421da177e4SLinus Torvalds */ 5431da177e4SLinus Torvalds int flags; /* some ASYNC_xxxx flags are supported */ 5441da177e4SLinus Torvalds unsigned long last_dtr_rts; /* saved modem control outputs */ 5451da177e4SLinus Torvalds wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 5461da177e4SLinus Torvalds char prev_status, diff_status; /* Used for TIOCMIWAIT */ 5471da177e4SLinus Torvalds __u8 rx_flags; /* receive state flags (throttling) */ 5481da177e4SLinus Torvalds spinlock_t rx_lock; /* spinlock for receive state */ 54976854ceaSIan Abbott struct work_struct rx_work; 55076854ceaSIan Abbott int rx_processed; 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds __u16 interface; /* FT2232C port interface (0 for FT232/245) */ 5531da177e4SLinus Torvalds 5541da177e4SLinus Torvalds int force_baud; /* if non-zero, force the baud rate to this value */ 5551da177e4SLinus Torvalds int force_rtscts; /* if non-zero, force RTS-CTS to always be enabled */ 5561da177e4SLinus Torvalds }; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds /* Used for TIOCMIWAIT */ 5591da177e4SLinus Torvalds #define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD) 5601da177e4SLinus Torvalds #define FTDI_STATUS_B1_MASK (FTDI_RS_BI) 5611da177e4SLinus Torvalds /* End TIOCMIWAIT */ 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds #define FTDI_IMPL_ASYNC_FLAGS = ( ASYNC_SPD_HI | ASYNC_SPD_VHI \ 5641da177e4SLinus Torvalds ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP ) 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds /* function prototypes for a FTDI serial converter */ 5678f977e42SIan Abbott static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id); 5688f977e42SIan Abbott static int ftdi_sio_attach (struct usb_serial *serial); 5691da177e4SLinus Torvalds static void ftdi_shutdown (struct usb_serial *serial); 5701da177e4SLinus Torvalds static int ftdi_open (struct usb_serial_port *port, struct file *filp); 5711da177e4SLinus Torvalds static void ftdi_close (struct usb_serial_port *port, struct file *filp); 5721da177e4SLinus Torvalds static int ftdi_write (struct usb_serial_port *port, const unsigned char *buf, int count); 5731da177e4SLinus Torvalds static int ftdi_write_room (struct usb_serial_port *port); 5741da177e4SLinus Torvalds static int ftdi_chars_in_buffer (struct usb_serial_port *port); 5751da177e4SLinus Torvalds static void ftdi_write_bulk_callback (struct urb *urb, struct pt_regs *regs); 5761da177e4SLinus Torvalds static void ftdi_read_bulk_callback (struct urb *urb, struct pt_regs *regs); 57776854ceaSIan Abbott static void ftdi_process_read (void *param); 5781da177e4SLinus Torvalds static void ftdi_set_termios (struct usb_serial_port *port, struct termios * old); 5791da177e4SLinus Torvalds static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file); 5801da177e4SLinus Torvalds static int ftdi_tiocmset (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear); 5811da177e4SLinus Torvalds static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 5821da177e4SLinus Torvalds static void ftdi_break_ctl (struct usb_serial_port *port, int break_state ); 5831da177e4SLinus Torvalds static void ftdi_throttle (struct usb_serial_port *port); 5841da177e4SLinus Torvalds static void ftdi_unthrottle (struct usb_serial_port *port); 5851da177e4SLinus Torvalds 5861da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_base_to_divisor (int baud, int base); 5871da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_to_divisor (int baud); 5881da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base); 5891da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_to_divisor (int baud); 5901da177e4SLinus Torvalds 591ea65370dSGreg Kroah-Hartman static struct usb_serial_driver ftdi_sio_device = { 59218fcac35SGreg Kroah-Hartman .driver = { 5931da177e4SLinus Torvalds .owner = THIS_MODULE, 594269bda1cSGreg Kroah-Hartman .name = "ftdi_sio", 59518fcac35SGreg Kroah-Hartman }, 596269bda1cSGreg Kroah-Hartman .description = "FTDI USB Serial Device", 5978f977e42SIan Abbott .id_table = id_table_combined, 5981da177e4SLinus Torvalds .num_interrupt_in = 0, 5991da177e4SLinus Torvalds .num_bulk_in = 1, 6001da177e4SLinus Torvalds .num_bulk_out = 1, 6011da177e4SLinus Torvalds .num_ports = 1, 6028f977e42SIan Abbott .probe = ftdi_sio_probe, 6031da177e4SLinus Torvalds .open = ftdi_open, 6041da177e4SLinus Torvalds .close = ftdi_close, 6051da177e4SLinus Torvalds .throttle = ftdi_throttle, 6061da177e4SLinus Torvalds .unthrottle = ftdi_unthrottle, 6071da177e4SLinus Torvalds .write = ftdi_write, 6081da177e4SLinus Torvalds .write_room = ftdi_write_room, 6091da177e4SLinus Torvalds .chars_in_buffer = ftdi_chars_in_buffer, 6101da177e4SLinus Torvalds .read_bulk_callback = ftdi_read_bulk_callback, 6111da177e4SLinus Torvalds .write_bulk_callback = ftdi_write_bulk_callback, 6121da177e4SLinus Torvalds .tiocmget = ftdi_tiocmget, 6131da177e4SLinus Torvalds .tiocmset = ftdi_tiocmset, 6141da177e4SLinus Torvalds .ioctl = ftdi_ioctl, 6151da177e4SLinus Torvalds .set_termios = ftdi_set_termios, 6161da177e4SLinus Torvalds .break_ctl = ftdi_break_ctl, 6178f977e42SIan Abbott .attach = ftdi_sio_attach, 6181da177e4SLinus Torvalds .shutdown = ftdi_shutdown, 6191da177e4SLinus Torvalds }; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds #define WDR_TIMEOUT 5000 /* default urb timeout */ 623279e1545SIan Abbott #define WDR_SHORT_TIMEOUT 1000 /* shorter urb timeout */ 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds /* High and low are for DTR, RTS etc etc */ 6261da177e4SLinus Torvalds #define HIGH 1 6271da177e4SLinus Torvalds #define LOW 0 6281da177e4SLinus Torvalds 6291da177e4SLinus Torvalds /* 6301da177e4SLinus Torvalds * *************************************************************************** 6311da177e4SLinus Torvalds * Utlity functions 6321da177e4SLinus Torvalds * *************************************************************************** 6331da177e4SLinus Torvalds */ 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base) 6361da177e4SLinus Torvalds { 6371da177e4SLinus Torvalds unsigned short int divisor; 6381da177e4SLinus Torvalds int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left 6391da177e4SLinus Torvalds if ((divisor3 & 0x7) == 7) divisor3 ++; // round x.7/8 up to x+1 6401da177e4SLinus Torvalds divisor = divisor3 >> 3; 6411da177e4SLinus Torvalds divisor3 &= 0x7; 6421da177e4SLinus Torvalds if (divisor3 == 1) divisor |= 0xc000; else // 0.125 6431da177e4SLinus Torvalds if (divisor3 >= 4) divisor |= 0x4000; else // 0.5 6441da177e4SLinus Torvalds if (divisor3 != 0) divisor |= 0x8000; // 0.25 6451da177e4SLinus Torvalds if (divisor == 1) divisor = 0; /* special case for maximum baud rate */ 6461da177e4SLinus Torvalds return divisor; 6471da177e4SLinus Torvalds } 6481da177e4SLinus Torvalds 6491da177e4SLinus Torvalds static unsigned short int ftdi_232am_baud_to_divisor(int baud) 6501da177e4SLinus Torvalds { 6511da177e4SLinus Torvalds return(ftdi_232am_baud_base_to_divisor(baud, 48000000)); 6521da177e4SLinus Torvalds } 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base) 6551da177e4SLinus Torvalds { 6561da177e4SLinus Torvalds static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 }; 6571da177e4SLinus Torvalds __u32 divisor; 6581da177e4SLinus Torvalds int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left 6591da177e4SLinus Torvalds divisor = divisor3 >> 3; 6601da177e4SLinus Torvalds divisor |= (__u32)divfrac[divisor3 & 0x7] << 14; 6611da177e4SLinus Torvalds /* Deal with special cases for highest baud rates. */ 6621da177e4SLinus Torvalds if (divisor == 1) divisor = 0; else // 1.0 6631da177e4SLinus Torvalds if (divisor == 0x4001) divisor = 1; // 1.5 6641da177e4SLinus Torvalds return divisor; 6651da177e4SLinus Torvalds } 6661da177e4SLinus Torvalds 6671da177e4SLinus Torvalds static __u32 ftdi_232bm_baud_to_divisor(int baud) 6681da177e4SLinus Torvalds { 6691da177e4SLinus Torvalds return(ftdi_232bm_baud_base_to_divisor(baud, 48000000)); 6701da177e4SLinus Torvalds } 6711da177e4SLinus Torvalds 67274ede0ffSIan Abbott #define set_mctrl(port, set) update_mctrl((port), (set), 0) 67374ede0ffSIan Abbott #define clear_mctrl(port, clear) update_mctrl((port), 0, (clear)) 67474ede0ffSIan Abbott 67574ede0ffSIan Abbott static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned int clear) 6761da177e4SLinus Torvalds { 6771da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 6781da177e4SLinus Torvalds char *buf; 67974ede0ffSIan Abbott unsigned urb_value; 6801da177e4SLinus Torvalds int rv; 6811da177e4SLinus Torvalds 68274ede0ffSIan Abbott if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) { 68374ede0ffSIan Abbott dbg("%s - DTR|RTS not being set|cleared", __FUNCTION__); 68474ede0ffSIan Abbott return 0; /* no change */ 6851da177e4SLinus Torvalds } 68674ede0ffSIan Abbott 68774ede0ffSIan Abbott buf = kmalloc(1, GFP_NOIO); 68874ede0ffSIan Abbott if (!buf) { 68974ede0ffSIan Abbott return -ENOMEM; 69074ede0ffSIan Abbott } 69174ede0ffSIan Abbott 69274ede0ffSIan Abbott clear &= ~set; /* 'set' takes precedence over 'clear' */ 69374ede0ffSIan Abbott urb_value = 0; 69474ede0ffSIan Abbott if (clear & TIOCM_DTR) 69574ede0ffSIan Abbott urb_value |= FTDI_SIO_SET_DTR_LOW; 69674ede0ffSIan Abbott if (clear & TIOCM_RTS) 69774ede0ffSIan Abbott urb_value |= FTDI_SIO_SET_RTS_LOW; 69874ede0ffSIan Abbott if (set & TIOCM_DTR) 69974ede0ffSIan Abbott urb_value |= FTDI_SIO_SET_DTR_HIGH; 70074ede0ffSIan Abbott if (set & TIOCM_RTS) 70174ede0ffSIan Abbott urb_value |= FTDI_SIO_SET_RTS_HIGH; 7021da177e4SLinus Torvalds rv = usb_control_msg(port->serial->dev, 7031da177e4SLinus Torvalds usb_sndctrlpipe(port->serial->dev, 0), 7041da177e4SLinus Torvalds FTDI_SIO_SET_MODEM_CTRL_REQUEST, 7051da177e4SLinus Torvalds FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE, 70674ede0ffSIan Abbott urb_value, priv->interface, 7071da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT); 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds kfree(buf); 71074ede0ffSIan Abbott if (rv < 0) { 71174ede0ffSIan Abbott err("%s Error from MODEM_CTRL urb: DTR %s, RTS %s", 71274ede0ffSIan Abbott __FUNCTION__, 71374ede0ffSIan Abbott (set & TIOCM_DTR) ? "HIGH" : 71474ede0ffSIan Abbott (clear & TIOCM_DTR) ? "LOW" : "unchanged", 71574ede0ffSIan Abbott (set & TIOCM_RTS) ? "HIGH" : 71674ede0ffSIan Abbott (clear & TIOCM_RTS) ? "LOW" : "unchanged"); 7171da177e4SLinus Torvalds } else { 71874ede0ffSIan Abbott dbg("%s - DTR %s, RTS %s", __FUNCTION__, 71974ede0ffSIan Abbott (set & TIOCM_DTR) ? "HIGH" : 72074ede0ffSIan Abbott (clear & TIOCM_DTR) ? "LOW" : "unchanged", 72174ede0ffSIan Abbott (set & TIOCM_RTS) ? "HIGH" : 72274ede0ffSIan Abbott (clear & TIOCM_RTS) ? "LOW" : "unchanged"); 72374ede0ffSIan Abbott priv->last_dtr_rts = (priv->last_dtr_rts & ~clear) | set; 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds return rv; 7261da177e4SLinus Torvalds } 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds static __u32 get_ftdi_divisor(struct usb_serial_port * port); 7301da177e4SLinus Torvalds 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds static int change_speed(struct usb_serial_port *port) 7331da177e4SLinus Torvalds { 7341da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 7351da177e4SLinus Torvalds char *buf; 7361da177e4SLinus Torvalds __u16 urb_value; 7371da177e4SLinus Torvalds __u16 urb_index; 7381da177e4SLinus Torvalds __u32 urb_index_value; 7391da177e4SLinus Torvalds int rv; 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds buf = kmalloc(1, GFP_NOIO); 7421da177e4SLinus Torvalds if (!buf) 7431da177e4SLinus Torvalds return -ENOMEM; 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds urb_index_value = get_ftdi_divisor(port); 7461da177e4SLinus Torvalds urb_value = (__u16)urb_index_value; 7471da177e4SLinus Torvalds urb_index = (__u16)(urb_index_value >> 16); 7481da177e4SLinus Torvalds if (priv->interface) { /* FT2232C */ 7491da177e4SLinus Torvalds urb_index = (__u16)((urb_index << 8) | priv->interface); 7501da177e4SLinus Torvalds } 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds rv = usb_control_msg(port->serial->dev, 7531da177e4SLinus Torvalds usb_sndctrlpipe(port->serial->dev, 0), 7541da177e4SLinus Torvalds FTDI_SIO_SET_BAUDRATE_REQUEST, 7551da177e4SLinus Torvalds FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE, 7561da177e4SLinus Torvalds urb_value, urb_index, 757279e1545SIan Abbott buf, 0, WDR_SHORT_TIMEOUT); 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds kfree(buf); 7601da177e4SLinus Torvalds return rv; 7611da177e4SLinus Torvalds } 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds static __u32 get_ftdi_divisor(struct usb_serial_port * port) 7651da177e4SLinus Torvalds { /* get_ftdi_divisor */ 7661da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 7671da177e4SLinus Torvalds __u32 div_value = 0; 7681da177e4SLinus Torvalds int div_okay = 1; 7691da177e4SLinus Torvalds int baud; 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds /* 7721da177e4SLinus Torvalds * The logic involved in setting the baudrate can be cleanly split in 3 steps. 7731da177e4SLinus Torvalds * Obtaining the actual baud rate is a little tricky since unix traditionally 7741da177e4SLinus Torvalds * somehow ignored the possibility to set non-standard baud rates. 7751da177e4SLinus Torvalds * 1. Standard baud rates are set in tty->termios->c_cflag 7761da177e4SLinus Torvalds * 2. If these are not enough, you can set any speed using alt_speed as follows: 7771da177e4SLinus Torvalds * - set tty->termios->c_cflag speed to B38400 7781da177e4SLinus Torvalds * - set your real speed in tty->alt_speed; it gets ignored when 7791da177e4SLinus Torvalds * alt_speed==0, (or) 7801da177e4SLinus Torvalds * - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows: 7811da177e4SLinus Torvalds * flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP], this just 7821da177e4SLinus Torvalds * sets alt_speed to (HI: 57600, VHI: 115200, SHI: 230400, WARP: 460800) 7831da177e4SLinus Torvalds * ** Steps 1, 2 are done courtesy of tty_get_baud_rate 7841da177e4SLinus Torvalds * 3. You can also set baud rate by setting custom divisor as follows 7851da177e4SLinus Torvalds * - set tty->termios->c_cflag speed to B38400 7861da177e4SLinus Torvalds * - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows: 7871da177e4SLinus Torvalds * o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST 7881da177e4SLinus Torvalds * o custom_divisor set to baud_base / your_new_baudrate 7891da177e4SLinus Torvalds * ** Step 3 is done courtesy of code borrowed from serial.c - I should really 7901da177e4SLinus Torvalds * spend some time and separate+move this common code to serial.c, it is 7911da177e4SLinus Torvalds * replicated in nearly every serial driver you see. 7921da177e4SLinus Torvalds */ 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds /* 1. Get the baud rate from the tty settings, this observes alt_speed hack */ 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds baud = tty_get_baud_rate(port->tty); 7971da177e4SLinus Torvalds dbg("%s - tty_get_baud_rate reports speed %d", __FUNCTION__, baud); 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds /* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */ 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds if (baud == 38400 && 8021da177e4SLinus Torvalds ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 8031da177e4SLinus Torvalds (priv->custom_divisor)) { 8041da177e4SLinus Torvalds baud = priv->baud_base / priv->custom_divisor; 8051da177e4SLinus Torvalds dbg("%s - custom divisor %d sets baud rate to %d", __FUNCTION__, priv->custom_divisor, baud); 8061da177e4SLinus Torvalds } 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds /* 3. Convert baudrate to device-specific divisor */ 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds if (!baud) baud = 9600; 8111da177e4SLinus Torvalds switch(priv->chip_type) { 8121da177e4SLinus Torvalds case SIO: /* SIO chip */ 8131da177e4SLinus Torvalds switch(baud) { 8141da177e4SLinus Torvalds case 300: div_value = ftdi_sio_b300; break; 8151da177e4SLinus Torvalds case 600: div_value = ftdi_sio_b600; break; 8161da177e4SLinus Torvalds case 1200: div_value = ftdi_sio_b1200; break; 8171da177e4SLinus Torvalds case 2400: div_value = ftdi_sio_b2400; break; 8181da177e4SLinus Torvalds case 4800: div_value = ftdi_sio_b4800; break; 8191da177e4SLinus Torvalds case 9600: div_value = ftdi_sio_b9600; break; 8201da177e4SLinus Torvalds case 19200: div_value = ftdi_sio_b19200; break; 8211da177e4SLinus Torvalds case 38400: div_value = ftdi_sio_b38400; break; 8221da177e4SLinus Torvalds case 57600: div_value = ftdi_sio_b57600; break; 8231da177e4SLinus Torvalds case 115200: div_value = ftdi_sio_b115200; break; 8241da177e4SLinus Torvalds } /* baud */ 8251da177e4SLinus Torvalds if (div_value == 0) { 8261da177e4SLinus Torvalds dbg("%s - Baudrate (%d) requested is not supported", __FUNCTION__, baud); 8271da177e4SLinus Torvalds div_value = ftdi_sio_b9600; 8281da177e4SLinus Torvalds div_okay = 0; 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds break; 8311da177e4SLinus Torvalds case FT8U232AM: /* 8U232AM chip */ 8321da177e4SLinus Torvalds if (baud <= 3000000) { 8331da177e4SLinus Torvalds div_value = ftdi_232am_baud_to_divisor(baud); 8341da177e4SLinus Torvalds } else { 8351da177e4SLinus Torvalds dbg("%s - Baud rate too high!", __FUNCTION__); 8361da177e4SLinus Torvalds div_value = ftdi_232am_baud_to_divisor(9600); 8371da177e4SLinus Torvalds div_okay = 0; 8381da177e4SLinus Torvalds } 8391da177e4SLinus Torvalds break; 8401da177e4SLinus Torvalds case FT232BM: /* FT232BM chip */ 8411da177e4SLinus Torvalds case FT2232C: /* FT2232C chip */ 8421da177e4SLinus Torvalds if (baud <= 3000000) { 8431da177e4SLinus Torvalds div_value = ftdi_232bm_baud_to_divisor(baud); 8441da177e4SLinus Torvalds } else { 8451da177e4SLinus Torvalds dbg("%s - Baud rate too high!", __FUNCTION__); 8461da177e4SLinus Torvalds div_value = ftdi_232bm_baud_to_divisor(9600); 8471da177e4SLinus Torvalds div_okay = 0; 8481da177e4SLinus Torvalds } 8491da177e4SLinus Torvalds break; 8501da177e4SLinus Torvalds } /* priv->chip_type */ 8511da177e4SLinus Torvalds 8521da177e4SLinus Torvalds if (div_okay) { 8531da177e4SLinus Torvalds dbg("%s - Baud rate set to %d (divisor 0x%lX) on chip %s", 8541da177e4SLinus Torvalds __FUNCTION__, baud, (unsigned long)div_value, 8551da177e4SLinus Torvalds ftdi_chip_name[priv->chip_type]); 8561da177e4SLinus Torvalds } 8571da177e4SLinus Torvalds 8581da177e4SLinus Torvalds return(div_value); 8591da177e4SLinus Torvalds } 8601da177e4SLinus Torvalds 8611da177e4SLinus Torvalds 8621da177e4SLinus Torvalds static int get_serial_info(struct usb_serial_port * port, struct serial_struct __user * retinfo) 8631da177e4SLinus Torvalds { 8641da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 8651da177e4SLinus Torvalds struct serial_struct tmp; 8661da177e4SLinus Torvalds 8671da177e4SLinus Torvalds if (!retinfo) 8681da177e4SLinus Torvalds return -EFAULT; 8691da177e4SLinus Torvalds memset(&tmp, 0, sizeof(tmp)); 8701da177e4SLinus Torvalds tmp.flags = priv->flags; 8711da177e4SLinus Torvalds tmp.baud_base = priv->baud_base; 8721da177e4SLinus Torvalds tmp.custom_divisor = priv->custom_divisor; 8731da177e4SLinus Torvalds if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 8741da177e4SLinus Torvalds return -EFAULT; 8751da177e4SLinus Torvalds return 0; 8761da177e4SLinus Torvalds } /* get_serial_info */ 8771da177e4SLinus Torvalds 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds static int set_serial_info(struct usb_serial_port * port, struct serial_struct __user * newinfo) 8801da177e4SLinus Torvalds { /* set_serial_info */ 8811da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 8821da177e4SLinus Torvalds struct serial_struct new_serial; 8831da177e4SLinus Torvalds struct ftdi_private old_priv; 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) 8861da177e4SLinus Torvalds return -EFAULT; 8871da177e4SLinus Torvalds old_priv = * priv; 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvalds /* Do error checking and permission checking */ 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) { 8921da177e4SLinus Torvalds if (((new_serial.flags & ~ASYNC_USR_MASK) != 8931da177e4SLinus Torvalds (priv->flags & ~ASYNC_USR_MASK))) 8941da177e4SLinus Torvalds return -EPERM; 8951da177e4SLinus Torvalds priv->flags = ((priv->flags & ~ASYNC_USR_MASK) | 8961da177e4SLinus Torvalds (new_serial.flags & ASYNC_USR_MASK)); 8971da177e4SLinus Torvalds priv->custom_divisor = new_serial.custom_divisor; 8981da177e4SLinus Torvalds goto check_and_exit; 8991da177e4SLinus Torvalds } 9001da177e4SLinus Torvalds 9011da177e4SLinus Torvalds if ((new_serial.baud_base != priv->baud_base) && 9021da177e4SLinus Torvalds (new_serial.baud_base < 9600)) 9031da177e4SLinus Torvalds return -EINVAL; 9041da177e4SLinus Torvalds 9051da177e4SLinus Torvalds /* Make the changes - these are privileged changes! */ 9061da177e4SLinus Torvalds 9071da177e4SLinus Torvalds priv->flags = ((priv->flags & ~ASYNC_FLAGS) | 9081da177e4SLinus Torvalds (new_serial.flags & ASYNC_FLAGS)); 9091da177e4SLinus Torvalds priv->custom_divisor = new_serial.custom_divisor; 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 9121da177e4SLinus Torvalds 9131da177e4SLinus Torvalds check_and_exit: 9141da177e4SLinus Torvalds if ((old_priv.flags & ASYNC_SPD_MASK) != 9151da177e4SLinus Torvalds (priv->flags & ASYNC_SPD_MASK)) { 9161da177e4SLinus Torvalds if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 9171da177e4SLinus Torvalds port->tty->alt_speed = 57600; 9181da177e4SLinus Torvalds else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 9191da177e4SLinus Torvalds port->tty->alt_speed = 115200; 9201da177e4SLinus Torvalds else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 9211da177e4SLinus Torvalds port->tty->alt_speed = 230400; 9221da177e4SLinus Torvalds else if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 9231da177e4SLinus Torvalds port->tty->alt_speed = 460800; 9241da177e4SLinus Torvalds else 9251da177e4SLinus Torvalds port->tty->alt_speed = 0; 9261da177e4SLinus Torvalds } 9271da177e4SLinus Torvalds if (((old_priv.flags & ASYNC_SPD_MASK) != 9281da177e4SLinus Torvalds (priv->flags & ASYNC_SPD_MASK)) || 9291da177e4SLinus Torvalds (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 9301da177e4SLinus Torvalds (old_priv.custom_divisor != priv->custom_divisor))) { 9311da177e4SLinus Torvalds change_speed(port); 9321da177e4SLinus Torvalds } 9331da177e4SLinus Torvalds 9341da177e4SLinus Torvalds return (0); 9351da177e4SLinus Torvalds 9361da177e4SLinus Torvalds } /* set_serial_info */ 9371da177e4SLinus Torvalds 9381da177e4SLinus Torvalds 9398f977e42SIan Abbott /* Determine type of FTDI chip based on USB config and descriptor. */ 9408f977e42SIan Abbott static void ftdi_determine_type(struct usb_serial_port *port) 9418f977e42SIan Abbott { 9428f977e42SIan Abbott struct ftdi_private *priv = usb_get_serial_port_data(port); 9438f977e42SIan Abbott struct usb_serial *serial = port->serial; 9448f977e42SIan Abbott struct usb_device *udev = serial->dev; 9458f977e42SIan Abbott unsigned version; 9468f977e42SIan Abbott unsigned interfaces; 9478f977e42SIan Abbott 9488f977e42SIan Abbott /* Assume it is not the original SIO device for now. */ 949f5e09b7cSIan Abbott priv->baud_base = 48000000 / 2; 9508f977e42SIan Abbott priv->write_offset = 0; 9518f977e42SIan Abbott 9528f977e42SIan Abbott version = le16_to_cpu(udev->descriptor.bcdDevice); 9538f977e42SIan Abbott interfaces = udev->actconfig->desc.bNumInterfaces; 9548f977e42SIan Abbott dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __FUNCTION__, 9558f977e42SIan Abbott version, interfaces); 9568f977e42SIan Abbott if (interfaces > 1) { 9578f977e42SIan Abbott int inter; 9588f977e42SIan Abbott 9598f977e42SIan Abbott /* Multiple interfaces. Assume FT2232C. */ 9608f977e42SIan Abbott priv->chip_type = FT2232C; 9618f977e42SIan Abbott /* Determine interface code. */ 9628f977e42SIan Abbott inter = serial->interface->altsetting->desc.bInterfaceNumber; 9638f977e42SIan Abbott if (inter == 0) { 9648f977e42SIan Abbott priv->interface = PIT_SIOA; 9658f977e42SIan Abbott } else { 9668f977e42SIan Abbott priv->interface = PIT_SIOB; 9678f977e42SIan Abbott } 9688f977e42SIan Abbott /* BM-type devices have a bug where bcdDevice gets set 9698f977e42SIan Abbott * to 0x200 when iSerialNumber is 0. */ 9708f977e42SIan Abbott if (version < 0x500) { 9718f977e42SIan Abbott dbg("%s: something fishy - bcdDevice too low for multi-interface device", 9728f977e42SIan Abbott __FUNCTION__); 9738f977e42SIan Abbott } 9748f977e42SIan Abbott } else if (version < 0x200) { 9758f977e42SIan Abbott /* Old device. Assume its the original SIO. */ 9768f977e42SIan Abbott priv->chip_type = SIO; 9778f977e42SIan Abbott priv->baud_base = 12000000 / 16; 9788f977e42SIan Abbott priv->write_offset = 1; 9798f977e42SIan Abbott } else if (version < 0x400) { 9808f977e42SIan Abbott /* Assume its an FT8U232AM (or FT8U245AM) */ 9818f977e42SIan Abbott /* (It might be a BM because of the iSerialNumber bug, 9828f977e42SIan Abbott * but it will still work as an AM device.) */ 9838f977e42SIan Abbott priv->chip_type = FT8U232AM; 9848f977e42SIan Abbott } else { 9858f977e42SIan Abbott /* Assume its an FT232BM (or FT245BM) */ 9868f977e42SIan Abbott priv->chip_type = FT232BM; 9878f977e42SIan Abbott } 9888f977e42SIan Abbott info("Detected %s", ftdi_chip_name[priv->chip_type]); 9898f977e42SIan Abbott } 9908f977e42SIan Abbott 9918f977e42SIan Abbott 9921da177e4SLinus Torvalds /* 9931da177e4SLinus Torvalds * *************************************************************************** 9941da177e4SLinus Torvalds * Sysfs Attribute 9951da177e4SLinus Torvalds * *************************************************************************** 9961da177e4SLinus Torvalds */ 9971da177e4SLinus Torvalds 998060b8845SYani Ioannou static ssize_t show_latency_timer(struct device *dev, struct device_attribute *attr, char *buf) 9991da177e4SLinus Torvalds { 10001da177e4SLinus Torvalds struct usb_serial_port *port = to_usb_serial_port(dev); 10011da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 10021da177e4SLinus Torvalds struct usb_device *udev; 10031da177e4SLinus Torvalds unsigned short latency = 0; 10041da177e4SLinus Torvalds int rv = 0; 10051da177e4SLinus Torvalds 10061da177e4SLinus Torvalds udev = to_usb_device(dev); 10071da177e4SLinus Torvalds 10081da177e4SLinus Torvalds dbg("%s",__FUNCTION__); 10091da177e4SLinus Torvalds 10101da177e4SLinus Torvalds rv = usb_control_msg(udev, 10111da177e4SLinus Torvalds usb_rcvctrlpipe(udev, 0), 10121da177e4SLinus Torvalds FTDI_SIO_GET_LATENCY_TIMER_REQUEST, 10131da177e4SLinus Torvalds FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 10141da177e4SLinus Torvalds 0, priv->interface, 10151da177e4SLinus Torvalds (char*) &latency, 1, WDR_TIMEOUT); 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds if (rv < 0) { 10181da177e4SLinus Torvalds dev_err(dev, "Unable to read latency timer: %i", rv); 10191da177e4SLinus Torvalds return -EIO; 10201da177e4SLinus Torvalds } 10211da177e4SLinus Torvalds return sprintf(buf, "%i\n", latency); 10221da177e4SLinus Torvalds } 10231da177e4SLinus Torvalds 10241da177e4SLinus Torvalds /* Write a new value of the latency timer, in units of milliseconds. */ 1025060b8845SYani Ioannou static ssize_t store_latency_timer(struct device *dev, struct device_attribute *attr, const char *valbuf, 10261da177e4SLinus Torvalds size_t count) 10271da177e4SLinus Torvalds { 10281da177e4SLinus Torvalds struct usb_serial_port *port = to_usb_serial_port(dev); 10291da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 10301da177e4SLinus Torvalds struct usb_device *udev; 10311da177e4SLinus Torvalds char buf[1]; 10321da177e4SLinus Torvalds int v = simple_strtoul(valbuf, NULL, 10); 10331da177e4SLinus Torvalds int rv = 0; 10341da177e4SLinus Torvalds 10351da177e4SLinus Torvalds udev = to_usb_device(dev); 10361da177e4SLinus Torvalds 10371da177e4SLinus Torvalds dbg("%s: setting latency timer = %i", __FUNCTION__, v); 10381da177e4SLinus Torvalds 10391da177e4SLinus Torvalds rv = usb_control_msg(udev, 10401da177e4SLinus Torvalds usb_sndctrlpipe(udev, 0), 10411da177e4SLinus Torvalds FTDI_SIO_SET_LATENCY_TIMER_REQUEST, 10421da177e4SLinus Torvalds FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, 10431da177e4SLinus Torvalds v, priv->interface, 10441da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT); 10451da177e4SLinus Torvalds 10461da177e4SLinus Torvalds if (rv < 0) { 10471da177e4SLinus Torvalds dev_err(dev, "Unable to write latency timer: %i", rv); 10481da177e4SLinus Torvalds return -EIO; 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds 10511da177e4SLinus Torvalds return count; 10521da177e4SLinus Torvalds } 10531da177e4SLinus Torvalds 10541da177e4SLinus Torvalds /* Write an event character directly to the FTDI register. The ASCII 10551da177e4SLinus Torvalds value is in the low 8 bits, with the enable bit in the 9th bit. */ 1056060b8845SYani Ioannou static ssize_t store_event_char(struct device *dev, struct device_attribute *attr, const char *valbuf, 10571da177e4SLinus Torvalds size_t count) 10581da177e4SLinus Torvalds { 10591da177e4SLinus Torvalds struct usb_serial_port *port = to_usb_serial_port(dev); 10601da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 10611da177e4SLinus Torvalds struct usb_device *udev; 10621da177e4SLinus Torvalds char buf[1]; 10631da177e4SLinus Torvalds int v = simple_strtoul(valbuf, NULL, 10); 10641da177e4SLinus Torvalds int rv = 0; 10651da177e4SLinus Torvalds 10661da177e4SLinus Torvalds udev = to_usb_device(dev); 10671da177e4SLinus Torvalds 10681da177e4SLinus Torvalds dbg("%s: setting event char = %i", __FUNCTION__, v); 10691da177e4SLinus Torvalds 10701da177e4SLinus Torvalds rv = usb_control_msg(udev, 10711da177e4SLinus Torvalds usb_sndctrlpipe(udev, 0), 10721da177e4SLinus Torvalds FTDI_SIO_SET_EVENT_CHAR_REQUEST, 10731da177e4SLinus Torvalds FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE, 10741da177e4SLinus Torvalds v, priv->interface, 10751da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT); 10761da177e4SLinus Torvalds 10771da177e4SLinus Torvalds if (rv < 0) { 10781da177e4SLinus Torvalds dbg("Unable to write event character: %i", rv); 10791da177e4SLinus Torvalds return -EIO; 10801da177e4SLinus Torvalds } 10811da177e4SLinus Torvalds 10821da177e4SLinus Torvalds return count; 10831da177e4SLinus Torvalds } 10841da177e4SLinus Torvalds 10851da177e4SLinus Torvalds static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); 10861da177e4SLinus Torvalds static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); 10871da177e4SLinus Torvalds 10881da177e4SLinus Torvalds static void create_sysfs_attrs(struct usb_serial *serial) 10891da177e4SLinus Torvalds { 10901da177e4SLinus Torvalds struct ftdi_private *priv; 10911da177e4SLinus Torvalds struct usb_device *udev; 10921da177e4SLinus Torvalds 10931da177e4SLinus Torvalds dbg("%s",__FUNCTION__); 10941da177e4SLinus Torvalds 10951da177e4SLinus Torvalds priv = usb_get_serial_port_data(serial->port[0]); 10961da177e4SLinus Torvalds udev = serial->dev; 10971da177e4SLinus Torvalds 10981da177e4SLinus Torvalds /* XXX I've no idea if the original SIO supports the event_char 10991da177e4SLinus Torvalds * sysfs parameter, so I'm playing it safe. */ 11001da177e4SLinus Torvalds if (priv->chip_type != SIO) { 11011da177e4SLinus Torvalds dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]); 11021da177e4SLinus Torvalds device_create_file(&udev->dev, &dev_attr_event_char); 11031da177e4SLinus Torvalds if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { 11041da177e4SLinus Torvalds device_create_file(&udev->dev, &dev_attr_latency_timer); 11051da177e4SLinus Torvalds } 11061da177e4SLinus Torvalds } 11071da177e4SLinus Torvalds } 11081da177e4SLinus Torvalds 11091da177e4SLinus Torvalds static void remove_sysfs_attrs(struct usb_serial *serial) 11101da177e4SLinus Torvalds { 11111da177e4SLinus Torvalds struct ftdi_private *priv; 11121da177e4SLinus Torvalds struct usb_device *udev; 11131da177e4SLinus Torvalds 11141da177e4SLinus Torvalds dbg("%s",__FUNCTION__); 11151da177e4SLinus Torvalds 11161da177e4SLinus Torvalds priv = usb_get_serial_port_data(serial->port[0]); 11171da177e4SLinus Torvalds udev = serial->dev; 11181da177e4SLinus Torvalds 11191da177e4SLinus Torvalds /* XXX see create_sysfs_attrs */ 11201da177e4SLinus Torvalds if (priv->chip_type != SIO) { 11211da177e4SLinus Torvalds device_remove_file(&udev->dev, &dev_attr_event_char); 11221da177e4SLinus Torvalds if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { 11231da177e4SLinus Torvalds device_remove_file(&udev->dev, &dev_attr_latency_timer); 11241da177e4SLinus Torvalds } 11251da177e4SLinus Torvalds } 11261da177e4SLinus Torvalds 11271da177e4SLinus Torvalds } 11281da177e4SLinus Torvalds 11291da177e4SLinus Torvalds /* 11301da177e4SLinus Torvalds * *************************************************************************** 11311da177e4SLinus Torvalds * FTDI driver specific functions 11321da177e4SLinus Torvalds * *************************************************************************** 11331da177e4SLinus Torvalds */ 11341da177e4SLinus Torvalds 11358f977e42SIan Abbott /* Probe function to check for special devices */ 11368f977e42SIan Abbott static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id) 11378f977e42SIan Abbott { 11388f977e42SIan Abbott usb_set_serial_data(serial, (void *)id->driver_info); 11398f977e42SIan Abbott 11408f977e42SIan Abbott return (0); 11418f977e42SIan Abbott } 11428f977e42SIan Abbott 11438f977e42SIan Abbott /* attach subroutine */ 11448f977e42SIan Abbott static int ftdi_sio_attach (struct usb_serial *serial) 11451da177e4SLinus Torvalds { 11461da177e4SLinus Torvalds struct usb_serial_port *port = serial->port[0]; 11471da177e4SLinus Torvalds struct ftdi_private *priv; 11488f977e42SIan Abbott struct ftdi_sio_quirk *quirk; 11491da177e4SLinus Torvalds 11501da177e4SLinus Torvalds dbg("%s",__FUNCTION__); 11511da177e4SLinus Torvalds 115280b6ca48SEric Sesterhenn priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); 11531da177e4SLinus Torvalds if (!priv){ 11541da177e4SLinus Torvalds err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct ftdi_private)); 11551da177e4SLinus Torvalds return -ENOMEM; 11561da177e4SLinus Torvalds } 11571da177e4SLinus Torvalds 11581da177e4SLinus Torvalds spin_lock_init(&priv->rx_lock); 11591da177e4SLinus Torvalds init_waitqueue_head(&priv->delta_msr_wait); 11601da177e4SLinus Torvalds /* This will push the characters through immediately rather 11611da177e4SLinus Torvalds than queue a task to deliver them */ 11621da177e4SLinus Torvalds priv->flags = ASYNC_LOW_LATENCY; 11631da177e4SLinus Torvalds 11641da177e4SLinus Torvalds /* Increase the size of read buffers */ 11651da177e4SLinus Torvalds kfree(port->bulk_in_buffer); 11661da177e4SLinus Torvalds port->bulk_in_buffer = kmalloc (BUFSZ, GFP_KERNEL); 11671da177e4SLinus Torvalds if (!port->bulk_in_buffer) { 11681da177e4SLinus Torvalds kfree (priv); 11691da177e4SLinus Torvalds return -ENOMEM; 11701da177e4SLinus Torvalds } 11711da177e4SLinus Torvalds if (port->read_urb) { 11721da177e4SLinus Torvalds port->read_urb->transfer_buffer = port->bulk_in_buffer; 11731da177e4SLinus Torvalds port->read_urb->transfer_buffer_length = BUFSZ; 11741da177e4SLinus Torvalds } 11751da177e4SLinus Torvalds 117676854ceaSIan Abbott INIT_WORK(&priv->rx_work, ftdi_process_read, port); 117776854ceaSIan Abbott 11781da177e4SLinus Torvalds /* Free port's existing write urb and transfer buffer. */ 11791da177e4SLinus Torvalds if (port->write_urb) { 11801da177e4SLinus Torvalds usb_free_urb (port->write_urb); 11811da177e4SLinus Torvalds port->write_urb = NULL; 11821da177e4SLinus Torvalds } 11831da177e4SLinus Torvalds kfree(port->bulk_out_buffer); 11841da177e4SLinus Torvalds port->bulk_out_buffer = NULL; 11851da177e4SLinus Torvalds 11861da177e4SLinus Torvalds usb_set_serial_port_data(serial->port[0], priv); 11871da177e4SLinus Torvalds 11888f977e42SIan Abbott ftdi_determine_type (serial->port[0]); 11898f977e42SIan Abbott create_sysfs_attrs(serial); 11908f977e42SIan Abbott 11918f977e42SIan Abbott /* Check for device requiring special set up. */ 11928f977e42SIan Abbott quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial); 11938f977e42SIan Abbott if (quirk && quirk->setup) { 11948f977e42SIan Abbott quirk->setup(serial); 11951da177e4SLinus Torvalds } 11961da177e4SLinus Torvalds 11978f977e42SIan Abbott return (0); 11988f977e42SIan Abbott } /* ftdi_sio_attach */ 11991da177e4SLinus Torvalds 12008f977e42SIan Abbott 12018f977e42SIan Abbott /* Setup for the USB-UIRT device, which requires hardwired 12028f977e42SIan Abbott * baudrate (38400 gets mapped to 312500) */ 12031da177e4SLinus Torvalds /* Called from usbserial:serial_probe */ 12048f977e42SIan Abbott static void ftdi_USB_UIRT_setup (struct usb_serial *serial) 12051da177e4SLinus Torvalds { 12061da177e4SLinus Torvalds struct ftdi_private *priv; 12071da177e4SLinus Torvalds 12081da177e4SLinus Torvalds dbg("%s",__FUNCTION__); 12091da177e4SLinus Torvalds 12101da177e4SLinus Torvalds priv = usb_get_serial_port_data(serial->port[0]); 12111da177e4SLinus Torvalds priv->flags |= ASYNC_SPD_CUST; 12121da177e4SLinus Torvalds priv->custom_divisor = 77; 12131da177e4SLinus Torvalds priv->force_baud = B38400; 12148f977e42SIan Abbott } /* ftdi_USB_UIRT_setup */ 12151da177e4SLinus Torvalds 12168f977e42SIan Abbott /* Setup for the HE-TIRA1 device, which requires hardwired 12178f977e42SIan Abbott * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */ 12188f977e42SIan Abbott static void ftdi_HE_TIRA1_setup (struct usb_serial *serial) 12198f977e42SIan Abbott { 12201da177e4SLinus Torvalds struct ftdi_private *priv; 12211da177e4SLinus Torvalds 12221da177e4SLinus Torvalds dbg("%s",__FUNCTION__); 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds priv = usb_get_serial_port_data(serial->port[0]); 12251da177e4SLinus Torvalds priv->flags |= ASYNC_SPD_CUST; 12261da177e4SLinus Torvalds priv->custom_divisor = 240; 12271da177e4SLinus Torvalds priv->force_baud = B38400; 12281da177e4SLinus Torvalds priv->force_rtscts = 1; 12298f977e42SIan Abbott } /* ftdi_HE_TIRA1_setup */ 12301da177e4SLinus Torvalds 12311da177e4SLinus Torvalds 12321da177e4SLinus Torvalds /* ftdi_shutdown is called from usbserial:usb_serial_disconnect 12331da177e4SLinus Torvalds * it is called when the usb device is disconnected 12341da177e4SLinus Torvalds * 12351da177e4SLinus Torvalds * usbserial:usb_serial_disconnect 12361da177e4SLinus Torvalds * calls __serial_close for each open of the port 12371da177e4SLinus Torvalds * shutdown is called then (ie ftdi_shutdown) 12381da177e4SLinus Torvalds */ 12391da177e4SLinus Torvalds 12401da177e4SLinus Torvalds 12411da177e4SLinus Torvalds static void ftdi_shutdown (struct usb_serial *serial) 12421da177e4SLinus Torvalds { /* ftdi_shutdown */ 12431da177e4SLinus Torvalds 12441da177e4SLinus Torvalds struct usb_serial_port *port = serial->port[0]; 12451da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 12461da177e4SLinus Torvalds 12471da177e4SLinus Torvalds dbg("%s", __FUNCTION__); 12481da177e4SLinus Torvalds 12491da177e4SLinus Torvalds remove_sysfs_attrs(serial); 12501da177e4SLinus Torvalds 12511da177e4SLinus Torvalds /* all open ports are closed at this point 12521da177e4SLinus Torvalds * (by usbserial.c:__serial_close, which calls ftdi_close) 12531da177e4SLinus Torvalds */ 12541da177e4SLinus Torvalds 12551da177e4SLinus Torvalds if (priv) { 12561da177e4SLinus Torvalds usb_set_serial_port_data(port, NULL); 12571da177e4SLinus Torvalds kfree(priv); 12581da177e4SLinus Torvalds } 12591da177e4SLinus Torvalds } /* ftdi_shutdown */ 12601da177e4SLinus Torvalds 12611da177e4SLinus Torvalds 12621da177e4SLinus Torvalds static int ftdi_open (struct usb_serial_port *port, struct file *filp) 12631da177e4SLinus Torvalds { /* ftdi_open */ 12641da177e4SLinus Torvalds struct usb_device *dev = port->serial->dev; 12651da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 12661da177e4SLinus Torvalds unsigned long flags; 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds int result = 0; 12691da177e4SLinus Torvalds char buf[1]; /* Needed for the usb_control_msg I think */ 12701da177e4SLinus Torvalds 12711da177e4SLinus Torvalds dbg("%s", __FUNCTION__); 12721da177e4SLinus Torvalds 127357845bd1SGuennadi Liakhovetski if (port->tty) 12741da177e4SLinus Torvalds port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 12751da177e4SLinus Torvalds 12761da177e4SLinus Torvalds /* No error checking for this (will get errors later anyway) */ 12771da177e4SLinus Torvalds /* See ftdi_sio.h for description of what is reset */ 12781da177e4SLinus Torvalds usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 12791da177e4SLinus Torvalds FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE, 12801da177e4SLinus Torvalds FTDI_SIO_RESET_SIO, 12811da177e4SLinus Torvalds priv->interface, buf, 0, WDR_TIMEOUT); 12821da177e4SLinus Torvalds 12831da177e4SLinus Torvalds /* Termios defaults are set by usb_serial_init. We don't change 12841da177e4SLinus Torvalds port->tty->termios - this would loose speed settings, etc. 12851da177e4SLinus Torvalds This is same behaviour as serial.c/rs_open() - Kuba */ 12861da177e4SLinus Torvalds 12871da177e4SLinus Torvalds /* ftdi_set_termios will send usb control messages */ 128857845bd1SGuennadi Liakhovetski if (port->tty) 128957845bd1SGuennadi Liakhovetski ftdi_set_termios(port, NULL); 12901da177e4SLinus Torvalds 12911da177e4SLinus Torvalds /* FIXME: Flow control might be enabled, so it should be checked - 12921da177e4SLinus Torvalds we have no control of defaults! */ 12931da177e4SLinus Torvalds /* Turn on RTS and DTR since we are not flow controlling by default */ 129474ede0ffSIan Abbott set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 12951da177e4SLinus Torvalds 12961da177e4SLinus Torvalds /* Not throttled */ 12971da177e4SLinus Torvalds spin_lock_irqsave(&priv->rx_lock, flags); 12981da177e4SLinus Torvalds priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); 12991da177e4SLinus Torvalds spin_unlock_irqrestore(&priv->rx_lock, flags); 13001da177e4SLinus Torvalds 13011da177e4SLinus Torvalds /* Start reading from the device */ 130276854ceaSIan Abbott priv->rx_processed = 0; 13031da177e4SLinus Torvalds usb_fill_bulk_urb(port->read_urb, dev, 13041da177e4SLinus Torvalds usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), 13051da177e4SLinus Torvalds port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 13061da177e4SLinus Torvalds ftdi_read_bulk_callback, port); 13071da177e4SLinus Torvalds result = usb_submit_urb(port->read_urb, GFP_KERNEL); 13081da177e4SLinus Torvalds if (result) 13091da177e4SLinus Torvalds err("%s - failed submitting read urb, error %d", __FUNCTION__, result); 13101da177e4SLinus Torvalds 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds return result; 13131da177e4SLinus Torvalds } /* ftdi_open */ 13141da177e4SLinus Torvalds 13151da177e4SLinus Torvalds 13161da177e4SLinus Torvalds 13171da177e4SLinus Torvalds /* 13181da177e4SLinus Torvalds * usbserial:__serial_close only calls ftdi_close if the point is open 13191da177e4SLinus Torvalds * 13201da177e4SLinus Torvalds * This only gets called when it is the last close 13211da177e4SLinus Torvalds * 13221da177e4SLinus Torvalds * 13231da177e4SLinus Torvalds */ 13241da177e4SLinus Torvalds 13251da177e4SLinus Torvalds static void ftdi_close (struct usb_serial_port *port, struct file *filp) 13261da177e4SLinus Torvalds { /* ftdi_close */ 13271da177e4SLinus Torvalds unsigned int c_cflag = port->tty->termios->c_cflag; 13281da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 13291da177e4SLinus Torvalds char buf[1]; 13301da177e4SLinus Torvalds 13311da177e4SLinus Torvalds dbg("%s", __FUNCTION__); 13321da177e4SLinus Torvalds 13331da177e4SLinus Torvalds if (c_cflag & HUPCL){ 13341da177e4SLinus Torvalds /* Disable flow control */ 13351da177e4SLinus Torvalds if (usb_control_msg(port->serial->dev, 13361da177e4SLinus Torvalds usb_sndctrlpipe(port->serial->dev, 0), 13371da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST, 13381da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 13391da177e4SLinus Torvalds 0, priv->interface, buf, 0, 13401da177e4SLinus Torvalds WDR_TIMEOUT) < 0) { 13411da177e4SLinus Torvalds err("error from flowcontrol urb"); 13421da177e4SLinus Torvalds } 13431da177e4SLinus Torvalds 134474ede0ffSIan Abbott /* drop RTS and DTR */ 134574ede0ffSIan Abbott clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 13461da177e4SLinus Torvalds } /* Note change no line if hupcl is off */ 13471da177e4SLinus Torvalds 134876854ceaSIan Abbott /* cancel any scheduled reading */ 134976854ceaSIan Abbott cancel_delayed_work(&priv->rx_work); 135076854ceaSIan Abbott flush_scheduled_work(); 135176854ceaSIan Abbott 13521da177e4SLinus Torvalds /* shutdown our bulk read */ 13531da177e4SLinus Torvalds if (port->read_urb) 13541da177e4SLinus Torvalds usb_kill_urb(port->read_urb); 13551da177e4SLinus Torvalds } /* ftdi_close */ 13561da177e4SLinus Torvalds 13571da177e4SLinus Torvalds 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds /* The SIO requires the first byte to have: 13601da177e4SLinus Torvalds * B0 1 13611da177e4SLinus Torvalds * B1 0 13621da177e4SLinus Torvalds * B2..7 length of message excluding byte 0 13631da177e4SLinus Torvalds * 13641da177e4SLinus Torvalds * The new devices do not require this byte 13651da177e4SLinus Torvalds */ 13661da177e4SLinus Torvalds static int ftdi_write (struct usb_serial_port *port, 13671da177e4SLinus Torvalds const unsigned char *buf, int count) 13681da177e4SLinus Torvalds { /* ftdi_write */ 13691da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 13701da177e4SLinus Torvalds struct urb *urb; 13711da177e4SLinus Torvalds unsigned char *buffer; 13721da177e4SLinus Torvalds int data_offset ; /* will be 1 for the SIO and 0 otherwise */ 13731da177e4SLinus Torvalds int status; 13741da177e4SLinus Torvalds int transfer_size; 13751da177e4SLinus Torvalds 13761da177e4SLinus Torvalds dbg("%s port %d, %d bytes", __FUNCTION__, port->number, count); 13771da177e4SLinus Torvalds 13781da177e4SLinus Torvalds if (count == 0) { 13791da177e4SLinus Torvalds dbg("write request of 0 bytes"); 13801da177e4SLinus Torvalds return 0; 13811da177e4SLinus Torvalds } 13821da177e4SLinus Torvalds 13831da177e4SLinus Torvalds data_offset = priv->write_offset; 13841da177e4SLinus Torvalds dbg("data_offset set to %d",data_offset); 13851da177e4SLinus Torvalds 13861da177e4SLinus Torvalds /* Determine total transfer size */ 13871da177e4SLinus Torvalds transfer_size = count; 13881da177e4SLinus Torvalds if (data_offset > 0) { 13891da177e4SLinus Torvalds /* Original sio needs control bytes too... */ 13901da177e4SLinus Torvalds transfer_size += (data_offset * 13911da177e4SLinus Torvalds ((count + (PKTSZ - 1 - data_offset)) / 13921da177e4SLinus Torvalds (PKTSZ - data_offset))); 13931da177e4SLinus Torvalds } 13941da177e4SLinus Torvalds 13951da177e4SLinus Torvalds buffer = kmalloc (transfer_size, GFP_ATOMIC); 13961da177e4SLinus Torvalds if (!buffer) { 13971da177e4SLinus Torvalds err("%s ran out of kernel memory for urb ...", __FUNCTION__); 13981da177e4SLinus Torvalds return -ENOMEM; 13991da177e4SLinus Torvalds } 14001da177e4SLinus Torvalds 14011da177e4SLinus Torvalds urb = usb_alloc_urb(0, GFP_ATOMIC); 14021da177e4SLinus Torvalds if (!urb) { 14031da177e4SLinus Torvalds err("%s - no more free urbs", __FUNCTION__); 14041da177e4SLinus Torvalds kfree (buffer); 14051da177e4SLinus Torvalds return -ENOMEM; 14061da177e4SLinus Torvalds } 14071da177e4SLinus Torvalds 14081da177e4SLinus Torvalds /* Copy data */ 14091da177e4SLinus Torvalds if (data_offset > 0) { 14101da177e4SLinus Torvalds /* Original sio requires control byte at start of each packet. */ 14111da177e4SLinus Torvalds int user_pktsz = PKTSZ - data_offset; 14121da177e4SLinus Torvalds int todo = count; 14131da177e4SLinus Torvalds unsigned char *first_byte = buffer; 14141da177e4SLinus Torvalds const unsigned char *current_position = buf; 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds while (todo > 0) { 14171da177e4SLinus Torvalds if (user_pktsz > todo) { 14181da177e4SLinus Torvalds user_pktsz = todo; 14191da177e4SLinus Torvalds } 14201da177e4SLinus Torvalds /* Write the control byte at the front of the packet*/ 14211da177e4SLinus Torvalds *first_byte = 1 | ((user_pktsz) << 2); 14221da177e4SLinus Torvalds /* Copy data for packet */ 14231da177e4SLinus Torvalds memcpy (first_byte + data_offset, 14241da177e4SLinus Torvalds current_position, user_pktsz); 14251da177e4SLinus Torvalds first_byte += user_pktsz + data_offset; 14261da177e4SLinus Torvalds current_position += user_pktsz; 14271da177e4SLinus Torvalds todo -= user_pktsz; 14281da177e4SLinus Torvalds } 14291da177e4SLinus Torvalds } else { 14301da177e4SLinus Torvalds /* No control byte required. */ 14311da177e4SLinus Torvalds /* Copy in the data to send */ 14321da177e4SLinus Torvalds memcpy (buffer, buf, count); 14331da177e4SLinus Torvalds } 14341da177e4SLinus Torvalds 14351da177e4SLinus Torvalds usb_serial_debug_data(debug, &port->dev, __FUNCTION__, transfer_size, buffer); 14361da177e4SLinus Torvalds 14371da177e4SLinus Torvalds /* fill the buffer and send it */ 14381da177e4SLinus Torvalds usb_fill_bulk_urb(urb, port->serial->dev, 14391da177e4SLinus Torvalds usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), 14401da177e4SLinus Torvalds buffer, transfer_size, 14411da177e4SLinus Torvalds ftdi_write_bulk_callback, port); 14421da177e4SLinus Torvalds 14431da177e4SLinus Torvalds status = usb_submit_urb(urb, GFP_ATOMIC); 14441da177e4SLinus Torvalds if (status) { 14451da177e4SLinus Torvalds err("%s - failed submitting write urb, error %d", __FUNCTION__, status); 14461da177e4SLinus Torvalds count = status; 14471da177e4SLinus Torvalds kfree (buffer); 14481da177e4SLinus Torvalds } 14491da177e4SLinus Torvalds 14501da177e4SLinus Torvalds /* we are done with this urb, so let the host driver 14511da177e4SLinus Torvalds * really free it when it is finished with it */ 14521da177e4SLinus Torvalds usb_free_urb (urb); 14531da177e4SLinus Torvalds 14541da177e4SLinus Torvalds dbg("%s write returning: %d", __FUNCTION__, count); 14551da177e4SLinus Torvalds return count; 14561da177e4SLinus Torvalds } /* ftdi_write */ 14571da177e4SLinus Torvalds 14581da177e4SLinus Torvalds 14591da177e4SLinus Torvalds /* This function may get called when the device is closed */ 14601da177e4SLinus Torvalds 14611da177e4SLinus Torvalds static void ftdi_write_bulk_callback (struct urb *urb, struct pt_regs *regs) 14621da177e4SLinus Torvalds { 14631da177e4SLinus Torvalds struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 14641da177e4SLinus Torvalds 14651da177e4SLinus Torvalds /* free up the transfer buffer, as usb_free_urb() does not do this */ 14661da177e4SLinus Torvalds kfree (urb->transfer_buffer); 14671da177e4SLinus Torvalds 14681da177e4SLinus Torvalds dbg("%s - port %d", __FUNCTION__, port->number); 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds if (urb->status) { 14711da177e4SLinus Torvalds dbg("nonzero write bulk status received: %d", urb->status); 14721da177e4SLinus Torvalds return; 14731da177e4SLinus Torvalds } 14741da177e4SLinus Torvalds 1475*cf2c7481SPete Zaitcev usb_serial_port_softint(port); 14761da177e4SLinus Torvalds } /* ftdi_write_bulk_callback */ 14771da177e4SLinus Torvalds 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds static int ftdi_write_room( struct usb_serial_port *port ) 14801da177e4SLinus Torvalds { 14811da177e4SLinus Torvalds dbg("%s - port %d", __FUNCTION__, port->number); 14821da177e4SLinus Torvalds 14831da177e4SLinus Torvalds /* 14841da177e4SLinus Torvalds * We really can take anything the user throws at us 14851da177e4SLinus Torvalds * but let's pick a nice big number to tell the tty 14861da177e4SLinus Torvalds * layer that we have lots of free space 14871da177e4SLinus Torvalds */ 14881da177e4SLinus Torvalds return 2048; 14891da177e4SLinus Torvalds } /* ftdi_write_room */ 14901da177e4SLinus Torvalds 14911da177e4SLinus Torvalds 14921da177e4SLinus Torvalds static int ftdi_chars_in_buffer (struct usb_serial_port *port) 14931da177e4SLinus Torvalds { /* ftdi_chars_in_buffer */ 14941da177e4SLinus Torvalds dbg("%s - port %d", __FUNCTION__, port->number); 14951da177e4SLinus Torvalds 14961da177e4SLinus Torvalds /* 14971da177e4SLinus Torvalds * We can't really account for how much data we 14981da177e4SLinus Torvalds * have sent out, but hasn't made it through to the 14991da177e4SLinus Torvalds * device, so just tell the tty layer that everything 15001da177e4SLinus Torvalds * is flushed. 15011da177e4SLinus Torvalds */ 15021da177e4SLinus Torvalds return 0; 15031da177e4SLinus Torvalds } /* ftdi_chars_in_buffer */ 15041da177e4SLinus Torvalds 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds 15071da177e4SLinus Torvalds static void ftdi_read_bulk_callback (struct urb *urb, struct pt_regs *regs) 15081da177e4SLinus Torvalds { /* ftdi_read_bulk_callback */ 15091da177e4SLinus Torvalds struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 15101da177e4SLinus Torvalds struct tty_struct *tty; 15111da177e4SLinus Torvalds struct ftdi_private *priv; 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds if (urb->number_of_packets > 0) { 15141da177e4SLinus Torvalds err("%s transfer_buffer_length %d actual_length %d number of packets %d",__FUNCTION__, 15151da177e4SLinus Torvalds urb->transfer_buffer_length, urb->actual_length, urb->number_of_packets ); 15161da177e4SLinus Torvalds err("%s transfer_flags %x ", __FUNCTION__,urb->transfer_flags ); 15171da177e4SLinus Torvalds } 15181da177e4SLinus Torvalds 15191da177e4SLinus Torvalds dbg("%s - port %d", __FUNCTION__, port->number); 15201da177e4SLinus Torvalds 15211da177e4SLinus Torvalds if (port->open_count <= 0) 15221da177e4SLinus Torvalds return; 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds tty = port->tty; 15251da177e4SLinus Torvalds if (!tty) { 15261da177e4SLinus Torvalds dbg("%s - bad tty pointer - exiting",__FUNCTION__); 15271da177e4SLinus Torvalds return; 15281da177e4SLinus Torvalds } 15291da177e4SLinus Torvalds 15301da177e4SLinus Torvalds priv = usb_get_serial_port_data(port); 15311da177e4SLinus Torvalds if (!priv) { 15321da177e4SLinus Torvalds dbg("%s - bad port private data pointer - exiting", __FUNCTION__); 15331da177e4SLinus Torvalds return; 15341da177e4SLinus Torvalds } 15351da177e4SLinus Torvalds 15361da177e4SLinus Torvalds if (urb != port->read_urb) { 15371da177e4SLinus Torvalds err("%s - Not my urb!", __FUNCTION__); 15381da177e4SLinus Torvalds } 15391da177e4SLinus Torvalds 15401da177e4SLinus Torvalds if (urb->status) { 15411da177e4SLinus Torvalds /* This will happen at close every time so it is a dbg not an err */ 15421da177e4SLinus Torvalds dbg("(this is ok on close) nonzero read bulk status received: %d", urb->status); 15431da177e4SLinus Torvalds return; 15441da177e4SLinus Torvalds } 15451da177e4SLinus Torvalds 15461da177e4SLinus Torvalds ftdi_process_read(port); 15471da177e4SLinus Torvalds 15481da177e4SLinus Torvalds } /* ftdi_read_bulk_callback */ 15491da177e4SLinus Torvalds 15501da177e4SLinus Torvalds 155176854ceaSIan Abbott static void ftdi_process_read (void *param) 15521da177e4SLinus Torvalds { /* ftdi_process_read */ 155376854ceaSIan Abbott struct usb_serial_port *port = (struct usb_serial_port*)param; 15541da177e4SLinus Torvalds struct urb *urb; 15551da177e4SLinus Torvalds struct tty_struct *tty; 15561da177e4SLinus Torvalds struct ftdi_private *priv; 15571da177e4SLinus Torvalds char error_flag; 15581da177e4SLinus Torvalds unsigned char *data; 15591da177e4SLinus Torvalds 15601da177e4SLinus Torvalds int i; 15611da177e4SLinus Torvalds int result; 15621da177e4SLinus Torvalds int need_flip; 15631da177e4SLinus Torvalds int packet_offset; 156476854ceaSIan Abbott unsigned long flags; 15651da177e4SLinus Torvalds 15661da177e4SLinus Torvalds dbg("%s - port %d", __FUNCTION__, port->number); 15671da177e4SLinus Torvalds 15681da177e4SLinus Torvalds if (port->open_count <= 0) 15691da177e4SLinus Torvalds return; 15701da177e4SLinus Torvalds 15711da177e4SLinus Torvalds tty = port->tty; 15721da177e4SLinus Torvalds if (!tty) { 15731da177e4SLinus Torvalds dbg("%s - bad tty pointer - exiting",__FUNCTION__); 15741da177e4SLinus Torvalds return; 15751da177e4SLinus Torvalds } 15761da177e4SLinus Torvalds 15771da177e4SLinus Torvalds priv = usb_get_serial_port_data(port); 15781da177e4SLinus Torvalds if (!priv) { 15791da177e4SLinus Torvalds dbg("%s - bad port private data pointer - exiting", __FUNCTION__); 15801da177e4SLinus Torvalds return; 15811da177e4SLinus Torvalds } 15821da177e4SLinus Torvalds 15831da177e4SLinus Torvalds urb = port->read_urb; 15841da177e4SLinus Torvalds if (!urb) { 15851da177e4SLinus Torvalds dbg("%s - bad read_urb pointer - exiting", __FUNCTION__); 15861da177e4SLinus Torvalds return; 15871da177e4SLinus Torvalds } 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds data = urb->transfer_buffer; 15901da177e4SLinus Torvalds 159176854ceaSIan Abbott if (priv->rx_processed) { 159276854ceaSIan Abbott dbg("%s - already processed: %d bytes, %d remain", __FUNCTION__, 159376854ceaSIan Abbott priv->rx_processed, 159476854ceaSIan Abbott urb->actual_length - priv->rx_processed); 159576854ceaSIan Abbott } else { 15961da177e4SLinus Torvalds /* The first two bytes of every read packet are status */ 15971da177e4SLinus Torvalds if (urb->actual_length > 2) { 15981da177e4SLinus Torvalds usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 15991da177e4SLinus Torvalds } else { 16001da177e4SLinus Torvalds dbg("Status only: %03oo %03oo",data[0],data[1]); 16011da177e4SLinus Torvalds } 160276854ceaSIan Abbott } 16031da177e4SLinus Torvalds 16041da177e4SLinus Torvalds 16051da177e4SLinus Torvalds /* TO DO -- check for hung up line and handle appropriately: */ 16061da177e4SLinus Torvalds /* send hangup */ 16071da177e4SLinus Torvalds /* See acm.c - you do a tty_hangup - eg tty_hangup(tty) */ 16081da177e4SLinus Torvalds /* if CD is dropped and the line is not CLOCAL then we should hangup */ 16091da177e4SLinus Torvalds 16101da177e4SLinus Torvalds need_flip = 0; 161176854ceaSIan Abbott for (packet_offset = priv->rx_processed; packet_offset < urb->actual_length; packet_offset += PKTSZ) { 161276854ceaSIan Abbott int length; 161376854ceaSIan Abbott 16141da177e4SLinus Torvalds /* Compare new line status to the old one, signal if different */ 161576854ceaSIan Abbott /* N.B. packet may be processed more than once, but differences 161676854ceaSIan Abbott * are only processed once. */ 16171da177e4SLinus Torvalds if (priv != NULL) { 16181da177e4SLinus Torvalds char new_status = data[packet_offset+0] & FTDI_STATUS_B0_MASK; 16191da177e4SLinus Torvalds if (new_status != priv->prev_status) { 16201da177e4SLinus Torvalds priv->diff_status |= new_status ^ priv->prev_status; 16211da177e4SLinus Torvalds wake_up_interruptible(&priv->delta_msr_wait); 16221da177e4SLinus Torvalds priv->prev_status = new_status; 16231da177e4SLinus Torvalds } 16241da177e4SLinus Torvalds } 16251da177e4SLinus Torvalds 162676854ceaSIan Abbott length = min(PKTSZ, urb->actual_length-packet_offset)-2; 162776854ceaSIan Abbott if (length < 0) { 162876854ceaSIan Abbott err("%s - bad packet length: %d", __FUNCTION__, length+2); 162976854ceaSIan Abbott length = 0; 163076854ceaSIan Abbott } 163176854ceaSIan Abbott 163276854ceaSIan Abbott if (priv->rx_flags & THROTTLED) { 163376854ceaSIan Abbott dbg("%s - throttled", __FUNCTION__); 163476854ceaSIan Abbott break; 163576854ceaSIan Abbott } 163633f0f88fSAlan Cox if (tty_buffer_request_room(tty, length) < length) { 163776854ceaSIan Abbott /* break out & wait for throttling/unthrottling to happen */ 163876854ceaSIan Abbott dbg("%s - receive room low", __FUNCTION__); 163976854ceaSIan Abbott break; 164076854ceaSIan Abbott } 164176854ceaSIan Abbott 16421da177e4SLinus Torvalds /* Handle errors and break */ 16431da177e4SLinus Torvalds error_flag = TTY_NORMAL; 16441da177e4SLinus Torvalds /* Although the device uses a bitmask and hence can have multiple */ 16451da177e4SLinus Torvalds /* errors on a packet - the order here sets the priority the */ 16461da177e4SLinus Torvalds /* error is returned to the tty layer */ 16471da177e4SLinus Torvalds 16481da177e4SLinus Torvalds if ( data[packet_offset+1] & FTDI_RS_OE ) { 16491da177e4SLinus Torvalds error_flag = TTY_OVERRUN; 16501da177e4SLinus Torvalds dbg("OVERRRUN error"); 16511da177e4SLinus Torvalds } 16521da177e4SLinus Torvalds if ( data[packet_offset+1] & FTDI_RS_BI ) { 16531da177e4SLinus Torvalds error_flag = TTY_BREAK; 16541da177e4SLinus Torvalds dbg("BREAK received"); 16551da177e4SLinus Torvalds } 16561da177e4SLinus Torvalds if ( data[packet_offset+1] & FTDI_RS_PE ) { 16571da177e4SLinus Torvalds error_flag = TTY_PARITY; 16581da177e4SLinus Torvalds dbg("PARITY error"); 16591da177e4SLinus Torvalds } 16601da177e4SLinus Torvalds if ( data[packet_offset+1] & FTDI_RS_FE ) { 16611da177e4SLinus Torvalds error_flag = TTY_FRAME; 16621da177e4SLinus Torvalds dbg("FRAMING error"); 16631da177e4SLinus Torvalds } 166476854ceaSIan Abbott if (length > 0) { 166576854ceaSIan Abbott for (i = 2; i < length+2; i++) { 16661da177e4SLinus Torvalds /* Note that the error flag is duplicated for 16671da177e4SLinus Torvalds every character received since we don't know 16681da177e4SLinus Torvalds which character it applied to */ 16691da177e4SLinus Torvalds tty_insert_flip_char(tty, data[packet_offset+i], error_flag); 16701da177e4SLinus Torvalds } 16711da177e4SLinus Torvalds need_flip = 1; 16721da177e4SLinus Torvalds } 16731da177e4SLinus Torvalds 16741da177e4SLinus Torvalds #ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW 16751da177e4SLinus Torvalds /* if a parity error is detected you get status packets forever 16761da177e4SLinus Torvalds until a character is sent without a parity error. 16771da177e4SLinus Torvalds This doesn't work well since the application receives a never 16781da177e4SLinus Torvalds ending stream of bad data - even though new data hasn't been sent. 16791da177e4SLinus Torvalds Therefore I (bill) have taken this out. 16801da177e4SLinus Torvalds However - this might make sense for framing errors and so on 16811da177e4SLinus Torvalds so I am leaving the code in for now. 16821da177e4SLinus Torvalds */ 16831da177e4SLinus Torvalds else { 16841da177e4SLinus Torvalds if (error_flag != TTY_NORMAL){ 16851da177e4SLinus Torvalds dbg("error_flag is not normal"); 16861da177e4SLinus Torvalds /* In this case it is just status - if that is an error send a bad character */ 16871da177e4SLinus Torvalds if(tty->flip.count >= TTY_FLIPBUF_SIZE) { 16881da177e4SLinus Torvalds tty_flip_buffer_push(tty); 16891da177e4SLinus Torvalds } 16901da177e4SLinus Torvalds tty_insert_flip_char(tty, 0xff, error_flag); 16911da177e4SLinus Torvalds need_flip = 1; 16921da177e4SLinus Torvalds } 16931da177e4SLinus Torvalds } 16941da177e4SLinus Torvalds #endif 16951da177e4SLinus Torvalds } /* "for(packet_offset=0..." */ 16961da177e4SLinus Torvalds 16971da177e4SLinus Torvalds /* Low latency */ 16981da177e4SLinus Torvalds if (need_flip) { 16991da177e4SLinus Torvalds tty_flip_buffer_push(tty); 17001da177e4SLinus Torvalds } 17011da177e4SLinus Torvalds 170276854ceaSIan Abbott if (packet_offset < urb->actual_length) { 170376854ceaSIan Abbott /* not completely processed - record progress */ 170476854ceaSIan Abbott priv->rx_processed = packet_offset; 170576854ceaSIan Abbott dbg("%s - incomplete, %d bytes processed, %d remain", 170676854ceaSIan Abbott __FUNCTION__, packet_offset, 170776854ceaSIan Abbott urb->actual_length - packet_offset); 170876854ceaSIan Abbott /* check if we were throttled while processing */ 170976854ceaSIan Abbott spin_lock_irqsave(&priv->rx_lock, flags); 171076854ceaSIan Abbott if (priv->rx_flags & THROTTLED) { 171176854ceaSIan Abbott priv->rx_flags |= ACTUALLY_THROTTLED; 171276854ceaSIan Abbott spin_unlock_irqrestore(&priv->rx_lock, flags); 171376854ceaSIan Abbott dbg("%s - deferring remainder until unthrottled", 171476854ceaSIan Abbott __FUNCTION__); 171576854ceaSIan Abbott return; 171676854ceaSIan Abbott } 171776854ceaSIan Abbott spin_unlock_irqrestore(&priv->rx_lock, flags); 171876854ceaSIan Abbott /* if the port is closed stop trying to read */ 171976854ceaSIan Abbott if (port->open_count > 0){ 172076854ceaSIan Abbott /* delay processing of remainder */ 172176854ceaSIan Abbott schedule_delayed_work(&priv->rx_work, 1); 172276854ceaSIan Abbott } else { 172376854ceaSIan Abbott dbg("%s - port is closed", __FUNCTION__); 172476854ceaSIan Abbott } 172576854ceaSIan Abbott return; 172676854ceaSIan Abbott } 172776854ceaSIan Abbott 172876854ceaSIan Abbott /* urb is completely processed */ 172976854ceaSIan Abbott priv->rx_processed = 0; 173076854ceaSIan Abbott 17311da177e4SLinus Torvalds /* if the port is closed stop trying to read */ 17321da177e4SLinus Torvalds if (port->open_count > 0){ 17331da177e4SLinus Torvalds /* Continue trying to always read */ 17341da177e4SLinus Torvalds usb_fill_bulk_urb(port->read_urb, port->serial->dev, 17351da177e4SLinus Torvalds usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 17361da177e4SLinus Torvalds port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 17371da177e4SLinus Torvalds ftdi_read_bulk_callback, port); 17381da177e4SLinus Torvalds 17391da177e4SLinus Torvalds result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 17401da177e4SLinus Torvalds if (result) 17411da177e4SLinus Torvalds err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 17421da177e4SLinus Torvalds } 17431da177e4SLinus Torvalds 17441da177e4SLinus Torvalds return; 17451da177e4SLinus Torvalds } /* ftdi_process_read */ 17461da177e4SLinus Torvalds 17471da177e4SLinus Torvalds 17481da177e4SLinus Torvalds static void ftdi_break_ctl( struct usb_serial_port *port, int break_state ) 17491da177e4SLinus Torvalds { 17501da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 17511da177e4SLinus Torvalds __u16 urb_value = 0; 17521da177e4SLinus Torvalds char buf[1]; 17531da177e4SLinus Torvalds 17541da177e4SLinus Torvalds /* break_state = -1 to turn on break, and 0 to turn off break */ 17551da177e4SLinus Torvalds /* see drivers/char/tty_io.c to see it used */ 17561da177e4SLinus Torvalds /* last_set_data_urb_value NEVER has the break bit set in it */ 17571da177e4SLinus Torvalds 17581da177e4SLinus Torvalds if (break_state) { 17591da177e4SLinus Torvalds urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK; 17601da177e4SLinus Torvalds } else { 17611da177e4SLinus Torvalds urb_value = priv->last_set_data_urb_value; 17621da177e4SLinus Torvalds } 17631da177e4SLinus Torvalds 17641da177e4SLinus Torvalds 17651da177e4SLinus Torvalds if (usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), 17661da177e4SLinus Torvalds FTDI_SIO_SET_DATA_REQUEST, 17671da177e4SLinus Torvalds FTDI_SIO_SET_DATA_REQUEST_TYPE, 17681da177e4SLinus Torvalds urb_value , priv->interface, 17691da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT) < 0) { 17701da177e4SLinus Torvalds err("%s FAILED to enable/disable break state (state was %d)", __FUNCTION__,break_state); 17711da177e4SLinus Torvalds } 17721da177e4SLinus Torvalds 17731da177e4SLinus Torvalds dbg("%s break state is %d - urb is %d", __FUNCTION__,break_state, urb_value); 17741da177e4SLinus Torvalds 17751da177e4SLinus Torvalds } 17761da177e4SLinus Torvalds 17771da177e4SLinus Torvalds 17781da177e4SLinus Torvalds /* old_termios contains the original termios settings and tty->termios contains 17791da177e4SLinus Torvalds * the new setting to be used 17801da177e4SLinus Torvalds * WARNING: set_termios calls this with old_termios in kernel space 17811da177e4SLinus Torvalds */ 17821da177e4SLinus Torvalds 17831da177e4SLinus Torvalds static void ftdi_set_termios (struct usb_serial_port *port, struct termios *old_termios) 17841da177e4SLinus Torvalds { /* ftdi_termios */ 17851da177e4SLinus Torvalds struct usb_device *dev = port->serial->dev; 17861da177e4SLinus Torvalds unsigned int cflag = port->tty->termios->c_cflag; 17871da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 17881da177e4SLinus Torvalds __u16 urb_value; /* will hold the new flags */ 17891da177e4SLinus Torvalds char buf[1]; /* Perhaps I should dynamically alloc this? */ 17901da177e4SLinus Torvalds 17911da177e4SLinus Torvalds // Added for xon/xoff support 17921da177e4SLinus Torvalds unsigned int iflag = port->tty->termios->c_iflag; 17931da177e4SLinus Torvalds unsigned char vstop; 17941da177e4SLinus Torvalds unsigned char vstart; 17951da177e4SLinus Torvalds 17961da177e4SLinus Torvalds dbg("%s", __FUNCTION__); 17971da177e4SLinus Torvalds 17981da177e4SLinus Torvalds /* Force baud rate if this device requires it, unless it is set to B0. */ 17991da177e4SLinus Torvalds if (priv->force_baud && ((port->tty->termios->c_cflag & CBAUD) != B0)) { 18001da177e4SLinus Torvalds dbg("%s: forcing baud rate for this device", __FUNCTION__); 18011da177e4SLinus Torvalds port->tty->termios->c_cflag &= ~CBAUD; 18021da177e4SLinus Torvalds port->tty->termios->c_cflag |= priv->force_baud; 18031da177e4SLinus Torvalds } 18041da177e4SLinus Torvalds 18051da177e4SLinus Torvalds /* Force RTS-CTS if this device requires it. */ 18061da177e4SLinus Torvalds if (priv->force_rtscts) { 18071da177e4SLinus Torvalds dbg("%s: forcing rtscts for this device", __FUNCTION__); 18081da177e4SLinus Torvalds port->tty->termios->c_cflag |= CRTSCTS; 18091da177e4SLinus Torvalds } 18101da177e4SLinus Torvalds 18111da177e4SLinus Torvalds cflag = port->tty->termios->c_cflag; 18121da177e4SLinus Torvalds 18131da177e4SLinus Torvalds /* FIXME -For this cut I don't care if the line is really changing or 18141da177e4SLinus Torvalds not - so just do the change regardless - should be able to 18151da177e4SLinus Torvalds compare old_termios and tty->termios */ 18161da177e4SLinus Torvalds /* NOTE These routines can get interrupted by 18171da177e4SLinus Torvalds ftdi_sio_read_bulk_callback - need to examine what this 18181da177e4SLinus Torvalds means - don't see any problems yet */ 18191da177e4SLinus Torvalds 18201da177e4SLinus Torvalds /* Set number of data bits, parity, stop bits */ 18211da177e4SLinus Torvalds 18221da177e4SLinus Torvalds urb_value = 0; 18231da177e4SLinus Torvalds urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 : 18241da177e4SLinus Torvalds FTDI_SIO_SET_DATA_STOP_BITS_1); 18251da177e4SLinus Torvalds urb_value |= (cflag & PARENB ? 18261da177e4SLinus Torvalds (cflag & PARODD ? FTDI_SIO_SET_DATA_PARITY_ODD : 18271da177e4SLinus Torvalds FTDI_SIO_SET_DATA_PARITY_EVEN) : 18281da177e4SLinus Torvalds FTDI_SIO_SET_DATA_PARITY_NONE); 18291da177e4SLinus Torvalds if (cflag & CSIZE) { 18301da177e4SLinus Torvalds switch (cflag & CSIZE) { 18311da177e4SLinus Torvalds case CS5: urb_value |= 5; dbg("Setting CS5"); break; 18321da177e4SLinus Torvalds case CS6: urb_value |= 6; dbg("Setting CS6"); break; 18331da177e4SLinus Torvalds case CS7: urb_value |= 7; dbg("Setting CS7"); break; 18341da177e4SLinus Torvalds case CS8: urb_value |= 8; dbg("Setting CS8"); break; 18351da177e4SLinus Torvalds default: 18361da177e4SLinus Torvalds err("CSIZE was set but not CS5-CS8"); 18371da177e4SLinus Torvalds } 18381da177e4SLinus Torvalds } 18391da177e4SLinus Torvalds 18401da177e4SLinus Torvalds /* This is needed by the break command since it uses the same command - but is 18411da177e4SLinus Torvalds * or'ed with this value */ 18421da177e4SLinus Torvalds priv->last_set_data_urb_value = urb_value; 18431da177e4SLinus Torvalds 18441da177e4SLinus Torvalds if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 18451da177e4SLinus Torvalds FTDI_SIO_SET_DATA_REQUEST, 18461da177e4SLinus Torvalds FTDI_SIO_SET_DATA_REQUEST_TYPE, 18471da177e4SLinus Torvalds urb_value , priv->interface, 1848279e1545SIan Abbott buf, 0, WDR_SHORT_TIMEOUT) < 0) { 18491da177e4SLinus Torvalds err("%s FAILED to set databits/stopbits/parity", __FUNCTION__); 18501da177e4SLinus Torvalds } 18511da177e4SLinus Torvalds 18521da177e4SLinus Torvalds /* Now do the baudrate */ 18531da177e4SLinus Torvalds if ((cflag & CBAUD) == B0 ) { 18541da177e4SLinus Torvalds /* Disable flow control */ 18551da177e4SLinus Torvalds if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 18561da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST, 18571da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 18581da177e4SLinus Torvalds 0, priv->interface, 18591da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT) < 0) { 18601da177e4SLinus Torvalds err("%s error from disable flowcontrol urb", __FUNCTION__); 18611da177e4SLinus Torvalds } 18621da177e4SLinus Torvalds /* Drop RTS and DTR */ 186374ede0ffSIan Abbott clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 18641da177e4SLinus Torvalds } else { 18651da177e4SLinus Torvalds /* set the baudrate determined before */ 18661da177e4SLinus Torvalds if (change_speed(port)) { 186772a755fcSPeter Favrholdt err("%s urb failed to set baudrate", __FUNCTION__); 18681da177e4SLinus Torvalds } 186972a755fcSPeter Favrholdt /* Ensure RTS and DTR are raised when baudrate changed from 0 */ 187057845bd1SGuennadi Liakhovetski if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) { 187174ede0ffSIan Abbott set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 18721da177e4SLinus Torvalds } 187372a755fcSPeter Favrholdt } 18741da177e4SLinus Torvalds 18751da177e4SLinus Torvalds /* Set flow control */ 18761da177e4SLinus Torvalds /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */ 18771da177e4SLinus Torvalds if (cflag & CRTSCTS) { 18781da177e4SLinus Torvalds dbg("%s Setting to CRTSCTS flow control", __FUNCTION__); 18791da177e4SLinus Torvalds if (usb_control_msg(dev, 18801da177e4SLinus Torvalds usb_sndctrlpipe(dev, 0), 18811da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST, 18821da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 18831da177e4SLinus Torvalds 0 , (FTDI_SIO_RTS_CTS_HS | priv->interface), 18841da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT) < 0) { 18851da177e4SLinus Torvalds err("urb failed to set to rts/cts flow control"); 18861da177e4SLinus Torvalds } 18871da177e4SLinus Torvalds 18881da177e4SLinus Torvalds } else { 18891da177e4SLinus Torvalds /* 18901da177e4SLinus Torvalds * Xon/Xoff code 18911da177e4SLinus Torvalds * 18921da177e4SLinus Torvalds * Check the IXOFF status in the iflag component of the termios structure 18931da177e4SLinus Torvalds * if IXOFF is not set, the pre-xon/xoff code is executed. 18941da177e4SLinus Torvalds */ 18951da177e4SLinus Torvalds if (iflag & IXOFF) { 18961da177e4SLinus Torvalds dbg("%s request to enable xonxoff iflag=%04x",__FUNCTION__,iflag); 18971da177e4SLinus Torvalds // Try to enable the XON/XOFF on the ftdi_sio 18981da177e4SLinus Torvalds // Set the vstart and vstop -- could have been done up above where 18991da177e4SLinus Torvalds // a lot of other dereferencing is done but that would be very 19001da177e4SLinus Torvalds // inefficient as vstart and vstop are not always needed 19011da177e4SLinus Torvalds vstart=port->tty->termios->c_cc[VSTART]; 19021da177e4SLinus Torvalds vstop=port->tty->termios->c_cc[VSTOP]; 19031da177e4SLinus Torvalds urb_value=(vstop << 8) | (vstart); 19041da177e4SLinus Torvalds 19051da177e4SLinus Torvalds if (usb_control_msg(dev, 19061da177e4SLinus Torvalds usb_sndctrlpipe(dev, 0), 19071da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST, 19081da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 19091da177e4SLinus Torvalds urb_value , (FTDI_SIO_XON_XOFF_HS 19101da177e4SLinus Torvalds | priv->interface), 19111da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT) < 0) { 19121da177e4SLinus Torvalds err("urb failed to set to xon/xoff flow control"); 19131da177e4SLinus Torvalds } 19141da177e4SLinus Torvalds } else { 19151da177e4SLinus Torvalds /* else clause to only run if cfag ! CRTSCTS and iflag ! XOFF */ 19161da177e4SLinus Torvalds /* CHECKME Assuming XON/XOFF handled by tty stack - not by device */ 19171da177e4SLinus Torvalds dbg("%s Turning off hardware flow control", __FUNCTION__); 19181da177e4SLinus Torvalds if (usb_control_msg(dev, 19191da177e4SLinus Torvalds usb_sndctrlpipe(dev, 0), 19201da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST, 19211da177e4SLinus Torvalds FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 19221da177e4SLinus Torvalds 0, priv->interface, 19231da177e4SLinus Torvalds buf, 0, WDR_TIMEOUT) < 0) { 19241da177e4SLinus Torvalds err("urb failed to clear flow control"); 19251da177e4SLinus Torvalds } 19261da177e4SLinus Torvalds } 19271da177e4SLinus Torvalds 19281da177e4SLinus Torvalds } 19291da177e4SLinus Torvalds return; 19301da177e4SLinus Torvalds } /* ftdi_termios */ 19311da177e4SLinus Torvalds 19321da177e4SLinus Torvalds 19331da177e4SLinus Torvalds static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file) 19341da177e4SLinus Torvalds { 19351da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 19361da177e4SLinus Torvalds unsigned char buf[2]; 19371da177e4SLinus Torvalds int ret; 19381da177e4SLinus Torvalds 19391da177e4SLinus Torvalds dbg("%s TIOCMGET", __FUNCTION__); 19401da177e4SLinus Torvalds switch (priv->chip_type) { 19411da177e4SLinus Torvalds case SIO: 19421da177e4SLinus Torvalds /* Request the status from the device */ 19431da177e4SLinus Torvalds if ((ret = usb_control_msg(port->serial->dev, 19441da177e4SLinus Torvalds usb_rcvctrlpipe(port->serial->dev, 0), 19451da177e4SLinus Torvalds FTDI_SIO_GET_MODEM_STATUS_REQUEST, 19461da177e4SLinus Torvalds FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 19471da177e4SLinus Torvalds 0, 0, 19481da177e4SLinus Torvalds buf, 1, WDR_TIMEOUT)) < 0 ) { 19491da177e4SLinus Torvalds err("%s Could not get modem status of device - err: %d", __FUNCTION__, 19501da177e4SLinus Torvalds ret); 19511da177e4SLinus Torvalds return(ret); 19521da177e4SLinus Torvalds } 19531da177e4SLinus Torvalds break; 19541da177e4SLinus Torvalds case FT8U232AM: 19551da177e4SLinus Torvalds case FT232BM: 19561da177e4SLinus Torvalds case FT2232C: 19571da177e4SLinus Torvalds /* the 8U232AM returns a two byte value (the sio is a 1 byte value) - in the same 19581da177e4SLinus Torvalds format as the data returned from the in point */ 19591da177e4SLinus Torvalds if ((ret = usb_control_msg(port->serial->dev, 19601da177e4SLinus Torvalds usb_rcvctrlpipe(port->serial->dev, 0), 19611da177e4SLinus Torvalds FTDI_SIO_GET_MODEM_STATUS_REQUEST, 19621da177e4SLinus Torvalds FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 19631da177e4SLinus Torvalds 0, priv->interface, 19641da177e4SLinus Torvalds buf, 2, WDR_TIMEOUT)) < 0 ) { 19651da177e4SLinus Torvalds err("%s Could not get modem status of device - err: %d", __FUNCTION__, 19661da177e4SLinus Torvalds ret); 19671da177e4SLinus Torvalds return(ret); 19681da177e4SLinus Torvalds } 19691da177e4SLinus Torvalds break; 19701da177e4SLinus Torvalds default: 19711da177e4SLinus Torvalds return -EFAULT; 19721da177e4SLinus Torvalds break; 19731da177e4SLinus Torvalds } 19741da177e4SLinus Torvalds 19751da177e4SLinus Torvalds return (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) | 19761da177e4SLinus Torvalds (buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) | 19771da177e4SLinus Torvalds (buf[0] & FTDI_SIO_RI_MASK ? TIOCM_RI : 0) | 19781da177e4SLinus Torvalds (buf[0] & FTDI_SIO_RLSD_MASK ? TIOCM_CD : 0) | 19791da177e4SLinus Torvalds priv->last_dtr_rts; 19801da177e4SLinus Torvalds } 19811da177e4SLinus Torvalds 19821da177e4SLinus Torvalds static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear) 19831da177e4SLinus Torvalds { 19841da177e4SLinus Torvalds dbg("%s TIOCMSET", __FUNCTION__); 198574ede0ffSIan Abbott return update_mctrl(port, set, clear); 19861da177e4SLinus Torvalds } 19871da177e4SLinus Torvalds 19881da177e4SLinus Torvalds 19891da177e4SLinus Torvalds static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 19901da177e4SLinus Torvalds { 19911da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 19921da177e4SLinus Torvalds 19931da177e4SLinus Torvalds dbg("%s cmd 0x%04x", __FUNCTION__, cmd); 19941da177e4SLinus Torvalds 19951da177e4SLinus Torvalds /* Based on code from acm.c and others */ 19961da177e4SLinus Torvalds switch (cmd) { 19971da177e4SLinus Torvalds 19981da177e4SLinus Torvalds case TIOCGSERIAL: /* gets serial port data */ 19991da177e4SLinus Torvalds return get_serial_info(port, (struct serial_struct __user *) arg); 20001da177e4SLinus Torvalds 20011da177e4SLinus Torvalds case TIOCSSERIAL: /* sets serial port data */ 20021da177e4SLinus Torvalds return set_serial_info(port, (struct serial_struct __user *) arg); 20031da177e4SLinus Torvalds 20041da177e4SLinus Torvalds /* 20051da177e4SLinus Torvalds * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 20061da177e4SLinus Torvalds * - mask passed in arg for lines of interest 20071da177e4SLinus Torvalds * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 20081da177e4SLinus Torvalds * Caller should use TIOCGICOUNT to see which one it was. 20091da177e4SLinus Torvalds * 20101da177e4SLinus Torvalds * This code is borrowed from linux/drivers/char/serial.c 20111da177e4SLinus Torvalds */ 20121da177e4SLinus Torvalds case TIOCMIWAIT: 20131da177e4SLinus Torvalds while (priv != NULL) { 20141da177e4SLinus Torvalds interruptible_sleep_on(&priv->delta_msr_wait); 20151da177e4SLinus Torvalds /* see if a signal did it */ 20161da177e4SLinus Torvalds if (signal_pending(current)) 20171da177e4SLinus Torvalds return -ERESTARTSYS; 20181da177e4SLinus Torvalds else { 20191da177e4SLinus Torvalds char diff = priv->diff_status; 20201da177e4SLinus Torvalds 20211da177e4SLinus Torvalds if (diff == 0) { 20221da177e4SLinus Torvalds return -EIO; /* no change => error */ 20231da177e4SLinus Torvalds } 20241da177e4SLinus Torvalds 20251da177e4SLinus Torvalds /* Consume all events */ 20261da177e4SLinus Torvalds priv->diff_status = 0; 20271da177e4SLinus Torvalds 20281da177e4SLinus Torvalds /* Return 0 if caller wanted to know about these bits */ 20291da177e4SLinus Torvalds if ( ((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) || 20301da177e4SLinus Torvalds ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) || 20311da177e4SLinus Torvalds ((arg & TIOCM_CD) && (diff & FTDI_RS0_RLSD)) || 20321da177e4SLinus Torvalds ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS)) ) { 20331da177e4SLinus Torvalds return 0; 20341da177e4SLinus Torvalds } 20351da177e4SLinus Torvalds /* 20361da177e4SLinus Torvalds * Otherwise caller can't care less about what happened, 20371da177e4SLinus Torvalds * and so we continue to wait for more events. 20381da177e4SLinus Torvalds */ 20391da177e4SLinus Torvalds } 20401da177e4SLinus Torvalds } 20411da177e4SLinus Torvalds return(0); 20421da177e4SLinus Torvalds break; 20431da177e4SLinus Torvalds default: 20441da177e4SLinus Torvalds break; 20451da177e4SLinus Torvalds 20461da177e4SLinus Torvalds } 20471da177e4SLinus Torvalds 20481da177e4SLinus Torvalds 20491da177e4SLinus Torvalds /* This is not necessarily an error - turns out the higher layers will do 20501da177e4SLinus Torvalds * some ioctls itself (see comment above) 20511da177e4SLinus Torvalds */ 20521da177e4SLinus Torvalds dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __FUNCTION__, cmd); 20531da177e4SLinus Torvalds 20541da177e4SLinus Torvalds return(-ENOIOCTLCMD); 20551da177e4SLinus Torvalds } /* ftdi_ioctl */ 20561da177e4SLinus Torvalds 20571da177e4SLinus Torvalds 20581da177e4SLinus Torvalds static void ftdi_throttle (struct usb_serial_port *port) 20591da177e4SLinus Torvalds { 20601da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 20611da177e4SLinus Torvalds unsigned long flags; 20621da177e4SLinus Torvalds 20631da177e4SLinus Torvalds dbg("%s - port %d", __FUNCTION__, port->number); 20641da177e4SLinus Torvalds 20651da177e4SLinus Torvalds spin_lock_irqsave(&priv->rx_lock, flags); 20661da177e4SLinus Torvalds priv->rx_flags |= THROTTLED; 20671da177e4SLinus Torvalds spin_unlock_irqrestore(&priv->rx_lock, flags); 20681da177e4SLinus Torvalds } 20691da177e4SLinus Torvalds 20701da177e4SLinus Torvalds 20711da177e4SLinus Torvalds static void ftdi_unthrottle (struct usb_serial_port *port) 20721da177e4SLinus Torvalds { 20731da177e4SLinus Torvalds struct ftdi_private *priv = usb_get_serial_port_data(port); 20741da177e4SLinus Torvalds int actually_throttled; 20751da177e4SLinus Torvalds unsigned long flags; 20761da177e4SLinus Torvalds 20771da177e4SLinus Torvalds dbg("%s - port %d", __FUNCTION__, port->number); 20781da177e4SLinus Torvalds 20791da177e4SLinus Torvalds spin_lock_irqsave(&priv->rx_lock, flags); 20801da177e4SLinus Torvalds actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; 20811da177e4SLinus Torvalds priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); 20821da177e4SLinus Torvalds spin_unlock_irqrestore(&priv->rx_lock, flags); 20831da177e4SLinus Torvalds 20841da177e4SLinus Torvalds if (actually_throttled) 208576854ceaSIan Abbott schedule_work(&priv->rx_work); 20861da177e4SLinus Torvalds } 20871da177e4SLinus Torvalds 20881da177e4SLinus Torvalds static int __init ftdi_init (void) 20891da177e4SLinus Torvalds { 20901da177e4SLinus Torvalds int retval; 20911da177e4SLinus Torvalds 20921da177e4SLinus Torvalds dbg("%s", __FUNCTION__); 2093fdcb0a0fSIan Abbott if (vendor > 0 && product > 0) { 2094fdcb0a0fSIan Abbott /* Add user specified VID/PID to reserved element of table. */ 2095fdcb0a0fSIan Abbott int i; 2096fdcb0a0fSIan Abbott for (i = 0; id_table_combined[i].idVendor; i++) 2097fdcb0a0fSIan Abbott ; 2098fdcb0a0fSIan Abbott id_table_combined[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 2099fdcb0a0fSIan Abbott id_table_combined[i].idVendor = vendor; 2100fdcb0a0fSIan Abbott id_table_combined[i].idProduct = product; 2101fdcb0a0fSIan Abbott } 21028f977e42SIan Abbott retval = usb_serial_register(&ftdi_sio_device); 21031da177e4SLinus Torvalds if (retval) 21048f977e42SIan Abbott goto failed_sio_register; 21051da177e4SLinus Torvalds retval = usb_register(&ftdi_driver); 21061da177e4SLinus Torvalds if (retval) 21071da177e4SLinus Torvalds goto failed_usb_register; 21081da177e4SLinus Torvalds 21091da177e4SLinus Torvalds info(DRIVER_VERSION ":" DRIVER_DESC); 21101da177e4SLinus Torvalds return 0; 21111da177e4SLinus Torvalds failed_usb_register: 21128f977e42SIan Abbott usb_serial_deregister(&ftdi_sio_device); 21138f977e42SIan Abbott failed_sio_register: 21141da177e4SLinus Torvalds return retval; 21151da177e4SLinus Torvalds } 21161da177e4SLinus Torvalds 21171da177e4SLinus Torvalds 21181da177e4SLinus Torvalds static void __exit ftdi_exit (void) 21191da177e4SLinus Torvalds { 21201da177e4SLinus Torvalds 21211da177e4SLinus Torvalds dbg("%s", __FUNCTION__); 21221da177e4SLinus Torvalds 21231da177e4SLinus Torvalds usb_deregister (&ftdi_driver); 21248f977e42SIan Abbott usb_serial_deregister (&ftdi_sio_device); 21251da177e4SLinus Torvalds 21261da177e4SLinus Torvalds } 21271da177e4SLinus Torvalds 21281da177e4SLinus Torvalds 21291da177e4SLinus Torvalds module_init(ftdi_init); 21301da177e4SLinus Torvalds module_exit(ftdi_exit); 21311da177e4SLinus Torvalds 21321da177e4SLinus Torvalds MODULE_AUTHOR( DRIVER_AUTHOR ); 21331da177e4SLinus Torvalds MODULE_DESCRIPTION( DRIVER_DESC ); 21341da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 21351da177e4SLinus Torvalds 21361da177e4SLinus Torvalds module_param(debug, bool, S_IRUGO | S_IWUSR); 21371da177e4SLinus Torvalds MODULE_PARM_DESC(debug, "Debug enabled or not"); 2138fdcb0a0fSIan Abbott module_param(vendor, ushort, 0); 2139fdcb0a0fSIan Abbott MODULE_PARM_DESC(vendor, "User specified vendor ID (default=" 2140fdcb0a0fSIan Abbott __MODULE_STRING(FTDI_VID)")"); 2141fdcb0a0fSIan Abbott module_param(product, ushort, 0); 2142fdcb0a0fSIan Abbott MODULE_PARM_DESC(vendor, "User specified product ID"); 21431da177e4SLinus Torvalds 2144