Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB Cypress M8 driver |
| 3 | * |
| 4 | * Copyright (C) 2004 |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 5 | * Lonnie Mendez (dignome@gmail.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2003,2004 |
| 7 | * Neil Whelchel (koyama@firstlight.net) |
| 8 | * |
| 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. |
| 13 | * |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 14 | * See Documentation/usb/usb-serial.txt for more information on using this |
| 15 | * driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
| 17 | * See http://geocities.com/i0xox0i for information on this driver and the |
| 18 | * earthmate usb device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 21 | /* Thanks to Neil Whelchel for writing the first cypress m8 implementation |
| 22 | for linux. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* Thanks to cypress for providing references for the hid reports. */ |
| 24 | /* Thanks to Jiang Zhang for providing links and for general help. */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 25 | /* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/errno.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/tty.h> |
| 33 | #include <linux/tty_driver.h> |
| 34 | #include <linux/tty_flip.h> |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/moduleparam.h> |
| 37 | #include <linux/spinlock.h> |
| 38 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 39 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/serial.h> |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 41 | #include <linux/kfifo.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/delay.h> |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 43 | #include <linux/uaccess.h> |
Johan Hovold | 0f2c2d7 | 2009-12-31 16:48:01 +0100 | [diff] [blame] | 44 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include "cypress_m8.h" |
| 47 | |
| 48 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 49 | static bool debug; |
| 50 | static bool stats; |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 51 | static int interval; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 52 | static bool unstable_bauds; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Version Information |
| 56 | */ |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 57 | #define DRIVER_VERSION "v1.10" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>" |
| 59 | #define DRIVER_DESC "Cypress USB to Serial Driver" |
| 60 | |
| 61 | /* write buffer size defines */ |
| 62 | #define CYPRESS_BUF_SIZE 1024 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 64 | static const struct usb_device_id id_table_earthmate[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, |
Lonnie Mendez | 25b6f08 | 2005-05-10 17:09:52 -0500 | [diff] [blame] | 66 | { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { } /* Terminating entry */ |
| 68 | }; |
| 69 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 70 | static const struct usb_device_id id_table_cyphidcomrs232[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) }, |
Dmitry Shapin | 6f6f06e | 2008-03-04 15:25:10 -0800 | [diff] [blame] | 72 | { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { } /* Terminating entry */ |
| 74 | }; |
| 75 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 76 | static const struct usb_device_id id_table_nokiaca42v2[] = { |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 77 | { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) }, |
| 78 | { } /* Terminating entry */ |
| 79 | }; |
| 80 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 81 | static const struct usb_device_id id_table_combined[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, |
Lonnie Mendez | 25b6f08 | 2005-05-10 17:09:52 -0500 | [diff] [blame] | 83 | { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) }, |
Dmitry Shapin | 6f6f06e | 2008-03-04 15:25:10 -0800 | [diff] [blame] | 85 | { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) }, |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 86 | { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { } /* Terminating entry */ |
| 88 | }; |
| 89 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 90 | MODULE_DEVICE_TABLE(usb, id_table_combined); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | static struct usb_driver cypress_driver = { |
| 93 | .name = "cypress", |
| 94 | .probe = usb_serial_probe, |
| 95 | .disconnect = usb_serial_disconnect, |
| 96 | .id_table = id_table_combined, |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 97 | .no_dynamic_id = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 100 | enum packet_format { |
| 101 | packet_format_1, /* b0:status, b1:payload count */ |
| 102 | packet_format_2 /* b0[7:3]:status, b0[2:0]:payload count */ |
| 103 | }; |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | struct cypress_private { |
| 106 | spinlock_t lock; /* private lock */ |
| 107 | int chiptype; /* identifier of device, for quirks/etc */ |
| 108 | int bytes_in; /* used for statistics */ |
| 109 | int bytes_out; /* used for statistics */ |
| 110 | int cmd_count; /* used for statistics */ |
| 111 | int cmd_ctrl; /* always set this to 1 before issuing a command */ |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 112 | struct kfifo write_fifo; /* write fifo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | int write_urb_in_use; /* write urb in use indicator */ |
Mike Isely | 0257fa9 | 2006-08-29 22:06:59 -0500 | [diff] [blame] | 114 | int write_urb_interval; /* interval to use for write urb */ |
| 115 | int read_urb_interval; /* interval to use for read urb */ |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 116 | int comm_is_ok; /* true if communication is (still) ok */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | int termios_initialized; |
| 118 | __u8 line_control; /* holds dtr / rts value */ |
| 119 | __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */ |
| 120 | __u8 current_config; /* stores the current configuration byte */ |
| 121 | __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */ |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 122 | enum packet_format pkt_fmt; /* format to use for packet send / receive */ |
Mike Isely | 3d6aa32 | 2008-02-10 20:23:24 -0600 | [diff] [blame] | 123 | int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 124 | int baud_rate; /* stores current baud rate in |
| 125 | integer form */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | int isthrottled; /* if throttled, discard reads */ |
| 127 | wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ |
| 128 | char prev_status, diff_status; /* used for TIOCMIWAIT */ |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 129 | /* we pass a pointer to this as the argument sent to |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 130 | cypress_set_termios old_termios */ |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 131 | struct ktermios tmp_termios; /* stores the old termios settings */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /* function prototypes for the Cypress USB to serial device */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 135 | static int cypress_earthmate_startup(struct usb_serial *serial); |
| 136 | static int cypress_hidcom_startup(struct usb_serial *serial); |
| 137 | static int cypress_ca42v2_startup(struct usb_serial *serial); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 138 | static void cypress_release(struct usb_serial *serial); |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 139 | static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 140 | static void cypress_close(struct usb_serial_port *port); |
| 141 | static void cypress_dtr_rts(struct usb_serial_port *port, int on); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 142 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 143 | const unsigned char *buf, int count); |
| 144 | static void cypress_send(struct usb_serial_port *port); |
| 145 | static int cypress_write_room(struct tty_struct *tty); |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 146 | static int cypress_ioctl(struct tty_struct *tty, |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 147 | unsigned int cmd, unsigned long arg); |
| 148 | static void cypress_set_termios(struct tty_struct *tty, |
| 149 | struct usb_serial_port *port, struct ktermios *old); |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 150 | static int cypress_tiocmget(struct tty_struct *tty); |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 151 | static int cypress_tiocmset(struct tty_struct *tty, |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 152 | unsigned int set, unsigned int clear); |
| 153 | static int cypress_chars_in_buffer(struct tty_struct *tty); |
| 154 | static void cypress_throttle(struct tty_struct *tty); |
| 155 | static void cypress_unthrottle(struct tty_struct *tty); |
| 156 | static void cypress_set_dead(struct usb_serial_port *port); |
| 157 | static void cypress_read_int_callback(struct urb *urb); |
| 158 | static void cypress_write_int_callback(struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 160 | static struct usb_serial_driver cypress_earthmate_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 161 | .driver = { |
| 162 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 163 | .name = "earthmate", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 164 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 165 | .description = "DeLorme Earthmate USB", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 166 | .usb_driver = &cypress_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | .id_table = id_table_earthmate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | .num_ports = 1, |
| 169 | .attach = cypress_earthmate_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 170 | .release = cypress_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | .open = cypress_open, |
| 172 | .close = cypress_close, |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 173 | .dtr_rts = cypress_dtr_rts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | .write = cypress_write, |
| 175 | .write_room = cypress_write_room, |
| 176 | .ioctl = cypress_ioctl, |
| 177 | .set_termios = cypress_set_termios, |
| 178 | .tiocmget = cypress_tiocmget, |
| 179 | .tiocmset = cypress_tiocmset, |
| 180 | .chars_in_buffer = cypress_chars_in_buffer, |
| 181 | .throttle = cypress_throttle, |
| 182 | .unthrottle = cypress_unthrottle, |
| 183 | .read_int_callback = cypress_read_int_callback, |
| 184 | .write_int_callback = cypress_write_int_callback, |
| 185 | }; |
| 186 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 187 | static struct usb_serial_driver cypress_hidcom_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 188 | .driver = { |
| 189 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 190 | .name = "cyphidcom", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 191 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 192 | .description = "HID->COM RS232 Adapter", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 193 | .usb_driver = &cypress_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | .id_table = id_table_cyphidcomrs232, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | .num_ports = 1, |
| 196 | .attach = cypress_hidcom_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 197 | .release = cypress_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | .open = cypress_open, |
| 199 | .close = cypress_close, |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 200 | .dtr_rts = cypress_dtr_rts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | .write = cypress_write, |
| 202 | .write_room = cypress_write_room, |
| 203 | .ioctl = cypress_ioctl, |
| 204 | .set_termios = cypress_set_termios, |
| 205 | .tiocmget = cypress_tiocmget, |
| 206 | .tiocmset = cypress_tiocmset, |
| 207 | .chars_in_buffer = cypress_chars_in_buffer, |
| 208 | .throttle = cypress_throttle, |
| 209 | .unthrottle = cypress_unthrottle, |
| 210 | .read_int_callback = cypress_read_int_callback, |
| 211 | .write_int_callback = cypress_write_int_callback, |
| 212 | }; |
| 213 | |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 214 | static struct usb_serial_driver cypress_ca42v2_device = { |
| 215 | .driver = { |
| 216 | .owner = THIS_MODULE, |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 217 | .name = "nokiaca42v2", |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 218 | }, |
| 219 | .description = "Nokia CA-42 V2 Adapter", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 220 | .usb_driver = &cypress_driver, |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 221 | .id_table = id_table_nokiaca42v2, |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 222 | .num_ports = 1, |
| 223 | .attach = cypress_ca42v2_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 224 | .release = cypress_release, |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 225 | .open = cypress_open, |
| 226 | .close = cypress_close, |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 227 | .dtr_rts = cypress_dtr_rts, |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 228 | .write = cypress_write, |
| 229 | .write_room = cypress_write_room, |
| 230 | .ioctl = cypress_ioctl, |
| 231 | .set_termios = cypress_set_termios, |
| 232 | .tiocmget = cypress_tiocmget, |
| 233 | .tiocmset = cypress_tiocmset, |
| 234 | .chars_in_buffer = cypress_chars_in_buffer, |
| 235 | .throttle = cypress_throttle, |
| 236 | .unthrottle = cypress_unthrottle, |
| 237 | .read_int_callback = cypress_read_int_callback, |
| 238 | .write_int_callback = cypress_write_int_callback, |
| 239 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | /***************************************************************************** |
| 242 | * Cypress serial helper functions |
| 243 | *****************************************************************************/ |
| 244 | |
| 245 | |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 246 | static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate) |
Mike Isely | 92983c2 | 2008-02-10 20:23:32 -0600 | [diff] [blame] | 247 | { |
Mike Isely | 92983c2 | 2008-02-10 20:23:32 -0600 | [diff] [blame] | 248 | struct cypress_private *priv; |
| 249 | priv = usb_get_serial_port_data(port); |
| 250 | |
Mike Frysinger | c312659 | 2009-12-18 16:33:03 -0500 | [diff] [blame] | 251 | if (unstable_bauds) |
| 252 | return new_rate; |
| 253 | |
Mike Isely | 92983c2 | 2008-02-10 20:23:32 -0600 | [diff] [blame] | 254 | /* |
| 255 | * The general purpose firmware for the Cypress M8 allows for |
| 256 | * a maximum speed of 57600bps (I have no idea whether DeLorme |
| 257 | * chose to use the general purpose firmware or not), if you |
| 258 | * need to modify this speed setting for your own project |
| 259 | * please add your own chiptype and modify the code likewise. |
| 260 | * The Cypress HID->COM device will work successfully up to |
| 261 | * 115200bps (but the actual throughput is around 3kBps). |
| 262 | */ |
Mike Isely | 92983c2 | 2008-02-10 20:23:32 -0600 | [diff] [blame] | 263 | if (port->serial->dev->speed == USB_SPEED_LOW) { |
| 264 | /* |
| 265 | * Mike Isely <isely@pobox.com> 2-Feb-2008: The |
| 266 | * Cypress app note that describes this mechanism |
| 267 | * states the the low-speed part can't handle more |
| 268 | * than 800 bytes/sec, in which case 4800 baud is the |
| 269 | * safest speed for a part like that. |
| 270 | */ |
| 271 | if (new_rate > 4800) { |
| 272 | dbg("%s - failed setting baud rate, device incapable " |
| 273 | "speed %d", __func__, new_rate); |
| 274 | return -1; |
| 275 | } |
| 276 | } |
| 277 | switch (priv->chiptype) { |
| 278 | case CT_EARTHMATE: |
| 279 | if (new_rate <= 600) { |
| 280 | /* 300 and 600 baud rates are supported under |
| 281 | * the generic firmware, but are not used with |
| 282 | * NMEA and SiRF protocols */ |
| 283 | dbg("%s - failed setting baud rate, unsupported speed " |
| 284 | "of %d on Earthmate GPS", __func__, new_rate); |
| 285 | return -1; |
| 286 | } |
| 287 | break; |
| 288 | default: |
| 289 | break; |
| 290 | } |
| 291 | return new_rate; |
| 292 | } |
| 293 | |
| 294 | |
Steven Cole | 093cf72 | 2005-05-03 19:07:24 -0600 | [diff] [blame] | 295 | /* This function can either set or retrieve the current serial line settings */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 296 | static int cypress_serial_control(struct tty_struct *tty, |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 297 | struct usb_serial_port *port, speed_t baud_rate, int data_bits, |
| 298 | int stop_bits, int parity_enable, int parity_type, int reset, |
| 299 | int cypress_request_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 301 | int new_baudrate = 0, retval = 0, tries = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | struct cypress_private *priv; |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 303 | u8 *feature_buffer; |
| 304 | const unsigned int feature_len = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | unsigned long flags; |
| 306 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 307 | dbg("%s", __func__); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | priv = usb_get_serial_port_data(port); |
| 310 | |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 311 | if (!priv->comm_is_ok) |
| 312 | return -ENODEV; |
| 313 | |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 314 | feature_buffer = kcalloc(feature_len, sizeof(u8), GFP_KERNEL); |
| 315 | if (!feature_buffer) |
| 316 | return -ENOMEM; |
| 317 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 318 | switch (cypress_request_type) { |
| 319 | case CYPRESS_SET_CONFIG: |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 320 | /* 0 means 'Hang up' so doesn't change the true bit rate */ |
Mike Frysinger | 2805eb1 | 2009-12-18 16:33:02 -0500 | [diff] [blame] | 321 | new_baudrate = priv->baud_rate; |
| 322 | if (baud_rate && baud_rate != priv->baud_rate) { |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 323 | dbg("%s - baud rate is changing", __func__); |
| 324 | retval = analyze_baud_rate(port, baud_rate); |
Mike Frysinger | 2805eb1 | 2009-12-18 16:33:02 -0500 | [diff] [blame] | 325 | if (retval >= 0) { |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 326 | new_baudrate = retval; |
| 327 | dbg("%s - New baud rate set to %d", |
| 328 | __func__, new_baudrate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 330 | } |
| 331 | dbg("%s - baud rate is being sent as %d", |
| 332 | __func__, new_baudrate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 334 | /* fill the feature_buffer with new configuration */ |
Johan Hovold | 0f2c2d7 | 2009-12-31 16:48:01 +0100 | [diff] [blame] | 335 | put_unaligned_le32(new_baudrate, feature_buffer); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 336 | feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */ |
| 337 | /* 1 bit gap */ |
| 338 | feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */ |
| 339 | feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */ |
| 340 | feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */ |
| 341 | /* 1 bit gap */ |
| 342 | feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 344 | dbg("%s - device is being sent this feature report:", |
| 345 | __func__); |
| 346 | dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, |
| 347 | feature_buffer[0], feature_buffer[1], |
| 348 | feature_buffer[2], feature_buffer[3], |
| 349 | feature_buffer[4]); |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 350 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 351 | do { |
| 352 | retval = usb_control_msg(port->serial->dev, |
| 353 | usb_sndctrlpipe(port->serial->dev, 0), |
| 354 | HID_REQ_SET_REPORT, |
| 355 | USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, |
| 356 | 0x0300, 0, feature_buffer, |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 357 | feature_len, 500); |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 358 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 359 | if (tries++ >= 3) |
| 360 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 362 | } while (retval != feature_len && |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 363 | retval != -ENODEV); |
Mike Isely | 9307554 | 2008-02-10 20:23:14 -0600 | [diff] [blame] | 364 | |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 365 | if (retval != feature_len) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 366 | dev_err(&port->dev, "%s - failed sending serial " |
| 367 | "line settings - %d\n", __func__, retval); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 368 | cypress_set_dead(port); |
| 369 | } else { |
| 370 | spin_lock_irqsave(&priv->lock, flags); |
| 371 | priv->baud_rate = new_baudrate; |
| 372 | priv->current_config = feature_buffer[4]; |
| 373 | spin_unlock_irqrestore(&priv->lock, flags); |
| 374 | /* If we asked for a speed change encode it */ |
| 375 | if (baud_rate) |
| 376 | tty_encode_baud_rate(tty, |
| 377 | new_baudrate, new_baudrate); |
| 378 | } |
| 379 | break; |
| 380 | case CYPRESS_GET_CONFIG: |
| 381 | if (priv->get_cfg_unsafe) { |
| 382 | /* Not implemented for this device, |
| 383 | and if we try to do it we're likely |
| 384 | to crash the hardware. */ |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 385 | retval = -ENOTTY; |
| 386 | goto out; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 387 | } |
| 388 | dbg("%s - retreiving serial line settings", __func__); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 389 | do { |
| 390 | retval = usb_control_msg(port->serial->dev, |
| 391 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 392 | HID_REQ_GET_REPORT, |
| 393 | USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS, |
| 394 | 0x0300, 0, feature_buffer, |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 395 | feature_len, 500); |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 396 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 397 | if (tries++ >= 3) |
| 398 | break; |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 399 | } while (retval != feature_len |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 400 | && retval != -ENODEV); |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 401 | |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 402 | if (retval != feature_len) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 403 | dev_err(&port->dev, "%s - failed to retrieve serial " |
| 404 | "line settings - %d\n", __func__, retval); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 405 | cypress_set_dead(port); |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 406 | goto out; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 407 | } else { |
| 408 | spin_lock_irqsave(&priv->lock, flags); |
| 409 | /* store the config in one byte, and later |
| 410 | use bit masks to check values */ |
| 411 | priv->current_config = feature_buffer[4]; |
Johan Hovold | 0f2c2d7 | 2009-12-31 16:48:01 +0100 | [diff] [blame] | 412 | priv->baud_rate = get_unaligned_le32(feature_buffer); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 413 | spin_unlock_irqrestore(&priv->lock, flags); |
| 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 416 | spin_lock_irqsave(&priv->lock, flags); |
| 417 | ++priv->cmd_count; |
| 418 | spin_unlock_irqrestore(&priv->lock, flags); |
Johan Hovold | 0954644 | 2009-12-28 23:01:48 +0100 | [diff] [blame] | 419 | out: |
| 420 | kfree(feature_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | return retval; |
| 422 | } /* cypress_serial_control */ |
| 423 | |
| 424 | |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 425 | static void cypress_set_dead(struct usb_serial_port *port) |
| 426 | { |
| 427 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 428 | unsigned long flags; |
| 429 | |
| 430 | spin_lock_irqsave(&priv->lock, flags); |
| 431 | if (!priv->comm_is_ok) { |
| 432 | spin_unlock_irqrestore(&priv->lock, flags); |
| 433 | return; |
| 434 | } |
| 435 | priv->comm_is_ok = 0; |
| 436 | spin_unlock_irqrestore(&priv->lock, flags); |
| 437 | |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 438 | dev_err(&port->dev, "cypress_m8 suspending failing port %d - " |
| 439 | "interval might be too short\n", port->number); |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | /***************************************************************************** |
| 444 | * Cypress serial driver functions |
| 445 | *****************************************************************************/ |
| 446 | |
| 447 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 448 | static int generic_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
| 450 | struct cypress_private *priv; |
Mike Isely | 0257fa9 | 2006-08-29 22:06:59 -0500 | [diff] [blame] | 451 | struct usb_serial_port *port = serial->port[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 453 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 455 | priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | if (!priv) |
| 457 | return -ENOMEM; |
| 458 | |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 459 | priv->comm_is_ok = !0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | spin_lock_init(&priv->lock); |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 461 | if (kfifo_alloc(&priv->write_fifo, CYPRESS_BUF_SIZE, GFP_KERNEL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | kfree(priv); |
| 463 | return -ENOMEM; |
| 464 | } |
| 465 | init_waitqueue_head(&priv->delta_msr_wait); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 466 | |
| 467 | usb_reset_configuration(serial->dev); |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | priv->cmd_ctrl = 0; |
| 470 | priv->line_control = 0; |
| 471 | priv->termios_initialized = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | priv->rx_flags = 0; |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 473 | /* Default packet format setting is determined by packet size. |
| 474 | Anything with a size larger then 9 must have a separate |
| 475 | count field since the 3 bit count field is otherwise too |
| 476 | small. Otherwise we can use the slightly more compact |
| 477 | format. This is in accordance with the cypress_m8 serial |
| 478 | converter app note. */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 479 | if (port->interrupt_out_size > 9) |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 480 | priv->pkt_fmt = packet_format_1; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 481 | else |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 482 | priv->pkt_fmt = packet_format_2; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 483 | |
Mike Isely | 0257fa9 | 2006-08-29 22:06:59 -0500 | [diff] [blame] | 484 | if (interval > 0) { |
| 485 | priv->write_urb_interval = interval; |
| 486 | priv->read_urb_interval = interval; |
| 487 | dbg("%s - port %d read & write intervals forced to %d", |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 488 | __func__, port->number, interval); |
Mike Isely | 0257fa9 | 2006-08-29 22:06:59 -0500 | [diff] [blame] | 489 | } else { |
| 490 | priv->write_urb_interval = port->interrupt_out_urb->interval; |
| 491 | priv->read_urb_interval = port->interrupt_in_urb->interval; |
| 492 | dbg("%s - port %d intervals: read=%d write=%d", |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 493 | __func__, port->number, |
| 494 | priv->read_urb_interval, priv->write_urb_interval); |
Mike Isely | 0257fa9 | 2006-08-29 22:06:59 -0500 | [diff] [blame] | 495 | } |
| 496 | usb_set_serial_port_data(port, priv); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 497 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 498 | return 0; |
| 499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
| 501 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 502 | static int cypress_earthmate_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
| 504 | struct cypress_private *priv; |
Mike Isely | 3d6aa32 | 2008-02-10 20:23:24 -0600 | [diff] [blame] | 505 | struct usb_serial_port *port = serial->port[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 507 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | if (generic_startup(serial)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 510 | dbg("%s - Failed setting up port %d", __func__, |
Mike Isely | 3d6aa32 | 2008-02-10 20:23:24 -0600 | [diff] [blame] | 511 | port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | return 1; |
| 513 | } |
| 514 | |
Mike Isely | 3d6aa32 | 2008-02-10 20:23:24 -0600 | [diff] [blame] | 515 | priv = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | priv->chiptype = CT_EARTHMATE; |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 517 | /* All Earthmate devices use the separated-count packet |
| 518 | format! Idiotic. */ |
| 519 | priv->pkt_fmt = packet_format_1; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 520 | if (serial->dev->descriptor.idProduct != |
| 521 | cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) { |
Mike Isely | 3d6aa32 | 2008-02-10 20:23:24 -0600 | [diff] [blame] | 522 | /* The old original USB Earthmate seemed able to |
| 523 | handle GET_CONFIG requests; everything they've |
| 524 | produced since that time crashes if this command is |
| 525 | attempted :-( */ |
| 526 | dbg("%s - Marking this device as unsafe for GET_CONFIG " |
| 527 | "commands", __func__); |
| 528 | priv->get_cfg_unsafe = !0; |
| 529 | } |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 530 | |
| 531 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } /* cypress_earthmate_startup */ |
| 533 | |
| 534 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 535 | static int cypress_hidcom_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | { |
| 537 | struct cypress_private *priv; |
| 538 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 539 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | if (generic_startup(serial)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 542 | dbg("%s - Failed setting up port %d", __func__, |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 543 | serial->port[0]->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | return 1; |
| 545 | } |
| 546 | |
| 547 | priv = usb_get_serial_port_data(serial->port[0]); |
| 548 | priv->chiptype = CT_CYPHIDCOM; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 549 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 550 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } /* cypress_hidcom_startup */ |
| 552 | |
| 553 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 554 | static int cypress_ca42v2_startup(struct usb_serial *serial) |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 555 | { |
| 556 | struct cypress_private *priv; |
| 557 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 558 | dbg("%s", __func__); |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 559 | |
| 560 | if (generic_startup(serial)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 561 | dbg("%s - Failed setting up port %d", __func__, |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 562 | serial->port[0]->number); |
| 563 | return 1; |
| 564 | } |
| 565 | |
| 566 | priv = usb_get_serial_port_data(serial->port[0]); |
| 567 | priv->chiptype = CT_CA42V2; |
| 568 | |
| 569 | return 0; |
| 570 | } /* cypress_ca42v2_startup */ |
| 571 | |
| 572 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 573 | static void cypress_release(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
| 575 | struct cypress_private *priv; |
| 576 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 577 | dbg("%s - port %d", __func__, serial->port[0]->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
| 579 | /* all open ports are closed at this point */ |
| 580 | |
| 581 | priv = usb_get_serial_port_data(serial->port[0]); |
| 582 | |
| 583 | if (priv) { |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 584 | kfifo_free(&priv->write_fifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | kfree(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 590 | static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
| 592 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 593 | struct usb_serial *serial = port->serial; |
| 594 | unsigned long flags; |
| 595 | int result = 0; |
| 596 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 597 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 599 | if (!priv->comm_is_ok) |
| 600 | return -EIO; |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | /* clear halts before open */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | usb_clear_halt(serial->dev, 0x81); |
| 604 | usb_clear_halt(serial->dev, 0x02); |
| 605 | |
| 606 | spin_lock_irqsave(&priv->lock, flags); |
| 607 | /* reset read/write statistics */ |
| 608 | priv->bytes_in = 0; |
| 609 | priv->bytes_out = 0; |
| 610 | priv->cmd_count = 0; |
| 611 | priv->rx_flags = 0; |
| 612 | spin_unlock_irqrestore(&priv->lock, flags); |
| 613 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 614 | /* Set termios */ |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 615 | cypress_send(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 617 | if (tty) |
| 618 | cypress_set_termios(tty, port, &priv->tmp_termios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | /* setup the port and start reading from the device */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 621 | if (!port->interrupt_in_urb) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 622 | dev_err(&port->dev, "%s - interrupt_in_urb is empty!\n", |
| 623 | __func__); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 624 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | usb_fill_int_urb(port->interrupt_in_urb, serial->dev, |
| 628 | usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 629 | port->interrupt_in_urb->transfer_buffer, |
| 630 | port->interrupt_in_urb->transfer_buffer_length, |
Mike Isely | 0257fa9 | 2006-08-29 22:06:59 -0500 | [diff] [blame] | 631 | cypress_read_int_callback, port, priv->read_urb_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 633 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 634 | if (result) { |
| 635 | dev_err(&port->dev, |
| 636 | "%s - failed submitting read urb, error %d\n", |
| 637 | __func__, result); |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 638 | cypress_set_dead(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 640 | port->port.drain_delay = 256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return result; |
| 642 | } /* cypress_open */ |
| 643 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 644 | static void cypress_dtr_rts(struct usb_serial_port *port, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
| 646 | struct cypress_private *priv = usb_get_serial_port_data(port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 647 | /* drop dtr and rts */ |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 648 | spin_lock_irq(&priv->lock); |
| 649 | if (on == 0) |
| 650 | priv->line_control = 0; |
| 651 | else |
| 652 | priv->line_control = CONTROL_DTR | CONTROL_RTS; |
| 653 | priv->cmd_ctrl = 1; |
| 654 | spin_unlock_irq(&priv->lock); |
| 655 | cypress_write(NULL, port, NULL, 0); |
| 656 | } |
| 657 | |
| 658 | static void cypress_close(struct usb_serial_port *port) |
| 659 | { |
| 660 | struct cypress_private *priv = usb_get_serial_port_data(port); |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 661 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 663 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Oliver Neukum | 9e3b1d8 | 2008-01-22 15:54:54 +0100 | [diff] [blame] | 665 | /* writing is potentially harmful, lock must be taken */ |
| 666 | mutex_lock(&port->serial->disc_mutex); |
| 667 | if (port->serial->disconnected) { |
| 668 | mutex_unlock(&port->serial->disc_mutex); |
| 669 | return; |
| 670 | } |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 671 | spin_lock_irqsave(&priv->lock, flags); |
| 672 | kfifo_reset_out(&priv->write_fifo); |
| 673 | spin_unlock_irqrestore(&priv->lock, flags); |
| 674 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 675 | dbg("%s - stopping urbs", __func__); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 676 | usb_kill_urb(port->interrupt_in_urb); |
| 677 | usb_kill_urb(port->interrupt_out_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | if (stats) |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 680 | dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", |
| 681 | priv->bytes_in, priv->bytes_out, priv->cmd_count); |
Oliver Neukum | 9e3b1d8 | 2008-01-22 15:54:54 +0100 | [diff] [blame] | 682 | mutex_unlock(&port->serial->disc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } /* cypress_close */ |
| 684 | |
| 685 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 686 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 687 | const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
| 689 | struct cypress_private *priv = usb_get_serial_port_data(port); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 690 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 691 | dbg("%s - port %d, %d bytes", __func__, port->number, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | /* line control commands, which need to be executed immediately, |
| 694 | are not put into the buffer for obvious reasons. |
| 695 | */ |
| 696 | if (priv->cmd_ctrl) { |
| 697 | count = 0; |
| 698 | goto finish; |
| 699 | } |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | if (!count) |
| 702 | return count; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 703 | |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 704 | count = kfifo_in_locked(&priv->write_fifo, buf, count, &priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
| 706 | finish: |
| 707 | cypress_send(port); |
| 708 | |
| 709 | return count; |
| 710 | } /* cypress_write */ |
| 711 | |
| 712 | |
| 713 | static void cypress_send(struct usb_serial_port *port) |
| 714 | { |
| 715 | int count = 0, result, offset, actual_size; |
| 716 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 717 | unsigned long flags; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 718 | |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 719 | if (!priv->comm_is_ok) |
| 720 | return; |
| 721 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 722 | dbg("%s - port %d", __func__, port->number); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 723 | dbg("%s - interrupt out size is %d", __func__, |
| 724 | port->interrupt_out_size); |
| 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | spin_lock_irqsave(&priv->lock, flags); |
| 727 | if (priv->write_urb_in_use) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 728 | dbg("%s - can't write, urb in use", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | spin_unlock_irqrestore(&priv->lock, flags); |
| 730 | return; |
| 731 | } |
| 732 | spin_unlock_irqrestore(&priv->lock, flags); |
| 733 | |
| 734 | /* clear buffer */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 735 | memset(port->interrupt_out_urb->transfer_buffer, 0, |
| 736 | port->interrupt_out_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | spin_lock_irqsave(&priv->lock, flags); |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 739 | switch (priv->pkt_fmt) { |
| 740 | default: |
| 741 | case packet_format_1: |
| 742 | /* this is for the CY7C64013... */ |
| 743 | offset = 2; |
| 744 | port->interrupt_out_buffer[0] = priv->line_control; |
| 745 | break; |
| 746 | case packet_format_2: |
| 747 | /* this is for the CY7C63743... */ |
| 748 | offset = 1; |
| 749 | port->interrupt_out_buffer[0] = priv->line_control; |
| 750 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | if (priv->line_control & CONTROL_RESET) |
| 754 | priv->line_control &= ~CONTROL_RESET; |
| 755 | |
| 756 | if (priv->cmd_ctrl) { |
| 757 | priv->cmd_count++; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 758 | dbg("%s - line control command being issued", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | spin_unlock_irqrestore(&priv->lock, flags); |
| 760 | goto send; |
| 761 | } else |
| 762 | spin_unlock_irqrestore(&priv->lock, flags); |
| 763 | |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 764 | count = kfifo_out_locked(&priv->write_fifo, |
| 765 | &port->interrupt_out_buffer[offset], |
| 766 | port->interrupt_out_size - offset, |
| 767 | &priv->lock); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 768 | if (count == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 771 | switch (priv->pkt_fmt) { |
| 772 | default: |
| 773 | case packet_format_1: |
| 774 | port->interrupt_out_buffer[1] = count; |
| 775 | break; |
| 776 | case packet_format_2: |
| 777 | port->interrupt_out_buffer[0] |= count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 780 | dbg("%s - count is %d", __func__, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | send: |
| 783 | spin_lock_irqsave(&priv->lock, flags); |
| 784 | priv->write_urb_in_use = 1; |
| 785 | spin_unlock_irqrestore(&priv->lock, flags); |
| 786 | |
| 787 | if (priv->cmd_ctrl) |
| 788 | actual_size = 1; |
| 789 | else |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 790 | actual_size = count + |
| 791 | (priv->pkt_fmt == packet_format_1 ? 2 : 1); |
| 792 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 793 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 794 | port->interrupt_out_size, |
| 795 | port->interrupt_out_urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Mike Isely | 9aa8dae | 2006-08-29 22:07:04 -0500 | [diff] [blame] | 797 | usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, |
| 798 | usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), |
| 799 | port->interrupt_out_buffer, port->interrupt_out_size, |
| 800 | cypress_write_int_callback, port, priv->write_urb_interval); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 801 | result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | if (result) { |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 803 | dev_err(&port->dev, |
| 804 | "%s - failed submitting write urb, error %d\n", |
| 805 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | priv->write_urb_in_use = 0; |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 807 | cypress_set_dead(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | spin_lock_irqsave(&priv->lock, flags); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 811 | if (priv->cmd_ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | priv->cmd_ctrl = 0; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 813 | |
| 814 | /* do not count the line control and size bytes */ |
| 815 | priv->bytes_out += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | spin_unlock_irqrestore(&priv->lock, flags); |
| 817 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 818 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } /* cypress_send */ |
| 820 | |
| 821 | |
| 822 | /* returns how much space is available in the soft buffer */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 823 | static int cypress_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 825 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 827 | int room = 0; |
| 828 | unsigned long flags; |
| 829 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 830 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
| 832 | spin_lock_irqsave(&priv->lock, flags); |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 833 | room = kfifo_avail(&priv->write_fifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | spin_unlock_irqrestore(&priv->lock, flags); |
| 835 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 836 | dbg("%s - returns %d", __func__, room); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | return room; |
| 838 | } |
| 839 | |
| 840 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 841 | static int cypress_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 843 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 845 | __u8 status, control; |
| 846 | unsigned int result = 0; |
| 847 | unsigned long flags; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 848 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 849 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | spin_lock_irqsave(&priv->lock, flags); |
| 852 | control = priv->line_control; |
| 853 | status = priv->current_status; |
| 854 | spin_unlock_irqrestore(&priv->lock, flags); |
| 855 | |
| 856 | result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) |
| 857 | | ((control & CONTROL_RTS) ? TIOCM_RTS : 0) |
| 858 | | ((status & UART_CTS) ? TIOCM_CTS : 0) |
| 859 | | ((status & UART_DSR) ? TIOCM_DSR : 0) |
| 860 | | ((status & UART_RI) ? TIOCM_RI : 0) |
| 861 | | ((status & UART_CD) ? TIOCM_CD : 0); |
| 862 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 863 | dbg("%s - result = %x", __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
| 865 | return result; |
| 866 | } |
| 867 | |
| 868 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 869 | static int cypress_tiocmset(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | unsigned int set, unsigned int clear) |
| 871 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 872 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 874 | unsigned long flags; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 875 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 876 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | spin_lock_irqsave(&priv->lock, flags); |
| 879 | if (set & TIOCM_RTS) |
| 880 | priv->line_control |= CONTROL_RTS; |
| 881 | if (set & TIOCM_DTR) |
| 882 | priv->line_control |= CONTROL_DTR; |
| 883 | if (clear & TIOCM_RTS) |
| 884 | priv->line_control &= ~CONTROL_RTS; |
| 885 | if (clear & TIOCM_DTR) |
| 886 | priv->line_control &= ~CONTROL_DTR; |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 887 | priv->cmd_ctrl = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | spin_unlock_irqrestore(&priv->lock, flags); |
| 889 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 890 | return cypress_write(tty, port, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 894 | static int cypress_ioctl(struct tty_struct *tty, |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 895 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 897 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 899 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 900 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | switch (cmd) { |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 903 | /* This code comes from drivers/char/serial.c and ftdi_sio.c */ |
| 904 | case TIOCMIWAIT: |
| 905 | while (priv != NULL) { |
| 906 | interruptible_sleep_on(&priv->delta_msr_wait); |
| 907 | /* see if a signal did it */ |
| 908 | if (signal_pending(current)) |
| 909 | return -ERESTARTSYS; |
| 910 | else { |
| 911 | char diff = priv->diff_status; |
| 912 | if (diff == 0) |
| 913 | return -EIO; /* no change => error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 915 | /* consume all events */ |
| 916 | priv->diff_status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 918 | /* return 0 if caller wanted to know about |
| 919 | these bits */ |
| 920 | if (((arg & TIOCM_RNG) && (diff & UART_RI)) || |
| 921 | ((arg & TIOCM_DSR) && (diff & UART_DSR)) || |
| 922 | ((arg & TIOCM_CD) && (diff & UART_CD)) || |
| 923 | ((arg & TIOCM_CTS) && (diff & UART_CTS))) |
| 924 | return 0; |
| 925 | /* otherwise caller can't care less about what |
| 926 | * happened, and so we continue to wait for |
| 927 | * more events. |
| 928 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 930 | } |
| 931 | return 0; |
| 932 | default: |
| 933 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 935 | dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | return -ENOIOCTLCMD; |
| 937 | } /* cypress_ioctl */ |
| 938 | |
| 939 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 940 | static void cypress_set_termios(struct tty_struct *tty, |
| 941 | struct usb_serial_port *port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { |
| 943 | struct cypress_private *priv = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | int data_bits, stop_bits, parity_type, parity_enable; |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 945 | unsigned cflag, iflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | unsigned long flags; |
| 947 | __u8 oldlines; |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 948 | int linechange = 0; |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 949 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 950 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | spin_lock_irqsave(&priv->lock, flags); |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 953 | /* We can't clean this one up as we don't know the device type |
| 954 | early enough */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | if (!priv->termios_initialized) { |
| 956 | if (priv->chiptype == CT_EARTHMATE) { |
| 957 | *(tty->termios) = tty_std_termios; |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 958 | tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL | |
| 959 | CLOCAL; |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 960 | tty->termios->c_ispeed = 4800; |
| 961 | tty->termios->c_ospeed = 4800; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | } else if (priv->chiptype == CT_CYPHIDCOM) { |
| 963 | *(tty->termios) = tty_std_termios; |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 964 | tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | |
| 965 | CLOCAL; |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 966 | tty->termios->c_ispeed = 9600; |
| 967 | tty->termios->c_ospeed = 9600; |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 968 | } else if (priv->chiptype == CT_CA42V2) { |
| 969 | *(tty->termios) = tty_std_termios; |
| 970 | tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | |
| 971 | CLOCAL; |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 972 | tty->termios->c_ispeed = 9600; |
| 973 | tty->termios->c_ospeed = 9600; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | } |
| 975 | priv->termios_initialized = 1; |
| 976 | } |
| 977 | spin_unlock_irqrestore(&priv->lock, flags); |
| 978 | |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 979 | /* Unsupported features need clearing */ |
| 980 | tty->termios->c_cflag &= ~(CMSPAR|CRTSCTS); |
| 981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | cflag = tty->termios->c_cflag; |
| 983 | iflag = tty->termios->c_iflag; |
| 984 | |
| 985 | /* check if there are new settings */ |
| 986 | if (old_termios) { |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 987 | spin_lock_irqsave(&priv->lock, flags); |
| 988 | priv->tmp_termios = *(tty->termios); |
| 989 | spin_unlock_irqrestore(&priv->lock, flags); |
| 990 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
| 992 | /* set number of data bits, parity, stop bits */ |
| 993 | /* when parity is disabled the parity type bit is ignored */ |
| 994 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 995 | /* 1 means 2 stop bits, 0 means 1 stop bit */ |
| 996 | stop_bits = cflag & CSTOPB ? 1 : 0; |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | if (cflag & PARENB) { |
| 999 | parity_enable = 1; |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1000 | /* 1 means odd parity, 0 means even parity */ |
| 1001 | parity_type = cflag & PARODD ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | } else |
| 1003 | parity_enable = parity_type = 0; |
| 1004 | |
Alan Cox | 7733682 | 2008-07-22 11:10:53 +0100 | [diff] [blame] | 1005 | switch (cflag & CSIZE) { |
| 1006 | case CS5: |
| 1007 | data_bits = 0; |
| 1008 | break; |
| 1009 | case CS6: |
| 1010 | data_bits = 1; |
| 1011 | break; |
| 1012 | case CS7: |
| 1013 | data_bits = 2; |
| 1014 | break; |
| 1015 | case CS8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | data_bits = 3; |
Alan Cox | 7733682 | 2008-07-22 11:10:53 +0100 | [diff] [blame] | 1017 | break; |
| 1018 | default: |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 1019 | dev_err(&port->dev, "%s - CSIZE was set, but not CS5-CS8\n", |
| 1020 | __func__); |
Alan Cox | 7733682 | 2008-07-22 11:10:53 +0100 | [diff] [blame] | 1021 | data_bits = 3; |
| 1022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | spin_lock_irqsave(&priv->lock, flags); |
| 1024 | oldlines = priv->line_control; |
| 1025 | if ((cflag & CBAUD) == B0) { |
| 1026 | /* drop dtr and rts */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1027 | dbg("%s - dropping the lines, baud rate 0bps", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); |
Alan Cox | 8873aaa | 2008-03-10 21:59:28 +0000 | [diff] [blame] | 1029 | } else |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 1030 | priv->line_control = (CONTROL_DTR | CONTROL_RTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1033 | dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, " |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1034 | "%d data_bits (+5)", __func__, stop_bits, |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1035 | parity_enable, parity_type, data_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1037 | cypress_serial_control(tty, port, tty_get_baud_rate(tty), |
| 1038 | data_bits, stop_bits, |
| 1039 | parity_enable, parity_type, |
| 1040 | 0, CYPRESS_SET_CONFIG); |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1041 | |
| 1042 | /* we perform a CYPRESS_GET_CONFIG so that the current settings are |
| 1043 | * filled into the private structure this should confirm that all is |
| 1044 | * working if it returns what we just set */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1045 | cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1047 | /* Here we can define custom tty settings for devices; the main tty |
| 1048 | * termios flag base comes from empeg.c */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1050 | spin_lock_irqsave(&priv->lock, flags); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1051 | if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) { |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1052 | dbg("Using custom termios settings for a baud rate of " |
| 1053 | "4800bps."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | /* define custom termios settings for NMEA protocol */ |
| 1055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | tty->termios->c_iflag /* input modes - */ |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1057 | &= ~(IGNBRK /* disable ignore break */ |
| 1058 | | BRKINT /* disable break causes interrupt */ |
| 1059 | | PARMRK /* disable mark parity errors */ |
| 1060 | | ISTRIP /* disable clear high bit of input char */ |
| 1061 | | INLCR /* disable translate NL to CR */ |
| 1062 | | IGNCR /* disable ignore CR */ |
| 1063 | | ICRNL /* disable translate CR to NL */ |
| 1064 | | IXON); /* disable enable XON/XOFF flow control */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1066 | tty->termios->c_oflag /* output modes */ |
| 1067 | &= ~OPOST; /* disable postprocess output char */ |
| 1068 | |
| 1069 | tty->termios->c_lflag /* line discipline modes */ |
| 1070 | &= ~(ECHO /* disable echo input characters */ |
| 1071 | | ECHONL /* disable echo new line */ |
| 1072 | | ICANON /* disable erase, kill, werase, and rprnt |
| 1073 | special characters */ |
| 1074 | | ISIG /* disable interrupt, quit, and suspend |
| 1075 | special characters */ |
| 1076 | | IEXTEN); /* disable non-POSIX special characters */ |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 1077 | } /* CT_CYPHIDCOM: Application should handle this for device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | linechange = (priv->line_control != oldlines); |
| 1080 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1081 | |
| 1082 | /* if necessary, set lines */ |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 1083 | if (linechange) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | priv->cmd_ctrl = 1; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1085 | cypress_write(tty, port, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | } /* cypress_set_termios */ |
| 1088 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | /* returns amount of data still left in soft buffer */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1091 | static int cypress_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1093 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 1095 | int chars = 0; |
| 1096 | unsigned long flags; |
| 1097 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1098 | dbg("%s - port %d", __func__, port->number); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | spin_lock_irqsave(&priv->lock, flags); |
Johan Hovold | 117fb8d | 2010-05-16 20:33:50 +0200 | [diff] [blame] | 1101 | chars = kfifo_len(&priv->write_fifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1103 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1104 | dbg("%s - returns %d", __func__, chars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | return chars; |
| 1106 | } |
| 1107 | |
| 1108 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1109 | static void cypress_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1111 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | struct cypress_private *priv = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1114 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1116 | spin_lock_irq(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | priv->rx_flags = THROTTLED; |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1118 | spin_unlock_irq(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1122 | static void cypress_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1124 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 1126 | int actually_throttled, result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1128 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1130 | spin_lock_irq(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; |
| 1132 | priv->rx_flags = 0; |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1133 | spin_unlock_irq(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 1135 | if (!priv->comm_is_ok) |
| 1136 | return; |
| 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | if (actually_throttled) { |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1139 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 1140 | if (result) { |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1141 | dev_err(&port->dev, "%s - failed submitting read urb, " |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1142 | "error %d\n", __func__, result); |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 1143 | cypress_set_dead(port); |
| 1144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1149 | static void cypress_read_int_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1151 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 1153 | struct tty_struct *tty; |
| 1154 | unsigned char *data = urb->transfer_buffer; |
| 1155 | unsigned long flags; |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1156 | char tty_flag = TTY_NORMAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | int havedata = 0; |
| 1158 | int bytes = 0; |
| 1159 | int result; |
| 1160 | int i = 0; |
Greg Kroah-Hartman | 8d7bc55 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1161 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1163 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
Greg Kroah-Hartman | 8d7bc55 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1165 | switch (status) { |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 1166 | case 0: /* success */ |
| 1167 | break; |
| 1168 | case -ECONNRESET: |
| 1169 | case -ENOENT: |
| 1170 | case -ESHUTDOWN: |
| 1171 | /* precursor to disconnect so just go away */ |
| 1172 | return; |
| 1173 | case -EPIPE: |
Alan Stern | 4d2fae8 | 2009-07-09 12:59:57 -0400 | [diff] [blame] | 1174 | /* Can't call usb_clear_halt while in_interrupt */ |
| 1175 | /* FALLS THROUGH */ |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 1176 | default: |
| 1177 | /* something ugly is going on... */ |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1178 | dev_err(&urb->dev->dev, |
| 1179 | "%s - unexpected nonzero read status received: %d\n", |
| 1180 | __func__, status); |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 1181 | cypress_set_dead(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | spin_lock_irqsave(&priv->lock, flags); |
| 1186 | if (priv->rx_flags & THROTTLED) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1187 | dbg("%s - now throttling", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | priv->rx_flags |= ACTUALLY_THROTTLED; |
| 1189 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1190 | return; |
| 1191 | } |
| 1192 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1193 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1194 | tty = tty_port_tty_get(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | if (!tty) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1196 | dbg("%s - bad tty pointer - exiting", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | return; |
| 1198 | } |
| 1199 | |
| 1200 | spin_lock_irqsave(&priv->lock, flags); |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 1201 | result = urb->actual_length; |
| 1202 | switch (priv->pkt_fmt) { |
| 1203 | default: |
| 1204 | case packet_format_1: |
| 1205 | /* This is for the CY7C64013... */ |
| 1206 | priv->current_status = data[0] & 0xF8; |
| 1207 | bytes = data[1] + 2; |
| 1208 | i = 2; |
| 1209 | if (bytes > 2) |
| 1210 | havedata = 1; |
| 1211 | break; |
| 1212 | case packet_format_2: |
| 1213 | /* This is for the CY7C63743... */ |
| 1214 | priv->current_status = data[0] & 0xF8; |
| 1215 | bytes = (data[0] & 0x07) + 1; |
| 1216 | i = 1; |
| 1217 | if (bytes > 1) |
| 1218 | havedata = 1; |
| 1219 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | } |
| 1221 | spin_unlock_irqrestore(&priv->lock, flags); |
Mike Isely | 3416eaa | 2008-02-10 20:23:19 -0600 | [diff] [blame] | 1222 | if (result < bytes) { |
| 1223 | dbg("%s - wrong packet size - received %d bytes but packet " |
| 1224 | "said %d bytes", __func__, result, bytes); |
| 1225 | goto continue_read; |
| 1226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1228 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 1229 | urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
| 1231 | spin_lock_irqsave(&priv->lock, flags); |
| 1232 | /* check to see if status has changed */ |
Mike Isely | 6768306 | 2008-02-10 20:23:28 -0600 | [diff] [blame] | 1233 | if (priv->current_status != priv->prev_status) { |
| 1234 | priv->diff_status |= priv->current_status ^ |
| 1235 | priv->prev_status; |
| 1236 | wake_up_interruptible(&priv->delta_msr_wait); |
| 1237 | priv->prev_status = priv->current_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1239 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1241 | /* hangup, as defined in acm.c... this might be a bad place for it |
| 1242 | * though */ |
| 1243 | if (tty && !(tty->termios->c_cflag & CLOCAL) && |
| 1244 | !(priv->current_status & UART_CD)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1245 | dbg("%s - calling hangup", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | tty_hangup(tty); |
| 1247 | goto continue_read; |
| 1248 | } |
| 1249 | |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1250 | /* There is one error bit... I'm assuming it is a parity error |
| 1251 | * indicator as the generic firmware will set this bit to 1 if a |
| 1252 | * parity error occurs. |
| 1253 | * I can not find reference to any other error events. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | spin_lock_irqsave(&priv->lock, flags); |
| 1255 | if (priv->current_status & CYP_ERROR) { |
| 1256 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1257 | tty_flag = TTY_PARITY; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1258 | dbg("%s - Parity Error detected", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } else |
| 1260 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1261 | |
| 1262 | /* process read if there is data other than line status */ |
Alan Cox | a108bfc | 2010-02-18 16:44:01 +0000 | [diff] [blame] | 1263 | if (tty && bytes > i) { |
| 1264 | tty_insert_flip_string_fixed_flag(tty, data + i, |
Johan Hovold | 70ced22 | 2010-05-07 19:46:56 +0200 | [diff] [blame] | 1265 | tty_flag, bytes - i); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1266 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | spin_lock_irqsave(&priv->lock, flags); |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1270 | /* control and status byte(s) are also counted */ |
| 1271 | priv->bytes_in += bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1273 | |
| 1274 | continue_read: |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1275 | tty_kref_put(tty); |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1276 | |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 1277 | /* Continue trying to always read */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 1279 | if (priv->comm_is_ok) { |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1280 | usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, |
| 1281 | usb_rcvintpipe(port->serial->dev, |
| 1282 | port->interrupt_in_endpointAddress), |
| 1283 | port->interrupt_in_urb->transfer_buffer, |
| 1284 | port->interrupt_in_urb->transfer_buffer_length, |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1285 | cypress_read_int_callback, port, |
| 1286 | priv->read_urb_interval); |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1287 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 1288 | if (result && result != -EPERM) { |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1289 | dev_err(&urb->dev->dev, "%s - failed resubmitting " |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1290 | "read urb, error %d\n", __func__, |
Lonnie Mendez | b9db07f | 2005-07-12 17:21:31 -0500 | [diff] [blame] | 1291 | result); |
Mike Isely | 78aef51 | 2006-08-29 22:07:11 -0500 | [diff] [blame] | 1292 | cypress_set_dead(port); |
| 1293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | } /* cypress_read_int_callback */ |
| 1296 | |
| 1297 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1298 | static void cypress_write_int_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1300 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | struct cypress_private *priv = usb_get_serial_port_data(port); |
| 1302 | int result; |
Greg Kroah-Hartman | 8d7bc55 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1303 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1305 | dbg("%s - port %d", __func__, port->number); |
Greg Kroah-Hartman | 8d7bc55 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1306 | |
| 1307 | switch (status) { |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1308 | case 0: |
| 1309 | /* success */ |
| 1310 | break; |
| 1311 | case -ECONNRESET: |
| 1312 | case -ENOENT: |
| 1313 | case -ESHUTDOWN: |
| 1314 | /* this urb is terminated, clean up */ |
| 1315 | dbg("%s - urb shutting down with status: %d", |
| 1316 | __func__, status); |
| 1317 | priv->write_urb_in_use = 0; |
| 1318 | return; |
| 1319 | case -EPIPE: /* no break needed; clear halt and resubmit */ |
| 1320 | if (!priv->comm_is_ok) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | break; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1322 | usb_clear_halt(port->serial->dev, 0x02); |
| 1323 | /* error in the urb, so we have to resubmit it */ |
| 1324 | dbg("%s - nonzero write bulk status received: %d", |
| 1325 | __func__, status); |
| 1326 | port->interrupt_out_urb->transfer_buffer_length = 1; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1327 | result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); |
| 1328 | if (!result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | return; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1330 | dev_err(&urb->dev->dev, |
| 1331 | "%s - failed resubmitting write urb, error %d\n", |
| 1332 | __func__, result); |
| 1333 | cypress_set_dead(port); |
| 1334 | break; |
| 1335 | default: |
| 1336 | dev_err(&urb->dev->dev, |
| 1337 | "%s - unexpected nonzero write status received: %d\n", |
| 1338 | __func__, status); |
| 1339 | cypress_set_dead(port); |
| 1340 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | priv->write_urb_in_use = 0; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | /* send any buffered data */ |
| 1345 | cypress_send(port); |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | /***************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | * Module functions |
| 1351 | *****************************************************************************/ |
| 1352 | |
| 1353 | static int __init cypress_init(void) |
| 1354 | { |
| 1355 | int retval; |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1356 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1357 | dbg("%s", __func__); |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | retval = usb_serial_register(&cypress_earthmate_device); |
| 1360 | if (retval) |
| 1361 | goto failed_em_register; |
| 1362 | retval = usb_serial_register(&cypress_hidcom_device); |
| 1363 | if (retval) |
| 1364 | goto failed_hidcom_register; |
Lonnie Mendez | a5c44e2 | 2006-03-01 10:45:24 -0600 | [diff] [blame] | 1365 | retval = usb_serial_register(&cypress_ca42v2_device); |
| 1366 | if (retval) |
| 1367 | goto failed_ca42v2_register; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | retval = usb_register(&cypress_driver); |
| 1369 | if (retval) |
| 1370 | goto failed_usb_register; |
| 1371 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 1372 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 1373 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
Mariusz Kozlowski | 2e46b74 | 2006-11-17 17:49:22 +0100 | [diff] [blame] | 1376 | failed_usb_register: |
| 1377 | usb_serial_deregister(&cypress_ca42v2_device); |
| 1378 | failed_ca42v2_register: |
| 1379 | usb_serial_deregister(&cypress_hidcom_device); |
| 1380 | failed_hidcom_register: |
| 1381 | usb_serial_deregister(&cypress_earthmate_device); |
| 1382 | failed_em_register: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | return retval; |
| 1384 | } |
| 1385 | |
| 1386 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1387 | static void __exit cypress_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1389 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1391 | usb_deregister(&cypress_driver); |
| 1392 | usb_serial_deregister(&cypress_earthmate_device); |
| 1393 | usb_serial_deregister(&cypress_hidcom_device); |
| 1394 | usb_serial_deregister(&cypress_ca42v2_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | module_init(cypress_init); |
| 1399 | module_exit(cypress_exit); |
| 1400 | |
Alan Cox | 813a224 | 2008-07-22 11:10:36 +0100 | [diff] [blame] | 1401 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1402 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1403 | MODULE_VERSION(DRIVER_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | MODULE_LICENSE("GPL"); |
| 1405 | |
| 1406 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 1407 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |
| 1408 | module_param(stats, bool, S_IRUGO | S_IWUSR); |
| 1409 | MODULE_PARM_DESC(stats, "Enable statistics or not"); |
Lonnie Mendez | 3cb4a4f | 2005-05-03 17:02:20 -0500 | [diff] [blame] | 1410 | module_param(interval, int, S_IRUGO | S_IWUSR); |
| 1411 | MODULE_PARM_DESC(interval, "Overrides interrupt interval"); |
Mike Frysinger | c312659 | 2009-12-18 16:33:03 -0500 | [diff] [blame] | 1412 | module_param(unstable_bauds, bool, S_IRUGO | S_IWUSR); |
| 1413 | MODULE_PARM_DESC(unstable_bauds, "Allow unstable baud rates"); |