Skip to content

Commit

Permalink
USB: serial: ports: add minor and port number
Browse files Browse the repository at this point in the history
The usb_serial_port structure had the number field, which was the minor
number for the port, which almost no one really cared about.  They
really wanted the number of the port within the device, which you had to
subtract from the minor of the parent usb_serial_device structure.  To
clean this up, provide the real minor number of the port, and the number
of the port within the serial device separately, as these numbers might
not be related in the future.

Bonus is that this cleans up a lot of logic in the drivers, and saves
lines overall.

Tested-by: Tobias Winter <tobias@linuxdingsda.de>
Reviewed-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

--
 drivers/staging/serqt_usb2/serqt_usb2.c |   21 +++--------
 drivers/usb/serial/ark3116.c            |    2 -
 drivers/usb/serial/bus.c                |    6 +--
 drivers/usb/serial/console.c            |    2 -
 drivers/usb/serial/cp210x.c             |    2 -
 drivers/usb/serial/cypress_m8.c         |    4 +-
 drivers/usb/serial/digi_acceleport.c    |    6 ---
 drivers/usb/serial/f81232.c             |    5 +-
 drivers/usb/serial/garmin_gps.c         |    6 +--
 drivers/usb/serial/io_edgeport.c        |   58 ++++++++++++--------------------
 drivers/usb/serial/io_ti.c              |   21 ++++-------
 drivers/usb/serial/keyspan.c            |   29 +++++++---------
 drivers/usb/serial/metro-usb.c          |    4 +-
 drivers/usb/serial/mos7720.c            |   37 +++++++++-----------
 drivers/usb/serial/mos7840.c            |   52 +++++++++-------------------
 drivers/usb/serial/opticon.c            |    2 -
 drivers/usb/serial/pl2303.c             |    2 -
 drivers/usb/serial/quatech2.c           |    7 +--
 drivers/usb/serial/sierra.c             |    2 -
 drivers/usb/serial/ti_usb_3410_5052.c   |   10 ++---
 drivers/usb/serial/usb-serial.c         |    7 ++-
 drivers/usb/serial/usb_wwan.c           |    2 -
 drivers/usb/serial/whiteheat.c          |   20 +++++------
 include/linux/usb/serial.h              |    6 ++-
 24 files changed, 133 insertions(+), 180 deletions(-)
  • Loading branch information
Greg Kroah-Hartman committed Jun 10, 2013
1 parent 141dc40 commit 1143832
Show file tree
Hide file tree
Showing 24 changed files with 133 additions and 180 deletions.
21 changes: 7 additions & 14 deletions drivers/staging/serqt_usb2/serqt_usb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ static int qt_open(struct tty_struct *tty,
result = qt_get_device(serial, &port0->DeviceData);

/* Port specific setups */
result = qt_open_channel(serial, port->number, &ChannelData);
result = qt_open_channel(serial, port->port_number, &ChannelData);
if (result < 0) {
dev_dbg(&port->dev, "qt_open_channel failed\n");
return result;
Expand All @@ -888,7 +888,7 @@ static int qt_open(struct tty_struct *tty,
(SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD);

/* Set Baud rate to default and turn off (default)flow control here */
result = qt_setuart(serial, port->number, DEFAULT_DIVISOR, DEFAULT_LCR);
result = qt_setuart(serial, port->port_number, DEFAULT_DIVISOR, DEFAULT_LCR);
if (result < 0) {
dev_dbg(&port->dev, "qt_setuart failed\n");
return result;
Expand All @@ -906,7 +906,6 @@ static int qt_open(struct tty_struct *tty,
qt_submit_urb_from_open(serial, port);
}

dev_dbg(&port->dev, "port number is %d\n", port->number);
dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor);
dev_dbg(&port->dev,
"Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
Expand Down Expand Up @@ -1022,14 +1021,11 @@ static void qt_close(struct usb_serial_port *port)
/* Close uart channel */
status = qt_close_channel(serial, index);
if (status < 0)
dev_dbg(&port->dev,
"%s - port %d qt_close_channel failed.\n",
__func__, port->number);
dev_dbg(&port->dev, "%s - qt_close_channel failed.\n", __func__);

port0->open_ports--;

dev_dbg(&port->dev, "qt_num_open_ports in close%d:in port%d\n",
port0->open_ports, port->number);
dev_dbg(&port->dev, "qt_num_open_ports in close%d\n", port0->open_ports);

if (port0->open_ports == 0) {
if (serial->port[0]->interrupt_in_urb) {
Expand Down Expand Up @@ -1169,8 +1165,7 @@ static int qt_ioctl(struct tty_struct *tty,
return 0;
}

dev_dbg(&port->dev, "%s -No ioctl for that one. port = %d\n",
__func__, port->number);
dev_dbg(&port->dev, "%s -No ioctl for that one.\n", __func__);
return -ENOIOCTLCMD;
}

Expand Down Expand Up @@ -1245,8 +1240,7 @@ static void qt_set_termios(struct tty_struct *tty,

/* Now determine flow control */
if (cflag & CRTSCTS) {
dev_dbg(&port->dev, "%s - Enabling HW flow control port %d\n",
__func__, port->number);
dev_dbg(&port->dev, "%s - Enabling HW flow control\n", __func__);

/* Enable RTS/CTS flow control */
status = BoxSetHW_FlowCtrl(port->serial, index, 1);
Expand All @@ -1258,8 +1252,7 @@ static void qt_set_termios(struct tty_struct *tty,
} else {
/* Disable RTS/CTS flow control */
dev_dbg(&port->dev,
"%s - disabling HW flow control port %d\n",
__func__, port->number);
"%s - disabling HW flow control\n", __func__);

status = BoxSetHW_FlowCtrl(port->serial, index, 0);
if (status < 0) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/ark3116.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ static int ark3116_ioctl(struct tty_struct *tty,
memset(&serstruct, 0, sizeof(serstruct));
serstruct.type = PORT_16654;
serstruct.line = port->serial->minor;
serstruct.port = port->number;
serstruct.port = port->port_number;
serstruct.custom_divisor = 0;
serstruct.baud_base = 460800;

Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/serial/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static ssize_t show_port_number(struct device *dev,
{
struct usb_serial_port *port = to_usb_serial_port(dev);

return sprintf(buf, "%d\n", port->number - port->serial->minor);
return sprintf(buf, "%d\n", port->port_number);
}

static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
Expand Down Expand Up @@ -80,7 +80,7 @@ static int usb_serial_device_probe(struct device *dev)
goto exit_with_autopm;
}

minor = port->number;
minor = port->minor;
tty_register_device(usb_serial_tty_driver, minor, dev);
dev_info(&port->serial->dev->dev,
"%s converter now attached to ttyUSB%d\n",
Expand All @@ -106,7 +106,7 @@ static int usb_serial_device_remove(struct device *dev)
/* make sure suspend/resume doesn't race against port_remove */
usb_autopm_get_interface(port->serial->interface);

minor = port->number;
minor = port->minor;
tty_unregister_device(usb_serial_tty_driver, minor);

device_remove_file(&port->dev, &dev_attr_port_number);
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static void usb_console_write(struct console *co,
if (count == 0)
return;

pr_debug("%s - port %d, %d byte(s)\n", __func__, port->number, count);
pr_debug("%s - minor %d, %d byte(s)\n", __func__, port->minor, count);

if (!port->port.console) {
pr_debug("%s - port not opened\n", __func__);
Expand Down
2 changes: 0 additions & 2 deletions drivers/usb/serial/cp210x.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,6 @@ static void cp210x_set_termios(struct tty_struct *tty,
unsigned int bits;
unsigned int modem_ctl[4];

dev_dbg(dev, "%s - port %d\n", __func__, port->number);

if (!tty)
return;

Expand Down
4 changes: 2 additions & 2 deletions drivers/usb/serial/cypress_m8.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ static void cypress_set_dead(struct usb_serial_port *port)
spin_unlock_irqrestore(&priv->lock, flags);

dev_err(&port->dev, "cypress_m8 suspending failing port %d - "
"interval might be too short\n", port->number);
"interval might be too short\n", port->port_number);
}


Expand Down Expand Up @@ -667,7 +667,7 @@ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
{
struct cypress_private *priv = usb_get_serial_port_data(port);

dev_dbg(&port->dev, "%s - port %d, %d bytes\n", __func__, port->number, count);
dev_dbg(&port->dev, "%s - %d bytes\n", __func__, count);

/* line control commands, which need to be executed immediately,
are not put into the buffer for obvious reasons.
Expand Down
6 changes: 1 addition & 5 deletions drivers/usb/serial/digi_acceleport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,11 +1304,7 @@ static void digi_release(struct usb_serial *serial)

static int digi_port_probe(struct usb_serial_port *port)
{
unsigned port_num;

port_num = port->number - port->serial->minor;

return digi_port_init(port, port_num);
return digi_port_init(port, port->port_number);
}

static int digi_port_remove(struct usb_serial_port *port)
Expand Down
5 changes: 2 additions & 3 deletions drivers/usb/serial/f81232.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,14 @@ static int f81232_ioctl(struct tty_struct *tty,
struct serial_struct ser;
struct usb_serial_port *port = tty->driver_data;

dev_dbg(&port->dev, "%s (%d) cmd = 0x%04x\n", __func__,
port->number, cmd);
dev_dbg(&port->dev, "%s cmd = 0x%04x\n", __func__, cmd);

switch (cmd) {
case TIOCGSERIAL:
memset(&ser, 0, sizeof ser);
ser.type = PORT_16654;
ser.line = port->serial->minor;
ser.port = port->number;
ser.port = port->port_number;
ser.baud_base = 460800;

if (copy_to_user((void __user *)arg, &ser, sizeof ser))
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/serial/garmin_gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,9 @@ static void garmin_close(struct usb_serial_port *port)
{
struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);

dev_dbg(&port->dev, "%s - port %d - mode=%d state=%d flags=0x%X\n",
__func__, port->number, garmin_data_p->mode,
garmin_data_p->state, garmin_data_p->flags);
dev_dbg(&port->dev, "%s - mode=%d state=%d flags=0x%X\n",
__func__, garmin_data_p->mode, garmin_data_p->state,
garmin_data_p->flags);

garmin_clear(garmin_data_p);

Expand Down
58 changes: 23 additions & 35 deletions drivers/usb/serial/io_edgeport.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,8 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
return -ENOMEM;
}

dev_dbg(dev, "%s(%d) - Initialize TX fifo to %d bytes\n",
__func__, port->number, edge_port->maxTxCredits);
dev_dbg(dev, "%s - Initialize TX fifo to %d bytes\n",
__func__, edge_port->maxTxCredits);

return 0;
}
Expand Down Expand Up @@ -1122,9 +1122,8 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
copySize = min((unsigned int)count,
(edge_port->txCredits - fifo->count));

dev_dbg(&port->dev, "%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes\n",
__func__, port->number, count,
edge_port->txCredits - fifo->count, copySize);
dev_dbg(&port->dev, "%s of %d byte(s) Fifo room %d -- will copy %d bytes\n",
__func__, count, edge_port->txCredits - fifo->count, copySize);

/* catch writes of 0 bytes which the tty driver likes to give us,
and when txCredits is empty */
Expand Down Expand Up @@ -1216,9 +1215,8 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
if (edge_port->write_in_progress ||
!edge_port->open ||
(fifo->count == 0)) {
dev_dbg(dev, "%s(%d) EXIT - fifo %d, PendingWrite = %d\n",
__func__, edge_port->port->number,
fifo->count, edge_port->write_in_progress);
dev_dbg(dev, "%s EXIT - fifo %d, PendingWrite = %d\n",
__func__, fifo->count, edge_port->write_in_progress);
goto exit_send;
}

Expand All @@ -1230,9 +1228,8 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
* it's better to wait for more credits so we can do a larger write.
*/
if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits, EDGE_FW_BULK_MAX_PACKET_SIZE)) {
dev_dbg(dev, "%s(%d) Not enough credit - fifo %d TxCredit %d\n",
__func__, edge_port->port->number, fifo->count,
edge_port->txCredits);
dev_dbg(dev, "%s Not enough credit - fifo %d TxCredit %d\n",
__func__, fifo->count, edge_port->txCredits);
goto exit_send;
}

Expand All @@ -1256,10 +1253,8 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
edge_port->write_in_progress = false;
goto exit_send;
}
buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->number
- edge_port->port->serial->minor, count);
buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->number
- edge_port->port->serial->minor, count);
buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->port_number, count);
buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->port_number, count);

/* now copy our data */
bytesleft = fifo->size - fifo->tail;
Expand Down Expand Up @@ -1377,8 +1372,7 @@ static int edge_chars_in_buffer(struct tty_struct *tty)
edge_port->txfifo.count;
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
if (num_chars) {
dev_dbg(&port->dev, "%s(port %d) - returns %d\n", __func__,
port->number, num_chars);
dev_dbg(&port->dev, "%s - returns %d\n", __func__, num_chars);
}

return num_chars;
Expand Down Expand Up @@ -1576,7 +1570,7 @@ static int get_serial_info(struct edgeport_port *edge_port,

tmp.type = PORT_16550A;
tmp.line = edge_port->port->serial->minor;
tmp.port = edge_port->port->number;
tmp.port = edge_port->port->port_number;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
tmp.xmit_fifo_size = edge_port->maxTxCredits;
Expand All @@ -1601,15 +1595,15 @@ static int edge_ioctl(struct tty_struct *tty,
DEFINE_WAIT(wait);
struct edgeport_port *edge_port = usb_get_serial_port_data(port);

dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd);

switch (cmd) {
case TIOCSERGETLSR:
dev_dbg(&port->dev, "%s (%d) TIOCSERGETLSR\n", __func__, port->number);
dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__);
return get_lsr_info(edge_port, (unsigned int __user *) arg);

case TIOCGSERIAL:
dev_dbg(&port->dev, "%s (%d) TIOCGSERIAL\n", __func__, port->number);
dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__);
return get_serial_info(edge_port, (struct serial_struct __user *) arg);
}
return -ENOIOCTLCMD;
Expand Down Expand Up @@ -2181,9 +2175,8 @@ static int send_iosp_ext_cmd(struct edgeport_port *edge_port,

currentCommand = buffer;

MAKE_CMD_EXT_CMD(&currentCommand, &length,
edge_port->port->number - edge_port->port->serial->minor,
command, param);
MAKE_CMD_EXT_CMD(&currentCommand, &length, edge_port->port->port_number,
command, param);

status = write_cmd_usb(edge_port, buffer, length);
if (status) {
Expand Down Expand Up @@ -2266,18 +2259,16 @@ static int send_cmd_write_baud_rate(struct edgeport_port *edge_port,
int cmdLen = 0;
int divisor;
int status;
unsigned char number =
edge_port->port->number - edge_port->port->serial->minor;
u32 number = edge_port->port->port_number;

if (edge_serial->is_epic &&
!edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) {
dev_dbg(dev, "SendCmdWriteBaudRate - NOT Setting baud rate for port = %d, baud = %d\n",
edge_port->port->number, baudRate);
dev_dbg(dev, "SendCmdWriteBaudRate - NOT Setting baud rate for port, baud = %d\n",
baudRate);
return 0;
}

dev_dbg(dev, "%s - port = %d, baud = %d\n", __func__,
edge_port->port->number, baudRate);
dev_dbg(dev, "%s - baud = %d\n", __func__, baudRate);

status = calc_baud_rate_divisor(dev, baudRate, &divisor);
if (status) {
Expand Down Expand Up @@ -2388,9 +2379,8 @@ static int send_cmd_write_uart_register(struct edgeport_port *edge_port,
currCmd = cmdBuffer;

/* Build a cmd in the buffer to write the given register */
MAKE_CMD_WRITE_REG(&currCmd, &cmdLen,
edge_port->port->number - edge_port->port->serial->minor,
regNum, regValue);
MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, edge_port->port->port_number,
regNum, regValue);

status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
if (status) {
Expand Down Expand Up @@ -2424,8 +2414,6 @@ static void change_port_settings(struct tty_struct *tty,
__u8 txFlow;
int status;

dev_dbg(dev, "%s - port %d\n", __func__, edge_port->port->number);

if (!edge_port->open &&
!edge_port->openPending) {
dev_dbg(dev, "%s - port not opened\n", __func__);
Expand Down
Loading

0 comments on commit 1143832

Please sign in to comment.