2005-04-17 06:20:36 +08: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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/usb.h>
|
2006-07-12 12:22:58 +08:00
|
|
|
#include <linux/usb/serial.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-22 18:09:48 +08:00
|
|
|
static int usb_serial_device_match(struct device *dev,
|
|
|
|
struct device_driver *drv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-21 12:15:16 +08:00
|
|
|
struct usb_serial_driver *driver;
|
2005-04-17 06:20:36 +08: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;
|
|
|
|
}
|
|
|
|
|
2008-07-22 18:09:48 +08:00
|
|
|
static int usb_serial_device_probe(struct device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-21 12:15:16 +08:00
|
|
|
struct usb_serial_driver *driver;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_serial_port *port;
|
2015-02-18 11:34:51 +08:00
|
|
|
struct device *tty_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval = 0;
|
|
|
|
int minor;
|
|
|
|
|
|
|
|
port = to_usb_serial_port(dev);
|
2015-02-18 12:04:46 +08:00
|
|
|
if (!port)
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-07-27 07:11:42 +08:00
|
|
|
/* make sure suspend/resume doesn't race against port_probe */
|
|
|
|
retval = usb_autopm_get_interface(port->serial->interface);
|
|
|
|
if (retval)
|
2015-02-18 12:04:46 +08:00
|
|
|
return retval;
|
2012-07-27 07:11:42 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
driver = port->serial->type;
|
|
|
|
if (driver->port_probe) {
|
2008-07-22 18:09:48 +08:00
|
|
|
retval = driver->port_probe(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval)
|
2015-02-18 12:04:46 +08:00
|
|
|
goto err_autopm_put;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 01:32:00 +08:00
|
|
|
minor = port->minor;
|
2015-02-18 11:34:51 +08:00
|
|
|
tty_dev = tty_register_device(usb_serial_tty_driver, minor, dev);
|
|
|
|
if (IS_ERR(tty_dev)) {
|
|
|
|
retval = PTR_ERR(tty_dev);
|
2015-02-18 12:04:46 +08:00
|
|
|
goto err_port_remove;
|
2015-02-18 11:34:51 +08:00
|
|
|
}
|
|
|
|
|
2015-02-18 12:04:46 +08:00
|
|
|
usb_autopm_put_interface(port->serial->interface);
|
|
|
|
|
2008-07-22 18:09:48 +08:00
|
|
|
dev_info(&port->serial->dev->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"%s converter now attached to ttyUSB%d\n",
|
2005-06-21 12:15:16 +08:00
|
|
|
driver->description, minor);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-02-18 12:04:46 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_port_remove:
|
|
|
|
if (driver->port_remove)
|
|
|
|
driver->port_remove(port);
|
|
|
|
err_autopm_put:
|
2012-07-27 07:11:42 +08:00
|
|
|
usb_autopm_put_interface(port->serial->interface);
|
2015-02-18 12:04:46 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-07-22 18:09:48 +08:00
|
|
|
static int usb_serial_device_remove(struct device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-21 12:15:16 +08:00
|
|
|
struct usb_serial_driver *driver;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_serial_port *port;
|
|
|
|
int retval = 0;
|
|
|
|
int minor;
|
2014-05-27 01:23:33 +08:00
|
|
|
int autopm_err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
port = to_usb_serial_port(dev);
|
2008-07-22 18:09:48 +08:00
|
|
|
if (!port)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2014-05-27 01:23:33 +08:00
|
|
|
/*
|
|
|
|
* Make sure suspend/resume doesn't race against port_remove.
|
|
|
|
*
|
|
|
|
* Note that no further runtime PM callbacks will be made if
|
|
|
|
* autopm_get fails.
|
|
|
|
*/
|
|
|
|
autopm_err = usb_autopm_get_interface(port->serial->interface);
|
2012-07-27 07:11:42 +08:00
|
|
|
|
2013-06-07 01:32:00 +08:00
|
|
|
minor = port->minor;
|
2013-03-21 19:36:50 +08:00
|
|
|
tty_unregister_device(usb_serial_tty_driver, minor);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
driver = port->serial->type;
|
2009-06-02 23:54:11 +08:00
|
|
|
if (driver->port_remove)
|
2008-07-22 18:09:48 +08:00
|
|
|
retval = driver->port_remove(port);
|
2009-06-02 23:54:11 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
|
2005-06-21 12:15:16 +08:00
|
|
|
driver->description, minor);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-05-27 01:23:33 +08:00
|
|
|
if (!autopm_err)
|
|
|
|
usb_autopm_put_interface(port->serial->interface);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-08-24 05:24:36 +08:00
|
|
|
static ssize_t new_id_store(struct device_driver *driver,
|
2006-12-18 04:50:23 +08:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
|
2014-01-11 02:36:42 +08:00
|
|
|
ssize_t retval = usb_store_new_id(&usb_drv->dynids, usb_drv->id_table,
|
|
|
|
driver, buf, count);
|
2006-12-18 04:50:23 +08:00
|
|
|
|
|
|
|
if (retval >= 0 && usb_drv->usb_driver != NULL)
|
|
|
|
retval = usb_store_new_id(&usb_drv->usb_driver->dynids,
|
2014-01-11 02:36:42 +08:00
|
|
|
usb_drv->usb_driver->id_table,
|
2006-12-18 04:50:23 +08:00
|
|
|
&usb_drv->usb_driver->drvwrap.driver,
|
|
|
|
buf, count);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-08-24 05:24:36 +08:00
|
|
|
static ssize_t new_id_show(struct device_driver *driver, char *buf)
|
2012-05-13 18:35:00 +08:00
|
|
|
{
|
|
|
|
struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
|
|
|
|
|
|
|
|
return usb_show_dynids(&usb_drv->dynids, buf);
|
|
|
|
}
|
2013-08-24 05:24:36 +08:00
|
|
|
static DRIVER_ATTR_RW(new_id);
|
2012-05-13 18:35:00 +08:00
|
|
|
|
2013-08-24 05:24:36 +08:00
|
|
|
static struct attribute *usb_serial_drv_attrs[] = {
|
|
|
|
&driver_attr_new_id.attr,
|
|
|
|
NULL,
|
2006-12-18 04:50:23 +08:00
|
|
|
};
|
2013-08-24 05:24:36 +08:00
|
|
|
ATTRIBUTE_GROUPS(usb_serial_drv);
|
2006-12-18 04:50:23 +08:00
|
|
|
|
|
|
|
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 22:43:11 +08: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,
|
2013-08-24 05:24:36 +08:00
|
|
|
.drv_groups = usb_serial_drv_groups,
|
2006-01-05 22:43:11 +08:00
|
|
|
};
|
|
|
|
|
2005-06-21 12:15:16 +08:00
|
|
|
int usb_serial_bus_register(struct usb_serial_driver *driver)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2005-06-21 12:15:16 +08:00
|
|
|
driver->driver.bus = &usb_serial_bus_type;
|
2006-12-18 04:50:23 +08:00
|
|
|
spin_lock_init(&driver->dynids.lock);
|
|
|
|
INIT_LIST_HEAD(&driver->dynids.list);
|
|
|
|
|
2005-06-21 12:15:16 +08:00
|
|
|
retval = driver_register(&driver->driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-06-21 12:15:16 +08:00
|
|
|
void usb_serial_bus_deregister(struct usb_serial_driver *driver)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-12-18 04:50:23 +08:00
|
|
|
free_dynids(driver);
|
2005-06-21 12:15:16 +08:00
|
|
|
driver_unregister(&driver->driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|