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