Commit b1cbc108 authored by Kumar Gala's avatar Kumar Gala Committed by Greg Kroah-Hartman

[PATCH] Driver Core: Add platform_get_resource_byname & platform_get_resource_byirq

Adds the ability to find a resource or irq on a platform device by its
resource name.  This patch also tweaks how resource names get set.
Before, resources names were set to pdev->dev.bus_id, now that only
happens if the resource name has not been previous set.

All of this allows us to find a resource without assuming what order the
resources are in.
Signed-off-by: default avatarKumar Gala <kumar.gala@freescale.com>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent dd965578
......@@ -57,6 +57,41 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
return r ? r->start : 0;
}
/**
* platform_get_resource_byname - get a resource for a device by name
* @dev: platform device
* @type: resource type
* @name: resource name
*/
struct resource *
platform_get_resource_byname(struct platform_device *dev, unsigned int type,
char *name)
{
int i;
for (i = 0; i < dev->num_resources; i++) {
struct resource *r = &dev->resource[i];
if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM|
IORESOURCE_IRQ|IORESOURCE_DMA)) == type)
if (!strcmp(r->name, name))
return r;
}
return NULL;
}
/**
* platform_get_irq - get an IRQ for a device
* @dev: platform device
* @name: IRQ name
*/
int platform_get_irq_byname(struct platform_device *dev, char *name)
{
struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
return r ? r->start : 0;
}
/**
* platform_add_devices - add a numbers of platform devices
* @devs: array of platform devices to add
......@@ -103,6 +138,7 @@ int platform_device_register(struct platform_device * pdev)
for (i = 0; i < pdev->num_resources; i++) {
struct resource *p, *r = &pdev->resource[i];
if (r->name == NULL)
r->name = pdev->dev.bus_id;
p = NULL;
......@@ -308,3 +344,5 @@ EXPORT_SYMBOL_GPL(platform_device_register_simple);
EXPORT_SYMBOL_GPL(platform_device_unregister);
EXPORT_SYMBOL_GPL(platform_get_irq);
EXPORT_SYMBOL_GPL(platform_get_resource);
EXPORT_SYMBOL_GPL(platform_get_irq_byname);
EXPORT_SYMBOL_GPL(platform_get_resource_byname);
......@@ -382,6 +382,8 @@ extern struct device platform_bus;
extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
extern int platform_get_irq(struct platform_device *, unsigned int);
extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, char *);
extern int platform_get_irq_byname(struct platform_device *, char *);
extern int platform_add_devices(struct platform_device **, int);
extern struct platform_device *platform_device_register_simple(char *, unsigned int, struct resource *, unsigned int);
......
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