dm: core: Update device_bind_driver_to_node() to use ofnode

Adjust this function to us an ofnode instead of an offset, so it can be
used with livetree. This involves updating all callers.

Signed-off-by: Simon Glass <sjg@chromium.org>
master
Simon Glass 7 years ago
parent f5b5719cdf
commit 45a26867e8
  1. 2
      drivers/clk/at91/pmc.c
  2. 15
      drivers/core/lists.c
  3. 6
      drivers/cpu/cpu-uclass.c
  4. 11
      drivers/i2c/muxes/i2c-mux-uclass.c
  5. 2
      drivers/led/led_bcm6328.c
  6. 2
      drivers/led/led_bcm6358.c
  7. 13
      drivers/led/led_gpio.c
  8. 6
      drivers/misc/tegra186_bpmp.c
  9. 4
      drivers/misc/tegra_car.c
  10. 6
      drivers/net/keystone_net.c
  11. 15
      drivers/pinctrl/pinctrl-uclass.c
  12. 2
      drivers/usb/musb-new/ti-musb.c
  13. 2
      include/dm.h
  14. 2
      include/dm/lists.h

@ -79,7 +79,7 @@ int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name)
if (!name) if (!name)
return -EINVAL; return -EINVAL;
ret = device_bind_driver_to_node(dev, drv_name, name, ret = device_bind_driver_to_node(dev, drv_name, name,
offset, NULL); offset_to_ofnode(offset), NULL);
if (ret) if (ret)
return ret; return ret;
} }

@ -74,11 +74,12 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)
int device_bind_driver(struct udevice *parent, const char *drv_name, int device_bind_driver(struct udevice *parent, const char *drv_name,
const char *dev_name, struct udevice **devp) const char *dev_name, struct udevice **devp)
{ {
return device_bind_driver_to_node(parent, drv_name, dev_name, -1, devp); return device_bind_driver_to_node(parent, drv_name, dev_name,
ofnode_null(), devp);
} }
int device_bind_driver_to_node(struct udevice *parent, const char *drv_name, int device_bind_driver_to_node(struct udevice *parent, const char *drv_name,
const char *dev_name, int node, const char *dev_name, ofnode node,
struct udevice **devp) struct udevice **devp)
{ {
struct driver *drv; struct driver *drv;
@ -89,14 +90,10 @@ int device_bind_driver_to_node(struct udevice *parent, const char *drv_name,
debug("Cannot find driver '%s'\n", drv_name); debug("Cannot find driver '%s'\n", drv_name);
return -ENOENT; return -ENOENT;
} }
ret = device_bind(parent, drv, dev_name, NULL, node, devp); ret = device_bind_with_driver_data(parent, drv, dev_name, 0 /* data */,
if (ret) { node, devp);
debug("Cannot create device named '%s' (err=%d)\n",
dev_name, ret);
return ret;
}
return 0; return ret;
} }
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)

@ -63,11 +63,11 @@ U_BOOT_DRIVER(cpu_bus) = {
static int uclass_cpu_init(struct uclass *uc) static int uclass_cpu_init(struct uclass *uc)
{ {
struct udevice *dev; struct udevice *dev;
int node; ofnode node;
int ret; int ret;
node = fdt_path_offset(gd->fdt_blob, "/cpus"); node = ofnode_path("/cpus");
if (node < 0) if (!ofnode_valid(node))
return 0; return 0;
ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node, ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,

@ -51,24 +51,21 @@ static int i2c_mux_child_post_bind(struct udevice *dev)
/* Find the I2C buses selected by this mux */ /* Find the I2C buses selected by this mux */
static int i2c_mux_post_bind(struct udevice *mux) static int i2c_mux_post_bind(struct udevice *mux)
{ {
const void *blob = gd->fdt_blob; ofnode node;
int ret; int ret;
int offset;
debug("%s: %s\n", __func__, mux->name); debug("%s: %s\n", __func__, mux->name);
/* /*
* There is no compatible string in the sub-nodes, so we must manually * There is no compatible string in the sub-nodes, so we must manually
* bind these * bind these
*/ */
for (offset = fdt_first_subnode(blob, dev_of_offset(mux)); dev_for_each_subnode(node, mux) {
offset > 0;
offset = fdt_next_subnode(blob, offset)) {
struct udevice *dev; struct udevice *dev;
const char *name; const char *name;
name = fdt_get_name(blob, offset, NULL); name = ofnode_get_name(node);
ret = device_bind_driver_to_node(mux, "i2c_mux_bus_drv", name, ret = device_bind_driver_to_node(mux, "i2c_mux_bus_drv", name,
offset, &dev); node, &dev);
debug(" - bind ret=%d, %s\n", ret, dev ? dev->name : NULL); debug(" - bind ret=%d, %s\n", ret, dev ? dev->name : NULL);
if (ret) if (ret)
return ret; return ret;

@ -236,7 +236,7 @@ static int bcm6328_led_bind(struct udevice *parent)
ret = device_bind_driver_to_node(parent, "bcm6328-led", ret = device_bind_driver_to_node(parent, "bcm6328-led",
fdt_get_name(blob, node, NULL), fdt_get_name(blob, node, NULL),
node, &dev); offset_to_ofnode(node), &dev);
if (ret) if (ret)
return ret; return ret;

@ -201,7 +201,7 @@ static int bcm6358_led_bind(struct udevice *parent)
ret = device_bind_driver_to_node(parent, "bcm6358-led", ret = device_bind_driver_to_node(parent, "bcm6358-led",
fdt_get_name(blob, node, NULL), fdt_get_name(blob, node, NULL),
node, &dev); offset_to_ofnode(node), &dev);
if (ret) if (ret)
return ret; return ret;

@ -85,25 +85,22 @@ static int led_gpio_remove(struct udevice *dev)
static int led_gpio_bind(struct udevice *parent) static int led_gpio_bind(struct udevice *parent)
{ {
const void *blob = gd->fdt_blob;
struct udevice *dev; struct udevice *dev;
int node; ofnode node;
int ret; int ret;
for (node = fdt_first_subnode(blob, dev_of_offset(parent)); dev_for_each_subnode(node, parent) {
node > 0;
node = fdt_next_subnode(blob, node)) {
struct led_uc_plat *uc_plat; struct led_uc_plat *uc_plat;
const char *label; const char *label;
label = fdt_getprop(blob, node, "label", NULL); label = ofnode_read_string(node, "label");
if (!label) { if (!label) {
debug("%s: node %s has no label\n", __func__, debug("%s: node %s has no label\n", __func__,
fdt_get_name(blob, node, NULL)); ofnode_get_name(node));
return -EINVAL; return -EINVAL;
} }
ret = device_bind_driver_to_node(parent, "gpio_led", ret = device_bind_driver_to_node(parent, "gpio_led",
fdt_get_name(blob, node, NULL), ofnode_get_name(node),
node, &dev); node, &dev);
if (ret) if (ret)
return ret; return ret;

@ -112,19 +112,19 @@ static int tegra186_bpmp_bind(struct udevice *dev)
debug("%s(dev=%p)\n", __func__, dev); debug("%s(dev=%p)\n", __func__, dev);
ret = device_bind_driver_to_node(dev, "tegra186_clk", "tegra186_clk", ret = device_bind_driver_to_node(dev, "tegra186_clk", "tegra186_clk",
dev_of_offset(dev), &child); dev_ofnode(dev), &child);
if (ret) if (ret)
return ret; return ret;
ret = device_bind_driver_to_node(dev, "tegra186_reset", ret = device_bind_driver_to_node(dev, "tegra186_reset",
"tegra186_reset", dev_of_offset(dev), "tegra186_reset", dev_ofnode(dev),
&child); &child);
if (ret) if (ret)
return ret; return ret;
ret = device_bind_driver_to_node(dev, "tegra186_power_domain", ret = device_bind_driver_to_node(dev, "tegra186_power_domain",
"tegra186_power_domain", "tegra186_power_domain",
dev_of_offset(dev), &child); dev_ofnode(dev), &child);
if (ret) if (ret)
return ret; return ret;

@ -22,12 +22,12 @@ static int tegra_car_bpmp_bind(struct udevice *dev)
debug("%s(dev=%p)\n", __func__, dev); debug("%s(dev=%p)\n", __func__, dev);
ret = device_bind_driver_to_node(dev, "tegra_car_clk", "tegra_car_clk", ret = device_bind_driver_to_node(dev, "tegra_car_clk", "tegra_car_clk",
dev_of_offset(dev), &child); dev_ofnode(dev), &child);
if (ret) if (ret)
return ret; return ret;
ret = device_bind_driver_to_node(dev, "tegra_car_reset", ret = device_bind_driver_to_node(dev, "tegra_car_reset",
"tegra_car_reset", dev_of_offset(dev), "tegra_car_reset", dev_ofnode(dev),
&child); &child);
if (ret) if (ret)
return ret; return ret;

@ -1008,8 +1008,8 @@ static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0)
slave_name = malloc(20); slave_name = malloc(20);
snprintf(slave_name, 20, "netcp@slave-%d", slave_no); snprintf(slave_name, 20, "netcp@slave-%d", slave_no);
ret = device_bind_driver_to_node(dev, "eth_ks2_sl", ret = device_bind_driver_to_node(dev, "eth_ks2_sl",
slave_name, slave, slave_name, offset_to_ofnode(slave),
&sl_dev); &sl_dev);
if (ret) { if (ret) {
error("ks2_net - not able to bind slave interfaces\n"); error("ks2_net - not able to bind slave interfaces\n");
return ret; return ret;
@ -1029,7 +1029,7 @@ static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0)
slave_name = malloc(20); slave_name = malloc(20);
snprintf(slave_name, 20, "netcp@slave-%d", slave_no); snprintf(slave_name, 20, "netcp@slave-%d", slave_no);
ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name,
slave, &sl_dev); offset_to_ofnode(slave), &sl_dev);
if (ret) { if (ret) {
error("ks2_net - not able to bind slave interfaces\n"); error("ks2_net - not able to bind slave interfaces\n");
return ret; return ret;

@ -121,34 +121,31 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
*/ */
static int pinconfig_post_bind(struct udevice *dev) static int pinconfig_post_bind(struct udevice *dev)
{ {
const void *fdt = gd->fdt_blob;
int offset = dev_of_offset(dev);
bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC);
const char *name; const char *name;
ofnode node;
int ret; int ret;
for (offset = fdt_first_subnode(fdt, offset); dev_for_each_subnode(node, dev) {
offset > 0;
offset = fdt_next_subnode(fdt, offset)) {
if (pre_reloc_only && if (pre_reloc_only &&
!dm_fdt_pre_reloc(fdt, offset)) !ofnode_pre_reloc(node))
continue; continue;
/* /*
* If this node has "compatible" property, this is not * If this node has "compatible" property, this is not
* a pin configuration node, but a normal device. skip. * a pin configuration node, but a normal device. skip.
*/ */
fdt_get_property(fdt, offset, "compatible", &ret); ofnode_read_prop(node, "compatible", &ret);
if (ret >= 0) if (ret >= 0)
continue; continue;
if (ret != -FDT_ERR_NOTFOUND) if (ret != -FDT_ERR_NOTFOUND)
return ret; return ret;
name = fdt_get_name(fdt, offset, NULL); name = ofnode_get_name(node);
if (!name) if (!name)
return -EINVAL; return -EINVAL;
ret = device_bind_driver_to_node(dev, "pinconfig", name, ret = device_bind_driver_to_node(dev, "pinconfig", name,
offset, NULL); node, NULL);
if (ret) if (ret)
return ret; return ret;
} }

@ -227,7 +227,7 @@ static int ti_musb_wrapper_bind(struct udevice *parent)
case USB_DR_MODE_HOST: case USB_DR_MODE_HOST:
/* Bind MUSB host */ /* Bind MUSB host */
ret = device_bind_driver_to_node(parent, "ti-musb-host", ret = device_bind_driver_to_node(parent, "ti-musb-host",
name, node, &dev); name, offset_to_ofnode(node), &dev);
if (ret) { if (ret) {
error("musb - not able to bind usb host node\n"); error("musb - not able to bind usb host node\n");
return ret; return ret;

@ -10,6 +10,8 @@
#include <dm/ofnode.h> #include <dm/ofnode.h>
#include <dm/device.h> #include <dm/device.h>
#include <dm/fdtaddr.h> #include <dm/fdtaddr.h>
#include <dm/ofnode.h>
#include <dm/read.h>
#include <dm/platdata.h> #include <dm/platdata.h>
#include <dm/uclass.h> #include <dm/uclass.h>

@ -85,7 +85,7 @@ int device_bind_driver(struct udevice *parent, const char *drv_name,
* @devp: If non-NULL, returns the newly bound device * @devp: If non-NULL, returns the newly bound device
*/ */
int device_bind_driver_to_node(struct udevice *parent, const char *drv_name, int device_bind_driver_to_node(struct udevice *parent, const char *drv_name,
const char *dev_name, int node, const char *dev_name, ofnode node,
struct udevice **devp); struct udevice **devp);
#endif #endif

Loading…
Cancel
Save