driver core: platform: Introduce platform_get_mem_or_io()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 9 Dec 2020 20:36:38 +0000 (22:36 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Dec 2020 15:31:46 +0000 (16:31 +0100)
There are at least few existing users of the proposed API which
retrieves either MEM or IO resource from platform device.

Make it common to utilize in the existing and new users.

Cc: Eric Auger <eric.auger@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: Peng Hao <peng.hao2@zte.com.cn>
Cc: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20201209203642.27648-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/platform.c
include/linux/platform_device.h

index 8ad06daa2eaa7c2c8b3ebcdb1f9cada48889d1fb..0358dc3ea3ad623735376991b526a0134aeab5d0 100644 (file)
@@ -63,6 +63,21 @@ struct resource *platform_get_resource(struct platform_device *dev,
 }
 EXPORT_SYMBOL_GPL(platform_get_resource);
 
+struct resource *platform_get_mem_or_io(struct platform_device *dev,
+                                       unsigned int num)
+{
+       u32 i;
+
+       for (i = 0; i < dev->num_resources; i++) {
+               struct resource *r = &dev->resource[i];
+
+               if ((resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) && num-- == 0)
+                       return r;
+       }
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(platform_get_mem_or_io);
+
 #ifdef CONFIG_HAS_IOMEM
 /**
  * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a
index 77a2aada106dcb016833d77cc3b0842c35a4db4b..ee6a9f10c2c73803761e386d1bfee44a83155ac9 100644 (file)
@@ -52,6 +52,9 @@ extern struct device platform_bus;
 
 extern struct resource *platform_get_resource(struct platform_device *,
                                              unsigned int, unsigned int);
+extern struct resource *platform_get_mem_or_io(struct platform_device *,
+                                              unsigned int);
+
 extern struct device *
 platform_find_device_by_driver(struct device *start,
                               const struct device_driver *drv);