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