blob: 88ec7bfd9d354f9c157b1ab3270c0bd49ff2402b [file] [log] [blame]
Kevin Lloyd69de51f2006-06-30 11:17:55 -07001/*
Kevin Lloyd033a3fb2006-10-13 23:53:21 -07002 USB Driver for Sierra Wireless
3
Kevin Lloydf3564de2008-03-28 10:05:08 -07004 Copyright (C) 2006, 2007, 2008 Kevin Lloyd <klloyd@sierrawireless.com>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -07005
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 Lloyd033a3fb2006-10-13 23:53:21 -070015*/
16
Elina Pasheva212b8f02009-04-21 17:54:42 -070017#define DRIVER_VERSION "v.1.3.3"
Kevin Lloydf3564de2008-03-28 10:05:08 -070018#define DRIVER_AUTHOR "Kevin Lloyd <klloyd@sierrawireless.com>"
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070019#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
Kevin Lloyd69de51f2006-06-30 11:17:55 -070020
21#include <linux/kernel.h>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070022#include <linux/jiffies.h>
23#include <linux/errno.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070024#include <linux/tty.h>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070025#include <linux/tty_flip.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070026#include <linux/module.h>
27#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070028#include <linux/usb/serial.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070029
Kevin Lloyd228426e2008-01-10 11:11:04 -080030#define SWIMS_USB_REQUEST_SetPower 0x00
31#define SWIMS_USB_REQUEST_SetNmea 0x07
Kevin Lloyd112225b2007-07-16 13:49:27 -070032
Kevin Lloyd112225b2007-07-16 13:49:27 -070033#define N_IN_URB 4
34#define N_OUT_URB 4
35#define IN_BUFLEN 4096
36
37static int debug;
Kevin Lloyd228426e2008-01-10 11:11:04 -080038static int nmea;
Kevin Lloyd112225b2007-07-16 13:49:27 -070039
Adrian Bunk82a24e62007-07-29 16:59:02 +020040static int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
Kevin Lloyd112225b2007-07-16 13:49:27 -070041{
42 int result;
Kevin Lloyd4e0fee82008-07-10 14:14:47 -070043 dev_dbg(&udev->dev, "%s", __func__);
Kevin Lloyd112225b2007-07-16 13:49:27 -070044 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
Kevin Lloyd228426e2008-01-10 11:11:04 -080045 SWIMS_USB_REQUEST_SetPower, /* __u8 request */
Kevin Lloydf3564de2008-03-28 10:05:08 -070046 USB_TYPE_VENDOR, /* __u8 request type */
Kevin Lloyd228426e2008-01-10 11:11:04 -080047 swiState, /* __u16 value */
48 0, /* __u16 index */
49 NULL, /* void *data */
50 0, /* __u16 size */
51 USB_CTRL_SET_TIMEOUT); /* int timeout */
Kevin Lloyd112225b2007-07-16 13:49:27 -070052 return result;
53}
54
Kevin Lloyd228426e2008-01-10 11:11:04 -080055static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable)
Kevin Lloyd112225b2007-07-16 13:49:27 -070056{
57 int result;
Kevin Lloyd4e0fee82008-07-10 14:14:47 -070058 dev_dbg(&udev->dev, "%s", __func__);
Kevin Lloyd228426e2008-01-10 11:11:04 -080059 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
60 SWIMS_USB_REQUEST_SetNmea, /* __u8 request */
Kevin Lloydf3564de2008-03-28 10:05:08 -070061 USB_TYPE_VENDOR, /* __u8 request type */
Kevin Lloyd228426e2008-01-10 11:11:04 -080062 enable, /* __u16 value */
63 0x0000, /* __u16 index */
64 NULL, /* void *data */
65 0, /* __u16 size */
66 USB_CTRL_SET_TIMEOUT); /* int timeout */
67 return result;
68}
Kevin Lloyd112225b2007-07-16 13:49:27 -070069
Kevin Lloyd228426e2008-01-10 11:11:04 -080070static int sierra_calc_num_ports(struct usb_serial *serial)
71{
72 int result;
73 int *num_ports = usb_get_serial_data(serial);
Kevin Lloyd4e0fee82008-07-10 14:14:47 -070074 dev_dbg(&serial->dev->dev, "%s", __func__);
Kevin Lloyd112225b2007-07-16 13:49:27 -070075
Kevin Lloyd228426e2008-01-10 11:11:04 -080076 result = *num_ports;
77
78 if (result) {
79 kfree(num_ports);
80 usb_set_serial_data(serial, NULL);
Kevin Lloyd112225b2007-07-16 13:49:27 -070081 }
82
Kevin Lloyd228426e2008-01-10 11:11:04 -080083 return result;
84}
85
Kevin Lloyd71069672008-04-02 11:24:56 -070086static int sierra_calc_interface(struct usb_serial *serial)
87{
Kevin Lloyd4e0fee82008-07-10 14:14:47 -070088 int interface;
89 struct usb_interface *p_interface;
90 struct usb_host_interface *p_host_interface;
91 dev_dbg(&serial->dev->dev, "%s", __func__);
Kevin Lloyd71069672008-04-02 11:24:56 -070092
Kevin Lloyd4e0fee82008-07-10 14:14:47 -070093 /* Get the interface structure pointer from the serial struct */
94 p_interface = serial->interface;
Kevin Lloyd71069672008-04-02 11:24:56 -070095
Kevin Lloyd4e0fee82008-07-10 14:14:47 -070096 /* Get a pointer to the host interface structure */
97 p_host_interface = p_interface->cur_altsetting;
Kevin Lloyd71069672008-04-02 11:24:56 -070098
Kevin Lloyd4e0fee82008-07-10 14:14:47 -070099 /* read the interface descriptor for this active altsetting
100 * to find out the interface number we are on
101 */
102 interface = p_host_interface->desc.bInterfaceNumber;
Kevin Lloyd71069672008-04-02 11:24:56 -0700103
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700104 return interface;
Kevin Lloyd71069672008-04-02 11:24:56 -0700105}
106
Kevin Lloyd228426e2008-01-10 11:11:04 -0800107static int sierra_probe(struct usb_serial *serial,
108 const struct usb_device_id *id)
109{
110 int result = 0;
111 struct usb_device *udev;
112 int *num_ports;
113 u8 ifnum;
Kevin Lloyde3173b22008-07-10 14:14:51 -0700114 u8 numendpoints;
115
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700116 dev_dbg(&serial->dev->dev, "%s", __func__);
Kevin Lloyd228426e2008-01-10 11:11:04 -0800117
118 num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL);
119 if (!num_ports)
120 return -ENOMEM;
121
122 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
Kevin Lloyde3173b22008-07-10 14:14:51 -0700123 numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints;
Kevin Lloyd228426e2008-01-10 11:11:04 -0800124 udev = serial->dev;
125
Kevin Lloyde3173b22008-07-10 14:14:51 -0700126 /* Figure out the interface number from the serial structure */
127 ifnum = sierra_calc_interface(serial);
Kevin Lloyd71069672008-04-02 11:24:56 -0700128
Kevin Lloyde3173b22008-07-10 14:14:51 -0700129 /*
130 * If this interface supports more than 1 alternate
131 * select the 2nd one
132 */
133 if (serial->interface->num_altsetting == 2) {
134 dev_dbg(&udev->dev, "Selecting alt setting for interface %d\n",
135 ifnum);
136 /* We know the alternate setting is 1 for the MC8785 */
137 usb_set_interface(udev, ifnum, 1);
138 }
Kevin Lloyd71069672008-04-02 11:24:56 -0700139
Kevin Lloyde3173b22008-07-10 14:14:51 -0700140 /* Dummy interface present on some SKUs should be ignored */
Kevin Lloyd0585e4d2008-07-10 14:14:54 -0700141 if (ifnum == 0x99)
Kevin Lloyd228426e2008-01-10 11:11:04 -0800142 *num_ports = 0;
Kevin Lloyde3173b22008-07-10 14:14:51 -0700143 else if (numendpoints <= 3)
144 *num_ports = 1;
Kevin Lloyd228426e2008-01-10 11:11:04 -0800145 else
Kevin Lloyde3173b22008-07-10 14:14:51 -0700146 *num_ports = (numendpoints-1)/2;
147
Kevin Lloyd228426e2008-01-10 11:11:04 -0800148 /*
149 * save off our num_ports info so that we can use it in the
150 * calc_num_ports callback
151 */
152 usb_set_serial_data(serial, (void *)num_ports);
153
154 return result;
Kevin Lloyd112225b2007-07-16 13:49:27 -0700155}
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700156
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700157static struct usb_device_id id_table [] = {
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700158 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800159 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
Greg Kroah-Hartman90ac3c82002-04-09 12:14:34 -0700160 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
Tony Murrayf8834f12008-08-22 17:30:44 -0500161 { USB_DEVICE(0x03f0, 0x1b1d) }, /* HP ev2200 a.k.a MC5720 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800162 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700163 { USB_DEVICE(0x1199, 0x0024) }, /* Sierra Wireless MC5727 */
agilmore@wirelessbeehive.comb9e13ac2007-12-04 11:37:12 -0700164 { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800165 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
166 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700167 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700168 /* Sierra Wireless C597 */
169 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0023, 0xFF, 0xFF, 0xFF) },
Kevin Lloyde3173b22008-07-10 14:14:51 -0700170 /* Sierra Wireless Device */
171 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0025, 0xFF, 0xFF, 0xFF) },
172 { USB_DEVICE(0x1199, 0x0026) }, /* Sierra Wireless Device */
Kevin Lloyd73b2c202008-08-25 19:20:40 -0700173 { USB_DEVICE(0x1199, 0x0027) }, /* Sierra Wireless Device */
174 { USB_DEVICE(0x1199, 0x0028) }, /* Sierra Wireless Device */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700175
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700176 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800177 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700178 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700179 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700180 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Lenovo) */
Kevin Lloyd7f170a62008-03-14 00:53:24 -0700181 { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */
Stefan Seyfried8f7f85e2008-04-17 07:47:34 +0200182 { USB_DEVICE(0x03f0, 0x1e1d) }, /* HP hs2300 a.k.a MC8775 */
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700183 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
Kevin Lloyd71069672008-04-02 11:24:56 -0700184 { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700185 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780 */
186 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */
Kevin Lloydb77a5c72008-09-17 09:03:38 -0700187 { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */
Kevin Lloyde3173b22008-07-10 14:14:51 -0700188 { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */
189 { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */
190 { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */
191 { USB_DEVICE(0x1199, 0x683E) }, /* Sierra Wireless MC8790 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700192 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
193 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
194 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
195 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
Kevin Lloyd6835b322008-01-10 11:11:04 -0800196 { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
Jessica L. Blank62aad3a2007-12-30 20:11:35 -0600197 { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
Kevin Lloyde3173b22008-07-10 14:14:51 -0700198 { USB_DEVICE(0x1199, 0x6859) }, /* Sierra Wireless AirCard 885 E */
199 { USB_DEVICE(0x1199, 0x685A) }, /* Sierra Wireless AirCard 885 E */
200 /* Sierra Wireless C885 */
201 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6880, 0xFF, 0xFF, 0xFF)},
202 /* Sierra Wireless Device */
203 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6890, 0xFF, 0xFF, 0xFF)},
204 /* Sierra Wireless Device */
Kevin Lloyd73b2c202008-08-25 19:20:40 -0700205 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6891, 0xFF, 0xFF, 0xFF)},
206 /* Sierra Wireless Device */
Kevin Lloyde3173b22008-07-10 14:14:51 -0700207 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6892, 0xFF, 0xFF, 0xFF)},
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700208
Kevin Lloyde3173b22008-07-10 14:14:51 -0700209 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
210 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */
Kevin Lloyd112225b2007-07-16 13:49:27 -0700211
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700212 { }
213};
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700214MODULE_DEVICE_TABLE(usb, id_table);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700215
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700216static struct usb_driver sierra_driver = {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700217 .name = "sierra",
Kevin Lloyd228426e2008-01-10 11:11:04 -0800218 .probe = usb_serial_probe,
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700219 .disconnect = usb_serial_disconnect,
220 .id_table = id_table,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700221 .no_dynamic_id = 1,
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700222};
223
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700224struct sierra_port_private {
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900225 spinlock_t lock; /* lock the structure */
226 int outstanding_urbs; /* number of out urbs in flight */
227
Oliver Neukum4f4f9c52008-03-14 00:53:24 -0700228 /* Input endpoints and buffers for this port */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700229 struct urb *in_urbs[N_IN_URB];
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700230
231 /* Settings for the port */
232 int rts_state; /* Handshaking pins (outputs) */
233 int dtr_state;
234 int cts_state; /* Handshaking pins (inputs) */
235 int dsr_state;
236 int dcd_state;
237 int ri_state;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700238};
239
Alan Cox335f8512009-06-11 12:26:29 +0100240static int sierra_send_setup(struct usb_serial_port *port)
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700241{
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700242 struct usb_serial *serial = port->serial;
243 struct sierra_port_private *portdata;
Kevin Lloyd228426e2008-01-10 11:11:04 -0800244 __u16 interface = 0;
Alan Cox335f8512009-06-11 12:26:29 +0100245 int val = 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700246
Kevin Lloyd7384a922008-09-16 21:05:24 -0700247 dev_dbg(&port->dev, "%s", __func__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700248
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700249 portdata = usb_get_serial_port_data(port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700250
Alan Cox335f8512009-06-11 12:26:29 +0100251 if (portdata->dtr_state)
252 val |= 0x01;
253 if (portdata->rts_state)
254 val |= 0x02;
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700255
Alan Cox335f8512009-06-11 12:26:29 +0100256 /* If composite device then properly report interface */
Alan Cox00b040d2009-06-11 14:29:29 +0100257 if (serial->num_ports == 1) {
Alan Cox335f8512009-06-11 12:26:29 +0100258 interface = sierra_calc_interface(serial);
Alan Cox00b040d2009-06-11 14:29:29 +0100259 /* Control message is sent only to interfaces with
260 * interrupt_in endpoints
261 */
262 if (port->interrupt_in_urb) {
263 /* send control message */
264 return usb_control_msg(serial->dev,
265 usb_rcvctrlpipe(serial->dev, 0),
266 0x22, 0x21, val, interface,
267 NULL, 0, USB_CTRL_SET_TIMEOUT);
268 }
269 }
Kevin Lloyde3173b22008-07-10 14:14:51 -0700270
Alan Cox335f8512009-06-11 12:26:29 +0100271 /* Otherwise the need to do non-composite mapping */
272 else {
273 if (port->bulk_out_endpointAddress == 2)
274 interface = 0;
275 else if (port->bulk_out_endpointAddress == 4)
276 interface = 1;
277 else if (port->bulk_out_endpointAddress == 5)
278 interface = 2;
Alan Cox00b040d2009-06-11 14:29:29 +0100279 return usb_control_msg(serial->dev,
Alan Cox335f8512009-06-11 12:26:29 +0100280 usb_rcvctrlpipe(serial->dev, 0),
281 0x22, 0x21, val, interface,
282 NULL, 0, USB_CTRL_SET_TIMEOUT);
Alan Cox00b040d2009-06-11 14:29:29 +0100283 }
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700284 return 0;
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700285}
286
Alan Cox95da3102008-07-22 11:09:07 +0100287static void sierra_set_termios(struct tty_struct *tty,
288 struct usb_serial_port *port, struct ktermios *old_termios)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700289{
Kevin Lloyd7384a922008-09-16 21:05:24 -0700290 dev_dbg(&port->dev, "%s", __func__);
Alan Cox95da3102008-07-22 11:09:07 +0100291 tty_termios_copy_hw(tty->termios, old_termios);
Alan Cox335f8512009-06-11 12:26:29 +0100292 sierra_send_setup(port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700293}
294
Alan Cox95da3102008-07-22 11:09:07 +0100295static int sierra_tiocmget(struct tty_struct *tty, struct file *file)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700296{
Alan Cox95da3102008-07-22 11:09:07 +0100297 struct usb_serial_port *port = tty->driver_data;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700298 unsigned int value;
299 struct sierra_port_private *portdata;
300
Kevin Lloyd7384a922008-09-16 21:05:24 -0700301 dev_dbg(&port->dev, "%s", __func__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700302 portdata = usb_get_serial_port_data(port);
303
304 value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
305 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
306 ((portdata->cts_state) ? TIOCM_CTS : 0) |
307 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
308 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
309 ((portdata->ri_state) ? TIOCM_RNG : 0);
310
311 return value;
312}
313
Alan Cox95da3102008-07-22 11:09:07 +0100314static int sierra_tiocmset(struct tty_struct *tty, struct file *file,
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700315 unsigned int set, unsigned int clear)
316{
Alan Cox95da3102008-07-22 11:09:07 +0100317 struct usb_serial_port *port = tty->driver_data;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700318 struct sierra_port_private *portdata;
319
320 portdata = usb_get_serial_port_data(port);
321
322 if (set & TIOCM_RTS)
323 portdata->rts_state = 1;
324 if (set & TIOCM_DTR)
325 portdata->dtr_state = 1;
326
327 if (clear & TIOCM_RTS)
328 portdata->rts_state = 0;
329 if (clear & TIOCM_DTR)
330 portdata->dtr_state = 0;
Alan Cox335f8512009-06-11 12:26:29 +0100331 return sierra_send_setup(port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700332}
333
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100334static void sierra_release_urb(struct urb *urb)
335{
336 struct usb_serial_port *port;
337 if (urb) {
338 port = urb->context;
339 dev_dbg(&port->dev, "%s: %p\n", __func__, urb);
340 kfree(urb->transfer_buffer);
341 usb_free_urb(urb);
342 }
343}
344
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900345static void sierra_outdat_callback(struct urb *urb)
346{
347 struct usb_serial_port *port = urb->context;
348 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
349 int status = urb->status;
350 unsigned long flags;
351
Kevin Lloyd7384a922008-09-16 21:05:24 -0700352 dev_dbg(&port->dev, "%s - port %d", __func__, port->number);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900353
354 /* free up the transfer buffer, as usb_free_urb() does not do this */
355 kfree(urb->transfer_buffer);
356
357 if (status)
Kevin Lloyd7384a922008-09-16 21:05:24 -0700358 dev_dbg(&port->dev, "%s - nonzero write bulk status "
359 "received: %d", __func__, status);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900360
361 spin_lock_irqsave(&portdata->lock, flags);
362 --portdata->outstanding_urbs;
363 spin_unlock_irqrestore(&portdata->lock, flags);
364
365 usb_serial_port_softint(port);
366}
367
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700368/* Write */
Alan Cox95da3102008-07-22 11:09:07 +0100369static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
370 const unsigned char *buf, int count)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700371{
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900372 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
373 struct usb_serial *serial = port->serial;
374 unsigned long flags;
375 unsigned char *buffer;
376 struct urb *urb;
377 int status;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700378
379 portdata = usb_get_serial_port_data(port);
380
Kevin Lloyd7384a922008-09-16 21:05:24 -0700381 dev_dbg(&port->dev, "%s: write (%d chars)", __func__, count);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700382
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900383 spin_lock_irqsave(&portdata->lock, flags);
384 if (portdata->outstanding_urbs > N_OUT_URB) {
385 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd7384a922008-09-16 21:05:24 -0700386 dev_dbg(&port->dev, "%s - write limit hit\n", __func__);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900387 return 0;
388 }
389 portdata->outstanding_urbs++;
390 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700391
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900392 buffer = kmalloc(count, GFP_ATOMIC);
393 if (!buffer) {
394 dev_err(&port->dev, "out of memory\n");
395 count = -ENOMEM;
396 goto error_no_buffer;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700397 }
398
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900399 urb = usb_alloc_urb(0, GFP_ATOMIC);
400 if (!urb) {
401 dev_err(&port->dev, "no more free urbs\n");
402 count = -ENOMEM;
403 goto error_no_urb;
404 }
405
406 memcpy(buffer, buf, count);
407
Harvey Harrison441b62c2008-03-03 16:08:34 -0800408 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900409
410 usb_fill_bulk_urb(urb, serial->dev,
411 usb_sndbulkpipe(serial->dev,
412 port->bulk_out_endpointAddress),
413 buffer, count, sierra_outdat_callback, port);
414
415 /* send it down the pipe */
416 status = usb_submit_urb(urb, GFP_ATOMIC);
417 if (status) {
418 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed "
Harvey Harrison441b62c2008-03-03 16:08:34 -0800419 "with status = %d\n", __func__, status);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900420 count = status;
421 goto error;
422 }
423
424 /* we are done with this urb, so let the host driver
425 * really free it when it is finished with it */
426 usb_free_urb(urb);
427
428 return count;
429error:
430 usb_free_urb(urb);
431error_no_urb:
432 kfree(buffer);
433error_no_buffer:
434 spin_lock_irqsave(&portdata->lock, flags);
435 --portdata->outstanding_urbs;
436 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700437 return count;
438}
439
440static void sierra_indat_callback(struct urb *urb)
441{
442 int err;
443 int endpoint;
444 struct usb_serial_port *port;
445 struct tty_struct *tty;
446 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700447 int status = urb->status;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700448
Harvey Harrison441b62c2008-03-03 16:08:34 -0800449 dbg("%s: %p", __func__, urb);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700450
451 endpoint = usb_pipeendpoint(urb->pipe);
Ming Leicdc97792008-02-24 18:41:47 +0800452 port = urb->context;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700453
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700454 if (status) {
Kevin Lloyd7384a922008-09-16 21:05:24 -0700455 dev_dbg(&port->dev, "%s: nonzero status: %d on"
456 " endpoint %02x.", __func__, status, endpoint);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700457 } else {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700458 if (urb->actual_length) {
Alan Coxd95186d2009-01-02 13:42:56 +0000459 tty = tty_port_tty_get(&port->port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700460 tty_buffer_request_room(tty, urb->actual_length);
461 tty_insert_flip_string(tty, data, urb->actual_length);
462 tty_flip_buffer_push(tty);
Alan Cox4a90f092008-10-13 10:39:46 +0100463 tty_kref_put(tty);
464 } else
Kevin Lloyd7384a922008-09-16 21:05:24 -0700465 dev_dbg(&port->dev, "%s: empty read urb"
466 " received", __func__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700467
468 /* Resubmit urb so we continue receiving */
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100469 if (port->port.count && status != -ESHUTDOWN && status != -EPERM) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700470 err = usb_submit_urb(urb, GFP_ATOMIC);
471 if (err)
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900472 dev_err(&port->dev, "resubmit read urb failed."
Joe Perches898eb712007-10-18 03:06:30 -0700473 "(%d)\n", err);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700474 }
475 }
476 return;
477}
478
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700479static void sierra_instat_callback(struct urb *urb)
480{
481 int err;
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700482 int status = urb->status;
Ming Leicdc97792008-02-24 18:41:47 +0800483 struct usb_serial_port *port = urb->context;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700484 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
485 struct usb_serial *serial = port->serial;
486
Kevin Lloyd7384a922008-09-16 21:05:24 -0700487 dev_dbg(&port->dev, "%s", __func__);
488 dev_dbg(&port->dev, "%s: urb %p port %p has data %p", __func__,
489 urb, port, portdata);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700490
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700491 if (status == 0) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700492 struct usb_ctrlrequest *req_pkt =
493 (struct usb_ctrlrequest *)urb->transfer_buffer;
494
495 if (!req_pkt) {
Kevin Lloyd7384a922008-09-16 21:05:24 -0700496 dev_dbg(&port->dev, "%s: NULL req_pkt\n",
497 __func__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700498 return;
499 }
500 if ((req_pkt->bRequestType == 0xA1) &&
501 (req_pkt->bRequest == 0x20)) {
502 int old_dcd_state;
503 unsigned char signals = *((unsigned char *)
504 urb->transfer_buffer +
505 sizeof(struct usb_ctrlrequest));
Alan Cox4a90f092008-10-13 10:39:46 +0100506 struct tty_struct *tty;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700507
Kevin Lloyd7384a922008-09-16 21:05:24 -0700508 dev_dbg(&port->dev, "%s: signal x%x", __func__,
509 signals);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700510
511 old_dcd_state = portdata->dcd_state;
512 portdata->cts_state = 1;
513 portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
514 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
515 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
516
Alan Cox4a90f092008-10-13 10:39:46 +0100517 tty = tty_port_tty_get(&port->port);
518 if (tty && !C_CLOCAL(tty) &&
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700519 old_dcd_state && !portdata->dcd_state)
Alan Cox4a90f092008-10-13 10:39:46 +0100520 tty_hangup(tty);
521 tty_kref_put(tty);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700522 } else {
Kevin Lloyd7384a922008-09-16 21:05:24 -0700523 dev_dbg(&port->dev, "%s: type %x req %x",
524 __func__, req_pkt->bRequestType,
525 req_pkt->bRequest);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700526 }
527 } else
Kevin Lloyd7384a922008-09-16 21:05:24 -0700528 dev_dbg(&port->dev, "%s: error %d", __func__, status);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700529
530 /* Resubmit urb so we continue receiving IRQ data */
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700531 if (status != -ESHUTDOWN) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700532 urb->dev = serial->dev;
533 err = usb_submit_urb(urb, GFP_ATOMIC);
534 if (err)
Kevin Lloyd7384a922008-09-16 21:05:24 -0700535 dev_dbg(&port->dev, "%s: resubmit intr urb "
536 "failed. (%d)", __func__, err);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700537 }
538}
539
Alan Cox95da3102008-07-22 11:09:07 +0100540static int sierra_write_room(struct tty_struct *tty)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700541{
Alan Cox95da3102008-07-22 11:09:07 +0100542 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900543 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
544 unsigned long flags;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700545
Kevin Lloyd7384a922008-09-16 21:05:24 -0700546 dev_dbg(&port->dev, "%s - port %d", __func__, port->number);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700547
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900548 /* try to give a good number back based on if we have any free urbs at
549 * this point in time */
550 spin_lock_irqsave(&portdata->lock, flags);
551 if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) {
552 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd7384a922008-09-16 21:05:24 -0700553 dev_dbg(&port->dev, "%s - write limit hit\n", __func__);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900554 return 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700555 }
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900556 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700557
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900558 return 2048;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700559}
560
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100561static void sierra_stop_rx_urbs(struct usb_serial_port *port)
562{
563 int i;
564 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
565
566 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++)
567 usb_kill_urb(portdata->in_urbs[i]);
568
569 usb_kill_urb(port->interrupt_in_urb);
570}
571
572static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags)
573{
574 int ok_cnt;
575 int err = -EINVAL;
576 int i;
577 struct urb *urb;
578 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
579
580 ok_cnt = 0;
581 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) {
582 urb = portdata->in_urbs[i];
583 if (!urb)
584 continue;
585 err = usb_submit_urb(urb, mem_flags);
586 if (err) {
587 dev_err(&port->dev, "%s: submit urb failed: %d\n",
588 __func__, err);
589 } else {
590 ok_cnt++;
591 }
592 }
593
594 if (ok_cnt && port->interrupt_in_urb) {
595 err = usb_submit_urb(port->interrupt_in_urb, mem_flags);
596 if (err) {
597 dev_err(&port->dev, "%s: submit intr urb failed: %d\n",
598 __func__, err);
599 }
600 }
601
602 if (ok_cnt > 0) /* at least one rx urb submitted */
603 return 0;
604 else
605 return err;
606}
607
608static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint,
609 int dir, void *ctx, int len,
610 gfp_t mem_flags,
611 usb_complete_t callback)
612{
613 struct urb *urb;
614 u8 *buf;
615
616 if (endpoint == -1)
617 return NULL;
618
619 urb = usb_alloc_urb(0, mem_flags);
620 if (urb == NULL) {
621 dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n",
622 __func__, endpoint);
623 return NULL;
624 }
625
626 buf = kmalloc(len, mem_flags);
627 if (buf) {
628 /* Fill URB using supplied data */
629 usb_fill_bulk_urb(urb, serial->dev,
630 usb_sndbulkpipe(serial->dev, endpoint) | dir,
631 buf, len, callback, ctx);
632
633 /* debug */
634 dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__,
635 dir == USB_DIR_IN ? 'i' : 'o', urb, buf);
636 } else {
637 dev_dbg(&serial->dev->dev, "%s %c u:%p d:%p\n", __func__,
638 dir == USB_DIR_IN ? 'i' : 'o', urb, buf);
639
640 sierra_release_urb(urb);
641 urb = NULL;
642 }
643
644 return urb;
645}
646
647static void sierra_close(struct usb_serial_port *port)
648{
649 int i;
650 struct usb_serial *serial = port->serial;
651 struct sierra_port_private *portdata;
652
653 dev_dbg(&port->dev, "%s\n", __func__);
654 portdata = usb_get_serial_port_data(port);
655
656 portdata->rts_state = 0;
657 portdata->dtr_state = 0;
658
659 if (serial->dev) {
660 mutex_lock(&serial->disc_mutex);
661 if (!serial->disconnected)
662 sierra_send_setup(port);
663 mutex_unlock(&serial->disc_mutex);
664
665 /* Stop reading urbs */
666 sierra_stop_rx_urbs(port);
667 /* .. and release them */
668 for (i = 0; i < N_IN_URB; i++) {
669 sierra_release_urb(portdata->in_urbs[i]);
670 portdata->in_urbs[i] = NULL;
671 }
672 }
673}
674
Alan Cox95da3102008-07-22 11:09:07 +0100675static int sierra_open(struct tty_struct *tty,
676 struct usb_serial_port *port, struct file *filp)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700677{
678 struct sierra_port_private *portdata;
679 struct usb_serial *serial = port->serial;
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900680 int i;
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100681 int err;
682 int endpoint;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700683 struct urb *urb;
684
685 portdata = usb_get_serial_port_data(port);
686
Kevin Lloyd7384a922008-09-16 21:05:24 -0700687 dev_dbg(&port->dev, "%s", __func__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700688
689 /* Set some sane defaults */
690 portdata->rts_state = 1;
691 portdata->dtr_state = 1;
692
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700693
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100694 endpoint = port->bulk_in_endpointAddress;
695 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) {
696 urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port,
697 IN_BUFLEN, GFP_KERNEL,
698 sierra_indat_callback);
699 portdata->in_urbs[i] = urb;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700700 }
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100701 /* clear halt condition */
702 usb_clear_halt(serial->dev,
703 usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700704
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100705 err = sierra_submit_rx_urbs(port, GFP_KERNEL);
706 if (err) {
707 /* get rid of everything as in close */
708 sierra_close(port);
709 return err;
710 }
Alan Cox335f8512009-06-11 12:26:29 +0100711 sierra_send_setup(port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700712
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900713 return 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700714}
715
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100716
Alan Cox335f8512009-06-11 12:26:29 +0100717static void sierra_dtr_rts(struct usb_serial_port *port, int on)
718{
719 struct usb_serial *serial = port->serial;
720 struct sierra_port_private *portdata;
721
722 portdata = usb_get_serial_port_data(port);
723 portdata->rts_state = on;
724 portdata->dtr_state = on;
725
726 if (serial->dev) {
727 mutex_lock(&serial->disc_mutex);
728 if (!serial->disconnected)
729 sierra_send_setup(port);
730 mutex_unlock(&serial->disc_mutex);
731 }
732}
733
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700734static int sierra_startup(struct usb_serial *serial)
735{
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700736 struct usb_serial_port *port;
737 struct sierra_port_private *portdata;
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900738 int i;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700739
Kevin Lloyd7384a922008-09-16 21:05:24 -0700740 dev_dbg(&serial->dev->dev, "%s", __func__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700741
Kevin Lloyd228426e2008-01-10 11:11:04 -0800742 /* Set Device mode to D0 */
Kevin Lloyd112225b2007-07-16 13:49:27 -0700743 sierra_set_power_state(serial->dev, 0x0000);
744
Kevin Lloyd228426e2008-01-10 11:11:04 -0800745 /* Check NMEA and set */
746 if (nmea)
747 sierra_vsc_set_nmea(serial->dev, 1);
748
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700749 /* Now setup per port private data */
750 for (i = 0; i < serial->num_ports; i++) {
751 port = serial->port[i];
752 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
753 if (!portdata) {
Kevin Lloyd7384a922008-09-16 21:05:24 -0700754 dev_dbg(&port->dev, "%s: kmalloc for "
755 "sierra_port_private (%d) failed!.",
756 __func__, i);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900757 return -ENOMEM;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700758 }
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900759 spin_lock_init(&portdata->lock);
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100760 /* Set the port private data pointer */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700761 usb_set_serial_port_data(port, portdata);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700762 }
763
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900764 return 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700765}
766
767static void sierra_shutdown(struct usb_serial *serial)
768{
Elina Pashevab9a44bc12009-06-11 14:30:21 +0100769 int i;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700770 struct usb_serial_port *port;
771 struct sierra_port_private *portdata;
772
Kevin Lloyd7384a922008-09-16 21:05:24 -0700773 dev_dbg(&serial->dev->dev, "%s", __func__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700774
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700775 for (i = 0; i < serial->num_ports; ++i) {
776 port = serial->port[i];
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700777 if (!port)
778 continue;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700779 portdata = usb_get_serial_port_data(port);
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700780 if (!portdata)
781 continue;
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900782 kfree(portdata);
783 usb_set_serial_port_data(port, NULL);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700784 }
785}
786
Kevin Lloyd228426e2008-01-10 11:11:04 -0800787static struct usb_serial_driver sierra_device = {
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700788 .driver = {
789 .owner = THIS_MODULE,
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700790 .name = "sierra",
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700791 },
Kevin Lloyd228426e2008-01-10 11:11:04 -0800792 .description = "Sierra USB modem",
793 .id_table = id_table,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100794 .usb_driver = &sierra_driver,
Kevin Lloyd228426e2008-01-10 11:11:04 -0800795 .calc_num_ports = sierra_calc_num_ports,
796 .probe = sierra_probe,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700797 .open = sierra_open,
798 .close = sierra_close,
Alan Cox335f8512009-06-11 12:26:29 +0100799 .dtr_rts = sierra_dtr_rts,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700800 .write = sierra_write,
801 .write_room = sierra_write_room,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700802 .set_termios = sierra_set_termios,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700803 .tiocmget = sierra_tiocmget,
804 .tiocmset = sierra_tiocmset,
805 .attach = sierra_startup,
806 .shutdown = sierra_shutdown,
807 .read_int_callback = sierra_instat_callback,
808};
809
810/* Functions used by new usb-serial code. */
811static int __init sierra_init(void)
812{
813 int retval;
Kevin Lloyd228426e2008-01-10 11:11:04 -0800814 retval = usb_serial_register(&sierra_device);
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700815 if (retval)
Kevin Lloyd228426e2008-01-10 11:11:04 -0800816 goto failed_device_register;
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700817
818
819 retval = usb_register(&sierra_driver);
820 if (retval)
821 goto failed_driver_register;
822
Greg Kroah-Hartmanc197a8d2008-08-18 13:21:04 -0700823 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
824 DRIVER_DESC "\n");
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700825
826 return 0;
827
828failed_driver_register:
Kevin Lloyd228426e2008-01-10 11:11:04 -0800829 usb_serial_deregister(&sierra_device);
830failed_device_register:
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700831 return retval;
832}
833
834static void __exit sierra_exit(void)
835{
Alan Cox9660ea32008-07-22 11:14:59 +0100836 usb_deregister(&sierra_driver);
Kevin Lloyd228426e2008-01-10 11:11:04 -0800837 usb_serial_deregister(&sierra_device);
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700838}
839
840module_init(sierra_init);
841module_exit(sierra_exit);
842
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700843MODULE_AUTHOR(DRIVER_AUTHOR);
844MODULE_DESCRIPTION(DRIVER_DESC);
845MODULE_VERSION(DRIVER_VERSION);
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700846MODULE_LICENSE("GPL");
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700847
Kevin Lloyd4e0fee82008-07-10 14:14:47 -0700848module_param(nmea, bool, S_IRUGO | S_IWUSR);
Kevin Lloyd228426e2008-01-10 11:11:04 -0800849MODULE_PARM_DESC(nmea, "NMEA streaming");
850
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700851module_param(debug, bool, S_IRUGO | S_IWUSR);
852MODULE_PARM_DESC(debug, "Debug messages");