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/usb/ezusb.h>
36 #include "whiteheat.h" /* WhiteHEAT specific commands */
45 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
46 #define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
48 #define CONNECT_TECH_VENDOR_ID 0x0710
49 #define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
50 #define CONNECT_TECH_WHITE_HEAT_ID 0x8001
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.
59 static const struct usb_device_id id_table_std
[] = {
60 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_WHITE_HEAT_ID
) },
61 { } /* Terminating entry */
64 static const struct usb_device_id id_table_prerenumeration
[] = {
65 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_FAKE_WHITE_HEAT_ID
) },
66 { } /* Terminating entry */
69 static const struct usb_device_id id_table_combined
[] = {
70 { 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 */
75 MODULE_DEVICE_TABLE(usb
, id_table_combined
);
78 /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
79 static int whiteheat_firmware_download(struct usb_serial
*serial
,
80 const struct usb_device_id
*id
);
81 static int whiteheat_firmware_attach(struct usb_serial
*serial
);
83 /* function prototypes for the Connect Tech WhiteHEAT serial converter */
84 static int whiteheat_probe(struct usb_serial
*serial
,
85 const struct usb_device_id
*id
);
86 static int whiteheat_attach(struct usb_serial
*serial
);
87 static void whiteheat_release(struct usb_serial
*serial
);
88 static int whiteheat_port_probe(struct usb_serial_port
*port
);
89 static int whiteheat_port_remove(struct usb_serial_port
*port
);
90 static int whiteheat_open(struct tty_struct
*tty
,
91 struct usb_serial_port
*port
);
92 static void whiteheat_close(struct usb_serial_port
*port
);
93 static int whiteheat_ioctl(struct tty_struct
*tty
,
94 unsigned int cmd
, unsigned long arg
);
95 static void whiteheat_set_termios(struct tty_struct
*tty
,
96 struct usb_serial_port
*port
, struct ktermios
*old
);
97 static int whiteheat_tiocmget(struct tty_struct
*tty
);
98 static int whiteheat_tiocmset(struct tty_struct
*tty
,
99 unsigned int set
, unsigned int clear
);
100 static void whiteheat_break_ctl(struct tty_struct
*tty
, int break_state
);
102 static struct usb_serial_driver whiteheat_fake_device
= {
104 .owner
= THIS_MODULE
,
105 .name
= "whiteheatnofirm",
107 .description
= "Connect Tech - WhiteHEAT - (prerenumeration)",
108 .id_table
= id_table_prerenumeration
,
110 .probe
= whiteheat_firmware_download
,
111 .attach
= whiteheat_firmware_attach
,
114 static struct usb_serial_driver whiteheat_device
= {
116 .owner
= THIS_MODULE
,
119 .description
= "Connect Tech - WhiteHEAT",
120 .id_table
= id_table_std
,
122 .probe
= whiteheat_probe
,
123 .attach
= whiteheat_attach
,
124 .release
= whiteheat_release
,
125 .port_probe
= whiteheat_port_probe
,
126 .port_remove
= whiteheat_port_remove
,
127 .open
= whiteheat_open
,
128 .close
= whiteheat_close
,
129 .ioctl
= whiteheat_ioctl
,
130 .set_termios
= whiteheat_set_termios
,
131 .break_ctl
= whiteheat_break_ctl
,
132 .tiocmget
= whiteheat_tiocmget
,
133 .tiocmset
= whiteheat_tiocmset
,
134 .throttle
= usb_serial_generic_throttle
,
135 .unthrottle
= usb_serial_generic_unthrottle
,
138 static struct usb_serial_driver
* const serial_drivers
[] = {
139 &whiteheat_fake_device
, &whiteheat_device
, NULL
142 struct whiteheat_command_private
{
145 __u8 command_finished
;
146 wait_queue_head_t wait_command
; /* for handling sleeping whilst
147 waiting for a command to
149 __u8 result_buffer
[64];
152 struct whiteheat_private
{
153 __u8 mcr
; /* FIXME: no locking on mcr */
157 /* local function prototypes */
158 static int start_command_port(struct usb_serial
*serial
);
159 static void stop_command_port(struct usb_serial
*serial
);
160 static void command_port_write_callback(struct urb
*urb
);
161 static void command_port_read_callback(struct urb
*urb
);
163 static int firm_send_command(struct usb_serial_port
*port
, __u8 command
,
164 __u8
*data
, __u8 datasize
);
165 static int firm_open(struct usb_serial_port
*port
);
166 static int firm_close(struct usb_serial_port
*port
);
167 static void firm_setup_port(struct tty_struct
*tty
);
168 static int firm_set_rts(struct usb_serial_port
*port
, __u8 onoff
);
169 static int firm_set_dtr(struct usb_serial_port
*port
, __u8 onoff
);
170 static int firm_set_break(struct usb_serial_port
*port
, __u8 onoff
);
171 static int firm_purge(struct usb_serial_port
*port
, __u8 rxtx
);
172 static int firm_get_dtr_rts(struct usb_serial_port
*port
);
173 static int firm_report_tx_done(struct usb_serial_port
*port
);
176 #define COMMAND_PORT 4
177 #define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */
178 #define COMMAND_TIMEOUT_MS 2000
179 #define CLOSING_DELAY (30 * HZ)
182 /*****************************************************************************
183 * Connect Tech's White Heat prerenumeration driver functions
184 *****************************************************************************/
186 /* steps to download the firmware to the WhiteHEAT device:
187 - hold the reset (by writing to the reset bit of the CPUCS register)
188 - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
189 - release the reset (by writing to the CPUCS register)
190 - download the WH.HEX file for all addresses greater than 0x1b3f using
191 VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
193 - download the WH.HEX file for all addresses less than 0x1b40 using
194 VENDOR_REQUEST_ANCHOR_LOAD
196 - device renumerated itself and comes up as new device id with all
197 firmware download completed.
199 static int whiteheat_firmware_download(struct usb_serial
*serial
,
200 const struct usb_device_id
*id
)
204 response
= ezusb_fx1_ihex_firmware_download(serial
->dev
, "whiteheat_loader.fw");
206 response
= ezusb_fx1_ihex_firmware_download(serial
->dev
, "whiteheat.fw");
214 static int whiteheat_firmware_attach(struct usb_serial
*serial
)
216 /* We want this device to fail to have a driver assigned to it */
221 /*****************************************************************************
222 * Connect Tech's White Heat serial driver functions
223 *****************************************************************************/
225 static int whiteheat_probe(struct usb_serial
*serial
,
226 const struct usb_device_id
*id
)
228 struct usb_host_interface
*iface_desc
;
229 struct usb_endpoint_descriptor
*endpoint
;
230 size_t num_bulk_in
= 0;
231 size_t num_bulk_out
= 0;
235 iface_desc
= serial
->interface
->cur_altsetting
;
237 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; i
++) {
238 endpoint
= &iface_desc
->endpoint
[i
].desc
;
239 if (usb_endpoint_is_bulk_in(endpoint
))
241 if (usb_endpoint_is_bulk_out(endpoint
))
245 min_num_bulk
= COMMAND_PORT
+ 1;
246 if (num_bulk_in
< min_num_bulk
|| num_bulk_out
< min_num_bulk
)
252 static int whiteheat_attach(struct usb_serial
*serial
)
254 struct usb_serial_port
*command_port
;
255 struct whiteheat_command_private
*command_info
;
256 struct whiteheat_hw_info
*hw_info
;
263 command_port
= serial
->port
[COMMAND_PORT
];
265 pipe
= usb_sndbulkpipe(serial
->dev
,
266 command_port
->bulk_out_endpointAddress
);
267 command
= kmalloc(2, GFP_KERNEL
);
269 goto no_command_buffer
;
270 command
[0] = WHITEHEAT_GET_HW_INFO
;
273 result
= kmalloc(sizeof(*hw_info
) + 1, GFP_KERNEL
);
275 goto no_result_buffer
;
277 * When the module is reloaded the firmware is still there and
278 * the endpoints are still in the usb core unchanged. This is the
279 * unlinking bug in disguise. Same for the call below.
281 usb_clear_halt(serial
->dev
, pipe
);
282 ret
= usb_bulk_msg(serial
->dev
, pipe
, command
, 2,
283 &alen
, COMMAND_TIMEOUT_MS
);
285 dev_err(&serial
->dev
->dev
, "%s: Couldn't send command [%d]\n",
286 serial
->type
->description
, ret
);
288 } else if (alen
!= 2) {
289 dev_err(&serial
->dev
->dev
, "%s: Send command incomplete [%d]\n",
290 serial
->type
->description
, alen
);
294 pipe
= usb_rcvbulkpipe(serial
->dev
,
295 command_port
->bulk_in_endpointAddress
);
296 /* See the comment on the usb_clear_halt() above */
297 usb_clear_halt(serial
->dev
, pipe
);
298 ret
= usb_bulk_msg(serial
->dev
, pipe
, result
,
299 sizeof(*hw_info
) + 1, &alen
, COMMAND_TIMEOUT_MS
);
301 dev_err(&serial
->dev
->dev
, "%s: Couldn't get results [%d]\n",
302 serial
->type
->description
, ret
);
304 } else if (alen
!= sizeof(*hw_info
) + 1) {
305 dev_err(&serial
->dev
->dev
, "%s: Get results incomplete [%d]\n",
306 serial
->type
->description
, alen
);
308 } else if (result
[0] != command
[0]) {
309 dev_err(&serial
->dev
->dev
, "%s: Command failed [%d]\n",
310 serial
->type
->description
, result
[0]);
314 hw_info
= (struct whiteheat_hw_info
*)&result
[1];
316 dev_info(&serial
->dev
->dev
, "%s: Firmware v%d.%02d\n",
317 serial
->type
->description
,
318 hw_info
->sw_major_rev
, hw_info
->sw_minor_rev
);
320 command_info
= kmalloc(sizeof(struct whiteheat_command_private
),
322 if (command_info
== NULL
) {
323 dev_err(&serial
->dev
->dev
,
324 "%s: Out of memory for port structures\n",
325 serial
->type
->description
);
326 goto no_command_private
;
329 mutex_init(&command_info
->mutex
);
330 command_info
->port_running
= 0;
331 init_waitqueue_head(&command_info
->wait_command
);
332 usb_set_serial_port_data(command_port
, command_info
);
333 command_port
->write_urb
->complete
= command_port_write_callback
;
334 command_port
->read_urb
->complete
= command_port_read_callback
;
341 /* Firmware likely not running */
342 dev_err(&serial
->dev
->dev
,
343 "%s: Unable to retrieve firmware version, try replugging\n",
344 serial
->type
->description
);
345 dev_err(&serial
->dev
->dev
,
346 "%s: If the firmware is not running (status led not blinking)\n",
347 serial
->type
->description
);
348 dev_err(&serial
->dev
->dev
,
349 "%s: please contact support@connecttech.com\n",
350 serial
->type
->description
);
363 static void whiteheat_release(struct usb_serial
*serial
)
365 struct usb_serial_port
*command_port
;
367 /* free up our private data for our command port */
368 command_port
= serial
->port
[COMMAND_PORT
];
369 kfree(usb_get_serial_port_data(command_port
));
372 static int whiteheat_port_probe(struct usb_serial_port
*port
)
374 struct whiteheat_private
*info
;
376 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
380 usb_set_serial_port_data(port
, info
);
385 static int whiteheat_port_remove(struct usb_serial_port
*port
)
387 struct whiteheat_private
*info
;
389 info
= usb_get_serial_port_data(port
);
395 static int whiteheat_open(struct tty_struct
*tty
, struct usb_serial_port
*port
)
399 retval
= start_command_port(port
->serial
);
403 /* send an open port command */
404 retval
= firm_open(port
);
406 stop_command_port(port
->serial
);
410 retval
= firm_purge(port
, WHITEHEAT_PURGE_RX
| WHITEHEAT_PURGE_TX
);
413 stop_command_port(port
->serial
);
418 firm_setup_port(tty
);
420 /* Work around HCD bugs */
421 usb_clear_halt(port
->serial
->dev
, port
->read_urb
->pipe
);
422 usb_clear_halt(port
->serial
->dev
, port
->write_urb
->pipe
);
424 retval
= usb_serial_generic_open(tty
, port
);
427 stop_command_port(port
->serial
);
435 static void whiteheat_close(struct usb_serial_port
*port
)
437 firm_report_tx_done(port
);
440 usb_serial_generic_close(port
);
442 stop_command_port(port
->serial
);
445 static int whiteheat_tiocmget(struct tty_struct
*tty
)
447 struct usb_serial_port
*port
= tty
->driver_data
;
448 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
449 unsigned int modem_signals
= 0;
451 firm_get_dtr_rts(port
);
452 if (info
->mcr
& UART_MCR_DTR
)
453 modem_signals
|= TIOCM_DTR
;
454 if (info
->mcr
& UART_MCR_RTS
)
455 modem_signals
|= TIOCM_RTS
;
457 return modem_signals
;
460 static int whiteheat_tiocmset(struct tty_struct
*tty
,
461 unsigned int set
, unsigned int clear
)
463 struct usb_serial_port
*port
= tty
->driver_data
;
464 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
467 info
->mcr
|= UART_MCR_RTS
;
469 info
->mcr
|= UART_MCR_DTR
;
471 if (clear
& TIOCM_RTS
)
472 info
->mcr
&= ~UART_MCR_RTS
;
473 if (clear
& TIOCM_DTR
)
474 info
->mcr
&= ~UART_MCR_DTR
;
476 firm_set_dtr(port
, info
->mcr
& UART_MCR_DTR
);
477 firm_set_rts(port
, info
->mcr
& UART_MCR_RTS
);
482 static int whiteheat_ioctl(struct tty_struct
*tty
,
483 unsigned int cmd
, unsigned long arg
)
485 struct usb_serial_port
*port
= tty
->driver_data
;
486 struct serial_struct serstruct
;
487 void __user
*user_arg
= (void __user
*)arg
;
489 dev_dbg(&port
->dev
, "%s - cmd 0x%.4x\n", __func__
, cmd
);
493 memset(&serstruct
, 0, sizeof(serstruct
));
494 serstruct
.type
= PORT_16654
;
495 serstruct
.line
= port
->minor
;
496 serstruct
.port
= port
->port_number
;
497 serstruct
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
498 serstruct
.xmit_fifo_size
= kfifo_size(&port
->write_fifo
);
499 serstruct
.custom_divisor
= 0;
500 serstruct
.baud_base
= 460800;
501 serstruct
.close_delay
= CLOSING_DELAY
;
502 serstruct
.closing_wait
= CLOSING_DELAY
;
504 if (copy_to_user(user_arg
, &serstruct
, sizeof(serstruct
)))
515 static void whiteheat_set_termios(struct tty_struct
*tty
,
516 struct usb_serial_port
*port
, struct ktermios
*old_termios
)
518 firm_setup_port(tty
);
521 static void whiteheat_break_ctl(struct tty_struct
*tty
, int break_state
)
523 struct usb_serial_port
*port
= tty
->driver_data
;
524 firm_set_break(port
, break_state
);
528 /*****************************************************************************
529 * Connect Tech's White Heat callback routines
530 *****************************************************************************/
531 static void command_port_write_callback(struct urb
*urb
)
533 int status
= urb
->status
;
536 dev_dbg(&urb
->dev
->dev
, "nonzero urb status: %d\n", status
);
542 static void command_port_read_callback(struct urb
*urb
)
544 struct usb_serial_port
*command_port
= urb
->context
;
545 struct whiteheat_command_private
*command_info
;
546 int status
= urb
->status
;
547 unsigned char *data
= urb
->transfer_buffer
;
550 command_info
= usb_get_serial_port_data(command_port
);
552 dev_dbg(&urb
->dev
->dev
, "%s - command_info is NULL, exiting.\n", __func__
);
555 if (!urb
->actual_length
) {
556 dev_dbg(&urb
->dev
->dev
, "%s - empty response, exiting.\n", __func__
);
560 dev_dbg(&urb
->dev
->dev
, "%s - nonzero urb status: %d\n", __func__
, status
);
561 if (status
!= -ENOENT
)
562 command_info
->command_finished
= WHITEHEAT_CMD_FAILURE
;
563 wake_up(&command_info
->wait_command
);
567 usb_serial_debug_data(&command_port
->dev
, __func__
, urb
->actual_length
, data
);
569 if (data
[0] == WHITEHEAT_CMD_COMPLETE
) {
570 command_info
->command_finished
= WHITEHEAT_CMD_COMPLETE
;
571 wake_up(&command_info
->wait_command
);
572 } else if (data
[0] == WHITEHEAT_CMD_FAILURE
) {
573 command_info
->command_finished
= WHITEHEAT_CMD_FAILURE
;
574 wake_up(&command_info
->wait_command
);
575 } else if (data
[0] == WHITEHEAT_EVENT
) {
576 /* These are unsolicited reports from the firmware, hence no
577 waiting command to wakeup */
578 dev_dbg(&urb
->dev
->dev
, "%s - event received\n", __func__
);
579 } else if ((data
[0] == WHITEHEAT_GET_DTR_RTS
) &&
580 (urb
->actual_length
- 1 <= sizeof(command_info
->result_buffer
))) {
581 memcpy(command_info
->result_buffer
, &data
[1],
582 urb
->actual_length
- 1);
583 command_info
->command_finished
= WHITEHEAT_CMD_COMPLETE
;
584 wake_up(&command_info
->wait_command
);
586 dev_dbg(&urb
->dev
->dev
, "%s - bad reply from firmware\n", __func__
);
588 /* Continue trying to always read */
589 result
= usb_submit_urb(command_port
->read_urb
, GFP_ATOMIC
);
591 dev_dbg(&urb
->dev
->dev
, "%s - failed resubmitting read urb, error %d\n",
596 /*****************************************************************************
597 * Connect Tech's White Heat firmware interface
598 *****************************************************************************/
599 static int firm_send_command(struct usb_serial_port
*port
, __u8 command
,
600 __u8
*data
, __u8 datasize
)
602 struct usb_serial_port
*command_port
;
603 struct whiteheat_command_private
*command_info
;
604 struct whiteheat_private
*info
;
605 struct device
*dev
= &port
->dev
;
606 __u8
*transfer_buffer
;
610 dev_dbg(dev
, "%s - command %d\n", __func__
, command
);
612 command_port
= port
->serial
->port
[COMMAND_PORT
];
613 command_info
= usb_get_serial_port_data(command_port
);
614 mutex_lock(&command_info
->mutex
);
615 command_info
->command_finished
= false;
617 transfer_buffer
= (__u8
*)command_port
->write_urb
->transfer_buffer
;
618 transfer_buffer
[0] = command
;
619 memcpy(&transfer_buffer
[1], data
, datasize
);
620 command_port
->write_urb
->transfer_buffer_length
= datasize
+ 1;
621 retval
= usb_submit_urb(command_port
->write_urb
, GFP_NOIO
);
623 dev_dbg(dev
, "%s - submit urb failed\n", __func__
);
627 /* wait for the command to complete */
628 t
= wait_event_timeout(command_info
->wait_command
,
629 (bool)command_info
->command_finished
, COMMAND_TIMEOUT
);
631 usb_kill_urb(command_port
->write_urb
);
633 if (command_info
->command_finished
== false) {
634 dev_dbg(dev
, "%s - command timed out.\n", __func__
);
639 if (command_info
->command_finished
== WHITEHEAT_CMD_FAILURE
) {
640 dev_dbg(dev
, "%s - command failed.\n", __func__
);
645 if (command_info
->command_finished
== WHITEHEAT_CMD_COMPLETE
) {
646 dev_dbg(dev
, "%s - command completed.\n", __func__
);
648 case WHITEHEAT_GET_DTR_RTS
:
649 info
= usb_get_serial_port_data(port
);
650 memcpy(&info
->mcr
, command_info
->result_buffer
,
651 sizeof(struct whiteheat_dr_info
));
656 mutex_unlock(&command_info
->mutex
);
661 static int firm_open(struct usb_serial_port
*port
)
663 struct whiteheat_simple open_command
;
665 open_command
.port
= port
->port_number
+ 1;
666 return firm_send_command(port
, WHITEHEAT_OPEN
,
667 (__u8
*)&open_command
, sizeof(open_command
));
671 static int firm_close(struct usb_serial_port
*port
)
673 struct whiteheat_simple close_command
;
675 close_command
.port
= port
->port_number
+ 1;
676 return firm_send_command(port
, WHITEHEAT_CLOSE
,
677 (__u8
*)&close_command
, sizeof(close_command
));
681 static void firm_setup_port(struct tty_struct
*tty
)
683 struct usb_serial_port
*port
= tty
->driver_data
;
684 struct device
*dev
= &port
->dev
;
685 struct whiteheat_port_settings port_settings
;
686 unsigned int cflag
= tty
->termios
.c_cflag
;
688 port_settings
.port
= port
->port_number
+ 1;
690 /* get the byte size */
691 switch (cflag
& CSIZE
) {
692 case CS5
: port_settings
.bits
= 5; break;
693 case CS6
: port_settings
.bits
= 6; break;
694 case CS7
: port_settings
.bits
= 7; break;
696 case CS8
: port_settings
.bits
= 8; break;
698 dev_dbg(dev
, "%s - data bits = %d\n", __func__
, port_settings
.bits
);
700 /* determine the parity */
704 port_settings
.parity
= WHITEHEAT_PAR_MARK
;
706 port_settings
.parity
= WHITEHEAT_PAR_SPACE
;
709 port_settings
.parity
= WHITEHEAT_PAR_ODD
;
711 port_settings
.parity
= WHITEHEAT_PAR_EVEN
;
713 port_settings
.parity
= WHITEHEAT_PAR_NONE
;
714 dev_dbg(dev
, "%s - parity = %c\n", __func__
, port_settings
.parity
);
716 /* figure out the stop bits requested */
718 port_settings
.stop
= 2;
720 port_settings
.stop
= 1;
721 dev_dbg(dev
, "%s - stop bits = %d\n", __func__
, port_settings
.stop
);
723 /* figure out the flow control settings */
725 port_settings
.hflow
= (WHITEHEAT_HFLOW_CTS
|
726 WHITEHEAT_HFLOW_RTS
);
728 port_settings
.hflow
= WHITEHEAT_HFLOW_NONE
;
729 dev_dbg(dev
, "%s - hardware flow control = %s %s %s %s\n", __func__
,
730 (port_settings
.hflow
& WHITEHEAT_HFLOW_CTS
) ? "CTS" : "",
731 (port_settings
.hflow
& WHITEHEAT_HFLOW_RTS
) ? "RTS" : "",
732 (port_settings
.hflow
& WHITEHEAT_HFLOW_DSR
) ? "DSR" : "",
733 (port_settings
.hflow
& WHITEHEAT_HFLOW_DTR
) ? "DTR" : "");
735 /* determine software flow control */
737 port_settings
.sflow
= WHITEHEAT_SFLOW_RXTX
;
739 port_settings
.sflow
= WHITEHEAT_SFLOW_NONE
;
740 dev_dbg(dev
, "%s - software flow control = %c\n", __func__
, port_settings
.sflow
);
742 port_settings
.xon
= START_CHAR(tty
);
743 port_settings
.xoff
= STOP_CHAR(tty
);
744 dev_dbg(dev
, "%s - XON = %2x, XOFF = %2x\n", __func__
, port_settings
.xon
, port_settings
.xoff
);
746 /* get the baud rate wanted */
747 port_settings
.baud
= tty_get_baud_rate(tty
);
748 dev_dbg(dev
, "%s - baud rate = %d\n", __func__
, port_settings
.baud
);
750 /* fixme: should set validated settings */
751 tty_encode_baud_rate(tty
, port_settings
.baud
, port_settings
.baud
);
752 /* handle any settings that aren't specified in the tty structure */
753 port_settings
.lloop
= 0;
755 /* now send the message to the device */
756 firm_send_command(port
, WHITEHEAT_SETUP_PORT
,
757 (__u8
*)&port_settings
, sizeof(port_settings
));
761 static int firm_set_rts(struct usb_serial_port
*port
, __u8 onoff
)
763 struct whiteheat_set_rdb rts_command
;
765 rts_command
.port
= port
->port_number
+ 1;
766 rts_command
.state
= onoff
;
767 return firm_send_command(port
, WHITEHEAT_SET_RTS
,
768 (__u8
*)&rts_command
, sizeof(rts_command
));
772 static int firm_set_dtr(struct usb_serial_port
*port
, __u8 onoff
)
774 struct whiteheat_set_rdb dtr_command
;
776 dtr_command
.port
= port
->port_number
+ 1;
777 dtr_command
.state
= onoff
;
778 return firm_send_command(port
, WHITEHEAT_SET_DTR
,
779 (__u8
*)&dtr_command
, sizeof(dtr_command
));
783 static int firm_set_break(struct usb_serial_port
*port
, __u8 onoff
)
785 struct whiteheat_set_rdb break_command
;
787 break_command
.port
= port
->port_number
+ 1;
788 break_command
.state
= onoff
;
789 return firm_send_command(port
, WHITEHEAT_SET_BREAK
,
790 (__u8
*)&break_command
, sizeof(break_command
));
794 static int firm_purge(struct usb_serial_port
*port
, __u8 rxtx
)
796 struct whiteheat_purge purge_command
;
798 purge_command
.port
= port
->port_number
+ 1;
799 purge_command
.what
= rxtx
;
800 return firm_send_command(port
, WHITEHEAT_PURGE
,
801 (__u8
*)&purge_command
, sizeof(purge_command
));
805 static int firm_get_dtr_rts(struct usb_serial_port
*port
)
807 struct whiteheat_simple get_dr_command
;
809 get_dr_command
.port
= port
->port_number
+ 1;
810 return firm_send_command(port
, WHITEHEAT_GET_DTR_RTS
,
811 (__u8
*)&get_dr_command
, sizeof(get_dr_command
));
815 static int firm_report_tx_done(struct usb_serial_port
*port
)
817 struct whiteheat_simple close_command
;
819 close_command
.port
= port
->port_number
+ 1;
820 return firm_send_command(port
, WHITEHEAT_REPORT_TX_DONE
,
821 (__u8
*)&close_command
, sizeof(close_command
));
825 /*****************************************************************************
826 * Connect Tech's White Heat utility functions
827 *****************************************************************************/
828 static int start_command_port(struct usb_serial
*serial
)
830 struct usb_serial_port
*command_port
;
831 struct whiteheat_command_private
*command_info
;
834 command_port
= serial
->port
[COMMAND_PORT
];
835 command_info
= usb_get_serial_port_data(command_port
);
836 mutex_lock(&command_info
->mutex
);
837 if (!command_info
->port_running
) {
838 /* Work around HCD bugs */
839 usb_clear_halt(serial
->dev
, command_port
->read_urb
->pipe
);
841 retval
= usb_submit_urb(command_port
->read_urb
, GFP_KERNEL
);
843 dev_err(&serial
->dev
->dev
,
844 "%s - failed submitting read urb, error %d\n",
849 command_info
->port_running
++;
852 mutex_unlock(&command_info
->mutex
);
857 static void stop_command_port(struct usb_serial
*serial
)
859 struct usb_serial_port
*command_port
;
860 struct whiteheat_command_private
*command_info
;
862 command_port
= serial
->port
[COMMAND_PORT
];
863 command_info
= usb_get_serial_port_data(command_port
);
864 mutex_lock(&command_info
->mutex
);
865 command_info
->port_running
--;
866 if (!command_info
->port_running
)
867 usb_kill_urb(command_port
->read_urb
);
868 mutex_unlock(&command_info
->mutex
);
871 module_usb_serial_driver(serial_drivers
, id_table_combined
);
873 MODULE_AUTHOR(DRIVER_AUTHOR
);
874 MODULE_DESCRIPTION(DRIVER_DESC
);
875 MODULE_LICENSE("GPL");
877 MODULE_FIRMWARE("whiteheat.fw");
878 MODULE_FIRMWARE("whiteheat_loader.fw");