diff options
Diffstat (limited to 'drivers/usb/serial/cypress_m8.c')
-rw-r--r-- | drivers/usb/serial/cypress_m8.c | 703 |
1 files changed, 371 insertions, 332 deletions
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 0230d3c0888a..22837a3f2f89 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * USB Cypress M8 driver | 2 | * USB Cypress M8 driver |
3 | * | 3 | * |
4 | * Copyright (C) 2004 | 4 | * Copyright (C) 2004 |
5 | * Lonnie Mendez (dignome@gmail.com) | 5 | * Lonnie Mendez (dignome@gmail.com) |
6 | * Copyright (C) 2003,2004 | 6 | * Copyright (C) 2003,2004 |
7 | * Neil Whelchel (koyama@firstlight.net) | 7 | * Neil Whelchel (koyama@firstlight.net) |
8 | * | 8 | * |
@@ -11,19 +11,21 @@ | |||
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | 13 | * |
14 | * See Documentation/usb/usb-serial.txt for more information on using this driver | 14 | * See Documentation/usb/usb-serial.txt for more information on using this |
15 | * driver | ||
15 | * | 16 | * |
16 | * See http://geocities.com/i0xox0i for information on this driver and the | 17 | * See http://geocities.com/i0xox0i for information on this driver and the |
17 | * earthmate usb device. | 18 | * earthmate usb device. |
18 | * | 19 | * |
19 | * Lonnie Mendez <dignome@gmail.com> | 20 | * Lonnie Mendez <dignome@gmail.com> |
20 | * 4-29-2005 | 21 | * 4-29-2005 |
21 | * Fixed problem where setting or retreiving the serial config would fail with | 22 | * Fixed problem where setting or retreiving the serial config would fail |
22 | * EPIPE. Removed CRTS toggling so the driver behaves more like other usbserial | 23 | * with EPIPE. Removed CRTS toggling so the driver behaves more like |
23 | * adapters. Issued new interval of 1ms instead of the default 10ms. As a | 24 | * other usbserial adapters. Issued new interval of 1ms instead of the |
24 | * result, transfer speed has been substantially increased. From avg. 850bps to | 25 | * default 10ms. As a result, transfer speed has been substantially |
25 | * avg. 3300bps. initial termios has also been modified. Cleaned up code and | 26 | * increased from avg. 850bps to avg. 3300bps. initial termios has also |
26 | * formatting issues so it is more readable. Replaced the C++ style comments. | 27 | * been modified. Cleaned up code and formatting issues so it is more |
28 | * readable. Replaced the C++ style comments. | ||
27 | * | 29 | * |
28 | * Lonnie Mendez <dignome@gmail.com> | 30 | * Lonnie Mendez <dignome@gmail.com> |
29 | * 12-15-2004 | 31 | * 12-15-2004 |
@@ -42,10 +44,11 @@ | |||
42 | * | 44 | * |
43 | */ | 45 | */ |
44 | 46 | ||
45 | /* Thanks to Neil Whelchel for writing the first cypress m8 implementation for linux. */ | 47 | /* Thanks to Neil Whelchel for writing the first cypress m8 implementation |
48 | for linux. */ | ||
46 | /* Thanks to cypress for providing references for the hid reports. */ | 49 | /* Thanks to cypress for providing references for the hid reports. */ |
47 | /* Thanks to Jiang Zhang for providing links and for general help. */ | 50 | /* 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 | /* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/ |
49 | 52 | ||
50 | 53 | ||
51 | #include <linux/kernel.h> | 54 | #include <linux/kernel.h> |
@@ -62,7 +65,7 @@ | |||
62 | #include <linux/usb/serial.h> | 65 | #include <linux/usb/serial.h> |
63 | #include <linux/serial.h> | 66 | #include <linux/serial.h> |
64 | #include <linux/delay.h> | 67 | #include <linux/delay.h> |
65 | #include <asm/uaccess.h> | 68 | #include <linux/uaccess.h> |
66 | 69 | ||
67 | #include "cypress_m8.h" | 70 | #include "cypress_m8.h" |
68 | 71 | ||
@@ -112,7 +115,7 @@ static struct usb_device_id id_table_combined [] = { | |||
112 | { } /* Terminating entry */ | 115 | { } /* Terminating entry */ |
113 | }; | 116 | }; |
114 | 117 | ||
115 | MODULE_DEVICE_TABLE (usb, id_table_combined); | 118 | MODULE_DEVICE_TABLE(usb, id_table_combined); |
116 | 119 | ||
117 | static struct usb_driver cypress_driver = { | 120 | static struct usb_driver cypress_driver = { |
118 | .name = "cypress", | 121 | .name = "cypress", |
@@ -146,11 +149,13 @@ struct cypress_private { | |||
146 | __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */ | 149 | __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */ |
147 | enum packet_format pkt_fmt; /* format to use for packet send / receive */ | 150 | 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 */ | 151 | int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */ |
149 | int baud_rate; /* stores current baud rate in integer form */ | 152 | int baud_rate; /* stores current baud rate in |
153 | integer form */ | ||
150 | int isthrottled; /* if throttled, discard reads */ | 154 | int isthrottled; /* if throttled, discard reads */ |
151 | wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ | 155 | wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ |
152 | char prev_status, diff_status; /* used for TIOCMIWAIT */ | 156 | 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 */ | 157 | /* we pass a pointer to this as the arguement sent to |
158 | cypress_set_termios old_termios */ | ||
154 | struct ktermios tmp_termios; /* stores the old termios settings */ | 159 | struct ktermios tmp_termios; /* stores the old termios settings */ |
155 | }; | 160 | }; |
156 | 161 | ||
@@ -163,33 +168,41 @@ struct cypress_buf { | |||
163 | }; | 168 | }; |
164 | 169 | ||
165 | /* function prototypes for the Cypress USB to serial device */ | 170 | /* function prototypes for the Cypress USB to serial device */ |
166 | static int cypress_earthmate_startup (struct usb_serial *serial); | 171 | static int cypress_earthmate_startup(struct usb_serial *serial); |
167 | static int cypress_hidcom_startup (struct usb_serial *serial); | 172 | static int cypress_hidcom_startup(struct usb_serial *serial); |
168 | static int cypress_ca42v2_startup (struct usb_serial *serial); | 173 | static int cypress_ca42v2_startup(struct usb_serial *serial); |
169 | static void cypress_shutdown (struct usb_serial *serial); | 174 | static void cypress_shutdown(struct usb_serial *serial); |
170 | static int cypress_open (struct usb_serial_port *port, struct file *filp); | 175 | static int cypress_open(struct tty_struct *tty, |
171 | static void cypress_close (struct usb_serial_port *port, struct file *filp); | 176 | struct usb_serial_port *port, struct file *filp); |
172 | static int cypress_write (struct usb_serial_port *port, const unsigned char *buf, int count); | 177 | static void cypress_close(struct tty_struct *tty, |
173 | static void cypress_send (struct usb_serial_port *port); | 178 | struct usb_serial_port *port, struct file *filp); |
174 | static int cypress_write_room (struct usb_serial_port *port); | 179 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, |
175 | static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); | 180 | const unsigned char *buf, int count); |
176 | static void cypress_set_termios (struct usb_serial_port *port, struct ktermios * old); | 181 | static void cypress_send(struct usb_serial_port *port); |
177 | static int cypress_tiocmget (struct usb_serial_port *port, struct file *file); | 182 | static int cypress_write_room(struct tty_struct *tty); |
178 | static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); | 183 | static int cypress_ioctl(struct tty_struct *tty, struct file *file, |
179 | static int cypress_chars_in_buffer (struct usb_serial_port *port); | 184 | unsigned int cmd, unsigned long arg); |
180 | static void cypress_throttle (struct usb_serial_port *port); | 185 | static void cypress_set_termios(struct tty_struct *tty, |
181 | static void cypress_unthrottle (struct usb_serial_port *port); | 186 | struct usb_serial_port *port, struct ktermios *old); |
182 | static void cypress_set_dead (struct usb_serial_port *port); | 187 | static int cypress_tiocmget(struct tty_struct *tty, struct file *file); |
183 | static void cypress_read_int_callback (struct urb *urb); | 188 | static int cypress_tiocmset(struct tty_struct *tty, struct file *file, |
184 | static void cypress_write_int_callback (struct urb *urb); | 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); | ||
185 | /* write buffer functions */ | 196 | /* write buffer functions */ |
186 | static struct cypress_buf *cypress_buf_alloc(unsigned int size); | 197 | static struct cypress_buf *cypress_buf_alloc(unsigned int size); |
187 | static void cypress_buf_free(struct cypress_buf *cb); | 198 | static void cypress_buf_free(struct cypress_buf *cb); |
188 | static void cypress_buf_clear(struct cypress_buf *cb); | 199 | static void cypress_buf_clear(struct cypress_buf *cb); |
189 | static unsigned int cypress_buf_data_avail(struct cypress_buf *cb); | 200 | static unsigned int cypress_buf_data_avail(struct cypress_buf *cb); |
190 | static unsigned int cypress_buf_space_avail(struct cypress_buf *cb); | 201 | 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); | 202 | static unsigned int cypress_buf_put(struct cypress_buf *cb, |
192 | static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count); | 203 | const char *buf, unsigned int count); |
204 | static unsigned int cypress_buf_get(struct cypress_buf *cb, | ||
205 | char *buf, unsigned int count); | ||
193 | 206 | ||
194 | 207 | ||
195 | static struct usb_serial_driver cypress_earthmate_device = { | 208 | static struct usb_serial_driver cypress_earthmate_device = { |
@@ -247,7 +260,7 @@ static struct usb_serial_driver cypress_hidcom_device = { | |||
247 | static struct usb_serial_driver cypress_ca42v2_device = { | 260 | static struct usb_serial_driver cypress_ca42v2_device = { |
248 | .driver = { | 261 | .driver = { |
249 | .owner = THIS_MODULE, | 262 | .owner = THIS_MODULE, |
250 | .name = "nokiaca42v2", | 263 | .name = "nokiaca42v2", |
251 | }, | 264 | }, |
252 | .description = "Nokia CA-42 V2 Adapter", | 265 | .description = "Nokia CA-42 V2 Adapter", |
253 | .usb_driver = &cypress_driver, | 266 | .usb_driver = &cypress_driver, |
@@ -322,8 +335,10 @@ static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate) | |||
322 | 335 | ||
323 | 336 | ||
324 | /* This function can either set or retrieve the current serial line settings */ | 337 | /* This function can either set or retrieve the current serial line settings */ |
325 | static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_rate, int data_bits, int stop_bits, | 338 | static int cypress_serial_control(struct tty_struct *tty, |
326 | int parity_enable, int parity_type, int reset, int cypress_request_type) | 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) | ||
327 | { | 342 | { |
328 | int new_baudrate = 0, retval = 0, tries = 0; | 343 | int new_baudrate = 0, retval = 0, tries = 0; |
329 | struct cypress_private *priv; | 344 | struct cypress_private *priv; |
@@ -331,111 +346,114 @@ static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_ra | |||
331 | unsigned long flags; | 346 | unsigned long flags; |
332 | 347 | ||
333 | dbg("%s", __func__); | 348 | dbg("%s", __func__); |
334 | 349 | ||
335 | priv = usb_get_serial_port_data(port); | 350 | priv = usb_get_serial_port_data(port); |
336 | 351 | ||
337 | if (!priv->comm_is_ok) | 352 | if (!priv->comm_is_ok) |
338 | return -ENODEV; | 353 | return -ENODEV; |
339 | 354 | ||
340 | switch(cypress_request_type) { | 355 | switch (cypress_request_type) { |
341 | case CYPRESS_SET_CONFIG: | 356 | case CYPRESS_SET_CONFIG: |
357 | new_baudrate = priv->baud_rate; | ||
358 | /* 0 means 'Hang up' so doesn't change the true bit rate */ | ||
359 | if (baud_rate == 0) | ||
342 | new_baudrate = priv->baud_rate; | 360 | new_baudrate = priv->baud_rate; |
343 | /* 0 means 'Hang up' so doesn't change the true bit rate */ | 361 | /* Change of speed ? */ |
344 | if (baud_rate == 0) | 362 | else if (baud_rate != priv->baud_rate) { |
345 | new_baudrate = priv->baud_rate; | 363 | dbg("%s - baud rate is changing", __func__); |
346 | /* Change of speed ? */ | 364 | retval = analyze_baud_rate(port, baud_rate); |
347 | else if (baud_rate != priv->baud_rate) { | 365 | if (retval >= 0) { |
348 | dbg("%s - baud rate is changing", __func__); | 366 | new_baudrate = retval; |
349 | retval = analyze_baud_rate(port, baud_rate); | 367 | dbg("%s - New baud rate set to %d", |
350 | if (retval >= 0) { | 368 | __func__, new_baudrate); |
351 | new_baudrate = retval; | ||
352 | dbg("%s - New baud rate set to %d", | ||
353 | __func__, new_baudrate); | ||
354 | } | ||
355 | } | ||
356 | dbg("%s - baud rate is being sent as %d", __func__, new_baudrate); | ||
357 | |||
358 | memset(feature_buffer, 0, sizeof(feature_buffer)); | ||
359 | /* fill the feature_buffer with new configuration */ | ||
360 | *((u_int32_t *)feature_buffer) = new_baudrate; | ||
361 | |||
362 | feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */ | ||
363 | /* 1 bit gap */ | ||
364 | feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */ | ||
365 | feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */ | ||
366 | feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */ | ||
367 | /* 1 bit gap */ | ||
368 | feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */ | ||
369 | |||
370 | dbg("%s - device is being sent this feature report:", __func__); | ||
371 | dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, feature_buffer[0], feature_buffer[1], | ||
372 | feature_buffer[2], feature_buffer[3], feature_buffer[4]); | ||
373 | |||
374 | do { | ||
375 | retval = usb_control_msg(port->serial->dev, | ||
376 | usb_sndctrlpipe(port->serial->dev, 0), | ||
377 | HID_REQ_SET_REPORT, | ||
378 | USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, | ||
379 | 0x0300, 0, feature_buffer, | ||
380 | sizeof(feature_buffer), 500); | ||
381 | |||
382 | if (tries++ >= 3) | ||
383 | break; | ||
384 | |||
385 | } while (retval != sizeof(feature_buffer) && | ||
386 | retval != -ENODEV); | ||
387 | |||
388 | if (retval != sizeof(feature_buffer)) { | ||
389 | err("%s - failed sending serial line settings - %d", __func__, retval); | ||
390 | cypress_set_dead(port); | ||
391 | } else { | ||
392 | spin_lock_irqsave(&priv->lock, flags); | ||
393 | priv->baud_rate = new_baudrate; | ||
394 | priv->current_config = feature_buffer[4]; | ||
395 | spin_unlock_irqrestore(&priv->lock, flags); | ||
396 | /* If we asked for a speed change encode it */ | ||
397 | if (baud_rate) | ||
398 | tty_encode_baud_rate(port->tty, | ||
399 | new_baudrate, new_baudrate); | ||
400 | } | ||
401 | break; | ||
402 | case CYPRESS_GET_CONFIG: | ||
403 | if (priv->get_cfg_unsafe) { | ||
404 | /* Not implemented for this device, | ||
405 | and if we try to do it we're likely | ||
406 | to crash the hardware. */ | ||
407 | return -ENOTTY; | ||
408 | } | ||
409 | dbg("%s - retreiving serial line settings", __func__); | ||
410 | /* set initial values in feature buffer */ | ||
411 | memset(feature_buffer, 0, sizeof(feature_buffer)); | ||
412 | |||
413 | do { | ||
414 | retval = usb_control_msg(port->serial->dev, | ||
415 | usb_rcvctrlpipe(port->serial->dev, 0), | ||
416 | HID_REQ_GET_REPORT, | ||
417 | USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS, | ||
418 | 0x0300, 0, feature_buffer, | ||
419 | sizeof(feature_buffer), 500); | ||
420 | |||
421 | if (tries++ >= 3) | ||
422 | break; | ||
423 | |||
424 | } while (retval != sizeof(feature_buffer) && | ||
425 | retval != -ENODEV); | ||
426 | |||
427 | if (retval != sizeof(feature_buffer)) { | ||
428 | err("%s - failed to retrieve serial line settings - %d", __func__, retval); | ||
429 | cypress_set_dead(port); | ||
430 | return retval; | ||
431 | } else { | ||
432 | spin_lock_irqsave(&priv->lock, flags); | ||
433 | |||
434 | /* store the config in one byte, and later use bit masks to check values */ | ||
435 | priv->current_config = feature_buffer[4]; | ||
436 | priv->baud_rate = *((u_int32_t *)feature_buffer); | ||
437 | spin_unlock_irqrestore(&priv->lock, flags); | ||
438 | } | 369 | } |
370 | } | ||
371 | dbg("%s - baud rate is being sent as %d", | ||
372 | __func__, new_baudrate); | ||
373 | |||
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 ) */ | ||
378 | /* 1 bit gap */ | ||
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 */ | ||
382 | /* 1 bit gap */ | ||
383 | feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */ | ||
384 | |||
385 | dbg("%s - device is being sent this feature report:", | ||
386 | __func__); | ||
387 | dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, | ||
388 | feature_buffer[0], feature_buffer[1], | ||
389 | feature_buffer[2], feature_buffer[3], | ||
390 | feature_buffer[4]); | ||
391 | |||
392 | do { | ||
393 | retval = usb_control_msg(port->serial->dev, | ||
394 | usb_sndctrlpipe(port->serial->dev, 0), | ||
395 | HID_REQ_SET_REPORT, | ||
396 | USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, | ||
397 | 0x0300, 0, feature_buffer, | ||
398 | sizeof(feature_buffer), 500); | ||
399 | |||
400 | if (tries++ >= 3) | ||
401 | break; | ||
402 | |||
403 | } while (retval != sizeof(feature_buffer) && | ||
404 | retval != -ENODEV); | ||
405 | |||
406 | if (retval != sizeof(feature_buffer)) { | ||
407 | err("%s - failed sending serial line settings - %d", | ||
408 | __func__, retval); | ||
409 | cypress_set_dead(port); | ||
410 | } else { | ||
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 */ | ||
416 | if (baud_rate) | ||
417 | tty_encode_baud_rate(tty, | ||
418 | new_baudrate, new_baudrate); | ||
419 | } | ||
420 | break; | ||
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. */ | ||
426 | return -ENOTTY; | ||
427 | } | ||
428 | dbg("%s - retreiving serial line settings", __func__); | ||
429 | /* set initial values in feature buffer */ | ||
430 | memset(feature_buffer, 0, sizeof(feature_buffer)); | ||
431 | |||
432 | do { | ||
433 | retval = usb_control_msg(port->serial->dev, | ||
434 | usb_rcvctrlpipe(port->serial->dev, 0), | ||
435 | HID_REQ_GET_REPORT, | ||
436 | USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS, | ||
437 | 0x0300, 0, feature_buffer, | ||
438 | sizeof(feature_buffer), 500); | ||
439 | |||
440 | if (tries++ >= 3) | ||
441 | break; | ||
442 | } while (retval != sizeof(feature_buffer) | ||
443 | && retval != -ENODEV); | ||
444 | |||
445 | if (retval != sizeof(feature_buffer)) { | ||
446 | err("%s - failed to retrieve serial line settings - %d", __func__, retval); | ||
447 | cypress_set_dead(port); | ||
448 | return retval; | ||
449 | } else { | ||
450 | spin_lock_irqsave(&priv->lock, flags); | ||
451 | /* store the config in one byte, and later | ||
452 | use bit masks to check values */ | ||
453 | priv->current_config = feature_buffer[4]; | ||
454 | priv->baud_rate = *((u_int32_t *)feature_buffer); | ||
455 | spin_unlock_irqrestore(&priv->lock, flags); | ||
456 | } | ||
439 | } | 457 | } |
440 | spin_lock_irqsave(&priv->lock, flags); | 458 | spin_lock_irqsave(&priv->lock, flags); |
441 | ++priv->cmd_count; | 459 | ++priv->cmd_count; |
@@ -468,14 +486,14 @@ static void cypress_set_dead(struct usb_serial_port *port) | |||
468 | *****************************************************************************/ | 486 | *****************************************************************************/ |
469 | 487 | ||
470 | 488 | ||
471 | static int generic_startup (struct usb_serial *serial) | 489 | static int generic_startup(struct usb_serial *serial) |
472 | { | 490 | { |
473 | struct cypress_private *priv; | 491 | struct cypress_private *priv; |
474 | struct usb_serial_port *port = serial->port[0]; | 492 | struct usb_serial_port *port = serial->port[0]; |
475 | 493 | ||
476 | dbg("%s - port %d", __func__, port->number); | 494 | dbg("%s - port %d", __func__, port->number); |
477 | 495 | ||
478 | priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL); | 496 | priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL); |
479 | if (!priv) | 497 | if (!priv) |
480 | return -ENOMEM; | 498 | return -ENOMEM; |
481 | 499 | ||
@@ -487,9 +505,9 @@ static int generic_startup (struct usb_serial *serial) | |||
487 | return -ENOMEM; | 505 | return -ENOMEM; |
488 | } | 506 | } |
489 | init_waitqueue_head(&priv->delta_msr_wait); | 507 | init_waitqueue_head(&priv->delta_msr_wait); |
490 | 508 | ||
491 | usb_reset_configuration (serial->dev); | 509 | usb_reset_configuration(serial->dev); |
492 | 510 | ||
493 | priv->cmd_ctrl = 0; | 511 | priv->cmd_ctrl = 0; |
494 | priv->line_control = 0; | 512 | priv->line_control = 0; |
495 | priv->termios_initialized = 0; | 513 | priv->termios_initialized = 0; |
@@ -500,30 +518,30 @@ static int generic_startup (struct usb_serial *serial) | |||
500 | small. Otherwise we can use the slightly more compact | 518 | small. Otherwise we can use the slightly more compact |
501 | format. This is in accordance with the cypress_m8 serial | 519 | format. This is in accordance with the cypress_m8 serial |
502 | converter app note. */ | 520 | converter app note. */ |
503 | if (port->interrupt_out_size > 9) { | 521 | if (port->interrupt_out_size > 9) |
504 | priv->pkt_fmt = packet_format_1; | 522 | priv->pkt_fmt = packet_format_1; |
505 | } else { | 523 | else |
506 | priv->pkt_fmt = packet_format_2; | 524 | priv->pkt_fmt = packet_format_2; |
507 | } | 525 | |
508 | if (interval > 0) { | 526 | if (interval > 0) { |
509 | priv->write_urb_interval = interval; | 527 | priv->write_urb_interval = interval; |
510 | priv->read_urb_interval = interval; | 528 | priv->read_urb_interval = interval; |
511 | dbg("%s - port %d read & write intervals forced to %d", | 529 | dbg("%s - port %d read & write intervals forced to %d", |
512 | __func__,port->number,interval); | 530 | __func__, port->number, interval); |
513 | } else { | 531 | } else { |
514 | priv->write_urb_interval = port->interrupt_out_urb->interval; | 532 | priv->write_urb_interval = port->interrupt_out_urb->interval; |
515 | priv->read_urb_interval = port->interrupt_in_urb->interval; | 533 | priv->read_urb_interval = port->interrupt_in_urb->interval; |
516 | dbg("%s - port %d intervals: read=%d write=%d", | 534 | dbg("%s - port %d intervals: read=%d write=%d", |
517 | __func__,port->number, | 535 | __func__, port->number, |
518 | priv->read_urb_interval,priv->write_urb_interval); | 536 | priv->read_urb_interval, priv->write_urb_interval); |
519 | } | 537 | } |
520 | usb_set_serial_port_data(port, priv); | 538 | usb_set_serial_port_data(port, priv); |
521 | 539 | ||
522 | return 0; | 540 | return 0; |
523 | } | 541 | } |
524 | 542 | ||
525 | 543 | ||
526 | static int cypress_earthmate_startup (struct usb_serial *serial) | 544 | static int cypress_earthmate_startup(struct usb_serial *serial) |
527 | { | 545 | { |
528 | struct cypress_private *priv; | 546 | struct cypress_private *priv; |
529 | struct usb_serial_port *port = serial->port[0]; | 547 | struct usb_serial_port *port = serial->port[0]; |
@@ -541,7 +559,8 @@ static int cypress_earthmate_startup (struct usb_serial *serial) | |||
541 | /* All Earthmate devices use the separated-count packet | 559 | /* All Earthmate devices use the separated-count packet |
542 | format! Idiotic. */ | 560 | format! Idiotic. */ |
543 | priv->pkt_fmt = packet_format_1; | 561 | priv->pkt_fmt = packet_format_1; |
544 | if (serial->dev->descriptor.idProduct != cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) { | 562 | if (serial->dev->descriptor.idProduct != |
563 | cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) { | ||
545 | /* The old original USB Earthmate seemed able to | 564 | /* The old original USB Earthmate seemed able to |
546 | handle GET_CONFIG requests; everything they've | 565 | handle GET_CONFIG requests; everything they've |
547 | produced since that time crashes if this command is | 566 | produced since that time crashes if this command is |
@@ -555,7 +574,7 @@ static int cypress_earthmate_startup (struct usb_serial *serial) | |||
555 | } /* cypress_earthmate_startup */ | 574 | } /* cypress_earthmate_startup */ |
556 | 575 | ||
557 | 576 | ||
558 | static int cypress_hidcom_startup (struct usb_serial *serial) | 577 | static int cypress_hidcom_startup(struct usb_serial *serial) |
559 | { | 578 | { |
560 | struct cypress_private *priv; | 579 | struct cypress_private *priv; |
561 | 580 | ||
@@ -569,12 +588,12 @@ static int cypress_hidcom_startup (struct usb_serial *serial) | |||
569 | 588 | ||
570 | priv = usb_get_serial_port_data(serial->port[0]); | 589 | priv = usb_get_serial_port_data(serial->port[0]); |
571 | priv->chiptype = CT_CYPHIDCOM; | 590 | priv->chiptype = CT_CYPHIDCOM; |
572 | 591 | ||
573 | return 0; | 592 | return 0; |
574 | } /* cypress_hidcom_startup */ | 593 | } /* cypress_hidcom_startup */ |
575 | 594 | ||
576 | 595 | ||
577 | static int cypress_ca42v2_startup (struct usb_serial *serial) | 596 | static int cypress_ca42v2_startup(struct usb_serial *serial) |
578 | { | 597 | { |
579 | struct cypress_private *priv; | 598 | struct cypress_private *priv; |
580 | 599 | ||
@@ -593,11 +612,11 @@ static int cypress_ca42v2_startup (struct usb_serial *serial) | |||
593 | } /* cypress_ca42v2_startup */ | 612 | } /* cypress_ca42v2_startup */ |
594 | 613 | ||
595 | 614 | ||
596 | static void cypress_shutdown (struct usb_serial *serial) | 615 | static void cypress_shutdown(struct usb_serial *serial) |
597 | { | 616 | { |
598 | struct cypress_private *priv; | 617 | struct cypress_private *priv; |
599 | 618 | ||
600 | dbg ("%s - port %d", __func__, serial->port[0]->number); | 619 | dbg("%s - port %d", __func__, serial->port[0]->number); |
601 | 620 | ||
602 | /* all open ports are closed at this point */ | 621 | /* all open ports are closed at this point */ |
603 | 622 | ||
@@ -611,7 +630,8 @@ static void cypress_shutdown (struct usb_serial *serial) | |||
611 | } | 630 | } |
612 | 631 | ||
613 | 632 | ||
614 | static int cypress_open (struct usb_serial_port *port, struct file *filp) | 633 | static int cypress_open(struct tty_struct *tty, |
634 | struct usb_serial_port *port, struct file *filp) | ||
615 | { | 635 | { |
616 | struct cypress_private *priv = usb_get_serial_port_data(port); | 636 | struct cypress_private *priv = usb_get_serial_port_data(port); |
617 | struct usb_serial *serial = port->serial; | 637 | struct usb_serial *serial = port->serial; |
@@ -636,37 +656,44 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp) | |||
636 | spin_unlock_irqrestore(&priv->lock, flags); | 656 | spin_unlock_irqrestore(&priv->lock, flags); |
637 | 657 | ||
638 | /* setting to zero could cause data loss */ | 658 | /* setting to zero could cause data loss */ |
639 | port->tty->low_latency = 1; | 659 | if (tty) |
660 | tty->low_latency = 1; | ||
640 | 661 | ||
641 | /* raise both lines and set termios */ | 662 | /* raise both lines and set termios */ |
642 | spin_lock_irqsave(&priv->lock, flags); | 663 | spin_lock_irqsave(&priv->lock, flags); |
643 | priv->line_control = CONTROL_DTR | CONTROL_RTS; | 664 | priv->line_control = CONTROL_DTR | CONTROL_RTS; |
644 | priv->cmd_ctrl = 1; | 665 | priv->cmd_ctrl = 1; |
645 | spin_unlock_irqrestore(&priv->lock, flags); | 666 | spin_unlock_irqrestore(&priv->lock, flags); |
646 | result = cypress_write(port, NULL, 0); | 667 | result = cypress_write(tty, port, NULL, 0); |
647 | 668 | ||
648 | if (result) { | 669 | if (result) { |
649 | dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __func__, result); | 670 | dev_err(&port->dev, |
671 | "%s - failed setting the control lines - error %d\n", | ||
672 | __func__, result); | ||
650 | return result; | 673 | return result; |
651 | } else | 674 | } else |
652 | dbg("%s - success setting the control lines", __func__); | 675 | dbg("%s - success setting the control lines", __func__); |
653 | 676 | ||
654 | cypress_set_termios(port, &priv->tmp_termios); | 677 | if (tty) |
678 | cypress_set_termios(tty, port, &priv->tmp_termios); | ||
655 | 679 | ||
656 | /* setup the port and start reading from the device */ | 680 | /* setup the port and start reading from the device */ |
657 | if(!port->interrupt_in_urb){ | 681 | if (!port->interrupt_in_urb) { |
658 | err("%s - interrupt_in_urb is empty!", __func__); | 682 | err("%s - interrupt_in_urb is empty!", __func__); |
659 | return(-1); | 683 | return -1; |
660 | } | 684 | } |
661 | 685 | ||
662 | usb_fill_int_urb(port->interrupt_in_urb, serial->dev, | 686 | usb_fill_int_urb(port->interrupt_in_urb, serial->dev, |
663 | usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), | 687 | usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), |
664 | port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, | 688 | port->interrupt_in_urb->transfer_buffer, |
689 | port->interrupt_in_urb->transfer_buffer_length, | ||
665 | cypress_read_int_callback, port, priv->read_urb_interval); | 690 | cypress_read_int_callback, port, priv->read_urb_interval); |
666 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 691 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
667 | 692 | ||
668 | if (result){ | 693 | if (result) { |
669 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); | 694 | dev_err(&port->dev, |
695 | "%s - failed submitting read urb, error %d\n", | ||
696 | __func__, result); | ||
670 | cypress_set_dead(port); | 697 | cypress_set_dead(port); |
671 | } | 698 | } |
672 | 699 | ||
@@ -674,7 +701,8 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp) | |||
674 | } /* cypress_open */ | 701 | } /* cypress_open */ |
675 | 702 | ||
676 | 703 | ||
677 | static void cypress_close(struct usb_serial_port *port, struct file * filp) | 704 | static void cypress_close(struct tty_struct *tty, |
705 | struct usb_serial_port *port, struct file *filp) | ||
678 | { | 706 | { |
679 | struct cypress_private *priv = usb_get_serial_port_data(port); | 707 | struct cypress_private *priv = usb_get_serial_port_data(port); |
680 | unsigned int c_cflag; | 708 | unsigned int c_cflag; |
@@ -688,7 +716,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) | |||
688 | spin_lock_irq(&priv->lock); | 716 | spin_lock_irq(&priv->lock); |
689 | timeout = CYPRESS_CLOSING_WAIT; | 717 | timeout = CYPRESS_CLOSING_WAIT; |
690 | init_waitqueue_entry(&wait, current); | 718 | init_waitqueue_entry(&wait, current); |
691 | add_wait_queue(&port->tty->write_wait, &wait); | 719 | add_wait_queue(&tty->write_wait, &wait); |
692 | for (;;) { | 720 | for (;;) { |
693 | set_current_state(TASK_INTERRUPTIBLE); | 721 | set_current_state(TASK_INTERRUPTIBLE); |
694 | if (cypress_buf_data_avail(priv->buf) == 0 | 722 | if (cypress_buf_data_avail(priv->buf) == 0 |
@@ -701,7 +729,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) | |||
701 | spin_lock_irq(&priv->lock); | 729 | spin_lock_irq(&priv->lock); |
702 | } | 730 | } |
703 | set_current_state(TASK_RUNNING); | 731 | set_current_state(TASK_RUNNING); |
704 | remove_wait_queue(&port->tty->write_wait, &wait); | 732 | remove_wait_queue(&tty->write_wait, &wait); |
705 | /* clear out any remaining data in the buffer */ | 733 | /* clear out any remaining data in the buffer */ |
706 | cypress_buf_clear(priv->buf); | 734 | cypress_buf_clear(priv->buf); |
707 | spin_unlock_irq(&priv->lock); | 735 | spin_unlock_irq(&priv->lock); |
@@ -713,19 +741,21 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) | |||
713 | return; | 741 | return; |
714 | } | 742 | } |
715 | /* wait for characters to drain from device */ | 743 | /* wait for characters to drain from device */ |
716 | bps = tty_get_baud_rate(port->tty); | 744 | if (tty) { |
717 | if (bps > 1200) | 745 | bps = tty_get_baud_rate(tty); |
718 | timeout = max((HZ*2560)/bps,HZ/10); | 746 | if (bps > 1200) |
719 | else | 747 | timeout = max((HZ * 2560) / bps, HZ / 10); |
720 | timeout = 2*HZ; | 748 | else |
721 | schedule_timeout_interruptible(timeout); | 749 | timeout = 2 * HZ; |
750 | schedule_timeout_interruptible(timeout); | ||
751 | } | ||
722 | 752 | ||
723 | dbg("%s - stopping urbs", __func__); | 753 | dbg("%s - stopping urbs", __func__); |
724 | usb_kill_urb (port->interrupt_in_urb); | 754 | usb_kill_urb(port->interrupt_in_urb); |
725 | usb_kill_urb (port->interrupt_out_urb); | 755 | usb_kill_urb(port->interrupt_out_urb); |
726 | 756 | ||
727 | if (port->tty) { | 757 | if (tty) { |
728 | c_cflag = port->tty->termios->c_cflag; | 758 | c_cflag = tty->termios->c_cflag; |
729 | if (c_cflag & HUPCL) { | 759 | if (c_cflag & HUPCL) { |
730 | /* drop dtr and rts */ | 760 | /* drop dtr and rts */ |
731 | priv = usb_get_serial_port_data(port); | 761 | priv = usb_get_serial_port_data(port); |
@@ -733,22 +763,23 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) | |||
733 | priv->line_control = 0; | 763 | priv->line_control = 0; |
734 | priv->cmd_ctrl = 1; | 764 | priv->cmd_ctrl = 1; |
735 | spin_unlock_irq(&priv->lock); | 765 | spin_unlock_irq(&priv->lock); |
736 | cypress_write(port, NULL, 0); | 766 | cypress_write(tty, port, NULL, 0); |
737 | } | 767 | } |
738 | } | 768 | } |
739 | 769 | ||
740 | if (stats) | 770 | if (stats) |
741 | dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", | 771 | dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", |
742 | priv->bytes_in, priv->bytes_out, priv->cmd_count); | 772 | priv->bytes_in, priv->bytes_out, priv->cmd_count); |
743 | mutex_unlock(&port->serial->disc_mutex); | 773 | mutex_unlock(&port->serial->disc_mutex); |
744 | } /* cypress_close */ | 774 | } /* cypress_close */ |
745 | 775 | ||
746 | 776 | ||
747 | static int cypress_write(struct usb_serial_port *port, const unsigned char *buf, int count) | 777 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, |
778 | const unsigned char *buf, int count) | ||
748 | { | 779 | { |
749 | struct cypress_private *priv = usb_get_serial_port_data(port); | 780 | struct cypress_private *priv = usb_get_serial_port_data(port); |
750 | unsigned long flags; | 781 | unsigned long flags; |
751 | 782 | ||
752 | dbg("%s - port %d, %d bytes", __func__, port->number, count); | 783 | dbg("%s - port %d, %d bytes", __func__, port->number, count); |
753 | 784 | ||
754 | /* line control commands, which need to be executed immediately, | 785 | /* line control commands, which need to be executed immediately, |
@@ -758,10 +789,10 @@ static int cypress_write(struct usb_serial_port *port, const unsigned char *buf, | |||
758 | count = 0; | 789 | count = 0; |
759 | goto finish; | 790 | goto finish; |
760 | } | 791 | } |
761 | 792 | ||
762 | if (!count) | 793 | if (!count) |
763 | return count; | 794 | return count; |
764 | 795 | ||
765 | spin_lock_irqsave(&priv->lock, flags); | 796 | spin_lock_irqsave(&priv->lock, flags); |
766 | count = cypress_buf_put(priv->buf, buf, count); | 797 | count = cypress_buf_put(priv->buf, buf, count); |
767 | spin_unlock_irqrestore(&priv->lock, flags); | 798 | spin_unlock_irqrestore(&priv->lock, flags); |
@@ -778,13 +809,14 @@ static void cypress_send(struct usb_serial_port *port) | |||
778 | int count = 0, result, offset, actual_size; | 809 | int count = 0, result, offset, actual_size; |
779 | struct cypress_private *priv = usb_get_serial_port_data(port); | 810 | struct cypress_private *priv = usb_get_serial_port_data(port); |
780 | unsigned long flags; | 811 | unsigned long flags; |
781 | 812 | ||
782 | if (!priv->comm_is_ok) | 813 | if (!priv->comm_is_ok) |
783 | return; | 814 | return; |
784 | 815 | ||
785 | dbg("%s - port %d", __func__, port->number); | 816 | dbg("%s - port %d", __func__, port->number); |
786 | dbg("%s - interrupt out size is %d", __func__, port->interrupt_out_size); | 817 | dbg("%s - interrupt out size is %d", __func__, |
787 | 818 | port->interrupt_out_size); | |
819 | |||
788 | spin_lock_irqsave(&priv->lock, flags); | 820 | spin_lock_irqsave(&priv->lock, flags); |
789 | if (priv->write_urb_in_use) { | 821 | if (priv->write_urb_in_use) { |
790 | dbg("%s - can't write, urb in use", __func__); | 822 | dbg("%s - can't write, urb in use", __func__); |
@@ -794,7 +826,8 @@ static void cypress_send(struct usb_serial_port *port) | |||
794 | spin_unlock_irqrestore(&priv->lock, flags); | 826 | spin_unlock_irqrestore(&priv->lock, flags); |
795 | 827 | ||
796 | /* clear buffer */ | 828 | /* clear buffer */ |
797 | memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size); | 829 | memset(port->interrupt_out_urb->transfer_buffer, 0, |
830 | port->interrupt_out_size); | ||
798 | 831 | ||
799 | spin_lock_irqsave(&priv->lock, flags); | 832 | spin_lock_irqsave(&priv->lock, flags); |
800 | switch (priv->pkt_fmt) { | 833 | switch (priv->pkt_fmt) { |
@@ -825,9 +858,8 @@ static void cypress_send(struct usb_serial_port *port) | |||
825 | count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset], | 858 | count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset], |
826 | port->interrupt_out_size-offset); | 859 | port->interrupt_out_size-offset); |
827 | 860 | ||
828 | if (count == 0) { | 861 | if (count == 0) |
829 | return; | 862 | return; |
830 | } | ||
831 | 863 | ||
832 | switch (priv->pkt_fmt) { | 864 | switch (priv->pkt_fmt) { |
833 | default: | 865 | default: |
@@ -851,26 +883,29 @@ send: | |||
851 | actual_size = count + | 883 | actual_size = count + |
852 | (priv->pkt_fmt == packet_format_1 ? 2 : 1); | 884 | (priv->pkt_fmt == packet_format_1 ? 2 : 1); |
853 | 885 | ||
854 | usb_serial_debug_data(debug, &port->dev, __func__, port->interrupt_out_size, | 886 | usb_serial_debug_data(debug, &port->dev, __func__, |
855 | port->interrupt_out_urb->transfer_buffer); | 887 | port->interrupt_out_size, |
888 | port->interrupt_out_urb->transfer_buffer); | ||
856 | 889 | ||
857 | usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, | 890 | usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, |
858 | usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), | 891 | usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), |
859 | port->interrupt_out_buffer, port->interrupt_out_size, | 892 | port->interrupt_out_buffer, port->interrupt_out_size, |
860 | cypress_write_int_callback, port, priv->write_urb_interval); | 893 | cypress_write_int_callback, port, priv->write_urb_interval); |
861 | result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC); | 894 | result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); |
862 | if (result) { | 895 | if (result) { |
863 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, | 896 | dev_err(&port->dev, |
864 | result); | 897 | "%s - failed submitting write urb, error %d\n", |
898 | __func__, result); | ||
865 | priv->write_urb_in_use = 0; | 899 | priv->write_urb_in_use = 0; |
866 | cypress_set_dead(port); | 900 | cypress_set_dead(port); |
867 | } | 901 | } |
868 | 902 | ||
869 | spin_lock_irqsave(&priv->lock, flags); | 903 | spin_lock_irqsave(&priv->lock, flags); |
870 | if (priv->cmd_ctrl) { | 904 | if (priv->cmd_ctrl) |
871 | priv->cmd_ctrl = 0; | 905 | priv->cmd_ctrl = 0; |
872 | } | 906 | |
873 | priv->bytes_out += count; /* do not count the line control and size bytes */ | 907 | /* do not count the line control and size bytes */ |
908 | priv->bytes_out += count; | ||
874 | spin_unlock_irqrestore(&priv->lock, flags); | 909 | spin_unlock_irqrestore(&priv->lock, flags); |
875 | 910 | ||
876 | usb_serial_port_softint(port); | 911 | usb_serial_port_softint(port); |
@@ -878,8 +913,9 @@ send: | |||
878 | 913 | ||
879 | 914 | ||
880 | /* returns how much space is available in the soft buffer */ | 915 | /* returns how much space is available in the soft buffer */ |
881 | static int cypress_write_room(struct usb_serial_port *port) | 916 | static int cypress_write_room(struct tty_struct *tty) |
882 | { | 917 | { |
918 | struct usb_serial_port *port = tty->driver_data; | ||
883 | struct cypress_private *priv = usb_get_serial_port_data(port); | 919 | struct cypress_private *priv = usb_get_serial_port_data(port); |
884 | int room = 0; | 920 | int room = 0; |
885 | unsigned long flags; | 921 | unsigned long flags; |
@@ -895,13 +931,14 @@ static int cypress_write_room(struct usb_serial_port *port) | |||
895 | } | 931 | } |
896 | 932 | ||
897 | 933 | ||
898 | static int cypress_tiocmget (struct usb_serial_port *port, struct file *file) | 934 | static int cypress_tiocmget(struct tty_struct *tty, struct file *file) |
899 | { | 935 | { |
936 | struct usb_serial_port *port = tty->driver_data; | ||
900 | struct cypress_private *priv = usb_get_serial_port_data(port); | 937 | struct cypress_private *priv = usb_get_serial_port_data(port); |
901 | __u8 status, control; | 938 | __u8 status, control; |
902 | unsigned int result = 0; | 939 | unsigned int result = 0; |
903 | unsigned long flags; | 940 | unsigned long flags; |
904 | 941 | ||
905 | dbg("%s - port %d", __func__, port->number); | 942 | dbg("%s - port %d", __func__, port->number); |
906 | 943 | ||
907 | spin_lock_irqsave(&priv->lock, flags); | 944 | spin_lock_irqsave(&priv->lock, flags); |
@@ -922,12 +959,13 @@ static int cypress_tiocmget (struct usb_serial_port *port, struct file *file) | |||
922 | } | 959 | } |
923 | 960 | ||
924 | 961 | ||
925 | static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, | 962 | static int cypress_tiocmset(struct tty_struct *tty, struct file *file, |
926 | unsigned int set, unsigned int clear) | 963 | unsigned int set, unsigned int clear) |
927 | { | 964 | { |
965 | struct usb_serial_port *port = tty->driver_data; | ||
928 | struct cypress_private *priv = usb_get_serial_port_data(port); | 966 | struct cypress_private *priv = usb_get_serial_port_data(port); |
929 | unsigned long flags; | 967 | unsigned long flags; |
930 | 968 | ||
931 | dbg("%s - port %d", __func__, port->number); | 969 | dbg("%s - port %d", __func__, port->number); |
932 | 970 | ||
933 | spin_lock_irqsave(&priv->lock, flags); | 971 | spin_lock_irqsave(&priv->lock, flags); |
@@ -942,63 +980,60 @@ static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, | |||
942 | priv->cmd_ctrl = 1; | 980 | priv->cmd_ctrl = 1; |
943 | spin_unlock_irqrestore(&priv->lock, flags); | 981 | spin_unlock_irqrestore(&priv->lock, flags); |
944 | 982 | ||
945 | return cypress_write(port, NULL, 0); | 983 | return cypress_write(tty, port, NULL, 0); |
946 | } | 984 | } |
947 | 985 | ||
948 | 986 | ||
949 | static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) | 987 | static int cypress_ioctl(struct tty_struct *tty, struct file *file, |
988 | unsigned int cmd, unsigned long arg) | ||
950 | { | 989 | { |
990 | struct usb_serial_port *port = tty->driver_data; | ||
951 | struct cypress_private *priv = usb_get_serial_port_data(port); | 991 | struct cypress_private *priv = usb_get_serial_port_data(port); |
952 | 992 | ||
953 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); | 993 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); |
954 | 994 | ||
955 | switch (cmd) { | 995 | switch (cmd) { |
956 | /* This code comes from drivers/char/serial.c and ftdi_sio.c */ | 996 | /* This code comes from drivers/char/serial.c and ftdi_sio.c */ |
957 | case TIOCMIWAIT: | 997 | case TIOCMIWAIT: |
958 | while (priv != NULL) { | 998 | while (priv != NULL) { |
959 | interruptible_sleep_on(&priv->delta_msr_wait); | 999 | interruptible_sleep_on(&priv->delta_msr_wait); |
960 | /* see if a signal did it */ | 1000 | /* see if a signal did it */ |
961 | if (signal_pending(current)) | 1001 | if (signal_pending(current)) |
962 | return -ERESTARTSYS; | 1002 | return -ERESTARTSYS; |
963 | else { | 1003 | else { |
964 | char diff = priv->diff_status; | 1004 | char diff = priv->diff_status; |
965 | 1005 | if (diff == 0) | |
966 | if (diff == 0) { | 1006 | return -EIO; /* no change => error */ |
967 | return -EIO; /* no change => error */ | 1007 | |
968 | } | 1008 | /* consume all events */ |
969 | 1009 | priv->diff_status = 0; | |
970 | /* consume all events */ | 1010 | |
971 | priv->diff_status = 0; | 1011 | /* return 0 if caller wanted to know about |
972 | 1012 | these bits */ | |
973 | /* return 0 if caller wanted to know about these bits */ | 1013 | if (((arg & TIOCM_RNG) && (diff & UART_RI)) || |
974 | if ( ((arg & TIOCM_RNG) && (diff & UART_RI)) || | 1014 | ((arg & TIOCM_DSR) && (diff & UART_DSR)) || |
975 | ((arg & TIOCM_DSR) && (diff & UART_DSR)) || | 1015 | ((arg & TIOCM_CD) && (diff & UART_CD)) || |
976 | ((arg & TIOCM_CD) && (diff & UART_CD)) || | 1016 | ((arg & TIOCM_CTS) && (diff & UART_CTS))) |
977 | ((arg & TIOCM_CTS) && (diff & UART_CTS)) ) { | 1017 | return 0; |
978 | return 0; | 1018 | /* otherwise caller can't care less about what |
979 | } | 1019 | * happened, and so we continue to wait for |
980 | /* otherwise caller can't care less about what happened, | 1020 | * more events. |
981 | * and so we continue to wait for more events. | 1021 | */ |
982 | */ | ||
983 | } | ||
984 | } | 1022 | } |
985 | return 0; | 1023 | } |
986 | break; | 1024 | return 0; |
987 | default: | 1025 | default: |
988 | break; | 1026 | break; |
989 | } | 1027 | } |
990 | |||
991 | dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd); | 1028 | dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd); |
992 | |||
993 | return -ENOIOCTLCMD; | 1029 | return -ENOIOCTLCMD; |
994 | } /* cypress_ioctl */ | 1030 | } /* cypress_ioctl */ |
995 | 1031 | ||
996 | 1032 | ||
997 | static void cypress_set_termios (struct usb_serial_port *port, | 1033 | static void cypress_set_termios(struct tty_struct *tty, |
998 | struct ktermios *old_termios) | 1034 | struct usb_serial_port *port, struct ktermios *old_termios) |
999 | { | 1035 | { |
1000 | struct cypress_private *priv = usb_get_serial_port_data(port); | 1036 | struct cypress_private *priv = usb_get_serial_port_data(port); |
1001 | struct tty_struct *tty; | ||
1002 | int data_bits, stop_bits, parity_type, parity_enable; | 1037 | int data_bits, stop_bits, parity_type, parity_enable; |
1003 | unsigned cflag, iflag; | 1038 | unsigned cflag, iflag; |
1004 | unsigned long flags; | 1039 | unsigned long flags; |
@@ -1007,8 +1042,6 @@ static void cypress_set_termios (struct usb_serial_port *port, | |||
1007 | 1042 | ||
1008 | dbg("%s - port %d", __func__, port->number); | 1043 | dbg("%s - port %d", __func__, port->number); |
1009 | 1044 | ||
1010 | tty = port->tty; | ||
1011 | |||
1012 | spin_lock_irqsave(&priv->lock, flags); | 1045 | spin_lock_irqsave(&priv->lock, flags); |
1013 | if (!priv->termios_initialized) { | 1046 | if (!priv->termios_initialized) { |
1014 | if (priv->chiptype == CT_EARTHMATE) { | 1047 | if (priv->chiptype == CT_EARTHMATE) { |
@@ -1060,28 +1093,24 @@ static void cypress_set_termios (struct usb_serial_port *port, | |||
1060 | } else | 1093 | } else |
1061 | parity_enable = parity_type = 0; | 1094 | parity_enable = parity_type = 0; |
1062 | 1095 | ||
1063 | if (cflag & CSIZE) { | 1096 | switch (cflag & CSIZE) { |
1064 | switch (cflag & CSIZE) { | 1097 | case CS5: |
1065 | case CS5: | 1098 | data_bits = 0; |
1066 | data_bits = 0; | 1099 | break; |
1067 | break; | 1100 | case CS6: |
1068 | case CS6: | 1101 | data_bits = 1; |
1069 | data_bits = 1; | 1102 | break; |
1070 | break; | 1103 | case CS7: |
1071 | case CS7: | 1104 | data_bits = 2; |
1072 | data_bits = 2; | 1105 | break; |
1073 | break; | 1106 | case CS8: |
1074 | case CS8: | ||
1075 | data_bits = 3; | ||
1076 | break; | ||
1077 | default: | ||
1078 | err("%s - CSIZE was set, but not CS5-CS8", | ||
1079 | __func__); | ||
1080 | data_bits = 3; | ||
1081 | } | ||
1082 | } else | ||
1083 | data_bits = 3; | 1107 | data_bits = 3; |
1084 | 1108 | break; | |
1109 | default: | ||
1110 | err("%s - CSIZE was set, but not CS5-CS8", | ||
1111 | __func__); | ||
1112 | data_bits = 3; | ||
1113 | } | ||
1085 | spin_lock_irqsave(&priv->lock, flags); | 1114 | spin_lock_irqsave(&priv->lock, flags); |
1086 | oldlines = priv->line_control; | 1115 | oldlines = priv->line_control; |
1087 | if ((cflag & CBAUD) == B0) { | 1116 | if ((cflag & CBAUD) == B0) { |
@@ -1096,19 +1125,21 @@ static void cypress_set_termios (struct usb_serial_port *port, | |||
1096 | "%d data_bits (+5)", __func__, stop_bits, | 1125 | "%d data_bits (+5)", __func__, stop_bits, |
1097 | parity_enable, parity_type, data_bits); | 1126 | parity_enable, parity_type, data_bits); |
1098 | 1127 | ||
1099 | cypress_serial_control(port, tty_get_baud_rate(tty), data_bits, stop_bits, | 1128 | cypress_serial_control(tty, port, tty_get_baud_rate(tty), |
1100 | parity_enable, parity_type, 0, CYPRESS_SET_CONFIG); | 1129 | data_bits, stop_bits, |
1130 | parity_enable, parity_type, | ||
1131 | 0, CYPRESS_SET_CONFIG); | ||
1101 | 1132 | ||
1102 | /* we perform a CYPRESS_GET_CONFIG so that the current settings are | 1133 | /* we perform a CYPRESS_GET_CONFIG so that the current settings are |
1103 | * filled into the private structure this should confirm that all is | 1134 | * filled into the private structure this should confirm that all is |
1104 | * working if it returns what we just set */ | 1135 | * working if it returns what we just set */ |
1105 | cypress_serial_control(port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG); | 1136 | cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG); |
1106 | 1137 | ||
1107 | /* Here we can define custom tty settings for devices; the main tty | 1138 | /* Here we can define custom tty settings for devices; the main tty |
1108 | * termios flag base comes from empeg.c */ | 1139 | * termios flag base comes from empeg.c */ |
1109 | 1140 | ||
1110 | spin_lock_irqsave(&priv->lock, flags); | 1141 | spin_lock_irqsave(&priv->lock, flags); |
1111 | if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) { | 1142 | if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) { |
1112 | dbg("Using custom termios settings for a baud rate of " | 1143 | dbg("Using custom termios settings for a baud rate of " |
1113 | "4800bps."); | 1144 | "4800bps."); |
1114 | /* define custom termios settings for NMEA protocol */ | 1145 | /* define custom termios settings for NMEA protocol */ |
@@ -1142,20 +1173,21 @@ static void cypress_set_termios (struct usb_serial_port *port, | |||
1142 | /* if necessary, set lines */ | 1173 | /* if necessary, set lines */ |
1143 | if (linechange) { | 1174 | if (linechange) { |
1144 | priv->cmd_ctrl = 1; | 1175 | priv->cmd_ctrl = 1; |
1145 | cypress_write(port, NULL, 0); | 1176 | cypress_write(tty, port, NULL, 0); |
1146 | } | 1177 | } |
1147 | } /* cypress_set_termios */ | 1178 | } /* cypress_set_termios */ |
1148 | 1179 | ||
1149 | 1180 | ||
1150 | /* returns amount of data still left in soft buffer */ | 1181 | /* returns amount of data still left in soft buffer */ |
1151 | static int cypress_chars_in_buffer(struct usb_serial_port *port) | 1182 | static int cypress_chars_in_buffer(struct tty_struct *tty) |
1152 | { | 1183 | { |
1184 | struct usb_serial_port *port = tty->driver_data; | ||
1153 | struct cypress_private *priv = usb_get_serial_port_data(port); | 1185 | struct cypress_private *priv = usb_get_serial_port_data(port); |
1154 | int chars = 0; | 1186 | int chars = 0; |
1155 | unsigned long flags; | 1187 | unsigned long flags; |
1156 | 1188 | ||
1157 | dbg("%s - port %d", __func__, port->number); | 1189 | dbg("%s - port %d", __func__, port->number); |
1158 | 1190 | ||
1159 | spin_lock_irqsave(&priv->lock, flags); | 1191 | spin_lock_irqsave(&priv->lock, flags); |
1160 | chars = cypress_buf_data_avail(priv->buf); | 1192 | chars = cypress_buf_data_avail(priv->buf); |
1161 | spin_unlock_irqrestore(&priv->lock, flags); | 1193 | spin_unlock_irqrestore(&priv->lock, flags); |
@@ -1165,8 +1197,9 @@ static int cypress_chars_in_buffer(struct usb_serial_port *port) | |||
1165 | } | 1197 | } |
1166 | 1198 | ||
1167 | 1199 | ||
1168 | static void cypress_throttle (struct usb_serial_port *port) | 1200 | static void cypress_throttle(struct tty_struct *tty) |
1169 | { | 1201 | { |
1202 | struct usb_serial_port *port = tty->driver_data; | ||
1170 | struct cypress_private *priv = usb_get_serial_port_data(port); | 1203 | struct cypress_private *priv = usb_get_serial_port_data(port); |
1171 | unsigned long flags; | 1204 | unsigned long flags; |
1172 | 1205 | ||
@@ -1178,8 +1211,9 @@ static void cypress_throttle (struct usb_serial_port *port) | |||
1178 | } | 1211 | } |
1179 | 1212 | ||
1180 | 1213 | ||
1181 | static void cypress_unthrottle (struct usb_serial_port *port) | 1214 | static void cypress_unthrottle(struct tty_struct *tty) |
1182 | { | 1215 | { |
1216 | struct usb_serial_port *port = tty->driver_data; | ||
1183 | struct cypress_private *priv = usb_get_serial_port_data(port); | 1217 | struct cypress_private *priv = usb_get_serial_port_data(port); |
1184 | int actually_throttled, result; | 1218 | int actually_throttled, result; |
1185 | unsigned long flags; | 1219 | unsigned long flags; |
@@ -1232,12 +1266,13 @@ static void cypress_read_int_callback(struct urb *urb) | |||
1232 | /* precursor to disconnect so just go away */ | 1266 | /* precursor to disconnect so just go away */ |
1233 | return; | 1267 | return; |
1234 | case -EPIPE: | 1268 | case -EPIPE: |
1235 | usb_clear_halt(port->serial->dev,0x81); | 1269 | usb_clear_halt(port->serial->dev, 0x81); |
1236 | break; | 1270 | break; |
1237 | default: | 1271 | default: |
1238 | /* something ugly is going on... */ | 1272 | /* something ugly is going on... */ |
1239 | dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n", | 1273 | dev_err(&urb->dev->dev, |
1240 | __func__, status); | 1274 | "%s - unexpected nonzero read status received: %d\n", |
1275 | __func__, status); | ||
1241 | cypress_set_dead(port); | 1276 | cypress_set_dead(port); |
1242 | return; | 1277 | return; |
1243 | } | 1278 | } |
@@ -1251,7 +1286,7 @@ static void cypress_read_int_callback(struct urb *urb) | |||
1251 | } | 1286 | } |
1252 | spin_unlock_irqrestore(&priv->lock, flags); | 1287 | spin_unlock_irqrestore(&priv->lock, flags); |
1253 | 1288 | ||
1254 | tty = port->tty; | 1289 | tty = port->port.tty; |
1255 | if (!tty) { | 1290 | if (!tty) { |
1256 | dbg("%s - bad tty pointer - exiting", __func__); | 1291 | dbg("%s - bad tty pointer - exiting", __func__); |
1257 | return; | 1292 | return; |
@@ -1285,8 +1320,8 @@ static void cypress_read_int_callback(struct urb *urb) | |||
1285 | goto continue_read; | 1320 | goto continue_read; |
1286 | } | 1321 | } |
1287 | 1322 | ||
1288 | usb_serial_debug_data (debug, &port->dev, __func__, | 1323 | usb_serial_debug_data(debug, &port->dev, __func__, |
1289 | urb->actual_length, data); | 1324 | urb->actual_length, data); |
1290 | 1325 | ||
1291 | spin_lock_irqsave(&priv->lock, flags); | 1326 | spin_lock_irqsave(&priv->lock, flags); |
1292 | /* check to see if status has changed */ | 1327 | /* check to see if status has changed */ |
@@ -1327,7 +1362,7 @@ static void cypress_read_int_callback(struct urb *urb) | |||
1327 | data[i]); | 1362 | data[i]); |
1328 | tty_insert_flip_char(tty, data[i], tty_flag); | 1363 | tty_insert_flip_char(tty, data[i], tty_flag); |
1329 | } | 1364 | } |
1330 | tty_flip_buffer_push(port->tty); | 1365 | tty_flip_buffer_push(port->port.tty); |
1331 | } | 1366 | } |
1332 | 1367 | ||
1333 | spin_lock_irqsave(&priv->lock, flags); | 1368 | spin_lock_irqsave(&priv->lock, flags); |
@@ -1339,13 +1374,14 @@ continue_read: | |||
1339 | 1374 | ||
1340 | /* Continue trying to always read... unless the port has closed. */ | 1375 | /* Continue trying to always read... unless the port has closed. */ |
1341 | 1376 | ||
1342 | if (port->open_count > 0 && priv->comm_is_ok) { | 1377 | if (port->port.count > 0 && priv->comm_is_ok) { |
1343 | usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, | 1378 | usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, |
1344 | usb_rcvintpipe(port->serial->dev, | 1379 | usb_rcvintpipe(port->serial->dev, |
1345 | port->interrupt_in_endpointAddress), | 1380 | port->interrupt_in_endpointAddress), |
1346 | port->interrupt_in_urb->transfer_buffer, | 1381 | port->interrupt_in_urb->transfer_buffer, |
1347 | port->interrupt_in_urb->transfer_buffer_length, | 1382 | port->interrupt_in_urb->transfer_buffer_length, |
1348 | cypress_read_int_callback, port, priv->read_urb_interval); | 1383 | cypress_read_int_callback, port, |
1384 | priv->read_urb_interval); | ||
1349 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); | 1385 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
1350 | if (result) { | 1386 | if (result) { |
1351 | dev_err(&urb->dev->dev, "%s - failed resubmitting " | 1387 | dev_err(&urb->dev->dev, "%s - failed resubmitting " |
@@ -1369,42 +1405,43 @@ static void cypress_write_int_callback(struct urb *urb) | |||
1369 | dbg("%s - port %d", __func__, port->number); | 1405 | dbg("%s - port %d", __func__, port->number); |
1370 | 1406 | ||
1371 | switch (status) { | 1407 | switch (status) { |
1372 | case 0: | 1408 | case 0: |
1373 | /* success */ | 1409 | /* success */ |
1410 | break; | ||
1411 | case -ECONNRESET: | ||
1412 | case -ENOENT: | ||
1413 | case -ESHUTDOWN: | ||
1414 | /* this urb is terminated, clean up */ | ||
1415 | dbg("%s - urb shutting down with status: %d", | ||
1416 | __func__, status); | ||
1417 | priv->write_urb_in_use = 0; | ||
1418 | return; | ||
1419 | case -EPIPE: /* no break needed; clear halt and resubmit */ | ||
1420 | if (!priv->comm_is_ok) | ||
1374 | break; | 1421 | break; |
1375 | case -ECONNRESET: | 1422 | usb_clear_halt(port->serial->dev, 0x02); |
1376 | case -ENOENT: | 1423 | /* error in the urb, so we have to resubmit it */ |
1377 | case -ESHUTDOWN: | 1424 | dbg("%s - nonzero write bulk status received: %d", |
1378 | /* this urb is terminated, clean up */ | 1425 | __func__, status); |
1379 | dbg("%s - urb shutting down with status: %d", | 1426 | port->interrupt_out_urb->transfer_buffer_length = 1; |
1380 | __func__, status); | 1427 | port->interrupt_out_urb->dev = port->serial->dev; |
1381 | priv->write_urb_in_use = 0; | 1428 | result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); |
1429 | if (!result) | ||
1382 | return; | 1430 | return; |
1383 | case -EPIPE: /* no break needed; clear halt and resubmit */ | 1431 | dev_err(&urb->dev->dev, |
1384 | if (!priv->comm_is_ok) | 1432 | "%s - failed resubmitting write urb, error %d\n", |
1385 | break; | 1433 | __func__, result); |
1386 | usb_clear_halt(port->serial->dev, 0x02); | 1434 | cypress_set_dead(port); |
1387 | /* error in the urb, so we have to resubmit it */ | 1435 | break; |
1388 | dbg("%s - nonzero write bulk status received: %d", | 1436 | default: |
1389 | __func__, status); | 1437 | dev_err(&urb->dev->dev, |
1390 | port->interrupt_out_urb->transfer_buffer_length = 1; | 1438 | "%s - unexpected nonzero write status received: %d\n", |
1391 | port->interrupt_out_urb->dev = port->serial->dev; | 1439 | __func__, status); |
1392 | result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); | 1440 | cypress_set_dead(port); |
1393 | if (!result) | 1441 | break; |
1394 | return; | ||
1395 | dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", | ||
1396 | __func__, result); | ||
1397 | cypress_set_dead(port); | ||
1398 | break; | ||
1399 | default: | ||
1400 | dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n", | ||
1401 | __func__, status); | ||
1402 | cypress_set_dead(port); | ||
1403 | break; | ||
1404 | } | 1442 | } |
1405 | |||
1406 | priv->write_urb_in_use = 0; | 1443 | priv->write_urb_in_use = 0; |
1407 | 1444 | ||
1408 | /* send any buffered data */ | 1445 | /* send any buffered data */ |
1409 | cypress_send(port); | 1446 | cypress_send(port); |
1410 | } | 1447 | } |
@@ -1486,7 +1523,8 @@ static void cypress_buf_clear(struct cypress_buf *cb) | |||
1486 | static unsigned int cypress_buf_data_avail(struct cypress_buf *cb) | 1523 | static unsigned int cypress_buf_data_avail(struct cypress_buf *cb) |
1487 | { | 1524 | { |
1488 | if (cb != NULL) | 1525 | if (cb != NULL) |
1489 | return ((cb->buf_size + cb->buf_put - cb->buf_get) % cb->buf_size); | 1526 | return (cb->buf_size + cb->buf_put - cb->buf_get) |
1527 | % cb->buf_size; | ||
1490 | else | 1528 | else |
1491 | return 0; | 1529 | return 0; |
1492 | } | 1530 | } |
@@ -1502,7 +1540,8 @@ static unsigned int cypress_buf_data_avail(struct cypress_buf *cb) | |||
1502 | static unsigned int cypress_buf_space_avail(struct cypress_buf *cb) | 1540 | static unsigned int cypress_buf_space_avail(struct cypress_buf *cb) |
1503 | { | 1541 | { |
1504 | if (cb != NULL) | 1542 | if (cb != NULL) |
1505 | return ((cb->buf_size + cb->buf_get - cb->buf_put - 1) % cb->buf_size); | 1543 | return (cb->buf_size + cb->buf_get - cb->buf_put - 1) |
1544 | % cb->buf_size; | ||
1506 | else | 1545 | else |
1507 | return 0; | 1546 | return 0; |
1508 | } | 1547 | } |
@@ -1602,9 +1641,9 @@ static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, | |||
1602 | static int __init cypress_init(void) | 1641 | static int __init cypress_init(void) |
1603 | { | 1642 | { |
1604 | int retval; | 1643 | int retval; |
1605 | 1644 | ||
1606 | dbg("%s", __func__); | 1645 | dbg("%s", __func__); |
1607 | 1646 | ||
1608 | retval = usb_serial_register(&cypress_earthmate_device); | 1647 | retval = usb_serial_register(&cypress_earthmate_device); |
1609 | if (retval) | 1648 | if (retval) |
1610 | goto failed_em_register; | 1649 | goto failed_em_register; |
@@ -1632,23 +1671,23 @@ failed_em_register: | |||
1632 | } | 1671 | } |
1633 | 1672 | ||
1634 | 1673 | ||
1635 | static void __exit cypress_exit (void) | 1674 | static void __exit cypress_exit(void) |
1636 | { | 1675 | { |
1637 | dbg("%s", __func__); | 1676 | dbg("%s", __func__); |
1638 | 1677 | ||
1639 | usb_deregister (&cypress_driver); | 1678 | usb_deregister(&cypress_driver); |
1640 | usb_serial_deregister (&cypress_earthmate_device); | 1679 | usb_serial_deregister(&cypress_earthmate_device); |
1641 | usb_serial_deregister (&cypress_hidcom_device); | 1680 | usb_serial_deregister(&cypress_hidcom_device); |
1642 | usb_serial_deregister (&cypress_ca42v2_device); | 1681 | usb_serial_deregister(&cypress_ca42v2_device); |
1643 | } | 1682 | } |
1644 | 1683 | ||
1645 | 1684 | ||
1646 | module_init(cypress_init); | 1685 | module_init(cypress_init); |
1647 | module_exit(cypress_exit); | 1686 | module_exit(cypress_exit); |
1648 | 1687 | ||
1649 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1688 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1650 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1689 | MODULE_DESCRIPTION(DRIVER_DESC); |
1651 | MODULE_VERSION( DRIVER_VERSION ); | 1690 | MODULE_VERSION(DRIVER_VERSION); |
1652 | MODULE_LICENSE("GPL"); | 1691 | MODULE_LICENSE("GPL"); |
1653 | 1692 | ||
1654 | module_param(debug, bool, S_IRUGO | S_IWUSR); | 1693 | module_param(debug, bool, S_IRUGO | S_IWUSR); |