aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorMathieu OTHACEHE <m.othacehe@gmail.com>2016-07-26 13:59:41 -0400
committerJohan Hovold <johan@kernel.org>2016-08-23 04:07:39 -0400
commitf1054b2d6a6b7b87c91467a301c2c08413f92d86 (patch)
tree0bb6aa1bb54b916dcb79a0f32ed57dc5b2a49d02 /drivers/usb
parent919568691df41e655a6dac2b7a5f94befeedaf71 (diff)
USB: serial: ti_usb_3410_5052: do not use __uX types
__uX types should only be used for user-space interactions. Also clean up uart-config endianess handling, and drop some redundant casts. Signed-off-by: Mathieu OTHACEHE <m.othacehe@gmail.com> [ johan: amend commit message ] Signed-off-by: Johan Hovold <johan@kernel.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c99
1 files changed, 50 insertions, 49 deletions
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 07b4bf01061d..7f3d2c71bb54 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -179,23 +179,23 @@
179 179
180/* Config struct */ 180/* Config struct */
181struct ti_uart_config { 181struct ti_uart_config {
182 __u16 wBaudRate; 182 __be16 wBaudRate;
183 __u16 wFlags; 183 __be16 wFlags;
184 __u8 bDataBits; 184 u8 bDataBits;
185 __u8 bParity; 185 u8 bParity;
186 __u8 bStopBits; 186 u8 bStopBits;
187 char cXon; 187 char cXon;
188 char cXoff; 188 char cXoff;
189 __u8 bUartMode; 189 u8 bUartMode;
190} __packed; 190} __packed;
191 191
192/* Get port status */ 192/* Get port status */
193struct ti_port_status { 193struct ti_port_status {
194 __u8 bCmdCode; 194 u8 bCmdCode;
195 __u8 bModuleId; 195 u8 bModuleId;
196 __u8 bErrorCode; 196 u8 bErrorCode;
197 __u8 bMSR; 197 u8 bMSR;
198 __u8 bLSR; 198 u8 bLSR;
199} __packed; 199} __packed;
200 200
201/* Purge modes */ 201/* Purge modes */
@@ -218,12 +218,12 @@ struct ti_port_status {
218#define TI_RW_DATA_DOUBLE_WORD 0x04 218#define TI_RW_DATA_DOUBLE_WORD 0x04
219 219
220struct ti_write_data_bytes { 220struct ti_write_data_bytes {
221 __u8 bAddrType; 221 u8 bAddrType;
222 __u8 bDataType; 222 u8 bDataType;
223 __u8 bDataCounter; 223 u8 bDataCounter;
224 __be16 wBaseAddrHi; 224 __be16 wBaseAddrHi;
225 __be16 wBaseAddrLo; 225 __be16 wBaseAddrLo;
226 __u8 bData[0]; 226 u8 bData[0];
227} __packed; 227} __packed;
228 228
229struct ti_read_data_request { 229struct ti_read_data_request {
@@ -258,7 +258,7 @@ struct ti_interrupt {
258/* Firmware image header */ 258/* Firmware image header */
259struct ti_firmware_header { 259struct ti_firmware_header {
260 __le16 wLength; 260 __le16 wLength;
261 __u8 bCheckSum; 261 u8 bCheckSum;
262} __packed; 262} __packed;
263 263
264/* UART addresses */ 264/* UART addresses */
@@ -288,9 +288,9 @@ struct ti_firmware_header {
288 288
289struct ti_port { 289struct ti_port {
290 int tp_is_open; 290 int tp_is_open;
291 __u8 tp_msr; 291 u8 tp_msr;
292 __u8 tp_shadow_mcr; 292 u8 tp_shadow_mcr;
293 __u8 tp_uart_mode; /* 232 or 485 modes */ 293 u8 tp_uart_mode; /* 232 or 485 modes */
294 unsigned int tp_uart_base_addr; 294 unsigned int tp_uart_base_addr;
295 int tp_flags; 295 int tp_flags;
296 struct ti_device *tp_tdev; 296 struct ti_device *tp_tdev;
@@ -343,7 +343,7 @@ static int ti_get_serial_info(struct ti_port *tport,
343 struct serial_struct __user *ret_arg); 343 struct serial_struct __user *ret_arg);
344static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport, 344static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
345 struct serial_struct __user *new_arg); 345 struct serial_struct __user *new_arg);
346static void ti_handle_new_msr(struct ti_port *tport, __u8 msr); 346static void ti_handle_new_msr(struct ti_port *tport, u8 msr);
347 347
348static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty); 348static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty);
349static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty); 349static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty);
@@ -354,7 +354,7 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
354 __u16 moduleid, __u16 value, __u8 *data, int size); 354 __u16 moduleid, __u16 value, __u8 *data, int size);
355 355
356static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev, 356static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev,
357 unsigned long addr, __u8 mask, __u8 byte); 357 unsigned long addr, u8 mask, u8 byte);
358 358
359static int ti_download_firmware(struct ti_device *tdev); 359static int ti_download_firmware(struct ti_device *tdev);
360 360
@@ -647,9 +647,11 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
647 struct urb *urb; 647 struct urb *urb;
648 int port_number; 648 int port_number;
649 int status; 649 int status;
650 __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINUOUS | 650 u16 open_settings;
651 TI_PIPE_TIMEOUT_ENABLE | 651
652 (TI_TRANSFER_TIMEOUT << 2)); 652 open_settings = (TI_PIPE_MODE_CONTINUOUS |
653 TI_PIPE_TIMEOUT_ENABLE |
654 (TI_TRANSFER_TIMEOUT << 2));
653 655
654 if (tport == NULL) 656 if (tport == NULL)
655 return -ENODEV; 657 return -ENODEV;
@@ -959,6 +961,8 @@ static void ti_set_termios(struct tty_struct *tty,
959 int status; 961 int status;
960 int port_number = port->port_number; 962 int port_number = port->port_number;
961 unsigned int mcr; 963 unsigned int mcr;
964 u16 wbaudrate;
965 u16 wflags = 0;
962 966
963 cflag = tty->termios.c_cflag; 967 cflag = tty->termios.c_cflag;
964 iflag = tty->termios.c_iflag; 968 iflag = tty->termios.c_iflag;
@@ -974,12 +978,10 @@ static void ti_set_termios(struct tty_struct *tty,
974 if (!config) 978 if (!config)
975 return; 979 return;
976 980
977 config->wFlags = 0;
978
979 /* these flags must be set */ 981 /* these flags must be set */
980 config->wFlags |= TI_UART_ENABLE_MS_INTS; 982 wflags |= TI_UART_ENABLE_MS_INTS;
981 config->wFlags |= TI_UART_ENABLE_AUTO_START_DMA; 983 wflags |= TI_UART_ENABLE_AUTO_START_DMA;
982 config->bUartMode = (__u8)(tport->tp_uart_mode); 984 config->bUartMode = tport->tp_uart_mode;
983 985
984 switch (cflag & CSIZE) { 986 switch (cflag & CSIZE) {
985 case CS5: 987 case CS5:
@@ -1002,14 +1004,14 @@ static void ti_set_termios(struct tty_struct *tty,
1002 1004
1003 if (cflag & PARENB) { 1005 if (cflag & PARENB) {
1004 if (cflag & PARODD) { 1006 if (cflag & PARODD) {
1005 config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; 1007 wflags |= TI_UART_ENABLE_PARITY_CHECKING;
1006 config->bParity = TI_UART_ODD_PARITY; 1008 config->bParity = TI_UART_ODD_PARITY;
1007 } else { 1009 } else {
1008 config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; 1010 wflags |= TI_UART_ENABLE_PARITY_CHECKING;
1009 config->bParity = TI_UART_EVEN_PARITY; 1011 config->bParity = TI_UART_EVEN_PARITY;
1010 } 1012 }
1011 } else { 1013 } else {
1012 config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING; 1014 wflags &= ~TI_UART_ENABLE_PARITY_CHECKING;
1013 config->bParity = TI_UART_NO_PARITY; 1015 config->bParity = TI_UART_NO_PARITY;
1014 } 1016 }
1015 1017
@@ -1021,8 +1023,8 @@ static void ti_set_termios(struct tty_struct *tty,
1021 if (cflag & CRTSCTS) { 1023 if (cflag & CRTSCTS) {
1022 /* RTS flow control must be off to drop RTS for baud rate B0 */ 1024 /* RTS flow control must be off to drop RTS for baud rate B0 */
1023 if ((cflag & CBAUD) != B0) 1025 if ((cflag & CBAUD) != B0)
1024 config->wFlags |= TI_UART_ENABLE_RTS_IN; 1026 wflags |= TI_UART_ENABLE_RTS_IN;
1025 config->wFlags |= TI_UART_ENABLE_CTS_OUT; 1027 wflags |= TI_UART_ENABLE_CTS_OUT;
1026 } else { 1028 } else {
1027 ti_restart_read(tport, tty); 1029 ti_restart_read(tport, tty);
1028 } 1030 }
@@ -1032,21 +1034,21 @@ static void ti_set_termios(struct tty_struct *tty,
1032 config->cXoff = STOP_CHAR(tty); 1034 config->cXoff = STOP_CHAR(tty);
1033 1035
1034 if (I_IXOFF(tty)) 1036 if (I_IXOFF(tty))
1035 config->wFlags |= TI_UART_ENABLE_X_IN; 1037 wflags |= TI_UART_ENABLE_X_IN;
1036 else 1038 else
1037 ti_restart_read(tport, tty); 1039 ti_restart_read(tport, tty);
1038 1040
1039 if (I_IXON(tty)) 1041 if (I_IXON(tty))
1040 config->wFlags |= TI_UART_ENABLE_X_OUT; 1042 wflags |= TI_UART_ENABLE_X_OUT;
1041 } 1043 }
1042 1044
1043 baud = tty_get_baud_rate(tty); 1045 baud = tty_get_baud_rate(tty);
1044 if (!baud) 1046 if (!baud)
1045 baud = 9600; 1047 baud = 9600;
1046 if (tport->tp_tdev->td_is_3410) 1048 if (tport->tp_tdev->td_is_3410)
1047 config->wBaudRate = (__u16)((923077 + baud/2) / baud); 1049 wbaudrate = (923077 + baud/2) / baud;
1048 else 1050 else
1049 config->wBaudRate = (__u16)((461538 + baud/2) / baud); 1051 wbaudrate = (461538 + baud/2) / baud;
1050 1052
1051 /* FIXME: Should calculate resulting baud here and report it back */ 1053 /* FIXME: Should calculate resulting baud here and report it back */
1052 if ((cflag & CBAUD) != B0) 1054 if ((cflag & CBAUD) != B0)
@@ -1054,12 +1056,12 @@ static void ti_set_termios(struct tty_struct *tty,
1054 1056
1055 dev_dbg(&port->dev, 1057 dev_dbg(&port->dev,
1056 "%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d\n", 1058 "%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d\n",
1057 __func__, baud, config->wBaudRate, config->wFlags, 1059 __func__, baud, wbaudrate, wflags,
1058 config->bDataBits, config->bParity, config->bStopBits, 1060 config->bDataBits, config->bParity, config->bStopBits,
1059 config->cXon, config->cXoff, config->bUartMode); 1061 config->cXon, config->cXoff, config->bUartMode);
1060 1062
1061 cpu_to_be16s(&config->wBaudRate); 1063 config->wBaudRate = cpu_to_be16(wbaudrate);
1062 cpu_to_be16s(&config->wFlags); 1064 config->wFlags = cpu_to_be16(wflags);
1063 1065
1064 status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG, 1066 status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG,
1065 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, 1067 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config,
@@ -1189,7 +1191,7 @@ static void ti_interrupt_callback(struct urb *urb)
1189 int function; 1191 int function;
1190 int status = urb->status; 1192 int status = urb->status;
1191 int retval; 1193 int retval;
1192 __u8 msr; 1194 u8 msr;
1193 1195
1194 switch (status) { 1196 switch (status) {
1195 case 0: 1197 case 0:
@@ -1522,7 +1524,7 @@ static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
1522} 1524}
1523 1525
1524 1526
1525static void ti_handle_new_msr(struct ti_port *tport, __u8 msr) 1527static void ti_handle_new_msr(struct ti_port *tport, u8 msr)
1526{ 1528{
1527 struct async_icount *icount; 1529 struct async_icount *icount;
1528 struct tty_struct *tty; 1530 struct tty_struct *tty;
@@ -1634,8 +1636,8 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
1634 1636
1635 1637
1636static int ti_write_byte(struct usb_serial_port *port, 1638static int ti_write_byte(struct usb_serial_port *port,
1637 struct ti_device *tdev, unsigned long addr, 1639 struct ti_device *tdev, unsigned long addr,
1638 __u8 mask, __u8 byte) 1640 u8 mask, u8 byte)
1639{ 1641{
1640 int status; 1642 int status;
1641 unsigned int size; 1643 unsigned int size;
@@ -1679,11 +1681,10 @@ static int ti_do_download(struct usb_device *dev, int pipe,
1679 int len; 1681 int len;
1680 1682
1681 for (pos = sizeof(struct ti_firmware_header); pos < size; pos++) 1683 for (pos = sizeof(struct ti_firmware_header); pos < size; pos++)
1682 cs = (__u8)(cs + buffer[pos]); 1684 cs = (u8)(cs + buffer[pos]);
1683 1685
1684 header = (struct ti_firmware_header *)buffer; 1686 header = (struct ti_firmware_header *)buffer;
1685 header->wLength = cpu_to_le16((__u16)(size 1687 header->wLength = cpu_to_le16(size - sizeof(*header));
1686 - sizeof(struct ti_firmware_header)));
1687 header->bCheckSum = cs; 1688 header->bCheckSum = cs;
1688 1689
1689 dev_dbg(&dev->dev, "%s - downloading firmware\n", __func__); 1690 dev_dbg(&dev->dev, "%s - downloading firmware\n", __func__);
@@ -1701,7 +1702,7 @@ static int ti_download_firmware(struct ti_device *tdev)
1701{ 1702{
1702 int status; 1703 int status;
1703 int buffer_size; 1704 int buffer_size;
1704 __u8 *buffer; 1705 u8 *buffer;
1705 struct usb_device *dev = tdev->td_serial->dev; 1706 struct usb_device *dev = tdev->td_serial->dev;
1706 unsigned int pipe = usb_sndbulkpipe(dev, 1707 unsigned int pipe = usb_sndbulkpipe(dev,
1707 tdev->td_serial->port[0]->bulk_out_endpointAddress); 1708 tdev->td_serial->port[0]->bulk_out_endpointAddress);