ftdi_sio.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:37k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * USB FTDI SIO driver
  3.  *
  4.  *  Copyright (C) 1999 - 2001
  5.  *      Greg Kroah-Hartman (greg@kroah.com)
  6.  *          Bill Ryder (bryder@sgi.com)
  7.  * Copyright (C) 2002
  8.  *     Kuba Ober (kuba@mareimbrium.org)
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  * See Documentation/usb/usb-serial.txt for more information on using this driver
  16.  *
  17.  * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
  18.  * and extra documentation
  19.  *
  20.  * (25/Jul/2002) Bill Ryder inserted Dmitri's TIOCMIWAIT patch
  21.  *      Not tested by me but it doesn't break anything I use.
  22.  * 
  23.  * (04/Jan/2002) Kuba Ober
  24.  * Implemented 38400 baudrate kludge, where it can be substituted with other
  25.  *   values. That's the only way to set custom baudrates.
  26.  * Implemented TIOCSSERIAL, TIOCGSERIAL ioctl's so that setserial is happy.
  27.  * FIXME: both baudrate things should eventually go to usbserial.c as other
  28.  *   devices may need that functionality too. Actually, it can probably be
  29.  *   merged in serial.c somehow - too many drivers repeat this code over
  30.  *   and over.
  31.  * Fixed baudrate forgetfulness - open() used to reset baudrate to 9600 every time.
  32.  * Divisors for baudrates are calculated by a macro.
  33.  * Small code cleanups. Ugly whitespace changes for Plato's sake only ;-].
  34.  *
  35.  * (04/Nov/2001) Bill Ryder
  36.  * Fixed bug in read_bulk_callback where incorrect urb buffer was used.
  37.  * Cleaned up write offset calculation
  38.  * Added write_room since default values can be incorrect for sio
  39.  * Changed write_bulk_callback to use same queue_task as other drivers
  40.  *        (the previous version caused panics)
  41.  * Removed port iteration code since the device only has one I/O port and it
  42.  *   was wrong anyway.
  43.  * 
  44.  * (31/May/2001) gkh
  45.  * Switched from using spinlock to a semaphore, which fixes lots of problems.
  46.  *
  47.  * (23/May/2001)   Bill Ryder
  48.  * Added runtime debug patch (thanx Tyson D Sawyer).
  49.  * Cleaned up comments for 8U232
  50.  * Added parity, framing and overrun error handling
  51.  * Added receive break handling.
  52.  * 
  53.  * (04/08/2001) gb
  54.  * Identify version on module load.
  55.  *       
  56.  * (18/March/2001) Bill Ryder
  57.  * (Not released)
  58.  * Added send break handling. (requires kernel patch too)
  59.  * Fixed 8U232AM hardware RTS/CTS etc status reporting.
  60.  * Added flipbuf fix copied from generic device
  61.  * 
  62.  * (12/3/2000) Bill Ryder
  63.  * Added support for 8U232AM device.
  64.  * Moved PID and VIDs into header file only.
  65.  * Turned on low-latency for the tty (device will do high baudrates)
  66.  * Added shutdown routine to close files when device removed.
  67.  * More debug and error message cleanups.
  68.  *
  69.  * (11/13/2000) Bill Ryder
  70.  * Added spinlock protected open code and close code.
  71.  * Multiple opens work (sort of - see webpage mentioned above).
  72.  * Cleaned up comments. Removed multiple PID/VID definitions.
  73.  * Factorised cts/dtr code
  74.  * Made use of __FUNCTION__ in dbg's
  75.  *      
  76.  * (11/01/2000) Adam J. Richter
  77.  * usb_device_id table support
  78.  * 
  79.  * (10/05/2000) gkh
  80.  * Fixed bug with urb->dev not being set properly, now that the usb
  81.  * core needs it.
  82.  * 
  83.  * (09/11/2000) gkh
  84.  * Removed DEBUG #ifdefs with call to usb_serial_debug_data
  85.  *
  86.  * (07/19/2000) gkh
  87.  * Added module_init and module_exit functions to handle the fact that this
  88.  * driver is a loadable module now.
  89.  *
  90.  * (04/04/2000) Bill Ryder 
  91.  * Fixed bugs in TCGET/TCSET ioctls (by removing them - they are
  92.  *        handled elsewhere in the tty io driver chain).
  93.  *
  94.  * (03/30/2000) Bill Ryder 
  95.  * Implemented lots of ioctls
  96.  * Fixed a race condition in write
  97.  * Changed some dbg's to errs
  98.  *
  99.  * (03/26/2000) gkh
  100.  * Split driver up into device specific pieces.
  101.  *
  102.  */
  103. /* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */
  104. /* Thanx to FTDI for so kindly providing details of the protocol required */
  105. /*   to talk to the device */
  106. /* Thanx to gkh and the rest of the usb dev group for all code I have assimilated :-) */
  107. #include <linux/config.h>
  108. #include <linux/kernel.h>
  109. #include <linux/errno.h>
  110. #include <linux/init.h>
  111. #include <linux/slab.h>
  112. #include <linux/tty.h>
  113. #include <linux/tty_driver.h>
  114. #include <linux/tty_flip.h>
  115. #include <linux/module.h>
  116. #include <linux/spinlock.h>
  117. #include <asm/uaccess.h>
  118. #include <linux/usb.h>
  119. #include <linux/serial.h>
  120. #ifdef CONFIG_USB_SERIAL_DEBUG
  121. static int debug = 1;
  122. #else
  123. static int debug;
  124. #endif
  125. #include "usb-serial.h"
  126. #include "ftdi_sio.h"
  127. /*
  128.  * Version Information
  129.  */
  130. #define DRIVER_VERSION "v1.2.1"
  131. #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>"
  132. #define DRIVER_DESC "USB FTDI Serial Converters Driver"
  133. static struct usb_device_id id_table_sio [] = {
  134. { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) },
  135. { } /* Terminating entry */
  136. };
  137. /*
  138.  * The 8U232AM has the same API as the sio except for:
  139.  * - it can support MUCH higher baudrates; up to:
  140.  *   o 921600 for RS232 and 2000000 for RS422/485 at 48MHz
  141.  *   o 230400 at 12MHz
  142.  *   so .. 8U232AM's baudrate setting codes are different
  143.  * - it has a two byte status code.
  144.  * - it returns characters every 16ms (the FTDI does it every 40ms)
  145.  */
  146. static struct usb_device_id id_table_8U232AM [] = {
  147. { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) },
  148. { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) },
  149. { } /* Terminating entry */
  150. };
  151. static __devinitdata struct usb_device_id id_table_combined [] = {
  152. { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) },
  153. { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) },
  154. { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) },
  155. { } /* Terminating entry */
  156. };
  157. MODULE_DEVICE_TABLE (usb, id_table_combined);
  158. struct ftdi_private {
  159. ftdi_chip_type_t chip_type;
  160. /* type of the device, either SIO or FT8U232AM */
  161. int baud_base; /* baud base clock for divisor setting */
  162. int custom_divisor; /* custom_divisor kludge, this is for baud_base (different from what goes to the chip!) */
  163. __u16 last_set_data_urb_value ;
  164. /* the last data state set - needed for doing a break */
  165.         int write_offset;       /* This is the offset in the usb data block to write the serial data - 
  166.  * it is different between devices
  167.  */
  168. int flags; /* some ASYNC_xxxx flags are supported */
  169.         wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
  170.   char prev_status, diff_status;        /* Used for TIOCMIWAIT */
  171. };
  172. /* Used for TIOCMIWAIT */
  173. #define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
  174. #define FTDI_STATUS_B1_MASK (FTDI_RS_BI)
  175. /* End TIOCMIWAIT */
  176. #define FTDI_IMPL_ASYNC_FLAGS = ( ASYNC_SPD_HI | ASYNC_SPD_VHI 
  177.  ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP )
  178. /* function prototypes for a FTDI serial converter */
  179. static int  ftdi_SIO_startup (struct usb_serial *serial);
  180. static int  ftdi_8U232AM_startup (struct usb_serial *serial);
  181. static void ftdi_shutdown (struct usb_serial *serial);
  182. static int  ftdi_open (struct usb_serial_port *port, struct file *filp);
  183. static void ftdi_close (struct usb_serial_port *port, struct file *filp);
  184. static int  ftdi_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
  185. static int  ftdi_write_room (struct usb_serial_port *port);
  186. static void ftdi_write_bulk_callback (struct urb *urb);
  187. static void ftdi_read_bulk_callback (struct urb *urb);
  188. static void ftdi_set_termios (struct usb_serial_port *port, struct termios * old);
  189. static int  ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
  190. static void ftdi_break_ctl (struct usb_serial_port *port, int break_state );
  191. static struct usb_serial_device_type ftdi_SIO_device = {
  192. .owner = THIS_MODULE,
  193. .name = "FTDI SIO",
  194. .id_table = id_table_sio,
  195. .num_interrupt_in = 0,
  196. .num_bulk_in = 1,
  197. .num_bulk_out = 1,
  198. .num_ports = 1,
  199. .open = ftdi_open,
  200. .close = ftdi_close,
  201. .write = ftdi_write,
  202. .write_room = ftdi_write_room,
  203. .read_bulk_callback = ftdi_read_bulk_callback,
  204. .write_bulk_callback = ftdi_write_bulk_callback,
  205. .ioctl = ftdi_ioctl,
  206. .set_termios = ftdi_set_termios,
  207. .break_ctl = ftdi_break_ctl,
  208. .startup = ftdi_SIO_startup,
  209. .shutdown = ftdi_shutdown,
  210. };
  211. static struct usb_serial_device_type ftdi_8U232AM_device = {
  212. .owner = THIS_MODULE,
  213. .name = "FTDI 8U232AM",
  214. .id_table = id_table_8U232AM,
  215. .num_interrupt_in = 0,
  216. .num_bulk_in = 1,
  217. .num_bulk_out = 1,
  218. .num_ports = 1,
  219. .open = ftdi_open,
  220. .close = ftdi_close,
  221. .write = ftdi_write,
  222. .write_room = ftdi_write_room,
  223. .read_bulk_callback = ftdi_read_bulk_callback,
  224. .write_bulk_callback = ftdi_write_bulk_callback,
  225. .ioctl = ftdi_ioctl,
  226. .set_termios = ftdi_set_termios,
  227. .break_ctl = ftdi_break_ctl,
  228. .startup = ftdi_8U232AM_startup,
  229. .shutdown = ftdi_shutdown,
  230. };
  231. #define WDR_TIMEOUT (HZ * 5 ) /* default urb timeout */
  232. #define HIGH 1
  233. #define LOW 0
  234. /*
  235.  * ***************************************************************************
  236.  * Utlity functions
  237.  * ***************************************************************************
  238.  */
  239. static int set_rts(struct usb_device *dev,
  240.    unsigned int pipe,
  241.    int high_or_low)
  242. {
  243. static char buf[1];
  244. unsigned ftdi_high_or_low = (high_or_low? FTDI_SIO_SET_RTS_HIGH : 
  245. FTDI_SIO_SET_RTS_LOW);
  246. return(usb_control_msg(dev, pipe,
  247.        FTDI_SIO_SET_MODEM_CTRL_REQUEST, 
  248.        FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
  249.        ftdi_high_or_low, 0, 
  250.        buf, 0, WDR_TIMEOUT));
  251. }
  252. static int set_dtr(struct usb_device *dev,
  253.                    unsigned int pipe,
  254.                    int high_or_low)
  255. {
  256. static char buf[1];
  257. unsigned ftdi_high_or_low = (high_or_low? FTDI_SIO_SET_DTR_HIGH : 
  258. FTDI_SIO_SET_DTR_LOW);
  259. return(usb_control_msg(dev, pipe,
  260.        FTDI_SIO_SET_MODEM_CTRL_REQUEST, 
  261.        FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
  262.        ftdi_high_or_low, 0, 
  263.        buf, 0, WDR_TIMEOUT));
  264. }
  265. static __u16 get_ftdi_divisor(struct usb_serial_port * port);
  266. static int change_speed(struct usb_serial_port *port)
  267. {
  268. char buf[1];
  269.         __u16 urb_value;
  270. urb_value = get_ftdi_divisor(port);
  271. return (usb_control_msg(port->serial->dev,
  272.     usb_sndctrlpipe(port->serial->dev, 0),
  273.     FTDI_SIO_SET_BAUDRATE_REQUEST,
  274.     FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
  275.     urb_value, 0,
  276.     buf, 0, 100) < 0);
  277. }
  278. static __u16 get_ftdi_divisor(struct usb_serial_port * port)
  279. { /* get_ftdi_divisor */
  280. struct ftdi_private * priv = (struct ftdi_private *)port->private;
  281. __u16 urb_value = 0;
  282. int baud;
  283. /*
  284.  * The logic involved in setting the baudrate can be cleanly split in 3 steps.
  285.  * Obtaining the actual baud rate is a little tricky since unix traditionally
  286.  * somehow ignored the possibility to set non-standard baud rates.
  287.  * 1. Standard baud rates are set in tty->termios->c_cflag
  288.  * 2. If these are not enough, you can set any speed using alt_speed as follows:
  289.  *    - set tty->termios->c_cflag speed to B38400
  290.  *    - set your real speed in tty->alt_speed; it gets ignored when
  291.  *      alt_speed==0, (or)
  292.  *    - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows:
  293.  *      flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP], this just
  294.  *      sets alt_speed to (HI: 57600, VHI: 115200, SHI: 230400, WARP: 460800)
  295.  * ** Steps 1, 2 are done courtesy of tty_get_baud_rate
  296.  * 3. You can also set baud rate by setting custom divisor as follows
  297.  *    - set tty->termios->c_cflag speed to B38400
  298.  *    - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows:
  299.  *      o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
  300.  *      o custom_divisor set to baud_base / your_new_baudrate
  301.  * ** Step 3 is done courtesy of code borrowed from serial.c - I should really
  302.  *    spend some time and separate+move this common code to serial.c, it is
  303.  *    replicated in nearly every serial driver you see.
  304.  */
  305. /* 1. Get the baud rate from the tty settings, this observes alt_speed hack */
  306. baud = tty_get_baud_rate(port->tty);
  307. dbg("%s - tty_get_baud_rate reports speed %d", __FUNCTION__, baud);
  308. /* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */
  309. if (baud == 38400 &&
  310.     ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
  311.      (priv->custom_divisor)) {
  312. baud = priv->baud_base / priv->custom_divisor;
  313. dbg("%s - custom divisor %d sets baud rate to %d", __FUNCTION__, priv->custom_divisor, baud);
  314. }
  315. /* 3. Convert baudrate to device-specific divisor */
  316. if (!baud) baud = 9600;
  317. switch(priv->chip_type) {
  318. case SIO: /* SIO chip */
  319. switch(baud) {
  320. case 300: urb_value = ftdi_sio_b300; break;
  321. case 600: urb_value = ftdi_sio_b600; break;
  322. case 1200: urb_value = ftdi_sio_b1200; break;
  323. case 2400: urb_value = ftdi_sio_b2400; break;
  324. case 4800: urb_value = ftdi_sio_b4800; break;
  325. case 9600: urb_value = ftdi_sio_b9600; break;
  326. case 19200: urb_value = ftdi_sio_b19200; break;
  327. case 38400: urb_value = ftdi_sio_b38400; break;
  328. case 57600: urb_value = ftdi_sio_b57600;  break;
  329. case 115200: urb_value = ftdi_sio_b115200; break;
  330. } /* baud */
  331. if (urb_value == 0)
  332. dbg("%s - Baudrate (%d) requested is not supported", __FUNCTION__,  baud);
  333. break;
  334. case FT8U232AM: /* 8U232AM chip */
  335. if (baud <= 3000000) {
  336. urb_value = FTDI_SIO_BAUD_TO_DIVISOR(baud);
  337. } else {
  338.                 dbg("%s - Baud rate too high!", __FUNCTION__);
  339. }
  340. break;
  341. } /* priv->chip_type */
  342. if (urb_value == 0) {
  343. urb_value = ftdi_sio_b9600;
  344. } else {
  345. dbg("%s - Baud rate set to %d (divisor %d) on chip %s", __FUNCTION__, baud, urb_value, (priv->chip_type == SIO) ? "SIO" : "FT8U232AM" );
  346. }
  347. return(urb_value);
  348. }
  349. static int get_serial_info(struct usb_serial_port * port, struct serial_struct * retinfo)
  350. {
  351. struct ftdi_private * priv = (struct ftdi_private*) port->private;
  352. struct serial_struct tmp;
  353. if (!retinfo)
  354. return -EFAULT;
  355. memset(&tmp, 0, sizeof(tmp));
  356. tmp.flags = priv->flags;
  357. tmp.baud_base = priv->baud_base;
  358. tmp.custom_divisor = priv->custom_divisor;
  359. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  360. return -EFAULT;
  361. return 0;
  362. } /* get_serial_info */
  363. static int set_serial_info(struct usb_serial_port * port, struct serial_struct * newinfo)
  364. { /* set_serial_info */
  365. struct ftdi_private * priv = (struct ftdi_private *) port->private;
  366. struct serial_struct new_serial;
  367. struct ftdi_private old_priv;
  368. if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
  369. return -EFAULT;
  370. old_priv = * priv;
  371. /* Do error checking and permission checking */
  372. if (!capable(CAP_SYS_ADMIN)) {
  373. if (((new_serial.flags & ~ASYNC_USR_MASK) !=
  374.      (priv->flags & ~ASYNC_USR_MASK)))
  375. return -EPERM;
  376. priv->flags = ((priv->flags & ~ASYNC_USR_MASK) |
  377.        (new_serial.flags & ASYNC_USR_MASK));
  378. priv->custom_divisor = new_serial.custom_divisor;
  379. goto check_and_exit;
  380. }
  381. if ((new_serial.baud_base != priv->baud_base) ||
  382.     (new_serial.baud_base < 9600))
  383. return -EINVAL;
  384. /* Make the changes - these are privileged changes! */
  385. priv->flags = ((priv->flags & ~ASYNC_FLAGS) |
  386.                (new_serial.flags & ASYNC_FLAGS));
  387. priv->custom_divisor = new_serial.custom_divisor;
  388. port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  389. check_and_exit:
  390. if (((old_priv.flags & ASYNC_SPD_MASK) !=
  391.      (priv->flags & ASYNC_SPD_MASK)) ||
  392.     (old_priv.custom_divisor != priv->custom_divisor)) {
  393. if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  394. port->tty->alt_speed = 57600;
  395. if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  396. port->tty->alt_speed = 115200;
  397. if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  398. port->tty->alt_speed = 230400;
  399. if ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  400. port->tty->alt_speed = 460800;
  401. change_speed(port);
  402. }
  403. return (0);
  404. } /* set_serial_info */
  405. /*
  406.  * ***************************************************************************
  407.  * FTDI driver specific functions
  408.  * ***************************************************************************
  409.  */
  410. /* Startup for the SIO chip */
  411. static int ftdi_SIO_startup (struct usb_serial *serial)
  412. {
  413. struct ftdi_private *priv;
  414. priv = serial->port->private = kmalloc(sizeof(struct ftdi_private), GFP_KERNEL);
  415. if (!priv){
  416. err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct ftdi_private));
  417. return -ENOMEM;
  418. }
  419. priv->chip_type = SIO;
  420. priv->baud_base = 12000000 / 16;
  421. priv->custom_divisor = 0;
  422. priv->write_offset = 1;
  423.   priv->prev_status = priv->diff_status = 0;
  424. /* This will push the characters through immediately rather
  425.    than queue a task to deliver them */
  426. priv->flags = ASYNC_LOW_LATENCY;
  427. return (0);
  428. }
  429. /* Startup for the 8U232AM chip */
  430. static int ftdi_8U232AM_startup (struct usb_serial *serial)
  431. {
  432. struct ftdi_private *priv;
  433. priv = serial->port->private = kmalloc(sizeof(struct ftdi_private), GFP_KERNEL);
  434. if (!priv){
  435. err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct ftdi_private));
  436. return -ENOMEM;
  437. }
  438. priv->chip_type = FT8U232AM;
  439. priv->baud_base = 48000000 / 2; /* Would be / 16, but FTDI supports 0.125, 0.25 and 0.5 divisor fractions! */
  440. priv->custom_divisor = 0;
  441. priv->write_offset = 0;
  442.         init_waitqueue_head(&priv->delta_msr_wait);
  443. /* This will push the characters through immediately rather
  444.    than queue a task to deliver them */
  445. priv->flags = ASYNC_LOW_LATENCY;
  446. return (0);
  447. }
  448. static void ftdi_shutdown (struct usb_serial *serial)
  449. {
  450. dbg("%s", __FUNCTION__);
  451. /* stop reads and writes on all ports */
  452. while (serial->port[0].open_count > 0) {
  453.         ftdi_close (&serial->port[0], NULL);
  454. }
  455. if (serial->port[0].private){
  456. kfree(serial->port[0].private);
  457. serial->port[0].private = NULL;
  458. }
  459. }
  460. static int  ftdi_open (struct usb_serial_port *port, struct file *filp)
  461. { /* ftdi_open */
  462. struct termios tmp_termios;
  463. struct usb_serial *serial = port->serial;
  464. struct ftdi_private *priv = port->private;
  465. int result = 0;
  466. char buf[1]; /* Needed for the usb_control_msg I think */
  467. dbg("%s", __FUNCTION__);
  468. port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  469. /* No error checking for this (will get errors later anyway) */
  470. /* See ftdi_sio.h for description of what is reset */
  471. usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  472. FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE, 
  473. FTDI_SIO_RESET_SIO, 
  474. 0, buf, 0, WDR_TIMEOUT);
  475. /* Termios defaults are set by usb_serial_init. We don't change
  476.    port->tty->termios - this would loose speed settings, etc.
  477.    This is same behaviour as serial.c/rs_open() - Kuba */
  478. /* ftdi_set_termios  will send usb control messages */
  479. ftdi_set_termios(port, &tmp_termios);
  480. /* FIXME: Flow control might be enabled, so it should be checked -
  481.    we have no control of defaults! */
  482. /* Turn on RTS and DTR since we are not flow controlling by default */
  483. if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0),HIGH) < 0) {
  484. err("%s Error from DTR HIGH urb", __FUNCTION__);
  485. }
  486. if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),HIGH) < 0){
  487. err("%s Error from RTS HIGH urb", __FUNCTION__);
  488. }
  489. /* Start reading from the device */
  490. FILL_BULK_URB(port->read_urb, serial->dev, 
  491.       usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
  492.       port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
  493.       ftdi_read_bulk_callback, port);
  494. result = usb_submit_urb(port->read_urb);
  495. if (result)
  496. err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
  497. return result;
  498. } /* ftdi_open */
  499. static void ftdi_close (struct usb_serial_port *port, struct file *filp)
  500. { /* ftdi_close */
  501. struct usb_serial *serial = port->serial; /* Checked in usbserial.c */
  502. unsigned int c_cflag = port->tty->termios->c_cflag;
  503. char buf[1];
  504. dbg("%s", __FUNCTION__);
  505. if (serial->dev) {
  506. if (c_cflag & HUPCL){
  507. /* Disable flow control */
  508. if (usb_control_msg(serial->dev, 
  509.     usb_sndctrlpipe(serial->dev, 0),
  510.     FTDI_SIO_SET_FLOW_CTRL_REQUEST,
  511.     FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  512.     0, 0, buf, 0, WDR_TIMEOUT) < 0) {
  513. err("error from flowcontrol urb");
  514. }     
  515. /* drop DTR */
  516. if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0), LOW) < 0){
  517. err("Error from DTR LOW urb");
  518. }
  519. /* drop RTS */
  520. if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),LOW) < 0) {
  521. err("Error from RTS LOW urb");
  522. }
  523. } /* Note change no line is hupcl is off */
  524. /* shutdown our bulk reads and writes */
  525. /* ***CHECK*** behaviour when there is nothing queued */
  526. usb_unlink_urb (port->write_urb);
  527. usb_unlink_urb (port->read_urb);
  528. }
  529. } /* ftdi_close */
  530.   
  531. /* The ftdi_sio requires the first byte to have:
  532.  *  B0 1
  533.  *  B1 0
  534.  *  B2..7 length of message excluding byte 0
  535.  */
  536. static int ftdi_write (struct usb_serial_port *port, int from_user,
  537.    const unsigned char *buf, int count)
  538. { /* ftdi_write */
  539. struct usb_serial *serial = port->serial;
  540. struct ftdi_private *priv = (struct ftdi_private *)port->private;
  541. unsigned char *first_byte = port->write_urb->transfer_buffer;
  542. int data_offset ;
  543. int result;
  544. dbg("%s port %d, %d bytes", __FUNCTION__, port->number, count);
  545. if (count == 0) {
  546. err("write request of 0 bytes");
  547. return 0;
  548. }
  549. data_offset = priv->write_offset;
  550.         dbg("data_offset set to %d",data_offset);
  551. if (port->write_urb->status == -EINPROGRESS) {
  552. dbg("%s - already writing", __FUNCTION__);
  553. return (0);
  554. }
  555. count += data_offset;
  556. count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
  557. /* Copy in the data to send */
  558. if (from_user) {
  559. if (copy_from_user(port->write_urb->transfer_buffer + data_offset,
  560.    buf, count - data_offset )){
  561. return -EFAULT;
  562. }
  563. } else {
  564. memcpy(port->write_urb->transfer_buffer + data_offset,
  565.        buf, count - data_offset );
  566. }  
  567. first_byte = port->write_urb->transfer_buffer;
  568. if (data_offset > 0){
  569. /* Write the control byte at the front of the packet*/
  570. *first_byte = 1 | ((count-data_offset) << 2) ; 
  571. }
  572. dbg("%s Bytes: %d, First Byte: 0x%02x", __FUNCTION__,count, first_byte[0]);
  573. usb_serial_debug_data (__FILE__, __FUNCTION__, count, first_byte);
  574. /* send the data out the bulk port */
  575. FILL_BULK_URB(port->write_urb, serial->dev, 
  576.       usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
  577.       port->write_urb->transfer_buffer, count,
  578.       ftdi_write_bulk_callback, port);
  579. result = usb_submit_urb(port->write_urb);
  580. if (result) {
  581. err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
  582. return 0;
  583. }
  584. dbg("%s write returning: %d", __FUNCTION__, count - data_offset);
  585. return (count - data_offset);
  586. } /* ftdi_write */
  587. static void ftdi_write_bulk_callback (struct urb *urb)
  588. {
  589. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  590. struct usb_serial *serial;
  591. dbg("%s", __FUNCTION__);
  592. if (port_paranoia_check (port, "ftdi_write_bulk_callback")) {
  593. return;
  594. }
  595. serial = port->serial;
  596. if (serial_paranoia_check (serial, "ftdi_write_bulk_callback")) {
  597. return;
  598. }
  599. if (urb->status) {
  600. dbg("nonzero write bulk status received: %d", urb->status);
  601. return;
  602. }
  603. queue_task(&port->tqueue, &tq_immediate);
  604. mark_bh(IMMEDIATE_BH);
  605. return;
  606. } /* ftdi_write_bulk_callback */
  607. static int ftdi_write_room( struct usb_serial_port *port )
  608. {
  609. struct ftdi_private *priv = (struct ftdi_private *)port->private;
  610. int room;
  611. if ( port->write_urb->status == -EINPROGRESS) {
  612. /* There is a race here with the _write routines but it won't hurt */
  613. room = 0;
  614. } else { 
  615. room = port->bulk_out_size - priv->write_offset;
  616. }
  617. return(room);
  618. } /* ftdi_write_room */
  619. static void ftdi_read_bulk_callback (struct urb *urb)
  620. { /* ftdi_read_bulk_callback */
  621. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  622. struct usb_serial *serial;
  623.         struct tty_struct *tty = port->tty ;
  624. struct ftdi_private *priv = (struct ftdi_private *) port->private;
  625. char error_flag;
  626.         unsigned char *data = urb->transfer_buffer;
  627. const int data_offset = 2;
  628. int i;
  629. int result;
  630. dbg("%s - port %d", __FUNCTION__, port->number);
  631. if (port_paranoia_check (port, "ftdi_sio_read_bulk_callback")) {
  632. return;
  633. }
  634. serial = port->serial;
  635. if (serial_paranoia_check (serial, "ftdi_sio_read_bulk_callback")) {
  636. return;
  637. }
  638. if (urb->status) {
  639. /* This will happen at close every time so it is a dbg not an err */
  640. dbg("nonzero read bulk status received: %d", urb->status);
  641. return;
  642. }
  643. if (urb->actual_length > 2) {
  644. usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
  645. } else {
  646.                 dbg("Just status 0o%03o0o%03o",data[0],data[1]);
  647.         }
  648. /* TO DO -- check for hung up line and handle appropriately: */
  649. /*   send hangup  */
  650. /* See acm.c - you do a tty_hangup  - eg tty_hangup(tty) */
  651. /* if CD is dropped and the line is not CLOCAL then we should hangup */
  652. /* Compare new line status to the old one, signal if different */
  653. if (priv != NULL) {
  654. char new_status = data[0] & FTDI_STATUS_B0_MASK;
  655. if (new_status != priv->prev_status) {
  656. priv->diff_status |= new_status ^ priv->prev_status;
  657. wake_up_interruptible(&priv->delta_msr_wait);
  658. priv->prev_status = new_status;
  659. }
  660. }
  661. /* Handle errors and break */
  662. error_flag = TTY_NORMAL;
  663.         /* Although the device uses a bitmask and hence can have multiple */
  664.         /* errors on a packet - the order here sets the priority the */
  665.         /* error is returned to the tty layer  */
  666. if ( data[1] & FTDI_RS_OE ) { 
  667. error_flag = TTY_OVERRUN;
  668.                 dbg("OVERRRUN error");
  669. }
  670. if ( data[1] & FTDI_RS_BI ) { 
  671. error_flag = TTY_BREAK;
  672.                 dbg("BREAK received");
  673. }
  674. if ( data[1] & FTDI_RS_PE ) { 
  675. error_flag = TTY_PARITY;
  676.                 dbg("PARITY error");
  677. }
  678. if ( data[1] & FTDI_RS_FE ) { 
  679. error_flag = TTY_FRAME;
  680.                 dbg("FRAMING error");
  681. }
  682. if (urb->actual_length > data_offset) {
  683. for (i = data_offset ; i < urb->actual_length ; ++i) {
  684. /* have to make sure we don't overflow the buffer
  685.   with tty_insert_flip_char's */
  686. if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
  687. tty_flip_buffer_push(tty);
  688. }
  689. /* Note that the error flag is duplicated for 
  690.    every character received since we don't know
  691.    which character it applied to */
  692. tty_insert_flip_char(tty, data[i], error_flag);
  693. }
  694.    tty_flip_buffer_push(tty);
  695. #ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
  696. /* if a parity error is detected you get status packets forever
  697.    until a character is sent without a parity error.
  698.    This doesn't work well since the application receives a never
  699.    ending stream of bad data - even though new data hasn't been sent.
  700.    Therefore I (bill) have taken this out.
  701.    However - this might make sense for framing errors and so on 
  702.    so I am leaving the code in for now.
  703. */
  704.       else {
  705. if (error_flag != TTY_NORMAL){
  706. dbg("error_flag is not normal");
  707. /* In this case it is just status - if that is an error send a bad character */
  708. if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
  709. tty_flip_buffer_push(tty);
  710. }
  711. tty_insert_flip_char(tty, 0xff, error_flag);
  712. tty_flip_buffer_push(tty);
  713. }
  714. }
  715. #endif
  716. /* Continue trying to always read  */
  717. FILL_BULK_URB(port->read_urb, serial->dev, 
  718.       usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
  719.       port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
  720.       ftdi_read_bulk_callback, port);
  721. result = usb_submit_urb(port->read_urb);
  722. if (result)
  723. err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
  724. return;
  725. } /* ftdi_read_bulk_callback */
  726. static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
  727. {
  728. struct usb_serial *serial = port->serial;
  729. struct ftdi_private *priv = (struct ftdi_private *)port->private;
  730. __u16 urb_value = 0; 
  731. char buf[1];
  732. /* break_state = -1 to turn on break, and 0 to turn off break */
  733. /* see drivers/char/tty_io.c to see it used */
  734. /* last_set_data_urb_value NEVER has the break bit set in it */
  735. if (break_state) {
  736. urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;
  737. } else {
  738. urb_value = priv->last_set_data_urb_value; 
  739. }
  740. if (usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  741.     FTDI_SIO_SET_DATA_REQUEST, 
  742.     FTDI_SIO_SET_DATA_REQUEST_TYPE,
  743.     urb_value , 0,
  744.     buf, 0, WDR_TIMEOUT) < 0) {
  745. err("%s FAILED to enable/disable break state (state was %d)", __FUNCTION__,break_state);
  746. }    
  747. dbg("%s break state is %d - urb is %d", __FUNCTION__,break_state, urb_value);
  748. }
  749. /* old_termios contains the original termios settings and tty->termios contains
  750.  * the new setting to be used
  751.  * WARNING: set_termios calls this with old_termios in kernel space
  752.  */
  753. static void ftdi_set_termios (struct usb_serial_port *port, struct termios *old_termios)
  754. { /* ftdi_termios */
  755. struct usb_serial *serial = port->serial;
  756. unsigned int cflag = port->tty->termios->c_cflag;
  757. struct ftdi_private *priv = (struct ftdi_private *)port->private;
  758. __u16 urb_value; /* will hold the new flags */
  759. char buf[1]; /* Perhaps I should dynamically alloc this? */
  760. dbg("%s", __FUNCTION__);
  761. /* FIXME -For this cut I don't care if the line is really changing or 
  762.    not  - so just do the change regardless  - should be able to 
  763.    compare old_termios and tty->termios */
  764. /* NOTE These routines can get interrupted by 
  765.    ftdi_sio_read_bulk_callback  - need to examine what this 
  766.            means - don't see any problems yet */
  767. /* Set number of data bits, parity, stop bits */
  768. urb_value = 0;
  769. urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 :
  770.       FTDI_SIO_SET_DATA_STOP_BITS_1);
  771. urb_value |= (cflag & PARENB ? 
  772.       (cflag & PARODD ? FTDI_SIO_SET_DATA_PARITY_ODD : 
  773.        FTDI_SIO_SET_DATA_PARITY_EVEN) :
  774.       FTDI_SIO_SET_DATA_PARITY_NONE);
  775. if (cflag & CSIZE) {
  776. switch (cflag & CSIZE) {
  777. case CS5: urb_value |= 5; dbg("Setting CS5"); break;
  778. case CS6: urb_value |= 6; dbg("Setting CS6"); break;
  779. case CS7: urb_value |= 7; dbg("Setting CS7"); break;
  780. case CS8: urb_value |= 8; dbg("Setting CS8"); break;
  781. default:
  782. err("CSIZE was set but not CS5-CS8");
  783. }
  784. }
  785. /* This is needed by the break command since it uses the same command - but is
  786.  *  or'ed with this value  */
  787. priv->last_set_data_urb_value = urb_value;
  788. if (usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  789.     FTDI_SIO_SET_DATA_REQUEST, 
  790.     FTDI_SIO_SET_DATA_REQUEST_TYPE,
  791.     urb_value , 0,
  792.     buf, 0, 100) < 0) {
  793. err("%s FAILED to set databits/stopbits/parity", __FUNCTION__);
  794. }    
  795. /* Now do the baudrate */
  796. if ((cflag & CBAUD) == B0 ) {
  797. /* Disable flow control */
  798. if (usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  799.     FTDI_SIO_SET_FLOW_CTRL_REQUEST, 
  800.     FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  801.     0, 0, 
  802.     buf, 0, WDR_TIMEOUT) < 0) {
  803. err("%s error from disable flowcontrol urb", __FUNCTION__);
  804. }     
  805. /* Drop RTS and DTR */
  806. if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0),LOW) < 0){
  807. err("%s Error from DTR LOW urb", __FUNCTION__);
  808. }
  809. if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),LOW) < 0){
  810. err("%s Error from RTS LOW urb", __FUNCTION__);
  811. }
  812. } else {
  813. /* set the baudrate determined before */
  814. if (change_speed(port)) {
  815. err("%s urb failed to set baurdrate", __FUNCTION__);
  816. }
  817. }
  818. /* Set flow control */
  819. /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */
  820. if (cflag & CRTSCTS) {
  821. dbg("%s Setting to CRTSCTS flow control", __FUNCTION__);
  822. if (usb_control_msg(serial->dev, 
  823.     usb_sndctrlpipe(serial->dev, 0),
  824.     FTDI_SIO_SET_FLOW_CTRL_REQUEST, 
  825.     FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  826.     0 , FTDI_SIO_RTS_CTS_HS,
  827.     buf, 0, WDR_TIMEOUT) < 0) {
  828. err("urb failed to set to rts/cts flow control");
  829. }
  830. } else { 
  831. /* CHECKME Assuming XON/XOFF handled by tty stack - not by device */
  832. dbg("%s Turning off hardware flow control", __FUNCTION__);
  833. if (usb_control_msg(serial->dev, 
  834.     usb_sndctrlpipe(serial->dev, 0),
  835.     FTDI_SIO_SET_FLOW_CTRL_REQUEST, 
  836.     FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
  837.     0, 0, 
  838.     buf, 0, WDR_TIMEOUT) < 0) {
  839. err("urb failed to clear flow control");
  840. }
  841. }
  842. return;
  843. } /* ftdi_termios */
  844. static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
  845. {
  846. struct usb_serial *serial = port->serial;
  847. struct ftdi_private *priv = (struct ftdi_private *)port->private;
  848. __u16 urb_value=0; /* Will hold the new flags */
  849. char buf[2];
  850. int  ret, mask;
  851. dbg("%s cmd 0x%04x", __FUNCTION__, cmd);
  852. /* Based on code from acm.c and others */
  853. switch (cmd) {
  854. case TIOCMGET:
  855. dbg("%s TIOCMGET", __FUNCTION__);
  856. switch (priv->chip_type) {
  857. case SIO:
  858. /* Request the status from the device */
  859. if ((ret = usb_control_msg(serial->dev, 
  860.    usb_rcvctrlpipe(serial->dev, 0),
  861.    FTDI_SIO_GET_MODEM_STATUS_REQUEST, 
  862.    FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
  863.    0, 0, 
  864.    buf, 1, WDR_TIMEOUT)) < 0 ) {
  865. err("%s Could not get modem status of device - err: %d", __FUNCTION__,
  866.     ret);
  867. return(ret);
  868. }
  869. break;
  870. case FT8U232AM:
  871. /* the 8U232AM returns a two byte value (the sio is a 1 byte value) - in the same
  872.    format as the data returned from the in point */
  873. if ((ret = usb_control_msg(serial->dev, 
  874.    usb_rcvctrlpipe(serial->dev, 0),
  875.    FTDI_SIO_GET_MODEM_STATUS_REQUEST, 
  876.    FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
  877.    0, 0, 
  878.    buf, 2, WDR_TIMEOUT)) < 0 ) {
  879. err("%s Could not get modem status of device - err: %d", __FUNCTION__,
  880.     ret);
  881. return(ret);
  882. }
  883. break;
  884. default:
  885. return -EFAULT;
  886. break;
  887. }
  888. return put_user((buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) |
  889. (buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) |
  890. (buf[0]  & FTDI_SIO_RI_MASK  ? TIOCM_RI  : 0) |
  891. (buf[0]  & FTDI_SIO_RLSD_MASK ? TIOCM_CD  : 0),
  892. (unsigned long *) arg);
  893. break;
  894. case TIOCMSET: /* Turns on and off the lines as specified by the mask */
  895. dbg("%s TIOCMSET", __FUNCTION__);
  896. if (get_user(mask, (unsigned long *) arg))
  897. return -EFAULT;
  898. urb_value = ((mask & TIOCM_DTR) ? HIGH : LOW);
  899. if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0),urb_value) < 0){
  900. err("Error from DTR set urb (TIOCMSET)");
  901. }
  902. urb_value = ((mask & TIOCM_RTS) ? HIGH : LOW);
  903. if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),urb_value) < 0){
  904. err("Error from RTS set urb (TIOCMSET)");
  905. }
  906. break;
  907. case TIOCMBIS: /* turns on (Sets) the lines as specified by the mask */
  908. dbg("%s TIOCMBIS", __FUNCTION__);
  909.           if (get_user(mask, (unsigned long *) arg))
  910. return -EFAULT;
  911.            if (mask & TIOCM_DTR){
  912. if ((ret = set_dtr(serial->dev, 
  913.    usb_sndctrlpipe(serial->dev, 0),
  914.    HIGH)) < 0) {
  915. err("Urb to set DTR failed");
  916. return(ret);
  917. }
  918. }
  919. if (mask & TIOCM_RTS) {
  920. if ((ret = set_rts(serial->dev, 
  921.    usb_sndctrlpipe(serial->dev, 0),
  922.    HIGH)) < 0){
  923. err("Urb to set RTS failed");
  924. return(ret);
  925. }
  926. }
  927. break;
  928. case TIOCMBIC: /* turns off (Clears) the lines as specified by the mask */
  929. dbg("%s TIOCMBIC", __FUNCTION__);
  930.           if (get_user(mask, (unsigned long *) arg))
  931. return -EFAULT;
  932.            if (mask & TIOCM_DTR){
  933. if ((ret = set_dtr(serial->dev, 
  934.    usb_sndctrlpipe(serial->dev, 0),
  935.    LOW)) < 0){
  936. err("Urb to unset DTR failed");
  937. return(ret);
  938. }
  939. }
  940. if (mask & TIOCM_RTS) {
  941. if ((ret = set_rts(serial->dev, 
  942.    usb_sndctrlpipe(serial->dev, 0),
  943.    LOW)) < 0){
  944. err("Urb to unset RTS failed");
  945. return(ret);
  946. }
  947. }
  948. break;
  949. /*
  950.  * I had originally implemented TCSET{A,S}{,F,W} and
  951.  * TCGET{A,S} here separately, however when testing I
  952.  * found that the higher layers actually do the termios
  953.  * conversions themselves and pass the call onto
  954.  * ftdi_sio_set_termios. 
  955.  *
  956.  */
  957. case TIOCGSERIAL: /* gets serial port data */
  958. return get_serial_info(port, (struct serial_struct *) arg);
  959. case TIOCSSERIAL: /* sets serial port data */
  960. return set_serial_info(port, (struct serial_struct *) arg);
  961. /*
  962.  * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  963.  * - mask passed in arg for lines of interest
  964.  *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  965.  * Caller should use TIOCGICOUNT to see which one it was.
  966.  *
  967.  * This code is borrowed from linux/drivers/char/serial.c
  968.  */
  969. case TIOCMIWAIT:
  970. while (priv != NULL) {
  971. interruptible_sleep_on(&priv->delta_msr_wait);
  972. /* see if a signal did it */
  973. if (signal_pending(current))
  974. return -ERESTARTSYS;
  975. else {
  976. char diff = priv->diff_status;
  977. if (diff == 0) {
  978. return -EIO; /* no change => error */
  979. }
  980. /* Consume all events */
  981. priv->diff_status = 0;
  982. /* Return 0 if caller wanted to know about these bits */
  983. if ( ((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
  984.      ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
  985.      ((arg & TIOCM_CD)  && (diff & FTDI_RS0_RLSD)) ||
  986.      ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS)) ) {
  987. return 0;
  988. }
  989. /*
  990.  * Otherwise caller can't care less about what happened,
  991.  * and so we continue to wait for more events.
  992.  */
  993. }
  994. }
  995. /* NOTREACHED */
  996. default:
  997.   /* This is not an error - turns out the higher layers will do 
  998.    *  some ioctls itself (see comment above)
  999.      */
  1000. dbg("%s arg not supported - it was 0x%04x", __FUNCTION__,cmd);
  1001. return(-ENOIOCTLCMD);
  1002. break;
  1003. }
  1004. return 0;
  1005. } /* ftdi_ioctl */
  1006. static int __init ftdi_init (void)
  1007. {
  1008. dbg("%s", __FUNCTION__);
  1009. usb_serial_register (&ftdi_SIO_device);
  1010. usb_serial_register (&ftdi_8U232AM_device);
  1011. info(DRIVER_VERSION ":" DRIVER_DESC);
  1012. return 0;
  1013. }
  1014. static void __exit ftdi_exit (void)
  1015. {
  1016. dbg("%s", __FUNCTION__);
  1017. usb_serial_deregister (&ftdi_SIO_device);
  1018. usb_serial_deregister (&ftdi_8U232AM_device);
  1019. }
  1020. module_init(ftdi_init);
  1021. module_exit(ftdi_exit);
  1022. MODULE_AUTHOR( DRIVER_AUTHOR );
  1023. MODULE_DESCRIPTION( DRIVER_DESC );
  1024. MODULE_LICENSE("GPL");
  1025. MODULE_PARM(debug, "i");
  1026. MODULE_PARM_DESC(debug, "Debug enabled or not");