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