2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* USB Cypress M8 driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004
|
2008-07-22 10:10:36 +00:00
|
|
|
* Lonnie Mendez (dignome@gmail.com)
|
2005-04-16 22:20:36 +00:00
|
|
|
* Copyright (C) 2003,2004
|
|
|
|
* Neil Whelchel (koyama@firstlight.net)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2008-07-22 10:10:36 +00:00
|
|
|
* See Documentation/usb/usb-serial.txt for more information on using this
|
|
|
|
* driver
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* See http://geocities.com/i0xox0i for information on this driver and the
|
|
|
|
* earthmate usb device.
|
|
|
|
*/
|
|
|
|
|
2008-07-22 10:10:36 +00:00
|
|
|
/* Thanks to Neil Whelchel for writing the first cypress m8 implementation
|
|
|
|
for linux. */
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Thanks to cypress for providing references for the hid reports. */
|
|
|
|
/* Thanks to Jiang Zhang for providing links and for general help. */
|
2008-07-22 10:10:36 +00:00
|
|
|
/* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_driver.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/usb.h>
|
2006-07-12 04:22:58 +00:00
|
|
|
#include <linux/usb/serial.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/serial.h>
|
2010-05-16 18:33:50 +00:00
|
|
|
#include <linux/kfifo.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/delay.h>
|
2008-07-22 10:10:36 +00:00
|
|
|
#include <linux/uaccess.h>
|
2009-12-31 15:48:01 +00:00
|
|
|
#include <asm/unaligned.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "cypress_m8.h"
|
|
|
|
|
|
|
|
|
2012-01-12 23:02:20 +00:00
|
|
|
static bool stats;
|
2005-05-03 22:02:20 +00:00
|
|
|
static int interval;
|
2012-01-12 23:02:20 +00:00
|
|
|
static bool unstable_bauds;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>"
|
|
|
|
#define DRIVER_DESC "Cypress USB to Serial Driver"
|
|
|
|
|
|
|
|
/* write buffer size defines */
|
|
|
|
#define CYPRESS_BUF_SIZE 1024
|
|
|
|
|
2010-01-10 14:34:24 +00:00
|
|
|
static const struct usb_device_id id_table_earthmate[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
|
2005-05-10 22:09:52 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
2010-01-10 14:34:24 +00:00
|
|
|
static const struct usb_device_id id_table_cyphidcomrs232[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
|
2008-03-04 23:25:10 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
|
2013-05-31 15:09:51 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_FRWD, PRODUCT_ID_CYPHIDCOM_FRWD) },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
2010-01-10 14:34:24 +00:00
|
|
|
static const struct usb_device_id id_table_nokiaca42v2[] = {
|
2006-03-01 16:45:24 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
2010-01-10 14:34:24 +00:00
|
|
|
static const struct usb_device_id id_table_combined[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
|
2005-05-10 22:09:52 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
|
2008-03-04 23:25:10 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
|
2013-05-31 15:09:51 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_FRWD, PRODUCT_ID_CYPHIDCOM_FRWD) },
|
2006-03-01 16:45:24 +00:00
|
|
|
{ USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
2008-07-22 10:10:36 +00:00
|
|
|
MODULE_DEVICE_TABLE(usb, id_table_combined);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-11 02:23:19 +00:00
|
|
|
enum packet_format {
|
|
|
|
packet_format_1, /* b0:status, b1:payload count */
|
|
|
|
packet_format_2 /* b0[7:3]:status, b0[2:0]:payload count */
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private {
|
|
|
|
spinlock_t lock; /* private lock */
|
|
|
|
int chiptype; /* identifier of device, for quirks/etc */
|
|
|
|
int bytes_in; /* used for statistics */
|
|
|
|
int bytes_out; /* used for statistics */
|
|
|
|
int cmd_count; /* used for statistics */
|
|
|
|
int cmd_ctrl; /* always set this to 1 before issuing a command */
|
2010-05-16 18:33:50 +00:00
|
|
|
struct kfifo write_fifo; /* write fifo */
|
2005-04-16 22:20:36 +00:00
|
|
|
int write_urb_in_use; /* write urb in use indicator */
|
2006-08-30 03:06:59 +00:00
|
|
|
int write_urb_interval; /* interval to use for write urb */
|
|
|
|
int read_urb_interval; /* interval to use for read urb */
|
2006-08-30 03:07:11 +00:00
|
|
|
int comm_is_ok; /* true if communication is (still) ok */
|
2005-04-16 22:20:36 +00:00
|
|
|
int termios_initialized;
|
|
|
|
__u8 line_control; /* holds dtr / rts value */
|
|
|
|
__u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */
|
|
|
|
__u8 current_config; /* stores the current configuration byte */
|
|
|
|
__u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
|
2008-02-11 02:23:19 +00:00
|
|
|
enum packet_format pkt_fmt; /* format to use for packet send / receive */
|
2008-02-11 02:23:24 +00:00
|
|
|
int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */
|
2008-07-22 10:10:36 +00:00
|
|
|
int baud_rate; /* stores current baud rate in
|
|
|
|
integer form */
|
2005-04-16 22:20:36 +00:00
|
|
|
int isthrottled; /* if throttled, discard reads */
|
|
|
|
char prev_status, diff_status; /* used for TIOCMIWAIT */
|
tree-wide: Assorted spelling fixes
In particular, several occurances of funny versions of 'success',
'unknown', 'therefore', 'acknowledge', 'argument', 'achieve', 'address',
'beginning', 'desirable', 'separate' and 'necessary' are fixed.
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Joe Perches <joe@perches.com>
Cc: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2010-02-03 00:01:28 +00:00
|
|
|
/* we pass a pointer to this as the argument sent to
|
2008-07-22 10:10:36 +00:00
|
|
|
cypress_set_termios old_termios */
|
2006-12-08 10:38:45 +00:00
|
|
|
struct ktermios tmp_termios; /* stores the old termios settings */
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* function prototypes for the Cypress USB to serial device */
|
2012-10-17 11:34:55 +00:00
|
|
|
static int cypress_earthmate_port_probe(struct usb_serial_port *port);
|
|
|
|
static int cypress_hidcom_port_probe(struct usb_serial_port *port);
|
|
|
|
static int cypress_ca42v2_port_probe(struct usb_serial_port *port);
|
|
|
|
static int cypress_port_remove(struct usb_serial_port *port);
|
2009-09-19 20:13:26 +00:00
|
|
|
static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port);
|
2009-06-11 11:26:29 +00:00
|
|
|
static void cypress_close(struct usb_serial_port *port);
|
|
|
|
static void cypress_dtr_rts(struct usb_serial_port *port, int on);
|
2008-07-22 10:10:36 +00:00
|
|
|
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 void cypress_set_termios(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct ktermios *old);
|
2011-02-14 16:26:14 +00:00
|
|
|
static int cypress_tiocmget(struct tty_struct *tty);
|
2011-02-14 16:26:50 +00:00
|
|
|
static int cypress_tiocmset(struct tty_struct *tty,
|
2008-07-22 10:10:36 +00:00
|
|
|
unsigned int set, unsigned int clear);
|
2013-03-21 11:37:02 +00:00
|
|
|
static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg);
|
2008-07-22 10:10:36 +00:00
|
|
|
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);
|
|
|
|
static void cypress_set_dead(struct usb_serial_port *port);
|
|
|
|
static void cypress_read_int_callback(struct urb *urb);
|
|
|
|
static void cypress_write_int_callback(struct urb *urb);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-21 04:15:16 +00:00
|
|
|
static struct usb_serial_driver cypress_earthmate_device = {
|
2005-06-21 04:15:16 +00:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2005-06-21 04:15:16 +00:00
|
|
|
.name = "earthmate",
|
2005-06-21 04:15:16 +00:00
|
|
|
},
|
2005-06-21 04:15:16 +00:00
|
|
|
.description = "DeLorme Earthmate USB",
|
2005-04-16 22:20:36 +00:00
|
|
|
.id_table = id_table_earthmate,
|
|
|
|
.num_ports = 1,
|
2012-10-17 11:34:55 +00:00
|
|
|
.port_probe = cypress_earthmate_port_probe,
|
|
|
|
.port_remove = cypress_port_remove,
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = cypress_open,
|
|
|
|
.close = cypress_close,
|
2009-06-11 11:26:29 +00:00
|
|
|
.dtr_rts = cypress_dtr_rts,
|
2005-04-16 22:20:36 +00:00
|
|
|
.write = cypress_write,
|
|
|
|
.write_room = cypress_write_room,
|
|
|
|
.set_termios = cypress_set_termios,
|
|
|
|
.tiocmget = cypress_tiocmget,
|
|
|
|
.tiocmset = cypress_tiocmset,
|
2013-03-21 11:37:02 +00:00
|
|
|
.tiocmiwait = cypress_tiocmiwait,
|
2005-04-16 22:20:36 +00:00
|
|
|
.chars_in_buffer = cypress_chars_in_buffer,
|
|
|
|
.throttle = cypress_throttle,
|
|
|
|
.unthrottle = cypress_unthrottle,
|
|
|
|
.read_int_callback = cypress_read_int_callback,
|
|
|
|
.write_int_callback = cypress_write_int_callback,
|
|
|
|
};
|
|
|
|
|
2005-06-21 04:15:16 +00:00
|
|
|
static struct usb_serial_driver cypress_hidcom_device = {
|
2005-06-21 04:15:16 +00:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2005-06-21 04:15:16 +00:00
|
|
|
.name = "cyphidcom",
|
2005-06-21 04:15:16 +00:00
|
|
|
},
|
2005-06-21 04:15:16 +00:00
|
|
|
.description = "HID->COM RS232 Adapter",
|
2005-04-16 22:20:36 +00:00
|
|
|
.id_table = id_table_cyphidcomrs232,
|
|
|
|
.num_ports = 1,
|
2012-10-17 11:34:55 +00:00
|
|
|
.port_probe = cypress_hidcom_port_probe,
|
|
|
|
.port_remove = cypress_port_remove,
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = cypress_open,
|
|
|
|
.close = cypress_close,
|
2009-06-11 11:26:29 +00:00
|
|
|
.dtr_rts = cypress_dtr_rts,
|
2005-04-16 22:20:36 +00:00
|
|
|
.write = cypress_write,
|
|
|
|
.write_room = cypress_write_room,
|
|
|
|
.set_termios = cypress_set_termios,
|
|
|
|
.tiocmget = cypress_tiocmget,
|
|
|
|
.tiocmset = cypress_tiocmset,
|
2013-03-21 11:37:02 +00:00
|
|
|
.tiocmiwait = cypress_tiocmiwait,
|
2005-04-16 22:20:36 +00:00
|
|
|
.chars_in_buffer = cypress_chars_in_buffer,
|
|
|
|
.throttle = cypress_throttle,
|
|
|
|
.unthrottle = cypress_unthrottle,
|
|
|
|
.read_int_callback = cypress_read_int_callback,
|
|
|
|
.write_int_callback = cypress_write_int_callback,
|
|
|
|
};
|
|
|
|
|
2006-03-01 16:45:24 +00:00
|
|
|
static struct usb_serial_driver cypress_ca42v2_device = {
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2008-07-22 10:10:36 +00:00
|
|
|
.name = "nokiaca42v2",
|
2006-03-01 16:45:24 +00:00
|
|
|
},
|
|
|
|
.description = "Nokia CA-42 V2 Adapter",
|
|
|
|
.id_table = id_table_nokiaca42v2,
|
|
|
|
.num_ports = 1,
|
2012-10-17 11:34:55 +00:00
|
|
|
.port_probe = cypress_ca42v2_port_probe,
|
|
|
|
.port_remove = cypress_port_remove,
|
2006-03-01 16:45:24 +00:00
|
|
|
.open = cypress_open,
|
|
|
|
.close = cypress_close,
|
2009-06-11 11:26:29 +00:00
|
|
|
.dtr_rts = cypress_dtr_rts,
|
2006-03-01 16:45:24 +00:00
|
|
|
.write = cypress_write,
|
|
|
|
.write_room = cypress_write_room,
|
|
|
|
.set_termios = cypress_set_termios,
|
|
|
|
.tiocmget = cypress_tiocmget,
|
|
|
|
.tiocmset = cypress_tiocmset,
|
2013-03-21 11:37:02 +00:00
|
|
|
.tiocmiwait = cypress_tiocmiwait,
|
2006-03-01 16:45:24 +00:00
|
|
|
.chars_in_buffer = cypress_chars_in_buffer,
|
|
|
|
.throttle = cypress_throttle,
|
|
|
|
.unthrottle = cypress_unthrottle,
|
|
|
|
.read_int_callback = cypress_read_int_callback,
|
|
|
|
.write_int_callback = cypress_write_int_callback,
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-02-23 19:56:17 +00:00
|
|
|
static struct usb_serial_driver * const serial_drivers[] = {
|
|
|
|
&cypress_earthmate_device, &cypress_hidcom_device,
|
|
|
|
&cypress_ca42v2_device, NULL
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Cypress serial helper functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2013-05-31 15:09:51 +00:00
|
|
|
/* FRWD Dongle hidcom needs to skip reset and speed checks */
|
|
|
|
static inline bool is_frwd(struct usb_device *dev)
|
|
|
|
{
|
|
|
|
return ((le16_to_cpu(dev->descriptor.idVendor) == VENDOR_ID_FRWD) &&
|
|
|
|
(le16_to_cpu(dev->descriptor.idProduct) == PRODUCT_ID_CYPHIDCOM_FRWD));
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-03-10 21:59:28 +00:00
|
|
|
static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
|
2008-02-11 02:23:32 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv;
|
|
|
|
priv = usb_get_serial_port_data(port);
|
|
|
|
|
2009-12-18 21:33:03 +00:00
|
|
|
if (unstable_bauds)
|
|
|
|
return new_rate;
|
|
|
|
|
2013-05-31 15:09:51 +00:00
|
|
|
/* FRWD Dongle uses 115200 bps */
|
|
|
|
if (is_frwd(port->serial->dev))
|
|
|
|
return new_rate;
|
|
|
|
|
2008-02-11 02:23:32 +00:00
|
|
|
/*
|
|
|
|
* The general purpose firmware for the Cypress M8 allows for
|
|
|
|
* a maximum speed of 57600bps (I have no idea whether DeLorme
|
|
|
|
* chose to use the general purpose firmware or not), if you
|
|
|
|
* need to modify this speed setting for your own project
|
|
|
|
* please add your own chiptype and modify the code likewise.
|
|
|
|
* The Cypress HID->COM device will work successfully up to
|
|
|
|
* 115200bps (but the actual throughput is around 3kBps).
|
|
|
|
*/
|
|
|
|
if (port->serial->dev->speed == USB_SPEED_LOW) {
|
|
|
|
/*
|
|
|
|
* Mike Isely <isely@pobox.com> 2-Feb-2008: The
|
|
|
|
* Cypress app note that describes this mechanism
|
|
|
|
* states the the low-speed part can't handle more
|
|
|
|
* than 800 bytes/sec, in which case 4800 baud is the
|
|
|
|
* safest speed for a part like that.
|
|
|
|
*/
|
|
|
|
if (new_rate > 4800) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev,
|
|
|
|
"%s - failed setting baud rate, device incapable speed %d\n",
|
|
|
|
__func__, new_rate);
|
2008-02-11 02:23:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (priv->chiptype) {
|
|
|
|
case CT_EARTHMATE:
|
|
|
|
if (new_rate <= 600) {
|
|
|
|
/* 300 and 600 baud rates are supported under
|
|
|
|
* the generic firmware, but are not used with
|
|
|
|
* NMEA and SiRF protocols */
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev,
|
|
|
|
"%s - failed setting baud rate, unsupported speed of %d on Earthmate GPS",
|
|
|
|
__func__, new_rate);
|
2008-02-11 02:23:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return new_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-04 01:07:24 +00:00
|
|
|
/* This function can either set or retrieve the current serial line settings */
|
2008-07-22 10:10:36 +00:00
|
|
|
static int cypress_serial_control(struct tty_struct *tty,
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port, speed_t baud_rate, int data_bits,
|
|
|
|
int stop_bits, int parity_enable, int parity_type, int reset,
|
|
|
|
int cypress_request_type)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-05-03 22:02:20 +00:00
|
|
|
int new_baudrate = 0, retval = 0, tries = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv;
|
2012-09-14 16:47:38 +00:00
|
|
|
struct device *dev = &port->dev;
|
2009-12-28 22:01:48 +00:00
|
|
|
u8 *feature_buffer;
|
|
|
|
const unsigned int feature_len = 5;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
priv = usb_get_serial_port_data(port);
|
|
|
|
|
2006-08-30 03:07:11 +00:00
|
|
|
if (!priv->comm_is_ok)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2009-12-28 22:01:48 +00:00
|
|
|
feature_buffer = kcalloc(feature_len, sizeof(u8), GFP_KERNEL);
|
|
|
|
if (!feature_buffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-07-22 10:10:36 +00:00
|
|
|
switch (cypress_request_type) {
|
|
|
|
case CYPRESS_SET_CONFIG:
|
|
|
|
/* 0 means 'Hang up' so doesn't change the true bit rate */
|
2009-12-18 21:33:02 +00:00
|
|
|
new_baudrate = priv->baud_rate;
|
|
|
|
if (baud_rate && baud_rate != priv->baud_rate) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - baud rate is changing\n", __func__);
|
2008-07-22 10:10:36 +00:00
|
|
|
retval = analyze_baud_rate(port, baud_rate);
|
2009-12-18 21:33:02 +00:00
|
|
|
if (retval >= 0) {
|
2008-07-22 10:10:36 +00:00
|
|
|
new_baudrate = retval;
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - New baud rate set to %d\n",
|
|
|
|
__func__, new_baudrate);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-07-22 10:10:36 +00:00
|
|
|
}
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - baud rate is being sent as %d\n", __func__,
|
|
|
|
new_baudrate);
|
2008-07-22 10:10:36 +00:00
|
|
|
|
|
|
|
/* fill the feature_buffer with new configuration */
|
2009-12-31 15:48:01 +00:00
|
|
|
put_unaligned_le32(new_baudrate, feature_buffer);
|
2008-07-22 10:10:36 +00:00
|
|
|
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 */
|
|
|
|
feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
|
|
|
|
feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
|
|
|
|
/* 1 bit gap */
|
|
|
|
feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - device is being sent this feature report:\n", __func__);
|
|
|
|
dev_dbg(dev, "%s - %02X - %02X - %02X - %02X - %02X\n", __func__,
|
2008-07-22 10:10:36 +00:00
|
|
|
feature_buffer[0], feature_buffer[1],
|
|
|
|
feature_buffer[2], feature_buffer[3],
|
|
|
|
feature_buffer[4]);
|
|
|
|
|
|
|
|
do {
|
|
|
|
retval = usb_control_msg(port->serial->dev,
|
|
|
|
usb_sndctrlpipe(port->serial->dev, 0),
|
|
|
|
HID_REQ_SET_REPORT,
|
|
|
|
USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
|
|
|
|
0x0300, 0, feature_buffer,
|
2009-12-28 22:01:48 +00:00
|
|
|
feature_len, 500);
|
2008-07-22 10:10:36 +00:00
|
|
|
|
|
|
|
if (tries++ >= 3)
|
|
|
|
break;
|
|
|
|
|
2009-12-28 22:01:48 +00:00
|
|
|
} while (retval != feature_len &&
|
2008-07-22 10:10:36 +00:00
|
|
|
retval != -ENODEV);
|
|
|
|
|
2009-12-28 22:01:48 +00:00
|
|
|
if (retval != feature_len) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_err(dev, "%s - failed sending serial line settings - %d\n",
|
|
|
|
__func__, retval);
|
2008-07-22 10:10:36 +00:00
|
|
|
cypress_set_dead(port);
|
|
|
|
} else {
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
priv->baud_rate = new_baudrate;
|
|
|
|
priv->current_config = feature_buffer[4];
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
/* If we asked for a speed change encode it */
|
|
|
|
if (baud_rate)
|
|
|
|
tty_encode_baud_rate(tty,
|
|
|
|
new_baudrate, new_baudrate);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CYPRESS_GET_CONFIG:
|
|
|
|
if (priv->get_cfg_unsafe) {
|
|
|
|
/* Not implemented for this device,
|
|
|
|
and if we try to do it we're likely
|
|
|
|
to crash the hardware. */
|
2009-12-28 22:01:48 +00:00
|
|
|
retval = -ENOTTY;
|
|
|
|
goto out;
|
2008-07-22 10:10:36 +00:00
|
|
|
}
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - retreiving serial line settings\n", __func__);
|
2008-07-22 10:10:36 +00:00
|
|
|
do {
|
|
|
|
retval = usb_control_msg(port->serial->dev,
|
|
|
|
usb_rcvctrlpipe(port->serial->dev, 0),
|
|
|
|
HID_REQ_GET_REPORT,
|
|
|
|
USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
|
|
|
|
0x0300, 0, feature_buffer,
|
2009-12-28 22:01:48 +00:00
|
|
|
feature_len, 500);
|
2008-07-22 10:10:36 +00:00
|
|
|
|
|
|
|
if (tries++ >= 3)
|
|
|
|
break;
|
2009-12-28 22:01:48 +00:00
|
|
|
} while (retval != feature_len
|
2008-07-22 10:10:36 +00:00
|
|
|
&& retval != -ENODEV);
|
|
|
|
|
2009-12-28 22:01:48 +00:00
|
|
|
if (retval != feature_len) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_err(dev, "%s - failed to retrieve serial line settings - %d\n",
|
|
|
|
__func__, retval);
|
2008-07-22 10:10:36 +00:00
|
|
|
cypress_set_dead(port);
|
2009-12-28 22:01:48 +00:00
|
|
|
goto out;
|
2008-07-22 10:10:36 +00:00
|
|
|
} else {
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
/* store the config in one byte, and later
|
|
|
|
use bit masks to check values */
|
|
|
|
priv->current_config = feature_buffer[4];
|
2009-12-31 15:48:01 +00:00
|
|
|
priv->baud_rate = get_unaligned_le32(feature_buffer);
|
2008-07-22 10:10:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-05-03 22:02:20 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
++priv->cmd_count;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2009-12-28 22:01:48 +00:00
|
|
|
out:
|
|
|
|
kfree(feature_buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
return retval;
|
|
|
|
} /* cypress_serial_control */
|
|
|
|
|
|
|
|
|
2006-08-30 03:07:11 +00:00
|
|
|
static void cypress_set_dead(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (!priv->comm_is_ok) {
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
priv->comm_is_ok = 0;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2008-08-20 23:56:34 +00:00
|
|
|
dev_err(&port->dev, "cypress_m8 suspending failing port %d - "
|
2013-06-06 17:32:00 +00:00
|
|
|
"interval might be too short\n", port->port_number);
|
2006-08-30 03:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Cypress serial driver functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
static int cypress_generic_port_probe(struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-10-17 11:34:55 +00:00
|
|
|
struct usb_serial *serial = port->serial;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv;
|
|
|
|
|
2008-07-22 10:10:36 +00:00
|
|
|
priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2006-08-30 03:07:11 +00:00
|
|
|
priv->comm_is_ok = !0;
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_init(&priv->lock);
|
2010-05-16 18:33:50 +00:00
|
|
|
if (kfifo_alloc(&priv->write_fifo, CYPRESS_BUF_SIZE, GFP_KERNEL)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2013-05-31 15:09:51 +00:00
|
|
|
/* Skip reset for FRWD device. It is a workaound:
|
|
|
|
device hangs if it receives SET_CONFIGURE in Configured
|
|
|
|
state. */
|
|
|
|
if (!is_frwd(serial->dev))
|
|
|
|
usb_reset_configuration(serial->dev);
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->cmd_ctrl = 0;
|
|
|
|
priv->line_control = 0;
|
|
|
|
priv->termios_initialized = 0;
|
|
|
|
priv->rx_flags = 0;
|
2008-02-11 02:23:19 +00:00
|
|
|
/* Default packet format setting is determined by packet size.
|
|
|
|
Anything with a size larger then 9 must have a separate
|
|
|
|
count field since the 3 bit count field is otherwise too
|
|
|
|
small. Otherwise we can use the slightly more compact
|
|
|
|
format. This is in accordance with the cypress_m8 serial
|
|
|
|
converter app note. */
|
2008-07-22 10:10:36 +00:00
|
|
|
if (port->interrupt_out_size > 9)
|
2008-02-11 02:23:19 +00:00
|
|
|
priv->pkt_fmt = packet_format_1;
|
2008-07-22 10:10:36 +00:00
|
|
|
else
|
2008-02-11 02:23:19 +00:00
|
|
|
priv->pkt_fmt = packet_format_2;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2006-08-30 03:06:59 +00:00
|
|
|
if (interval > 0) {
|
|
|
|
priv->write_urb_interval = interval;
|
|
|
|
priv->read_urb_interval = interval;
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - read & write intervals forced to %d\n",
|
|
|
|
__func__, interval);
|
2006-08-30 03:06:59 +00:00
|
|
|
} else {
|
|
|
|
priv->write_urb_interval = port->interrupt_out_urb->interval;
|
|
|
|
priv->read_urb_interval = port->interrupt_in_urb->interval;
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - intervals: read=%d write=%d\n",
|
|
|
|
__func__, priv->read_urb_interval,
|
|
|
|
priv->write_urb_interval);
|
2006-08-30 03:06:59 +00:00
|
|
|
}
|
|
|
|
usb_set_serial_port_data(port, priv);
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
static int cypress_earthmate_port_probe(struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-10-17 11:34:55 +00:00
|
|
|
struct usb_serial *serial = port->serial;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv;
|
2012-10-17 11:34:55 +00:00
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
ret = cypress_generic_port_probe(port);
|
|
|
|
if (ret) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
|
2012-10-17 11:34:55 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-11 02:23:24 +00:00
|
|
|
priv = usb_get_serial_port_data(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->chiptype = CT_EARTHMATE;
|
2008-02-11 02:23:19 +00:00
|
|
|
/* All Earthmate devices use the separated-count packet
|
|
|
|
format! Idiotic. */
|
|
|
|
priv->pkt_fmt = packet_format_1;
|
2008-07-22 10:10:36 +00:00
|
|
|
if (serial->dev->descriptor.idProduct !=
|
|
|
|
cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
|
2008-02-11 02:23:24 +00:00
|
|
|
/* The old original USB Earthmate seemed able to
|
|
|
|
handle GET_CONFIG requests; everything they've
|
|
|
|
produced since that time crashes if this command is
|
|
|
|
attempted :-( */
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev,
|
|
|
|
"%s - Marking this device as unsafe for GET_CONFIG commands\n",
|
|
|
|
__func__);
|
2008-02-11 02:23:24 +00:00
|
|
|
priv->get_cfg_unsafe = !0;
|
|
|
|
}
|
2005-07-12 22:21:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-10-17 11:34:55 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
static int cypress_hidcom_port_probe(struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv;
|
2012-10-17 11:34:55 +00:00
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
ret = cypress_generic_port_probe(port);
|
|
|
|
if (ret) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
|
2012-10-17 11:34:55 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
priv = usb_get_serial_port_data(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->chiptype = CT_CYPHIDCOM;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
return 0;
|
2012-10-17 11:34:55 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
static int cypress_ca42v2_port_probe(struct usb_serial_port *port)
|
2006-03-01 16:45:24 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv;
|
2012-10-17 11:34:55 +00:00
|
|
|
int ret;
|
2006-03-01 16:45:24 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
ret = cypress_generic_port_probe(port);
|
|
|
|
if (ret) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
|
2012-10-17 11:34:55 +00:00
|
|
|
return ret;
|
2006-03-01 16:45:24 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
priv = usb_get_serial_port_data(port);
|
2006-03-01 16:45:24 +00:00
|
|
|
priv->chiptype = CT_CA42V2;
|
|
|
|
|
|
|
|
return 0;
|
2012-10-17 11:34:55 +00:00
|
|
|
}
|
2006-03-01 16:45:24 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
static int cypress_port_remove(struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv;
|
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
priv = usb_get_serial_port_data(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
kfifo_free(&priv->write_fifo);
|
|
|
|
kfree(priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-17 11:34:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-09-19 20:13:26 +00:00
|
|
|
static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
struct usb_serial *serial = port->serial;
|
|
|
|
unsigned long flags;
|
|
|
|
int result = 0;
|
|
|
|
|
2006-08-30 03:07:11 +00:00
|
|
|
if (!priv->comm_is_ok)
|
|
|
|
return -EIO;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* clear halts before open */
|
|
|
|
usb_clear_halt(serial->dev, 0x81);
|
|
|
|
usb_clear_halt(serial->dev, 0x02);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
/* reset read/write statistics */
|
|
|
|
priv->bytes_in = 0;
|
|
|
|
priv->bytes_out = 0;
|
|
|
|
priv->cmd_count = 0;
|
|
|
|
priv->rx_flags = 0;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2009-06-11 11:26:29 +00:00
|
|
|
/* Set termios */
|
2009-09-19 20:13:33 +00:00
|
|
|
cypress_send(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
if (tty)
|
|
|
|
cypress_set_termios(tty, port, &priv->tmp_termios);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* setup the port and start reading from the device */
|
2008-07-22 10:10:36 +00:00
|
|
|
if (!port->interrupt_in_urb) {
|
2008-08-20 23:56:34 +00:00
|
|
|
dev_err(&port->dev, "%s - interrupt_in_urb is empty!\n",
|
|
|
|
__func__);
|
2008-07-22 10:10:36 +00:00
|
|
|
return -1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
|
|
|
|
usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
|
2008-07-22 10:10:36 +00:00
|
|
|
port->interrupt_in_urb->transfer_buffer,
|
|
|
|
port->interrupt_in_urb->transfer_buffer_length,
|
2006-08-30 03:06:59 +00:00
|
|
|
cypress_read_int_callback, port, priv->read_urb_interval);
|
2005-04-16 22:20:36 +00:00
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
|
|
|
|
|
2008-07-22 10:10:36 +00:00
|
|
|
if (result) {
|
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - failed submitting read urb, error %d\n",
|
|
|
|
__func__, result);
|
2006-08-30 03:07:11 +00:00
|
|
|
cypress_set_dead(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-06-11 11:26:29 +00:00
|
|
|
port->port.drain_delay = 256;
|
2005-04-16 22:20:36 +00:00
|
|
|
return result;
|
|
|
|
} /* cypress_open */
|
|
|
|
|
2009-06-11 11:26:29 +00:00
|
|
|
static void cypress_dtr_rts(struct usb_serial_port *port, int on)
|
|
|
|
{
|
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
/* drop dtr and rts */
|
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
if (on == 0)
|
|
|
|
priv->line_control = 0;
|
|
|
|
else
|
|
|
|
priv->line_control = CONTROL_DTR | CONTROL_RTS;
|
|
|
|
priv->cmd_ctrl = 1;
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
cypress_write(NULL, port, NULL, 0);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-06-11 11:26:29 +00:00
|
|
|
static void cypress_close(struct usb_serial_port *port)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
2010-05-16 18:33:50 +00:00
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-05-16 18:33:50 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
kfifo_reset_out(&priv->write_fifo);
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - stopping urbs\n", __func__);
|
2008-07-22 10:10:36 +00:00
|
|
|
usb_kill_urb(port->interrupt_in_urb);
|
|
|
|
usb_kill_urb(port->interrupt_out_urb);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (stats)
|
2008-07-22 10:10:36 +00:00
|
|
|
dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
|
|
|
|
priv->bytes_in, priv->bytes_out, priv->cmd_count);
|
2005-04-16 22:20:36 +00:00
|
|
|
} /* cypress_close */
|
|
|
|
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
|
|
|
|
const unsigned char *buf, int count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2013-06-06 17:32:00 +00:00
|
|
|
dev_dbg(&port->dev, "%s - %d bytes\n", __func__, count);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* line control commands, which need to be executed immediately,
|
|
|
|
are not put into the buffer for obvious reasons.
|
|
|
|
*/
|
|
|
|
if (priv->cmd_ctrl) {
|
|
|
|
count = 0;
|
|
|
|
goto finish;
|
|
|
|
}
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!count)
|
|
|
|
return count;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2010-05-16 18:33:50 +00:00
|
|
|
count = kfifo_in_locked(&priv->write_fifo, buf, count, &priv->lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
finish:
|
|
|
|
cypress_send(port);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
} /* cypress_write */
|
|
|
|
|
|
|
|
|
|
|
|
static void cypress_send(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
int count = 0, result, offset, actual_size;
|
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
2012-09-14 16:47:38 +00:00
|
|
|
struct device *dev = &port->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2006-08-30 03:07:11 +00:00
|
|
|
if (!priv->comm_is_ok)
|
|
|
|
return;
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - interrupt out size is %d\n", __func__,
|
|
|
|
port->interrupt_out_size);
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (priv->write_urb_in_use) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - can't write, urb in use\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
/* clear buffer */
|
2008-07-22 10:10:36 +00:00
|
|
|
memset(port->interrupt_out_urb->transfer_buffer, 0,
|
|
|
|
port->interrupt_out_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-02-11 02:23:19 +00:00
|
|
|
switch (priv->pkt_fmt) {
|
|
|
|
default:
|
|
|
|
case packet_format_1:
|
|
|
|
/* this is for the CY7C64013... */
|
|
|
|
offset = 2;
|
|
|
|
port->interrupt_out_buffer[0] = priv->line_control;
|
|
|
|
break;
|
|
|
|
case packet_format_2:
|
|
|
|
/* this is for the CY7C63743... */
|
|
|
|
offset = 1;
|
|
|
|
port->interrupt_out_buffer[0] = priv->line_control;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->line_control & CONTROL_RESET)
|
|
|
|
priv->line_control &= ~CONTROL_RESET;
|
|
|
|
|
|
|
|
if (priv->cmd_ctrl) {
|
|
|
|
priv->cmd_count++;
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - line control command being issued\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
goto send;
|
|
|
|
} else
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2010-05-16 18:33:50 +00:00
|
|
|
count = kfifo_out_locked(&priv->write_fifo,
|
|
|
|
&port->interrupt_out_buffer[offset],
|
|
|
|
port->interrupt_out_size - offset,
|
|
|
|
&priv->lock);
|
2008-07-22 10:10:36 +00:00
|
|
|
if (count == 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
2008-02-11 02:23:19 +00:00
|
|
|
switch (priv->pkt_fmt) {
|
|
|
|
default:
|
|
|
|
case packet_format_1:
|
|
|
|
port->interrupt_out_buffer[1] = count;
|
|
|
|
break;
|
|
|
|
case packet_format_2:
|
|
|
|
port->interrupt_out_buffer[0] |= count;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - count is %d\n", __func__, count);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
send:
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
priv->write_urb_in_use = 1;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
if (priv->cmd_ctrl)
|
|
|
|
actual_size = 1;
|
|
|
|
else
|
2008-02-11 02:23:19 +00:00
|
|
|
actual_size = count +
|
|
|
|
(priv->pkt_fmt == packet_format_1 ? 2 : 1);
|
|
|
|
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(dev, __func__, port->interrupt_out_size,
|
|
|
|
port->interrupt_out_urb->transfer_buffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-08-30 03:07:04 +00:00
|
|
|
usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
|
|
|
|
usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress),
|
|
|
|
port->interrupt_out_buffer, port->interrupt_out_size,
|
|
|
|
cypress_write_int_callback, port, priv->write_urb_interval);
|
2008-07-22 10:10:36 +00:00
|
|
|
result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (result) {
|
2012-02-10 12:20:51 +00:00
|
|
|
dev_err_console(port,
|
2008-07-22 10:10:36 +00:00
|
|
|
"%s - failed submitting write urb, error %d\n",
|
|
|
|
__func__, result);
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->write_urb_in_use = 0;
|
2006-08-30 03:07:11 +00:00
|
|
|
cypress_set_dead(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-07-22 10:10:36 +00:00
|
|
|
if (priv->cmd_ctrl)
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->cmd_ctrl = 0;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
|
|
|
/* do not count the line control and size bytes */
|
|
|
|
priv->bytes_out += count;
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2006-05-23 04:58:49 +00:00
|
|
|
usb_serial_port_softint(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
} /* cypress_send */
|
|
|
|
|
|
|
|
|
|
|
|
/* returns how much space is available in the soft buffer */
|
2008-07-22 10:09:07 +00:00
|
|
|
static int cypress_write_room(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int room = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2010-05-16 18:33:50 +00:00
|
|
|
room = kfifo_avail(&priv->write_fifo);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
|
2005-04-16 22:20:36 +00:00
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-14 16:26:14 +00:00
|
|
|
static int cypress_tiocmget(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
__u8 status, control;
|
|
|
|
unsigned int result = 0;
|
|
|
|
unsigned long flags;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
control = priv->line_control;
|
|
|
|
status = priv->current_status;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
|
|
|
|
| ((control & CONTROL_RTS) ? TIOCM_RTS : 0)
|
|
|
|
| ((status & UART_CTS) ? TIOCM_CTS : 0)
|
|
|
|
| ((status & UART_DSR) ? TIOCM_DSR : 0)
|
|
|
|
| ((status & UART_RI) ? TIOCM_RI : 0)
|
|
|
|
| ((status & UART_CD) ? TIOCM_CD : 0);
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - result = %x\n", __func__, result);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-14 16:26:50 +00:00
|
|
|
static int cypress_tiocmset(struct tty_struct *tty,
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int set, unsigned int clear)
|
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (set & TIOCM_RTS)
|
|
|
|
priv->line_control |= CONTROL_RTS;
|
|
|
|
if (set & TIOCM_DTR)
|
|
|
|
priv->line_control |= CONTROL_DTR;
|
|
|
|
if (clear & TIOCM_RTS)
|
|
|
|
priv->line_control &= ~CONTROL_RTS;
|
|
|
|
if (clear & TIOCM_DTR)
|
|
|
|
priv->line_control &= ~CONTROL_DTR;
|
2008-03-10 21:59:28 +00:00
|
|
|
priv->cmd_ctrl = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
return cypress_write(tty, port, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-21 11:37:02 +00:00
|
|
|
static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
2013-03-21 11:37:02 +00:00
|
|
|
char diff;
|
|
|
|
|
|
|
|
for (;;) {
|
2013-03-21 11:37:03 +00:00
|
|
|
interruptible_sleep_on(&port->port.delta_msr_wait);
|
2013-03-21 11:37:02 +00:00
|
|
|
/* see if a signal did it */
|
|
|
|
if (signal_pending(current))
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
|
|
|
if (port->serial->disconnected)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
diff = priv->diff_status;
|
|
|
|
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 */
|
|
|
|
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)))
|
|
|
|
return 0;
|
|
|
|
/* otherwise caller can't care less about what
|
|
|
|
* happened, and so we continue to wait for
|
|
|
|
* more events.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 11:37:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void cypress_set_termios(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct ktermios *old_termios)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
2012-09-14 16:47:38 +00:00
|
|
|
struct device *dev = &port->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
int data_bits, stop_bits, parity_type, parity_enable;
|
2008-03-10 21:59:28 +00:00
|
|
|
unsigned cflag, iflag;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
__u8 oldlines;
|
2005-05-03 22:02:20 +00:00
|
|
|
int linechange = 0;
|
2005-07-12 22:21:31 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2009-09-19 20:13:33 +00:00
|
|
|
/* We can't clean this one up as we don't know the device type
|
|
|
|
early enough */
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!priv->termios_initialized) {
|
|
|
|
if (priv->chiptype == CT_EARTHMATE) {
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios = tty_std_termios;
|
|
|
|
tty->termios.c_cflag = B4800 | CS8 | CREAD | HUPCL |
|
2005-07-12 22:21:31 +00:00
|
|
|
CLOCAL;
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_ispeed = 4800;
|
|
|
|
tty->termios.c_ospeed = 4800;
|
2005-04-16 22:20:36 +00:00
|
|
|
} else if (priv->chiptype == CT_CYPHIDCOM) {
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios = tty_std_termios;
|
|
|
|
tty->termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
|
2005-07-12 22:21:31 +00:00
|
|
|
CLOCAL;
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_ispeed = 9600;
|
|
|
|
tty->termios.c_ospeed = 9600;
|
2006-03-01 16:45:24 +00:00
|
|
|
} else if (priv->chiptype == CT_CA42V2) {
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios = tty_std_termios;
|
|
|
|
tty->termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
|
2006-03-01 16:45:24 +00:00
|
|
|
CLOCAL;
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_ispeed = 9600;
|
|
|
|
tty->termios.c_ospeed = 9600;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
priv->termios_initialized = 1;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2008-03-10 21:59:28 +00:00
|
|
|
/* Unsupported features need clearing */
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_cflag &= ~(CMSPAR|CRTSCTS);
|
2008-03-10 21:59:28 +00:00
|
|
|
|
2012-07-14 14:31:47 +00:00
|
|
|
cflag = tty->termios.c_cflag;
|
|
|
|
iflag = tty->termios.c_iflag;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* check if there are new settings */
|
|
|
|
if (old_termios) {
|
2008-03-10 21:59:28 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2012-07-14 14:31:47 +00:00
|
|
|
priv->tmp_termios = tty->termios;
|
2008-03-10 21:59:28 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* set number of data bits, parity, stop bits */
|
|
|
|
/* when parity is disabled the parity type bit is ignored */
|
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
/* 1 means 2 stop bits, 0 means 1 stop bit */
|
|
|
|
stop_bits = cflag & CSTOPB ? 1 : 0;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cflag & PARENB) {
|
|
|
|
parity_enable = 1;
|
2005-07-12 22:21:31 +00:00
|
|
|
/* 1 means odd parity, 0 means even parity */
|
|
|
|
parity_type = cflag & PARODD ? 1 : 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
} else
|
|
|
|
parity_enable = parity_type = 0;
|
|
|
|
|
2008-07-22 10:10:53 +00:00
|
|
|
switch (cflag & CSIZE) {
|
|
|
|
case CS5:
|
|
|
|
data_bits = 0;
|
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
data_bits = 1;
|
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
data_bits = 2;
|
|
|
|
break;
|
|
|
|
case CS8:
|
2005-04-16 22:20:36 +00:00
|
|
|
data_bits = 3;
|
2008-07-22 10:10:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_err(dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__);
|
2008-07-22 10:10:53 +00:00
|
|
|
data_bits = 3;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
oldlines = priv->line_control;
|
|
|
|
if ((cflag & CBAUD) == B0) {
|
|
|
|
/* drop dtr and rts */
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - dropping the lines, baud rate 0bps\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
|
2008-03-10 21:59:28 +00:00
|
|
|
} else
|
2005-05-03 22:02:20 +00:00
|
|
|
priv->line_control = (CONTROL_DTR | CONTROL_RTS);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - sending %d stop_bits, %d parity_enable, %d parity_type, %d data_bits (+5)\n",
|
|
|
|
__func__, stop_bits, parity_enable, parity_type, data_bits);
|
2005-07-12 22:21:31 +00:00
|
|
|
|
2008-07-22 10:10:36 +00:00
|
|
|
cypress_serial_control(tty, port, tty_get_baud_rate(tty),
|
|
|
|
data_bits, stop_bits,
|
|
|
|
parity_enable, parity_type,
|
|
|
|
0, CYPRESS_SET_CONFIG);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
/* we perform a CYPRESS_GET_CONFIG so that the current settings are
|
|
|
|
* filled into the private structure this should confirm that all is
|
|
|
|
* working if it returns what we just set */
|
2008-07-22 10:09:07 +00:00
|
|
|
cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
/* Here we can define custom tty settings for devices; the main tty
|
|
|
|
* termios flag base comes from empeg.c */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-07-22 10:10:36 +00:00
|
|
|
if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "Using custom termios settings for a baud rate of 4800bps.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
/* define custom termios settings for NMEA protocol */
|
|
|
|
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_iflag /* input modes - */
|
2005-07-12 22:21:31 +00:00
|
|
|
&= ~(IGNBRK /* disable ignore break */
|
|
|
|
| BRKINT /* disable break causes interrupt */
|
|
|
|
| PARMRK /* disable mark parity errors */
|
|
|
|
| ISTRIP /* disable clear high bit of input char */
|
|
|
|
| INLCR /* disable translate NL to CR */
|
|
|
|
| IGNCR /* disable ignore CR */
|
|
|
|
| ICRNL /* disable translate CR to NL */
|
|
|
|
| IXON); /* disable enable XON/XOFF flow control */
|
|
|
|
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_oflag /* output modes */
|
2005-07-12 22:21:31 +00:00
|
|
|
&= ~OPOST; /* disable postprocess output char */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-07-14 14:31:47 +00:00
|
|
|
tty->termios.c_lflag /* line discipline modes */
|
2005-07-12 22:21:31 +00:00
|
|
|
&= ~(ECHO /* disable echo input characters */
|
|
|
|
| ECHONL /* disable echo new line */
|
|
|
|
| ICANON /* disable erase, kill, werase, and rprnt
|
|
|
|
special characters */
|
|
|
|
| ISIG /* disable interrupt, quit, and suspend
|
|
|
|
special characters */
|
|
|
|
| IEXTEN); /* disable non-POSIX special characters */
|
2005-05-03 22:02:20 +00:00
|
|
|
} /* CT_CYPHIDCOM: Application should handle this for device */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
linechange = (priv->line_control != oldlines);
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
/* if necessary, set lines */
|
2005-05-03 22:02:20 +00:00
|
|
|
if (linechange) {
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->cmd_ctrl = 1;
|
2008-07-22 10:09:07 +00:00
|
|
|
cypress_write(tty, port, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
} /* cypress_set_termios */
|
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* returns amount of data still left in soft buffer */
|
2008-07-22 10:09:07 +00:00
|
|
|
static int cypress_chars_in_buffer(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int chars = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2010-05-16 18:33:50 +00:00
|
|
|
chars = kfifo_len(&priv->write_fifo);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
|
2005-04-16 22:20:36 +00:00
|
|
|
return chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void cypress_throttle(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
|
2009-10-07 08:50:23 +00:00
|
|
|
spin_lock_irq(&priv->lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->rx_flags = THROTTLED;
|
2009-10-07 08:50:23 +00:00
|
|
|
spin_unlock_irq(&priv->lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 10:09:07 +00:00
|
|
|
static void cypress_unthrottle(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-22 10:09:07 +00:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int actually_throttled, result;
|
|
|
|
|
2009-10-07 08:50:23 +00:00
|
|
|
spin_lock_irq(&priv->lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
|
|
|
|
priv->rx_flags = 0;
|
2009-10-07 08:50:23 +00:00
|
|
|
spin_unlock_irq(&priv->lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-08-30 03:07:11 +00:00
|
|
|
if (!priv->comm_is_ok)
|
|
|
|
return;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (actually_throttled) {
|
2009-10-07 08:50:23 +00:00
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
|
2006-08-30 03:07:11 +00:00
|
|
|
if (result) {
|
2005-07-12 22:21:31 +00:00
|
|
|
dev_err(&port->dev, "%s - failed submitting read urb, "
|
2008-03-04 00:08:34 +00:00
|
|
|
"error %d\n", __func__, result);
|
2006-08-30 03:07:11 +00:00
|
|
|
cypress_set_dead(port);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static void cypress_read_int_callback(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-24 10:41:47 +00:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
2012-09-14 16:47:38 +00:00
|
|
|
struct device *dev = &urb->dev->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct tty_struct *tty;
|
|
|
|
unsigned char *data = urb->transfer_buffer;
|
|
|
|
unsigned long flags;
|
2005-07-12 22:21:31 +00:00
|
|
|
char tty_flag = TTY_NORMAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
int havedata = 0;
|
|
|
|
int bytes = 0;
|
|
|
|
int result;
|
|
|
|
int i = 0;
|
2007-06-15 22:44:13 +00:00
|
|
|
int status = urb->status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-06-15 22:44:13 +00:00
|
|
|
switch (status) {
|
2006-08-30 03:07:11 +00:00
|
|
|
case 0: /* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* precursor to disconnect so just go away */
|
|
|
|
return;
|
|
|
|
case -EPIPE:
|
2009-07-09 16:59:57 +00:00
|
|
|
/* Can't call usb_clear_halt while in_interrupt */
|
|
|
|
/* FALLS THROUGH */
|
2006-08-30 03:07:11 +00:00
|
|
|
default:
|
|
|
|
/* something ugly is going on... */
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_err(dev, "%s - unexpected nonzero read status received: %d\n",
|
|
|
|
__func__, status);
|
2006-08-30 03:07:11 +00:00
|
|
|
cypress_set_dead(port);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (priv->rx_flags & THROTTLED) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - now throttling\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
priv->rx_flags |= ACTUALLY_THROTTLED;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2008-10-13 09:39:46 +00:00
|
|
|
tty = tty_port_tty_get(&port->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!tty) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - bad tty pointer - exiting\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-02-11 02:23:19 +00:00
|
|
|
result = urb->actual_length;
|
|
|
|
switch (priv->pkt_fmt) {
|
|
|
|
default:
|
|
|
|
case packet_format_1:
|
|
|
|
/* This is for the CY7C64013... */
|
|
|
|
priv->current_status = data[0] & 0xF8;
|
|
|
|
bytes = data[1] + 2;
|
|
|
|
i = 2;
|
|
|
|
if (bytes > 2)
|
|
|
|
havedata = 1;
|
|
|
|
break;
|
|
|
|
case packet_format_2:
|
|
|
|
/* This is for the CY7C63743... */
|
|
|
|
priv->current_status = data[0] & 0xF8;
|
|
|
|
bytes = (data[0] & 0x07) + 1;
|
|
|
|
i = 1;
|
|
|
|
if (bytes > 1)
|
|
|
|
havedata = 1;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2008-02-11 02:23:19 +00:00
|
|
|
if (result < bytes) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev,
|
|
|
|
"%s - wrong packet size - received %d bytes but packet said %d bytes\n",
|
|
|
|
__func__, result, bytes);
|
2008-02-11 02:23:19 +00:00
|
|
|
goto continue_read;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-18 08:58:57 +00:00
|
|
|
usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
/* check to see if status has changed */
|
2008-02-11 02:23:28 +00:00
|
|
|
if (priv->current_status != priv->prev_status) {
|
|
|
|
priv->diff_status |= priv->current_status ^
|
|
|
|
priv->prev_status;
|
2013-03-21 11:37:03 +00:00
|
|
|
wake_up_interruptible(&port->port.delta_msr_wait);
|
2008-02-11 02:23:28 +00:00
|
|
|
priv->prev_status = priv->current_status;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-07-12 22:21:31 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
/* hangup, as defined in acm.c... this might be a bad place for it
|
|
|
|
* though */
|
2012-07-14 14:31:47 +00:00
|
|
|
if (tty && !(tty->termios.c_cflag & CLOCAL) &&
|
2005-07-12 22:21:31 +00:00
|
|
|
!(priv->current_status & UART_CD)) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - calling hangup\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
tty_hangup(tty);
|
|
|
|
goto continue_read;
|
|
|
|
}
|
|
|
|
|
2005-07-12 22:21:31 +00:00
|
|
|
/* There is one error bit... I'm assuming it is a parity error
|
|
|
|
* indicator as the generic firmware will set this bit to 1 if a
|
|
|
|
* parity error occurs.
|
|
|
|
* I can not find reference to any other error events. */
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (priv->current_status & CYP_ERROR) {
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
tty_flag = TTY_PARITY;
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - Parity Error detected\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
/* process read if there is data other than line status */
|
2013-01-03 14:53:06 +00:00
|
|
|
if (bytes > i) {
|
2013-01-03 14:53:02 +00:00
|
|
|
tty_insert_flip_string_fixed_flag(&port->port, data + i,
|
2010-05-07 17:46:56 +00:00
|
|
|
tty_flag, bytes - i);
|
2013-01-03 14:53:06 +00:00
|
|
|
tty_flip_buffer_push(&port->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2005-07-12 22:21:31 +00:00
|
|
|
/* control and status byte(s) are also counted */
|
|
|
|
priv->bytes_in += bytes;
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
continue_read:
|
2008-10-13 09:39:46 +00:00
|
|
|
tty_kref_put(tty);
|
2005-07-12 22:21:31 +00:00
|
|
|
|
2010-02-17 15:05:47 +00:00
|
|
|
/* Continue trying to always read */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-02-17 15:05:47 +00:00
|
|
|
if (priv->comm_is_ok) {
|
2005-07-12 22:21:31 +00:00
|
|
|
usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
|
|
|
|
usb_rcvintpipe(port->serial->dev,
|
|
|
|
port->interrupt_in_endpointAddress),
|
|
|
|
port->interrupt_in_urb->transfer_buffer,
|
|
|
|
port->interrupt_in_urb->transfer_buffer_length,
|
2008-07-22 10:10:36 +00:00
|
|
|
cypress_read_int_callback, port,
|
|
|
|
priv->read_urb_interval);
|
2005-07-12 22:21:31 +00:00
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
|
2010-02-17 15:05:47 +00:00
|
|
|
if (result && result != -EPERM) {
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_err(dev, "%s - failed resubmitting read urb, error %d\n",
|
|
|
|
__func__, result);
|
2006-08-30 03:07:11 +00:00
|
|
|
cypress_set_dead(port);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
} /* cypress_read_int_callback */
|
|
|
|
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static void cypress_write_int_callback(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-24 10:41:47 +00:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cypress_private *priv = usb_get_serial_port_data(port);
|
2012-09-14 16:47:38 +00:00
|
|
|
struct device *dev = &urb->dev->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
int result;
|
2007-06-15 22:44:13 +00:00
|
|
|
int status = urb->status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-06-15 22:44:13 +00:00
|
|
|
switch (status) {
|
2008-07-22 10:10:36 +00:00
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - urb shutting down with status: %d\n",
|
|
|
|
__func__, status);
|
2008-07-22 10:10:36 +00:00
|
|
|
priv->write_urb_in_use = 0;
|
|
|
|
return;
|
|
|
|
case -EPIPE: /* no break needed; clear halt and resubmit */
|
|
|
|
if (!priv->comm_is_ok)
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2008-07-22 10:10:36 +00:00
|
|
|
usb_clear_halt(port->serial->dev, 0x02);
|
|
|
|
/* error in the urb, so we have to resubmit it */
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_dbg(dev, "%s - nonzero write bulk status received: %d\n",
|
2008-07-22 10:10:36 +00:00
|
|
|
__func__, status);
|
|
|
|
port->interrupt_out_urb->transfer_buffer_length = 1;
|
|
|
|
result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
|
|
|
|
if (!result)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_err(dev, "%s - failed resubmitting write urb, error %d\n",
|
|
|
|
__func__, result);
|
2008-07-22 10:10:36 +00:00
|
|
|
cypress_set_dead(port);
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-14 16:47:38 +00:00
|
|
|
dev_err(dev, "%s - unexpected nonzero write status received: %d\n",
|
|
|
|
__func__, status);
|
2008-07-22 10:10:36 +00:00
|
|
|
cypress_set_dead(port);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
priv->write_urb_in_use = 0;
|
2008-07-22 10:10:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* send any buffered data */
|
|
|
|
cypress_send(port);
|
|
|
|
}
|
|
|
|
|
2012-05-08 22:46:14 +00:00
|
|
|
module_usb_serial_driver(serial_drivers, id_table_combined);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-22 10:10:36 +00:00
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_param(stats, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(stats, "Enable statistics or not");
|
2005-05-03 22:02:20 +00:00
|
|
|
module_param(interval, int, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(interval, "Overrides interrupt interval");
|
2009-12-18 21:33:03 +00:00
|
|
|
module_param(unstable_bauds, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(unstable_bauds, "Allow unstable baud rates");
|