diff options
author | Suzuki K Poulose <suzuki.poulose@arm.com> | 2019-07-23 18:18:33 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-30 07:07:41 -0400 |
commit | cfba5de9b99f8bbb8b4ea11b3049784e78b8759b (patch) | |
tree | 1c9f123ae5f350f61efa4d6c5730bba20601b74a | |
parent | 6cda08a20dbde45b021091230c8a359fa08c5103 (diff) |
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>
-rw-r--r-- | drivers/amba/tegra-ahb.c | 11 | ||||
-rw-r--r-- | drivers/fpga/fpga-bridge.c | 8 | ||||
-rw-r--r-- | drivers/fpga/fpga-mgr.c | 8 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_mipi_dsi.c | 7 | ||||
-rw-r--r-- | drivers/i2c/i2c-core-of.c | 7 | ||||
-rw-r--r-- | drivers/mfd/altera-sysmgr.c | 14 | ||||
-rw-r--r-- | drivers/mux/core.c | 7 | ||||
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 9 | ||||
-rw-r--r-- | drivers/nvmem/core.c | 7 | ||||
-rw-r--r-- | drivers/of/of_mdio.c | 8 | ||||
-rw-r--r-- | drivers/of/platform.c | 7 | ||||
-rw-r--r-- | drivers/regulator/of_regulator.c | 7 | ||||
-rw-r--r-- | drivers/spi/spi.c | 20 | ||||
-rw-r--r-- | include/linux/device.h | 37 | ||||
-rw-r--r-- | sound/soc/rockchip/rk3399_gru_sound.c | 9 |
15 files changed, 56 insertions, 110 deletions
diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c index aa64eece77a6..57d3b2e2d007 100644 --- a/drivers/amba/tegra-ahb.c +++ b/drivers/amba/tegra-ahb.c | |||
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset) | |||
134 | } | 134 | } |
135 | 135 | ||
136 | #ifdef CONFIG_TEGRA_IOMMU_SMMU | 136 | #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 | |||
145 | int tegra_ahb_enable_smmu(struct device_node *dn) | 137 | int tegra_ahb_enable_smmu(struct device_node *dn) |
146 | { | 138 | { |
147 | struct device *dev; | 139 | struct device *dev; |
148 | u32 val; | 140 | u32 val; |
149 | struct tegra_ahb *ahb; | 141 | struct tegra_ahb *ahb; |
150 | 142 | ||
151 | dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn, | 143 | dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn); |
152 | tegra_ahb_match_by_smmu); | ||
153 | if (!dev) | 144 | if (!dev) |
154 | return -EPROBE_DEFER; | 145 | return -EPROBE_DEFER; |
155 | ahb = dev_get_drvdata(dev); | 146 | ahb = dev_get_drvdata(dev); |
diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c index 80bd8f1b2aa6..4bab9028940a 100644 --- a/drivers/fpga/fpga-bridge.c +++ b/drivers/fpga/fpga-bridge.c | |||
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class; | |||
19 | /* Lock for adding/removing bridges to linked lists*/ | 19 | /* Lock for adding/removing bridges to linked lists*/ |
20 | static spinlock_t bridge_list_lock; | 20 | static spinlock_t bridge_list_lock; |
21 | 21 | ||
22 | static int fpga_bridge_of_node_match(struct device *dev, const void *data) | ||
23 | { | ||
24 | return dev->of_node == data; | ||
25 | } | ||
26 | |||
27 | /** | 22 | /** |
28 | * fpga_bridge_enable - Enable transactions on the bridge | 23 | * fpga_bridge_enable - Enable transactions on the bridge |
29 | * | 24 | * |
@@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np, | |||
104 | { | 99 | { |
105 | struct device *dev; | 100 | struct device *dev; |
106 | 101 | ||
107 | dev = class_find_device(fpga_bridge_class, NULL, np, | 102 | dev = class_find_device_by_of_node(fpga_bridge_class, np); |
108 | fpga_bridge_of_node_match); | ||
109 | if (!dev) | 103 | if (!dev) |
110 | return ERR_PTR(-ENODEV); | 104 | return ERR_PTR(-ENODEV); |
111 | 105 | ||
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index c3866816456a..e05104f5e40c 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c | |||
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev) | |||
482 | } | 482 | } |
483 | EXPORT_SYMBOL_GPL(fpga_mgr_get); | 483 | EXPORT_SYMBOL_GPL(fpga_mgr_get); |
484 | 484 | ||
485 | static int fpga_mgr_of_node_match(struct device *dev, const void *data) | ||
486 | { | ||
487 | return dev->of_node == data; | ||
488 | } | ||
489 | |||
490 | /** | 485 | /** |
491 | * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr. | 486 | * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr. |
492 | * | 487 | * |
@@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node) | |||
498 | { | 493 | { |
499 | struct device *dev; | 494 | struct device *dev; |
500 | 495 | ||
501 | dev = class_find_device(fpga_mgr_class, NULL, node, | 496 | dev = class_find_device_by_of_node(fpga_mgr_class, node); |
502 | fpga_mgr_of_node_match); | ||
503 | if (!dev) | 497 | if (!dev) |
504 | return ERR_PTR(-ENODEV); | 498 | return ERR_PTR(-ENODEV); |
505 | 499 | ||
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index ad19df0686c9..bd2498bbd74a 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c | |||
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = { | |||
93 | .pm = &mipi_dsi_device_pm_ops, | 93 | .pm = &mipi_dsi_device_pm_ops, |
94 | }; | 94 | }; |
95 | 95 | ||
96 | static int of_device_match(struct device *dev, const void *data) | ||
97 | { | ||
98 | return dev->of_node == data; | ||
99 | } | ||
100 | |||
101 | /** | 96 | /** |
102 | * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a | 97 | * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a |
103 | * device tree node | 98 | * device tree node |
@@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np) | |||
110 | { | 105 | { |
111 | struct device *dev; | 106 | struct device *dev; |
112 | 107 | ||
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); |
114 | 109 | ||
115 | return dev ? to_mipi_dsi_device(dev) : NULL; | 110 | return dev ? to_mipi_dsi_device(dev) : NULL; |
116 | } | 111 | } |
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index d1c48dec7118..6f632d543fcc 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c | |||
@@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap) | |||
113 | of_node_put(bus); | 113 | of_node_put(bus); |
114 | } | 114 | } |
115 | 115 | ||
116 | static int of_dev_node_match(struct device *dev, const void *data) | ||
117 | { | ||
118 | return dev->of_node == data; | ||
119 | } | ||
120 | |||
121 | static int of_dev_or_parent_node_match(struct device *dev, const void *data) | 116 | static int of_dev_or_parent_node_match(struct device *dev, const void *data) |
122 | { | 117 | { |
123 | if (dev->of_node == data) | 118 | if (dev->of_node == data) |
@@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) | |||
135 | struct device *dev; | 130 | struct device *dev; |
136 | struct i2c_client *client; | 131 | struct i2c_client *client; |
137 | 132 | ||
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); |
139 | if (!dev) | 134 | if (!dev) |
140 | return NULL; | 135 | return NULL; |
141 | 136 | ||
diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c index 2ee14d8a6d31..d2a13a547a3c 100644 --- a/drivers/mfd/altera-sysmgr.c +++ b/drivers/mfd/altera-sysmgr.c | |||
@@ -88,16 +88,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = { | |||
88 | }; | 88 | }; |
89 | 89 | ||
90 | /** | 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 | |||
100 | /** | ||
101 | * altr_sysmgr_regmap_lookup_by_phandle | 91 | * altr_sysmgr_regmap_lookup_by_phandle |
102 | * Find the sysmgr previous configured in probe() and return regmap property. | 92 | * Find the sysmgr previous configured in probe() and return regmap property. |
103 | * Return: regmap if found or error if not found. | 93 | * Return: regmap if found or error if not found. |
@@ -117,8 +107,8 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np, | |||
117 | if (!sysmgr_np) | 107 | if (!sysmgr_np) |
118 | return ERR_PTR(-ENODEV); | 108 | return ERR_PTR(-ENODEV); |
119 | 109 | ||
120 | dev = driver_find_device(&altr_sysmgr_driver.driver, NULL, | 110 | dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver, |
121 | (void *)sysmgr_np, sysmgr_match_phandle); | 111 | (void *)sysmgr_np); |
122 | of_node_put(sysmgr_np); | 112 | of_node_put(sysmgr_np); |
123 | if (!dev) | 113 | if (!dev) |
124 | return ERR_PTR(-EPROBE_DEFER); | 114 | return ERR_PTR(-EPROBE_DEFER); |
diff --git a/drivers/mux/core.c b/drivers/mux/core.c index d1271c1ee23c..1fb22388e7e0 100644 --- a/drivers/mux/core.c +++ b/drivers/mux/core.c | |||
@@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux) | |||
405 | } | 405 | } |
406 | EXPORT_SYMBOL_GPL(mux_control_deselect); | 406 | EXPORT_SYMBOL_GPL(mux_control_deselect); |
407 | 407 | ||
408 | static int of_dev_node_match(struct device *dev, const void *data) | ||
409 | { | ||
410 | return dev->of_node == data; | ||
411 | } | ||
412 | |||
413 | /* Note this function returns a reference to the mux_chip dev. */ | 408 | /* Note this function returns a reference to the mux_chip dev. */ |
414 | static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) | 409 | static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) |
415 | { | 410 | { |
416 | struct device *dev; | 411 | struct device *dev; |
417 | 412 | ||
418 | dev = class_find_device(&mux_class, NULL, np, of_dev_node_match); | 413 | dev = class_find_device_by_of_node(&mux_class, np); |
419 | 414 | ||
420 | return dev ? to_mux_chip(dev) : NULL; | 415 | return dev ? to_mux_chip(dev) : NULL; |
421 | } | 416 | } |
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index bd04fe762056..ce940871331e 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -262,11 +262,6 @@ static struct class mdio_bus_class = { | |||
262 | }; | 262 | }; |
263 | 263 | ||
264 | #if IS_ENABLED(CONFIG_OF_MDIO) | 264 | #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 | } | ||
270 | /** | 265 | /** |
271 | * of_mdio_find_bus - Given an mii_bus node, find the mii_bus. | 266 | * of_mdio_find_bus - Given an mii_bus node, find the mii_bus. |
272 | * @mdio_bus_np: Pointer to the mii_bus. | 267 | * @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) | |||
287 | if (!mdio_bus_np) | 282 | if (!mdio_bus_np) |
288 | return NULL; | 283 | return NULL; |
289 | 284 | ||
290 | d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np, | 285 | d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np); |
291 | of_mdio_bus_match); | ||
292 | |||
293 | return d ? to_mii_bus(d) : NULL; | 286 | return d ? to_mii_bus(d) : NULL; |
294 | } | 287 | } |
295 | EXPORT_SYMBOL(of_mdio_find_bus); | 288 | EXPORT_SYMBOL(of_mdio_find_bus); |
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index ac5d945be88a..057d1ff87d5d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c | |||
@@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = { | |||
76 | .name = "nvmem", | 76 | .name = "nvmem", |
77 | }; | 77 | }; |
78 | 78 | ||
79 | static int of_nvmem_match(struct device *dev, const void *nvmem_np) | ||
80 | { | ||
81 | return dev->of_node == nvmem_np; | ||
82 | } | ||
83 | |||
84 | static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) | 79 | static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) |
85 | { | 80 | { |
86 | struct device *d; | 81 | struct device *d; |
@@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) | |||
88 | if (!nvmem_np) | 83 | if (!nvmem_np) |
89 | return NULL; | 84 | return NULL; |
90 | 85 | ||
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); |
92 | 87 | ||
93 | if (!d) | 88 | if (!d) |
94 | return NULL; | 89 | return NULL; |
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 44f53496cab1..000b95787df1 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c | |||
@@ -280,12 +280,6 @@ unregister: | |||
280 | } | 280 | } |
281 | EXPORT_SYMBOL(of_mdiobus_register); | 281 | EXPORT_SYMBOL(of_mdiobus_register); |
282 | 282 | ||
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 | |||
289 | /** | 283 | /** |
290 | * of_phy_find_device - Give a PHY node, find the phy_device | 284 | * of_phy_find_device - Give a PHY node, find the phy_device |
291 | * @phy_np: Pointer to the phy's device tree node | 285 | * @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) | |||
301 | if (!phy_np) | 295 | if (!phy_np) |
302 | return NULL; | 296 | return NULL; |
303 | 297 | ||
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); |
305 | if (d) { | 299 | if (d) { |
306 | mdiodev = to_mdio_device(d); | 300 | mdiodev = to_mdio_device(d); |
307 | if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) | 301 | if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) |
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 7801e25e6895..b47a2292fe8e 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c | |||
@@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = { | |||
37 | {} /* Empty terminated list */ | 37 | {} /* Empty terminated list */ |
38 | }; | 38 | }; |
39 | 39 | ||
40 | static int of_dev_node_match(struct device *dev, const void *data) | ||
41 | { | ||
42 | return dev->of_node == data; | ||
43 | } | ||
44 | |||
45 | /** | 40 | /** |
46 | * of_find_device_by_node - Find the platform_device associated with a node | 41 | * of_find_device_by_node - Find the platform_device associated with a node |
47 | * @np: Pointer to device tree node | 42 | * @np: Pointer to device tree node |
@@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np) | |||
55 | { | 50 | { |
56 | struct device *dev; | 51 | struct device *dev; |
57 | 52 | ||
58 | dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match); | 53 | dev = bus_find_device_by_of_node(&platform_bus_type, np); |
59 | return dev ? to_platform_device(dev) : NULL; | 54 | return dev ? to_platform_device(dev) : NULL; |
60 | } | 55 | } |
61 | EXPORT_SYMBOL(of_find_device_by_node); | 56 | EXPORT_SYMBOL(of_find_device_by_node); |
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 397918ebba55..20dcc9c03adc 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c | |||
@@ -460,16 +460,11 @@ error: | |||
460 | return NULL; | 460 | return NULL; |
461 | } | 461 | } |
462 | 462 | ||
463 | static int of_node_match(struct device *dev, const void *data) | ||
464 | { | ||
465 | return dev->of_node == data; | ||
466 | } | ||
467 | |||
468 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np) | 463 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np) |
469 | { | 464 | { |
470 | struct device *dev; | 465 | struct device *dev; |
471 | 466 | ||
472 | dev = class_find_device(®ulator_class, NULL, np, of_node_match); | 467 | dev = class_find_device_by_of_node(®ulator_class, np); |
473 | 468 | ||
474 | return dev ? dev_to_rdev(dev) : NULL; | 469 | return dev ? dev_to_rdev(dev) : NULL; |
475 | } | 470 | } |
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 75ac046cae52..a591da87981a 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read); | |||
3652 | /*-------------------------------------------------------------------------*/ | 3652 | /*-------------------------------------------------------------------------*/ |
3653 | 3653 | ||
3654 | #if IS_ENABLED(CONFIG_OF) | 3654 | #if IS_ENABLED(CONFIG_OF) |
3655 | static int __spi_of_device_match(struct device *dev, const void *data) | ||
3656 | { | ||
3657 | return dev->of_node == data; | ||
3658 | } | ||
3659 | |||
3660 | /* must call put_device() when done with returned spi_device device */ | 3655 | /* must call put_device() when done with returned spi_device device */ |
3661 | struct spi_device *of_find_spi_device_by_node(struct device_node *node) | 3656 | struct spi_device *of_find_spi_device_by_node(struct device_node *node) |
3662 | { | 3657 | { |
3663 | struct device *dev = bus_find_device(&spi_bus_type, NULL, node, | 3658 | struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node); |
3664 | __spi_of_device_match); | 3659 | |
3665 | return dev ? to_spi_device(dev) : NULL; | 3660 | return dev ? to_spi_device(dev) : NULL; |
3666 | } | 3661 | } |
3667 | EXPORT_SYMBOL_GPL(of_find_spi_device_by_node); | 3662 | EXPORT_SYMBOL_GPL(of_find_spi_device_by_node); |
3668 | #endif /* IS_ENABLED(CONFIG_OF) */ | 3663 | #endif /* IS_ENABLED(CONFIG_OF) */ |
3669 | 3664 | ||
3670 | #if IS_ENABLED(CONFIG_OF_DYNAMIC) | 3665 | #if IS_ENABLED(CONFIG_OF_DYNAMIC) |
3671 | static int __spi_of_controller_match(struct device *dev, const void *data) | ||
3672 | { | ||
3673 | return dev->of_node == data; | ||
3674 | } | ||
3675 | |||
3676 | /* the spi controllers are not using spi_bus, so we find it with another way */ | 3666 | /* the spi controllers are not using spi_bus, so we find it with another way */ |
3677 | static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) | 3667 | static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) |
3678 | { | 3668 | { |
3679 | struct device *dev; | 3669 | struct device *dev; |
3680 | 3670 | ||
3681 | dev = class_find_device(&spi_master_class, NULL, node, | 3671 | dev = class_find_device_by_of_node(&spi_master_class, node); |
3682 | __spi_of_controller_match); | ||
3683 | if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) | 3672 | if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) |
3684 | dev = class_find_device(&spi_slave_class, NULL, node, | 3673 | dev = class_find_device_by_of_node(&spi_slave_class, node); |
3685 | __spi_of_controller_match); | ||
3686 | if (!dev) | 3674 | if (!dev) |
3687 | return NULL; | 3675 | return NULL; |
3688 | 3676 | ||
diff --git a/include/linux/device.h b/include/linux/device.h index 3ba376b8b456..29d8d7ad41e6 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -186,6 +186,18 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus, | |||
186 | return bus_find_device(bus, start, name, device_match_name); | 186 | return bus_find_device(bus, start, name, device_match_name); |
187 | } | 187 | } |
188 | 188 | ||
189 | /** | ||
190 | * bus_find_device_by_of_node : device iterator for locating a particular device | ||
191 | * matching the of_node. | ||
192 | * @bus: bus type | ||
193 | * @np: of_node of the device to match. | ||
194 | */ | ||
195 | static inline struct device * | ||
196 | bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) | ||
197 | { | ||
198 | return bus_find_device(bus, NULL, np, device_match_of_node); | ||
199 | } | ||
200 | |||
189 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, | 201 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
190 | struct device *hint); | 202 | struct device *hint); |
191 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, | 203 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
@@ -366,6 +378,19 @@ static inline struct device *driver_find_device_by_name(struct device_driver *dr | |||
366 | return driver_find_device(drv, NULL, name, device_match_name); | 378 | return driver_find_device(drv, NULL, name, device_match_name); |
367 | } | 379 | } |
368 | 380 | ||
381 | /** | ||
382 | * driver_find_device_by_of_node- device iterator for locating a particular device | ||
383 | * by of_node pointer. | ||
384 | * @driver: the driver we're iterating | ||
385 | * @np: of_node pointer to match. | ||
386 | */ | ||
387 | static inline struct device * | ||
388 | driver_find_device_by_of_node(struct device_driver *drv, | ||
389 | const struct device_node *np) | ||
390 | { | ||
391 | return driver_find_device(drv, NULL, np, device_match_of_node); | ||
392 | } | ||
393 | |||
369 | void driver_deferred_probe_add(struct device *dev); | 394 | void driver_deferred_probe_add(struct device *dev); |
370 | int driver_deferred_probe_check_state(struct device *dev); | 395 | int driver_deferred_probe_check_state(struct device *dev); |
371 | int driver_deferred_probe_check_state_continue(struct device *dev); | 396 | int driver_deferred_probe_check_state_continue(struct device *dev); |
@@ -507,6 +532,18 @@ static inline struct device *class_find_device_by_name(struct class *class, | |||
507 | return class_find_device(class, NULL, name, device_match_name); | 532 | return class_find_device(class, NULL, name, device_match_name); |
508 | } | 533 | } |
509 | 534 | ||
535 | /** | ||
536 | * class_find_device_by_of_node : device iterator for locating a particular device | ||
537 | * matching the of_node. | ||
538 | * @class: class type | ||
539 | * @np: of_node of the device to match. | ||
540 | */ | ||
541 | static inline struct device * | ||
542 | class_find_device_by_of_node(struct class *class, const struct device_node *np) | ||
543 | { | ||
544 | return class_find_device(class, NULL, np, device_match_of_node); | ||
545 | } | ||
546 | |||
510 | struct class_attribute { | 547 | struct class_attribute { |
511 | struct attribute attr; | 548 | struct attribute attr; |
512 | ssize_t (*show)(struct class *class, struct class_attribute *attr, | 549 | ssize_t (*show)(struct class *class, struct class_attribute *attr, |
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c index c16b0ffe8cfc..d951100bf770 100644 --- a/sound/soc/rockchip/rk3399_gru_sound.c +++ b/sound/soc/rockchip/rk3399_gru_sound.c | |||
@@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = { | |||
422 | }, | 422 | }, |
423 | }; | 423 | }; |
424 | 424 | ||
425 | static int of_dev_node_match(struct device *dev, const void *data) | ||
426 | { | ||
427 | return dev->of_node == data; | ||
428 | } | ||
429 | |||
430 | static int rockchip_sound_codec_node_match(struct device_node *np_codec) | 425 | static int rockchip_sound_codec_node_match(struct device_node *np_codec) |
431 | { | 426 | { |
432 | struct device *dev; | 427 | struct device *dev; |
@@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec) | |||
438 | continue; | 433 | continue; |
439 | 434 | ||
440 | if (dailink_match[i].bus_type) { | 435 | if (dailink_match[i].bus_type) { |
441 | dev = bus_find_device(dailink_match[i].bus_type, NULL, | 436 | dev = bus_find_device_by_of_node(dailink_match[i].bus_type, |
442 | np_codec, of_dev_node_match); | 437 | np_codec); |
443 | if (!dev) | 438 | if (!dev) |
444 | continue; | 439 | continue; |
445 | put_device(dev); | 440 | put_device(dev); |