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