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