19 #include <linux/kernel.h>
20 #include <linux/errno.h>
22 #include <linux/slab.h>
23 #include <linux/tty.h>
26 #include <linux/module.h>
30 #include <asm/termbits.h>
33 #include <linux/serial.h>
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
64 static const struct usb_device_id id_table_prerenumeration[] = {
88 static int whiteheat_open(
struct tty_struct *tty,
91 static int whiteheat_ioctl(
struct tty_struct *tty,
92 unsigned int cmd,
unsigned long arg);
93 static void whiteheat_set_termios(
struct tty_struct *tty,
95 static int whiteheat_tiocmget(
struct tty_struct *tty);
96 static int whiteheat_tiocmset(
struct tty_struct *tty,
97 unsigned int set,
unsigned int clear);
98 static void whiteheat_break_ctl(
struct tty_struct *tty,
int break_state);
103 .name =
"whiteheatnofirm",
105 .description =
"Connect Tech - WhiteHEAT - (prerenumeration)",
106 .id_table = id_table_prerenumeration,
108 .probe = whiteheat_firmware_download,
109 .attach = whiteheat_firmware_attach,
117 .description =
"Connect Tech - WhiteHEAT",
118 .id_table = id_table_std,
120 .attach = whiteheat_attach,
121 .release = whiteheat_release,
122 .port_probe = whiteheat_port_probe,
123 .port_remove = whiteheat_port_remove,
124 .open = whiteheat_open,
125 .close = whiteheat_close,
126 .ioctl = whiteheat_ioctl,
127 .set_termios = whiteheat_set_termios,
128 .break_ctl = whiteheat_break_ctl,
129 .tiocmget = whiteheat_tiocmget,
130 .tiocmset = whiteheat_tiocmset,
136 &whiteheat_fake_device, &whiteheat_device,
NULL
157 static void command_port_write_callback(
struct urb *
urb);
158 static void command_port_read_callback(
struct urb *
urb);
164 static void firm_setup_port(
struct tty_struct *tty);
173 #define COMMAND_PORT 4
174 #define COMMAND_TIMEOUT (2*HZ)
175 #define COMMAND_TIMEOUT_MS 2000
176 #define CLOSING_DELAY (30 * HZ)
234 pipe = usb_sndbulkpipe(serial->
dev,
238 goto no_command_buffer;
244 goto no_result_buffer;
254 dev_err(&serial->
dev->dev,
"%s: Couldn't send command [%d]\n",
255 serial->
type->description, ret);
257 }
else if (alen != 2) {
258 dev_err(&serial->
dev->dev,
"%s: Send command incomplete [%d]\n",
259 serial->
type->description, alen);
263 pipe = usb_rcvbulkpipe(serial->
dev,
270 dev_err(&serial->
dev->dev,
"%s: Couldn't get results [%d]\n",
271 serial->
type->description, ret);
273 }
else if (alen !=
sizeof(*hw_info) + 1) {
274 dev_err(&serial->
dev->dev,
"%s: Get results incomplete [%d]\n",
275 serial->
type->description, alen);
277 }
else if (result[0] != command[0]) {
278 dev_err(&serial->
dev->dev,
"%s: Command failed [%d]\n",
279 serial->
type->description, result[0]);
285 dev_info(&serial->
dev->dev,
"%s: Firmware v%d.%02d\n",
286 serial->
type->description,
291 if (command_info ==
NULL) {
293 "%s: Out of memory for port structures\n",
294 serial->
type->description);
295 goto no_command_private;
301 usb_set_serial_port_data(command_port, command_info);
302 command_port->
write_urb->complete = command_port_write_callback;
303 command_port->
read_urb->complete = command_port_read_callback;
312 "%s: Unable to retrieve firmware version, try replugging\n",
313 serial->
type->description);
315 "%s: If the firmware is not running (status led not blinking)\n",
316 serial->
type->description);
319 serial->
type->description);
332 static void whiteheat_release(
struct usb_serial *serial)
338 kfree(usb_get_serial_port_data(command_port));
349 usb_set_serial_port_data(port, info);
358 info = usb_get_serial_port_data(port);
368 retval = start_command_port(port->
serial);
373 retval = firm_open(port);
375 stop_command_port(port->
serial);
382 stop_command_port(port->
serial);
387 firm_setup_port(tty);
396 stop_command_port(port->
serial);
406 firm_report_tx_done(port);
411 stop_command_port(port->
serial);
414 static int whiteheat_tiocmget(
struct tty_struct *tty)
418 unsigned int modem_signals = 0;
420 firm_get_dtr_rts(port);
426 return modem_signals;
429 static int whiteheat_tiocmset(
struct tty_struct *tty,
430 unsigned int set,
unsigned int clear)
451 static int whiteheat_ioctl(
struct tty_struct *tty,
452 unsigned int cmd,
unsigned long arg)
458 dev_dbg(&port->
dev,
"%s - cmd 0x%.4x\n", __func__, cmd);
462 memset(&serstruct, 0,
sizeof(serstruct));
464 serstruct.line = port->
serial->minor;
465 serstruct.port = port->
number;
468 serstruct.custom_divisor = 0;
469 serstruct.baud_base = 460800;
473 if (
copy_to_user(user_arg, &serstruct,
sizeof(serstruct)))
484 static void whiteheat_set_termios(
struct tty_struct *tty,
487 firm_setup_port(tty);
490 static void whiteheat_break_ctl(
struct tty_struct *tty,
int break_state)
493 firm_set_break(port, break_state);
500 static void command_port_write_callback(
struct urb *
urb)
505 dev_dbg(&urb->dev->dev,
"nonzero urb status: %d\n", status);
511 static void command_port_read_callback(
struct urb *urb)
515 int status = urb->status;
516 unsigned char *
data = urb->transfer_buffer;
519 command_info = usb_get_serial_port_data(command_port);
521 dev_dbg(&urb->dev->dev,
"%s - command_info is NULL, exiting.\n", __func__);
525 dev_dbg(&urb->dev->dev,
"%s - nonzero urb status: %d\n", __func__, status);
532 usb_serial_debug_data(&command_port->
dev, __func__, urb->actual_length, data);
543 dev_dbg(&urb->dev->dev,
"%s - event received\n", __func__);
546 urb->actual_length - 1);
550 dev_dbg(&urb->dev->dev,
"%s - bad reply from firmware\n", __func__);
555 dev_dbg(&urb->dev->dev,
"%s - failed resubmitting read urb, error %d\n",
574 dev_dbg(dev,
"%s - command %d\n", __func__, command);
577 command_info = usb_get_serial_port_data(command_port);
581 transfer_buffer = (
__u8 *)command_port->
write_urb->transfer_buffer;
582 transfer_buffer[0] = command;
583 memcpy(&transfer_buffer[1], data, datasize);
584 command_port->
write_urb->transfer_buffer_length = datasize + 1;
587 dev_dbg(dev,
"%s - submit urb failed\n", __func__);
598 dev_dbg(dev,
"%s - command timed out.\n", __func__);
604 dev_dbg(dev,
"%s - command failed.\n", __func__);
610 dev_dbg(dev,
"%s - command completed.\n", __func__);
613 info = usb_get_serial_port_data(port);
631 (
__u8 *)&open_command,
sizeof(open_command));
641 (
__u8 *)&close_command,
sizeof(close_command));
645 static void firm_setup_port(
struct tty_struct *tty)
650 unsigned int cflag = tty->termios.c_cflag;
655 switch (cflag &
CSIZE) {
656 case CS5: port_settings.bits = 5;
break;
657 case CS6: port_settings.bits = 6;
break;
658 case CS7: port_settings.bits = 7;
break;
660 case CS8: port_settings.bits = 8;
break;
662 dev_dbg(dev,
"%s - data bits = %d\n", __func__, port_settings.bits);
678 dev_dbg(dev,
"%s - parity = %c\n", __func__, port_settings.parity);
682 port_settings.stop = 2;
684 port_settings.stop = 1;
685 dev_dbg(dev,
"%s - stop bits = %d\n", __func__, port_settings.stop);
693 dev_dbg(dev,
"%s - hardware flow control = %s %s %s %s\n", __func__,
704 dev_dbg(dev,
"%s - software flow control = %c\n", __func__, port_settings.sflow);
708 dev_dbg(dev,
"%s - XON = %2x, XOFF = %2x\n", __func__, port_settings.xon, port_settings.xoff);
712 dev_dbg(dev,
"%s - baud rate = %d\n", __func__, port_settings.baud);
717 port_settings.lloop = 0;
721 (
__u8 *)&port_settings,
sizeof(port_settings));
730 rts_command.state =
onoff;
732 (
__u8 *)&rts_command,
sizeof(rts_command));
741 dtr_command.state =
onoff;
743 (
__u8 *)&dtr_command,
sizeof(dtr_command));
752 break_command.state =
onoff;
754 (
__u8 *)&break_command,
sizeof(break_command));
763 purge_command.what =
rxtx;
765 (
__u8 *)&purge_command,
sizeof(purge_command));
775 (
__u8 *)&get_dr_command,
sizeof(get_dr_command));
785 (
__u8 *)&close_command,
sizeof(close_command));
792 static int start_command_port(
struct usb_serial *serial)
799 command_info = usb_get_serial_port_data(command_port);
808 "%s - failed submitting read urb, error %d\n",
821 static void stop_command_port(
struct usb_serial *serial)
827 command_info = usb_get_serial_port_data(command_port);