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