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 | * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com) |
| 19 | * Upgrade to full working driver |
| 20 | * |
| 21 | * (05/30/2001) gkh |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 22 | * switched from using spinlock to a semaphore, which fixes lots of |
| 23 | * problems. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * |
| 25 | * (04/08/2001) gb |
| 26 | * Identify version on module load. |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 27 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * 2001_Mar_19 gkh |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 29 | * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * than once, and the got the proper usb_device_id table entries so |
| 31 | * the driver works again. |
| 32 | * |
| 33 | * (11/01/2000) Adam J. Richter |
| 34 | * usb_device_id table support |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 35 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * (10/05/2000) gkh |
| 37 | * Fixed bug with urb->dev not being set properly, now that the usb |
| 38 | * core needs it. |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 39 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * (10/03/2000) smd |
| 41 | * firmware is improved to guard against crap sent to device |
| 42 | * firmware now replies CMD_FAILURE on bad things |
| 43 | * read_callback fix you provided for private info struct |
| 44 | * command_finished now indicates success or fail |
| 45 | * setup_port struct now packed to avoid gcc padding |
| 46 | * firmware uses 1 based port numbering, driver now handles that |
| 47 | * |
| 48 | * (09/11/2000) gkh |
| 49 | * Removed DEBUG #ifdefs with call to usb_serial_debug_data |
| 50 | * |
| 51 | * (07/19/2000) gkh |
| 52 | * Added module_init and module_exit functions to handle the fact that this |
| 53 | * driver is a loadable module now. |
| 54 | * Fixed bug with port->minor that was found by Al Borchers |
| 55 | * |
| 56 | * (07/04/2000) gkh |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 57 | * Added support for port settings. Baud rate can now be changed. Line |
| 58 | * signals are not transferred to and from the tty layer yet, but things |
| 59 | * seem to be working well now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * |
| 61 | * (05/04/2000) gkh |
| 62 | * First cut at open and close commands. Data can flow through the ports at |
| 63 | * default speeds now. |
| 64 | * |
| 65 | * (03/26/2000) gkh |
| 66 | * Split driver up into device specific pieces. |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 67 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #include <linux/kernel.h> |
| 71 | #include <linux/errno.h> |
| 72 | #include <linux/init.h> |
| 73 | #include <linux/slab.h> |
| 74 | #include <linux/tty.h> |
| 75 | #include <linux/tty_driver.h> |
| 76 | #include <linux/tty_flip.h> |
| 77 | #include <linux/module.h> |
| 78 | #include <linux/spinlock.h> |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 79 | #include <linux/mutex.h> |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 80 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include <asm/termbits.h> |
| 82 | #include <linux/usb.h> |
| 83 | #include <linux/serial_reg.h> |
| 84 | #include <linux/serial.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 85 | #include <linux/usb/serial.h> |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 86 | #include <linux/firmware.h> |
| 87 | #include <linux/ihex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #include "whiteheat.h" /* WhiteHEAT specific commands */ |
| 89 | |
| 90 | static int debug; |
| 91 | |
| 92 | #ifndef CMSPAR |
| 93 | #define CMSPAR 0 |
| 94 | #endif |
| 95 | |
| 96 | /* |
| 97 | * Version Information |
| 98 | */ |
| 99 | #define DRIVER_VERSION "v2.0" |
| 100 | #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>" |
| 101 | #define DRIVER_DESC "USB ConnectTech WhiteHEAT driver" |
| 102 | |
| 103 | #define CONNECT_TECH_VENDOR_ID 0x0710 |
| 104 | #define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001 |
| 105 | #define CONNECT_TECH_WHITE_HEAT_ID 0x8001 |
| 106 | |
| 107 | /* |
| 108 | ID tables for whiteheat are unusual, because we want to different |
| 109 | things for different versions of the device. Eventually, this |
| 110 | will be doable from a single table. But, for now, we define two |
| 111 | separate ID tables, and then a third table that combines them |
| 112 | just for the purpose of exporting the autoloading information. |
| 113 | */ |
| 114 | static struct usb_device_id id_table_std [] = { |
| 115 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) }, |
| 116 | { } /* Terminating entry */ |
| 117 | }; |
| 118 | |
| 119 | static struct usb_device_id id_table_prerenumeration [] = { |
| 120 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) }, |
| 121 | { } /* Terminating entry */ |
| 122 | }; |
| 123 | |
| 124 | static struct usb_device_id id_table_combined [] = { |
| 125 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) }, |
| 126 | { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) }, |
| 127 | { } /* Terminating entry */ |
| 128 | }; |
| 129 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 130 | MODULE_DEVICE_TABLE(usb, id_table_combined); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | static struct usb_driver whiteheat_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | .name = "whiteheat", |
| 134 | .probe = usb_serial_probe, |
| 135 | .disconnect = usb_serial_disconnect, |
| 136 | .id_table = id_table_combined, |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 137 | .no_dynamic_id = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 141 | static int whiteheat_firmware_download(struct usb_serial *serial, |
| 142 | const struct usb_device_id *id); |
| 143 | static int whiteheat_firmware_attach(struct usb_serial *serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* function prototypes for the Connect Tech WhiteHEAT serial converter */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 146 | static int whiteheat_attach(struct usb_serial *serial); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame^] | 147 | static void whiteheat_release(struct usb_serial *serial); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 148 | static int whiteheat_open(struct tty_struct *tty, |
| 149 | struct usb_serial_port *port, struct file *filp); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 150 | static void whiteheat_close(struct usb_serial_port *port); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 151 | static int whiteheat_write(struct tty_struct *tty, |
| 152 | struct usb_serial_port *port, |
| 153 | const unsigned char *buf, int count); |
| 154 | static int whiteheat_write_room(struct tty_struct *tty); |
| 155 | static int whiteheat_ioctl(struct tty_struct *tty, struct file *file, |
| 156 | unsigned int cmd, unsigned long arg); |
| 157 | static void whiteheat_set_termios(struct tty_struct *tty, |
| 158 | struct usb_serial_port *port, struct ktermios *old); |
| 159 | static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file); |
| 160 | static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file, |
| 161 | unsigned int set, unsigned int clear); |
| 162 | static void whiteheat_break_ctl(struct tty_struct *tty, int break_state); |
| 163 | static int whiteheat_chars_in_buffer(struct tty_struct *tty); |
| 164 | static void whiteheat_throttle(struct tty_struct *tty); |
| 165 | static void whiteheat_unthrottle(struct tty_struct *tty); |
| 166 | static void whiteheat_read_callback(struct urb *urb); |
| 167 | static void whiteheat_write_callback(struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 169 | static struct usb_serial_driver whiteheat_fake_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 170 | .driver = { |
| 171 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 172 | .name = "whiteheatnofirm", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 173 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 174 | .description = "Connect Tech - WhiteHEAT - (prerenumeration)", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 175 | .usb_driver = &whiteheat_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | .id_table = id_table_prerenumeration, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | .num_ports = 1, |
| 178 | .probe = whiteheat_firmware_download, |
| 179 | .attach = whiteheat_firmware_attach, |
| 180 | }; |
| 181 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 182 | static struct usb_serial_driver whiteheat_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 183 | .driver = { |
| 184 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 185 | .name = "whiteheat", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 186 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 187 | .description = "Connect Tech - WhiteHEAT", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 188 | .usb_driver = &whiteheat_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | .id_table = id_table_std, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | .num_ports = 4, |
| 191 | .attach = whiteheat_attach, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame^] | 192 | .release = whiteheat_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | .open = whiteheat_open, |
| 194 | .close = whiteheat_close, |
| 195 | .write = whiteheat_write, |
| 196 | .write_room = whiteheat_write_room, |
| 197 | .ioctl = whiteheat_ioctl, |
| 198 | .set_termios = whiteheat_set_termios, |
| 199 | .break_ctl = whiteheat_break_ctl, |
| 200 | .tiocmget = whiteheat_tiocmget, |
| 201 | .tiocmset = whiteheat_tiocmset, |
| 202 | .chars_in_buffer = whiteheat_chars_in_buffer, |
| 203 | .throttle = whiteheat_throttle, |
| 204 | .unthrottle = whiteheat_unthrottle, |
| 205 | .read_bulk_callback = whiteheat_read_callback, |
| 206 | .write_bulk_callback = whiteheat_write_callback, |
| 207 | }; |
| 208 | |
| 209 | |
| 210 | struct whiteheat_command_private { |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 211 | struct mutex mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | __u8 port_running; |
| 213 | __u8 command_finished; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 214 | wait_queue_head_t wait_command; /* for handling sleeping whilst |
| 215 | waiting for a command to |
| 216 | finish */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | __u8 result_buffer[64]; |
| 218 | }; |
| 219 | |
| 220 | |
| 221 | #define THROTTLED 0x01 |
| 222 | #define ACTUALLY_THROTTLED 0x02 |
| 223 | |
| 224 | static int urb_pool_size = 8; |
| 225 | |
| 226 | struct whiteheat_urb_wrap { |
| 227 | struct list_head list; |
| 228 | struct urb *urb; |
| 229 | }; |
| 230 | |
| 231 | struct whiteheat_private { |
| 232 | spinlock_t lock; |
| 233 | __u8 flags; |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 234 | __u8 mcr; /* FIXME: no locking on mcr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | struct list_head rx_urbs_free; |
| 236 | struct list_head rx_urbs_submitted; |
| 237 | struct list_head rx_urb_q; |
| 238 | struct work_struct rx_work; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 239 | struct usb_serial_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | struct list_head tx_urbs_free; |
| 241 | struct list_head tx_urbs_submitted; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 242 | struct mutex deathwarrant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | |
| 246 | /* local function prototypes */ |
| 247 | static int start_command_port(struct usb_serial *serial); |
| 248 | static void stop_command_port(struct usb_serial *serial); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 249 | static void command_port_write_callback(struct urb *urb); |
| 250 | static void command_port_read_callback(struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | static int start_port_read(struct usb_serial_port *port); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 253 | static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, |
| 254 | struct list_head *head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | static struct list_head *list_first(struct list_head *head); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 256 | static void rx_data_softint(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 258 | static int firm_send_command(struct usb_serial_port *port, __u8 command, |
| 259 | __u8 *data, __u8 datasize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | static int firm_open(struct usb_serial_port *port); |
| 261 | static int firm_close(struct usb_serial_port *port); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 262 | static int firm_setup_port(struct tty_struct *tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); |
| 264 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); |
| 265 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff); |
| 266 | static int firm_purge(struct usb_serial_port *port, __u8 rxtx); |
| 267 | static int firm_get_dtr_rts(struct usb_serial_port *port); |
| 268 | static int firm_report_tx_done(struct usb_serial_port *port); |
| 269 | |
| 270 | |
| 271 | #define COMMAND_PORT 4 |
| 272 | #define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */ |
| 273 | #define COMMAND_TIMEOUT_MS 2000 |
| 274 | #define CLOSING_DELAY (30 * HZ) |
| 275 | |
| 276 | |
| 277 | /***************************************************************************** |
| 278 | * Connect Tech's White Heat prerenumeration driver functions |
| 279 | *****************************************************************************/ |
| 280 | |
| 281 | /* steps to download the firmware to the WhiteHEAT device: |
| 282 | - hold the reset (by writing to the reset bit of the CPUCS register) |
| 283 | - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD |
| 284 | - release the reset (by writing to the CPUCS register) |
| 285 | - download the WH.HEX file for all addresses greater than 0x1b3f using |
| 286 | VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD |
| 287 | - hold the reset |
| 288 | - download the WH.HEX file for all addresses less than 0x1b40 using |
| 289 | VENDOR_REQUEST_ANCHOR_LOAD |
| 290 | - release the reset |
| 291 | - device renumerated itself and comes up as new device id with all |
| 292 | firmware download completed. |
| 293 | */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 294 | static int whiteheat_firmware_download(struct usb_serial *serial, |
| 295 | const struct usb_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 297 | int response, ret = -ENOENT; |
| 298 | const struct firmware *loader_fw = NULL, *firmware_fw = NULL; |
| 299 | const struct ihex_binrec *record; |
| 300 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 301 | dbg("%s", __func__); |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 302 | |
| 303 | if (request_ihex_firmware(&firmware_fw, "whiteheat.fw", |
| 304 | &serial->dev->dev)) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 305 | dev_err(&serial->dev->dev, |
| 306 | "%s - request \"whiteheat.fw\" failed\n", __func__); |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 307 | goto out; |
| 308 | } |
| 309 | if (request_ihex_firmware(&loader_fw, "whiteheat_loader.fw", |
| 310 | &serial->dev->dev)) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 311 | dev_err(&serial->dev->dev, |
| 312 | "%s - request \"whiteheat_loader.fw\" failed\n", |
| 313 | __func__); |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 314 | goto out; |
| 315 | } |
| 316 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | response = ezusb_set_reset (serial, 1); |
| 318 | |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 319 | record = (const struct ihex_binrec *)loader_fw->data; |
| 320 | while (record) { |
| 321 | response = ezusb_writememory (serial, be32_to_cpu(record->addr), |
| 322 | (unsigned char *)record->data, |
| 323 | be16_to_cpu(record->len), 0xa0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | if (response < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 325 | dev_err(&serial->dev->dev, "%s - ezusb_writememory " |
| 326 | "failed for loader (%d %04X %p %d)\n", |
| 327 | __func__, response, be32_to_cpu(record->addr), |
| 328 | record->data, be16_to_cpu(record->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | break; |
| 330 | } |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 331 | record = ihex_next_binrec(record); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 334 | response = ezusb_set_reset(serial, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 336 | record = (const struct ihex_binrec *)firmware_fw->data; |
| 337 | while (record && be32_to_cpu(record->addr) < 0x1b40) |
| 338 | record = ihex_next_binrec(record); |
| 339 | while (record) { |
| 340 | response = ezusb_writememory (serial, be32_to_cpu(record->addr), |
| 341 | (unsigned char *)record->data, |
| 342 | be16_to_cpu(record->len), 0xa3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | if (response < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 344 | dev_err(&serial->dev->dev, "%s - ezusb_writememory " |
| 345 | "failed for first firmware step " |
| 346 | "(%d %04X %p %d)\n", __func__, response, |
| 347 | be32_to_cpu(record->addr), record->data, |
| 348 | be16_to_cpu(record->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | break; |
| 350 | } |
| 351 | ++record; |
| 352 | } |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 353 | |
| 354 | response = ezusb_set_reset(serial, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 356 | record = (const struct ihex_binrec *)firmware_fw->data; |
| 357 | while (record && be32_to_cpu(record->addr) < 0x1b40) { |
| 358 | response = ezusb_writememory (serial, be32_to_cpu(record->addr), |
| 359 | (unsigned char *)record->data, |
| 360 | be16_to_cpu(record->len), 0xa0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | if (response < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 362 | dev_err(&serial->dev->dev, "%s - ezusb_writememory " |
| 363 | "failed for second firmware step " |
| 364 | "(%d %04X %p %d)\n", __func__, response, |
| 365 | be32_to_cpu(record->addr), record->data, |
| 366 | be16_to_cpu(record->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | break; |
| 368 | } |
| 369 | ++record; |
| 370 | } |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 371 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | response = ezusb_set_reset (serial, 0); |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 373 | out: |
| 374 | release_firmware(loader_fw); |
| 375 | release_firmware(firmware_fw); |
| 376 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 380 | static int whiteheat_firmware_attach(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
| 382 | /* We want this device to fail to have a driver assigned to it */ |
| 383 | return 1; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | /***************************************************************************** |
| 388 | * Connect Tech's White Heat serial driver functions |
| 389 | *****************************************************************************/ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 390 | static int whiteheat_attach(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
| 392 | struct usb_serial_port *command_port; |
| 393 | struct whiteheat_command_private *command_info; |
| 394 | struct usb_serial_port *port; |
| 395 | struct whiteheat_private *info; |
| 396 | struct whiteheat_hw_info *hw_info; |
| 397 | int pipe; |
| 398 | int ret; |
| 399 | int alen; |
| 400 | __u8 *command; |
| 401 | __u8 *result; |
| 402 | int i; |
| 403 | int j; |
| 404 | struct urb *urb; |
| 405 | int buf_size; |
| 406 | struct whiteheat_urb_wrap *wrap; |
| 407 | struct list_head *tmp; |
| 408 | |
| 409 | command_port = serial->port[COMMAND_PORT]; |
| 410 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 411 | pipe = usb_sndbulkpipe(serial->dev, |
| 412 | command_port->bulk_out_endpointAddress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | command = kmalloc(2, GFP_KERNEL); |
| 414 | if (!command) |
| 415 | goto no_command_buffer; |
| 416 | command[0] = WHITEHEAT_GET_HW_INFO; |
| 417 | command[1] = 0; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL); |
| 420 | if (!result) |
| 421 | goto no_result_buffer; |
| 422 | /* |
| 423 | * When the module is reloaded the firmware is still there and |
| 424 | * the endpoints are still in the usb core unchanged. This is the |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 425 | * unlinking bug in disguise. Same for the call below. |
| 426 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | usb_clear_halt(serial->dev, pipe); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 428 | ret = usb_bulk_msg(serial->dev, pipe, command, 2, |
| 429 | &alen, COMMAND_TIMEOUT_MS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | if (ret) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 431 | dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n", |
| 432 | serial->type->description, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | goto no_firmware; |
Stuart MacDonald | 09fd6bc | 2006-05-31 13:28:40 -0400 | [diff] [blame] | 434 | } else if (alen != 2) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 435 | dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n", |
| 436 | serial->type->description, alen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | goto no_firmware; |
| 438 | } |
| 439 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 440 | pipe = usb_rcvbulkpipe(serial->dev, |
| 441 | command_port->bulk_in_endpointAddress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | /* See the comment on the usb_clear_halt() above */ |
| 443 | usb_clear_halt(serial->dev, pipe); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 444 | ret = usb_bulk_msg(serial->dev, pipe, result, |
| 445 | sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | if (ret) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 447 | dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n", |
| 448 | serial->type->description, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | goto no_firmware; |
Stuart MacDonald | 09fd6bc | 2006-05-31 13:28:40 -0400 | [diff] [blame] | 450 | } else if (alen != sizeof(*hw_info) + 1) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 451 | dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n", |
| 452 | serial->type->description, alen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | goto no_firmware; |
| 454 | } else if (result[0] != command[0]) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 455 | dev_err(&serial->dev->dev, "%s: Command failed [%d]\n", |
| 456 | serial->type->description, result[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | goto no_firmware; |
| 458 | } |
| 459 | |
| 460 | hw_info = (struct whiteheat_hw_info *)&result[1]; |
| 461 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 462 | dev_info(&serial->dev->dev, "%s: Driver %s: Firmware v%d.%02d\n", |
| 463 | serial->type->description, DRIVER_VERSION, |
| 464 | hw_info->sw_major_rev, hw_info->sw_minor_rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | for (i = 0; i < serial->num_ports; i++) { |
| 467 | port = serial->port[i]; |
| 468 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 469 | info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (info == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 471 | dev_err(&port->dev, |
| 472 | "%s: Out of memory for port structures\n", |
| 473 | serial->type->description); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | goto no_private; |
| 475 | } |
| 476 | |
| 477 | spin_lock_init(&info->lock); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 478 | mutex_init(&info->deathwarrant); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | info->flags = 0; |
| 480 | info->mcr = 0; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 481 | INIT_WORK(&info->rx_work, rx_data_softint); |
| 482 | info->port = port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | INIT_LIST_HEAD(&info->rx_urbs_free); |
| 485 | INIT_LIST_HEAD(&info->rx_urbs_submitted); |
| 486 | INIT_LIST_HEAD(&info->rx_urb_q); |
| 487 | INIT_LIST_HEAD(&info->tx_urbs_free); |
| 488 | INIT_LIST_HEAD(&info->tx_urbs_submitted); |
| 489 | |
| 490 | for (j = 0; j < urb_pool_size; j++) { |
| 491 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 492 | if (!urb) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 493 | dev_err(&port->dev, "No free urbs available\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | goto no_rx_urb; |
| 495 | } |
| 496 | buf_size = port->read_urb->transfer_buffer_length; |
| 497 | urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL); |
| 498 | if (!urb->transfer_buffer) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 499 | dev_err(&port->dev, |
| 500 | "Couldn't allocate urb buffer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | goto no_rx_buf; |
| 502 | } |
| 503 | wrap = kmalloc(sizeof(*wrap), GFP_KERNEL); |
| 504 | if (!wrap) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 505 | dev_err(&port->dev, |
| 506 | "Couldn't allocate urb wrapper\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | goto no_rx_wrap; |
| 508 | } |
| 509 | usb_fill_bulk_urb(urb, serial->dev, |
| 510 | usb_rcvbulkpipe(serial->dev, |
| 511 | port->bulk_in_endpointAddress), |
| 512 | urb->transfer_buffer, buf_size, |
| 513 | whiteheat_read_callback, port); |
| 514 | wrap->urb = urb; |
| 515 | list_add(&wrap->list, &info->rx_urbs_free); |
| 516 | |
| 517 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 518 | if (!urb) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 519 | dev_err(&port->dev, "No free urbs available\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | goto no_tx_urb; |
| 521 | } |
| 522 | buf_size = port->write_urb->transfer_buffer_length; |
| 523 | urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL); |
| 524 | if (!urb->transfer_buffer) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 525 | dev_err(&port->dev, |
| 526 | "Couldn't allocate urb buffer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | goto no_tx_buf; |
| 528 | } |
| 529 | wrap = kmalloc(sizeof(*wrap), GFP_KERNEL); |
| 530 | if (!wrap) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 531 | dev_err(&port->dev, |
| 532 | "Couldn't allocate urb wrapper\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | goto no_tx_wrap; |
| 534 | } |
| 535 | usb_fill_bulk_urb(urb, serial->dev, |
| 536 | usb_sndbulkpipe(serial->dev, |
| 537 | port->bulk_out_endpointAddress), |
| 538 | urb->transfer_buffer, buf_size, |
| 539 | whiteheat_write_callback, port); |
| 540 | wrap->urb = urb; |
| 541 | list_add(&wrap->list, &info->tx_urbs_free); |
| 542 | } |
| 543 | |
| 544 | usb_set_serial_port_data(port, info); |
| 545 | } |
| 546 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 547 | command_info = kmalloc(sizeof(struct whiteheat_command_private), |
| 548 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (command_info == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 550 | dev_err(&serial->dev->dev, |
| 551 | "%s: Out of memory for port structures\n", |
| 552 | serial->type->description); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | goto no_command_private; |
| 554 | } |
| 555 | |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 556 | mutex_init(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | command_info->port_running = 0; |
| 558 | init_waitqueue_head(&command_info->wait_command); |
| 559 | usb_set_serial_port_data(command_port, command_info); |
| 560 | command_port->write_urb->complete = command_port_write_callback; |
| 561 | command_port->read_urb->complete = command_port_read_callback; |
| 562 | kfree(result); |
| 563 | kfree(command); |
| 564 | |
| 565 | return 0; |
| 566 | |
| 567 | no_firmware: |
| 568 | /* Firmware likely not running */ |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 569 | dev_err(&serial->dev->dev, |
| 570 | "%s: Unable to retrieve firmware version, try replugging\n", |
| 571 | serial->type->description); |
| 572 | dev_err(&serial->dev->dev, |
| 573 | "%s: If the firmware is not running (status led not blinking)\n", |
| 574 | serial->type->description); |
| 575 | dev_err(&serial->dev->dev, |
| 576 | "%s: please contact support@connecttech.com\n", |
| 577 | serial->type->description); |
Jesper Juhl | 67ca0284 | 2006-04-23 19:59:23 +0200 | [diff] [blame] | 578 | kfree(result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | return -ENODEV; |
| 580 | |
| 581 | no_command_private: |
| 582 | for (i = serial->num_ports - 1; i >= 0; i--) { |
| 583 | port = serial->port[i]; |
| 584 | info = usb_get_serial_port_data(port); |
| 585 | for (j = urb_pool_size - 1; j >= 0; j--) { |
| 586 | tmp = list_first(&info->tx_urbs_free); |
| 587 | list_del(tmp); |
| 588 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 589 | urb = wrap->urb; |
| 590 | kfree(wrap); |
| 591 | no_tx_wrap: |
| 592 | kfree(urb->transfer_buffer); |
| 593 | no_tx_buf: |
| 594 | usb_free_urb(urb); |
| 595 | no_tx_urb: |
| 596 | tmp = list_first(&info->rx_urbs_free); |
| 597 | list_del(tmp); |
| 598 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 599 | urb = wrap->urb; |
| 600 | kfree(wrap); |
| 601 | no_rx_wrap: |
| 602 | kfree(urb->transfer_buffer); |
| 603 | no_rx_buf: |
| 604 | usb_free_urb(urb); |
| 605 | no_rx_urb: |
| 606 | ; |
| 607 | } |
| 608 | kfree(info); |
| 609 | no_private: |
| 610 | ; |
| 611 | } |
| 612 | kfree(result); |
| 613 | no_result_buffer: |
| 614 | kfree(command); |
| 615 | no_command_buffer: |
| 616 | return -ENOMEM; |
| 617 | } |
| 618 | |
| 619 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame^] | 620 | static void whiteheat_release(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { |
| 622 | struct usb_serial_port *command_port; |
| 623 | struct usb_serial_port *port; |
| 624 | struct whiteheat_private *info; |
| 625 | struct whiteheat_urb_wrap *wrap; |
| 626 | struct urb *urb; |
| 627 | struct list_head *tmp; |
| 628 | struct list_head *tmp2; |
| 629 | int i; |
| 630 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 631 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | /* free up our private data for our command port */ |
| 634 | command_port = serial->port[COMMAND_PORT]; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 635 | kfree(usb_get_serial_port_data(command_port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
| 637 | for (i = 0; i < serial->num_ports; i++) { |
| 638 | port = serial->port[i]; |
| 639 | info = usb_get_serial_port_data(port); |
| 640 | list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) { |
| 641 | list_del(tmp); |
| 642 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 643 | urb = wrap->urb; |
| 644 | kfree(wrap); |
| 645 | kfree(urb->transfer_buffer); |
| 646 | usb_free_urb(urb); |
| 647 | } |
| 648 | list_for_each_safe(tmp, tmp2, &info->tx_urbs_free) { |
| 649 | list_del(tmp); |
| 650 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 651 | urb = wrap->urb; |
| 652 | kfree(wrap); |
| 653 | kfree(urb->transfer_buffer); |
| 654 | usb_free_urb(urb); |
| 655 | } |
| 656 | kfree(info); |
| 657 | } |
| 658 | |
| 659 | return; |
| 660 | } |
| 661 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 662 | static int whiteheat_open(struct tty_struct *tty, |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 663 | struct usb_serial_port *port, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
| 665 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 667 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | retval = start_command_port(port->serial); |
| 670 | if (retval) |
| 671 | goto exit; |
| 672 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 673 | if (tty) |
| 674 | tty->low_latency = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
| 676 | /* send an open port command */ |
| 677 | retval = firm_open(port); |
| 678 | if (retval) { |
| 679 | stop_command_port(port->serial); |
| 680 | goto exit; |
| 681 | } |
| 682 | |
| 683 | retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX); |
| 684 | if (retval) { |
| 685 | firm_close(port); |
| 686 | stop_command_port(port->serial); |
| 687 | goto exit; |
| 688 | } |
| 689 | |
Alan Cox | 72e2741 | 2008-07-22 11:09:29 +0100 | [diff] [blame] | 690 | if (tty) |
| 691 | firm_setup_port(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | /* Work around HCD bugs */ |
| 694 | usb_clear_halt(port->serial->dev, port->read_urb->pipe); |
| 695 | usb_clear_halt(port->serial->dev, port->write_urb->pipe); |
| 696 | |
| 697 | /* Start reading from the device */ |
| 698 | retval = start_port_read(port); |
| 699 | if (retval) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 700 | dev_err(&port->dev, |
| 701 | "%s - failed submitting read urb, error %d\n", |
| 702 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | firm_close(port); |
| 704 | stop_command_port(port->serial); |
| 705 | goto exit; |
| 706 | } |
| 707 | |
| 708 | exit: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 709 | dbg("%s - exit, retval = %d", __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | return retval; |
| 711 | } |
| 712 | |
| 713 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 714 | static void whiteheat_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
| 716 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 717 | struct whiteheat_urb_wrap *wrap; |
| 718 | struct urb *urb; |
| 719 | struct list_head *tmp; |
| 720 | struct list_head *tmp2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 722 | dbg("%s - port %d", __func__, port->number); |
Oliver Neukum | e33fe4d | 2008-01-21 17:44:10 +0100 | [diff] [blame] | 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | firm_report_tx_done(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | firm_close(port); |
| 726 | |
| 727 | /* shutdown our bulk reads and writes */ |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 728 | mutex_lock(&info->deathwarrant); |
| 729 | spin_lock_irq(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) { |
| 731 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 732 | urb = wrap->urb; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 733 | list_del(tmp); |
| 734 | spin_unlock_irq(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | usb_kill_urb(urb); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 736 | spin_lock_irq(&info->lock); |
| 737 | list_add(tmp, &info->rx_urbs_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | } |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 739 | list_for_each_safe(tmp, tmp2, &info->rx_urb_q) |
| 740 | list_move(tmp, &info->rx_urbs_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | list_for_each_safe(tmp, tmp2, &info->tx_urbs_submitted) { |
| 742 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 743 | urb = wrap->urb; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 744 | list_del(tmp); |
| 745 | spin_unlock_irq(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | usb_kill_urb(urb); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 747 | spin_lock_irq(&info->lock); |
| 748 | list_add(tmp, &info->tx_urbs_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 750 | spin_unlock_irq(&info->lock); |
| 751 | mutex_unlock(&info->deathwarrant); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | stop_command_port(port->serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 756 | static int whiteheat_write(struct tty_struct *tty, |
| 757 | struct usb_serial_port *port, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
| 759 | struct usb_serial *serial = port->serial; |
| 760 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 761 | struct whiteheat_urb_wrap *wrap; |
| 762 | struct urb *urb; |
| 763 | int result; |
| 764 | int bytes; |
| 765 | int sent = 0; |
| 766 | unsigned long flags; |
| 767 | struct list_head *tmp; |
| 768 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 769 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
| 771 | if (count == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 772 | dbg("%s - write request of 0 bytes", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | return (0); |
| 774 | } |
| 775 | |
| 776 | while (count) { |
| 777 | spin_lock_irqsave(&info->lock, flags); |
| 778 | if (list_empty(&info->tx_urbs_free)) { |
| 779 | spin_unlock_irqrestore(&info->lock, flags); |
| 780 | break; |
| 781 | } |
| 782 | tmp = list_first(&info->tx_urbs_free); |
| 783 | list_del(tmp); |
| 784 | spin_unlock_irqrestore(&info->lock, flags); |
| 785 | |
| 786 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 787 | urb = wrap->urb; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 788 | bytes = (count > port->bulk_out_size) ? |
| 789 | port->bulk_out_size : count; |
| 790 | memcpy(urb->transfer_buffer, buf + sent, bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 792 | usb_serial_debug_data(debug, &port->dev, |
| 793 | __func__, bytes, urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | urb->dev = serial->dev; |
| 796 | urb->transfer_buffer_length = bytes; |
| 797 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 798 | if (result) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 799 | dev_err(&port->dev, |
| 800 | "%s - failed submitting write urb, error %d\n", |
| 801 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | sent = result; |
| 803 | spin_lock_irqsave(&info->lock, flags); |
| 804 | list_add(tmp, &info->tx_urbs_free); |
| 805 | spin_unlock_irqrestore(&info->lock, flags); |
| 806 | break; |
| 807 | } else { |
| 808 | sent += bytes; |
| 809 | count -= bytes; |
| 810 | spin_lock_irqsave(&info->lock, flags); |
| 811 | list_add(tmp, &info->tx_urbs_submitted); |
| 812 | spin_unlock_irqrestore(&info->lock, flags); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | return sent; |
| 817 | } |
| 818 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 819 | static int whiteheat_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 821 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 823 | struct list_head *tmp; |
| 824 | int room = 0; |
| 825 | unsigned long flags; |
| 826 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 827 | dbg("%s - port %d", __func__, port->number); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | spin_lock_irqsave(&info->lock, flags); |
| 830 | list_for_each(tmp, &info->tx_urbs_free) |
| 831 | room++; |
| 832 | spin_unlock_irqrestore(&info->lock, flags); |
| 833 | room *= port->bulk_out_size; |
| 834 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 835 | dbg("%s - returns %d", __func__, room); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | return (room); |
| 837 | } |
| 838 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 839 | static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 841 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 843 | unsigned int modem_signals = 0; |
| 844 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 845 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
| 847 | firm_get_dtr_rts(port); |
| 848 | if (info->mcr & UART_MCR_DTR) |
| 849 | modem_signals |= TIOCM_DTR; |
| 850 | if (info->mcr & UART_MCR_RTS) |
| 851 | modem_signals |= TIOCM_RTS; |
| 852 | |
| 853 | return modem_signals; |
| 854 | } |
| 855 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 856 | static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | unsigned int set, unsigned int clear) |
| 858 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 859 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 861 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 862 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | if (set & TIOCM_RTS) |
| 865 | info->mcr |= UART_MCR_RTS; |
| 866 | if (set & TIOCM_DTR) |
| 867 | info->mcr |= UART_MCR_DTR; |
| 868 | |
| 869 | if (clear & TIOCM_RTS) |
| 870 | info->mcr &= ~UART_MCR_RTS; |
| 871 | if (clear & TIOCM_DTR) |
| 872 | info->mcr &= ~UART_MCR_DTR; |
| 873 | |
| 874 | firm_set_dtr(port, info->mcr & UART_MCR_DTR); |
| 875 | firm_set_rts(port, info->mcr & UART_MCR_RTS); |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 880 | static int whiteheat_ioctl(struct tty_struct *tty, struct file *file, |
| 881 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 883 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | struct serial_struct serstruct; |
| 885 | void __user *user_arg = (void __user *)arg; |
| 886 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 887 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
| 889 | switch (cmd) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 890 | case TIOCGSERIAL: |
| 891 | memset(&serstruct, 0, sizeof(serstruct)); |
| 892 | serstruct.type = PORT_16654; |
| 893 | serstruct.line = port->serial->minor; |
| 894 | serstruct.port = port->number; |
| 895 | serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; |
| 896 | serstruct.xmit_fifo_size = port->bulk_out_size; |
| 897 | serstruct.custom_divisor = 0; |
| 898 | serstruct.baud_base = 460800; |
| 899 | serstruct.close_delay = CLOSING_DELAY; |
| 900 | serstruct.closing_wait = CLOSING_DELAY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 902 | if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) |
| 903 | return -EFAULT; |
| 904 | break; |
| 905 | default: |
| 906 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | return -ENOIOCTLCMD; |
| 910 | } |
| 911 | |
| 912 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 913 | static void whiteheat_set_termios(struct tty_struct *tty, |
| 914 | struct usb_serial_port *port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 916 | firm_setup_port(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 919 | static void whiteheat_break_ctl(struct tty_struct *tty, int break_state) |
| 920 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 921 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | firm_set_break(port, break_state); |
| 923 | } |
| 924 | |
| 925 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 926 | static int whiteheat_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 928 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 930 | struct list_head *tmp; |
| 931 | struct whiteheat_urb_wrap *wrap; |
| 932 | int chars = 0; |
| 933 | unsigned long flags; |
| 934 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 935 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
| 937 | spin_lock_irqsave(&info->lock, flags); |
| 938 | list_for_each(tmp, &info->tx_urbs_submitted) { |
| 939 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 940 | chars += wrap->urb->transfer_buffer_length; |
| 941 | } |
| 942 | spin_unlock_irqrestore(&info->lock, flags); |
| 943 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 944 | dbg("%s - returns %d", __func__, chars); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 945 | return chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 949 | static void whiteheat_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 951 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 953 | unsigned long flags; |
| 954 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 955 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | spin_lock_irqsave(&info->lock, flags); |
| 958 | info->flags |= THROTTLED; |
| 959 | spin_unlock_irqrestore(&info->lock, flags); |
| 960 | |
| 961 | return; |
| 962 | } |
| 963 | |
| 964 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 965 | static void whiteheat_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 967 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 969 | int actually_throttled; |
| 970 | unsigned long flags; |
| 971 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 972 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
| 974 | spin_lock_irqsave(&info->lock, flags); |
| 975 | actually_throttled = info->flags & ACTUALLY_THROTTLED; |
| 976 | info->flags &= ~(THROTTLED | ACTUALLY_THROTTLED); |
| 977 | spin_unlock_irqrestore(&info->lock, flags); |
| 978 | |
| 979 | if (actually_throttled) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 980 | rx_data_softint(&info->rx_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
| 982 | return; |
| 983 | } |
| 984 | |
| 985 | |
| 986 | /***************************************************************************** |
| 987 | * Connect Tech's White Heat callback routines |
| 988 | *****************************************************************************/ |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 989 | static void command_port_write_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 991 | int status = urb->status; |
| 992 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 993 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 995 | if (status) { |
| 996 | dbg("nonzero urb status: %d", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | return; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1002 | static void command_port_read_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1004 | struct usb_serial_port *command_port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | struct whiteheat_command_private *command_info; |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1006 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | unsigned char *data = urb->transfer_buffer; |
| 1008 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1010 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | command_info = usb_get_serial_port_data(command_port); |
| 1013 | if (!command_info) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1014 | dbg("%s - command_info is NULL, exiting.", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | return; |
| 1016 | } |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1017 | if (status) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1018 | dbg("%s - nonzero urb status: %d", __func__, status); |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1019 | if (status != -ENOENT) |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1020 | command_info->command_finished = WHITEHEAT_CMD_FAILURE; |
| 1021 | wake_up(&command_info->wait_command); |
| 1022 | return; |
| 1023 | } |
| 1024 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1025 | usb_serial_debug_data(debug, &command_port->dev, |
| 1026 | __func__, urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
| 1028 | if (data[0] == WHITEHEAT_CMD_COMPLETE) { |
| 1029 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1030 | wake_up(&command_info->wait_command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | } else if (data[0] == WHITEHEAT_CMD_FAILURE) { |
| 1032 | command_info->command_finished = WHITEHEAT_CMD_FAILURE; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1033 | wake_up(&command_info->wait_command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } else if (data[0] == WHITEHEAT_EVENT) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1035 | /* These are unsolicited reports from the firmware, hence no |
| 1036 | waiting command to wakeup */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1037 | dbg("%s - event received", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | } else if (data[0] == WHITEHEAT_GET_DTR_RTS) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1039 | memcpy(command_info->result_buffer, &data[1], |
| 1040 | urb->actual_length - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1042 | wake_up(&command_info->wait_command); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1043 | } else |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1044 | dbg("%s - bad reply from firmware", __func__); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | /* Continue trying to always read */ |
| 1047 | command_port->read_urb->dev = command_port->serial->dev; |
| 1048 | result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | if (result) |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1050 | dbg("%s - failed resubmitting read urb, error %d", |
| 1051 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1055 | static void whiteheat_read_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1057 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | struct whiteheat_urb_wrap *wrap; |
| 1059 | unsigned char *data = urb->transfer_buffer; |
| 1060 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1061 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1063 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | spin_lock(&info->lock); |
| 1066 | wrap = urb_to_wrap(urb, &info->rx_urbs_submitted); |
| 1067 | if (!wrap) { |
| 1068 | spin_unlock(&info->lock); |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1069 | dev_err(&port->dev, "%s - Not my urb!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | return; |
| 1071 | } |
| 1072 | list_del(&wrap->list); |
| 1073 | spin_unlock(&info->lock); |
| 1074 | |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1075 | if (status) { |
| 1076 | dbg("%s - nonzero read bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1077 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | spin_lock(&info->lock); |
| 1079 | list_add(&wrap->list, &info->rx_urbs_free); |
| 1080 | spin_unlock(&info->lock); |
| 1081 | return; |
| 1082 | } |
| 1083 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1084 | usb_serial_debug_data(debug, &port->dev, |
| 1085 | __func__, urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
| 1087 | spin_lock(&info->lock); |
| 1088 | list_add_tail(&wrap->list, &info->rx_urb_q); |
| 1089 | if (info->flags & THROTTLED) { |
| 1090 | info->flags |= ACTUALLY_THROTTLED; |
| 1091 | spin_unlock(&info->lock); |
| 1092 | return; |
| 1093 | } |
| 1094 | spin_unlock(&info->lock); |
| 1095 | |
| 1096 | schedule_work(&info->rx_work); |
| 1097 | } |
| 1098 | |
| 1099 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1100 | static void whiteheat_write_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1102 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 1104 | struct whiteheat_urb_wrap *wrap; |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1105 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1107 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
| 1109 | spin_lock(&info->lock); |
| 1110 | wrap = urb_to_wrap(urb, &info->tx_urbs_submitted); |
| 1111 | if (!wrap) { |
| 1112 | spin_unlock(&info->lock); |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1113 | dev_err(&port->dev, "%s - Not my urb!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | return; |
| 1115 | } |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 1116 | list_move(&wrap->list, &info->tx_urbs_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | spin_unlock(&info->lock); |
| 1118 | |
Greg Kroah-Hartman | 0540001 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1119 | if (status) { |
| 1120 | dbg("%s - nonzero write bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1121 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | return; |
| 1123 | } |
| 1124 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 1125 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | /***************************************************************************** |
| 1130 | * Connect Tech's White Heat firmware interface |
| 1131 | *****************************************************************************/ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1132 | static int firm_send_command(struct usb_serial_port *port, __u8 command, |
| 1133 | __u8 *data, __u8 datasize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | { |
| 1135 | struct usb_serial_port *command_port; |
| 1136 | struct whiteheat_command_private *command_info; |
| 1137 | struct whiteheat_private *info; |
| 1138 | __u8 *transfer_buffer; |
| 1139 | int retval = 0; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1140 | int t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1142 | dbg("%s - command %d", __func__, command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
| 1144 | command_port = port->serial->port[COMMAND_PORT]; |
| 1145 | command_info = usb_get_serial_port_data(command_port); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1146 | mutex_lock(&command_info->mutex); |
Richard Knutsson | 38c3cb5 | 2007-03-26 22:00:28 -0800 | [diff] [blame] | 1147 | command_info->command_finished = false; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; |
| 1150 | transfer_buffer[0] = command; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1151 | memcpy(&transfer_buffer[1], data, datasize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | command_port->write_urb->transfer_buffer_length = datasize + 1; |
| 1153 | command_port->write_urb->dev = port->serial->dev; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1154 | retval = usb_submit_urb(command_port->write_urb, GFP_NOIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | if (retval) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1156 | dbg("%s - submit urb failed", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | goto exit; |
| 1158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
| 1160 | /* wait for the command to complete */ |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1161 | t = wait_event_timeout(command_info->wait_command, |
Richard Knutsson | 38c3cb5 | 2007-03-26 22:00:28 -0800 | [diff] [blame] | 1162 | (bool)command_info->command_finished, COMMAND_TIMEOUT); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1163 | if (!t) |
| 1164 | usb_kill_urb(command_port->write_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
Richard Knutsson | 38c3cb5 | 2007-03-26 22:00:28 -0800 | [diff] [blame] | 1166 | if (command_info->command_finished == false) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1167 | dbg("%s - command timed out.", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | retval = -ETIMEDOUT; |
| 1169 | goto exit; |
| 1170 | } |
| 1171 | |
| 1172 | if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1173 | dbg("%s - command failed.", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | retval = -EIO; |
| 1175 | goto exit; |
| 1176 | } |
| 1177 | |
| 1178 | if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1179 | dbg("%s - command completed.", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | switch (command) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1181 | case WHITEHEAT_GET_DTR_RTS: |
| 1182 | info = usb_get_serial_port_data(port); |
| 1183 | memcpy(&info->mcr, command_info->result_buffer, |
| 1184 | sizeof(struct whiteheat_dr_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | break; |
| 1186 | } |
| 1187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | exit: |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1189 | mutex_unlock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | return retval; |
| 1191 | } |
| 1192 | |
| 1193 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1194 | static int firm_open(struct usb_serial_port *port) |
| 1195 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | struct whiteheat_simple open_command; |
| 1197 | |
| 1198 | open_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1199 | return firm_send_command(port, WHITEHEAT_OPEN, |
| 1200 | (__u8 *)&open_command, sizeof(open_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1204 | static int firm_close(struct usb_serial_port *port) |
| 1205 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | struct whiteheat_simple close_command; |
| 1207 | |
| 1208 | close_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1209 | return firm_send_command(port, WHITEHEAT_CLOSE, |
| 1210 | (__u8 *)&close_command, sizeof(close_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1214 | static int firm_setup_port(struct tty_struct *tty) |
| 1215 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1216 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | struct whiteheat_port_settings port_settings; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1218 | unsigned int cflag = tty->termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
| 1220 | port_settings.port = port->number + 1; |
| 1221 | |
| 1222 | /* get the byte size */ |
| 1223 | switch (cflag & CSIZE) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1224 | case CS5: port_settings.bits = 5; break; |
| 1225 | case CS6: port_settings.bits = 6; break; |
| 1226 | case CS7: port_settings.bits = 7; break; |
| 1227 | default: |
| 1228 | case CS8: port_settings.bits = 8; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1230 | dbg("%s - data bits = %d", __func__, port_settings.bits); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | /* determine the parity */ |
| 1233 | if (cflag & PARENB) |
| 1234 | if (cflag & CMSPAR) |
| 1235 | if (cflag & PARODD) |
| 1236 | port_settings.parity = WHITEHEAT_PAR_MARK; |
| 1237 | else |
| 1238 | port_settings.parity = WHITEHEAT_PAR_SPACE; |
| 1239 | else |
| 1240 | if (cflag & PARODD) |
| 1241 | port_settings.parity = WHITEHEAT_PAR_ODD; |
| 1242 | else |
| 1243 | port_settings.parity = WHITEHEAT_PAR_EVEN; |
| 1244 | else |
| 1245 | port_settings.parity = WHITEHEAT_PAR_NONE; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1246 | dbg("%s - parity = %c", __func__, port_settings.parity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* figure out the stop bits requested */ |
| 1249 | if (cflag & CSTOPB) |
| 1250 | port_settings.stop = 2; |
| 1251 | else |
| 1252 | port_settings.stop = 1; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1253 | dbg("%s - stop bits = %d", __func__, port_settings.stop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
| 1255 | /* figure out the flow control settings */ |
| 1256 | if (cflag & CRTSCTS) |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1257 | port_settings.hflow = (WHITEHEAT_HFLOW_CTS | |
| 1258 | WHITEHEAT_HFLOW_RTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | else |
| 1260 | port_settings.hflow = WHITEHEAT_HFLOW_NONE; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1261 | dbg("%s - hardware flow control = %s %s %s %s", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "", |
| 1263 | (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "", |
| 1264 | (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "", |
| 1265 | (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : ""); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | /* determine software flow control */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1268 | if (I_IXOFF(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | port_settings.sflow = WHITEHEAT_SFLOW_RXTX; |
| 1270 | else |
| 1271 | port_settings.sflow = WHITEHEAT_SFLOW_NONE; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1272 | dbg("%s - software flow control = %c", __func__, port_settings.sflow); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1273 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1274 | port_settings.xon = START_CHAR(tty); |
| 1275 | port_settings.xoff = STOP_CHAR(tty); |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1276 | dbg("%s - XON = %2x, XOFF = %2x", |
| 1277 | __func__, port_settings.xon, port_settings.xoff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
| 1279 | /* get the baud rate wanted */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1280 | port_settings.baud = tty_get_baud_rate(tty); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1281 | dbg("%s - baud rate = %d", __func__, port_settings.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | |
Alan Cox | 01d1df2 | 2007-10-18 01:24:23 -0700 | [diff] [blame] | 1283 | /* fixme: should set validated settings */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1284 | tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | /* handle any settings that aren't specified in the tty structure */ |
| 1286 | port_settings.lloop = 0; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | /* now send the message to the device */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1289 | return firm_send_command(port, WHITEHEAT_SETUP_PORT, |
| 1290 | (__u8 *)&port_settings, sizeof(port_settings)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1294 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff) |
| 1295 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | struct whiteheat_set_rdb rts_command; |
| 1297 | |
| 1298 | rts_command.port = port->number - port->serial->minor + 1; |
| 1299 | rts_command.state = onoff; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1300 | return firm_send_command(port, WHITEHEAT_SET_RTS, |
| 1301 | (__u8 *)&rts_command, sizeof(rts_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1305 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff) |
| 1306 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | struct whiteheat_set_rdb dtr_command; |
| 1308 | |
| 1309 | dtr_command.port = port->number - port->serial->minor + 1; |
| 1310 | dtr_command.state = onoff; |
Alan Cox | 72e2741 | 2008-07-22 11:09:29 +0100 | [diff] [blame] | 1311 | return firm_send_command(port, WHITEHEAT_SET_DTR, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1312 | (__u8 *)&dtr_command, sizeof(dtr_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1316 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff) |
| 1317 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | struct whiteheat_set_rdb break_command; |
| 1319 | |
| 1320 | break_command.port = port->number - port->serial->minor + 1; |
| 1321 | break_command.state = onoff; |
Alan Cox | 72e2741 | 2008-07-22 11:09:29 +0100 | [diff] [blame] | 1322 | return firm_send_command(port, WHITEHEAT_SET_BREAK, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1323 | (__u8 *)&break_command, sizeof(break_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1327 | static int firm_purge(struct usb_serial_port *port, __u8 rxtx) |
| 1328 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | struct whiteheat_purge purge_command; |
| 1330 | |
| 1331 | purge_command.port = port->number - port->serial->minor + 1; |
| 1332 | purge_command.what = rxtx; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1333 | return firm_send_command(port, WHITEHEAT_PURGE, |
| 1334 | (__u8 *)&purge_command, sizeof(purge_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1338 | static int firm_get_dtr_rts(struct usb_serial_port *port) |
| 1339 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | struct whiteheat_simple get_dr_command; |
| 1341 | |
| 1342 | get_dr_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1343 | return firm_send_command(port, WHITEHEAT_GET_DTR_RTS, |
| 1344 | (__u8 *)&get_dr_command, sizeof(get_dr_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1348 | static int firm_report_tx_done(struct usb_serial_port *port) |
| 1349 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | struct whiteheat_simple close_command; |
| 1351 | |
| 1352 | close_command.port = port->number - port->serial->minor + 1; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1353 | return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE, |
| 1354 | (__u8 *)&close_command, sizeof(close_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | |
| 1358 | /***************************************************************************** |
| 1359 | * Connect Tech's White Heat utility functions |
| 1360 | *****************************************************************************/ |
| 1361 | static int start_command_port(struct usb_serial *serial) |
| 1362 | { |
| 1363 | struct usb_serial_port *command_port; |
| 1364 | struct whiteheat_command_private *command_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | int retval = 0; |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | command_port = serial->port[COMMAND_PORT]; |
| 1368 | command_info = usb_get_serial_port_data(command_port); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1369 | mutex_lock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | if (!command_info->port_running) { |
| 1371 | /* Work around HCD bugs */ |
| 1372 | usb_clear_halt(serial->dev, command_port->read_urb->pipe); |
| 1373 | |
| 1374 | command_port->read_urb->dev = serial->dev; |
| 1375 | retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL); |
| 1376 | if (retval) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1377 | dev_err(&serial->dev->dev, |
| 1378 | "%s - failed submitting read urb, error %d\n", |
| 1379 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | goto exit; |
| 1381 | } |
| 1382 | } |
| 1383 | command_info->port_running++; |
| 1384 | |
| 1385 | exit: |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1386 | mutex_unlock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | return retval; |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | static void stop_command_port(struct usb_serial *serial) |
| 1392 | { |
| 1393 | struct usb_serial_port *command_port; |
| 1394 | struct whiteheat_command_private *command_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
| 1396 | command_port = serial->port[COMMAND_PORT]; |
| 1397 | command_info = usb_get_serial_port_data(command_port); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1398 | mutex_lock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | command_info->port_running--; |
| 1400 | if (!command_info->port_running) |
| 1401 | usb_kill_urb(command_port->read_urb); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1402 | mutex_unlock(&command_info->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | |
| 1406 | static int start_port_read(struct usb_serial_port *port) |
| 1407 | { |
| 1408 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
| 1409 | struct whiteheat_urb_wrap *wrap; |
| 1410 | struct urb *urb; |
| 1411 | int retval = 0; |
| 1412 | unsigned long flags; |
| 1413 | struct list_head *tmp; |
| 1414 | struct list_head *tmp2; |
| 1415 | |
| 1416 | spin_lock_irqsave(&info->lock, flags); |
| 1417 | |
| 1418 | list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) { |
| 1419 | list_del(tmp); |
| 1420 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 1421 | urb = wrap->urb; |
| 1422 | urb->dev = port->serial->dev; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1423 | spin_unlock_irqrestore(&info->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | retval = usb_submit_urb(urb, GFP_KERNEL); |
| 1425 | if (retval) { |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1426 | spin_lock_irqsave(&info->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | list_add(tmp, &info->rx_urbs_free); |
| 1428 | list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) { |
| 1429 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 1430 | urb = wrap->urb; |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1431 | list_del(tmp); |
| 1432 | spin_unlock_irqrestore(&info->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | usb_kill_urb(urb); |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1434 | spin_lock_irqsave(&info->lock, flags); |
| 1435 | list_add(tmp, &info->rx_urbs_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | } |
| 1437 | break; |
| 1438 | } |
Oliver Neukum | 08a2b3b | 2007-05-24 13:52:51 +0200 | [diff] [blame] | 1439 | spin_lock_irqsave(&info->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | list_add(tmp, &info->rx_urbs_submitted); |
| 1441 | } |
| 1442 | |
| 1443 | spin_unlock_irqrestore(&info->lock, flags); |
| 1444 | |
| 1445 | return retval; |
| 1446 | } |
| 1447 | |
| 1448 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1449 | static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, |
| 1450 | struct list_head *head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | { |
| 1452 | struct whiteheat_urb_wrap *wrap; |
| 1453 | struct list_head *tmp; |
| 1454 | |
| 1455 | list_for_each(tmp, head) { |
| 1456 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 1457 | if (wrap->urb == urb) |
| 1458 | return wrap; |
| 1459 | } |
| 1460 | |
| 1461 | return NULL; |
| 1462 | } |
| 1463 | |
| 1464 | |
| 1465 | static struct list_head *list_first(struct list_head *head) |
| 1466 | { |
| 1467 | return head->next; |
| 1468 | } |
| 1469 | |
| 1470 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1471 | static void rx_data_softint(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1473 | struct whiteheat_private *info = |
| 1474 | container_of(work, struct whiteheat_private, rx_work); |
| 1475 | struct usb_serial_port *port = info->port; |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1476 | struct tty_struct *tty = tty_port_tty_get(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | struct whiteheat_urb_wrap *wrap; |
| 1478 | struct urb *urb; |
| 1479 | unsigned long flags; |
| 1480 | struct list_head *tmp; |
| 1481 | struct list_head *tmp2; |
| 1482 | int result; |
| 1483 | int sent = 0; |
| 1484 | |
| 1485 | spin_lock_irqsave(&info->lock, flags); |
| 1486 | if (info->flags & THROTTLED) { |
| 1487 | spin_unlock_irqrestore(&info->lock, flags); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1488 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | list_for_each_safe(tmp, tmp2, &info->rx_urb_q) { |
| 1492 | list_del(tmp); |
| 1493 | spin_unlock_irqrestore(&info->lock, flags); |
| 1494 | |
| 1495 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
| 1496 | urb = wrap->urb; |
| 1497 | |
| 1498 | if (tty && urb->actual_length) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1499 | int len = tty_buffer_request_room(tty, |
| 1500 | urb->actual_length); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1501 | /* This stuff can go away now I suspect */ |
| 1502 | if (unlikely(len < urb->actual_length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | spin_lock_irqsave(&info->lock, flags); |
| 1504 | list_add(tmp, &info->rx_urb_q); |
| 1505 | spin_unlock_irqrestore(&info->lock, flags); |
| 1506 | tty_flip_buffer_push(tty); |
| 1507 | schedule_work(&info->rx_work); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1508 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | } |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1510 | tty_insert_flip_string(tty, urb->transfer_buffer, len); |
| 1511 | sent += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | urb->dev = port->serial->dev; |
| 1515 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 1516 | if (result) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1517 | dev_err(&port->dev, |
| 1518 | "%s - failed resubmitting read urb, error %d\n", |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1519 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | spin_lock_irqsave(&info->lock, flags); |
| 1521 | list_add(tmp, &info->rx_urbs_free); |
| 1522 | continue; |
| 1523 | } |
| 1524 | |
| 1525 | spin_lock_irqsave(&info->lock, flags); |
| 1526 | list_add(tmp, &info->rx_urbs_submitted); |
| 1527 | } |
| 1528 | spin_unlock_irqrestore(&info->lock, flags); |
| 1529 | |
| 1530 | if (sent) |
| 1531 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1532 | out: |
| 1533 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | |
| 1537 | /***************************************************************************** |
| 1538 | * Connect Tech's White Heat module functions |
| 1539 | *****************************************************************************/ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1540 | static int __init whiteheat_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | { |
| 1542 | int retval; |
| 1543 | retval = usb_serial_register(&whiteheat_fake_device); |
| 1544 | if (retval) |
| 1545 | goto failed_fake_register; |
| 1546 | retval = usb_serial_register(&whiteheat_device); |
| 1547 | if (retval) |
| 1548 | goto failed_device_register; |
| 1549 | retval = usb_register(&whiteheat_driver); |
| 1550 | if (retval) |
| 1551 | goto failed_usb_register; |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 1552 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 1553 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | return 0; |
| 1555 | failed_usb_register: |
| 1556 | usb_serial_deregister(&whiteheat_device); |
| 1557 | failed_device_register: |
| 1558 | usb_serial_deregister(&whiteheat_fake_device); |
| 1559 | failed_fake_register: |
| 1560 | return retval; |
| 1561 | } |
| 1562 | |
| 1563 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1564 | static void __exit whiteheat_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1566 | usb_deregister(&whiteheat_driver); |
| 1567 | usb_serial_deregister(&whiteheat_fake_device); |
| 1568 | usb_serial_deregister(&whiteheat_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | module_init(whiteheat_init); |
| 1573 | module_exit(whiteheat_exit); |
| 1574 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 1575 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1576 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | MODULE_LICENSE("GPL"); |
| 1578 | |
David Woodhouse | ec6752f | 2008-05-31 01:35:29 +0300 | [diff] [blame] | 1579 | MODULE_FIRMWARE("whiteheat.fw"); |
| 1580 | MODULE_FIRMWARE("whiteheat_loader.fw"); |
| 1581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | module_param(urb_pool_size, int, 0); |
| 1583 | MODULE_PARM_DESC(urb_pool_size, "Number of urbs to use for buffering"); |
| 1584 | |
| 1585 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 1586 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |