From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bo Shen Date: Mon, 23 Mar 2015 16:36:08 +0800 Subject: [U-Boot] question about software i2c multi instance In-Reply-To: <20150323092828.7a22c885@amdc2363> References: <550BEBEC.7060609@atmel.com> <20150323092828.7a22c885@amdc2363> Message-ID: <550FD078.1040804@atmel.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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