mmc: fsl_esdhc: workaround for hardware 3.3v IO reliability issue
[oweals/u-boot.git] / drivers / core / device-remove.c
index 586fadee0a8731f9b77f24369606ed355d94e5b5..efdb0f29058f641837d936389563ceb47543d980 100644 (file)
 
 #include <common.h>
 #include <errno.h>
+#include <log.h>
 #include <malloc.h>
 #include <dm/device.h>
 #include <dm/device-internal.h>
 #include <dm/uclass.h>
 #include <dm/uclass-internal.h>
 #include <dm/util.h>
+#include <power-domain.h>
 
 int device_chld_unbind(struct udevice *dev, struct driver *drv)
 {
@@ -29,11 +31,14 @@ int device_chld_unbind(struct udevice *dev, struct driver *drv)
                        continue;
 
                ret = device_unbind(pos);
-               if (ret && !saved_ret)
+               if (ret && !saved_ret) {
+                       log_warning("device '%s' failed to unbind\n",
+                                   pos->name);
                        saved_ret = ret;
+               }
        }
 
-       return saved_ret;
+       return log_ret(saved_ret);
 }
 
 int device_chld_remove(struct udevice *dev, struct driver *drv,
@@ -62,13 +67,13 @@ int device_unbind(struct udevice *dev)
        int ret;
 
        if (!dev)
-               return -EINVAL;
+               return log_msg_ret("dev", -EINVAL);
 
        if (dev->flags & DM_FLAG_ACTIVATED)
-               return -EINVAL;
+               return log_msg_ret("active", -EINVAL);
 
        if (!(dev->flags & DM_FLAG_BOUND))
-               return -EINVAL;
+               return log_msg_ret("not-bound", -EINVAL);
 
        drv = dev->driver;
        assert(drv);
@@ -76,12 +81,12 @@ int device_unbind(struct udevice *dev)
        if (drv->unbind) {
                ret = drv->unbind(dev);
                if (ret)
-                       return ret;
+                       return log_msg_ret("unbind", ret);
        }
 
        ret = device_chld_unbind(dev, NULL);
        if (ret)
-               return ret;
+               return log_msg_ret("child unbind", ret);
 
        if (dev->flags & DM_FLAG_ALLOC_PDATA) {
                free(dev->platdata);
@@ -97,7 +102,7 @@ int device_unbind(struct udevice *dev)
        }
        ret = uclass_unbind_device(dev);
        if (ret)
-               return ret;
+               return log_msg_ret("uc", ret);
 
        if (dev->parent)
                list_del(&dev->sibling_node);
@@ -139,6 +144,7 @@ void device_free(struct udevice *dev)
                        dev->parent_priv = NULL;
                }
        }
+       dev->flags &= ~DM_FLAG_PLATDATA_VALID;
 
        devres_release_probe(dev);
 }
@@ -192,6 +198,12 @@ int device_remove(struct udevice *dev, uint flags)
                }
        }
 
+       if (!(flags & DM_REMOVE_NO_PD) &&
+           !(drv->flags &
+             (DM_FLAG_DEFAULT_PD_CTRL_OFF | DM_FLAG_REMOVE_WITH_PD_ON)) &&
+           dev != gd->cur_serial_dev)
+               dev_power_domain_off(dev);
+
        if (flags_remove(flags, drv->flags)) {
                device_free(dev);