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