Re: [PATCH] USB and Driver Core patches for 2.6.10

From: Greg KH (greg_at_kroah.com)
Date: 01/08/05

  • Next message: Greg KH: "Re: [PATCH] USB and Driver Core patches for 2.6.10"
    Date:	Fri, 7 Jan 2005 21:47:39 -0800
    To: linux-usb-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
    
    

    ChangeSet 1.1938.444.8, 2004/12/17 14:11:24-08:00, galak@linen.sps.mot.com

    [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>

     drivers/base/platform.c | 40 +++++++++++++++++++++++++++++++++++++++-
     include/linux/device.h | 2 ++
     2 files changed, 41 insertions(+), 1 deletion(-)

    diff -Nru a/drivers/base/platform.c b/drivers/base/platform.c
    --- a/drivers/base/platform.c 2005-01-07 15:46:02 -08:00
    +++ b/drivers/base/platform.c 2005-01-07 15:46:02 -08:00
    @@ -58,6 +58,41 @@
     }
     
     /**
    + * 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 @@
             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_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 -Nru a/include/linux/device.h b/include/linux/device.h
    --- a/include/linux/device.h 2005-01-07 15:46:02 -08:00
    +++ b/include/linux/device.h 2005-01-07 15:46:02 -08:00
    @@ -382,6 +382,8 @@
     
     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);

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Greg KH: "Re: [PATCH] USB and Driver Core patches for 2.6.10"

    Relevant Pages


    Loading