linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD
@ 2016-08-27  7:39 Zhuo-hao Lee
  2016-08-28 12:31 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Zhuo-hao Lee @ 2016-08-27  7:39 UTC (permalink / raw)
  To: jarkko.nikula, andriy.shevchenko, mika.westerberg, wsa, linux-i2c
  Cc: zhuo-hao.lee, linux-kernel

There are several ways to set the SDA hold time for i2c controller,
including: Device Tree, built-in device properties and ACPI. However,
if the SDA hold time is not specified by above method, we should
read the value, where it is preset by firmware, and save it to
sda_hold_time. This is needed because when i2c controller enters
runtime suspend, the DW_IC_SDA_HOLD value will be reset to chipset
default value. And during runtime resume, i2c_dw_init will be called
to reconfigure i2c controller. If sda_hold_time is zero, the chipset
default hold time will be used, that will be too short for some
platforms. Therefore, to have a better tolerance, the DW_IC_SDA_HOLD
value should be kept by sda_hold_time.

Signed-off-by: Zhuo-hao Lee <zhuo-hao.lee@intel.com>
---
 drivers/i2c/busses/i2c-designware-core.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index c6922b8..fcd973d 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -367,13 +367,17 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 	dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
 
 	/* Configure SDA Hold Time if required */
-	if (dev->sda_hold_time) {
-		reg = dw_readl(dev, DW_IC_COMP_VERSION);
-		if (reg >= DW_IC_SDA_HOLD_MIN_VERS)
+	reg = dw_readl(dev, DW_IC_COMP_VERSION);
+	if (reg >= DW_IC_SDA_HOLD_MIN_VERS) {
+		if (dev->sda_hold_time) {
 			dw_writel(dev, dev->sda_hold_time, DW_IC_SDA_HOLD);
-		else
-			dev_warn(dev->dev,
-				"Hardware too old to adjust SDA hold time.");
+		} else {
+			/* Keep previous hold time setting if no one set it */
+			dev->sda_hold_time = dw_readl(dev, DW_IC_SDA_HOLD);
+		}
+	} else {
+		dev_warn(dev->dev,
+			"Hardware too old to adjust SDA hold time.\n");
 	}
 
 	/* Configure Tx/Rx FIFO threshold levels */
-- 
1.9.1

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

* Re: [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD
  2016-08-27  7:39 [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD Zhuo-hao Lee
@ 2016-08-28 12:31 ` Andy Shevchenko
  2016-08-29  6:17   ` Jarkko Nikula
  2016-08-30 20:59 ` Wolfram Sang
  2016-09-08 20:18 ` Wolfram Sang
  2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2016-08-28 12:31 UTC (permalink / raw)
  To: Zhuo-hao Lee, jarkko.nikula, mika.westerberg, wsa, linux-i2c; +Cc: linux-kernel

On Sat, 2016-08-27 at 15:39 +0800, Zhuo-hao Lee wrote:
> There are several ways to set the SDA hold time for i2c controller,
> including: Device Tree, built-in device properties and ACPI. However,
> if the SDA hold time is not specified by above method, we should
> read the value, where it is preset by firmware, and save it to
> sda_hold_time. This is needed because when i2c controller enters
> runtime suspend, the DW_IC_SDA_HOLD value will be reset to chipset
> default value. And during runtime resume, i2c_dw_init will be called
> to reconfigure i2c controller. If sda_hold_time is zero, the chipset
> default hold time will be used, that will be too short for some
> platforms. Therefore, to have a better tolerance, the DW_IC_SDA_HOLD
> value should be kept by sda_hold_time.

Looks good to me.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> 
> Signed-off-by: Zhuo-hao Lee <zhuo-hao.lee@intel.com>
> ---
>  drivers/i2c/busses/i2c-designware-core.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.c
> b/drivers/i2c/busses/i2c-designware-core.c
> index c6922b8..fcd973d 100644
> --- a/drivers/i2c/busses/i2c-designware-core.c
> +++ b/drivers/i2c/busses/i2c-designware-core.c
> @@ -367,13 +367,17 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
>  	dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt,
> lcnt);
>  
>  	/* Configure SDA Hold Time if required */
> -	if (dev->sda_hold_time) {
> -		reg = dw_readl(dev, DW_IC_COMP_VERSION);
> -		if (reg >= DW_IC_SDA_HOLD_MIN_VERS)
> +	reg = dw_readl(dev, DW_IC_COMP_VERSION);
> +	if (reg >= DW_IC_SDA_HOLD_MIN_VERS) {
> +		if (dev->sda_hold_time) {
>  			dw_writel(dev, dev->sda_hold_time,
> DW_IC_SDA_HOLD);
> -		else
> -			dev_warn(dev->dev,
> -				"Hardware too old to adjust SDA hold
> time.");
> +		} else {
> +			/* Keep previous hold time setting if no one
> set it */
> +			dev->sda_hold_time = dw_readl(dev,
> DW_IC_SDA_HOLD);
> +		}
> +	} else {
> +		dev_warn(dev->dev,
> +			"Hardware too old to adjust SDA hold
> time.\n");
>  	}
>  
>  	/* Configure Tx/Rx FIFO threshold levels */

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

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

* Re: [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD
  2016-08-28 12:31 ` Andy Shevchenko
@ 2016-08-29  6:17   ` Jarkko Nikula
  0 siblings, 0 replies; 6+ messages in thread
From: Jarkko Nikula @ 2016-08-29  6:17 UTC (permalink / raw)
  To: Andy Shevchenko, Zhuo-hao Lee, mika.westerberg, wsa, linux-i2c
  Cc: linux-kernel

On 08/28/2016 03:31 PM, Andy Shevchenko wrote:
> On Sat, 2016-08-27 at 15:39 +0800, Zhuo-hao Lee wrote:
>> There are several ways to set the SDA hold time for i2c controller,
>> including: Device Tree, built-in device properties and ACPI. However,
>> if the SDA hold time is not specified by above method, we should
>> read the value, where it is preset by firmware, and save it to
>> sda_hold_time. This is needed because when i2c controller enters
>> runtime suspend, the DW_IC_SDA_HOLD value will be reset to chipset
>> default value. And during runtime resume, i2c_dw_init will be called
>> to reconfigure i2c controller. If sda_hold_time is zero, the chipset
>> default hold time will be used, that will be too short for some
>> platforms. Therefore, to have a better tolerance, the DW_IC_SDA_HOLD
>> value should be kept by sda_hold_time.
>
> Looks good to me.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

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

* Re: [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD
  2016-08-27  7:39 [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD Zhuo-hao Lee
  2016-08-28 12:31 ` Andy Shevchenko
@ 2016-08-30 20:59 ` Wolfram Sang
  2016-08-31  0:24   ` Lee, Zhuo-hao
  2016-09-08 20:18 ` Wolfram Sang
  2 siblings, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2016-08-30 20:59 UTC (permalink / raw)
  To: Zhuo-hao Lee
  Cc: jarkko.nikula, andriy.shevchenko, mika.westerberg, linux-i2c,
	linux-kernel

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

On Sat, Aug 27, 2016 at 03:39:30PM +0800, Zhuo-hao Lee wrote:
> There are several ways to set the SDA hold time for i2c controller,
> including: Device Tree, built-in device properties and ACPI. However,
> if the SDA hold time is not specified by above method, we should
> read the value, where it is preset by firmware, and save it to
> sda_hold_time. This is needed because when i2c controller enters
> runtime suspend, the DW_IC_SDA_HOLD value will be reset to chipset
> default value. And during runtime resume, i2c_dw_init will be called
> to reconfigure i2c controller. If sda_hold_time is zero, the chipset
> default hold time will be used, that will be too short for some
> platforms. Therefore, to have a better tolerance, the DW_IC_SDA_HOLD
> value should be kept by sda_hold_time.
> 
> Signed-off-by: Zhuo-hao Lee <zhuo-hao.lee@intel.com>

Looks good. But is it a bugfix? Looks more like for-next material to me,
but not sure...


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

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

* RE: [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD
  2016-08-30 20:59 ` Wolfram Sang
@ 2016-08-31  0:24   ` Lee, Zhuo-hao
  0 siblings, 0 replies; 6+ messages in thread
From: Lee, Zhuo-hao @ 2016-08-31  0:24 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: jarkko.nikula, andriy.shevchenko, mika.westerberg, linux-i2c,
	linux-kernel

>On Sat, Aug 27, 2016 at 03:39:30PM +0800, Zhuo-hao Lee wrote:
>> There are several ways to set the SDA hold time for i2c controller,
>> including: Device Tree, built-in device properties and ACPI. However, 
>> if the SDA hold time is not specified by above method, we should read 
>> the value, where it is preset by firmware, and save it to 
>> sda_hold_time. This is needed because when i2c controller enters 
>> runtime suspend, the DW_IC_SDA_HOLD value will be reset to chipset 
>> default value. And during runtime resume, i2c_dw_init will be called 
>> to reconfigure i2c controller. If sda_hold_time is zero, the chipset 
>> default hold time will be used, that will be too short for some 
>> platforms. Therefore, to have a better tolerance, the DW_IC_SDA_HOLD 
>> value should be kept by sda_hold_time.
>> 
>> Signed-off-by: Zhuo-hao Lee <zhuo-hao.lee@intel.com>

>Looks good. But is it a bugfix? Looks more like for-next material to me, but not sure...
Yes, as least for me, this is a bug.
This is an error handling in case Device Tree, built-in device properties and ACPI were not set 
the SDA hold time. We should use the firmware setting instead of chipset reset value. 

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

* Re: [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD
  2016-08-27  7:39 [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD Zhuo-hao Lee
  2016-08-28 12:31 ` Andy Shevchenko
  2016-08-30 20:59 ` Wolfram Sang
@ 2016-09-08 20:18 ` Wolfram Sang
  2 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2016-09-08 20:18 UTC (permalink / raw)
  To: Zhuo-hao Lee
  Cc: jarkko.nikula, andriy.shevchenko, mika.westerberg, linux-i2c,
	linux-kernel

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

On Sat, Aug 27, 2016 at 03:39:30PM +0800, Zhuo-hao Lee wrote:
> There are several ways to set the SDA hold time for i2c controller,
> including: Device Tree, built-in device properties and ACPI. However,
> if the SDA hold time is not specified by above method, we should
> read the value, where it is preset by firmware, and save it to
> sda_hold_time. This is needed because when i2c controller enters
> runtime suspend, the DW_IC_SDA_HOLD value will be reset to chipset
> default value. And during runtime resume, i2c_dw_init will be called
> to reconfigure i2c controller. If sda_hold_time is zero, the chipset
> default hold time will be used, that will be too short for some
> platforms. Therefore, to have a better tolerance, the DW_IC_SDA_HOLD
> value should be kept by sda_hold_time.
> 
> Signed-off-by: Zhuo-hao Lee <zhuo-hao.lee@intel.com>

Applied to for-current, thanks!


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

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-27  7:39 [PATCH v1] i2c: designware: save the preset value of DW_IC_SDA_HOLD Zhuo-hao Lee
2016-08-28 12:31 ` Andy Shevchenko
2016-08-29  6:17   ` Jarkko Nikula
2016-08-30 20:59 ` Wolfram Sang
2016-08-31  0:24   ` Lee, Zhuo-hao
2016-09-08 20:18 ` 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).