dm: core: add support for device re-parenting

In common clock framework the relation b/w parent and child clocks is
determined based on the udevice parent/child information. A clock
parent could be changed based on devices needs. In case this is happen
the functionalities for clock who's parent is changed are broken. Add
a function that reparent a device. This will be used in clk-uclass.c
to reparent a clock device.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Claudiu Beznea
2020-09-07 17:46:33 +03:00
committed by Eugen Hristev
parent b04da9fcf7
commit cfecbaf4e7
3 changed files with 191 additions and 0 deletions

View File

@@ -276,6 +276,28 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
return ret;
}
int device_reparent(struct udevice *dev, struct udevice *new_parent)
{
struct udevice *pos, *n;
assert(dev);
assert(new_parent);
list_for_each_entry_safe(pos, n, &dev->parent->child_head,
sibling_node) {
if (pos->driver != dev->driver)
continue;
list_del(&dev->sibling_node);
list_add_tail(&dev->sibling_node, &new_parent->child_head);
dev->parent = new_parent;
break;
}
return 0;
}
static void *alloc_priv(int size, uint flags)
{
void *priv;