2005-04-26 04:46:29 +00:00
|
|
|
/*
|
|
|
|
* AirPrime CDMA Wireless Serial USB driver
|
|
|
|
*
|
2006-07-03 22:43:01 +00:00
|
|
|
* Copyright (C) 2005-2006 Greg Kroah-Hartman <gregkh@suse.de>
|
2005-04-26 04:46:29 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version
|
|
|
|
* 2 as published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/tty.h>
|
2006-07-03 22:43:01 +00:00
|
|
|
#include <linux/tty_flip.h>
|
2005-04-26 04:46:29 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/usb.h>
|
2006-07-12 04:22:58 +00:00
|
|
|
#include <linux/usb/serial.h>
|
2005-04-26 04:46:29 +00:00
|
|
|
|
|
|
|
static struct usb_device_id id_table [] = {
|
2006-06-16 11:42:59 +00:00
|
|
|
{ USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */
|
2006-07-03 22:43:01 +00:00
|
|
|
{ USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */
|
2006-12-19 21:15:25 +00:00
|
|
|
{ USB_DEVICE(0x1410, 0x1130) }, /* Novatel Wireless S720 CDMA/EV-DO */
|
|
|
|
{ USB_DEVICE(0x1410, 0x2110) }, /* Novatel Wireless U720 CDMA/EV-DO */
|
2006-11-11 02:47:52 +00:00
|
|
|
{ USB_DEVICE(0x1410, 0x1430) }, /* Novatel Merlin XU870 HSDPA/3G */
|
2006-10-03 13:31:36 +00:00
|
|
|
{ USB_DEVICE(0x1410, 0x1100) }, /* ExpressCard34 Qualcomm 3G CDMA */
|
2006-11-25 00:40:04 +00:00
|
|
|
{ USB_DEVICE(0x413c, 0x8115) }, /* Dell Wireless HSDPA 5500 */
|
2005-04-26 04:46:29 +00:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, id_table);
|
|
|
|
|
2006-07-03 22:43:01 +00:00
|
|
|
#define URB_TRANSFER_BUFFER_SIZE 4096
|
|
|
|
#define NUM_READ_URBS 4
|
|
|
|
#define NUM_WRITE_URBS 4
|
|
|
|
#define NUM_BULK_EPS 3
|
|
|
|
#define MAX_BULK_EPS 6
|
|
|
|
|
|
|
|
/* if overridden by the user, then use their value for the size of the
|
|
|
|
* read and write urbs, and the number of endpoints */
|
|
|
|
static int buffer_size = URB_TRANSFER_BUFFER_SIZE;
|
|
|
|
static int endpoints = NUM_BULK_EPS;
|
|
|
|
static int debug;
|
|
|
|
struct airprime_private {
|
|
|
|
spinlock_t lock;
|
|
|
|
int outstanding_urbs;
|
|
|
|
int throttled;
|
|
|
|
struct urb *read_urbp[NUM_READ_URBS];
|
2007-03-01 12:49:48 +00:00
|
|
|
|
|
|
|
/* Settings for the port */
|
|
|
|
int rts_state; /* Handshaking pins (outputs) */
|
|
|
|
int dtr_state;
|
|
|
|
int cts_state; /* Handshaking pins (inputs) */
|
|
|
|
int dsr_state;
|
|
|
|
int dcd_state;
|
|
|
|
int ri_state;
|
2006-07-03 22:43:01 +00:00
|
|
|
};
|
|
|
|
|
2007-03-01 12:49:48 +00:00
|
|
|
static int airprime_send_setup(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
struct usb_serial *serial = port->serial;
|
|
|
|
struct airprime_private *priv;
|
|
|
|
|
|
|
|
dbg("%s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (port->number != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
priv = usb_get_serial_port_data(port);
|
|
|
|
|
|
|
|
if (port->tty) {
|
|
|
|
int val = 0;
|
|
|
|
if (priv->dtr_state)
|
|
|
|
val |= 0x01;
|
|
|
|
if (priv->rts_state)
|
|
|
|
val |= 0x02;
|
|
|
|
|
|
|
|
return usb_control_msg(serial->dev,
|
|
|
|
usb_rcvctrlpipe(serial->dev, 0),
|
|
|
|
0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static void airprime_read_bulk_callback(struct urb *urb)
|
2006-07-03 22:43:01 +00:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = urb->context;
|
|
|
|
unsigned char *data = urb->transfer_buffer;
|
|
|
|
struct tty_struct *tty;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
dbg("%s - port %d", __FUNCTION__, port->number);
|
|
|
|
|
|
|
|
if (urb->status) {
|
|
|
|
dbg("%s - nonzero read bulk status received: %d",
|
|
|
|
__FUNCTION__, urb->status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
|
|
|
|
|
|
|
|
tty = port->tty;
|
|
|
|
if (tty && urb->actual_length) {
|
|
|
|
tty_insert_flip_string (tty, data, urb->actual_length);
|
|
|
|
tty_flip_buffer_push (tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = usb_submit_urb (urb, GFP_ATOMIC);
|
|
|
|
if (result)
|
|
|
|
dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
|
|
|
|
__FUNCTION__, result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static void airprime_write_bulk_callback(struct urb *urb)
|
2006-07-03 22:43:01 +00:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = urb->context;
|
|
|
|
struct airprime_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
dbg("%s - port %d", __FUNCTION__, port->number);
|
|
|
|
|
|
|
|
/* free up the transfer buffer, as usb_free_urb() does not do this */
|
|
|
|
kfree (urb->transfer_buffer);
|
|
|
|
|
|
|
|
if (urb->status)
|
|
|
|
dbg("%s - nonzero write bulk status received: %d",
|
|
|
|
__FUNCTION__, urb->status);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
--priv->outstanding_urbs;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
usb_serial_port_softint(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int airprime_open(struct usb_serial_port *port, struct file *filp)
|
|
|
|
{
|
|
|
|
struct airprime_private *priv = usb_get_serial_port_data(port);
|
|
|
|
struct usb_serial *serial = port->serial;
|
|
|
|
struct urb *urb;
|
|
|
|
char *buffer = NULL;
|
|
|
|
int i;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
dbg("%s - port %d", __FUNCTION__, port->number);
|
|
|
|
|
|
|
|
/* initialize our private data structure if it isn't already created */
|
|
|
|
if (!priv) {
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv) {
|
|
|
|
result = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
spin_lock_init(&priv->lock);
|
|
|
|
usb_set_serial_port_data(port, priv);
|
|
|
|
}
|
|
|
|
|
2007-03-01 12:49:48 +00:00
|
|
|
/* Set some sane defaults */
|
|
|
|
priv->rts_state = 1;
|
|
|
|
priv->dtr_state = 1;
|
|
|
|
|
2006-07-03 22:43:01 +00:00
|
|
|
for (i = 0; i < NUM_READ_URBS; ++i) {
|
|
|
|
buffer = kmalloc(buffer_size, GFP_KERNEL);
|
|
|
|
if (!buffer) {
|
|
|
|
dev_err(&port->dev, "%s - out of memory.\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
result = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!urb) {
|
2006-10-10 21:42:50 +00:00
|
|
|
kfree(buffer);
|
2006-07-03 22:43:01 +00:00
|
|
|
dev_err(&port->dev, "%s - no more urbs?\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
result = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
usb_fill_bulk_urb(urb, serial->dev,
|
|
|
|
usb_rcvbulkpipe(serial->dev,
|
|
|
|
port->bulk_out_endpointAddress),
|
|
|
|
buffer, buffer_size,
|
|
|
|
airprime_read_bulk_callback, port);
|
|
|
|
result = usb_submit_urb(urb, GFP_KERNEL);
|
|
|
|
if (result) {
|
2007-02-03 07:13:14 +00:00
|
|
|
usb_free_urb(urb);
|
|
|
|
kfree(buffer);
|
2006-07-03 22:43:01 +00:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - failed submitting read urb %d for port %d, error %d\n",
|
|
|
|
__FUNCTION__, i, port->number, result);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
/* remember this urb so we can kill it when the port is closed */
|
|
|
|
priv->read_urbp[i] = urb;
|
|
|
|
}
|
2007-03-01 12:49:48 +00:00
|
|
|
|
|
|
|
airprime_send_setup(port);
|
|
|
|
|
2006-07-03 22:43:01 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
/* some error happened, cancel any submitted urbs and clean up anything that
|
|
|
|
got allocated successfully */
|
|
|
|
|
2007-02-03 07:13:14 +00:00
|
|
|
while (i-- != 0) {
|
2006-07-03 22:43:01 +00:00
|
|
|
urb = priv->read_urbp[i];
|
2007-02-03 07:13:14 +00:00
|
|
|
buffer = urb->transfer_buffer;
|
|
|
|
usb_kill_urb (urb);
|
|
|
|
usb_free_urb (urb);
|
|
|
|
kfree (buffer);
|
2006-07-03 22:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void airprime_close(struct usb_serial_port *port, struct file * filp)
|
|
|
|
{
|
|
|
|
struct airprime_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dbg("%s - port %d", __FUNCTION__, port->number);
|
|
|
|
|
2007-03-01 12:49:48 +00:00
|
|
|
priv->rts_state = 0;
|
|
|
|
priv->dtr_state = 0;
|
|
|
|
|
|
|
|
airprime_send_setup(port);
|
|
|
|
|
2006-07-03 22:43:01 +00:00
|
|
|
for (i = 0; i < NUM_READ_URBS; ++i) {
|
|
|
|
usb_kill_urb (priv->read_urbp[i]);
|
2007-02-03 07:13:14 +00:00
|
|
|
kfree (priv->read_urbp[i]->transfer_buffer);
|
2006-07-03 22:43:01 +00:00
|
|
|
usb_free_urb (priv->read_urbp[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free up private structure */
|
|
|
|
kfree (priv);
|
|
|
|
usb_set_serial_port_data(port, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int airprime_write(struct usb_serial_port *port,
|
|
|
|
const unsigned char *buf, int count)
|
|
|
|
{
|
|
|
|
struct airprime_private *priv = usb_get_serial_port_data(port);
|
|
|
|
struct usb_serial *serial = port->serial;
|
|
|
|
struct urb *urb;
|
|
|
|
unsigned char *buffer;
|
|
|
|
unsigned long flags;
|
|
|
|
int status;
|
|
|
|
dbg("%s - port %d", __FUNCTION__, port->number);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
if (priv->outstanding_urbs > NUM_WRITE_URBS) {
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
dbg("%s - write limit hit\n", __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
buffer = kmalloc(count, GFP_ATOMIC);
|
|
|
|
if (!buffer) {
|
|
|
|
dev_err(&port->dev, "out of memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
|
|
|
if (!urb) {
|
|
|
|
dev_err(&port->dev, "no more free urbs\n");
|
|
|
|
kfree (buffer);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memcpy (buffer, buf, count);
|
|
|
|
|
|
|
|
usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer);
|
|
|
|
|
|
|
|
usb_fill_bulk_urb(urb, serial->dev,
|
|
|
|
usb_sndbulkpipe(serial->dev,
|
|
|
|
port->bulk_out_endpointAddress),
|
|
|
|
buffer, count,
|
|
|
|
airprime_write_bulk_callback, port);
|
|
|
|
|
|
|
|
/* send it down the pipe */
|
|
|
|
status = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (status) {
|
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - usb_submit_urb(write bulk) failed with status = %d\n",
|
|
|
|
__FUNCTION__, status);
|
|
|
|
count = status;
|
|
|
|
kfree (buffer);
|
|
|
|
} else {
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
++priv->outstanding_urbs;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
|
|
|
/* we are done with this urb, so let the host driver
|
|
|
|
* really free it when it is finished with it */
|
|
|
|
usb_free_urb (urb);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2005-04-26 04:46:29 +00:00
|
|
|
static struct usb_driver airprime_driver = {
|
|
|
|
.name = "airprime",
|
|
|
|
.probe = usb_serial_probe,
|
|
|
|
.disconnect = usb_serial_disconnect,
|
|
|
|
.id_table = id_table,
|
2006-07-03 22:43:01 +00:00
|
|
|
.no_dynamic_id = 1,
|
2005-04-26 04:46:29 +00:00
|
|
|
};
|
|
|
|
|
2005-06-21 04:15:16 +00:00
|
|
|
static struct usb_serial_driver airprime_device = {
|
2005-06-21 04:15:16 +00:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2005-06-21 04:15:16 +00:00
|
|
|
.name = "airprime",
|
2005-06-21 04:15:16 +00:00
|
|
|
},
|
2006-12-17 20:50:24 +00:00
|
|
|
.usb_driver = &airprime_driver,
|
2005-04-26 04:46:29 +00:00
|
|
|
.id_table = id_table,
|
|
|
|
.num_interrupt_in = NUM_DONT_CARE,
|
|
|
|
.num_bulk_in = NUM_DONT_CARE,
|
|
|
|
.num_bulk_out = NUM_DONT_CARE,
|
2006-07-03 22:43:01 +00:00
|
|
|
.open = airprime_open,
|
|
|
|
.close = airprime_close,
|
|
|
|
.write = airprime_write,
|
2005-04-26 04:46:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init airprime_init(void)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2006-07-03 22:43:01 +00:00
|
|
|
airprime_device.num_ports =
|
|
|
|
(endpoints > 0 && endpoints <= MAX_BULK_EPS) ? endpoints : NUM_BULK_EPS;
|
2005-04-26 04:46:29 +00:00
|
|
|
retval = usb_serial_register(&airprime_device);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
retval = usb_register(&airprime_driver);
|
|
|
|
if (retval)
|
|
|
|
usb_serial_deregister(&airprime_device);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit airprime_exit(void)
|
|
|
|
{
|
2006-07-03 22:43:01 +00:00
|
|
|
dbg("%s", __FUNCTION__);
|
|
|
|
|
2005-04-26 04:46:29 +00:00
|
|
|
usb_deregister(&airprime_driver);
|
|
|
|
usb_serial_deregister(&airprime_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(airprime_init);
|
|
|
|
module_exit(airprime_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
2006-07-03 22:43:01 +00:00
|
|
|
|
|
|
|
module_param(debug, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug enabled");
|
|
|
|
module_param(buffer_size, int, 0);
|
|
|
|
MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers in bytes (default 4096)");
|
|
|
|
module_param(endpoints, int, 0);
|
|
|
|
MODULE_PARM_DESC(endpoints, "Number of bulk EPs to configure (default 3)");
|