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