Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* vi: ts=8 sw=8 |
| 2 | * |
| 3 | * TI 3410/5052 USB Serial Driver |
| 4 | * |
| 5 | * Copyright (C) 2004 Texas Instruments |
| 6 | * |
| 7 | * This driver is based on the Linux io_ti driver, which is |
| 8 | * Copyright (C) 2000-2002 Inside Out Networks |
| 9 | * Copyright (C) 2001-2002 Greg Kroah-Hartman |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * For questions or problems with this driver, contact Texas Instruments |
| 17 | * technical support, or Al Borchers <alborchers@steinerpoint.com>, or |
| 18 | * Peter Berger <pberger@brimson.com>. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 23 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/tty.h> |
| 27 | #include <linux/tty_driver.h> |
| 28 | #include <linux/tty_flip.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/ioctl.h> |
| 32 | #include <linux/serial.h> |
Johan Hovold | 074ef65 | 2010-05-19 00:01:35 +0200 | [diff] [blame] | 33 | #include <linux/kfifo.h> |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 34 | #include <linux/mutex.h> |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 35 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 37 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "ti_usb_3410_5052.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* Defines */ |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define TI_DRIVER_AUTHOR "Al Borchers <alborchers@steinerpoint.com>" |
| 44 | #define TI_DRIVER_DESC "TI USB 3410/5052 Serial Driver" |
| 45 | |
| 46 | #define TI_FIRMWARE_BUF_SIZE 16284 |
| 47 | |
| 48 | #define TI_WRITE_BUF_SIZE 1024 |
| 49 | |
| 50 | #define TI_TRANSFER_TIMEOUT 2 |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define TI_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */ |
| 53 | |
| 54 | /* supported setserial flags */ |
Oliver Neukum | 2400a2b | 2009-04-20 17:28:53 +0200 | [diff] [blame] | 55 | #define TI_SET_SERIAL_FLAGS 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /* read urb states */ |
| 58 | #define TI_READ_URB_RUNNING 0 |
| 59 | #define TI_READ_URB_STOPPING 1 |
| 60 | #define TI_READ_URB_STOPPED 2 |
| 61 | |
| 62 | #define TI_EXTRA_VID_PID_COUNT 5 |
| 63 | |
| 64 | |
| 65 | /* Structures */ |
| 66 | |
| 67 | struct ti_port { |
| 68 | int tp_is_open; |
| 69 | __u8 tp_msr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | __u8 tp_shadow_mcr; |
| 71 | __u8 tp_uart_mode; /* 232 or 485 modes */ |
| 72 | unsigned int tp_uart_base_addr; |
| 73 | int tp_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | wait_queue_head_t tp_write_wait; |
| 75 | struct ti_device *tp_tdev; |
| 76 | struct usb_serial_port *tp_port; |
| 77 | spinlock_t tp_lock; |
| 78 | int tp_read_urb_state; |
| 79 | int tp_write_urb_in_use; |
Johan Hovold | 074ef65 | 2010-05-19 00:01:35 +0200 | [diff] [blame] | 80 | struct kfifo write_fifo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | struct ti_device { |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 84 | struct mutex td_open_close_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | int td_open_port_count; |
| 86 | struct usb_serial *td_serial; |
| 87 | int td_is_3410; |
| 88 | int td_urb_error; |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | /* Function Declarations */ |
| 93 | |
| 94 | static int ti_startup(struct usb_serial *serial); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 95 | static void ti_release(struct usb_serial *serial); |
Johan Hovold | 51ef847 | 2012-10-17 16:31:35 +0200 | [diff] [blame] | 96 | static int ti_port_probe(struct usb_serial_port *port); |
| 97 | static int ti_port_remove(struct usb_serial_port *port); |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 98 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 99 | static void ti_close(struct usb_serial_port *port); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 100 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 101 | const unsigned char *data, int count); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 102 | static int ti_write_room(struct tty_struct *tty); |
| 103 | static int ti_chars_in_buffer(struct tty_struct *tty); |
Johan Hovold | ff93b19 | 2013-05-05 20:32:32 +0200 | [diff] [blame] | 104 | static bool ti_tx_empty(struct usb_serial_port *port); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 105 | static void ti_throttle(struct tty_struct *tty); |
| 106 | static void ti_unthrottle(struct tty_struct *tty); |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 107 | static int ti_ioctl(struct tty_struct *tty, |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 108 | unsigned int cmd, unsigned long arg); |
| 109 | static void ti_set_termios(struct tty_struct *tty, |
| 110 | struct usb_serial_port *port, struct ktermios *old_termios); |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 111 | static int ti_tiocmget(struct tty_struct *tty); |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 112 | static int ti_tiocmset(struct tty_struct *tty, |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 113 | unsigned int set, unsigned int clear); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 114 | static void ti_break(struct tty_struct *tty, int break_state); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 115 | static void ti_interrupt_callback(struct urb *urb); |
| 116 | static void ti_bulk_in_callback(struct urb *urb); |
| 117 | static void ti_bulk_out_callback(struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 119 | static void ti_recv(struct usb_serial_port *port, unsigned char *data, |
| 120 | int length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | static void ti_send(struct ti_port *tport); |
| 122 | static int ti_set_mcr(struct ti_port *tport, unsigned int mcr); |
Johan Hovold | b5784f7 | 2013-04-18 17:33:20 +0200 | [diff] [blame] | 123 | static int ti_get_lsr(struct ti_port *tport, u8 *lsr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static int ti_get_serial_info(struct ti_port *tport, |
| 125 | struct serial_struct __user *ret_arg); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 126 | static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | struct serial_struct __user *new_arg); |
| 128 | static void ti_handle_new_msr(struct ti_port *tport, __u8 msr); |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty); |
| 131 | static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty); |
| 132 | |
| 133 | static int ti_command_out_sync(struct ti_device *tdev, __u8 command, |
| 134 | __u16 moduleid, __u16 value, __u8 *data, int size); |
| 135 | static int ti_command_in_sync(struct ti_device *tdev, __u8 command, |
| 136 | __u16 moduleid, __u16 value, __u8 *data, int size); |
| 137 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 138 | static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev, |
| 139 | unsigned long addr, __u8 mask, __u8 byte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 141 | static int ti_download_firmware(struct ti_device *tdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | /* Data */ |
| 145 | |
| 146 | /* module parameters */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | static int closing_wait = TI_DEFAULT_CLOSING_WAIT; |
| 148 | static ushort vendor_3410[TI_EXTRA_VID_PID_COUNT]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 149 | static unsigned int vendor_3410_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | static ushort product_3410[TI_EXTRA_VID_PID_COUNT]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 151 | static unsigned int product_3410_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | static ushort vendor_5052[TI_EXTRA_VID_PID_COUNT]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 153 | static unsigned int vendor_5052_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | static ushort product_5052[TI_EXTRA_VID_PID_COUNT]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 155 | static unsigned int product_5052_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | /* supported devices */ |
| 158 | /* the array dimension is the number of default entries plus */ |
| 159 | /* TI_EXTRA_VID_PID_COUNT user defined entries plus 1 terminating */ |
| 160 | /* null entry */ |
Darren Hart | 975dc33 | 2012-05-11 13:56:57 -0700 | [diff] [blame] | 161 | static struct usb_device_id ti_id_table_3410[15+TI_EXTRA_VID_PID_COUNT+1] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, |
Oleg Verych | 1f54a6a | 2006-11-17 08:21:27 +0000 | [diff] [blame] | 163 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, |
Chris Adams | cb7a7c6 | 2009-01-11 19:49:00 +0000 | [diff] [blame] | 164 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, |
| 165 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_NO_FW_PRODUCT_ID) }, |
| 166 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) }, |
| 167 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) }, |
| 168 | { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) }, |
Alex Manoussakis | cdc0483 | 2010-04-22 15:18:20 -0700 | [diff] [blame] | 169 | { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234MU_PRODUCT_ID) }, |
| 170 | { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBA_PRODUCT_ID) }, |
| 171 | { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBAOLD_PRODUCT_ID) }, |
Oliver Neukum | 1a1fab51 | 2009-01-12 13:31:16 +0100 | [diff] [blame] | 172 | { USB_DEVICE(IBM_VENDOR_ID, IBM_4543_PRODUCT_ID) }, |
Oliver Neukum | 97dcf04 | 2009-02-04 16:38:33 +0100 | [diff] [blame] | 173 | { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) }, |
| 174 | { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) }, |
Andrew Lunn | 7fd2570 | 2012-02-20 09:31:57 +0100 | [diff] [blame] | 175 | { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) }, |
Darren Hart | 975dc33 | 2012-05-11 13:56:57 -0700 | [diff] [blame] | 176 | { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
Oliver Neukum | 97dcf04 | 2009-02-04 16:38:33 +0100 | [diff] [blame] | 179 | static struct usb_device_id ti_id_table_5052[5+TI_EXTRA_VID_PID_COUNT+1] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, |
| 181 | { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, |
| 182 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, |
| 183 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) }, |
| 184 | }; |
| 185 | |
Darren Hart | 975dc33 | 2012-05-11 13:56:57 -0700 | [diff] [blame] | 186 | static struct usb_device_id ti_id_table_combined[19+2*TI_EXTRA_VID_PID_COUNT+1] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, |
Oleg Verych | 1f54a6a | 2006-11-17 08:21:27 +0000 | [diff] [blame] | 188 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, |
Chris Adams | cb7a7c6 | 2009-01-11 19:49:00 +0000 | [diff] [blame] | 189 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, |
| 190 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_NO_FW_PRODUCT_ID) }, |
| 191 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) }, |
| 192 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) }, |
| 193 | { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) }, |
Alex Manoussakis | cdc0483 | 2010-04-22 15:18:20 -0700 | [diff] [blame] | 194 | { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234MU_PRODUCT_ID) }, |
| 195 | { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBA_PRODUCT_ID) }, |
| 196 | { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBAOLD_PRODUCT_ID) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, |
| 198 | { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, |
| 199 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, |
| 200 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) }, |
Oliver Neukum | 1a1fab51 | 2009-01-12 13:31:16 +0100 | [diff] [blame] | 201 | { USB_DEVICE(IBM_VENDOR_ID, IBM_4543_PRODUCT_ID) }, |
Oliver Neukum | 97dcf04 | 2009-02-04 16:38:33 +0100 | [diff] [blame] | 202 | { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) }, |
| 203 | { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) }, |
Andrew Lunn | 7fd2570 | 2012-02-20 09:31:57 +0100 | [diff] [blame] | 204 | { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) }, |
Darren Hart | 975dc33 | 2012-05-11 13:56:57 -0700 | [diff] [blame] | 205 | { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { } |
| 207 | }; |
| 208 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 209 | static struct usb_serial_driver ti_1port_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 210 | .driver = { |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 211 | .owner = THIS_MODULE, |
| 212 | .name = "ti_usb_3410_5052_1", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 213 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 214 | .description = "TI USB 3410 1 port adapter", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | .id_table = ti_id_table_3410, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | .num_ports = 1, |
| 217 | .attach = ti_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 218 | .release = ti_release, |
Johan Hovold | 51ef847 | 2012-10-17 16:31:35 +0200 | [diff] [blame] | 219 | .port_probe = ti_port_probe, |
| 220 | .port_remove = ti_port_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | .open = ti_open, |
| 222 | .close = ti_close, |
| 223 | .write = ti_write, |
| 224 | .write_room = ti_write_room, |
| 225 | .chars_in_buffer = ti_chars_in_buffer, |
Johan Hovold | ff93b19 | 2013-05-05 20:32:32 +0200 | [diff] [blame] | 226 | .tx_empty = ti_tx_empty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | .throttle = ti_throttle, |
| 228 | .unthrottle = ti_unthrottle, |
| 229 | .ioctl = ti_ioctl, |
| 230 | .set_termios = ti_set_termios, |
| 231 | .tiocmget = ti_tiocmget, |
| 232 | .tiocmset = ti_tiocmset, |
Johan Hovold | 6c75e26 | 2013-03-21 12:37:34 +0100 | [diff] [blame] | 233 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
Johan Hovold | 783ca35 | 2013-03-21 12:37:33 +0100 | [diff] [blame] | 234 | .get_icount = usb_serial_generic_get_icount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | .break_ctl = ti_break, |
| 236 | .read_int_callback = ti_interrupt_callback, |
| 237 | .read_bulk_callback = ti_bulk_in_callback, |
| 238 | .write_bulk_callback = ti_bulk_out_callback, |
| 239 | }; |
| 240 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 241 | static struct usb_serial_driver ti_2port_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 242 | .driver = { |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 243 | .owner = THIS_MODULE, |
| 244 | .name = "ti_usb_3410_5052_2", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 245 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 246 | .description = "TI USB 5052 2 port adapter", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | .id_table = ti_id_table_5052, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | .num_ports = 2, |
| 249 | .attach = ti_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 250 | .release = ti_release, |
Johan Hovold | 51ef847 | 2012-10-17 16:31:35 +0200 | [diff] [blame] | 251 | .port_probe = ti_port_probe, |
| 252 | .port_remove = ti_port_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | .open = ti_open, |
| 254 | .close = ti_close, |
| 255 | .write = ti_write, |
| 256 | .write_room = ti_write_room, |
| 257 | .chars_in_buffer = ti_chars_in_buffer, |
Johan Hovold | ff93b19 | 2013-05-05 20:32:32 +0200 | [diff] [blame] | 258 | .tx_empty = ti_tx_empty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | .throttle = ti_throttle, |
| 260 | .unthrottle = ti_unthrottle, |
| 261 | .ioctl = ti_ioctl, |
| 262 | .set_termios = ti_set_termios, |
| 263 | .tiocmget = ti_tiocmget, |
| 264 | .tiocmset = ti_tiocmset, |
Johan Hovold | 6c75e26 | 2013-03-21 12:37:34 +0100 | [diff] [blame] | 265 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
Johan Hovold | 783ca35 | 2013-03-21 12:37:33 +0100 | [diff] [blame] | 266 | .get_icount = usb_serial_generic_get_icount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | .break_ctl = ti_break, |
| 268 | .read_int_callback = ti_interrupt_callback, |
| 269 | .read_bulk_callback = ti_bulk_in_callback, |
| 270 | .write_bulk_callback = ti_bulk_out_callback, |
| 271 | }; |
| 272 | |
Alan Stern | 29618e9 | 2012-02-23 14:57:32 -0500 | [diff] [blame] | 273 | static struct usb_serial_driver * const serial_drivers[] = { |
| 274 | &ti_1port_device, &ti_2port_device, NULL |
| 275 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | /* Module */ |
| 278 | |
| 279 | MODULE_AUTHOR(TI_DRIVER_AUTHOR); |
| 280 | MODULE_DESCRIPTION(TI_DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | MODULE_LICENSE("GPL"); |
| 282 | |
David Woodhouse | 5f24e2d | 2008-05-30 18:49:51 +0300 | [diff] [blame] | 283 | MODULE_FIRMWARE("ti_3410.fw"); |
| 284 | MODULE_FIRMWARE("ti_5052.fw"); |
Chris Adams | 7df5231 | 2009-01-11 19:49:11 +0000 | [diff] [blame] | 285 | MODULE_FIRMWARE("mts_cdma.fw"); |
| 286 | MODULE_FIRMWARE("mts_gsm.fw"); |
| 287 | MODULE_FIRMWARE("mts_edge.fw"); |
Alex Manoussakis | cdc0483 | 2010-04-22 15:18:20 -0700 | [diff] [blame] | 288 | MODULE_FIRMWARE("mts_mt9234mu.fw"); |
| 289 | MODULE_FIRMWARE("mts_mt9234zba.fw"); |
David Woodhouse | 5f24e2d | 2008-05-30 18:49:51 +0300 | [diff] [blame] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | module_param(closing_wait, int, S_IRUGO | S_IWUSR); |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 292 | MODULE_PARM_DESC(closing_wait, |
| 293 | "Maximum wait for data to drain in close, in .01 secs, default is 4000"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | module_param_array(vendor_3410, ushort, &vendor_3410_count, S_IRUGO); |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 296 | MODULE_PARM_DESC(vendor_3410, |
| 297 | "Vendor ids for 3410 based devices, 1-5 short integers"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | module_param_array(product_3410, ushort, &product_3410_count, S_IRUGO); |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 299 | MODULE_PARM_DESC(product_3410, |
| 300 | "Product ids for 3410 based devices, 1-5 short integers"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | module_param_array(vendor_5052, ushort, &vendor_5052_count, S_IRUGO); |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 302 | MODULE_PARM_DESC(vendor_5052, |
| 303 | "Vendor ids for 5052 based devices, 1-5 short integers"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | module_param_array(product_5052, ushort, &product_5052_count, S_IRUGO); |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 305 | MODULE_PARM_DESC(product_5052, |
| 306 | "Product ids for 5052 based devices, 1-5 short integers"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | MODULE_DEVICE_TABLE(usb, ti_id_table_combined); |
| 309 | |
| 310 | |
| 311 | /* Functions */ |
| 312 | |
| 313 | static int __init ti_init(void) |
| 314 | { |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 315 | int i, j, c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /* insert extra vendor and product ids */ |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 318 | c = ARRAY_SIZE(ti_id_table_combined) - 2 * TI_EXTRA_VID_PID_COUNT - 1; |
Tobias Klauser | 52950ed | 2005-12-11 16:20:08 +0100 | [diff] [blame] | 319 | j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1; |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 320 | for (i = 0; i < min(vendor_3410_count, product_3410_count); i++, j++, c++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | ti_id_table_3410[j].idVendor = vendor_3410[i]; |
| 322 | ti_id_table_3410[j].idProduct = product_3410[i]; |
| 323 | ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 324 | ti_id_table_combined[c].idVendor = vendor_3410[i]; |
| 325 | ti_id_table_combined[c].idProduct = product_3410[i]; |
| 326 | ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
Tobias Klauser | 52950ed | 2005-12-11 16:20:08 +0100 | [diff] [blame] | 328 | j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1; |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 329 | for (i = 0; i < min(vendor_5052_count, product_5052_count); i++, j++, c++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | ti_id_table_5052[j].idVendor = vendor_5052[i]; |
| 331 | ti_id_table_5052[j].idProduct = product_5052[i]; |
| 332 | ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 333 | ti_id_table_combined[c].idVendor = vendor_5052[i]; |
| 334 | ti_id_table_combined[c].idProduct = product_5052[i]; |
| 335 | ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Greg Kroah-Hartman | f378dfe | 2012-09-18 17:09:00 +0100 | [diff] [blame] | 338 | return usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, ti_id_table_combined); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | static void __exit ti_exit(void) |
| 342 | { |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 343 | usb_serial_deregister_drivers(serial_drivers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | module_init(ti_init); |
| 347 | module_exit(ti_exit); |
| 348 | |
| 349 | |
| 350 | static int ti_startup(struct usb_serial *serial) |
| 351 | { |
| 352 | struct ti_device *tdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | struct usb_device *dev = serial->dev; |
| 354 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 356 | dev_dbg(&dev->dev, |
| 357 | "%s - product 0x%4X, num configurations %d, configuration value %d", |
| 358 | __func__, le16_to_cpu(dev->descriptor.idProduct), |
| 359 | dev->descriptor.bNumConfigurations, |
| 360 | dev->actconfig->desc.bConfigurationValue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | /* create device structure */ |
Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 363 | tdev = kzalloc(sizeof(struct ti_device), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | if (tdev == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 365 | dev_err(&dev->dev, "%s - out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return -ENOMEM; |
| 367 | } |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 368 | mutex_init(&tdev->td_open_close_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | tdev->td_serial = serial; |
| 370 | usb_set_serial_data(serial, tdev); |
| 371 | |
| 372 | /* determine device type */ |
| 373 | if (usb_match_id(serial->interface, ti_id_table_3410)) |
| 374 | tdev->td_is_3410 = 1; |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 375 | dev_dbg(&dev->dev, "%s - device type is %s\n", __func__, |
| 376 | tdev->td_is_3410 ? "3410" : "5052"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | /* if we have only 1 configuration, download firmware */ |
| 379 | if (dev->descriptor.bNumConfigurations == 1) { |
Adhir Ramjiawan | 72b27a0 | 2012-04-09 14:01:38 +0200 | [diff] [blame] | 380 | status = ti_download_firmware(tdev); |
| 381 | |
| 382 | if (status != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | goto free_tdev; |
| 384 | |
| 385 | /* 3410 must be reset, 5052 resets itself */ |
| 386 | if (tdev->td_is_3410) { |
| 387 | msleep_interruptible(100); |
| 388 | usb_reset_device(dev); |
| 389 | } |
| 390 | |
| 391 | status = -ENODEV; |
| 392 | goto free_tdev; |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Oliver Neukum | 413ba6f | 2008-12-16 12:25:55 +0100 | [diff] [blame] | 395 | /* the second configuration must be set */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (dev->actconfig->desc.bConfigurationValue == TI_BOOT_CONFIG) { |
Oliver Neukum | 413ba6f | 2008-12-16 12:25:55 +0100 | [diff] [blame] | 397 | status = usb_driver_set_configuration(dev, TI_ACTIVE_CONFIG); |
| 398 | status = status ? status : -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | goto free_tdev; |
| 400 | } |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return 0; |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | free_tdev: |
| 405 | kfree(tdev); |
| 406 | usb_set_serial_data(serial, NULL); |
| 407 | return status; |
| 408 | } |
| 409 | |
| 410 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 411 | static void ti_release(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | struct ti_device *tdev = usb_get_serial_data(serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 415 | kfree(tdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Johan Hovold | 51ef847 | 2012-10-17 16:31:35 +0200 | [diff] [blame] | 418 | static int ti_port_probe(struct usb_serial_port *port) |
| 419 | { |
| 420 | struct ti_port *tport; |
| 421 | |
| 422 | tport = kzalloc(sizeof(*tport), GFP_KERNEL); |
| 423 | if (!tport) |
| 424 | return -ENOMEM; |
| 425 | |
| 426 | spin_lock_init(&tport->tp_lock); |
| 427 | if (port == port->serial->port[0]) |
| 428 | tport->tp_uart_base_addr = TI_UART1_BASE_ADDR; |
| 429 | else |
| 430 | tport->tp_uart_base_addr = TI_UART2_BASE_ADDR; |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 431 | port->port.closing_wait = msecs_to_jiffies(10 * closing_wait); |
Johan Hovold | 51ef847 | 2012-10-17 16:31:35 +0200 | [diff] [blame] | 432 | init_waitqueue_head(&tport->tp_write_wait); |
| 433 | if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE, GFP_KERNEL)) { |
| 434 | kfree(tport); |
| 435 | return -ENOMEM; |
| 436 | } |
| 437 | tport->tp_port = port; |
| 438 | tport->tp_tdev = usb_get_serial_data(port->serial); |
| 439 | tport->tp_uart_mode = 0; /* default is RS232 */ |
| 440 | |
| 441 | usb_set_serial_port_data(port, tport); |
| 442 | |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | static int ti_port_remove(struct usb_serial_port *port) |
| 447 | { |
| 448 | struct ti_port *tport; |
| 449 | |
| 450 | tport = usb_get_serial_port_data(port); |
| 451 | kfifo_free(&tport->write_fifo); |
| 452 | kfree(tport); |
| 453 | |
| 454 | return 0; |
| 455 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 457 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
| 459 | struct ti_port *tport = usb_get_serial_port_data(port); |
| 460 | struct ti_device *tdev; |
| 461 | struct usb_device *dev; |
| 462 | struct urb *urb; |
| 463 | int port_number; |
| 464 | int status; |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 465 | __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINOUS | |
| 466 | TI_PIPE_TIMEOUT_ENABLE | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | (TI_TRANSFER_TIMEOUT << 2)); |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | if (tport == NULL) |
| 470 | return -ENODEV; |
| 471 | |
| 472 | dev = port->serial->dev; |
| 473 | tdev = tport->tp_tdev; |
| 474 | |
| 475 | /* only one open on any port on a device at a time */ |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 476 | if (mutex_lock_interruptible(&tdev->td_open_close_lock)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | return -ERESTARTSYS; |
| 478 | |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame^] | 479 | port_number = port->port_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | tport->tp_msr = 0; |
| 482 | tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR); |
| 483 | |
| 484 | /* start interrupt urb the first time a port is opened on this device */ |
| 485 | if (tdev->td_open_port_count == 0) { |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 486 | dev_dbg(&port->dev, "%s - start interrupt in urb\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | urb = tdev->td_serial->port[0]->interrupt_in_urb; |
| 488 | if (!urb) { |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 489 | dev_err(&port->dev, "%s - no interrupt urb\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | status = -EINVAL; |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 491 | goto release_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | urb->context = tdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | status = usb_submit_urb(urb, GFP_KERNEL); |
| 495 | if (status) { |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 496 | dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __func__, status); |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 497 | goto release_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 501 | if (tty) |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 502 | ti_set_termios(tty, port, &tty->termios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 504 | dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | status = ti_command_out_sync(tdev, TI_OPEN_PORT, |
| 506 | (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); |
| 507 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 508 | dev_err(&port->dev, "%s - cannot send open command, %d\n", |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 509 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | goto unlink_int_urb; |
| 511 | } |
| 512 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 513 | dev_dbg(&port->dev, "%s - sending TI_START_PORT\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | status = ti_command_out_sync(tdev, TI_START_PORT, |
| 515 | (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); |
| 516 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 517 | dev_err(&port->dev, "%s - cannot send start command, %d\n", |
| 518 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | goto unlink_int_urb; |
| 520 | } |
| 521 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 522 | dev_dbg(&port->dev, "%s - sending TI_PURGE_PORT\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | status = ti_command_out_sync(tdev, TI_PURGE_PORT, |
| 524 | (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0); |
| 525 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 526 | dev_err(&port->dev, "%s - cannot clear input buffers, %d\n", |
| 527 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | goto unlink_int_urb; |
| 529 | } |
| 530 | status = ti_command_out_sync(tdev, TI_PURGE_PORT, |
| 531 | (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0); |
| 532 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 533 | dev_err(&port->dev, "%s - cannot clear output buffers, %d\n", |
| 534 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | goto unlink_int_urb; |
| 536 | } |
| 537 | |
| 538 | /* reset the data toggle on the bulk endpoints to work around bug in |
| 539 | * host controllers where things get out of sync some times */ |
| 540 | usb_clear_halt(dev, port->write_urb->pipe); |
| 541 | usb_clear_halt(dev, port->read_urb->pipe); |
| 542 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 543 | if (tty) |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 544 | ti_set_termios(tty, port, &tty->termios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 546 | dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT (2)\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | status = ti_command_out_sync(tdev, TI_OPEN_PORT, |
| 548 | (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); |
| 549 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 550 | dev_err(&port->dev, "%s - cannot send open command (2), %d\n", |
| 551 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | goto unlink_int_urb; |
| 553 | } |
| 554 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 555 | dev_dbg(&port->dev, "%s - sending TI_START_PORT (2)\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | status = ti_command_out_sync(tdev, TI_START_PORT, |
| 557 | (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); |
| 558 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 559 | dev_err(&port->dev, "%s - cannot send start command (2), %d\n", |
| 560 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | goto unlink_int_urb; |
| 562 | } |
| 563 | |
| 564 | /* start read urb */ |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 565 | dev_dbg(&port->dev, "%s - start read urb\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | urb = port->read_urb; |
| 567 | if (!urb) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 568 | dev_err(&port->dev, "%s - no read urb\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | status = -EINVAL; |
| 570 | goto unlink_int_urb; |
| 571 | } |
| 572 | tport->tp_read_urb_state = TI_READ_URB_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | urb->context = tport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | status = usb_submit_urb(urb, GFP_KERNEL); |
| 575 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 576 | dev_err(&port->dev, "%s - submit read urb failed, %d\n", |
| 577 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | goto unlink_int_urb; |
| 579 | } |
| 580 | |
| 581 | tport->tp_is_open = 1; |
| 582 | ++tdev->td_open_port_count; |
| 583 | |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 584 | port->port.drain_delay = 3; |
| 585 | |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 586 | goto release_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | unlink_int_urb: |
| 589 | if (tdev->td_open_port_count == 0) |
| 590 | usb_kill_urb(port->serial->port[0]->interrupt_in_urb); |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 591 | release_lock: |
| 592 | mutex_unlock(&tdev->td_open_close_lock); |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 593 | dev_dbg(&port->dev, "%s - exit %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | return status; |
| 595 | } |
| 596 | |
| 597 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 598 | static void ti_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
| 600 | struct ti_device *tdev; |
| 601 | struct ti_port *tport; |
| 602 | int port_number; |
| 603 | int status; |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 604 | int do_unlock; |
Johan Hovold | 113ec31 | 2013-04-18 17:33:19 +0200 | [diff] [blame] | 605 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | tdev = usb_get_serial_data(port->serial); |
| 608 | tport = usb_get_serial_port_data(port); |
| 609 | if (tdev == NULL || tport == NULL) |
| 610 | return; |
| 611 | |
| 612 | tport->tp_is_open = 0; |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | usb_kill_urb(port->read_urb); |
| 615 | usb_kill_urb(port->write_urb); |
| 616 | tport->tp_write_urb_in_use = 0; |
Johan Hovold | 113ec31 | 2013-04-18 17:33:19 +0200 | [diff] [blame] | 617 | spin_lock_irqsave(&tport->tp_lock, flags); |
| 618 | kfifo_reset_out(&tport->write_fifo); |
| 619 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame^] | 621 | port_number = port->port_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 623 | dev_dbg(&port->dev, "%s - sending TI_CLOSE_PORT\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | status = ti_command_out_sync(tdev, TI_CLOSE_PORT, |
| 625 | (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); |
| 626 | if (status) |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 627 | dev_err(&port->dev, |
| 628 | "%s - cannot send close port command, %d\n" |
| 629 | , __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 631 | /* if mutex_lock is interrupted, continue anyway */ |
| 632 | do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | --tport->tp_tdev->td_open_port_count; |
| 634 | if (tport->tp_tdev->td_open_port_count <= 0) { |
| 635 | /* last port is closed, shut down interrupt urb */ |
| 636 | usb_kill_urb(port->serial->port[0]->interrupt_in_urb); |
| 637 | tport->tp_tdev->td_open_port_count = 0; |
| 638 | } |
Matthias Kaehlcke | 9da0068 | 2007-11-21 15:13:16 -0800 | [diff] [blame] | 639 | if (do_unlock) |
| 640 | mutex_unlock(&tdev->td_open_close_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 644 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 645 | const unsigned char *data, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
| 647 | struct ti_port *tport = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | if (count == 0) { |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 650 | dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | if (tport == NULL || !tport->tp_is_open) |
| 655 | return -ENODEV; |
| 656 | |
Johan Hovold | 074ef65 | 2010-05-19 00:01:35 +0200 | [diff] [blame] | 657 | count = kfifo_in_locked(&tport->write_fifo, data, count, |
| 658 | &tport->tp_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | ti_send(tport); |
| 660 | |
| 661 | return count; |
| 662 | } |
| 663 | |
| 664 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 665 | static int ti_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 667 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | struct ti_port *tport = usb_get_serial_port_data(port); |
| 669 | int room = 0; |
| 670 | unsigned long flags; |
| 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | if (tport == NULL) |
Alan Cox | 23198fd | 2009-07-20 16:05:27 +0100 | [diff] [blame] | 673 | return 0; |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | spin_lock_irqsave(&tport->tp_lock, flags); |
Johan Hovold | 074ef65 | 2010-05-19 00:01:35 +0200 | [diff] [blame] | 676 | room = kfifo_avail(&tport->write_fifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
| 678 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 679 | dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | return room; |
| 681 | } |
| 682 | |
| 683 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 684 | static int ti_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 686 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | struct ti_port *tport = usb_get_serial_port_data(port); |
| 688 | int chars = 0; |
| 689 | unsigned long flags; |
| 690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (tport == NULL) |
Alan Cox | 23198fd | 2009-07-20 16:05:27 +0100 | [diff] [blame] | 692 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | spin_lock_irqsave(&tport->tp_lock, flags); |
Johan Hovold | 074ef65 | 2010-05-19 00:01:35 +0200 | [diff] [blame] | 695 | chars = kfifo_len(&tport->write_fifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
| 697 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 698 | dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return chars; |
| 700 | } |
| 701 | |
Johan Hovold | ff93b19 | 2013-05-05 20:32:32 +0200 | [diff] [blame] | 702 | static bool ti_tx_empty(struct usb_serial_port *port) |
| 703 | { |
| 704 | struct ti_port *tport = usb_get_serial_port_data(port); |
| 705 | int ret; |
| 706 | u8 lsr; |
| 707 | |
| 708 | ret = ti_get_lsr(tport, &lsr); |
| 709 | if (!ret && !(lsr & TI_LSR_TX_EMPTY)) |
| 710 | return false; |
| 711 | |
| 712 | return true; |
| 713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 715 | static void ti_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 717 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | struct ti_port *tport = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | if (tport == NULL) |
| 721 | return; |
| 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | if (I_IXOFF(tty) || C_CRTSCTS(tty)) |
| 724 | ti_stop_read(tport, tty); |
| 725 | |
| 726 | } |
| 727 | |
| 728 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 729 | static void ti_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 731 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | struct ti_port *tport = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | int status; |
| 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | if (tport == NULL) |
| 736 | return; |
| 737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | if (I_IXOFF(tty) || C_CRTSCTS(tty)) { |
| 739 | status = ti_restart_read(tport, tty); |
| 740 | if (status) |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 741 | dev_err(&port->dev, "%s - cannot restart read, %d\n", |
| 742 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 746 | static int ti_ioctl(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | unsigned int cmd, unsigned long arg) |
| 748 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 749 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | struct ti_port *tport = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 752 | dev_dbg(&port->dev, "%s - cmd = 0x%04X\n", __func__, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | if (tport == NULL) |
| 755 | return -ENODEV; |
| 756 | |
| 757 | switch (cmd) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 758 | case TIOCGSERIAL: |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 759 | dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__); |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 760 | return ti_get_serial_info(tport, |
| 761 | (struct serial_struct __user *)arg); |
| 762 | case TIOCSSERIAL: |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 763 | dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 764 | return ti_set_serial_info(tty, tport, |
| 765 | (struct serial_struct __user *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | return -ENOIOCTLCMD; |
| 768 | } |
| 769 | |
| 770 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 771 | static void ti_set_termios(struct tty_struct *tty, |
| 772 | struct usb_serial_port *port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
| 774 | struct ti_port *tport = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | struct ti_uart_config *config; |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 776 | tcflag_t cflag, iflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | int baud; |
| 778 | int status; |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame^] | 779 | int port_number = port->port_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | unsigned int mcr; |
| 781 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 782 | cflag = tty->termios.c_cflag; |
| 783 | iflag = tty->termios.c_iflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 785 | dev_dbg(&port->dev, "%s - cflag %08x, iflag %08x\n", __func__, cflag, iflag); |
| 786 | dev_dbg(&port->dev, "%s - old clfag %08x, old iflag %08x\n", __func__, |
| 787 | old_termios->c_cflag, old_termios->c_iflag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
| 789 | if (tport == NULL) |
| 790 | return; |
| 791 | |
| 792 | config = kmalloc(sizeof(*config), GFP_KERNEL); |
| 793 | if (!config) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 794 | dev_err(&port->dev, "%s - out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | return; |
| 796 | } |
| 797 | |
| 798 | config->wFlags = 0; |
| 799 | |
| 800 | /* these flags must be set */ |
| 801 | config->wFlags |= TI_UART_ENABLE_MS_INTS; |
| 802 | config->wFlags |= TI_UART_ENABLE_AUTO_START_DMA; |
| 803 | config->bUartMode = (__u8)(tport->tp_uart_mode); |
| 804 | |
| 805 | switch (cflag & CSIZE) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 806 | case CS5: |
| 807 | config->bDataBits = TI_UART_5_DATA_BITS; |
| 808 | break; |
| 809 | case CS6: |
| 810 | config->bDataBits = TI_UART_6_DATA_BITS; |
| 811 | break; |
| 812 | case CS7: |
| 813 | config->bDataBits = TI_UART_7_DATA_BITS; |
| 814 | break; |
| 815 | default: |
| 816 | case CS8: |
| 817 | config->bDataBits = TI_UART_8_DATA_BITS; |
| 818 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Alan Cox | 537699e | 2008-01-03 17:03:11 +0000 | [diff] [blame] | 821 | /* CMSPAR isn't supported by this driver */ |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 822 | tty->termios.c_cflag &= ~CMSPAR; |
Alan Cox | 537699e | 2008-01-03 17:03:11 +0000 | [diff] [blame] | 823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | if (cflag & PARENB) { |
| 825 | if (cflag & PARODD) { |
| 826 | config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; |
| 827 | config->bParity = TI_UART_ODD_PARITY; |
| 828 | } else { |
| 829 | config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; |
| 830 | config->bParity = TI_UART_EVEN_PARITY; |
| 831 | } |
| 832 | } else { |
| 833 | config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING; |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 834 | config->bParity = TI_UART_NO_PARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | if (cflag & CSTOPB) |
| 838 | config->bStopBits = TI_UART_2_STOP_BITS; |
| 839 | else |
| 840 | config->bStopBits = TI_UART_1_STOP_BITS; |
| 841 | |
| 842 | if (cflag & CRTSCTS) { |
| 843 | /* RTS flow control must be off to drop RTS for baud rate B0 */ |
| 844 | if ((cflag & CBAUD) != B0) |
| 845 | config->wFlags |= TI_UART_ENABLE_RTS_IN; |
| 846 | config->wFlags |= TI_UART_ENABLE_CTS_OUT; |
| 847 | } else { |
| 848 | tty->hw_stopped = 0; |
| 849 | ti_restart_read(tport, tty); |
| 850 | } |
| 851 | |
| 852 | if (I_IXOFF(tty) || I_IXON(tty)) { |
| 853 | config->cXon = START_CHAR(tty); |
| 854 | config->cXoff = STOP_CHAR(tty); |
| 855 | |
| 856 | if (I_IXOFF(tty)) |
| 857 | config->wFlags |= TI_UART_ENABLE_X_IN; |
| 858 | else |
| 859 | ti_restart_read(tport, tty); |
| 860 | |
| 861 | if (I_IXON(tty)) |
| 862 | config->wFlags |= TI_UART_ENABLE_X_OUT; |
| 863 | } |
| 864 | |
| 865 | baud = tty_get_baud_rate(tty); |
Alan Cox | 537699e | 2008-01-03 17:03:11 +0000 | [diff] [blame] | 866 | if (!baud) |
| 867 | baud = 9600; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | if (tport->tp_tdev->td_is_3410) |
| 869 | config->wBaudRate = (__u16)((923077 + baud/2) / baud); |
| 870 | else |
| 871 | config->wBaudRate = (__u16)((461538 + baud/2) / baud); |
| 872 | |
Alan Cox | 537699e | 2008-01-03 17:03:11 +0000 | [diff] [blame] | 873 | /* FIXME: Should calculate resulting baud here and report it back */ |
| 874 | if ((cflag & CBAUD) != B0) |
| 875 | tty_encode_baud_rate(tty, baud, baud); |
| 876 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 877 | dev_dbg(&port->dev, |
| 878 | "%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d", |
| 879 | __func__, baud, config->wBaudRate, config->wFlags, |
| 880 | config->bDataBits, config->bParity, config->bStopBits, |
| 881 | config->cXon, config->cXoff, config->bUartMode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
| 883 | cpu_to_be16s(&config->wBaudRate); |
| 884 | cpu_to_be16s(&config->wFlags); |
| 885 | |
| 886 | status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG, |
| 887 | (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, |
| 888 | sizeof(*config)); |
| 889 | if (status) |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 890 | dev_err(&port->dev, "%s - cannot set config on port %d, %d\n", |
| 891 | __func__, port_number, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | /* SET_CONFIG asserts RTS and DTR, reset them correctly */ |
| 894 | mcr = tport->tp_shadow_mcr; |
| 895 | /* if baud rate is B0, clear RTS and DTR */ |
| 896 | if ((cflag & CBAUD) == B0) |
| 897 | mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); |
| 898 | status = ti_set_mcr(tport, mcr); |
| 899 | if (status) |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 900 | dev_err(&port->dev, |
| 901 | "%s - cannot set modem control on port %d, %d\n", |
| 902 | __func__, port_number, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | kfree(config); |
| 905 | } |
| 906 | |
| 907 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 908 | static int ti_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 910 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | struct ti_port *tport = usb_get_serial_port_data(port); |
| 912 | unsigned int result; |
| 913 | unsigned int msr; |
| 914 | unsigned int mcr; |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 915 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | if (tport == NULL) |
| 918 | return -ENODEV; |
| 919 | |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 920 | spin_lock_irqsave(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | msr = tport->tp_msr; |
| 922 | mcr = tport->tp_shadow_mcr; |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 923 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
| 925 | result = ((mcr & TI_MCR_DTR) ? TIOCM_DTR : 0) |
| 926 | | ((mcr & TI_MCR_RTS) ? TIOCM_RTS : 0) |
| 927 | | ((mcr & TI_MCR_LOOP) ? TIOCM_LOOP : 0) |
| 928 | | ((msr & TI_MSR_CTS) ? TIOCM_CTS : 0) |
| 929 | | ((msr & TI_MSR_CD) ? TIOCM_CAR : 0) |
| 930 | | ((msr & TI_MSR_RI) ? TIOCM_RI : 0) |
| 931 | | ((msr & TI_MSR_DSR) ? TIOCM_DSR : 0); |
| 932 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 933 | dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | return result; |
| 936 | } |
| 937 | |
| 938 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 939 | static int ti_tiocmset(struct tty_struct *tty, |
| 940 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 942 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | struct ti_port *tport = usb_get_serial_port_data(port); |
| 944 | unsigned int mcr; |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 945 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | if (tport == NULL) |
| 948 | return -ENODEV; |
| 949 | |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 950 | spin_lock_irqsave(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | mcr = tport->tp_shadow_mcr; |
| 952 | |
| 953 | if (set & TIOCM_RTS) |
| 954 | mcr |= TI_MCR_RTS; |
| 955 | if (set & TIOCM_DTR) |
| 956 | mcr |= TI_MCR_DTR; |
| 957 | if (set & TIOCM_LOOP) |
| 958 | mcr |= TI_MCR_LOOP; |
| 959 | |
| 960 | if (clear & TIOCM_RTS) |
| 961 | mcr &= ~TI_MCR_RTS; |
| 962 | if (clear & TIOCM_DTR) |
| 963 | mcr &= ~TI_MCR_DTR; |
| 964 | if (clear & TIOCM_LOOP) |
| 965 | mcr &= ~TI_MCR_LOOP; |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 966 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
| 968 | return ti_set_mcr(tport, mcr); |
| 969 | } |
| 970 | |
| 971 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 972 | static void ti_break(struct tty_struct *tty, int break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 974 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | struct ti_port *tport = usb_get_serial_port_data(port); |
| 976 | int status; |
| 977 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 978 | dev_dbg(&port->dev, "%s - state = %d\n", __func__, break_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | if (tport == NULL) |
| 981 | return; |
| 982 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 983 | status = ti_write_byte(port, tport->tp_tdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | tport->tp_uart_base_addr + TI_UART_OFFSET_LCR, |
| 985 | TI_LCR_BREAK, break_state == -1 ? TI_LCR_BREAK : 0); |
| 986 | |
| 987 | if (status) |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 988 | dev_dbg(&port->dev, "%s - error setting break, %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 992 | static void ti_interrupt_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 994 | struct ti_device *tdev = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | struct usb_serial_port *port; |
| 996 | struct usb_serial *serial = tdev->td_serial; |
| 997 | struct ti_port *tport; |
| 998 | struct device *dev = &urb->dev->dev; |
| 999 | unsigned char *data = urb->transfer_buffer; |
| 1000 | int length = urb->actual_length; |
| 1001 | int port_number; |
| 1002 | int function; |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1003 | int status = urb->status; |
| 1004 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | __u8 msr; |
| 1006 | |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1007 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | case 0: |
| 1009 | break; |
| 1010 | case -ECONNRESET: |
| 1011 | case -ENOENT: |
| 1012 | case -ESHUTDOWN: |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1013 | dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | tdev->td_urb_error = 1; |
| 1015 | return; |
| 1016 | default: |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1017 | dev_err(dev, "%s - nonzero urb status, %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | tdev->td_urb_error = 1; |
| 1019 | goto exit; |
| 1020 | } |
| 1021 | |
| 1022 | if (length != 2) { |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1023 | dev_dbg(dev, "%s - bad packet size, %d\n", __func__, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | goto exit; |
| 1025 | } |
| 1026 | |
| 1027 | if (data[0] == TI_CODE_HARDWARE_ERROR) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1028 | dev_err(dev, "%s - hardware error, %d\n", __func__, data[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | goto exit; |
| 1030 | } |
| 1031 | |
| 1032 | port_number = TI_GET_PORT_FROM_CODE(data[0]); |
| 1033 | function = TI_GET_FUNC_FROM_CODE(data[0]); |
| 1034 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1035 | dev_dbg(dev, "%s - port_number %d, function %d, data 0x%02X\n", |
| 1036 | __func__, port_number, function, data[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (port_number >= serial->num_ports) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1039 | dev_err(dev, "%s - bad port number, %d\n", |
| 1040 | __func__, port_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | goto exit; |
| 1042 | } |
| 1043 | |
| 1044 | port = serial->port[port_number]; |
| 1045 | |
| 1046 | tport = usb_get_serial_port_data(port); |
| 1047 | if (!tport) |
| 1048 | goto exit; |
| 1049 | |
| 1050 | switch (function) { |
| 1051 | case TI_CODE_DATA_ERROR: |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1052 | dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n", |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1053 | __func__, port_number, data[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | break; |
| 1055 | |
| 1056 | case TI_CODE_MODEM_STATUS: |
| 1057 | msr = data[1]; |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1058 | dev_dbg(dev, "%s - port %d, msr 0x%02X\n", __func__, port_number, msr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | ti_handle_new_msr(tport, msr); |
| 1060 | break; |
| 1061 | |
| 1062 | default: |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1063 | dev_err(dev, "%s - unknown interrupt code, 0x%02X\n", |
| 1064 | __func__, data[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | break; |
| 1066 | } |
| 1067 | |
| 1068 | exit: |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1069 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 1070 | if (retval) |
| 1071 | dev_err(dev, "%s - resubmit interrupt urb failed, %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1072 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1076 | static void ti_bulk_in_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1078 | struct ti_port *tport = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | struct usb_serial_port *port = tport->tp_port; |
| 1080 | struct device *dev = &urb->dev->dev; |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1081 | int status = urb->status; |
| 1082 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1084 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | case 0: |
| 1086 | break; |
| 1087 | case -ECONNRESET: |
| 1088 | case -ENOENT: |
| 1089 | case -ESHUTDOWN: |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1090 | dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | tport->tp_tdev->td_urb_error = 1; |
| 1092 | wake_up_interruptible(&tport->tp_write_wait); |
| 1093 | return; |
| 1094 | default: |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1095 | dev_err(dev, "%s - nonzero urb status, %d\n", |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1096 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | tport->tp_tdev->td_urb_error = 1; |
| 1098 | wake_up_interruptible(&tport->tp_write_wait); |
| 1099 | } |
| 1100 | |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1101 | if (status == -EPIPE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | goto exit; |
| 1103 | |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1104 | if (status) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1105 | dev_err(dev, "%s - stopping read!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | return; |
| 1107 | } |
| 1108 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 1109 | if (urb->actual_length) { |
| 1110 | usb_serial_debug_data(dev, __func__, urb->actual_length, |
| 1111 | urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 1113 | if (!tport->tp_is_open) |
| 1114 | dev_dbg(dev, "%s - port closed, dropping data\n", |
| 1115 | __func__); |
| 1116 | else |
| 1117 | ti_recv(port, urb->transfer_buffer, urb->actual_length); |
| 1118 | spin_lock(&tport->tp_lock); |
Johan Hovold | 783ca35 | 2013-03-21 12:37:33 +0100 | [diff] [blame] | 1119 | port->icount.rx += urb->actual_length; |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 1120 | spin_unlock(&tport->tp_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | exit: |
| 1124 | /* continue to read unless stopping */ |
| 1125 | spin_lock(&tport->tp_lock); |
Johan Hovold | 5833041 | 2011-11-06 19:06:28 +0100 | [diff] [blame] | 1126 | if (tport->tp_read_urb_state == TI_READ_URB_RUNNING) |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1127 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Johan Hovold | 5833041 | 2011-11-06 19:06:28 +0100 | [diff] [blame] | 1128 | else if (tport->tp_read_urb_state == TI_READ_URB_STOPPING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | tport->tp_read_urb_state = TI_READ_URB_STOPPED; |
Johan Hovold | 5833041 | 2011-11-06 19:06:28 +0100 | [diff] [blame] | 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | spin_unlock(&tport->tp_lock); |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1132 | if (retval) |
| 1133 | dev_err(dev, "%s - resubmit read urb failed, %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1134 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1138 | static void ti_bulk_out_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1140 | struct ti_port *tport = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | struct usb_serial_port *port = tport->tp_port; |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1142 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | tport->tp_write_urb_in_use = 0; |
| 1145 | |
Greg Kroah-Hartman | 52171b4 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1146 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | case 0: |
| 1148 | break; |
| 1149 | case -ECONNRESET: |
| 1150 | case -ENOENT: |
| 1151 | case -ESHUTDOWN: |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1152 | dev_dbg(&port->dev, "%s - urb shutting down, %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | tport->tp_tdev->td_urb_error = 1; |
| 1154 | wake_up_interruptible(&tport->tp_write_wait); |
| 1155 | return; |
| 1156 | default: |
Johan Hovold | 22a416c | 2012-02-10 13:20:51 +0100 | [diff] [blame] | 1157 | dev_err_console(port, "%s - nonzero urb status, %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1158 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | tport->tp_tdev->td_urb_error = 1; |
| 1160 | wake_up_interruptible(&tport->tp_write_wait); |
| 1161 | } |
| 1162 | |
| 1163 | /* send any buffered data */ |
| 1164 | ti_send(tport); |
| 1165 | } |
| 1166 | |
| 1167 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 1168 | static void ti_recv(struct usb_serial_port *port, unsigned char *data, |
| 1169 | int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | { |
| 1171 | int cnt; |
| 1172 | |
| 1173 | do { |
Jiri Slaby | 05c7cd3 | 2013-01-03 15:53:04 +0100 | [diff] [blame] | 1174 | cnt = tty_insert_flip_string(&port->port, data, length); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1175 | if (cnt < length) { |
Jiri Slaby | 05c7cd3 | 2013-01-03 15:53:04 +0100 | [diff] [blame] | 1176 | dev_err(&port->dev, "%s - dropping data, %d bytes lost\n", |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1177 | __func__, length - cnt); |
| 1178 | if (cnt == 0) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1179 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | } |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 1181 | tty_flip_buffer_push(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | data += cnt; |
| 1183 | length -= cnt; |
| 1184 | } while (length > 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | |
| 1188 | static void ti_send(struct ti_port *tport) |
| 1189 | { |
| 1190 | int count, result; |
| 1191 | struct usb_serial_port *port = tport->tp_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | unsigned long flags; |
| 1193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | spin_lock_irqsave(&tport->tp_lock, flags); |
| 1195 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1196 | if (tport->tp_write_urb_in_use) |
| 1197 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Johan Hovold | 074ef65 | 2010-05-19 00:01:35 +0200 | [diff] [blame] | 1199 | count = kfifo_out(&tport->write_fifo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | port->write_urb->transfer_buffer, |
| 1201 | port->bulk_out_size); |
| 1202 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1203 | if (count == 0) |
| 1204 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
| 1206 | tport->tp_write_urb_in_use = 1; |
| 1207 | |
| 1208 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
| 1209 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 1210 | usb_serial_debug_data(&port->dev, __func__, count, |
| 1211 | port->write_urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
| 1213 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, |
| 1214 | usb_sndbulkpipe(port->serial->dev, |
| 1215 | port->bulk_out_endpointAddress), |
| 1216 | port->write_urb->transfer_buffer, count, |
| 1217 | ti_bulk_out_callback, tport); |
| 1218 | |
| 1219 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
| 1220 | if (result) { |
Johan Hovold | 22a416c | 2012-02-10 13:20:51 +0100 | [diff] [blame] | 1221 | dev_err_console(port, "%s - submit write urb failed, %d\n", |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1222 | __func__, result); |
| 1223 | tport->tp_write_urb_in_use = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | /* TODO: reschedule ti_send */ |
| 1225 | } else { |
| 1226 | spin_lock_irqsave(&tport->tp_lock, flags); |
Johan Hovold | 783ca35 | 2013-03-21 12:37:33 +0100 | [diff] [blame] | 1227 | port->icount.tx += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
| 1229 | } |
| 1230 | |
| 1231 | /* more room in the buffer for new writes, wakeup */ |
Jiri Slaby | 6aad04f | 2013-03-07 13:12:29 +0100 | [diff] [blame] | 1232 | tty_port_tty_wakeup(&port->port); |
| 1233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | wake_up_interruptible(&tport->tp_write_wait); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1235 | return; |
| 1236 | unlock: |
| 1237 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1238 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | static int ti_set_mcr(struct ti_port *tport, unsigned int mcr) |
| 1243 | { |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 1244 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | int status; |
| 1246 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1247 | status = ti_write_byte(tport->tp_port, tport->tp_tdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | tport->tp_uart_base_addr + TI_UART_OFFSET_MCR, |
| 1249 | TI_MCR_RTS | TI_MCR_DTR | TI_MCR_LOOP, mcr); |
| 1250 | |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 1251 | spin_lock_irqsave(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | if (!status) |
| 1253 | tport->tp_shadow_mcr = mcr; |
Alan Cox | 04ca89d | 2008-02-20 21:41:40 +0000 | [diff] [blame] | 1254 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
| 1256 | return status; |
| 1257 | } |
| 1258 | |
| 1259 | |
Johan Hovold | b5784f7 | 2013-04-18 17:33:20 +0200 | [diff] [blame] | 1260 | static int ti_get_lsr(struct ti_port *tport, u8 *lsr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1262 | int size, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | struct ti_device *tdev = tport->tp_tdev; |
| 1264 | struct usb_serial_port *port = tport->tp_port; |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame^] | 1265 | int port_number = port->port_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | struct ti_port_status *data; |
| 1267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | size = sizeof(struct ti_port_status); |
| 1269 | data = kmalloc(size, GFP_KERNEL); |
| 1270 | if (!data) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1271 | dev_err(&port->dev, "%s - out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | return -ENOMEM; |
| 1273 | } |
| 1274 | |
| 1275 | status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, |
| 1276 | (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size); |
| 1277 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1278 | dev_err(&port->dev, |
| 1279 | "%s - get port status command failed, %d\n", |
| 1280 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | goto free_data; |
| 1282 | } |
| 1283 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1284 | dev_dbg(&port->dev, "%s - lsr 0x%02X\n", __func__, data->bLSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
Johan Hovold | b5784f7 | 2013-04-18 17:33:20 +0200 | [diff] [blame] | 1286 | *lsr = data->bLSR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
| 1288 | free_data: |
| 1289 | kfree(data); |
| 1290 | return status; |
| 1291 | } |
| 1292 | |
| 1293 | |
| 1294 | static int ti_get_serial_info(struct ti_port *tport, |
| 1295 | struct serial_struct __user *ret_arg) |
| 1296 | { |
| 1297 | struct usb_serial_port *port = tport->tp_port; |
| 1298 | struct serial_struct ret_serial; |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 1299 | unsigned cwait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
| 1301 | if (!ret_arg) |
| 1302 | return -EFAULT; |
| 1303 | |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 1304 | cwait = port->port.closing_wait; |
| 1305 | if (cwait != ASYNC_CLOSING_WAIT_NONE) |
| 1306 | cwait = jiffies_to_msecs(cwait) / 10; |
| 1307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | memset(&ret_serial, 0, sizeof(ret_serial)); |
| 1309 | |
| 1310 | ret_serial.type = PORT_16550A; |
| 1311 | ret_serial.line = port->serial->minor; |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame^] | 1312 | ret_serial.port = port->port_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | ret_serial.flags = tport->tp_flags; |
| 1314 | ret_serial.xmit_fifo_size = TI_WRITE_BUF_SIZE; |
| 1315 | ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800; |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 1316 | ret_serial.closing_wait = cwait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | |
| 1318 | if (copy_to_user(ret_arg, &ret_serial, sizeof(*ret_arg))) |
| 1319 | return -EFAULT; |
| 1320 | |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
| 1324 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1325 | static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | struct serial_struct __user *new_arg) |
| 1327 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | struct serial_struct new_serial; |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 1329 | unsigned cwait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | |
| 1331 | if (copy_from_user(&new_serial, new_arg, sizeof(new_serial))) |
| 1332 | return -EFAULT; |
| 1333 | |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 1334 | cwait = new_serial.closing_wait; |
| 1335 | if (cwait != ASYNC_CLOSING_WAIT_NONE) |
| 1336 | cwait = msecs_to_jiffies(10 * new_serial.closing_wait); |
| 1337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; |
Johan Hovold | f1175da | 2013-04-18 17:33:23 +0200 | [diff] [blame] | 1339 | tport->tp_port->port.closing_wait = cwait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | static void ti_handle_new_msr(struct ti_port *tport, __u8 msr) |
| 1346 | { |
| 1347 | struct async_icount *icount; |
| 1348 | struct tty_struct *tty; |
| 1349 | unsigned long flags; |
| 1350 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1351 | dev_dbg(&tport->tp_port->dev, "%s - msr 0x%02X\n", __func__, msr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
| 1353 | if (msr & TI_MSR_DELTA_MASK) { |
| 1354 | spin_lock_irqsave(&tport->tp_lock, flags); |
Johan Hovold | 783ca35 | 2013-03-21 12:37:33 +0100 | [diff] [blame] | 1355 | icount = &tport->tp_port->icount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | if (msr & TI_MSR_DELTA_CTS) |
| 1357 | icount->cts++; |
| 1358 | if (msr & TI_MSR_DELTA_DSR) |
| 1359 | icount->dsr++; |
| 1360 | if (msr & TI_MSR_DELTA_CD) |
| 1361 | icount->dcd++; |
| 1362 | if (msr & TI_MSR_DELTA_RI) |
| 1363 | icount->rng++; |
Johan Hovold | 6c75e26 | 2013-03-21 12:37:34 +0100 | [diff] [blame] | 1364 | wake_up_interruptible(&tport->tp_port->port.delta_msr_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
| 1366 | } |
| 1367 | |
| 1368 | tport->tp_msr = msr & TI_MSR_MASK; |
| 1369 | |
| 1370 | /* handle CTS flow control */ |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1371 | tty = tty_port_tty_get(&tport->tp_port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | if (tty && C_CRTSCTS(tty)) { |
| 1373 | if (msr & TI_MSR_CTS) { |
| 1374 | tty->hw_stopped = 0; |
| 1375 | tty_wakeup(tty); |
| 1376 | } else { |
| 1377 | tty->hw_stopped = 1; |
| 1378 | } |
| 1379 | } |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1380 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty) |
| 1385 | { |
| 1386 | unsigned long flags; |
| 1387 | |
| 1388 | spin_lock_irqsave(&tport->tp_lock, flags); |
| 1389 | |
| 1390 | if (tport->tp_read_urb_state == TI_READ_URB_RUNNING) |
| 1391 | tport->tp_read_urb_state = TI_READ_URB_STOPPING; |
| 1392 | |
| 1393 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
| 1394 | } |
| 1395 | |
| 1396 | |
| 1397 | static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty) |
| 1398 | { |
| 1399 | struct urb *urb; |
| 1400 | int status = 0; |
| 1401 | unsigned long flags; |
| 1402 | |
| 1403 | spin_lock_irqsave(&tport->tp_lock, flags); |
| 1404 | |
| 1405 | if (tport->tp_read_urb_state == TI_READ_URB_STOPPED) { |
Oliver Neukum | 944dc18 | 2007-05-07 08:33:18 +0200 | [diff] [blame] | 1406 | tport->tp_read_urb_state = TI_READ_URB_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | urb = tport->tp_port->read_urb; |
Oliver Neukum | 944dc18 | 2007-05-07 08:33:18 +0200 | [diff] [blame] | 1408 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | urb->context = tport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | status = usb_submit_urb(urb, GFP_KERNEL); |
Oliver Neukum | 944dc18 | 2007-05-07 08:33:18 +0200 | [diff] [blame] | 1411 | } else { |
| 1412 | tport->tp_read_urb_state = TI_READ_URB_RUNNING; |
| 1413 | spin_unlock_irqrestore(&tport->tp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
| 1416 | return status; |
| 1417 | } |
| 1418 | |
| 1419 | |
| 1420 | static int ti_command_out_sync(struct ti_device *tdev, __u8 command, |
| 1421 | __u16 moduleid, __u16 value, __u8 *data, int size) |
| 1422 | { |
| 1423 | int status; |
| 1424 | |
| 1425 | status = usb_control_msg(tdev->td_serial->dev, |
| 1426 | usb_sndctrlpipe(tdev->td_serial->dev, 0), command, |
| 1427 | (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT), |
| 1428 | value, moduleid, data, size, 1000); |
| 1429 | |
| 1430 | if (status == size) |
| 1431 | status = 0; |
| 1432 | |
| 1433 | if (status > 0) |
| 1434 | status = -ECOMM; |
| 1435 | |
| 1436 | return status; |
| 1437 | } |
| 1438 | |
| 1439 | |
| 1440 | static int ti_command_in_sync(struct ti_device *tdev, __u8 command, |
| 1441 | __u16 moduleid, __u16 value, __u8 *data, int size) |
| 1442 | { |
| 1443 | int status; |
| 1444 | |
| 1445 | status = usb_control_msg(tdev->td_serial->dev, |
| 1446 | usb_rcvctrlpipe(tdev->td_serial->dev, 0), command, |
| 1447 | (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN), |
| 1448 | value, moduleid, data, size, 1000); |
| 1449 | |
| 1450 | if (status == size) |
| 1451 | status = 0; |
| 1452 | |
| 1453 | if (status > 0) |
| 1454 | status = -ECOMM; |
| 1455 | |
| 1456 | return status; |
| 1457 | } |
| 1458 | |
| 1459 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1460 | static int ti_write_byte(struct usb_serial_port *port, |
| 1461 | struct ti_device *tdev, unsigned long addr, |
| 1462 | __u8 mask, __u8 byte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
| 1464 | int status; |
| 1465 | unsigned int size; |
| 1466 | struct ti_write_data_bytes *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1468 | dev_dbg(&port->dev, "%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X\n", __func__, |
| 1469 | addr, mask, byte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | |
| 1471 | size = sizeof(struct ti_write_data_bytes) + 2; |
| 1472 | data = kmalloc(size, GFP_KERNEL); |
| 1473 | if (!data) { |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1474 | dev_err(&port->dev, "%s - out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | return -ENOMEM; |
| 1476 | } |
| 1477 | |
| 1478 | data->bAddrType = TI_RW_DATA_ADDR_XDATA; |
| 1479 | data->bDataType = TI_RW_DATA_BYTE; |
| 1480 | data->bDataCounter = 1; |
| 1481 | data->wBaseAddrHi = cpu_to_be16(addr>>16); |
| 1482 | data->wBaseAddrLo = cpu_to_be16(addr); |
| 1483 | data->bData[0] = mask; |
| 1484 | data->bData[1] = byte; |
| 1485 | |
| 1486 | status = ti_command_out_sync(tdev, TI_WRITE_DATA, TI_RAM_PORT, 0, |
| 1487 | (__u8 *)data, size); |
| 1488 | |
| 1489 | if (status < 0) |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1490 | dev_err(&port->dev, "%s - failed, %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | |
| 1492 | kfree(data); |
| 1493 | |
| 1494 | return status; |
| 1495 | } |
| 1496 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1497 | static int ti_do_download(struct usb_device *dev, int pipe, |
| 1498 | u8 *buffer, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | int pos; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1501 | u8 cs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | int done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | struct ti_firmware_header *header; |
Oliver Neukum | 87ea8c8 | 2009-06-30 09:44:24 +0200 | [diff] [blame] | 1504 | int status = 0; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1505 | int len; |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1506 | |
| 1507 | for (pos = sizeof(struct ti_firmware_header); pos < size; pos++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | cs = (__u8)(cs + buffer[pos]); |
| 1509 | |
| 1510 | header = (struct ti_firmware_header *)buffer; |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1511 | header->wLength = cpu_to_le16((__u16)(size |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1512 | - sizeof(struct ti_firmware_header))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | header->bCheckSum = cs; |
| 1514 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1515 | dev_dbg(&dev->dev, "%s - downloading firmware\n", __func__); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1516 | for (pos = 0; pos < size; pos += done) { |
| 1517 | len = min(size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE); |
| 1518 | status = usb_bulk_msg(dev, pipe, buffer + pos, len, |
| 1519 | &done, 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | if (status) |
| 1521 | break; |
| 1522 | } |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1523 | return status; |
| 1524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 1526 | static int ti_download_firmware(struct ti_device *tdev) |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1527 | { |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 1528 | int status; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1529 | int buffer_size; |
| 1530 | __u8 *buffer; |
| 1531 | struct usb_device *dev = tdev->td_serial->dev; |
| 1532 | unsigned int pipe = usb_sndbulkpipe(dev, |
| 1533 | tdev->td_serial->port[0]->bulk_out_endpointAddress); |
| 1534 | const struct firmware *fw_p; |
| 1535 | char buf[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 1537 | /* try ID specific firmware first, then try generic firmware */ |
| 1538 | sprintf(buf, "ti_usb-v%04x-p%04x.fw", dev->descriptor.idVendor, |
| 1539 | dev->descriptor.idProduct); |
Adhir Ramjiawan | 72b27a0 | 2012-04-09 14:01:38 +0200 | [diff] [blame] | 1540 | status = request_firmware(&fw_p, buf, &dev->dev); |
| 1541 | |
| 1542 | if (status != 0) { |
Chris Adams | cb7a7c6 | 2009-01-11 19:49:00 +0000 | [diff] [blame] | 1543 | buf[0] = '\0'; |
| 1544 | if (dev->descriptor.idVendor == MTS_VENDOR_ID) { |
| 1545 | switch (dev->descriptor.idProduct) { |
| 1546 | case MTS_CDMA_PRODUCT_ID: |
| 1547 | strcpy(buf, "mts_cdma.fw"); |
| 1548 | break; |
| 1549 | case MTS_GSM_PRODUCT_ID: |
| 1550 | strcpy(buf, "mts_gsm.fw"); |
| 1551 | break; |
| 1552 | case MTS_EDGE_PRODUCT_ID: |
| 1553 | strcpy(buf, "mts_edge.fw"); |
| 1554 | break; |
Alex Manoussakis | cdc0483 | 2010-04-22 15:18:20 -0700 | [diff] [blame] | 1555 | case MTS_MT9234MU_PRODUCT_ID: |
| 1556 | strcpy(buf, "mts_mt9234mu.fw"); |
| 1557 | break; |
| 1558 | case MTS_MT9234ZBA_PRODUCT_ID: |
| 1559 | strcpy(buf, "mts_mt9234zba.fw"); |
| 1560 | break; |
| 1561 | case MTS_MT9234ZBAOLD_PRODUCT_ID: |
| 1562 | strcpy(buf, "mts_mt9234zba.fw"); |
| 1563 | break; } |
Chris Adams | cb7a7c6 | 2009-01-11 19:49:00 +0000 | [diff] [blame] | 1564 | } |
| 1565 | if (buf[0] == '\0') { |
| 1566 | if (tdev->td_is_3410) |
| 1567 | strcpy(buf, "ti_3410.fw"); |
| 1568 | else |
| 1569 | strcpy(buf, "ti_5052.fw"); |
| 1570 | } |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 1571 | status = request_firmware(&fw_p, buf, &dev->dev); |
| 1572 | } |
| 1573 | if (status) { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1574 | dev_err(&dev->dev, "%s - firmware not found\n", __func__); |
| 1575 | return -ENOENT; |
| 1576 | } |
| 1577 | if (fw_p->size > TI_FIRMWARE_BUF_SIZE) { |
Randy Dunlap | 75181f3 | 2010-04-15 11:38:56 -0700 | [diff] [blame] | 1578 | dev_err(&dev->dev, "%s - firmware too large %zu\n", __func__, fw_p->size); |
Jesper Juhl | 357f45d | 2011-06-13 22:50:41 +0200 | [diff] [blame] | 1579 | release_firmware(fw_p); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1580 | return -ENOENT; |
| 1581 | } |
| 1582 | |
| 1583 | buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header); |
| 1584 | buffer = kmalloc(buffer_size, GFP_KERNEL); |
| 1585 | if (buffer) { |
| 1586 | memcpy(buffer, fw_p->data, fw_p->size); |
| 1587 | memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size); |
Chris Adams | 2bcbe4c1 | 2008-09-10 14:11:38 -0700 | [diff] [blame] | 1588 | status = ti_do_download(dev, pipe, buffer, fw_p->size); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1589 | kfree(buffer); |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 1590 | } else { |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1591 | dev_dbg(&dev->dev, "%s ENOMEM\n", __func__); |
Chris Adams | 05a3d90 | 2009-01-11 19:48:53 +0000 | [diff] [blame] | 1592 | status = -ENOMEM; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1593 | } |
| 1594 | release_firmware(fw_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | if (status) { |
Alan Cox | a30fa79 | 2008-07-22 11:15:17 +0100 | [diff] [blame] | 1596 | dev_err(&dev->dev, "%s - error downloading firmware, %d\n", |
| 1597 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | return status; |
| 1599 | } |
| 1600 | |
Greg Kroah-Hartman | d53839c | 2012-09-14 15:08:36 -0700 | [diff] [blame] | 1601 | dev_dbg(&dev->dev, "%s - download successful\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | |
| 1603 | return 0; |
| 1604 | } |