Currently, the platform driver core always calls of_clk_set_defaults()
before calling the driver probe() function. This will apply any
"assigned-clock-parents" and "assigned-clock-rates" specified in the device
tree. However, in some situations, these defaults cannot be safely applied
before the driver has performed some early initialization. Otherwise, the
clock operations might fail or the device could malfunction.

Add a "driver_managed_clk_defaults" option to the platform_driver struct,
similar to the existing "driver_managed_dma" option. If this option is set,
applying the clock defaults is skipped in the platform driver core and the
driver must do this itself when ready.

Signed-off-by: Stephan Gerhold <stephan.gerh...@linaro.org>
---
 drivers/base/platform.c         | 8 +++++---
 include/linux/platform_device.h | 6 ++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 
09450349cf32364bcb3c8dd94023406442ec204d..c7278ace71d3f6d473fdea35bf79bcf80a56ee21
 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1392,9 +1392,11 @@ static int platform_probe(struct device *_dev)
        if (unlikely(drv->probe == platform_probe_fail))
                return -ENXIO;
 
-       ret = of_clk_set_defaults(_dev->of_node, false);
-       if (ret < 0)
-               return ret;
+       if (!drv->driver_managed_clk_defaults) {
+               ret = of_clk_set_defaults(_dev->of_node, false);
+               if (ret < 0)
+                       return ret;
+       }
 
        ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON |
                                         PD_FLAG_DETACH_POWER_OFF);
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 
074754c23d330c9a099e20eecfeb6cbd5025e04f..fa561dae2f106b61d868a870e10d9656542b1c7e
 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -250,6 +250,12 @@ struct platform_driver {
         * to setup and manage their own I/O address space.
         */
        bool driver_managed_dma;
+       /*
+        * Skip calling of_clk_set_defaults() before calling the probe function.
+        * Use this if the driver needs to perform some initialization before
+        * clock defaults (parent, rates) are applied.
+        */
+       bool driver_managed_clk_defaults;
 };
 
 #define to_platform_driver(drv)        (container_of((drv), struct 
platform_driver, \

-- 
2.50.1

Reply via email to