Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8bf2540 authored by Dmitry Eremin-Solenikov's avatar Dmitry Eremin-Solenikov Committed by Greg Kroah-Hartman
Browse files

platform: add new device registration helper



Add a helper that registers simple platform_device w/o resources but with
parent and device data.

This is usefull to cleanup platform code from code that registers such
simple devices as leds-gpio, generic-bl, etc.

Signed-off-by: default avatarDmitry Baryshkov <dbaryshkov@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 45c076c5
Loading
Loading
Loading
Loading
+47 −0
Original line number Original line Diff line number Diff line
@@ -391,6 +391,53 @@ struct platform_device *platform_device_register_simple(const char *name,
}
}
EXPORT_SYMBOL_GPL(platform_device_register_simple);
EXPORT_SYMBOL_GPL(platform_device_register_simple);


/**
 * platform_device_register_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.
 */
struct platform_device *platform_device_register_data(
		struct device *parent,
		const char *name, int id,
		const void *data, size_t size)
{
	struct platform_device *pdev;
	int retval;

	pdev = platform_device_alloc(name, id);
	if (!pdev) {
		retval = -ENOMEM;
		goto error;
	}

	pdev->dev.parent = parent;

	if (size) {
		retval = platform_device_add_data(pdev, data, size);
		if (retval)
			goto error;
	}

	retval = platform_device_add(pdev);
	if (retval)
		goto error;

	return pdev;

error:
	platform_device_put(pdev);
	return ERR_PTR(retval);
}

static int platform_drv_probe(struct device *_dev)
static int platform_drv_probe(struct device *_dev)
{
{
	struct platform_driver *drv = to_platform_driver(_dev->driver);
	struct platform_driver *drv = to_platform_driver(_dev->driver);
+2 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,8 @@ 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_simple(const char *, int id,
					struct resource *, unsigned int);
					struct resource *, unsigned int);
extern struct platform_device *platform_device_register_data(struct device *,
		const char *, int, const void *, size_t);


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, struct resource *res, unsigned int num);
extern int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num);