dm: core: Allow binding a device from a live tree

When a live tree is being used we need to record the node that was used to
create the device. Update device_bind_with_driver_data() to support this.

Signed-off-by: Simon Glass <sjg@chromium.org>
master
Simon Glass 8 years ago
parent 47a0fd3bad
commit 396e343b3d
  1. 18
      drivers/core/device.c
  2. 2
      drivers/core/lists.c
  3. 10
      include/dm/device-internal.h

@ -19,6 +19,7 @@
#include <dm/lists.h> #include <dm/lists.h>
#include <dm/pinctrl.h> #include <dm/pinctrl.h>
#include <dm/platdata.h> #include <dm/platdata.h>
#include <dm/read.h>
#include <dm/uclass.h> #include <dm/uclass.h>
#include <dm/uclass-internal.h> #include <dm/uclass-internal.h>
#include <dm/util.h> #include <dm/util.h>
@ -77,10 +78,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
*/ */
if (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS) { if (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS) {
if (uc->uc_drv->name && ofnode_valid(node)) { if (uc->uc_drv->name && ofnode_valid(node)) {
fdtdec_get_alias_seq(gd->fdt_blob, dev_read_alias_seq(dev, &dev->req_seq);
uc->uc_drv->name,
ofnode_to_offset(node),
&dev->req_seq);
} }
} }
} }
@ -216,11 +214,11 @@ fail_alloc1:
int device_bind_with_driver_data(struct udevice *parent, int device_bind_with_driver_data(struct udevice *parent,
const struct driver *drv, const char *name, const struct driver *drv, const char *name,
ulong driver_data, int of_offset, ulong driver_data, ofnode node,
struct udevice **devp) struct udevice **devp)
{ {
return device_bind_common(parent, drv, name, NULL, driver_data, return device_bind_common(parent, drv, name, NULL, driver_data, node,
offset_to_ofnode(of_offset), 0, devp); 0, devp);
} }
int device_bind(struct udevice *parent, const struct driver *drv, int device_bind(struct udevice *parent, const struct driver *drv,
@ -247,8 +245,8 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
platdata_size = info->platdata_size; platdata_size = info->platdata_size;
#endif #endif
return device_bind_common(parent, drv, info->name, return device_bind_common(parent, drv, info->name,
(void *)info->platdata, 0, offset_to_ofnode(-1), (void *)info->platdata, 0, ofnode_null(), platdata_size,
platdata_size, devp); devp);
} }
static void *alloc_priv(int size, uint flags) static void *alloc_priv(int size, uint flags)
@ -385,7 +383,7 @@ int device_probe(struct udevice *dev)
goto fail; goto fail;
} }
if (drv->ofdata_to_platdata && dev_of_offset(dev) >= 0) { if (drv->ofdata_to_platdata && dev_has_of_node(dev)) {
ret = drv->ofdata_to_platdata(dev); ret = drv->ofdata_to_platdata(dev);
if (ret) if (ret)
goto fail; goto fail;

@ -177,7 +177,7 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
dm_dbg(" - found match at '%s'\n", entry->name); dm_dbg(" - found match at '%s'\n", entry->name);
ret = device_bind_with_driver_data(parent, entry, name, ret = device_bind_with_driver_data(parent, entry, name,
id->data, offset, &dev); id->data, offset_to_ofnode(offset), &dev);
if (ret == -ENODEV) { if (ret == -ENODEV) {
dm_dbg("Driver '%s' refuses to bind\n", entry->name); dm_dbg("Driver '%s' refuses to bind\n", entry->name);
continue; continue;

@ -11,6 +11,9 @@
#ifndef _DM_DEVICE_INTERNAL_H #ifndef _DM_DEVICE_INTERNAL_H
#define _DM_DEVICE_INTERNAL_H #define _DM_DEVICE_INTERNAL_H
#include <dm/ofnode.h>
struct device_node;
struct udevice; struct udevice;
/** /**
@ -52,16 +55,15 @@ int device_bind(struct udevice *parent, const struct driver *drv,
* @drv: Device's driver * @drv: Device's driver
* @name: Name of device (e.g. device tree node name) * @name: Name of device (e.g. device tree node name)
* @driver_data: The driver_data field from the driver's match table. * @driver_data: The driver_data field from the driver's match table.
* @of_offset: Offset of device tree node for this device. This is -1 for * @node: Device tree node for this device. This is invalid for devices which
* devices which don't use device tree. * don't use device tree.
* @devp: if non-NULL, returns a pointer to the bound device * @devp: if non-NULL, returns a pointer to the bound device
* @return 0 if OK, -ve on error * @return 0 if OK, -ve on error
*/ */
int device_bind_with_driver_data(struct udevice *parent, int device_bind_with_driver_data(struct udevice *parent,
const struct driver *drv, const char *name, const struct driver *drv, const char *name,
ulong driver_data, int of_offset, ulong driver_data, ofnode node,
struct udevice **devp); struct udevice **devp);
/** /**
* device_bind_by_name: Create a device and bind it to a driver * device_bind_by_name: Create a device and bind it to a driver
* *

Loading…
Cancel
Save