0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/kernel.h>
0016 #include <linux/errno.h>
0017 #include <linux/slab.h>
0018 #include <linux/tty.h>
0019 #include <linux/tty_driver.h>
0020 #include <linux/tty_flip.h>
0021 #include <linux/module.h>
0022 #include <linux/spinlock.h>
0023 #include <linux/mutex.h>
0024 #include <linux/uaccess.h>
0025 #include <asm/termbits.h>
0026 #include <linux/usb.h>
0027 #include <linux/serial_reg.h>
0028 #include <linux/serial.h>
0029 #include <linux/usb/serial.h>
0030 #include <linux/usb/ezusb.h>
0031 #include "whiteheat.h" /* WhiteHEAT specific commands */
0032
0033
0034
0035
0036 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
0037 #define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
0038
0039 #define CONNECT_TECH_VENDOR_ID 0x0710
0040 #define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
0041 #define CONNECT_TECH_WHITE_HEAT_ID 0x8001
0042
0043
0044
0045
0046
0047
0048
0049
0050 static const struct usb_device_id id_table_std[] = {
0051 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
0052 { }
0053 };
0054
0055 static const struct usb_device_id id_table_prerenumeration[] = {
0056 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
0057 { }
0058 };
0059
0060 static const struct usb_device_id id_table_combined[] = {
0061 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
0062 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
0063 { }
0064 };
0065
0066 MODULE_DEVICE_TABLE(usb, id_table_combined);
0067
0068
0069
0070 static int whiteheat_firmware_download(struct usb_serial *serial,
0071 const struct usb_device_id *id);
0072 static int whiteheat_firmware_attach(struct usb_serial *serial);
0073
0074
0075 static int whiteheat_attach(struct usb_serial *serial);
0076 static void whiteheat_release(struct usb_serial *serial);
0077 static int whiteheat_port_probe(struct usb_serial_port *port);
0078 static void whiteheat_port_remove(struct usb_serial_port *port);
0079 static int whiteheat_open(struct tty_struct *tty,
0080 struct usb_serial_port *port);
0081 static void whiteheat_close(struct usb_serial_port *port);
0082 static void whiteheat_get_serial(struct tty_struct *tty,
0083 struct serial_struct *ss);
0084 static void whiteheat_set_termios(struct tty_struct *tty,
0085 struct usb_serial_port *port, struct ktermios *old);
0086 static int whiteheat_tiocmget(struct tty_struct *tty);
0087 static int whiteheat_tiocmset(struct tty_struct *tty,
0088 unsigned int set, unsigned int clear);
0089 static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
0090
0091 static struct usb_serial_driver whiteheat_fake_device = {
0092 .driver = {
0093 .owner = THIS_MODULE,
0094 .name = "whiteheatnofirm",
0095 },
0096 .description = "Connect Tech - WhiteHEAT - (prerenumeration)",
0097 .id_table = id_table_prerenumeration,
0098 .num_ports = 1,
0099 .probe = whiteheat_firmware_download,
0100 .attach = whiteheat_firmware_attach,
0101 };
0102
0103 static struct usb_serial_driver whiteheat_device = {
0104 .driver = {
0105 .owner = THIS_MODULE,
0106 .name = "whiteheat",
0107 },
0108 .description = "Connect Tech - WhiteHEAT",
0109 .id_table = id_table_std,
0110 .num_ports = 4,
0111 .num_bulk_in = 5,
0112 .num_bulk_out = 5,
0113 .attach = whiteheat_attach,
0114 .release = whiteheat_release,
0115 .port_probe = whiteheat_port_probe,
0116 .port_remove = whiteheat_port_remove,
0117 .open = whiteheat_open,
0118 .close = whiteheat_close,
0119 .get_serial = whiteheat_get_serial,
0120 .set_termios = whiteheat_set_termios,
0121 .break_ctl = whiteheat_break_ctl,
0122 .tiocmget = whiteheat_tiocmget,
0123 .tiocmset = whiteheat_tiocmset,
0124 .throttle = usb_serial_generic_throttle,
0125 .unthrottle = usb_serial_generic_unthrottle,
0126 };
0127
0128 static struct usb_serial_driver * const serial_drivers[] = {
0129 &whiteheat_fake_device, &whiteheat_device, NULL
0130 };
0131
0132 struct whiteheat_command_private {
0133 struct mutex mutex;
0134 __u8 port_running;
0135 __u8 command_finished;
0136 wait_queue_head_t wait_command;
0137
0138
0139 __u8 result_buffer[64];
0140 };
0141
0142 struct whiteheat_private {
0143 __u8 mcr;
0144 };
0145
0146
0147
0148 static int start_command_port(struct usb_serial *serial);
0149 static void stop_command_port(struct usb_serial *serial);
0150 static void command_port_write_callback(struct urb *urb);
0151 static void command_port_read_callback(struct urb *urb);
0152
0153 static int firm_send_command(struct usb_serial_port *port, __u8 command,
0154 __u8 *data, __u8 datasize);
0155 static int firm_open(struct usb_serial_port *port);
0156 static int firm_close(struct usb_serial_port *port);
0157 static void firm_setup_port(struct tty_struct *tty);
0158 static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
0159 static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
0160 static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
0161 static int firm_purge(struct usb_serial_port *port, __u8 rxtx);
0162 static int firm_get_dtr_rts(struct usb_serial_port *port);
0163 static int firm_report_tx_done(struct usb_serial_port *port);
0164
0165
0166 #define COMMAND_PORT 4
0167 #define COMMAND_TIMEOUT (2*HZ)
0168 #define COMMAND_TIMEOUT_MS 2000
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 static int whiteheat_firmware_download(struct usb_serial *serial,
0189 const struct usb_device_id *id)
0190 {
0191 int response;
0192
0193 response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat_loader.fw");
0194 if (response >= 0) {
0195 response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat.fw");
0196 if (response >= 0)
0197 return 0;
0198 }
0199 return -ENOENT;
0200 }
0201
0202
0203 static int whiteheat_firmware_attach(struct usb_serial *serial)
0204 {
0205
0206 return 1;
0207 }
0208
0209
0210
0211
0212
0213
0214 static int whiteheat_attach(struct usb_serial *serial)
0215 {
0216 struct usb_serial_port *command_port;
0217 struct whiteheat_command_private *command_info;
0218 struct whiteheat_hw_info *hw_info;
0219 int pipe;
0220 int ret;
0221 int alen;
0222 __u8 *command;
0223 __u8 *result;
0224
0225 command_port = serial->port[COMMAND_PORT];
0226
0227 pipe = usb_sndbulkpipe(serial->dev,
0228 command_port->bulk_out_endpointAddress);
0229 command = kmalloc(2, GFP_KERNEL);
0230 if (!command)
0231 goto no_command_buffer;
0232 command[0] = WHITEHEAT_GET_HW_INFO;
0233 command[1] = 0;
0234
0235 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
0236 if (!result)
0237 goto no_result_buffer;
0238
0239
0240
0241
0242
0243 usb_clear_halt(serial->dev, pipe);
0244 ret = usb_bulk_msg(serial->dev, pipe, command, 2,
0245 &alen, COMMAND_TIMEOUT_MS);
0246 if (ret) {
0247 dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
0248 serial->type->description, ret);
0249 goto no_firmware;
0250 } else if (alen != 2) {
0251 dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
0252 serial->type->description, alen);
0253 goto no_firmware;
0254 }
0255
0256 pipe = usb_rcvbulkpipe(serial->dev,
0257 command_port->bulk_in_endpointAddress);
0258
0259 usb_clear_halt(serial->dev, pipe);
0260 ret = usb_bulk_msg(serial->dev, pipe, result,
0261 sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
0262 if (ret) {
0263 dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
0264 serial->type->description, ret);
0265 goto no_firmware;
0266 } else if (alen != sizeof(*hw_info) + 1) {
0267 dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n",
0268 serial->type->description, alen);
0269 goto no_firmware;
0270 } else if (result[0] != command[0]) {
0271 dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
0272 serial->type->description, result[0]);
0273 goto no_firmware;
0274 }
0275
0276 hw_info = (struct whiteheat_hw_info *)&result[1];
0277
0278 dev_info(&serial->dev->dev, "%s: Firmware v%d.%02d\n",
0279 serial->type->description,
0280 hw_info->sw_major_rev, hw_info->sw_minor_rev);
0281
0282 command_info = kmalloc(sizeof(struct whiteheat_command_private),
0283 GFP_KERNEL);
0284 if (!command_info)
0285 goto no_command_private;
0286
0287 mutex_init(&command_info->mutex);
0288 command_info->port_running = 0;
0289 init_waitqueue_head(&command_info->wait_command);
0290 usb_set_serial_port_data(command_port, command_info);
0291 command_port->write_urb->complete = command_port_write_callback;
0292 command_port->read_urb->complete = command_port_read_callback;
0293 kfree(result);
0294 kfree(command);
0295
0296 return 0;
0297
0298 no_firmware:
0299
0300 dev_err(&serial->dev->dev,
0301 "%s: Unable to retrieve firmware version, try replugging\n",
0302 serial->type->description);
0303 dev_err(&serial->dev->dev,
0304 "%s: If the firmware is not running (status led not blinking)\n",
0305 serial->type->description);
0306 dev_err(&serial->dev->dev,
0307 "%s: please contact support@connecttech.com\n",
0308 serial->type->description);
0309 kfree(result);
0310 kfree(command);
0311 return -ENODEV;
0312
0313 no_command_private:
0314 kfree(result);
0315 no_result_buffer:
0316 kfree(command);
0317 no_command_buffer:
0318 return -ENOMEM;
0319 }
0320
0321 static void whiteheat_release(struct usb_serial *serial)
0322 {
0323 struct usb_serial_port *command_port;
0324
0325
0326 command_port = serial->port[COMMAND_PORT];
0327 kfree(usb_get_serial_port_data(command_port));
0328 }
0329
0330 static int whiteheat_port_probe(struct usb_serial_port *port)
0331 {
0332 struct whiteheat_private *info;
0333
0334 info = kzalloc(sizeof(*info), GFP_KERNEL);
0335 if (!info)
0336 return -ENOMEM;
0337
0338 usb_set_serial_port_data(port, info);
0339
0340 return 0;
0341 }
0342
0343 static void whiteheat_port_remove(struct usb_serial_port *port)
0344 {
0345 struct whiteheat_private *info;
0346
0347 info = usb_get_serial_port_data(port);
0348 kfree(info);
0349 }
0350
0351 static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
0352 {
0353 int retval;
0354
0355 retval = start_command_port(port->serial);
0356 if (retval)
0357 goto exit;
0358
0359
0360 retval = firm_open(port);
0361 if (retval) {
0362 stop_command_port(port->serial);
0363 goto exit;
0364 }
0365
0366 retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
0367 if (retval) {
0368 firm_close(port);
0369 stop_command_port(port->serial);
0370 goto exit;
0371 }
0372
0373 if (tty)
0374 firm_setup_port(tty);
0375
0376
0377 usb_clear_halt(port->serial->dev, port->read_urb->pipe);
0378 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
0379
0380 retval = usb_serial_generic_open(tty, port);
0381 if (retval) {
0382 firm_close(port);
0383 stop_command_port(port->serial);
0384 goto exit;
0385 }
0386 exit:
0387 return retval;
0388 }
0389
0390
0391 static void whiteheat_close(struct usb_serial_port *port)
0392 {
0393 firm_report_tx_done(port);
0394 firm_close(port);
0395
0396 usb_serial_generic_close(port);
0397
0398 stop_command_port(port->serial);
0399 }
0400
0401 static int whiteheat_tiocmget(struct tty_struct *tty)
0402 {
0403 struct usb_serial_port *port = tty->driver_data;
0404 struct whiteheat_private *info = usb_get_serial_port_data(port);
0405 unsigned int modem_signals = 0;
0406
0407 firm_get_dtr_rts(port);
0408 if (info->mcr & UART_MCR_DTR)
0409 modem_signals |= TIOCM_DTR;
0410 if (info->mcr & UART_MCR_RTS)
0411 modem_signals |= TIOCM_RTS;
0412
0413 return modem_signals;
0414 }
0415
0416 static int whiteheat_tiocmset(struct tty_struct *tty,
0417 unsigned int set, unsigned int clear)
0418 {
0419 struct usb_serial_port *port = tty->driver_data;
0420 struct whiteheat_private *info = usb_get_serial_port_data(port);
0421
0422 if (set & TIOCM_RTS)
0423 info->mcr |= UART_MCR_RTS;
0424 if (set & TIOCM_DTR)
0425 info->mcr |= UART_MCR_DTR;
0426
0427 if (clear & TIOCM_RTS)
0428 info->mcr &= ~UART_MCR_RTS;
0429 if (clear & TIOCM_DTR)
0430 info->mcr &= ~UART_MCR_DTR;
0431
0432 firm_set_dtr(port, info->mcr & UART_MCR_DTR);
0433 firm_set_rts(port, info->mcr & UART_MCR_RTS);
0434 return 0;
0435 }
0436
0437
0438 static void whiteheat_get_serial(struct tty_struct *tty, struct serial_struct *ss)
0439 {
0440 ss->baud_base = 460800;
0441 }
0442
0443
0444 static void whiteheat_set_termios(struct tty_struct *tty,
0445 struct usb_serial_port *port, struct ktermios *old_termios)
0446 {
0447 firm_setup_port(tty);
0448 }
0449
0450 static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
0451 {
0452 struct usb_serial_port *port = tty->driver_data;
0453 firm_set_break(port, break_state);
0454 }
0455
0456
0457
0458
0459
0460 static void command_port_write_callback(struct urb *urb)
0461 {
0462 int status = urb->status;
0463
0464 if (status) {
0465 dev_dbg(&urb->dev->dev, "nonzero urb status: %d\n", status);
0466 return;
0467 }
0468 }
0469
0470
0471 static void command_port_read_callback(struct urb *urb)
0472 {
0473 struct usb_serial_port *command_port = urb->context;
0474 struct whiteheat_command_private *command_info;
0475 int status = urb->status;
0476 unsigned char *data = urb->transfer_buffer;
0477 int result;
0478
0479 command_info = usb_get_serial_port_data(command_port);
0480 if (!command_info) {
0481 dev_dbg(&urb->dev->dev, "%s - command_info is NULL, exiting.\n", __func__);
0482 return;
0483 }
0484 if (!urb->actual_length) {
0485 dev_dbg(&urb->dev->dev, "%s - empty response, exiting.\n", __func__);
0486 return;
0487 }
0488 if (status) {
0489 dev_dbg(&urb->dev->dev, "%s - nonzero urb status: %d\n", __func__, status);
0490 if (status != -ENOENT)
0491 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
0492 wake_up(&command_info->wait_command);
0493 return;
0494 }
0495
0496 usb_serial_debug_data(&command_port->dev, __func__, urb->actual_length, data);
0497
0498 if (data[0] == WHITEHEAT_CMD_COMPLETE) {
0499 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
0500 wake_up(&command_info->wait_command);
0501 } else if (data[0] == WHITEHEAT_CMD_FAILURE) {
0502 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
0503 wake_up(&command_info->wait_command);
0504 } else if (data[0] == WHITEHEAT_EVENT) {
0505
0506
0507 dev_dbg(&urb->dev->dev, "%s - event received\n", __func__);
0508 } else if ((data[0] == WHITEHEAT_GET_DTR_RTS) &&
0509 (urb->actual_length - 1 <= sizeof(command_info->result_buffer))) {
0510 memcpy(command_info->result_buffer, &data[1],
0511 urb->actual_length - 1);
0512 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
0513 wake_up(&command_info->wait_command);
0514 } else
0515 dev_dbg(&urb->dev->dev, "%s - bad reply from firmware\n", __func__);
0516
0517
0518 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
0519 if (result)
0520 dev_dbg(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n",
0521 __func__, result);
0522 }
0523
0524
0525
0526
0527
0528 static int firm_send_command(struct usb_serial_port *port, __u8 command,
0529 __u8 *data, __u8 datasize)
0530 {
0531 struct usb_serial_port *command_port;
0532 struct whiteheat_command_private *command_info;
0533 struct whiteheat_private *info;
0534 struct device *dev = &port->dev;
0535 __u8 *transfer_buffer;
0536 int retval = 0;
0537 int t;
0538
0539 dev_dbg(dev, "%s - command %d\n", __func__, command);
0540
0541 command_port = port->serial->port[COMMAND_PORT];
0542 command_info = usb_get_serial_port_data(command_port);
0543
0544 if (command_port->bulk_out_size < datasize + 1)
0545 return -EIO;
0546
0547 mutex_lock(&command_info->mutex);
0548 command_info->command_finished = false;
0549
0550 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
0551 transfer_buffer[0] = command;
0552 memcpy(&transfer_buffer[1], data, datasize);
0553 command_port->write_urb->transfer_buffer_length = datasize + 1;
0554 retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
0555 if (retval) {
0556 dev_dbg(dev, "%s - submit urb failed\n", __func__);
0557 goto exit;
0558 }
0559
0560
0561 t = wait_event_timeout(command_info->wait_command,
0562 (bool)command_info->command_finished, COMMAND_TIMEOUT);
0563 if (!t)
0564 usb_kill_urb(command_port->write_urb);
0565
0566 if (command_info->command_finished == false) {
0567 dev_dbg(dev, "%s - command timed out.\n", __func__);
0568 retval = -ETIMEDOUT;
0569 goto exit;
0570 }
0571
0572 if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
0573 dev_dbg(dev, "%s - command failed.\n", __func__);
0574 retval = -EIO;
0575 goto exit;
0576 }
0577
0578 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
0579 dev_dbg(dev, "%s - command completed.\n", __func__);
0580 switch (command) {
0581 case WHITEHEAT_GET_DTR_RTS:
0582 info = usb_get_serial_port_data(port);
0583 info->mcr = command_info->result_buffer[0];
0584 break;
0585 }
0586 }
0587 exit:
0588 mutex_unlock(&command_info->mutex);
0589 return retval;
0590 }
0591
0592
0593 static int firm_open(struct usb_serial_port *port)
0594 {
0595 struct whiteheat_simple open_command;
0596
0597 open_command.port = port->port_number + 1;
0598 return firm_send_command(port, WHITEHEAT_OPEN,
0599 (__u8 *)&open_command, sizeof(open_command));
0600 }
0601
0602
0603 static int firm_close(struct usb_serial_port *port)
0604 {
0605 struct whiteheat_simple close_command;
0606
0607 close_command.port = port->port_number + 1;
0608 return firm_send_command(port, WHITEHEAT_CLOSE,
0609 (__u8 *)&close_command, sizeof(close_command));
0610 }
0611
0612
0613 static void firm_setup_port(struct tty_struct *tty)
0614 {
0615 struct usb_serial_port *port = tty->driver_data;
0616 struct device *dev = &port->dev;
0617 struct whiteheat_port_settings port_settings;
0618 unsigned int cflag = tty->termios.c_cflag;
0619 speed_t baud;
0620
0621 port_settings.port = port->port_number + 1;
0622
0623 port_settings.bits = tty_get_char_size(cflag);
0624 dev_dbg(dev, "%s - data bits = %d\n", __func__, port_settings.bits);
0625
0626
0627 if (cflag & PARENB)
0628 if (cflag & CMSPAR)
0629 if (cflag & PARODD)
0630 port_settings.parity = WHITEHEAT_PAR_MARK;
0631 else
0632 port_settings.parity = WHITEHEAT_PAR_SPACE;
0633 else
0634 if (cflag & PARODD)
0635 port_settings.parity = WHITEHEAT_PAR_ODD;
0636 else
0637 port_settings.parity = WHITEHEAT_PAR_EVEN;
0638 else
0639 port_settings.parity = WHITEHEAT_PAR_NONE;
0640 dev_dbg(dev, "%s - parity = %c\n", __func__, port_settings.parity);
0641
0642
0643 if (cflag & CSTOPB)
0644 port_settings.stop = 2;
0645 else
0646 port_settings.stop = 1;
0647 dev_dbg(dev, "%s - stop bits = %d\n", __func__, port_settings.stop);
0648
0649
0650 if (cflag & CRTSCTS)
0651 port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
0652 WHITEHEAT_HFLOW_RTS);
0653 else
0654 port_settings.hflow = WHITEHEAT_HFLOW_NONE;
0655 dev_dbg(dev, "%s - hardware flow control = %s %s %s %s\n", __func__,
0656 (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
0657 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
0658 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
0659 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
0660
0661
0662 if (I_IXOFF(tty))
0663 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
0664 else
0665 port_settings.sflow = WHITEHEAT_SFLOW_NONE;
0666 dev_dbg(dev, "%s - software flow control = %c\n", __func__, port_settings.sflow);
0667
0668 port_settings.xon = START_CHAR(tty);
0669 port_settings.xoff = STOP_CHAR(tty);
0670 dev_dbg(dev, "%s - XON = %2x, XOFF = %2x\n", __func__, port_settings.xon, port_settings.xoff);
0671
0672
0673 baud = tty_get_baud_rate(tty);
0674 port_settings.baud = cpu_to_le32(baud);
0675 dev_dbg(dev, "%s - baud rate = %u\n", __func__, baud);
0676
0677
0678 tty_encode_baud_rate(tty, baud, baud);
0679
0680
0681 port_settings.lloop = 0;
0682
0683
0684 firm_send_command(port, WHITEHEAT_SETUP_PORT,
0685 (__u8 *)&port_settings, sizeof(port_settings));
0686 }
0687
0688
0689 static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
0690 {
0691 struct whiteheat_set_rdb rts_command;
0692
0693 rts_command.port = port->port_number + 1;
0694 rts_command.state = onoff;
0695 return firm_send_command(port, WHITEHEAT_SET_RTS,
0696 (__u8 *)&rts_command, sizeof(rts_command));
0697 }
0698
0699
0700 static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
0701 {
0702 struct whiteheat_set_rdb dtr_command;
0703
0704 dtr_command.port = port->port_number + 1;
0705 dtr_command.state = onoff;
0706 return firm_send_command(port, WHITEHEAT_SET_DTR,
0707 (__u8 *)&dtr_command, sizeof(dtr_command));
0708 }
0709
0710
0711 static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
0712 {
0713 struct whiteheat_set_rdb break_command;
0714
0715 break_command.port = port->port_number + 1;
0716 break_command.state = onoff;
0717 return firm_send_command(port, WHITEHEAT_SET_BREAK,
0718 (__u8 *)&break_command, sizeof(break_command));
0719 }
0720
0721
0722 static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
0723 {
0724 struct whiteheat_purge purge_command;
0725
0726 purge_command.port = port->port_number + 1;
0727 purge_command.what = rxtx;
0728 return firm_send_command(port, WHITEHEAT_PURGE,
0729 (__u8 *)&purge_command, sizeof(purge_command));
0730 }
0731
0732
0733 static int firm_get_dtr_rts(struct usb_serial_port *port)
0734 {
0735 struct whiteheat_simple get_dr_command;
0736
0737 get_dr_command.port = port->port_number + 1;
0738 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
0739 (__u8 *)&get_dr_command, sizeof(get_dr_command));
0740 }
0741
0742
0743 static int firm_report_tx_done(struct usb_serial_port *port)
0744 {
0745 struct whiteheat_simple close_command;
0746
0747 close_command.port = port->port_number + 1;
0748 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
0749 (__u8 *)&close_command, sizeof(close_command));
0750 }
0751
0752
0753
0754
0755
0756 static int start_command_port(struct usb_serial *serial)
0757 {
0758 struct usb_serial_port *command_port;
0759 struct whiteheat_command_private *command_info;
0760 int retval = 0;
0761
0762 command_port = serial->port[COMMAND_PORT];
0763 command_info = usb_get_serial_port_data(command_port);
0764 mutex_lock(&command_info->mutex);
0765 if (!command_info->port_running) {
0766
0767 usb_clear_halt(serial->dev, command_port->read_urb->pipe);
0768
0769 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
0770 if (retval) {
0771 dev_err(&serial->dev->dev,
0772 "%s - failed submitting read urb, error %d\n",
0773 __func__, retval);
0774 goto exit;
0775 }
0776 }
0777 command_info->port_running++;
0778
0779 exit:
0780 mutex_unlock(&command_info->mutex);
0781 return retval;
0782 }
0783
0784
0785 static void stop_command_port(struct usb_serial *serial)
0786 {
0787 struct usb_serial_port *command_port;
0788 struct whiteheat_command_private *command_info;
0789
0790 command_port = serial->port[COMMAND_PORT];
0791 command_info = usb_get_serial_port_data(command_port);
0792 mutex_lock(&command_info->mutex);
0793 command_info->port_running--;
0794 if (!command_info->port_running)
0795 usb_kill_urb(command_port->read_urb);
0796 mutex_unlock(&command_info->mutex);
0797 }
0798
0799 module_usb_serial_driver(serial_drivers, id_table_combined);
0800
0801 MODULE_AUTHOR(DRIVER_AUTHOR);
0802 MODULE_DESCRIPTION(DRIVER_DESC);
0803 MODULE_LICENSE("GPL");
0804
0805 MODULE_FIRMWARE("whiteheat.fw");
0806 MODULE_FIRMWARE("whiteheat_loader.fw");