Skip to content

Commit d040963

Browse files
Dong AishengShawn Guo
authored andcommitted
clk: imx: scu: add suspend/resume support
Clock state will be lost when its power domain is completely off during system suspend/resume. So we save and restore the state accordingly in suspend/resume callback. Cc: Shawn Guo <[email protected]> Cc: Sascha Hauer <[email protected]> Cc: Michael Turquette <[email protected]> Reviewed-by: Stephen Boyd <[email protected]> Signed-off-by: Dong Aisheng <[email protected]> Signed-off-by: Shawn Guo <[email protected]>
1 parent 78edeb0 commit d040963

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

drivers/clk/imx/clk-scu.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ struct clk_scu {
4545
struct clk_hw hw;
4646
u16 rsrc_id;
4747
u8 clk_type;
48+
49+
/* for state save&restore */
50+
bool is_enabled;
51+
u32 rate;
4852
};
4953

5054
/*
@@ -430,6 +434,9 @@ struct clk_hw *__imx_clk_scu(struct device *dev, const char *name,
430434
hw = ERR_PTR(ret);
431435
}
432436

437+
if (dev)
438+
dev_set_drvdata(dev, clk);
439+
433440
return hw;
434441
}
435442

@@ -486,10 +493,52 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
486493
return 0;
487494
}
488495

496+
static int __maybe_unused imx_clk_scu_suspend(struct device *dev)
497+
{
498+
struct clk_scu *clk = dev_get_drvdata(dev);
499+
500+
clk->rate = clk_hw_get_rate(&clk->hw);
501+
clk->is_enabled = clk_hw_is_enabled(&clk->hw);
502+
503+
if (clk->rate)
504+
dev_dbg(dev, "save rate %d\n", clk->rate);
505+
506+
if (clk->is_enabled)
507+
dev_dbg(dev, "save enabled state\n");
508+
509+
return 0;
510+
}
511+
512+
static int __maybe_unused imx_clk_scu_resume(struct device *dev)
513+
{
514+
struct clk_scu *clk = dev_get_drvdata(dev);
515+
int ret = 0;
516+
517+
if (clk->rate) {
518+
ret = clk_scu_set_rate(&clk->hw, clk->rate, 0);
519+
dev_dbg(dev, "restore rate %d %s\n", clk->rate,
520+
!ret ? "success" : "failed");
521+
}
522+
523+
if (clk->is_enabled) {
524+
ret = clk_scu_prepare(&clk->hw);
525+
dev_dbg(dev, "restore enabled state %s\n",
526+
!ret ? "success" : "failed");
527+
}
528+
529+
return ret;
530+
}
531+
532+
static const struct dev_pm_ops imx_clk_scu_pm_ops = {
533+
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx_clk_scu_suspend,
534+
imx_clk_scu_resume)
535+
};
536+
489537
static struct platform_driver imx_clk_scu_driver = {
490538
.driver = {
491539
.name = "imx-scu-clk",
492540
.suppress_bind_attrs = true,
541+
.pm = &imx_clk_scu_pm_ops,
493542
},
494543
.probe = imx_clk_scu_probe,
495544
};

0 commit comments

Comments
 (0)