diff mbox series

[V3] clk: vc5: Add suspend/resume support

Message ID 20181213161528.20318-1-marek.vasut+renesas@gmail.com (mailing list archive)
State Accepted
Headers show
Series [V3] clk: vc5: Add suspend/resume support | expand

Commit Message

Marek Vasut Dec. 13, 2018, 4:15 p.m. UTC
Add simple suspend/resume handlers to the driver to restore the chip
configuration after resume. It is possible that the chip was configured
with non-default values before suspend-resume cycle and that the chip
is powered down during this cycle, so the configuration could get lost.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Alexey Firago <alexey_firago@mentor.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: linux-renesas-soc@vger.kernel.org
---
V2: Replace ifdef with __maybe_unused
    Simplify return value handling in resume
V3: Drop useless regcache_sync() call from suspend callback
    (thanks Laurent for testing with working DU)
---
 drivers/clk/clk-versaclock5.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Laurent Pinchart Dec. 13, 2018, 8:39 p.m. UTC | #1
Hi Marek,

Thank you for the patch.

On Thursday, 13 December 2018 18:15:28 EET Marek Vasut wrote:
> Add simple suspend/resume handlers to the driver to restore the chip
> configuration after resume. It is possible that the chip was configured
> with non-default values before suspend-resume cycle and that the chip
> is powered down during this cycle, so the configuration could get lost.
> 
> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
> Cc: Alexey Firago <alexey_firago@mentor.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: linux-renesas-soc@vger.kernel.org

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> V2: Replace ifdef with __maybe_unused
>     Simplify return value handling in resume
> V3: Drop useless regcache_sync() call from suspend callback
>     (thanks Laurent for testing with working DU)
> ---
>  drivers/clk/clk-versaclock5.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c
> index decffb3826ec..5b393e711e94 100644
> --- a/drivers/clk/clk-versaclock5.c
> +++ b/drivers/clk/clk-versaclock5.c
> @@ -906,6 +906,28 @@ static int vc5_remove(struct i2c_client *client)
>  	return 0;
>  }
> 
> +static int __maybe_unused vc5_suspend(struct device *dev)
> +{
> +	struct vc5_driver_data *vc5 = dev_get_drvdata(dev);
> +
> +	regcache_cache_only(vc5->regmap, true);
> +	regcache_mark_dirty(vc5->regmap);
> +
> +	return 0;
> +}
> +
> +static int __maybe_unused vc5_resume(struct device *dev)
> +{
> +	struct vc5_driver_data *vc5 = dev_get_drvdata(dev);
> +	int ret;
> +
> +	regcache_cache_only(vc5->regmap, false);
> +	ret = regcache_sync(vc5->regmap);
> +	if (ret)
> +		dev_err(dev, "Failed to restore register map: %d\n", ret);
> +	return ret;
> +}
> +
>  static const struct vc5_chip_info idt_5p49v5923_info = {
>  	.model = IDT_VC5_5P49V5923,
>  	.clk_fod_cnt = 2,
> @@ -961,9 +983,12 @@ static const struct of_device_id clk_vc5_of_match[] = {
> };
>  MODULE_DEVICE_TABLE(of, clk_vc5_of_match);
> 
> +static SIMPLE_DEV_PM_OPS(vc5_pm_ops, vc5_suspend, vc5_resume);
> +
>  static struct i2c_driver vc5_driver = {
>  	.driver = {
>  		.name = "vc5",
> +		.pm	= &vc5_pm_ops,
>  		.of_match_table = clk_vc5_of_match,
>  	},
>  	.probe		= vc5_probe,
Stephen Boyd Dec. 14, 2018, 9:44 p.m. UTC | #2
Quoting Marek Vasut (2018-12-13 08:15:28)
> Add simple suspend/resume handlers to the driver to restore the chip
> configuration after resume. It is possible that the chip was configured
> with non-default values before suspend-resume cycle and that the chip
> is powered down during this cycle, so the configuration could get lost.
> 
> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
> Cc: Alexey Firago <alexey_firago@mentor.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: linux-renesas-soc@vger.kernel.org
> ---

Applied to clk-next
diff mbox series

Patch

diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c
index decffb3826ec..5b393e711e94 100644
--- a/drivers/clk/clk-versaclock5.c
+++ b/drivers/clk/clk-versaclock5.c
@@ -906,6 +906,28 @@  static int vc5_remove(struct i2c_client *client)
 	return 0;
 }
 
+static int __maybe_unused vc5_suspend(struct device *dev)
+{
+	struct vc5_driver_data *vc5 = dev_get_drvdata(dev);
+
+	regcache_cache_only(vc5->regmap, true);
+	regcache_mark_dirty(vc5->regmap);
+
+	return 0;
+}
+
+static int __maybe_unused vc5_resume(struct device *dev)
+{
+	struct vc5_driver_data *vc5 = dev_get_drvdata(dev);
+	int ret;
+
+	regcache_cache_only(vc5->regmap, false);
+	ret = regcache_sync(vc5->regmap);
+	if (ret)
+		dev_err(dev, "Failed to restore register map: %d\n", ret);
+	return ret;
+}
+
 static const struct vc5_chip_info idt_5p49v5923_info = {
 	.model = IDT_VC5_5P49V5923,
 	.clk_fod_cnt = 2,
@@ -961,9 +983,12 @@  static const struct of_device_id clk_vc5_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, clk_vc5_of_match);
 
+static SIMPLE_DEV_PM_OPS(vc5_pm_ops, vc5_suspend, vc5_resume);
+
 static struct i2c_driver vc5_driver = {
 	.driver = {
 		.name = "vc5",
+		.pm	= &vc5_pm_ops,
 		.of_match_table = clk_vc5_of_match,
 	},
 	.probe		= vc5_probe,