mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / usb / serial / whiteheat.c
blob69fec1a99b3e79a886861a72af15b39f2fc426a3
1 /*
2 * USB ConnectTech WhiteHEAT driver
4 * Copyright (C) 2002
5 * Connect Tech Inc.
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
16 * driver
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 */
38 #ifndef CMSPAR
39 #define CMSPAR 0
40 #endif
43 * Version Information
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 = {
103 .driver = {
104 .owner = THIS_MODULE,
105 .name = "whiteheatnofirm",
107 .description = "Connect Tech - WhiteHEAT - (prerenumeration)",
108 .id_table = id_table_prerenumeration,
109 .num_ports = 1,
110 .probe = whiteheat_firmware_download,
111 .attach = whiteheat_firmware_attach,
114 static struct usb_serial_driver whiteheat_device = {
115 .driver = {
116 .owner = THIS_MODULE,
117 .name = "whiteheat",
119 .description = "Connect Tech - WhiteHEAT",
120 .id_table = id_table_std,
121 .num_ports = 4,
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 {
143 struct mutex mutex;
144 __u8 port_running;
145 __u8 command_finished;
146 wait_queue_head_t wait_command; /* for handling sleeping whilst
147 waiting for a command to
148 finish */
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
192 - hold the reset
193 - download the WH.HEX file for all addresses less than 0x1b40 using
194 VENDOR_REQUEST_ANCHOR_LOAD
195 - release the reset
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)
202 int response;
204 response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat_loader.fw");
205 if (response >= 0) {
206 response = ezusb_fx1_ihex_firmware_download(serial->dev, "whiteheat.fw");
207 if (response >= 0)
208 return 0;
210 return -ENOENT;
214 static int whiteheat_firmware_attach(struct usb_serial *serial)
216 /* We want this device to fail to have a driver assigned to it */
217 return 1;
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;
232 size_t min_num_bulk;
233 unsigned int i;
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))
240 ++num_bulk_in;
241 if (usb_endpoint_is_bulk_out(endpoint))
242 ++num_bulk_out;
245 min_num_bulk = COMMAND_PORT + 1;
246 if (num_bulk_in < min_num_bulk || num_bulk_out < min_num_bulk)
247 return -ENODEV;
249 return 0;
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;
257 int pipe;
258 int ret;
259 int alen;
260 __u8 *command;
261 __u8 *result;
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);
268 if (!command)
269 goto no_command_buffer;
270 command[0] = WHITEHEAT_GET_HW_INFO;
271 command[1] = 0;
273 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
274 if (!result)
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);
284 if (ret) {
285 dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
286 serial->type->description, ret);
287 goto no_firmware;
288 } else if (alen != 2) {
289 dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
290 serial->type->description, alen);
291 goto no_firmware;
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);
300 if (ret) {
301 dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
302 serial->type->description, ret);
303 goto no_firmware;
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);
307 goto no_firmware;
308 } else if (result[0] != command[0]) {
309 dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
310 serial->type->description, result[0]);
311 goto no_firmware;
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),
321 GFP_KERNEL);
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;
335 kfree(result);
336 kfree(command);
338 return 0;
340 no_firmware:
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);
351 kfree(result);
352 kfree(command);
353 return -ENODEV;
355 no_command_private:
356 kfree(result);
357 no_result_buffer:
358 kfree(command);
359 no_command_buffer:
360 return -ENOMEM;
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);
377 if (!info)
378 return -ENOMEM;
380 usb_set_serial_port_data(port, info);
382 return 0;
385 static int whiteheat_port_remove(struct usb_serial_port *port)
387 struct whiteheat_private *info;
389 info = usb_get_serial_port_data(port);
390 kfree(info);
392 return 0;
395 static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
397 int retval;
399 retval = start_command_port(port->serial);
400 if (retval)
401 goto exit;
403 /* send an open port command */
404 retval = firm_open(port);
405 if (retval) {
406 stop_command_port(port->serial);
407 goto exit;
410 retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
411 if (retval) {
412 firm_close(port);
413 stop_command_port(port->serial);
414 goto exit;
417 if (tty)
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);
425 if (retval) {
426 firm_close(port);
427 stop_command_port(port->serial);
428 goto exit;
430 exit:
431 return retval;
435 static void whiteheat_close(struct usb_serial_port *port)
437 firm_report_tx_done(port);
438 firm_close(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);
466 if (set & TIOCM_RTS)
467 info->mcr |= UART_MCR_RTS;
468 if (set & TIOCM_DTR)
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);
478 return 0;
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);
491 switch (cmd) {
492 case TIOCGSERIAL:
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)))
505 return -EFAULT;
506 break;
507 default:
508 break;
511 return -ENOIOCTLCMD;
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;
535 if (status) {
536 dev_dbg(&urb->dev->dev, "nonzero urb status: %d\n", status);
537 return;
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;
548 int result;
550 command_info = usb_get_serial_port_data(command_port);
551 if (!command_info) {
552 dev_dbg(&urb->dev->dev, "%s - command_info is NULL, exiting.\n", __func__);
553 return;
555 if (!urb->actual_length) {
556 dev_dbg(&urb->dev->dev, "%s - empty response, exiting.\n", __func__);
557 return;
559 if (status) {
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);
564 return;
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);
585 } else
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);
590 if (result)
591 dev_dbg(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n",
592 __func__, result);
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;
607 int retval = 0;
608 int t;
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);
622 if (retval) {
623 dev_dbg(dev, "%s - submit urb failed\n", __func__);
624 goto exit;
627 /* wait for the command to complete */
628 t = wait_event_timeout(command_info->wait_command,
629 (bool)command_info->command_finished, COMMAND_TIMEOUT);
630 if (!t)
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__);
635 retval = -ETIMEDOUT;
636 goto exit;
639 if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
640 dev_dbg(dev, "%s - command failed.\n", __func__);
641 retval = -EIO;
642 goto exit;
645 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
646 dev_dbg(dev, "%s - command completed.\n", __func__);
647 switch (command) {
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));
652 break;
655 exit:
656 mutex_unlock(&command_info->mutex);
657 return retval;
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;
695 default:
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 */
701 if (cflag & PARENB)
702 if (cflag & CMSPAR)
703 if (cflag & PARODD)
704 port_settings.parity = WHITEHEAT_PAR_MARK;
705 else
706 port_settings.parity = WHITEHEAT_PAR_SPACE;
707 else
708 if (cflag & PARODD)
709 port_settings.parity = WHITEHEAT_PAR_ODD;
710 else
711 port_settings.parity = WHITEHEAT_PAR_EVEN;
712 else
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 */
717 if (cflag & CSTOPB)
718 port_settings.stop = 2;
719 else
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 */
724 if (cflag & CRTSCTS)
725 port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
726 WHITEHEAT_HFLOW_RTS);
727 else
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 */
736 if (I_IXOFF(tty))
737 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
738 else
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;
832 int retval = 0;
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);
842 if (retval) {
843 dev_err(&serial->dev->dev,
844 "%s - failed submitting read urb, error %d\n",
845 __func__, retval);
846 goto exit;
849 command_info->port_running++;
851 exit:
852 mutex_unlock(&command_info->mutex);
853 return retval;
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");