22 #define DRIVER_VERSION "v0.7.2"
24 #define DRIVER_DESC "USB Driver for GSM modems"
26 #include <linux/kernel.h>
28 #include <linux/errno.h>
29 #include <linux/slab.h>
30 #include <linux/tty.h>
32 #include <linux/module.h>
33 #include <linux/bitops.h>
37 #include <linux/serial.h>
46 intfdata = port->
serial->private;
51 portdata = usb_get_serial_port_data(port);
81 portdata = usb_get_serial_port_data(port);
95 unsigned int set,
unsigned int clear)
101 portdata = usb_get_serial_port_data(port);
102 intfdata = port->
serial->private;
133 tmp.close_delay = port->
port.close_delay / 10;
136 port->
port.closing_wait / 10;
153 close_delay = new_serial.close_delay * 10;
160 if ((close_delay != port->
port.close_delay) ||
161 (closing_wait != port->
port.closing_wait))
175 unsigned int cmd,
unsigned long arg)
179 dev_dbg(&port->
dev,
"%s cmd 0x%04x\n", __func__, cmd);
183 return get_serial_info(port,
186 return set_serial_info(port,
192 dev_dbg(&port->
dev,
"%s arg not supported\n", __func__);
200 const unsigned char *
buf,
int count)
210 portdata = usb_get_serial_port_data(port);
211 intfdata = port->
serial->private;
213 dev_dbg(&port->
dev,
"%s: write (%d chars)\n", __func__, count);
217 for (i = 0; left > 0 && i <
N_OUT_URB; i++) {
230 dev_dbg(&port->
dev,
"%s: endpoint %d buf %d\n", __func__,
231 usb_pipeendpoint(this_urb->pipe), i);
233 err = usb_autopm_get_interface_async(port->
serial->interface);
238 memcpy(this_urb->transfer_buffer, buf, todo);
239 this_urb->transfer_buffer_length =
todo;
244 spin_unlock_irqrestore(&intfdata->
susp_lock, flags);
247 spin_unlock_irqrestore(&intfdata->
susp_lock, flags);
251 "usb_submit_urb %p (write bulk) failed (%d)\n",
256 spin_unlock_irqrestore(&intfdata->
susp_lock,
258 usb_autopm_put_interface_async(port->
serial->interface);
269 dev_dbg(&port->
dev,
"%s: wrote (did %d)\n", __func__, count);
274 static void usb_wwan_indat_callback(
struct urb *
urb)
281 unsigned char *
data = urb->transfer_buffer;
284 endpoint = usb_pipeendpoint(urb->pipe);
289 dev_dbg(dev,
"%s: nonzero status: %d on endpoint %02x.\n",
290 __func__, status, endpoint);
294 if (urb->actual_length) {
295 tty_insert_flip_string(tty, data,
299 dev_dbg(dev,
"%s: empty read urb received\n", __func__);
307 dev_err(dev,
"%s: resubmit read urb failed. (%d)\n", __func__, err);
309 usb_mark_last_busy(port->
serial->dev);
312 usb_mark_last_busy(port->
serial->dev);
317 static void usb_wwan_outdat_callback(
struct urb *urb)
325 intfdata = port->
serial->private;
328 usb_autopm_put_interface_async(port->
serial->interface);
329 portdata = usb_get_serial_port_data(port);
349 struct urb *this_urb;
351 portdata = usb_get_serial_port_data(port);
359 dev_dbg(&port->
dev,
"%s: %d\n", __func__, data_len);
370 struct urb *this_urb;
372 portdata = usb_get_serial_port_data(port);
379 data_len += this_urb->transfer_buffer_length;
381 dev_dbg(&port->
dev,
"%s: %d\n", __func__, data_len);
394 portdata = usb_get_serial_port_data(port);
404 dev_dbg(&port->
dev,
"%s: submit urb %d failed (%d) %d\n",
405 __func__, i, err, urb->transfer_buffer_length);
412 serial->
interface->needs_remote_wakeup = 1;
417 usb_autopm_put_interface(serial->
interface);
430 portdata = usb_get_serial_port_data(port);
443 usb_autopm_get_interface_no_resume(serial->
interface);
444 serial->
interface->needs_remote_wakeup = 0;
452 int dir,
void *
ctx,
char *
buf,
int len,
461 "%s: alloc for endpoint %d failed.\n", __func__,
467 usb_fill_bulk_urb(urb, serial->
dev,
468 usb_sndbulkpipe(serial->
dev, endpoint) | dir,
482 portdata = kzalloc(
sizeof(*portdata),
GFP_KERNEL);
486 init_usb_anchor(&portdata->
delayed);
500 usb_wwan_indat_callback);
510 goto bail_out_error2;
516 usb_wwan_outdat_callback);
520 usb_set_serial_port_data(port, portdata);
525 dev_dbg(&port->
dev,
"%s: submit irq_in urb failed %d\n",
552 portdata = usb_get_serial_port_data(port);
553 usb_set_serial_port_data(port,
NULL);
574 static void stop_read_write_urbs(
struct usb_serial *serial)
582 port = serial->
port[
i];
583 portdata = usb_get_serial_port_data(port);
610 stop_read_write_urbs(serial);
635 portdata = usb_get_serial_port_data(port);
636 data = port->
serial->private;
644 unbusy_queued_urb(urb, portdata);
645 usb_autopm_put_interface_no_suspend(port->
serial->interface);
652 int usb_wwan_resume(
struct usb_serial *serial)
662 for (i = 0; i < serial->
num_ports; i++) {
663 port = serial->
port[
i];
665 dev_dbg(&port->
dev,
"%s: No interrupt URB for port\n", __func__);
669 dev_dbg(&port->
dev,
"Submitted interrupt URB for port (result %d)\n", err);
671 dev_err(&port->
dev,
"%s: Error %d for interrupt URB\n",
677 for (i = 0; i < serial->
num_ports; i++) {
679 port = serial->
port[
i];
680 portdata = usb_get_serial_port_data(port);
684 if (!portdata || !portdata->
opened) {
693 dev_err(&port->
dev,
"%s: Error %d for bulk URB %d\n",