Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 813a224f authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds
Browse files

cypress_m8: coding style



Coding style clean ups

Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b9c52f15
Loading
Loading
Loading
Loading
+324 −293
Original line number Diff line number Diff line
@@ -11,19 +11,21 @@
 * 	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://geocities.com/i0xox0i for information on this driver and the
 * earthmate usb device.
 *
 *  Lonnie Mendez <dignome@gmail.com>
 *  4-29-2005
 *	Fixed problem where setting or retreiving the serial config would fail with
 * 	EPIPE.  Removed CRTS toggling so the driver behaves more like other usbserial
 * 	adapters.  Issued new interval of 1ms instead of the default 10ms.  As a
 * 	result, transfer speed has been substantially increased.  From avg. 850bps to
 * 	avg. 3300bps.  initial termios has also been modified.  Cleaned up code and
 * 	formatting issues so it is more readable.  Replaced the C++ style comments.
 *	Fixed problem where setting or retreiving the serial config would fail
 *	with EPIPE.  Removed CRTS toggling so the driver behaves more like
 *	other usbserial adapters.  Issued new interval of 1ms instead of the
 *	default 10ms.  As a result, transfer speed has been substantially
 *	increased from avg. 850bps to avg. 3300bps.  initial termios has also
 *	been modified.  Cleaned up code and formatting issues so it is more
 *	readable.  Replaced the C++ style comments.
 *
 *  Lonnie Mendez <dignome@gmail.com>
 *  12-15-2004
@@ -42,7 +44,8 @@
 *
 */

/* Thanks to Neil Whelchel for writing the first cypress m8 implementation for linux. */
/* Thanks to Neil Whelchel for writing the first cypress m8 implementation
   for linux. */
/* Thanks to cypress for providing references for the hid reports. */
/* Thanks to Jiang Zhang for providing links and for general help. */
/* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/
@@ -62,7 +65,7 @@
#include <linux/usb/serial.h>
#include <linux/serial.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>

#include "cypress_m8.h"

@@ -146,11 +149,13 @@ struct cypress_private {
	__u8 rx_flags;			   /* throttling - used from whiteheat/ftdi_sio */
	enum packet_format pkt_fmt;	   /* format to use for packet send / receive */
	int get_cfg_unsafe;		   /* If true, the CYPRESS_GET_CONFIG is unsafe */
	int baud_rate;			   /* stores current baud rate in integer form */
	int baud_rate;			   /* stores current baud rate in
					      integer form */
	int isthrottled;		   /* if throttled, discard reads */
	wait_queue_head_t delta_msr_wait;  /* used for TIOCMIWAIT */
	char prev_status, diff_status;	   /* used for TIOCMIWAIT */
	/* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
	/* we pass a pointer to this as the arguement sent to
	   cypress_set_termios old_termios */
	struct ktermios tmp_termios; 	   /* stores the old termios settings */
};

@@ -167,15 +172,21 @@ static int cypress_earthmate_startup (struct usb_serial *serial);
static int  cypress_hidcom_startup(struct usb_serial *serial);
static int  cypress_ca42v2_startup(struct usb_serial *serial);
static void cypress_shutdown(struct usb_serial *serial);
static int  cypress_open		(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
static void cypress_close		(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
static int  cypress_write		(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count);
static int  cypress_open(struct tty_struct *tty,
			struct usb_serial_port *port, struct file *filp);
static void cypress_close(struct tty_struct *tty,
			struct usb_serial_port *port, struct file *filp);
static int  cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
			const unsigned char *buf, int count);
static void cypress_send(struct usb_serial_port *port);
static int  cypress_write_room(struct tty_struct *tty);
static int  cypress_ioctl		(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg);
static void cypress_set_termios		(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios * old);
static int  cypress_ioctl(struct tty_struct *tty, struct file *file,
			unsigned int cmd, unsigned long arg);
static void cypress_set_termios(struct tty_struct *tty,
			struct usb_serial_port *port, struct ktermios *old);
static int  cypress_tiocmget(struct tty_struct *tty, struct file *file);
static int  cypress_tiocmset		(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear);
static int  cypress_tiocmset(struct tty_struct *tty, struct file *file,
			unsigned int set, unsigned int clear);
static int  cypress_chars_in_buffer(struct tty_struct *tty);
static void cypress_throttle(struct tty_struct *tty);
static void cypress_unthrottle(struct tty_struct *tty);
@@ -188,8 +199,10 @@ static void cypress_buf_free(struct cypress_buf *cb);
static void cypress_buf_clear(struct cypress_buf *cb);
static unsigned int cypress_buf_data_avail(struct cypress_buf *cb);
static unsigned int cypress_buf_space_avail(struct cypress_buf *cb);
static unsigned int	  cypress_buf_put(struct cypress_buf *cb, const char *buf, unsigned int count);
static unsigned int	  cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count);
static unsigned int cypress_buf_put(struct cypress_buf *cb,
					const char *buf, unsigned int count);
static unsigned int cypress_buf_get(struct cypress_buf *cb,
					char *buf, unsigned int count);


static struct usb_serial_driver cypress_earthmate_device = {
@@ -355,12 +368,12 @@ static int cypress_serial_control (struct tty_struct *tty,
				    __func__, new_baudrate);
			}
		}
			dbg("%s - baud rate is being sent as %d", __func__, new_baudrate);
		dbg("%s - baud rate is being sent as %d",
					__func__, new_baudrate);

		memset(feature_buffer, 0, sizeof(feature_buffer));
		/* fill the feature_buffer with new configuration */
		*((u_int32_t *)feature_buffer) = new_baudrate;

		feature_buffer[4] |= data_bits;   /* assign data bits in 2 bit space ( max 3 ) */
		/* 1 bit gap */
		feature_buffer[4] |= (stop_bits << 3);   /* assign stop bits in 1 bit space */
@@ -369,9 +382,12 @@ static int cypress_serial_control (struct tty_struct *tty,
		/* 1 bit gap */
		feature_buffer[4] |= (reset << 7);   /* assign reset at end of byte, 1 bit space */

			dbg("%s - device is being sent this feature report:", __func__);
			dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, feature_buffer[0], feature_buffer[1],
		            feature_buffer[2], feature_buffer[3], feature_buffer[4]);
		dbg("%s - device is being sent this feature report:",
								__func__);
		dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__,
			feature_buffer[0], feature_buffer[1],
			feature_buffer[2], feature_buffer[3],
			feature_buffer[4]);

		do {
			retval = usb_control_msg(port->serial->dev,
@@ -388,7 +404,8 @@ static int cypress_serial_control (struct tty_struct *tty,
			 retval != -ENODEV);

		if (retval != sizeof(feature_buffer)) {
				err("%s - failed sending serial line settings - %d", __func__, retval);
			err("%s - failed sending serial line settings - %d",
							__func__, retval);
			cypress_set_dead(port);
		} else {
			spin_lock_irqsave(&priv->lock, flags);
@@ -422,9 +439,8 @@ static int cypress_serial_control (struct tty_struct *tty,

			if (tries++ >= 3)
				break;

			} while (retval != sizeof(feature_buffer) &&
				 retval != -ENODEV);
		} while (retval != sizeof(feature_buffer)
						&& retval != -ENODEV);

		if (retval != sizeof(feature_buffer)) {
			err("%s - failed to retrieve serial line settings - %d", __func__, retval);
@@ -432,8 +448,8 @@ static int cypress_serial_control (struct tty_struct *tty,
			return retval;
		} else {
			spin_lock_irqsave(&priv->lock, flags);

				/* store the config in one byte, and later use bit masks to check values */
			/* store the config in one byte, and later
			   use bit masks to check values */
			priv->current_config = feature_buffer[4];
			priv->baud_rate = *((u_int32_t *)feature_buffer);
			spin_unlock_irqrestore(&priv->lock, flags);
@@ -502,11 +518,11 @@ static int generic_startup (struct usb_serial *serial)
	   small.  Otherwise we can use the slightly more compact
	   format.  This is in accordance with the cypress_m8 serial
	   converter app note. */
	if (port->interrupt_out_size > 9) {
	if (port->interrupt_out_size > 9)
		priv->pkt_fmt = packet_format_1;
	} else {
	else
		priv->pkt_fmt = packet_format_2;
	}

	if (interval > 0) {
		priv->write_urb_interval = interval;
		priv->read_urb_interval = interval;
@@ -543,7 +559,8 @@ static int cypress_earthmate_startup (struct usb_serial *serial)
	/* All Earthmate devices use the separated-count packet
	   format!  Idiotic. */
	priv->pkt_fmt = packet_format_1;
	if (serial->dev->descriptor.idProduct != cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
	if (serial->dev->descriptor.idProduct !=
				cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
		/* The old original USB Earthmate seemed able to
		   handle GET_CONFIG requests; everything they've
		   produced since that time crashes if this command is
@@ -650,7 +667,9 @@ static int cypress_open(struct tty_struct *tty,
	result = cypress_write(tty, port, NULL, 0);

	if (result) {
		dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __func__, result);
		dev_err(&port->dev,
			"%s - failed setting the control lines - error %d\n",
							__func__, result);
		return result;
	} else
		dbg("%s - success setting the control lines", __func__);
@@ -661,17 +680,20 @@ static int cypress_open(struct tty_struct *tty,
	/* setup the port and start reading from the device */
	if (!port->interrupt_in_urb) {
		err("%s - interrupt_in_urb is empty!", __func__);
		return(-1);
		return -1;
	}

	usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
		usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
		port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length,
		port->interrupt_in_urb->transfer_buffer,
		port->interrupt_in_urb->transfer_buffer_length,
		cypress_read_int_callback, port, priv->read_urb_interval);
	result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);

	if (result) {
		dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result);
		dev_err(&port->dev,
			"%s - failed submitting read urb, error %d\n",
							__func__, result);
		cypress_set_dead(port);
	}

@@ -792,7 +814,8 @@ static void cypress_send(struct usb_serial_port *port)
		return;

	dbg("%s - port %d", __func__, port->number);
	dbg("%s - interrupt out size is %d", __func__, port->interrupt_out_size);
	dbg("%s - interrupt out size is %d", __func__,
						port->interrupt_out_size);

	spin_lock_irqsave(&priv->lock, flags);
	if (priv->write_urb_in_use) {
@@ -803,7 +826,8 @@ static void cypress_send(struct usb_serial_port *port)
	spin_unlock_irqrestore(&priv->lock, flags);

	/* clear buffer */
	memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size);
	memset(port->interrupt_out_urb->transfer_buffer, 0,
						port->interrupt_out_size);

	spin_lock_irqsave(&priv->lock, flags);
	switch (priv->pkt_fmt) {
@@ -834,9 +858,8 @@ static void cypress_send(struct usb_serial_port *port)
	count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset],
				port->interrupt_out_size-offset);

	if (count == 0) {
	if (count == 0)
		return;
	}

	switch (priv->pkt_fmt) {
	default:
@@ -860,7 +883,8 @@ static void cypress_send(struct usb_serial_port *port)
		actual_size = count +
			      (priv->pkt_fmt == packet_format_1 ? 2 : 1);

	usb_serial_debug_data(debug, &port->dev, __func__, port->interrupt_out_size,
	usb_serial_debug_data(debug, &port->dev, __func__,
		port->interrupt_out_size,
		port->interrupt_out_urb->transfer_buffer);

	usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
@@ -869,17 +893,19 @@ static void cypress_send(struct usb_serial_port *port)
		cypress_write_int_callback, port, priv->write_urb_interval);
	result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
	if (result) {
		dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__,
			result);
		dev_err(&port->dev,
				"%s - failed submitting write urb, error %d\n",
							__func__, result);
		priv->write_urb_in_use = 0;
		cypress_set_dead(port);
	}

	spin_lock_irqsave(&priv->lock, flags);
	if (priv->cmd_ctrl) {
	if (priv->cmd_ctrl)
		priv->cmd_ctrl = 0;
	}
	priv->bytes_out += count; /* do not count the line control and size bytes */

	/* do not count the line control and size bytes */
	priv->bytes_out += count;
	spin_unlock_irqrestore(&priv->lock, flags);

	usb_serial_port_softint(port);
@@ -976,23 +1002,22 @@ static int cypress_ioctl(struct tty_struct *tty, struct file * file,
				return -ERESTARTSYS;
			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 & UART_RI)) ||
				    ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
				    ((arg & TIOCM_CD) && (diff & UART_CD)) ||
					     ((arg & TIOCM_CTS) && (diff & UART_CTS)) ) {
				    ((arg & TIOCM_CTS) && (diff & UART_CTS)))
					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.
				 */
			}
		}
@@ -1086,7 +1111,6 @@ static void cypress_set_termios(struct tty_struct *tty,
			err("%s - CSIZE was set, but not CS5-CS8",
					__func__);
			data_bits = 3;
		}
	} else
		data_bits = 3;

@@ -1104,8 +1128,10 @@ static void cypress_set_termios(struct tty_struct *tty,
			"%d data_bits (+5)", __func__, stop_bits,
			parity_enable, parity_type, data_bits);

	cypress_serial_control(tty, port, tty_get_baud_rate(tty), data_bits, stop_bits,
			parity_enable, parity_type, 0, CYPRESS_SET_CONFIG);
	cypress_serial_control(tty, port, tty_get_baud_rate(tty),
			data_bits, stop_bits,
			parity_enable, parity_type,
			0, CYPRESS_SET_CONFIG);

	/* we perform a CYPRESS_GET_CONFIG so that the current settings are
	 * filled into the private structure this should confirm that all is
@@ -1116,7 +1142,7 @@ static void cypress_set_termios(struct tty_struct *tty,
	 * termios flag base comes from empeg.c */

	spin_lock_irqsave(&priv->lock, flags);
	if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) {
	if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) {
		dbg("Using custom termios settings for a baud rate of "
				"4800bps.");
		/* define custom termios settings for NMEA protocol */
@@ -1247,7 +1273,8 @@ static void cypress_read_int_callback(struct urb *urb)
		break;
	default:
		/* something ugly is going on... */
		dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n",
		dev_err(&urb->dev->dev,
			"%s - unexpected nonzero read status received: %d\n",
							__func__, status);
		cypress_set_dead(port);
		return;
@@ -1356,7 +1383,8 @@ static void cypress_read_int_callback(struct urb *urb)
					port->interrupt_in_endpointAddress),
				port->interrupt_in_urb->transfer_buffer,
				port->interrupt_in_urb->transfer_buffer_length,
				cypress_read_int_callback, port, priv->read_urb_interval);
				cypress_read_int_callback, port,
				priv->read_urb_interval);
		result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
		if (result) {
			dev_err(&urb->dev->dev, "%s - failed resubmitting "
@@ -1403,17 +1431,18 @@ static void cypress_write_int_callback(struct urb *urb)
		result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
		if (!result)
			return;
			dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n",
		dev_err(&urb->dev->dev,
			"%s - failed resubmitting write urb, error %d\n",
							__func__, result);
		cypress_set_dead(port);
		break;
	default:
			dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n",
		dev_err(&urb->dev->dev,
			 "%s - unexpected nonzero write status received: %d\n",
							__func__, status);
		cypress_set_dead(port);
		break;
	}
	
	priv->write_urb_in_use = 0;

	/* send any buffered data */
@@ -1497,7 +1526,8 @@ static void cypress_buf_clear(struct cypress_buf *cb)
static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
{
	if (cb != NULL)
		return ((cb->buf_size + cb->buf_put - cb->buf_get) % cb->buf_size);
		return (cb->buf_size + cb->buf_put - cb->buf_get)
							% cb->buf_size;
	else
		return 0;
}
@@ -1513,7 +1543,8 @@ static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
static unsigned int cypress_buf_space_avail(struct cypress_buf *cb)
{
	if (cb != NULL)
		return ((cb->buf_size + cb->buf_get - cb->buf_put - 1) % cb->buf_size);
		return (cb->buf_size + cb->buf_get - cb->buf_put - 1)
							% cb->buf_size;
	else
		return 0;
}
+1 −1

File changed.

Contains only whitespace changes.