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