Commit 24fb3161 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Alexandre Belloni
Browse files

rtc: mpfs: Use devm_clk_get_enabled() helper



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().

That said, mpfs_rtc_init_clk() is the same as devm_clk_get_enabled(), so
use this function directly instead.

This also fixes an (unlikely) unchecked devm_add_action_or_reset() error.

Based on my test with allyesconfig, this reduces the .o size from:
   text	   data	    bss	    dec	    hex	filename
   5330	   2208	      0	   7538	   1d72	drivers/rtc/rtc-mpfs.o
down to:
   5074	   2208	      0	   7282	   1c72	drivers/rtc/rtc-mpfs.o

Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: default avatarConor Dooley <conor.dooley@microchip.com>
Link: https://lore.kernel.org/r/e55c959f2821a2c367a4c5de529a638b1cc6b8cd.1661329086.git.christophe.jaillet@wanadoo.fr


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent d73d66c0
Loading
Loading
Loading
Loading
+1 −18
Original line number Diff line number Diff line
@@ -193,23 +193,6 @@ static int mpfs_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
	return 0;
}

static inline struct clk *mpfs_rtc_init_clk(struct device *dev)
{
	struct clk *clk;
	int ret;

	clk = devm_clk_get(dev, "rtc");
	if (IS_ERR(clk))
		return clk;

	ret = clk_prepare_enable(clk);
	if (ret)
		return ERR_PTR(ret);

	devm_add_action_or_reset(dev, (void (*) (void *))clk_disable_unprepare, clk);
	return clk;
}

static irqreturn_t mpfs_rtc_wakeup_irq_handler(int irq, void *dev)
{
	struct mpfs_rtc_dev *rtcdev = dev;
@@ -251,7 +234,7 @@ static int mpfs_rtc_probe(struct platform_device *pdev)
	/* range is capped by alarm max, lower reg is 31:0 & upper is 10:0 */
	rtcdev->rtc->range_max = GENMASK_ULL(42, 0);

	clk = mpfs_rtc_init_clk(&pdev->dev);
	clk = devm_clk_get_enabled(&pdev->dev, "rtc");
	if (IS_ERR(clk))
		return PTR_ERR(clk);