| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | Keyspan USB to Serial Converter driver | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 3 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | (C) Copyright (C) 2000-2001	Hugh Blemings <hugh@blemings.org> | 
|  | 5 | (C) Copyright (C) 2002	Greg Kroah-Hartman <greg@kroah.com> | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 6 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | This program is free software; you can redistribute it and/or modify | 
|  | 8 | it under the terms of the GNU General Public License as published by | 
|  | 9 | the Free Software Foundation; either version 2 of the License, or | 
|  | 10 | (at your option) any later version. | 
|  | 11 |  | 
|  | 12 | See http://misc.nu/hugh/keyspan.html for more information. | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 13 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | Code in this driver inspired by and in a number of places taken | 
|  | 15 | from Brian Warner's original Keyspan-PDA driver. | 
|  | 16 |  | 
|  | 17 | This driver has been put together with the support of Innosys, Inc. | 
|  | 18 | and Keyspan, Inc the manufacturers of the Keyspan USB-serial products. | 
|  | 19 | Thanks Guys :) | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 20 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | Thanks to Paulus for miscellaneous tidy ups, some largish chunks | 
|  | 22 | of much nicer and/or completely new code and (perhaps most uniquely) | 
|  | 23 | having the patience to sit down and explain why and where he'd changed | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 24 | stuff. | 
|  | 25 |  | 
|  | 26 | Tip 'o the hat to IBM (and previously Linuxcare :) for supporting | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | staff in their work on open source projects. | 
|  | 28 |  | 
|  | 29 | Change History | 
|  | 30 |  | 
|  | 31 | 2003sep04	LPM (Keyspan) add support for new single port product USA19HS. | 
|  | 32 | Improve setup message handling for all devices. | 
|  | 33 |  | 
|  | 34 | Wed Feb 19 22:00:00 PST 2003 (Jeffrey S. Laing <keyspan@jsl.com>) | 
|  | 35 | Merged the current (1/31/03) Keyspan code with the current (2.4.21-pre4) | 
|  | 36 | Linux source tree.  The Linux tree lacked support for the 49WLC and | 
|  | 37 | others.  The Keyspan patches didn't work with the current kernel. | 
|  | 38 |  | 
|  | 39 | 2003jan30	LPM	add support for the 49WLC and MPR | 
|  | 40 |  | 
|  | 41 | Wed Apr 25 12:00:00 PST 2002 (Keyspan) | 
|  | 42 | Started with Hugh Blemings' code dated Jan 17, 2002.  All adapters | 
|  | 43 | now supported (including QI and QW).  Modified port open, port | 
|  | 44 | close, and send setup() logic to fix various data and endpoint | 
|  | 45 | synchronization bugs and device LED status bugs.  Changed keyspan_ | 
|  | 46 | write_room() to accurately return transmit buffer availability. | 
|  | 47 | Changed forwardingLength from 1 to 16 for all adapters. | 
|  | 48 |  | 
|  | 49 | Fri Oct 12 16:45:00 EST 2001 | 
|  | 50 | Preliminary USA-19QI and USA-28 support (both test OK for me, YMMV) | 
|  | 51 |  | 
|  | 52 | Wed Apr 25 12:00:00 PST 2002 (Keyspan) | 
|  | 53 | Started with Hugh Blemings' code dated Jan 17, 2002.  All adapters | 
|  | 54 | now supported (including QI and QW).  Modified port open, port | 
|  | 55 | close, and send setup() logic to fix various data and endpoint | 
|  | 56 | synchronization bugs and device LED status bugs.  Changed keyspan_ | 
|  | 57 | write_room() to accurately return transmit buffer availability. | 
|  | 58 | Changed forwardingLength from 1 to 16 for all adapters. | 
|  | 59 |  | 
|  | 60 | Fri Oct 12 16:45:00 EST 2001 | 
|  | 61 | Preliminary USA-19QI and USA-28 support (both test OK for me, YMMV) | 
|  | 62 |  | 
|  | 63 | Mon Oct  8 14:29:00 EST 2001 hugh | 
|  | 64 | Fixed bug that prevented mulitport devices operating correctly | 
|  | 65 | if they weren't the first unit attached. | 
|  | 66 |  | 
|  | 67 | Sat Oct  6 12:31:21 EST 2001 hugh | 
|  | 68 | Added support for USA-28XA and -28XB, misc cleanups, break support | 
|  | 69 | for usa26 based models thanks to David Gibson. | 
|  | 70 |  | 
|  | 71 | Thu May 31 11:56:42 PDT 2001 gkh | 
|  | 72 | switched from using spinlock to a semaphore | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 73 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | (04/08/2001) gb | 
|  | 75 | Identify version on module load. | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 76 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | (11/01/2000) Adam J. Richter | 
|  | 78 | usb_device_id table support. | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 79 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | Tue Oct 10 23:15:33 EST 2000 Hugh | 
|  | 81 | Merged Paul's changes with my USA-49W mods.  Work in progress | 
|  | 82 | still... | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 83 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | Wed Jul 19 14:00:42 EST 2000 gkh | 
|  | 85 | Added module_init and module_exit functions to handle the fact that | 
|  | 86 | this driver is a loadable module now. | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 87 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | Tue Jul 18 16:14:52 EST 2000 Hugh | 
|  | 89 | Basic character input/output for USA-19 now mostly works, | 
|  | 90 | fixed at 9600 baud for the moment. | 
|  | 91 |  | 
|  | 92 | Sat Jul  8 11:11:48 EST 2000 Hugh | 
|  | 93 | First public release - nothing works except the firmware upload. | 
|  | 94 | Tested on PPC and x86 architectures, seems to behave... | 
|  | 95 | */ | 
|  | 96 |  | 
|  | 97 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #include <linux/kernel.h> | 
|  | 99 | #include <linux/jiffies.h> | 
|  | 100 | #include <linux/errno.h> | 
|  | 101 | #include <linux/init.h> | 
|  | 102 | #include <linux/slab.h> | 
|  | 103 | #include <linux/tty.h> | 
|  | 104 | #include <linux/tty_driver.h> | 
|  | 105 | #include <linux/tty_flip.h> | 
|  | 106 | #include <linux/module.h> | 
|  | 107 | #include <linux/spinlock.h> | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 108 | #include <linux/firmware.h> | 
|  | 109 | #include <linux/ihex.h> | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 110 | #include <linux/uaccess.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | #include <linux/usb.h> | 
| Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 112 | #include <linux/usb/serial.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #include "keyspan.h" | 
|  | 114 |  | 
|  | 115 | static int debug; | 
|  | 116 |  | 
|  | 117 | /* | 
|  | 118 | * Version Information | 
|  | 119 | */ | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 120 | #define DRIVER_VERSION "v1.1.5" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu" | 
|  | 122 | #define DRIVER_DESC "Keyspan USB to Serial Converter Driver" | 
|  | 123 |  | 
|  | 124 | #define INSTAT_BUFLEN	32 | 
|  | 125 | #define GLOCONT_BUFLEN	64 | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 126 | #define INDAT49W_BUFLEN	512 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 |  | 
|  | 128 | /* Per device and per port private data */ | 
|  | 129 | struct keyspan_serial_private { | 
|  | 130 | const struct keyspan_device_details	*device_details; | 
|  | 131 |  | 
|  | 132 | struct urb	*instat_urb; | 
|  | 133 | char		instat_buf[INSTAT_BUFLEN]; | 
|  | 134 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 135 | /* added to support 49wg, where data from all 4 ports comes in | 
|  | 136 | on 1 EP and high-speed supported */ | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 137 | struct urb	*indat_urb; | 
|  | 138 | char		indat_buf[INDAT49W_BUFLEN]; | 
|  | 139 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* XXX this one probably will need a lock */ | 
|  | 141 | struct urb	*glocont_urb; | 
|  | 142 | char		glocont_buf[GLOCONT_BUFLEN]; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 143 | char		ctrl_buf[8];	/* for EP0 control message */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; | 
|  | 145 |  | 
|  | 146 | struct keyspan_port_private { | 
|  | 147 | /* Keep track of which input & output endpoints to use */ | 
|  | 148 | int		in_flip; | 
|  | 149 | int		out_flip; | 
|  | 150 |  | 
|  | 151 | /* Keep duplicate of device details in each port | 
|  | 152 | structure as well - simplifies some of the | 
|  | 153 | callback functions etc. */ | 
|  | 154 | const struct keyspan_device_details	*device_details; | 
|  | 155 |  | 
|  | 156 | /* Input endpoints and buffer for this port */ | 
|  | 157 | struct urb	*in_urbs[2]; | 
|  | 158 | char		in_buffer[2][64]; | 
|  | 159 | /* Output endpoints and buffer for this port */ | 
|  | 160 | struct urb	*out_urbs[2]; | 
|  | 161 | char		out_buffer[2][64]; | 
|  | 162 |  | 
|  | 163 | /* Input ack endpoint */ | 
|  | 164 | struct urb	*inack_urb; | 
|  | 165 | char		inack_buffer[1]; | 
|  | 166 |  | 
|  | 167 | /* Output control endpoint */ | 
|  | 168 | struct urb	*outcont_urb; | 
|  | 169 | char		outcont_buffer[64]; | 
|  | 170 |  | 
|  | 171 | /* Settings for the port */ | 
|  | 172 | int		baud; | 
|  | 173 | int		old_baud; | 
|  | 174 | unsigned int	cflag; | 
|  | 175 | unsigned int	old_cflag; | 
|  | 176 | enum		{flow_none, flow_cts, flow_xon} flow_control; | 
|  | 177 | int		rts_state;	/* Handshaking pins (outputs) */ | 
|  | 178 | int		dtr_state; | 
|  | 179 | int		cts_state;	/* Handshaking pins (inputs) */ | 
|  | 180 | int		dsr_state; | 
|  | 181 | int		dcd_state; | 
|  | 182 | int		ri_state; | 
|  | 183 | int		break_on; | 
|  | 184 |  | 
|  | 185 | unsigned long	tx_start_time[2]; | 
|  | 186 | int		resend_cont;	/* need to resend control packet */ | 
|  | 187 | }; | 
|  | 188 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* Include Keyspan message headers.  All current Keyspan Adapters | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 190 | make use of one of five message formats which are referred | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 191 | to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and | 
|  | 192 | within this driver. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | #include "keyspan_usa26msg.h" | 
|  | 194 | #include "keyspan_usa28msg.h" | 
|  | 195 | #include "keyspan_usa49msg.h" | 
|  | 196 | #include "keyspan_usa90msg.h" | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 197 | #include "keyspan_usa67msg.h" | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 198 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
|  | 200 | /* Functions used by new usb-serial code. */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 201 | static int __init keyspan_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { | 
|  | 203 | int retval; | 
|  | 204 | retval = usb_serial_register(&keyspan_pre_device); | 
|  | 205 | if (retval) | 
|  | 206 | goto failed_pre_device_register; | 
|  | 207 | retval = usb_serial_register(&keyspan_1port_device); | 
|  | 208 | if (retval) | 
|  | 209 | goto failed_1port_device_register; | 
|  | 210 | retval = usb_serial_register(&keyspan_2port_device); | 
|  | 211 | if (retval) | 
|  | 212 | goto failed_2port_device_register; | 
|  | 213 | retval = usb_serial_register(&keyspan_4port_device); | 
|  | 214 | if (retval) | 
|  | 215 | goto failed_4port_device_register; | 
|  | 216 | retval = usb_register(&keyspan_driver); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 217 | if (retval) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | goto failed_usb_register; | 
|  | 219 |  | 
|  | 220 | info(DRIVER_VERSION ":" DRIVER_DESC); | 
|  | 221 |  | 
|  | 222 | return 0; | 
|  | 223 | failed_usb_register: | 
|  | 224 | usb_serial_deregister(&keyspan_4port_device); | 
|  | 225 | failed_4port_device_register: | 
|  | 226 | usb_serial_deregister(&keyspan_2port_device); | 
|  | 227 | failed_2port_device_register: | 
|  | 228 | usb_serial_deregister(&keyspan_1port_device); | 
|  | 229 | failed_1port_device_register: | 
|  | 230 | usb_serial_deregister(&keyspan_pre_device); | 
|  | 231 | failed_pre_device_register: | 
|  | 232 | return retval; | 
|  | 233 | } | 
|  | 234 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 235 | static void __exit keyspan_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 237 | usb_deregister(&keyspan_driver); | 
|  | 238 | usb_serial_deregister(&keyspan_pre_device); | 
|  | 239 | usb_serial_deregister(&keyspan_1port_device); | 
|  | 240 | usb_serial_deregister(&keyspan_2port_device); | 
|  | 241 | usb_serial_deregister(&keyspan_4port_device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
|  | 244 | module_init(keyspan_init); | 
|  | 245 | module_exit(keyspan_exit); | 
|  | 246 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 247 | static void keyspan_break_ctl(struct tty_struct *tty, int break_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 249 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | struct keyspan_port_private 	*p_priv; | 
|  | 251 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 252 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 |  | 
|  | 254 | p_priv = usb_get_serial_port_data(port); | 
|  | 255 |  | 
|  | 256 | if (break_state == -1) | 
|  | 257 | p_priv->break_on = 1; | 
|  | 258 | else | 
|  | 259 | p_priv->break_on = 0; | 
|  | 260 |  | 
|  | 261 | keyspan_send_setup(port, 0); | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 265 | static void keyspan_set_termios(struct tty_struct *tty, | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 266 | struct usb_serial_port *port, struct ktermios *old_termios) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { | 
|  | 268 | int				baud_rate, device_port; | 
|  | 269 | struct keyspan_port_private 	*p_priv; | 
|  | 270 | const struct keyspan_device_details	*d_details; | 
|  | 271 | unsigned int 			cflag; | 
|  | 272 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 273 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 |  | 
|  | 275 | p_priv = usb_get_serial_port_data(port); | 
|  | 276 | d_details = p_priv->device_details; | 
| Alan Cox | 74240b0 | 2007-10-18 01:24:20 -0700 | [diff] [blame] | 277 | cflag = tty->termios->c_cflag; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | device_port = port->number - port->serial->minor; | 
|  | 279 |  | 
|  | 280 | /* Baud rate calculation takes baud rate as an integer | 
|  | 281 | so other rates can be generated if desired. */ | 
| Alan Cox | 74240b0 | 2007-10-18 01:24:20 -0700 | [diff] [blame] | 282 | baud_rate = tty_get_baud_rate(tty); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 283 | /* If no match or invalid, don't change */ | 
| Alan Cox | 74240b0 | 2007-10-18 01:24:20 -0700 | [diff] [blame] | 284 | if (d_details->calculate_baud_rate(baud_rate, d_details->baudclk, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { | 
|  | 286 | /* FIXME - more to do here to ensure rate changes cleanly */ | 
| Alan Cox | 74240b0 | 2007-10-18 01:24:20 -0700 | [diff] [blame] | 287 | /* FIXME - calcuate exact rate from divisor ? */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | p_priv->baud = baud_rate; | 
| Alan Cox | 74240b0 | 2007-10-18 01:24:20 -0700 | [diff] [blame] | 289 | } else | 
|  | 290 | baud_rate = tty_termios_baud_rate(old_termios); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 |  | 
| Alan Cox | 74240b0 | 2007-10-18 01:24:20 -0700 | [diff] [blame] | 292 | tty_encode_baud_rate(tty, baud_rate, baud_rate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | /* set CTS/RTS handshake etc. */ | 
|  | 294 | p_priv->cflag = cflag; | 
|  | 295 | p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none; | 
|  | 296 |  | 
| Alan Cox | 74240b0 | 2007-10-18 01:24:20 -0700 | [diff] [blame] | 297 | /* Mark/Space not supported */ | 
|  | 298 | tty->termios->c_cflag &= ~CMSPAR; | 
|  | 299 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | keyspan_send_setup(port, 0); | 
|  | 301 | } | 
|  | 302 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 303 | static int keyspan_tiocmget(struct tty_struct *tty, struct file *file) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 305 | struct usb_serial_port *port = tty->driver_data; | 
|  | 306 | struct keyspan_port_private *p_priv = usb_get_serial_port_data(port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | unsigned int			value; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 308 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | value = ((p_priv->rts_state) ? TIOCM_RTS : 0) | | 
|  | 310 | ((p_priv->dtr_state) ? TIOCM_DTR : 0) | | 
|  | 311 | ((p_priv->cts_state) ? TIOCM_CTS : 0) | | 
|  | 312 | ((p_priv->dsr_state) ? TIOCM_DSR : 0) | | 
|  | 313 | ((p_priv->dcd_state) ? TIOCM_CAR : 0) | | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 314 | ((p_priv->ri_state) ? TIOCM_RNG : 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 |  | 
|  | 316 | return value; | 
|  | 317 | } | 
|  | 318 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 319 | static int keyspan_tiocmset(struct tty_struct *tty, struct file *file, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | unsigned int set, unsigned int clear) | 
|  | 321 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 322 | struct usb_serial_port *port = tty->driver_data; | 
|  | 323 | struct keyspan_port_private *p_priv = usb_get_serial_port_data(port); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 324 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | if (set & TIOCM_RTS) | 
|  | 326 | p_priv->rts_state = 1; | 
|  | 327 | if (set & TIOCM_DTR) | 
|  | 328 | p_priv->dtr_state = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | if (clear & TIOCM_RTS) | 
|  | 330 | p_priv->rts_state = 0; | 
|  | 331 | if (clear & TIOCM_DTR) | 
|  | 332 | p_priv->dtr_state = 0; | 
|  | 333 | keyspan_send_setup(port, 0); | 
|  | 334 | return 0; | 
|  | 335 | } | 
|  | 336 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 337 | /* Write function is similar for the four protocols used | 
|  | 338 | with only a minor change for usa90 (usa19hs) required */ | 
|  | 339 | static int keyspan_write(struct tty_struct *tty, | 
|  | 340 | struct usb_serial_port *port, const unsigned char *buf, int count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { | 
|  | 342 | struct keyspan_port_private 	*p_priv; | 
|  | 343 | const struct keyspan_device_details	*d_details; | 
|  | 344 | int				flip; | 
|  | 345 | int 				left, todo; | 
|  | 346 | struct urb			*this_urb; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 347 | int 				err, maxDataLen, dataOffset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 |  | 
|  | 349 | p_priv = usb_get_serial_port_data(port); | 
|  | 350 | d_details = p_priv->device_details; | 
|  | 351 |  | 
|  | 352 | if (d_details->msg_format == msg_usa90) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 353 | maxDataLen = 64; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | dataOffset = 0; | 
|  | 355 | } else { | 
|  | 356 | maxDataLen = 63; | 
|  | 357 | dataOffset = 1; | 
|  | 358 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 359 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | dbg("%s - for port %d (%d chars), flip=%d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 361 | __func__, port->number, count, p_priv->out_flip); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 |  | 
|  | 363 | for (left = count; left > 0; left -= todo) { | 
|  | 364 | todo = left; | 
|  | 365 | if (todo > maxDataLen) | 
|  | 366 | todo = maxDataLen; | 
|  | 367 |  | 
|  | 368 | flip = p_priv->out_flip; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 369 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | /* Check we have a valid urb/endpoint before we use it... */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 371 | this_urb = p_priv->out_urbs[flip]; | 
|  | 372 | if (this_urb == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | /* no bulk out, so return 0 bytes written */ | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 374 | dbg("%s - no output urb :(", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return count; | 
|  | 376 | } | 
|  | 377 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 378 | dbg("%s - endpoint %d flip %d", | 
|  | 379 | __func__, usb_pipeendpoint(this_urb->pipe), flip); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 |  | 
|  | 381 | if (this_urb->status == -EINPROGRESS) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 382 | if (time_before(jiffies, | 
|  | 383 | p_priv->tx_start_time[flip] + 10 * HZ)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | usb_unlink_urb(this_urb); | 
|  | 386 | break; | 
|  | 387 | } | 
|  | 388 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 389 | /* First byte in buffer is "last flag" (except for usa19hx) | 
|  | 390 | - unused so for now so set to zero */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | ((char *)this_urb->transfer_buffer)[0] = 0; | 
|  | 392 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 393 | memcpy(this_urb->transfer_buffer + dataOffset, buf, todo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | buf += todo; | 
|  | 395 |  | 
|  | 396 | /* send the data out the bulk port */ | 
|  | 397 | this_urb->transfer_buffer_length = todo + dataOffset; | 
|  | 398 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | this_urb->dev = port->serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 400 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 
|  | 401 | if (err != 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | dbg("usb_submit_urb(write bulk) failed (%d)", err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | p_priv->tx_start_time[flip] = jiffies; | 
|  | 404 |  | 
|  | 405 | /* Flip for next time if usa26 or usa28 interface | 
|  | 406 | (not used on usa49) */ | 
|  | 407 | p_priv->out_flip = (flip + 1) & d_details->outdat_endp_flip; | 
|  | 408 | } | 
|  | 409 |  | 
|  | 410 | return count - left; | 
|  | 411 | } | 
|  | 412 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 413 | static void	usa26_indat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { | 
|  | 415 | int			i, err; | 
|  | 416 | int			endpoint; | 
|  | 417 | struct usb_serial_port	*port; | 
|  | 418 | struct tty_struct	*tty; | 
|  | 419 | unsigned char 		*data = urb->transfer_buffer; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 420 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 422 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 |  | 
|  | 424 | endpoint = usb_pipeendpoint(urb->pipe); | 
|  | 425 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 426 | if (status) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | dbg("%s - nonzero status: %x on endpoint %d.", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 428 | __func__, status, endpoint); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return; | 
|  | 430 | } | 
|  | 431 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 432 | port =  urb->context; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 433 | tty = tty_port_tty_get(&port->port); | 
| Alan Cox | a5569a5 | 2008-01-21 17:18:24 -0800 | [diff] [blame] | 434 | if (tty && urb->actual_length) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | /* 0x80 bit is error flag */ | 
|  | 436 | if ((data[0] & 0x80) == 0) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 437 | /* no errors on individual bytes, only | 
|  | 438 | possible overrun err */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | if (data[0] & RXERROR_OVERRUN) | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 440 | err = TTY_OVERRUN; | 
|  | 441 | else | 
|  | 442 | err = 0; | 
|  | 443 | for (i = 1; i < urb->actual_length ; ++i) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | tty_insert_flip_char(tty, data[i], err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } else { | 
|  | 446 | /* some bytes had errors, every byte has status */ | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 447 | dbg("%s - RX error!!!!", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | for (i = 0; i + 1 < urb->actual_length; i += 2) { | 
|  | 449 | int stat = data[i], flag = 0; | 
|  | 450 | if (stat & RXERROR_OVERRUN) | 
|  | 451 | flag |= TTY_OVERRUN; | 
|  | 452 | if (stat & RXERROR_FRAMING) | 
|  | 453 | flag |= TTY_FRAME; | 
|  | 454 | if (stat & RXERROR_PARITY) | 
|  | 455 | flag |= TTY_PARITY; | 
|  | 456 | /* XXX should handle break (0x10) */ | 
|  | 457 | tty_insert_flip_char(tty, data[i+1], flag); | 
|  | 458 | } | 
|  | 459 | } | 
|  | 460 | tty_flip_buffer_push(tty); | 
|  | 461 | } | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 462 | tty_kref_put(tty); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 463 |  | 
|  | 464 | /* Resubmit urb so we continue receiving */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | urb->dev = port->serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 466 | if (port->port.count) { | 
|  | 467 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 468 | if (err != 0) | 
|  | 469 | dbg("%s - resubmit read urb failed. (%d)", | 
|  | 470 | __func__, err); | 
|  | 471 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return; | 
|  | 473 | } | 
|  | 474 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 475 | /* Outdat handling is common for all devices */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 476 | static void	usa2x_outdat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | { | 
|  | 478 | struct usb_serial_port *port; | 
|  | 479 | struct keyspan_port_private *p_priv; | 
|  | 480 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 481 | port =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | p_priv = usb_get_serial_port_data(port); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 483 | dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 485 | if (port->port.count) | 
| Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 486 | usb_serial_port_softint(port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } | 
|  | 488 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 489 | static void	usa26_inack_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 491 | dbg("%s", __func__); | 
|  | 492 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } | 
|  | 494 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 495 | static void	usa26_outcont_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { | 
|  | 497 | struct usb_serial_port *port; | 
|  | 498 | struct keyspan_port_private *p_priv; | 
|  | 499 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 500 | port =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | p_priv = usb_get_serial_port_data(port); | 
|  | 502 |  | 
|  | 503 | if (p_priv->resend_cont) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 504 | dbg("%s - sending setup", __func__); | 
|  | 505 | keyspan_usa26_send_setup(port->serial, port, | 
|  | 506 | p_priv->resend_cont - 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } | 
|  | 508 | } | 
|  | 509 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 510 | static void	usa26_instat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { | 
|  | 512 | unsigned char 				*data = urb->transfer_buffer; | 
|  | 513 | struct keyspan_usa26_portStatusMessage	*msg; | 
|  | 514 | struct usb_serial			*serial; | 
|  | 515 | struct usb_serial_port			*port; | 
|  | 516 | struct keyspan_port_private	 	*p_priv; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 517 | struct tty_struct			*tty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | int old_dcd_state, err; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 519 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 521 | serial =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 523 | if (status) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 524 | dbg("%s - nonzero status: %x", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return; | 
|  | 526 | } | 
|  | 527 | if (urb->actual_length != 9) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 528 | dbg("%s - %d byte report??", __func__, urb->actual_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | goto exit; | 
|  | 530 | } | 
|  | 531 |  | 
|  | 532 | msg = (struct keyspan_usa26_portStatusMessage *)data; | 
|  | 533 |  | 
|  | 534 | #if 0 | 
|  | 535 | dbg("%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 536 | __func__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr, msg->ri, msg->_txOff, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | msg->_txXoff, msg->rxEnabled, msg->controlResponse); | 
|  | 538 | #endif | 
|  | 539 |  | 
|  | 540 | /* Now do something useful with the data */ | 
|  | 541 |  | 
|  | 542 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 543 | /* Check port number from message and retrieve private data */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | if (msg->port >= serial->num_ports) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 545 | dbg("%s - Unexpected port number %d", __func__, msg->port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | goto exit; | 
|  | 547 | } | 
|  | 548 | port = serial->port[msg->port]; | 
|  | 549 | p_priv = usb_get_serial_port_data(port); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 550 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /* Update handshaking pin state information */ | 
|  | 552 | old_dcd_state = p_priv->dcd_state; | 
|  | 553 | p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0); | 
|  | 554 | p_priv->dsr_state = ((msg->dsr) ? 1 : 0); | 
|  | 555 | p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); | 
|  | 556 | p_priv->ri_state = ((msg->ri) ? 1 : 0); | 
|  | 557 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 558 | if (old_dcd_state != p_priv->dcd_state) { | 
|  | 559 | tty = tty_port_tty_get(&port->port); | 
|  | 560 | if (tty && !C_CLOCAL(tty)) | 
|  | 561 | tty_hangup(tty); | 
|  | 562 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 564 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | /* Resubmit urb so we continue receiving */ | 
|  | 566 | urb->dev = serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 567 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 568 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 569 | dbg("%s - resubmit read urb failed. (%d)", __func__, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | exit: ; | 
|  | 571 | } | 
|  | 572 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 573 | static void	usa26_glocont_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 575 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } | 
|  | 577 |  | 
|  | 578 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 579 | static void usa28_indat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { | 
| Alan Cox | f035a8a | 2008-07-22 11:13:32 +0100 | [diff] [blame] | 581 | int                     err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | struct usb_serial_port  *port; | 
|  | 583 | struct tty_struct       *tty; | 
|  | 584 | unsigned char           *data; | 
|  | 585 | struct keyspan_port_private             *p_priv; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 586 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 588 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 590 | port =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | p_priv = usb_get_serial_port_data(port); | 
|  | 592 | data = urb->transfer_buffer; | 
|  | 593 |  | 
|  | 594 | if (urb != p_priv->in_urbs[p_priv->in_flip]) | 
|  | 595 | return; | 
|  | 596 |  | 
|  | 597 | do { | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 598 | if (status) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | dbg("%s - nonzero status: %x on endpoint %d.", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 600 | __func__, status, usb_pipeendpoint(urb->pipe)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return; | 
|  | 602 | } | 
|  | 603 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 604 | port =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | p_priv = usb_get_serial_port_data(port); | 
|  | 606 | data = urb->transfer_buffer; | 
|  | 607 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 608 | tty =tty_port_tty_get(&port->port); | 
|  | 609 | if (tty && urb->actual_length) { | 
| Alan Cox | f035a8a | 2008-07-22 11:13:32 +0100 | [diff] [blame] | 610 | tty_insert_flip_string(tty, data, urb->actual_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | tty_flip_buffer_push(tty); | 
|  | 612 | } | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 613 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 |  | 
|  | 615 | /* Resubmit urb so we continue receiving */ | 
|  | 616 | urb->dev = port->serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 617 | if (port->port.count) { | 
|  | 618 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 619 | if (err != 0) | 
|  | 620 | dbg("%s - resubmit read urb failed. (%d)", | 
|  | 621 | __func__, err); | 
|  | 622 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | p_priv->in_flip ^= 1; | 
|  | 624 |  | 
|  | 625 | urb = p_priv->in_urbs[p_priv->in_flip]; | 
|  | 626 | } while (urb->status != -EINPROGRESS); | 
|  | 627 | } | 
|  | 628 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 629 | static void	usa28_inack_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 631 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } | 
|  | 633 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 634 | static void	usa28_outcont_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { | 
|  | 636 | struct usb_serial_port *port; | 
|  | 637 | struct keyspan_port_private *p_priv; | 
|  | 638 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 639 | port =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | p_priv = usb_get_serial_port_data(port); | 
|  | 641 |  | 
|  | 642 | if (p_priv->resend_cont) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 643 | dbg("%s - sending setup", __func__); | 
|  | 644 | keyspan_usa28_send_setup(port->serial, port, | 
|  | 645 | p_priv->resend_cont - 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } | 
|  | 647 | } | 
|  | 648 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 649 | static void	usa28_instat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { | 
|  | 651 | int					err; | 
|  | 652 | unsigned char 				*data = urb->transfer_buffer; | 
|  | 653 | struct keyspan_usa28_portStatusMessage	*msg; | 
|  | 654 | struct usb_serial			*serial; | 
|  | 655 | struct usb_serial_port			*port; | 
|  | 656 | struct keyspan_port_private	 	*p_priv; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 657 | struct tty_struct			*tty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | int old_dcd_state; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 659 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 661 | serial =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 663 | if (status) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 664 | dbg("%s - nonzero status: %x", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | return; | 
|  | 666 | } | 
|  | 667 |  | 
|  | 668 | if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 669 | dbg("%s - bad length %d", __func__, urb->actual_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | goto exit; | 
|  | 671 | } | 
|  | 672 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 673 | /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | data[0], data[1], data[2], data[3], data[4], data[5], | 
|  | 675 | data[6], data[7], data[8], data[9], data[10], data[11]);*/ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 676 |  | 
|  | 677 | /* Now do something useful with the data */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | msg = (struct keyspan_usa28_portStatusMessage *)data; | 
|  | 679 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 680 | /* Check port number from message and retrieve private data */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | if (msg->port >= serial->num_ports) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 682 | dbg("%s - Unexpected port number %d", __func__, msg->port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | goto exit; | 
|  | 684 | } | 
|  | 685 | port = serial->port[msg->port]; | 
|  | 686 | p_priv = usb_get_serial_port_data(port); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 687 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | /* Update handshaking pin state information */ | 
|  | 689 | old_dcd_state = p_priv->dcd_state; | 
|  | 690 | p_priv->cts_state = ((msg->cts) ? 1 : 0); | 
|  | 691 | p_priv->dsr_state = ((msg->dsr) ? 1 : 0); | 
|  | 692 | p_priv->dcd_state = ((msg->dcd) ? 1 : 0); | 
|  | 693 | p_priv->ri_state = ((msg->ri) ? 1 : 0); | 
|  | 694 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 695 | if( old_dcd_state != p_priv->dcd_state && old_dcd_state) { | 
|  | 696 | tty = tty_port_tty_get(&port->port); | 
|  | 697 | if (tty && !C_CLOCAL(tty)) | 
|  | 698 | tty_hangup(tty); | 
|  | 699 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } | 
|  | 701 |  | 
|  | 702 | /* Resubmit urb so we continue receiving */ | 
|  | 703 | urb->dev = serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 704 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 705 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 706 | dbg("%s - resubmit read urb failed. (%d)", __func__, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | exit: ; | 
|  | 708 | } | 
|  | 709 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 710 | static void	usa28_glocont_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 712 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } | 
|  | 714 |  | 
|  | 715 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 716 | static void	usa49_glocont_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | { | 
|  | 718 | struct usb_serial *serial; | 
|  | 719 | struct usb_serial_port *port; | 
|  | 720 | struct keyspan_port_private *p_priv; | 
|  | 721 | int i; | 
|  | 722 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 723 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 725 | serial =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | for (i = 0; i < serial->num_ports; ++i) { | 
|  | 727 | port = serial->port[i]; | 
|  | 728 | p_priv = usb_get_serial_port_data(port); | 
|  | 729 |  | 
|  | 730 | if (p_priv->resend_cont) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 731 | dbg("%s - sending setup", __func__); | 
|  | 732 | keyspan_usa49_send_setup(serial, port, | 
|  | 733 | p_priv->resend_cont - 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | break; | 
|  | 735 | } | 
|  | 736 | } | 
|  | 737 | } | 
|  | 738 |  | 
|  | 739 | /* This is actually called glostat in the Keyspan | 
|  | 740 | doco */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 741 | static void	usa49_instat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { | 
|  | 743 | int					err; | 
|  | 744 | unsigned char 				*data = urb->transfer_buffer; | 
|  | 745 | struct keyspan_usa49_portStatusMessage	*msg; | 
|  | 746 | struct usb_serial			*serial; | 
|  | 747 | struct usb_serial_port			*port; | 
|  | 748 | struct keyspan_port_private	 	*p_priv; | 
|  | 749 | int old_dcd_state; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 750 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 752 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 754 | serial =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 756 | if (status) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 757 | dbg("%s - nonzero status: %x", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | return; | 
|  | 759 | } | 
|  | 760 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 761 | if (urb->actual_length != | 
|  | 762 | sizeof(struct keyspan_usa49_portStatusMessage)) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 763 | dbg("%s - bad length %d", __func__, urb->actual_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | goto exit; | 
|  | 765 | } | 
|  | 766 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 767 | /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __func__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | data[0], data[1], data[2], data[3], data[4], data[5], | 
|  | 769 | data[6], data[7], data[8], data[9], data[10]);*/ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 770 |  | 
|  | 771 | /* Now do something useful with the data */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | msg = (struct keyspan_usa49_portStatusMessage *)data; | 
|  | 773 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 774 | /* Check port number from message and retrieve private data */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | if (msg->portNumber >= serial->num_ports) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 776 | dbg("%s - Unexpected port number %d", | 
|  | 777 | __func__, msg->portNumber); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | goto exit; | 
|  | 779 | } | 
|  | 780 | port = serial->port[msg->portNumber]; | 
|  | 781 | p_priv = usb_get_serial_port_data(port); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 782 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | /* Update handshaking pin state information */ | 
|  | 784 | old_dcd_state = p_priv->dcd_state; | 
|  | 785 | p_priv->cts_state = ((msg->cts) ? 1 : 0); | 
|  | 786 | p_priv->dsr_state = ((msg->dsr) ? 1 : 0); | 
|  | 787 | p_priv->dcd_state = ((msg->dcd) ? 1 : 0); | 
|  | 788 | p_priv->ri_state = ((msg->ri) ? 1 : 0); | 
|  | 789 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 790 | if (old_dcd_state != p_priv->dcd_state && old_dcd_state) { | 
|  | 791 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 
|  | 792 | if (tty && !C_CLOCAL(tty)) | 
|  | 793 | tty_hangup(tty); | 
|  | 794 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } | 
|  | 796 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 797 | /* Resubmit urb so we continue receiving */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | urb->dev = serial->dev; | 
|  | 799 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 800 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 801 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 802 | dbg("%s - resubmit read urb failed. (%d)", __func__, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | exit:	; | 
|  | 804 | } | 
|  | 805 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 806 | static void	usa49_inack_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 808 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } | 
|  | 810 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 811 | static void	usa49_indat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | { | 
|  | 813 | int			i, err; | 
|  | 814 | int			endpoint; | 
|  | 815 | struct usb_serial_port	*port; | 
|  | 816 | struct tty_struct	*tty; | 
|  | 817 | unsigned char 		*data = urb->transfer_buffer; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 818 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 820 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 |  | 
|  | 822 | endpoint = usb_pipeendpoint(urb->pipe); | 
|  | 823 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 824 | if (status) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 825 | dbg("%s - nonzero status: %x on endpoint %d.", __func__, | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 826 | status, endpoint); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | return; | 
|  | 828 | } | 
|  | 829 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 830 | port =  urb->context; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 831 | tty = tty_port_tty_get(&port->port); | 
| Alan Cox | 3004e53 | 2008-01-03 16:59:04 +0000 | [diff] [blame] | 832 | if (tty && urb->actual_length) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | /* 0x80 bit is error flag */ | 
|  | 834 | if ((data[0] & 0x80) == 0) { | 
|  | 835 | /* no error on any byte */ | 
| Alan Cox | f035a8a | 2008-07-22 11:13:32 +0100 | [diff] [blame] | 836 | tty_insert_flip_string(tty, data + 1, | 
|  | 837 | urb->actual_length - 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } else { | 
|  | 839 | /* some bytes had errors, every byte has status */ | 
|  | 840 | for (i = 0; i + 1 < urb->actual_length; i += 2) { | 
|  | 841 | int stat = data[i], flag = 0; | 
|  | 842 | if (stat & RXERROR_OVERRUN) | 
|  | 843 | flag |= TTY_OVERRUN; | 
|  | 844 | if (stat & RXERROR_FRAMING) | 
|  | 845 | flag |= TTY_FRAME; | 
|  | 846 | if (stat & RXERROR_PARITY) | 
|  | 847 | flag |= TTY_PARITY; | 
|  | 848 | /* XXX should handle break (0x10) */ | 
|  | 849 | tty_insert_flip_char(tty, data[i+1], flag); | 
|  | 850 | } | 
|  | 851 | } | 
|  | 852 | tty_flip_buffer_push(tty); | 
|  | 853 | } | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 854 | tty_kref_put(tty); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 855 |  | 
|  | 856 | /* Resubmit urb so we continue receiving */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | urb->dev = port->serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 858 | if (port->port.count) { | 
|  | 859 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 860 | if (err != 0) | 
|  | 861 | dbg("%s - resubmit read urb failed. (%d)", | 
|  | 862 | __func__, err); | 
|  | 863 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } | 
|  | 865 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 866 | static void usa49wg_indat_callback(struct urb *urb) | 
|  | 867 | { | 
|  | 868 | int			i, len, x, err; | 
|  | 869 | struct usb_serial	*serial; | 
|  | 870 | struct usb_serial_port	*port; | 
|  | 871 | struct tty_struct	*tty; | 
|  | 872 | unsigned char 		*data = urb->transfer_buffer; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 873 | int status = urb->status; | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 874 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 875 | dbg("%s", __func__); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 876 |  | 
|  | 877 | serial = urb->context; | 
|  | 878 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 879 | if (status) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 880 | dbg("%s - nonzero status: %x", __func__, status); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 881 | return; | 
|  | 882 | } | 
|  | 883 |  | 
|  | 884 | /* inbound data is in the form P#, len, status, data */ | 
|  | 885 | i = 0; | 
|  | 886 | len = 0; | 
|  | 887 |  | 
|  | 888 | if (urb->actual_length) { | 
|  | 889 | while (i < urb->actual_length) { | 
|  | 890 |  | 
|  | 891 | /* Check port number from message*/ | 
|  | 892 | if (data[i] >= serial->num_ports) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 893 | dbg("%s - Unexpected port number %d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 894 | __func__, data[i]); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 895 | return; | 
|  | 896 | } | 
|  | 897 | port = serial->port[data[i++]]; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 898 | tty = tty_port_tty_get(&port->port); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 899 | len = data[i++]; | 
|  | 900 |  | 
|  | 901 | /* 0x80 bit is error flag */ | 
|  | 902 | if ((data[i] & 0x80) == 0) { | 
|  | 903 | /* no error on any byte */ | 
|  | 904 | i++; | 
|  | 905 | for (x = 1; x < len ; ++x) | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 906 | if (port->port.count) | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 907 | tty_insert_flip_char(tty, | 
|  | 908 | data[i++], 0); | 
|  | 909 | else | 
|  | 910 | i++; | 
|  | 911 | } else { | 
|  | 912 | /* | 
|  | 913 | * some bytes had errors, every byte has status | 
|  | 914 | */ | 
|  | 915 | for (x = 0; x + 1 < len; x += 2) { | 
|  | 916 | int stat = data[i], flag = 0; | 
|  | 917 | if (stat & RXERROR_OVERRUN) | 
|  | 918 | flag |= TTY_OVERRUN; | 
|  | 919 | if (stat & RXERROR_FRAMING) | 
|  | 920 | flag |= TTY_FRAME; | 
|  | 921 | if (stat & RXERROR_PARITY) | 
|  | 922 | flag |= TTY_PARITY; | 
|  | 923 | /* XXX should handle break (0x10) */ | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 924 | if (port->port.count) | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 925 | tty_insert_flip_char(tty, | 
|  | 926 | data[i+1], flag); | 
|  | 927 | i += 2; | 
|  | 928 | } | 
|  | 929 | } | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 930 | if (port->port.count) | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 931 | tty_flip_buffer_push(tty); | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 932 | tty_kref_put(tty); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 933 | } | 
|  | 934 | } | 
|  | 935 |  | 
|  | 936 | /* Resubmit urb so we continue receiving */ | 
|  | 937 | urb->dev = serial->dev; | 
|  | 938 |  | 
|  | 939 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 940 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 941 | dbg("%s - resubmit read urb failed. (%d)", __func__, err); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 942 | } | 
|  | 943 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | /* not used, usa-49 doesn't have per-port control endpoints */ | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 945 | static void usa49_outcont_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 947 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | } | 
|  | 949 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 950 | static void usa90_indat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | { | 
|  | 952 | int			i, err; | 
|  | 953 | int			endpoint; | 
|  | 954 | struct usb_serial_port	*port; | 
|  | 955 | struct keyspan_port_private	 	*p_priv; | 
|  | 956 | struct tty_struct	*tty; | 
|  | 957 | unsigned char 		*data = urb->transfer_buffer; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 958 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 960 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 |  | 
|  | 962 | endpoint = usb_pipeendpoint(urb->pipe); | 
|  | 963 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 964 | if (status) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | dbg("%s - nonzero status: %x on endpoint %d.", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 966 | __func__, status, endpoint); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | return; | 
|  | 968 | } | 
|  | 969 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 970 | port =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | p_priv = usb_get_serial_port_data(port); | 
|  | 972 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | if (urb->actual_length) { | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 974 | tty = tty_port_tty_get(&port->port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | /* if current mode is DMA, looks like usa28 format | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 976 | otherwise looks like usa26 data format */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 |  | 
| Alan Cox | f035a8a | 2008-07-22 11:13:32 +0100 | [diff] [blame] | 978 | if (p_priv->baud > 57600) | 
|  | 979 | tty_insert_flip_string(tty, data, urb->actual_length); | 
|  | 980 | else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | /* 0x80 bit is error flag */ | 
|  | 982 | if ((data[0] & 0x80) == 0) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 983 | /* no errors on individual bytes, only | 
|  | 984 | possible overrun err*/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | if (data[0] & RXERROR_OVERRUN) | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 986 | err = TTY_OVERRUN; | 
|  | 987 | else | 
|  | 988 | err = 0; | 
|  | 989 | for (i = 1; i < urb->actual_length ; ++i) | 
|  | 990 | tty_insert_flip_char(tty, data[i], | 
|  | 991 | err); | 
|  | 992 | }  else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | /* some bytes had errors, every byte has status */ | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 994 | dbg("%s - RX error!!!!", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | for (i = 0; i + 1 < urb->actual_length; i += 2) { | 
|  | 996 | int stat = data[i], flag = 0; | 
|  | 997 | if (stat & RXERROR_OVERRUN) | 
|  | 998 | flag |= TTY_OVERRUN; | 
|  | 999 | if (stat & RXERROR_FRAMING) | 
|  | 1000 | flag |= TTY_FRAME; | 
|  | 1001 | if (stat & RXERROR_PARITY) | 
|  | 1002 | flag |= TTY_PARITY; | 
|  | 1003 | /* XXX should handle break (0x10) */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1004 | tty_insert_flip_char(tty, data[i+1], | 
|  | 1005 | flag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | } | 
|  | 1007 | } | 
|  | 1008 | } | 
|  | 1009 | tty_flip_buffer_push(tty); | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1010 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1012 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | /* Resubmit urb so we continue receiving */ | 
|  | 1014 | urb->dev = port->serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1015 | if (port->port.count) { | 
|  | 1016 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 1017 | if (err != 0) | 
|  | 1018 | dbg("%s - resubmit read urb failed. (%d)", | 
|  | 1019 | __func__, err); | 
|  | 1020 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | return; | 
|  | 1022 | } | 
|  | 1023 |  | 
|  | 1024 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1025 | static void	usa90_instat_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | { | 
|  | 1027 | unsigned char 				*data = urb->transfer_buffer; | 
|  | 1028 | struct keyspan_usa90_portStatusMessage	*msg; | 
|  | 1029 | struct usb_serial			*serial; | 
|  | 1030 | struct usb_serial_port			*port; | 
|  | 1031 | struct keyspan_port_private	 	*p_priv; | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1032 | struct tty_struct			*tty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | int old_dcd_state, err; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1034 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1036 | serial =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1038 | if (status) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1039 | dbg("%s - nonzero status: %x", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | return; | 
|  | 1041 | } | 
|  | 1042 | if (urb->actual_length < 14) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1043 | dbg("%s - %d byte report??", __func__, urb->actual_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | goto exit; | 
|  | 1045 | } | 
|  | 1046 |  | 
|  | 1047 | msg = (struct keyspan_usa90_portStatusMessage *)data; | 
|  | 1048 |  | 
|  | 1049 | /* Now do something useful with the data */ | 
|  | 1050 |  | 
|  | 1051 | port = serial->port[0]; | 
|  | 1052 | p_priv = usb_get_serial_port_data(port); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1053 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | /* Update handshaking pin state information */ | 
|  | 1055 | old_dcd_state = p_priv->dcd_state; | 
|  | 1056 | p_priv->cts_state = ((msg->cts) ? 1 : 0); | 
|  | 1057 | p_priv->dsr_state = ((msg->dsr) ? 1 : 0); | 
|  | 1058 | p_priv->dcd_state = ((msg->dcd) ? 1 : 0); | 
|  | 1059 | p_priv->ri_state = ((msg->ri) ? 1 : 0); | 
|  | 1060 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1061 | if (old_dcd_state != p_priv->dcd_state && old_dcd_state) { | 
|  | 1062 | tty = tty_port_tty_get(&port->port); | 
|  | 1063 | if (tty && !C_CLOCAL(tty)) | 
|  | 1064 | tty_hangup(tty); | 
|  | 1065 | tty_kref_put(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1067 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | /* Resubmit urb so we continue receiving */ | 
|  | 1069 | urb->dev = serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1070 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 1071 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1072 | dbg("%s - resubmit read urb failed. (%d)", __func__, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | exit: | 
|  | 1074 | ; | 
|  | 1075 | } | 
|  | 1076 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1077 | static void	usa90_outcont_callback(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | { | 
|  | 1079 | struct usb_serial_port *port; | 
|  | 1080 | struct keyspan_port_private *p_priv; | 
|  | 1081 |  | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1082 | port =  urb->context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | p_priv = usb_get_serial_port_data(port); | 
|  | 1084 |  | 
|  | 1085 | if (p_priv->resend_cont) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1086 | dbg("%s - sending setup", __func__); | 
|  | 1087 | keyspan_usa90_send_setup(port->serial, port, | 
|  | 1088 | p_priv->resend_cont - 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | } | 
|  | 1090 | } | 
|  | 1091 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1092 | /* Status messages from the 28xg */ | 
|  | 1093 | static void	usa67_instat_callback(struct urb *urb) | 
|  | 1094 | { | 
|  | 1095 | int					err; | 
|  | 1096 | unsigned char 				*data = urb->transfer_buffer; | 
|  | 1097 | struct keyspan_usa67_portStatusMessage	*msg; | 
|  | 1098 | struct usb_serial			*serial; | 
|  | 1099 | struct usb_serial_port			*port; | 
|  | 1100 | struct keyspan_port_private	 	*p_priv; | 
|  | 1101 | int old_dcd_state; | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1102 | int status = urb->status; | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1103 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1104 | dbg("%s", __func__); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1105 |  | 
|  | 1106 | serial = urb->context; | 
|  | 1107 |  | 
| Greg Kroah-Hartman | 95b9345 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1108 | if (status) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1109 | dbg("%s - nonzero status: %x", __func__, status); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1110 | return; | 
|  | 1111 | } | 
|  | 1112 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1113 | if (urb->actual_length != | 
|  | 1114 | sizeof(struct keyspan_usa67_portStatusMessage)) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1115 | dbg("%s - bad length %d", __func__, urb->actual_length); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1116 | return; | 
|  | 1117 | } | 
|  | 1118 |  | 
|  | 1119 |  | 
|  | 1120 | /* Now do something useful with the data */ | 
|  | 1121 | msg = (struct keyspan_usa67_portStatusMessage *)data; | 
|  | 1122 |  | 
|  | 1123 | /* Check port number from message and retrieve private data */ | 
|  | 1124 | if (msg->port >= serial->num_ports) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1125 | dbg("%s - Unexpected port number %d", __func__, msg->port); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1126 | return; | 
|  | 1127 | } | 
|  | 1128 |  | 
|  | 1129 | port = serial->port[msg->port]; | 
|  | 1130 | p_priv = usb_get_serial_port_data(port); | 
|  | 1131 |  | 
|  | 1132 | /* Update handshaking pin state information */ | 
|  | 1133 | old_dcd_state = p_priv->dcd_state; | 
|  | 1134 | p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0); | 
|  | 1135 | p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); | 
|  | 1136 |  | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1137 | if (old_dcd_state != p_priv->dcd_state && old_dcd_state) { | 
|  | 1138 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 
|  | 1139 | if (tty && !C_CLOCAL(tty)) | 
|  | 1140 | tty_hangup(tty); | 
|  | 1141 | tty_kref_put(tty); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1142 | } | 
|  | 1143 |  | 
|  | 1144 | /* Resubmit urb so we continue receiving */ | 
|  | 1145 | urb->dev = serial->dev; | 
|  | 1146 | err = usb_submit_urb(urb, GFP_ATOMIC); | 
|  | 1147 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1148 | dbg("%s - resubmit read urb failed. (%d)", __func__, err); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1149 | } | 
|  | 1150 |  | 
|  | 1151 | static void usa67_glocont_callback(struct urb *urb) | 
|  | 1152 | { | 
|  | 1153 | struct usb_serial *serial; | 
|  | 1154 | struct usb_serial_port *port; | 
|  | 1155 | struct keyspan_port_private *p_priv; | 
|  | 1156 | int i; | 
|  | 1157 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1158 | dbg("%s", __func__); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1159 |  | 
|  | 1160 | serial = urb->context; | 
|  | 1161 | for (i = 0; i < serial->num_ports; ++i) { | 
|  | 1162 | port = serial->port[i]; | 
|  | 1163 | p_priv = usb_get_serial_port_data(port); | 
|  | 1164 |  | 
|  | 1165 | if (p_priv->resend_cont) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1166 | dbg("%s - sending setup", __func__); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1167 | keyspan_usa67_send_setup(serial, port, | 
|  | 1168 | p_priv->resend_cont - 1); | 
|  | 1169 | break; | 
|  | 1170 | } | 
|  | 1171 | } | 
|  | 1172 | } | 
|  | 1173 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1174 | static int keyspan_write_room(struct tty_struct *tty) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1176 | struct usb_serial_port *port = tty->driver_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | struct keyspan_port_private	*p_priv; | 
|  | 1178 | const struct keyspan_device_details	*d_details; | 
|  | 1179 | int				flip; | 
|  | 1180 | int				data_len; | 
|  | 1181 | struct urb			*this_urb; | 
|  | 1182 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1183 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | p_priv = usb_get_serial_port_data(port); | 
|  | 1185 | d_details = p_priv->device_details; | 
|  | 1186 |  | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 1187 | /* FIXME: locking */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | if (d_details->msg_format == msg_usa90) | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1189 | data_len = 64; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | else | 
|  | 1191 | data_len = 63; | 
|  | 1192 |  | 
|  | 1193 | flip = p_priv->out_flip; | 
|  | 1194 |  | 
|  | 1195 | /* Check both endpoints to see if any are available. */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1196 | this_urb = p_priv->out_urbs[flip]; | 
|  | 1197 | if (this_urb != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | if (this_urb->status != -EINPROGRESS) | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1199 | return data_len; | 
|  | 1200 | flip = (flip + 1) & d_details->outdat_endp_flip; | 
|  | 1201 | this_urb = p_priv->out_urbs[flip]; | 
|  | 1202 | if (this_urb != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | if (this_urb->status != -EINPROGRESS) | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1204 | return data_len; | 
|  | 1205 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 1207 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } | 
|  | 1209 |  | 
|  | 1210 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1211 | static int keyspan_open(struct tty_struct *tty, | 
|  | 1212 | struct usb_serial_port *port, struct file *filp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | { | 
| Andrew Morton | f78ba15 | 2007-11-28 16:21:54 -0800 | [diff] [blame] | 1214 | struct keyspan_port_private 	*p_priv; | 
|  | 1215 | struct keyspan_serial_private 	*s_priv; | 
|  | 1216 | struct usb_serial 		*serial = port->serial; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | const struct keyspan_device_details	*d_details; | 
|  | 1218 | int				i, err; | 
| Andrew Morton | f78ba15 | 2007-11-28 16:21:54 -0800 | [diff] [blame] | 1219 | int				baud_rate, device_port; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | struct urb			*urb; | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1221 | unsigned int			cflag = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 |  | 
|  | 1223 | s_priv = usb_get_serial_data(serial); | 
|  | 1224 | p_priv = usb_get_serial_port_data(port); | 
|  | 1225 | d_details = p_priv->device_details; | 
| Borislav Petkov | 7eea436 | 2007-11-14 17:00:39 -0800 | [diff] [blame] | 1226 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1227 | dbg("%s - port%d.", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 |  | 
|  | 1229 | /* Set some sane defaults */ | 
|  | 1230 | p_priv->rts_state = 1; | 
|  | 1231 | p_priv->dtr_state = 1; | 
|  | 1232 | p_priv->baud = 9600; | 
|  | 1233 |  | 
|  | 1234 | /* force baud and lcr to be set on open */ | 
|  | 1235 | p_priv->old_baud = 0; | 
|  | 1236 | p_priv->old_cflag = 0; | 
|  | 1237 |  | 
|  | 1238 | p_priv->out_flip = 0; | 
|  | 1239 | p_priv->in_flip = 0; | 
|  | 1240 |  | 
|  | 1241 | /* Reset low level data toggle and start reading from endpoints */ | 
|  | 1242 | for (i = 0; i < 2; i++) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1243 | urb = p_priv->in_urbs[i]; | 
|  | 1244 | if (urb == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | continue; | 
|  | 1246 | urb->dev = serial->dev; | 
|  | 1247 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1248 | /* make sure endpoint data toggle is synchronized | 
|  | 1249 | with the device */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | usb_clear_halt(urb->dev, urb->pipe); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1251 | err = usb_submit_urb(urb, GFP_KERNEL); | 
|  | 1252 | if (err != 0) | 
|  | 1253 | dbg("%s - submit urb %d failed (%d)", | 
|  | 1254 | __func__, i, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | } | 
|  | 1256 |  | 
|  | 1257 | /* Reset low level data toggle on out endpoints */ | 
|  | 1258 | for (i = 0; i < 2; i++) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1259 | urb = p_priv->out_urbs[i]; | 
|  | 1260 | if (urb == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | continue; | 
|  | 1262 | urb->dev = serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1263 | /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), | 
|  | 1264 | usb_pipeout(urb->pipe), 0); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } | 
|  | 1266 |  | 
| Andrew Morton | f78ba15 | 2007-11-28 16:21:54 -0800 | [diff] [blame] | 1267 | /* get the terminal config for the setup message now so we don't | 
|  | 1268 | * need to send 2 of them */ | 
|  | 1269 |  | 
| Andrew Morton | f78ba15 | 2007-11-28 16:21:54 -0800 | [diff] [blame] | 1270 | device_port = port->number - port->serial->minor; | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1271 | if (tty) { | 
|  | 1272 | cflag = tty->termios->c_cflag; | 
|  | 1273 | /* Baud rate calculation takes baud rate as an integer | 
|  | 1274 | so other rates can be generated if desired. */ | 
|  | 1275 | baud_rate = tty_get_baud_rate(tty); | 
|  | 1276 | /* If no match or invalid, leave as default */ | 
|  | 1277 | if (baud_rate >= 0 | 
|  | 1278 | && d_details->calculate_baud_rate(baud_rate, d_details->baudclk, | 
|  | 1279 | NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { | 
|  | 1280 | p_priv->baud = baud_rate; | 
|  | 1281 | } | 
| Andrew Morton | f78ba15 | 2007-11-28 16:21:54 -0800 | [diff] [blame] | 1282 | } | 
| Andrew Morton | f78ba15 | 2007-11-28 16:21:54 -0800 | [diff] [blame] | 1283 | /* set CTS/RTS handshake etc. */ | 
|  | 1284 | p_priv->cflag = cflag; | 
|  | 1285 | p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none; | 
|  | 1286 |  | 
|  | 1287 | keyspan_send_setup(port, 1); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1288 | /* mdelay(100); */ | 
|  | 1289 | /* keyspan_set_termios(port, NULL); */ | 
| Andrew Morton | f78ba15 | 2007-11-28 16:21:54 -0800 | [diff] [blame] | 1290 |  | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 1291 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | } | 
|  | 1293 |  | 
|  | 1294 | static inline void stop_urb(struct urb *urb) | 
|  | 1295 | { | 
| Greg Kroah-Hartman | 242cf67 | 2005-07-29 16:11:07 -0400 | [diff] [blame] | 1296 | if (urb && urb->status == -EINPROGRESS) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | usb_kill_urb(urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | } | 
|  | 1299 |  | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1300 | static void keyspan_close(struct tty_struct *tty, | 
|  | 1301 | struct usb_serial_port *port, struct file *filp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | { | 
|  | 1303 | int			i; | 
|  | 1304 | struct usb_serial	*serial = port->serial; | 
|  | 1305 | struct keyspan_serial_private 	*s_priv; | 
|  | 1306 | struct keyspan_port_private 	*p_priv; | 
|  | 1307 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1308 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | s_priv = usb_get_serial_data(serial); | 
|  | 1310 | p_priv = usb_get_serial_port_data(port); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1311 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | p_priv->rts_state = 0; | 
|  | 1313 | p_priv->dtr_state = 0; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1314 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | if (serial->dev) { | 
|  | 1316 | keyspan_send_setup(port, 2); | 
|  | 1317 | /* pilot-xfer seems to work best with this delay */ | 
|  | 1318 | mdelay(100); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1319 | /* keyspan_set_termios(port, NULL); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } | 
|  | 1321 |  | 
|  | 1322 | /*while (p_priv->outcont_urb->status == -EINPROGRESS) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1323 | dbg("%s - urb in progress", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | }*/ | 
|  | 1325 |  | 
|  | 1326 | p_priv->out_flip = 0; | 
|  | 1327 | p_priv->in_flip = 0; | 
|  | 1328 |  | 
|  | 1329 | if (serial->dev) { | 
|  | 1330 | /* Stop reading/writing urbs */ | 
|  | 1331 | stop_urb(p_priv->inack_urb); | 
|  | 1332 | /* stop_urb(p_priv->outcont_urb); */ | 
|  | 1333 | for (i = 0; i < 2; i++) { | 
|  | 1334 | stop_urb(p_priv->in_urbs[i]); | 
|  | 1335 | stop_urb(p_priv->out_urbs[i]); | 
|  | 1336 | } | 
|  | 1337 | } | 
| Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1338 | tty_port_tty_set(&port->port, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } | 
|  | 1340 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1341 | /* download the firmware to a pre-renumeration device */ | 
|  | 1342 | static int keyspan_fake_startup(struct usb_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | { | 
|  | 1344 | int 				response; | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1345 | const struct ihex_binrec 	*record; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | char				*fw_name; | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1347 | const struct firmware		*fw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 |  | 
|  | 1349 | dbg("Keyspan startup version %04x product %04x", | 
|  | 1350 | le16_to_cpu(serial->dev->descriptor.bcdDevice), | 
|  | 1351 | le16_to_cpu(serial->dev->descriptor.idProduct)); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1352 |  | 
|  | 1353 | if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000) | 
|  | 1354 | != 0x8000) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | dbg("Firmware already loaded.  Quitting."); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1356 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } | 
|  | 1358 |  | 
|  | 1359 | /* Select firmware image on the basis of idProduct */ | 
|  | 1360 | switch (le16_to_cpu(serial->dev->descriptor.idProduct)) { | 
|  | 1361 | case keyspan_usa28_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1362 | fw_name = "keyspan/usa28.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | break; | 
|  | 1364 |  | 
|  | 1365 | case keyspan_usa28x_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1366 | fw_name = "keyspan/usa28x.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | break; | 
|  | 1368 |  | 
|  | 1369 | case keyspan_usa28xa_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1370 | fw_name = "keyspan/usa28xa.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | break; | 
|  | 1372 |  | 
|  | 1373 | case keyspan_usa28xb_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1374 | fw_name = "keyspan/usa28xb.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | break; | 
|  | 1376 |  | 
|  | 1377 | case keyspan_usa19_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1378 | fw_name = "keyspan/usa19.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | break; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1380 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | case keyspan_usa19qi_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1382 | fw_name = "keyspan/usa19qi.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | break; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1384 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | case keyspan_mpr_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1386 | fw_name = "keyspan/mpr.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | break; | 
|  | 1388 |  | 
|  | 1389 | case keyspan_usa19qw_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1390 | fw_name = "keyspan/usa19qw.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | break; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1392 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | case keyspan_usa18x_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1394 | fw_name = "keyspan/usa18x.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | break; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1396 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | case keyspan_usa19w_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1398 | fw_name = "keyspan/usa19w.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | break; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1400 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | case keyspan_usa49w_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1402 | fw_name = "keyspan/usa49w.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | break; | 
|  | 1404 |  | 
|  | 1405 | case keyspan_usa49wlc_pre_product_id: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1406 | fw_name = "keyspan/usa49wlc.fw"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | break; | 
|  | 1408 |  | 
|  | 1409 | default: | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1410 | dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n", | 
|  | 1411 | le16_to_cpu(serial->dev->descriptor.idProduct)); | 
|  | 1412 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | } | 
|  | 1414 |  | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1415 | if (request_ihex_firmware(&fw, fw_name, &serial->dev->dev)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | dev_err(&serial->dev->dev, "Required keyspan firmware image (%s) unavailable.\n", fw_name); | 
|  | 1417 | return(1); | 
|  | 1418 | } | 
|  | 1419 |  | 
|  | 1420 | dbg("Uploading Keyspan %s firmware.", fw_name); | 
|  | 1421 |  | 
|  | 1422 | /* download the firmware image */ | 
|  | 1423 | response = ezusb_set_reset(serial, 1); | 
|  | 1424 |  | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1425 | record = (const struct ihex_binrec *)fw->data; | 
|  | 1426 |  | 
|  | 1427 | while (record) { | 
|  | 1428 | response = ezusb_writememory(serial, be32_to_cpu(record->addr), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | (unsigned char *)record->data, | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1430 | be16_to_cpu(record->len), 0xa0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | if (response < 0) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1432 | dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan firmware (%d %04X %p %d)\n", | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1433 | response, be32_to_cpu(record->addr), | 
|  | 1434 | record->data, be16_to_cpu(record->len)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | break; | 
|  | 1436 | } | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1437 | record = ihex_next_binrec(record); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | } | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 1439 | release_firmware(fw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | /* bring device out of reset. Renumeration will occur in a | 
|  | 1441 | moment and the new device will bind to the real driver */ | 
|  | 1442 | response = ezusb_set_reset(serial, 0); | 
|  | 1443 |  | 
|  | 1444 | /* we don't want this device to have a driver assigned to it. */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1445 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } | 
|  | 1447 |  | 
|  | 1448 | /* Helper functions used by keyspan_setup_urbs */ | 
| Rainer Weikusat | fdcba53 | 2007-01-03 15:36:25 +0100 | [diff] [blame] | 1449 | static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial, | 
|  | 1450 | int endpoint) | 
|  | 1451 | { | 
|  | 1452 | struct usb_host_interface *iface_desc; | 
|  | 1453 | struct usb_endpoint_descriptor *ep; | 
|  | 1454 | int i; | 
|  | 1455 |  | 
|  | 1456 | iface_desc = serial->interface->cur_altsetting; | 
|  | 1457 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { | 
|  | 1458 | ep = &iface_desc->endpoint[i].desc; | 
|  | 1459 | if (ep->bEndpointAddress == endpoint) | 
|  | 1460 | return ep; | 
|  | 1461 | } | 
|  | 1462 | dev_warn(&serial->interface->dev, "found no endpoint descriptor for " | 
|  | 1463 | "endpoint %x\n", endpoint); | 
|  | 1464 | return NULL; | 
|  | 1465 | } | 
|  | 1466 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1467 | static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | int dir, void *ctx, char *buf, int len, | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1469 | void (*callback)(struct urb *)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | { | 
|  | 1471 | struct urb *urb; | 
| Rainer Weikusat | fdcba53 | 2007-01-03 15:36:25 +0100 | [diff] [blame] | 1472 | struct usb_endpoint_descriptor const *ep_desc; | 
|  | 1473 | char const *ep_type_name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 |  | 
|  | 1475 | if (endpoint == -1) | 
|  | 1476 | return NULL;		/* endpoint not needed */ | 
|  | 1477 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1478 | dbg("%s - alloc for endpoint %d.", __func__, endpoint); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | urb = usb_alloc_urb(0, GFP_KERNEL);		/* No ISO */ | 
|  | 1480 | if (urb == NULL) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1481 | dbg("%s - alloc for endpoint %d failed.", __func__, endpoint); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | return NULL; | 
|  | 1483 | } | 
|  | 1484 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1485 | if (endpoint == 0) { | 
|  | 1486 | /* control EP filled in when used */ | 
|  | 1487 | return urb; | 
|  | 1488 | } | 
|  | 1489 |  | 
| Rainer Weikusat | fdcba53 | 2007-01-03 15:36:25 +0100 | [diff] [blame] | 1490 | ep_desc = find_ep(serial, endpoint); | 
|  | 1491 | if (!ep_desc) { | 
|  | 1492 | /* leak the urb, something's wrong and the callers don't care */ | 
|  | 1493 | return urb; | 
|  | 1494 | } | 
|  | 1495 | if (usb_endpoint_xfer_int(ep_desc)) { | 
|  | 1496 | ep_type_name = "INT"; | 
|  | 1497 | usb_fill_int_urb(urb, serial->dev, | 
|  | 1498 | usb_sndintpipe(serial->dev, endpoint) | dir, | 
|  | 1499 | buf, len, callback, ctx, | 
|  | 1500 | ep_desc->bInterval); | 
|  | 1501 | } else if (usb_endpoint_xfer_bulk(ep_desc)) { | 
|  | 1502 | ep_type_name = "BULK"; | 
|  | 1503 | usb_fill_bulk_urb(urb, serial->dev, | 
|  | 1504 | usb_sndbulkpipe(serial->dev, endpoint) | dir, | 
|  | 1505 | buf, len, callback, ctx); | 
|  | 1506 | } else { | 
|  | 1507 | dev_warn(&serial->interface->dev, | 
|  | 1508 | "unsupported endpoint type %x\n", | 
|  | 1509 | ep_desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); | 
|  | 1510 | usb_free_urb(urb); | 
|  | 1511 | return NULL; | 
|  | 1512 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 |  | 
| Rainer Weikusat | fdcba53 | 2007-01-03 15:36:25 +0100 | [diff] [blame] | 1514 | dbg("%s - using urb %p for %s endpoint %x", | 
|  | 1515 | __func__, urb, ep_type_name, endpoint); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | return urb; | 
|  | 1517 | } | 
|  | 1518 |  | 
|  | 1519 | static struct callbacks { | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1520 | void	(*instat_callback)(struct urb *); | 
|  | 1521 | void	(*glocont_callback)(struct urb *); | 
|  | 1522 | void	(*indat_callback)(struct urb *); | 
|  | 1523 | void	(*outdat_callback)(struct urb *); | 
|  | 1524 | void	(*inack_callback)(struct urb *); | 
|  | 1525 | void	(*outcont_callback)(struct urb *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | } keyspan_callbacks[] = { | 
|  | 1527 | { | 
|  | 1528 | /* msg_usa26 callbacks */ | 
|  | 1529 | .instat_callback =	usa26_instat_callback, | 
|  | 1530 | .glocont_callback =	usa26_glocont_callback, | 
|  | 1531 | .indat_callback =	usa26_indat_callback, | 
|  | 1532 | .outdat_callback =	usa2x_outdat_callback, | 
|  | 1533 | .inack_callback =	usa26_inack_callback, | 
|  | 1534 | .outcont_callback =	usa26_outcont_callback, | 
|  | 1535 | }, { | 
|  | 1536 | /* msg_usa28 callbacks */ | 
|  | 1537 | .instat_callback =	usa28_instat_callback, | 
|  | 1538 | .glocont_callback =	usa28_glocont_callback, | 
|  | 1539 | .indat_callback =	usa28_indat_callback, | 
|  | 1540 | .outdat_callback =	usa2x_outdat_callback, | 
|  | 1541 | .inack_callback =	usa28_inack_callback, | 
|  | 1542 | .outcont_callback =	usa28_outcont_callback, | 
|  | 1543 | }, { | 
|  | 1544 | /* msg_usa49 callbacks */ | 
|  | 1545 | .instat_callback =	usa49_instat_callback, | 
|  | 1546 | .glocont_callback =	usa49_glocont_callback, | 
|  | 1547 | .indat_callback =	usa49_indat_callback, | 
|  | 1548 | .outdat_callback =	usa2x_outdat_callback, | 
|  | 1549 | .inack_callback =	usa49_inack_callback, | 
|  | 1550 | .outcont_callback =	usa49_outcont_callback, | 
|  | 1551 | }, { | 
|  | 1552 | /* msg_usa90 callbacks */ | 
|  | 1553 | .instat_callback =	usa90_instat_callback, | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1554 | .glocont_callback =	usa28_glocont_callback, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | .indat_callback =	usa90_indat_callback, | 
|  | 1556 | .outdat_callback =	usa2x_outdat_callback, | 
|  | 1557 | .inack_callback =	usa28_inack_callback, | 
|  | 1558 | .outcont_callback =	usa90_outcont_callback, | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1559 | }, { | 
|  | 1560 | /* msg_usa67 callbacks */ | 
|  | 1561 | .instat_callback =	usa67_instat_callback, | 
|  | 1562 | .glocont_callback =	usa67_glocont_callback, | 
|  | 1563 | .indat_callback =	usa26_indat_callback, | 
|  | 1564 | .outdat_callback =	usa2x_outdat_callback, | 
|  | 1565 | .inack_callback =	usa26_inack_callback, | 
|  | 1566 | .outcont_callback =	usa26_outcont_callback, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | } | 
|  | 1568 | }; | 
|  | 1569 |  | 
|  | 1570 | /* Generic setup urbs function that uses | 
|  | 1571 | data in device_details */ | 
|  | 1572 | static void keyspan_setup_urbs(struct usb_serial *serial) | 
|  | 1573 | { | 
|  | 1574 | int				i, j; | 
|  | 1575 | struct keyspan_serial_private 	*s_priv; | 
|  | 1576 | const struct keyspan_device_details	*d_details; | 
|  | 1577 | struct usb_serial_port		*port; | 
|  | 1578 | struct keyspan_port_private	*p_priv; | 
|  | 1579 | struct callbacks		*cback; | 
|  | 1580 | int				endp; | 
|  | 1581 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1582 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 |  | 
|  | 1584 | s_priv = usb_get_serial_data(serial); | 
|  | 1585 | d_details = s_priv->device_details; | 
|  | 1586 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1587 | /* Setup values for the various callback routines */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | cback = &keyspan_callbacks[d_details->msg_format]; | 
|  | 1589 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1590 | /* Allocate and set up urbs for each one that is in use, | 
|  | 1591 | starting with instat endpoints */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | s_priv->instat_urb = keyspan_setup_urb | 
|  | 1593 | (serial, d_details->instat_endpoint, USB_DIR_IN, | 
|  | 1594 | serial, s_priv->instat_buf, INSTAT_BUFLEN, | 
|  | 1595 | cback->instat_callback); | 
|  | 1596 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1597 | s_priv->indat_urb = keyspan_setup_urb | 
|  | 1598 | (serial, d_details->indat_endpoint, USB_DIR_IN, | 
|  | 1599 | serial, s_priv->indat_buf, INDAT49W_BUFLEN, | 
|  | 1600 | usa49wg_indat_callback); | 
|  | 1601 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | s_priv->glocont_urb = keyspan_setup_urb | 
|  | 1603 | (serial, d_details->glocont_endpoint, USB_DIR_OUT, | 
|  | 1604 | serial, s_priv->glocont_buf, GLOCONT_BUFLEN, | 
|  | 1605 | cback->glocont_callback); | 
|  | 1606 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1607 | /* Setup endpoints for each port specific thing */ | 
|  | 1608 | for (i = 0; i < d_details->num_ports; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | port = serial->port[i]; | 
|  | 1610 | p_priv = usb_get_serial_port_data(port); | 
|  | 1611 |  | 
|  | 1612 | /* Do indat endpoints first, once for each flip */ | 
|  | 1613 | endp = d_details->indat_endpoints[i]; | 
|  | 1614 | for (j = 0; j <= d_details->indat_endp_flip; ++j, ++endp) { | 
|  | 1615 | p_priv->in_urbs[j] = keyspan_setup_urb | 
|  | 1616 | (serial, endp, USB_DIR_IN, port, | 
|  | 1617 | p_priv->in_buffer[j], 64, | 
|  | 1618 | cback->indat_callback); | 
|  | 1619 | } | 
|  | 1620 | for (; j < 2; ++j) | 
|  | 1621 | p_priv->in_urbs[j] = NULL; | 
|  | 1622 |  | 
|  | 1623 | /* outdat endpoints also have flip */ | 
|  | 1624 | endp = d_details->outdat_endpoints[i]; | 
|  | 1625 | for (j = 0; j <= d_details->outdat_endp_flip; ++j, ++endp) { | 
|  | 1626 | p_priv->out_urbs[j] = keyspan_setup_urb | 
|  | 1627 | (serial, endp, USB_DIR_OUT, port, | 
|  | 1628 | p_priv->out_buffer[j], 64, | 
|  | 1629 | cback->outdat_callback); | 
|  | 1630 | } | 
|  | 1631 | for (; j < 2; ++j) | 
|  | 1632 | p_priv->out_urbs[j] = NULL; | 
|  | 1633 |  | 
|  | 1634 | /* inack endpoint */ | 
|  | 1635 | p_priv->inack_urb = keyspan_setup_urb | 
|  | 1636 | (serial, d_details->inack_endpoints[i], USB_DIR_IN, | 
|  | 1637 | port, p_priv->inack_buffer, 1, cback->inack_callback); | 
|  | 1638 |  | 
|  | 1639 | /* outcont endpoint */ | 
|  | 1640 | p_priv->outcont_urb = keyspan_setup_urb | 
|  | 1641 | (serial, d_details->outcont_endpoints[i], USB_DIR_OUT, | 
|  | 1642 | port, p_priv->outcont_buffer, 64, | 
|  | 1643 | cback->outcont_callback); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1644 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | } | 
|  | 1646 |  | 
|  | 1647 | /* usa19 function doesn't require prescaler */ | 
|  | 1648 | static int keyspan_usa19_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi, | 
|  | 1649 | u8 *rate_low, u8 *prescaler, int portnum) | 
|  | 1650 | { | 
|  | 1651 | u32 	b16,	/* baud rate times 16 (actual rate used internally) */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1652 | div,	/* divisor */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | cnt;	/* inverse of divisor (programmed into 8051) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1655 | dbg("%s - %d.", __func__, baud_rate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1657 | /* prevent divide by zero...  */ | 
|  | 1658 | b16 = baud_rate * 16L; | 
|  | 1659 | if (b16 == 0) | 
|  | 1660 | return KEYSPAN_INVALID_BAUD_RATE; | 
|  | 1661 | /* Any "standard" rate over 57k6 is marginal on the USA-19 | 
|  | 1662 | as we run out of divisor resolution. */ | 
|  | 1663 | if (baud_rate > 57600) | 
|  | 1664 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1666 | /* calculate the divisor and the counter (its inverse) */ | 
|  | 1667 | div = baudclk / b16; | 
|  | 1668 | if (div == 0) | 
|  | 1669 | return KEYSPAN_INVALID_BAUD_RATE; | 
|  | 1670 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | cnt = 0 - div; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1673 | if (div > 0xffff) | 
|  | 1674 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1676 | /* return the counter values if non-null */ | 
|  | 1677 | if (rate_low) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | *rate_low = (u8) (cnt & 0xff); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1679 | if (rate_hi) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | *rate_hi = (u8) ((cnt >> 8) & 0xff); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1681 | if (rate_low && rate_hi) | 
|  | 1682 | dbg("%s - %d %02x %02x.", | 
|  | 1683 | __func__, baud_rate, *rate_hi, *rate_low); | 
|  | 1684 | return KEYSPAN_BAUD_RATE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | } | 
|  | 1686 |  | 
|  | 1687 | /* usa19hs function doesn't require prescaler */ | 
|  | 1688 | static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi, | 
|  | 1689 | u8 *rate_low, u8 *prescaler, int portnum) | 
|  | 1690 | { | 
|  | 1691 | u32 	b16,	/* baud rate times 16 (actual rate used internally) */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1692 | div;	/* divisor */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1694 | dbg("%s - %d.", __func__, baud_rate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1696 | /* prevent divide by zero...  */ | 
|  | 1697 | b16 = baud_rate * 16L; | 
|  | 1698 | if (b16 == 0) | 
|  | 1699 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1701 | /* calculate the divisor */ | 
|  | 1702 | div = baudclk / b16; | 
|  | 1703 | if (div == 0) | 
|  | 1704 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1706 | if (div > 0xffff) | 
|  | 1707 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1709 | /* return the counter values if non-null */ | 
|  | 1710 | if (rate_low) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | *rate_low = (u8) (div & 0xff); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1712 |  | 
|  | 1713 | if (rate_hi) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | *rate_hi = (u8) ((div >> 8) & 0xff); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1715 |  | 
|  | 1716 | if (rate_low && rate_hi) | 
|  | 1717 | dbg("%s - %d %02x %02x.", | 
|  | 1718 | __func__, baud_rate, *rate_hi, *rate_low); | 
|  | 1719 |  | 
|  | 1720 | return KEYSPAN_BAUD_RATE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | } | 
|  | 1722 |  | 
|  | 1723 | static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi, | 
|  | 1724 | u8 *rate_low, u8 *prescaler, int portnum) | 
|  | 1725 | { | 
|  | 1726 | u32 	b16,	/* baud rate times 16 (actual rate used internally) */ | 
|  | 1727 | clk,	/* clock with 13/8 prescaler */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1728 | div,	/* divisor using 13/8 prescaler */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | res,	/* resulting baud rate using 13/8 prescaler */ | 
|  | 1730 | diff,	/* error using 13/8 prescaler */ | 
|  | 1731 | smallest_diff; | 
|  | 1732 | u8	best_prescaler; | 
|  | 1733 | int	i; | 
|  | 1734 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1735 | dbg("%s - %d.", __func__, baud_rate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1737 | /* prevent divide by zero */ | 
|  | 1738 | b16 = baud_rate * 16L; | 
|  | 1739 | if (b16 == 0) | 
|  | 1740 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1742 | /* Calculate prescaler by trying them all and looking | 
|  | 1743 | for best fit */ | 
|  | 1744 |  | 
|  | 1745 | /* start with largest possible difference */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | smallest_diff = 0xffffffff; | 
|  | 1747 |  | 
|  | 1748 | /* 0 is an invalid prescaler, used as a flag */ | 
|  | 1749 | best_prescaler = 0; | 
|  | 1750 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1751 | for (i = 8; i <= 0xff; ++i) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | clk = (baudclk * 8) / (u32) i; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1753 |  | 
|  | 1754 | div = clk / b16; | 
|  | 1755 | if (div == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 |  | 
|  | 1758 | res = clk / div; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1759 | diff = (res > b16) ? (res-b16) : (b16-res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1761 | if (diff < smallest_diff) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | best_prescaler = i; | 
|  | 1763 | smallest_diff = diff; | 
|  | 1764 | } | 
|  | 1765 | } | 
|  | 1766 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1767 | if (best_prescaler == 0) | 
|  | 1768 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 |  | 
|  | 1770 | clk = (baudclk * 8) / (u32) best_prescaler; | 
|  | 1771 | div = clk / b16; | 
|  | 1772 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1773 | /* return the divisor and prescaler if non-null */ | 
|  | 1774 | if (rate_low) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | *rate_low = (u8) (div & 0xff); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1776 | if (rate_hi) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | *rate_hi = (u8) ((div >> 8) & 0xff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | if (prescaler) { | 
|  | 1779 | *prescaler = best_prescaler; | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1780 | /*  dbg("%s - %d %d", __func__, *prescaler, div); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1782 | return KEYSPAN_BAUD_RATE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | } | 
|  | 1784 |  | 
|  | 1785 | /* USA-28 supports different maximum baud rates on each port */ | 
|  | 1786 | static int keyspan_usa28_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi, | 
|  | 1787 | u8 *rate_low, u8 *prescaler, int portnum) | 
|  | 1788 | { | 
|  | 1789 | u32 	b16,	/* baud rate times 16 (actual rate used internally) */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1790 | div,	/* divisor */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | cnt;	/* inverse of divisor (programmed into 8051) */ | 
|  | 1792 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1793 | dbg("%s - %d.", __func__, baud_rate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 |  | 
|  | 1795 | /* prevent divide by zero */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1796 | b16 = baud_rate * 16L; | 
|  | 1797 | if (b16 == 0) | 
|  | 1798 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1800 | /* calculate the divisor and the counter (its inverse) */ | 
|  | 1801 | div = KEYSPAN_USA28_BAUDCLK / b16; | 
|  | 1802 | if (div == 0) | 
|  | 1803 | return KEYSPAN_INVALID_BAUD_RATE; | 
|  | 1804 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | cnt = 0 - div; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1807 | /* check for out of range, based on portnum, | 
|  | 1808 | and return result */ | 
|  | 1809 | if (portnum == 0) { | 
|  | 1810 | if (div > 0xffff) | 
|  | 1811 | return KEYSPAN_INVALID_BAUD_RATE; | 
|  | 1812 | } else { | 
|  | 1813 | if (portnum == 1) { | 
|  | 1814 | if (div > 0xff) | 
|  | 1815 | return KEYSPAN_INVALID_BAUD_RATE; | 
|  | 1816 | } else | 
|  | 1817 | return KEYSPAN_INVALID_BAUD_RATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | } | 
|  | 1819 |  | 
|  | 1820 | /* return the counter values if not NULL | 
|  | 1821 | (port 1 will ignore retHi) */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1822 | if (rate_low) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | *rate_low = (u8) (cnt & 0xff); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1824 | if (rate_hi) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | *rate_hi = (u8) ((cnt >> 8) & 0xff); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1826 | dbg("%s - %d OK.", __func__, baud_rate); | 
|  | 1827 | return KEYSPAN_BAUD_RATE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | } | 
|  | 1829 |  | 
|  | 1830 | static int keyspan_usa26_send_setup(struct usb_serial *serial, | 
|  | 1831 | struct usb_serial_port *port, | 
|  | 1832 | int reset_port) | 
|  | 1833 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1834 | struct keyspan_usa26_portControlMessage	msg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | struct keyspan_serial_private 		*s_priv; | 
|  | 1836 | struct keyspan_port_private 		*p_priv; | 
|  | 1837 | const struct keyspan_device_details	*d_details; | 
|  | 1838 | int 					outcont_urb; | 
|  | 1839 | struct urb				*this_urb; | 
|  | 1840 | int 					device_port, err; | 
|  | 1841 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1842 | dbg("%s reset=%d", __func__, reset_port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 |  | 
|  | 1844 | s_priv = usb_get_serial_data(serial); | 
|  | 1845 | p_priv = usb_get_serial_port_data(port); | 
|  | 1846 | d_details = s_priv->device_details; | 
|  | 1847 | device_port = port->number - port->serial->minor; | 
|  | 1848 |  | 
|  | 1849 | outcont_urb = d_details->outcont_endpoints[port->number]; | 
|  | 1850 | this_urb = p_priv->outcont_urb; | 
|  | 1851 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1852 | dbg("%s - endpoint %d", __func__, usb_pipeendpoint(this_urb->pipe)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 |  | 
|  | 1854 | /* Make sure we have an urb then send the message */ | 
|  | 1855 | if (this_urb == NULL) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1856 | dbg("%s - oops no urb.", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | return -1; | 
|  | 1858 | } | 
|  | 1859 |  | 
|  | 1860 | /* Save reset port val for resend. | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 1861 | Don't overwrite resend for open/close condition. */ | 
|  | 1862 | if ((reset_port + 1) > p_priv->resend_cont) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | p_priv->resend_cont = reset_port + 1; | 
|  | 1864 | if (this_urb->status == -EINPROGRESS) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1865 | /*  dbg("%s - already writing", __func__); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | mdelay(5); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1867 | return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | } | 
|  | 1869 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1870 | memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage)); | 
|  | 1871 |  | 
|  | 1872 | /* Only set baud rate if it's changed */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | if (p_priv->old_baud != p_priv->baud) { | 
|  | 1874 | p_priv->old_baud = p_priv->baud; | 
|  | 1875 | msg.setClocking = 0xff; | 
|  | 1876 | if (d_details->calculate_baud_rate | 
|  | 1877 | (p_priv->baud, d_details->baudclk, &msg.baudHi, | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1878 | &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) { | 
|  | 1879 | dbg("%s - Invalid baud rate %d requested, using 9600.", | 
|  | 1880 | __func__, p_priv->baud); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | msg.baudLo = 0; | 
|  | 1882 | msg.baudHi = 125;	/* Values for 9600 baud */ | 
|  | 1883 | msg.prescaler = 10; | 
|  | 1884 | } | 
|  | 1885 | msg.setPrescaler = 0xff; | 
|  | 1886 | } | 
|  | 1887 |  | 
|  | 1888 | msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1; | 
|  | 1889 | switch (p_priv->cflag & CSIZE) { | 
|  | 1890 | case CS5: | 
|  | 1891 | msg.lcr |= USA_DATABITS_5; | 
|  | 1892 | break; | 
|  | 1893 | case CS6: | 
|  | 1894 | msg.lcr |= USA_DATABITS_6; | 
|  | 1895 | break; | 
|  | 1896 | case CS7: | 
|  | 1897 | msg.lcr |= USA_DATABITS_7; | 
|  | 1898 | break; | 
|  | 1899 | case CS8: | 
|  | 1900 | msg.lcr |= USA_DATABITS_8; | 
|  | 1901 | break; | 
|  | 1902 | } | 
|  | 1903 | if (p_priv->cflag & PARENB) { | 
|  | 1904 | /* note USA_PARITY_NONE == 0 */ | 
|  | 1905 | msg.lcr |= (p_priv->cflag & PARODD)? | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1906 | USA_PARITY_ODD : USA_PARITY_EVEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | } | 
|  | 1908 | msg.setLcr = 0xff; | 
|  | 1909 |  | 
|  | 1910 | msg.ctsFlowControl = (p_priv->flow_control == flow_cts); | 
|  | 1911 | msg.xonFlowControl = 0; | 
|  | 1912 | msg.setFlowControl = 0xff; | 
|  | 1913 | msg.forwardingLength = 16; | 
|  | 1914 | msg.xonChar = 17; | 
|  | 1915 | msg.xoffChar = 19; | 
|  | 1916 |  | 
|  | 1917 | /* Opening port */ | 
|  | 1918 | if (reset_port == 1) { | 
|  | 1919 | msg._txOn = 1; | 
|  | 1920 | msg._txOff = 0; | 
|  | 1921 | msg.txFlush = 0; | 
|  | 1922 | msg.txBreak = 0; | 
|  | 1923 | msg.rxOn = 1; | 
|  | 1924 | msg.rxOff = 0; | 
|  | 1925 | msg.rxFlush = 1; | 
|  | 1926 | msg.rxForward = 0; | 
|  | 1927 | msg.returnStatus = 0; | 
|  | 1928 | msg.resetDataToggle = 0xff; | 
|  | 1929 | } | 
|  | 1930 |  | 
|  | 1931 | /* Closing port */ | 
|  | 1932 | else if (reset_port == 2) { | 
|  | 1933 | msg._txOn = 0; | 
|  | 1934 | msg._txOff = 1; | 
|  | 1935 | msg.txFlush = 0; | 
|  | 1936 | msg.txBreak = 0; | 
|  | 1937 | msg.rxOn = 0; | 
|  | 1938 | msg.rxOff = 1; | 
|  | 1939 | msg.rxFlush = 1; | 
|  | 1940 | msg.rxForward = 0; | 
|  | 1941 | msg.returnStatus = 0; | 
|  | 1942 | msg.resetDataToggle = 0; | 
|  | 1943 | } | 
|  | 1944 |  | 
|  | 1945 | /* Sending intermediate configs */ | 
|  | 1946 | else { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1947 | msg._txOn = (!p_priv->break_on); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | msg._txOff = 0; | 
|  | 1949 | msg.txFlush = 0; | 
|  | 1950 | msg.txBreak = (p_priv->break_on); | 
|  | 1951 | msg.rxOn = 0; | 
|  | 1952 | msg.rxOff = 0; | 
|  | 1953 | msg.rxFlush = 0; | 
|  | 1954 | msg.rxForward = 0; | 
|  | 1955 | msg.returnStatus = 0; | 
|  | 1956 | msg.resetDataToggle = 0x0; | 
|  | 1957 | } | 
|  | 1958 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1959 | /* Do handshaking outputs */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | msg.setTxTriState_setRts = 0xff; | 
|  | 1961 | msg.txTriState_rts = p_priv->rts_state; | 
|  | 1962 |  | 
|  | 1963 | msg.setHskoa_setDtr = 0xff; | 
|  | 1964 | msg.hskoa_dtr = p_priv->dtr_state; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1965 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | p_priv->resend_cont = 0; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1967 | memcpy(this_urb->transfer_buffer, &msg, sizeof(msg)); | 
|  | 1968 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | /* send the data out the device on control endpoint */ | 
|  | 1970 | this_urb->transfer_buffer_length = sizeof(msg); | 
|  | 1971 |  | 
|  | 1972 | this_urb->dev = serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1973 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 
|  | 1974 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1975 | dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | #if 0 | 
|  | 1977 | else { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1978 | dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | outcont_urb, this_urb->transfer_buffer_length, | 
|  | 1980 | usb_pipeendpoint(this_urb->pipe)); | 
|  | 1981 | } | 
|  | 1982 | #endif | 
|  | 1983 |  | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 1984 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | } | 
|  | 1986 |  | 
|  | 1987 | static int keyspan_usa28_send_setup(struct usb_serial *serial, | 
|  | 1988 | struct usb_serial_port *port, | 
|  | 1989 | int reset_port) | 
|  | 1990 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1991 | struct keyspan_usa28_portControlMessage	msg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | struct keyspan_serial_private	 	*s_priv; | 
|  | 1993 | struct keyspan_port_private 		*p_priv; | 
|  | 1994 | const struct keyspan_device_details	*d_details; | 
|  | 1995 | struct urb				*this_urb; | 
|  | 1996 | int 					device_port, err; | 
|  | 1997 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 1998 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 |  | 
|  | 2000 | s_priv = usb_get_serial_data(serial); | 
|  | 2001 | p_priv = usb_get_serial_port_data(port); | 
|  | 2002 | d_details = s_priv->device_details; | 
|  | 2003 | device_port = port->number - port->serial->minor; | 
|  | 2004 |  | 
|  | 2005 | /* only do something if we have a bulk out endpoint */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2006 | this_urb = p_priv->outcont_urb; | 
|  | 2007 | if (this_urb == NULL) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2008 | dbg("%s - oops no urb.", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | return -1; | 
|  | 2010 | } | 
|  | 2011 |  | 
|  | 2012 | /* Save reset port val for resend. | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2013 | Don't overwrite resend for open/close condition. */ | 
|  | 2014 | if ((reset_port + 1) > p_priv->resend_cont) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | p_priv->resend_cont = reset_port + 1; | 
|  | 2016 | if (this_urb->status == -EINPROGRESS) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2017 | dbg("%s already writing", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | mdelay(5); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2019 | return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | } | 
|  | 2021 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2022 | memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 |  | 
|  | 2024 | msg.setBaudRate = 1; | 
|  | 2025 | if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk, | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2026 | &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE) { | 
|  | 2027 | dbg("%s - Invalid baud rate requested %d.", | 
|  | 2028 | __func__, p_priv->baud); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | msg.baudLo = 0xff; | 
|  | 2030 | msg.baudHi = 0xb2;	/* Values for 9600 baud */ | 
|  | 2031 | } | 
|  | 2032 |  | 
|  | 2033 | /* If parity is enabled, we must calculate it ourselves. */ | 
|  | 2034 | msg.parity = 0;		/* XXX for now */ | 
|  | 2035 |  | 
|  | 2036 | msg.ctsFlowControl = (p_priv->flow_control == flow_cts); | 
|  | 2037 | msg.xonFlowControl = 0; | 
|  | 2038 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2039 | /* Do handshaking outputs, DTR is inverted relative to RTS */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | msg.rts = p_priv->rts_state; | 
|  | 2041 | msg.dtr = p_priv->dtr_state; | 
|  | 2042 |  | 
|  | 2043 | msg.forwardingLength = 16; | 
|  | 2044 | msg.forwardMs = 10; | 
|  | 2045 | msg.breakThreshold = 45; | 
|  | 2046 | msg.xonChar = 17; | 
|  | 2047 | msg.xoffChar = 19; | 
|  | 2048 |  | 
|  | 2049 | /*msg.returnStatus = 1; | 
|  | 2050 | msg.resetDataToggle = 0xff;*/ | 
|  | 2051 | /* Opening port */ | 
|  | 2052 | if (reset_port == 1) { | 
|  | 2053 | msg._txOn = 1; | 
|  | 2054 | msg._txOff = 0; | 
|  | 2055 | msg.txFlush = 0; | 
|  | 2056 | msg.txForceXoff = 0; | 
|  | 2057 | msg.txBreak = 0; | 
|  | 2058 | msg.rxOn = 1; | 
|  | 2059 | msg.rxOff = 0; | 
|  | 2060 | msg.rxFlush = 1; | 
|  | 2061 | msg.rxForward = 0; | 
|  | 2062 | msg.returnStatus = 0; | 
|  | 2063 | msg.resetDataToggle = 0xff; | 
|  | 2064 | } | 
|  | 2065 | /* Closing port */ | 
|  | 2066 | else if (reset_port == 2) { | 
|  | 2067 | msg._txOn = 0; | 
|  | 2068 | msg._txOff = 1; | 
|  | 2069 | msg.txFlush = 0; | 
|  | 2070 | msg.txForceXoff = 0; | 
|  | 2071 | msg.txBreak = 0; | 
|  | 2072 | msg.rxOn = 0; | 
|  | 2073 | msg.rxOff = 1; | 
|  | 2074 | msg.rxFlush = 1; | 
|  | 2075 | msg.rxForward = 0; | 
|  | 2076 | msg.returnStatus = 0; | 
|  | 2077 | msg.resetDataToggle = 0; | 
|  | 2078 | } | 
|  | 2079 | /* Sending intermediate configs */ | 
|  | 2080 | else { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2081 | msg._txOn = (!p_priv->break_on); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | msg._txOff = 0; | 
|  | 2083 | msg.txFlush = 0; | 
|  | 2084 | msg.txForceXoff = 0; | 
|  | 2085 | msg.txBreak = (p_priv->break_on); | 
|  | 2086 | msg.rxOn = 0; | 
|  | 2087 | msg.rxOff = 0; | 
|  | 2088 | msg.rxFlush = 0; | 
|  | 2089 | msg.rxForward = 0; | 
|  | 2090 | msg.returnStatus = 0; | 
|  | 2091 | msg.resetDataToggle = 0x0; | 
|  | 2092 | } | 
|  | 2093 |  | 
|  | 2094 | p_priv->resend_cont = 0; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2095 | memcpy(this_urb->transfer_buffer, &msg, sizeof(msg)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 |  | 
|  | 2097 | /* send the data out the device on control endpoint */ | 
|  | 2098 | this_urb->transfer_buffer_length = sizeof(msg); | 
|  | 2099 |  | 
|  | 2100 | this_urb->dev = serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2101 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 
|  | 2102 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2103 | dbg("%s - usb_submit_urb(setup) failed", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | #if 0 | 
|  | 2105 | else { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2106 | dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | this_urb->transfer_buffer_length); | 
|  | 2108 | } | 
|  | 2109 | #endif | 
|  | 2110 |  | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 2111 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | } | 
|  | 2113 |  | 
|  | 2114 | static int keyspan_usa49_send_setup(struct usb_serial *serial, | 
|  | 2115 | struct usb_serial_port *port, | 
|  | 2116 | int reset_port) | 
|  | 2117 | { | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2118 | struct keyspan_usa49_portControlMessage	msg; | 
|  | 2119 | struct usb_ctrlrequest 			*dr = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | struct keyspan_serial_private 		*s_priv; | 
|  | 2121 | struct keyspan_port_private 		*p_priv; | 
|  | 2122 | const struct keyspan_device_details	*d_details; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | struct urb				*this_urb; | 
|  | 2124 | int 					err, device_port; | 
|  | 2125 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2126 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 |  | 
|  | 2128 | s_priv = usb_get_serial_data(serial); | 
|  | 2129 | p_priv = usb_get_serial_port_data(port); | 
|  | 2130 | d_details = s_priv->device_details; | 
|  | 2131 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | this_urb = s_priv->glocont_urb; | 
|  | 2133 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2134 | /* Work out which port within the device is being setup */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | device_port = port->number - port->serial->minor; | 
|  | 2136 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2137 | dbg("%s - endpoint %d port %d (%d)", | 
|  | 2138 | __func__, usb_pipeendpoint(this_urb->pipe), | 
|  | 2139 | port->number, device_port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 |  | 
|  | 2141 | /* Make sure we have an urb then send the message */ | 
|  | 2142 | if (this_urb == NULL) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2143 | dbg("%s - oops no urb for port %d.", __func__, port->number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | return -1; | 
|  | 2145 | } | 
|  | 2146 |  | 
|  | 2147 | /* Save reset port val for resend. | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2148 | Don't overwrite resend for open/close condition. */ | 
|  | 2149 | if ((reset_port + 1) > p_priv->resend_cont) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | p_priv->resend_cont = reset_port + 1; | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2151 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | if (this_urb->status == -EINPROGRESS) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2153 | /*  dbg("%s - already writing", __func__); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | mdelay(5); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2155 | return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | } | 
|  | 2157 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2158 | memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 |  | 
|  | 2160 | /*msg.portNumber = port->number;*/ | 
|  | 2161 | msg.portNumber = device_port; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2162 |  | 
|  | 2163 | /* Only set baud rate if it's changed */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | if (p_priv->old_baud != p_priv->baud) { | 
|  | 2165 | p_priv->old_baud = p_priv->baud; | 
|  | 2166 | msg.setClocking = 0xff; | 
|  | 2167 | if (d_details->calculate_baud_rate | 
|  | 2168 | (p_priv->baud, d_details->baudclk, &msg.baudHi, | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2169 | &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) { | 
|  | 2170 | dbg("%s - Invalid baud rate %d requested, using 9600.", | 
|  | 2171 | __func__, p_priv->baud); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | msg.baudLo = 0; | 
|  | 2173 | msg.baudHi = 125;	/* Values for 9600 baud */ | 
|  | 2174 | msg.prescaler = 10; | 
|  | 2175 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2176 | /* msg.setPrescaler = 0xff; */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } | 
|  | 2178 |  | 
|  | 2179 | msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1; | 
|  | 2180 | switch (p_priv->cflag & CSIZE) { | 
|  | 2181 | case CS5: | 
|  | 2182 | msg.lcr |= USA_DATABITS_5; | 
|  | 2183 | break; | 
|  | 2184 | case CS6: | 
|  | 2185 | msg.lcr |= USA_DATABITS_6; | 
|  | 2186 | break; | 
|  | 2187 | case CS7: | 
|  | 2188 | msg.lcr |= USA_DATABITS_7; | 
|  | 2189 | break; | 
|  | 2190 | case CS8: | 
|  | 2191 | msg.lcr |= USA_DATABITS_8; | 
|  | 2192 | break; | 
|  | 2193 | } | 
|  | 2194 | if (p_priv->cflag & PARENB) { | 
|  | 2195 | /* note USA_PARITY_NONE == 0 */ | 
|  | 2196 | msg.lcr |= (p_priv->cflag & PARODD)? | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2197 | USA_PARITY_ODD : USA_PARITY_EVEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | } | 
|  | 2199 | msg.setLcr = 0xff; | 
|  | 2200 |  | 
|  | 2201 | msg.ctsFlowControl = (p_priv->flow_control == flow_cts); | 
|  | 2202 | msg.xonFlowControl = 0; | 
|  | 2203 | msg.setFlowControl = 0xff; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2204 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | msg.forwardingLength = 16; | 
|  | 2206 | msg.xonChar = 17; | 
|  | 2207 | msg.xoffChar = 19; | 
|  | 2208 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2209 | /* Opening port */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | if (reset_port == 1) { | 
|  | 2211 | msg._txOn = 1; | 
|  | 2212 | msg._txOff = 0; | 
|  | 2213 | msg.txFlush = 0; | 
|  | 2214 | msg.txBreak = 0; | 
|  | 2215 | msg.rxOn = 1; | 
|  | 2216 | msg.rxOff = 0; | 
|  | 2217 | msg.rxFlush = 1; | 
|  | 2218 | msg.rxForward = 0; | 
|  | 2219 | msg.returnStatus = 0; | 
|  | 2220 | msg.resetDataToggle = 0xff; | 
|  | 2221 | msg.enablePort = 1; | 
|  | 2222 | msg.disablePort = 0; | 
|  | 2223 | } | 
|  | 2224 | /* Closing port */ | 
|  | 2225 | else if (reset_port == 2) { | 
|  | 2226 | msg._txOn = 0; | 
|  | 2227 | msg._txOff = 1; | 
|  | 2228 | msg.txFlush = 0; | 
|  | 2229 | msg.txBreak = 0; | 
|  | 2230 | msg.rxOn = 0; | 
|  | 2231 | msg.rxOff = 1; | 
|  | 2232 | msg.rxFlush = 1; | 
|  | 2233 | msg.rxForward = 0; | 
|  | 2234 | msg.returnStatus = 0; | 
|  | 2235 | msg.resetDataToggle = 0; | 
|  | 2236 | msg.enablePort = 0; | 
|  | 2237 | msg.disablePort = 1; | 
|  | 2238 | } | 
|  | 2239 | /* Sending intermediate configs */ | 
|  | 2240 | else { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2241 | msg._txOn = (!p_priv->break_on); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | msg._txOff = 0; | 
|  | 2243 | msg.txFlush = 0; | 
|  | 2244 | msg.txBreak = (p_priv->break_on); | 
|  | 2245 | msg.rxOn = 0; | 
|  | 2246 | msg.rxOff = 0; | 
|  | 2247 | msg.rxFlush = 0; | 
|  | 2248 | msg.rxForward = 0; | 
|  | 2249 | msg.returnStatus = 0; | 
|  | 2250 | msg.resetDataToggle = 0x0; | 
|  | 2251 | msg.enablePort = 0; | 
|  | 2252 | msg.disablePort = 0; | 
|  | 2253 | } | 
|  | 2254 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2255 | /* Do handshaking outputs */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | msg.setRts = 0xff; | 
|  | 2257 | msg.rts = p_priv->rts_state; | 
|  | 2258 |  | 
|  | 2259 | msg.setDtr = 0xff; | 
|  | 2260 | msg.dtr = p_priv->dtr_state; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2261 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | p_priv->resend_cont = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2264 | /* if the device is a 49wg, we send control message on usb | 
|  | 2265 | control EP 0 */ | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2266 |  | 
|  | 2267 | if (d_details->product_id == keyspan_usa49wg_product_id) { | 
|  | 2268 | dr = (void *)(s_priv->ctrl_buf); | 
|  | 2269 | dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT; | 
|  | 2270 | dr->bRequest = 0xB0;	/* 49wg control message */; | 
|  | 2271 | dr->wValue = 0; | 
|  | 2272 | dr->wIndex = 0; | 
|  | 2273 | dr->wLength = cpu_to_le16(sizeof(msg)); | 
|  | 2274 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2275 | memcpy(s_priv->glocont_buf, &msg, sizeof(msg)); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2276 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2277 | usb_fill_control_urb(this_urb, serial->dev, | 
|  | 2278 | usb_sndctrlpipe(serial->dev, 0), | 
|  | 2279 | (unsigned char *)dr, s_priv->glocont_buf, | 
|  | 2280 | sizeof(msg), usa49_glocont_callback, serial); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2281 |  | 
|  | 2282 | } else { | 
|  | 2283 | memcpy(this_urb->transfer_buffer, &msg, sizeof(msg)); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2284 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2285 | /* send the data out the device on control endpoint */ | 
|  | 2286 | this_urb->transfer_buffer_length = sizeof(msg); | 
|  | 2287 |  | 
|  | 2288 | this_urb->dev = serial->dev; | 
|  | 2289 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2290 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 
|  | 2291 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2292 | dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | #if 0 | 
|  | 2294 | else { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2295 | dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__, | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2296 | outcont_urb, this_urb->transfer_buffer_length, | 
|  | 2297 | usb_pipeendpoint(this_urb->pipe)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | } | 
|  | 2299 | #endif | 
|  | 2300 |  | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 2301 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | } | 
|  | 2303 |  | 
|  | 2304 | static int keyspan_usa90_send_setup(struct usb_serial *serial, | 
|  | 2305 | struct usb_serial_port *port, | 
|  | 2306 | int reset_port) | 
|  | 2307 | { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2308 | struct keyspan_usa90_portControlMessage	msg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | struct keyspan_serial_private 		*s_priv; | 
|  | 2310 | struct keyspan_port_private 		*p_priv; | 
|  | 2311 | const struct keyspan_device_details	*d_details; | 
|  | 2312 | struct urb				*this_urb; | 
|  | 2313 | int 					err; | 
|  | 2314 | u8						prescaler; | 
|  | 2315 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2316 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 |  | 
|  | 2318 | s_priv = usb_get_serial_data(serial); | 
|  | 2319 | p_priv = usb_get_serial_port_data(port); | 
|  | 2320 | d_details = s_priv->device_details; | 
|  | 2321 |  | 
|  | 2322 | /* only do something if we have a bulk out endpoint */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2323 | this_urb = p_priv->outcont_urb; | 
|  | 2324 | if (this_urb == NULL) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2325 | dbg("%s - oops no urb.", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | return -1; | 
|  | 2327 | } | 
|  | 2328 |  | 
|  | 2329 | /* Save reset port val for resend. | 
|  | 2330 | Don't overwrite resend for open/close condition. */ | 
|  | 2331 | if ((reset_port + 1) > p_priv->resend_cont) | 
|  | 2332 | p_priv->resend_cont = reset_port + 1; | 
|  | 2333 | if (this_urb->status == -EINPROGRESS) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2334 | dbg("%s already writing", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | mdelay(5); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2336 | return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | } | 
|  | 2338 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2339 | memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2341 | /* Only set baud rate if it's changed */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | if (p_priv->old_baud != p_priv->baud) { | 
|  | 2343 | p_priv->old_baud = p_priv->baud; | 
|  | 2344 | msg.setClocking = 0x01; | 
|  | 2345 | if (d_details->calculate_baud_rate | 
|  | 2346 | (p_priv->baud, d_details->baudclk, &msg.baudHi, | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2347 | &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) { | 
|  | 2348 | dbg("%s - Invalid baud rate %d requested, using 9600.", | 
|  | 2349 | __func__, p_priv->baud); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | p_priv->baud = 9600; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2351 | d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | &msg.baudHi, &msg.baudLo, &prescaler, 0); | 
|  | 2353 | } | 
|  | 2354 | msg.setRxMode = 1; | 
|  | 2355 | msg.setTxMode = 1; | 
|  | 2356 | } | 
|  | 2357 |  | 
|  | 2358 | /* modes must always be correctly specified */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2359 | if (p_priv->baud > 57600) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | msg.rxMode = RXMODE_DMA; | 
|  | 2361 | msg.txMode = TXMODE_DMA; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2362 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | msg.rxMode = RXMODE_BYHAND; | 
|  | 2364 | msg.txMode = TXMODE_BYHAND; | 
|  | 2365 | } | 
|  | 2366 |  | 
|  | 2367 | msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1; | 
|  | 2368 | switch (p_priv->cflag & CSIZE) { | 
|  | 2369 | case CS5: | 
|  | 2370 | msg.lcr |= USA_DATABITS_5; | 
|  | 2371 | break; | 
|  | 2372 | case CS6: | 
|  | 2373 | msg.lcr |= USA_DATABITS_6; | 
|  | 2374 | break; | 
|  | 2375 | case CS7: | 
|  | 2376 | msg.lcr |= USA_DATABITS_7; | 
|  | 2377 | break; | 
|  | 2378 | case CS8: | 
|  | 2379 | msg.lcr |= USA_DATABITS_8; | 
|  | 2380 | break; | 
|  | 2381 | } | 
|  | 2382 | if (p_priv->cflag & PARENB) { | 
|  | 2383 | /* note USA_PARITY_NONE == 0 */ | 
|  | 2384 | msg.lcr |= (p_priv->cflag & PARODD)? | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2385 | USA_PARITY_ODD : USA_PARITY_EVEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | } | 
|  | 2387 | if (p_priv->old_cflag != p_priv->cflag) { | 
|  | 2388 | p_priv->old_cflag = p_priv->cflag; | 
|  | 2389 | msg.setLcr = 0x01; | 
|  | 2390 | } | 
|  | 2391 |  | 
|  | 2392 | if (p_priv->flow_control == flow_cts) | 
|  | 2393 | msg.txFlowControl = TXFLOW_CTS; | 
|  | 2394 | msg.setTxFlowControl = 0x01; | 
|  | 2395 | msg.setRxFlowControl = 0x01; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2396 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | msg.rxForwardingLength = 16; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2398 | msg.rxForwardingTimeout = 16; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | msg.txAckSetting = 0; | 
|  | 2400 | msg.xonChar = 17; | 
|  | 2401 | msg.xoffChar = 19; | 
|  | 2402 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2403 | /* Opening port */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | if (reset_port == 1) { | 
|  | 2405 | msg.portEnabled = 1; | 
|  | 2406 | msg.rxFlush = 1; | 
|  | 2407 | msg.txBreak = (p_priv->break_on); | 
|  | 2408 | } | 
|  | 2409 | /* Closing port */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2410 | else if (reset_port == 2) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | msg.portEnabled = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | /* Sending intermediate configs */ | 
|  | 2413 | else { | 
| Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2414 | if (port->port.count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | msg.portEnabled = 1; | 
|  | 2416 | msg.txBreak = (p_priv->break_on); | 
|  | 2417 | } | 
|  | 2418 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2419 | /* Do handshaking outputs */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | msg.setRts = 0x01; | 
|  | 2421 | msg.rts = p_priv->rts_state; | 
|  | 2422 |  | 
|  | 2423 | msg.setDtr = 0x01; | 
|  | 2424 | msg.dtr = p_priv->dtr_state; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2425 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | p_priv->resend_cont = 0; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2427 | memcpy(this_urb->transfer_buffer, &msg, sizeof(msg)); | 
|  | 2428 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | /* send the data out the device on control endpoint */ | 
|  | 2430 | this_urb->transfer_buffer_length = sizeof(msg); | 
|  | 2431 |  | 
|  | 2432 | this_urb->dev = serial->dev; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2433 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 
|  | 2434 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2435 | dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err); | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 2436 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | } | 
|  | 2438 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2439 | static int keyspan_usa67_send_setup(struct usb_serial *serial, | 
|  | 2440 | struct usb_serial_port *port, | 
|  | 2441 | int reset_port) | 
|  | 2442 | { | 
|  | 2443 | struct keyspan_usa67_portControlMessage	msg; | 
|  | 2444 | struct keyspan_serial_private 		*s_priv; | 
|  | 2445 | struct keyspan_port_private 		*p_priv; | 
|  | 2446 | const struct keyspan_device_details	*d_details; | 
|  | 2447 | struct urb				*this_urb; | 
|  | 2448 | int 					err, device_port; | 
|  | 2449 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2450 | dbg("%s", __func__); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2451 |  | 
|  | 2452 | s_priv = usb_get_serial_data(serial); | 
|  | 2453 | p_priv = usb_get_serial_port_data(port); | 
|  | 2454 | d_details = s_priv->device_details; | 
|  | 2455 |  | 
|  | 2456 | this_urb = s_priv->glocont_urb; | 
|  | 2457 |  | 
|  | 2458 | /* Work out which port within the device is being setup */ | 
|  | 2459 | device_port = port->number - port->serial->minor; | 
|  | 2460 |  | 
|  | 2461 | /* Make sure we have an urb then send the message */ | 
|  | 2462 | if (this_urb == NULL) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2463 | dbg("%s - oops no urb for port %d.", __func__, | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2464 | port->number); | 
|  | 2465 | return -1; | 
|  | 2466 | } | 
|  | 2467 |  | 
|  | 2468 | /* Save reset port val for resend. | 
|  | 2469 | Don't overwrite resend for open/close condition. */ | 
|  | 2470 | if ((reset_port + 1) > p_priv->resend_cont) | 
|  | 2471 | p_priv->resend_cont = reset_port + 1; | 
|  | 2472 | if (this_urb->status == -EINPROGRESS) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2473 | /*  dbg("%s - already writing", __func__); */ | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2474 | mdelay(5); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2475 | return -1; | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2476 | } | 
|  | 2477 |  | 
|  | 2478 | memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage)); | 
|  | 2479 |  | 
|  | 2480 | msg.port = device_port; | 
|  | 2481 |  | 
|  | 2482 | /* Only set baud rate if it's changed */ | 
|  | 2483 | if (p_priv->old_baud != p_priv->baud) { | 
|  | 2484 | p_priv->old_baud = p_priv->baud; | 
|  | 2485 | msg.setClocking = 0xff; | 
|  | 2486 | if (d_details->calculate_baud_rate | 
|  | 2487 | (p_priv->baud, d_details->baudclk, &msg.baudHi, | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2488 | &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) { | 
|  | 2489 | dbg("%s - Invalid baud rate %d requested, using 9600.", | 
|  | 2490 | __func__, p_priv->baud); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2491 | msg.baudLo = 0; | 
|  | 2492 | msg.baudHi = 125;	/* Values for 9600 baud */ | 
|  | 2493 | msg.prescaler = 10; | 
|  | 2494 | } | 
|  | 2495 | msg.setPrescaler = 0xff; | 
|  | 2496 | } | 
|  | 2497 |  | 
|  | 2498 | msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1; | 
|  | 2499 | switch (p_priv->cflag & CSIZE) { | 
|  | 2500 | case CS5: | 
|  | 2501 | msg.lcr |= USA_DATABITS_5; | 
|  | 2502 | break; | 
|  | 2503 | case CS6: | 
|  | 2504 | msg.lcr |= USA_DATABITS_6; | 
|  | 2505 | break; | 
|  | 2506 | case CS7: | 
|  | 2507 | msg.lcr |= USA_DATABITS_7; | 
|  | 2508 | break; | 
|  | 2509 | case CS8: | 
|  | 2510 | msg.lcr |= USA_DATABITS_8; | 
|  | 2511 | break; | 
|  | 2512 | } | 
|  | 2513 | if (p_priv->cflag & PARENB) { | 
|  | 2514 | /* note USA_PARITY_NONE == 0 */ | 
|  | 2515 | msg.lcr |= (p_priv->cflag & PARODD)? | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2516 | USA_PARITY_ODD : USA_PARITY_EVEN; | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2517 | } | 
|  | 2518 | msg.setLcr = 0xff; | 
|  | 2519 |  | 
|  | 2520 | msg.ctsFlowControl = (p_priv->flow_control == flow_cts); | 
|  | 2521 | msg.xonFlowControl = 0; | 
|  | 2522 | msg.setFlowControl = 0xff; | 
|  | 2523 | msg.forwardingLength = 16; | 
|  | 2524 | msg.xonChar = 17; | 
|  | 2525 | msg.xoffChar = 19; | 
|  | 2526 |  | 
|  | 2527 | if (reset_port == 1) { | 
|  | 2528 | /* Opening port */ | 
|  | 2529 | msg._txOn = 1; | 
|  | 2530 | msg._txOff = 0; | 
|  | 2531 | msg.txFlush = 0; | 
|  | 2532 | msg.txBreak = 0; | 
|  | 2533 | msg.rxOn = 1; | 
|  | 2534 | msg.rxOff = 0; | 
|  | 2535 | msg.rxFlush = 1; | 
|  | 2536 | msg.rxForward = 0; | 
|  | 2537 | msg.returnStatus = 0; | 
|  | 2538 | msg.resetDataToggle = 0xff; | 
|  | 2539 | } else if (reset_port == 2) { | 
|  | 2540 | /* Closing port */ | 
|  | 2541 | msg._txOn = 0; | 
|  | 2542 | msg._txOff = 1; | 
|  | 2543 | msg.txFlush = 0; | 
|  | 2544 | msg.txBreak = 0; | 
|  | 2545 | msg.rxOn = 0; | 
|  | 2546 | msg.rxOff = 1; | 
|  | 2547 | msg.rxFlush = 1; | 
|  | 2548 | msg.rxForward = 0; | 
|  | 2549 | msg.returnStatus = 0; | 
|  | 2550 | msg.resetDataToggle = 0; | 
|  | 2551 | } else { | 
|  | 2552 | /* Sending intermediate configs */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2553 | msg._txOn = (!p_priv->break_on); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2554 | msg._txOff = 0; | 
|  | 2555 | msg.txFlush = 0; | 
|  | 2556 | msg.txBreak = (p_priv->break_on); | 
|  | 2557 | msg.rxOn = 0; | 
|  | 2558 | msg.rxOff = 0; | 
|  | 2559 | msg.rxFlush = 0; | 
|  | 2560 | msg.rxForward = 0; | 
|  | 2561 | msg.returnStatus = 0; | 
|  | 2562 | msg.resetDataToggle = 0x0; | 
|  | 2563 | } | 
|  | 2564 |  | 
|  | 2565 | /* Do handshaking outputs */ | 
|  | 2566 | msg.setTxTriState_setRts = 0xff; | 
|  | 2567 | msg.txTriState_rts = p_priv->rts_state; | 
|  | 2568 |  | 
|  | 2569 | msg.setHskoa_setDtr = 0xff; | 
|  | 2570 | msg.hskoa_dtr = p_priv->dtr_state; | 
|  | 2571 |  | 
|  | 2572 | p_priv->resend_cont = 0; | 
|  | 2573 |  | 
|  | 2574 | memcpy(this_urb->transfer_buffer, &msg, sizeof(msg)); | 
|  | 2575 |  | 
|  | 2576 | /* send the data out the device on control endpoint */ | 
|  | 2577 | this_urb->transfer_buffer_length = sizeof(msg); | 
|  | 2578 | this_urb->dev = serial->dev; | 
|  | 2579 |  | 
|  | 2580 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 
|  | 2581 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2582 | dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2583 | err); | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 2584 | return 0; | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2585 | } | 
|  | 2586 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | static void keyspan_send_setup(struct usb_serial_port *port, int reset_port) | 
|  | 2588 | { | 
|  | 2589 | struct usb_serial *serial = port->serial; | 
|  | 2590 | struct keyspan_serial_private *s_priv; | 
|  | 2591 | const struct keyspan_device_details *d_details; | 
|  | 2592 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2593 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 |  | 
|  | 2595 | s_priv = usb_get_serial_data(serial); | 
|  | 2596 | d_details = s_priv->device_details; | 
|  | 2597 |  | 
|  | 2598 | switch (d_details->msg_format) { | 
|  | 2599 | case msg_usa26: | 
|  | 2600 | keyspan_usa26_send_setup(serial, port, reset_port); | 
|  | 2601 | break; | 
|  | 2602 | case msg_usa28: | 
|  | 2603 | keyspan_usa28_send_setup(serial, port, reset_port); | 
|  | 2604 | break; | 
|  | 2605 | case msg_usa49: | 
|  | 2606 | keyspan_usa49_send_setup(serial, port, reset_port); | 
|  | 2607 | break; | 
|  | 2608 | case msg_usa90: | 
|  | 2609 | keyspan_usa90_send_setup(serial, port, reset_port); | 
|  | 2610 | break; | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2611 | case msg_usa67: | 
|  | 2612 | keyspan_usa67_send_setup(serial, port, reset_port); | 
|  | 2613 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | } | 
|  | 2615 | } | 
|  | 2616 |  | 
|  | 2617 |  | 
|  | 2618 | /* Gets called by the "real" driver (ie once firmware is loaded | 
|  | 2619 | and renumeration has taken place. */ | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2620 | static int keyspan_startup(struct usb_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | { | 
|  | 2622 | int				i, err; | 
|  | 2623 | struct usb_serial_port		*port; | 
|  | 2624 | struct keyspan_serial_private 	*s_priv; | 
|  | 2625 | struct keyspan_port_private	*p_priv; | 
|  | 2626 | const struct keyspan_device_details	*d_details; | 
|  | 2627 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2628 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 |  | 
|  | 2630 | for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i) | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2631 | if (d_details->product_id == | 
|  | 2632 | le16_to_cpu(serial->dev->descriptor.idProduct)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | break; | 
|  | 2634 | if (d_details == NULL) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2635 | dev_err(&serial->dev->dev, "%s - unknown product id %x\n", | 
|  | 2636 | __func__, le16_to_cpu(serial->dev->descriptor.idProduct)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | return 1; | 
|  | 2638 | } | 
|  | 2639 |  | 
|  | 2640 | /* Setup private data for serial driver */ | 
| Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 2641 | s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | if (!s_priv) { | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2643 | dbg("%s - kmalloc for keyspan_serial_private failed.", | 
|  | 2644 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | return -ENOMEM; | 
|  | 2646 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 |  | 
|  | 2648 | s_priv->device_details = d_details; | 
|  | 2649 | usb_set_serial_data(serial, s_priv); | 
|  | 2650 |  | 
|  | 2651 | /* Now setup per port private data */ | 
|  | 2652 | for (i = 0; i < serial->num_ports; i++) { | 
|  | 2653 | port = serial->port[i]; | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2654 | p_priv = kzalloc(sizeof(struct keyspan_port_private), | 
|  | 2655 | GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | if (!p_priv) { | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2657 | dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i); | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2658 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | p_priv->device_details = d_details; | 
|  | 2661 | usb_set_serial_port_data(port, p_priv); | 
|  | 2662 | } | 
|  | 2663 |  | 
|  | 2664 | keyspan_setup_urbs(serial); | 
|  | 2665 |  | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2666 | if (s_priv->instat_urb != NULL) { | 
|  | 2667 | s_priv->instat_urb->dev = serial->dev; | 
|  | 2668 | err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL); | 
|  | 2669 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2670 | dbg("%s - submit instat urb failed %d", __func__, | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2671 | err); | 
|  | 2672 | } | 
|  | 2673 | if (s_priv->indat_urb != NULL) { | 
|  | 2674 | s_priv->indat_urb->dev = serial->dev; | 
|  | 2675 | err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL); | 
|  | 2676 | if (err != 0) | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2677 | dbg("%s - submit indat urb failed %d", __func__, | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2678 | err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | } | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2680 |  | 
| Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 2681 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | } | 
|  | 2683 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2684 | static void keyspan_shutdown(struct usb_serial *serial) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | { | 
|  | 2686 | int				i, j; | 
|  | 2687 | struct usb_serial_port		*port; | 
|  | 2688 | struct keyspan_serial_private 	*s_priv; | 
|  | 2689 | struct keyspan_port_private	*p_priv; | 
|  | 2690 |  | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2691 | dbg("%s", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 |  | 
|  | 2693 | s_priv = usb_get_serial_data(serial); | 
|  | 2694 |  | 
|  | 2695 | /* Stop reading/writing urbs */ | 
|  | 2696 | stop_urb(s_priv->instat_urb); | 
|  | 2697 | stop_urb(s_priv->glocont_urb); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2698 | stop_urb(s_priv->indat_urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | for (i = 0; i < serial->num_ports; ++i) { | 
|  | 2700 | port = serial->port[i]; | 
|  | 2701 | p_priv = usb_get_serial_port_data(port); | 
|  | 2702 | stop_urb(p_priv->inack_urb); | 
|  | 2703 | stop_urb(p_priv->outcont_urb); | 
|  | 2704 | for (j = 0; j < 2; j++) { | 
|  | 2705 | stop_urb(p_priv->in_urbs[j]); | 
|  | 2706 | stop_urb(p_priv->out_urbs[j]); | 
|  | 2707 | } | 
|  | 2708 | } | 
|  | 2709 |  | 
|  | 2710 | /* Now free them */ | 
| Mariusz Kozlowski | 1cadc13 | 2006-11-08 15:36:34 +0100 | [diff] [blame] | 2711 | usb_free_urb(s_priv->instat_urb); | 
| Lucy McCoy | 0ca1268 | 2007-05-18 12:10:41 -0700 | [diff] [blame] | 2712 | usb_free_urb(s_priv->indat_urb); | 
| Mariusz Kozlowski | 1cadc13 | 2006-11-08 15:36:34 +0100 | [diff] [blame] | 2713 | usb_free_urb(s_priv->glocont_urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | for (i = 0; i < serial->num_ports; ++i) { | 
|  | 2715 | port = serial->port[i]; | 
|  | 2716 | p_priv = usb_get_serial_port_data(port); | 
| Mariusz Kozlowski | 1cadc13 | 2006-11-08 15:36:34 +0100 | [diff] [blame] | 2717 | usb_free_urb(p_priv->inack_urb); | 
|  | 2718 | usb_free_urb(p_priv->outcont_urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | for (j = 0; j < 2; j++) { | 
| Mariusz Kozlowski | 1cadc13 | 2006-11-08 15:36:34 +0100 | [diff] [blame] | 2720 | usb_free_urb(p_priv->in_urbs[j]); | 
|  | 2721 | usb_free_urb(p_priv->out_urbs[j]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | } | 
|  | 2723 | } | 
|  | 2724 |  | 
|  | 2725 | /*  dbg("Freeing serial->private."); */ | 
|  | 2726 | kfree(s_priv); | 
|  | 2727 |  | 
|  | 2728 | /*  dbg("Freeing port->private."); */ | 
|  | 2729 | /* Now free per port private data */ | 
|  | 2730 | for (i = 0; i < serial->num_ports; i++) { | 
|  | 2731 | port = serial->port[i]; | 
|  | 2732 | kfree(usb_get_serial_port_data(port)); | 
|  | 2733 | } | 
|  | 2734 | } | 
|  | 2735 |  | 
| Alan Cox | deb9168 | 2008-07-22 11:13:08 +0100 | [diff] [blame] | 2736 | MODULE_AUTHOR(DRIVER_AUTHOR); | 
|  | 2737 | MODULE_DESCRIPTION(DRIVER_DESC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | MODULE_LICENSE("GPL"); | 
|  | 2739 |  | 
| David Woodhouse | 2971c57 | 2008-05-30 14:04:03 +0300 | [diff] [blame] | 2740 | MODULE_FIRMWARE("keyspan/usa28.fw"); | 
|  | 2741 | MODULE_FIRMWARE("keyspan/usa28x.fw"); | 
|  | 2742 | MODULE_FIRMWARE("keyspan/usa28xa.fw"); | 
|  | 2743 | MODULE_FIRMWARE("keyspan/usa28xb.fw"); | 
|  | 2744 | MODULE_FIRMWARE("keyspan/usa19.fw"); | 
|  | 2745 | MODULE_FIRMWARE("keyspan/usa19qi.fw"); | 
|  | 2746 | MODULE_FIRMWARE("keyspan/mpr.fw"); | 
|  | 2747 | MODULE_FIRMWARE("keyspan/usa19qw.fw"); | 
|  | 2748 | MODULE_FIRMWARE("keyspan/usa18x.fw"); | 
|  | 2749 | MODULE_FIRMWARE("keyspan/usa19w.fw"); | 
|  | 2750 | MODULE_FIRMWARE("keyspan/usa49w.fw"); | 
|  | 2751 | MODULE_FIRMWARE("keyspan/usa49wlc.fw"); | 
|  | 2752 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | module_param(debug, bool, S_IRUGO | S_IWUSR); | 
|  | 2754 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | 
|  | 2755 |  |