i2c-designware: make SDA hold time configurable
Subsystems (5)
Mika Westerberg
maintainerQuoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>
Hi Wolfram,
What happened to this patch? I don't see it merged for 3.10.
The reason I'm asking is that I would like to add ACPI support for the SDA hold time parameter analogous to the DT version.
Thanks.
Quoted 101 lines
--- .../devicetree/bindings/i2c/i2c-designware.txt | 14 ++++++++++++++ drivers/i2c/busses/i2c-designware-core.c | 5 +++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 9 +++++++++ 4 files changed, 29 insertions(+), 0 deletions(-)Documentation/devicetree/bindings/i2c/i2c-designware.txt +14
-0@@ -10,6 +10,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. +Optional properties : + - sda-hold-time : should contain the SDA hold time in nanoseconds. + Example : i2c@f0000 {@@ -20,3 +23,14 @@ Example : interrupts = <11>; clock-frequency = <400000>; }; + + i2c@1120000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x1120000 0x1000>; + interrupt-parent = <&ictl>; + interrupts = <12 1>; + clock-frequency = <400000>; + sda-hold-time = <300>; + };drivers/i2c/busses/i2c-designware-core.c +5
-0@@ -67,6 +67,7 @@#define DW_IC_STATUS 0x70#define DW_IC_TXFLR 0x74#define DW_IC_RXFLR 0x78 +#define DW_IC_SDA_HOLD 0x7c#define DW_IC_TX_ABRT_SOURCE 0x80#define DW_IC_COMP_PARAM_1 0xf4#define DW_IC_COMP_TYPE 0xfc@@ -310,6 +311,10 @@ int i2c_dw_init(struct dw_i2c_dev *dev)dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT );dev_dbg (dev->dev,"Fast-mode HCNT:LCNT = %d:%d\n" , hcnt, lcnt); +/* Configure SDA Hold Time if required */ +if (dev->sda_hold_time) +dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); +/* Configure Tx/Rx FIFO threshold levels */ dw_writel (dev, dev->tx_fifo_depth -1 ,DW_IC_TX_TL );dw_writel (dev,0 ,DW_IC_RX_TL );drivers/i2c/busses/i2c-designware-core.h +1
-0@@ -88,6 +88,7 @@ struct dw_i2c_dev {u32 master_cfg;unsigned int tx_fifo_depth;unsigned int rx_fifo_depth; +u32 sda_hold_time; };#define ACCESS_SWAP 0x00000001drivers/i2c/busses/i2c-designware-platdrv.c +9
-0@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/err.h> #include <linux/interrupt.h> +#include <linux/of.h> #include <linux/of_i2c.h> #include <linux/platform_device.h> #include <linux/pm.h> @@ -136,6 +137,14 @@ static int dw_i2c_probe(struct platform_device *pdev) }clk_prepare_enable (dev->clk); +if (pdev->dev.of_node) { +u32 ht; +u32 ic_clk = dev->get_clk_rate_khz (dev); + +of_property_read_u32 (pdev->dev.of_node,"sda-hold-time" , &ht); + dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + } + dev->functionality =I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |Signature · 1 line
1.7.1
PATCH 1/1 i2c-designware: make SDA hold time configurable
This patch makes the SDA hold time configurable through device tree.
[rebased to i2c-current/i2c-next/mainline-3.10-rc1]
--- .../devicetree/bindings/i2c/i2c-designware.txt | 14 ++++++++++++++ drivers/i2c/busses/i2c-designware-core.c | 5 +++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 9 +++++++++ 4 files changed, 29 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-designware.txt +14 -0
@@ -10,6 +10,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. +Optional properties : + - sda-hold-time : should contain the SDA hold time in nanoseconds. + Example : i2c@f0000 {
@@ -20,3 +23,14 @@ Example : interrupts = <11>; clock-frequency = <400000>; }; + + i2c@1120000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x1120000 0x1000>; + interrupt-parent = <&ictl>; + interrupts = <12 1>; + clock-frequency = <400000>; + sda-hold-time = <300>; + };
drivers/i2c/busses/i2c-designware-core.c +5 -0
@@ -67,6 +67,7 @@#define DW_IC_STATUS 0x70#define DW_IC_TXFLR 0x74#define DW_IC_RXFLR 0x78 +#define DW_IC_SDA_HOLD 0x7c#define DW_IC_TX_ABRT_SOURCE 0x80#define DW_IC_ENABLE_STATUS 0x9c#define DW_IC_COMP_PARAM_1 0xf4
@@ -332,6 +333,10 @@ int i2c_dw_init(struct dw_i2c_dev *dev)dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT );dev_dbg (dev->dev,"Fast-mode HCNT:LCNT = %d:%d\n" , hcnt, lcnt); +/* Configure SDA Hold Time if required */ +if (dev->sda_hold_time) +dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); +/* Configure Tx/Rx FIFO threshold levels */ dw_writel (dev, dev->tx_fifo_depth -1 ,DW_IC_TX_TL );dw_writel (dev,0 ,DW_IC_RX_TL );
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -88,6 +88,7 @@ struct dw_i2c_dev {u32 master_cfg;unsigned int tx_fifo_depth;unsigned int rx_fifo_depth; +u32 sda_hold_time; };#define ACCESS_SWAP 0x00000001
drivers/i2c/busses/i2c-designware-platdrv.c +9 -0
@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/err.h> #include <linux/interrupt.h> +#include <linux/of.h> #include <linux/of_i2c.h> #include <linux/platform_device.h> #include <linux/pm.h>
@@ -120,6 +121,14 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +if (pdev->dev.of_node) { +u32 ht; +u32 ic_clk = dev->get_clk_rate_khz (dev); + +of_property_read_u32 (pdev->dev.of_node,"sda-hold-time" , &ht); + dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + } + dev->functionality =I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |
Signature · 1 line
1.7.1
Quoted 6 lines · Mika Westerberg
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>
Quoted 6 lines
Hi Wolfram,
What happened to this patch? I don't see it merged for 3.10.
The reason I'm asking is that I would like to add ACPI support for the SDA hold time parameter analogous to the DT version.
New bindings are complicated. I need to check if there is an existing/similar one, check if it is generic enough for drivers still to come, etc. I didn't have the time to do this for 3.10, so it is 3.11 material.
Mika Westerberg
maintainerQuoted 11 lines · Wolfram Sang
Quoted 10 lines · Mika Westerberg
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Hi Wolfram,
What happened to this patch? I don't see it merged for 3.10.
Quoted 7 lines
Quoted 2 lines
The reason I'm asking is that I would like to add ACPI support for the SDA hold time parameter analogous to the DT version.
New bindings are complicated. I need to check if there is an existing/similar one, check if it is generic enough for drivers still to come, etc. I didn't have the time to do this for 3.10, so it is 3.11 material.
OK, thanks. I just wanted to be sure this patch wasn't forgotten as it is useful for Haswell/Lynxpoint as well.
Quoted 8 lines
Quoted 5 lines
New bindings are complicated. I need to check if there is an existing/similar one, check if it is generic enough for drivers still to come, etc. I didn't have the time to do this for 3.10, so it is 3.11 material.
OK, thanks. I just wanted to be sure this patch wasn't forgotten as it is useful for Haswell/Lynxpoint as well.
i2c list is monitored by patchwork which is rigorously not forgetting ;)
Quoted 6 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
[rebased to i2c-current/i2c-next/mainline-3.10-rc1]
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>
Hmm, I really have problems adding a generic property. I need to better understand why this is needed? What is the usecase? Can't a safe value be calculated depending on the bus-speed? Is there a public datasheet available somewhere?
Thanks,
Wolfram
Quoted 5 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
[rebased to i2c-current/i2c-next/mainline-3.10-rc1]
Quoted 7 lines
Quoted 2 lines
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Hmm, I really have problems adding a generic property. I need to better understand why this is needed? What is the usecase? Can't a safe value be calculated depending on the bus-speed? Is there a public datasheet available somewhere?
I checked with our PCB/Applications team and the data sheets for the peripherals in question (DVB demodulator front ends) are under NDA. Mika, you seem to be interested in this patch as well. Do you know of any publicly available data sheets for hardware requiring this adjustment?
In the case of the Designware block, the parameter both changes SDA and START hold times, however, and you'll find lots of data sheets for hardware with START hold time requirements on the net, e.g.
http://ww1.microchip.com/downloads/en/DeviceDoc/21805B.pdf
The empirical solution in the function i2c_dw_scl_hcnt does not seem to work in all cases: Our lab guys confirmed that we have several PCB designs which do not work without adjusting the sda-hold-time parameter to an appropriate value. The value seems to be different for different PCBs.
I suspect that this kind of configurability is not the same for all i2c bus master hardware. If you don't want to add a generic property, would you accept the patch with the property renamed to dwi2c,sda-hold-time?
Greetings,
Christian
Signature · 4 lines
Christian Ruppert , <[email protected]> /| Tel: +41/(0)22 816 19-42 //| 3, Chemin du Pré-Fleuri _// | bilis Systems CH-1228 Plan-les-Ouates
Mika Westerberg
maintainerQuoted 14 lines · Christian Ruppert
Quoted 5 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
[rebased to i2c-current/i2c-next/mainline-3.10-rc1]
Quoted 7 lines
Quoted 2 lines
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Hmm, I really have problems adding a generic property. I need to better understand why this is needed? What is the usecase? Can't a safe value be calculated depending on the bus-speed? Is there a public datasheet available somewhere?
Quoted 5 lines
I checked with our PCB/Applications team and the data sheets for the peripherals in question (DVB demodulator front ends) are under NDA. Mika, you seem to be interested in this patch as well. Do you know of any publicly available data sheets for hardware requiring this adjustment?
Sorry for the delay, I was on vacation.
I'm not aware of any publicly available datasheets for this block, unfortunately.
Quoted 10 lines
In the case of the Designware block, the parameter both changes SDA and START hold times, however, and you'll find lots of data sheets for hardware with START hold time requirements on the net, e.g.
http://ww1.microchip.com/downloads/en/DeviceDoc/21805B.pdfThe empirical solution in the function
i2c_dw_scl_hcntdoes not seem to work in all cases: Our lab guys confirmed that we have several PCB designs which do not work without adjusting the sda-hold-time parameter to an appropriate value. The value seems to be different for different PCBs.
Yeah, we see the same problem. Our platform guys have solved this so that they made the SDA hold time available from ACPI to the device driver.
Quoted 13 lines
I suspect that this kind of configurability is not the same for all i2c bus master hardware. If you don't want to add a generic property, would you accept the patch with the property renamed to dwi2c,sda-hold-time?
Greetings,
ChristianSignature · 4 lines
Christian Ruppert , <[email protected]> /| Tel: +41/(0)22 816 19-42 //| 3, Chemin du Pré-Fleuri _// | bilis Systems CH-1228 Plan-les-Ouates
Quoted 18 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
[rebased to i2c-current/i2c-next/mainline-3.10-rc1]
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>--- .../devicetree/bindings/i2c/i2c-designware.txt | 14 ++++++++++++++ drivers/i2c/busses/i2c-designware-core.c | 5 +++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 9 +++++++++ 4 files changed, 29 insertions(+), 0 deletions(-)Documentation/devicetree/bindings/i2c/i2c-designware.txt +0
-0
Documentation/devicetree/bindings/i2c/i2c-designware.txt Recommended properties : · line 14
Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-designware.txt +2
-0@@ -10,6 +10,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. +Optional properties : + - sda-hold-time : should contain the SDA hold time in nanoseconds.
Please specify time units in the property name. Perhaps i2c-sda-hold-time-ns.
Based on reading the discussion, there is one similar property I have
found: "samsung,i2c-sda-delay = <100>". I wouldn't copy it as it doesn't tell the units or what the delay is.
Otherwise, looks fine to me.
Rob
Quoted 82 lines
Documentation/devicetree/bindings/i2c/i2c-designware.txt +12
-0+ Example : i2c@f0000 {@@ -20,3 +23,14 @@ Example : interrupts = <11>; clock-frequency = <400000>; }; + + i2c@1120000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x1120000 0x1000>; + interrupt-parent = <&ictl>; + interrupts = <12 1>; + clock-frequency = <400000>; + sda-hold-time = <300>; + };drivers/i2c/busses/i2c-designware-core.c +5
-0@@ -67,6 +67,7 @@#define DW_IC_STATUS 0x70#define DW_IC_TXFLR 0x74#define DW_IC_RXFLR 0x78 +#define DW_IC_SDA_HOLD 0x7c#define DW_IC_TX_ABRT_SOURCE 0x80#define DW_IC_ENABLE_STATUS 0x9c#define DW_IC_COMP_PARAM_1 0xf4@@ -332,6 +333,10 @@ int i2c_dw_init(struct dw_i2c_dev *dev)dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT );dev_dbg (dev->dev,"Fast-mode HCNT:LCNT = %d:%d\n" , hcnt, lcnt); +/* Configure SDA Hold Time if required */ +if (dev->sda_hold_time) +dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); +/* Configure Tx/Rx FIFO threshold levels */ dw_writel (dev, dev->tx_fifo_depth -1 ,DW_IC_TX_TL );dw_writel (dev,0 ,DW_IC_RX_TL );drivers/i2c/busses/i2c-designware-core.h +1
-0@@ -88,6 +88,7 @@ struct dw_i2c_dev {u32 master_cfg;unsigned int tx_fifo_depth;unsigned int rx_fifo_depth; +u32 sda_hold_time; };#define ACCESS_SWAP 0x00000001drivers/i2c/busses/i2c-designware-platdrv.c +9
-0@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/err.h> #include <linux/interrupt.h> +#include <linux/of.h> #include <linux/of_i2c.h> #include <linux/platform_device.h> #include <linux/pm.h> @@ -120,6 +121,14 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +if (pdev->dev.of_node) { +u32 ht; +u32 ic_clk = dev->get_clk_rate_khz (dev); + +of_property_read_u32 (pdev->dev.of_node,"sda-hold-time" , &ht); + dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + } + dev->functionality =I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |
PATCH v8 1/1 i2c-designware: make SDA hold time configurable
This patch makes the SDA hold time configurable through device tree.
--- .../devicetree/bindings/i2c/i2c-designware.txt | 14 ++++++++++++++ arch/arc/boot/dts/abilis_tb100_dvk.dts | 10 +++++----- arch/arc/boot/dts/abilis_tb101_dvk.dts | 10 +++++----- drivers/i2c/busses/i2c-designware-core.c | 5 +++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++++ 6 files changed, 40 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-designware.txt +14 -0
@@ -10,6 +10,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. +Optional properties : + - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds. + Example : i2c@f0000 {
@@ -20,3 +23,14 @@ Example : interrupts = <11>; clock-frequency = <400000>; }; + + i2c@1120000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x1120000 0x1000>; + interrupt-parent = <&ictl>; + interrupts = <12 1>; + clock-frequency = <400000>; + i2c-sda-hold-time-ns = <300>; + };
arch/arc/boot/dts/abilis_tb100_dvk.dts +5 -5
@@ -45,19 +45,19 @@ }; i2c0: i2c@FF120000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c1: i2c@FF121000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c2: i2c@FF122000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c3: i2c@FF123000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c4: i2c@FF124000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; leds {
arch/arc/boot/dts/abilis_tb101_dvk.dts +5 -5
@@ -45,19 +45,19 @@ }; i2c0: i2c@FF120000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c1: i2c@FF121000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c2: i2c@FF122000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c3: i2c@FF123000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c4: i2c@FF124000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; leds {
drivers/i2c/busses/i2c-designware-core.c +5 -0
@@ -67,6 +67,7 @@#define DW_IC_STATUS 0x70#define DW_IC_TXFLR 0x74#define DW_IC_RXFLR 0x78 +#define DW_IC_SDA_HOLD 0x7c#define DW_IC_TX_ABRT_SOURCE 0x80#define DW_IC_ENABLE_STATUS 0x9c#define DW_IC_COMP_PARAM_1 0xf4
@@ -332,6 +333,10 @@ int i2c_dw_init(struct dw_i2c_dev *dev)dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT );dev_dbg (dev->dev,"Fast-mode HCNT:LCNT = %d:%d\n" , hcnt, lcnt); +/* Configure SDA Hold Time if required */ +if (dev->sda_hold_time) +dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); +/* Configure Tx/Rx FIFO threshold levels */ dw_writel (dev, dev->tx_fifo_depth -1 ,DW_IC_TX_TL );dw_writel (dev,0 ,DW_IC_RX_TL );
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -90,6 +90,7 @@ struct dw_i2c_dev {unsigned int tx_fifo_depth;unsigned int rx_fifo_depth;int rx_outstanding; +u32 sda_hold_time; };#define ACCESS_SWAP 0x00000001
drivers/i2c/busses/i2c-designware-platdrv.c +10 -0
@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/err.h> #include <linux/interrupt.h> +#include <linux/of.h> #include <linux/of_i2c.h> #include <linux/platform_device.h> #include <linux/pm.h>
@@ -121,6 +122,15 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +if (pdev->dev.of_node) { +u32 ht; +u32 ic_clk = dev->get_clk_rate_khz (dev); + +of_property_read_u32 (pdev->dev.of_node, +"i2c-sda-hold-time-ns" , &ht); + dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + } + dev->functionality =I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |
Signature · 1 line
1.7.1
Quoted 9 lines · Rob Herring
Quoted 2 lines
+Optional properties :
+ - sda-hold-time : should contain the SDA hold time in nanoseconds.Please specify time units in the property name. Perhaps i2c-sda-hold-time-ns.
Based on reading the discussion, there is one similar property I have
found: "samsung,i2c-sda-delay = <100>". I wouldn't copy it as it doesn't tell the units or what the delay is.
Often on of the painful issues with DT models is the absence of the properties. Should someone create the property definition first under Documentation and _then_ patch everything around?
(Though I think better to think and create documents first and after program accordingly)
--
With Best Regards,
Andy Shevchenko
Hi,
Quoted 14 lines · Christian Ruppert
Quoted 5 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
[rebased to i2c-current/i2c-next/mainline-3.10-rc1]
Quoted 7 lines
Quoted 2 lines
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Hmm, I really have problems adding a generic property. I need to better understand why this is needed? What is the usecase? Can't a safe value be calculated depending on the bus-speed? Is there a public datasheet available somewhere?
Quoted 5 lines
I checked with our PCB/Applications team and the data sheets for the peripherals in question (DVB demodulator front ends) are under NDA. Mika, you seem to be interested in this patch as well. Do you know of any publicly available data sheets for hardware requiring this adjustment?
So, I looked around and found:
http://www.maximintegrated.com/app-notes/index.mvp/id/3268
which after thinking further about it gives me the following conclusions:
- sda-hold-time is a property/requirement of a device not following the I2C spec. It is not a property of the master!
- It should not be encoded in the devicetree, since the flaw is implicit to the device, so only the driver needs to know about it. I wonder about something like this in the i2c slave driver:
ret = i2c_request_sda_hold_time(client);
The core then can collect the requests and forward them to the host driver. This driver then can set up the hardware or return -EOPNOTSUPP and we can even warn the user that there might be problems ahead.
- I wonder if we really need to have a parameter time-in-ns? The specs cleary say 300ns, so I'd think this is the value we should always use. This is from a theorhetical pov though, maybe your practical experience is different. What values do you need?
Quoted 4 lines
In the case of the Designware block, the parameter both changes SDA and START hold times, however, and you'll find lots of data sheets for hardware with START hold time requirements on the net, e.g.
http://ww1.microchip.com/downloads/en/DeviceDoc/21805B.pdf
What I couldn't find is a reference manual for a designware IP that supports sda hold time? I found some spear SoC which do not have that register, so that should surely be reflected in the patchset, too.
Quoted 5 lines
The empirical solution in the function
i2c_dw_scl_hcntdoes not seem to work in all cases: Our lab guys confirmed that we have several PCB designs which do not work without adjusting the sda-hold-time parameter to an appropriate value. The value seems to be different for different PCBs.
I'd hope that 300ns is a safe value for all PCBs?
Quoted 2 lines
I suspect that this kind of configurability is not the same for all i2c bus master hardware.
Yeah, maybe some do sda-holding by default? Dunno, never checked for that detail.
Regards,
Wolfram
Quoted 23 lines · Wolfram Sang
Hi,
Quoted 14 lines · Christian Ruppert
Quoted 5 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
[rebased to i2c-current/i2c-next/mainline-3.10-rc1]
Quoted 7 lines
Quoted 2 lines
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Hmm, I really have problems adding a generic property. I need to better understand why this is needed? What is the usecase? Can't a safe value be calculated depending on the bus-speed? Is there a public datasheet available somewhere?
Quoted 5 lines
I checked with our PCB/Applications team and the data sheets for the peripherals in question (DVB demodulator front ends) are under NDA. Mika, you seem to be interested in this patch as well. Do you know of any publicly available data sheets for hardware requiring this adjustment?
Quoted 8 lines
So, I looked around and found:
http://www.maximintegrated.com/app-notes/index.mvp/id/3268which after thinking further about it gives me the following conclusions:
- sda-hold-time is a property/requirement of a device not following the I2C spec. It is not a property of the master!
Actually, in a protocol like I2C, every device on the bus must respect timing constraints like hold time etc. These parameters apply at the same time to the master and to all slaves.
Quoted 9 lines
- It should not be encoded in the devicetree, since the flaw is implicit to the device, so only the driver needs to know about it. I wonder about something like this in the i2c slave driver:
ret = i2c_request_sda_hold_time(client);The core then can collect the requests and forward them to the host driver. This driver then can set up the hardware or return
-EOPNOTSUPPand we can even warn the user that there might be problems ahead.
This might be a solution but given that many I2C drivers are written as an afterthought by device manufacturers and are released under more or less open terms of licensing into the wild I doubt this would work very well in practise.
Quoted 4 lines
- I wonder if we really need to have a parameter time-in-ns? The specs cleary say 300ns, so I'd think this is the value we should always use. This is from a theorhetical pov though, maybe your practical experience is different. What values do you need?
In reality, the I2C specification is more subtle than that: The "data hold time" is specified as 0ns with a footnote [3] stating that devices "must internally provide a hold time of at least 300ns for the SDA signal...".
Revision 5 contains a relatively understandable explanation about how to interpret this but earlier versions are less helpful. I think this confusion is at the root of many timing issues encountered with I2C (and the reason why Synopsys made this configurable). In fact, especially earlier specs are _all but_ clear in this point and we cannot assume that all peripherals were designed after Revision 5 was released in October 2012.
Quoted 8 lines
Quoted 4 lines
In the case of the Designware block, the parameter both changes SDA and START hold times, however, and you'll find lots of data sheets for hardware with START hold time requirements on the net, e.g.
http://ww1.microchip.com/downloads/en/DeviceDoc/21805B.pdfWhat I couldn't find is a reference manual for a designware IP that supports sda hold time? I found some spear SoC which do not have that register, so that should surely be reflected in the patchset, too.
If you have access to DesignWare documentation, check out the "DesignWare DW_apb_i2c Databook" Version 1.17a from March 2012. Unluckily, I clearly don't have the right to share this document with you. Do you know the version of the blocks in the spear SoC which do not support this register?
Quoted 7 lines
Quoted 5 lines
The empirical solution in the function
i2c_dw_scl_hcntdoes not seem to work in all cases: Our lab guys confirmed that we have several PCB designs which do not work without adjusting the sda-hold-time parameter to an appropriate value. The value seems to be different for different PCBs.I'd hope that 300ns is a safe value for all PCBs?
Not according to our PCB guys. The highest value I have found in a quick check of our device trees is 650ns with others being just slightly above 300ns.
Quoted 10 lines
Quoted 2 lines
I suspect that this kind of configurability is not the same for all i2c bus master hardware.
Yeah, maybe some do sda-holding by default? Dunno, never checked for that detail.
Regards,
Wolfram
Signature · 4 lines
Christian Ruppert , <[email protected]> /| Tel: +41/(0)22 816 19-42 //| 3, Chemin du Pré-Fleuri _// | bilis Systems CH-1228 Plan-les-Ouates
Hi Christian,
Quoted 6 lines
Quoted 6 lines
So, I looked around and found:
http://www.maximintegrated.com/app-notes/index.mvp/id/3268which after thinking further about it gives me the following conclusions:
Quoted 6 lines
Quoted 2 lines
- sda-hold-time is a property/requirement of a device not following the I2C spec. It is not a property of the master!
Actually, in a protocol like I2C, every device on the bus must respect timing constraints like hold time etc. These parameters apply at the same time to the master and to all slaves.
Yes. What I meant is: the flaw of one a specific device on the bus imposes the timing on the whole bus.
Quoted 7 lines
Quoted 7 lines
- It should not be encoded in the devicetree, since the flaw is implicit to the device, so only the driver needs to know about it. I wonder about something like this in the i2c slave driver:
ret = i2c_request_sda_hold_time(client);
Quoted 8 lines
Quoted 3 lines
The core then can collect the requests and forward them to the host driver. This driver then can set up the hardware or return
-EOPNOTSUPPand we can even warn the user that there might be problems ahead.This might be a solution but given that many I2C drivers are written as an afterthought by device manufacturers and are released under more or less open terms of licensing into the wild I doubt this would work very well in practise.
Hrmgl, the design looks much better to me, though. Once a driver is identified to need this, the core is able to report this requirement to a user who might even be unaware of the issue. The dt property has a bit of "try this if things don't work, you may be lucky" taste to it. Need to think about it. If PCB design also has an influence, then my idea won't work, though.
Quoted 10 lines
Quoted 4 lines
- I wonder if we really need to have a parameter time-in-ns? The specs cleary say 300ns, so I'd think this is the value we should always use. This is from a theorhetical pov though, maybe your practical experience is different. What values do you need?
In reality, the I2C specification is more subtle than that: The "data hold time" is specified as 0ns with a footnote [3] stating that devices "must internally provide a hold time of at least 300ns for the SDA signal...".
Quoted 7 lines
Revision 5 contains a relatively understandable explanation about how to interpret this but earlier versions are less helpful. I think this confusion is at the root of many timing issues encountered with I2C (and the reason why Synopsys made this configurable). In fact, especially earlier specs are
_allbut_clear in this point and we cannot assume that all peripherals were designed after Revision 5 was released in October 2012.
OK, agreed. Still surprised that I never encountered such a device, probably I was just lucky.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
In the case of the Designware block, the parameter both changes SDA and START hold times, however, and you'll find lots of data sheets for hardware with START hold time requirements on the net, e.g.
http://ww1.microchip.com/downloads/en/DeviceDoc/21805B.pdf
Quoted 6 lines
Quoted 3 lines
What I couldn't find is a reference manual for a designware IP that supports sda hold time? I found some spear SoC which do not have that register, so that should surely be reflected in the patchset, too.
If you have access to DesignWare documentation, check out the "DesignWare
DW_apb_i2cDatabook" Version 1.17a from March 2012.
I don't have, and I do have a hard time finding information about it otherwise :(
Quoted 3 lines
Unluckily, I clearly don't have the right to share this document with you. Do you know the version of the blocks in the spear SoC which do not support this register?
ST Spear300 and 600 have 0x3130352a in the version reg according to the refman.
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
The empirical solution in the function
i2c_dw_scl_hcntdoes not seem to work in all cases: Our lab guys confirmed that we have several PCB designs which do not work without adjusting the sda-hold-time parameter to an appropriate value. The value seems to be different for different PCBs.I'd hope that 300ns is a safe value for all PCBs?
Not according to our PCB guys. The highest value I have found in a quick check of our device trees is 650ns with others being just slightly above 300ns.
Thanks for sharing your results \o/ This helps me a lot. Can you find out/guess if this value is solely dependend on a slave or is it also dependend on PCB layout?
Thanks,
Wolfram
Hello Wolfram,
Quoted 17 lines · Wolfram Sang
[...]
Quoted 7 lines
Quoted 7 lines
- It should not be encoded in the devicetree, since the flaw is implicit to the device, so only the driver needs to know about it. I wonder about something like this in the i2c slave driver:
ret = i2c_request_sda_hold_time(client);Quoted 8 lines
Quoted 3 lines
The core then can collect the requests and forward them to the host driver. This driver then can set up the hardware or return
-EOPNOTSUPPand we can even warn the user that there might be problems ahead.This might be a solution but given that many I2C drivers are written as an afterthought by device manufacturers and are released under more or less open terms of licensing into the wild I doubt this would work very well in practise.
Quoted 6 lines
Hrmgl, the design looks much better to me, though. Once a driver is identified to need this, the core is able to report this requirement to a user who might even be unaware of the issue. The dt property has a bit of "try this if things don't work, you may be lucky" taste to it. Need to think about it. If PCB design also has an influence, then my idea won't work, though.
I agree with that in theory. We would need to define more constraints in this case, however: Both min and max setup and hold times would be required for data and start/stop conditions. We have seen cases in which the hold time we configured was too big for some devices on the bus which in turn seemed to get confused between data and start/stop conditions. I don't remember the exact values causing this issue but it was definitely less than the max of 650ns I have grepped out yesterday.
Addressing this issue properly would mean implementing some simple form of STA. Not sure if an operating system kernel is the right place for this, though (and pretty sure that individual device drivers aren't). These questions are probably better addressed at the PCB design stage.
Quoted 17 lines
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
In the case of the Designware block, the parameter both changes SDA and START hold times, however, and you'll find lots of data sheets for hardware with START hold time requirements on the net, e.g.
http://ww1.microchip.com/downloads/en/DeviceDoc/21805B.pdfQuoted 6 lines
Quoted 3 lines
What I couldn't find is a reference manual for a designware IP that supports sda hold time? I found some spear SoC which do not have that register, so that should surely be reflected in the patchset, too.
If you have access to DesignWare documentation, check out the "DesignWare
DW_apb_i2cDatabook" Version 1.17a from March 2012.I don't have, and I do have a hard time finding information about it otherwise :(
Quoted 6 lines
Quoted 3 lines
Unluckily, I clearly don't have the right to share this document with you. Do you know the version of the blocks in the spear SoC which do not support this register?
ST Spear300 and 600 have
0x3130352ain the version reg according to the refman.
Hrmmm... Going through the release notes it looks like this feature was added with module version 1.11a, released in 2010 (the initial version of the IP was released in 2003).
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
The empirical solution in the function
i2c_dw_scl_hcntdoes not seem to work in all cases: Our lab guys confirmed that we have several PCB designs which do not work without adjusting the sda-hold-time parameter to an appropriate value. The value seems to be different for different PCBs.I'd hope that 300ns is a safe value for all PCBs?
Quoted 7 lines
Quoted 3 lines
Not according to our PCB guys. The highest value I have found in a quick check of our device trees is 650ns with others being just slightly above 300ns.
Thanks for sharing your results \o/ This helps me a lot. Can you find out/guess if this value is solely dependend on a slave or is it also dependend on PCB layout?
In the simplest form of STA, timings are generally considered a function of three factors:
. Drive strength
. Bus load (Fan out)
. Internal timings of all devices on the bus (setup/hold times etc.)
This applies to ASIC internal timing. My PCB experience is quite limited and I'm not sure if this can be applied as such. That said, the I2C specification does define all three of these factors and I deduce they all have their importance. We know that the specified internal device timings are sometimes buggy, I don't know about the other two.
Greetings,
Christian
Signature · 4 lines
Christian Ruppert , <[email protected]> /| Tel: +41/(0)22 816 19-42 //| 3, Chemin du Pré-Fleuri _// | bilis Systems CH-1228 Plan-les-Ouates
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>
Okay, I am convinced of the property now...
Quoted 13 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-0@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/err.h> #include <linux/interrupt.h> +#include <linux/of.h> #include <linux/of_i2c.h> #include <linux/platform_device.h> #include <linux/pm.h>
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 131
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +7
-0@@ -121,6 +122,15 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +if (pdev->dev.of_node) { +u32 ht; +u32 ic_clk = dev->get_clk_rate_khz (dev); + +of_property_read_u32 (pdev->dev.of_node, +"i2c-sda-hold-time-ns" , &ht); + dev->sda_holdO_time = ((u64 )ic_clk * ht +500000 ) /1000000 ;
... but is this correct even if the property is not defined?
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 133
Quoted 2 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0+ } +
Thanks for all the input so far!
Quoted 7 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Okay, I am convinced of the property now...
and the version check is missing since older revisions do not support sda-hold-time.
PATCH v9 1/1 i2c-designware: make SDA hold time configurable
This patch makes the SDA hold time configurable through device tree.
--- .../devicetree/bindings/i2c/i2c-designware.txt | 14 ++++++++++++++ arch/arc/boot/dts/abilis_tb100_dvk.dts | 10 +++++----- arch/arc/boot/dts/abilis_tb101_dvk.dts | 10 +++++----- drivers/i2c/busses/i2c-designware-core.c | 13 +++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++++ 6 files changed, 48 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-designware.txt +14 -0
@@ -10,6 +10,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. +Optional properties : + - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds. + Example : i2c@f0000 {
@@ -20,3 +23,14 @@ Example : interrupts = <11>; clock-frequency = <400000>; }; + + i2c@1120000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x1120000 0x1000>; + interrupt-parent = <&ictl>; + interrupts = <12 1>; + clock-frequency = <400000>; + i2c-sda-hold-time-ns = <300>; + };
arch/arc/boot/dts/abilis_tb100_dvk.dts +5 -5
@@ -45,19 +45,19 @@ }; i2c0: i2c@FF120000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c1: i2c@FF121000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c2: i2c@FF122000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c3: i2c@FF123000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c4: i2c@FF124000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; leds {
arch/arc/boot/dts/abilis_tb101_dvk.dts +5 -5
@@ -45,19 +45,19 @@ }; i2c0: i2c@FF120000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c1: i2c@FF121000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c2: i2c@FF122000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c3: i2c@FF123000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c4: i2c@FF124000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; leds {
drivers/i2c/busses/i2c-designware-core.c +13 -0
@@ -67,9 +67,12 @@#define DW_IC_STATUS 0x70#define DW_IC_TXFLR 0x74#define DW_IC_RXFLR 0x78 +#define DW_IC_SDA_HOLD 0x7c#define DW_IC_TX_ABRT_SOURCE 0x80#define DW_IC_ENABLE_STATUS 0x9c#define DW_IC_COMP_PARAM_1 0xf4 +#define DW_IC_COMP_VERSION 0xf8 +#define DW_IC_SDA_HOLD_MIN_VERS 0x3131312A#define DW_IC_COMP_TYPE 0xfc#define DW_IC_COMP_TYPE_VALUE 0x44570140
@@ -332,6 +335,16 @@ int i2c_dw_init(struct dw_i2c_dev *dev)dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT );dev_dbg (dev->dev,"Fast-mode HCNT:LCNT = %d:%d\n" , hcnt, lcnt); +/* Configure SDA Hold Time if required */ + reg =dw_readl (dev,DW_IC_COMP_VERSION ); +if (dev->sda_hold_time) { +if (reg >=DW_IC_SDA_HOLD_MIN_VERS ) +dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); +else +dev_warn (dev->dev, +"Hardware too old to adjust SDA hold time." ); + } +/* Configure Tx/Rx FIFO threshold levels */ dw_writel (dev, dev->tx_fifo_depth -1 ,DW_IC_TX_TL );dw_writel (dev,0 ,DW_IC_RX_TL );
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -90,6 +90,7 @@ struct dw_i2c_dev {unsigned int tx_fifo_depth;unsigned int rx_fifo_depth;int rx_outstanding; +u32 sda_hold_time; };#define ACCESS_SWAP 0x00000001
drivers/i2c/busses/i2c-designware-platdrv.c +10 -0
@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/err.h> #include <linux/interrupt.h> +#include <linux/of.h> #include <linux/of_i2c.h> #include <linux/platform_device.h> #include <linux/pm.h>
@@ -121,6 +122,15 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +if (pdev->dev.of_node) { +u32 ht =0 ; +u32 ic_clk = dev->get_clk_rate_khz (dev); + +of_property_read_u32 (pdev->dev.of_node, +"i2c-sda-hold-time-ns" , &ht); + dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + } + dev->functionality =I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |
Signature · 1 line
1.7.1
Hi,
Quoted 8 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>--- .../devicetree/bindings/i2c/i2c-designware.txt | 14 ++++++++++++++ arch/arc/boot/dts/abilis_tb100_dvk.dts | 10 +++++----- arch/arc/boot/dts/abilis_tb101_dvk.dts | 10 +++++-----
Vineet, an ack for those would be nice since I think it is better if I take all this via I2C.
Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c | 13 +++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++++ 6 files changed, 48 insertions(+), 10 deletions(-)Documentation/devicetree/bindings/i2c/i2c-designware.txt +0
-0
Documentation/devicetree/bindings/i2c/i2c-designware.txt Recommended properties : · line 14
Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-designware.txt +2
-0@@ -10,6 +10,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. +Optional properties : + - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds.
Not on all versions, should be mentioned here.
Quoted 37 lines
Documentation/devicetree/bindings/i2c/i2c-designware.txt +12
-0+ Example : i2c@f0000 {@@ -20,3 +23,14 @@ Example : interrupts = <11>; clock-frequency = <400000>; }; + + i2c@1120000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x1120000 0x1000>; + interrupt-parent = <&ictl>; + interrupts = <12 1>; + clock-frequency = <400000>; + i2c-sda-hold-time-ns = <300>; + };drivers/i2c/busses/i2c-designware-core.c +3
-0@@ -67,9 +67,12 @@#define DW_IC_STATUS 0x70#define DW_IC_TXFLR 0x74#define DW_IC_RXFLR 0x78 +#define DW_IC_SDA_HOLD 0x7c#define DW_IC_TX_ABRT_SOURCE 0x80#define DW_IC_ENABLE_STATUS 0x9c#define DW_IC_COMP_PARAM_1 0xf4 +#define DW_IC_COMP_VERSION 0xf8 +#define DW_IC_SDA_HOLD_MIN_VERS 0x3131312A#define DW_IC_COMP_TYPE 0xfc#define DW_IC_COMP_TYPE_VALUE 0x44570140
drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev) · line 339
Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.c +2
-0@@ -332,6 +335,16 @@ int i2c_dw_init(struct dw_i2c_dev *dev)dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT );dev_dbg (dev->dev,"Fast-mode HCNT:LCNT = %d:%d\n" , hcnt, lcnt); +/* Configure SDA Hold Time if required */ + reg =dw_readl (dev,DW_IC_COMP_VERSION );
Why not reading reg inside the if-block?
Thanks,
Wolfram
Vineet Gupta
Acked-byQuoted 5 lines · Wolfram Sang
Hi,
Quoted 2 lines · Christian Ruppert
Quoted 2 lines
This patch makes the SDA hold time configurable through device tree.
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>--- .../devicetree/bindings/i2c/i2c-designware.txt | 14 ++++++++++++++ arch/arc/boot/dts/abilis_tb100_dvk.dts | 10 +++++----- arch/arc/boot/dts/abilis_tb101_dvk.dts | 10 +++++-----Vineet, an ack for those would be nice since I think it is better if I take all this via I2C.
Certainly, I was waiting for you guys to converge :-)
-Vineet
PATCH v10 1/1 i2c-designware: make SDA hold time configurable
In reply to Wolfram SangThis patch makes the SDA hold time configurable through device tree.
--- .../devicetree/bindings/i2c/i2c-designware.txt | 15 +++++++++++++++ arch/arc/boot/dts/abilis_tb100_dvk.dts | 10 +++++----- arch/arc/boot/dts/abilis_tb101_dvk.dts | 10 +++++----- drivers/i2c/busses/i2c-designware-core.c | 13 +++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++++ 6 files changed, 49 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-designware.txt +15 -0
@@ -10,6 +10,10 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. +Optional properties : + - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds. + This option is only supported in hardware blocks version 1.11a or newer. + Example : i2c@f0000 {
@@ -20,3 +24,14 @@ Example : interrupts = <11>; clock-frequency = <400000>; }; + + i2c@1120000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,designware-i2c"; + reg = <0x1120000 0x1000>; + interrupt-parent = <&ictl>; + interrupts = <12 1>; + clock-frequency = <400000>; + i2c-sda-hold-time-ns = <300>; + };
arch/arc/boot/dts/abilis_tb100_dvk.dts +5 -5
@@ -45,19 +45,19 @@ }; i2c0: i2c@FF120000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c1: i2c@FF121000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c2: i2c@FF122000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c3: i2c@FF123000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c4: i2c@FF124000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; leds {
arch/arc/boot/dts/abilis_tb101_dvk.dts +5 -5
@@ -45,19 +45,19 @@ }; i2c0: i2c@FF120000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c1: i2c@FF121000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c2: i2c@FF122000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c3: i2c@FF123000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; i2c4: i2c@FF124000 { - sda-hold-time = <432>; + i2c-sda-hold-time-ns = <432>; }; leds {
drivers/i2c/busses/i2c-designware-core.c +13 -0
@@ -67,9 +67,12 @@#define DW_IC_STATUS 0x70#define DW_IC_TXFLR 0x74#define DW_IC_RXFLR 0x78 +#define DW_IC_SDA_HOLD 0x7c#define DW_IC_TX_ABRT_SOURCE 0x80#define DW_IC_ENABLE_STATUS 0x9c#define DW_IC_COMP_PARAM_1 0xf4 +#define DW_IC_COMP_VERSION 0xf8 +#define DW_IC_SDA_HOLD_MIN_VERS 0x3131312A#define DW_IC_COMP_TYPE 0xfc#define DW_IC_COMP_TYPE_VALUE 0x44570140
@@ -332,6 +335,16 @@ int i2c_dw_init(struct dw_i2c_dev *dev)dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT );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 ) +dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); +else +dev_warn (dev->dev, +"Hardware too old to adjust SDA hold time." ); + } +/* Configure Tx/Rx FIFO threshold levels */ dw_writel (dev, dev->tx_fifo_depth -1 ,DW_IC_TX_TL );dw_writel (dev,0 ,DW_IC_RX_TL );
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -90,6 +90,7 @@ struct dw_i2c_dev {unsigned int tx_fifo_depth;unsigned int rx_fifo_depth;int rx_outstanding; +u32 sda_hold_time; };#define ACCESS_SWAP 0x00000001
drivers/i2c/busses/i2c-designware-platdrv.c +10 -0
@@ -34,6 +34,7 @@#include <linux/sched.h> #include <linux/err.h> #include <linux/interrupt.h> +#include <linux/of.h> #include <linux/of_i2c.h> #include <linux/platform_device.h> #include <linux/pm.h>
@@ -121,6 +122,15 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +if (pdev->dev.of_node) { +u32 ht =0 ; +u32 ic_clk = dev->get_clk_rate_khz (dev); + +of_property_read_u32 (pdev->dev.of_node, +"i2c-sda-hold-time-ns" , &ht); + dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + } + dev->functionality =I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |
Signature · 1 line
1.7.1
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>
Quoted 8 lines
--- .../devicetree/bindings/i2c/i2c-designware.txt | 15 +++++++++++++++ arch/arc/boot/dts/abilis_tb100_dvk.dts | 10 +++++----- arch/arc/boot/dts/abilis_tb101_dvk.dts | 10 +++++----- drivers/i2c/busses/i2c-designware-core.c | 13 +++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++++ 6 files changed, 49 insertions(+), 10 deletions(-)
-Vineet
Wolfram Sang
AppliedQuoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>
Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Sorry, but I got a regression that I didn't find reported elsewhere so far, even though it breaks a lot of the ARM defconfig builds:
drivers/built-in.o: In function `dw_i2c_probe':
/git/arm-soc/drivers/i2c/busses/i2c-designware-platdrv.c:125: undefined reference to `__udivdi3'
I suspect you want something like the change below.
drivers/i2c/busses/i2c-designware-platdrv.c +4 -1
@@ -119,10 +119,13 @@ static int dw_i2c_probe(struct platform_device *pdev)if (pdev->dev.of_node) {u32 ht =0 ;u32 ic_clk = dev->get_clk_rate_khz (dev); +u64 hold_time;of_property_read_u32 (pdev->dev.of_node,"i2c-sda-hold-time-ns" , &ht); - dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + hold_time = (u64 )ic_clk * ht +500000 ; +do_div (hold_time,1000000 ); + dev->sda_hold_time = hold_time; } dev->functionality =
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Quoted 7 lines
Sorry, but I got a regression that I didn't find reported elsewhere so far, even though it breaks a lot of the ARM defconfig builds:
drivers/built-in.o: In function `dw_i2c_probe':
/git/arm-soc/drivers/i2c/busses/i2c-designware-platdrv.c:125: undefined reference to `__udivdi3'I suspect you want something like the change below.
This looks similar to a patch Vincent Stehle submitted yesterday, see
https://lkml.org/lkml/2013/7/2/145
Quoted 21 lines
Signed-off-by Arnd Bergmann <[email protected]>drivers/i2c/busses/i2c-designware-platdrv.c +4
-1@@ -119,10 +119,13 @@ static int dw_i2c_probe(struct platform_device *pdev)if (pdev->dev.of_node) {u32 ht =0 ;u32 ic_clk = dev->get_clk_rate_khz (dev); +u64 hold_time;of_property_read_u32 (pdev->dev.of_node,"i2c-sda-hold-time-ns" , &ht); - dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + hold_time = (u64 )ic_clk * ht +500000 ; +do_div (hold_time,1000000 ); + dev->sda_hold_time = hold_time; } dev->functionality =
Signature · 4 lines
Christian Ruppert , <[email protected]> /| Tel: +41/(0)22 816 19-42 //| 3, Chemin du Pré-Fleuri _// | bilis Systems CH-1228 Plan-les-Ouates
Quoted 14 lines · Christian Ruppert
Quoted 13 lines · Arnd Bergmann
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Sorry, but I got a regression that I didn't find reported elsewhere so far, even though it breaks a lot of the ARM defconfig builds:
Quoted 7 lines
Quoted 4 lines
drivers/built-in.o: In function `dw_i2c_probe':
/git/arm-soc/drivers/i2c/busses/i2c-designware-platdrv.c:125: undefined reference to `__udivdi3'I suspect you want something like the change below.
This looks similar to a patch Vincent Stehle submitted yesterday, see
https://lkml.org/lkml/2013/7/2/145
Thanks for the link. Actually his patch looks wrong to me, because
dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000, 1000000);
assigns the division remainder to sda_hold_time, not the quotient.
Arnd
Quoted 21 lines
Quoted 21 lines
Signed-off-by Arnd Bergmann <[email protected]>drivers/i2c/busses/i2c-designware-platdrv.c +4
-1@@ -119,10 +119,13 @@ static int dw_i2c_probe(struct platform_device *pdev)if (pdev->dev.of_node) {u32 ht =0 ;u32 ic_clk = dev->get_clk_rate_khz (dev); +u64 hold_time;of_property_read_u32 (pdev->dev.of_node,"i2c-sda-hold-time-ns" , &ht); - dev->sda_hold_time = ((u64 )ic_clk * ht +500000 ) /1000000 ; + hold_time = (u64 )ic_clk * ht +500000 ; +do_div (hold_time,1000000 ); + dev->sda_hold_time = hold_time; } dev->functionality =
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Christian Ruppert
Quoted 17 lines · Arnd Bergmann
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Sorry, but I got a regression that I didn't find reported elsewhere so far, even though it breaks a lot of the ARM defconfig builds:
drivers/built-in.o: In function `dw_i2c_probe':
/git/arm-soc/drivers/i2c/busses/i2c-designware-platdrv.c:125: undefined reference to `__udivdi3'I suspect you want something like the change below.
Quoted 8 lines
Quoted 2 lines
This looks similar to a patch Vincent Stehle submitted yesterday, see
https://lkml.org/lkml/2013/7/2/145Thanks for the link. Actually his patch looks wrong to me, because
dev->sda_hold_time=div_u64((u64)ic_clk * ht + 500000, 1000000);assigns the division remainder to
sda_hold_time, not the quotient.
Hrmmm... At least when I tested it this morning on an ARC architecture it worked as intended and returned the quotient. Does that mean we have an issue with this function on ARC? Can anyone who knows these functions better than I comment?
Greetings,
Christian
Signature · 4 lines
Christian Ruppert , <[email protected]> /| Tel: +41/(0)22 816 19-42 //| 3, Chemin du Pré-Fleuri _// | bilis Systems CH-1228 Plan-les-Ouates
Quoted 26 lines · Christian Ruppert
Quoted 25 lines · Arnd Bergmann
Quoted 14 lines · Christian Ruppert
Quoted 13 lines · Arnd Bergmann
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Sorry, but I got a regression that I didn't find reported elsewhere so far, even though it breaks a lot of the ARM defconfig builds:
Quoted 7 lines
Quoted 4 lines
drivers/built-in.o: In function `dw_i2c_probe':
/git/arm-soc/drivers/i2c/busses/i2c-designware-platdrv.c:125: undefined reference to `__udivdi3'I suspect you want something like the change below.
This looks similar to a patch Vincent Stehle submitted yesterday, see
https://lkml.org/lkml/2013/7/2/145Thanks for the link. Actually his patch looks wrong to me, because
Quoted 8 lines
Quoted 3 lines
dev->sda_hold_time=div_u64((u64)ic_clk * ht + 500000, 1000000);assigns the division remainder to
sda_hold_time, not the quotient.Hrmmm... At least when I tested it this morning on an ARC architecture it worked as intended and returned the quotient. Does that mean we have an issue with this function on ARC? Can anyone who knows these functions better than I comment?
ARC just uses the generic version of div_u64, which is defined in lib/div64.c.
I suspect that the division remainder just happens to work well enough for you to not cause any run-time error. You could try adding a printk in that function to show the values you get on ARC.
Arnd
Quoted 26 lines · Christian Ruppert
Quoted 25 lines · Arnd Bergmann
Quoted 14 lines · Christian Ruppert
Quoted 13 lines · Arnd Bergmann
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Sorry, but I got a regression that I didn't find reported elsewhere so far, even though it breaks a lot of the ARM defconfig builds:
Quoted 7 lines
Quoted 4 lines
drivers/built-in.o: In function `dw_i2c_probe':
/git/arm-soc/drivers/i2c/busses/i2c-designware-platdrv.c:125: undefined reference to `__udivdi3'I suspect you want something like the change below.
This looks similar to a patch Vincent Stehle submitted yesterday, see
https://lkml.org/lkml/2013/7/2/145Thanks for the link. Actually his patch looks wrong to me, because
Quoted 8 lines
Quoted 3 lines
dev->sda_hold_time=div_u64((u64)ic_clk * ht + 500000, 1000000);assigns the division remainder to
sda_hold_time, not the quotient.Hrmmm... At least when I tested it this morning on an ARC architecture it worked as intended and returned the quotient. Does that mean we have an issue with this function on ARC? Can anyone who knows these functions better than I comment?
ARC just uses the generic version of div_u64, which is defined in lib/div64.c.
I suspect that the division remainder just happens to work well enough for you to not cause any run-time error. You could try adding a printk in that function to show the values you get on ARC.
Arnd
Quoted 36 lines · Arnd Bergmann
Quoted 26 lines · Christian Ruppert
Quoted 25 lines · Arnd Bergmann
Quoted 14 lines · Christian Ruppert
Quoted 13 lines · Arnd Bergmann
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Christian Ruppert
This patch makes the SDA hold time configurable through device tree.
Signed-off-by Christian Ruppert <[email protected]>Signed-off-by Pierrick Hascoet <[email protected]>Applied to for-next, thanks for keeping at it and providing lots of useful information. Much appreciated!
Sorry, but I got a regression that I didn't find reported elsewhere so far, even though it breaks a lot of the ARM defconfig builds:
Quoted 7 lines
Quoted 4 lines
drivers/built-in.o: In function `dw_i2c_probe':
/git/arm-soc/drivers/i2c/busses/i2c-designware-platdrv.c:125: undefined reference to `__udivdi3'I suspect you want something like the change below.
This looks similar to a patch Vincent Stehle submitted yesterday, see
https://lkml.org/lkml/2013/7/2/145Thanks for the link. Actually his patch looks wrong to me, because
Quoted 8 lines
Quoted 3 lines
dev->sda_hold_time=div_u64((u64)ic_clk * ht + 500000, 1000000);assigns the division remainder to
sda_hold_time, not the quotient.Hrmmm... At least when I tested it this morning on an ARC architecture it worked as intended and returned the quotient. Does that mean we have an issue with this function on ARC? Can anyone who knows these functions better than I comment?
Quoted 5 lines
ARC just uses the generic version of
div_u64, which is defined inlib/div64.c.I suspect that the division remainder just happens to work well enough for you to not cause any run-time error. You could try adding a printk in that function to show the values you get on ARC.
That's what I did and they were identical to the original values calculated with /. I just looked at include/linux/math64.h and found the following comment:
/**
* div_u64 - unsigned 64bit divide with 32bit divisor
*
* This is the most common 64bit divide and should be used if possible,
* as many 32bit archs can optimize this variant better than a full 64bit
* divide.
*/
Although this doesn't explicitly state what the function returns to me this sounds more like the quotient is returned rather than the remainder?
Signature · 4 lines
Christian Ruppert , <[email protected]> /| Tel: +41/(0)22 816 19-42 //| 3, Chemin du Pré-Fleuri _// | bilis Systems CH-1228 Plan-les-Ouates
Quoted 1 line
From: Christian Ruppert [mailto:[email protected]]
(..)
Quoted 2 lines
Although this doesn't explicitly state what the function returns to me this sounds more like the quotient is returned rather than the remainder?
Hi,
Yes div_u64() returns the quotient.
It is defined in linux/math64.h as:
static inline u64 div_u64(u64 dividend, u32 divisor)
{
u32 remainder;
return div_u64_rem(dividend, divisor, &remainder);
}The remainder is probably fully optimized out.
Best regards,
V.
Arnd Bergmann
Acked-byQuoted 11 lines · On Wednesday 03 July 2013, Stehle Vincent-B46079 wrote:
Quoted 1 line
From: Christian Ruppert [mailto:[email protected]]
(..)
Quoted 2 lines
Although this doesn't explicitly state what the function returns to me this sounds more like the quotient is returned rather than the remainder?
Hi,
Yes
div_u64()returns the quotient.It is defined in
linux/math64.has:
Quoted 7 lines
static inline u64 div_u64(u64 dividend, u32 divisor) { u32 remainder; return div_u64_rem(dividend, divisor, &remainder); }The remainder is probably fully optimized out.
Ah, you are right, sorry for the confusion on my part.
I thought you had used do_div() rather than div_u64(). Everything's fine then, feel free to add my
to your patch.
Arnd