For I2c to operate correctly under all speed mode, sda-hold-time need to
be perfectly tuned. However, sda-hold-time is precalculated according to
circuit parameter which make it platform-specific.
In order to get accurate sda-hold-time for all platforms, pretuned
sda-hold-time for particular platform is stored in ACPI table and driver
to load the sda holding time from ACPI table.
This patch read the I2c sda-hold-time from ACPI table and assigned the
suitable hold time based on the i2c clock frequency.
Tested on Intel Apollo Lake.
Changes in V3:
- Remove null handling in function dw_i2c_acpi_params.
- Add descriptions to commit message.
Changes in V2:
- The code is realigned according to suggestion.
- "case 400000:" is added on top of "default:" for readability.
Tan Chin Yew (1):
i2c: designware: Get selected speed mode sda-hold-time via ACPI
drivers/i2c/busses/i2c-designware-platdrv.c | 31 ++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
--
1.9.1
Sda-hold-time is an important parameter for tuning i2c to meet the
electrical specification especially for high speed. I2C with incorrect
sda-hold-time may cause lost arbitration error. Instead of loading all
speed mode settings, only selected speed mode settings are loaded.
Signed-off-by: Tan Chin Yew <[email protected]>
---
drivers/i2c/busses/i2c-designware-platdrv.c | 31 ++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index a597ba32..5a4eb6b 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -85,8 +85,7 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[],
*hcnt = (u16)objs[0].integer.value;
*lcnt = (u16)objs[1].integer.value;
- if (sda_hold)
- *sda_hold = (u32)objs[2].integer.value;
+ *sda_hold = (u32)objs[2].integer.value;
}
kfree(buf.pointer);
@@ -105,14 +104,28 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
dev->rx_fifo_depth = 32;
/*
- * Try to get SDA hold time and *CNT values from an ACPI method if
- * it exists for both supported speed modes.
+ * Try to get SDA hold time and *CNT values from an ACPI method for
+ * selected speed modes.
*/
- dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt, NULL);
- dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt,
- &dev->sda_hold_time);
- dw_i2c_acpi_params(pdev, "FPCN", &dev->fp_hcnt, &dev->fp_lcnt, NULL);
- dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev->hs_lcnt, NULL);
+ switch (dev->clk_freq) {
+ case 100000:
+ dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt,
+ &dev->sda_hold_time);
+ break;
+ case 1000000:
+ dw_i2c_acpi_params(pdev, "FPCN", &dev->fp_hcnt, &dev->fp_lcnt,
+ &dev->sda_hold_time);
+ break;
+ case 3400000:
+ dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev->hs_lcnt,
+ &dev->sda_hold_time);
+ break;
+ case 400000:
+ default:
+ dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt,
+ &dev->sda_hold_time);
+ break;
+ }
id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev);
if (id && id->driver_data)
--
1.9.1
On Tue, 2017-03-28 at 16:48 +0800, Tan Chin Yew wrote:
> Sda-hold-time is an important parameter for tuning i2c to meet the
> electrical specification especially for high speed. I2C with incorrect
> sda-hold-time may cause lost arbitration error. Instead of loading all
> speed mode settings, only selected speed mode settings are loaded.
>
> Signed-off-by: Tan Chin Yew <[email protected]>
Looks good to me:
Reviewed-by: Andy Shevchenko <[email protected]>
> ---
> drivers/i2c/busses/i2c-designware-platdrv.c | 31
> ++++++++++++++++++++---------
> 1 file changed, 22 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c
> b/drivers/i2c/busses/i2c-designware-platdrv.c
> index a597ba32..5a4eb6b 100644
> --- a/drivers/i2c/busses/i2c-designware-platdrv.c
> +++ b/drivers/i2c/busses/i2c-designware-platdrv.c
> @@ -85,8 +85,7 @@ static void dw_i2c_acpi_params(struct
> platform_device *pdev, char method[],
>
> *hcnt = (u16)objs[0].integer.value;
> *lcnt = (u16)objs[1].integer.value;
> - if (sda_hold)
> - *sda_hold = (u32)objs[2].integer.value;
> + *sda_hold = (u32)objs[2].integer.value;
> }
>
> kfree(buf.pointer);
> @@ -105,14 +104,28 @@ static int dw_i2c_acpi_configure(struct
> platform_device *pdev)
> dev->rx_fifo_depth = 32;
>
> /*
> - * Try to get SDA hold time and *CNT values from an ACPI
> method if
> - * it exists for both supported speed modes.
> + * Try to get SDA hold time and *CNT values from an ACPI
> method for
> + * selected speed modes.
> */
> - dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev-
> >ss_lcnt, NULL);
> - dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev-
> >fs_lcnt,
> - &dev->sda_hold_time);
> - dw_i2c_acpi_params(pdev, "FPCN", &dev->fp_hcnt, &dev-
> >fp_lcnt, NULL);
> - dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev-
> >hs_lcnt, NULL);
> + switch (dev->clk_freq) {
> + case 100000:
> + dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev-
> >ss_lcnt,
> + &dev->sda_hold_time);
> + break;
> + case 1000000:
> + dw_i2c_acpi_params(pdev, "FPCN", &dev->fp_hcnt, &dev-
> >fp_lcnt,
> + &dev->sda_hold_time);
> + break;
> + case 3400000:
> + dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev-
> >hs_lcnt,
> + &dev->sda_hold_time);
> + break;
> + case 400000:
> + default:
> + dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev-
> >fs_lcnt,
> + &dev->sda_hold_time);
> + break;
> + }
>
> id = acpi_match_device(pdev->dev.driver->acpi_match_table,
> &pdev->dev);
> if (id && id->driver_data)
--
Andy Shevchenko <[email protected]>
Intel Finland Oy
On 03/28/2017 12:13 PM, Andy Shevchenko wrote:
> On Tue, 2017-03-28 at 16:48 +0800, Tan Chin Yew wrote:
>> Sda-hold-time is an important parameter for tuning i2c to meet the
>> electrical specification especially for high speed. I2C with incorrect
>> sda-hold-time may cause lost arbitration error. Instead of loading all
>> speed mode settings, only selected speed mode settings are loaded.
>>
>> Signed-off-by: Tan Chin Yew <[email protected]>
>
>
> Looks good to me:
>
> Reviewed-by: Andy Shevchenko <[email protected]>
>
Acked-by: Jarkko Nikula <[email protected]>
On Tue, Mar 28, 2017 at 04:48:02PM +0800, Tan Chin Yew wrote:
> Sda-hold-time is an important parameter for tuning i2c to meet the
> electrical specification especially for high speed. I2C with incorrect
> sda-hold-time may cause lost arbitration error. Instead of loading all
> speed mode settings, only selected speed mode settings are loaded.
>
> Signed-off-by: Tan Chin Yew <[email protected]>
Applied to for-next, thanks!