aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKumar Gala <galak@linen.sps.mot.com>2004-12-16 22:11:24 -0800
committerGreg Kroah-Hartman <greg@kroah.com>2004-12-16 22:11:24 -0800
commitb1cbc1086d663905c0e5775f3f5f28239f6c505e (patch)
tree3ae6366a4581629d64648a58853cb808c7498757
parentdd96557809ebcfaeb6055045c2e4ce8bddb5a1a3 (diff)
downloadhistory-b1cbc1086d663905c0e5775f3f5f28239f6c505e.tar.gz
[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: Kumar Gala <kumar.gala@freescale.com> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
-rw-r--r--drivers/base/platform.c40
-rw-r--r--include/linux/device.h2
2 files changed, 41 insertions, 1 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 04451da003a6bb..3518207131145b 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -58,6 +58,41 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
}
/**
+ * 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
* @num: number of platform devices in array
@@ -103,7 +138,8 @@ int platform_device_register(struct platform_device * pdev)
for (i = 0; i < pdev->num_resources; i++) {
struct resource *p, *r = &pdev->resource[i];
- r->name = pdev->dev.bus_id;
+ if (r->name == NULL)
+ r->name = pdev->dev.bus_id;
p = NULL;
if (r->flags & IORESOURCE_MEM)
@@ -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);
diff --git a/include/linux/device.h b/include/linux/device.h
index c64cec37dd69d1..d885723a2c3aa6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -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);