2 * USB Cypress M8 driver
5 * Lonnie Mendez (dignome@gmail.com)
6 * Copyright (C) 2003,2004
7 * Neil Whelchel (koyama@firstlight.net)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * See Documentation/usb/usb-serial.txt for more information on using this
17 * See http://geocities.com/i0xox0i for information on this driver and the
18 * earthmate usb device.
20 * Lonnie Mendez <dignome@gmail.com>
22 * Fixed problem where setting or retreiving the serial config would fail
23 * with EPIPE. Removed CRTS toggling so the driver behaves more like
24 * other usbserial adapters. Issued new interval of 1ms instead of the
25 * default 10ms. As a result, transfer speed has been substantially
26 * increased from avg. 850bps to avg. 3300bps. initial termios has also
27 * been modified. Cleaned up code and formatting issues so it is more
28 * readable. Replaced the C++ style comments.
30 * Lonnie Mendez <dignome@gmail.com>
32 * Incorporated write buffering from pl2303 driver. Fixed bug with line
33 * handling so both lines are raised in cypress_open. (was dropping rts)
34 * Various code cleanups made as well along with other misc bug fixes.
36 * Lonnie Mendez <dignome@gmail.com>
38 * Driver modified to support dynamic line settings. Various improvments
43 * Driver first released.
47 /* Thanks to Neil Whelchel for writing the first cypress m8 implementation
49 /* Thanks to cypress for providing references for the hid reports. */
50 /* Thanks to Jiang Zhang for providing links and for general help. */
51 /* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/
54 #include <linux/kernel.h>
55 #include <linux/errno.h>
56 #include <linux/init.h>
57 #include <linux/slab.h>
58 #include <linux/tty.h>
59 #include <linux/tty_driver.h>
60 #include <linux/tty_flip.h>
61 #include <linux/module.h>
62 #include <linux/moduleparam.h>
63 #include <linux/spinlock.h>
64 #include <linux/usb.h>
65 #include <linux/usb/serial.h>
66 #include <linux/serial.h>
67 #include <linux/delay.h>
68 #include <linux/uaccess.h>
70 #include "cypress_m8.h"
73 #ifdef CONFIG_USB_SERIAL_DEBUG
84 #define DRIVER_VERSION "v1.09"
85 #define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>"
86 #define DRIVER_DESC "Cypress USB to Serial Driver"
88 /* write buffer size defines */
89 #define CYPRESS_BUF_SIZE 1024
90 #define CYPRESS_CLOSING_WAIT (30*HZ)
92 static struct usb_device_id id_table_earthmate [] = {
93 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
94 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
95 { } /* Terminating entry */
98 static struct usb_device_id id_table_cyphidcomrs232 [] = {
99 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
100 { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
101 { } /* Terminating entry */
104 static struct usb_device_id id_table_nokiaca42v2 [] = {
105 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
106 { } /* Terminating entry */
109 static struct usb_device_id id_table_combined [] = {
110 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
111 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
112 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
113 { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
114 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
115 { } /* Terminating entry */
118 MODULE_DEVICE_TABLE(usb, id_table_combined);
120 static struct usb_driver cypress_driver = {
122 .probe = usb_serial_probe,
123 .disconnect = usb_serial_disconnect,
124 .id_table = id_table_combined,
129 packet_format_1, /* b0:status, b1:payload count */
130 packet_format_2 /* b0[7:3]:status, b0[2:0]:payload count */
133 struct cypress_private {
134 spinlock_t lock; /* private lock */
135 int chiptype; /* identifier of device, for quirks/etc */
136 int bytes_in; /* used for statistics */
137 int bytes_out; /* used for statistics */
138 int cmd_count; /* used for statistics */
139 int cmd_ctrl; /* always set this to 1 before issuing a command */
140 struct cypress_buf *buf; /* write buffer */
141 int write_urb_in_use; /* write urb in use indicator */
142 int write_urb_interval; /* interval to use for write urb */
143 int read_urb_interval; /* interval to use for read urb */
144 int comm_is_ok; /* true if communication is (still) ok */
145 int termios_initialized;
146 __u8 line_control; /* holds dtr / rts value */
147 __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */
148 __u8 current_config; /* stores the current configuration byte */
149 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
150 enum packet_format pkt_fmt; /* format to use for packet send / receive */
151 int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */
152 int baud_rate; /* stores current baud rate in
154 int isthrottled; /* if throttled, discard reads */
155 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
156 char prev_status, diff_status; /* used for TIOCMIWAIT */
157 /* we pass a pointer to this as the arguement sent to
158 cypress_set_termios old_termios */
159 struct ktermios tmp_termios; /* stores the old termios settings */
162 /* write buffer structure */
164 unsigned int buf_size;
170 /* function prototypes for the Cypress USB to serial device */
171 static int cypress_earthmate_startup(struct usb_serial *serial);
172 static int cypress_hidcom_startup(struct usb_serial *serial);
173 static int cypress_ca42v2_startup(struct usb_serial *serial);
174 static void cypress_shutdown(struct usb_serial *serial);
175 static int cypress_open(struct tty_struct *tty,
176 struct usb_serial_port *port, struct file *filp);
177 static void cypress_close(struct tty_struct *tty,
178 struct usb_serial_port *port, struct file *filp);
179 static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
180 const unsigned char *buf, int count);
181 static void cypress_send(struct usb_serial_port *port);
182 static int cypress_write_room(struct tty_struct *tty);
183 static int cypress_ioctl(struct tty_struct *tty, struct file *file,
184 unsigned int cmd, unsigned long arg);
185 static void cypress_set_termios(struct tty_struct *tty,
186 struct usb_serial_port *port, struct ktermios *old);
187 static int cypress_tiocmget(struct tty_struct *tty, struct file *file);
188 static int cypress_tiocmset(struct tty_struct *tty, struct file *file,
189 unsigned int set, unsigned int clear);
190 static int cypress_chars_in_buffer(struct tty_struct *tty);
191 static void cypress_throttle(struct tty_struct *tty);
192 static void cypress_unthrottle(struct tty_struct *tty);
193 static void cypress_set_dead(struct usb_serial_port *port);
194 static void cypress_read_int_callback(struct urb *urb);
195 static void cypress_write_int_callback(struct urb *urb);
196 /* write buffer functions */
197 static struct cypress_buf *cypress_buf_alloc(unsigned int size);
198 static void cypress_buf_free(struct cypress_buf *cb);
199 static void cypress_buf_clear(struct cypress_buf *cb);
200 static unsigned int cypress_buf_data_avail(struct cypress_buf *cb);
201 static unsigned int cypress_buf_space_avail(struct cypress_buf *cb);
202 static unsigned int cypress_buf_put(struct cypress_buf *cb,
203 const char *buf, unsigned int count);
204 static unsigned int cypress_buf_get(struct cypress_buf *cb,
205 char *buf, unsigned int count);
208 static struct usb_serial_driver cypress_earthmate_device = {
210 .owner = THIS_MODULE,
213 .description = "DeLorme Earthmate USB",
214 .usb_driver = &cypress_driver,
215 .id_table = id_table_earthmate,
217 .attach = cypress_earthmate_startup,
218 .shutdown = cypress_shutdown,
219 .open = cypress_open,
220 .close = cypress_close,
221 .write = cypress_write,
222 .write_room = cypress_write_room,
223 .ioctl = cypress_ioctl,
224 .set_termios = cypress_set_termios,
225 .tiocmget = cypress_tiocmget,
226 .tiocmset = cypress_tiocmset,
227 .chars_in_buffer = cypress_chars_in_buffer,
228 .throttle = cypress_throttle,
229 .unthrottle = cypress_unthrottle,
230 .read_int_callback = cypress_read_int_callback,
231 .write_int_callback = cypress_write_int_callback,
234 static struct usb_serial_driver cypress_hidcom_device = {
236 .owner = THIS_MODULE,
239 .description = "HID->COM RS232 Adapter",
240 .usb_driver = &cypress_driver,
241 .id_table = id_table_cyphidcomrs232,
243 .attach = cypress_hidcom_startup,
244 .shutdown = cypress_shutdown,
245 .open = cypress_open,
246 .close = cypress_close,
247 .write = cypress_write,
248 .write_room = cypress_write_room,
249 .ioctl = cypress_ioctl,
250 .set_termios = cypress_set_termios,
251 .tiocmget = cypress_tiocmget,
252 .tiocmset = cypress_tiocmset,
253 .chars_in_buffer = cypress_chars_in_buffer,
254 .throttle = cypress_throttle,
255 .unthrottle = cypress_unthrottle,
256 .read_int_callback = cypress_read_int_callback,
257 .write_int_callback = cypress_write_int_callback,
260 static struct usb_serial_driver cypress_ca42v2_device = {
262 .owner = THIS_MODULE,
263 .name = "nokiaca42v2",
265 .description = "Nokia CA-42 V2 Adapter",
266 .usb_driver = &cypress_driver,
267 .id_table = id_table_nokiaca42v2,
269 .attach = cypress_ca42v2_startup,
270 .shutdown = cypress_shutdown,
271 .open = cypress_open,
272 .close = cypress_close,
273 .write = cypress_write,
274 .write_room = cypress_write_room,
275 .ioctl = cypress_ioctl,
276 .set_termios = cypress_set_termios,
277 .tiocmget = cypress_tiocmget,
278 .tiocmset = cypress_tiocmset,
279 .chars_in_buffer = cypress_chars_in_buffer,
280 .throttle = cypress_throttle,
281 .unthrottle = cypress_unthrottle,
282 .read_int_callback = cypress_read_int_callback,
283 .write_int_callback = cypress_write_int_callback,
286 /*****************************************************************************
287 * Cypress serial helper functions
288 *****************************************************************************/
291 static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
293 struct cypress_private *priv;
294 priv = usb_get_serial_port_data(port);
297 * The general purpose firmware for the Cypress M8 allows for
298 * a maximum speed of 57600bps (I have no idea whether DeLorme
299 * chose to use the general purpose firmware or not), if you
300 * need to modify this speed setting for your own project
301 * please add your own chiptype and modify the code likewise.
302 * The Cypress HID->COM device will work successfully up to
303 * 115200bps (but the actual throughput is around 3kBps).
305 if (port->serial->dev->speed == USB_SPEED_LOW) {
307 * Mike Isely <isely@pobox.com> 2-Feb-2008: The
308 * Cypress app note that describes this mechanism
309 * states the the low-speed part can't handle more
310 * than 800 bytes/sec, in which case 4800 baud is the
311 * safest speed for a part like that.
313 if (new_rate > 4800) {
314 dbg("%s - failed setting baud rate, device incapable "
315 "speed %d", __func__, new_rate);
319 switch (priv->chiptype) {
321 if (new_rate <= 600) {
322 /* 300 and 600 baud rates are supported under
323 * the generic firmware, but are not used with
324 * NMEA and SiRF protocols */
325 dbg("%s - failed setting baud rate, unsupported speed "
326 "of %d on Earthmate GPS", __func__, new_rate);
337 /* This function can either set or retrieve the current serial line settings */
338 static int cypress_serial_control(struct tty_struct *tty,
339 struct usb_serial_port *port, speed_t baud_rate, int data_bits,
340 int stop_bits, int parity_enable, int parity_type, int reset,
341 int cypress_request_type)
343 int new_baudrate = 0, retval = 0, tries = 0;
344 struct cypress_private *priv;
345 __u8 feature_buffer[5];
350 priv = usb_get_serial_port_data(port);
352 if (!priv->comm_is_ok)
355 switch (cypress_request_type) {
356 case CYPRESS_SET_CONFIG:
357 new_baudrate = priv->baud_rate;
358 /* 0 means 'Hang up' so doesn't change the true bit rate */
360 new_baudrate = priv->baud_rate;
361 /* Change of speed ? */
362 else if (baud_rate != priv->baud_rate) {
363 dbg("%s - baud rate is changing", __func__);
364 retval = analyze_baud_rate(port, baud_rate);
366 new_baudrate = retval;
367 dbg("%s - New baud rate set to %d",
368 __func__, new_baudrate);
371 dbg("%s - baud rate is being sent as %d",
372 __func__, new_baudrate);
374 memset(feature_buffer, 0, sizeof(feature_buffer));
375 /* fill the feature_buffer with new configuration */
376 *((u_int32_t *)feature_buffer) = new_baudrate;
377 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
379 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
380 feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
381 feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
383 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
385 dbg("%s - device is being sent this feature report:",
387 dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__,
388 feature_buffer[0], feature_buffer[1],
389 feature_buffer[2], feature_buffer[3],
393 retval = usb_control_msg(port->serial->dev,
394 usb_sndctrlpipe(port->serial->dev, 0),
396 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
397 0x0300, 0, feature_buffer,
398 sizeof(feature_buffer), 500);
403 } while (retval != sizeof(feature_buffer) &&
406 if (retval != sizeof(feature_buffer)) {
407 dev_err(&port->dev, "%s - failed sending serial "
408 "line settings - %d\n", __func__, retval);
409 cypress_set_dead(port);
411 spin_lock_irqsave(&priv->lock, flags);
412 priv->baud_rate = new_baudrate;
413 priv->current_config = feature_buffer[4];
414 spin_unlock_irqrestore(&priv->lock, flags);
415 /* If we asked for a speed change encode it */
417 tty_encode_baud_rate(tty,
418 new_baudrate, new_baudrate);
421 case CYPRESS_GET_CONFIG:
422 if (priv->get_cfg_unsafe) {
423 /* Not implemented for this device,
424 and if we try to do it we're likely
425 to crash the hardware. */
428 dbg("%s - retreiving serial line settings", __func__);
429 /* set initial values in feature buffer */
430 memset(feature_buffer, 0, sizeof(feature_buffer));
433 retval = usb_control_msg(port->serial->dev,
434 usb_rcvctrlpipe(port->serial->dev, 0),
436 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
437 0x0300, 0, feature_buffer,
438 sizeof(feature_buffer), 500);
442 } while (retval != sizeof(feature_buffer)
443 && retval != -ENODEV);
445 if (retval != sizeof(feature_buffer)) {
446 dev_err(&port->dev, "%s - failed to retrieve serial "
447 "line settings - %d\n", __func__, retval);
448 cypress_set_dead(port);
451 spin_lock_irqsave(&priv->lock, flags);
452 /* store the config in one byte, and later
453 use bit masks to check values */
454 priv->current_config = feature_buffer[4];
455 priv->baud_rate = *((u_int32_t *)feature_buffer);
456 spin_unlock_irqrestore(&priv->lock, flags);
459 spin_lock_irqsave(&priv->lock, flags);
461 spin_unlock_irqrestore(&priv->lock, flags);
464 } /* cypress_serial_control */
467 static void cypress_set_dead(struct usb_serial_port *port)
469 struct cypress_private *priv = usb_get_serial_port_data(port);
472 spin_lock_irqsave(&priv->lock, flags);
473 if (!priv->comm_is_ok) {
474 spin_unlock_irqrestore(&priv->lock, flags);
477 priv->comm_is_ok = 0;
478 spin_unlock_irqrestore(&priv->lock, flags);
480 dev_err(&port->dev, "cypress_m8 suspending failing port %d - "
481 "interval might be too short\n", port->number);
485 /*****************************************************************************
486 * Cypress serial driver functions
487 *****************************************************************************/
490 static int generic_startup(struct usb_serial *serial)
492 struct cypress_private *priv;
493 struct usb_serial_port *port = serial->port[0];
495 dbg("%s - port %d", __func__, port->number);
497 priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL);
501 priv->comm_is_ok = !0;
502 spin_lock_init(&priv->lock);
503 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE);
504 if (priv->buf == NULL) {
508 init_waitqueue_head(&priv->delta_msr_wait);
510 usb_reset_configuration(serial->dev);
513 priv->line_control = 0;
514 priv->termios_initialized = 0;
516 /* Default packet format setting is determined by packet size.
517 Anything with a size larger then 9 must have a separate
518 count field since the 3 bit count field is otherwise too
519 small. Otherwise we can use the slightly more compact
520 format. This is in accordance with the cypress_m8 serial
521 converter app note. */
522 if (port->interrupt_out_size > 9)
523 priv->pkt_fmt = packet_format_1;
525 priv->pkt_fmt = packet_format_2;
528 priv->write_urb_interval = interval;
529 priv->read_urb_interval = interval;
530 dbg("%s - port %d read & write intervals forced to %d",
531 __func__, port->number, interval);
533 priv->write_urb_interval = port->interrupt_out_urb->interval;
534 priv->read_urb_interval = port->interrupt_in_urb->interval;
535 dbg("%s - port %d intervals: read=%d write=%d",
536 __func__, port->number,
537 priv->read_urb_interval, priv->write_urb_interval);
539 usb_set_serial_port_data(port, priv);
545 static int cypress_earthmate_startup(struct usb_serial *serial)
547 struct cypress_private *priv;
548 struct usb_serial_port *port = serial->port[0];
552 if (generic_startup(serial)) {
553 dbg("%s - Failed setting up port %d", __func__,
558 priv = usb_get_serial_port_data(port);
559 priv->chiptype = CT_EARTHMATE;
560 /* All Earthmate devices use the separated-count packet
562 priv->pkt_fmt = packet_format_1;
563 if (serial->dev->descriptor.idProduct !=
564 cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
565 /* The old original USB Earthmate seemed able to
566 handle GET_CONFIG requests; everything they've
567 produced since that time crashes if this command is
569 dbg("%s - Marking this device as unsafe for GET_CONFIG "
570 "commands", __func__);
571 priv->get_cfg_unsafe = !0;
575 } /* cypress_earthmate_startup */
578 static int cypress_hidcom_startup(struct usb_serial *serial)
580 struct cypress_private *priv;
584 if (generic_startup(serial)) {
585 dbg("%s - Failed setting up port %d", __func__,
586 serial->port[0]->number);
590 priv = usb_get_serial_port_data(serial->port[0]);
591 priv->chiptype = CT_CYPHIDCOM;
594 } /* cypress_hidcom_startup */
597 static int cypress_ca42v2_startup(struct usb_serial *serial)
599 struct cypress_private *priv;
603 if (generic_startup(serial)) {
604 dbg("%s - Failed setting up port %d", __func__,
605 serial->port[0]->number);
609 priv = usb_get_serial_port_data(serial->port[0]);
610 priv->chiptype = CT_CA42V2;
613 } /* cypress_ca42v2_startup */
616 static void cypress_shutdown(struct usb_serial *serial)
618 struct cypress_private *priv;
620 dbg("%s - port %d", __func__, serial->port[0]->number);
622 /* all open ports are closed at this point */
624 priv = usb_get_serial_port_data(serial->port[0]);
627 cypress_buf_free(priv->buf);
629 usb_set_serial_port_data(serial->port[0], NULL);
634 static int cypress_open(struct tty_struct *tty,
635 struct usb_serial_port *port, struct file *filp)
637 struct cypress_private *priv = usb_get_serial_port_data(port);
638 struct usb_serial *serial = port->serial;
642 dbg("%s - port %d", __func__, port->number);
644 if (!priv->comm_is_ok)
647 /* clear halts before open */
648 usb_clear_halt(serial->dev, 0x81);
649 usb_clear_halt(serial->dev, 0x02);
651 spin_lock_irqsave(&priv->lock, flags);
652 /* reset read/write statistics */
657 spin_unlock_irqrestore(&priv->lock, flags);
659 /* setting to zero could cause data loss */
661 tty->low_latency = 1;
663 /* raise both lines and set termios */
664 spin_lock_irqsave(&priv->lock, flags);
665 priv->line_control = CONTROL_DTR | CONTROL_RTS;
667 spin_unlock_irqrestore(&priv->lock, flags);
668 result = cypress_write(tty, port, NULL, 0);
672 "%s - failed setting the control lines - error %d\n",
676 dbg("%s - success setting the control lines", __func__);
679 cypress_set_termios(tty, port, &priv->tmp_termios);
681 /* setup the port and start reading from the device */
682 if (!port->interrupt_in_urb) {
683 dev_err(&port->dev, "%s - interrupt_in_urb is empty!\n",
688 usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
689 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
690 port->interrupt_in_urb->transfer_buffer,
691 port->interrupt_in_urb->transfer_buffer_length,
692 cypress_read_int_callback, port, priv->read_urb_interval);
693 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
697 "%s - failed submitting read urb, error %d\n",
699 cypress_set_dead(port);
706 static void cypress_close(struct tty_struct *tty,
707 struct usb_serial_port *port, struct file *filp)
709 struct cypress_private *priv = usb_get_serial_port_data(port);
710 unsigned int c_cflag;
715 dbg("%s - port %d", __func__, port->number);
717 /* wait for data to drain from buffer */
718 spin_lock_irq(&priv->lock);
719 timeout = CYPRESS_CLOSING_WAIT;
720 init_waitqueue_entry(&wait, current);
721 add_wait_queue(&tty->write_wait, &wait);
723 set_current_state(TASK_INTERRUPTIBLE);
724 if (cypress_buf_data_avail(priv->buf) == 0
725 || timeout == 0 || signal_pending(current)
726 /* without mutex, allowed due to harmless failure mode */
727 || port->serial->disconnected)
729 spin_unlock_irq(&priv->lock);
730 timeout = schedule_timeout(timeout);
731 spin_lock_irq(&priv->lock);
733 set_current_state(TASK_RUNNING);
734 remove_wait_queue(&tty->write_wait, &wait);
735 /* clear out any remaining data in the buffer */
736 cypress_buf_clear(priv->buf);
737 spin_unlock_irq(&priv->lock);
739 /* writing is potentially harmful, lock must be taken */
740 mutex_lock(&port->serial->disc_mutex);
741 if (port->serial->disconnected) {
742 mutex_unlock(&port->serial->disc_mutex);
745 /* wait for characters to drain from device */
747 bps = tty_get_baud_rate(tty);
749 timeout = max((HZ * 2560) / bps, HZ / 10);
752 schedule_timeout_interruptible(timeout);
755 dbg("%s - stopping urbs", __func__);
756 usb_kill_urb(port->interrupt_in_urb);
757 usb_kill_urb(port->interrupt_out_urb);
760 c_cflag = tty->termios->c_cflag;
761 if (c_cflag & HUPCL) {
762 /* drop dtr and rts */
763 priv = usb_get_serial_port_data(port);
764 spin_lock_irq(&priv->lock);
765 priv->line_control = 0;
767 spin_unlock_irq(&priv->lock);
768 cypress_write(tty, port, NULL, 0);
773 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
774 priv->bytes_in, priv->bytes_out, priv->cmd_count);
775 mutex_unlock(&port->serial->disc_mutex);
776 } /* cypress_close */
779 static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
780 const unsigned char *buf, int count)
782 struct cypress_private *priv = usb_get_serial_port_data(port);
785 dbg("%s - port %d, %d bytes", __func__, port->number, count);
787 /* line control commands, which need to be executed immediately,
788 are not put into the buffer for obvious reasons.
790 if (priv->cmd_ctrl) {
798 spin_lock_irqsave(&priv->lock, flags);
799 count = cypress_buf_put(priv->buf, buf, count);
800 spin_unlock_irqrestore(&priv->lock, flags);
806 } /* cypress_write */
809 static void cypress_send(struct usb_serial_port *port)
811 int count = 0, result, offset, actual_size;
812 struct cypress_private *priv = usb_get_serial_port_data(port);
815 if (!priv->comm_is_ok)
818 dbg("%s - port %d", __func__, port->number);
819 dbg("%s - interrupt out size is %d", __func__,
820 port->interrupt_out_size);
822 spin_lock_irqsave(&priv->lock, flags);
823 if (priv->write_urb_in_use) {
824 dbg("%s - can't write, urb in use", __func__);
825 spin_unlock_irqrestore(&priv->lock, flags);
828 spin_unlock_irqrestore(&priv->lock, flags);
831 memset(port->interrupt_out_urb->transfer_buffer, 0,
832 port->interrupt_out_size);
834 spin_lock_irqsave(&priv->lock, flags);
835 switch (priv->pkt_fmt) {
837 case packet_format_1:
838 /* this is for the CY7C64013... */
840 port->interrupt_out_buffer[0] = priv->line_control;
842 case packet_format_2:
843 /* this is for the CY7C63743... */
845 port->interrupt_out_buffer[0] = priv->line_control;
849 if (priv->line_control & CONTROL_RESET)
850 priv->line_control &= ~CONTROL_RESET;
852 if (priv->cmd_ctrl) {
854 dbg("%s - line control command being issued", __func__);
855 spin_unlock_irqrestore(&priv->lock, flags);
858 spin_unlock_irqrestore(&priv->lock, flags);
860 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset],
861 port->interrupt_out_size-offset);
866 switch (priv->pkt_fmt) {
868 case packet_format_1:
869 port->interrupt_out_buffer[1] = count;
871 case packet_format_2:
872 port->interrupt_out_buffer[0] |= count;
875 dbg("%s - count is %d", __func__, count);
878 spin_lock_irqsave(&priv->lock, flags);
879 priv->write_urb_in_use = 1;
880 spin_unlock_irqrestore(&priv->lock, flags);
885 actual_size = count +
886 (priv->pkt_fmt == packet_format_1 ? 2 : 1);
888 usb_serial_debug_data(debug, &port->dev, __func__,
889 port->interrupt_out_size,
890 port->interrupt_out_urb->transfer_buffer);
892 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
893 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress),
894 port->interrupt_out_buffer, port->interrupt_out_size,
895 cypress_write_int_callback, port, priv->write_urb_interval);
896 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
899 "%s - failed submitting write urb, error %d\n",
901 priv->write_urb_in_use = 0;
902 cypress_set_dead(port);
905 spin_lock_irqsave(&priv->lock, flags);
909 /* do not count the line control and size bytes */
910 priv->bytes_out += count;
911 spin_unlock_irqrestore(&priv->lock, flags);
913 usb_serial_port_softint(port);
917 /* returns how much space is available in the soft buffer */
918 static int cypress_write_room(struct tty_struct *tty)
920 struct usb_serial_port *port = tty->driver_data;
921 struct cypress_private *priv = usb_get_serial_port_data(port);
925 dbg("%s - port %d", __func__, port->number);
927 spin_lock_irqsave(&priv->lock, flags);
928 room = cypress_buf_space_avail(priv->buf);
929 spin_unlock_irqrestore(&priv->lock, flags);
931 dbg("%s - returns %d", __func__, room);
936 static int cypress_tiocmget(struct tty_struct *tty, struct file *file)
938 struct usb_serial_port *port = tty->driver_data;
939 struct cypress_private *priv = usb_get_serial_port_data(port);
940 __u8 status, control;
941 unsigned int result = 0;
944 dbg("%s - port %d", __func__, port->number);
946 spin_lock_irqsave(&priv->lock, flags);
947 control = priv->line_control;
948 status = priv->current_status;
949 spin_unlock_irqrestore(&priv->lock, flags);
951 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
952 | ((control & CONTROL_RTS) ? TIOCM_RTS : 0)
953 | ((status & UART_CTS) ? TIOCM_CTS : 0)
954 | ((status & UART_DSR) ? TIOCM_DSR : 0)
955 | ((status & UART_RI) ? TIOCM_RI : 0)
956 | ((status & UART_CD) ? TIOCM_CD : 0);
958 dbg("%s - result = %x", __func__, result);
964 static int cypress_tiocmset(struct tty_struct *tty, struct file *file,
965 unsigned int set, unsigned int clear)
967 struct usb_serial_port *port = tty->driver_data;
968 struct cypress_private *priv = usb_get_serial_port_data(port);
971 dbg("%s - port %d", __func__, port->number);
973 spin_lock_irqsave(&priv->lock, flags);
975 priv->line_control |= CONTROL_RTS;
977 priv->line_control |= CONTROL_DTR;
978 if (clear & TIOCM_RTS)
979 priv->line_control &= ~CONTROL_RTS;
980 if (clear & TIOCM_DTR)
981 priv->line_control &= ~CONTROL_DTR;
983 spin_unlock_irqrestore(&priv->lock, flags);
985 return cypress_write(tty, port, NULL, 0);
989 static int cypress_ioctl(struct tty_struct *tty, struct file *file,
990 unsigned int cmd, unsigned long arg)
992 struct usb_serial_port *port = tty->driver_data;
993 struct cypress_private *priv = usb_get_serial_port_data(port);
995 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
998 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
1000 while (priv != NULL) {
1001 interruptible_sleep_on(&priv->delta_msr_wait);
1002 /* see if a signal did it */
1003 if (signal_pending(current))
1004 return -ERESTARTSYS;
1006 char diff = priv->diff_status;
1008 return -EIO; /* no change => error */
1010 /* consume all events */
1011 priv->diff_status = 0;
1013 /* return 0 if caller wanted to know about
1015 if (((arg & TIOCM_RNG) && (diff & UART_RI)) ||
1016 ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
1017 ((arg & TIOCM_CD) && (diff & UART_CD)) ||
1018 ((arg & TIOCM_CTS) && (diff & UART_CTS)))
1020 /* otherwise caller can't care less about what
1021 * happened, and so we continue to wait for
1030 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd);
1031 return -ENOIOCTLCMD;
1032 } /* cypress_ioctl */
1035 static void cypress_set_termios(struct tty_struct *tty,
1036 struct usb_serial_port *port, struct ktermios *old_termios)
1038 struct cypress_private *priv = usb_get_serial_port_data(port);
1039 int data_bits, stop_bits, parity_type, parity_enable;
1040 unsigned cflag, iflag;
1041 unsigned long flags;
1045 dbg("%s - port %d", __func__, port->number);
1047 spin_lock_irqsave(&priv->lock, flags);
1048 if (!priv->termios_initialized) {
1049 if (priv->chiptype == CT_EARTHMATE) {
1050 *(tty->termios) = tty_std_termios;
1051 tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL |
1053 tty->termios->c_ispeed = 4800;
1054 tty->termios->c_ospeed = 4800;
1055 } else if (priv->chiptype == CT_CYPHIDCOM) {
1056 *(tty->termios) = tty_std_termios;
1057 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1059 tty->termios->c_ispeed = 9600;
1060 tty->termios->c_ospeed = 9600;
1061 } else if (priv->chiptype == CT_CA42V2) {
1062 *(tty->termios) = tty_std_termios;
1063 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1065 tty->termios->c_ispeed = 9600;
1066 tty->termios->c_ospeed = 9600;
1068 priv->termios_initialized = 1;
1070 spin_unlock_irqrestore(&priv->lock, flags);
1072 /* Unsupported features need clearing */
1073 tty->termios->c_cflag &= ~(CMSPAR|CRTSCTS);
1075 cflag = tty->termios->c_cflag;
1076 iflag = tty->termios->c_iflag;
1078 /* check if there are new settings */
1080 spin_lock_irqsave(&priv->lock, flags);
1081 priv->tmp_termios = *(tty->termios);
1082 spin_unlock_irqrestore(&priv->lock, flags);
1085 /* set number of data bits, parity, stop bits */
1086 /* when parity is disabled the parity type bit is ignored */
1088 /* 1 means 2 stop bits, 0 means 1 stop bit */
1089 stop_bits = cflag & CSTOPB ? 1 : 0;
1091 if (cflag & PARENB) {
1093 /* 1 means odd parity, 0 means even parity */
1094 parity_type = cflag & PARODD ? 1 : 0;
1096 parity_enable = parity_type = 0;
1098 switch (cflag & CSIZE) {
1112 dev_err(&port->dev, "%s - CSIZE was set, but not CS5-CS8\n",
1116 spin_lock_irqsave(&priv->lock, flags);
1117 oldlines = priv->line_control;
1118 if ((cflag & CBAUD) == B0) {
1119 /* drop dtr and rts */
1120 dbg("%s - dropping the lines, baud rate 0bps", __func__);
1121 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
1123 priv->line_control = (CONTROL_DTR | CONTROL_RTS);
1124 spin_unlock_irqrestore(&priv->lock, flags);
1126 dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, "
1127 "%d data_bits (+5)", __func__, stop_bits,
1128 parity_enable, parity_type, data_bits);
1130 cypress_serial_control(tty, port, tty_get_baud_rate(tty),
1131 data_bits, stop_bits,
1132 parity_enable, parity_type,
1133 0, CYPRESS_SET_CONFIG);
1135 /* we perform a CYPRESS_GET_CONFIG so that the current settings are
1136 * filled into the private structure this should confirm that all is
1137 * working if it returns what we just set */
1138 cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
1140 /* Here we can define custom tty settings for devices; the main tty
1141 * termios flag base comes from empeg.c */
1143 spin_lock_irqsave(&priv->lock, flags);
1144 if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) {
1145 dbg("Using custom termios settings for a baud rate of "
1147 /* define custom termios settings for NMEA protocol */
1149 tty->termios->c_iflag /* input modes - */
1150 &= ~(IGNBRK /* disable ignore break */
1151 | BRKINT /* disable break causes interrupt */
1152 | PARMRK /* disable mark parity errors */
1153 | ISTRIP /* disable clear high bit of input char */
1154 | INLCR /* disable translate NL to CR */
1155 | IGNCR /* disable ignore CR */
1156 | ICRNL /* disable translate CR to NL */
1157 | IXON); /* disable enable XON/XOFF flow control */
1159 tty->termios->c_oflag /* output modes */
1160 &= ~OPOST; /* disable postprocess output char */
1162 tty->termios->c_lflag /* line discipline modes */
1163 &= ~(ECHO /* disable echo input characters */
1164 | ECHONL /* disable echo new line */
1165 | ICANON /* disable erase, kill, werase, and rprnt
1166 special characters */
1167 | ISIG /* disable interrupt, quit, and suspend
1168 special characters */
1169 | IEXTEN); /* disable non-POSIX special characters */
1170 } /* CT_CYPHIDCOM: Application should handle this for device */
1172 linechange = (priv->line_control != oldlines);
1173 spin_unlock_irqrestore(&priv->lock, flags);
1175 /* if necessary, set lines */
1178 cypress_write(tty, port, NULL, 0);
1180 } /* cypress_set_termios */
1183 /* returns amount of data still left in soft buffer */
1184 static int cypress_chars_in_buffer(struct tty_struct *tty)
1186 struct usb_serial_port *port = tty->driver_data;
1187 struct cypress_private *priv = usb_get_serial_port_data(port);
1189 unsigned long flags;
1191 dbg("%s - port %d", __func__, port->number);
1193 spin_lock_irqsave(&priv->lock, flags);
1194 chars = cypress_buf_data_avail(priv->buf);
1195 spin_unlock_irqrestore(&priv->lock, flags);
1197 dbg("%s - returns %d", __func__, chars);
1202 static void cypress_throttle(struct tty_struct *tty)
1204 struct usb_serial_port *port = tty->driver_data;
1205 struct cypress_private *priv = usb_get_serial_port_data(port);
1206 unsigned long flags;
1208 dbg("%s - port %d", __func__, port->number);
1210 spin_lock_irqsave(&priv->lock, flags);
1211 priv->rx_flags = THROTTLED;
1212 spin_unlock_irqrestore(&priv->lock, flags);
1216 static void cypress_unthrottle(struct tty_struct *tty)
1218 struct usb_serial_port *port = tty->driver_data;
1219 struct cypress_private *priv = usb_get_serial_port_data(port);
1220 int actually_throttled, result;
1221 unsigned long flags;
1223 dbg("%s - port %d", __func__, port->number);
1225 spin_lock_irqsave(&priv->lock, flags);
1226 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
1228 spin_unlock_irqrestore(&priv->lock, flags);
1230 if (!priv->comm_is_ok)
1233 if (actually_throttled) {
1234 port->interrupt_in_urb->dev = port->serial->dev;
1236 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1238 dev_err(&port->dev, "%s - failed submitting read urb, "
1239 "error %d\n", __func__, result);
1240 cypress_set_dead(port);
1246 static void cypress_read_int_callback(struct urb *urb)
1248 struct usb_serial_port *port = urb->context;
1249 struct cypress_private *priv = usb_get_serial_port_data(port);
1250 struct tty_struct *tty;
1251 unsigned char *data = urb->transfer_buffer;
1252 unsigned long flags;
1253 char tty_flag = TTY_NORMAL;
1258 int status = urb->status;
1260 dbg("%s - port %d", __func__, port->number);
1263 case 0: /* success */
1268 /* precursor to disconnect so just go away */
1271 usb_clear_halt(port->serial->dev, 0x81);
1274 /* something ugly is going on... */
1275 dev_err(&urb->dev->dev,
1276 "%s - unexpected nonzero read status received: %d\n",
1278 cypress_set_dead(port);
1282 spin_lock_irqsave(&priv->lock, flags);
1283 if (priv->rx_flags & THROTTLED) {
1284 dbg("%s - now throttling", __func__);
1285 priv->rx_flags |= ACTUALLY_THROTTLED;
1286 spin_unlock_irqrestore(&priv->lock, flags);
1289 spin_unlock_irqrestore(&priv->lock, flags);
1291 tty = tty_port_tty_get(&port->port);
1293 dbg("%s - bad tty pointer - exiting", __func__);
1297 spin_lock_irqsave(&priv->lock, flags);
1298 result = urb->actual_length;
1299 switch (priv->pkt_fmt) {
1301 case packet_format_1:
1302 /* This is for the CY7C64013... */
1303 priv->current_status = data[0] & 0xF8;
1304 bytes = data[1] + 2;
1309 case packet_format_2:
1310 /* This is for the CY7C63743... */
1311 priv->current_status = data[0] & 0xF8;
1312 bytes = (data[0] & 0x07) + 1;
1318 spin_unlock_irqrestore(&priv->lock, flags);
1319 if (result < bytes) {
1320 dbg("%s - wrong packet size - received %d bytes but packet "
1321 "said %d bytes", __func__, result, bytes);
1325 usb_serial_debug_data(debug, &port->dev, __func__,
1326 urb->actual_length, data);
1328 spin_lock_irqsave(&priv->lock, flags);
1329 /* check to see if status has changed */
1330 if (priv->current_status != priv->prev_status) {
1331 priv->diff_status |= priv->current_status ^
1333 wake_up_interruptible(&priv->delta_msr_wait);
1334 priv->prev_status = priv->current_status;
1336 spin_unlock_irqrestore(&priv->lock, flags);
1338 /* hangup, as defined in acm.c... this might be a bad place for it
1340 if (tty && !(tty->termios->c_cflag & CLOCAL) &&
1341 !(priv->current_status & UART_CD)) {
1342 dbg("%s - calling hangup", __func__);
1347 /* There is one error bit... I'm assuming it is a parity error
1348 * indicator as the generic firmware will set this bit to 1 if a
1349 * parity error occurs.
1350 * I can not find reference to any other error events. */
1351 spin_lock_irqsave(&priv->lock, flags);
1352 if (priv->current_status & CYP_ERROR) {
1353 spin_unlock_irqrestore(&priv->lock, flags);
1354 tty_flag = TTY_PARITY;
1355 dbg("%s - Parity Error detected", __func__);
1357 spin_unlock_irqrestore(&priv->lock, flags);
1359 /* process read if there is data other than line status */
1360 if (tty && (bytes > i)) {
1361 bytes = tty_buffer_request_room(tty, bytes);
1362 for (; i < bytes ; ++i) {
1363 dbg("pushing byte number %d - %d - %c", i, data[i],
1365 tty_insert_flip_char(tty, data[i], tty_flag);
1367 tty_flip_buffer_push(tty);
1370 spin_lock_irqsave(&priv->lock, flags);
1371 /* control and status byte(s) are also counted */
1372 priv->bytes_in += bytes;
1373 spin_unlock_irqrestore(&priv->lock, flags);
1378 /* Continue trying to always read... unless the port has closed. */
1380 if (port->port.count > 0 && priv->comm_is_ok) {
1381 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1382 usb_rcvintpipe(port->serial->dev,
1383 port->interrupt_in_endpointAddress),
1384 port->interrupt_in_urb->transfer_buffer,
1385 port->interrupt_in_urb->transfer_buffer_length,
1386 cypress_read_int_callback, port,
1387 priv->read_urb_interval);
1388 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1390 dev_err(&urb->dev->dev, "%s - failed resubmitting "
1391 "read urb, error %d\n", __func__,
1393 cypress_set_dead(port);
1398 } /* cypress_read_int_callback */
1401 static void cypress_write_int_callback(struct urb *urb)
1403 struct usb_serial_port *port = urb->context;
1404 struct cypress_private *priv = usb_get_serial_port_data(port);
1406 int status = urb->status;
1408 dbg("%s - port %d", __func__, port->number);
1417 /* this urb is terminated, clean up */
1418 dbg("%s - urb shutting down with status: %d",
1420 priv->write_urb_in_use = 0;
1422 case -EPIPE: /* no break needed; clear halt and resubmit */
1423 if (!priv->comm_is_ok)
1425 usb_clear_halt(port->serial->dev, 0x02);
1426 /* error in the urb, so we have to resubmit it */
1427 dbg("%s - nonzero write bulk status received: %d",
1429 port->interrupt_out_urb->transfer_buffer_length = 1;
1430 port->interrupt_out_urb->dev = port->serial->dev;
1431 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
1434 dev_err(&urb->dev->dev,
1435 "%s - failed resubmitting write urb, error %d\n",
1437 cypress_set_dead(port);
1440 dev_err(&urb->dev->dev,
1441 "%s - unexpected nonzero write status received: %d\n",
1443 cypress_set_dead(port);
1446 priv->write_urb_in_use = 0;
1448 /* send any buffered data */
1453 /*****************************************************************************
1454 * Write buffer functions - buffering code from pl2303 used
1455 *****************************************************************************/
1460 * Allocate a circular buffer and all associated memory.
1463 static struct cypress_buf *cypress_buf_alloc(unsigned int size)
1466 struct cypress_buf *cb;
1472 cb = kmalloc(sizeof(struct cypress_buf), GFP_KERNEL);
1476 cb->buf_buf = kmalloc(size, GFP_KERNEL);
1477 if (cb->buf_buf == NULL) {
1482 cb->buf_size = size;
1483 cb->buf_get = cb->buf_put = cb->buf_buf;
1493 * Free the buffer and all associated memory.
1496 static void cypress_buf_free(struct cypress_buf *cb)
1508 * Clear out all data in the circular buffer.
1511 static void cypress_buf_clear(struct cypress_buf *cb)
1514 cb->buf_get = cb->buf_put;
1515 /* equivalent to a get of all data available */
1520 * cypress_buf_data_avail
1522 * Return the number of bytes of data available in the circular
1526 static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1529 return (cb->buf_size + cb->buf_put - cb->buf_get)
1537 * cypress_buf_space_avail
1539 * Return the number of bytes of space available in the circular
1543 static unsigned int cypress_buf_space_avail(struct cypress_buf *cb)
1546 return (cb->buf_size + cb->buf_get - cb->buf_put - 1)
1556 * Copy data data from a user buffer and put it into the circular buffer.
1557 * Restrict to the amount of space available.
1559 * Return the number of bytes copied.
1562 static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf,
1572 len = cypress_buf_space_avail(cb);
1579 len = cb->buf_buf + cb->buf_size - cb->buf_put;
1581 memcpy(cb->buf_put, buf, len);
1582 memcpy(cb->buf_buf, buf+len, count - len);
1583 cb->buf_put = cb->buf_buf + count - len;
1585 memcpy(cb->buf_put, buf, count);
1587 cb->buf_put += count;
1588 else /* count == len */
1589 cb->buf_put = cb->buf_buf;
1600 * Get data from the circular buffer and copy to the given buffer.
1601 * Restrict to the amount of data available.
1603 * Return the number of bytes copied.
1606 static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf,
1616 len = cypress_buf_data_avail(cb);
1623 len = cb->buf_buf + cb->buf_size - cb->buf_get;
1625 memcpy(buf, cb->buf_get, len);
1626 memcpy(buf+len, cb->buf_buf, count - len);
1627 cb->buf_get = cb->buf_buf + count - len;
1629 memcpy(buf, cb->buf_get, count);
1631 cb->buf_get += count;
1632 else /* count == len */
1633 cb->buf_get = cb->buf_buf;
1640 /*****************************************************************************
1642 *****************************************************************************/
1644 static int __init cypress_init(void)
1648 dbg("%s", __func__);
1650 retval = usb_serial_register(&cypress_earthmate_device);
1652 goto failed_em_register;
1653 retval = usb_serial_register(&cypress_hidcom_device);
1655 goto failed_hidcom_register;
1656 retval = usb_serial_register(&cypress_ca42v2_device);
1658 goto failed_ca42v2_register;
1659 retval = usb_register(&cypress_driver);
1661 goto failed_usb_register;
1663 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1667 failed_usb_register:
1668 usb_serial_deregister(&cypress_ca42v2_device);
1669 failed_ca42v2_register:
1670 usb_serial_deregister(&cypress_hidcom_device);
1671 failed_hidcom_register:
1672 usb_serial_deregister(&cypress_earthmate_device);
1678 static void __exit cypress_exit(void)
1680 dbg("%s", __func__);
1682 usb_deregister(&cypress_driver);
1683 usb_serial_deregister(&cypress_earthmate_device);
1684 usb_serial_deregister(&cypress_hidcom_device);
1685 usb_serial_deregister(&cypress_ca42v2_device);
1689 module_init(cypress_init);
1690 module_exit(cypress_exit);
1692 MODULE_AUTHOR(DRIVER_AUTHOR);
1693 MODULE_DESCRIPTION(DRIVER_DESC);
1694 MODULE_VERSION(DRIVER_VERSION);
1695 MODULE_LICENSE("GPL");
1697 module_param(debug, bool, S_IRUGO | S_IWUSR);
1698 MODULE_PARM_DESC(debug, "Debug enabled or not");
1699 module_param(stats, bool, S_IRUGO | S_IWUSR);
1700 MODULE_PARM_DESC(stats, "Enable statistics or not");
1701 module_param(interval, int, S_IRUGO | S_IWUSR);
1702 MODULE_PARM_DESC(interval, "Overrides interrupt interval");