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 driver
16 * See http://geocities.com/i0xox0i for information on this driver and the
17 * earthmate usb device.
19 * Lonnie Mendez <dignome@gmail.com>
21 * Fixed problem where setting or retreiving the serial config would fail with
22 * EPIPE. Removed CRTS toggling so the driver behaves more like other usbserial
23 * adapters. Issued new interval of 1ms instead of the default 10ms. As a
24 * result, transfer speed has been substantially increased. From avg. 850bps to
25 * avg. 3300bps. initial termios has also been modified. Cleaned up code and
26 * formatting issues so it is more readable. Replaced the C++ style comments.
28 * Lonnie Mendez <dignome@gmail.com>
30 * Incorporated write buffering from pl2303 driver. Fixed bug with line
31 * handling so both lines are raised in cypress_open. (was dropping rts)
32 * Various code cleanups made as well along with other misc bug fixes.
34 * Lonnie Mendez <dignome@gmail.com>
36 * Driver modified to support dynamic line settings. Various improvments
41 * Driver first released.
45 /* Thanks to Neil Whelchel for writing the first cypress m8 implementation for linux. */
46 /* Thanks to cypress for providing references for the hid reports. */
47 /* Thanks to Jiang Zhang for providing links and for general help. */
48 /* Code originates and was built up from ftdi_sio, belkin, pl2303 and others. */
51 #include <linux/kernel.h>
52 #include <linux/errno.h>
53 #include <linux/init.h>
54 #include <linux/slab.h>
55 #include <linux/tty.h>
56 #include <linux/tty_driver.h>
57 #include <linux/tty_flip.h>
58 #include <linux/module.h>
59 #include <linux/moduleparam.h>
60 #include <linux/spinlock.h>
61 #include <linux/usb.h>
62 #include <linux/usb/serial.h>
63 #include <linux/serial.h>
64 #include <linux/delay.h>
65 #include <asm/uaccess.h>
67 #include "cypress_m8.h"
70 #ifdef CONFIG_USB_SERIAL_DEBUG
81 #define DRIVER_VERSION "v1.09"
82 #define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>"
83 #define DRIVER_DESC "Cypress USB to Serial Driver"
85 /* write buffer size defines */
86 #define CYPRESS_BUF_SIZE 1024
87 #define CYPRESS_CLOSING_WAIT (30*HZ)
89 static struct usb_device_id id_table_earthmate [] = {
90 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
91 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
92 { } /* Terminating entry */
95 static struct usb_device_id id_table_cyphidcomrs232 [] = {
96 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
97 { } /* Terminating entry */
100 static struct usb_device_id id_table_nokiaca42v2 [] = {
101 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
102 { } /* Terminating entry */
105 static struct usb_device_id id_table_combined [] = {
106 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
107 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
108 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
109 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
110 { } /* Terminating entry */
113 MODULE_DEVICE_TABLE (usb, id_table_combined);
115 static struct usb_driver cypress_driver = {
117 .probe = usb_serial_probe,
118 .disconnect = usb_serial_disconnect,
119 .id_table = id_table_combined,
123 struct cypress_private {
124 spinlock_t lock; /* private lock */
125 int chiptype; /* identifier of device, for quirks/etc */
126 int bytes_in; /* used for statistics */
127 int bytes_out; /* used for statistics */
128 int cmd_count; /* used for statistics */
129 int cmd_ctrl; /* always set this to 1 before issuing a command */
130 struct cypress_buf *buf; /* write buffer */
131 int write_urb_in_use; /* write urb in use indicator */
132 int write_urb_interval; /* interval to use for write urb */
133 int read_urb_interval; /* interval to use for read urb */
134 int termios_initialized;
135 __u8 line_control; /* holds dtr / rts value */
136 __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */
137 __u8 current_config; /* stores the current configuration byte */
138 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
139 int baud_rate; /* stores current baud rate in integer form */
140 int cbr_mask; /* stores current baud rate in masked form */
141 int isthrottled; /* if throttled, discard reads */
142 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
143 char prev_status, diff_status; /* used for TIOCMIWAIT */
144 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
145 struct termios tmp_termios; /* stores the old termios settings */
148 /* write buffer structure */
150 unsigned int buf_size;
156 /* function prototypes for the Cypress USB to serial device */
157 static int cypress_earthmate_startup (struct usb_serial *serial);
158 static int cypress_hidcom_startup (struct usb_serial *serial);
159 static int cypress_ca42v2_startup (struct usb_serial *serial);
160 static void cypress_shutdown (struct usb_serial *serial);
161 static int cypress_open (struct usb_serial_port *port, struct file *filp);
162 static void cypress_close (struct usb_serial_port *port, struct file *filp);
163 static int cypress_write (struct usb_serial_port *port, const unsigned char *buf, int count);
164 static void cypress_send (struct usb_serial_port *port);
165 static int cypress_write_room (struct usb_serial_port *port);
166 static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
167 static void cypress_set_termios (struct usb_serial_port *port, struct termios * old);
168 static int cypress_tiocmget (struct usb_serial_port *port, struct file *file);
169 static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
170 static int cypress_chars_in_buffer (struct usb_serial_port *port);
171 static void cypress_throttle (struct usb_serial_port *port);
172 static void cypress_unthrottle (struct usb_serial_port *port);
173 static void cypress_read_int_callback (struct urb *urb, struct pt_regs *regs);
174 static void cypress_write_int_callback (struct urb *urb, struct pt_regs *regs);
175 /* baud helper functions */
176 static int mask_to_rate (unsigned mask);
177 static unsigned rate_to_mask (int rate);
178 /* write buffer functions */
179 static struct cypress_buf *cypress_buf_alloc(unsigned int size);
180 static void cypress_buf_free(struct cypress_buf *cb);
181 static void cypress_buf_clear(struct cypress_buf *cb);
182 static unsigned int cypress_buf_data_avail(struct cypress_buf *cb);
183 static unsigned int cypress_buf_space_avail(struct cypress_buf *cb);
184 static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf, unsigned int count);
185 static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count);
188 static struct usb_serial_driver cypress_earthmate_device = {
190 .owner = THIS_MODULE,
193 .description = "DeLorme Earthmate USB",
194 .id_table = id_table_earthmate,
195 .num_interrupt_in = 1,
196 .num_interrupt_out = 1,
197 .num_bulk_in = NUM_DONT_CARE,
198 .num_bulk_out = NUM_DONT_CARE,
200 .attach = cypress_earthmate_startup,
201 .shutdown = cypress_shutdown,
202 .open = cypress_open,
203 .close = cypress_close,
204 .write = cypress_write,
205 .write_room = cypress_write_room,
206 .ioctl = cypress_ioctl,
207 .set_termios = cypress_set_termios,
208 .tiocmget = cypress_tiocmget,
209 .tiocmset = cypress_tiocmset,
210 .chars_in_buffer = cypress_chars_in_buffer,
211 .throttle = cypress_throttle,
212 .unthrottle = cypress_unthrottle,
213 .read_int_callback = cypress_read_int_callback,
214 .write_int_callback = cypress_write_int_callback,
217 static struct usb_serial_driver cypress_hidcom_device = {
219 .owner = THIS_MODULE,
222 .description = "HID->COM RS232 Adapter",
223 .id_table = id_table_cyphidcomrs232,
224 .num_interrupt_in = 1,
225 .num_interrupt_out = 1,
226 .num_bulk_in = NUM_DONT_CARE,
227 .num_bulk_out = NUM_DONT_CARE,
229 .attach = cypress_hidcom_startup,
230 .shutdown = cypress_shutdown,
231 .open = cypress_open,
232 .close = cypress_close,
233 .write = cypress_write,
234 .write_room = cypress_write_room,
235 .ioctl = cypress_ioctl,
236 .set_termios = cypress_set_termios,
237 .tiocmget = cypress_tiocmget,
238 .tiocmset = cypress_tiocmset,
239 .chars_in_buffer = cypress_chars_in_buffer,
240 .throttle = cypress_throttle,
241 .unthrottle = cypress_unthrottle,
242 .read_int_callback = cypress_read_int_callback,
243 .write_int_callback = cypress_write_int_callback,
246 static struct usb_serial_driver cypress_ca42v2_device = {
248 .owner = THIS_MODULE,
249 .name = "nokiaca42v2",
251 .description = "Nokia CA-42 V2 Adapter",
252 .id_table = id_table_nokiaca42v2,
253 .num_interrupt_in = 1,
254 .num_interrupt_out = 1,
255 .num_bulk_in = NUM_DONT_CARE,
256 .num_bulk_out = NUM_DONT_CARE,
258 .attach = cypress_ca42v2_startup,
259 .shutdown = cypress_shutdown,
260 .open = cypress_open,
261 .close = cypress_close,
262 .write = cypress_write,
263 .write_room = cypress_write_room,
264 .ioctl = cypress_ioctl,
265 .set_termios = cypress_set_termios,
266 .tiocmget = cypress_tiocmget,
267 .tiocmset = cypress_tiocmset,
268 .chars_in_buffer = cypress_chars_in_buffer,
269 .throttle = cypress_throttle,
270 .unthrottle = cypress_unthrottle,
271 .read_int_callback = cypress_read_int_callback,
272 .write_int_callback = cypress_write_int_callback,
275 /*****************************************************************************
276 * Cypress serial helper functions
277 *****************************************************************************/
280 /* This function can either set or retrieve the current serial line settings */
281 static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_mask, int data_bits, int stop_bits,
282 int parity_enable, int parity_type, int reset, int cypress_request_type)
284 int new_baudrate = 0, retval = 0, tries = 0;
285 struct cypress_private *priv;
286 __u8 feature_buffer[8];
289 dbg("%s", __FUNCTION__);
291 priv = usb_get_serial_port_data(port);
293 switch(cypress_request_type) {
294 case CYPRESS_SET_CONFIG:
297 * The general purpose firmware for the Cypress M8 allows for a maximum speed
298 * of 57600bps (I have no idea whether DeLorme chose to use the general purpose
299 * firmware or not), if you need to modify this speed setting for your own
300 * project please add your own chiptype and modify the code likewise. The
301 * Cypress HID->COM device will work successfully up to 115200bps (but the
302 * actual throughput is around 3kBps).
304 if (baud_mask != priv->cbr_mask) {
305 dbg("%s - baud rate is changing", __FUNCTION__);
306 if ( priv->chiptype == CT_EARTHMATE ) {
307 /* 300 and 600 baud rates are supported under the generic firmware,
308 * but are not used with NMEA and SiRF protocols */
310 if ( (baud_mask == B300) || (baud_mask == B600) ) {
311 err("%s - failed setting baud rate, unsupported speed",
313 new_baudrate = priv->baud_rate;
314 } else if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
315 err("%s - failed setting baud rate, unsupported speed",
317 new_baudrate = priv->baud_rate;
319 } else if (priv->chiptype == CT_CYPHIDCOM) {
320 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
321 err("%s - failed setting baud rate, unsupported speed",
323 new_baudrate = priv->baud_rate;
325 } else if (priv->chiptype == CT_CA42V2) {
326 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
327 err("%s - failed setting baud rate, unsupported speed",
329 new_baudrate = priv->baud_rate;
331 } else if (priv->chiptype == CT_GENERIC) {
332 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
333 err("%s - failed setting baud rate, unsupported speed",
335 new_baudrate = priv->baud_rate;
338 info("%s - please define your chiptype", __FUNCTION__);
339 new_baudrate = priv->baud_rate;
341 } else { /* baud rate not changing, keep the old */
342 new_baudrate = priv->baud_rate;
344 dbg("%s - baud rate is being sent as %d", __FUNCTION__, new_baudrate);
346 memset(feature_buffer, 0, 8);
347 /* fill the feature_buffer with new configuration */
348 *((u_int32_t *)feature_buffer) = new_baudrate;
350 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
352 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
353 feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
354 feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
356 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
358 dbg("%s - device is being sent this feature report:", __FUNCTION__);
359 dbg("%s - %02X - %02X - %02X - %02X - %02X", __FUNCTION__, feature_buffer[0], feature_buffer[1],
360 feature_buffer[2], feature_buffer[3], feature_buffer[4]);
363 retval = usb_control_msg (port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0),
364 HID_REQ_SET_REPORT, USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
365 0x0300, 0, feature_buffer, 8, 500);
371 usb_clear_halt(port->serial->dev, 0x00);
372 } while (retval != 8 && retval != ENODEV);
375 err("%s - failed sending serial line settings - %d", __FUNCTION__, retval);
377 spin_lock_irqsave(&priv->lock, flags);
378 priv->baud_rate = new_baudrate;
379 priv->cbr_mask = baud_mask;
380 priv->current_config = feature_buffer[4];
381 spin_unlock_irqrestore(&priv->lock, flags);
384 case CYPRESS_GET_CONFIG:
385 dbg("%s - retreiving serial line settings", __FUNCTION__);
386 /* set initial values in feature buffer */
387 memset(feature_buffer, 0, 8);
390 retval = usb_control_msg (port->serial->dev, usb_rcvctrlpipe(port->serial->dev, 0),
391 HID_REQ_GET_REPORT, USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
392 0x0300, 0, feature_buffer, 8, 500);
398 usb_clear_halt(port->serial->dev, 0x00);
399 } while (retval != 5 && retval != ENODEV);
402 err("%s - failed to retrieve serial line settings - %d", __FUNCTION__, retval);
405 spin_lock_irqsave(&priv->lock, flags);
407 /* store the config in one byte, and later use bit masks to check values */
408 priv->current_config = feature_buffer[4];
409 priv->baud_rate = *((u_int32_t *)feature_buffer);
411 if ( (priv->cbr_mask = rate_to_mask(priv->baud_rate)) == 0x40)
412 dbg("%s - failed setting the baud mask (not defined)", __FUNCTION__);
413 spin_unlock_irqrestore(&priv->lock, flags);
416 spin_lock_irqsave(&priv->lock, flags);
418 spin_unlock_irqrestore(&priv->lock, flags);
421 } /* cypress_serial_control */
424 /* given a baud mask, it will return integer baud on success */
425 static int mask_to_rate (unsigned mask)
430 case B0: rate = 0; break;
431 case B300: rate = 300; break;
432 case B600: rate = 600; break;
433 case B1200: rate = 1200; break;
434 case B2400: rate = 2400; break;
435 case B4800: rate = 4800; break;
436 case B9600: rate = 9600; break;
437 case B19200: rate = 19200; break;
438 case B38400: rate = 38400; break;
439 case B57600: rate = 57600; break;
440 case B115200: rate = 115200; break;
448 static unsigned rate_to_mask (int rate)
453 case 0: mask = B0; break;
454 case 300: mask = B300; break;
455 case 600: mask = B600; break;
456 case 1200: mask = B1200; break;
457 case 2400: mask = B2400; break;
458 case 4800: mask = B4800; break;
459 case 9600: mask = B9600; break;
460 case 19200: mask = B19200; break;
461 case 38400: mask = B38400; break;
462 case 57600: mask = B57600; break;
463 case 115200: mask = B115200; break;
464 default: mask = 0x40;
469 /*****************************************************************************
470 * Cypress serial driver functions
471 *****************************************************************************/
474 static int generic_startup (struct usb_serial *serial)
476 struct cypress_private *priv;
477 struct usb_serial_port *port = serial->port[0];
479 dbg("%s - port %d", __FUNCTION__, port->number);
481 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL);
485 spin_lock_init(&priv->lock);
486 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE);
487 if (priv->buf == NULL) {
491 init_waitqueue_head(&priv->delta_msr_wait);
493 usb_reset_configuration (serial->dev);
496 priv->line_control = 0;
497 priv->termios_initialized = 0;
499 priv->cbr_mask = B300;
501 priv->write_urb_interval = interval;
502 priv->read_urb_interval = interval;
503 dbg("%s - port %d read & write intervals forced to %d",
504 __FUNCTION__,port->number,interval);
506 priv->write_urb_interval = port->interrupt_out_urb->interval;
507 priv->read_urb_interval = port->interrupt_in_urb->interval;
508 dbg("%s - port %d intervals: read=%d write=%d",
509 __FUNCTION__,port->number,
510 priv->read_urb_interval,priv->write_urb_interval);
512 usb_set_serial_port_data(port, priv);
518 static int cypress_earthmate_startup (struct usb_serial *serial)
520 struct cypress_private *priv;
522 dbg("%s", __FUNCTION__);
524 if (generic_startup(serial)) {
525 dbg("%s - Failed setting up port %d", __FUNCTION__,
526 serial->port[0]->number);
530 priv = usb_get_serial_port_data(serial->port[0]);
531 priv->chiptype = CT_EARTHMATE;
534 } /* cypress_earthmate_startup */
537 static int cypress_hidcom_startup (struct usb_serial *serial)
539 struct cypress_private *priv;
541 dbg("%s", __FUNCTION__);
543 if (generic_startup(serial)) {
544 dbg("%s - Failed setting up port %d", __FUNCTION__,
545 serial->port[0]->number);
549 priv = usb_get_serial_port_data(serial->port[0]);
550 priv->chiptype = CT_CYPHIDCOM;
553 } /* cypress_hidcom_startup */
556 static int cypress_ca42v2_startup (struct usb_serial *serial)
558 struct cypress_private *priv;
560 dbg("%s", __FUNCTION__);
562 if (generic_startup(serial)) {
563 dbg("%s - Failed setting up port %d", __FUNCTION__,
564 serial->port[0]->number);
568 priv = usb_get_serial_port_data(serial->port[0]);
569 priv->chiptype = CT_CA42V2;
572 } /* cypress_ca42v2_startup */
575 static void cypress_shutdown (struct usb_serial *serial)
577 struct cypress_private *priv;
579 dbg ("%s - port %d", __FUNCTION__, serial->port[0]->number);
581 /* all open ports are closed at this point */
583 priv = usb_get_serial_port_data(serial->port[0]);
586 cypress_buf_free(priv->buf);
588 usb_set_serial_port_data(serial->port[0], NULL);
593 static int cypress_open (struct usb_serial_port *port, struct file *filp)
595 struct cypress_private *priv = usb_get_serial_port_data(port);
596 struct usb_serial *serial = port->serial;
600 dbg("%s - port %d", __FUNCTION__, port->number);
602 /* clear halts before open */
603 usb_clear_halt(serial->dev, 0x81);
604 usb_clear_halt(serial->dev, 0x02);
606 spin_lock_irqsave(&priv->lock, flags);
607 /* reset read/write statistics */
612 spin_unlock_irqrestore(&priv->lock, flags);
614 /* setting to zero could cause data loss */
615 port->tty->low_latency = 1;
617 /* raise both lines and set termios */
618 spin_lock_irqsave(&priv->lock, flags);
619 priv->line_control = CONTROL_DTR | CONTROL_RTS;
621 spin_unlock_irqrestore(&priv->lock, flags);
622 result = cypress_write(port, NULL, 0);
625 dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __FUNCTION__, result);
628 dbg("%s - success setting the control lines", __FUNCTION__);
630 cypress_set_termios(port, &priv->tmp_termios);
632 /* setup the port and start reading from the device */
633 if(!port->interrupt_in_urb){
634 err("%s - interrupt_in_urb is empty!", __FUNCTION__);
638 usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
639 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
640 port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length,
641 cypress_read_int_callback, port, priv->read_urb_interval);
642 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
645 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
652 static void cypress_close(struct usb_serial_port *port, struct file * filp)
654 struct cypress_private *priv = usb_get_serial_port_data(port);
655 unsigned int c_cflag;
661 dbg("%s - port %d", __FUNCTION__, port->number);
663 /* wait for data to drain from buffer */
664 spin_lock_irqsave(&priv->lock, flags);
665 timeout = CYPRESS_CLOSING_WAIT;
666 init_waitqueue_entry(&wait, current);
667 add_wait_queue(&port->tty->write_wait, &wait);
669 set_current_state(TASK_INTERRUPTIBLE);
670 if (cypress_buf_data_avail(priv->buf) == 0
671 || timeout == 0 || signal_pending(current)
672 || !usb_get_intfdata(port->serial->interface))
674 spin_unlock_irqrestore(&priv->lock, flags);
675 timeout = schedule_timeout(timeout);
676 spin_lock_irqsave(&priv->lock, flags);
678 set_current_state(TASK_RUNNING);
679 remove_wait_queue(&port->tty->write_wait, &wait);
680 /* clear out any remaining data in the buffer */
681 cypress_buf_clear(priv->buf);
682 spin_unlock_irqrestore(&priv->lock, flags);
684 /* wait for characters to drain from device */
685 bps = tty_get_baud_rate(port->tty);
687 timeout = max((HZ*2560)/bps,HZ/10);
690 schedule_timeout_interruptible(timeout);
692 dbg("%s - stopping urbs", __FUNCTION__);
693 usb_kill_urb (port->interrupt_in_urb);
694 usb_kill_urb (port->interrupt_out_urb);
697 c_cflag = port->tty->termios->c_cflag;
698 if (c_cflag & HUPCL) {
699 /* drop dtr and rts */
700 priv = usb_get_serial_port_data(port);
701 spin_lock_irqsave(&priv->lock, flags);
702 priv->line_control = 0;
704 spin_unlock_irqrestore(&priv->lock, flags);
705 cypress_write(port, NULL, 0);
710 dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
711 priv->bytes_in, priv->bytes_out, priv->cmd_count);
712 } /* cypress_close */
715 static int cypress_write(struct usb_serial_port *port, const unsigned char *buf, int count)
717 struct cypress_private *priv = usb_get_serial_port_data(port);
720 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
722 /* line control commands, which need to be executed immediately,
723 are not put into the buffer for obvious reasons.
725 if (priv->cmd_ctrl) {
733 spin_lock_irqsave(&priv->lock, flags);
734 count = cypress_buf_put(priv->buf, buf, count);
735 spin_unlock_irqrestore(&priv->lock, flags);
741 } /* cypress_write */
744 static void cypress_send(struct usb_serial_port *port)
746 int count = 0, result, offset, actual_size;
747 struct cypress_private *priv = usb_get_serial_port_data(port);
750 dbg("%s - port %d", __FUNCTION__, port->number);
751 dbg("%s - interrupt out size is %d", __FUNCTION__, port->interrupt_out_size);
753 spin_lock_irqsave(&priv->lock, flags);
754 if (priv->write_urb_in_use) {
755 dbg("%s - can't write, urb in use", __FUNCTION__);
756 spin_unlock_irqrestore(&priv->lock, flags);
759 spin_unlock_irqrestore(&priv->lock, flags);
762 memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size);
764 spin_lock_irqsave(&priv->lock, flags);
765 switch (port->interrupt_out_size) {
767 /* this is for the CY7C64013... */
769 port->interrupt_out_buffer[0] = priv->line_control;
772 /* this is for the CY7C63743... */
774 port->interrupt_out_buffer[0] = priv->line_control;
777 dbg("%s - wrong packet size", __FUNCTION__);
778 spin_unlock_irqrestore(&priv->lock, flags);
782 if (priv->line_control & CONTROL_RESET)
783 priv->line_control &= ~CONTROL_RESET;
785 if (priv->cmd_ctrl) {
787 dbg("%s - line control command being issued", __FUNCTION__);
788 spin_unlock_irqrestore(&priv->lock, flags);
791 spin_unlock_irqrestore(&priv->lock, flags);
793 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset],
794 port->interrupt_out_size-offset);
800 switch (port->interrupt_out_size) {
802 port->interrupt_out_buffer[1] = count;
805 port->interrupt_out_buffer[0] |= count;
808 dbg("%s - count is %d", __FUNCTION__, count);
811 spin_lock_irqsave(&priv->lock, flags);
812 priv->write_urb_in_use = 1;
813 spin_unlock_irqrestore(&priv->lock, flags);
818 actual_size = count + (port->interrupt_out_size == 32 ? 2 : 1);
820 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, port->interrupt_out_size,
821 port->interrupt_out_urb->transfer_buffer);
823 port->interrupt_out_urb->transfer_buffer_length = actual_size;
824 port->interrupt_out_urb->dev = port->serial->dev;
825 port->interrupt_out_urb->interval = priv->write_urb_interval;
826 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC);
828 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__,
830 priv->write_urb_in_use = 0;
833 spin_lock_irqsave(&priv->lock, flags);
834 if (priv->cmd_ctrl) {
837 priv->bytes_out += count; /* do not count the line control and size bytes */
838 spin_unlock_irqrestore(&priv->lock, flags);
840 usb_serial_port_softint(port);
844 /* returns how much space is available in the soft buffer */
845 static int cypress_write_room(struct usb_serial_port *port)
847 struct cypress_private *priv = usb_get_serial_port_data(port);
851 dbg("%s - port %d", __FUNCTION__, port->number);
853 spin_lock_irqsave(&priv->lock, flags);
854 room = cypress_buf_space_avail(priv->buf);
855 spin_unlock_irqrestore(&priv->lock, flags);
857 dbg("%s - returns %d", __FUNCTION__, room);
862 static int cypress_tiocmget (struct usb_serial_port *port, struct file *file)
864 struct cypress_private *priv = usb_get_serial_port_data(port);
865 __u8 status, control;
866 unsigned int result = 0;
869 dbg("%s - port %d", __FUNCTION__, port->number);
871 spin_lock_irqsave(&priv->lock, flags);
872 control = priv->line_control;
873 status = priv->current_status;
874 spin_unlock_irqrestore(&priv->lock, flags);
876 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
877 | ((control & CONTROL_RTS) ? TIOCM_RTS : 0)
878 | ((status & UART_CTS) ? TIOCM_CTS : 0)
879 | ((status & UART_DSR) ? TIOCM_DSR : 0)
880 | ((status & UART_RI) ? TIOCM_RI : 0)
881 | ((status & UART_CD) ? TIOCM_CD : 0);
883 dbg("%s - result = %x", __FUNCTION__, result);
889 static int cypress_tiocmset (struct usb_serial_port *port, struct file *file,
890 unsigned int set, unsigned int clear)
892 struct cypress_private *priv = usb_get_serial_port_data(port);
895 dbg("%s - port %d", __FUNCTION__, port->number);
897 spin_lock_irqsave(&priv->lock, flags);
899 priv->line_control |= CONTROL_RTS;
901 priv->line_control |= CONTROL_DTR;
902 if (clear & TIOCM_RTS)
903 priv->line_control &= ~CONTROL_RTS;
904 if (clear & TIOCM_DTR)
905 priv->line_control &= ~CONTROL_DTR;
906 spin_unlock_irqrestore(&priv->lock, flags);
909 return cypress_write(port, NULL, 0);
913 static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
915 struct cypress_private *priv = usb_get_serial_port_data(port);
917 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
921 if (copy_to_user((void __user *)arg, port->tty->termios, sizeof(struct termios))) {
927 if (copy_from_user(port->tty->termios, (void __user *)arg, sizeof(struct termios))) {
930 /* here we need to call cypress_set_termios to invoke the new settings */
931 cypress_set_termios(port, &priv->tmp_termios);
934 /* these are called when setting baud rate from gpsd */
936 if (copy_to_user((void __user *)arg, port->tty->termios, sizeof(struct termios))) {
942 if (copy_from_user(port->tty->termios, (void __user *)arg, sizeof(struct termios))) {
945 /* here we need to call cypress_set_termios to invoke the new settings */
946 cypress_set_termios(port, &priv->tmp_termios);
949 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
951 while (priv != NULL) {
952 interruptible_sleep_on(&priv->delta_msr_wait);
953 /* see if a signal did it */
954 if (signal_pending(current))
957 char diff = priv->diff_status;
960 return -EIO; /* no change => error */
963 /* consume all events */
964 priv->diff_status = 0;
966 /* return 0 if caller wanted to know about these bits */
967 if ( ((arg & TIOCM_RNG) && (diff & UART_RI)) ||
968 ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
969 ((arg & TIOCM_CD) && (diff & UART_CD)) ||
970 ((arg & TIOCM_CTS) && (diff & UART_CTS)) ) {
973 /* otherwise caller can't care less about what happened,
974 * and so we continue to wait for more events.
984 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __FUNCTION__, cmd);
987 } /* cypress_ioctl */
990 static void cypress_set_termios (struct usb_serial_port *port,
991 struct termios *old_termios)
993 struct cypress_private *priv = usb_get_serial_port_data(port);
994 struct tty_struct *tty;
995 int data_bits, stop_bits, parity_type, parity_enable;
996 unsigned cflag, iflag, baud_mask;
1001 dbg("%s - port %d", __FUNCTION__, port->number);
1004 if ((!tty) || (!tty->termios)) {
1005 dbg("%s - no tty structures", __FUNCTION__);
1009 spin_lock_irqsave(&priv->lock, flags);
1010 if (!priv->termios_initialized) {
1011 if (priv->chiptype == CT_EARTHMATE) {
1012 *(tty->termios) = tty_std_termios;
1013 tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL |
1015 } else if (priv->chiptype == CT_CYPHIDCOM) {
1016 *(tty->termios) = tty_std_termios;
1017 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1019 } else if (priv->chiptype == CT_CA42V2) {
1020 *(tty->termios) = tty_std_termios;
1021 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1024 priv->termios_initialized = 1;
1026 spin_unlock_irqrestore(&priv->lock, flags);
1028 cflag = tty->termios->c_cflag;
1029 iflag = tty->termios->c_iflag;
1031 /* check if there are new settings */
1033 if ((cflag != old_termios->c_cflag) ||
1034 (RELEVANT_IFLAG(iflag) !=
1035 RELEVANT_IFLAG(old_termios->c_iflag))) {
1036 dbg("%s - attempting to set new termios settings",
1038 /* should make a copy of this in case something goes
1039 * wrong in the function, we can restore it */
1040 spin_lock_irqsave(&priv->lock, flags);
1041 priv->tmp_termios = *(tty->termios);
1042 spin_unlock_irqrestore(&priv->lock, flags);
1044 dbg("%s - nothing to do, exiting", __FUNCTION__);
1050 /* set number of data bits, parity, stop bits */
1051 /* when parity is disabled the parity type bit is ignored */
1053 /* 1 means 2 stop bits, 0 means 1 stop bit */
1054 stop_bits = cflag & CSTOPB ? 1 : 0;
1056 if (cflag & PARENB) {
1058 /* 1 means odd parity, 0 means even parity */
1059 parity_type = cflag & PARODD ? 1 : 0;
1061 parity_enable = parity_type = 0;
1063 if (cflag & CSIZE) {
1064 switch (cflag & CSIZE) {
1078 err("%s - CSIZE was set, but not CS5-CS8",
1085 spin_lock_irqsave(&priv->lock, flags);
1086 oldlines = priv->line_control;
1087 if ((cflag & CBAUD) == B0) {
1088 /* drop dtr and rts */
1089 dbg("%s - dropping the lines, baud rate 0bps", __FUNCTION__);
1091 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
1093 baud_mask = (cflag & CBAUD);
1096 dbg("%s - setting baud 300bps", __FUNCTION__);
1099 dbg("%s - setting baud 600bps", __FUNCTION__);
1102 dbg("%s - setting baud 1200bps", __FUNCTION__);
1105 dbg("%s - setting baud 2400bps", __FUNCTION__);
1108 dbg("%s - setting baud 4800bps", __FUNCTION__);
1111 dbg("%s - setting baud 9600bps", __FUNCTION__);
1114 dbg("%s - setting baud 19200bps", __FUNCTION__);
1117 dbg("%s - setting baud 38400bps", __FUNCTION__);
1120 dbg("%s - setting baud 57600bps", __FUNCTION__);
1123 dbg("%s - setting baud 115200bps", __FUNCTION__);
1126 dbg("%s - unknown masked baud rate", __FUNCTION__);
1128 priv->line_control = (CONTROL_DTR | CONTROL_RTS);
1130 spin_unlock_irqrestore(&priv->lock, flags);
1132 dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, "
1133 "%d data_bits (+5)", __FUNCTION__, stop_bits,
1134 parity_enable, parity_type, data_bits);
1136 cypress_serial_control(port, baud_mask, data_bits, stop_bits,
1137 parity_enable, parity_type, 0, CYPRESS_SET_CONFIG);
1139 /* we perform a CYPRESS_GET_CONFIG so that the current settings are
1140 * filled into the private structure this should confirm that all is
1141 * working if it returns what we just set */
1142 cypress_serial_control(port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
1144 /* Here we can define custom tty settings for devices; the main tty
1145 * termios flag base comes from empeg.c */
1147 spin_lock_irqsave(&priv->lock, flags);
1148 if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) {
1149 dbg("Using custom termios settings for a baud rate of "
1151 /* define custom termios settings for NMEA protocol */
1153 tty->termios->c_iflag /* input modes - */
1154 &= ~(IGNBRK /* disable ignore break */
1155 | BRKINT /* disable break causes interrupt */
1156 | PARMRK /* disable mark parity errors */
1157 | ISTRIP /* disable clear high bit of input char */
1158 | INLCR /* disable translate NL to CR */
1159 | IGNCR /* disable ignore CR */
1160 | ICRNL /* disable translate CR to NL */
1161 | IXON); /* disable enable XON/XOFF flow control */
1163 tty->termios->c_oflag /* output modes */
1164 &= ~OPOST; /* disable postprocess output char */
1166 tty->termios->c_lflag /* line discipline modes */
1167 &= ~(ECHO /* disable echo input characters */
1168 | ECHONL /* disable echo new line */
1169 | ICANON /* disable erase, kill, werase, and rprnt
1170 special characters */
1171 | ISIG /* disable interrupt, quit, and suspend
1172 special characters */
1173 | IEXTEN); /* disable non-POSIX special characters */
1174 } /* CT_CYPHIDCOM: Application should handle this for device */
1176 linechange = (priv->line_control != oldlines);
1177 spin_unlock_irqrestore(&priv->lock, flags);
1179 /* if necessary, set lines */
1182 cypress_write(port, NULL, 0);
1184 } /* cypress_set_termios */
1187 /* returns amount of data still left in soft buffer */
1188 static int cypress_chars_in_buffer(struct usb_serial_port *port)
1190 struct cypress_private *priv = usb_get_serial_port_data(port);
1192 unsigned long flags;
1194 dbg("%s - port %d", __FUNCTION__, port->number);
1196 spin_lock_irqsave(&priv->lock, flags);
1197 chars = cypress_buf_data_avail(priv->buf);
1198 spin_unlock_irqrestore(&priv->lock, flags);
1200 dbg("%s - returns %d", __FUNCTION__, chars);
1205 static void cypress_throttle (struct usb_serial_port *port)
1207 struct cypress_private *priv = usb_get_serial_port_data(port);
1208 unsigned long flags;
1210 dbg("%s - port %d", __FUNCTION__, port->number);
1212 spin_lock_irqsave(&priv->lock, flags);
1213 priv->rx_flags = THROTTLED;
1214 spin_unlock_irqrestore(&priv->lock, flags);
1218 static void cypress_unthrottle (struct usb_serial_port *port)
1220 struct cypress_private *priv = usb_get_serial_port_data(port);
1221 int actually_throttled, result;
1222 unsigned long flags;
1224 dbg("%s - port %d", __FUNCTION__, port->number);
1226 spin_lock_irqsave(&priv->lock, flags);
1227 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
1229 spin_unlock_irqrestore(&priv->lock, flags);
1231 if (actually_throttled) {
1232 port->interrupt_in_urb->dev = port->serial->dev;
1234 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1236 dev_err(&port->dev, "%s - failed submitting read urb, "
1237 "error %d\n", __FUNCTION__, result);
1242 static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs)
1244 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1245 struct cypress_private *priv = usb_get_serial_port_data(port);
1246 struct tty_struct *tty;
1247 unsigned char *data = urb->transfer_buffer;
1248 unsigned long flags;
1249 char tty_flag = TTY_NORMAL;
1255 dbg("%s - port %d", __FUNCTION__, port->number);
1258 dbg("%s - nonzero read status received: %d", __FUNCTION__,
1263 spin_lock_irqsave(&priv->lock, flags);
1264 if (priv->rx_flags & THROTTLED) {
1265 dbg("%s - now throttling", __FUNCTION__);
1266 priv->rx_flags |= ACTUALLY_THROTTLED;
1267 spin_unlock_irqrestore(&priv->lock, flags);
1270 spin_unlock_irqrestore(&priv->lock, flags);
1274 dbg("%s - bad tty pointer - exiting", __FUNCTION__);
1278 spin_lock_irqsave(&priv->lock, flags);
1279 switch(urb->actual_length) {
1281 /* This is for the CY7C64013... */
1282 priv->current_status = data[0] & 0xF8;
1283 bytes = data[1] + 2;
1289 /* This is for the CY7C63743... */
1290 priv->current_status = data[0] & 0xF8;
1291 bytes = (data[0] & 0x07) + 1;
1297 dbg("%s - wrong packet size - received %d bytes",
1298 __FUNCTION__, urb->actual_length);
1299 spin_unlock_irqrestore(&priv->lock, flags);
1302 spin_unlock_irqrestore(&priv->lock, flags);
1304 usb_serial_debug_data (debug, &port->dev, __FUNCTION__,
1305 urb->actual_length, data);
1307 spin_lock_irqsave(&priv->lock, flags);
1308 /* check to see if status has changed */
1310 if (priv->current_status != priv->prev_status) {
1311 priv->diff_status |= priv->current_status ^
1313 wake_up_interruptible(&priv->delta_msr_wait);
1314 priv->prev_status = priv->current_status;
1317 spin_unlock_irqrestore(&priv->lock, flags);
1319 /* hangup, as defined in acm.c... this might be a bad place for it
1321 if (tty && !(tty->termios->c_cflag & CLOCAL) &&
1322 !(priv->current_status & UART_CD)) {
1323 dbg("%s - calling hangup", __FUNCTION__);
1328 /* There is one error bit... I'm assuming it is a parity error
1329 * indicator as the generic firmware will set this bit to 1 if a
1330 * parity error occurs.
1331 * I can not find reference to any other error events. */
1332 spin_lock_irqsave(&priv->lock, flags);
1333 if (priv->current_status & CYP_ERROR) {
1334 spin_unlock_irqrestore(&priv->lock, flags);
1335 tty_flag = TTY_PARITY;
1336 dbg("%s - Parity Error detected", __FUNCTION__);
1338 spin_unlock_irqrestore(&priv->lock, flags);
1340 /* process read if there is data other than line status */
1341 if (tty && (bytes > i)) {
1342 bytes = tty_buffer_request_room(tty, bytes);
1343 for (; i < bytes ; ++i) {
1344 dbg("pushing byte number %d - %d - %c", i, data[i],
1346 tty_insert_flip_char(tty, data[i], tty_flag);
1348 tty_flip_buffer_push(port->tty);
1351 spin_lock_irqsave(&priv->lock, flags);
1352 /* control and status byte(s) are also counted */
1353 priv->bytes_in += bytes;
1354 spin_unlock_irqrestore(&priv->lock, flags);
1358 /* Continue trying to always read... unless the port has closed. */
1360 if (port->open_count > 0) {
1361 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1362 usb_rcvintpipe(port->serial->dev,
1363 port->interrupt_in_endpointAddress),
1364 port->interrupt_in_urb->transfer_buffer,
1365 port->interrupt_in_urb->transfer_buffer_length,
1366 cypress_read_int_callback, port, priv->read_urb_interval);
1367 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1369 dev_err(&urb->dev->dev, "%s - failed resubmitting "
1370 "read urb, error %d\n", __FUNCTION__,
1375 } /* cypress_read_int_callback */
1378 static void cypress_write_int_callback(struct urb *urb, struct pt_regs *regs)
1380 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1381 struct cypress_private *priv = usb_get_serial_port_data(port);
1384 dbg("%s - port %d", __FUNCTION__, port->number);
1386 switch (urb->status) {
1393 /* this urb is terminated, clean up */
1394 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1395 priv->write_urb_in_use = 0;
1397 case -EPIPE: /* no break needed */
1398 usb_clear_halt(port->serial->dev, 0x02);
1400 /* error in the urb, so we have to resubmit it */
1401 dbg("%s - Overflow in write", __FUNCTION__);
1402 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
1403 port->interrupt_out_urb->transfer_buffer_length = 1;
1404 port->interrupt_out_urb->dev = port->serial->dev;
1405 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
1407 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n",
1408 __FUNCTION__, result);
1413 priv->write_urb_in_use = 0;
1415 /* send any buffered data */
1420 /*****************************************************************************
1421 * Write buffer functions - buffering code from pl2303 used
1422 *****************************************************************************/
1427 * Allocate a circular buffer and all associated memory.
1430 static struct cypress_buf *cypress_buf_alloc(unsigned int size)
1433 struct cypress_buf *cb;
1439 cb = (struct cypress_buf *)kmalloc(sizeof(struct cypress_buf), GFP_KERNEL);
1443 cb->buf_buf = kmalloc(size, GFP_KERNEL);
1444 if (cb->buf_buf == NULL) {
1449 cb->buf_size = size;
1450 cb->buf_get = cb->buf_put = cb->buf_buf;
1460 * Free the buffer and all associated memory.
1463 static void cypress_buf_free(struct cypress_buf *cb)
1475 * Clear out all data in the circular buffer.
1478 static void cypress_buf_clear(struct cypress_buf *cb)
1481 cb->buf_get = cb->buf_put;
1482 /* equivalent to a get of all data available */
1487 * cypress_buf_data_avail
1489 * Return the number of bytes of data available in the circular
1493 static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1496 return ((cb->buf_size + cb->buf_put - cb->buf_get) % cb->buf_size);
1503 * cypress_buf_space_avail
1505 * Return the number of bytes of space available in the circular
1509 static unsigned int cypress_buf_space_avail(struct cypress_buf *cb)
1512 return ((cb->buf_size + cb->buf_get - cb->buf_put - 1) % cb->buf_size);
1521 * Copy data data from a user buffer and put it into the circular buffer.
1522 * Restrict to the amount of space available.
1524 * Return the number of bytes copied.
1527 static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf,
1537 len = cypress_buf_space_avail(cb);
1544 len = cb->buf_buf + cb->buf_size - cb->buf_put;
1546 memcpy(cb->buf_put, buf, len);
1547 memcpy(cb->buf_buf, buf+len, count - len);
1548 cb->buf_put = cb->buf_buf + count - len;
1550 memcpy(cb->buf_put, buf, count);
1552 cb->buf_put += count;
1553 else /* count == len */
1554 cb->buf_put = cb->buf_buf;
1565 * Get data from the circular buffer and copy to the given buffer.
1566 * Restrict to the amount of data available.
1568 * Return the number of bytes copied.
1571 static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf,
1581 len = cypress_buf_data_avail(cb);
1588 len = cb->buf_buf + cb->buf_size - cb->buf_get;
1590 memcpy(buf, cb->buf_get, len);
1591 memcpy(buf+len, cb->buf_buf, count - len);
1592 cb->buf_get = cb->buf_buf + count - len;
1594 memcpy(buf, cb->buf_get, count);
1596 cb->buf_get += count;
1597 else /* count == len */
1598 cb->buf_get = cb->buf_buf;
1605 /*****************************************************************************
1607 *****************************************************************************/
1609 static int __init cypress_init(void)
1613 dbg("%s", __FUNCTION__);
1615 retval = usb_serial_register(&cypress_earthmate_device);
1617 goto failed_em_register;
1618 retval = usb_serial_register(&cypress_hidcom_device);
1620 goto failed_hidcom_register;
1621 retval = usb_serial_register(&cypress_ca42v2_device);
1623 goto failed_ca42v2_register;
1624 retval = usb_register(&cypress_driver);
1626 goto failed_usb_register;
1628 info(DRIVER_DESC " " DRIVER_VERSION);
1630 failed_usb_register:
1631 usb_deregister(&cypress_driver);
1632 failed_ca42v2_register:
1633 usb_serial_deregister(&cypress_ca42v2_device);
1634 failed_hidcom_register:
1635 usb_serial_deregister(&cypress_hidcom_device);
1637 usb_serial_deregister(&cypress_earthmate_device);
1643 static void __exit cypress_exit (void)
1645 dbg("%s", __FUNCTION__);
1647 usb_deregister (&cypress_driver);
1648 usb_serial_deregister (&cypress_earthmate_device);
1649 usb_serial_deregister (&cypress_hidcom_device);
1650 usb_serial_deregister (&cypress_ca42v2_device);
1654 module_init(cypress_init);
1655 module_exit(cypress_exit);
1657 MODULE_AUTHOR( DRIVER_AUTHOR );
1658 MODULE_DESCRIPTION( DRIVER_DESC );
1659 MODULE_VERSION( DRIVER_VERSION );
1660 MODULE_LICENSE("GPL");
1662 module_param(debug, bool, S_IRUGO | S_IWUSR);
1663 MODULE_PARM_DESC(debug, "Debug enabled or not");
1664 module_param(stats, bool, S_IRUGO | S_IWUSR);
1665 MODULE_PARM_DESC(stats, "Enable statistics or not");
1666 module_param(interval, int, S_IRUGO | S_IWUSR);
1667 MODULE_PARM_DESC(interval, "Overrides interrupt interval");