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