mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-19 10:14:23 +08:00
USB: serial: omninet: use generic write implementation
Now that the endpoint-port mapping has been properly set up during probe, we can switch to using the more efficient generic write implementation. Note that this currently means that chars_in_buffer now overcounts slightly as we always write a full endpoint-sized packet. Also add a copyright entry. Signed-off-by: Johan Hovold <johan@kernel.org>
This commit is contained in:
parent
2dc1071b34
commit
d27444152c
@ -1,6 +1,8 @@
|
||||
/*
|
||||
* USB ZyXEL omni.net LCD PLUS driver
|
||||
*
|
||||
* Copyright (C) 2013,2017 Johan Hovold <johan@kernel.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 as published by the Free Software Foundation.
|
||||
@ -32,10 +34,8 @@
|
||||
|
||||
/* function prototypes */
|
||||
static void omninet_process_read_urb(struct urb *urb);
|
||||
static void omninet_write_bulk_callback(struct urb *urb);
|
||||
static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
|
||||
const unsigned char *buf, int count);
|
||||
static int omninet_write_room(struct tty_struct *tty);
|
||||
static int omninet_prepare_write_buffer(struct usb_serial_port *port,
|
||||
void *buf, size_t count);
|
||||
static int omninet_calc_num_ports(struct usb_serial *serial,
|
||||
struct usb_serial_endpoints *epds);
|
||||
static int omninet_port_probe(struct usb_serial_port *port);
|
||||
@ -59,10 +59,8 @@ static struct usb_serial_driver zyxel_omninet_device = {
|
||||
.calc_num_ports = omninet_calc_num_ports,
|
||||
.port_probe = omninet_port_probe,
|
||||
.port_remove = omninet_port_remove,
|
||||
.write = omninet_write,
|
||||
.write_room = omninet_write_room,
|
||||
.write_bulk_callback = omninet_write_bulk_callback,
|
||||
.process_read_urb = omninet_process_read_urb,
|
||||
.prepare_write_buffer = omninet_prepare_write_buffer,
|
||||
};
|
||||
|
||||
static struct usb_serial_driver * const serial_drivers[] = {
|
||||
@ -157,81 +155,24 @@ static void omninet_process_read_urb(struct urb *urb)
|
||||
tty_flip_buffer_push(&port->port);
|
||||
}
|
||||
|
||||
static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
|
||||
const unsigned char *buf, int count)
|
||||
static int omninet_prepare_write_buffer(struct usb_serial_port *port,
|
||||
void *buf, size_t count)
|
||||
{
|
||||
struct omninet_data *od = usb_get_serial_port_data(port);
|
||||
struct omninet_header *header = (struct omninet_header *)
|
||||
port->write_urb->transfer_buffer;
|
||||
int result;
|
||||
struct omninet_header *header = buf;
|
||||
|
||||
if (count == 0) {
|
||||
dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
count = min_t(size_t, count, OMNINET_PAYLOADSIZE);
|
||||
|
||||
if (!test_and_clear_bit(0, &port->write_urbs_free)) {
|
||||
dev_dbg(&port->dev, "%s - already writing\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
count = kfifo_out_locked(&port->write_fifo, buf + OMNINET_HEADERLEN,
|
||||
count, &port->lock);
|
||||
|
||||
count = (count > OMNINET_PAYLOADSIZE) ? OMNINET_PAYLOADSIZE : count;
|
||||
header->oh_seq = od->od_outseq++;
|
||||
header->oh_len = count;
|
||||
header->oh_xxx = 0x03;
|
||||
header->oh_pad = 0x00;
|
||||
|
||||
memcpy(port->write_urb->transfer_buffer + OMNINET_HEADERLEN,
|
||||
buf, count);
|
||||
|
||||
usb_serial_debug_data(&port->dev, __func__, count,
|
||||
port->write_urb->transfer_buffer);
|
||||
|
||||
header->oh_seq = od->od_outseq++;
|
||||
header->oh_len = count;
|
||||
header->oh_xxx = 0x03;
|
||||
header->oh_pad = 0x00;
|
||||
|
||||
/* send the data out the bulk port, always 64 bytes */
|
||||
port->write_urb->transfer_buffer_length = OMNINET_BULKOUTSIZE;
|
||||
|
||||
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
|
||||
if (result) {
|
||||
set_bit(0, &port->write_urbs_free);
|
||||
dev_err_console(port,
|
||||
"%s - failed submitting write urb, error %d\n",
|
||||
__func__, result);
|
||||
} else
|
||||
result = count;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int omninet_write_room(struct tty_struct *tty)
|
||||
{
|
||||
struct usb_serial_port *port = tty->driver_data;
|
||||
int room = 0; /* Default: no room */
|
||||
|
||||
if (test_bit(0, &port->write_urbs_free))
|
||||
room = port->bulk_out_size - OMNINET_HEADERLEN;
|
||||
|
||||
dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
static void omninet_write_bulk_callback(struct urb *urb)
|
||||
{
|
||||
/* struct omninet_header *header = (struct omninet_header *)
|
||||
urb->transfer_buffer; */
|
||||
struct usb_serial_port *port = urb->context;
|
||||
int status = urb->status;
|
||||
|
||||
set_bit(0, &port->write_urbs_free);
|
||||
if (status) {
|
||||
dev_dbg(&port->dev, "%s - nonzero write bulk status received: %d\n",
|
||||
__func__, status);
|
||||
return;
|
||||
}
|
||||
|
||||
usb_serial_port_softint(port);
|
||||
/* always 64 bytes */
|
||||
return OMNINET_BULKOUTSIZE;
|
||||
}
|
||||
|
||||
module_usb_serial_driver(serial_drivers, id_table);
|
||||
|
Loading…
Reference in New Issue
Block a user