Skip to content

Commit cfba5de

Browse files
Suzuki K Poulosegregkh
authored andcommitted
drivers: Introduce device lookup variants by of_node
Introduce wrappers for {bus/driver/class}_find_device() to locate devices by its of_node. Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Cc: Maxime Ripard <maxime.ripard@bootlin.com> Cc: dri-devel@lists.freedesktop.org Cc: David Airlie <airlied@linux.ie> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: devicetree@vger.kernel.org Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Frank Rowand <frowand.list@gmail.com> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Liam Girdwood <lgirdwood@gmail.com> Cc: linux-i2c@vger.kernel.org Cc: linux-rockchip@lists.infradead.org Cc: linux-spi@vger.kernel.org Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Rob Herring <robh+dt@kernel.org> Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Cc: Takashi Iwai <tiwai@suse.com> Cc: Alan Tull <atull@kernel.org> Cc: linux-fpga@vger.kernel.org Cc: Peter Rosin <peda@axentia.se> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Heiner Kallweit <hkallweit1@gmail.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Liam Girdwood <lgirdwood@gmail.com> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Thor Thayer <thor.thayer@linux.intel.com> Cc: Jiri Slaby <jslaby@suse.com> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Peter Rosin <peda@axentia.se> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Acked-by: Lee Jones <lee.jones@linaro.org> Acked-by: Wolfram Sang <wsa@the-dreams.de> # I2C part Acked-by: Moritz Fischer <mdf@kernel.org> # For FPGA part Acked-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20190723221838.12024-3-suzuki.poulose@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6cda08a commit cfba5de

15 files changed

Lines changed: 56 additions & 110 deletions

File tree

‎drivers/amba/tegra-ahb.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
134134
}
135135

136136
#ifdef CONFIG_TEGRA_IOMMU_SMMU
137-
static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
138-
{
139-
struct tegra_ahb *ahb = dev_get_drvdata(dev);
140-
const struct device_node *dn = data;
141-
142-
return (ahb->dev->of_node == dn) ? 1 : 0;
143-
}
144-
145137
int tegra_ahb_enable_smmu(struct device_node *dn)
146138
{
147139
struct device *dev;
148140
u32 val;
149141
struct tegra_ahb *ahb;
150142

151-
dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
152-
tegra_ahb_match_by_smmu);
143+
dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
153144
if (!dev)
154145
return -EPROBE_DEFER;
155146
ahb = dev_get_drvdata(dev);

‎drivers/fpga/fpga-bridge.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
1919
/* Lock for adding/removing bridges to linked lists*/
2020
static spinlock_t bridge_list_lock;
2121

22-
static int fpga_bridge_of_node_match(struct device *dev, const void *data)
23-
{
24-
return dev->of_node == data;
25-
}
26-
2722
/**
2823
* fpga_bridge_enable - Enable transactions on the bridge
2924
*
@@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
10499
{
105100
struct device *dev;
106101

107-
dev = class_find_device(fpga_bridge_class, NULL, np,
108-
fpga_bridge_of_node_match);
102+
dev = class_find_device_by_of_node(fpga_bridge_class, np);
109103
if (!dev)
110104
return ERR_PTR(-ENODEV);
111105

‎drivers/fpga/fpga-mgr.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
482482
}
483483
EXPORT_SYMBOL_GPL(fpga_mgr_get);
484484

485-
static int fpga_mgr_of_node_match(struct device *dev, const void *data)
486-
{
487-
return dev->of_node == data;
488-
}
489-
490485
/**
491486
* of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
492487
*
@@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
498493
{
499494
struct device *dev;
500495

501-
dev = class_find_device(fpga_mgr_class, NULL, node,
502-
fpga_mgr_of_node_match);
496+
dev = class_find_device_by_of_node(fpga_mgr_class, node);
503497
if (!dev)
504498
return ERR_PTR(-ENODEV);
505499

‎drivers/gpu/drm/drm_mipi_dsi.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
9393
.pm = &mipi_dsi_device_pm_ops,
9494
};
9595

96-
static int of_device_match(struct device *dev, const void *data)
97-
{
98-
return dev->of_node == data;
99-
}
100-
10196
/**
10297
* of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
10398
* device tree node
@@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
110105
{
111106
struct device *dev;
112107

113-
dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
108+
dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
114109

115110
return dev ? to_mipi_dsi_device(dev) : NULL;
116111
}

‎drivers/i2c/i2c-core-of.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
113113
of_node_put(bus);
114114
}
115115

116-
static int of_dev_node_match(struct device *dev, const void *data)
117-
{
118-
return dev->of_node == data;
119-
}
120-
121116
static int of_dev_or_parent_node_match(struct device *dev, const void *data)
122117
{
123118
if (dev->of_node == data)
@@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
135130
struct device *dev;
136131
struct i2c_client *client;
137132

138-
dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
133+
dev = bus_find_device_by_of_node(&i2c_bus_type, node);
139134
if (!dev)
140135
return NULL;
141136

‎drivers/mfd/altera-sysmgr.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = {
8787
.use_single_write = true,
8888
};
8989

90-
/**
91-
* sysmgr_match_phandle
92-
* Matching function used by driver_find_device().
93-
* Return: True if match is found, otherwise false.
94-
*/
95-
static int sysmgr_match_phandle(struct device *dev, const void *data)
96-
{
97-
return dev->of_node == (const struct device_node *)data;
98-
}
99-
10090
/**
10191
* altr_sysmgr_regmap_lookup_by_phandle
10292
* Find the sysmgr previous configured in probe() and return regmap property.
@@ -117,8 +107,8 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np,
117107
if (!sysmgr_np)
118108
return ERR_PTR(-ENODEV);
119109

120-
dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
121-
(void *)sysmgr_np, sysmgr_match_phandle);
110+
dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
111+
(void *)sysmgr_np);
122112
of_node_put(sysmgr_np);
123113
if (!dev)
124114
return ERR_PTR(-EPROBE_DEFER);

‎drivers/mux/core.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux)
405405
}
406406
EXPORT_SYMBOL_GPL(mux_control_deselect);
407407

408-
static int of_dev_node_match(struct device *dev, const void *data)
409-
{
410-
return dev->of_node == data;
411-
}
412-
413408
/* Note this function returns a reference to the mux_chip dev. */
414409
static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
415410
{
416411
struct device *dev;
417412

418-
dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
413+
dev = class_find_device_by_of_node(&mux_class, np);
419414

420415
return dev ? to_mux_chip(dev) : NULL;
421416
}

‎drivers/net/phy/mdio_bus.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,6 @@ static struct class mdio_bus_class = {
262262
};
263263

264264
#if IS_ENABLED(CONFIG_OF_MDIO)
265-
/* Helper function for of_mdio_find_bus */
266-
static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
267-
{
268-
return dev->of_node == mdio_bus_np;
269-
}
270265
/**
271266
* of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
272267
* @mdio_bus_np: Pointer to the mii_bus.
@@ -287,9 +282,7 @@ struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
287282
if (!mdio_bus_np)
288283
return NULL;
289284

290-
d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np,
291-
of_mdio_bus_match);
292-
285+
d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
293286
return d ? to_mii_bus(d) : NULL;
294287
}
295288
EXPORT_SYMBOL(of_mdio_find_bus);

‎drivers/nvmem/core.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,14 @@ static struct bus_type nvmem_bus_type = {
7676
.name = "nvmem",
7777
};
7878

79-
static int of_nvmem_match(struct device *dev, const void *nvmem_np)
80-
{
81-
return dev->of_node == nvmem_np;
82-
}
83-
8479
static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
8580
{
8681
struct device *d;
8782

8883
if (!nvmem_np)
8984
return NULL;
9085

91-
d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
86+
d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
9287

9388
if (!d)
9489
return NULL;

‎drivers/of/of_mdio.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
280280
}
281281
EXPORT_SYMBOL(of_mdiobus_register);
282282

283-
/* Helper function for of_phy_find_device */
284-
static int of_phy_match(struct device *dev, const void *phy_np)
285-
{
286-
return dev->of_node == phy_np;
287-
}
288-
289283
/**
290284
* of_phy_find_device - Give a PHY node, find the phy_device
291285
* @phy_np: Pointer to the phy's device tree node
@@ -301,7 +295,7 @@ struct phy_device *of_phy_find_device(struct device_node *phy_np)
301295
if (!phy_np)
302296
return NULL;
303297

304-
d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
298+
d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
305299
if (d) {
306300
mdiodev = to_mdio_device(d);
307301
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)

0 commit comments

Comments
 (0)