From: Mathieu OTHACEHE <m.othacehe@gmail.com>
To: johan@kernel.org
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mathieu OTHACEHE <m.othacehe@gmail.com>
Subject: [PATCH 12/36] usb: serial: ti_usb_3410_5052: Use generic read/write callbacks
Date: Thu, 12 May 2016 10:48:44 +0200 [thread overview]
Message-ID: <1463042948-12205-13-git-send-email-m.othacehe@gmail.com> (raw)
In-Reply-To: <1463042948-12205-1-git-send-email-m.othacehe@gmail.com>
Remove read_bulk_callback, write_bulk_callback, write, write_room,
chars_in_buffer, throttle and unthrottle callbacks who uselessly
reimplements generic functions.
Signed-off-by: Mathieu OTHACEHE <m.othacehe@gmail.com>
---
drivers/usb/serial/ti_usb_3410_5052.c | 315 ----------------------------------
1 file changed, 315 deletions(-)
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 601fab6..58df42d 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -268,11 +268,6 @@ struct ti_firmware_header {
/* supported setserial flags */
#define TI_SET_SERIAL_FLAGS 0
-/* read urb states */
-#define TI_READ_URB_RUNNING 0
-#define TI_READ_URB_STOPPING 1
-#define TI_READ_URB_STOPPED 2
-
#define TI_EXTRA_VID_PID_COUNT 5
struct ti_port {
@@ -285,8 +280,6 @@ struct ti_port {
struct ti_device *tp_tdev;
struct usb_serial_port *tp_port;
spinlock_t tp_lock;
- int tp_read_urb_state;
- int tp_write_urb_in_use;
};
struct ti_device {
@@ -304,13 +297,7 @@ static int ti_port_probe(struct usb_serial_port *port);
static int ti_port_remove(struct usb_serial_port *port);
static int ti_open(struct tty_struct *tty, struct usb_serial_port *port);
static void ti_close(struct usb_serial_port *port);
-static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
- const unsigned char *data, int count);
-static int ti_write_room(struct tty_struct *tty);
-static int ti_chars_in_buffer(struct tty_struct *tty);
static bool ti_tx_empty(struct usb_serial_port *port);
-static void ti_throttle(struct tty_struct *tty);
-static void ti_unthrottle(struct tty_struct *tty);
static int ti_ioctl(struct tty_struct *tty,
unsigned int cmd, unsigned long arg);
static void ti_set_termios(struct tty_struct *tty,
@@ -320,12 +307,7 @@ static int ti_tiocmset(struct tty_struct *tty,
unsigned int set, unsigned int clear);
static void ti_break(struct tty_struct *tty, int break_state);
static void ti_interrupt_callback(struct urb *urb);
-static void ti_bulk_in_callback(struct urb *urb);
-static void ti_bulk_out_callback(struct urb *urb);
-static void ti_recv(struct usb_serial_port *port, unsigned char *data,
- int length);
-static void ti_send(struct ti_port *tport);
static int ti_set_mcr(struct ti_port *tport, unsigned int mcr);
static int ti_get_lsr(struct ti_port *tport, u8 *lsr);
static int ti_get_serial_info(struct ti_port *tport,
@@ -334,9 +316,6 @@ static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
struct serial_struct __user *new_arg);
static void ti_handle_new_msr(struct ti_port *tport, u8 msr);
-static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty);
-static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty);
-
static int ti_command_out_sync(struct ti_device *tdev, __u8 command,
__u16 moduleid, __u16 value, __u8 *data, int size);
static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
@@ -425,12 +404,7 @@ static struct usb_serial_driver ti_1port_device = {
.port_remove = ti_port_remove,
.open = ti_open,
.close = ti_close,
- .write = ti_write,
- .write_room = ti_write_room,
- .chars_in_buffer = ti_chars_in_buffer,
.tx_empty = ti_tx_empty,
- .throttle = ti_throttle,
- .unthrottle = ti_unthrottle,
.ioctl = ti_ioctl,
.set_termios = ti_set_termios,
.tiocmget = ti_tiocmget,
@@ -439,8 +413,6 @@ static struct usb_serial_driver ti_1port_device = {
.get_icount = usb_serial_generic_get_icount,
.break_ctl = ti_break,
.read_int_callback = ti_interrupt_callback,
- .read_bulk_callback = ti_bulk_in_callback,
- .write_bulk_callback = ti_bulk_out_callback,
};
static struct usb_serial_driver ti_2port_device = {
@@ -457,12 +429,7 @@ static struct usb_serial_driver ti_2port_device = {
.port_remove = ti_port_remove,
.open = ti_open,
.close = ti_close,
- .write = ti_write,
- .write_room = ti_write_room,
- .chars_in_buffer = ti_chars_in_buffer,
.tx_empty = ti_tx_empty,
- .throttle = ti_throttle,
- .unthrottle = ti_unthrottle,
.ioctl = ti_ioctl,
.set_termios = ti_set_termios,
.tiocmget = ti_tiocmget,
@@ -471,8 +438,6 @@ static struct usb_serial_driver ti_2port_device = {
.get_icount = usb_serial_generic_get_icount,
.break_ctl = ti_break,
.read_int_callback = ti_interrupt_callback,
- .read_bulk_callback = ti_bulk_in_callback,
- .write_bulk_callback = ti_bulk_out_callback,
};
static struct usb_serial_driver * const serial_drivers[] = {
@@ -732,7 +697,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
status = -EINVAL;
goto unlink_int_urb;
}
- tport->tp_read_urb_state = TI_READ_URB_RUNNING;
urb->context = tport;
status = usb_submit_urb(urb, GFP_KERNEL);
if (status) {
@@ -771,7 +735,6 @@ static void ti_close(struct usb_serial_port *port)
usb_kill_urb(port->read_urb);
usb_kill_urb(port->write_urb);
- tport->tp_write_urb_in_use = 0;
spin_lock_irqsave(&tport->tp_lock, flags);
kfifo_reset_out(&port->write_fifo);
spin_unlock_irqrestore(&tport->tp_lock, flags);
@@ -797,56 +760,6 @@ static void ti_close(struct usb_serial_port *port)
mutex_unlock(&tdev->td_open_close_lock);
}
-
-static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
- const unsigned char *data, int count)
-{
- struct ti_port *tport = usb_get_serial_port_data(port);
-
- if (count == 0) {
- return 0;
- }
-
- if (!tport->tp_is_open)
- return -ENODEV;
-
- count = kfifo_in_locked(&port->write_fifo, data, count,
- &tport->tp_lock);
- ti_send(tport);
-
- return count;
-}
-
-
-static int ti_write_room(struct tty_struct *tty)
-{
- struct usb_serial_port *port = tty->driver_data;
- struct ti_port *tport = usb_get_serial_port_data(port);
- int room = 0;
- unsigned long flags;
-
- spin_lock_irqsave(&tport->tp_lock, flags);
- room = kfifo_avail(&port->write_fifo);
- spin_unlock_irqrestore(&tport->tp_lock, flags);
-
- return room;
-}
-
-
-static int ti_chars_in_buffer(struct tty_struct *tty)
-{
- struct usb_serial_port *port = tty->driver_data;
- struct ti_port *tport = usb_get_serial_port_data(port);
- int chars = 0;
- unsigned long flags;
-
- spin_lock_irqsave(&tport->tp_lock, flags);
- chars = kfifo_len(&port->write_fifo);
- spin_unlock_irqrestore(&tport->tp_lock, flags);
-
- return chars;
-}
-
static bool ti_tx_empty(struct usb_serial_port *port)
{
struct ti_port *tport = usb_get_serial_port_data(port);
@@ -860,31 +773,6 @@ static bool ti_tx_empty(struct usb_serial_port *port)
return true;
}
-static void ti_throttle(struct tty_struct *tty)
-{
- struct usb_serial_port *port = tty->driver_data;
- struct ti_port *tport = usb_get_serial_port_data(port);
-
- if (I_IXOFF(tty) || C_CRTSCTS(tty))
- ti_stop_read(tport, tty);
-
-}
-
-
-static void ti_unthrottle(struct tty_struct *tty)
-{
- struct usb_serial_port *port = tty->driver_data;
- struct ti_port *tport = usb_get_serial_port_data(port);
- int status;
-
- if (I_IXOFF(tty) || C_CRTSCTS(tty)) {
- status = ti_restart_read(tport, tty);
- if (status)
- dev_err(&port->dev, "%s - cannot restart read, %d\n",
- __func__, status);
- }
-}
-
static int ti_ioctl(struct tty_struct *tty,
unsigned int cmd, unsigned long arg)
{
@@ -978,8 +866,6 @@ static void ti_set_termios(struct tty_struct *tty,
if ((C_BAUD(tty)) != B0)
config->wFlags |= TI_UART_ENABLE_RTS_IN;
config->wFlags |= TI_UART_ENABLE_CTS_OUT;
- } else {
- ti_restart_read(tport, tty);
}
if (I_IXOFF(tty) || I_IXON(tty)) {
@@ -988,8 +874,6 @@ static void ti_set_termios(struct tty_struct *tty,
if (I_IXOFF(tty))
config->wFlags |= TI_UART_ENABLE_X_IN;
- else
- ti_restart_read(tport, tty);
if (I_IXON(tty))
config->wFlags |= TI_UART_ENABLE_X_OUT;
@@ -1193,168 +1077,6 @@ exit:
__func__, retval);
}
-
-static void ti_bulk_in_callback(struct urb *urb)
-{
- struct ti_port *tport = urb->context;
- struct usb_serial_port *port = tport->tp_port;
- struct device *dev = &urb->dev->dev;
- int status = urb->status;
- int retval = 0;
-
- switch (status) {
- case 0:
- break;
- case -ECONNRESET:
- case -ENOENT:
- case -ESHUTDOWN:
- dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status);
- tport->tp_tdev->td_urb_error = 1;
- return;
- default:
- dev_err(dev, "%s - nonzero urb status, %d\n",
- __func__, status);
- tport->tp_tdev->td_urb_error = 1;
- }
-
- if (status == -EPIPE)
- goto exit;
-
- if (status) {
- dev_err(dev, "%s - stopping read!\n", __func__);
- return;
- }
-
- if (urb->actual_length) {
- usb_serial_debug_data(dev, __func__, urb->actual_length,
- urb->transfer_buffer);
-
- if (!tport->tp_is_open)
- dev_dbg(dev, "%s - port closed, dropping data\n",
- __func__);
- else
- ti_recv(port, urb->transfer_buffer, urb->actual_length);
- spin_lock(&tport->tp_lock);
- port->icount.rx += urb->actual_length;
- spin_unlock(&tport->tp_lock);
- }
-
-exit:
- /* continue to read unless stopping */
- spin_lock(&tport->tp_lock);
- if (tport->tp_read_urb_state == TI_READ_URB_RUNNING)
- retval = usb_submit_urb(urb, GFP_ATOMIC);
- else if (tport->tp_read_urb_state == TI_READ_URB_STOPPING)
- tport->tp_read_urb_state = TI_READ_URB_STOPPED;
-
- spin_unlock(&tport->tp_lock);
- if (retval)
- dev_err(dev, "%s - resubmit read urb failed, %d\n",
- __func__, retval);
-}
-
-
-static void ti_bulk_out_callback(struct urb *urb)
-{
- struct ti_port *tport = urb->context;
- struct usb_serial_port *port = tport->tp_port;
- int status = urb->status;
-
- tport->tp_write_urb_in_use = 0;
-
- switch (status) {
- case 0:
- break;
- case -ECONNRESET:
- case -ENOENT:
- case -ESHUTDOWN:
- dev_dbg(&port->dev, "%s - urb shutting down, %d\n", __func__, status);
- tport->tp_tdev->td_urb_error = 1;
- return;
- default:
- dev_err_console(port, "%s - nonzero urb status, %d\n",
- __func__, status);
- tport->tp_tdev->td_urb_error = 1;
- }
-
- /* send any buffered data */
- ti_send(tport);
-}
-
-
-static void ti_recv(struct usb_serial_port *port, unsigned char *data,
- int length)
-{
- int cnt;
-
- do {
- cnt = tty_insert_flip_string(&port->port, data, length);
- if (cnt < length) {
- dev_err(&port->dev, "%s - dropping data, %d bytes lost\n",
- __func__, length - cnt);
- if (cnt == 0)
- break;
- }
- tty_flip_buffer_push(&port->port);
- data += cnt;
- length -= cnt;
- } while (length > 0);
-}
-
-
-static void ti_send(struct ti_port *tport)
-{
- int count, result;
- struct usb_serial_port *port = tport->tp_port;
- unsigned long flags;
-
- spin_lock_irqsave(&tport->tp_lock, flags);
-
- if (tport->tp_write_urb_in_use)
- goto unlock;
-
- count = kfifo_out(&port->write_fifo,
- port->write_urb->transfer_buffer,
- port->bulk_out_size);
-
- if (count == 0)
- goto unlock;
-
- tport->tp_write_urb_in_use = 1;
-
- spin_unlock_irqrestore(&tport->tp_lock, flags);
-
- usb_serial_debug_data(&port->dev, __func__, count,
- port->write_urb->transfer_buffer);
-
- usb_fill_bulk_urb(port->write_urb, port->serial->dev,
- usb_sndbulkpipe(port->serial->dev,
- port->bulk_out_endpointAddress),
- port->write_urb->transfer_buffer, count,
- ti_bulk_out_callback, tport);
-
- result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
- if (result) {
- dev_err_console(port, "%s - submit write urb failed, %d\n",
- __func__, result);
- tport->tp_write_urb_in_use = 0;
- /* TODO: reschedule ti_send */
- } else {
- spin_lock_irqsave(&tport->tp_lock, flags);
- port->icount.tx += count;
- spin_unlock_irqrestore(&tport->tp_lock, flags);
- }
-
- /* more room in the buffer for new writes, wakeup */
- tty_port_tty_wakeup(&port->port);
-
- return;
-unlock:
- spin_unlock_irqrestore(&tport->tp_lock, flags);
- return;
-}
-
-
static int ti_set_mcr(struct ti_port *tport, unsigned int mcr)
{
unsigned long flags;
@@ -1490,43 +1212,6 @@ static void ti_handle_new_msr(struct ti_port *tport, u8 msr)
tty_kref_put(tty);
}
-
-static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&tport->tp_lock, flags);
-
- if (tport->tp_read_urb_state == TI_READ_URB_RUNNING)
- tport->tp_read_urb_state = TI_READ_URB_STOPPING;
-
- spin_unlock_irqrestore(&tport->tp_lock, flags);
-}
-
-
-static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty)
-{
- struct urb *urb;
- int status = 0;
- unsigned long flags;
-
- spin_lock_irqsave(&tport->tp_lock, flags);
-
- if (tport->tp_read_urb_state == TI_READ_URB_STOPPED) {
- tport->tp_read_urb_state = TI_READ_URB_RUNNING;
- urb = tport->tp_port->read_urb;
- spin_unlock_irqrestore(&tport->tp_lock, flags);
- urb->context = tport;
- status = usb_submit_urb(urb, GFP_KERNEL);
- } else {
- tport->tp_read_urb_state = TI_READ_URB_RUNNING;
- spin_unlock_irqrestore(&tport->tp_lock, flags);
- }
-
- return status;
-}
-
-
static int ti_command_out_sync(struct ti_device *tdev, __u8 command,
__u16 moduleid, __u16 value, __u8 *data, int size)
{
--
2.8.2
next prev parent reply other threads:[~2016-05-12 9:01 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 8:48 [PATCH 00/36] usb: serial: ti_usb_3410_5052: clean driver Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 01/36] usb: serial: ti_usb_3410_5052: Remove useless comments Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 02/36] usb: serial: ti_usb_3410_5052: use __packed instead of __attribute__((packed)) Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 03/36] usb: serial: ti_usb_3410_5052: Remove ti_usb_3410_5052.h Mathieu OTHACEHE
2016-07-15 10:49 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 04/36] usb: serial: ti_usb_3410_5052: Use inline functions rather than macro Mathieu OTHACEHE
2016-05-12 12:00 ` Sergei Shtylyov
2016-07-15 10:50 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 05/36] usb: serial: ti_usb_3410_5052: Remove unused data structures Mathieu OTHACEHE
2016-07-15 10:53 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 06/36] usb: serial: ti_usb_3410_5052: Do not use __uX types Mathieu OTHACEHE
2016-07-15 11:03 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 07/36] usb: serial: ti_usb_3410_5052: Remove closing_wait module parameter Mathieu OTHACEHE
2016-07-15 11:08 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 08/36] usb: serial: ti_usb_3410_5052: Remove useless dev_dbg messages Mathieu OTHACEHE
2016-07-15 11:12 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 09/36] usb: serial: ti_usb_3410_5052: Use kzalloc instead of kmalloc Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 10/36] usb: serial: ti_usb_3410_5052: Remove useless NULL-testing Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 11/36] usb: serial: ti_usb_3410_5052: Use C_X macros instead of c_cflag manipulation Mathieu OTHACEHE
2016-05-12 8:48 ` Mathieu OTHACEHE [this message]
2016-07-15 11:19 ` [PATCH 12/36] usb: serial: ti_usb_3410_5052: Use generic read/write callbacks Johan Hovold
2016-05-12 8:48 ` [PATCH 13/36] usb: serial: ti_usb_3410_5052: Remove unused variables Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 14/36] usb: serial: ti_usb_3410_5052: Use macros instead of magic values Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 15/36] usb: serial: ti_usb_3410_5052: Remove in_sync and out_sync functions Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 16/36] usb: serial: ti_usb_3410_5052: Use bulk_out_size in TIOCGSERIAL Mathieu OTHACEHE
2016-07-15 11:27 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 17/36] usb: serial: ti_usb_3410_5052: Remove useless tty_wakeup Mathieu OTHACEHE
2016-07-15 11:33 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 18/36] usb: serial: ti_usb_3410_5052: Change ti_write_byte function arguments Mathieu OTHACEHE
2016-07-15 11:36 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 19/36] usb: serial: ti_usb_3410_5052: Do not modify interrupt context Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 20/36] usb: serial: ti_usb_3410_5052: Remove usb_serial pointer in ti_port Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 21/36] usb: serial: ti_usb_3410_5052: Use generic close function Mathieu OTHACEHE
2016-07-15 12:08 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 22/36] usb: serial: ti_usb_3410_5052: Change ti_get/set_serial_info function arguments Mathieu OTHACEHE
2016-07-15 12:09 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 23/36] usb: serial: ti_usb_3410_5052: Do not set shadow mcr in open callback Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 24/36] usb: serial: ti_usb_3410_5052: Use usb_serial_generic_open Mathieu OTHACEHE
2016-07-15 12:12 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 25/36] usb: serial: ti_usb_3410_5052: Check old_termios parameter in set_termios Mathieu OTHACEHE
2016-07-15 12:14 ` Johan Hovold
2016-05-12 8:48 ` [PATCH 26/36] usb: serial: ti_usb_3410_5052: Fix firmware downloading Mathieu OTHACEHE
2016-05-12 8:48 ` [PATCH 27/36] usb: serial: ti_usb_3410_5052: Standardize debug and error messages Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 28/36] usb: serial: ti_usb_3410_5052: Use variables for vendor and product Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 29/36] usb: serial: ti_usb_3410_5052: Set shadow msr before waking up waiters Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 30/36] usb: serial: ti_usb_3410_5052: Remove backpointer in ti_port Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 31/36] usb: serial: ti_usb_3410_5052: Use a mutex to protect shadow mcr Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 32/36] usb: serial: ti_usb_3410_5052: Remove prefixes from private structures Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 33/36] usb: serial: ti_usb_3410_5052: Add CMSPAR support Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 34/36] usb: serial: ti_usb_3410_5052: Fix indentation problems Mathieu OTHACEHE
2016-05-12 8:49 ` [PATCH 35/36] usb: serial: ti_usb_3410_5052: Remove function prototypes Mathieu OTHACEHE
2016-07-15 12:18 ` Johan Hovold
2016-05-12 8:49 ` [PATCH 36/36] usb: serial: ti_usb_3410_5052: Add myself as an author Mathieu OTHACEHE
2016-07-15 10:48 ` [PATCH 00/36] usb: serial: ti_usb_3410_5052: clean driver Johan Hovold
2016-07-15 12:20 ` Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463042948-12205-13-git-send-email-m.othacehe@gmail.com \
--to=m.othacehe@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome