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