blob: efa32bf5f7587f49d478eb7daec89a535f278357 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Cox80359a92008-07-22 11:09:16 +010015 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#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 Neukum08a2b3b2007-05-24 13:52:51 +020028#include <linux/mutex.h>
Alan Cox80359a92008-07-22 11:09:16 +010029#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/termbits.h>
31#include <linux/usb.h>
32#include <linux/serial_reg.h>
33#include <linux/serial.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070034#include <linux/usb/serial.h>
Rene Buergelcc183e22012-09-18 09:00:41 +020035#include <linux/usb/ezusb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "whiteheat.h" /* WhiteHEAT specific commands */
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#ifndef CMSPAR
39#define CMSPAR 0
40#endif
41
42/*
43 * Version Information
44 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
46#define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
47
48#define CONNECT_TECH_VENDOR_ID 0x0710
49#define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
50#define CONNECT_TECH_WHITE_HEAT_ID 0x8001
51
52/*
53 ID tables for whiteheat are unusual, because we want to different
54 things for different versions of the device. Eventually, this
55 will be doable from a single table. But, for now, we define two
56 separate ID tables, and then a third table that combines them
57 just for the purpose of exporting the autoloading information.
58*/
Németh Márton7d40d7e2010-01-10 15:34:24 +010059static const struct usb_device_id id_table_std[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
61 { } /* Terminating entry */
62};
63
Németh Márton7d40d7e2010-01-10 15:34:24 +010064static const struct usb_device_id id_table_prerenumeration[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
66 { } /* Terminating entry */
67};
68
Németh Márton7d40d7e2010-01-10 15:34:24 +010069static const struct usb_device_id id_table_combined[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
71 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
72 { } /* Terminating entry */
73};
74
Alan Cox80359a92008-07-22 11:09:16 +010075MODULE_DEVICE_TABLE(usb, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
Alan Cox80359a92008-07-22 11:09:16 +010079static int whiteheat_firmware_download(struct usb_serial *serial,
80 const struct usb_device_id *id);
81static int whiteheat_firmware_attach(struct usb_serial *serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/* function prototypes for the Connect Tech WhiteHEAT serial converter */
Alan Cox80359a92008-07-22 11:09:16 +010084static int whiteheat_attach(struct usb_serial *serial);
Alan Sternf9c99bb2009-06-02 11:53:55 -040085static void whiteheat_release(struct usb_serial *serial);
Alan Cox80359a92008-07-22 11:09:16 +010086static int whiteheat_open(struct tty_struct *tty,
Alan Coxa509a7e2009-09-19 13:13:26 -070087 struct usb_serial_port *port);
Alan Cox335f8512009-06-11 12:26:29 +010088static void whiteheat_close(struct usb_serial_port *port);
Alan Cox00a0d0d2011-02-14 16:27:06 +000089static int whiteheat_ioctl(struct tty_struct *tty,
Alan Cox80359a92008-07-22 11:09:16 +010090 unsigned int cmd, unsigned long arg);
91static void whiteheat_set_termios(struct tty_struct *tty,
92 struct usb_serial_port *port, struct ktermios *old);
Alan Cox60b33c12011-02-14 16:26:14 +000093static int whiteheat_tiocmget(struct tty_struct *tty);
Alan Cox20b9d172011-02-14 16:26:50 +000094static int whiteheat_tiocmset(struct tty_struct *tty,
Alan Cox80359a92008-07-22 11:09:16 +010095 unsigned int set, unsigned int clear);
96static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -070098static struct usb_serial_driver whiteheat_fake_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -070099 .driver = {
100 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700101 .name = "whiteheatnofirm",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700102 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700103 .description = "Connect Tech - WhiteHEAT - (prerenumeration)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 .id_table = id_table_prerenumeration,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .num_ports = 1,
106 .probe = whiteheat_firmware_download,
107 .attach = whiteheat_firmware_attach,
108};
109
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700110static struct usb_serial_driver whiteheat_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700111 .driver = {
112 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700113 .name = "whiteheat",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700114 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700115 .description = "Connect Tech - WhiteHEAT",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .id_table = id_table_std,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .num_ports = 4,
118 .attach = whiteheat_attach,
Alan Sternf9c99bb2009-06-02 11:53:55 -0400119 .release = whiteheat_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .open = whiteheat_open,
121 .close = whiteheat_close,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .ioctl = whiteheat_ioctl,
123 .set_termios = whiteheat_set_termios,
124 .break_ctl = whiteheat_break_ctl,
125 .tiocmget = whiteheat_tiocmget,
126 .tiocmset = whiteheat_tiocmset,
Johan Hovold5c0c7582012-03-22 16:50:55 +0100127 .throttle = usb_serial_generic_throttle,
128 .unthrottle = usb_serial_generic_unthrottle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
Alan Stern29618e92012-02-23 14:57:32 -0500131static struct usb_serial_driver * const serial_drivers[] = {
132 &whiteheat_fake_device, &whiteheat_device, NULL
133};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135struct whiteheat_command_private {
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200136 struct mutex mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 __u8 port_running;
138 __u8 command_finished;
Alan Cox80359a92008-07-22 11:09:16 +0100139 wait_queue_head_t wait_command; /* for handling sleeping whilst
140 waiting for a command to
141 finish */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 __u8 result_buffer[64];
143};
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145struct whiteheat_private {
Alan Coxa5b6f602008-04-08 17:16:06 +0100146 __u8 mcr; /* FIXME: no locking on mcr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149
150/* local function prototypes */
151static int start_command_port(struct usb_serial *serial);
152static void stop_command_port(struct usb_serial *serial);
David Howells7d12e782006-10-05 14:55:46 +0100153static void command_port_write_callback(struct urb *urb);
154static void command_port_read_callback(struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Alan Cox80359a92008-07-22 11:09:16 +0100156static int firm_send_command(struct usb_serial_port *port, __u8 command,
157 __u8 *data, __u8 datasize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158static int firm_open(struct usb_serial_port *port);
159static int firm_close(struct usb_serial_port *port);
Alan Coxfe1ae7f2009-09-19 13:13:33 -0700160static void firm_setup_port(struct tty_struct *tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
162static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
163static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
164static int firm_purge(struct usb_serial_port *port, __u8 rxtx);
165static int firm_get_dtr_rts(struct usb_serial_port *port);
166static int firm_report_tx_done(struct usb_serial_port *port);
167
168
169#define COMMAND_PORT 4
170#define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */
171#define COMMAND_TIMEOUT_MS 2000
172#define CLOSING_DELAY (30 * HZ)
173
174
175/*****************************************************************************
176 * Connect Tech's White Heat prerenumeration driver functions
177 *****************************************************************************/
178
179/* steps to download the firmware to the WhiteHEAT device:
180 - hold the reset (by writing to the reset bit of the CPUCS register)
181 - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
182 - release the reset (by writing to the CPUCS register)
183 - download the WH.HEX file for all addresses greater than 0x1b3f using
184 VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
185 - hold the reset
186 - download the WH.HEX file for all addresses less than 0x1b40 using
187 VENDOR_REQUEST_ANCHOR_LOAD
188 - release the reset
189 - device renumerated itself and comes up as new device id with all
190 firmware download completed.
191*/
Alan Cox80359a92008-07-22 11:09:16 +0100192static int whiteheat_firmware_download(struct usb_serial *serial,
193 const struct usb_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Rene Buergel8d733e22012-09-18 09:02:01 +0200195 int response;
David Woodhouseec6752f2008-05-31 01:35:29 +0300196
Rene Buergel8d733e22012-09-18 09:02:01 +0200197 response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat_loader.fw");
198 if (response >= 0) {
199 response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat.fw");
200 if (response >= 0)
201 return 0;
David Woodhouseec6752f2008-05-31 01:35:29 +0300202 }
Rene Buergel8d733e22012-09-18 09:02:01 +0200203 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
206
Alan Cox80359a92008-07-22 11:09:16 +0100207static int whiteheat_firmware_attach(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
209 /* We want this device to fail to have a driver assigned to it */
210 return 1;
211}
212
213
214/*****************************************************************************
215 * Connect Tech's White Heat serial driver functions
216 *****************************************************************************/
Alan Cox80359a92008-07-22 11:09:16 +0100217static int whiteheat_attach(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 struct usb_serial_port *command_port;
220 struct whiteheat_command_private *command_info;
221 struct usb_serial_port *port;
222 struct whiteheat_private *info;
223 struct whiteheat_hw_info *hw_info;
224 int pipe;
225 int ret;
226 int alen;
227 __u8 *command;
228 __u8 *result;
229 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 command_port = serial->port[COMMAND_PORT];
232
Alan Cox80359a92008-07-22 11:09:16 +0100233 pipe = usb_sndbulkpipe(serial->dev,
234 command_port->bulk_out_endpointAddress);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 command = kmalloc(2, GFP_KERNEL);
236 if (!command)
237 goto no_command_buffer;
238 command[0] = WHITEHEAT_GET_HW_INFO;
239 command[1] = 0;
Alan Cox80359a92008-07-22 11:09:16 +0100240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
242 if (!result)
243 goto no_result_buffer;
244 /*
245 * When the module is reloaded the firmware is still there and
246 * the endpoints are still in the usb core unchanged. This is the
Alan Cox80359a92008-07-22 11:09:16 +0100247 * unlinking bug in disguise. Same for the call below.
248 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 usb_clear_halt(serial->dev, pipe);
Alan Cox80359a92008-07-22 11:09:16 +0100250 ret = usb_bulk_msg(serial->dev, pipe, command, 2,
251 &alen, COMMAND_TIMEOUT_MS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 if (ret) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700253 dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
254 serial->type->description, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 goto no_firmware;
Stuart MacDonald09fd6bc2006-05-31 13:28:40 -0400256 } else if (alen != 2) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700257 dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
258 serial->type->description, alen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 goto no_firmware;
260 }
261
Alan Cox80359a92008-07-22 11:09:16 +0100262 pipe = usb_rcvbulkpipe(serial->dev,
263 command_port->bulk_in_endpointAddress);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /* See the comment on the usb_clear_halt() above */
265 usb_clear_halt(serial->dev, pipe);
Alan Cox80359a92008-07-22 11:09:16 +0100266 ret = usb_bulk_msg(serial->dev, pipe, result,
267 sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if (ret) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700269 dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
270 serial->type->description, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 goto no_firmware;
Stuart MacDonald09fd6bc2006-05-31 13:28:40 -0400272 } else if (alen != sizeof(*hw_info) + 1) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700273 dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n",
274 serial->type->description, alen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 goto no_firmware;
276 } else if (result[0] != command[0]) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700277 dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
278 serial->type->description, result[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 goto no_firmware;
280 }
281
282 hw_info = (struct whiteheat_hw_info *)&result[1];
283
Johan Hovolda6765cb2012-03-22 16:50:54 +0100284 dev_info(&serial->dev->dev, "%s: Firmware v%d.%02d\n",
285 serial->type->description,
Greg Kroah-Hartmanc197a8d2008-08-18 13:21:04 -0700286 hw_info->sw_major_rev, hw_info->sw_minor_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 for (i = 0; i < serial->num_ports; i++) {
289 port = serial->port[i];
290
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800291 info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 if (info == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700293 dev_err(&port->dev,
294 "%s: Out of memory for port structures\n",
295 serial->type->description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 goto no_private;
297 }
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 info->mcr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 usb_set_serial_port_data(port, info);
302 }
303
Alan Cox80359a92008-07-22 11:09:16 +0100304 command_info = kmalloc(sizeof(struct whiteheat_command_private),
305 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (command_info == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700307 dev_err(&serial->dev->dev,
308 "%s: Out of memory for port structures\n",
309 serial->type->description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 goto no_command_private;
311 }
312
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200313 mutex_init(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 command_info->port_running = 0;
315 init_waitqueue_head(&command_info->wait_command);
316 usb_set_serial_port_data(command_port, command_info);
317 command_port->write_urb->complete = command_port_write_callback;
318 command_port->read_urb->complete = command_port_read_callback;
319 kfree(result);
320 kfree(command);
321
322 return 0;
323
324no_firmware:
325 /* Firmware likely not running */
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700326 dev_err(&serial->dev->dev,
327 "%s: Unable to retrieve firmware version, try replugging\n",
328 serial->type->description);
329 dev_err(&serial->dev->dev,
330 "%s: If the firmware is not running (status led not blinking)\n",
331 serial->type->description);
332 dev_err(&serial->dev->dev,
333 "%s: please contact support@connecttech.com\n",
334 serial->type->description);
Jesper Juhl67ca0282006-04-23 19:59:23 +0200335 kfree(result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return -ENODEV;
337
338no_command_private:
339 for (i = serial->num_ports - 1; i >= 0; i--) {
340 port = serial->port[i];
341 info = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 kfree(info);
343no_private:
344 ;
345 }
346 kfree(result);
347no_result_buffer:
348 kfree(command);
349no_command_buffer:
350 return -ENOMEM;
351}
352
353
Alan Sternf9c99bb2009-06-02 11:53:55 -0400354static void whiteheat_release(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 struct usb_serial_port *command_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 struct whiteheat_private *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 int i;
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 /* free up our private data for our command port */
361 command_port = serial->port[COMMAND_PORT];
Alan Cox80359a92008-07-22 11:09:16 +0100362 kfree(usb_get_serial_port_data(command_port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 for (i = 0; i < serial->num_ports; i++) {
Johan Hovold5c0c7582012-03-22 16:50:55 +0100365 info = usb_get_serial_port_data(serial->port[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 kfree(info);
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
Alan Coxa509a7e2009-09-19 13:13:26 -0700370static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Johan Hovold5c0c7582012-03-22 16:50:55 +0100372 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 retval = start_command_port(port->serial);
375 if (retval)
376 goto exit;
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 /* send an open port command */
379 retval = firm_open(port);
380 if (retval) {
381 stop_command_port(port->serial);
382 goto exit;
383 }
384
385 retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
386 if (retval) {
387 firm_close(port);
388 stop_command_port(port->serial);
389 goto exit;
390 }
391
Alan Cox72e27412008-07-22 11:09:29 +0100392 if (tty)
393 firm_setup_port(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 /* Work around HCD bugs */
396 usb_clear_halt(port->serial->dev, port->read_urb->pipe);
397 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
398
Johan Hovold5c0c7582012-03-22 16:50:55 +0100399 retval = usb_serial_generic_open(tty, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 firm_close(port);
402 stop_command_port(port->serial);
403 goto exit;
404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return retval;
407}
408
409
Alan Cox335f8512009-06-11 12:26:29 +0100410static void whiteheat_close(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 firm_report_tx_done(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 firm_close(port);
414
Johan Hovold5c0c7582012-03-22 16:50:55 +0100415 usb_serial_generic_close(port);
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 stop_command_port(port->serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Alan Cox60b33c12011-02-14 16:26:14 +0000420static int whiteheat_tiocmget(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Alan Cox95da3102008-07-22 11:09:07 +0100422 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 struct whiteheat_private *info = usb_get_serial_port_data(port);
424 unsigned int modem_signals = 0;
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 firm_get_dtr_rts(port);
427 if (info->mcr & UART_MCR_DTR)
428 modem_signals |= TIOCM_DTR;
429 if (info->mcr & UART_MCR_RTS)
430 modem_signals |= TIOCM_RTS;
431
432 return modem_signals;
433}
434
Alan Cox20b9d172011-02-14 16:26:50 +0000435static int whiteheat_tiocmset(struct tty_struct *tty,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 unsigned int set, unsigned int clear)
437{
Alan Cox95da3102008-07-22 11:09:07 +0100438 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 struct whiteheat_private *info = usb_get_serial_port_data(port);
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (set & TIOCM_RTS)
442 info->mcr |= UART_MCR_RTS;
443 if (set & TIOCM_DTR)
444 info->mcr |= UART_MCR_DTR;
445
446 if (clear & TIOCM_RTS)
447 info->mcr &= ~UART_MCR_RTS;
448 if (clear & TIOCM_DTR)
449 info->mcr &= ~UART_MCR_DTR;
450
451 firm_set_dtr(port, info->mcr & UART_MCR_DTR);
452 firm_set_rts(port, info->mcr & UART_MCR_RTS);
453 return 0;
454}
455
456
Alan Cox00a0d0d2011-02-14 16:27:06 +0000457static int whiteheat_ioctl(struct tty_struct *tty,
Alan Cox80359a92008-07-22 11:09:16 +0100458 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Alan Cox95da3102008-07-22 11:09:07 +0100460 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 struct serial_struct serstruct;
462 void __user *user_arg = (void __user *)arg;
463
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700464 dev_dbg(&port->dev, "%s - cmd 0x%.4x\n", __func__, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 switch (cmd) {
Alan Cox80359a92008-07-22 11:09:16 +0100467 case TIOCGSERIAL:
468 memset(&serstruct, 0, sizeof(serstruct));
469 serstruct.type = PORT_16654;
470 serstruct.line = port->serial->minor;
471 serstruct.port = port->number;
472 serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Johan Hovold5c0c7582012-03-22 16:50:55 +0100473 serstruct.xmit_fifo_size = kfifo_size(&port->write_fifo);
Alan Cox80359a92008-07-22 11:09:16 +0100474 serstruct.custom_divisor = 0;
475 serstruct.baud_base = 460800;
476 serstruct.close_delay = CLOSING_DELAY;
477 serstruct.closing_wait = CLOSING_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Alan Cox80359a92008-07-22 11:09:16 +0100479 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
480 return -EFAULT;
481 break;
482 default:
483 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485
486 return -ENOIOCTLCMD;
487}
488
489
Alan Cox80359a92008-07-22 11:09:16 +0100490static void whiteheat_set_termios(struct tty_struct *tty,
491 struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Alan Cox95da3102008-07-22 11:09:07 +0100493 firm_setup_port(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
Alan Cox80359a92008-07-22 11:09:16 +0100496static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
497{
Alan Cox95da3102008-07-22 11:09:07 +0100498 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 firm_set_break(port, break_state);
500}
501
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503/*****************************************************************************
504 * Connect Tech's White Heat callback routines
505 *****************************************************************************/
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200506static void command_port_write_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700508 int status = urb->status;
509
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700510 if (status) {
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700511 dev_dbg(&urb->dev->dev, "nonzero urb status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 return;
513 }
514}
515
516
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200517static void command_port_read_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Ming Leicdc97792008-02-24 18:41:47 +0800519 struct usb_serial_port *command_port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 struct whiteheat_command_private *command_info;
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700521 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 unsigned char *data = urb->transfer_buffer;
523 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 command_info = usb_get_serial_port_data(command_port);
526 if (!command_info) {
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700527 dev_dbg(&urb->dev->dev, "%s - command_info is NULL, exiting.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 return;
529 }
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700530 if (status) {
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700531 dev_dbg(&urb->dev->dev, "%s - nonzero urb status: %d\n", __func__, status);
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700532 if (status != -ENOENT)
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200533 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
534 wake_up(&command_info->wait_command);
535 return;
536 }
537
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100538 usb_serial_debug_data(&command_port->dev, __func__, urb->actual_length, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 if (data[0] == WHITEHEAT_CMD_COMPLETE) {
541 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200542 wake_up(&command_info->wait_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 } else if (data[0] == WHITEHEAT_CMD_FAILURE) {
544 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200545 wake_up(&command_info->wait_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 } else if (data[0] == WHITEHEAT_EVENT) {
Alan Cox80359a92008-07-22 11:09:16 +0100547 /* These are unsolicited reports from the firmware, hence no
548 waiting command to wakeup */
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700549 dev_dbg(&urb->dev->dev, "%s - event received\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
Alan Cox80359a92008-07-22 11:09:16 +0100551 memcpy(command_info->result_buffer, &data[1],
552 urb->actual_length - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200554 wake_up(&command_info->wait_command);
Alan Cox80359a92008-07-22 11:09:16 +0100555 } else
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700556 dev_dbg(&urb->dev->dev, "%s - bad reply from firmware\n", __func__);
Alan Cox80359a92008-07-22 11:09:16 +0100557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 /* Continue trying to always read */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (result)
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700561 dev_dbg(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n",
Alan Cox80359a92008-07-22 11:09:16 +0100562 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/*****************************************************************************
567 * Connect Tech's White Heat firmware interface
568 *****************************************************************************/
Alan Cox80359a92008-07-22 11:09:16 +0100569static int firm_send_command(struct usb_serial_port *port, __u8 command,
570 __u8 *data, __u8 datasize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
572 struct usb_serial_port *command_port;
573 struct whiteheat_command_private *command_info;
574 struct whiteheat_private *info;
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700575 struct device *dev = &port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 __u8 *transfer_buffer;
577 int retval = 0;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200578 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700580 dev_dbg(dev, "%s - command %d\n", __func__, command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 command_port = port->serial->port[COMMAND_PORT];
583 command_info = usb_get_serial_port_data(command_port);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200584 mutex_lock(&command_info->mutex);
Richard Knutsson38c3cb52007-03-26 22:00:28 -0800585 command_info->command_finished = false;
Alan Cox80359a92008-07-22 11:09:16 +0100586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
588 transfer_buffer[0] = command;
Alan Cox80359a92008-07-22 11:09:16 +0100589 memcpy(&transfer_buffer[1], data, datasize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 command_port->write_urb->transfer_buffer_length = datasize + 1;
Alan Cox80359a92008-07-22 11:09:16 +0100591 retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (retval) {
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700593 dev_dbg(dev, "%s - submit urb failed\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 goto exit;
595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 /* wait for the command to complete */
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200598 t = wait_event_timeout(command_info->wait_command,
Richard Knutsson38c3cb52007-03-26 22:00:28 -0800599 (bool)command_info->command_finished, COMMAND_TIMEOUT);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200600 if (!t)
601 usb_kill_urb(command_port->write_urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Richard Knutsson38c3cb52007-03-26 22:00:28 -0800603 if (command_info->command_finished == false) {
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700604 dev_dbg(dev, "%s - command timed out.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 retval = -ETIMEDOUT;
606 goto exit;
607 }
608
609 if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700610 dev_dbg(dev, "%s - command failed.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 retval = -EIO;
612 goto exit;
613 }
614
615 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700616 dev_dbg(dev, "%s - command completed.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 switch (command) {
Alan Cox80359a92008-07-22 11:09:16 +0100618 case WHITEHEAT_GET_DTR_RTS:
619 info = usb_get_serial_port_data(port);
620 memcpy(&info->mcr, command_info->result_buffer,
621 sizeof(struct whiteheat_dr_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 break;
623 }
624 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625exit:
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200626 mutex_unlock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return retval;
628}
629
630
Alan Cox80359a92008-07-22 11:09:16 +0100631static int firm_open(struct usb_serial_port *port)
632{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 struct whiteheat_simple open_command;
634
635 open_command.port = port->number - port->serial->minor + 1;
Alan Cox80359a92008-07-22 11:09:16 +0100636 return firm_send_command(port, WHITEHEAT_OPEN,
637 (__u8 *)&open_command, sizeof(open_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
640
Alan Cox80359a92008-07-22 11:09:16 +0100641static int firm_close(struct usb_serial_port *port)
642{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 struct whiteheat_simple close_command;
644
645 close_command.port = port->number - port->serial->minor + 1;
Alan Cox80359a92008-07-22 11:09:16 +0100646 return firm_send_command(port, WHITEHEAT_CLOSE,
647 (__u8 *)&close_command, sizeof(close_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648}
649
650
Alan Coxfe1ae7f2009-09-19 13:13:33 -0700651static void firm_setup_port(struct tty_struct *tty)
Alan Cox80359a92008-07-22 11:09:16 +0100652{
Alan Cox95da3102008-07-22 11:09:07 +0100653 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700654 struct device *dev = &port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 struct whiteheat_port_settings port_settings;
Alan Cox95da3102008-07-22 11:09:07 +0100656 unsigned int cflag = tty->termios->c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 port_settings.port = port->number + 1;
659
660 /* get the byte size */
661 switch (cflag & CSIZE) {
Alan Cox80359a92008-07-22 11:09:16 +0100662 case CS5: port_settings.bits = 5; break;
663 case CS6: port_settings.bits = 6; break;
664 case CS7: port_settings.bits = 7; break;
665 default:
666 case CS8: port_settings.bits = 8; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700668 dev_dbg(dev, "%s - data bits = %d\n", __func__, port_settings.bits);
Alan Cox80359a92008-07-22 11:09:16 +0100669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /* determine the parity */
671 if (cflag & PARENB)
672 if (cflag & CMSPAR)
673 if (cflag & PARODD)
674 port_settings.parity = WHITEHEAT_PAR_MARK;
675 else
676 port_settings.parity = WHITEHEAT_PAR_SPACE;
677 else
678 if (cflag & PARODD)
679 port_settings.parity = WHITEHEAT_PAR_ODD;
680 else
681 port_settings.parity = WHITEHEAT_PAR_EVEN;
682 else
683 port_settings.parity = WHITEHEAT_PAR_NONE;
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700684 dev_dbg(dev, "%s - parity = %c\n", __func__, port_settings.parity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 /* figure out the stop bits requested */
687 if (cflag & CSTOPB)
688 port_settings.stop = 2;
689 else
690 port_settings.stop = 1;
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700691 dev_dbg(dev, "%s - stop bits = %d\n", __func__, port_settings.stop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 /* figure out the flow control settings */
694 if (cflag & CRTSCTS)
Alan Cox80359a92008-07-22 11:09:16 +0100695 port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
696 WHITEHEAT_HFLOW_RTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 else
698 port_settings.hflow = WHITEHEAT_HFLOW_NONE;
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700699 dev_dbg(dev, "%s - hardware flow control = %s %s %s %s\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
701 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
702 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
703 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
Alan Cox80359a92008-07-22 11:09:16 +0100704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 /* determine software flow control */
Alan Cox95da3102008-07-22 11:09:07 +0100706 if (I_IXOFF(tty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
708 else
709 port_settings.sflow = WHITEHEAT_SFLOW_NONE;
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700710 dev_dbg(dev, "%s - software flow control = %c\n", __func__, port_settings.sflow);
Alan Cox80359a92008-07-22 11:09:16 +0100711
Alan Cox95da3102008-07-22 11:09:07 +0100712 port_settings.xon = START_CHAR(tty);
713 port_settings.xoff = STOP_CHAR(tty);
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700714 dev_dbg(dev, "%s - XON = %2x, XOFF = %2x\n", __func__, port_settings.xon, port_settings.xoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 /* get the baud rate wanted */
Alan Cox95da3102008-07-22 11:09:07 +0100717 port_settings.baud = tty_get_baud_rate(tty);
Greg Kroah-Hartman255b7032012-09-14 11:50:35 -0700718 dev_dbg(dev, "%s - baud rate = %d\n", __func__, port_settings.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Alan Cox01d1df22007-10-18 01:24:23 -0700720 /* fixme: should set validated settings */
Alan Cox95da3102008-07-22 11:09:07 +0100721 tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /* handle any settings that aren't specified in the tty structure */
723 port_settings.lloop = 0;
Alan Cox80359a92008-07-22 11:09:16 +0100724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 /* now send the message to the device */
Alan Coxfe1ae7f2009-09-19 13:13:33 -0700726 firm_send_command(port, WHITEHEAT_SETUP_PORT,
Alan Cox80359a92008-07-22 11:09:16 +0100727 (__u8 *)&port_settings, sizeof(port_settings));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728}
729
730
Alan Cox80359a92008-07-22 11:09:16 +0100731static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
732{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 struct whiteheat_set_rdb rts_command;
734
735 rts_command.port = port->number - port->serial->minor + 1;
736 rts_command.state = onoff;
Alan Cox80359a92008-07-22 11:09:16 +0100737 return firm_send_command(port, WHITEHEAT_SET_RTS,
738 (__u8 *)&rts_command, sizeof(rts_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
741
Alan Cox80359a92008-07-22 11:09:16 +0100742static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
743{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 struct whiteheat_set_rdb dtr_command;
745
746 dtr_command.port = port->number - port->serial->minor + 1;
747 dtr_command.state = onoff;
Alan Cox72e27412008-07-22 11:09:29 +0100748 return firm_send_command(port, WHITEHEAT_SET_DTR,
Alan Cox80359a92008-07-22 11:09:16 +0100749 (__u8 *)&dtr_command, sizeof(dtr_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
751
752
Alan Cox80359a92008-07-22 11:09:16 +0100753static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
754{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 struct whiteheat_set_rdb break_command;
756
757 break_command.port = port->number - port->serial->minor + 1;
758 break_command.state = onoff;
Alan Cox72e27412008-07-22 11:09:29 +0100759 return firm_send_command(port, WHITEHEAT_SET_BREAK,
Alan Cox80359a92008-07-22 11:09:16 +0100760 (__u8 *)&break_command, sizeof(break_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761}
762
763
Alan Cox80359a92008-07-22 11:09:16 +0100764static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
765{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 struct whiteheat_purge purge_command;
767
768 purge_command.port = port->number - port->serial->minor + 1;
769 purge_command.what = rxtx;
Alan Cox80359a92008-07-22 11:09:16 +0100770 return firm_send_command(port, WHITEHEAT_PURGE,
771 (__u8 *)&purge_command, sizeof(purge_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772}
773
774
Alan Cox80359a92008-07-22 11:09:16 +0100775static int firm_get_dtr_rts(struct usb_serial_port *port)
776{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 struct whiteheat_simple get_dr_command;
778
779 get_dr_command.port = port->number - port->serial->minor + 1;
Alan Cox80359a92008-07-22 11:09:16 +0100780 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
781 (__u8 *)&get_dr_command, sizeof(get_dr_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
783
784
Alan Cox80359a92008-07-22 11:09:16 +0100785static int firm_report_tx_done(struct usb_serial_port *port)
786{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 struct whiteheat_simple close_command;
788
789 close_command.port = port->number - port->serial->minor + 1;
Alan Cox80359a92008-07-22 11:09:16 +0100790 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
791 (__u8 *)&close_command, sizeof(close_command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
794
795/*****************************************************************************
796 * Connect Tech's White Heat utility functions
797 *****************************************************************************/
798static int start_command_port(struct usb_serial *serial)
799{
800 struct usb_serial_port *command_port;
801 struct whiteheat_command_private *command_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 int retval = 0;
Alan Cox80359a92008-07-22 11:09:16 +0100803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 command_port = serial->port[COMMAND_PORT];
805 command_info = usb_get_serial_port_data(command_port);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200806 mutex_lock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 if (!command_info->port_running) {
808 /* Work around HCD bugs */
809 usb_clear_halt(serial->dev, command_port->read_urb->pipe);
810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
812 if (retval) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700813 dev_err(&serial->dev->dev,
814 "%s - failed submitting read urb, error %d\n",
815 __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 goto exit;
817 }
818 }
819 command_info->port_running++;
820
821exit:
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200822 mutex_unlock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 return retval;
824}
825
826
827static void stop_command_port(struct usb_serial *serial)
828{
829 struct usb_serial_port *command_port;
830 struct whiteheat_command_private *command_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 command_port = serial->port[COMMAND_PORT];
833 command_info = usb_get_serial_port_data(command_port);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200834 mutex_lock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 command_info->port_running--;
836 if (!command_info->port_running)
837 usb_kill_urb(command_port->read_urb);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200838 mutex_unlock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839}
840
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -0700841module_usb_serial_driver(serial_drivers, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Alan Cox80359a92008-07-22 11:09:16 +0100843MODULE_AUTHOR(DRIVER_AUTHOR);
844MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845MODULE_LICENSE("GPL");
846
David Woodhouseec6752f2008-05-31 01:35:29 +0300847MODULE_FIRMWARE("whiteheat.fw");
848MODULE_FIRMWARE("whiteheat_loader.fw");