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