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