Provide a helper to lookup platform devices by matching device driver in order to avoid drivers trying to use platform bus internals.
Cc: Eric Anholt <e...@anholt.net> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: "Heiko Stübner" <he...@sntech.de> Cc: Inki Dae <inki....@samsung.com> Cc: "Rafael J. Wysocki" <raf...@kernel.org> Cc: Sandy Huang <h...@rock-chips.com> Cc: Seung-Woo Kim <sw0312....@samsung.com> Signed-off-by: Suzuki K Poulose <suzuki.poul...@arm.com> --- drivers/base/platform.c | 14 ++++++++++++++ include/linux/platform_device.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 4d17298..158ac24 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = { }; EXPORT_SYMBOL_GPL(platform_bus_type); +/** + * platform_find_device_by_driver - Find a platform device with a given + * driver. + * @start: The device to start the search from. + * @drv: The device driver to look for. + */ +struct device *platform_find_device_by_driver(struct device *start, + const struct device_driver *drv) +{ + return bus_find_device(&platform_bus_type, start, drv, + (void *)platform_match); +} +EXPORT_SYMBOL_GPL(platform_find_device_by_driver); + int __init platform_bus_init(void) { int error; diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index cc46485..36aa775 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -52,6 +52,9 @@ extern struct device platform_bus; extern void arch_setup_pdev_archdata(struct platform_device *); extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int); +extern struct device * +platform_find_device_by_driver(struct device * dev, + const struct device_driver *drv); extern void __iomem * devm_platform_ioremap_resource(struct platform_device *pdev, unsigned int index); -- 2.7.4