ftdi_sio: Coding style

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Alan Cox
2008-07-22 11:11:23 +01:00
committed by Linus Torvalds
parent 93c467952f
commit 464cbb2469
2 changed files with 635 additions and 569 deletions

View File

@@ -12,7 +12,8 @@
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See Documentation/usb/usb-serial.txt for more information on using this driver
* See Documentation/usb/usb-serial.txt for more information on using this
* driver
*
* See http://ftdi-usb-sio.sourceforge.net for upto date testing info
* and extra documentation
@@ -25,7 +26,8 @@
/* Bill Ryder - bryder@sgi.com - wrote the FTDI_SIO implementation */
/* Thanx to FTDI for so kindly providing details of the protocol required */
/* to talk to the device */
/* Thanx to gkh and the rest of the usb dev group for all code I have assimilated :-) */
/* Thanx to gkh and the rest of the usb dev group for all code I have
assimilated :-) */
#include <linux/kernel.h>
#include <linux/errno.h>
@@ -36,7 +38,7 @@
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>
#include <linux/usb.h>
#include <linux/serial.h>
#include <linux/usb/serial.h>
@@ -55,13 +57,18 @@ static __u16 product;
struct ftdi_private {
ftdi_chip_type_t chip_type;
/* type of the device, either SIO or FT8U232AM */
/* type of device, either SIO or FT8U232AM */
int baud_base; /* baud base clock for divisor setting */
int custom_divisor; /* custom_divisor kludge, this is for baud_base (different from what goes to the chip!) */
int custom_divisor; /* custom_divisor kludge, this is for
baud_base (different from what goes to the
chip!) */
__u16 last_set_data_urb_value ;
/* the last data state set - needed for doing a break */
int write_offset; /* This is the offset in the usb data block to write the serial data -
* it is different between devices
/* the last data state set - needed for doing
* a break
*/
int write_offset; /* This is the offset in the usb data block to
* write the serial data - it varies between
* devices
*/
int flags; /* some ASYNC_xxxx flags are supported */
unsigned long last_dtr_rts; /* saved modem control outputs */
@@ -76,8 +83,10 @@ struct ftdi_private {
__u16 interface; /* FT2232C port interface (0 for FT232/245) */
speed_t force_baud; /* if non-zero, force the baud rate to this value */
int force_rtscts; /* if non-zero, force RTS-CTS to always be enabled */
speed_t force_baud; /* if non-zero, force the baud rate to
this value */
int force_rtscts; /* if non-zero, force RTS-CTS to always
be enabled */
spinlock_t tx_lock; /* spinlock for transmit state */
unsigned long tx_bytes;
@@ -88,7 +97,8 @@ struct ftdi_private {
/* struct ftdi_sio_quirk is used by devices requiring special attention. */
struct ftdi_sio_quirk {
int (*probe)(struct usb_serial *);
void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */
/* Special settings for probed ports. */
void (*port_probe)(struct ftdi_private *);
};
static int ftdi_jtag_probe(struct usb_serial *serial);
@@ -678,22 +688,29 @@ static const char *ftdi_chip_name[] = {
| ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP)
/* function prototypes for a FTDI serial converter */
static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id);
static int ftdi_sio_probe(struct usb_serial *serial,
const struct usb_device_id *id);
static void ftdi_shutdown(struct usb_serial *serial);
static int ftdi_sio_port_probe(struct usb_serial_port *port);
static int ftdi_sio_port_remove(struct usb_serial_port *port);
static int ftdi_open (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
static void ftdi_close (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
static int ftdi_write (struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count);
static int ftdi_open(struct tty_struct *tty,
struct usb_serial_port *port, struct file *filp);
static void ftdi_close(struct tty_struct *tty,
struct usb_serial_port *port, struct file *filp);
static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
const unsigned char *buf, int count);
static int ftdi_write_room(struct tty_struct *tty);
static int ftdi_chars_in_buffer(struct tty_struct *tty);
static void ftdi_write_bulk_callback(struct urb *urb);
static void ftdi_read_bulk_callback(struct urb *urb);
static void ftdi_process_read(struct work_struct *work);
static void ftdi_set_termios (struct tty_struct *tty, struct usb_serial_port *port, struct ktermios * old);
static void ftdi_set_termios(struct tty_struct *tty,
struct usb_serial_port *port, struct ktermios *old);
static int ftdi_tiocmget(struct tty_struct *tty, struct file *file);
static int ftdi_tiocmset (struct tty_struct *tty, struct file * file, unsigned int set, unsigned int clear);
static int ftdi_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg);
static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
unsigned int set, unsigned int clear);
static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg);
static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
static void ftdi_throttle(struct tty_struct *tty);
static void ftdi_unthrottle(struct tty_struct *tty);
@@ -752,44 +769,54 @@ static struct usb_serial_driver ftdi_sio_device = {
static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
{
unsigned short int divisor;
int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left
if ((divisor3 & 0x7) == 7) divisor3 ++; // round x.7/8 up to x+1
/* divisor shifted 3 bits to the left */
int divisor3 = base / 2 / baud;
if ((divisor3 & 0x7) == 7)
divisor3++; /* round x.7/8 up to x+1 */
divisor = divisor3 >> 3;
divisor3 &= 0x7;
if (divisor3 == 1) divisor |= 0xc000; else // 0.125
if (divisor3 >= 4) divisor |= 0x4000; else // 0.5
if (divisor3 != 0) divisor |= 0x8000; // 0.25
if (divisor == 1) divisor = 0; /* special case for maximum baud rate */
if (divisor3 == 1)
divisor |= 0xc000;
else if (divisor3 >= 4)
divisor |= 0x4000;
else if (divisor3 != 0)
divisor |= 0x8000;
else if (divisor == 1)
divisor = 0; /* special case for maximum baud rate */
return divisor;
}
static unsigned short int ftdi_232am_baud_to_divisor(int baud)
{
return(ftdi_232am_baud_base_to_divisor(baud, 48000000));
return ftdi_232am_baud_base_to_divisor(baud, 48000000);
}
static __u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
{
static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
__u32 divisor;
int divisor3 = base / 2 / baud; // divisor shifted 3 bits to the left
/* divisor shifted 3 bits to the left */
int divisor3 = base / 2 / baud;
divisor = divisor3 >> 3;
divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
/* Deal with special cases for highest baud rates. */
if (divisor == 1) divisor = 0; else // 1.0
if (divisor == 0x4001) divisor = 1; // 1.5
if (divisor == 1)
divisor = 0;
else if (divisor == 0x4001)
divisor = 1;
return divisor;
}
static __u32 ftdi_232bm_baud_to_divisor(int baud)
{
return(ftdi_232bm_baud_base_to_divisor(baud, 48000000));
return ftdi_232bm_baud_base_to_divisor(baud, 48000000);
}
#define set_mctrl(port, set) update_mctrl((port), (set), 0)
#define clear_mctrl(port, clear) update_mctrl((port), 0, (clear))
static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned int clear)
static int update_mctrl(struct usb_serial_port *port, unsigned int set,
unsigned int clear)
{
struct ftdi_private *priv = usb_get_serial_port_data(port);
char *buf;
@@ -843,7 +870,8 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned
}
static __u32 get_ftdi_divisor(struct tty_struct *tty, struct usb_serial_port *port)
static __u32 get_ftdi_divisor(struct tty_struct *tty,
struct usb_serial_port *port)
{ /* get_ftdi_divisor */
struct ftdi_private *priv = usb_get_serial_port_data(port);
__u32 div_value = 0;
@@ -851,45 +879,53 @@ static __u32 get_ftdi_divisor(struct tty_struct *tty, struct usb_serial_port *po
int baud;
/*
* The logic involved in setting the baudrate can be cleanly split in 3 steps.
* Obtaining the actual baud rate is a little tricky since unix traditionally
* somehow ignored the possibility to set non-standard baud rates.
* The logic involved in setting the baudrate can be cleanly split into
* 3 steps.
* 1. Standard baud rates are set in tty->termios->c_cflag
* 2. If these are not enough, you can set any speed using alt_speed as follows:
* 2. If these are not enough, you can set any speed using alt_speed as
* follows:
* - set tty->termios->c_cflag speed to B38400
* - set your real speed in tty->alt_speed; it gets ignored when
* alt_speed==0, (or)
* - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows:
* flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP], this just
* sets alt_speed to (HI: 57600, VHI: 115200, SHI: 230400, WARP: 460800)
* - call TIOCSSERIAL ioctl with (struct serial_struct) set as
* follows:
* flags & ASYNC_SPD_MASK == ASYNC_SPD_[HI, VHI, SHI, WARP],
* this just sets alt_speed to (HI: 57600, VHI: 115200,
* SHI: 230400, WARP: 460800)
* ** Steps 1, 2 are done courtesy of tty_get_baud_rate
* 3. You can also set baud rate by setting custom divisor as follows
* - set tty->termios->c_cflag speed to B38400
* - call TIOCSSERIAL ioctl with (struct serial_struct) set as follows:
* - call TIOCSSERIAL ioctl with (struct serial_struct) set as
* follows:
* o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
* o custom_divisor set to baud_base / your_new_baudrate
* ** Step 3 is done courtesy of code borrowed from serial.c - I should really
* spend some time and separate+move this common code to serial.c, it is
* replicated in nearly every serial driver you see.
* ** Step 3 is done courtesy of code borrowed from serial.c
* I should really spend some time and separate + move this common
* code to serial.c, it is replicated in nearly every serial driver
* you see.
*/
/* 1. Get the baud rate from the tty settings, this observes alt_speed hack */
/* 1. Get the baud rate from the tty settings, this observes
alt_speed hack */
baud = tty_get_baud_rate(tty);
dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud);
/* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */
/* 2. Observe async-compatible custom_divisor hack, update baudrate
if needed */
if (baud == 38400 &&
((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
(priv->custom_divisor)) {
baud = priv->baud_base / priv->custom_divisor;
dbg("%s - custom divisor %d sets baud rate to %d", __func__, priv->custom_divisor, baud);
dbg("%s - custom divisor %d sets baud rate to %d",
__func__, priv->custom_divisor, baud);
}
/* 3. Convert baudrate to device-specific divisor */
if (!baud) baud = 9600;
if (!baud)
baud = 9600;
switch (priv->chip_type) {
case SIO: /* SIO chip */
switch (baud) {
@@ -905,7 +941,8 @@ static __u32 get_ftdi_divisor(struct tty_struct *tty, struct usb_serial_port *po
case 115200: div_value = ftdi_sio_b115200; break;
} /* baud */
if (div_value == 0) {
dbg("%s - Baudrate (%d) requested is not supported", __func__, baud);
dbg("%s - Baudrate (%d) requested is not supported",
__func__, baud);
div_value = ftdi_sio_b9600;
baud = 9600;
div_okay = 0;
@@ -942,7 +979,7 @@ static __u32 get_ftdi_divisor(struct tty_struct *tty, struct usb_serial_port *po
}
tty_encode_baud_rate(tty, baud, baud);
return(div_value);
return div_value;
}
static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
@@ -978,7 +1015,8 @@ static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
static int get_serial_info(struct usb_serial_port * port, struct serial_struct __user * retinfo)
static int get_serial_info(struct usb_serial_port *port,
struct serial_struct __user *retinfo)
{
struct ftdi_private *priv = usb_get_serial_port_data(port);
struct serial_struct tmp;
@@ -1079,11 +1117,10 @@ static void ftdi_determine_type(struct usb_serial_port *port)
priv->chip_type = FT2232C;
/* Determine interface code. */
inter = serial->interface->altsetting->desc.bInterfaceNumber;
if (inter == 0) {
if (inter == 0)
priv->interface = PIT_SIOA;
} else {
else
priv->interface = PIT_SIOB;
}
/* BM-type devices have a bug where bcdDevice gets set
* to 0x200 when iSerialNumber is 0. */
if (version < 0x500) {
@@ -1117,7 +1154,8 @@ static void ftdi_determine_type(struct usb_serial_port *port)
* ***************************************************************************
*/
static ssize_t show_latency_timer(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t show_latency_timer(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct usb_serial_port *port = to_usb_serial_port(dev);
struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1143,7 +1181,8 @@ static ssize_t show_latency_timer(struct device *dev, struct device_attribute *a
}
/* Write a new value of the latency timer, in units of milliseconds. */
static ssize_t store_latency_timer(struct device *dev, struct device_attribute *attr, const char *valbuf,
static ssize_t store_latency_timer(struct device *dev,
struct device_attribute *attr, const char *valbuf,
size_t count)
{
struct usb_serial_port *port = to_usb_serial_port(dev);
@@ -1172,8 +1211,8 @@ static ssize_t store_latency_timer(struct device *dev, struct device_attribute *
/* Write an event character directly to the FTDI register. The ASCII
value is in the low 8 bits, with the enable bit in the 9th bit. */
static ssize_t store_event_char(struct device *dev, struct device_attribute *attr, const char *valbuf,
size_t count)
static ssize_t store_event_char(struct device *dev,
struct device_attribute *attr, const char *valbuf, size_t count)
{
struct usb_serial_port *port = to_usb_serial_port(dev);
struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1199,7 +1238,8 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att
return count;
}
static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer);
static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer,
store_latency_timer);
static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char);
static int create_sysfs_attrs(struct usb_serial_port *port)
@@ -1250,9 +1290,11 @@ static void remove_sysfs_attrs(struct usb_serial_port *port)
*/
/* Probe function to check for special devices */
static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id)
static int ftdi_sio_probe(struct usb_serial *serial,
const struct usb_device_id *id)
{
struct ftdi_sio_quirk *quirk = (struct ftdi_sio_quirk *)id->driver_info;
struct ftdi_sio_quirk *quirk =
(struct ftdi_sio_quirk *)id->driver_info;
if (quirk && quirk->probe) {
int ret = quirk->probe(serial);
@@ -1275,7 +1317,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
if (!priv) {
err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct ftdi_private));
err("%s- kmalloc(%Zd) failed.", __func__,
sizeof(struct ftdi_private));
return -ENOMEM;
}
@@ -1333,6 +1376,7 @@ static void ftdi_USB_UIRT_setup (struct ftdi_private *priv)
/* Setup for the HE-TIRA1 device, which requires hardwired
* baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv)
{
dbg("%s", __func__);
@@ -1463,11 +1507,13 @@ static int ftdi_open(struct tty_struct *tty,
priv->rx_processed = 0;
usb_fill_bulk_urb(port->read_urb, dev,
usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
port->read_urb->transfer_buffer,
port->read_urb->transfer_buffer_length,
ftdi_read_bulk_callback, port);
result = usb_submit_urb(port->read_urb, GFP_KERNEL);
if (result)
err("%s - failed submitting read urb, error %d", __func__, result);
err("%s - failed submitting read urb, error %d",
__func__, result);
return result;
@@ -1580,16 +1626,16 @@ static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
/* Copy data */
if (data_offset > 0) {
/* Original sio requires control byte at start of each packet. */
/* Original sio requires control byte at start of
each packet. */
int user_pktsz = PKTSZ - data_offset;
int todo = count;
unsigned char *first_byte = buffer;
const unsigned char *current_position = buf;
while (todo > 0) {
if (user_pktsz > todo) {
if (user_pktsz > todo)
user_pktsz = todo;
}
/* Write the control byte at the front of the packet*/
*first_byte = 1 | ((user_pktsz) << 2);
/* Copy data for packet */
@@ -1605,17 +1651,20 @@ static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
memcpy(buffer, buf, count);
}
usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, buffer);
usb_serial_debug_data(debug, &port->dev, __func__,
transfer_size, buffer);
/* fill the buffer and send it */
usb_fill_bulk_urb(urb, port->serial->dev,
usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
usb_sndbulkpipe(port->serial->dev,
port->bulk_out_endpointAddress),
buffer, transfer_size,
ftdi_write_bulk_callback, port);
status = usb_submit_urb(urb, GFP_ATOMIC);
if (status) {
err("%s - failed submitting write urb, error %d", __func__, status);
err("%s - failed submitting write urb, error %d",
__func__, status);
count = status;
goto error;
} else {
@@ -1738,8 +1787,10 @@ static void ftdi_read_bulk_callback(struct urb *urb)
int status = urb->status;
if (urb->number_of_packets > 0) {
err("%s transfer_buffer_length %d actual_length %d number of packets %d",__func__,
urb->transfer_buffer_length, urb->actual_length, urb->number_of_packets );
err("%s transfer_buffer_length %d actual_length %d number of packets %d",
__func__,
urb->transfer_buffer_length,
urb->actual_length, urb->number_of_packets);
err("%s transfer_flags %x ", __func__, urb->transfer_flags);
}
@@ -1760,14 +1811,13 @@ static void ftdi_read_bulk_callback(struct urb *urb)
return;
}
if (urb != port->read_urb) {
if (urb != port->read_urb)
err("%s - Not my urb!", __func__);
}
if (status) {
/* This will happen at close every time so it is a dbg not an err */
dbg("(this is ok on close) nonzero read bulk status received: "
"%d", status);
/* This will happen at close every time so it is a dbg not an
err */
dbg("(this is ok on close) nonzero read bulk status received: %d", status);
return;
}
@@ -1830,12 +1880,12 @@ static void ftdi_process_read (struct work_struct *work)
urb->actual_length - priv->rx_processed);
} else {
/* The first two bytes of every read packet are status */
if (urb->actual_length > 2) {
usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
} else {
if (urb->actual_length > 2)
usb_serial_debug_data(debug, &port->dev, __func__,
urb->actual_length, data);
else
dbg("Status only: %03oo %03oo", data[0], data[1]);
}
}
/* TO DO -- check for hung up line and handle appropriately: */
@@ -1844,16 +1894,19 @@ static void ftdi_process_read (struct work_struct *work)
/* if CD is dropped and the line is not CLOCAL then we should hangup */
need_flip = 0;
for (packet_offset = priv->rx_processed; packet_offset < urb->actual_length; packet_offset += PKTSZ) {
for (packet_offset = priv->rx_processed;
packet_offset < urb->actual_length; packet_offset += PKTSZ) {
int length;
/* Compare new line status to the old one, signal if different */
/* N.B. packet may be processed more than once, but differences
* are only processed once. */
/* Compare new line status to the old one, signal if different/
N.B. packet may be processed more than once, but differences
are only processed once. */
if (priv != NULL) {
char new_status = data[packet_offset+0] & FTDI_STATUS_B0_MASK;
char new_status = data[packet_offset + 0] &
FTDI_STATUS_B0_MASK;
if (new_status != priv->prev_status) {
priv->diff_status |= new_status ^ priv->prev_status;
priv->diff_status |=
new_status ^ priv->prev_status;
wake_up_interruptible(&priv->delta_msr_wait);
priv->prev_status = new_status;
}
@@ -1870,16 +1923,17 @@ static void ftdi_process_read (struct work_struct *work)
break;
}
if (tty_buffer_request_room(tty, length) < length) {
/* break out & wait for throttling/unthrottling to happen */
/* break out & wait for throttling/unthrottling to
happen */
dbg("%s - receive room low", __func__);
break;
}
/* Handle errors and break */
error_flag = TTY_NORMAL;
/* Although the device uses a bitmask and hence can have multiple */
/* errors on a packet - the order here sets the priority the */
/* error is returned to the tty layer */
/* Although the device uses a bitmask and hence can have
multiple errors on a packet - the order here sets the
priority the error is returned to the tty layer */
if (data[packet_offset+1] & FTDI_RS_OE) {
error_flag = TTY_OVERRUN;
@@ -1902,7 +1956,8 @@ static void ftdi_process_read (struct work_struct *work)
/* Note that the error flag is duplicated for
every character received since we don't know
which character it applied to */
tty_insert_flip_char(tty, data[packet_offset+i], error_flag);
tty_insert_flip_char(tty,
data[packet_offset + i], error_flag);
}
need_flip = 1;
}
@@ -1910,19 +1965,19 @@ static void ftdi_process_read (struct work_struct *work)
#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
/* if a parity error is detected you get status packets forever
until a character is sent without a parity error.
This doesn't work well since the application receives a never
ending stream of bad data - even though new data hasn't been sent.
Therefore I (bill) have taken this out.
This doesn't work well since the application receives a
never ending stream of bad data - even though new data
hasn't been sent. Therefore I (bill) have taken this out.
However - this might make sense for framing errors and so on
so I am leaving the code in for now.
*/
else {
if (error_flag != TTY_NORMAL) {
dbg("error_flag is not normal");
/* In this case it is just status - if that is an error send a bad character */
if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
/* In this case it is just status - if that is
an error send a bad character */
if (tty->flip.count >= TTY_FLIPBUF_SIZE)
tty_flip_buffer_push(tty);
}
tty_insert_flip_char(tty, 0xff, error_flag);
need_flip = 1;
}
@@ -1931,9 +1986,8 @@ static void ftdi_process_read (struct work_struct *work)
} /* "for(packet_offset=0..." */
/* Low latency */
if (need_flip) {
if (need_flip)
tty_flip_buffer_push(tty);
}
if (packet_offset < urb->actual_length) {
/* not completely processed - record progress */
@@ -1952,12 +2006,11 @@ static void ftdi_process_read (struct work_struct *work)
}
spin_unlock_irqrestore(&priv->rx_lock, flags);
/* if the port is closed stop trying to read */
if (port->port.count > 0){
if (port->port.count > 0)
/* delay processing of remainder */
schedule_delayed_work(&priv->rx_work, 1);
} else {
else
dbg("%s - port is closed", __func__);
}
return;
}
@@ -1968,16 +2021,17 @@ static void ftdi_process_read (struct work_struct *work)
if (port->port.count > 0) {
/* Continue trying to always read */
usb_fill_bulk_urb(port->read_urb, port->serial->dev,
usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
usb_rcvbulkpipe(port->serial->dev,
port->bulk_in_endpointAddress),
port->read_urb->transfer_buffer,
port->read_urb->transfer_buffer_length,
ftdi_read_bulk_callback, port);
result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if (result)
err("%s - failed resubmitting read urb, error %d", __func__, result);
err("%s - failed resubmitting read urb, error %d",
__func__, result);
}
return;
} /* ftdi_process_read */
@@ -1992,22 +2046,23 @@ static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
/* see drivers/char/tty_io.c to see it used */
/* last_set_data_urb_value NEVER has the break bit set in it */
if (break_state) {
if (break_state)
urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;
} else {
else
urb_value = priv->last_set_data_urb_value;
}
if (usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0),
if (usb_control_msg(port->serial->dev,
usb_sndctrlpipe(port->serial->dev, 0),
FTDI_SIO_SET_DATA_REQUEST,
FTDI_SIO_SET_DATA_REQUEST_TYPE,
urb_value , priv->interface,
buf, 0, WDR_TIMEOUT) < 0) {
err("%s FAILED to enable/disable break state (state was %d)", __func__,break_state);
err("%s FAILED to enable/disable break state (state was %d)",
__func__, break_state);
}
dbg("%s break state is %d - urb is %d", __func__,break_state, urb_value);
dbg("%s break state is %d - urb is %d", __func__,
break_state, urb_value);
}
@@ -2027,14 +2082,15 @@ static void ftdi_set_termios(struct tty_struct *tty,
__u16 urb_value; /* will hold the new flags */
char buf[1]; /* Perhaps I should dynamically alloc this? */
// Added for xon/xoff support
/* Added for xon/xoff support */
unsigned int iflag = termios->c_iflag;
unsigned char vstop;
unsigned char vstart;
dbg("%s", __func__);
/* Force baud rate if this device requires it, unless it is set to B0. */
/* Force baud rate if this device requires it, unless it is set to
B0. */
if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) {
dbg("%s: forcing baud rate for this device", __func__);
tty_encode_baud_rate(tty, priv->force_baud,
@@ -2053,8 +2109,8 @@ static void ftdi_set_termios(struct tty_struct *tty,
not - so just do the change regardless - should be able to
compare old_termios and tty->termios */
/* NOTE These routines can get interrupted by
ftdi_sio_read_bulk_callback - need to examine what this
means - don't see any problems yet */
ftdi_sio_read_bulk_callback - need to examine what this means -
don't see any problems yet */
/* Set number of data bits, parity, stop bits */
@@ -2078,8 +2134,8 @@ static void ftdi_set_termios(struct tty_struct *tty,
}
}
/* This is needed by the break command since it uses the same command - but is
* or'ed with this value */
/* This is needed by the break command since it uses the same command
- but is or'ed with this value */
priv->last_set_data_urb_value = urb_value;
if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -2104,14 +2160,12 @@ static void ftdi_set_termios(struct tty_struct *tty,
clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
} else {
/* set the baudrate determined before */
if (change_speed(tty, port)) {
if (change_speed(tty, port))
err("%s urb failed to set baudrate", __func__);
}
/* Ensure RTS and DTR are raised when baudrate changed from 0 */
if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) {
if (!old_termios || (old_termios->c_cflag & CBAUD) == B0)
set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
}
}
/* Set flow control */
/* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */
@@ -2130,15 +2184,19 @@ static void ftdi_set_termios(struct tty_struct *tty,
/*
* Xon/Xoff code
*
* Check the IXOFF status in the iflag component of the termios structure
* if IXOFF is not set, the pre-xon/xoff code is executed.
* Check the IXOFF status in the iflag component of the
* termios structure. If IXOFF is not set, the pre-xon/xoff
* code is executed.
*/
if (iflag & IXOFF) {
dbg("%s request to enable xonxoff iflag=%04x",__func__,iflag);
// Try to enable the XON/XOFF on the ftdi_sio
// Set the vstart and vstop -- could have been done up above where
// a lot of other dereferencing is done but that would be very
// inefficient as vstart and vstop are not always needed
dbg("%s request to enable xonxoff iflag=%04x",
__func__, iflag);
/* Try to enable the XON/XOFF on the ftdi_sio
* Set the vstart and vstop -- could have been done up
* above where a lot of other dereferencing is done but
* that would be very inefficient as vstart and vstop
* are not always needed.
*/
vstart = termios->c_cc[VSTART];
vstop = termios->c_cc[VSTOP];
urb_value = (vstop << 8) | (vstart);
@@ -2153,8 +2211,9 @@ static void ftdi_set_termios(struct tty_struct *tty,
err("urb failed to set to xon/xoff flow control");
}
} else {
/* else clause to only run if cfag ! CRTSCTS and iflag ! XOFF */
/* CHECKME Assuming XON/XOFF handled by tty stack - not by device */
/* else clause to only run if cflag ! CRTSCTS and iflag
* ! XOFF. CHECKME Assuming XON/XOFF handled by tty
* stack - not by device */
dbg("%s Turning off hardware flow control", __func__);
if (usb_control_msg(dev,
usb_sndctrlpipe(dev, 0),
@@ -2181,32 +2240,35 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
switch (priv->chip_type) {
case SIO:
/* Request the status from the device */
if ((ret = usb_control_msg(port->serial->dev,
ret = usb_control_msg(port->serial->dev,
usb_rcvctrlpipe(port->serial->dev, 0),
FTDI_SIO_GET_MODEM_STATUS_REQUEST,
FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
0, 0,
buf, 1, WDR_TIMEOUT)) < 0 ) {
buf, 1, WDR_TIMEOUT);
if (ret < 0) {
err("%s Could not get modem status of device - err: %d", __func__,
ret);
return(ret);
return ret;
}
break;
case FT8U232AM:
case FT232BM:
case FT2232C:
case FT232RL:
/* the 8U232AM returns a two byte value (the sio is a 1 byte value) - in the same
format as the data returned from the in point */
if ((ret = usb_control_msg(port->serial->dev,
/* the 8U232AM returns a two byte value (the sio is a 1 byte
value) - in the same format as the data returned from the in
point */
ret = usb_control_msg(port->serial->dev,
usb_rcvctrlpipe(port->serial->dev, 0),
FTDI_SIO_GET_MODEM_STATUS_REQUEST,
FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
0, priv->interface,
buf, 2, WDR_TIMEOUT)) < 0 ) {
buf, 2, WDR_TIMEOUT);
if (ret < 0) {
err("%s Could not get modem status of device - err: %d", __func__,
ret);
return(ret);
return ret;
}
break;
default:
@@ -2230,7 +2292,8 @@ static int ftdi_tiocmset(struct tty_struct *tty, struct file * file,
}
static int ftdi_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct usb_serial_port *port = tty->driver_data;
struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -2241,10 +2304,12 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file * file, unsigned int c
switch (cmd) {
case TIOCGSERIAL: /* gets serial port data */
return get_serial_info(port, (struct serial_struct __user *) arg);
return get_serial_info(port,
(struct serial_struct __user *) arg);
case TIOCSSERIAL: /* sets serial port data */
return set_serial_info(tty, port, (struct serial_struct __user *) arg);
return set_serial_info(tty, port,
(struct serial_struct __user *) arg);
/*
* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
@@ -2263,14 +2328,14 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file * file, unsigned int c
else {
char diff = priv->diff_status;
if (diff == 0) {
if (diff == 0)
return -EIO; /* no change => error */
}
/* Consume all events */
priv->diff_status = 0;
/* Return 0 if caller wanted to know about these bits */
/* Return 0 if caller wanted to know about
these bits */
if (((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
((arg & TIOCM_CD) && (diff & FTDI_RS0_RLSD)) ||
@@ -2278,8 +2343,9 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file * file, unsigned int c
return 0;
}
/*
* Otherwise caller can't care less about what happened,
* and so we continue to wait for more events.
* Otherwise caller can't care less about what
* happened,and so we continue to wait for more
* events.
*/
}
}
@@ -2287,8 +2353,8 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file * file, unsigned int c
default:
break;
}
/* This is not necessarily an error - turns out the higher layers will do
* some ioctls itself (see comment above)
/* This is not necessarily an error - turns out the higher layers
* will do some ioctls themselves (see comment above)
*/
dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd);
return -ENOIOCTLCMD;