diff mbox

[U-Boot,v2,3/9] kmp204x: I2C deblocking for I2C-bus1 added

Message ID 1390819752-21233-4-git-send-email-valentin.longchamp@keymile.com
State Superseded
Delegated to: York Sun
Headers show

Commit Message

Valentin Longchamp Jan. 27, 2014, 10:49 a.m. UTC
From: Rainer Boschung <rainer.boschung@keymile.com>

-uses common deblocking algorithm from ../common/common.c
-supports deblocking of of  I2C-bus1 by means of QRIO GPIO
  - SCL1 = GPIO_A16
  - SDA1 = GPIO_A17

QRIO GPIOs act in an open-drain-like manner, for 0 GPIO drives
low and for 1 the GPIO is an input and must be pulled up externaly!

Signed-off-by: Rainer Boschung <rainer.boschung@keymile.com>
Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
---

Changes in v2: None

 board/keymile/kmp204x/kmp204x.c     | 53 ++++++++++++++++++++++++++++++++++---
 include/configs/km/kmp204x-common.h | 10 +++++++
 2 files changed, 60 insertions(+), 3 deletions(-)

Comments

York Sun Jan. 30, 2014, 2:30 a.m. UTC | #1
On 01/27/2014 02:49 AM, Valentin Longchamp wrote:
> From: Rainer Boschung <rainer.boschung@keymile.com>
> 
> -uses common deblocking algorithm from ../common/common.c

I don't see any algorithm in the common.c file.

> -supports deblocking of of  I2C-bus1 by means of QRIO GPIO
>   - SCL1 = GPIO_A16
>   - SDA1 = GPIO_A17
> 
> QRIO GPIOs act in an open-drain-like manner, for 0 GPIO drives
> low and for 1 the GPIO is an input and must be pulled up externaly!
> 
> Signed-off-by: Rainer Boschung <rainer.boschung@keymile.com>
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> ---
> 
> Changes in v2: None
> 
>  board/keymile/kmp204x/kmp204x.c     | 53 ++++++++++++++++++++++++++++++++++---
>  include/configs/km/kmp204x-common.h | 10 +++++++
>  2 files changed, 60 insertions(+), 3 deletions(-)
> 
> diff --git a/board/keymile/kmp204x/kmp204x.c b/board/keymile/kmp204x/kmp204x.c
> index bbb2453..8d6eecb 100644
> --- a/board/keymile/kmp204x/kmp204x.c
> +++ b/board/keymile/kmp204x/kmp204x.c
> @@ -33,12 +33,51 @@ int checkboard(void)
>  	return 0;
>  }
>  
> -/* TODO: implement the I2C deblocking function */
> -int i2c_make_abort(void)
> +/* I2C deblocking uses the algorithm defined in ../common/common.c, which
> + * makes use of 2 QRIO GPIOs to act on the SCL and SDA signals of an I2C bus.
> + * According to the standard I2C IOs must not drive HI-Levels, so the
> + * QRIO GPIOs are used in open-drain fashion:
> + *  -> 0 GPIO configured as output that drives low
> + *  -> 1 GPIO configured as input pull-up ties high
> + */
> +

I failed to understand these comments as well. Are these comments copy-n-paste?

York
Valentin Longchamp Jan. 30, 2014, 7:32 a.m. UTC | #2
On 01/30/2014 03:30 AM, York Sun wrote:
> On 01/27/2014 02:49 AM, Valentin Longchamp wrote:
>> From: Rainer Boschung <rainer.boschung@keymile.com>
>>
>> -uses common deblocking algorithm from ../common/common.c
> 
> I don't see any algorithm in the common.c file.

The file is board/keymile/common/common.c, where the i2c_make_abort() and the
i2c_write_start_seq() functions are defined. I guess that's what Rainer means
with "algorithm".

I agree that the relative path for the file is not very fortunate and that's why
you have not found the functions.

> 
>> -supports deblocking of of  I2C-bus1 by means of QRIO GPIO
>>   - SCL1 = GPIO_A16
>>   - SDA1 = GPIO_A17
>>
>> QRIO GPIOs act in an open-drain-like manner, for 0 GPIO drives
>> low and for 1 the GPIO is an input and must be pulled up externaly!
>>
>> Signed-off-by: Rainer Boschung <rainer.boschung@keymile.com>
>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>> ---
>>
>> Changes in v2: None
>>
>>  board/keymile/kmp204x/kmp204x.c     | 53 ++++++++++++++++++++++++++++++++++---
>>  include/configs/km/kmp204x-common.h | 10 +++++++
>>  2 files changed, 60 insertions(+), 3 deletions(-)
>>
>> diff --git a/board/keymile/kmp204x/kmp204x.c b/board/keymile/kmp204x/kmp204x.c
>> index bbb2453..8d6eecb 100644
>> --- a/board/keymile/kmp204x/kmp204x.c
>> +++ b/board/keymile/kmp204x/kmp204x.c
>> @@ -33,12 +33,51 @@ int checkboard(void)
>>  	return 0;
>>  }
>>  
>> -/* TODO: implement the I2C deblocking function */
>> -int i2c_make_abort(void)
>> +/* I2C deblocking uses the algorithm defined in ../common/common.c, which
>> + * makes use of 2 QRIO GPIOs to act on the SCL and SDA signals of an I2C bus.
>> + * According to the standard I2C IOs must not drive HI-Levels, so the
>> + * QRIO GPIOs are used in open-drain fashion:
>> + *  -> 0 GPIO configured as output that drives low
>> + *  -> 1 GPIO configured as input pull-up ties high
>> + */
>> +
> 
> I failed to understand these comments as well. Are these comments copy-n-paste?
> 

I will let Rainer answer this as he has written this comment. But I don't think
it's copy-n-paste. It's maybe not very clear for people who don't know the hardware.

Valentin
Boschung, Rainer Jan. 30, 2014, 9:17 a.m. UTC | #3
On 01/30/2014 08:32 AM, Valentin Longchamp wrote:
> On 01/30/2014 03:30 AM, York Sun wrote:
>> On 01/27/2014 02:49 AM, Valentin Longchamp wrote:
>>> From: Rainer Boschung <rainer.boschung@keymile.com>
>>>
>>> -uses common deblocking algorithm from ../common/common.c
>>
>> I don't see any algorithm in the common.c file.
>
> The file is board/keymile/common/common.c, where the i2c_make_abort() and the
> i2c_write_start_seq() functions are defined. I guess that's what Rainer means with "algorithm".

That is what I meant. I will add a more precise comment.
> 
> I agree that the relative path for the file is not very fortunate and that's why you have not found the functions.
>
>>
>>> -supports deblocking of of  I2C-bus1 by means of QRIO GPIO
>>>   - SCL1 = GPIO_A16
>>>   - SDA1 = GPIO_A17
>>>
>>> QRIO GPIOs act in an open-drain-like manner, for 0 GPIO drives low
>>> and for 1 the GPIO is an input and must be pulled up externaly!
>>>
>>> Signed-off-by: Rainer Boschung <rainer.boschung@keymile.com>
>>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>>> ---
>>>
>>> Changes in v2: None
>>>
>>>  board/keymile/kmp204x/kmp204x.c     | 53 ++++++++++++++++++++++++++++++++++---
>>>  include/configs/km/kmp204x-common.h | 10 +++++++
>>>  2 files changed, 60 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/board/keymile/kmp204x/kmp204x.c
>>> b/board/keymile/kmp204x/kmp204x.c index bbb2453..8d6eecb 100644
>>> --- a/board/keymile/kmp204x/kmp204x.c
>>> +++ b/board/keymile/kmp204x/kmp204x.c
>>> @@ -33,12 +33,51 @@ int checkboard(void)
>>>  	return 0;
>>>  }
>>>
>>> -/* TODO: implement the I2C deblocking function */ -int
>>> i2c_make_abort(void)
>>> +/* I2C deblocking uses the algorithm defined in ../common/common.c,
>>> +which
>>> + * makes use of 2 QRIO GPIOs to act on the SCL and SDA signals of an I2C bus.
>>> + * According to the standard I2C IOs must not drive HI-Levels, so
>>> +the
>>> + * QRIO GPIOs are used in open-drain fashion:
>>> + *  -> 0 GPIO configured as output that drives low
>>> + *  -> 1 GPIO configured as input pull-up ties high  */
>>> +
>>
>> I failed to understand these comments as well. Are these comments copy-n-paste?
>>
>
> I will let Rainer answer this as he has written this comment. But I don't think it's copy-n-paste. It's maybe not very clear for people who don't know the hardware.

No the comment isn't copy-n-paste. The GPIO just drives low states, for a high states the pin is not driven (= GPIO configured as input), it is pull-up by a resistor.
I will try to clarify this comment.

>
> Valentin

Rainer
York Sun Jan. 30, 2014, 5:40 p.m. UTC | #4
On 01/30/2014 01:17 AM, Boschung, Rainer wrote:
> On 01/30/2014 08:32 AM, Valentin Longchamp wrote:
>> On 01/30/2014 03:30 AM, York Sun wrote:
>>> On 01/27/2014 02:49 AM, Valentin Longchamp wrote:
>>>> From: Rainer Boschung <rainer.boschung@keymile.com>
>>>>
>>>> -uses common deblocking algorithm from ../common/common.c
>>>
>>> I don't see any algorithm in the common.c file.
>>
>> The file is board/keymile/common/common.c, where the i2c_make_abort() and the
>> i2c_write_start_seq() functions are defined. I guess that's what Rainer means with "algorithm".
> 
> That is what I meant. I will add a more precise comment.
>>

Please send v3 for this patch only, or an incremental patch. I will swap/squash
the patch.

York
diff mbox

Patch

diff --git a/board/keymile/kmp204x/kmp204x.c b/board/keymile/kmp204x/kmp204x.c
index bbb2453..8d6eecb 100644
--- a/board/keymile/kmp204x/kmp204x.c
+++ b/board/keymile/kmp204x/kmp204x.c
@@ -33,12 +33,51 @@  int checkboard(void)
 	return 0;
 }
 
-/* TODO: implement the I2C deblocking function */
-int i2c_make_abort(void)
+/* I2C deblocking uses the algorithm defined in ../common/common.c, which
+ * makes use of 2 QRIO GPIOs to act on the SCL and SDA signals of an I2C bus.
+ * According to the standard I2C IOs must not drive HI-Levels, so the
+ * QRIO GPIOs are used in open-drain fashion:
+ *  -> 0 GPIO configured as output that drives low
+ *  -> 1 GPIO configured as input pull-up ties high
+ */
+
+/* GPIOs used for deblocking I2C bus 1 */
+#define DBLK_PORT1	GPIO_A
+#define DBLK_SCL1	16
+#define DBLK_SDA1	17
+
+/* By default deblock GPIOs are floating */
+static void i2c_deblock_gpio_cfg(void)
+{
+	/* set I2C bus 1 deblocking GPIOs input, but 0 value for open drain */
+	qrio_gpio_direction_input(DBLK_PORT1, DBLK_SCL1);
+	qrio_gpio_direction_input(DBLK_PORT1, DBLK_SDA1);
+
+	qrio_set_gpio(DBLK_PORT1, DBLK_SCL1, 0);
+	qrio_set_gpio(DBLK_PORT1, DBLK_SDA1, 0);
+}
+
+void set_sda(int state)
+{
+	qrio_set_opendrain_gpio(DBLK_PORT1, DBLK_SDA1, state);
+}
+
+void set_scl(int state)
+{
+	qrio_set_opendrain_gpio(DBLK_PORT1, DBLK_SCL1, state);
+}
+
+int get_sda(void)
+{
+	return qrio_get_gpio(DBLK_PORT1, DBLK_SDA1);
+}
+
+int get_scl(void)
 {
-	return 1;
+	return qrio_get_gpio(DBLK_PORT1, DBLK_SCL1);
 }
 
+
 #define ZL30158_RST	8
 #define ZL30343_RST	9
 
@@ -77,6 +116,14 @@  unsigned long get_board_sys_clk(unsigned long dummy)
 	return 66666666;
 }
 
+int misc_init_f(void)
+{
+	/* configure QRIO pis for i2c deblocking */
+	i2c_deblock_gpio_cfg();
+
+	return 0;
+}
+
 #define NUM_SRDS_BANKS	2
 #define PHY_RST		15
 
diff --git a/include/configs/km/kmp204x-common.h b/include/configs/km/kmp204x-common.h
index e33ac90..626879a 100644
--- a/include/configs/km/kmp204x-common.h
+++ b/include/configs/km/kmp204x-common.h
@@ -211,6 +211,7 @@  unsigned long get_board_sys_clk(unsigned long dummy);
 
 #define CONFIG_BOARD_EARLY_INIT_F
 #define CONFIG_BOARD_EARLY_INIT_R	/* call board_early_init_r function */
+#define CONFIG_MISC_INIT_F
 #define CONFIG_MISC_INIT_R
 #define CONFIG_LAST_STAGE_INIT
 
@@ -266,7 +267,10 @@  unsigned long get_board_sys_clk(unsigned long dummy);
 #define CONFIG_FIT_VERBOSE	/* enable fit_format_{error,warning}() */
 
 /* I2C */
+
 #define CONFIG_SYS_I2C
+#define CONFIG_SYS_I2C_INIT_BOARD
+#define CONFIG_SYS_I2C_SPEED		100000 /* deblocking */
 #define CONFIG_SYS_NUM_I2C_BUSES	3
 #define CONFIG_SYS_I2C_MAX_HOPS		1
 #define CONFIG_SYS_I2C_FSL		/* Use FSL I2C driver */
@@ -279,6 +283,12 @@  unsigned long get_board_sys_clk(unsigned long dummy);
 					{0, {{I2C_MUX_PCA9547, 0x70, 1 } } }, \
 					{0, {{I2C_MUX_PCA9547, 0x70, 2 } } }, \
 				}
+#ifndef __ASSEMBLY__
+void set_sda(int state);
+void set_scl(int state);
+int get_sda(void);
+int get_scl(void);
+#endif
 
 #define CONFIG_KM_IVM_BUS		1	/* I2C1 (Mux-Port 1)*/