devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT
@ 2015-11-24 13:47 Ludovic Desroches
  2015-11-24 13:47 ` [PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding Ludovic Desroches
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ludovic Desroches @ 2015-11-24 13:47 UTC (permalink / raw)
  To: wsa, nicolas.ferre, alexandre.belloni, plagnioj
  Cc: linux-i2c, linux-kernel, devicetree, linux-arm-kernel,
	cyrille.pichen, Wenyou Yang, Ludovic Desroches

From: Wenyou Yang <wenyou.yang@atmel.com>

Add the HOLD field management. Some i2c devices need a longer data hold
time than the one given in the i2c bus specification. Since this value
depends on the i2c device connected to the bus, add a DT property to
configure it: "atmel,twd-hold-cycles".

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
---
 drivers/i2c/busses/i2c-at91.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 10835d1..b3595ea 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -64,6 +64,7 @@
 #define	AT91_TWI_IADR		0x000c	/* Internal Address Register */
 
 #define	AT91_TWI_CWGR		0x0010	/* Clock Waveform Generator Reg */
+#define	AT91_TWI_CWGR_HOLD(x)	(((x) & 0x1f) << 24)
 
 #define	AT91_TWI_SR		0x0020	/* Status Register */
 #define	AT91_TWI_TXCOMP		BIT(0)	/* Transmission Complete */
@@ -185,7 +186,8 @@ static void at91_init_twi_bus(struct at91_twi_dev *dev)
  * Calculate symmetric clock as stated in datasheet:
  * twi_clk = F_MAIN / (2 * (cdiv * (1 << ckdiv) + offset))
  */
-static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
+static void at91_calc_twi_clock(struct at91_twi_dev *dev,
+				int twi_clk, u32 twd_hold)
 {
 	int ckdiv, cdiv, div;
 	struct at91_twi_pdata *pdata = dev->pdata;
@@ -204,7 +206,9 @@ static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
 		cdiv = 255;
 	}
 
-	dev->twi_cwgr_reg = (ckdiv << 16) | (cdiv << 8) | cdiv;
+	dev->twi_cwgr_reg = (ckdiv << 16) | (cdiv << 8) | cdiv
+			    | AT91_TWI_CWGR_HOLD(twd_hold);
+
 	dev_dbg(dev->dev, "cdiv %d ckdiv %d\n", cdiv, ckdiv);
 }
 
@@ -994,6 +998,7 @@ static int at91_twi_probe(struct platform_device *pdev)
 	int rc;
 	u32 phy_addr;
 	u32 bus_clk_rate;
+	u32 twd_hold_cycles = 0;
 
 	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
 	if (!dev)
@@ -1050,7 +1055,10 @@ static int at91_twi_probe(struct platform_device *pdev)
 	if (rc)
 		bus_clk_rate = DEFAULT_TWI_CLK_HZ;
 
-	at91_calc_twi_clock(dev, bus_clk_rate);
+	of_property_read_u32(dev->dev->of_node, "atmel,twd-hold-cycles",
+			     &twd_hold_cycles);
+
+	at91_calc_twi_clock(dev, bus_clk_rate, twd_hold_cycles);
 	at91_init_twi_bus(dev);
 
 	snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91");
-- 
2.5.0

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

* [PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding
  2015-11-24 13:47 [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Ludovic Desroches
@ 2015-11-24 13:47 ` Ludovic Desroches
  2015-11-25 22:46   ` Rob Herring
  2015-11-24 13:47 ` [PATCH 3/3] ARM: dts: at91: specify DT property "atmel,twd-hold-cycles" Ludovic Desroches
  2015-11-30 15:13 ` [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Wolfram Sang
  2 siblings, 1 reply; 6+ messages in thread
From: Ludovic Desroches @ 2015-11-24 13:47 UTC (permalink / raw)
  To: wsa, nicolas.ferre, alexandre.belloni, plagnioj
  Cc: linux-i2c, linux-kernel, devicetree, linux-arm-kernel,
	cyrille.pichen, Wenyou Yang, Ludovic Desroches

From: Wenyou Yang <wenyou.yang@atmel.com>

Add a DT property "atmel,twd-hold-cycles" to specify the HOLD
filed of TWIHS_CWGR register to increase the TWD hold time.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
---
 Documentation/devicetree/bindings/i2c/i2c-at91.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
index 6e81dc1..c81a0cb 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
@@ -17,6 +17,9 @@ Optional properties:
 - dma-names: should contain "tx" and "rx".
 - atmel,fifo-size: maximum number of data the RX and TX FIFOs can store for FIFO
   capable I2C controllers.
+- atmel,twd-hold-cycles: number of cycles for TWD hold time whose value is
+  determinated by (atmel,twd-hold-cycles + 3) x t_peripheral_clock,
+  maximum value is 0x1f.
 - Child nodes conforming to i2c bus binding
 
 Examples :
@@ -29,6 +32,7 @@ i2c0: i2c@fff84000 {
 	#size-cells = <0>;
 	clocks = <&twi0_clk>;
 	clock-frequency = <400000>;
+	atmel,twd-hold-cycles = <2>;
 
 	24c512@50 {
 		compatible = "24c512";
-- 
2.5.0

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

* [PATCH 3/3] ARM: dts: at91: specify DT property "atmel,twd-hold-cycles"
  2015-11-24 13:47 [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Ludovic Desroches
  2015-11-24 13:47 ` [PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding Ludovic Desroches
@ 2015-11-24 13:47 ` Ludovic Desroches
  2015-11-30 15:13 ` [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Wolfram Sang
  2 siblings, 0 replies; 6+ messages in thread
From: Ludovic Desroches @ 2015-11-24 13:47 UTC (permalink / raw)
  To: wsa, nicolas.ferre, alexandre.belloni, plagnioj
  Cc: linux-i2c, linux-kernel, devicetree, linux-arm-kernel,
	cyrille.pichen, Wenyou Yang

From: Wenyou Yang <wenyou.yang@atmel.com>

Specify the device tree property "atmel,twd-hold-cycles" to 25
to adapt to the PMIC ACT8945A.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
 arch/arm/boot/dts/at91-sama5d2_xplained.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/at91-sama5d2_xplained.dts b/arch/arm/boot/dts/at91-sama5d2_xplained.dts
index ad6de73..25ffd86 100644
--- a/arch/arm/boot/dts/at91-sama5d2_xplained.dts
+++ b/arch/arm/boot/dts/at91-sama5d2_xplained.dts
@@ -129,6 +129,7 @@
 				dmas = <0>, <0>;
 				pinctrl-names = "default";
 				pinctrl-0 = <&pinctrl_i2c0_default>;
+				atmel,twd-hold-cycles = <25>;
 				status = "okay";
 
 				pmic: act8865@5b {
-- 
2.5.0

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

* Re: [PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding
  2015-11-24 13:47 ` [PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding Ludovic Desroches
@ 2015-11-25 22:46   ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2015-11-25 22:46 UTC (permalink / raw)
  To: Ludovic Desroches
  Cc: wsa, nicolas.ferre, alexandre.belloni, plagnioj, linux-i2c,
	linux-kernel, devicetree, linux-arm-kernel, cyrille.pichen,
	Wenyou Yang

On Tue, Nov 24, 2015 at 02:47:41PM +0100, Ludovic Desroches wrote:
> From: Wenyou Yang <wenyou.yang@atmel.com>
> 
> Add a DT property "atmel,twd-hold-cycles" to specify the HOLD
> filed of TWIHS_CWGR register to increase the TWD hold time.
> 
> Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>

Acked-by: Rob Herring <robh@kernel.org>

> ---
>  Documentation/devicetree/bindings/i2c/i2c-at91.txt | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
> index 6e81dc1..c81a0cb 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
> @@ -17,6 +17,9 @@ Optional properties:
>  - dma-names: should contain "tx" and "rx".
>  - atmel,fifo-size: maximum number of data the RX and TX FIFOs can store for FIFO
>    capable I2C controllers.
> +- atmel,twd-hold-cycles: number of cycles for TWD hold time whose value is
> +  determinated by (atmel,twd-hold-cycles + 3) x t_peripheral_clock,
> +  maximum value is 0x1f.
>  - Child nodes conforming to i2c bus binding
>  
>  Examples :
> @@ -29,6 +32,7 @@ i2c0: i2c@fff84000 {
>  	#size-cells = <0>;
>  	clocks = <&twi0_clk>;
>  	clock-frequency = <400000>;
> +	atmel,twd-hold-cycles = <2>;
>  
>  	24c512@50 {
>  		compatible = "24c512";
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT
  2015-11-24 13:47 [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Ludovic Desroches
  2015-11-24 13:47 ` [PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding Ludovic Desroches
  2015-11-24 13:47 ` [PATCH 3/3] ARM: dts: at91: specify DT property "atmel,twd-hold-cycles" Ludovic Desroches
@ 2015-11-30 15:13 ` Wolfram Sang
  2015-11-30 15:57   ` Ludovic Desroches
  2 siblings, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2015-11-30 15:13 UTC (permalink / raw)
  To: Ludovic Desroches
  Cc: nicolas.ferre, alexandre.belloni, plagnioj, linux-i2c,
	linux-kernel, devicetree, linux-arm-kernel, cyrille.pichen,
	Wenyou Yang

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

On Tue, Nov 24, 2015 at 02:47:40PM +0100, Ludovic Desroches wrote:
> From: Wenyou Yang <wenyou.yang@atmel.com>
> 
> Add the HOLD field management. Some i2c devices need a longer data hold
> time than the one given in the i2c bus specification. Since this value
> depends on the i2c device connected to the bus, add a DT property to
> configure it: "atmel,twd-hold-cycles".

We already have "i2c-sda-hold-time-ns". Can you use that one? Sorry that
this is not obviously documented, I am working on it...


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

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

* Re: [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT
  2015-11-30 15:13 ` [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Wolfram Sang
@ 2015-11-30 15:57   ` Ludovic Desroches
  0 siblings, 0 replies; 6+ messages in thread
From: Ludovic Desroches @ 2015-11-30 15:57 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Ludovic Desroches, nicolas.ferre, alexandre.belloni, plagnioj,
	linux-i2c, linux-kernel, devicetree, linux-arm-kernel,
	cyrille.pichen, Wenyou Yang

On Mon, Nov 30, 2015 at 04:13:20PM +0100, Wolfram Sang wrote:
> On Tue, Nov 24, 2015 at 02:47:40PM +0100, Ludovic Desroches wrote:
> > From: Wenyou Yang <wenyou.yang@atmel.com>
> > 
> > Add the HOLD field management. Some i2c devices need a longer data hold
> > time than the one given in the i2c bus specification. Since this value
> > depends on the i2c device connected to the bus, add a DT property to
> > configure it: "atmel,twd-hold-cycles".
> 
> We already have "i2c-sda-hold-time-ns". Can you use that one? Sorry that
> this is not obviously documented, I am working on it...
> 

I think we can use it, I'll rework the patch to convert duration in
number of cycles.

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

end of thread, other threads:[~2015-11-30 15:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-24 13:47 [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Ludovic Desroches
2015-11-24 13:47 ` [PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding Ludovic Desroches
2015-11-25 22:46   ` Rob Herring
2015-11-24 13:47 ` [PATCH 3/3] ARM: dts: at91: specify DT property "atmel,twd-hold-cycles" Ludovic Desroches
2015-11-30 15:13 ` [PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT Wolfram Sang
2015-11-30 15:57   ` Ludovic Desroches

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).