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