rtc: k3: Use devm_clk_get_enabled() helper
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Wed, 24 Aug 2022 08:25:11 +0000 (10:25 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Wed, 12 Oct 2022 22:31:57 +0000 (00:31 +0200)
The devm_clk_get_enabled() helper:
   - calls devm_clk_get()
   - calls clk_prepare_enable() and registers what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code, the error handling paths and avoid the need of
a dedicated function used with devm_add_action_or_reset().

Based on my test with allyesconfig, this reduces the .o size from:
   text    data     bss     dec     hex filename
   12843    4804      64   17711    452f drivers/rtc/rtc-ti-k3.o
down to:
   12523    4804      64   17391    43ef drivers/rtc/rtc-ti-k3.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/601288834ab71c0fddde7eedd8cdb8001254ed7e.1661329498.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-ti-k3.c

index 68e50c6..ba23163 100644 (file)
@@ -515,21 +515,12 @@ static struct nvmem_config ti_k3_rtc_nvmem_config = {
 
 static int k3rtc_get_32kclk(struct device *dev, struct ti_k3_rtc *priv)
 {
-       int ret;
        struct clk *clk;
 
-       clk = devm_clk_get(dev, "osc32k");
+       clk = devm_clk_get_enabled(dev, "osc32k");
        if (IS_ERR(clk))
                return PTR_ERR(clk);
 
-       ret = clk_prepare_enable(clk);
-       if (ret)
-               return ret;
-
-       ret = devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk);
-       if (ret)
-               return ret;
-
        priv->rate_32k = clk_get_rate(clk);
 
        /* Make sure we are exact 32k clock. Else, try to compensate delay */
@@ -544,24 +535,19 @@ static int k3rtc_get_32kclk(struct device *dev, struct ti_k3_rtc *priv)
         */
        priv->sync_timeout_us = (u32)(DIV_ROUND_UP_ULL(1000000, priv->rate_32k) * 4);
 
-       return ret;
+       return 0;
 }
 
 static int k3rtc_get_vbusclk(struct device *dev, struct ti_k3_rtc *priv)
 {
-       int ret;
        struct clk *clk;
 
        /* Note: VBUS isn't a context clock, it is needed for hardware operation */
-       clk = devm_clk_get(dev, "vbus");
+       clk = devm_clk_get_enabled(dev, "vbus");
        if (IS_ERR(clk))
                return PTR_ERR(clk);
 
-       ret = clk_prepare_enable(clk);
-       if (ret)
-               return ret;
-
-       return devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk);
+       return 0;
 }
 
 static int ti_k3_rtc_probe(struct platform_device *pdev)