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