Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Suzuki K Poulose and committed by
Greg Kroah-Hartman
cfba5de9 6cda08a2

+56 -110
+1 -10
drivers/amba/tegra-ahb.c
··· 134 134 } 135 135 136 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 137 int tegra_ahb_enable_smmu(struct device_node *dn) 146 138 { 147 139 struct device *dev; 148 140 u32 val; 149 141 struct tegra_ahb *ahb; 150 142 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); 153 144 if (!dev) 154 145 return -EPROBE_DEFER; 155 146 ahb = dev_get_drvdata(dev);
+1 -7
drivers/fpga/fpga-bridge.c
··· 19 19 /* Lock for adding/removing bridges to linked lists*/ 20 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 23 * fpga_bridge_enable - Enable transactions on the bridge 29 24 * ··· 99 104 { 100 105 struct device *dev; 101 106 102 - dev = class_find_device(fpga_bridge_class, NULL, np, 103 - fpga_bridge_of_node_match); 107 + dev = class_find_device_by_of_node(fpga_bridge_class, np); 104 108 if (!dev) 105 109 return ERR_PTR(-ENODEV); 106 110
+1 -7
drivers/fpga/fpga-mgr.c
··· 482 482 } 483 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 486 * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr. 492 487 * ··· 493 498 { 494 499 struct device *dev; 495 500 496 - dev = class_find_device(fpga_mgr_class, NULL, node, 497 - fpga_mgr_of_node_match); 501 + dev = class_find_device_by_of_node(fpga_mgr_class, node); 498 502 if (!dev) 499 503 return ERR_PTR(-ENODEV); 500 504
+1 -6
drivers/gpu/drm/drm_mipi_dsi.c
··· 93 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 97 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a 103 98 * device tree node ··· 105 110 { 106 111 struct device *dev; 107 112 108 - dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match); 113 + dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np); 109 114 110 115 return dev ? to_mipi_dsi_device(dev) : NULL; 111 116 }
+1 -6
drivers/i2c/i2c-core-of.c
··· 113 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 116 static int of_dev_or_parent_node_match(struct device *dev, const void *data) 122 117 { 123 118 if (dev->of_node == data) ··· 130 135 struct device *dev; 131 136 struct i2c_client *client; 132 137 133 - dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match); 138 + dev = bus_find_device_by_of_node(&i2c_bus_type, node); 134 139 if (!dev) 135 140 return NULL; 136 141
+2 -12
drivers/mfd/altera-sysmgr.c
··· 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 91 * altr_sysmgr_regmap_lookup_by_phandle 102 92 * Find the sysmgr previous configured in probe() and return regmap property. 103 93 * Return: regmap if found or error if not found. ··· 107 117 if (!sysmgr_np) 108 118 return ERR_PTR(-ENODEV); 109 119 110 - dev = driver_find_device(&altr_sysmgr_driver.driver, NULL, 111 - (void *)sysmgr_np, sysmgr_match_phandle); 120 + dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver, 121 + (void *)sysmgr_np); 112 122 of_node_put(sysmgr_np); 113 123 if (!dev) 114 124 return ERR_PTR(-EPROBE_DEFER);
+1 -6
drivers/mux/core.c
··· 405 405 } 406 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 408 /* Note this function returns a reference to the mux_chip dev. */ 414 409 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) 415 410 { 416 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 415 return dev ? to_mux_chip(dev) : NULL; 421 416 }
+1 -8
drivers/net/phy/mdio_bus.c
··· 262 262 }; 263 263 264 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 266 * of_mdio_find_bus - Given an mii_bus node, find the mii_bus. 272 267 * @mdio_bus_np: Pointer to the mii_bus. ··· 282 287 if (!mdio_bus_np) 283 288 return NULL; 284 289 285 - d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np, 286 - of_mdio_bus_match); 287 - 290 + d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np); 288 291 return d ? to_mii_bus(d) : NULL; 289 292 } 290 293 EXPORT_SYMBOL(of_mdio_find_bus);
+1 -6
drivers/nvmem/core.c
··· 76 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 79 static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) 85 80 { 86 81 struct device *d; ··· 83 88 if (!nvmem_np) 84 89 return NULL; 85 90 86 - d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match); 91 + d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np); 87 92 88 93 if (!d) 89 94 return NULL;
+1 -7
drivers/of/of_mdio.c
··· 280 280 } 281 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 284 * of_phy_find_device - Give a PHY node, find the phy_device 291 285 * @phy_np: Pointer to the phy's device tree node ··· 295 301 if (!phy_np) 296 302 return NULL; 297 303 298 - d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match); 304 + d = bus_find_device_by_of_node(&mdio_bus_type, phy_np); 299 305 if (d) { 300 306 mdiodev = to_mdio_device(d); 301 307 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
+1 -6
drivers/of/platform.c
··· 37 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 41 * of_find_device_by_node - Find the platform_device associated with a node 47 42 * @np: Pointer to device tree node ··· 50 55 { 51 56 struct device *dev; 52 57 53 - dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match); 58 + dev = bus_find_device_by_of_node(&platform_bus_type, np); 54 59 return dev ? to_platform_device(dev) : NULL; 55 60 } 56 61 EXPORT_SYMBOL(of_find_device_by_node);
+1 -6
drivers/regulator/of_regulator.c
··· 460 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 463 struct regulator_dev *of_find_regulator_by_node(struct device_node *np) 469 464 { 470 465 struct device *dev; 471 466 472 - dev = class_find_device(&regulator_class, NULL, np, of_node_match); 467 + dev = class_find_device_by_of_node(&regulator_class, np); 473 468 474 469 return dev ? dev_to_rdev(dev) : NULL; 475 470 }
+4 -16
drivers/spi/spi.c
··· 3652 3652 /*-------------------------------------------------------------------------*/ 3653 3653 3654 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 3655 /* must call put_device() when done with returned spi_device device */ 3661 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, 3664 - __spi_of_device_match); 3658 + struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node); 3659 + 3665 3660 return dev ? to_spi_device(dev) : NULL; 3666 3661 } 3667 3662 EXPORT_SYMBOL_GPL(of_find_spi_device_by_node); 3668 3663 #endif /* IS_ENABLED(CONFIG_OF) */ 3669 3664 3670 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 3666 /* the spi controllers are not using spi_bus, so we find it with another way */ 3677 3667 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) 3678 3668 { 3679 3669 struct device *dev; 3680 3670 3681 - dev = class_find_device(&spi_master_class, NULL, node, 3682 - __spi_of_controller_match); 3671 + dev = class_find_device_by_of_node(&spi_master_class, node); 3683 3672 if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) 3684 - dev = class_find_device(&spi_slave_class, NULL, node, 3685 - __spi_of_controller_match); 3673 + dev = class_find_device_by_of_node(&spi_slave_class, node); 3686 3674 if (!dev) 3687 3675 return NULL; 3688 3676
+37
include/linux/device.h
··· 186 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 201 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, 190 202 struct device *hint); 191 203 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, ··· 378 366 return driver_find_device(drv, NULL, name, device_match_name); 379 367 } 380 368 369 + /** 370 + * driver_find_device_by_of_node- device iterator for locating a particular device 371 + * by of_node pointer. 372 + * @driver: the driver we're iterating 373 + * @np: of_node pointer to match. 374 + */ 375 + static inline struct device * 376 + driver_find_device_by_of_node(struct device_driver *drv, 377 + const struct device_node *np) 378 + { 379 + return driver_find_device(drv, NULL, np, device_match_of_node); 380 + } 381 + 381 382 void driver_deferred_probe_add(struct device *dev); 382 383 int driver_deferred_probe_check_state(struct device *dev); 383 384 int driver_deferred_probe_check_state_continue(struct device *dev); ··· 530 505 const char *name) 531 506 { 532 507 return class_find_device(class, NULL, name, device_match_name); 508 + } 509 + 510 + /** 511 + * class_find_device_by_of_node : device iterator for locating a particular device 512 + * matching the of_node. 513 + * @class: class type 514 + * @np: of_node of the device to match. 515 + */ 516 + static inline struct device * 517 + class_find_device_by_of_node(struct class *class, const struct device_node *np) 518 + { 519 + return class_find_device(class, NULL, np, device_match_of_node); 533 520 } 534 521 535 522 struct class_attribute {
+2 -7
sound/soc/rockchip/rk3399_gru_sound.c
··· 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 425 static int rockchip_sound_codec_node_match(struct device_node *np_codec) 431 426 { 432 427 struct device *dev; ··· 433 438 continue; 434 439 435 440 if (dailink_match[i].bus_type) { 436 - dev = bus_find_device(dailink_match[i].bus_type, NULL, 437 - np_codec, of_dev_node_match); 441 + dev = bus_find_device_by_of_node(dailink_match[i].bus_type, 442 + np_codec); 438 443 if (!dev) 439 444 continue; 440 445 put_device(dev);