linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: rk3x: Restore clock settings at resume time
@ 2016-08-29 21:22 Douglas Anderson
  2016-09-01  2:10 ` David.Wu
  2016-09-08 20:50 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Douglas Anderson @ 2016-08-29 21:22 UTC (permalink / raw)
  To: wsa, heiko
  Cc: linux-rockchip, david.wu, wxt, Douglas Anderson,
	linux-arm-kernel, linux-i2c, linux-kernel

Depending on a number of factors including:
- Which exact Rockchip SoC we're working with
- How deep we suspend
- Which i2c port we're on

We might lose the state of the i2c registers at suspend time.
Specifically we've found that on rk3399 the i2c ports that are not in
the PMU power domain lose their state with the current suspend depth
configured by ARM Tursted Firmware.

Note that there are very few actual i2c registers that aren't configured
per transfer anyway so all we actually need to re-configure are the
clock config registers.  We'll just add a call to rk3x_i2c_adapt_div()
at resume time and be done with it.

NOTE: On rk3399 on ports whose power was lost, I put printouts in at
resume time.  I saw things like:
  before: con=0x00010300, div=0x00060006
  after:  con=0x00010200, div=0x00180025

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
Tested on chromeos-4.4 kernel with backports.

drivers/i2c/busses/i2c-rk3x.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index 3b87afe82f63..0df5ad6bfa31 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -1111,6 +1111,15 @@ static int rk3x_i2c_xfer(struct i2c_adapter *adap,
 	return ret < 0 ? ret : num;
 }
 
+static __maybe_unused int rk3x_i2c_resume(struct device *dev)
+{
+	struct rk3x_i2c *i2c = dev_get_drvdata(dev);
+
+	rk3x_i2c_adapt_div(i2c, clk_get_rate(i2c->clk));
+
+	return 0;
+}
+
 static u32 rk3x_i2c_func(struct i2c_adapter *adap)
 {
 	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
@@ -1332,12 +1341,15 @@ static int rk3x_i2c_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const SIMPLE_DEV_PM_OPS(rk3x_i2c_pm_ops, NULL, rk3x_i2c_resume);
+
 static struct platform_driver rk3x_i2c_driver = {
 	.probe   = rk3x_i2c_probe,
 	.remove  = rk3x_i2c_remove,
 	.driver  = {
 		.name  = "rk3x-i2c",
 		.of_match_table = rk3x_i2c_match,
+		.pm = &rk3x_i2c_pm_ops,
 	},
 };
 
-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: rk3x: Restore clock settings at resume time
  2016-08-29 21:22 [PATCH] i2c: rk3x: Restore clock settings at resume time Douglas Anderson
@ 2016-09-01  2:10 ` David.Wu
  2016-09-08 20:50 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: David.Wu @ 2016-09-01  2:10 UTC (permalink / raw)
  To: Douglas Anderson, wsa, heiko
  Cc: linux-rockchip, wxt, linux-arm-kernel, linux-i2c, linux-kernel

Hi Doug,

Last replied email HTML HEAD error, resend it.

在 2016/8/30 5:22, Douglas Anderson 写道:
> Depending on a number of factors including:
> - Which exact Rockchip SoC we're working with
> - How deep we suspend
> - Which i2c port we're on
>
> We might lose the state of the i2c registers at suspend time.
> Specifically we've found that on rk3399 the i2c ports that are not in
> the PMU power domain lose their state with the current suspend depth
> configured by ARM Tursted Firmware.
>
> Note that there are very few actual i2c registers that aren't configured
> per transfer anyway so all we actually need to re-configure are the
> clock config registers.  We'll just add a call to rk3x_i2c_adapt_div()
> at resume time and be done with it.
>
> NOTE: On rk3399 on ports whose power was lost, I put printouts in at
> resume time.  I saw things like:
>   before: con=0x00010300, div=0x00060006
>   after:  con=0x00010200, div=0x00180025
>

I do the suspend/resume stress test on my rk3399 & rk3288 board more 
than 24 hours,

the patch works well, it looks nice to me.

Reviewed-by: David Wu <david.wu@rock-chips.com>
Tested-by: David Wu <david.wu@rock-chips.com>

> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
> Tested on chromeos-4.4 kernel with backports.
>
> drivers/i2c/busses/i2c-rk3x.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
> index 3b87afe82f63..0df5ad6bfa31 100644
> --- a/drivers/i2c/busses/i2c-rk3x.c
> +++ b/drivers/i2c/busses/i2c-rk3x.c
> @@ -1111,6 +1111,15 @@ static int rk3x_i2c_xfer(struct i2c_adapter *adap,
>  	return ret < 0 ? ret : num;
>  }
>
> +static __maybe_unused int rk3x_i2c_resume(struct device *dev)
> +{
> +	struct rk3x_i2c *i2c = dev_get_drvdata(dev);
> +
> +	rk3x_i2c_adapt_div(i2c, clk_get_rate(i2c->clk));
> +
> +	return 0;
> +}
> +
>  static u32 rk3x_i2c_func(struct i2c_adapter *adap)
>  {
>  	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
> @@ -1332,12 +1341,15 @@ static int rk3x_i2c_remove(struct platform_device *pdev)
>  	return 0;
>  }
>
> +static const SIMPLE_DEV_PM_OPS(rk3x_i2c_pm_ops, NULL, rk3x_i2c_resume);
> +
>  static struct platform_driver rk3x_i2c_driver = {
>  	.probe   = rk3x_i2c_probe,
>  	.remove  = rk3x_i2c_remove,
>  	.driver  = {
>  		.name  = "rk3x-i2c",
>  		.of_match_table = rk3x_i2c_match,
> +		.pm = &rk3x_i2c_pm_ops,
>  	},
>  };
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: rk3x: Restore clock settings at resume time
  2016-08-29 21:22 [PATCH] i2c: rk3x: Restore clock settings at resume time Douglas Anderson
  2016-09-01  2:10 ` David.Wu
@ 2016-09-08 20:50 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2016-09-08 20:50 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: heiko, linux-rockchip, david.wu, wxt, linux-arm-kernel,
	linux-i2c, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]

On Mon, Aug 29, 2016 at 02:22:36PM -0700, Douglas Anderson wrote:
> Depending on a number of factors including:
> - Which exact Rockchip SoC we're working with
> - How deep we suspend
> - Which i2c port we're on
> 
> We might lose the state of the i2c registers at suspend time.
> Specifically we've found that on rk3399 the i2c ports that are not in
> the PMU power domain lose their state with the current suspend depth
> configured by ARM Tursted Firmware.
> 
> Note that there are very few actual i2c registers that aren't configured
> per transfer anyway so all we actually need to re-configure are the
> clock config registers.  We'll just add a call to rk3x_i2c_adapt_div()
> at resume time and be done with it.
> 
> NOTE: On rk3399 on ports whose power was lost, I put printouts in at
> resume time.  I saw things like:
>   before: con=0x00010300, div=0x00060006
>   after:  con=0x00010200, div=0x00180025
> 
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Fixed the code checker warnings:

    SPARSE
drivers/i2c/busses/i2c-rk3x.c:1346:14: warning: duplicate const
    SMATCH
drivers/i2c/busses/i2c-rk3x.c:1346:14: warning: duplicate const

and applied to for-current, thanks!


Note my code checkers also say this (unrelated to your patch):

    SPARSE
drivers/i2c/busses/i2c-rk3x.c:888:17: warning: cast truncates bits from constant value (ffffffffff00 becomes ffffff00)

  CC      drivers/i2c/busses/i2c-rk3x.o
drivers/i2c/busses/i2c-rk3x.c: In function 'rk3x_i2c_v1_calc_timings':
drivers/i2c/busses/i2c-rk3x.c:745:41: warning: variable 'min_total_ns' set but not used [-Wunused-but-set-variable]

I haven't checked those, though...


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-08 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-29 21:22 [PATCH] i2c: rk3x: Restore clock settings at resume time Douglas Anderson
2016-09-01  2:10 ` David.Wu
2016-09-08 20:50 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).