* [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR
@ 2015-09-30 8:47 Ludovic Desroches
2015-09-30 8:47 ` [PATCH 2/2] i2c: at91: update documentation for new "atmel, twd-hold-cycles" property Ludovic Desroches
2015-09-30 9:01 ` [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR Cyrille Pitchen
0 siblings, 2 replies; 3+ messages in thread
From: Ludovic Desroches @ 2015-09-30 8:47 UTC (permalink / raw)
To: linux-arm-kernel
From: Wenyou Yang <wenyou.yang@atmel.com>
Add the HOLD field setting in order to support I2C slave devices which need
a longer hold time of the data.
Since it depends on the slave devices connected to the bus, add a DT
property "atmel,twd-hold-cycles" to specify this HOLD field.
Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
---
drivers/i2c/busses/i2c-at91.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 1c758cd..06e66ef 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);
}
@@ -936,6 +940,7 @@ static int at91_twi_probe(struct platform_device *pdev)
int rc;
u32 phy_addr;
u32 bus_clk_rate;
+ u32 twd_hold_cycles;
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
@@ -992,7 +997,12 @@ 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);
+ rc = of_property_read_u32(dev->dev->of_node,
+ "atmel,twd-hold-cycles", &twd_hold_cycles);
+ if (rc)
+ twd_hold_cycles = 0;
+
+ 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] 3+ messages in thread
* [PATCH 2/2] i2c: at91: update documentation for new "atmel, twd-hold-cycles" property
2015-09-30 8:47 [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR Ludovic Desroches
@ 2015-09-30 8:47 ` Ludovic Desroches
2015-09-30 9:01 ` [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR Cyrille Pitchen
1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Desroches @ 2015-09-30 8:47 UTC (permalink / raw)
To: linux-arm-kernel
From: Wenyou Yang <wenyou.yang@atmel.com>
Add a DT property "atmel,twd-hold-cycles" to specify the HOLD
field 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 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
index 6e81dc1..f14c0b2 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
@@ -17,6 +17,8 @@ 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: increase the TWD hold time by
+ (atmel,twd-hold-cycles + 3) x t_periperal_clk, maximum value is 0x1f.
- Child nodes conforming to i2c bus binding
Examples :
@@ -29,6 +31,7 @@ i2c0: i2c at fff84000 {
#size-cells = <0>;
clocks = <&twi0_clk>;
clock-frequency = <400000>;
+ atmel,twd-hold-cycles = <2>;
24c512 at 50 {
compatible = "24c512";
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR
2015-09-30 8:47 [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR Ludovic Desroches
2015-09-30 8:47 ` [PATCH 2/2] i2c: at91: update documentation for new "atmel, twd-hold-cycles" property Ludovic Desroches
@ 2015-09-30 9:01 ` Cyrille Pitchen
1 sibling, 0 replies; 3+ messages in thread
From: Cyrille Pitchen @ 2015-09-30 9:01 UTC (permalink / raw)
To: linux-arm-kernel
Hi all,
it looks good to me.
Le 30/09/2015 10:47, Ludovic Desroches a ?crit :
> From: Wenyou Yang <wenyou.yang@atmel.com>
>
> Add the HOLD field setting in order to support I2C slave devices which need
> a longer hold time of the data.
> Since it depends on the slave devices connected to the bus, add a DT
> property "atmel,twd-hold-cycles" to specify this HOLD field.
>
> Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Acked-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
> ---
> drivers/i2c/busses/i2c-at91.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
> index 1c758cd..06e66ef 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);
> }
>
> @@ -936,6 +940,7 @@ static int at91_twi_probe(struct platform_device *pdev)
> int rc;
> u32 phy_addr;
> u32 bus_clk_rate;
> + u32 twd_hold_cycles;
>
> dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
> if (!dev)
> @@ -992,7 +997,12 @@ 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);
> + rc = of_property_read_u32(dev->dev->of_node,
> + "atmel,twd-hold-cycles", &twd_hold_cycles);
> + if (rc)
> + twd_hold_cycles = 0;
> +
> + 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");
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-09-30 9:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-30 8:47 [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR Ludovic Desroches
2015-09-30 8:47 ` [PATCH 2/2] i2c: at91: update documentation for new "atmel, twd-hold-cycles" property Ludovic Desroches
2015-09-30 9:01 ` [PATCH 1/2] i2c: at91: add DT property for the HOLD field of TWIHS_CWGR Cyrille Pitchen
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).