diff options
author | Simon Glass <sjg@chromium.org> | 2014-07-23 06:55:20 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-07-23 14:08:37 +0100 |
commit | e59f458de6999b8a786da857e653db6777f675ca (patch) | |
tree | 0e57f9b83b6a484fce0543562c7c313e66b89c75 /drivers/core | |
parent | 997c87bb0b1981fd33e34cefc26d9138f27326ce (diff) | |
download | u-boot-e59f458de6999b8a786da857e653db6777f675ca.tar.gz u-boot-e59f458de6999b8a786da857e653db6777f675ca.tar.xz u-boot-e59f458de6999b8a786da857e653db6777f675ca.zip |
dm: Introduce per-child data for devices
Some device types can have child devices and want to store information
about them. For example a USB flash stick attached to a USB host
controller would likely use this space. The controller can hold
information about the USB state of each of its children.
The data is stored attached to the child device in the 'parent_priv'
member. It can be auto-allocated by dm when the child is probed. To
do this, add a per_child_auto_alloc_size value to the parent driver.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/device.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c index 74bb5f0f8e..42d250f4a4 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -218,6 +218,13 @@ static void device_free(struct udevice *dev) free(dev->uclass_priv); dev->uclass_priv = NULL; } + if (dev->parent) { + size = dev->parent->driver->per_child_auto_alloc_size; + if (size) { + free(dev->parent_priv); + dev->parent_priv = NULL; + } + } } int device_probe(struct udevice *dev) @@ -263,6 +270,15 @@ int device_probe(struct udevice *dev) /* Ensure all parents are probed */ if (dev->parent) { + size = dev->parent->driver->per_child_auto_alloc_size; + if (size) { + dev->parent_priv = calloc(1, size); + if (!dev->parent_priv) { + ret = -ENOMEM; + goto fail; + } + } + ret = device_probe(dev->parent); if (ret) goto fail; @@ -377,6 +393,16 @@ void *dev_get_priv(struct udevice *dev) return dev->priv; } +void *dev_get_parentdata(struct udevice *dev) +{ + if (!dev) { + dm_warn("%s: null device", __func__); + return NULL; + } + + return dev->parent_priv; +} + static int device_get_device_tail(struct udevice *dev, int ret, struct udevice **devp) { |