2 * USB ConnectTech WhiteHEAT driver
7 * Copyright (C) 1999 - 2001
8 * Greg Kroah-Hartman (greg@kroah.com)
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.
15 * See Documentation/usb/usb-serial.txt for more information on using this
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>
28 #include <linux/mutex.h>
29 #include <linux/uaccess.h>
30 #include <asm/termbits.h>
31 #include <linux/usb.h>
32 #include <linux/serial_reg.h>
33 #include <linux/serial.h>
34 #include <linux/usb/serial.h>
35 #include <linux/firmware.h>
36 #include <linux/ihex.h>
37 #include "whiteheat.h" /* WhiteHEAT specific commands */
48 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
49 #define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
51 #define CONNECT_TECH_VENDOR_ID 0x0710
52 #define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
53 #define CONNECT_TECH_WHITE_HEAT_ID 0x8001
56 ID tables for whiteheat are unusual, because we want to different
57 things for different versions of the device. Eventually, this
58 will be doable from a single table. But, for now, we define two
59 separate ID tables, and then a third table that combines them
60 just for the purpose of exporting the autoloading information.
62 static const struct usb_device_id id_table_std[] = {
63 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
64 { } /* Terminating entry */
67 static const struct usb_device_id id_table_prerenumeration[] = {
68 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
69 { } /* Terminating entry */
72 static const struct usb_device_id id_table_combined[] = {
73 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
74 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
75 { } /* Terminating entry */
78 MODULE_DEVICE_TABLE(usb, id_table_combined);
80 static struct usb_driver whiteheat_driver = {
82 .disconnect = usb_serial_disconnect,
83 .id_table = id_table_combined,
86 /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
87 static int whiteheat_firmware_download(struct usb_serial *serial,
88 const struct usb_device_id *id);
89 static int whiteheat_firmware_attach(struct usb_serial *serial);
91 /* function prototypes for the Connect Tech WhiteHEAT serial converter */
92 static int whiteheat_attach(struct usb_serial *serial);
93 static void whiteheat_release(struct usb_serial *serial);
94 static int whiteheat_open(struct tty_struct *tty,
95 struct usb_serial_port *port);
96 static void whiteheat_close(struct usb_serial_port *port);
97 static int whiteheat_ioctl(struct tty_struct *tty,
98 unsigned int cmd, unsigned long arg);
99 static void whiteheat_set_termios(struct tty_struct *tty,
100 struct usb_serial_port *port, struct ktermios *old);
101 static int whiteheat_tiocmget(struct tty_struct *tty);
102 static int whiteheat_tiocmset(struct tty_struct *tty,
103 unsigned int set, unsigned int clear);
104 static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
106 static struct usb_serial_driver whiteheat_fake_device = {
108 .owner = THIS_MODULE,
109 .name = "whiteheatnofirm",
111 .description = "Connect Tech - WhiteHEAT - (prerenumeration)",
112 .id_table = id_table_prerenumeration,
114 .probe = whiteheat_firmware_download,
115 .attach = whiteheat_firmware_attach,
118 static struct usb_serial_driver whiteheat_device = {
120 .owner = THIS_MODULE,
123 .description = "Connect Tech - WhiteHEAT",
124 .id_table = id_table_std,
126 .attach = whiteheat_attach,
127 .release = whiteheat_release,
128 .open = whiteheat_open,
129 .close = whiteheat_close,
130 .ioctl = whiteheat_ioctl,
131 .set_termios = whiteheat_set_termios,
132 .break_ctl = whiteheat_break_ctl,
133 .tiocmget = whiteheat_tiocmget,
134 .tiocmset = whiteheat_tiocmset,
135 .throttle = usb_serial_generic_throttle,
136 .unthrottle = usb_serial_generic_unthrottle,
139 static struct usb_serial_driver * const serial_drivers[] = {
140 &whiteheat_fake_device, &whiteheat_device, NULL
143 struct whiteheat_command_private {
146 __u8 command_finished;
147 wait_queue_head_t wait_command; /* for handling sleeping whilst
148 waiting for a command to
150 __u8 result_buffer[64];
153 struct whiteheat_private {
154 __u8 mcr; /* FIXME: no locking on mcr */
158 /* local function prototypes */
159 static int start_command_port(struct usb_serial *serial);
160 static void stop_command_port(struct usb_serial *serial);
161 static void command_port_write_callback(struct urb *urb);
162 static void command_port_read_callback(struct urb *urb);
164 static int firm_send_command(struct usb_serial_port *port, __u8 command,
165 __u8 *data, __u8 datasize);
166 static int firm_open(struct usb_serial_port *port);
167 static int firm_close(struct usb_serial_port *port);
168 static void firm_setup_port(struct tty_struct *tty);
169 static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
170 static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
171 static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
172 static int firm_purge(struct usb_serial_port *port, __u8 rxtx);
173 static int firm_get_dtr_rts(struct usb_serial_port *port);
174 static int firm_report_tx_done(struct usb_serial_port *port);
177 #define COMMAND_PORT 4
178 #define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */
179 #define COMMAND_TIMEOUT_MS 2000
180 #define CLOSING_DELAY (30 * HZ)
183 /*****************************************************************************
184 * Connect Tech's White Heat prerenumeration driver functions
185 *****************************************************************************/
187 /* steps to download the firmware to the WhiteHEAT device:
188 - hold the reset (by writing to the reset bit of the CPUCS register)
189 - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
190 - release the reset (by writing to the CPUCS register)
191 - download the WH.HEX file for all addresses greater than 0x1b3f using
192 VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
194 - download the WH.HEX file for all addresses less than 0x1b40 using
195 VENDOR_REQUEST_ANCHOR_LOAD
197 - device renumerated itself and comes up as new device id with all
198 firmware download completed.
200 static int whiteheat_firmware_download(struct usb_serial *serial,
201 const struct usb_device_id *id)
203 int response, ret = -ENOENT;
204 const struct firmware *loader_fw = NULL, *firmware_fw = NULL;
205 const struct ihex_binrec *record;
207 if (request_ihex_firmware(&firmware_fw, "whiteheat.fw",
208 &serial->dev->dev)) {
209 dev_err(&serial->dev->dev,
210 "%s - request \"whiteheat.fw\" failed\n", __func__);
213 if (request_ihex_firmware(&loader_fw, "whiteheat_loader.fw",
214 &serial->dev->dev)) {
215 dev_err(&serial->dev->dev,
216 "%s - request \"whiteheat_loader.fw\" failed\n",
221 response = ezusb_set_reset (serial, 1);
223 record = (const struct ihex_binrec *)loader_fw->data;
225 response = ezusb_writememory (serial, be32_to_cpu(record->addr),
226 (unsigned char *)record->data,
227 be16_to_cpu(record->len), 0xa0);
229 dev_err(&serial->dev->dev, "%s - ezusb_writememory "
230 "failed for loader (%d %04X %p %d)\n",
231 __func__, response, be32_to_cpu(record->addr),
232 record->data, be16_to_cpu(record->len));
235 record = ihex_next_binrec(record);
238 response = ezusb_set_reset(serial, 0);
240 record = (const struct ihex_binrec *)firmware_fw->data;
241 while (record && be32_to_cpu(record->addr) < 0x1b40)
242 record = ihex_next_binrec(record);
244 response = ezusb_writememory (serial, be32_to_cpu(record->addr),
245 (unsigned char *)record->data,
246 be16_to_cpu(record->len), 0xa3);
248 dev_err(&serial->dev->dev, "%s - ezusb_writememory "
249 "failed for first firmware step "
250 "(%d %04X %p %d)\n", __func__, response,
251 be32_to_cpu(record->addr), record->data,
252 be16_to_cpu(record->len));
258 response = ezusb_set_reset(serial, 1);
260 record = (const struct ihex_binrec *)firmware_fw->data;
261 while (record && be32_to_cpu(record->addr) < 0x1b40) {
262 response = ezusb_writememory (serial, be32_to_cpu(record->addr),
263 (unsigned char *)record->data,
264 be16_to_cpu(record->len), 0xa0);
266 dev_err(&serial->dev->dev, "%s - ezusb_writememory "
267 "failed for second firmware step "
268 "(%d %04X %p %d)\n", __func__, response,
269 be32_to_cpu(record->addr), record->data,
270 be16_to_cpu(record->len));
276 response = ezusb_set_reset (serial, 0);
278 release_firmware(loader_fw);
279 release_firmware(firmware_fw);
284 static int whiteheat_firmware_attach(struct usb_serial *serial)
286 /* We want this device to fail to have a driver assigned to it */
291 /*****************************************************************************
292 * Connect Tech's White Heat serial driver functions
293 *****************************************************************************/
294 static int whiteheat_attach(struct usb_serial *serial)
296 struct usb_serial_port *command_port;
297 struct whiteheat_command_private *command_info;
298 struct usb_serial_port *port;
299 struct whiteheat_private *info;
300 struct whiteheat_hw_info *hw_info;
308 command_port = serial->port[COMMAND_PORT];
310 pipe = usb_sndbulkpipe(serial->dev,
311 command_port->bulk_out_endpointAddress);
312 command = kmalloc(2, GFP_KERNEL);
314 goto no_command_buffer;
315 command[0] = WHITEHEAT_GET_HW_INFO;
318 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
320 goto no_result_buffer;
322 * When the module is reloaded the firmware is still there and
323 * the endpoints are still in the usb core unchanged. This is the
324 * unlinking bug in disguise. Same for the call below.
326 usb_clear_halt(serial->dev, pipe);
327 ret = usb_bulk_msg(serial->dev, pipe, command, 2,
328 &alen, COMMAND_TIMEOUT_MS);
330 dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
331 serial->type->description, ret);
333 } else if (alen != 2) {
334 dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
335 serial->type->description, alen);
339 pipe = usb_rcvbulkpipe(serial->dev,
340 command_port->bulk_in_endpointAddress);
341 /* See the comment on the usb_clear_halt() above */
342 usb_clear_halt(serial->dev, pipe);
343 ret = usb_bulk_msg(serial->dev, pipe, result,
344 sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
346 dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
347 serial->type->description, ret);
349 } else if (alen != sizeof(*hw_info) + 1) {
350 dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n",
351 serial->type->description, alen);
353 } else if (result[0] != command[0]) {
354 dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
355 serial->type->description, result[0]);
359 hw_info = (struct whiteheat_hw_info *)&result[1];
361 dev_info(&serial->dev->dev, "%s: Firmware v%d.%02d\n",
362 serial->type->description,
363 hw_info->sw_major_rev, hw_info->sw_minor_rev);
365 for (i = 0; i < serial->num_ports; i++) {
366 port = serial->port[i];
368 info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
371 "%s: Out of memory for port structures\n",
372 serial->type->description);
378 usb_set_serial_port_data(port, info);
381 command_info = kmalloc(sizeof(struct whiteheat_command_private),
383 if (command_info == NULL) {
384 dev_err(&serial->dev->dev,
385 "%s: Out of memory for port structures\n",
386 serial->type->description);
387 goto no_command_private;
390 mutex_init(&command_info->mutex);
391 command_info->port_running = 0;
392 init_waitqueue_head(&command_info->wait_command);
393 usb_set_serial_port_data(command_port, command_info);
394 command_port->write_urb->complete = command_port_write_callback;
395 command_port->read_urb->complete = command_port_read_callback;
402 /* Firmware likely not running */
403 dev_err(&serial->dev->dev,
404 "%s: Unable to retrieve firmware version, try replugging\n",
405 serial->type->description);
406 dev_err(&serial->dev->dev,
407 "%s: If the firmware is not running (status led not blinking)\n",
408 serial->type->description);
409 dev_err(&serial->dev->dev,
410 "%s: please contact support@connecttech.com\n",
411 serial->type->description);
416 for (i = serial->num_ports - 1; i >= 0; i--) {
417 port = serial->port[i];
418 info = usb_get_serial_port_data(port);
431 static void whiteheat_release(struct usb_serial *serial)
433 struct usb_serial_port *command_port;
434 struct whiteheat_private *info;
437 /* free up our private data for our command port */
438 command_port = serial->port[COMMAND_PORT];
439 kfree(usb_get_serial_port_data(command_port));
441 for (i = 0; i < serial->num_ports; i++) {
442 info = usb_get_serial_port_data(serial->port[i]);
447 static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
451 retval = start_command_port(port->serial);
455 /* send an open port command */
456 retval = firm_open(port);
458 stop_command_port(port->serial);
462 retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
465 stop_command_port(port->serial);
470 firm_setup_port(tty);
472 /* Work around HCD bugs */
473 usb_clear_halt(port->serial->dev, port->read_urb->pipe);
474 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
476 retval = usb_serial_generic_open(tty, port);
479 stop_command_port(port->serial);
487 static void whiteheat_close(struct usb_serial_port *port)
489 firm_report_tx_done(port);
492 usb_serial_generic_close(port);
494 stop_command_port(port->serial);
497 static int whiteheat_tiocmget(struct tty_struct *tty)
499 struct usb_serial_port *port = tty->driver_data;
500 struct whiteheat_private *info = usb_get_serial_port_data(port);
501 unsigned int modem_signals = 0;
503 firm_get_dtr_rts(port);
504 if (info->mcr & UART_MCR_DTR)
505 modem_signals |= TIOCM_DTR;
506 if (info->mcr & UART_MCR_RTS)
507 modem_signals |= TIOCM_RTS;
509 return modem_signals;
512 static int whiteheat_tiocmset(struct tty_struct *tty,
513 unsigned int set, unsigned int clear)
515 struct usb_serial_port *port = tty->driver_data;
516 struct whiteheat_private *info = usb_get_serial_port_data(port);
519 info->mcr |= UART_MCR_RTS;
521 info->mcr |= UART_MCR_DTR;
523 if (clear & TIOCM_RTS)
524 info->mcr &= ~UART_MCR_RTS;
525 if (clear & TIOCM_DTR)
526 info->mcr &= ~UART_MCR_DTR;
528 firm_set_dtr(port, info->mcr & UART_MCR_DTR);
529 firm_set_rts(port, info->mcr & UART_MCR_RTS);
534 static int whiteheat_ioctl(struct tty_struct *tty,
535 unsigned int cmd, unsigned long arg)
537 struct usb_serial_port *port = tty->driver_data;
538 struct serial_struct serstruct;
539 void __user *user_arg = (void __user *)arg;
541 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
545 memset(&serstruct, 0, sizeof(serstruct));
546 serstruct.type = PORT_16654;
547 serstruct.line = port->serial->minor;
548 serstruct.port = port->number;
549 serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
550 serstruct.xmit_fifo_size = kfifo_size(&port->write_fifo);
551 serstruct.custom_divisor = 0;
552 serstruct.baud_base = 460800;
553 serstruct.close_delay = CLOSING_DELAY;
554 serstruct.closing_wait = CLOSING_DELAY;
556 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
567 static void whiteheat_set_termios(struct tty_struct *tty,
568 struct usb_serial_port *port, struct ktermios *old_termios)
570 firm_setup_port(tty);
573 static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
575 struct usb_serial_port *port = tty->driver_data;
576 firm_set_break(port, break_state);
580 /*****************************************************************************
581 * Connect Tech's White Heat callback routines
582 *****************************************************************************/
583 static void command_port_write_callback(struct urb *urb)
585 int status = urb->status;
588 dbg("nonzero urb status: %d", status);
594 static void command_port_read_callback(struct urb *urb)
596 struct usb_serial_port *command_port = urb->context;
597 struct whiteheat_command_private *command_info;
598 int status = urb->status;
599 unsigned char *data = urb->transfer_buffer;
602 command_info = usb_get_serial_port_data(command_port);
604 dbg("%s - command_info is NULL, exiting.", __func__);
608 dbg("%s - nonzero urb status: %d", __func__, status);
609 if (status != -ENOENT)
610 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
611 wake_up(&command_info->wait_command);
615 usb_serial_debug_data(debug, &command_port->dev,
616 __func__, urb->actual_length, data);
618 if (data[0] == WHITEHEAT_CMD_COMPLETE) {
619 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
620 wake_up(&command_info->wait_command);
621 } else if (data[0] == WHITEHEAT_CMD_FAILURE) {
622 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
623 wake_up(&command_info->wait_command);
624 } else if (data[0] == WHITEHEAT_EVENT) {
625 /* These are unsolicited reports from the firmware, hence no
626 waiting command to wakeup */
627 dbg("%s - event received", __func__);
628 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
629 memcpy(command_info->result_buffer, &data[1],
630 urb->actual_length - 1);
631 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
632 wake_up(&command_info->wait_command);
634 dbg("%s - bad reply from firmware", __func__);
636 /* Continue trying to always read */
637 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
639 dbg("%s - failed resubmitting read urb, error %d",
644 /*****************************************************************************
645 * Connect Tech's White Heat firmware interface
646 *****************************************************************************/
647 static int firm_send_command(struct usb_serial_port *port, __u8 command,
648 __u8 *data, __u8 datasize)
650 struct usb_serial_port *command_port;
651 struct whiteheat_command_private *command_info;
652 struct whiteheat_private *info;
653 __u8 *transfer_buffer;
657 dbg("%s - command %d", __func__, command);
659 command_port = port->serial->port[COMMAND_PORT];
660 command_info = usb_get_serial_port_data(command_port);
661 mutex_lock(&command_info->mutex);
662 command_info->command_finished = false;
664 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
665 transfer_buffer[0] = command;
666 memcpy(&transfer_buffer[1], data, datasize);
667 command_port->write_urb->transfer_buffer_length = datasize + 1;
668 retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
670 dbg("%s - submit urb failed", __func__);
674 /* wait for the command to complete */
675 t = wait_event_timeout(command_info->wait_command,
676 (bool)command_info->command_finished, COMMAND_TIMEOUT);
678 usb_kill_urb(command_port->write_urb);
680 if (command_info->command_finished == false) {
681 dbg("%s - command timed out.", __func__);
686 if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
687 dbg("%s - command failed.", __func__);
692 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
693 dbg("%s - command completed.", __func__);
695 case WHITEHEAT_GET_DTR_RTS:
696 info = usb_get_serial_port_data(port);
697 memcpy(&info->mcr, command_info->result_buffer,
698 sizeof(struct whiteheat_dr_info));
703 mutex_unlock(&command_info->mutex);
708 static int firm_open(struct usb_serial_port *port)
710 struct whiteheat_simple open_command;
712 open_command.port = port->number - port->serial->minor + 1;
713 return firm_send_command(port, WHITEHEAT_OPEN,
714 (__u8 *)&open_command, sizeof(open_command));
718 static int firm_close(struct usb_serial_port *port)
720 struct whiteheat_simple close_command;
722 close_command.port = port->number - port->serial->minor + 1;
723 return firm_send_command(port, WHITEHEAT_CLOSE,
724 (__u8 *)&close_command, sizeof(close_command));
728 static void firm_setup_port(struct tty_struct *tty)
730 struct usb_serial_port *port = tty->driver_data;
731 struct whiteheat_port_settings port_settings;
732 unsigned int cflag = tty->termios->c_cflag;
734 port_settings.port = port->number + 1;
736 /* get the byte size */
737 switch (cflag & CSIZE) {
738 case CS5: port_settings.bits = 5; break;
739 case CS6: port_settings.bits = 6; break;
740 case CS7: port_settings.bits = 7; break;
742 case CS8: port_settings.bits = 8; break;
744 dbg("%s - data bits = %d", __func__, port_settings.bits);
746 /* determine the parity */
750 port_settings.parity = WHITEHEAT_PAR_MARK;
752 port_settings.parity = WHITEHEAT_PAR_SPACE;
755 port_settings.parity = WHITEHEAT_PAR_ODD;
757 port_settings.parity = WHITEHEAT_PAR_EVEN;
759 port_settings.parity = WHITEHEAT_PAR_NONE;
760 dbg("%s - parity = %c", __func__, port_settings.parity);
762 /* figure out the stop bits requested */
764 port_settings.stop = 2;
766 port_settings.stop = 1;
767 dbg("%s - stop bits = %d", __func__, port_settings.stop);
769 /* figure out the flow control settings */
771 port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
772 WHITEHEAT_HFLOW_RTS);
774 port_settings.hflow = WHITEHEAT_HFLOW_NONE;
775 dbg("%s - hardware flow control = %s %s %s %s", __func__,
776 (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
777 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
778 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
779 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
781 /* determine software flow control */
783 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
785 port_settings.sflow = WHITEHEAT_SFLOW_NONE;
786 dbg("%s - software flow control = %c", __func__, port_settings.sflow);
788 port_settings.xon = START_CHAR(tty);
789 port_settings.xoff = STOP_CHAR(tty);
790 dbg("%s - XON = %2x, XOFF = %2x",
791 __func__, port_settings.xon, port_settings.xoff);
793 /* get the baud rate wanted */
794 port_settings.baud = tty_get_baud_rate(tty);
795 dbg("%s - baud rate = %d", __func__, port_settings.baud);
797 /* fixme: should set validated settings */
798 tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud);
799 /* handle any settings that aren't specified in the tty structure */
800 port_settings.lloop = 0;
802 /* now send the message to the device */
803 firm_send_command(port, WHITEHEAT_SETUP_PORT,
804 (__u8 *)&port_settings, sizeof(port_settings));
808 static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
810 struct whiteheat_set_rdb rts_command;
812 rts_command.port = port->number - port->serial->minor + 1;
813 rts_command.state = onoff;
814 return firm_send_command(port, WHITEHEAT_SET_RTS,
815 (__u8 *)&rts_command, sizeof(rts_command));
819 static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
821 struct whiteheat_set_rdb dtr_command;
823 dtr_command.port = port->number - port->serial->minor + 1;
824 dtr_command.state = onoff;
825 return firm_send_command(port, WHITEHEAT_SET_DTR,
826 (__u8 *)&dtr_command, sizeof(dtr_command));
830 static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
832 struct whiteheat_set_rdb break_command;
834 break_command.port = port->number - port->serial->minor + 1;
835 break_command.state = onoff;
836 return firm_send_command(port, WHITEHEAT_SET_BREAK,
837 (__u8 *)&break_command, sizeof(break_command));
841 static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
843 struct whiteheat_purge purge_command;
845 purge_command.port = port->number - port->serial->minor + 1;
846 purge_command.what = rxtx;
847 return firm_send_command(port, WHITEHEAT_PURGE,
848 (__u8 *)&purge_command, sizeof(purge_command));
852 static int firm_get_dtr_rts(struct usb_serial_port *port)
854 struct whiteheat_simple get_dr_command;
856 get_dr_command.port = port->number - port->serial->minor + 1;
857 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
858 (__u8 *)&get_dr_command, sizeof(get_dr_command));
862 static int firm_report_tx_done(struct usb_serial_port *port)
864 struct whiteheat_simple close_command;
866 close_command.port = port->number - port->serial->minor + 1;
867 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
868 (__u8 *)&close_command, sizeof(close_command));
872 /*****************************************************************************
873 * Connect Tech's White Heat utility functions
874 *****************************************************************************/
875 static int start_command_port(struct usb_serial *serial)
877 struct usb_serial_port *command_port;
878 struct whiteheat_command_private *command_info;
881 command_port = serial->port[COMMAND_PORT];
882 command_info = usb_get_serial_port_data(command_port);
883 mutex_lock(&command_info->mutex);
884 if (!command_info->port_running) {
885 /* Work around HCD bugs */
886 usb_clear_halt(serial->dev, command_port->read_urb->pipe);
888 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
890 dev_err(&serial->dev->dev,
891 "%s - failed submitting read urb, error %d\n",
896 command_info->port_running++;
899 mutex_unlock(&command_info->mutex);
904 static void stop_command_port(struct usb_serial *serial)
906 struct usb_serial_port *command_port;
907 struct whiteheat_command_private *command_info;
909 command_port = serial->port[COMMAND_PORT];
910 command_info = usb_get_serial_port_data(command_port);
911 mutex_lock(&command_info->mutex);
912 command_info->port_running--;
913 if (!command_info->port_running)
914 usb_kill_urb(command_port->read_urb);
915 mutex_unlock(&command_info->mutex);
918 module_usb_serial_driver(whiteheat_driver, serial_drivers);
920 MODULE_AUTHOR(DRIVER_AUTHOR);
921 MODULE_DESCRIPTION(DRIVER_DESC);
922 MODULE_LICENSE("GPL");
924 MODULE_FIRMWARE("whiteheat.fw");
925 MODULE_FIRMWARE("whiteheat_loader.fw");
927 module_param(debug, bool, S_IRUGO | S_IWUSR);
928 MODULE_PARM_DESC(debug, "Debug enabled or not");