mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-01 03:54:02 +00:00
Driver core: reduce duplicated code for platform_device creation
This makes the two similar functions platform_device_register_simple and platform_device_register_data one line inline functions using a new generic function platform_device_register_resndata. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
3e61dfd850
commit
44f28bdea0
3 changed files with 85 additions and 82 deletions
|
@ -111,6 +111,7 @@ X!Edrivers/base/attribute_container.c
|
||||||
<!--
|
<!--
|
||||||
X!Edrivers/base/interface.c
|
X!Edrivers/base/interface.c
|
||||||
-->
|
-->
|
||||||
|
!Iinclude/linux/platform_device.h
|
||||||
!Edrivers/base/platform.c
|
!Edrivers/base/platform.c
|
||||||
!Edrivers/base/bus.c
|
!Edrivers/base/bus.c
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
|
@ -344,108 +344,56 @@ void platform_device_unregister(struct platform_device *pdev)
|
||||||
EXPORT_SYMBOL_GPL(platform_device_unregister);
|
EXPORT_SYMBOL_GPL(platform_device_unregister);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* platform_device_register_simple - add a platform-level device and its resources
|
* platform_device_register_resndata - add a platform-level device with
|
||||||
|
* resources and platform-specific data
|
||||||
|
*
|
||||||
|
* @parent: parent device for the device we're adding
|
||||||
* @name: base name of the device we're adding
|
* @name: base name of the device we're adding
|
||||||
* @id: instance id
|
* @id: instance id
|
||||||
* @res: set of resources that needs to be allocated for the device
|
* @res: set of resources that needs to be allocated for the device
|
||||||
* @num: number of resources
|
* @num: number of resources
|
||||||
*
|
|
||||||
* This function creates a simple platform device that requires minimal
|
|
||||||
* resource and memory management. Canned release function freeing memory
|
|
||||||
* allocated for the device allows drivers using such devices to be
|
|
||||||
* unloaded without waiting for the last reference to the device to be
|
|
||||||
* dropped.
|
|
||||||
*
|
|
||||||
* This interface is primarily intended for use with legacy drivers which
|
|
||||||
* probe hardware directly. Because such drivers create sysfs device nodes
|
|
||||||
* themselves, rather than letting system infrastructure handle such device
|
|
||||||
* enumeration tasks, they don't fully conform to the Linux driver model.
|
|
||||||
* In particular, when such drivers are built as modules, they can't be
|
|
||||||
* "hotplugged".
|
|
||||||
*
|
|
||||||
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
|
|
||||||
*/
|
|
||||||
struct platform_device *platform_device_register_simple(const char *name,
|
|
||||||
int id,
|
|
||||||
const struct resource *res,
|
|
||||||
unsigned int num)
|
|
||||||
{
|
|
||||||
struct platform_device *pdev;
|
|
||||||
int retval;
|
|
||||||
|
|
||||||
pdev = platform_device_alloc(name, id);
|
|
||||||
if (!pdev) {
|
|
||||||
retval = -ENOMEM;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num) {
|
|
||||||
retval = platform_device_add_resources(pdev, res, num);
|
|
||||||
if (retval)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
retval = platform_device_add(pdev);
|
|
||||||
if (retval)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
return pdev;
|
|
||||||
|
|
||||||
error:
|
|
||||||
platform_device_put(pdev);
|
|
||||||
return ERR_PTR(retval);
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(platform_device_register_simple);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* platform_device_register_data - add a platform-level device with platform-specific data
|
|
||||||
* @parent: parent device for the device we're adding
|
|
||||||
* @name: base name of the device we're adding
|
|
||||||
* @id: instance id
|
|
||||||
* @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
|
||||||
*
|
*
|
||||||
* This function creates a simple platform device that requires minimal
|
|
||||||
* resource and memory management. Canned release function freeing memory
|
|
||||||
* allocated for the device allows drivers using such devices to be
|
|
||||||
* unloaded without waiting for the last reference to the device to be
|
|
||||||
* dropped.
|
|
||||||
*
|
|
||||||
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
|
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
|
||||||
*/
|
*/
|
||||||
struct platform_device *platform_device_register_data(
|
struct platform_device *platform_device_register_resndata(
|
||||||
struct device *parent,
|
struct device *parent,
|
||||||
const char *name, int id,
|
const char *name, int id,
|
||||||
|
const struct resource *res, unsigned int num,
|
||||||
const void *data, size_t size)
|
const void *data, size_t size)
|
||||||
{
|
{
|
||||||
|
int ret = -ENOMEM;
|
||||||
struct platform_device *pdev;
|
struct platform_device *pdev;
|
||||||
int retval;
|
|
||||||
|
|
||||||
pdev = platform_device_alloc(name, id);
|
pdev = platform_device_alloc(name, id);
|
||||||
if (!pdev) {
|
if (!pdev)
|
||||||
retval = -ENOMEM;
|
goto err;
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
pdev->dev.parent = parent;
|
pdev->dev.parent = parent;
|
||||||
|
|
||||||
if (size) {
|
if (res) {
|
||||||
retval = platform_device_add_data(pdev, data, size);
|
ret = platform_device_add_resources(pdev, res, num);
|
||||||
if (retval)
|
if (ret)
|
||||||
goto error;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = platform_device_add(pdev);
|
if (data) {
|
||||||
if (retval)
|
ret = platform_device_add_data(pdev, data, size);
|
||||||
goto error;
|
if (ret)
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = platform_device_add(pdev);
|
||||||
|
if (ret) {
|
||||||
|
err:
|
||||||
|
platform_device_put(pdev);
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
}
|
||||||
|
|
||||||
return pdev;
|
return pdev;
|
||||||
|
|
||||||
error:
|
|
||||||
platform_device_put(pdev);
|
|
||||||
return ERR_PTR(retval);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(platform_device_register_data);
|
EXPORT_SYMBOL_GPL(platform_device_register_resndata);
|
||||||
|
|
||||||
static int platform_drv_probe(struct device *_dev)
|
static int platform_drv_probe(struct device *_dev)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,10 +43,64 @@ extern struct resource *platform_get_resource_byname(struct platform_device *, u
|
||||||
extern int platform_get_irq_byname(struct platform_device *, const char *);
|
extern int platform_get_irq_byname(struct platform_device *, const char *);
|
||||||
extern int platform_add_devices(struct platform_device **, int);
|
extern int platform_add_devices(struct platform_device **, int);
|
||||||
|
|
||||||
extern struct platform_device *platform_device_register_simple(const char *, int id,
|
extern struct platform_device *platform_device_register_resndata(
|
||||||
const struct resource *, unsigned int);
|
struct device *parent, const char *name, int id,
|
||||||
extern struct platform_device *platform_device_register_data(struct device *,
|
const struct resource *res, unsigned int num,
|
||||||
const char *, int, const void *, size_t);
|
const void *data, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* platform_device_register_simple - add a platform-level device and its resources
|
||||||
|
* @name: base name of the device we're adding
|
||||||
|
* @id: instance id
|
||||||
|
* @res: set of resources that needs to be allocated for the device
|
||||||
|
* @num: number of resources
|
||||||
|
*
|
||||||
|
* This function creates a simple platform device that requires minimal
|
||||||
|
* resource and memory management. Canned release function freeing memory
|
||||||
|
* allocated for the device allows drivers using such devices to be
|
||||||
|
* unloaded without waiting for the last reference to the device to be
|
||||||
|
* dropped.
|
||||||
|
*
|
||||||
|
* This interface is primarily intended for use with legacy drivers which
|
||||||
|
* probe hardware directly. Because such drivers create sysfs device nodes
|
||||||
|
* themselves, rather than letting system infrastructure handle such device
|
||||||
|
* enumeration tasks, they don't fully conform to the Linux driver model.
|
||||||
|
* In particular, when such drivers are built as modules, they can't be
|
||||||
|
* "hotplugged".
|
||||||
|
*
|
||||||
|
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
|
||||||
|
*/
|
||||||
|
static inline struct platform_device *platform_device_register_simple(
|
||||||
|
const char *name, int id,
|
||||||
|
const struct resource *res, unsigned int num)
|
||||||
|
{
|
||||||
|
return platform_device_register_resndata(NULL, name, id,
|
||||||
|
res, num, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* platform_device_register_data - add a platform-level device with platform-specific data
|
||||||
|
* @parent: parent device for the device we're adding
|
||||||
|
* @name: base name of the device we're adding
|
||||||
|
* @id: instance id
|
||||||
|
* @data: platform specific data for this platform device
|
||||||
|
* @size: size of platform specific data
|
||||||
|
*
|
||||||
|
* This function creates a simple platform device that requires minimal
|
||||||
|
* resource and memory management. Canned release function freeing memory
|
||||||
|
* allocated for the device allows drivers using such devices to be
|
||||||
|
* unloaded without waiting for the last reference to the device to be
|
||||||
|
* dropped.
|
||||||
|
*
|
||||||
|
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
|
||||||
|
*/
|
||||||
|
static inline struct platform_device *platform_device_register_data(
|
||||||
|
struct device *parent, const char *name, int id,
|
||||||
|
const void *data, size_t size)
|
||||||
|
{
|
||||||
|
return platform_device_register_resndata(parent, name, id,
|
||||||
|
NULL, 0, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
extern struct platform_device *platform_device_alloc(const char *name, int id);
|
extern struct platform_device *platform_device_alloc(const char *name, int id);
|
||||||
extern int platform_device_add_resources(struct platform_device *pdev,
|
extern int platform_device_add_resources(struct platform_device *pdev,
|
||||||
|
|
Loading…
Add table
Reference in a new issue