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