2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* USB Serial Converter Bus specific functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
*
|
|
|
|
* 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/errno.h>
|
|
|
|
#include <linux/tty.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/usb.h>
|
2006-07-12 11:22:58 +07:00
|
|
|
#include <linux/usb/serial.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-07-22 17:09:48 +07:00
|
|
|
static int usb_serial_device_match(struct device *dev,
|
|
|
|
struct device_driver *drv)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-06-21 11:15:16 +07:00
|
|
|
struct usb_serial_driver *driver;
|
2005-04-17 05:20:36 +07:00
|
|
|
const struct usb_serial_port *port;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* drivers are already assigned to ports in serial_probe so it's
|
|
|
|
* a simple check here.
|
|
|
|
*/
|
|
|
|
port = to_usb_serial_port(dev);
|
|
|
|
if (!port)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
driver = to_usb_serial_driver(drv);
|
|
|
|
|
|
|
|
if (driver == port->serial->type)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-24 23:22:52 +07:00
|
|
|
static ssize_t show_port_number(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct usb_serial_port *port = to_usb_serial_port(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", port->number - port->serial->minor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
|
|
|
|
|
2008-07-22 17:09:48 +07:00
|
|
|
static int usb_serial_device_probe(struct device *dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-06-21 11:15:16 +07:00
|
|
|
struct usb_serial_driver *driver;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct usb_serial_port *port;
|
|
|
|
int retval = 0;
|
|
|
|
int minor;
|
|
|
|
|
|
|
|
port = to_usb_serial_port(dev);
|
|
|
|
if (!port) {
|
|
|
|
retval = -ENODEV;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2012-07-27 06:11:42 +07:00
|
|
|
/* make sure suspend/resume doesn't race against port_probe */
|
|
|
|
retval = usb_autopm_get_interface(port->serial->interface);
|
|
|
|
if (retval)
|
|
|
|
goto exit;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
driver = port->serial->type;
|
|
|
|
if (driver->port_probe) {
|
2008-07-22 17:09:48 +07:00
|
|
|
retval = driver->port_probe(port);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (retval)
|
2012-07-27 06:11:42 +07:00
|
|
|
goto exit_with_autopm;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-08-24 23:22:52 +07:00
|
|
|
retval = device_create_file(dev, &dev_attr_port_number);
|
2009-06-02 22:54:11 +07:00
|
|
|
if (retval) {
|
|
|
|
if (driver->port_remove)
|
|
|
|
retval = driver->port_remove(port);
|
2012-07-27 06:11:42 +07:00
|
|
|
goto exit_with_autopm;
|
2009-06-02 22:54:11 +07:00
|
|
|
}
|
2007-08-24 23:22:52 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
minor = port->number;
|
2008-07-22 17:09:48 +07:00
|
|
|
tty_register_device(usb_serial_tty_driver, minor, dev);
|
|
|
|
dev_info(&port->serial->dev->dev,
|
2005-04-17 05:20:36 +07:00
|
|
|
"%s converter now attached to ttyUSB%d\n",
|
2005-06-21 11:15:16 +07:00
|
|
|
driver->description, minor);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-07-27 06:11:42 +07:00
|
|
|
exit_with_autopm:
|
|
|
|
usb_autopm_put_interface(port->serial->interface);
|
2005-04-17 05:20:36 +07:00
|
|
|
exit:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-07-22 17:09:48 +07:00
|
|
|
static int usb_serial_device_remove(struct device *dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-06-21 11:15:16 +07:00
|
|
|
struct usb_serial_driver *driver;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct usb_serial_port *port;
|
|
|
|
int retval = 0;
|
|
|
|
int minor;
|
|
|
|
|
|
|
|
port = to_usb_serial_port(dev);
|
2008-07-22 17:09:48 +07:00
|
|
|
if (!port)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
2012-07-27 06:11:42 +07:00
|
|
|
/* make sure suspend/resume doesn't race against port_remove */
|
|
|
|
usb_autopm_get_interface(port->serial->interface);
|
|
|
|
|
2007-08-24 23:22:52 +07:00
|
|
|
device_remove_file(&port->dev, &dev_attr_port_number);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
driver = port->serial->type;
|
2009-06-02 22:54:11 +07:00
|
|
|
if (driver->port_remove)
|
2008-07-22 17:09:48 +07:00
|
|
|
retval = driver->port_remove(port);
|
2009-06-02 22:54:11 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
minor = port->number;
|
2008-07-22 17:09:48 +07:00
|
|
|
tty_unregister_device(usb_serial_tty_driver, minor);
|
2005-04-17 05:20:36 +07:00
|
|
|
dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
|
2005-06-21 11:15:16 +07:00
|
|
|
driver->description, minor);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-07-27 06:11:42 +07:00
|
|
|
usb_autopm_put_interface(port->serial->interface);
|
2005-04-17 05:20:36 +07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-12-18 03:50:23 +07:00
|
|
|
static ssize_t store_new_id(struct device_driver *driver,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
|
|
|
|
ssize_t retval = usb_store_new_id(&usb_drv->dynids, driver, buf, count);
|
|
|
|
|
|
|
|
if (retval >= 0 && usb_drv->usb_driver != NULL)
|
|
|
|
retval = usb_store_new_id(&usb_drv->usb_driver->dynids,
|
|
|
|
&usb_drv->usb_driver->drvwrap.driver,
|
|
|
|
buf, count);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-05-13 17:35:00 +07:00
|
|
|
static ssize_t show_dynids(struct device_driver *driver, char *buf)
|
|
|
|
{
|
|
|
|
struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
|
|
|
|
|
|
|
|
return usb_show_dynids(&usb_drv->dynids, buf);
|
|
|
|
}
|
|
|
|
|
2006-12-18 03:50:23 +07:00
|
|
|
static struct driver_attribute drv_attrs[] = {
|
2012-05-13 17:35:00 +07:00
|
|
|
__ATTR(new_id, S_IRUGO | S_IWUSR, show_dynids, store_new_id),
|
2006-12-18 03:50:23 +07:00
|
|
|
__ATTR_NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void free_dynids(struct usb_serial_driver *drv)
|
|
|
|
{
|
|
|
|
struct usb_dynid *dynid, *n;
|
|
|
|
|
|
|
|
spin_lock(&drv->dynids.lock);
|
|
|
|
list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {
|
|
|
|
list_del(&dynid->node);
|
|
|
|
kfree(dynid);
|
|
|
|
}
|
|
|
|
spin_unlock(&drv->dynids.lock);
|
|
|
|
}
|
|
|
|
|
2006-01-05 21:43:11 +07:00
|
|
|
struct bus_type usb_serial_bus_type = {
|
|
|
|
.name = "usb-serial",
|
|
|
|
.match = usb_serial_device_match,
|
|
|
|
.probe = usb_serial_device_probe,
|
|
|
|
.remove = usb_serial_device_remove,
|
2006-12-18 03:50:23 +07:00
|
|
|
.drv_attrs = drv_attrs,
|
2006-01-05 21:43:11 +07:00
|
|
|
};
|
|
|
|
|
2005-06-21 11:15:16 +07:00
|
|
|
int usb_serial_bus_register(struct usb_serial_driver *driver)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2005-06-21 11:15:16 +07:00
|
|
|
driver->driver.bus = &usb_serial_bus_type;
|
2006-12-18 03:50:23 +07:00
|
|
|
spin_lock_init(&driver->dynids.lock);
|
|
|
|
INIT_LIST_HEAD(&driver->dynids.list);
|
|
|
|
|
2005-06-21 11:15:16 +07:00
|
|
|
retval = driver_register(&driver->driver);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-06-21 11:15:16 +07:00
|
|
|
void usb_serial_bus_deregister(struct usb_serial_driver *driver)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-12-18 03:50:23 +07:00
|
|
|
free_dynids(driver);
|
2005-06-21 11:15:16 +07:00
|
|
|
driver_unregister(&driver->driver);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|