Commit 4a3ad20c authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Driver core: coding style fixes

Fix up a number of coding style issues in the drivers/base/ directory
that have annoyed me over the years.  checkpatch.pl is now very happy.
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent e374a2bf
...@@ -50,15 +50,15 @@ extern int platform_bus_init(void); ...@@ -50,15 +50,15 @@ extern int platform_bus_init(void);
extern int system_bus_init(void); extern int system_bus_init(void);
extern int cpu_dev_init(void); extern int cpu_dev_init(void);
extern int bus_add_device(struct device * dev); extern int bus_add_device(struct device *dev);
extern void bus_attach_device(struct device * dev); extern void bus_attach_device(struct device *dev);
extern void bus_remove_device(struct device * dev); extern void bus_remove_device(struct device *dev);
extern int bus_add_driver(struct device_driver *); extern int bus_add_driver(struct device_driver *drv);
extern void bus_remove_driver(struct device_driver *); extern void bus_remove_driver(struct device_driver *drv);
extern void driver_detach(struct device_driver * drv); extern void driver_detach(struct device_driver *drv);
extern int driver_probe_device(struct device_driver *, struct device *); extern int driver_probe_device(struct device_driver *drv, struct device *dev);
extern void sysdev_shutdown(void); extern void sysdev_shutdown(void);
extern int sysdev_suspend(pm_message_t state); extern int sysdev_suspend(pm_message_t state);
......
This diff is collapsed.
This diff is collapsed.
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
#include "base.h" #include "base.h"
#include "power/power.h" #include "power/power.h"
int (*platform_notify)(struct device * dev) = NULL; int (*platform_notify)(struct device *dev) = NULL;
int (*platform_notify_remove)(struct device * dev) = NULL; int (*platform_notify_remove)(struct device *dev) = NULL;
/* /*
* sysfs bindings for devices. * sysfs bindings for devices.
...@@ -51,11 +51,11 @@ EXPORT_SYMBOL(dev_driver_string); ...@@ -51,11 +51,11 @@ EXPORT_SYMBOL(dev_driver_string);
#define to_dev(obj) container_of(obj, struct device, kobj) #define to_dev(obj) container_of(obj, struct device, kobj)
#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
static ssize_t static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) char *buf)
{ {
struct device_attribute * dev_attr = to_dev_attr(attr); struct device_attribute *dev_attr = to_dev_attr(attr);
struct device * dev = to_dev(kobj); struct device *dev = to_dev(kobj);
ssize_t ret = -EIO; ssize_t ret = -EIO;
if (dev_attr->show) if (dev_attr->show)
...@@ -63,12 +63,11 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) ...@@ -63,12 +63,11 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
return ret; return ret;
} }
static ssize_t static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
dev_attr_store(struct kobject * kobj, struct attribute * attr, const char *buf, size_t count)
const char * buf, size_t count)
{ {
struct device_attribute * dev_attr = to_dev_attr(attr); struct device_attribute *dev_attr = to_dev_attr(attr);
struct device * dev = to_dev(kobj); struct device *dev = to_dev(kobj);
ssize_t ret = -EIO; ssize_t ret = -EIO;
if (dev_attr->store) if (dev_attr->store)
...@@ -90,9 +89,9 @@ static struct sysfs_ops dev_sysfs_ops = { ...@@ -90,9 +89,9 @@ static struct sysfs_ops dev_sysfs_ops = {
* reaches 0. We forward the call to the device's release * reaches 0. We forward the call to the device's release
* method, which should handle actually freeing the structure. * method, which should handle actually freeing the structure.
*/ */
static void device_release(struct kobject * kobj) static void device_release(struct kobject *kobj)
{ {
struct device * dev = to_dev(kobj); struct device *dev = to_dev(kobj);
if (dev->release) if (dev->release)
dev->release(dev); dev->release(dev);
...@@ -101,8 +100,8 @@ static void device_release(struct kobject * kobj) ...@@ -101,8 +100,8 @@ static void device_release(struct kobject * kobj)
else if (dev->class && dev->class->dev_release) else if (dev->class && dev->class->dev_release)
dev->class->dev_release(dev); dev->class->dev_release(dev);
else { else {
printk(KERN_ERR "Device '%s' does not have a release() function, " printk(KERN_ERR "Device '%s' does not have a release() "
"it is broken and must be fixed.\n", "function, it is broken and must be fixed.\n",
dev->bus_id); dev->bus_id);
WARN_ON(1); WARN_ON(1);
} }
...@@ -185,7 +184,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, ...@@ -185,7 +184,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
if (dev->driver) if (dev->driver)
add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name); add_uevent_var(env, "PHYSDEVDRIVER=%s",
dev->driver->name);
} }
#endif #endif
...@@ -327,7 +327,8 @@ static int device_add_groups(struct device *dev, ...@@ -327,7 +327,8 @@ static int device_add_groups(struct device *dev,
error = sysfs_create_group(&dev->kobj, groups[i]); error = sysfs_create_group(&dev->kobj, groups[i]);
if (error) { if (error) {
while (--i >= 0) while (--i >= 0)
sysfs_remove_group(&dev->kobj, groups[i]); sysfs_remove_group(&dev->kobj,
groups[i]);
break; break;
} }
} }
...@@ -406,14 +407,12 @@ static struct device_attribute devt_attr = ...@@ -406,14 +407,12 @@ static struct device_attribute devt_attr =
/* kset to create /sys/devices/ */ /* kset to create /sys/devices/ */
struct kset *devices_kset; struct kset *devices_kset;
/** /**
* device_create_file - create sysfs attribute file for device. * device_create_file - create sysfs attribute file for device.
* @dev: device. * @dev: device.
* @attr: device attribute descriptor. * @attr: device attribute descriptor.
*/ */
int device_create_file(struct device *dev, struct device_attribute *attr)
int device_create_file(struct device * dev, struct device_attribute * attr)
{ {
int error = 0; int error = 0;
if (get_device(dev)) { if (get_device(dev)) {
...@@ -428,8 +427,7 @@ int device_create_file(struct device * dev, struct device_attribute * attr) ...@@ -428,8 +427,7 @@ int device_create_file(struct device * dev, struct device_attribute * attr)
* @dev: device. * @dev: device.
* @attr: device attribute descriptor. * @attr: device attribute descriptor.
*/ */
void device_remove_file(struct device *dev, struct device_attribute *attr)
void device_remove_file(struct device * dev, struct device_attribute * attr)
{ {
if (get_device(dev)) { if (get_device(dev)) {
sysfs_remove_file(&dev->kobj, &attr->attr); sysfs_remove_file(&dev->kobj, &attr->attr);
...@@ -510,7 +508,6 @@ static void klist_children_put(struct klist_node *n) ...@@ -510,7 +508,6 @@ static void klist_children_put(struct klist_node *n)
put_device(dev); put_device(dev);
} }
/** /**
* device_initialize - init device structure. * device_initialize - init device structure.
* @dev: device. * @dev: device.
...@@ -521,7 +518,6 @@ static void klist_children_put(struct klist_node *n) ...@@ -521,7 +518,6 @@ static void klist_children_put(struct klist_node *n)
* that, though it can also be called separately, so one * that, though it can also be called separately, so one
* may use @dev's fields (e.g. the refcount). * may use @dev's fields (e.g. the refcount).
*/ */
void device_initialize(struct device *dev) void device_initialize(struct device *dev)
{ {
dev->kobj.kset = devices_kset; dev->kobj.kset = devices_kset;
...@@ -870,7 +866,6 @@ int device_add(struct device *dev) ...@@ -870,7 +866,6 @@ int device_add(struct device *dev)
goto Done; goto Done;
} }
/** /**
* device_register - register a device with the system. * device_register - register a device with the system.
* @dev: pointer to the device structure * @dev: pointer to the device structure
...@@ -882,14 +877,12 @@ int device_add(struct device *dev) ...@@ -882,14 +877,12 @@ int device_add(struct device *dev)
* have a clearly defined need to use and refcount the device * have a clearly defined need to use and refcount the device
* before it is added to the hierarchy. * before it is added to the hierarchy.
*/ */
int device_register(struct device *dev) int device_register(struct device *dev)
{ {
device_initialize(dev); device_initialize(dev);
return device_add(dev); return device_add(dev);
} }
/** /**
* get_device - increment reference count for device. * get_device - increment reference count for device.
* @dev: device. * @dev: device.
...@@ -898,25 +891,22 @@ int device_register(struct device *dev) ...@@ -898,25 +891,22 @@ int device_register(struct device *dev)
* we do take care to provide for the case that we get a NULL * we do take care to provide for the case that we get a NULL
* pointer passed in. * pointer passed in.
*/ */
struct device *get_device(struct device *dev)
struct device * get_device(struct device * dev)
{ {
return dev ? to_dev(kobject_get(&dev->kobj)) : NULL; return dev ? to_dev(kobject_get(&dev->kobj)) : NULL;
} }
/** /**
* put_device - decrement reference count. * put_device - decrement reference count.
* @dev: device in question. * @dev: device in question.
*/ */
void put_device(struct device * dev) void put_device(struct device *dev)
{ {
/* might_sleep(); */ /* might_sleep(); */
if (dev) if (dev)
kobject_put(&dev->kobj); kobject_put(&dev->kobj);
} }
/** /**
* device_del - delete device from system. * device_del - delete device from system.
* @dev: device. * @dev: device.
...@@ -930,10 +920,9 @@ void put_device(struct device * dev) ...@@ -930,10 +920,9 @@ void put_device(struct device * dev)
* NOTE: this should be called manually _iff_ device_add() was * NOTE: this should be called manually _iff_ device_add() was
* also called manually. * also called manually.
*/ */
void device_del(struct device *dev)
void device_del(struct device * dev)
{ {
struct device * parent = dev->parent; struct device *parent = dev->parent;
struct class_interface *class_intf; struct class_interface *class_intf;
device_pm_remove(dev); device_pm_remove(dev);
...@@ -989,17 +978,16 @@ void device_del(struct device * dev) ...@@ -989,17 +978,16 @@ void device_del(struct device * dev)
* via device_release() above. Otherwise, the structure will * via device_release() above. Otherwise, the structure will
* stick around until the final reference to the device is dropped. * stick around until the final reference to the device is dropped.
*/ */
void device_unregister(struct device * dev) void device_unregister(struct device *dev)
{ {
pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
device_del(dev); device_del(dev);
put_device(dev); put_device(dev);
} }
static struct device *next_device(struct klist_iter *i)
static struct device * next_device(struct klist_iter * i)
{ {
struct klist_node * n = klist_next(i); struct klist_node *n = klist_next(i);
return n ? container_of(n, struct device, knode_parent) : NULL; return n ? container_of(n, struct device, knode_parent) : NULL;
} }
...@@ -1015,11 +1003,11 @@ static struct device * next_device(struct klist_iter * i) ...@@ -1015,11 +1003,11 @@ static struct device * next_device(struct klist_iter * i)
* We check the return of @fn each time. If it returns anything * We check the return of @fn each time. If it returns anything
* other than 0, we break out and return that value. * other than 0, we break out and return that value.
*/ */
int device_for_each_child(struct device * parent, void * data, int device_for_each_child(struct device *parent, void *data,
int (*fn)(struct device *, void *)) int (*fn)(struct device *dev, void *data))
{ {
struct klist_iter i; struct klist_iter i;
struct device * child; struct device *child;
int error = 0; int error = 0;
klist_iter_init(&parent->klist_children, &i); klist_iter_init(&parent->klist_children, &i);
...@@ -1044,8 +1032,8 @@ int device_for_each_child(struct device * parent, void * data, ...@@ -1044,8 +1032,8 @@ int device_for_each_child(struct device * parent, void * data,
* current device can be obtained, this function will return to the caller * current device can be obtained, this function will return to the caller
* and not iterate over any more devices. * and not iterate over any more devices.
*/ */
struct device * device_find_child(struct device *parent, void *data, struct device *device_find_child(struct device *parent, void *data,
int (*match)(struct device *, void *)) int (*match)(struct device *dev, void *data))
{ {
struct klist_iter i; struct klist_iter i;
struct device *child; struct device *child;
...@@ -1312,8 +1300,7 @@ static int device_move_class_links(struct device *dev, ...@@ -1312,8 +1300,7 @@ static int device_move_class_links(struct device *dev,
class_name); class_name);
if (error) if (error)
sysfs_remove_link(&dev->kobj, "device"); sysfs_remove_link(&dev->kobj, "device");
} } else
else
error = 0; error = 0;
out: out:
kfree(class_name); kfree(class_name);
...@@ -1344,7 +1331,7 @@ int device_move(struct device *dev, struct device *new_parent) ...@@ -1344,7 +1331,7 @@ int device_move(struct device *dev, struct device *new_parent)
return -EINVAL; return -EINVAL;
new_parent = get_device(new_parent); new_parent = get_device(new_parent);
new_parent_kobj = get_device_parent (dev, new_parent); new_parent_kobj = get_device_parent(dev, new_parent);
pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
__FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>"); __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
...@@ -1390,7 +1377,7 @@ EXPORT_SYMBOL_GPL(device_move); ...@@ -1390,7 +1377,7 @@ EXPORT_SYMBOL_GPL(device_move);
*/ */
void device_shutdown(void) void device_shutdown(void)
{ {
struct device * dev, *devn; struct device *dev, *devn;
list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list, list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
kobj.entry) { kobj.entry) {
......
...@@ -93,6 +93,7 @@ int device_bind_driver(struct device *dev) ...@@ -93,6 +93,7 @@ int device_bind_driver(struct device *dev)
driver_bound(dev); driver_bound(dev);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(device_bind_driver);
static atomic_t probe_count = ATOMIC_INIT(0); static atomic_t probe_count = ATOMIC_INIT(0);
static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
...@@ -183,7 +184,7 @@ int driver_probe_done(void) ...@@ -183,7 +184,7 @@ int driver_probe_done(void)
* This function must be called with @dev->sem held. When called for a * This function must be called with @dev->sem held. When called for a
* USB interface, @dev->parent->sem must be held as well. * USB interface, @dev->parent->sem must be held as well.
*/ */
int driver_probe_device(struct device_driver * drv, struct device * dev) int driver_probe_device(struct device_driver *drv, struct device *dev)
{ {
int ret = 0; int ret = 0;
...@@ -201,9 +202,9 @@ done: ...@@ -201,9 +202,9 @@ done:
return ret; return ret;
} }
static int __device_attach(struct device_driver * drv, void * data) static int __device_attach(struct device_driver *drv, void *data)
{ {
struct device * dev = data; struct device *dev = data;
return driver_probe_device(drv, dev); return driver_probe_device(drv, dev);
} }
...@@ -221,7 +222,7 @@ static int __device_attach(struct device_driver * drv, void * data) ...@@ -221,7 +222,7 @@ static int __device_attach(struct device_driver * drv, void * data)
* *
* When called for a USB interface, @dev->parent->sem must be held. * When called for a USB interface, @dev->parent->sem must be held.
*/ */
int device_attach(struct device * dev) int device_attach(struct device *dev)
{ {
int ret = 0; int ret = 0;
...@@ -240,10 +241,11 @@ int device_attach(struct device * dev) ...@@ -240,10 +241,11 @@ int device_attach(struct device * dev)
up(&dev->sem); up(&dev->sem);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(device_attach);
static int __driver_attach(struct device * dev, void * data) static int __driver_attach(struct device *dev, void *data)
{ {
struct device_driver * drv = data; struct device_driver *drv = data;
/* /*
* Lock device and try to bind to it. We drop the error * Lock device and try to bind to it. We drop the error
...@@ -276,18 +278,19 @@ static int __driver_attach(struct device * dev, void * data) ...@@ -276,18 +278,19 @@ static int __driver_attach(struct device * dev, void * data)
* returns 0 and the @dev->driver is set, we've found a * returns 0 and the @dev->driver is set, we've found a
* compatible pair. * compatible pair.
*/ */
int driver_attach(struct device_driver * drv) int driver_attach(struct device_driver *drv)
{ {
return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
} }
EXPORT_SYMBOL_GPL(driver_attach);
/* /*
* __device_release_driver() must be called with @dev->sem held. * __device_release_driver() must be called with @dev->sem held.
* When called for a USB interface, @dev->parent->sem must be held as well. * When called for a USB interface, @dev->parent->sem must be held as well.
*/ */
static void __device_release_driver(struct device * dev) static void __device_release_driver(struct device *dev)
{ {
struct device_driver * drv; struct device_driver *drv;
drv = dev->driver; drv = dev->driver;
if (drv) { if (drv) {
...@@ -316,7 +319,7 @@ static void __device_release_driver(struct device * dev) ...@@ -316,7 +319,7 @@ static void __device_release_driver(struct device * dev)
* Manually detach device from driver. * Manually detach device from driver.
* When called for a USB interface, @dev->parent->sem must be held. * When called for a USB interface, @dev->parent->sem must be held.
*/ */
void device_release_driver(struct device * dev) void device_release_driver(struct device *dev)
{ {
/* /*
* If anyone calls device_release_driver() recursively from * If anyone calls device_release_driver() recursively from
...@@ -327,15 +330,15 @@ void device_release_driver(struct device * dev) ...@@ -327,15 +330,15 @@ void device_release_driver(struct device * dev)
__device_release_driver(dev); __device_release_driver(dev);
up(&dev->sem); up(&dev->sem);
} }
EXPORT_SYMBOL_GPL(device_release_driver);
/** /**
* driver_detach - detach driver from all devices it controls. * driver_detach - detach driver from all devices it controls.
* @drv: driver. * @drv: driver.
*/ */
void driver_detach(struct device_driver * drv) void driver_detach(struct device_driver *drv)
{ {
struct device * dev; struct device *dev;
for (;;) { for (;;) {
spin_lock(&drv->p->klist_devices.k_lock); spin_lock(&drv->p->klist_devices.k_lock);
...@@ -359,9 +362,3 @@ void driver_detach(struct device_driver * drv) ...@@ -359,9 +362,3 @@ void driver_detach(struct device_driver * drv)
put_device(dev); put_device(dev);
} }
} }
EXPORT_SYMBOL_GPL(device_bind_driver);
EXPORT_SYMBOL_GPL(device_release_driver);
EXPORT_SYMBOL_GPL(device_attach);
EXPORT_SYMBOL_GPL(driver_attach);
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
#define to_dev(node) container_of(node, struct device, driver_list) #define to_dev(node) container_of(node, struct device, driver_list)
static struct device * next_device(struct klist_iter * i) static struct device *next_device(struct klist_iter *i)
{ {
struct klist_node * n = klist_next(i); struct klist_node *n = klist_next(i);
return n ? container_of(n, struct device, knode_driver) : NULL; return n ? container_of(n, struct device, knode_driver) : NULL;
} }
...@@ -34,12 +34,11 @@ static struct device * next_device(struct klist_iter * i) ...@@ -34,12 +34,11 @@ static struct device * next_device(struct klist_iter * i)
* *
* Iterate over the @drv's list of devices calling @fn for each one. * Iterate over the @drv's list of devices calling @fn for each one.
*/ */
int driver_for_each_device(struct device_driver *drv, struct device *start,
int driver_for_each_device(struct device_driver * drv, struct device * start, void *data, int (*fn)(struct device *, void *))
void * data, int (*fn)(struct device *, void *))
{ {
struct klist_iter i; struct klist_iter i;
struct device * dev; struct device *dev;
int error = 0; int error = 0;
if (!drv) if (!drv)
...@@ -52,10 +51,8 @@ int driver_for_each_device(struct device_driver * drv, struct device * start, ...@@ -52,10 +51,8 @@ int driver_for_each_device(struct device_driver * drv, struct device * start,
klist_iter_exit(&i); klist_iter_exit(&i);
return error; return error;
} }
EXPORT_SYMBOL_GPL(driver_for_each_device); EXPORT_SYMBOL_GPL(driver_for_each_device);
/** /**
* driver_find_device - device iterator for locating a particular device. * driver_find_device - device iterator for locating a particular device.
* @drv: The device's driver * @drv: The device's driver
...@@ -71,9 +68,9 @@ EXPORT_SYMBOL_GPL(driver_for_each_device); ...@@ -71,9 +68,9 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
* if it does. If the callback returns non-zero, this function will * if it does. If the callback returns non-zero, this function will
* return to the caller and not iterate over any more devices. * return to the caller and not iterate over any more devices.
*/ */
struct device * driver_find_device(struct device_driver *drv, struct device *driver_find_device(struct device_driver *drv,
struct device * start, void * data, struct device *start, void *data,
int (*match)(struct device *, void *)) int (*match)(struct device *dev, void *data))
{ {
struct klist_iter i; struct klist_iter i;
struct device *dev; struct device *dev;
...@@ -96,8 +93,8 @@ EXPORT_SYMBOL_GPL(driver_find_device); ...@@ -96,8 +93,8 @@ EXPORT_SYMBOL_GPL(driver_find_device);
* @drv: driver. * @drv: driver.
* @attr: driver attribute descriptor. * @attr: driver attribute descriptor.
*/ */
int driver_create_file(struct device_driver *drv,
int driver_create_file(struct device_driver * drv, struct driver_attribute * attr) struct driver_attribute *attr)
{ {
int error; int error;
if (get_driver(drv)) { if (get_driver(drv)) {
...@@ -107,22 +104,22 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att ...@@ -107,22 +104,22 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att
error = -EINVAL; error = -EINVAL;
return error; return error;
} }
EXPORT_SYMBOL_GPL(driver_create_file);
/** /**
* driver_remove_file - remove sysfs file for driver. * driver_remove_file - remove sysfs file for driver.
* @drv: driver. * @drv: driver.
* @attr: driver attribute descriptor. * @attr: driver attribute descriptor.
*/ */
void driver_remove_file(struct device_driver *drv,
void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr) struct driver_attribute *attr)
{ {
if (get_driver(drv)) { if (get_driver(drv)) {
sysfs_remove_file(&drv->p->kobj, &attr->attr); sysfs_remove_file(&drv->p->kobj, &attr->attr);
put_driver(drv); put_driver(drv);
} }
} }
EXPORT_SYMBOL_GPL(driver_remove_file);
/** /**
* driver_add_kobj - add a kobject below the specified driver * driver_add_kobj - add a kobject below the specified driver
...@@ -152,7 +149,7 @@ EXPORT_SYMBOL_GPL(driver_add_kobj); ...@@ -152,7 +149,7 @@ EXPORT_SYMBOL_GPL(driver_add_kobj);
* get_driver - increment driver reference count. * get_driver - increment driver reference count.
* @drv: driver. * @drv: driver.
*/ */
struct device_driver * get_driver(struct device_driver * drv) struct device_driver *get_driver(struct device_driver *drv)
{ {
if (drv) { if (drv) {
struct driver_private *priv; struct driver_private *priv;
...@@ -164,16 +161,17 @@ struct device_driver * get_driver(struct device_driver * drv) ...@@ -164,16 +161,17 @@ struct device_driver * get_driver(struct device_driver * drv)
} }
return NULL; return NULL;
} }
EXPORT_SYMBOL_GPL(get_driver);
/** /**
* put_driver - decrement driver's refcount. * put_driver - decrement driver's refcount.
* @drv: driver. * @drv: driver.
*/ */
void put_driver(struct device_driver * drv) void put_driver(struct device_driver *drv)
{ {
kobject_put(&drv->p->kobj); kobject_put(&drv->p->kobj);
} }
EXPORT_SYMBOL_GPL(put_driver);
static int driver_add_groups(struct device_driver *drv, static int driver_add_groups(struct device_driver *drv,
struct attribute_group **groups) struct attribute_group **groups)
...@@ -205,7 +203,6 @@ static void driver_remove_groups(struct device_driver *drv, ...@@ -205,7 +203,6 @@ static void driver_remove_groups(struct device_driver *drv,
sysfs_remove_group(&drv->p->kobj, groups[i]); sysfs_remove_group(&drv->p->kobj, groups[i]);
} }
/** /**
* driver_register - register driver with bus * driver_register - register driver with bus
* @drv: driver to register * @drv: driver to register
...@@ -214,15 +211,15 @@ static void driver_remove_groups(struct device_driver *drv, ...@@ -214,15 +211,15 @@ static void driver_remove_groups(struct device_driver *drv,
* since most of the things we have to do deal with the bus * since most of the things we have to do deal with the bus
* structures. * structures.
*/ */
int driver_register(struct device_driver * drv) int driver_register(struct device_driver *drv)
{ {
int ret; int ret;
if ((drv->bus->probe && drv->probe) || if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) || (drv->bus->remove && drv->remove) ||
(drv->bus->shutdown && drv->shutdown)) { (drv->bus->shutdown && drv->shutdown))
printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); printk(KERN_WARNING "Driver '%s' needs updating - please use "
} "bus_type methods\n", drv->name);
ret = bus_add_driver(drv); ret = bus_add_driver(drv);
if (ret) if (ret)
return ret; return ret;
...@@ -231,6 +228,7 @@ int driver_register(struct device_driver * drv) ...@@ -231,6 +228,7 @@ int driver_register(struct device_driver * drv)
bus_remove_driver(drv); bus_remove_driver(drv);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(driver_register);
/** /**
* driver_unregister - remove driver from system. * driver_unregister - remove driver from system.
...@@ -238,12 +236,12 @@ int driver_register(struct device_driver * drv) ...@@ -238,12 +236,12 @@ int driver_register(struct device_driver * drv)
* *
* Again, we pass off most of the work to the bus-level call. * Again, we pass off most of the work to the bus-level call.
*/ */
void driver_unregister(struct device_driver *drv)
void driver_unregister(struct device_driver * drv)
{ {
driver_remove_groups(drv, drv->groups); driver_remove_groups(drv, drv->groups);
bus_remove_driver(drv); bus_remove_driver(drv);
} }
EXPORT_SYMBOL_GPL(driver_unregister);
/** /**
* driver_find - locate driver on a bus by its name. * driver_find - locate driver on a bus by its name.
...@@ -266,12 +264,4 @@ struct device_driver *driver_find(const char *name, struct bus_type *bus) ...@@ -266,12 +264,4 @@ struct device_driver *driver_find(const char *name, struct bus_type *bus)
} }
return NULL; return NULL;
} }
EXPORT_SYMBOL_GPL(driver_register);
EXPORT_SYMBOL_GPL(driver_unregister);
EXPORT_SYMBOL_GPL(get_driver);
EXPORT_SYMBOL_GPL(put_driver);
EXPORT_SYMBOL_GPL(driver_find); EXPORT_SYMBOL_GPL(driver_find);
EXPORT_SYMBOL_GPL(driver_create_file);
EXPORT_SYMBOL_GPL(driver_remove_file);
/* /*
*
* Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs * Copyright (c) 2002-3 Open Source Development Labs
* *
* This file is released under the GPLv2 * This file is released under the GPLv2
*
*/ */
#include <linux/device.h> #include <linux/device.h>
...@@ -19,7 +17,6 @@ ...@@ -19,7 +17,6 @@
* Call the driver model init functions to initialize their * Call the driver model init functions to initialize their
* subsystems. Called early from init/main.c. * subsystems. Called early from init/main.c.
*/ */
void __init driver_init(void) void __init driver_init(void)
{ {
/* These are the core pieces */ /* These are the core pieces */
......
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
#include "base.h" #include "base.h"
#define to_platform_driver(drv) (container_of((drv), struct platform_driver, driver)) #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
driver))
struct device platform_bus = { struct device platform_bus = {
.bus_id = "platform", .bus_id = "platform",
...@@ -33,9 +34,8 @@ EXPORT_SYMBOL_GPL(platform_bus); ...@@ -33,9 +34,8 @@ EXPORT_SYMBOL_GPL(platform_bus);
* @type: resource type * @type: resource type
* @num: resource index * @num: resource index
*/ */
struct resource * struct resource *platform_get_resource(struct platform_device *dev,
platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int type, unsigned int num)
unsigned int num)
{ {
int i; int i;
...@@ -43,8 +43,7 @@ platform_get_resource(struct platform_device *dev, unsigned int type, ...@@ -43,8 +43,7 @@ platform_get_resource(struct platform_device *dev, unsigned int type,
struct resource *r = &dev->resource[i]; struct resource *r = &dev->resource[i];
if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM|
IORESOURCE_IRQ|IORESOURCE_DMA)) IORESOURCE_IRQ|IORESOURCE_DMA)) == type)
== type)
if (num-- == 0) if (num-- == 0)
return r; return r;
} }
...@@ -71,9 +70,8 @@ EXPORT_SYMBOL_GPL(platform_get_irq); ...@@ -71,9 +70,8 @@ EXPORT_SYMBOL_GPL(platform_get_irq);
* @type: resource type * @type: resource type
* @name: resource name * @name: resource name
*/ */
struct resource * struct resource *platform_get_resource_byname(struct platform_device *dev,
platform_get_resource_byname(struct platform_device *dev, unsigned int type, unsigned int type, char *name)
char *name)
{ {
int i; int i;
...@@ -96,7 +94,8 @@ EXPORT_SYMBOL_GPL(platform_get_resource_byname); ...@@ -96,7 +94,8 @@ EXPORT_SYMBOL_GPL(platform_get_resource_byname);
*/ */
int platform_get_irq_byname(struct platform_device *dev, char *name) int platform_get_irq_byname(struct platform_device *dev, char *name)
{ {
struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name); struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ,
name);
return r ? r->start : -ENXIO; return r ? r->start : -ENXIO;
} }
...@@ -133,9 +132,8 @@ struct platform_object { ...@@ -133,9 +132,8 @@ struct platform_object {
* platform_device_put * platform_device_put
* @pdev: platform device to free * @pdev: platform device to free
* *
* Free all memory associated with a platform device. This function * Free all memory associated with a platform device. This function must
* must _only_ be externally called in error cases. All other usage * _only_ be externally called in error cases. All other usage is a bug.
* is a bug.
*/ */
void platform_device_put(struct platform_device *pdev) void platform_device_put(struct platform_device *pdev)
{ {
...@@ -146,7 +144,8 @@ EXPORT_SYMBOL_GPL(platform_device_put); ...@@ -146,7 +144,8 @@ EXPORT_SYMBOL_GPL(platform_device_put);
static void platform_device_release(struct device *dev) static void platform_device_release(struct device *dev)
{ {
struct platform_object *pa = container_of(dev, struct platform_object, pdev.dev); struct platform_object *pa = container_of(dev, struct platform_object,
pdev.dev);
kfree(pa->pdev.dev.platform_data); kfree(pa->pdev.dev.platform_data);
kfree(pa->pdev.resource); kfree(pa->pdev.resource);
...@@ -185,10 +184,11 @@ EXPORT_SYMBOL_GPL(platform_device_alloc); ...@@ -185,10 +184,11 @@ EXPORT_SYMBOL_GPL(platform_device_alloc);
* @num: number of resources * @num: number of resources
* *
* Add a copy of the resources to the platform device. The memory * Add a copy of the resources to the platform device. The memory
* associated with the resources will be freed when the platform * associated with the resources will be freed when the platform device is
* device is released. * released.
*/ */
int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num) int platform_device_add_resources(struct platform_device *pdev,
struct resource *res, unsigned int num)
{ {
struct resource *r; struct resource *r;
...@@ -208,11 +208,12 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources); ...@@ -208,11 +208,12 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources);
* @data: platform specific data for this platform device * @data: platform specific data for this platform device
* @size: size of platform specific data * @size: size of platform specific data
* *
* Add a copy of platform specific data to the platform device's platform_data * Add a copy of platform specific data to the platform device's
* pointer. The memory associated with the platform data will be freed * platform_data pointer. The memory associated with the platform data
* when the platform device is released. * will be freed when the platform device is released.
*/ */
int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size) int platform_device_add_data(struct platform_device *pdev, const void *data,
size_t size)
{ {
void *d; void *d;
...@@ -293,9 +294,8 @@ EXPORT_SYMBOL_GPL(platform_device_add); ...@@ -293,9 +294,8 @@ EXPORT_SYMBOL_GPL(platform_device_add);
* @pdev: platform device we're removing * @pdev: platform device we're removing
* *
* Note that this function will also release all memory- and port-based * Note that this function will also release all memory- and port-based
* resources owned by the device (@dev->resource). This function * resources owned by the device (@dev->resource). This function must
* must _only_ be externally called in error cases. All other usage * _only_ be externally called in error cases. All other usage is a bug.
* is a bug.
*/ */
void platform_device_del(struct platform_device *pdev) void platform_device_del(struct platform_device *pdev)
{ {
...@@ -316,9 +316,8 @@ EXPORT_SYMBOL_GPL(platform_device_del); ...@@ -316,9 +316,8 @@ EXPORT_SYMBOL_GPL(platform_device_del);
/** /**
* platform_device_register - add a platform-level device * platform_device_register - add a platform-level device
* @pdev: platform device we're adding * @pdev: platform device we're adding
*
*/ */
int platform_device_register(struct platform_device * pdev) int platform_device_register(struct platform_device *pdev)
{ {
device_initialize(&pdev->dev); device_initialize(&pdev->dev);
return platform_device_add(pdev); return platform_device_add(pdev);
...@@ -333,7 +332,7 @@ EXPORT_SYMBOL_GPL(platform_device_register); ...@@ -333,7 +332,7 @@ EXPORT_SYMBOL_GPL(platform_device_register);
* and remove it from the subsystem, then we drop reference count by * and remove it from the subsystem, then we drop reference count by
* calling platform_device_put(). * calling platform_device_put().
*/ */
void platform_device_unregister(struct platform_device * pdev) void platform_device_unregister(struct platform_device *pdev)
{ {
platform_device_del(pdev); platform_device_del(pdev);
platform_device_put(pdev); platform_device_put(pdev);
...@@ -348,20 +347,22 @@ EXPORT_SYMBOL_GPL(platform_device_unregister); ...@@ -348,20 +347,22 @@ EXPORT_SYMBOL_GPL(platform_device_unregister);
* @num: number of resources * @num: number of resources
* *
* This function creates a simple platform device that requires minimal * This function creates a simple platform device that requires minimal
* resource and memory management. Canned release function freeing * resource and memory management. Canned release function freeing memory
* memory allocated for the device allows drivers using such devices * allocated for the device allows drivers using such devices to be
* to be unloaded without waiting for the last reference to the device * unloaded without waiting for the last reference to the device to be
* to be dropped. * dropped.
* *
* This interface is primarily intended for use with legacy drivers * This interface is primarily intended for use with legacy drivers which
* which probe hardware directly. Because such drivers create sysfs * probe hardware directly. Because such drivers create sysfs device nodes
* device nodes themselves, rather than letting system infrastructure * themselves, rather than letting system infrastructure handle such device
* handle such device enumeration tasks, they don't fully conform to * enumeration tasks, they don't fully conform to the Linux driver model.
* the Linux driver model. In particular, when such drivers are built * In particular, when such drivers are built as modules, they can't be
* as modules, they can't be "hotplugged". * "hotplugged".
*/ */
struct platform_device *platform_device_register_simple(const char *name, int id, struct platform_device *platform_device_register_simple(const char *name,
struct resource *res, unsigned int num) int id,
struct resource *res,
unsigned int num)
{ {
struct platform_device *pdev; struct platform_device *pdev;
int retval; int retval;
...@@ -516,8 +517,8 @@ EXPORT_SYMBOL_GPL(platform_driver_probe); ...@@ -516,8 +517,8 @@ EXPORT_SYMBOL_GPL(platform_driver_probe);
* (b) sysfs attribute lets new-style coldplug recover from hotplug events * (b) sysfs attribute lets new-style coldplug recover from hotplug events
* mishandled before system is fully running: "modprobe $(cat modalias)" * mishandled before system is fully running: "modprobe $(cat modalias)"
*/ */
static ssize_t static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
modalias_show(struct device *dev, struct device_attribute *a, char *buf) char *buf)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name); int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);
...@@ -538,26 +539,24 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) ...@@ -538,26 +539,24 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
return 0; return 0;
} }
/** /**
* platform_match - bind platform device to platform driver. * platform_match - bind platform device to platform driver.
* @dev: device. * @dev: device.
* @drv: driver. * @drv: driver.
* *
* Platform device IDs are assumed to be encoded like this: * Platform device IDs are assumed to be encoded like this:
* "<name><instance>", where <name> is a short description of the * "<name><instance>", where <name> is a short description of the type of
* type of device, like "pci" or "floppy", and <instance> is the * device, like "pci" or "floppy", and <instance> is the enumerated
* enumerated instance of the device, like '0' or '42'. * instance of the device, like '0' or '42'. Driver IDs are simply
* Driver IDs are simply "<name>". * "<name>". So, extract the <name> from the platform_device structure,
* So, extract the <name> from the platform_device structure, * and compare it against the name of the driver. Return whether they match
* and compare it against the name of the driver. Return whether * or not.
* they match or not.
*/ */
static int platform_match(struct device *dev, struct device_driver *drv)
static int platform_match(struct device * dev, struct device_driver * drv)
{ {
struct platform_device *pdev = container_of(dev, struct platform_device, dev); struct platform_device *pdev;
pdev = container_of(dev, struct platform_device, dev);
return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
} }
...@@ -574,9 +573,10 @@ static int platform_suspend(struct device *dev, pm_message_t mesg) ...@@ -574,9 +573,10 @@ static int platform_suspend(struct device *dev, pm_message_t mesg)
static int platform_suspend_late(struct device *dev, pm_message_t mesg) static int platform_suspend_late(struct device *dev, pm_message_t mesg)
{ {
struct platform_driver *drv = to_platform_driver(dev->driver); struct platform_driver *drv = to_platform_driver(dev->driver);
struct platform_device *pdev = container_of(dev, struct platform_device, dev); struct platform_device *pdev;
int ret = 0; int ret = 0;
pdev = container_of(dev, struct platform_device, dev);
if (dev->driver && drv->suspend_late) if (dev->driver && drv->suspend_late)
ret = drv->suspend_late(pdev, mesg); ret = drv->suspend_late(pdev, mesg);
...@@ -586,16 +586,17 @@ static int platform_suspend_late(struct device *dev, pm_message_t mesg) ...@@ -586,16 +586,17 @@ static int platform_suspend_late(struct device *dev, pm_message_t mesg)
static int platform_resume_early(struct device *dev) static int platform_resume_early(struct device *dev)
{ {
struct platform_driver *drv = to_platform_driver(dev->driver); struct platform_driver *drv = to_platform_driver(dev->driver);
struct platform_device *pdev = container_of(dev, struct platform_device, dev); struct platform_device *pdev;
int ret = 0; int ret = 0;
pdev = container_of(dev, struct platform_device, dev);
if (dev->driver && drv->resume_early) if (dev->driver && drv->resume_early)
ret = drv->resume_early(pdev); ret = drv->resume_early(pdev);
return ret; return ret;
} }
static int platform_resume(struct device * dev) static int platform_resume(struct device *dev)
{ {
int ret = 0; int ret = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment