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