Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB ConnectTech WhiteHEAT driver |
| 3 | * |
| 4 | * Copyright (C) 2002 |
| 5 | * Connect Tech Inc. |
| 6 | * |
| 7 | * Copyright (C) 1999 - 2001 |
| 8 | * Greg Kroah-Hartman (greg@kroah.com) |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 15 | * See Documentation/usb/usb-serial.txt for more information on using this |
| 16 | * driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/tty.h> |
| 24 | #include <linux/tty_driver.h> |
| 25 | #include <linux/tty_flip.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/spinlock.h> |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 28 | #include <linux/mutex.h> |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 29 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/termbits.h> |
| 31 | #include <linux/usb.h> |
| 32 | #include <linux/serial_reg.h> |
| 33 | #include <linux/serial.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 34 | #include <linux/usb/serial.h> |
Rene Buergel | cc183e2 | 2012-09-18 09:00:41 +0200 | [diff] [blame] | 35 | #include <linux/usb/ezusb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "whiteheat.h" /* WhiteHEAT specific commands */ |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #ifndef CMSPAR |
| 39 | #define CMSPAR 0 |
| 40 | #endif |
| 41 | |
| 42 | /* |
| 43 | * Version Information |
| 44 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>" |
| 46 | #define DRIVER_DESC "USB ConnectTech WhiteHEAT driver" |
| 47 | |
| 48 | #define CONNECT_TECH_VENDOR_ID 0x0710 |
| 49 | #define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001 |
| 50 | #define CONNECT_TECH_WHITE_HEAT_ID 0x8001 |
| 51 | |
| 52 | /* |
| 53 | ID tables for whiteheat are unusual, because we want to different |
| 54 | things for different versions of the device. Eventually, this |
| 55 | will be doable from a single table. But, for now, we define two |
| 56 | separate ID tables, and then a third table that combines them |
| 57 | just for the purpose of exporting the autoloading information. |
| 58 | */ |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 59 | static const struct usb_device_id id_table_std[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) }, |
| 61 | { } /* Terminating entry */ |
| 62 | }; |
| 63 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 64 | static const struct usb_device_id id_table_prerenumeration[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) }, |
| 66 | { } /* Terminating entry */ |
| 67 | }; |
| 68 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 69 | static const struct usb_device_id id_table_combined[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) }, |
| 71 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) }, |
| 72 | { } /* Terminating entry */ |
| 73 | }; |
| 74 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 75 | MODULE_DEVICE_TABLE(usb, id_table_combined); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 79 | static int whiteheat_firmware_download(struct usb_serial *serial, |
| 80 | const struct usb_device_id *id); |
| 81 | static int whiteheat_firmware_attach(struct usb_serial *serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* function prototypes for the Connect Tech WhiteHEAT serial converter */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 84 | static int whiteheat_attach(struct usb_serial *serial); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 85 | static void whiteheat_release(struct usb_serial *serial); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 86 | static int whiteheat_open(struct tty_struct *tty, |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 87 | struct usb_serial_port *port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 88 | static void whiteheat_close(struct usb_serial_port *port); |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 89 | static int whiteheat_ioctl(struct tty_struct *tty, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 90 | unsigned int cmd, unsigned long arg); |
| 91 | static void whiteheat_set_termios(struct tty_struct *tty, |
| 92 | struct usb_serial_port *port, struct ktermios *old); |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 93 | static int whiteheat_tiocmget(struct tty_struct *tty); |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 94 | static int whiteheat_tiocmset(struct tty_struct *tty, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 95 | unsigned int set, unsigned int clear); |
| 96 | static void whiteheat_break_ctl(struct tty_struct *tty, int break_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 98 | static struct usb_serial_driver whiteheat_fake_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 99 | .driver = { |
| 100 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 101 | .name = "whiteheatnofirm", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 102 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 103 | .description = "Connect Tech - WhiteHEAT - (prerenumeration)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | .id_table = id_table_prerenumeration, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | .num_ports = 1, |
| 106 | .probe = whiteheat_firmware_download, |
| 107 | .attach = whiteheat_firmware_attach, |
| 108 | }; |
| 109 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 110 | static struct usb_serial_driver whiteheat_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 111 | .driver = { |
| 112 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 113 | .name = "whiteheat", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 114 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 115 | .description = "Connect Tech - WhiteHEAT", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | .id_table = id_table_std, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .num_ports = 4, |
| 118 | .attach = whiteheat_attach, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 119 | .release = whiteheat_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | .open = whiteheat_open, |
| 121 | .close = whiteheat_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .ioctl = whiteheat_ioctl, |
| 123 | .set_termios = whiteheat_set_termios, |
| 124 | .break_ctl = whiteheat_break_ctl, |
| 125 | .tiocmget = whiteheat_tiocmget, |
| 126 | .tiocmset = whiteheat_tiocmset, |
Johan Hovold | 5c0c758 | 2012-03-22 16:50:55 +0100 | [diff] [blame] | 127 | .throttle = usb_serial_generic_throttle, |
| 128 | .unthrottle = usb_serial_generic_unthrottle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
Alan Stern | 29618e9 | 2012-02-23 14:57:32 -0500 | [diff] [blame] | 131 | static struct usb_serial_driver * const serial_drivers[] = { |
| 132 | &whiteheat_fake_device, &whiteheat_device, NULL |
| 133 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | struct whiteheat_command_private { |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 136 | struct mutex mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | __u8 port_running; |
| 138 | __u8 command_finished; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 139 | wait_queue_head_t wait_command; /* for handling sleeping whilst |
| 140 | waiting for a command to |
| 141 | finish */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | __u8 result_buffer[64]; |
| 143 | }; |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | struct whiteheat_private { |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 146 | __u8 mcr; /* FIXME: no locking on mcr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | |
| 150 | /* local function prototypes */ |
| 151 | static int start_command_port(struct usb_serial *serial); |
| 152 | static void stop_command_port(struct usb_serial *serial); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 153 | static void command_port_write_callback(struct urb *urb); |
| 154 | static void command_port_read_callback(struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 156 | static int firm_send_command(struct usb_serial_port *port, __u8 command, |
| 157 | __u8 *data, __u8 datasize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | static int firm_open(struct usb_serial_port *port); |
| 159 | static int firm_close(struct usb_serial_port *port); |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 160 | static void firm_setup_port(struct tty_struct *tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); |
| 162 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); |
| 163 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff); |
| 164 | static int firm_purge(struct usb_serial_port *port, __u8 rxtx); |
| 165 | static int firm_get_dtr_rts(struct usb_serial_port *port); |
| 166 | static int firm_report_tx_done(struct usb_serial_port *port); |
| 167 | |
| 168 | |
| 169 | #define COMMAND_PORT 4 |
| 170 | #define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */ |
| 171 | #define COMMAND_TIMEOUT_MS 2000 |
| 172 | #define CLOSING_DELAY (30 * HZ) |
| 173 | |
| 174 | |
| 175 | /***************************************************************************** |
| 176 | * Connect Tech's White Heat prerenumeration driver functions |
| 177 | *****************************************************************************/ |
| 178 | |
| 179 | /* steps to download the firmware to the WhiteHEAT device: |
| 180 | - hold the reset (by writing to the reset bit of the CPUCS register) |
| 181 | - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD |
| 182 | - release the reset (by writing to the CPUCS register) |
| 183 | - download the WH.HEX file for all addresses greater than 0x1b3f using |
| 184 | VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD |
| 185 | - hold the reset |
| 186 | - download the WH.HEX file for all addresses less than 0x1b40 using |
| 187 | VENDOR_REQUEST_ANCHOR_LOAD |
| 188 | - release the reset |
| 189 | - device renumerated itself and comes up as new device id with all |
| 190 | firmware download completed. |
| 191 | */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 192 | static int whiteheat_firmware_download(struct usb_serial *serial, |
| 193 | const struct usb_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Rene Buergel | 8d733e2 | 2012-09-18 09:02:01 +0200 | [diff] [blame] | 195 | int response; |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 196 | |
Rene Buergel | 8d733e2 | 2012-09-18 09:02:01 +0200 | [diff] [blame] | 197 | response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat_loader.fw"); |
| 198 | if (response >= 0) { |
| 199 | response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat.fw"); |
| 200 | if (response >= 0) |
| 201 | return 0; |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 202 | } |
Rene Buergel | 8d733e2 | 2012-09-18 09:02:01 +0200 | [diff] [blame] | 203 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 207 | static int whiteheat_firmware_attach(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
| 209 | /* We want this device to fail to have a driver assigned to it */ |
| 210 | return 1; |
| 211 | } |
| 212 | |
| 213 | |
| 214 | /***************************************************************************** |
| 215 | * Connect Tech's White Heat serial driver functions |
| 216 | *****************************************************************************/ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 217 | static int whiteheat_attach(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
| 219 | struct usb_serial_port *command_port; |
| 220 | struct whiteheat_command_private *command_info; |
| 221 | struct usb_serial_port *port; |
| 222 | struct whiteheat_private *info; |
| 223 | struct whiteheat_hw_info *hw_info; |
| 224 | int pipe; |
| 225 | int ret; |
| 226 | int alen; |
| 227 | __u8 *command; |
| 228 | __u8 *result; |
| 229 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
| 231 | command_port = serial->port[COMMAND_PORT]; |
| 232 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 233 | pipe = usb_sndbulkpipe(serial->dev, |
| 234 | command_port->bulk_out_endpointAddress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | command = kmalloc(2, GFP_KERNEL); |
| 236 | if (!command) |
| 237 | goto no_command_buffer; |
| 238 | command[0] = WHITEHEAT_GET_HW_INFO; |
| 239 | command[1] = 0; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL); |
| 242 | if (!result) |
| 243 | goto no_result_buffer; |
| 244 | /* |
| 245 | * When the module is reloaded the firmware is still there and |
| 246 | * the endpoints are still in the usb core unchanged. This is the |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 247 | * unlinking bug in disguise. Same for the call below. |
| 248 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | usb_clear_halt(serial->dev, pipe); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 250 | ret = usb_bulk_msg(serial->dev, pipe, command, 2, |
| 251 | &alen, COMMAND_TIMEOUT_MS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | if (ret) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 253 | dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n", |
| 254 | serial->type->description, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | goto no_firmware; |
Stuart MacDonald | 09fd6bc | 2006-05-31 13:28:40 -0400 | [diff] [blame] | 256 | } else if (alen != 2) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 257 | dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n", |
| 258 | serial->type->description, alen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | goto no_firmware; |
| 260 | } |
| 261 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 262 | pipe = usb_rcvbulkpipe(serial->dev, |
| 263 | command_port->bulk_in_endpointAddress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /* See the comment on the usb_clear_halt() above */ |
| 265 | usb_clear_halt(serial->dev, pipe); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 266 | ret = usb_bulk_msg(serial->dev, pipe, result, |
| 267 | sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (ret) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 269 | dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n", |
| 270 | serial->type->description, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | goto no_firmware; |
Stuart MacDonald | 09fd6bc | 2006-05-31 13:28:40 -0400 | [diff] [blame] | 272 | } else if (alen != sizeof(*hw_info) + 1) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 273 | dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n", |
| 274 | serial->type->description, alen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | goto no_firmware; |
| 276 | } else if (result[0] != command[0]) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 277 | dev_err(&serial->dev->dev, "%s: Command failed [%d]\n", |
| 278 | serial->type->description, result[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | goto no_firmware; |
| 280 | } |
| 281 | |
| 282 | hw_info = (struct whiteheat_hw_info *)&result[1]; |
| 283 | |
Johan Hovold | a6765cb | 2012-03-22 16:50:54 +0100 | [diff] [blame] | 284 | dev_info(&serial->dev->dev, "%s: Firmware v%d.%02d\n", |
| 285 | serial->type->description, |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 286 | hw_info->sw_major_rev, hw_info->sw_minor_rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | for (i = 0; i < serial->num_ports; i++) { |
| 289 | port = serial->port[i]; |
| 290 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 291 | info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (info == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 293 | dev_err(&port->dev, |
| 294 | "%s: Out of memory for port structures\n", |
| 295 | serial->type->description); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | goto no_private; |
| 297 | } |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | info->mcr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | usb_set_serial_port_data(port, info); |
| 302 | } |
| 303 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 304 | command_info = kmalloc(sizeof(struct whiteheat_command_private), |
| 305 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | if (command_info == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 307 | dev_err(&serial->dev->dev, |
| 308 | "%s: Out of memory for port structures\n", |
| 309 | serial->type->description); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | goto no_command_private; |
| 311 | } |
| 312 | |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 313 | mutex_init(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | command_info->port_running = 0; |
| 315 | init_waitqueue_head(&command_info->wait_command); |
| 316 | usb_set_serial_port_data(command_port, command_info); |
| 317 | command_port->write_urb->complete = command_port_write_callback; |
| 318 | command_port->read_urb->complete = command_port_read_callback; |
| 319 | kfree(result); |
| 320 | kfree(command); |
| 321 | |
| 322 | return 0; |
| 323 | |
| 324 | no_firmware: |
| 325 | /* Firmware likely not running */ |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 326 | dev_err(&serial->dev->dev, |
| 327 | "%s: Unable to retrieve firmware version, try replugging\n", |
| 328 | serial->type->description); |
| 329 | dev_err(&serial->dev->dev, |
| 330 | "%s: If the firmware is not running (status led not blinking)\n", |
| 331 | serial->type->description); |
| 332 | dev_err(&serial->dev->dev, |
| 333 | "%s: please contact support@connecttech.com\n", |
| 334 | serial->type->description); |
Jesper Juhl | 67ca028 | 2006-04-23 19:59:23 +0200 | [diff] [blame] | 335 | kfree(result); |
Johan Hovold | c129197 | 2012-10-25 10:29:01 +0200 | [diff] [blame^] | 336 | kfree(command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return -ENODEV; |
| 338 | |
| 339 | no_command_private: |
| 340 | for (i = serial->num_ports - 1; i >= 0; i--) { |
| 341 | port = serial->port[i]; |
| 342 | info = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | kfree(info); |
| 344 | no_private: |
| 345 | ; |
| 346 | } |
| 347 | kfree(result); |
| 348 | no_result_buffer: |
| 349 | kfree(command); |
| 350 | no_command_buffer: |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
| 354 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 355 | static void whiteheat_release(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
| 357 | struct usb_serial_port *command_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | struct whiteheat_private *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | int i; |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | /* free up our private data for our command port */ |
| 362 | command_port = serial->port[COMMAND_PORT]; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 363 | kfree(usb_get_serial_port_data(command_port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | for (i = 0; i < serial->num_ports; i++) { |
Johan Hovold | 5c0c758 | 2012-03-22 16:50:55 +0100 | [diff] [blame] | 366 | info = usb_get_serial_port_data(serial->port[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | kfree(info); |
| 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 371 | static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
Johan Hovold | 5c0c758 | 2012-03-22 16:50:55 +0100 | [diff] [blame] | 373 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | retval = start_command_port(port->serial); |
| 376 | if (retval) |
| 377 | goto exit; |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* send an open port command */ |
| 380 | retval = firm_open(port); |
| 381 | if (retval) { |
| 382 | stop_command_port(port->serial); |
| 383 | goto exit; |
| 384 | } |
| 385 | |
| 386 | retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX); |
| 387 | if (retval) { |
| 388 | firm_close(port); |
| 389 | stop_command_port(port->serial); |
| 390 | goto exit; |
| 391 | } |
| 392 | |
Alan Cox | 72e2741 | 2008-07-22 11:09:29 +0100 | [diff] [blame] | 393 | if (tty) |
| 394 | firm_setup_port(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | /* Work around HCD bugs */ |
| 397 | usb_clear_halt(port->serial->dev, port->read_urb->pipe); |
| 398 | usb_clear_halt(port->serial->dev, port->write_urb->pipe); |
| 399 | |
Johan Hovold | 5c0c758 | 2012-03-22 16:50:55 +0100 | [diff] [blame] | 400 | retval = usb_serial_generic_open(tty, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | if (retval) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | firm_close(port); |
| 403 | stop_command_port(port->serial); |
| 404 | goto exit; |
| 405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | return retval; |
| 408 | } |
| 409 | |
| 410 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 411 | static void whiteheat_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | firm_report_tx_done(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | firm_close(port); |
| 415 | |
Johan Hovold | 5c0c758 | 2012-03-22 16:50:55 +0100 | [diff] [blame] | 416 | usb_serial_generic_close(port); |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | stop_command_port(port->serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 421 | static int whiteheat_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 423 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 425 | unsigned int modem_signals = 0; |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | firm_get_dtr_rts(port); |
| 428 | if (info->mcr & UART_MCR_DTR) |
| 429 | modem_signals |= TIOCM_DTR; |
| 430 | if (info->mcr & UART_MCR_RTS) |
| 431 | modem_signals |= TIOCM_RTS; |
| 432 | |
| 433 | return modem_signals; |
| 434 | } |
| 435 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 436 | static int whiteheat_tiocmset(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | unsigned int set, unsigned int clear) |
| 438 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 439 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | if (set & TIOCM_RTS) |
| 443 | info->mcr |= UART_MCR_RTS; |
| 444 | if (set & TIOCM_DTR) |
| 445 | info->mcr |= UART_MCR_DTR; |
| 446 | |
| 447 | if (clear & TIOCM_RTS) |
| 448 | info->mcr &= ~UART_MCR_RTS; |
| 449 | if (clear & TIOCM_DTR) |
| 450 | info->mcr &= ~UART_MCR_DTR; |
| 451 | |
| 452 | firm_set_dtr(port, info->mcr & UART_MCR_DTR); |
| 453 | firm_set_rts(port, info->mcr & UART_MCR_RTS); |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 458 | static int whiteheat_ioctl(struct tty_struct *tty, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 459 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 461 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | struct serial_struct serstruct; |
| 463 | void __user *user_arg = (void __user *)arg; |
| 464 | |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 465 | dev_dbg(&port->dev, "%s - cmd 0x%.4x\n", __func__, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | switch (cmd) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 468 | case TIOCGSERIAL: |
| 469 | memset(&serstruct, 0, sizeof(serstruct)); |
| 470 | serstruct.type = PORT_16654; |
| 471 | serstruct.line = port->serial->minor; |
| 472 | serstruct.port = port->number; |
| 473 | serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; |
Johan Hovold | 5c0c758 | 2012-03-22 16:50:55 +0100 | [diff] [blame] | 474 | serstruct.xmit_fifo_size = kfifo_size(&port->write_fifo); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 475 | serstruct.custom_divisor = 0; |
| 476 | serstruct.baud_base = 460800; |
| 477 | serstruct.close_delay = CLOSING_DELAY; |
| 478 | serstruct.closing_wait = CLOSING_DELAY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 480 | if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) |
| 481 | return -EFAULT; |
| 482 | break; |
| 483 | default: |
| 484 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | return -ENOIOCTLCMD; |
| 488 | } |
| 489 | |
| 490 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 491 | static void whiteheat_set_termios(struct tty_struct *tty, |
| 492 | struct usb_serial_port *port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 494 | firm_setup_port(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 497 | static void whiteheat_break_ctl(struct tty_struct *tty, int break_state) |
| 498 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 499 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | firm_set_break(port, break_state); |
| 501 | } |
| 502 | |
| 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | /***************************************************************************** |
| 505 | * Connect Tech's White Heat callback routines |
| 506 | *****************************************************************************/ |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 507 | static void command_port_write_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 509 | int status = urb->status; |
| 510 | |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 511 | if (status) { |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 512 | dev_dbg(&urb->dev->dev, "nonzero urb status: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | return; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 518 | static void command_port_read_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 520 | struct usb_serial_port *command_port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | struct whiteheat_command_private *command_info; |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 522 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | unsigned char *data = urb->transfer_buffer; |
| 524 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | command_info = usb_get_serial_port_data(command_port); |
| 527 | if (!command_info) { |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 528 | dev_dbg(&urb->dev->dev, "%s - command_info is NULL, exiting.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | return; |
| 530 | } |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 531 | if (status) { |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 532 | dev_dbg(&urb->dev->dev, "%s - nonzero urb status: %d\n", __func__, status); |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 533 | if (status != -ENOENT) |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 534 | command_info->command_finished = WHITEHEAT_CMD_FAILURE; |
| 535 | wake_up(&command_info->wait_command); |
| 536 | return; |
| 537 | } |
| 538 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 539 | usb_serial_debug_data(&command_port->dev, __func__, urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | if (data[0] == WHITEHEAT_CMD_COMPLETE) { |
| 542 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 543 | wake_up(&command_info->wait_command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } else if (data[0] == WHITEHEAT_CMD_FAILURE) { |
| 545 | command_info->command_finished = WHITEHEAT_CMD_FAILURE; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 546 | wake_up(&command_info->wait_command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } else if (data[0] == WHITEHEAT_EVENT) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 548 | /* These are unsolicited reports from the firmware, hence no |
| 549 | waiting command to wakeup */ |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 550 | dev_dbg(&urb->dev->dev, "%s - event received\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } else if (data[0] == WHITEHEAT_GET_DTR_RTS) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 552 | memcpy(command_info->result_buffer, &data[1], |
| 553 | urb->actual_length - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 555 | wake_up(&command_info->wait_command); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 556 | } else |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 557 | dev_dbg(&urb->dev->dev, "%s - bad reply from firmware\n", __func__); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | /* Continue trying to always read */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | if (result) |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 562 | dev_dbg(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 563 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | /***************************************************************************** |
| 568 | * Connect Tech's White Heat firmware interface |
| 569 | *****************************************************************************/ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 570 | static int firm_send_command(struct usb_serial_port *port, __u8 command, |
| 571 | __u8 *data, __u8 datasize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | { |
| 573 | struct usb_serial_port *command_port; |
| 574 | struct whiteheat_command_private *command_info; |
| 575 | struct whiteheat_private *info; |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 576 | struct device *dev = &port->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | __u8 *transfer_buffer; |
| 578 | int retval = 0; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 579 | int t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 581 | dev_dbg(dev, "%s - command %d\n", __func__, command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | command_port = port->serial->port[COMMAND_PORT]; |
| 584 | command_info = usb_get_serial_port_data(command_port); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 585 | mutex_lock(&command_info->mutex); |
Richard Knutsson | 38c3cb5 | 2007-03-26 22:00:28 -0800 | [diff] [blame] | 586 | command_info->command_finished = false; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; |
| 589 | transfer_buffer[0] = command; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 590 | memcpy(&transfer_buffer[1], data, datasize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | command_port->write_urb->transfer_buffer_length = datasize + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 592 | retval = usb_submit_urb(command_port->write_urb, GFP_NOIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | if (retval) { |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 594 | dev_dbg(dev, "%s - submit urb failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | goto exit; |
| 596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | /* wait for the command to complete */ |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 599 | t = wait_event_timeout(command_info->wait_command, |
Richard Knutsson | 38c3cb5 | 2007-03-26 22:00:28 -0800 | [diff] [blame] | 600 | (bool)command_info->command_finished, COMMAND_TIMEOUT); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 601 | if (!t) |
| 602 | usb_kill_urb(command_port->write_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Richard Knutsson | 38c3cb5 | 2007-03-26 22:00:28 -0800 | [diff] [blame] | 604 | if (command_info->command_finished == false) { |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 605 | dev_dbg(dev, "%s - command timed out.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | retval = -ETIMEDOUT; |
| 607 | goto exit; |
| 608 | } |
| 609 | |
| 610 | if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) { |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 611 | dev_dbg(dev, "%s - command failed.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | retval = -EIO; |
| 613 | goto exit; |
| 614 | } |
| 615 | |
| 616 | if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) { |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 617 | dev_dbg(dev, "%s - command completed.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | switch (command) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 619 | case WHITEHEAT_GET_DTR_RTS: |
| 620 | info = usb_get_serial_port_data(port); |
| 621 | memcpy(&info->mcr, command_info->result_buffer, |
| 622 | sizeof(struct whiteheat_dr_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | break; |
| 624 | } |
| 625 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | exit: |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 627 | mutex_unlock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | return retval; |
| 629 | } |
| 630 | |
| 631 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 632 | static int firm_open(struct usb_serial_port *port) |
| 633 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | struct whiteheat_simple open_command; |
| 635 | |
| 636 | open_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 637 | return firm_send_command(port, WHITEHEAT_OPEN, |
| 638 | (__u8 *)&open_command, sizeof(open_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 642 | static int firm_close(struct usb_serial_port *port) |
| 643 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | struct whiteheat_simple close_command; |
| 645 | |
| 646 | close_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 647 | return firm_send_command(port, WHITEHEAT_CLOSE, |
| 648 | (__u8 *)&close_command, sizeof(close_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 652 | static void firm_setup_port(struct tty_struct *tty) |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 653 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 654 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 655 | struct device *dev = &port->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | struct whiteheat_port_settings port_settings; |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 657 | unsigned int cflag = tty->termios.c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
| 659 | port_settings.port = port->number + 1; |
| 660 | |
| 661 | /* get the byte size */ |
| 662 | switch (cflag & CSIZE) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 663 | case CS5: port_settings.bits = 5; break; |
| 664 | case CS6: port_settings.bits = 6; break; |
| 665 | case CS7: port_settings.bits = 7; break; |
| 666 | default: |
| 667 | case CS8: port_settings.bits = 8; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 669 | dev_dbg(dev, "%s - data bits = %d\n", __func__, port_settings.bits); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | /* determine the parity */ |
| 672 | if (cflag & PARENB) |
| 673 | if (cflag & CMSPAR) |
| 674 | if (cflag & PARODD) |
| 675 | port_settings.parity = WHITEHEAT_PAR_MARK; |
| 676 | else |
| 677 | port_settings.parity = WHITEHEAT_PAR_SPACE; |
| 678 | else |
| 679 | if (cflag & PARODD) |
| 680 | port_settings.parity = WHITEHEAT_PAR_ODD; |
| 681 | else |
| 682 | port_settings.parity = WHITEHEAT_PAR_EVEN; |
| 683 | else |
| 684 | port_settings.parity = WHITEHEAT_PAR_NONE; |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 685 | dev_dbg(dev, "%s - parity = %c\n", __func__, port_settings.parity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | /* figure out the stop bits requested */ |
| 688 | if (cflag & CSTOPB) |
| 689 | port_settings.stop = 2; |
| 690 | else |
| 691 | port_settings.stop = 1; |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 692 | dev_dbg(dev, "%s - stop bits = %d\n", __func__, port_settings.stop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | /* figure out the flow control settings */ |
| 695 | if (cflag & CRTSCTS) |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 696 | port_settings.hflow = (WHITEHEAT_HFLOW_CTS | |
| 697 | WHITEHEAT_HFLOW_RTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | else |
| 699 | port_settings.hflow = WHITEHEAT_HFLOW_NONE; |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 700 | dev_dbg(dev, "%s - hardware flow control = %s %s %s %s\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "", |
| 702 | (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "", |
| 703 | (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "", |
| 704 | (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : ""); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | /* determine software flow control */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 707 | if (I_IXOFF(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | port_settings.sflow = WHITEHEAT_SFLOW_RXTX; |
| 709 | else |
| 710 | port_settings.sflow = WHITEHEAT_SFLOW_NONE; |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 711 | dev_dbg(dev, "%s - software flow control = %c\n", __func__, port_settings.sflow); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 712 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 713 | port_settings.xon = START_CHAR(tty); |
| 714 | port_settings.xoff = STOP_CHAR(tty); |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 715 | dev_dbg(dev, "%s - XON = %2x, XOFF = %2x\n", __func__, port_settings.xon, port_settings.xoff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
| 717 | /* get the baud rate wanted */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 718 | port_settings.baud = tty_get_baud_rate(tty); |
Greg Kroah-Hartman | 255b703 | 2012-09-14 11:50:35 -0700 | [diff] [blame] | 719 | dev_dbg(dev, "%s - baud rate = %d\n", __func__, port_settings.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Alan Cox | 01d1df2 | 2007-10-18 01:24:23 -0700 | [diff] [blame] | 721 | /* fixme: should set validated settings */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 722 | tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | /* handle any settings that aren't specified in the tty structure */ |
| 724 | port_settings.lloop = 0; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | /* now send the message to the device */ |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 727 | firm_send_command(port, WHITEHEAT_SETUP_PORT, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 728 | (__u8 *)&port_settings, sizeof(port_settings)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 732 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff) |
| 733 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | struct whiteheat_set_rdb rts_command; |
| 735 | |
| 736 | rts_command.port = port->number - port->serial->minor + 1; |
| 737 | rts_command.state = onoff; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 738 | return firm_send_command(port, WHITEHEAT_SET_RTS, |
| 739 | (__u8 *)&rts_command, sizeof(rts_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 743 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff) |
| 744 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | struct whiteheat_set_rdb dtr_command; |
| 746 | |
| 747 | dtr_command.port = port->number - port->serial->minor + 1; |
| 748 | dtr_command.state = onoff; |
Alan Cox | 72e2741 | 2008-07-22 11:09:29 +0100 | [diff] [blame] | 749 | return firm_send_command(port, WHITEHEAT_SET_DTR, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 750 | (__u8 *)&dtr_command, sizeof(dtr_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 754 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff) |
| 755 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | struct whiteheat_set_rdb break_command; |
| 757 | |
| 758 | break_command.port = port->number - port->serial->minor + 1; |
| 759 | break_command.state = onoff; |
Alan Cox | 72e2741 | 2008-07-22 11:09:29 +0100 | [diff] [blame] | 760 | return firm_send_command(port, WHITEHEAT_SET_BREAK, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 761 | (__u8 *)&break_command, sizeof(break_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 765 | static int firm_purge(struct usb_serial_port *port, __u8 rxtx) |
| 766 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | struct whiteheat_purge purge_command; |
| 768 | |
| 769 | purge_command.port = port->number - port->serial->minor + 1; |
| 770 | purge_command.what = rxtx; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 771 | return firm_send_command(port, WHITEHEAT_PURGE, |
| 772 | (__u8 *)&purge_command, sizeof(purge_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 776 | static int firm_get_dtr_rts(struct usb_serial_port *port) |
| 777 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | struct whiteheat_simple get_dr_command; |
| 779 | |
| 780 | get_dr_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 781 | return firm_send_command(port, WHITEHEAT_GET_DTR_RTS, |
| 782 | (__u8 *)&get_dr_command, sizeof(get_dr_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 786 | static int firm_report_tx_done(struct usb_serial_port *port) |
| 787 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | struct whiteheat_simple close_command; |
| 789 | |
| 790 | close_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 791 | return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE, |
| 792 | (__u8 *)&close_command, sizeof(close_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | |
| 796 | /***************************************************************************** |
| 797 | * Connect Tech's White Heat utility functions |
| 798 | *****************************************************************************/ |
| 799 | static int start_command_port(struct usb_serial *serial) |
| 800 | { |
| 801 | struct usb_serial_port *command_port; |
| 802 | struct whiteheat_command_private *command_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | int retval = 0; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | command_port = serial->port[COMMAND_PORT]; |
| 806 | command_info = usb_get_serial_port_data(command_port); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 807 | mutex_lock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (!command_info->port_running) { |
| 809 | /* Work around HCD bugs */ |
| 810 | usb_clear_halt(serial->dev, command_port->read_urb->pipe); |
| 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL); |
| 813 | if (retval) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 814 | dev_err(&serial->dev->dev, |
| 815 | "%s - failed submitting read urb, error %d\n", |
| 816 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | goto exit; |
| 818 | } |
| 819 | } |
| 820 | command_info->port_running++; |
| 821 | |
| 822 | exit: |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 823 | mutex_unlock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | return retval; |
| 825 | } |
| 826 | |
| 827 | |
| 828 | static void stop_command_port(struct usb_serial *serial) |
| 829 | { |
| 830 | struct usb_serial_port *command_port; |
| 831 | struct whiteheat_command_private *command_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
| 833 | command_port = serial->port[COMMAND_PORT]; |
| 834 | command_info = usb_get_serial_port_data(command_port); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 835 | mutex_lock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | command_info->port_running--; |
| 837 | if (!command_info->port_running) |
| 838 | usb_kill_urb(command_port->read_urb); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 839 | mutex_unlock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 842 | module_usb_serial_driver(serial_drivers, id_table_combined); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 844 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 845 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | MODULE_LICENSE("GPL"); |
| 847 | |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 848 | MODULE_FIRMWARE("whiteheat.fw"); |
| 849 | MODULE_FIRMWARE("whiteheat_loader.fw"); |