Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 1 | /* |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 2 | USB Driver for Sierra Wireless |
| 3 | |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 4 | Copyright (C) 2006, 2007 Kevin Lloyd <linux@sierrawireless.com> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 5 | |
| 6 | IMPORTANT DISCLAIMER: This driver is not commercially supported by |
| 7 | Sierra Wireless. Use at your own risk. |
| 8 | |
| 9 | This driver is free software; you can redistribute it and/or modify |
| 10 | it under the terms of Version 2 of the GNU General Public License as |
| 11 | published by the Free Software Foundation. |
| 12 | |
| 13 | Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de> |
| 14 | Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 17 | #define DRIVER_VERSION "v.1.2.5b" |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 18 | #define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>" |
| 19 | #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 20 | |
| 21 | #include <linux/kernel.h> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 22 | #include <linux/jiffies.h> |
| 23 | #include <linux/errno.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 24 | #include <linux/tty.h> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 25 | #include <linux/tty_flip.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 28 | #include <linux/usb/serial.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 29 | |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 30 | #define SWIMS_USB_REQUEST_SetMode 0x0B |
| 31 | #define SWIMS_USB_REQUEST_TYPE_SetMode 0x40 |
| 32 | #define SWIMS_USB_INDEX_SetMode 0x0000 |
| 33 | #define SWIMS_SET_MODE_Modem 0x0001 |
| 34 | |
| 35 | /* per port private data */ |
| 36 | #define N_IN_URB 4 |
| 37 | #define N_OUT_URB 4 |
| 38 | #define IN_BUFLEN 4096 |
| 39 | |
| 40 | static int debug; |
| 41 | |
| 42 | enum devicetype { |
| 43 | DEVICE_3_PORT = 0, |
| 44 | DEVICE_1_PORT = 1, |
| 45 | DEVICE_INSTALLER = 2, |
| 46 | }; |
| 47 | |
Adrian Bunk | 82a24e6 | 2007-07-29 16:59:02 +0200 | [diff] [blame] | 48 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 49 | { |
| 50 | int result; |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 51 | dev_dbg(&udev->dev, "%s", "SET POWER STATE\n"); |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 52 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 53 | 0x00, /* __u8 request */ |
| 54 | 0x40, /* __u8 request type */ |
| 55 | swiState, /* __u16 value */ |
| 56 | 0, /* __u16 index */ |
| 57 | NULL, /* void *data */ |
| 58 | 0, /* __u16 size */ |
| 59 | USB_CTRL_SET_TIMEOUT); /* int timeout */ |
| 60 | return result; |
| 61 | } |
| 62 | |
Adrian Bunk | 82a24e6 | 2007-07-29 16:59:02 +0200 | [diff] [blame] | 63 | static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSocMode) |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 64 | { |
| 65 | int result; |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 66 | dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n"); |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 67 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 68 | SWIMS_USB_REQUEST_SetMode, /* __u8 request */ |
| 69 | SWIMS_USB_REQUEST_TYPE_SetMode, /* __u8 request type */ |
| 70 | eSocMode, /* __u16 value */ |
| 71 | SWIMS_USB_INDEX_SetMode, /* __u16 index */ |
| 72 | NULL, /* void *data */ |
| 73 | 0, /* __u16 size */ |
| 74 | USB_CTRL_SET_TIMEOUT); /* int timeout */ |
| 75 | return result; |
| 76 | } |
| 77 | |
Adrian Bunk | 82a24e6 | 2007-07-29 16:59:02 +0200 | [diff] [blame] | 78 | static int sierra_probe(struct usb_interface *iface, |
| 79 | const struct usb_device_id *id) |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 80 | { |
| 81 | int result; |
| 82 | struct usb_device *udev; |
| 83 | |
| 84 | udev = usb_get_dev(interface_to_usbdev(iface)); |
| 85 | |
| 86 | /* Check if in installer mode */ |
| 87 | if (id->driver_info == DEVICE_INSTALLER) { |
| 88 | dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n"); |
| 89 | result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); |
| 90 | /*We do not want to bind to the device when in installer mode*/ |
| 91 | return -EIO; |
| 92 | } |
| 93 | |
| 94 | return usb_serial_probe(iface, id); |
| 95 | } |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 96 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 97 | static struct usb_device_id id_table [] = { |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 98 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 99 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
Greg Kroah-Hartman | 90ac3c8 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 100 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 101 | { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 102 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ |
agilmore@wirelessbeehive.com | b9e13ac | 2007-12-04 11:37:12 -0700 | [diff] [blame] | 103 | { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 104 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ |
| 105 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 106 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ |
| 107 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 108 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 109 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 110 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 111 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ |
Kevin R Page | ed0ccdb | 2007-12-13 01:10:48 +0000 | [diff] [blame^] | 112 | { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */ |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 113 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 114 | { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ |
| 115 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ |
| 116 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ |
| 117 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ |
| 118 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ |
| 119 | { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 120 | |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 121 | { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */ |
| 122 | { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */ |
| 123 | |
| 124 | { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 125 | { } |
| 126 | }; |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 127 | MODULE_DEVICE_TABLE(usb, id_table); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 128 | |
| 129 | static struct usb_device_id id_table_1port [] = { |
| 130 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ |
| 131 | { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */ |
| 132 | { } |
| 133 | }; |
| 134 | |
| 135 | static struct usb_device_id id_table_3port [] = { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 136 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 137 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 138 | { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */ |
Greg Kroah-Hartman | 90ac3c8 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 139 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 140 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ |
agilmore@wirelessbeehive.com | 5fdcd03 | 2007-11-20 13:39:03 -0700 | [diff] [blame] | 141 | { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 142 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ |
| 143 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 144 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/ |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 145 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 146 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 147 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 148 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 149 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ |
Kevin R Page | ed0ccdb | 2007-12-13 01:10:48 +0000 | [diff] [blame^] | 150 | { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 151 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 152 | { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ |
| 153 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ |
| 154 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ |
| 155 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ |
| 156 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */ |
| 157 | { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 158 | { } |
| 159 | }; |
| 160 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 161 | static struct usb_driver sierra_driver = { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 162 | .name = "sierra", |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 163 | .probe = sierra_probe, |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 164 | .disconnect = usb_serial_disconnect, |
| 165 | .id_table = id_table, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 166 | .no_dynamic_id = 1, |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 169 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 170 | struct sierra_port_private { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 171 | spinlock_t lock; /* lock the structure */ |
| 172 | int outstanding_urbs; /* number of out urbs in flight */ |
| 173 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 174 | /* Input endpoints and buffer for this port */ |
| 175 | struct urb *in_urbs[N_IN_URB]; |
| 176 | char in_buffer[N_IN_URB][IN_BUFLEN]; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 177 | |
| 178 | /* Settings for the port */ |
| 179 | int rts_state; /* Handshaking pins (outputs) */ |
| 180 | int dtr_state; |
| 181 | int cts_state; /* Handshaking pins (inputs) */ |
| 182 | int dsr_state; |
| 183 | int dcd_state; |
| 184 | int ri_state; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 187 | static int sierra_send_setup(struct usb_serial_port *port) |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 188 | { |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 189 | struct usb_serial *serial = port->serial; |
| 190 | struct sierra_port_private *portdata; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 191 | |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 192 | dbg("%s", __FUNCTION__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 193 | |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 194 | portdata = usb_get_serial_port_data(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 195 | |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 196 | if (port->tty) { |
| 197 | int val = 0; |
| 198 | if (portdata->dtr_state) |
| 199 | val |= 0x01; |
| 200 | if (portdata->rts_state) |
| 201 | val |= 0x02; |
| 202 | |
| 203 | return usb_control_msg(serial->dev, |
| 204 | usb_rcvctrlpipe(serial->dev, 0), |
| 205 | 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); |
| 206 | } |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 207 | |
| 208 | return 0; |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 211 | static void sierra_rx_throttle(struct usb_serial_port *port) |
| 212 | { |
| 213 | dbg("%s", __FUNCTION__); |
| 214 | } |
| 215 | |
| 216 | static void sierra_rx_unthrottle(struct usb_serial_port *port) |
| 217 | { |
| 218 | dbg("%s", __FUNCTION__); |
| 219 | } |
| 220 | |
| 221 | static void sierra_break_ctl(struct usb_serial_port *port, int break_state) |
| 222 | { |
| 223 | /* Unfortunately, I don't know how to send a break */ |
| 224 | dbg("%s", __FUNCTION__); |
| 225 | } |
| 226 | |
| 227 | static void sierra_set_termios(struct usb_serial_port *port, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 228 | struct ktermios *old_termios) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 229 | { |
| 230 | dbg("%s", __FUNCTION__); |
Alan Cox | ed1f12e | 2007-10-18 01:24:22 -0700 | [diff] [blame] | 231 | tty_termios_copy_hw(port->tty->termios, old_termios); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 232 | sierra_send_setup(port); |
| 233 | } |
| 234 | |
| 235 | static int sierra_tiocmget(struct usb_serial_port *port, struct file *file) |
| 236 | { |
| 237 | unsigned int value; |
| 238 | struct sierra_port_private *portdata; |
| 239 | |
| 240 | portdata = usb_get_serial_port_data(port); |
| 241 | |
| 242 | value = ((portdata->rts_state) ? TIOCM_RTS : 0) | |
| 243 | ((portdata->dtr_state) ? TIOCM_DTR : 0) | |
| 244 | ((portdata->cts_state) ? TIOCM_CTS : 0) | |
| 245 | ((portdata->dsr_state) ? TIOCM_DSR : 0) | |
| 246 | ((portdata->dcd_state) ? TIOCM_CAR : 0) | |
| 247 | ((portdata->ri_state) ? TIOCM_RNG : 0); |
| 248 | |
| 249 | return value; |
| 250 | } |
| 251 | |
| 252 | static int sierra_tiocmset(struct usb_serial_port *port, struct file *file, |
| 253 | unsigned int set, unsigned int clear) |
| 254 | { |
| 255 | struct sierra_port_private *portdata; |
| 256 | |
| 257 | portdata = usb_get_serial_port_data(port); |
| 258 | |
| 259 | if (set & TIOCM_RTS) |
| 260 | portdata->rts_state = 1; |
| 261 | if (set & TIOCM_DTR) |
| 262 | portdata->dtr_state = 1; |
| 263 | |
| 264 | if (clear & TIOCM_RTS) |
| 265 | portdata->rts_state = 0; |
| 266 | if (clear & TIOCM_DTR) |
| 267 | portdata->dtr_state = 0; |
| 268 | return sierra_send_setup(port); |
| 269 | } |
| 270 | |
| 271 | static int sierra_ioctl(struct usb_serial_port *port, struct file *file, |
| 272 | unsigned int cmd, unsigned long arg) |
| 273 | { |
| 274 | return -ENOIOCTLCMD; |
| 275 | } |
| 276 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 277 | static void sierra_outdat_callback(struct urb *urb) |
| 278 | { |
| 279 | struct usb_serial_port *port = urb->context; |
| 280 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 281 | int status = urb->status; |
| 282 | unsigned long flags; |
| 283 | |
| 284 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 285 | |
| 286 | /* free up the transfer buffer, as usb_free_urb() does not do this */ |
| 287 | kfree(urb->transfer_buffer); |
| 288 | |
| 289 | if (status) |
| 290 | dbg("%s - nonzero write bulk status received: %d", |
| 291 | __FUNCTION__, status); |
| 292 | |
| 293 | spin_lock_irqsave(&portdata->lock, flags); |
| 294 | --portdata->outstanding_urbs; |
| 295 | spin_unlock_irqrestore(&portdata->lock, flags); |
| 296 | |
| 297 | usb_serial_port_softint(port); |
| 298 | } |
| 299 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 300 | /* Write */ |
| 301 | static int sierra_write(struct usb_serial_port *port, |
| 302 | const unsigned char *buf, int count) |
| 303 | { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 304 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 305 | struct usb_serial *serial = port->serial; |
| 306 | unsigned long flags; |
| 307 | unsigned char *buffer; |
| 308 | struct urb *urb; |
| 309 | int status; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 310 | |
| 311 | portdata = usb_get_serial_port_data(port); |
| 312 | |
| 313 | dbg("%s: write (%d chars)", __FUNCTION__, count); |
| 314 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 315 | spin_lock_irqsave(&portdata->lock, flags); |
| 316 | if (portdata->outstanding_urbs > N_OUT_URB) { |
| 317 | spin_unlock_irqrestore(&portdata->lock, flags); |
| 318 | dbg("%s - write limit hit\n", __FUNCTION__); |
| 319 | return 0; |
| 320 | } |
| 321 | portdata->outstanding_urbs++; |
| 322 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 323 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 324 | buffer = kmalloc(count, GFP_ATOMIC); |
| 325 | if (!buffer) { |
| 326 | dev_err(&port->dev, "out of memory\n"); |
| 327 | count = -ENOMEM; |
| 328 | goto error_no_buffer; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 331 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 332 | if (!urb) { |
| 333 | dev_err(&port->dev, "no more free urbs\n"); |
| 334 | count = -ENOMEM; |
| 335 | goto error_no_urb; |
| 336 | } |
| 337 | |
| 338 | memcpy(buffer, buf, count); |
| 339 | |
| 340 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer); |
| 341 | |
| 342 | usb_fill_bulk_urb(urb, serial->dev, |
| 343 | usb_sndbulkpipe(serial->dev, |
| 344 | port->bulk_out_endpointAddress), |
| 345 | buffer, count, sierra_outdat_callback, port); |
| 346 | |
| 347 | /* send it down the pipe */ |
| 348 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 349 | if (status) { |
| 350 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " |
| 351 | "with status = %d\n", __FUNCTION__, status); |
| 352 | count = status; |
| 353 | goto error; |
| 354 | } |
| 355 | |
| 356 | /* we are done with this urb, so let the host driver |
| 357 | * really free it when it is finished with it */ |
| 358 | usb_free_urb(urb); |
| 359 | |
| 360 | return count; |
| 361 | error: |
| 362 | usb_free_urb(urb); |
| 363 | error_no_urb: |
| 364 | kfree(buffer); |
| 365 | error_no_buffer: |
| 366 | spin_lock_irqsave(&portdata->lock, flags); |
| 367 | --portdata->outstanding_urbs; |
| 368 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 369 | return count; |
| 370 | } |
| 371 | |
| 372 | static void sierra_indat_callback(struct urb *urb) |
| 373 | { |
| 374 | int err; |
| 375 | int endpoint; |
| 376 | struct usb_serial_port *port; |
| 377 | struct tty_struct *tty; |
| 378 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 379 | int status = urb->status; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 380 | |
| 381 | dbg("%s: %p", __FUNCTION__, urb); |
| 382 | |
| 383 | endpoint = usb_pipeendpoint(urb->pipe); |
| 384 | port = (struct usb_serial_port *) urb->context; |
| 385 | |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 386 | if (status) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 387 | dbg("%s: nonzero status: %d on endpoint %02x.", |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 388 | __FUNCTION__, status, endpoint); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 389 | } else { |
| 390 | tty = port->tty; |
| 391 | if (urb->actual_length) { |
| 392 | tty_buffer_request_room(tty, urb->actual_length); |
| 393 | tty_insert_flip_string(tty, data, urb->actual_length); |
| 394 | tty_flip_buffer_push(tty); |
| 395 | } else { |
| 396 | dbg("%s: empty read urb received", __FUNCTION__); |
| 397 | } |
| 398 | |
| 399 | /* Resubmit urb so we continue receiving */ |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 400 | if (port->open_count && status != -ESHUTDOWN) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 401 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 402 | if (err) |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 403 | dev_err(&port->dev, "resubmit read urb failed." |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 404 | "(%d)\n", err); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | return; |
| 408 | } |
| 409 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 410 | static void sierra_instat_callback(struct urb *urb) |
| 411 | { |
| 412 | int err; |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 413 | int status = urb->status; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 414 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; |
| 415 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 416 | struct usb_serial *serial = port->serial; |
| 417 | |
| 418 | dbg("%s", __FUNCTION__); |
| 419 | dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata); |
| 420 | |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 421 | if (status == 0) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 422 | struct usb_ctrlrequest *req_pkt = |
| 423 | (struct usb_ctrlrequest *)urb->transfer_buffer; |
| 424 | |
| 425 | if (!req_pkt) { |
| 426 | dbg("%s: NULL req_pkt\n", __FUNCTION__); |
| 427 | return; |
| 428 | } |
| 429 | if ((req_pkt->bRequestType == 0xA1) && |
| 430 | (req_pkt->bRequest == 0x20)) { |
| 431 | int old_dcd_state; |
| 432 | unsigned char signals = *((unsigned char *) |
| 433 | urb->transfer_buffer + |
| 434 | sizeof(struct usb_ctrlrequest)); |
| 435 | |
| 436 | dbg("%s: signal x%x", __FUNCTION__, signals); |
| 437 | |
| 438 | old_dcd_state = portdata->dcd_state; |
| 439 | portdata->cts_state = 1; |
| 440 | portdata->dcd_state = ((signals & 0x01) ? 1 : 0); |
| 441 | portdata->dsr_state = ((signals & 0x02) ? 1 : 0); |
| 442 | portdata->ri_state = ((signals & 0x08) ? 1 : 0); |
| 443 | |
| 444 | if (port->tty && !C_CLOCAL(port->tty) && |
| 445 | old_dcd_state && !portdata->dcd_state) |
| 446 | tty_hangup(port->tty); |
| 447 | } else { |
| 448 | dbg("%s: type %x req %x", __FUNCTION__, |
| 449 | req_pkt->bRequestType,req_pkt->bRequest); |
| 450 | } |
| 451 | } else |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 452 | dbg("%s: error %d", __FUNCTION__, status); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 453 | |
| 454 | /* Resubmit urb so we continue receiving IRQ data */ |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 455 | if (status != -ESHUTDOWN) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 456 | urb->dev = serial->dev; |
| 457 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 458 | if (err) |
| 459 | dbg("%s: resubmit intr urb failed. (%d)", |
| 460 | __FUNCTION__, err); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | static int sierra_write_room(struct usb_serial_port *port) |
| 465 | { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 466 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 467 | unsigned long flags; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 468 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 469 | dbg("%s - port %d", __FUNCTION__, port->number); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 470 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 471 | /* try to give a good number back based on if we have any free urbs at |
| 472 | * this point in time */ |
| 473 | spin_lock_irqsave(&portdata->lock, flags); |
| 474 | if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) { |
| 475 | spin_unlock_irqrestore(&portdata->lock, flags); |
| 476 | dbg("%s - write limit hit\n", __FUNCTION__); |
| 477 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 478 | } |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 479 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 480 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 481 | return 2048; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static int sierra_chars_in_buffer(struct usb_serial_port *port) |
| 485 | { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 486 | dbg("%s - port %d", __FUNCTION__, port->number); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 487 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 488 | /* |
| 489 | * We can't really account for how much data we |
| 490 | * have sent out, but hasn't made it through to the |
| 491 | * device as we can't see the backend here, so just |
| 492 | * tell the tty layer that everything is flushed. |
| 493 | */ |
| 494 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | static int sierra_open(struct usb_serial_port *port, struct file *filp) |
| 498 | { |
| 499 | struct sierra_port_private *portdata; |
| 500 | struct usb_serial *serial = port->serial; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 501 | int i; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 502 | struct urb *urb; |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 503 | int result; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 504 | |
| 505 | portdata = usb_get_serial_port_data(port); |
| 506 | |
| 507 | dbg("%s", __FUNCTION__); |
| 508 | |
| 509 | /* Set some sane defaults */ |
| 510 | portdata->rts_state = 1; |
| 511 | portdata->dtr_state = 1; |
| 512 | |
| 513 | /* Reset low level data toggle and start reading from endpoints */ |
| 514 | for (i = 0; i < N_IN_URB; i++) { |
| 515 | urb = portdata->in_urbs[i]; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 516 | if (!urb) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 517 | continue; |
| 518 | if (urb->dev != serial->dev) { |
| 519 | dbg("%s: dev %p != %p", __FUNCTION__, |
| 520 | urb->dev, serial->dev); |
| 521 | continue; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * make sure endpoint data toggle is synchronized with the |
| 526 | * device |
| 527 | */ |
| 528 | usb_clear_halt(urb->dev, urb->pipe); |
| 529 | |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 530 | result = usb_submit_urb(urb, GFP_KERNEL); |
| 531 | if (result) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 532 | dev_err(&port->dev, "submit urb %d failed (%d) %d\n", |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 533 | i, result, urb->transfer_buffer_length); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 537 | port->tty->low_latency = 1; |
| 538 | |
| 539 | sierra_send_setup(port); |
| 540 | |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 541 | /* start up the interrupt endpoint if we have one */ |
| 542 | if (port->interrupt_in_urb) { |
| 543 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 544 | if (result) |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 545 | dev_err(&port->dev, "submit irq_in urb failed %d\n", |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 546 | result); |
| 547 | } |
| 548 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 551 | static void sierra_close(struct usb_serial_port *port, struct file *filp) |
| 552 | { |
| 553 | int i; |
| 554 | struct usb_serial *serial = port->serial; |
| 555 | struct sierra_port_private *portdata; |
| 556 | |
| 557 | dbg("%s", __FUNCTION__); |
| 558 | portdata = usb_get_serial_port_data(port); |
| 559 | |
| 560 | portdata->rts_state = 0; |
| 561 | portdata->dtr_state = 0; |
| 562 | |
| 563 | if (serial->dev) { |
| 564 | sierra_send_setup(port); |
| 565 | |
| 566 | /* Stop reading/writing urbs */ |
| 567 | for (i = 0; i < N_IN_URB; i++) |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 568 | usb_kill_urb(portdata->in_urbs[i]); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 569 | } |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 570 | |
| 571 | usb_kill_urb(port->interrupt_in_urb); |
| 572 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 573 | port->tty = NULL; |
| 574 | } |
| 575 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 576 | static int sierra_startup(struct usb_serial *serial) |
| 577 | { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 578 | struct usb_serial_port *port; |
| 579 | struct sierra_port_private *portdata; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 580 | struct urb *urb; |
| 581 | int i; |
| 582 | int j; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 583 | |
| 584 | dbg("%s", __FUNCTION__); |
| 585 | |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 586 | /*Set Device mode to D0 */ |
| 587 | sierra_set_power_state(serial->dev, 0x0000); |
| 588 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 589 | /* Now setup per port private data */ |
| 590 | for (i = 0; i < serial->num_ports; i++) { |
| 591 | port = serial->port[i]; |
| 592 | portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); |
| 593 | if (!portdata) { |
| 594 | dbg("%s: kmalloc for sierra_port_private (%d) failed!.", |
| 595 | __FUNCTION__, i); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 596 | return -ENOMEM; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 597 | } |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 598 | spin_lock_init(&portdata->lock); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 599 | |
| 600 | usb_set_serial_port_data(port, portdata); |
| 601 | |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 602 | /* initialize the in urbs */ |
| 603 | for (j = 0; j < N_IN_URB; ++j) { |
| 604 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 605 | if (urb == NULL) { |
| 606 | dbg("%s: alloc for in port failed.", |
| 607 | __FUNCTION__); |
| 608 | continue; |
| 609 | } |
| 610 | /* Fill URB using supplied data. */ |
| 611 | usb_fill_bulk_urb(urb, serial->dev, |
| 612 | usb_rcvbulkpipe(serial->dev, |
| 613 | port->bulk_in_endpointAddress), |
| 614 | portdata->in_buffer[j], IN_BUFLEN, |
| 615 | sierra_indat_callback, port); |
| 616 | portdata->in_urbs[j] = urb; |
| 617 | } |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 620 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static void sierra_shutdown(struct usb_serial *serial) |
| 624 | { |
| 625 | int i, j; |
| 626 | struct usb_serial_port *port; |
| 627 | struct sierra_port_private *portdata; |
| 628 | |
| 629 | dbg("%s", __FUNCTION__); |
| 630 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 631 | for (i = 0; i < serial->num_ports; ++i) { |
| 632 | port = serial->port[i]; |
Greg Kroah-Hartman | f094e4f | 2007-04-26 00:12:01 -0700 | [diff] [blame] | 633 | if (!port) |
| 634 | continue; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 635 | portdata = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | f094e4f | 2007-04-26 00:12:01 -0700 | [diff] [blame] | 636 | if (!portdata) |
| 637 | continue; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 638 | |
| 639 | for (j = 0; j < N_IN_URB; j++) { |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 640 | usb_kill_urb(portdata->in_urbs[j]); |
| 641 | usb_free_urb(portdata->in_urbs[j]); |
| 642 | portdata->in_urbs[j] = NULL; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 643 | } |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 644 | kfree(portdata); |
| 645 | usb_set_serial_port_data(port, NULL); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 649 | static struct usb_serial_driver sierra_1port_device = { |
| 650 | .driver = { |
| 651 | .owner = THIS_MODULE, |
| 652 | .name = "sierra1", |
| 653 | }, |
| 654 | .description = "Sierra USB modem (1 port)", |
| 655 | .id_table = id_table_1port, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 656 | .usb_driver = &sierra_driver, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 657 | .num_interrupt_in = NUM_DONT_CARE, |
| 658 | .num_bulk_in = 1, |
| 659 | .num_bulk_out = 1, |
| 660 | .num_ports = 1, |
| 661 | .open = sierra_open, |
| 662 | .close = sierra_close, |
| 663 | .write = sierra_write, |
| 664 | .write_room = sierra_write_room, |
| 665 | .chars_in_buffer = sierra_chars_in_buffer, |
| 666 | .throttle = sierra_rx_throttle, |
| 667 | .unthrottle = sierra_rx_unthrottle, |
| 668 | .ioctl = sierra_ioctl, |
| 669 | .set_termios = sierra_set_termios, |
| 670 | .break_ctl = sierra_break_ctl, |
| 671 | .tiocmget = sierra_tiocmget, |
| 672 | .tiocmset = sierra_tiocmset, |
| 673 | .attach = sierra_startup, |
| 674 | .shutdown = sierra_shutdown, |
| 675 | .read_int_callback = sierra_instat_callback, |
| 676 | }; |
| 677 | |
| 678 | static struct usb_serial_driver sierra_3port_device = { |
| 679 | .driver = { |
| 680 | .owner = THIS_MODULE, |
| 681 | .name = "sierra3", |
| 682 | }, |
| 683 | .description = "Sierra USB modem (3 port)", |
| 684 | .id_table = id_table_3port, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 685 | .usb_driver = &sierra_driver, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 686 | .num_interrupt_in = NUM_DONT_CARE, |
| 687 | .num_bulk_in = 3, |
| 688 | .num_bulk_out = 3, |
| 689 | .num_ports = 3, |
| 690 | .open = sierra_open, |
| 691 | .close = sierra_close, |
| 692 | .write = sierra_write, |
| 693 | .write_room = sierra_write_room, |
| 694 | .chars_in_buffer = sierra_chars_in_buffer, |
| 695 | .throttle = sierra_rx_throttle, |
| 696 | .unthrottle = sierra_rx_unthrottle, |
| 697 | .ioctl = sierra_ioctl, |
| 698 | .set_termios = sierra_set_termios, |
| 699 | .break_ctl = sierra_break_ctl, |
| 700 | .tiocmget = sierra_tiocmget, |
| 701 | .tiocmset = sierra_tiocmset, |
| 702 | .attach = sierra_startup, |
| 703 | .shutdown = sierra_shutdown, |
| 704 | .read_int_callback = sierra_instat_callback, |
| 705 | }; |
| 706 | |
| 707 | /* Functions used by new usb-serial code. */ |
| 708 | static int __init sierra_init(void) |
| 709 | { |
| 710 | int retval; |
| 711 | retval = usb_serial_register(&sierra_1port_device); |
| 712 | if (retval) |
| 713 | goto failed_1port_device_register; |
| 714 | retval = usb_serial_register(&sierra_3port_device); |
| 715 | if (retval) |
| 716 | goto failed_3port_device_register; |
| 717 | |
| 718 | |
| 719 | retval = usb_register(&sierra_driver); |
| 720 | if (retval) |
| 721 | goto failed_driver_register; |
| 722 | |
| 723 | info(DRIVER_DESC ": " DRIVER_VERSION); |
| 724 | |
| 725 | return 0; |
| 726 | |
| 727 | failed_driver_register: |
| 728 | usb_serial_deregister(&sierra_3port_device); |
| 729 | failed_3port_device_register: |
| 730 | usb_serial_deregister(&sierra_1port_device); |
| 731 | failed_1port_device_register: |
| 732 | return retval; |
| 733 | } |
| 734 | |
| 735 | static void __exit sierra_exit(void) |
| 736 | { |
| 737 | usb_deregister (&sierra_driver); |
| 738 | usb_serial_deregister(&sierra_1port_device); |
| 739 | usb_serial_deregister(&sierra_3port_device); |
| 740 | } |
| 741 | |
| 742 | module_init(sierra_init); |
| 743 | module_exit(sierra_exit); |
| 744 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 745 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 746 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 747 | MODULE_VERSION(DRIVER_VERSION); |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 748 | MODULE_LICENSE("GPL"); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 749 | |
| 750 | #ifdef CONFIG_USB_DEBUG |
| 751 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 752 | MODULE_PARM_DESC(debug, "Debug messages"); |
| 753 | #endif |
| 754 | |