diff mbox series

[U-Boot,1/7] imx: mxc_i2c: tweak the i2c transfer method

Message ID 1509029285-27071-2-git-send-email-martyn@welchs.me.uk
State Superseded
Delegated to: Stefano Babic
Headers show
Series Add support for GE PPD | expand

Commit Message

Martyn Welch Oct. 26, 2017, 2:47 p.m. UTC
From: Nandor Han <nandor.han@ge.com>

Tweak the i2c transfer to work for devices that want to read data
without addressing a register.

Signed-off-by: Nandor Han <nandor.han@ge.com>
Signed-off-by: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Heiko Schocher <hs@denx.de>
Cc: Stefano Babic <sbabic@denx.de>
Signed-off-by: Martyn Welch <martyn@welchs.me.uk>
---
 drivers/i2c/mxc_i2c.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

Comments

Heiko Schocher Oct. 31, 2017, 4:27 a.m. UTC | #1
Hello Martyn,

Am 26.10.2017 um 16:47 schrieb Martyn Welch:
> From: Nandor Han <nandor.han@ge.com>
> 
> Tweak the i2c transfer to work for devices that want to read data
> without addressing a register.
> 
> Signed-off-by: Nandor Han <nandor.han@ge.com>
> Signed-off-by: Martyn Welch <martyn.welch@collabora.co.uk>
> Cc: Heiko Schocher <hs@denx.de>
> Cc: Stefano Babic <sbabic@denx.de>
> Signed-off-by: Martyn Welch <martyn@welchs.me.uk>
> ---
>   drivers/i2c/mxc_i2c.c | 25 +++++++++++++++----------
>   1 file changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
> index abf1da2..01f268b 100644
> --- a/drivers/i2c/mxc_i2c.c
> +++ b/drivers/i2c/mxc_i2c.c
> @@ -317,16 +317,19 @@ static int i2c_init_transfer_(struct mxc_i2c_bus *i2c_bus, u8 chip,
>   	temp |= I2CR_MTX | I2CR_TX_NO_AK;
>   	writeb(temp, base + (I2CR << reg_shift));
>   
> -	/* write slave address */
> -	ret = tx_byte(i2c_bus, chip << 1);
> -	if (ret < 0)
> -		return ret;
> -
> -	while (alen--) {
> -		ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff);
> +	if (alen != -1)	{

I prefer here a "if (alen >= 0) {"

Thanks!

bye,
Heiko
Nandor Han Oct. 31, 2017, 12:46 p.m. UTC | #2
> -----Original Message-----

> From: Heiko Schocher [mailto:hs@denx.de]

> Sent: 31 October 2017 06:28

> To: Martyn Welch <martyn@welchs.me.uk>

> Cc: u-boot@lists.denx.de; Han, Nandor (GE Healthcare)

> <nandor.han@ge.com>; Martyn Welch <martyn.welch@collabora.co.uk>;

> Stefano Babic <sbabic@denx.de>

> Subject: EXT: Re: [PATCH 1/7] imx: mxc_i2c: tweak the i2c transfer method

> 

> Hello Martyn,

> 

> Am 26.10.2017 um 16:47 schrieb Martyn Welch:

> > From: Nandor Han <nandor.han@ge.com>

> >

> > Tweak the i2c transfer to work for devices that want to read data

> > without addressing a register.

> >

> > Signed-off-by: Nandor Han <nandor.han@ge.com>

> > Signed-off-by: Martyn Welch <martyn.welch@collabora.co.uk>

> > Cc: Heiko Schocher <hs@denx.de>

> > Cc: Stefano Babic <sbabic@denx.de>

> > Signed-off-by: Martyn Welch <martyn@welchs.me.uk>

> > ---

> >   drivers/i2c/mxc_i2c.c | 25 +++++++++++++++----------

> >   1 file changed, 15 insertions(+), 10 deletions(-)

> >

> > diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c index

> > abf1da2..01f268b 100644

> > --- a/drivers/i2c/mxc_i2c.c

> > +++ b/drivers/i2c/mxc_i2c.c

> > @@ -317,16 +317,19 @@ static int i2c_init_transfer_(struct mxc_i2c_bus

> *i2c_bus, u8 chip,

> >   	temp |= I2CR_MTX | I2CR_TX_NO_AK;

> >   	writeb(temp, base + (I2CR << reg_shift));

> >

> > -	/* write slave address */

> > -	ret = tx_byte(i2c_bus, chip << 1);

> > -	if (ret < 0)

> > -		return ret;

> > -

> > -	while (alen--) {

> > -		ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff);

> > +	if (alen != -1)	{

> 

> I prefer here a "if (alen >= 0) {"


In normal cases yes. It looks that i2c framework doesn't support requesting data from i2c without addressing the slave. 
In this case -1 is used to specify that address is not needed.

> 

> Thanks!

> 

> bye,

> Heiko

> --

> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk

> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

> Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de
diff mbox series

Patch

diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
index abf1da2..01f268b 100644
--- a/drivers/i2c/mxc_i2c.c
+++ b/drivers/i2c/mxc_i2c.c
@@ -317,16 +317,19 @@  static int i2c_init_transfer_(struct mxc_i2c_bus *i2c_bus, u8 chip,
 	temp |= I2CR_MTX | I2CR_TX_NO_AK;
 	writeb(temp, base + (I2CR << reg_shift));
 
-	/* write slave address */
-	ret = tx_byte(i2c_bus, chip << 1);
-	if (ret < 0)
-		return ret;
-
-	while (alen--) {
-		ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff);
+	if (alen != -1)	{
+		/* write slave address */
+		ret = tx_byte(i2c_bus, chip << 1);
 		if (ret < 0)
 			return ret;
+
+		while (alen--) {
+			ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff);
+			if (ret < 0)
+				return ret;
+		}
 	}
+
 	return 0;
 }
 
@@ -537,9 +540,11 @@  static int bus_i2c_read(struct mxc_i2c_bus *i2c_bus, u8 chip, u32 addr,
 	if (ret < 0)
 		return ret;
 
-	temp = readb(base + (I2CR << reg_shift));
-	temp |= I2CR_RSTA;
-	writeb(temp, base + (I2CR << reg_shift));
+	if (alen != -1 ) {
+		temp = readb(base + (I2CR << reg_shift));
+		temp |= I2CR_RSTA;
+		writeb(temp, base + (I2CR << reg_shift));
+	}
 
 	ret = tx_byte(i2c_bus, (chip << 1) | 1);
 	if (ret < 0) {