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 { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
98 { } /* Terminating entry */
101 static struct usb_device_id id_table_nokiaca42v2 [] = {
102 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
103 { } /* Terminating entry */
106 static struct usb_device_id id_table_combined [] = {
107 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
108 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
109 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
110 { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
111 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
112 { } /* Terminating entry */
115 MODULE_DEVICE_TABLE (usb, id_table_combined);
117 static struct usb_driver cypress_driver = {
119 .probe = usb_serial_probe,
120 .disconnect = usb_serial_disconnect,
121 .id_table = id_table_combined,
126 packet_format_1, /* b0:status, b1:payload count */
127 packet_format_2 /* b0[7:3]:status, b0[2:0]:payload count */
130 struct cypress_private {
131 spinlock_t lock; /* private lock */
132 int chiptype; /* identifier of device, for quirks/etc */
133 int bytes_in; /* used for statistics */
134 int bytes_out; /* used for statistics */
135 int cmd_count; /* used for statistics */
136 int cmd_ctrl; /* always set this to 1 before issuing a command */
137 struct cypress_buf *buf; /* write buffer */
138 int write_urb_in_use; /* write urb in use indicator */
139 int write_urb_interval; /* interval to use for write urb */
140 int read_urb_interval; /* interval to use for read urb */
141 int comm_is_ok; /* true if communication is (still) ok */
142 int termios_initialized;
143 __u8 line_control; /* holds dtr / rts value */
144 __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */
145 __u8 current_config; /* stores the current configuration byte */
146 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
147 enum packet_format pkt_fmt; /* format to use for packet send / receive */
148 int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */
149 int baud_rate; /* stores current baud rate in integer form */
150 int isthrottled; /* if throttled, discard reads */
151 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
152 char prev_status, diff_status; /* used for TIOCMIWAIT */
153 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
154 struct ktermios tmp_termios; /* stores the old termios settings */
157 /* write buffer structure */
159 unsigned int buf_size;
165 /* function prototypes for the Cypress USB to serial device */
166 static int cypress_earthmate_startup (struct usb_serial *serial);
167 static int cypress_hidcom_startup (struct usb_serial *serial);
168 static int cypress_ca42v2_startup (struct usb_serial *serial);
169 static void cypress_shutdown (struct usb_serial *serial);
170 static int cypress_open (struct usb_serial_port *port, struct file *filp);
171 static void cypress_close (struct usb_serial_port *port, struct file *filp);
172 static int cypress_write (struct usb_serial_port *port, const unsigned char *buf, int count);
173 static void cypress_send (struct usb_serial_port *port);
174 static int cypress_write_room (struct usb_serial_port *port);
175 static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
176 static void cypress_set_termios (struct usb_serial_port *port, struct ktermios * old);
177 static int cypress_tiocmget (struct usb_serial_port *port, struct file *file);
178 static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
179 static int cypress_chars_in_buffer (struct usb_serial_port *port);
180 static void cypress_throttle (struct usb_serial_port *port);
181 static void cypress_unthrottle (struct usb_serial_port *port);
182 static void cypress_set_dead (struct usb_serial_port *port);
183 static void cypress_read_int_callback (struct urb *urb);
184 static void cypress_write_int_callback (struct urb *urb);
185 /* write buffer functions */
186 static struct cypress_buf *cypress_buf_alloc(unsigned int size);
187 static void cypress_buf_free(struct cypress_buf *cb);
188 static void cypress_buf_clear(struct cypress_buf *cb);
189 static unsigned int cypress_buf_data_avail(struct cypress_buf *cb);
190 static unsigned int cypress_buf_space_avail(struct cypress_buf *cb);
191 static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf, unsigned int count);
192 static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count);
195 static struct usb_serial_driver cypress_earthmate_device = {
197 .owner = THIS_MODULE,
200 .description = "DeLorme Earthmate USB",
201 .usb_driver = &cypress_driver,
202 .id_table = id_table_earthmate,
203 .num_interrupt_in = 1,
204 .num_interrupt_out = 1,
205 .num_bulk_in = NUM_DONT_CARE,
206 .num_bulk_out = NUM_DONT_CARE,
208 .attach = cypress_earthmate_startup,
209 .shutdown = cypress_shutdown,
210 .open = cypress_open,
211 .close = cypress_close,
212 .write = cypress_write,
213 .write_room = cypress_write_room,
214 .ioctl = cypress_ioctl,
215 .set_termios = cypress_set_termios,
216 .tiocmget = cypress_tiocmget,
217 .tiocmset = cypress_tiocmset,
218 .chars_in_buffer = cypress_chars_in_buffer,
219 .throttle = cypress_throttle,
220 .unthrottle = cypress_unthrottle,
221 .read_int_callback = cypress_read_int_callback,
222 .write_int_callback = cypress_write_int_callback,
225 static struct usb_serial_driver cypress_hidcom_device = {
227 .owner = THIS_MODULE,
230 .description = "HID->COM RS232 Adapter",
231 .usb_driver = &cypress_driver,
232 .id_table = id_table_cyphidcomrs232,
233 .num_interrupt_in = 1,
234 .num_interrupt_out = 1,
235 .num_bulk_in = NUM_DONT_CARE,
236 .num_bulk_out = NUM_DONT_CARE,
238 .attach = cypress_hidcom_startup,
239 .shutdown = cypress_shutdown,
240 .open = cypress_open,
241 .close = cypress_close,
242 .write = cypress_write,
243 .write_room = cypress_write_room,
244 .ioctl = cypress_ioctl,
245 .set_termios = cypress_set_termios,
246 .tiocmget = cypress_tiocmget,
247 .tiocmset = cypress_tiocmset,
248 .chars_in_buffer = cypress_chars_in_buffer,
249 .throttle = cypress_throttle,
250 .unthrottle = cypress_unthrottle,
251 .read_int_callback = cypress_read_int_callback,
252 .write_int_callback = cypress_write_int_callback,
255 static struct usb_serial_driver cypress_ca42v2_device = {
257 .owner = THIS_MODULE,
258 .name = "nokiaca42v2",
260 .description = "Nokia CA-42 V2 Adapter",
261 .usb_driver = &cypress_driver,
262 .id_table = id_table_nokiaca42v2,
263 .num_interrupt_in = 1,
264 .num_interrupt_out = 1,
265 .num_bulk_in = NUM_DONT_CARE,
266 .num_bulk_out = NUM_DONT_CARE,
268 .attach = cypress_ca42v2_startup,
269 .shutdown = cypress_shutdown,
270 .open = cypress_open,
271 .close = cypress_close,
272 .write = cypress_write,
273 .write_room = cypress_write_room,
274 .ioctl = cypress_ioctl,
275 .set_termios = cypress_set_termios,
276 .tiocmget = cypress_tiocmget,
277 .tiocmset = cypress_tiocmset,
278 .chars_in_buffer = cypress_chars_in_buffer,
279 .throttle = cypress_throttle,
280 .unthrottle = cypress_unthrottle,
281 .read_int_callback = cypress_read_int_callback,
282 .write_int_callback = cypress_write_int_callback,
285 /*****************************************************************************
286 * Cypress serial helper functions
287 *****************************************************************************/
290 static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
292 struct cypress_private *priv;
293 priv = usb_get_serial_port_data(port);
296 * The general purpose firmware for the Cypress M8 allows for
297 * a maximum speed of 57600bps (I have no idea whether DeLorme
298 * chose to use the general purpose firmware or not), if you
299 * need to modify this speed setting for your own project
300 * please add your own chiptype and modify the code likewise.
301 * The Cypress HID->COM device will work successfully up to
302 * 115200bps (but the actual throughput is around 3kBps).
304 if (port->serial->dev->speed == USB_SPEED_LOW) {
306 * Mike Isely <isely@pobox.com> 2-Feb-2008: The
307 * Cypress app note that describes this mechanism
308 * states the the low-speed part can't handle more
309 * than 800 bytes/sec, in which case 4800 baud is the
310 * safest speed for a part like that.
312 if (new_rate > 4800) {
313 dbg("%s - failed setting baud rate, device incapable "
314 "speed %d", __func__, new_rate);
318 switch (priv->chiptype) {
320 if (new_rate <= 600) {
321 /* 300 and 600 baud rates are supported under
322 * the generic firmware, but are not used with
323 * NMEA and SiRF protocols */
324 dbg("%s - failed setting baud rate, unsupported speed "
325 "of %d on Earthmate GPS", __func__, new_rate);
336 /* This function can either set or retrieve the current serial line settings */
337 static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_rate, int data_bits, int stop_bits,
338 int parity_enable, int parity_type, int reset, int cypress_request_type)
340 int new_baudrate = 0, retval = 0, tries = 0;
341 struct cypress_private *priv;
342 __u8 feature_buffer[5];
345 dbg("%s", __FUNCTION__);
347 priv = usb_get_serial_port_data(port);
349 if (!priv->comm_is_ok)
352 switch(cypress_request_type) {
353 case CYPRESS_SET_CONFIG:
354 new_baudrate = priv->baud_rate;
355 /* 0 means 'Hang up' so doesn't change the true bit rate */
357 new_baudrate = priv->baud_rate;
358 /* Change of speed ? */
359 else if (baud_rate != priv->baud_rate) {
360 dbg("%s - baud rate is changing", __FUNCTION__);
361 retval = analyze_baud_rate(port, baud_rate);
363 new_baudrate = retval;
364 dbg("%s - New baud rate set to %d",
365 __func__, new_baudrate);
368 dbg("%s - baud rate is being sent as %d", __FUNCTION__, new_baudrate);
370 memset(feature_buffer, 0, sizeof(feature_buffer));
371 /* fill the feature_buffer with new configuration */
372 *((u_int32_t *)feature_buffer) = new_baudrate;
374 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
376 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
377 feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
378 feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
380 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
382 dbg("%s - device is being sent this feature report:", __FUNCTION__);
383 dbg("%s - %02X - %02X - %02X - %02X - %02X", __FUNCTION__, feature_buffer[0], feature_buffer[1],
384 feature_buffer[2], feature_buffer[3], feature_buffer[4]);
387 retval = usb_control_msg(port->serial->dev,
388 usb_sndctrlpipe(port->serial->dev, 0),
390 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
391 0x0300, 0, feature_buffer,
392 sizeof(feature_buffer), 500);
397 } while (retval != sizeof(feature_buffer) &&
400 if (retval != sizeof(feature_buffer)) {
401 err("%s - failed sending serial line settings - %d", __FUNCTION__, retval);
402 cypress_set_dead(port);
404 spin_lock_irqsave(&priv->lock, flags);
405 priv->baud_rate = new_baudrate;
406 priv->current_config = feature_buffer[4];
407 spin_unlock_irqrestore(&priv->lock, flags);
408 /* If we asked for a speed change encode it */
410 tty_encode_baud_rate(port->tty,
411 new_baudrate, new_baudrate);
414 case CYPRESS_GET_CONFIG:
415 if (priv->get_cfg_unsafe) {
416 /* Not implemented for this device,
417 and if we try to do it we're likely
418 to crash the hardware. */
421 dbg("%s - retreiving serial line settings", __FUNCTION__);
422 /* set initial values in feature buffer */
423 memset(feature_buffer, 0, sizeof(feature_buffer));
426 retval = usb_control_msg(port->serial->dev,
427 usb_rcvctrlpipe(port->serial->dev, 0),
429 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
430 0x0300, 0, feature_buffer,
431 sizeof(feature_buffer), 500);
436 } while (retval != sizeof(feature_buffer) &&
439 if (retval != sizeof(feature_buffer)) {
440 err("%s - failed to retrieve serial line settings - %d", __FUNCTION__, retval);
441 cypress_set_dead(port);
444 spin_lock_irqsave(&priv->lock, flags);
446 /* store the config in one byte, and later use bit masks to check values */
447 priv->current_config = feature_buffer[4];
448 priv->baud_rate = *((u_int32_t *)feature_buffer);
449 spin_unlock_irqrestore(&priv->lock, flags);
452 spin_lock_irqsave(&priv->lock, flags);
454 spin_unlock_irqrestore(&priv->lock, flags);
457 } /* cypress_serial_control */
460 static void cypress_set_dead(struct usb_serial_port *port)
462 struct cypress_private *priv = usb_get_serial_port_data(port);
465 spin_lock_irqsave(&priv->lock, flags);
466 if (!priv->comm_is_ok) {
467 spin_unlock_irqrestore(&priv->lock, flags);
470 priv->comm_is_ok = 0;
471 spin_unlock_irqrestore(&priv->lock, flags);
473 err("cypress_m8 suspending failing port %d - interval might be too short",
478 /*****************************************************************************
479 * Cypress serial driver functions
480 *****************************************************************************/
483 static int generic_startup (struct usb_serial *serial)
485 struct cypress_private *priv;
486 struct usb_serial_port *port = serial->port[0];
488 dbg("%s - port %d", __FUNCTION__, port->number);
490 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL);
494 priv->comm_is_ok = !0;
495 spin_lock_init(&priv->lock);
496 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE);
497 if (priv->buf == NULL) {
501 init_waitqueue_head(&priv->delta_msr_wait);
503 usb_reset_configuration (serial->dev);
506 priv->line_control = 0;
507 priv->termios_initialized = 0;
509 /* Default packet format setting is determined by packet size.
510 Anything with a size larger then 9 must have a separate
511 count field since the 3 bit count field is otherwise too
512 small. Otherwise we can use the slightly more compact
513 format. This is in accordance with the cypress_m8 serial
514 converter app note. */
515 if (port->interrupt_out_size > 9) {
516 priv->pkt_fmt = packet_format_1;
518 priv->pkt_fmt = packet_format_2;
521 priv->write_urb_interval = interval;
522 priv->read_urb_interval = interval;
523 dbg("%s - port %d read & write intervals forced to %d",
524 __FUNCTION__,port->number,interval);
526 priv->write_urb_interval = port->interrupt_out_urb->interval;
527 priv->read_urb_interval = port->interrupt_in_urb->interval;
528 dbg("%s - port %d intervals: read=%d write=%d",
529 __FUNCTION__,port->number,
530 priv->read_urb_interval,priv->write_urb_interval);
532 usb_set_serial_port_data(port, priv);
538 static int cypress_earthmate_startup (struct usb_serial *serial)
540 struct cypress_private *priv;
541 struct usb_serial_port *port = serial->port[0];
543 dbg("%s", __FUNCTION__);
545 if (generic_startup(serial)) {
546 dbg("%s - Failed setting up port %d", __FUNCTION__,
551 priv = usb_get_serial_port_data(port);
552 priv->chiptype = CT_EARTHMATE;
553 /* All Earthmate devices use the separated-count packet
555 priv->pkt_fmt = packet_format_1;
556 if (serial->dev->descriptor.idProduct != PRODUCT_ID_EARTHMATEUSB) {
557 /* The old original USB Earthmate seemed able to
558 handle GET_CONFIG requests; everything they've
559 produced since that time crashes if this command is
561 dbg("%s - Marking this device as unsafe for GET_CONFIG "
562 "commands", __func__);
563 priv->get_cfg_unsafe = !0;
567 } /* cypress_earthmate_startup */
570 static int cypress_hidcom_startup (struct usb_serial *serial)
572 struct cypress_private *priv;
574 dbg("%s", __FUNCTION__);
576 if (generic_startup(serial)) {
577 dbg("%s - Failed setting up port %d", __FUNCTION__,
578 serial->port[0]->number);
582 priv = usb_get_serial_port_data(serial->port[0]);
583 priv->chiptype = CT_CYPHIDCOM;
586 } /* cypress_hidcom_startup */
589 static int cypress_ca42v2_startup (struct usb_serial *serial)
591 struct cypress_private *priv;
593 dbg("%s", __FUNCTION__);
595 if (generic_startup(serial)) {
596 dbg("%s - Failed setting up port %d", __FUNCTION__,
597 serial->port[0]->number);
601 priv = usb_get_serial_port_data(serial->port[0]);
602 priv->chiptype = CT_CA42V2;
605 } /* cypress_ca42v2_startup */
608 static void cypress_shutdown (struct usb_serial *serial)
610 struct cypress_private *priv;
612 dbg ("%s - port %d", __FUNCTION__, serial->port[0]->number);
614 /* all open ports are closed at this point */
616 priv = usb_get_serial_port_data(serial->port[0]);
619 cypress_buf_free(priv->buf);
621 usb_set_serial_port_data(serial->port[0], NULL);
626 static int cypress_open (struct usb_serial_port *port, struct file *filp)
628 struct cypress_private *priv = usb_get_serial_port_data(port);
629 struct usb_serial *serial = port->serial;
633 dbg("%s - port %d", __FUNCTION__, port->number);
635 if (!priv->comm_is_ok)
638 /* clear halts before open */
639 usb_clear_halt(serial->dev, 0x81);
640 usb_clear_halt(serial->dev, 0x02);
642 spin_lock_irqsave(&priv->lock, flags);
643 /* reset read/write statistics */
648 spin_unlock_irqrestore(&priv->lock, flags);
650 /* setting to zero could cause data loss */
651 port->tty->low_latency = 1;
653 /* raise both lines and set termios */
654 spin_lock_irqsave(&priv->lock, flags);
655 priv->line_control = CONTROL_DTR | CONTROL_RTS;
657 spin_unlock_irqrestore(&priv->lock, flags);
658 result = cypress_write(port, NULL, 0);
661 dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __FUNCTION__, result);
664 dbg("%s - success setting the control lines", __FUNCTION__);
666 cypress_set_termios(port, &priv->tmp_termios);
668 /* setup the port and start reading from the device */
669 if(!port->interrupt_in_urb){
670 err("%s - interrupt_in_urb is empty!", __FUNCTION__);
674 usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
675 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
676 port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length,
677 cypress_read_int_callback, port, priv->read_urb_interval);
678 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
681 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
682 cypress_set_dead(port);
689 static void cypress_close(struct usb_serial_port *port, struct file * filp)
691 struct cypress_private *priv = usb_get_serial_port_data(port);
692 unsigned int c_cflag;
697 dbg("%s - port %d", __FUNCTION__, port->number);
699 /* wait for data to drain from buffer */
700 spin_lock_irq(&priv->lock);
701 timeout = CYPRESS_CLOSING_WAIT;
702 init_waitqueue_entry(&wait, current);
703 add_wait_queue(&port->tty->write_wait, &wait);
705 set_current_state(TASK_INTERRUPTIBLE);
706 if (cypress_buf_data_avail(priv->buf) == 0
707 || timeout == 0 || signal_pending(current)
708 /* without mutex, allowed due to harmless failure mode */
709 || port->serial->disconnected)
711 spin_unlock_irq(&priv->lock);
712 timeout = schedule_timeout(timeout);
713 spin_lock_irq(&priv->lock);
715 set_current_state(TASK_RUNNING);
716 remove_wait_queue(&port->tty->write_wait, &wait);
717 /* clear out any remaining data in the buffer */
718 cypress_buf_clear(priv->buf);
719 spin_unlock_irq(&priv->lock);
721 /* writing is potentially harmful, lock must be taken */
722 mutex_lock(&port->serial->disc_mutex);
723 if (port->serial->disconnected) {
724 mutex_unlock(&port->serial->disc_mutex);
727 /* wait for characters to drain from device */
728 bps = tty_get_baud_rate(port->tty);
730 timeout = max((HZ*2560)/bps,HZ/10);
733 schedule_timeout_interruptible(timeout);
735 dbg("%s - stopping urbs", __FUNCTION__);
736 usb_kill_urb (port->interrupt_in_urb);
737 usb_kill_urb (port->interrupt_out_urb);
740 c_cflag = port->tty->termios->c_cflag;
741 if (c_cflag & HUPCL) {
742 /* drop dtr and rts */
743 priv = usb_get_serial_port_data(port);
744 spin_lock_irq(&priv->lock);
745 priv->line_control = 0;
747 spin_unlock_irq(&priv->lock);
748 cypress_write(port, NULL, 0);
753 dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
754 priv->bytes_in, priv->bytes_out, priv->cmd_count);
755 mutex_unlock(&port->serial->disc_mutex);
756 } /* cypress_close */
759 static int cypress_write(struct usb_serial_port *port, const unsigned char *buf, int count)
761 struct cypress_private *priv = usb_get_serial_port_data(port);
764 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
766 /* line control commands, which need to be executed immediately,
767 are not put into the buffer for obvious reasons.
769 if (priv->cmd_ctrl) {
777 spin_lock_irqsave(&priv->lock, flags);
778 count = cypress_buf_put(priv->buf, buf, count);
779 spin_unlock_irqrestore(&priv->lock, flags);
785 } /* cypress_write */
788 static void cypress_send(struct usb_serial_port *port)
790 int count = 0, result, offset, actual_size;
791 struct cypress_private *priv = usb_get_serial_port_data(port);
794 if (!priv->comm_is_ok)
797 dbg("%s - port %d", __FUNCTION__, port->number);
798 dbg("%s - interrupt out size is %d", __FUNCTION__, port->interrupt_out_size);
800 spin_lock_irqsave(&priv->lock, flags);
801 if (priv->write_urb_in_use) {
802 dbg("%s - can't write, urb in use", __FUNCTION__);
803 spin_unlock_irqrestore(&priv->lock, flags);
806 spin_unlock_irqrestore(&priv->lock, flags);
809 memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size);
811 spin_lock_irqsave(&priv->lock, flags);
812 switch (priv->pkt_fmt) {
814 case packet_format_1:
815 /* this is for the CY7C64013... */
817 port->interrupt_out_buffer[0] = priv->line_control;
819 case packet_format_2:
820 /* this is for the CY7C63743... */
822 port->interrupt_out_buffer[0] = priv->line_control;
826 if (priv->line_control & CONTROL_RESET)
827 priv->line_control &= ~CONTROL_RESET;
829 if (priv->cmd_ctrl) {
831 dbg("%s - line control command being issued", __FUNCTION__);
832 spin_unlock_irqrestore(&priv->lock, flags);
835 spin_unlock_irqrestore(&priv->lock, flags);
837 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset],
838 port->interrupt_out_size-offset);
844 switch (priv->pkt_fmt) {
846 case packet_format_1:
847 port->interrupt_out_buffer[1] = count;
849 case packet_format_2:
850 port->interrupt_out_buffer[0] |= count;
853 dbg("%s - count is %d", __FUNCTION__, count);
856 spin_lock_irqsave(&priv->lock, flags);
857 priv->write_urb_in_use = 1;
858 spin_unlock_irqrestore(&priv->lock, flags);
863 actual_size = count +
864 (priv->pkt_fmt == packet_format_1 ? 2 : 1);
866 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, port->interrupt_out_size,
867 port->interrupt_out_urb->transfer_buffer);
869 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
870 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress),
871 port->interrupt_out_buffer, port->interrupt_out_size,
872 cypress_write_int_callback, port, priv->write_urb_interval);
873 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC);
875 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__,
877 priv->write_urb_in_use = 0;
878 cypress_set_dead(port);
881 spin_lock_irqsave(&priv->lock, flags);
882 if (priv->cmd_ctrl) {
885 priv->bytes_out += count; /* do not count the line control and size bytes */
886 spin_unlock_irqrestore(&priv->lock, flags);
888 usb_serial_port_softint(port);
892 /* returns how much space is available in the soft buffer */
893 static int cypress_write_room(struct usb_serial_port *port)
895 struct cypress_private *priv = usb_get_serial_port_data(port);
899 dbg("%s - port %d", __FUNCTION__, port->number);
901 spin_lock_irqsave(&priv->lock, flags);
902 room = cypress_buf_space_avail(priv->buf);
903 spin_unlock_irqrestore(&priv->lock, flags);
905 dbg("%s - returns %d", __FUNCTION__, room);
910 static int cypress_tiocmget (struct usb_serial_port *port, struct file *file)
912 struct cypress_private *priv = usb_get_serial_port_data(port);
913 __u8 status, control;
914 unsigned int result = 0;
917 dbg("%s - port %d", __FUNCTION__, port->number);
919 spin_lock_irqsave(&priv->lock, flags);
920 control = priv->line_control;
921 status = priv->current_status;
922 spin_unlock_irqrestore(&priv->lock, flags);
924 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
925 | ((control & CONTROL_RTS) ? TIOCM_RTS : 0)
926 | ((status & UART_CTS) ? TIOCM_CTS : 0)
927 | ((status & UART_DSR) ? TIOCM_DSR : 0)
928 | ((status & UART_RI) ? TIOCM_RI : 0)
929 | ((status & UART_CD) ? TIOCM_CD : 0);
931 dbg("%s - result = %x", __FUNCTION__, result);
937 static int cypress_tiocmset (struct usb_serial_port *port, struct file *file,
938 unsigned int set, unsigned int clear)
940 struct cypress_private *priv = usb_get_serial_port_data(port);
943 dbg("%s - port %d", __FUNCTION__, port->number);
945 spin_lock_irqsave(&priv->lock, flags);
947 priv->line_control |= CONTROL_RTS;
949 priv->line_control |= CONTROL_DTR;
950 if (clear & TIOCM_RTS)
951 priv->line_control &= ~CONTROL_RTS;
952 if (clear & TIOCM_DTR)
953 priv->line_control &= ~CONTROL_DTR;
955 spin_unlock_irqrestore(&priv->lock, flags);
957 return cypress_write(port, NULL, 0);
961 static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
963 struct cypress_private *priv = usb_get_serial_port_data(port);
965 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
968 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
970 while (priv != NULL) {
971 interruptible_sleep_on(&priv->delta_msr_wait);
972 /* see if a signal did it */
973 if (signal_pending(current))
976 char diff = priv->diff_status;
979 return -EIO; /* no change => error */
982 /* consume all events */
983 priv->diff_status = 0;
985 /* return 0 if caller wanted to know about these bits */
986 if ( ((arg & TIOCM_RNG) && (diff & UART_RI)) ||
987 ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
988 ((arg & TIOCM_CD) && (diff & UART_CD)) ||
989 ((arg & TIOCM_CTS) && (diff & UART_CTS)) ) {
992 /* otherwise caller can't care less about what happened,
993 * and so we continue to wait for more events.
1003 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __FUNCTION__, cmd);
1005 return -ENOIOCTLCMD;
1006 } /* cypress_ioctl */
1009 static void cypress_set_termios (struct usb_serial_port *port,
1010 struct ktermios *old_termios)
1012 struct cypress_private *priv = usb_get_serial_port_data(port);
1013 struct tty_struct *tty;
1014 int data_bits, stop_bits, parity_type, parity_enable;
1015 unsigned cflag, iflag;
1016 unsigned long flags;
1020 dbg("%s - port %d", __FUNCTION__, port->number);
1024 spin_lock_irqsave(&priv->lock, flags);
1025 if (!priv->termios_initialized) {
1026 if (priv->chiptype == CT_EARTHMATE) {
1027 *(tty->termios) = tty_std_termios;
1028 tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL |
1030 tty->termios->c_ispeed = 4800;
1031 tty->termios->c_ospeed = 4800;
1032 } else if (priv->chiptype == CT_CYPHIDCOM) {
1033 *(tty->termios) = tty_std_termios;
1034 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1036 tty->termios->c_ispeed = 9600;
1037 tty->termios->c_ospeed = 9600;
1038 } else if (priv->chiptype == CT_CA42V2) {
1039 *(tty->termios) = tty_std_termios;
1040 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1042 tty->termios->c_ispeed = 9600;
1043 tty->termios->c_ospeed = 9600;
1045 priv->termios_initialized = 1;
1047 spin_unlock_irqrestore(&priv->lock, flags);
1049 /* Unsupported features need clearing */
1050 tty->termios->c_cflag &= ~(CMSPAR|CRTSCTS);
1052 cflag = tty->termios->c_cflag;
1053 iflag = tty->termios->c_iflag;
1055 /* check if there are new settings */
1057 spin_lock_irqsave(&priv->lock, flags);
1058 priv->tmp_termios = *(tty->termios);
1059 spin_unlock_irqrestore(&priv->lock, flags);
1062 /* set number of data bits, parity, stop bits */
1063 /* when parity is disabled the parity type bit is ignored */
1065 /* 1 means 2 stop bits, 0 means 1 stop bit */
1066 stop_bits = cflag & CSTOPB ? 1 : 0;
1068 if (cflag & PARENB) {
1070 /* 1 means odd parity, 0 means even parity */
1071 parity_type = cflag & PARODD ? 1 : 0;
1073 parity_enable = parity_type = 0;
1075 if (cflag & CSIZE) {
1076 switch (cflag & CSIZE) {
1090 err("%s - CSIZE was set, but not CS5-CS8",
1097 spin_lock_irqsave(&priv->lock, flags);
1098 oldlines = priv->line_control;
1099 if ((cflag & CBAUD) == B0) {
1100 /* drop dtr and rts */
1101 dbg("%s - dropping the lines, baud rate 0bps", __FUNCTION__);
1102 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
1104 priv->line_control = (CONTROL_DTR | CONTROL_RTS);
1105 spin_unlock_irqrestore(&priv->lock, flags);
1107 dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, "
1108 "%d data_bits (+5)", __FUNCTION__, stop_bits,
1109 parity_enable, parity_type, data_bits);
1111 cypress_serial_control(port, tty_get_baud_rate(tty), data_bits, stop_bits,
1112 parity_enable, parity_type, 0, CYPRESS_SET_CONFIG);
1114 /* we perform a CYPRESS_GET_CONFIG so that the current settings are
1115 * filled into the private structure this should confirm that all is
1116 * working if it returns what we just set */
1117 cypress_serial_control(port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
1119 /* Here we can define custom tty settings for devices; the main tty
1120 * termios flag base comes from empeg.c */
1122 spin_lock_irqsave(&priv->lock, flags);
1123 if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) {
1124 dbg("Using custom termios settings for a baud rate of "
1126 /* define custom termios settings for NMEA protocol */
1128 tty->termios->c_iflag /* input modes - */
1129 &= ~(IGNBRK /* disable ignore break */
1130 | BRKINT /* disable break causes interrupt */
1131 | PARMRK /* disable mark parity errors */
1132 | ISTRIP /* disable clear high bit of input char */
1133 | INLCR /* disable translate NL to CR */
1134 | IGNCR /* disable ignore CR */
1135 | ICRNL /* disable translate CR to NL */
1136 | IXON); /* disable enable XON/XOFF flow control */
1138 tty->termios->c_oflag /* output modes */
1139 &= ~OPOST; /* disable postprocess output char */
1141 tty->termios->c_lflag /* line discipline modes */
1142 &= ~(ECHO /* disable echo input characters */
1143 | ECHONL /* disable echo new line */
1144 | ICANON /* disable erase, kill, werase, and rprnt
1145 special characters */
1146 | ISIG /* disable interrupt, quit, and suspend
1147 special characters */
1148 | IEXTEN); /* disable non-POSIX special characters */
1149 } /* CT_CYPHIDCOM: Application should handle this for device */
1151 linechange = (priv->line_control != oldlines);
1152 spin_unlock_irqrestore(&priv->lock, flags);
1154 /* if necessary, set lines */
1157 cypress_write(port, NULL, 0);
1159 } /* cypress_set_termios */
1162 /* returns amount of data still left in soft buffer */
1163 static int cypress_chars_in_buffer(struct usb_serial_port *port)
1165 struct cypress_private *priv = usb_get_serial_port_data(port);
1167 unsigned long flags;
1169 dbg("%s - port %d", __FUNCTION__, port->number);
1171 spin_lock_irqsave(&priv->lock, flags);
1172 chars = cypress_buf_data_avail(priv->buf);
1173 spin_unlock_irqrestore(&priv->lock, flags);
1175 dbg("%s - returns %d", __FUNCTION__, chars);
1180 static void cypress_throttle (struct usb_serial_port *port)
1182 struct cypress_private *priv = usb_get_serial_port_data(port);
1183 unsigned long flags;
1185 dbg("%s - port %d", __FUNCTION__, port->number);
1187 spin_lock_irqsave(&priv->lock, flags);
1188 priv->rx_flags = THROTTLED;
1189 spin_unlock_irqrestore(&priv->lock, flags);
1193 static void cypress_unthrottle (struct usb_serial_port *port)
1195 struct cypress_private *priv = usb_get_serial_port_data(port);
1196 int actually_throttled, result;
1197 unsigned long flags;
1199 dbg("%s - port %d", __FUNCTION__, port->number);
1201 spin_lock_irqsave(&priv->lock, flags);
1202 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
1204 spin_unlock_irqrestore(&priv->lock, flags);
1206 if (!priv->comm_is_ok)
1209 if (actually_throttled) {
1210 port->interrupt_in_urb->dev = port->serial->dev;
1212 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1214 dev_err(&port->dev, "%s - failed submitting read urb, "
1215 "error %d\n", __FUNCTION__, result);
1216 cypress_set_dead(port);
1222 static void cypress_read_int_callback(struct urb *urb)
1224 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1225 struct cypress_private *priv = usb_get_serial_port_data(port);
1226 struct tty_struct *tty;
1227 unsigned char *data = urb->transfer_buffer;
1228 unsigned long flags;
1229 char tty_flag = TTY_NORMAL;
1234 int status = urb->status;
1236 dbg("%s - port %d", __FUNCTION__, port->number);
1239 case 0: /* success */
1244 /* precursor to disconnect so just go away */
1247 usb_clear_halt(port->serial->dev,0x81);
1250 /* something ugly is going on... */
1251 dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n",
1252 __FUNCTION__, status);
1253 cypress_set_dead(port);
1257 spin_lock_irqsave(&priv->lock, flags);
1258 if (priv->rx_flags & THROTTLED) {
1259 dbg("%s - now throttling", __FUNCTION__);
1260 priv->rx_flags |= ACTUALLY_THROTTLED;
1261 spin_unlock_irqrestore(&priv->lock, flags);
1264 spin_unlock_irqrestore(&priv->lock, flags);
1268 dbg("%s - bad tty pointer - exiting", __FUNCTION__);
1272 spin_lock_irqsave(&priv->lock, flags);
1273 result = urb->actual_length;
1274 switch (priv->pkt_fmt) {
1276 case packet_format_1:
1277 /* This is for the CY7C64013... */
1278 priv->current_status = data[0] & 0xF8;
1279 bytes = data[1] + 2;
1284 case packet_format_2:
1285 /* This is for the CY7C63743... */
1286 priv->current_status = data[0] & 0xF8;
1287 bytes = (data[0] & 0x07) + 1;
1293 spin_unlock_irqrestore(&priv->lock, flags);
1294 if (result < bytes) {
1295 dbg("%s - wrong packet size - received %d bytes but packet "
1296 "said %d bytes", __func__, result, bytes);
1300 usb_serial_debug_data (debug, &port->dev, __FUNCTION__,
1301 urb->actual_length, data);
1303 spin_lock_irqsave(&priv->lock, flags);
1304 /* check to see if status has changed */
1305 if (priv->current_status != priv->prev_status) {
1306 priv->diff_status |= priv->current_status ^
1308 wake_up_interruptible(&priv->delta_msr_wait);
1309 priv->prev_status = priv->current_status;
1311 spin_unlock_irqrestore(&priv->lock, flags);
1313 /* hangup, as defined in acm.c... this might be a bad place for it
1315 if (tty && !(tty->termios->c_cflag & CLOCAL) &&
1316 !(priv->current_status & UART_CD)) {
1317 dbg("%s - calling hangup", __FUNCTION__);
1322 /* There is one error bit... I'm assuming it is a parity error
1323 * indicator as the generic firmware will set this bit to 1 if a
1324 * parity error occurs.
1325 * I can not find reference to any other error events. */
1326 spin_lock_irqsave(&priv->lock, flags);
1327 if (priv->current_status & CYP_ERROR) {
1328 spin_unlock_irqrestore(&priv->lock, flags);
1329 tty_flag = TTY_PARITY;
1330 dbg("%s - Parity Error detected", __FUNCTION__);
1332 spin_unlock_irqrestore(&priv->lock, flags);
1334 /* process read if there is data other than line status */
1335 if (tty && (bytes > i)) {
1336 bytes = tty_buffer_request_room(tty, bytes);
1337 for (; i < bytes ; ++i) {
1338 dbg("pushing byte number %d - %d - %c", i, data[i],
1340 tty_insert_flip_char(tty, data[i], tty_flag);
1342 tty_flip_buffer_push(port->tty);
1345 spin_lock_irqsave(&priv->lock, flags);
1346 /* control and status byte(s) are also counted */
1347 priv->bytes_in += bytes;
1348 spin_unlock_irqrestore(&priv->lock, flags);
1352 /* Continue trying to always read... unless the port has closed. */
1354 if (port->open_count > 0 && priv->comm_is_ok) {
1355 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1356 usb_rcvintpipe(port->serial->dev,
1357 port->interrupt_in_endpointAddress),
1358 port->interrupt_in_urb->transfer_buffer,
1359 port->interrupt_in_urb->transfer_buffer_length,
1360 cypress_read_int_callback, port, priv->read_urb_interval);
1361 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1363 dev_err(&urb->dev->dev, "%s - failed resubmitting "
1364 "read urb, error %d\n", __FUNCTION__,
1366 cypress_set_dead(port);
1371 } /* cypress_read_int_callback */
1374 static void cypress_write_int_callback(struct urb *urb)
1376 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1377 struct cypress_private *priv = usb_get_serial_port_data(port);
1379 int status = urb->status;
1381 dbg("%s - port %d", __FUNCTION__, port->number);
1390 /* this urb is terminated, clean up */
1391 dbg("%s - urb shutting down with status: %d",
1392 __FUNCTION__, status);
1393 priv->write_urb_in_use = 0;
1395 case -EPIPE: /* no break needed; clear halt and resubmit */
1396 if (!priv->comm_is_ok)
1398 usb_clear_halt(port->serial->dev, 0x02);
1399 /* error in the urb, so we have to resubmit it */
1400 dbg("%s - nonzero write bulk status received: %d",
1401 __FUNCTION__, status);
1402 port->interrupt_out_urb->transfer_buffer_length = 1;
1403 port->interrupt_out_urb->dev = port->serial->dev;
1404 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);
1409 cypress_set_dead(port);
1412 dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n",
1413 __FUNCTION__, status);
1414 cypress_set_dead(port);
1418 priv->write_urb_in_use = 0;
1420 /* send any buffered data */
1425 /*****************************************************************************
1426 * Write buffer functions - buffering code from pl2303 used
1427 *****************************************************************************/
1432 * Allocate a circular buffer and all associated memory.
1435 static struct cypress_buf *cypress_buf_alloc(unsigned int size)
1438 struct cypress_buf *cb;
1444 cb = kmalloc(sizeof(struct cypress_buf), GFP_KERNEL);
1448 cb->buf_buf = kmalloc(size, GFP_KERNEL);
1449 if (cb->buf_buf == NULL) {
1454 cb->buf_size = size;
1455 cb->buf_get = cb->buf_put = cb->buf_buf;
1465 * Free the buffer and all associated memory.
1468 static void cypress_buf_free(struct cypress_buf *cb)
1480 * Clear out all data in the circular buffer.
1483 static void cypress_buf_clear(struct cypress_buf *cb)
1486 cb->buf_get = cb->buf_put;
1487 /* equivalent to a get of all data available */
1492 * cypress_buf_data_avail
1494 * Return the number of bytes of data available in the circular
1498 static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1501 return ((cb->buf_size + cb->buf_put - cb->buf_get) % cb->buf_size);
1508 * cypress_buf_space_avail
1510 * Return the number of bytes of space available in the circular
1514 static unsigned int cypress_buf_space_avail(struct cypress_buf *cb)
1517 return ((cb->buf_size + cb->buf_get - cb->buf_put - 1) % cb->buf_size);
1526 * Copy data data from a user buffer and put it into the circular buffer.
1527 * Restrict to the amount of space available.
1529 * Return the number of bytes copied.
1532 static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf,
1542 len = cypress_buf_space_avail(cb);
1549 len = cb->buf_buf + cb->buf_size - cb->buf_put;
1551 memcpy(cb->buf_put, buf, len);
1552 memcpy(cb->buf_buf, buf+len, count - len);
1553 cb->buf_put = cb->buf_buf + count - len;
1555 memcpy(cb->buf_put, buf, count);
1557 cb->buf_put += count;
1558 else /* count == len */
1559 cb->buf_put = cb->buf_buf;
1570 * Get data from the circular buffer and copy to the given buffer.
1571 * Restrict to the amount of data available.
1573 * Return the number of bytes copied.
1576 static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf,
1586 len = cypress_buf_data_avail(cb);
1593 len = cb->buf_buf + cb->buf_size - cb->buf_get;
1595 memcpy(buf, cb->buf_get, len);
1596 memcpy(buf+len, cb->buf_buf, count - len);
1597 cb->buf_get = cb->buf_buf + count - len;
1599 memcpy(buf, cb->buf_get, count);
1601 cb->buf_get += count;
1602 else /* count == len */
1603 cb->buf_get = cb->buf_buf;
1610 /*****************************************************************************
1612 *****************************************************************************/
1614 static int __init cypress_init(void)
1618 dbg("%s", __FUNCTION__);
1620 retval = usb_serial_register(&cypress_earthmate_device);
1622 goto failed_em_register;
1623 retval = usb_serial_register(&cypress_hidcom_device);
1625 goto failed_hidcom_register;
1626 retval = usb_serial_register(&cypress_ca42v2_device);
1628 goto failed_ca42v2_register;
1629 retval = usb_register(&cypress_driver);
1631 goto failed_usb_register;
1633 info(DRIVER_DESC " " DRIVER_VERSION);
1636 failed_usb_register:
1637 usb_serial_deregister(&cypress_ca42v2_device);
1638 failed_ca42v2_register:
1639 usb_serial_deregister(&cypress_hidcom_device);
1640 failed_hidcom_register:
1641 usb_serial_deregister(&cypress_earthmate_device);
1647 static void __exit cypress_exit (void)
1649 dbg("%s", __FUNCTION__);
1651 usb_deregister (&cypress_driver);
1652 usb_serial_deregister (&cypress_earthmate_device);
1653 usb_serial_deregister (&cypress_hidcom_device);
1654 usb_serial_deregister (&cypress_ca42v2_device);
1658 module_init(cypress_init);
1659 module_exit(cypress_exit);
1661 MODULE_AUTHOR( DRIVER_AUTHOR );
1662 MODULE_DESCRIPTION( DRIVER_DESC );
1663 MODULE_VERSION( DRIVER_VERSION );
1664 MODULE_LICENSE("GPL");
1666 module_param(debug, bool, S_IRUGO | S_IWUSR);
1667 MODULE_PARM_DESC(debug, "Debug enabled or not");
1668 module_param(stats, bool, S_IRUGO | S_IWUSR);
1669 MODULE_PARM_DESC(stats, "Enable statistics or not");
1670 module_param(interval, int, S_IRUGO | S_IWUSR);
1671 MODULE_PARM_DESC(interval, "Overrides interrupt interval");