public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] question about software i2c multi instance
@ 2015-03-20  9:44 Bo Shen
  2015-03-20 10:10 ` Heiko Schocher
  2015-03-23  8:28 ` Lukasz Majewski
  0 siblings, 2 replies; 7+ messages in thread
From: Bo Shen @ 2015-03-20  9:44 UTC (permalink / raw)
  To: u-boot

Hi Heiko,
   After check the software i2c code, I found it can not support multi 
instances, although it has I2C_SOFT_DECLARATIONS2, 
I2C_SOFT_DECLARATIONS3, I2C_SOFT_DECLARATIONS4.
   Because, when do GPIO operation, there is only one pair of 
CONFIG_SOFT_I2C_GPIO_SCL and CONFIG_SOFT_I2C_GPIO_SDA.
   So, if want to support multi instances, it needs to extend the GPIO 
configuration for SCL/SDA, am I right?

   Thanks.

Best Regards,
Bo Shen

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

* [U-Boot] question about software i2c multi instance
  2015-03-20  9:44 [U-Boot] question about software i2c multi instance Bo Shen
@ 2015-03-20 10:10 ` Heiko Schocher
  2015-03-23  6:27   ` Bo Shen
  2015-03-23  8:28 ` Lukasz Majewski
  1 sibling, 1 reply; 7+ messages in thread
From: Heiko Schocher @ 2015-03-20 10:10 UTC (permalink / raw)
  To: u-boot

Hello Bo,

Am 20.03.2015 10:44, schrieb Bo Shen:
> Hi Heiko,
>    After check the software i2c code, I found it can not support multi instances, although it has I2C_SOFT_DECLARATIONS2, I2C_SOFT_DECLARATIONS3, I2C_SOFT_DECLARATIONS4.
>    Because, when do GPIO operation, there is only one pair of CONFIG_SOFT_I2C_GPIO_SCL and CONFIG_SOFT_I2C_GPIO_SDA.
>    So, if want to support multi instances, it needs to extend the GPIO configuration for SCL/SDA, am I right?

Prefered way should be to use DM, Przemyslaw posted patches
for the soft-i2c driver, see
http://lists.denx.de/pipermail/u-boot/2015-March/207641.html

maybe you can try this?

If not, you are right, you must define your own I2C_SCL/I2C_SDA/I2C_READ/I2C_INIT
defines, for example:

#  define I2C_SCL(bit) \
         do { \
		switch(I2C_ADAP_HWNR) {
			case 0:
		                gpio_direction_output(CONFIG_SOFT_I2C_GPIO_SCL_0, bit); \
				break;
			case 1:
		                gpio_direction_output(CONFIG_SOFT_I2C_GPIO_SCL_1, bit); \
				break;
			[...]
                 I2C_GPIO_SYNC; \
         } while (0)

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] question about software i2c multi instance
  2015-03-20 10:10 ` Heiko Schocher
@ 2015-03-23  6:27   ` Bo Shen
  0 siblings, 0 replies; 7+ messages in thread
From: Bo Shen @ 2015-03-23  6:27 UTC (permalink / raw)
  To: u-boot

Hi Heiko,

On 03/20/2015 06:10 PM, Heiko Schocher wrote:
> Hello Bo,
>
> Am 20.03.2015 10:44, schrieb Bo Shen:
>> Hi Heiko,
>>    After check the software i2c code, I found it can not support multi
>> instances, although it has I2C_SOFT_DECLARATIONS2,
>> I2C_SOFT_DECLARATIONS3, I2C_SOFT_DECLARATIONS4.
>>    Because, when do GPIO operation, there is only one pair of
>> CONFIG_SOFT_I2C_GPIO_SCL and CONFIG_SOFT_I2C_GPIO_SDA.
>>    So, if want to support multi instances, it needs to extend the GPIO
>> configuration for SCL/SDA, am I right?
>
> Prefered way should be to use DM, Przemyslaw posted patches
> for the soft-i2c driver, see
> http://lists.denx.de/pipermail/u-boot/2015-March/207641.html
>
> maybe you can try this?

Thanks for your information.
As I try to use the old version of U-Boot, it doesn't support DM well.

> If not, you are right, you must define your own
> I2C_SCL/I2C_SDA/I2C_READ/I2C_INIT
> defines, for example:
>
> #  define I2C_SCL(bit) \
>          do { \
>          switch(I2C_ADAP_HWNR) {
>              case 0:
>
> gpio_direction_output(CONFIG_SOFT_I2C_GPIO_SCL_0, bit); \
>                  break;
>              case 1:
>
> gpio_direction_output(CONFIG_SOFT_I2C_GPIO_SCL_1, bit); \
>                  break;
>              [...]
>                  I2C_GPIO_SYNC; \
>          } while (0)

For this, the I2C_SCL and I2C_SDA working, however for I2C_READ, it 
maybe need to modify the definition from micro to function, as the 
I2C_READ can not use do {} while.

Thanks again.

> bye,
> Heiko

Best Regards,
Bo Shen

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

* [U-Boot] question about software i2c multi instance
  2015-03-20  9:44 [U-Boot] question about software i2c multi instance Bo Shen
  2015-03-20 10:10 ` Heiko Schocher
@ 2015-03-23  8:28 ` Lukasz Majewski
  2015-03-23  8:36   ` Bo Shen
  1 sibling, 1 reply; 7+ messages in thread
From: Lukasz Majewski @ 2015-03-23  8:28 UTC (permalink / raw)
  To: u-boot

Hi Bo,

> Hi Heiko,
>    After check the software i2c code, I found it can not support
> multi instances, although it has I2C_SOFT_DECLARATIONS2, 
> I2C_SOFT_DECLARATIONS3, I2C_SOFT_DECLARATIONS4.
>    Because, when do GPIO operation, there is only one pair of 
> CONFIG_SOFT_I2C_GPIO_SCL and CONFIG_SOFT_I2C_GPIO_SDA.
>    So, if want to support multi instances, it needs to extend the
> GPIO configuration for SCL/SDA, am I right?

Some time ago we had a similar problem with SW I2C code. Please look
into Samsung's trats board implementation.

However, such approach might be outdated, since Przemek is working on
porting this functionality to device model:

https://patchwork.ozlabs.org/patch/448460/

> 
>    Thanks.
> 
> Best Regards,
> Bo Shen



-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] question about software i2c multi instance
  2015-03-23  8:28 ` Lukasz Majewski
@ 2015-03-23  8:36   ` Bo Shen
  2015-03-23  8:47     ` Przemyslaw Marczak
  0 siblings, 1 reply; 7+ messages in thread
From: Bo Shen @ 2015-03-23  8:36 UTC (permalink / raw)
  To: u-boot

Hi Lukasz,

On 03/23/2015 04:28 PM, Lukasz Majewski wrote:
> Hi Bo,
>
>> Hi Heiko,
>>     After check the software i2c code, I found it can not support
>> multi instances, although it has I2C_SOFT_DECLARATIONS2,
>> I2C_SOFT_DECLARATIONS3, I2C_SOFT_DECLARATIONS4.
>>     Because, when do GPIO operation, there is only one pair of
>> CONFIG_SOFT_I2C_GPIO_SCL and CONFIG_SOFT_I2C_GPIO_SDA.
>>     So, if want to support multi instances, it needs to extend the
>> GPIO configuration for SCL/SDA, am I right?
>
> Some time ago we had a similar problem with SW I2C code. Please look
> into Samsung's trats board implementation.
>
> However, such approach might be outdated, since Przemek is working on
> porting this functionality to device model:
>
> https://patchwork.ozlabs.org/patch/448460/

Thanks for your information.
Now, I just do it as following to make it work. For next step, I will 
try to switch to use DM.

--->8---
diff --git a/drivers/i2c/soft_i2c.c b/drivers/i2c/soft_i2c.c
index db9b402..b9cfbb8 100644
--- a/drivers/i2c/soft_i2c.c
+++ b/drivers/i2c/soft_i2c.c
@@ -126,6 +126,13 @@ DECLARE_GLOBAL_DATA_PTR;
  #define PRINTD(fmt,args...)
  #endif

+#ifdef I2C_READ_ADAP
+static int soft_i2c_read_sda(void)
+{
+       I2C_READ_ADAP;
+}
+#endif
+
  /*-----------------------------------------------------------------------
   * Local functions
   */
@@ -256,7 +263,11 @@ static int write_byte(uchar data)
         I2C_SCL(1);
         I2C_DELAY;
         I2C_DELAY;
+#ifdef I2C_READ_ADAP
+       nack = soft_i2c_read_sda();
+#else
         nack = I2C_READ;
+#endif
         I2C_SCL(0);
         I2C_DELAY;
         I2C_ACTIVE;
@@ -286,7 +297,11 @@ static uchar read_byte(int ack)
                 I2C_SCL(1);
                 I2C_DELAY;
                 data <<= 1;
+#ifdef I2C_READ_ADAP
+               data |= soft_i2c_read_sda();
+#else
                 data |= I2C_READ;
+#endif
                 I2C_DELAY;
         }
         send_ack(ack);
---8<---

Thanks again.

Best Regards,
Bo Shen

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

* [U-Boot] question about software i2c multi instance
  2015-03-23  8:36   ` Bo Shen
@ 2015-03-23  8:47     ` Przemyslaw Marczak
  2015-03-23  9:09       ` Bo Shen
  0 siblings, 1 reply; 7+ messages in thread
From: Przemyslaw Marczak @ 2015-03-23  8:47 UTC (permalink / raw)
  To: u-boot

Hello Bo,


On 03/23/2015 09:36 AM, Bo Shen wrote:
> Hi Lukasz,
>
> On 03/23/2015 04:28 PM, Lukasz Majewski wrote:
>> Hi Bo,
>>
>>> Hi Heiko,
>>>     After check the software i2c code, I found it can not support
>>> multi instances, although it has I2C_SOFT_DECLARATIONS2,
>>> I2C_SOFT_DECLARATIONS3, I2C_SOFT_DECLARATIONS4.
>>>     Because, when do GPIO operation, there is only one pair of
>>> CONFIG_SOFT_I2C_GPIO_SCL and CONFIG_SOFT_I2C_GPIO_SDA.
>>>     So, if want to support multi instances, it needs to extend the
>>> GPIO configuration for SCL/SDA, am I right?
>>
>> Some time ago we had a similar problem with SW I2C code. Please look
>> into Samsung's trats board implementation.
>>
>> However, such approach might be outdated, since Przemek is working on
>> porting this functionality to device model:
>>
>> https://patchwork.ozlabs.org/patch/448460/
>
> Thanks for your information.
> Now, I just do it as following to make it work. For next step, I will
> try to switch to use DM.
>
> --->8---
> diff --git a/drivers/i2c/soft_i2c.c b/drivers/i2c/soft_i2c.c
> index db9b402..b9cfbb8 100644
> --- a/drivers/i2c/soft_i2c.c
> +++ b/drivers/i2c/soft_i2c.c
> @@ -126,6 +126,13 @@ DECLARE_GLOBAL_DATA_PTR;
>   #define PRINTD(fmt,args...)
>   #endif
>
> +#ifdef I2C_READ_ADAP
> +static int soft_i2c_read_sda(void)
> +{
> +       I2C_READ_ADAP;
> +}
> +#endif
> +
>   /*-----------------------------------------------------------------------
>    * Local functions
>    */
> @@ -256,7 +263,11 @@ static int write_byte(uchar data)
>          I2C_SCL(1);
>          I2C_DELAY;
>          I2C_DELAY;
> +#ifdef I2C_READ_ADAP
> +       nack = soft_i2c_read_sda();
> +#else
>          nack = I2C_READ;
> +#endif
>          I2C_SCL(0);
>          I2C_DELAY;
>          I2C_ACTIVE;
> @@ -286,7 +297,11 @@ static uchar read_byte(int ack)
>                  I2C_SCL(1);
>                  I2C_DELAY;
>                  data <<= 1;
> +#ifdef I2C_READ_ADAP
> +               data |= soft_i2c_read_sda();
> +#else
>                  data |= I2C_READ;
> +#endif
>                  I2C_DELAY;
>          }
>          send_ack(ack);
> ---8<---
>
> Thanks again.
>
> Best Regards,
> Bo Shen
>
>

Please look into the Trats2 board code in:

board/samsung/trats2/trats2.c lines 130-145
include/configs/trats2.h lines 180-185

It doesn't require i2c driver modifications. But anyway I recommend to 
use the code of my patches, which Lukasz mentioned.

Best regards,
-- 
Przemyslaw Marczak
Samsung R&D Institute Poland
Samsung Electronics
p.marczak at samsung.com

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

* [U-Boot] question about software i2c multi instance
  2015-03-23  8:47     ` Przemyslaw Marczak
@ 2015-03-23  9:09       ` Bo Shen
  0 siblings, 0 replies; 7+ messages in thread
From: Bo Shen @ 2015-03-23  9:09 UTC (permalink / raw)
  To: u-boot

Hi Przemyslaw Marczak,

On 03/23/2015 04:47 PM, Przemyslaw Marczak wrote:
>>
>
> Please look into the Trats2 board code in:
>
> board/samsung/trats2/trats2.c lines 130-145
> include/configs/trats2.h lines 180-185
>
> It doesn't require i2c driver modifications. But anyway I recommend to
> use the code of my patches, which Lukasz mentioned.

Thanks for your information. I will try this method.
Thanks again.

> Best regards,
> --
> Przemyslaw Marczak
> Samsung R&D Institute Poland
> Samsung Electronics
> p.marczak at samsung.com

Best Regards,
Bo shen

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

end of thread, other threads:[~2015-03-23  9:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-20  9:44 [U-Boot] question about software i2c multi instance Bo Shen
2015-03-20 10:10 ` Heiko Schocher
2015-03-23  6:27   ` Bo Shen
2015-03-23  8:28 ` Lukasz Majewski
2015-03-23  8:36   ` Bo Shen
2015-03-23  8:47     ` Przemyslaw Marczak
2015-03-23  9:09       ` Bo Shen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox