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