]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ti-u-boot/ti-u-boot.git/commitdiff
dm: core: Allow dropping run-time binding of devices
authorSimon Glass <sjg@chromium.org>
Mon, 15 Mar 2021 04:25:15 +0000 (17:25 +1300)
committerSimon Glass <sjg@chromium.org>
Mon, 22 Mar 2021 06:23:28 +0000 (19:23 +1300)
With OF_PLATDATA_INST devices are bound at build time. We should not need
binding of devices at runtime in most cases. However it is inflexible to
absolutely prohibit it, so add an option to control this.

Update the driver model core so that it does not bind devices. Update
device_bind() to return an error if called.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/core/device.c
dts/Kconfig

index 81f6880eac410e0833e5e733969537caf7076684..e915b3089dee39e50eb19723f2bed431543060b3 100644 (file)
@@ -45,6 +45,9 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
        bool auto_seq = true;
        void *ptr;
 
+       if (CONFIG_IS_ENABLED(OF_PLATDATA_NO_BIND))
+               return -ENOSYS;
+
        if (devp)
                *devp = NULL;
        if (!name)
@@ -395,26 +398,31 @@ int device_of_to_plat(struct udevice *dev)
        if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
                return 0;
 
-       /* Ensure all parents have ofdata */
-       if (dev->parent) {
-               ret = device_of_to_plat(dev->parent);
+       /*
+        * This is not needed if binding is disabled, since data is allocated
+        * at build time.
+        */
+       if (!CONFIG_IS_ENABLED(OF_PLATDATA_NO_BIND)) {
+               /* Ensure all parents have ofdata */
+               if (dev->parent) {
+                       ret = device_of_to_plat(dev->parent);
+                       if (ret)
+                               goto fail;
+
+                       /*
+                        * The device might have already been probed during
+                        * the call to device_probe() on its parent device
+                        * (e.g. PCI bridge devices). Test the flags again
+                        * so that we don't mess up the device.
+                        */
+                       if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
+                               return 0;
+               }
+
+               ret = device_alloc_priv(dev);
                if (ret)
                        goto fail;
-
-               /*
-                * The device might have already been probed during
-                * the call to device_probe() on its parent device
-                * (e.g. PCI bridge devices). Test the flags again
-                * so that we don't mess up the device.
-                */
-               if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
-                       return 0;
        }
-
-       ret = device_alloc_priv(dev);
-       if (ret)
-               goto fail;
-
        drv = dev->driver;
        assert(drv);
 
index c39cc368881f82843f5f9e0eb3f76da209949c9e..d289752a139e692f770d49823315ab3a7a9b17c3 100644 (file)
@@ -371,6 +371,15 @@ config SPL_OF_PLATDATA_INST
          Declare devices as udevice instances so that they do not need to be
          bound when U-Boot starts. This can save time and code space.
 
+config SPL_OF_PLATDATA_NO_BIND
+       bool "Don't allow run-time binding of devices"
+       depends on SPL_OF_PLATDATA_INST
+       default y
+       help
+         This removes the ability to bind devices at run time, thus saving
+         some code space in U-Boot. This can be disabled if binding is needed,
+         at the code of some code size increase.
+
 endif
 
 config TPL_OF_PLATDATA
@@ -411,6 +420,15 @@ config TPL_OF_PLATDATA_INST
          Declare devices as udevice instances so that they do not need to be
          bound when U-Boot starts. This can save time and code space.
 
+config TPL_OF_PLATDATA_NO_BIND
+       bool "Don't allow run-time binding of devices"
+       depends on TPL_OF_PLATDATA_INST
+       default y
+       help
+         This removes the ability to bind devices at run time, thus saving
+         some code space in U-Boot. This can be disabled if binding is needed,
+         at the code of some code size increase.
+
 endif
 
 endmenu