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