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 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 4 | Copyright (C) 2006, 2007, 2008 Kevin Lloyd <klloyd@sierrawireless.com>, |
| 5 | |
| 6 | Copyright (C) 2008, 2009 Elina Pasheva, Matthew Safar, Rory Filer |
| 7 | <linux@sierrawireless.com> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 8 | |
| 9 | IMPORTANT DISCLAIMER: This driver is not commercially supported by |
| 10 | Sierra Wireless. Use at your own risk. |
| 11 | |
| 12 | This driver is free software; you can redistribute it and/or modify |
| 13 | it under the terms of Version 2 of the GNU General Public License as |
| 14 | published by the Free Software Foundation. |
| 15 | |
| 16 | Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de> |
| 17 | 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] | 18 | */ |
| 19 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 20 | #define DRIVER_VERSION "v.1.3.6" |
| 21 | #define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer" |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 22 | #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 23 | |
| 24 | #include <linux/kernel.h> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/errno.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 27 | #include <linux/tty.h> |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 28 | #include <linux/tty_flip.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
| 30 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 31 | #include <linux/usb/serial.h> |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 32 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 33 | #define SWIMS_USB_REQUEST_SetPower 0x00 |
| 34 | #define SWIMS_USB_REQUEST_SetNmea 0x07 |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 35 | |
Elina Pasheva | b748bb7 | 2009-04-24 18:41:49 -0700 | [diff] [blame] | 36 | #define N_IN_URB 8 |
| 37 | #define N_OUT_URB 64 |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 38 | #define IN_BUFLEN 4096 |
| 39 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 40 | #define MAX_TRANSFER (PAGE_SIZE - 512) |
| 41 | /* MAX_TRANSFER is chosen so that the VM is not stressed by |
| 42 | allocations > PAGE_SIZE and the number of packets in a page |
| 43 | is an integer 512 is the largest possible packet on EHCI */ |
| 44 | |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 45 | static int debug; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 46 | static int nmea; |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 47 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 48 | /* Used in interface blacklisting */ |
| 49 | struct sierra_iface_info { |
| 50 | const u32 infolen; /* number of interface numbers on blacklist */ |
| 51 | const u8 *ifaceinfo; /* pointer to the array holding the numbers */ |
| 52 | }; |
| 53 | |
Adrian Bunk | 82a24e6 | 2007-07-29 16:59:02 +0200 | [diff] [blame] | 54 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 55 | { |
| 56 | int result; |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 57 | dev_dbg(&udev->dev, "%s\n", __func__); |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 58 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 59 | SWIMS_USB_REQUEST_SetPower, /* __u8 request */ |
Kevin Lloyd | f3564de | 2008-03-28 10:05:08 -0700 | [diff] [blame] | 60 | USB_TYPE_VENDOR, /* __u8 request type */ |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 61 | swiState, /* __u16 value */ |
| 62 | 0, /* __u16 index */ |
| 63 | NULL, /* void *data */ |
| 64 | 0, /* __u16 size */ |
| 65 | USB_CTRL_SET_TIMEOUT); /* int timeout */ |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 66 | return result; |
| 67 | } |
| 68 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 69 | static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable) |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 70 | { |
| 71 | int result; |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 72 | dev_dbg(&udev->dev, "%s\n", __func__); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 73 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
| 74 | SWIMS_USB_REQUEST_SetNmea, /* __u8 request */ |
Kevin Lloyd | f3564de | 2008-03-28 10:05:08 -0700 | [diff] [blame] | 75 | USB_TYPE_VENDOR, /* __u8 request type */ |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 76 | enable, /* __u16 value */ |
| 77 | 0x0000, /* __u16 index */ |
| 78 | NULL, /* void *data */ |
| 79 | 0, /* __u16 size */ |
| 80 | USB_CTRL_SET_TIMEOUT); /* int timeout */ |
| 81 | return result; |
| 82 | } |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 83 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 84 | static int sierra_calc_num_ports(struct usb_serial *serial) |
| 85 | { |
| 86 | int result; |
| 87 | int *num_ports = usb_get_serial_data(serial); |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 88 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 89 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 90 | result = *num_ports; |
| 91 | |
| 92 | if (result) { |
| 93 | kfree(num_ports); |
| 94 | usb_set_serial_data(serial, NULL); |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 97 | return result; |
| 98 | } |
| 99 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 100 | static int is_blacklisted(const u8 ifnum, |
| 101 | const struct sierra_iface_info *blacklist) |
| 102 | { |
| 103 | const u8 *info; |
| 104 | int i; |
| 105 | |
| 106 | if (blacklist) { |
| 107 | info = blacklist->ifaceinfo; |
| 108 | |
| 109 | for (i = 0; i < blacklist->infolen; i++) { |
| 110 | if (info[i] == ifnum) |
| 111 | return 1; |
| 112 | } |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 117 | static int sierra_calc_interface(struct usb_serial *serial) |
| 118 | { |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 119 | int interface; |
| 120 | struct usb_interface *p_interface; |
| 121 | struct usb_host_interface *p_host_interface; |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 122 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 123 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 124 | /* Get the interface structure pointer from the serial struct */ |
| 125 | p_interface = serial->interface; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 126 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 127 | /* Get a pointer to the host interface structure */ |
| 128 | p_host_interface = p_interface->cur_altsetting; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 129 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 130 | /* read the interface descriptor for this active altsetting |
| 131 | * to find out the interface number we are on |
| 132 | */ |
| 133 | interface = p_host_interface->desc.bInterfaceNumber; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 134 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 135 | return interface; |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 138 | static int sierra_probe(struct usb_serial *serial, |
| 139 | const struct usb_device_id *id) |
| 140 | { |
| 141 | int result = 0; |
| 142 | struct usb_device *udev; |
| 143 | int *num_ports; |
| 144 | u8 ifnum; |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 145 | u8 numendpoints; |
| 146 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 147 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 148 | |
| 149 | num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL); |
| 150 | if (!num_ports) |
| 151 | return -ENOMEM; |
| 152 | |
| 153 | ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 154 | numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 155 | udev = serial->dev; |
| 156 | |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 157 | /* Figure out the interface number from the serial structure */ |
| 158 | ifnum = sierra_calc_interface(serial); |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 159 | |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 160 | /* |
| 161 | * If this interface supports more than 1 alternate |
| 162 | * select the 2nd one |
| 163 | */ |
| 164 | if (serial->interface->num_altsetting == 2) { |
| 165 | dev_dbg(&udev->dev, "Selecting alt setting for interface %d\n", |
| 166 | ifnum); |
| 167 | /* We know the alternate setting is 1 for the MC8785 */ |
| 168 | usb_set_interface(udev, ifnum, 1); |
| 169 | } |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 170 | |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 171 | /* Dummy interface present on some SKUs should be ignored */ |
Kevin Lloyd | 0585e4d | 2008-07-10 14:14:54 -0700 | [diff] [blame] | 172 | if (ifnum == 0x99) |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 173 | *num_ports = 0; |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 174 | else if (numendpoints <= 3) |
| 175 | *num_ports = 1; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 176 | else |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 177 | *num_ports = (numendpoints-1)/2; |
| 178 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 179 | /* |
| 180 | * save off our num_ports info so that we can use it in the |
| 181 | * calc_num_ports callback |
| 182 | */ |
| 183 | usb_set_serial_data(serial, (void *)num_ports); |
| 184 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 185 | /* ifnum could have changed - by calling usb_set_interface */ |
| 186 | ifnum = sierra_calc_interface(serial); |
| 187 | |
| 188 | if (is_blacklisted(ifnum, |
| 189 | (struct sierra_iface_info *)id->driver_info)) { |
| 190 | dev_dbg(&serial->dev->dev, |
| 191 | "Ignoring blacklisted interface #%d\n", ifnum); |
| 192 | return -ENODEV; |
| 193 | } |
| 194 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 195 | return result; |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 196 | } |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 197 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 198 | static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; |
| 199 | static const struct sierra_iface_info direct_ip_interface_blacklist = { |
| 200 | .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces), |
| 201 | .ifaceinfo = direct_ip_non_serial_ifaces, |
| 202 | }; |
| 203 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 204 | static struct usb_device_id id_table [] = { |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 205 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 206 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
Greg Kroah-Hartman | 90ac3c8 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 207 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ |
Tony Murray | f8834f1 | 2008-08-22 17:30:44 -0500 | [diff] [blame] | 208 | { USB_DEVICE(0x03f0, 0x1b1d) }, /* HP ev2200 a.k.a MC5720 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 209 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 210 | { USB_DEVICE(0x1199, 0x0024) }, /* Sierra Wireless MC5727 */ |
agilmore@wirelessbeehive.com | b9e13ac | 2007-12-04 11:37:12 -0700 | [diff] [blame] | 211 | { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 212 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ |
| 213 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 214 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 215 | /* Sierra Wireless C597 */ |
| 216 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0023, 0xFF, 0xFF, 0xFF) }, |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 217 | /* Sierra Wireless Device */ |
| 218 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0025, 0xFF, 0xFF, 0xFF) }, |
| 219 | { USB_DEVICE(0x1199, 0x0026) }, /* Sierra Wireless Device */ |
Kevin Lloyd | 73b2c20 | 2008-08-25 19:20:40 -0700 | [diff] [blame] | 220 | { USB_DEVICE(0x1199, 0x0027) }, /* Sierra Wireless Device */ |
| 221 | { USB_DEVICE(0x1199, 0x0028) }, /* Sierra Wireless Device */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 222 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 223 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ |
Kevin Lloyd | e43062d | 2007-01-17 16:04:18 -0800 | [diff] [blame] | 224 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 225 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 226 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 227 | { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Lenovo) */ |
Kevin Lloyd | 7f170a6 | 2008-03-14 00:53:24 -0700 | [diff] [blame] | 228 | { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */ |
Stefan Seyfried | 8f7f85e | 2008-04-17 07:47:34 +0200 | [diff] [blame] | 229 | { USB_DEVICE(0x03f0, 0x1e1d) }, /* HP hs2300 a.k.a MC8775 */ |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 230 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ |
Kevin Lloyd | 7106967 | 2008-04-02 11:24:56 -0700 | [diff] [blame] | 231 | { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */ |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 232 | { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780 */ |
| 233 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */ |
Kevin Lloyd | b77a5c7 | 2008-09-17 09:03:38 -0700 | [diff] [blame] | 234 | { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 235 | { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 236 | /* Sierra Wireless MC8790, MC8791, MC8792 Composite */ |
| 237 | { USB_DEVICE(0x1199, 0x683C) }, |
| 238 | { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */ |
| 239 | /* Sierra Wireless MC8790, MC8791, MC8792 */ |
| 240 | { USB_DEVICE(0x1199, 0x683E) }, |
Kevin Lloyd | 9454c46 | 2007-07-16 13:49:29 -0700 | [diff] [blame] | 241 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ |
| 242 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ |
| 243 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ |
| 244 | { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ |
Kevin Lloyd | 6835b32 | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 245 | { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */ |
Jessica L. Blank | 62aad3a | 2007-12-30 20:11:35 -0600 | [diff] [blame] | 246 | { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 247 | { USB_DEVICE(0x1199, 0x6859) }, /* Sierra Wireless AirCard 885 E */ |
| 248 | { USB_DEVICE(0x1199, 0x685A) }, /* Sierra Wireless AirCard 885 E */ |
| 249 | /* Sierra Wireless C885 */ |
| 250 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6880, 0xFF, 0xFF, 0xFF)}, |
| 251 | /* Sierra Wireless Device */ |
| 252 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6890, 0xFF, 0xFF, 0xFF)}, |
| 253 | /* Sierra Wireless Device */ |
Kevin Lloyd | 73b2c20 | 2008-08-25 19:20:40 -0700 | [diff] [blame] | 254 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6891, 0xFF, 0xFF, 0xFF)}, |
| 255 | /* Sierra Wireless Device */ |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 256 | { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6892, 0xFF, 0xFF, 0xFF)}, |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 257 | |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 258 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ |
| 259 | { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 260 | |
Elina Pasheva | 4db2299 | 2009-06-11 14:32:01 +0100 | [diff] [blame] | 261 | { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ |
| 262 | .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist |
| 263 | }, |
| 264 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 265 | { } |
| 266 | }; |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 267 | MODULE_DEVICE_TABLE(usb, id_table); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 268 | |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 269 | static struct usb_driver sierra_driver = { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 270 | .name = "sierra", |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 271 | .probe = usb_serial_probe, |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 272 | .disconnect = usb_serial_disconnect, |
| 273 | .id_table = id_table, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 274 | .no_dynamic_id = 1, |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 275 | }; |
| 276 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 277 | struct sierra_port_private { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 278 | spinlock_t lock; /* lock the structure */ |
| 279 | int outstanding_urbs; /* number of out urbs in flight */ |
| 280 | |
Oliver Neukum | 4f4f9c5 | 2008-03-14 00:53:24 -0700 | [diff] [blame] | 281 | /* Input endpoints and buffers for this port */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 282 | struct urb *in_urbs[N_IN_URB]; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 283 | |
| 284 | /* Settings for the port */ |
| 285 | int rts_state; /* Handshaking pins (outputs) */ |
| 286 | int dtr_state; |
| 287 | int cts_state; /* Handshaking pins (inputs) */ |
| 288 | int dsr_state; |
| 289 | int dcd_state; |
| 290 | int ri_state; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 293 | static int sierra_send_setup(struct usb_serial_port *port) |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 294 | { |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 295 | struct usb_serial *serial = port->serial; |
| 296 | struct sierra_port_private *portdata; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 297 | __u16 interface = 0; |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 298 | int val = 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 299 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 300 | dev_dbg(&port->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 301 | |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 302 | portdata = usb_get_serial_port_data(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 303 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 304 | if (portdata->dtr_state) |
| 305 | val |= 0x01; |
| 306 | if (portdata->rts_state) |
| 307 | val |= 0x02; |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 308 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 309 | /* If composite device then properly report interface */ |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 310 | if (serial->num_ports == 1) { |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 311 | interface = sierra_calc_interface(serial); |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 312 | /* Control message is sent only to interfaces with |
| 313 | * interrupt_in endpoints |
| 314 | */ |
| 315 | if (port->interrupt_in_urb) { |
| 316 | /* send control message */ |
| 317 | return usb_control_msg(serial->dev, |
| 318 | usb_rcvctrlpipe(serial->dev, 0), |
| 319 | 0x22, 0x21, val, interface, |
| 320 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 321 | } |
| 322 | } |
Kevin Lloyd | e3173b2 | 2008-07-10 14:14:51 -0700 | [diff] [blame] | 323 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 324 | /* Otherwise the need to do non-composite mapping */ |
| 325 | else { |
| 326 | if (port->bulk_out_endpointAddress == 2) |
| 327 | interface = 0; |
| 328 | else if (port->bulk_out_endpointAddress == 4) |
| 329 | interface = 1; |
| 330 | else if (port->bulk_out_endpointAddress == 5) |
| 331 | interface = 2; |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 332 | return usb_control_msg(serial->dev, |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 333 | usb_rcvctrlpipe(serial->dev, 0), |
| 334 | 0x22, 0x21, val, interface, |
| 335 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
Alan Cox | 00b040d | 2009-06-11 14:29:29 +0100 | [diff] [blame] | 336 | } |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 337 | return 0; |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 340 | static void sierra_set_termios(struct tty_struct *tty, |
| 341 | struct usb_serial_port *port, struct ktermios *old_termios) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 342 | { |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 343 | dev_dbg(&port->dev, "%s\n", __func__); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 344 | tty_termios_copy_hw(tty->termios, old_termios); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 345 | sierra_send_setup(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 348 | static int sierra_tiocmget(struct tty_struct *tty, struct file *file) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 349 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 350 | struct usb_serial_port *port = tty->driver_data; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 351 | unsigned int value; |
| 352 | struct sierra_port_private *portdata; |
| 353 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 354 | dev_dbg(&port->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 355 | portdata = usb_get_serial_port_data(port); |
| 356 | |
| 357 | value = ((portdata->rts_state) ? TIOCM_RTS : 0) | |
| 358 | ((portdata->dtr_state) ? TIOCM_DTR : 0) | |
| 359 | ((portdata->cts_state) ? TIOCM_CTS : 0) | |
| 360 | ((portdata->dsr_state) ? TIOCM_DSR : 0) | |
| 361 | ((portdata->dcd_state) ? TIOCM_CAR : 0) | |
| 362 | ((portdata->ri_state) ? TIOCM_RNG : 0); |
| 363 | |
| 364 | return value; |
| 365 | } |
| 366 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 367 | static int sierra_tiocmset(struct tty_struct *tty, struct file *file, |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 368 | unsigned int set, unsigned int clear) |
| 369 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 370 | struct usb_serial_port *port = tty->driver_data; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 371 | struct sierra_port_private *portdata; |
| 372 | |
| 373 | portdata = usb_get_serial_port_data(port); |
| 374 | |
| 375 | if (set & TIOCM_RTS) |
| 376 | portdata->rts_state = 1; |
| 377 | if (set & TIOCM_DTR) |
| 378 | portdata->dtr_state = 1; |
| 379 | |
| 380 | if (clear & TIOCM_RTS) |
| 381 | portdata->rts_state = 0; |
| 382 | if (clear & TIOCM_DTR) |
| 383 | portdata->dtr_state = 0; |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 384 | return sierra_send_setup(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 387 | static void sierra_release_urb(struct urb *urb) |
| 388 | { |
| 389 | struct usb_serial_port *port; |
| 390 | if (urb) { |
| 391 | port = urb->context; |
| 392 | dev_dbg(&port->dev, "%s: %p\n", __func__, urb); |
| 393 | kfree(urb->transfer_buffer); |
| 394 | usb_free_urb(urb); |
| 395 | } |
| 396 | } |
| 397 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 398 | static void sierra_outdat_callback(struct urb *urb) |
| 399 | { |
| 400 | struct usb_serial_port *port = urb->context; |
| 401 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 402 | int status = urb->status; |
| 403 | unsigned long flags; |
| 404 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 405 | dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 406 | |
| 407 | /* free up the transfer buffer, as usb_free_urb() does not do this */ |
| 408 | kfree(urb->transfer_buffer); |
| 409 | |
| 410 | if (status) |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 411 | dev_dbg(&port->dev, "%s - nonzero write bulk status " |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 412 | "received: %d\n", __func__, status); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 413 | |
| 414 | spin_lock_irqsave(&portdata->lock, flags); |
| 415 | --portdata->outstanding_urbs; |
| 416 | spin_unlock_irqrestore(&portdata->lock, flags); |
| 417 | |
| 418 | usb_serial_port_softint(port); |
| 419 | } |
| 420 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 421 | /* Write */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 422 | static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 423 | const unsigned char *buf, int count) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 424 | { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 425 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 426 | struct usb_serial *serial = port->serial; |
| 427 | unsigned long flags; |
| 428 | unsigned char *buffer; |
| 429 | struct urb *urb; |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 430 | size_t writesize = min((size_t)count, (size_t)MAX_TRANSFER); |
| 431 | int retval = 0; |
| 432 | |
| 433 | /* verify that we actually have some data to write */ |
| 434 | if (count == 0) |
| 435 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 436 | |
| 437 | portdata = usb_get_serial_port_data(port); |
| 438 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 439 | dev_dbg(&port->dev, "%s: write (%d bytes)\n", __func__, writesize); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 440 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 441 | spin_lock_irqsave(&portdata->lock, flags); |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 442 | dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__, |
| 443 | portdata->outstanding_urbs); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 444 | if (portdata->outstanding_urbs > N_OUT_URB) { |
| 445 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 446 | dev_dbg(&port->dev, "%s - write limit hit\n", __func__); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | portdata->outstanding_urbs++; |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 450 | dev_dbg(&port->dev, "%s - 1, outstanding_urbs: %d\n", __func__, |
| 451 | portdata->outstanding_urbs); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 452 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 453 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 454 | buffer = kmalloc(writesize, GFP_ATOMIC); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 455 | if (!buffer) { |
| 456 | dev_err(&port->dev, "out of memory\n"); |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 457 | retval = -ENOMEM; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 458 | goto error_no_buffer; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 461 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 462 | if (!urb) { |
| 463 | dev_err(&port->dev, "no more free urbs\n"); |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 464 | retval = -ENOMEM; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 465 | goto error_no_urb; |
| 466 | } |
| 467 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 468 | memcpy(buffer, buf, writesize); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 469 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 470 | usb_serial_debug_data(debug, &port->dev, __func__, writesize, buffer); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 471 | |
| 472 | usb_fill_bulk_urb(urb, serial->dev, |
| 473 | usb_sndbulkpipe(serial->dev, |
| 474 | port->bulk_out_endpointAddress), |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 475 | buffer, writesize, sierra_outdat_callback, port); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 476 | |
| 477 | /* send it down the pipe */ |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 478 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 479 | if (retval) { |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 480 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 481 | "with status = %d\n", __func__, retval); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 482 | goto error; |
| 483 | } |
| 484 | |
| 485 | /* we are done with this urb, so let the host driver |
| 486 | * really free it when it is finished with it */ |
| 487 | usb_free_urb(urb); |
| 488 | |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 489 | return writesize; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 490 | error: |
| 491 | usb_free_urb(urb); |
| 492 | error_no_urb: |
| 493 | kfree(buffer); |
| 494 | error_no_buffer: |
| 495 | spin_lock_irqsave(&portdata->lock, flags); |
| 496 | --portdata->outstanding_urbs; |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 497 | dev_dbg(&port->dev, "%s - 2. outstanding_urbs: %d\n", __func__, |
| 498 | portdata->outstanding_urbs); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 499 | spin_unlock_irqrestore(&portdata->lock, flags); |
Elina Pasheva | 40d2ff3 | 2009-04-29 10:26:46 -0700 | [diff] [blame^] | 500 | return retval; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static void sierra_indat_callback(struct urb *urb) |
| 504 | { |
| 505 | int err; |
| 506 | int endpoint; |
| 507 | struct usb_serial_port *port; |
| 508 | struct tty_struct *tty; |
| 509 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 510 | int status = urb->status; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 511 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 512 | dbg("%s: %p", __func__, urb); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 513 | |
| 514 | endpoint = usb_pipeendpoint(urb->pipe); |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 515 | port = urb->context; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 516 | |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 517 | if (status) { |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 518 | dev_dbg(&port->dev, "%s: nonzero status: %d on" |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 519 | " endpoint %02x\n", __func__, status, endpoint); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 520 | } else { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 521 | if (urb->actual_length) { |
Alan Cox | d95186d | 2009-01-02 13:42:56 +0000 | [diff] [blame] | 522 | tty = tty_port_tty_get(&port->port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 523 | tty_buffer_request_room(tty, urb->actual_length); |
| 524 | tty_insert_flip_string(tty, data, urb->actual_length); |
| 525 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 526 | tty_kref_put(tty); |
| 527 | } else |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 528 | dev_dbg(&port->dev, "%s: empty read urb" |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 529 | " received\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 530 | |
| 531 | /* Resubmit urb so we continue receiving */ |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 532 | if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 533 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 534 | if (err) |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 535 | dev_err(&port->dev, "resubmit read urb failed." |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 536 | "(%d)\n", err); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | return; |
| 540 | } |
| 541 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 542 | static void sierra_instat_callback(struct urb *urb) |
| 543 | { |
| 544 | int err; |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 545 | int status = urb->status; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 546 | struct usb_serial_port *port = urb->context; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 547 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 548 | struct usb_serial *serial = port->serial; |
| 549 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 550 | dev_dbg(&port->dev, "%s\n", __func__); |
| 551 | dev_dbg(&port->dev, "%s: urb %p port %p has data %p\n", __func__, |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 552 | urb, port, portdata); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 553 | |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 554 | if (status == 0) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 555 | struct usb_ctrlrequest *req_pkt = |
| 556 | (struct usb_ctrlrequest *)urb->transfer_buffer; |
| 557 | |
| 558 | if (!req_pkt) { |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 559 | dev_dbg(&port->dev, "%s: NULL req_pkt\n", |
| 560 | __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 561 | return; |
| 562 | } |
| 563 | if ((req_pkt->bRequestType == 0xA1) && |
| 564 | (req_pkt->bRequest == 0x20)) { |
| 565 | int old_dcd_state; |
| 566 | unsigned char signals = *((unsigned char *) |
| 567 | urb->transfer_buffer + |
| 568 | sizeof(struct usb_ctrlrequest)); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 569 | struct tty_struct *tty; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 570 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 571 | dev_dbg(&port->dev, "%s: signal x%x\n", __func__, |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 572 | signals); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 573 | |
| 574 | old_dcd_state = portdata->dcd_state; |
| 575 | portdata->cts_state = 1; |
| 576 | portdata->dcd_state = ((signals & 0x01) ? 1 : 0); |
| 577 | portdata->dsr_state = ((signals & 0x02) ? 1 : 0); |
| 578 | portdata->ri_state = ((signals & 0x08) ? 1 : 0); |
| 579 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 580 | tty = tty_port_tty_get(&port->port); |
| 581 | if (tty && !C_CLOCAL(tty) && |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 582 | old_dcd_state && !portdata->dcd_state) |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 583 | tty_hangup(tty); |
| 584 | tty_kref_put(tty); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 585 | } else { |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 586 | dev_dbg(&port->dev, "%s: type %x req %x\n", |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 587 | __func__, req_pkt->bRequestType, |
| 588 | req_pkt->bRequest); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 589 | } |
| 590 | } else |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 591 | dev_dbg(&port->dev, "%s: error %d\n", __func__, status); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 592 | |
| 593 | /* Resubmit urb so we continue receiving IRQ data */ |
Greg Kroah-Hartman | 17dd221 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 594 | if (status != -ESHUTDOWN) { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 595 | urb->dev = serial->dev; |
| 596 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 597 | if (err) |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 598 | dev_dbg(&port->dev, "%s: resubmit intr urb " |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 599 | "failed. (%d)\n", __func__, err); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 603 | static int sierra_write_room(struct tty_struct *tty) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 604 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 605 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 606 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 607 | unsigned long flags; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 608 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 609 | dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 610 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 611 | /* try to give a good number back based on if we have any free urbs at |
| 612 | * this point in time */ |
| 613 | spin_lock_irqsave(&portdata->lock, flags); |
| 614 | if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) { |
| 615 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 616 | dev_dbg(&port->dev, "%s - write limit hit\n", __func__); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 617 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 618 | } |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 619 | spin_unlock_irqrestore(&portdata->lock, flags); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 620 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 621 | return 2048; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 624 | static void sierra_stop_rx_urbs(struct usb_serial_port *port) |
| 625 | { |
| 626 | int i; |
| 627 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 628 | |
| 629 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) |
| 630 | usb_kill_urb(portdata->in_urbs[i]); |
| 631 | |
| 632 | usb_kill_urb(port->interrupt_in_urb); |
| 633 | } |
| 634 | |
| 635 | static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags) |
| 636 | { |
| 637 | int ok_cnt; |
| 638 | int err = -EINVAL; |
| 639 | int i; |
| 640 | struct urb *urb; |
| 641 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
| 642 | |
| 643 | ok_cnt = 0; |
| 644 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { |
| 645 | urb = portdata->in_urbs[i]; |
| 646 | if (!urb) |
| 647 | continue; |
| 648 | err = usb_submit_urb(urb, mem_flags); |
| 649 | if (err) { |
| 650 | dev_err(&port->dev, "%s: submit urb failed: %d\n", |
| 651 | __func__, err); |
| 652 | } else { |
| 653 | ok_cnt++; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | if (ok_cnt && port->interrupt_in_urb) { |
| 658 | err = usb_submit_urb(port->interrupt_in_urb, mem_flags); |
| 659 | if (err) { |
| 660 | dev_err(&port->dev, "%s: submit intr urb failed: %d\n", |
| 661 | __func__, err); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | if (ok_cnt > 0) /* at least one rx urb submitted */ |
| 666 | return 0; |
| 667 | else |
| 668 | return err; |
| 669 | } |
| 670 | |
| 671 | static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, |
| 672 | int dir, void *ctx, int len, |
| 673 | gfp_t mem_flags, |
| 674 | usb_complete_t callback) |
| 675 | { |
| 676 | struct urb *urb; |
| 677 | u8 *buf; |
| 678 | |
| 679 | if (endpoint == -1) |
| 680 | return NULL; |
| 681 | |
| 682 | urb = usb_alloc_urb(0, mem_flags); |
| 683 | if (urb == NULL) { |
| 684 | dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n", |
| 685 | __func__, endpoint); |
| 686 | return NULL; |
| 687 | } |
| 688 | |
| 689 | buf = kmalloc(len, mem_flags); |
| 690 | if (buf) { |
| 691 | /* Fill URB using supplied data */ |
| 692 | usb_fill_bulk_urb(urb, serial->dev, |
| 693 | usb_sndbulkpipe(serial->dev, endpoint) | dir, |
| 694 | buf, len, callback, ctx); |
| 695 | |
| 696 | /* debug */ |
| 697 | dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__, |
| 698 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); |
| 699 | } else { |
| 700 | dev_dbg(&serial->dev->dev, "%s %c u:%p d:%p\n", __func__, |
| 701 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); |
| 702 | |
| 703 | sierra_release_urb(urb); |
| 704 | urb = NULL; |
| 705 | } |
| 706 | |
| 707 | return urb; |
| 708 | } |
| 709 | |
| 710 | static void sierra_close(struct usb_serial_port *port) |
| 711 | { |
| 712 | int i; |
| 713 | struct usb_serial *serial = port->serial; |
| 714 | struct sierra_port_private *portdata; |
| 715 | |
| 716 | dev_dbg(&port->dev, "%s\n", __func__); |
| 717 | portdata = usb_get_serial_port_data(port); |
| 718 | |
| 719 | portdata->rts_state = 0; |
| 720 | portdata->dtr_state = 0; |
| 721 | |
| 722 | if (serial->dev) { |
| 723 | mutex_lock(&serial->disc_mutex); |
| 724 | if (!serial->disconnected) |
| 725 | sierra_send_setup(port); |
| 726 | mutex_unlock(&serial->disc_mutex); |
| 727 | |
| 728 | /* Stop reading urbs */ |
| 729 | sierra_stop_rx_urbs(port); |
| 730 | /* .. and release them */ |
| 731 | for (i = 0; i < N_IN_URB; i++) { |
| 732 | sierra_release_urb(portdata->in_urbs[i]); |
| 733 | portdata->in_urbs[i] = NULL; |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 738 | static int sierra_open(struct tty_struct *tty, |
| 739 | struct usb_serial_port *port, struct file *filp) |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 740 | { |
| 741 | struct sierra_port_private *portdata; |
| 742 | struct usb_serial *serial = port->serial; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 743 | int i; |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 744 | int err; |
| 745 | int endpoint; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 746 | struct urb *urb; |
| 747 | |
| 748 | portdata = usb_get_serial_port_data(port); |
| 749 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 750 | dev_dbg(&port->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 751 | |
| 752 | /* Set some sane defaults */ |
| 753 | portdata->rts_state = 1; |
| 754 | portdata->dtr_state = 1; |
| 755 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 756 | |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 757 | endpoint = port->bulk_in_endpointAddress; |
| 758 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { |
| 759 | urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, |
| 760 | IN_BUFLEN, GFP_KERNEL, |
| 761 | sierra_indat_callback); |
| 762 | portdata->in_urbs[i] = urb; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 763 | } |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 764 | /* clear halt condition */ |
| 765 | usb_clear_halt(serial->dev, |
| 766 | usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 767 | |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 768 | err = sierra_submit_rx_urbs(port, GFP_KERNEL); |
| 769 | if (err) { |
| 770 | /* get rid of everything as in close */ |
| 771 | sierra_close(port); |
| 772 | return err; |
| 773 | } |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 774 | sierra_send_setup(port); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 775 | |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 776 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 779 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 780 | static void sierra_dtr_rts(struct usb_serial_port *port, int on) |
| 781 | { |
| 782 | struct usb_serial *serial = port->serial; |
| 783 | struct sierra_port_private *portdata; |
| 784 | |
| 785 | portdata = usb_get_serial_port_data(port); |
| 786 | portdata->rts_state = on; |
| 787 | portdata->dtr_state = on; |
| 788 | |
| 789 | if (serial->dev) { |
| 790 | mutex_lock(&serial->disc_mutex); |
| 791 | if (!serial->disconnected) |
| 792 | sierra_send_setup(port); |
| 793 | mutex_unlock(&serial->disc_mutex); |
| 794 | } |
| 795 | } |
| 796 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 797 | static int sierra_startup(struct usb_serial *serial) |
| 798 | { |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 799 | struct usb_serial_port *port; |
| 800 | struct sierra_port_private *portdata; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 801 | int i; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 802 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 803 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 804 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 805 | /* Set Device mode to D0 */ |
Kevin Lloyd | 112225b | 2007-07-16 13:49:27 -0700 | [diff] [blame] | 806 | sierra_set_power_state(serial->dev, 0x0000); |
| 807 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 808 | /* Check NMEA and set */ |
| 809 | if (nmea) |
| 810 | sierra_vsc_set_nmea(serial->dev, 1); |
| 811 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 812 | /* Now setup per port private data */ |
| 813 | for (i = 0; i < serial->num_ports; i++) { |
| 814 | port = serial->port[i]; |
| 815 | portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); |
| 816 | if (!portdata) { |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 817 | dev_dbg(&port->dev, "%s: kmalloc for " |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 818 | "sierra_port_private (%d) failed!.\n", |
Kevin Lloyd | 7384a92 | 2008-09-16 21:05:24 -0700 | [diff] [blame] | 819 | __func__, i); |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 820 | return -ENOMEM; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 821 | } |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 822 | spin_lock_init(&portdata->lock); |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 823 | /* Set the port private data pointer */ |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 824 | usb_set_serial_port_data(port, portdata); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Greg Kroah-Hartman | 17c2327 | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 827 | return 0; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | static void sierra_shutdown(struct usb_serial *serial) |
| 831 | { |
Elina Pasheva | b9a44bc1 | 2009-06-11 14:30:21 +0100 | [diff] [blame] | 832 | int i; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 833 | struct usb_serial_port *port; |
| 834 | struct sierra_port_private *portdata; |
| 835 | |
Elina Pasheva | 5d44b36 | 2009-04-27 18:41:52 -0700 | [diff] [blame] | 836 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 837 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 838 | for (i = 0; i < serial->num_ports; ++i) { |
| 839 | port = serial->port[i]; |
Greg Kroah-Hartman | f094e4f | 2007-04-26 00:12:01 -0700 | [diff] [blame] | 840 | if (!port) |
| 841 | continue; |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 842 | portdata = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | f094e4f | 2007-04-26 00:12:01 -0700 | [diff] [blame] | 843 | if (!portdata) |
| 844 | continue; |
Greg Kroah-Hartman | 9e85c5f | 2007-06-20 14:22:23 +0900 | [diff] [blame] | 845 | kfree(portdata); |
| 846 | usb_set_serial_port_data(port, NULL); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 850 | static struct usb_serial_driver sierra_device = { |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 851 | .driver = { |
| 852 | .owner = THIS_MODULE, |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 853 | .name = "sierra", |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 854 | }, |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 855 | .description = "Sierra USB modem", |
| 856 | .id_table = id_table, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 857 | .usb_driver = &sierra_driver, |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 858 | .calc_num_ports = sierra_calc_num_ports, |
| 859 | .probe = sierra_probe, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 860 | .open = sierra_open, |
| 861 | .close = sierra_close, |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 862 | .dtr_rts = sierra_dtr_rts, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 863 | .write = sierra_write, |
| 864 | .write_room = sierra_write_room, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 865 | .set_termios = sierra_set_termios, |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 866 | .tiocmget = sierra_tiocmget, |
| 867 | .tiocmset = sierra_tiocmset, |
| 868 | .attach = sierra_startup, |
| 869 | .shutdown = sierra_shutdown, |
| 870 | .read_int_callback = sierra_instat_callback, |
| 871 | }; |
| 872 | |
| 873 | /* Functions used by new usb-serial code. */ |
| 874 | static int __init sierra_init(void) |
| 875 | { |
| 876 | int retval; |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 877 | retval = usb_serial_register(&sierra_device); |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 878 | if (retval) |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 879 | goto failed_device_register; |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 880 | |
| 881 | |
| 882 | retval = usb_register(&sierra_driver); |
| 883 | if (retval) |
| 884 | goto failed_driver_register; |
| 885 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 886 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 887 | DRIVER_DESC "\n"); |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 888 | |
| 889 | return 0; |
| 890 | |
| 891 | failed_driver_register: |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 892 | usb_serial_deregister(&sierra_device); |
| 893 | failed_device_register: |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 894 | return retval; |
| 895 | } |
| 896 | |
| 897 | static void __exit sierra_exit(void) |
| 898 | { |
Alan Cox | 9660ea3 | 2008-07-22 11:14:59 +0100 | [diff] [blame] | 899 | usb_deregister(&sierra_driver); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 900 | usb_serial_deregister(&sierra_device); |
Greg Kroah-Hartman | 964ee1d | 2006-10-17 10:17:58 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | module_init(sierra_init); |
| 904 | module_exit(sierra_exit); |
| 905 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 906 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 907 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 908 | MODULE_VERSION(DRIVER_VERSION); |
Kevin Lloyd | 69de51f | 2006-06-30 11:17:55 -0700 | [diff] [blame] | 909 | MODULE_LICENSE("GPL"); |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 910 | |
Kevin Lloyd | 4e0fee8 | 2008-07-10 14:14:47 -0700 | [diff] [blame] | 911 | module_param(nmea, bool, S_IRUGO | S_IWUSR); |
Kevin Lloyd | 228426e | 2008-01-10 11:11:04 -0800 | [diff] [blame] | 912 | MODULE_PARM_DESC(nmea, "NMEA streaming"); |
| 913 | |
Kevin Lloyd | 033a3fb | 2006-10-13 23:53:21 -0700 | [diff] [blame] | 914 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 915 | MODULE_PARM_DESC(debug, "Debug messages"); |