Commit 3bfe4398 authored by Johan Hovold's avatar Johan Hovold

USB: serial: ti_usb_3410_5052: add port-command helpers

Add two port-command helpers to handle the UART module-id parameter
instead of open coding.
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
parent d2422336
...@@ -333,10 +333,14 @@ static void ti_handle_new_msr(struct ti_port *tport, u8 msr); ...@@ -333,10 +333,14 @@ 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 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_restart_read(struct ti_port *tport, struct tty_struct *tty);
static int ti_command_out_sync(struct ti_device *tdev, __u8 command, static int ti_command_out_sync(struct usb_device *udev, __u8 command,
__u16 moduleid, __u16 value, void *data, int size); __u16 moduleid, __u16 value, void *data, int size);
static int ti_command_in_sync(struct ti_device *tdev, __u8 command, static int ti_command_in_sync(struct usb_device *udev, __u8 command,
__u16 moduleid, __u16 value, void *data, int size); __u16 moduleid, __u16 value, void *data, int size);
static int ti_port_cmd_out(struct usb_serial_port *port, u8 command,
u16 value, void *data, int size);
static int ti_port_cmd_in(struct usb_serial_port *port, u8 command,
u16 value, void *data, int size);
static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev, static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev,
unsigned long addr, u8 mask, u8 byte); unsigned long addr, u8 mask, u8 byte);
...@@ -635,7 +639,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -635,7 +639,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
struct ti_device *tdev; struct ti_device *tdev;
struct usb_device *dev; struct usb_device *dev;
struct urb *urb; struct urb *urb;
int port_number;
int status; int status;
u16 open_settings; u16 open_settings;
...@@ -650,8 +653,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -650,8 +653,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
if (mutex_lock_interruptible(&tdev->td_open_close_lock)) if (mutex_lock_interruptible(&tdev->td_open_close_lock))
return -ERESTARTSYS; return -ERESTARTSYS;
port_number = port->port_number;
tport->tp_msr = 0; tport->tp_msr = 0;
tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR); tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR);
...@@ -675,31 +676,27 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -675,31 +676,27 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
if (tty) if (tty)
ti_set_termios(tty, port, &tty->termios); ti_set_termios(tty, port, &tty->termios);
status = ti_command_out_sync(tdev, TI_OPEN_PORT, status = ti_port_cmd_out(port, TI_OPEN_PORT, open_settings, NULL, 0);
(__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
if (status) { if (status) {
dev_err(&port->dev, "%s - cannot send open command, %d\n", dev_err(&port->dev, "%s - cannot send open command, %d\n",
__func__, status); __func__, status);
goto unlink_int_urb; goto unlink_int_urb;
} }
status = ti_command_out_sync(tdev, TI_START_PORT, status = ti_port_cmd_out(port, TI_START_PORT, 0, NULL, 0);
(__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
if (status) { if (status) {
dev_err(&port->dev, "%s - cannot send start command, %d\n", dev_err(&port->dev, "%s - cannot send start command, %d\n",
__func__, status); __func__, status);
goto unlink_int_urb; goto unlink_int_urb;
} }
status = ti_command_out_sync(tdev, TI_PURGE_PORT, status = ti_port_cmd_out(port, TI_PURGE_PORT, TI_PURGE_INPUT, NULL, 0);
(__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0);
if (status) { if (status) {
dev_err(&port->dev, "%s - cannot clear input buffers, %d\n", dev_err(&port->dev, "%s - cannot clear input buffers, %d\n",
__func__, status); __func__, status);
goto unlink_int_urb; goto unlink_int_urb;
} }
status = ti_command_out_sync(tdev, TI_PURGE_PORT, status = ti_port_cmd_out(port, TI_PURGE_PORT, TI_PURGE_OUTPUT, NULL, 0);
(__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0);
if (status) { if (status) {
dev_err(&port->dev, "%s - cannot clear output buffers, %d\n", dev_err(&port->dev, "%s - cannot clear output buffers, %d\n",
__func__, status); __func__, status);
...@@ -714,16 +711,14 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -714,16 +711,14 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
if (tty) if (tty)
ti_set_termios(tty, port, &tty->termios); ti_set_termios(tty, port, &tty->termios);
status = ti_command_out_sync(tdev, TI_OPEN_PORT, status = ti_port_cmd_out(port, TI_OPEN_PORT, open_settings, NULL, 0);
(__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
if (status) { if (status) {
dev_err(&port->dev, "%s - cannot send open command (2), %d\n", dev_err(&port->dev, "%s - cannot send open command (2), %d\n",
__func__, status); __func__, status);
goto unlink_int_urb; goto unlink_int_urb;
} }
status = ti_command_out_sync(tdev, TI_START_PORT, status = ti_port_cmd_out(port, TI_START_PORT, 0, NULL, 0);
(__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
if (status) { if (status) {
dev_err(&port->dev, "%s - cannot send start command (2), %d\n", dev_err(&port->dev, "%s - cannot send start command (2), %d\n",
__func__, status); __func__, status);
...@@ -764,7 +759,6 @@ static void ti_close(struct usb_serial_port *port) ...@@ -764,7 +759,6 @@ static void ti_close(struct usb_serial_port *port)
{ {
struct ti_device *tdev; struct ti_device *tdev;
struct ti_port *tport; struct ti_port *tport;
int port_number;
int status; int status;
unsigned long flags; unsigned long flags;
...@@ -780,10 +774,7 @@ static void ti_close(struct usb_serial_port *port) ...@@ -780,10 +774,7 @@ static void ti_close(struct usb_serial_port *port)
kfifo_reset_out(&port->write_fifo); kfifo_reset_out(&port->write_fifo);
spin_unlock_irqrestore(&tport->tp_lock, flags); spin_unlock_irqrestore(&tport->tp_lock, flags);
port_number = port->port_number; status = ti_port_cmd_out(port, TI_CLOSE_PORT, 0, NULL, 0);
status = ti_command_out_sync(tdev, TI_CLOSE_PORT,
(__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
if (status) if (status)
dev_err(&port->dev, dev_err(&port->dev,
"%s - cannot send close port command, %d\n" "%s - cannot send close port command, %d\n"
...@@ -904,7 +895,6 @@ static void ti_set_termios(struct tty_struct *tty, ...@@ -904,7 +895,6 @@ static void ti_set_termios(struct tty_struct *tty,
struct ti_uart_config *config; struct ti_uart_config *config;
int baud; int baud;
int status; int status;
int port_number = port->port_number;
unsigned int mcr; unsigned int mcr;
u16 wbaudrate; u16 wbaudrate;
u16 wflags = 0; u16 wflags = 0;
...@@ -998,12 +988,11 @@ static void ti_set_termios(struct tty_struct *tty, ...@@ -998,12 +988,11 @@ static void ti_set_termios(struct tty_struct *tty,
config->wBaudRate = cpu_to_be16(wbaudrate); config->wBaudRate = cpu_to_be16(wbaudrate);
config->wFlags = cpu_to_be16(wflags); config->wFlags = cpu_to_be16(wflags);
status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG, status = ti_port_cmd_out(port, TI_SET_CONFIG, 0, config,
(__u8)(TI_UART1_PORT + port_number), 0, config,
sizeof(*config)); sizeof(*config));
if (status) if (status)
dev_err(&port->dev, "%s - cannot set config on port %d, %d\n", dev_err(&port->dev, "%s - cannot set config on port %d, %d\n",
__func__, port_number, status); __func__, port->port_number, status);
/* SET_CONFIG asserts RTS and DTR, reset them correctly */ /* SET_CONFIG asserts RTS and DTR, reset them correctly */
mcr = tport->tp_shadow_mcr; mcr = tport->tp_shadow_mcr;
...@@ -1012,9 +1001,8 @@ static void ti_set_termios(struct tty_struct *tty, ...@@ -1012,9 +1001,8 @@ static void ti_set_termios(struct tty_struct *tty,
mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); mcr &= ~(TI_MCR_DTR | TI_MCR_RTS);
status = ti_set_mcr(tport, mcr); status = ti_set_mcr(tport, mcr);
if (status) if (status)
dev_err(&port->dev, dev_err(&port->dev, "%s - cannot set modem control on port %d, %d\n",
"%s - cannot set modem control on port %d, %d\n", __func__, port->port_number, status);
__func__, port_number, status);
kfree(config); kfree(config);
} }
...@@ -1365,9 +1353,7 @@ static int ti_set_mcr(struct ti_port *tport, unsigned int mcr) ...@@ -1365,9 +1353,7 @@ 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_lsr(struct ti_port *tport, u8 *lsr)
{ {
int size, status; int size, status;
struct ti_device *tdev = tport->tp_tdev;
struct usb_serial_port *port = tport->tp_port; struct usb_serial_port *port = tport->tp_port;
int port_number = port->port_number;
struct ti_port_status *data; struct ti_port_status *data;
size = sizeof(struct ti_port_status); size = sizeof(struct ti_port_status);
...@@ -1375,8 +1361,7 @@ static int ti_get_lsr(struct ti_port *tport, u8 *lsr) ...@@ -1375,8 +1361,7 @@ static int ti_get_lsr(struct ti_port *tport, u8 *lsr)
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, status = ti_port_cmd_in(port, TI_GET_PORT_STATUS, 0, data, size);
(__u8)(TI_UART1_PORT+port_number), 0, data, size);
if (status) { if (status) {
dev_err(&port->dev, dev_err(&port->dev,
"%s - get port status command failed, %d\n", "%s - get port status command failed, %d\n",
...@@ -1473,34 +1458,28 @@ static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty) ...@@ -1473,34 +1458,28 @@ static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty)
return status; return status;
} }
static int ti_command_out_sync(struct usb_device *udev, __u8 command,
static int ti_command_out_sync(struct ti_device *tdev, __u8 command,
__u16 moduleid, __u16 value, void *data, int size) __u16 moduleid, __u16 value, void *data, int size)
{ {
int status; int status;
status = usb_control_msg(tdev->td_serial->dev, status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), command,
usb_sndctrlpipe(tdev->td_serial->dev, 0), command, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
(USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
value, moduleid, data, size, 1000); value, moduleid, data, size, 1000);
if (status < 0) if (status < 0)
return status; return status;
return 0; return 0;
} }
static int ti_command_in_sync(struct usb_device *udev, __u8 command,
static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
__u16 moduleid, __u16 value, void *data, int size) __u16 moduleid, __u16 value, void *data, int size)
{ {
int status; int status;
status = usb_control_msg(tdev->td_serial->dev, status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), command,
usb_rcvctrlpipe(tdev->td_serial->dev, 0), command, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
(USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
value, moduleid, data, size, 1000); value, moduleid, data, size, 1000);
if (status == size) if (status == size)
status = 0; status = 0;
else if (status >= 0) else if (status >= 0)
...@@ -1509,6 +1488,21 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command, ...@@ -1509,6 +1488,21 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
return status; return status;
} }
static int ti_port_cmd_out(struct usb_serial_port *port, u8 command,
u16 value, void *data, int size)
{
return ti_command_out_sync(port->serial->dev, command,
TI_UART1_PORT + port->port_number,
value, data, size);
}
static int ti_port_cmd_in(struct usb_serial_port *port, u8 command,
u16 value, void *data, int size)
{
return ti_command_in_sync(port->serial->dev, command,
TI_UART1_PORT + port->port_number,
value, data, size);
}
static int ti_write_byte(struct usb_serial_port *port, static int ti_write_byte(struct usb_serial_port *port,
struct ti_device *tdev, unsigned long addr, struct ti_device *tdev, unsigned long addr,
...@@ -1534,8 +1528,8 @@ static int ti_write_byte(struct usb_serial_port *port, ...@@ -1534,8 +1528,8 @@ static int ti_write_byte(struct usb_serial_port *port,
data->bData[0] = mask; data->bData[0] = mask;
data->bData[1] = byte; data->bData[1] = byte;
status = ti_command_out_sync(tdev, TI_WRITE_DATA, TI_RAM_PORT, 0, status = ti_command_out_sync(port->serial->dev, TI_WRITE_DATA,
data, size); TI_RAM_PORT, 0, data, size);
if (status < 0) if (status < 0)
dev_err(&port->dev, "%s - failed, %d\n", __func__, status); dev_err(&port->dev, "%s - failed, %d\n", __func__, status);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment