2007-03-27 06:34:30 -04:00
|
|
|
/*
|
|
|
|
* Ours Technology Inc. OTi-6858 USB to serial adapter driver.
|
|
|
|
*
|
|
|
|
* Copyleft (C) 2007 Kees Lemmens (adapted for kernel 2.6.20)
|
|
|
|
* Copyright (C) 2006 Tomasz Michal Lukaszewski (FIXME: add e-mail)
|
|
|
|
* Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
* Copyright (C) 2003 IBM Corp.
|
|
|
|
*
|
|
|
|
* Many thanks to the authors of pl2303 driver: all functions in this file
|
|
|
|
* are heavily based on pl2303 code, buffering code is a 1-to-1 copy.
|
|
|
|
*
|
|
|
|
* Warning! You use this driver on your own risk! The only official
|
|
|
|
* description of this device I have is datasheet from manufacturer,
|
|
|
|
* and it doesn't contain almost any information needed to write a driver.
|
|
|
|
* Almost all knowlegde used while writing this driver was gathered by:
|
|
|
|
* - analyzing traffic between device and the M$ Windows 2000 driver,
|
|
|
|
* - trying different bit combinations and checking pin states
|
|
|
|
* with a voltmeter,
|
|
|
|
* - receiving malformed frames and producing buffer overflows
|
|
|
|
* to learn how errors are reported,
|
|
|
|
* So, THIS CODE CAN DESTROY OTi-6858 AND ANY OTHER DEVICES, THAT ARE
|
|
|
|
* CONNECTED TO IT!
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2008-07-22 06:15:36 -04:00
|
|
|
* See Documentation/usb/usb-serial.txt for more information on using this
|
|
|
|
* driver
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - implement correct flushing for ioctls and oti6858_close()
|
|
|
|
* - check how errors (rx overflow, parity error, framing error) are reported
|
|
|
|
* - implement oti6858_break_ctl()
|
|
|
|
* - implement more ioctls
|
|
|
|
* - test/implement flow control
|
|
|
|
* - allow setting custom baud rates
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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/serial.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/serial.h>
|
2008-07-22 06:15:36 -04:00
|
|
|
#include <linux/uaccess.h>
|
2007-03-27 06:34:30 -04:00
|
|
|
#include "oti6858.h"
|
|
|
|
|
|
|
|
#define OTI6858_DESCRIPTION \
|
|
|
|
"Ours Technology Inc. OTi-6858 USB to serial adapter driver"
|
|
|
|
#define OTI6858_AUTHOR "Tomasz Michal Lukaszewski <FIXME@FIXME>"
|
|
|
|
#define OTI6858_VERSION "0.1"
|
|
|
|
|
|
|
|
static struct usb_device_id id_table [] = {
|
|
|
|
{ USB_DEVICE(OTI6858_VENDOR_ID, OTI6858_PRODUCT_ID) },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, id_table);
|
|
|
|
|
|
|
|
static struct usb_driver oti6858_driver = {
|
|
|
|
.name = "oti6858",
|
|
|
|
.probe = usb_serial_probe,
|
|
|
|
.disconnect = usb_serial_disconnect,
|
|
|
|
.id_table = id_table,
|
|
|
|
.no_dynamic_id = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int debug;
|
|
|
|
|
|
|
|
|
|
|
|
/* buffering code, copied from pl2303 driver */
|
|
|
|
#define PL2303_BUF_SIZE 1024
|
|
|
|
#define PL2303_TMP_BUF_SIZE 1024
|
|
|
|
|
2008-01-19 11:02:37 -05:00
|
|
|
struct oti6858_buf {
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int buf_size;
|
|
|
|
char *buf_buf;
|
|
|
|
char *buf_get;
|
|
|
|
char *buf_put;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* requests */
|
|
|
|
#define OTI6858_REQ_GET_STATUS (USB_DIR_IN | USB_TYPE_VENDOR | 0x00)
|
|
|
|
#define OTI6858_REQ_T_GET_STATUS 0x01
|
|
|
|
|
|
|
|
#define OTI6858_REQ_SET_LINE (USB_DIR_OUT | USB_TYPE_VENDOR | 0x00)
|
|
|
|
#define OTI6858_REQ_T_SET_LINE 0x00
|
|
|
|
|
|
|
|
#define OTI6858_REQ_CHECK_TXBUFF (USB_DIR_IN | USB_TYPE_VENDOR | 0x01)
|
|
|
|
#define OTI6858_REQ_T_CHECK_TXBUFF 0x00
|
|
|
|
|
|
|
|
/* format of the control packet */
|
|
|
|
struct oti6858_control_pkt {
|
2008-04-28 02:00:16 -04:00
|
|
|
__le16 divisor; /* baud rate = 96000000 / (16 * divisor), LE */
|
2007-03-27 06:34:30 -04:00
|
|
|
#define OTI6858_MAX_BAUD_RATE 3000000
|
|
|
|
u8 frame_fmt;
|
|
|
|
#define FMT_STOP_BITS_MASK 0xc0
|
|
|
|
#define FMT_STOP_BITS_1 0x00
|
|
|
|
#define FMT_STOP_BITS_2 0x40 /* 1.5 stop bits if FMT_DATA_BITS_5 */
|
|
|
|
#define FMT_PARITY_MASK 0x38
|
|
|
|
#define FMT_PARITY_NONE 0x00
|
|
|
|
#define FMT_PARITY_ODD 0x08
|
|
|
|
#define FMT_PARITY_EVEN 0x18
|
|
|
|
#define FMT_PARITY_MARK 0x28
|
|
|
|
#define FMT_PARITY_SPACE 0x38
|
|
|
|
#define FMT_DATA_BITS_MASK 0x03
|
|
|
|
#define FMT_DATA_BITS_5 0x00
|
|
|
|
#define FMT_DATA_BITS_6 0x01
|
|
|
|
#define FMT_DATA_BITS_7 0x02
|
|
|
|
#define FMT_DATA_BITS_8 0x03
|
|
|
|
u8 something; /* always equals 0x43 */
|
|
|
|
u8 control; /* settings of flow control lines */
|
|
|
|
#define CONTROL_MASK 0x0c
|
|
|
|
#define CONTROL_DTR_HIGH 0x08
|
|
|
|
#define CONTROL_RTS_HIGH 0x04
|
|
|
|
u8 tx_status;
|
|
|
|
#define TX_BUFFER_EMPTIED 0x09
|
|
|
|
u8 pin_state;
|
|
|
|
#define PIN_MASK 0x3f
|
|
|
|
#define PIN_RTS 0x20 /* output pin */
|
|
|
|
#define PIN_CTS 0x10 /* input pin, active low */
|
|
|
|
#define PIN_DSR 0x08 /* input pin, active low */
|
|
|
|
#define PIN_DTR 0x04 /* output pin */
|
|
|
|
#define PIN_RI 0x02 /* input pin, active low */
|
|
|
|
#define PIN_DCD 0x01 /* input pin, active low */
|
|
|
|
u8 rx_bytes_avail; /* number of bytes in rx buffer */;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt)
|
|
|
|
#define OTI6858_CTRL_EQUALS_PENDING(a, priv) \
|
2008-07-22 06:15:36 -04:00
|
|
|
(((a)->divisor == (priv)->pending_setup.divisor) \
|
2007-03-27 06:34:30 -04:00
|
|
|
&& ((a)->control == (priv)->pending_setup.control) \
|
2008-07-22 06:15:36 -04:00
|
|
|
&& ((a)->frame_fmt == (priv)->pending_setup.frame_fmt))
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
/* function prototypes */
|
2009-09-19 16:13:26 -04:00
|
|
|
static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port);
|
2009-06-11 07:26:29 -04:00
|
|
|
static void oti6858_close(struct usb_serial_port *port);
|
2008-07-22 06:09:07 -04:00
|
|
|
static void oti6858_set_termios(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct ktermios *old);
|
2009-09-19 16:13:33 -04:00
|
|
|
static void oti6858_init_termios(struct tty_struct *tty);
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int cmd, unsigned long arg);
|
|
|
|
static void oti6858_read_int_callback(struct urb *urb);
|
|
|
|
static void oti6858_read_bulk_callback(struct urb *urb);
|
|
|
|
static void oti6858_write_bulk_callback(struct urb *urb);
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
|
2007-03-27 06:34:30 -04:00
|
|
|
const unsigned char *buf, int count);
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_write_room(struct tty_struct *tty);
|
|
|
|
static int oti6858_chars_in_buffer(struct tty_struct *tty);
|
|
|
|
static int oti6858_tiocmget(struct tty_struct *tty, struct file *file);
|
|
|
|
static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int set, unsigned int clear);
|
|
|
|
static int oti6858_startup(struct usb_serial *serial);
|
2009-06-02 11:53:55 -04:00
|
|
|
static void oti6858_release(struct usb_serial *serial);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
/* functions operating on buffers */
|
2008-01-19 11:02:37 -05:00
|
|
|
static struct oti6858_buf *oti6858_buf_alloc(unsigned int size);
|
|
|
|
static void oti6858_buf_free(struct oti6858_buf *pb);
|
|
|
|
static void oti6858_buf_clear(struct oti6858_buf *pb);
|
|
|
|
static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb);
|
|
|
|
static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb);
|
|
|
|
static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int count);
|
2008-01-19 11:02:37 -05:00
|
|
|
static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int count);
|
|
|
|
|
|
|
|
|
|
|
|
/* device info */
|
|
|
|
static struct usb_serial_driver oti6858_device = {
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "oti6858",
|
|
|
|
},
|
|
|
|
.id_table = id_table,
|
|
|
|
.num_ports = 1,
|
|
|
|
.open = oti6858_open,
|
|
|
|
.close = oti6858_close,
|
|
|
|
.write = oti6858_write,
|
|
|
|
.ioctl = oti6858_ioctl,
|
|
|
|
.set_termios = oti6858_set_termios,
|
2009-09-19 16:13:33 -04:00
|
|
|
.init_termios = oti6858_init_termios,
|
2007-03-27 06:34:30 -04:00
|
|
|
.tiocmget = oti6858_tiocmget,
|
|
|
|
.tiocmset = oti6858_tiocmset,
|
|
|
|
.read_bulk_callback = oti6858_read_bulk_callback,
|
|
|
|
.read_int_callback = oti6858_read_int_callback,
|
|
|
|
.write_bulk_callback = oti6858_write_bulk_callback,
|
|
|
|
.write_room = oti6858_write_room,
|
|
|
|
.chars_in_buffer = oti6858_chars_in_buffer,
|
|
|
|
.attach = oti6858_startup,
|
2009-06-02 11:53:55 -04:00
|
|
|
.release = oti6858_release,
|
2007-03-27 06:34:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct oti6858_private {
|
|
|
|
spinlock_t lock;
|
|
|
|
|
2008-01-19 11:02:37 -05:00
|
|
|
struct oti6858_buf *buf;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_control_pkt status;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u8 read_urb_in_use;
|
|
|
|
u8 write_urb_in_use;
|
|
|
|
} flags;
|
|
|
|
struct delayed_work delayed_write_work;
|
|
|
|
|
|
|
|
struct {
|
2008-04-28 02:00:16 -04:00
|
|
|
__le16 divisor;
|
2007-03-27 06:34:30 -04:00
|
|
|
u8 frame_fmt;
|
|
|
|
u8 control;
|
|
|
|
} pending_setup;
|
|
|
|
u8 transient;
|
|
|
|
u8 setup_done;
|
|
|
|
struct delayed_work delayed_setup_work;
|
|
|
|
|
|
|
|
wait_queue_head_t intr_wait;
|
2008-07-22 06:15:36 -04:00
|
|
|
struct usb_serial_port *port; /* USB port with which associated */
|
2007-03-27 06:34:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void setup_line(struct work_struct *work)
|
|
|
|
{
|
2008-07-22 06:15:36 -04:00
|
|
|
struct oti6858_private *priv = container_of(work,
|
|
|
|
struct oti6858_private, delayed_setup_work.work);
|
2007-03-27 06:34:30 -04:00
|
|
|
struct usb_serial_port *port = priv->port;
|
|
|
|
struct oti6858_control_pkt *new_setup;
|
|
|
|
unsigned long flags;
|
|
|
|
int result;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
|
|
|
|
if (new_setup == NULL) {
|
2008-03-03 19:08:34 -05:00
|
|
|
dev_err(&port->dev, "%s(): out of memory!\n", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
/* we will try again */
|
2008-07-22 06:15:36 -04:00
|
|
|
schedule_delayed_work(&priv->delayed_setup_work,
|
|
|
|
msecs_to_jiffies(2));
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = usb_control_msg(port->serial->dev,
|
|
|
|
usb_rcvctrlpipe(port->serial->dev, 0),
|
|
|
|
OTI6858_REQ_T_GET_STATUS,
|
|
|
|
OTI6858_REQ_GET_STATUS,
|
|
|
|
0, 0,
|
|
|
|
new_setup, OTI6858_CTRL_PKT_SIZE,
|
|
|
|
100);
|
|
|
|
|
|
|
|
if (result != OTI6858_CTRL_PKT_SIZE) {
|
2008-03-03 19:08:34 -05:00
|
|
|
dev_err(&port->dev, "%s(): error reading status\n", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
kfree(new_setup);
|
|
|
|
/* we will try again */
|
2008-07-22 06:15:36 -04:00
|
|
|
schedule_delayed_work(&priv->delayed_setup_work,
|
|
|
|
msecs_to_jiffies(2));
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (!OTI6858_CTRL_EQUALS_PENDING(new_setup, priv)) {
|
|
|
|
new_setup->divisor = priv->pending_setup.divisor;
|
|
|
|
new_setup->control = priv->pending_setup.control;
|
|
|
|
new_setup->frame_fmt = priv->pending_setup.frame_fmt;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
result = usb_control_msg(port->serial->dev,
|
|
|
|
usb_sndctrlpipe(port->serial->dev, 0),
|
|
|
|
OTI6858_REQ_T_SET_LINE,
|
|
|
|
OTI6858_REQ_SET_LINE,
|
|
|
|
0, 0,
|
|
|
|
new_setup, OTI6858_CTRL_PKT_SIZE,
|
|
|
|
100);
|
|
|
|
} else {
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
kfree(new_setup);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (result != OTI6858_CTRL_PKT_SIZE)
|
|
|
|
priv->transient = 0;
|
|
|
|
priv->setup_done = 1;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): submitting interrupt urb", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
port->interrupt_in_urb->dev = port->serial->dev;
|
2009-10-07 12:07:10 -04:00
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (result != 0) {
|
|
|
|
dev_err(&port->dev, "%s(): usb_submit_urb() failed"
|
2008-03-03 19:08:34 -05:00
|
|
|
" with error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void send_data(struct work_struct *work)
|
|
|
|
{
|
2008-07-22 06:15:36 -04:00
|
|
|
struct oti6858_private *priv = container_of(work,
|
|
|
|
struct oti6858_private, delayed_write_work.work);
|
2007-03-27 06:34:30 -04:00
|
|
|
struct usb_serial_port *port = priv->port;
|
|
|
|
int count = 0, result;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char allow;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (priv->flags.write_urb_in_use) {
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2008-07-22 06:15:36 -04:00
|
|
|
schedule_delayed_work(&priv->delayed_write_work,
|
|
|
|
msecs_to_jiffies(2));
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
priv->flags.write_urb_in_use = 1;
|
|
|
|
|
2008-01-19 11:02:37 -05:00
|
|
|
count = oti6858_buf_data_avail(priv->buf);
|
2007-03-27 06:34:30 -04:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
if (count > port->bulk_out_size)
|
|
|
|
count = port->bulk_out_size;
|
|
|
|
|
|
|
|
if (count != 0) {
|
|
|
|
result = usb_control_msg(port->serial->dev,
|
|
|
|
usb_rcvctrlpipe(port->serial->dev, 0),
|
|
|
|
OTI6858_REQ_T_CHECK_TXBUFF,
|
|
|
|
OTI6858_REQ_CHECK_TXBUFF,
|
|
|
|
count, 0, &allow, 1, 100);
|
|
|
|
if (result != 1 || allow != 0)
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
priv->flags.write_urb_in_use = 0;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): submitting interrupt urb", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
port->interrupt_in_urb->dev = port->serial->dev;
|
2009-10-07 12:07:10 -04:00
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (result != 0) {
|
|
|
|
dev_err(&port->dev, "%s(): usb_submit_urb() failed"
|
2008-03-03 19:08:34 -05:00
|
|
|
" with error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-01-19 11:02:37 -05:00
|
|
|
oti6858_buf_get(priv->buf, port->write_urb->transfer_buffer, count);
|
2007-03-27 06:34:30 -04:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
port->write_urb->transfer_buffer_length = count;
|
|
|
|
port->write_urb->dev = port->serial->dev;
|
2009-10-07 12:07:10 -04:00
|
|
|
result = usb_submit_urb(port->write_urb, GFP_NOIO);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (result != 0) {
|
|
|
|
dev_err(&port->dev, "%s(): usb_submit_urb() failed"
|
2008-03-03 19:08:34 -05:00
|
|
|
" with error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
priv->flags.write_urb_in_use = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_serial_port_softint(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int oti6858_startup(struct usb_serial *serial)
|
|
|
|
{
|
2008-07-22 06:15:36 -04:00
|
|
|
struct usb_serial_port *port = serial->port[0];
|
|
|
|
struct oti6858_private *priv;
|
2007-03-27 06:34:30 -04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < serial->num_ports; ++i) {
|
|
|
|
priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
break;
|
2008-01-19 11:02:37 -05:00
|
|
|
priv->buf = oti6858_buf_alloc(PL2303_BUF_SIZE);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (priv->buf == NULL) {
|
|
|
|
kfree(priv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&priv->lock);
|
|
|
|
init_waitqueue_head(&priv->intr_wait);
|
2008-07-22 06:15:36 -04:00
|
|
|
/* INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); */
|
|
|
|
/* INIT_WORK(&priv->write_work, send_data, serial->port[i]); */
|
2007-03-27 06:34:30 -04:00
|
|
|
priv->port = port;
|
|
|
|
INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line);
|
|
|
|
INIT_DELAYED_WORK(&priv->delayed_write_work, send_data);
|
|
|
|
|
|
|
|
usb_set_serial_port_data(serial->port[i], priv);
|
|
|
|
}
|
|
|
|
if (i == serial->num_ports)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (--i; i >= 0; --i) {
|
|
|
|
priv = usb_get_serial_port_data(serial->port[i]);
|
2008-01-19 11:02:37 -05:00
|
|
|
oti6858_buf_free(priv->buf);
|
2007-03-27 06:34:30 -04:00
|
|
|
kfree(priv);
|
|
|
|
usb_set_serial_port_data(serial->port[i], NULL);
|
|
|
|
}
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
|
2007-03-27 06:34:30 -04:00
|
|
|
const unsigned char *buf, int count)
|
|
|
|
{
|
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d, count = %d)", __func__, port->number, count);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return count;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-01-19 11:02:37 -05:00
|
|
|
count = oti6858_buf_put(priv->buf, buf, count);
|
2007-03-27 06:34:30 -04:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_write_room(struct tty_struct *tty)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
2008-07-22 06:09:07 -04:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int room = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-01-19 11:02:37 -05:00
|
|
|
room = oti6858_buf_space_avail(priv->buf);
|
2007-03-27 06:34:30 -04:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_chars_in_buffer(struct tty_struct *tty)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
2008-07-22 06:09:07 -04:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int chars = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2008-01-19 11:02:37 -05:00
|
|
|
chars = oti6858_buf_data_avail(priv->buf);
|
2007-03-27 06:34:30 -04:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
return chars;
|
|
|
|
}
|
|
|
|
|
2009-09-19 16:13:33 -04:00
|
|
|
static void oti6858_init_termios(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
*(tty->termios) = tty_std_termios;
|
|
|
|
tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL;
|
|
|
|
tty->termios->c_ispeed = 38400;
|
|
|
|
tty->termios->c_ospeed = 38400;
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
static void oti6858_set_termios(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct ktermios *old_termios)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int cflag;
|
|
|
|
u8 frame_fmt, control;
|
2008-04-28 02:00:16 -04:00
|
|
|
__le16 divisor;
|
2007-03-27 06:34:30 -04:00
|
|
|
int br;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
if (!tty) {
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): no tty structures", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
cflag = tty->termios->c_cflag;
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
divisor = priv->pending_setup.divisor;
|
|
|
|
frame_fmt = priv->pending_setup.frame_fmt;
|
|
|
|
control = priv->pending_setup.control;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
frame_fmt &= ~FMT_DATA_BITS_MASK;
|
|
|
|
switch (cflag & CSIZE) {
|
2008-07-22 06:15:36 -04:00
|
|
|
case CS5:
|
|
|
|
frame_fmt |= FMT_DATA_BITS_5;
|
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
frame_fmt |= FMT_DATA_BITS_6;
|
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
frame_fmt |= FMT_DATA_BITS_7;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case CS8:
|
|
|
|
frame_fmt |= FMT_DATA_BITS_8;
|
|
|
|
break;
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* manufacturer claims that this device can work with baud rates
|
|
|
|
* up to 3 Mbps; I've tested it only on 115200 bps, so I can't
|
|
|
|
* guarantee that any other baud rate will work (especially
|
|
|
|
* the higher ones)
|
|
|
|
*/
|
2008-07-22 06:09:07 -04:00
|
|
|
br = tty_get_baud_rate(tty);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (br == 0) {
|
|
|
|
divisor = 0;
|
2008-01-19 11:02:37 -05:00
|
|
|
} else {
|
2007-03-27 06:34:30 -04:00
|
|
|
int real_br;
|
2008-04-28 02:00:16 -04:00
|
|
|
int new_divisor;
|
2008-01-19 11:02:37 -05:00
|
|
|
br = min(br, OTI6858_MAX_BAUD_RATE);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2008-04-28 02:00:16 -04:00
|
|
|
new_divisor = (96000000 + 8 * br) / (16 * br);
|
|
|
|
real_br = 96000000 / (16 * new_divisor);
|
|
|
|
divisor = cpu_to_le16(new_divisor);
|
2008-07-22 06:09:07 -04:00
|
|
|
tty_encode_baud_rate(tty, real_br, real_br);
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
frame_fmt &= ~FMT_STOP_BITS_MASK;
|
2008-07-22 06:15:36 -04:00
|
|
|
if ((cflag & CSTOPB) != 0)
|
2007-03-27 06:34:30 -04:00
|
|
|
frame_fmt |= FMT_STOP_BITS_2;
|
2008-07-22 06:15:36 -04:00
|
|
|
else
|
2007-03-27 06:34:30 -04:00
|
|
|
frame_fmt |= FMT_STOP_BITS_1;
|
|
|
|
|
|
|
|
frame_fmt &= ~FMT_PARITY_MASK;
|
|
|
|
if ((cflag & PARENB) != 0) {
|
2008-07-22 06:15:36 -04:00
|
|
|
if ((cflag & PARODD) != 0)
|
2007-03-27 06:34:30 -04:00
|
|
|
frame_fmt |= FMT_PARITY_ODD;
|
2008-07-22 06:15:36 -04:00
|
|
|
else
|
2007-03-27 06:34:30 -04:00
|
|
|
frame_fmt |= FMT_PARITY_EVEN;
|
|
|
|
} else {
|
|
|
|
frame_fmt |= FMT_PARITY_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
control &= ~CONTROL_MASK;
|
|
|
|
if ((cflag & CRTSCTS) != 0)
|
|
|
|
control |= (CONTROL_DTR_HIGH | CONTROL_RTS_HIGH);
|
|
|
|
|
|
|
|
/* change control lines if we are switching to or from B0 */
|
|
|
|
/* FIXME:
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
control = priv->line_control;
|
|
|
|
if ((cflag & CBAUD) == B0)
|
|
|
|
priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
|
|
|
|
else
|
|
|
|
priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
|
|
|
|
if (control != priv->line_control) {
|
|
|
|
control = priv->line_control;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
set_control_lines(serial->dev, control);
|
|
|
|
} else {
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (divisor != priv->pending_setup.divisor
|
|
|
|
|| control != priv->pending_setup.control
|
|
|
|
|| frame_fmt != priv->pending_setup.frame_fmt) {
|
|
|
|
priv->pending_setup.divisor = divisor;
|
|
|
|
priv->pending_setup.control = control;
|
|
|
|
priv->pending_setup.frame_fmt = frame_fmt;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
|
|
|
|
2009-09-19 16:13:26 -04:00
|
|
|
static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
struct ktermios tmp_termios;
|
|
|
|
struct usb_serial *serial = port->serial;
|
|
|
|
struct oti6858_control_pkt *buf;
|
|
|
|
unsigned long flags;
|
|
|
|
int result;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
usb_clear_halt(serial->dev, port->write_urb->pipe);
|
|
|
|
usb_clear_halt(serial->dev, port->read_urb->pipe);
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
if (port->port.count != 1)
|
2007-03-27 06:34:30 -04:00
|
|
|
return 0;
|
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
|
|
|
|
if (buf == NULL) {
|
2008-03-03 19:08:34 -05:00
|
|
|
dev_err(&port->dev, "%s(): out of memory!\n", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
|
|
|
|
OTI6858_REQ_T_GET_STATUS,
|
|
|
|
OTI6858_REQ_GET_STATUS,
|
|
|
|
0, 0,
|
|
|
|
buf, OTI6858_CTRL_PKT_SIZE,
|
|
|
|
100);
|
|
|
|
if (result != OTI6858_CTRL_PKT_SIZE) {
|
|
|
|
/* assume default (after power-on reset) values */
|
|
|
|
buf->divisor = cpu_to_le16(0x009c); /* 38400 bps */
|
|
|
|
buf->frame_fmt = 0x03; /* 8N1 */
|
|
|
|
buf->something = 0x43;
|
|
|
|
buf->control = 0x4c; /* DTR, RTS */
|
|
|
|
buf->tx_status = 0x00;
|
|
|
|
buf->pin_state = 0x5b; /* RTS, CTS, DSR, DTR, RI, DCD */
|
|
|
|
buf->rx_bytes_avail = 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
memcpy(&priv->status, buf, OTI6858_CTRL_PKT_SIZE);
|
|
|
|
priv->pending_setup.divisor = buf->divisor;
|
|
|
|
priv->pending_setup.frame_fmt = buf->frame_fmt;
|
|
|
|
priv->pending_setup.control = buf->control;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
kfree(buf);
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): submitting interrupt urb", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
port->interrupt_in_urb->dev = serial->dev;
|
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
|
|
|
|
if (result != 0) {
|
|
|
|
dev_err(&port->dev, "%s(): usb_submit_urb() failed"
|
2008-03-03 19:08:34 -05:00
|
|
|
" with error %d\n", __func__, result);
|
2009-06-11 07:26:29 -04:00
|
|
|
oti6858_close(port);
|
2007-03-27 06:34:30 -04:00
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup termios */
|
2008-07-22 06:09:07 -04:00
|
|
|
if (tty)
|
|
|
|
oti6858_set_termios(tty, port, &tmp_termios);
|
2009-06-11 07:26:29 -04:00
|
|
|
port->port.drain_delay = 256; /* FIXME: check the FIFO length */
|
2007-03-27 06:34:30 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-11 07:26:29 -04:00
|
|
|
static void oti6858_close(struct usb_serial_port *port)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
/* clear out any remaining data in the buffer */
|
2008-01-19 11:02:37 -05:00
|
|
|
oti6858_buf_clear(priv->buf);
|
2007-03-27 06:34:30 -04:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2009-06-11 07:26:29 -04:00
|
|
|
dbg("%s(): after buf_clear()", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
/* cancel scheduled setup */
|
|
|
|
cancel_delayed_work(&priv->delayed_setup_work);
|
|
|
|
cancel_delayed_work(&priv->delayed_write_work);
|
|
|
|
flush_scheduled_work();
|
|
|
|
|
|
|
|
/* shutdown our urbs */
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): shutting down urbs", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
usb_kill_urb(port->write_urb);
|
|
|
|
usb_kill_urb(port->read_urb);
|
|
|
|
usb_kill_urb(port->interrupt_in_urb);
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int set, unsigned int clear)
|
|
|
|
{
|
2008-07-22 06:09:07 -04:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
u8 control;
|
|
|
|
|
|
|
|
dbg("%s(port = %d, set = 0x%08x, clear = 0x%08x)",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, port->number, set, clear);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
if (!usb_get_intfdata(port->serial->interface))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* FIXME: check if this is correct (active high/low) */
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
control = priv->pending_setup.control;
|
|
|
|
if ((set & TIOCM_RTS) != 0)
|
|
|
|
control |= CONTROL_RTS_HIGH;
|
|
|
|
if ((set & TIOCM_DTR) != 0)
|
|
|
|
control |= CONTROL_DTR_HIGH;
|
|
|
|
if ((clear & TIOCM_RTS) != 0)
|
|
|
|
control &= ~CONTROL_RTS_HIGH;
|
|
|
|
if ((clear & TIOCM_DTR) != 0)
|
|
|
|
control &= ~CONTROL_DTR_HIGH;
|
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
if (control != priv->pending_setup.control)
|
2007-03-27 06:34:30 -04:00
|
|
|
priv->pending_setup.control = control;
|
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2007-03-27 06:34:30 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_tiocmget(struct tty_struct *tty, struct file *file)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
2008-07-22 06:09:07 -04:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned pin_state;
|
|
|
|
unsigned result = 0;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(port = %d)", __func__, port->number);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
if (!usb_get_intfdata(port->serial->interface))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
pin_state = priv->status.pin_state & PIN_MASK;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
/* FIXME: check if this is correct (active high/low) */
|
|
|
|
if ((pin_state & PIN_RTS) != 0)
|
|
|
|
result |= TIOCM_RTS;
|
|
|
|
if ((pin_state & PIN_CTS) != 0)
|
|
|
|
result |= TIOCM_CTS;
|
|
|
|
if ((pin_state & PIN_DSR) != 0)
|
|
|
|
result |= TIOCM_DSR;
|
|
|
|
if ((pin_state & PIN_DTR) != 0)
|
|
|
|
result |= TIOCM_DTR;
|
|
|
|
if ((pin_state & PIN_RI) != 0)
|
|
|
|
result |= TIOCM_RI;
|
|
|
|
if ((pin_state & PIN_DCD) != 0)
|
|
|
|
result |= TIOCM_CD;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s() = 0x%08x", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
|
|
|
|
{
|
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int prev, status;
|
|
|
|
unsigned int changed;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
prev = priv->status.pin_state;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
while (1) {
|
2008-07-22 06:15:36 -04:00
|
|
|
wait_event_interruptible(priv->intr_wait,
|
|
|
|
priv->status.pin_state != prev);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (signal_pending(current))
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
status = priv->status.pin_state & PIN_MASK;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
changed = prev ^ status;
|
|
|
|
/* FIXME: check if this is correct (active high/low) */
|
2008-07-22 06:15:36 -04:00
|
|
|
if (((arg & TIOCM_RNG) && (changed & PIN_RI)) ||
|
|
|
|
((arg & TIOCM_DSR) && (changed & PIN_DSR)) ||
|
|
|
|
((arg & TIOCM_CD) && (changed & PIN_DCD)) ||
|
|
|
|
((arg & TIOCM_CTS) && (changed & PIN_CTS)))
|
|
|
|
return 0;
|
2007-03-27 06:34:30 -04:00
|
|
|
prev = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-22 06:09:07 -04:00
|
|
|
static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2008-07-22 06:09:07 -04:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
dbg("%s(port = %d, cmd = 0x%04x, arg = 0x%08lx)",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, port->number, cmd, arg);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
switch (cmd) {
|
2008-07-22 06:15:36 -04:00
|
|
|
case TIOCMIWAIT:
|
|
|
|
dbg("%s(): TIOCMIWAIT", __func__);
|
|
|
|
return wait_modem_info(port, arg);
|
|
|
|
default:
|
|
|
|
dbg("%s(): 0x%04x not supported", __func__, cmd);
|
|
|
|
break;
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-02 11:53:55 -04:00
|
|
|
static void oti6858_release(struct usb_serial *serial)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
struct oti6858_private *priv;
|
|
|
|
int i;
|
|
|
|
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s()", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
for (i = 0; i < serial->num_ports; ++i) {
|
|
|
|
priv = usb_get_serial_port_data(serial->port[i]);
|
|
|
|
if (priv) {
|
2008-01-19 11:02:37 -05:00
|
|
|
oti6858_buf_free(priv->buf);
|
2007-03-27 06:34:30 -04:00
|
|
|
kfree(priv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void oti6858_read_int_callback(struct urb *urb)
|
|
|
|
{
|
2008-02-24 05:41:47 -05:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int transient = 0, can_recv = 0, resubmit = 1;
|
2007-06-15 18:44:13 -04:00
|
|
|
int status = urb->status;
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2007-06-15 18:44:13 -04:00
|
|
|
dbg("%s(port = %d, status = %d)",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, port->number, status);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2007-06-15 18:44:13 -04:00
|
|
|
switch (status) {
|
2007-03-27 06:34:30 -04:00
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
|
|
|
dbg("%s(): urb shutting down with status: %d",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, status);
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
dbg("%s(): nonzero urb status received: %d",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, status);
|
2007-03-27 06:34:30 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-06-15 18:44:13 -04:00
|
|
|
if (status == 0 && urb->actual_length == OTI6858_CTRL_PKT_SIZE) {
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_control_pkt *xs = urb->transfer_buffer;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
|
|
|
|
if (!priv->transient) {
|
|
|
|
if (!OTI6858_CTRL_EQUALS_PENDING(xs, priv)) {
|
|
|
|
if (xs->rx_bytes_avail == 0) {
|
|
|
|
priv->transient = 4;
|
|
|
|
priv->setup_done = 0;
|
|
|
|
resubmit = 0;
|
|
|
|
dbg("%s(): scheduling setup_line()",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
schedule_delayed_work(&priv->delayed_setup_work, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (OTI6858_CTRL_EQUALS_PENDING(xs, priv)) {
|
|
|
|
priv->transient = 0;
|
|
|
|
} else if (!priv->setup_done) {
|
|
|
|
resubmit = 0;
|
|
|
|
} else if (--priv->transient == 0) {
|
|
|
|
if (xs->rx_bytes_avail == 0) {
|
|
|
|
priv->transient = 4;
|
|
|
|
priv->setup_done = 0;
|
|
|
|
resubmit = 0;
|
|
|
|
dbg("%s(): scheduling setup_line()",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
schedule_delayed_work(&priv->delayed_setup_work, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->transient) {
|
|
|
|
if (xs->pin_state != priv->status.pin_state)
|
|
|
|
wake_up_interruptible(&priv->intr_wait);
|
|
|
|
memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->transient && xs->rx_bytes_avail != 0) {
|
|
|
|
can_recv = xs->rx_bytes_avail;
|
|
|
|
priv->flags.read_urb_in_use = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
transient = priv->transient;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (can_recv) {
|
|
|
|
int result;
|
|
|
|
|
|
|
|
port->read_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
|
|
|
|
if (result != 0) {
|
|
|
|
priv->flags.read_urb_in_use = 0;
|
|
|
|
dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
|
2008-03-03 19:08:34 -05:00
|
|
|
" error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
} else {
|
|
|
|
resubmit = 0;
|
|
|
|
}
|
|
|
|
} else if (!transient) {
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (priv->flags.write_urb_in_use == 0
|
2008-01-19 11:02:37 -05:00
|
|
|
&& oti6858_buf_data_avail(priv->buf) != 0) {
|
2008-07-22 06:15:36 -04:00
|
|
|
schedule_delayed_work(&priv->delayed_write_work, 0);
|
2007-03-27 06:34:30 -04:00
|
|
|
resubmit = 0;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resubmit) {
|
|
|
|
int result;
|
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
/* dbg("%s(): submitting interrupt urb", __func__); */
|
2007-03-27 06:34:30 -04:00
|
|
|
urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (result != 0) {
|
|
|
|
dev_err(&urb->dev->dev,
|
|
|
|
"%s(): usb_submit_urb() failed with"
|
2008-03-03 19:08:34 -05:00
|
|
|
" error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void oti6858_read_bulk_callback(struct urb *urb)
|
|
|
|
{
|
2008-02-24 05:41:47 -05:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
|
|
|
struct tty_struct *tty;
|
|
|
|
unsigned char *data = urb->transfer_buffer;
|
|
|
|
unsigned long flags;
|
2007-06-15 18:44:13 -04:00
|
|
|
int status = urb->status;
|
2008-01-19 11:02:37 -05:00
|
|
|
int result;
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2007-06-15 18:44:13 -04:00
|
|
|
dbg("%s(port = %d, status = %d)",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, port->number, status);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
priv->flags.read_urb_in_use = 0;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
2007-06-15 18:44:13 -04:00
|
|
|
if (status != 0) {
|
2008-07-22 06:09:07 -04:00
|
|
|
if (!port->port.count) {
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): port is closed, exiting", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
2007-06-15 18:44:13 -04:00
|
|
|
if (status == -EPROTO) {
|
2008-07-22 06:15:36 -04:00
|
|
|
* PL2303 mysteriously fails with -EPROTO reschedule
|
|
|
|
the read *
|
|
|
|
dbg("%s - caught -EPROTO, resubmitting the urb",
|
|
|
|
__func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
result = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (result)
|
2008-03-03 19:08:34 -05:00
|
|
|
dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*/
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): unable to handle the error, exiting", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-13 05:39:46 -04:00
|
|
|
tty = tty_port_tty_get(&port->port);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (tty != NULL && urb->actual_length > 0) {
|
2008-01-19 11:02:37 -05:00
|
|
|
tty_insert_flip_string(tty, data, urb->actual_length);
|
2007-03-27 06:34:30 -04:00
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
}
|
2008-10-13 05:39:46 -04:00
|
|
|
tty_kref_put(tty);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
/* schedule the interrupt urb if we are still open */
|
2008-07-22 06:09:07 -04:00
|
|
|
if (port->port.count != 0) {
|
2007-03-27 06:34:30 -04:00
|
|
|
port->interrupt_in_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
|
|
|
|
if (result != 0) {
|
|
|
|
dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
|
2008-03-03 19:08:34 -05:00
|
|
|
" error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void oti6858_write_bulk_callback(struct urb *urb)
|
|
|
|
{
|
2008-02-24 05:41:47 -05:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2007-03-27 06:34:30 -04:00
|
|
|
struct oti6858_private *priv = usb_get_serial_port_data(port);
|
2007-06-15 18:44:13 -04:00
|
|
|
int status = urb->status;
|
2007-03-27 06:34:30 -04:00
|
|
|
int result;
|
|
|
|
|
2007-06-15 18:44:13 -04:00
|
|
|
dbg("%s(port = %d, status = %d)",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, port->number, status);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
2007-06-15 18:44:13 -04:00
|
|
|
switch (status) {
|
2007-03-27 06:34:30 -04:00
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
|
|
|
dbg("%s(): urb shutting down with status: %d",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, status);
|
2007-03-27 06:34:30 -04:00
|
|
|
priv->flags.write_urb_in_use = 0;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
/* error in the urb, so we have to resubmit it */
|
|
|
|
dbg("%s(): nonzero write bulk status received: %d",
|
2008-03-03 19:08:34 -05:00
|
|
|
__func__, status);
|
|
|
|
dbg("%s(): overflow in write", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
port->write_urb->transfer_buffer_length = 1;
|
|
|
|
port->write_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
|
|
|
|
if (result) {
|
|
|
|
dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
|
2008-03-03 19:08:34 -05:00
|
|
|
" error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->flags.write_urb_in_use = 0;
|
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
/* schedule the interrupt urb if we are still open */
|
2007-03-27 06:34:30 -04:00
|
|
|
port->interrupt_in_urb->dev = port->serial->dev;
|
2008-03-03 19:08:34 -05:00
|
|
|
dbg("%s(): submitting interrupt urb", __func__);
|
2007-03-27 06:34:30 -04:00
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
|
|
|
|
if (result != 0) {
|
|
|
|
dev_err(&port->dev, "%s(): failed submitting int urb,"
|
2008-03-03 19:08:34 -05:00
|
|
|
" error %d\n", __func__, result);
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-01-19 11:02:37 -05:00
|
|
|
* oti6858_buf_alloc
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* Allocate a circular buffer and all associated memory.
|
|
|
|
*/
|
2008-01-19 11:02:37 -05:00
|
|
|
static struct oti6858_buf *oti6858_buf_alloc(unsigned int size)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
2008-01-19 11:02:37 -05:00
|
|
|
struct oti6858_buf *pb;
|
2007-03-27 06:34:30 -04:00
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2008-01-19 11:02:37 -05:00
|
|
|
pb = kmalloc(sizeof(struct oti6858_buf), GFP_KERNEL);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (pb == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pb->buf_buf = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (pb->buf_buf == NULL) {
|
|
|
|
kfree(pb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pb->buf_size = size;
|
|
|
|
pb->buf_get = pb->buf_put = pb->buf_buf;
|
|
|
|
|
|
|
|
return pb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-19 11:02:37 -05:00
|
|
|
* oti6858_buf_free
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* Free the buffer and all associated memory.
|
|
|
|
*/
|
2008-01-19 11:02:37 -05:00
|
|
|
static void oti6858_buf_free(struct oti6858_buf *pb)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
if (pb) {
|
|
|
|
kfree(pb->buf_buf);
|
|
|
|
kfree(pb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-19 11:02:37 -05:00
|
|
|
* oti6858_buf_clear
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* Clear out all data in the circular buffer.
|
|
|
|
*/
|
2008-01-19 11:02:37 -05:00
|
|
|
static void oti6858_buf_clear(struct oti6858_buf *pb)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
if (pb != NULL) {
|
|
|
|
/* equivalent to a get of all data available */
|
|
|
|
pb->buf_get = pb->buf_put;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-19 11:02:37 -05:00
|
|
|
* oti6858_buf_data_avail
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* Return the number of bytes of data available in the circular
|
|
|
|
* buffer.
|
|
|
|
*/
|
2008-01-19 11:02:37 -05:00
|
|
|
static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
if (pb == NULL)
|
|
|
|
return 0;
|
2008-07-22 06:15:36 -04:00
|
|
|
return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-19 11:02:37 -05:00
|
|
|
* oti6858_buf_space_avail
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* Return the number of bytes of space available in the circular
|
|
|
|
* buffer.
|
|
|
|
*/
|
2008-01-19 11:02:37 -05:00
|
|
|
static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb)
|
2007-03-27 06:34:30 -04:00
|
|
|
{
|
|
|
|
if (pb == NULL)
|
|
|
|
return 0;
|
2008-07-22 06:15:36 -04:00
|
|
|
return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
|
2007-03-27 06:34:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-19 11:02:37 -05:00
|
|
|
* oti6858_buf_put
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* Copy data data from a user buffer and put it into the circular buffer.
|
|
|
|
* Restrict to the amount of space available.
|
|
|
|
*
|
|
|
|
* Return the number of bytes copied.
|
|
|
|
*/
|
2008-01-19 11:02:37 -05:00
|
|
|
static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int count)
|
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
if (pb == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2008-01-19 11:02:37 -05:00
|
|
|
len = oti6858_buf_space_avail(pb);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (count > len)
|
|
|
|
count = len;
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len = pb->buf_buf + pb->buf_size - pb->buf_put;
|
|
|
|
if (count > len) {
|
|
|
|
memcpy(pb->buf_put, buf, len);
|
|
|
|
memcpy(pb->buf_buf, buf+len, count - len);
|
|
|
|
pb->buf_put = pb->buf_buf + count - len;
|
|
|
|
} else {
|
|
|
|
memcpy(pb->buf_put, buf, count);
|
|
|
|
if (count < len)
|
|
|
|
pb->buf_put += count;
|
|
|
|
else /* count == len */
|
|
|
|
pb->buf_put = pb->buf_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-19 11:02:37 -05:00
|
|
|
* oti6858_buf_get
|
2007-03-27 06:34:30 -04:00
|
|
|
*
|
|
|
|
* Get data from the circular buffer and copy to the given buffer.
|
|
|
|
* Restrict to the amount of data available.
|
|
|
|
*
|
|
|
|
* Return the number of bytes copied.
|
|
|
|
*/
|
2008-01-19 11:02:37 -05:00
|
|
|
static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
|
2007-03-27 06:34:30 -04:00
|
|
|
unsigned int count)
|
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
if (pb == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2008-01-19 11:02:37 -05:00
|
|
|
len = oti6858_buf_data_avail(pb);
|
2007-03-27 06:34:30 -04:00
|
|
|
if (count > len)
|
|
|
|
count = len;
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len = pb->buf_buf + pb->buf_size - pb->buf_get;
|
|
|
|
if (count > len) {
|
|
|
|
memcpy(buf, pb->buf_get, len);
|
|
|
|
memcpy(buf+len, pb->buf_buf, count - len);
|
|
|
|
pb->buf_get = pb->buf_buf + count - len;
|
|
|
|
} else {
|
|
|
|
memcpy(buf, pb->buf_get, count);
|
|
|
|
if (count < len)
|
|
|
|
pb->buf_get += count;
|
|
|
|
else /* count == len */
|
|
|
|
pb->buf_get = pb->buf_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* module description and (de)initialization */
|
|
|
|
|
|
|
|
static int __init oti6858_init(void)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2008-07-22 06:15:36 -04:00
|
|
|
retval = usb_serial_register(&oti6858_device);
|
|
|
|
if (retval == 0) {
|
|
|
|
retval = usb_register(&oti6858_driver);
|
|
|
|
if (retval)
|
2007-03-27 06:34:30 -04:00
|
|
|
usb_serial_deregister(&oti6858_device);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit oti6858_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&oti6858_driver);
|
|
|
|
usb_serial_deregister(&oti6858_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(oti6858_init);
|
|
|
|
module_exit(oti6858_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(OTI6858_DESCRIPTION);
|
|
|
|
MODULE_AUTHOR(OTI6858_AUTHOR);
|
|
|
|
MODULE_VERSION(OTI6858_VERSION);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_param(debug, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(debug, "enable debug output");
|
|
|
|
|