of: Introduce of_match_device()
Subsystems (29)
cover of: Introduce of_match_device()
From: Thierry Reding <[email protected]>
This series of patches introduces a common implementation of a function that can be used in iterators (such as the bus_for_each_dev() or the driver_for_each_device() functions) and that compare's a device's device tree node with the passed in data. Numerous drivers and subsystems have their own variant of this function, so a lot of duplication can be removed by making use of the common implementation.
One thing that slightly bugs me about this is that it can't be used with users of class_for_each_device() or class_find_device() because they get passed a callback that takes a const void * rather than a void * for the device tree node. I had at some point investigated to turn the remainder of the iterators into taking const void *, but there are some drivers in the kernel that want to modify the data passed to them, so it isn't easy to switch.
An alternative would be to turn the const void * into void * for all the callbacks of this sort, so that we can use a single set throughout the tree, but I'm not sure how welcome that would be. I can give that a shot if people think it worth, though.
Greg, any thoughts on this?
I've also kept the list of recipients very short, to get early feedback and buy-in from Rob and Frank on the common implementation. I expect the naming to allow for some good bike-shedding.
Russell, I've Cc'ed you explicitly on this because last dozen or so patches touch users of component helpers and you've been busy working on those lately. I wanted to give you a heads up on this and am looking for your feedback on where you think this would fit in.
Merging this might get a little complicated, but I think it'd be easiest to take it all through the DT tree. Perhaps we can hold off on the final DRM and IOMMU patches since they are based on stuff currently in linux- next only, and defer those to v4.9?
Thierry
Thierry Reding (22):
of: Implement of_match_device()
amba: tegra-ahb: Use of_device_match()
coresight: Use of_device_match()
i2c: core: Use of_device_match()
net: cpsw-phy-sel: Use of_device_match()
nvmem: core: Use of_device_match()
of/platform: Use of_device_match()
spi: Use of_device_match()
of: mdio: Use of_device_match()
usb: phy: am335x-control: Use of_device_match()
usb: phy: isp1301: Use of_device_match()
drm/hdlcd: Use of_device_match()
drm/armada: Use of_device_match()
drm/etnaviv: Use of_device_match()
drm/hisilicon: Use of_device_match()
drm/mediatek: Use of_device_match()
drm/msm: Use of_device_match()
drm/rockchip: Use of_device_match()
drm/sti: Use of_device_match()
drm/sun4i: Use of_device_match()
drm/tilcdc: Use of_device_match()
iommu/mediatek: Use of_device_match()
drivers/amba/tegra-ahb.c | 11 ++--------- drivers/gpu/drm/arm/hdlcd_drv.c | 8 ++------ drivers/gpu/drm/armada/armada_drv.c | 8 ++------ drivers/gpu/drm/drm_mipi_dsi.c | 5 ----- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 12 +++--------- drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 8 ++------ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 8 ++------ drivers/gpu/drm/msm/msm_drv.c | 13 +++---------- drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 12 +++--------- drivers/gpu/drm/sti/sti_drv.c | 8 ++------ drivers/gpu/drm/sun4i/sun4i_drv.c | 12 ++---------- drivers/gpu/drm/tilcdc/tilcdc_external.c | 8 ++------ drivers/hwtracing/coresight/of_coresight.c | 10 +++------- drivers/i2c/i2c-core.c | 9 ++------- drivers/iommu/mtk_iommu.c | 8 ++------ drivers/net/ethernet/ti/cpsw-phy-sel.c | 9 ++------- drivers/nvmem/core.c | 8 ++------ drivers/of/of_mdio.c | 9 ++------- drivers/of/platform.c | 7 +------ drivers/spi/spi.c | 7 +------ drivers/usb/phy/phy-am335x-control.c | 10 +++------- drivers/usb/phy/phy-isp1301.c | 13 ++++--------- include/linux/of_device.h | 5 +++++ 23 files changed, 52 insertions(+), 156 deletions(-)
Signature · 6 lines
2.8.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/22 of: Implement of_match_device()
From: Thierry Reding <[email protected]>
Many drivers open-code a variant of this function to look up the device representing a given device tree node. Provide a common implementation that can be reused by all drivers to avoid duplication.
--- drivers/gpu/drm/drm_mipi_dsi.c | 5 ----- include/linux/of_device.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_mipi_dsi.c +0 -5
@@ -77,11 +77,6 @@ static struct bus_type mipi_dsi_bus_type = { .pm = &mipi_dsi_device_pm_ops, }; -static int of_device_match (struct device *dev,void *data) -{ -return dev->of_node == data; -} -/** * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a * device tree node
include/linux/of_device.h +5 -0
@@ -102,4 +102,9 @@ static inline void of_dma_configure(struct device *dev, struct device_node *np) {}#endif /* CONFIG_OF */ +static inline int of_device_match (struct device *dev,void *data) +{ +return dev->of_node == data; +} +#endif /* _LINUX_OF_DEVICE_H */
Signature · 6 lines
2.8.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/22 amba: tegra-ahb: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the open-coded variant.
--- drivers/amba/tegra-ahb.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/amba/tegra-ahb.c +2 -9
@@ -26,6 +26,7 @@#include <linux/platform_device.h> #include <linux/io.h> #include <linux/of.h> +#include <linux/of_device.h> #include <soc/tegra/ahb.h>
@@ -143,14 +144,6 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset) }#ifdef CONFIG_TEGRA_IOMMU_SMMU -static int tegra_ahb_match_by_smmu (struct device *dev,void *data) -{ -struct tegra_ahb *ahb =dev_get_drvdata (dev); -struct device_node *dn = data; - -return (ahb->dev->of_node == dn) ?1 :0 ; -} -int tegra_ahb_enable_smmu (struct device_node *dn) {struct device *dev;
@@ -158,7 +151,7 @@ int tegra_ahb_enable_smmu(struct device_node *dn)struct tegra_ahb *ahb; dev =driver_find_device (&tegra_ahb_driver.driver,NULL , dn, - tegra_ahb_match_by_smmu); + of_device_match);if (!dev)return -EPROBE_DEFER ; ahb =dev_get_drvdata (dev);
Signature · 1 line
2.8.3
PATCH 3/22 coresight: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/hwtracing/coresight/of_coresight.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/hwtracing/coresight/of_coresight.c +3 -7
@@ -16,6 +16,7 @@#include <linux/clk.h> #include <linux/of.h> #include <linux/of_address.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <linux/of_platform.h> #include <linux/platform_device.h>
@@ -25,11 +26,6 @@#include <asm/smp_plat.h> -static int of_dev_node_match (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static struct device *of_coresight_get_endpoint_device (struct device_node *endpoint) {
@@ -40,7 +36,7 @@ of_coresight_get_endpoint_device(struct device_node *endpoint)* platform bus. */ dev =bus_find_device (&platform_bus_type,NULL , - endpoint, of_dev_node_match); + endpoint, of_device_match);if (dev)return dev;
@@ -49,7 +45,7 @@ of_coresight_get_endpoint_device(struct device_node *endpoint)* looking for the device that matches the endpoint node. */ return bus_find_device (&amba_bustype,NULL , - endpoint, of_dev_node_match); + endpoint, of_device_match); } static void of_coresight_get_ports(struct device_node *node,
Signature · 1 line
2.8.3
PATCH 4/22 i2c: core: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the I2C-private variant.
--- drivers/i2c/i2c-core.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/i2c/i2c-core.c +2 -7
@@ -1426,18 +1426,13 @@ static void of_i2c_register_devices(struct i2c_adapter *adap) } } -static int of_dev_node_match (struct device *dev,void *data) -{ -return dev->of_node == data; -} -/* must call put_device() when done with returned i2c_client device */ struct i2c_client *of_find_i2c_device_by_node (struct device_node *node) {struct device *dev;struct i2c_client *client; - dev =bus_find_device (&i2c_bus_type,NULL , node, of_dev_node_match); + dev =bus_find_device (&i2c_bus_type,NULL , node, of_device_match);if (!dev)return NULL ;
@@ -1455,7 +1450,7 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)struct device *dev;struct i2c_adapter *adapter; - dev =bus_find_device (&i2c_bus_type,NULL , node, of_dev_node_match); + dev =bus_find_device (&i2c_bus_type,NULL , node, of_device_match);if (!dev)return NULL ;
Signature · 1 line
2.8.3
PATCH 5/22 net: cpsw-phy-sel: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This driver uses bus_find_device() to go through every platform device and match using the driver and device tree node. It's more efficient to use driver_find_device() to iterate over all devices associated with a particular driver, in which case the matching is reduced to the device tree node and can be done using the common implementation.
--- drivers/net/ethernet/ti/cpsw-phy-sel.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/ethernet/ti/cpsw-phy-sel.c +2 -7
@@ -143,12 +143,6 @@ static void cpsw_gmii_sel_dra7xx(struct cpsw_phy_sel_priv *priv, }static struct platform_driver cpsw_phy_sel_driver; -static int match (struct device *dev,void *data) -{ -struct device_node *node = (struct device_node *)data; -return dev->of_node == node && - dev->driver == &cpsw_phy_sel_driver.driver; -}void cpsw_phy_sel (struct device *dev,phy_interface_t phy_mode,int slave) {
@@ -161,7 +155,8 @@ void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave)return ; } - dev =bus_find_device (&platform_bus_type,NULL , node, match); + dev =driver_find_device (&cpsw_phy_sel_driver.driver,NULL , node, + of_device_match); priv =dev_get_drvdata (dev); priv->cpsw_phy_sel (priv, phy_mode, slave);
Signature · 1 line
2.8.3
PATCH 6/22 nvmem: core: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the subsystem-specific one.
--- drivers/nvmem/core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/nvmem/core.c +2 -6
@@ -23,6 +23,7 @@#include <linux/nvmem-consumer.h> #include <linux/nvmem-provider.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/slab.h> struct nvmem_device {
@@ -263,11 +264,6 @@ static struct bus_type nvmem_bus_type = { .name = "nvmem", }; -static int of_nvmem_match (struct device *dev,void *nvmem_np) -{ -return dev->of_node == nvmem_np; -} -static struct nvmem_device *of_nvmem_find (struct device_node *nvmem_np) {struct device *d;
@@ -275,7 +271,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)if (!nvmem_np)return NULL ; - d =bus_find_device (&nvmem_bus_type,NULL , nvmem_np, of_nvmem_match); + d =bus_find_device (&nvmem_bus_type,NULL , nvmem_np, of_device_match);if (!d)return NULL ;
Signature · 6 lines
2.8.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 7/22 of/platform: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the OF-private variant.
--- drivers/of/platform.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/of/platform.c +1 -6
@@ -33,11 +33,6 @@ const struct of_device_id of_default_bus_match_table[] = { };EXPORT_SYMBOL (of_default_bus_match_table); -static int of_dev_node_match (struct device *dev,void *data) -{ -return dev->of_node == data; -} -/** * of_find_device_by_node - Find the platform_device associated with a node * @np: Pointer to device tree node
@@ -48,7 +43,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np) {struct device *dev; - dev =bus_find_device (&platform_bus_type,NULL , np, of_dev_node_match); + dev =bus_find_device (&platform_bus_type,NULL , np, of_device_match);return dev ?to_platform_device (dev) :NULL ; }EXPORT_SYMBOL (of_find_device_by_node);
Signature · 1 line
2.8.3
PATCH 8/22 spi: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the SPI-private variant.
--- drivers/spi/spi.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/spi/spi.c +1 -6
@@ -3019,16 +3019,11 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);/*-------------------------------------------------------------------------*/ #if IS_ENABLED (CONFIG_OF_DYNAMIC ) -static int __spi_of_device_match (struct device *dev,void *data) -{ -return dev->of_node == data; -} -/* must call put_device() when done with returned spi_device device */ static struct spi_device *of_find_spi_device_by_node (struct device_node *node) {struct device *dev =bus_find_device (&spi_bus_type,NULL , node, - __spi_of_device_match); + of_device_match);return dev ?to_spi_device (dev) :NULL ; }
Signature · 1 line
2.8.3
PATCH 9/22 of: mdio: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the MDIO-private variant.
--- drivers/of/of_mdio.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/of/of_mdio.c +2 -7
@@ -16,6 +16,7 @@#include <linux/phy.h> #include <linux/phy_fixed.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/of_gpio.h> #include <linux/of_irq.h> #include <linux/of_mdio.h>
@@ -265,12 +266,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) }EXPORT_SYMBOL (of_mdiobus_register); -/* Helper function for of_phy_find_device */ -static int of_phy_match (struct device *dev,void *phy_np) -{ -return dev->of_node == phy_np; -} -/** * of_phy_find_device - Give a PHY node, find the phy_device * @phy_np: Pointer to the phy's device tree node
@@ -286,7 +281,7 @@ struct phy_device *of_phy_find_device(struct device_node *phy_np)if (!phy_np)return NULL ; - d =bus_find_device (&mdio_bus_type,NULL , phy_np, of_phy_match); + d =bus_find_device (&mdio_bus_type,NULL , phy_np, of_device_match);if (d) { mdiodev =to_mdio_device (d);if (mdiodev->flags &MDIO_DEVICE_FLAG_PHY )
Signature · 1 line
2.8.3
PATCH 10/22 usb: phy: am335x-control: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This driver uses bus_find_device() to go through every platform device and match using the driver and device tree node. It's more efficient to use driver_find_device() to iterate over all devices associated with a particular driver, in which case the matching is reduced to the device tree node and can be done using the common implementation.
--- drivers/usb/phy/phy-am335x-control.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/usb/phy/phy-am335x-control.c +3 -7
@@ -2,6 +2,7 @@#include <linux/platform_device.h> #include <linux/err.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/io.h> #include <linux/delay.h> #include <linux/usb/otg.h>
@@ -117,12 +118,6 @@ static const struct of_device_id omap_control_usb_id_table[] = {MODULE_DEVICE_TABLE (of, omap_control_usb_id_table);static struct platform_driver am335x_control_driver; -static int match (struct device *dev,void *data) -{ -struct device_node *node = (struct device_node *)data; -return dev->of_node == node && - dev->driver == &am335x_control_driver.driver; -}struct phy_control *am335x_get_phy_control (struct device *dev) {
@@ -133,7 +128,8 @@ struct phy_control *am335x_get_phy_control(struct device *dev)if (!node)return NULL ; - dev =bus_find_device (&platform_bus_type,NULL , node, match); + dev =driver_find_device (&am335x_control_driver.driver,NULL , node, + of_device_match);if (!dev)return NULL ;
Signature · 6 lines
2.8.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 11/22 usb: phy: isp1301: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This driver uses bus_find_device() to go through every platform device and match using the driver and device tree node. It's more efficient to use driver_find_device() to iterate over all devices associated with a particular driver, in which case the matching is reduced to the device tree node and can be done using the common implementation.
--- drivers/usb/phy/phy-isp1301.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/usb/phy/phy-isp1301.c +4 -9
@@ -13,6 +13,7 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/i2c.h> +#include <linux/of_device.h> #include <linux/usb/phy.h> #include <linux/usb/isp1301.h>
@@ -138,18 +139,12 @@ static struct i2c_driver isp1301_driver = {module_i2c_driver (isp1301_driver); -static int match (struct device *dev,void *data) -{ -struct device_node *node = (struct device_node *)data; -return (dev->of_node == node) && - (dev->driver == &isp1301_driver.driver); -} -struct i2c_client *isp1301_get_client (struct device_node *node) {if (node) {/* reference of ISP1301 I2C node via DT */ -struct device *dev =bus_find_device (&i2c_bus_type,NULL , - node, match); +struct device *dev =driver_find_device (&isp1301_driver.driver, +NULL , node, + of_device_match);if (!dev)return NULL ;return to_i2c_client (dev);
Signature · 1 line
2.8.3
PATCH 12/22 drm/hdlcd: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/arm/hdlcd_drv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/arm/hdlcd_drv.c +2 -6
@@ -14,6 +14,7 @@#include <linux/clk.h> #include <linux/component.h> #include <linux/list.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <linux/of_reserved_mem.h> #include <linux/pm_runtime.h>
@@ -429,11 +430,6 @@ static const struct component_master_ops hdlcd_master_ops = { .unbind = hdlcd_drm_unbind, }; -static int compare_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static void release_of (struct device *dev,void *data) {of_node_put (data);
@@ -466,7 +462,7 @@ static int hdlcd_probe(struct platform_device *pdev) }component_match_add_release (&pdev->dev, &match, release_of, - compare_of, port); + of_device_match, port);return component_master_add_with_match (&pdev->dev, &hdlcd_master_ops, match);
Signature · 1 line
2.8.3
PATCH 13/22 drm/armada: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/armada/armada_drv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/armada/armada_drv.c +2 -6
@@ -8,6 +8,7 @@#include <linux/clk.h> #include <linux/component.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <drm/drmP.h> #include <drm/drm_crtc_helper.h>
@@ -227,11 +228,6 @@ static void armada_drm_unbind(struct device *dev)drm_put_dev (dev_get_drvdata (dev)); } -static int compare_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static void release_of (struct device *dev,void *data) {of_node_put (data);
@@ -261,7 +257,7 @@ static void armada_add_endpoints(struct device *dev, }component_match_add_release (dev, match, release_of, - compare_of, remote); + of_device_match, remote); } }
Signature · 6 lines
2.8.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 14/22 drm/etnaviv: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_drv.c +3 -9
@@ -15,6 +15,7 @@*/ #include <linux/component.h> +#include <linux/of_device.h> #include <linux/of_platform.h> #include "etnaviv_drv.h"
@@ -606,13 +607,6 @@ static const struct component_master_ops etnaviv_master_ops = { .unbind = etnaviv_unbind, }; -static int compare_of (struct device *dev,void *data) -{ -struct device_node *np = data; - -return dev->of_node == np; -} -static int compare_str (struct device *dev,void *data) {return !strcmp (dev_name (dev), data);
@@ -635,8 +629,8 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)if (!core_node)break ; -component_match_add (&pdev->dev, &match, compare_of, - core_node); +component_match_add (&pdev->dev, &match, + of_device_match, core_node);of_node_put (core_node); } }else if (dev->platform_data) {
Signature · 1 line
2.8.3
PATCH 15/22 drm/hisilicon: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +2 -6
@@ -15,6 +15,7 @@* */ +#include <linux/of_device.h> #include <linux/of_platform.h> #include <linux/component.h> #include <linux/of_graph.h>
@@ -196,11 +197,6 @@ static struct drm_driver kirin_drm_driver = { .minor = 0, }; -static int compare_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static int kirin_drm_bind (struct device *dev) {struct drm_driver *driver = &kirin_drm_driver;
@@ -303,7 +299,7 @@ static int kirin_drm_platform_probe(struct platform_device *pdev)if (IS_ERR (remote))return PTR_ERR (remote); -component_match_add (dev, &match, compare_of, remote); +component_match_add (dev, &match, of_device_match, remote);return component_master_add_with_match (dev, &kirin_drm_ops, match);
Signature · 1 line
2.8.3
PATCH 16/22 drm/mediatek: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +2 -6
@@ -21,6 +21,7 @@#include <linux/component.h> #include <linux/iommu.h> #include <linux/of_address.h> +#include <linux/of_device.h> #include <linux/of_platform.h> #include <linux/pm_runtime.h>
@@ -265,11 +266,6 @@ static struct drm_driver mtk_drm_driver = { .minor = DRIVER_MINOR, }; -static int compare_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static int mtk_drm_bind (struct device *dev) {struct mtk_drm_private *private =dev_get_drvdata (dev);
@@ -406,7 +402,7 @@ static int mtk_drm_probe(struct platform_device *pdev) comp_type == MTK_DPI) { dev_info(dev, "Adding component match for %s\n", node->full_name); - component_match_add(dev, &match, compare_of, node); + component_match_add(dev, &match, of_device_match, node); } else {struct mtk_ddp_comp *comp;
Signature · 1 line
2.8.3
PATCH 17/22 drm/msm: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/msm/msm_drv.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +3 -10
@@ -15,6 +15,8 @@* this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <linux/of_device.h> +#include "msm_drv.h" #include "msm_debugfs.h" #include "msm_fence.h"
@@ -796,15 +798,6 @@ static const struct dev_pm_ops msm_pm_ops = {* Componentized driver support: */ -/* -* NOTE: duplication of the same code as exynos or imx (or probably any other). -* so probably some room for some helpers -*/ -static int compare_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static void release_of (struct device *dev,void *data) {of_node_put (data);
@@ -824,7 +817,7 @@ static int add_components(struct device *dev, struct component_match **matchptr,break ;component_match_add_release (dev, matchptr, release_of, - compare_of, node); + of_device_match, node); }return 0 ;
Signature · 1 line
2.8.3
PATCH 18/22 drm/rockchip: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +3 -9
@@ -22,6 +22,7 @@#include <linux/dma-mapping.h> #include <linux/pm_runtime.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <linux/component.h>
@@ -414,13 +415,6 @@ static const struct dev_pm_ops rockchip_drm_pm_ops = { rockchip_drm_sys_resume) }; -static int compare_of (struct device *dev,void *data) -{ -struct device_node *np = data; - -return dev->of_node == np; -} -static void release_of (struct device *dev,void *data) {of_node_put (data);
@@ -445,7 +439,7 @@ static void rockchip_add_endpoints(struct device *dev, }component_match_add_release (dev, match, release_of, - compare_of, remote); + of_device_match, remote); } }
@@ -525,7 +519,7 @@ static int rockchip_drm_platform_probe(struct platform_device *pdev)of_node_get (port->parent);component_match_add_release (dev, &match, release_of, - compare_of, port->parent); + of_device_match, port->parent);of_node_put (port); }
Signature · 1 line
2.8.3
PATCH 19/22 drm/sti: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation rather than the driver-private variant.
--- drivers/gpu/drm/sti/sti_drv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/sti/sti_drv.c +2 -6
@@ -10,6 +10,7 @@#include <linux/debugfs.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/of_platform.h> #include <drm/drm_atomic.h>
@@ -341,11 +342,6 @@ static struct drm_driver sti_driver = { .minor = DRIVER_MINOR, }; -static int compare_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static void release_of (struct device *dev,void *data) {of_node_put (data);
@@ -381,7 +377,7 @@ static int sti_platform_probe(struct platform_device *pdev)while (child_np) {component_match_add_release (dev, &match, release_of, - compare_of, child_np); + of_device_match, child_np); child_np =of_get_next_available_child (node, child_np); }
Signature · 1 line
2.8.3
PATCH 20/22 drm/sun4i: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation instead of the driver-private variant.
--- drivers/gpu/drm/sun4i/sun4i_drv.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/gpu/drm/sun4i/sun4i_drv.c +2 -10
@@ -11,6 +11,7 @@*/ #include <linux/component.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include <drm/drmP.h>
@@ -219,15 +220,6 @@ static bool sun4i_drv_node_is_tcon(struct device_node *node)return of_device_is_compatible (node,"allwinner,sun5i-a13-tcon" ); } -static int compare_of (struct device *dev,void *data) -{ -DRM_DEBUG_DRIVER ("Comparing of node %s with %s\n" , -of_node_full_name (dev->of_node), -of_node_full_name (data)); - -return dev->of_node == data; -} -static int sun4i_drv_add_endpoints (struct device *dev,struct component_match **match,struct device_node *node)
@@ -248,7 +240,7 @@ static int sun4i_drv_add_endpoints(struct device *dev,/* Add current component */ DRM_DEBUG_DRIVER ("Adding component %s\n" ,of_node_full_name (node)); -component_match_add (dev, match, compare_of, node); +component_match_add (dev, match, of_device_match, node); count++; }
Signature · 1 line
2.8.3
PATCH 21/22 drm/tilcdc: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation instead of the driver-private variant.
--- drivers/gpu/drm/tilcdc/tilcdc_external.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_external.c +2 -6
@@ -9,6 +9,7 @@*/ #include <linux/component.h> +#include <linux/of_device.h> #include <linux/of_graph.h> #include "tilcdc_drv.h"
@@ -130,11 +131,6 @@ void tilcdc_remove_external_encoders(struct drm_device *dev) priv->connector_funcs[i]); } -static int dev_match_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static void dev_release_of (struct device *dev,void *data) {of_node_put (data);
@@ -158,7 +154,7 @@ int tilcdc_get_external_components(struct device *dev,dev_dbg (dev,"Subdevice node '%s' found\n" , node->name);if (match)component_match_add_release (dev, match, dev_release_of, - dev_match_of, node); + of_device_match, node); count++; }
Signature · 1 line
2.8.3
PATCH 22/22 iommu/mediatek: Use of_device_match()
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Use the common implementation instead of the driver-private variant.
--- drivers/iommu/mtk_iommu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/iommu/mtk_iommu.c +2 -6
@@ -24,6 +24,7 @@#include <linux/iopoll.h> #include <linux/list.h> #include <linux/of_address.h> +#include <linux/of_device.h> #include <linux/of_iommu.h> #include <linux/of_irq.h> #include <linux/of_platform.h>
@@ -552,11 +553,6 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)return 0 ; } -static int compare_of (struct device *dev,void *data) -{ -return dev->of_node == data; -} -static void release_of (struct device *dev,void *data) {of_node_put (data);
@@ -647,7 +643,7 @@ static int mtk_iommu_probe(struct platform_device *pdev) data->smi_imu.larb_imu[i].dev = &plarbdev->dev;component_match_add_release (dev, &match, release_of, - compare_of, larbnode); + of_device_match, larbnode); }platform_set_drvdata (pdev, data);
Signature · 1 line
2.8.3
Quoted 22 lines · Thierry Reding
From: Thierry Reding <[email protected]>
This series of patches introduces a common implementation of a function that can be used in iterators (such as the
bus_for_each_dev()or thedriver_for_each_device()functions) and that compare's a device's device tree node with the passed in data. Numerous drivers and subsystems have their own variant of this function, so a lot of duplication can be removed by making use of the common implementation.One thing that slightly bugs me about this is that it can't be used with users of
class_for_each_device()orclass_find_device()because they get passed a callback that takes a const void * rather than a void * for the device tree node. I had at some point investigated to turn the remainder of the iterators into taking const void *, but there are some drivers in the kernel that want to modify the data passed to them, so it isn't easy to switch.An alternative would be to turn the const void * into void * for all the callbacks of this sort, so that we can use a single set throughout the tree, but I'm not sure how welcome that would be. I can give that a shot if people think it worth, though.
Quoted 5 lines
Greg, any thoughts on this?
I've also kept the list of recipients very short, to get early feedback and buy-in from Rob and Frank on the common implementation. I expect the naming to allow for some good bike-shedding.
Common implementation looks fine to me.
My shot at bike-shedding is to make the function name reflect the argument names of bus_find_device() and driver_find_device(). That would suggest of_node_match_data(). Or if one wanted to be more concise, of_node_match() or of_match_node().
But of_match_node() is already in wide use (for something else entirely).
And drivers/regulator/core.c is the one existing version of of_node_match():
static int of_node_match(struct device *dev, const void *data)
{
return dev->of_node == data;
}This is an example of the 'const void *data' vs 'void *data' that you mentioned, because this of_node_match() is used for class_find_device(). of_node_match() could be used since only one current usage of the name would have to be changed to some other name.
So that brings me back to of_node_match_data() being my preference because of_node_match() is entirely too similar to of_match_node(), which seems like it would lead to confusion when I am reading code. Then maybe a variant on that name with a 'const void *data' argument. Like the longer than I would like of_node_match_const_data().
< snip >
-Frank
Re: [PATCH 02/22] amba: tegra-ahb: Use of_device_match()
In reply to Thierry RedingQuoted 37 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Use the common implementation rather than the open-coded variant.
Signed-off-by Thierry Reding <[email protected]>--- drivers/amba/tegra-ahb.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)drivers/amba/tegra-ahb.c +1
-8@@ -26,6 +26,7 @@#include <linux/platform_device.h> #include <linux/io.h> #include <linux/of.h> +#include <linux/of_device.h> #include <soc/tegra/ahb.h> @@ -143,14 +144,6 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset) }#ifdef CONFIG_TEGRA_IOMMU_SMMU -static int tegra_ahb_match_by_smmu (struct device *dev,void *data) -{ -struct tegra_ahb *ahb =dev_get_drvdata (dev); -struct device_node *dn = data; - -return (ahb->dev->of_node == dn) ?1 :0 ; -} -int tegra_ahb_enable_smmu (struct device_node *dn) {struct device *dev;
drivers/amba/tegra-ahb.c int tegra_ahb_enable_smmu(struct device_node *dn) · line 153
Quoted 3 lines
drivers/amba/tegra-ahb.c +0
-0@@ -158,7 +151,7 @@ int tegra_ahb_enable_smmu(struct device_node *dn)struct tegra_ahb *ahb; dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
To use of_device_match, should that be something like:
struct tegra_ahb *ahb = dev_get_drvdata(dev);
dev = driver_find_device(&tegra_ahb_driver.driver, NULL, ahb->dev,Quoted 6 lines
drivers/amba/tegra-ahb.c +1
-1- tegra_ahb_match_by_smmu); + of_device_match);if (!dev)return -EPROBE_DEFER ; ahb =dev_get_drvdata (dev);