All of lore.kernel.org
 help / color / mirror / Atom feed
From: Minkyu Kang <mk7.kang@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Exynos5: i2c: Fix read NACK handling and remove some redundancy
Date: Mon, 01 Apr 2013 20:18:46 +0900	[thread overview]
Message-ID: <51596D16.4020707@samsung.com> (raw)
In-Reply-To: <1364212004-15964-1-git-send-email-akshay.s@samsung.com>

On 25/03/13 20:46, Akshay Saraswat wrote:
> From: Gabe Black <gabeblack@google.com>
> 
> The exynos s3c24x0 i2c driver wouldn't do the right thing when a NACK was
> received on a read because it didn't attempt a read before waiting for the
> read to finish. Putting a call to ReadWriteByte in the NACK path fixed a
> problem where getting a NACK reading from a device would jam up the bus and
> prevent future accesses like probing from working.
> 
> Because other than the ReadWriteByte call the NACK and normal paths were
> almost the same thing, and to avoid future instances of the NACK path not
> working because it's not exercised normally, this change also consolidates
> those two paths.
> 
> Signed-off-by: Gabe Black <gabeblack@google.com>
> Signed-off-by: Akshay Saraswat <akshay.s@samsung.com>
> ---
>  drivers/i2c/s3c24x0_i2c.c | 53 ++++++++++++++++-------------------------------
>  1 file changed, 18 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c
> index d2b4eb0..91298a7 100644
> --- a/drivers/i2c/s3c24x0_i2c.c
> +++ b/drivers/i2c/s3c24x0_i2c.c
> @@ -366,21 +366,25 @@ static int i2c_transfer(struct s3c24x0_i2c *i2c,
>  		break;
>  
>  	case I2C_READ:
> -		if (result == I2C_OK) {
> -			writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat);
> -			writel(chip, &i2c->iicds);
> -			/* send START */
> -			writel(readl(&i2c->iicstat) | I2C_START_STOP,
> -			       &i2c->iicstat);
> -			ReadWriteByte(i2c);
> -			result = WaitForXfer(i2c);
> +	{
> +		int was_ok = (result == I2C_OK);

do you really need the was_ok?
If not, please remove it.

> +
> +		writel(chip, &i2c->iicds);
> +		/* resend START */
> +		writel(I2C_MODE_MR | I2C_TXRX_ENA |
> +					I2C_START_STOP, &i2c->iicstat);
> +		ReadWriteByte(i2c);
> +		result = WaitForXfer(i2c);
> +
> +		if (was_ok || IsACK(i2c)) {
>  			i = 0;
>  			while ((i < data_len) && (result == I2C_OK)) {
>  				/* disable ACK for final READ */
> -				if (i == data_len - 1)
> -					writel(readl(&i2c->iiccon)
> -							& ~I2CCON_ACKGEN,
> -							&i2c->iiccon);
> +				if (i == data_len - 1) {
> +					writel(readl(&i2c->iiccon) &
> +					      ~I2CCON_ACKGEN,
> +					      &i2c->iiccon);
> +				}
>  				ReadWriteByte(i2c);
>  				result = WaitForXfer(i2c);
>  				data[i] = readl(&i2c->iicds);
> @@ -388,35 +392,14 @@ static int i2c_transfer(struct s3c24x0_i2c *i2c,
>  			}
>  
>  		} else {
> -			writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat);
> -			writel(chip, &i2c->iicds);
> -			/* send START */
> -			writel(readl(&i2c->iicstat) | I2C_START_STOP,
> -			       &i2c->iicstat);
> -			result = WaitForXfer(i2c);
> -
> -			if (IsACK(i2c)) {
> -				i = 0;
> -				while ((i < data_len) && (result == I2C_OK)) {
> -					/* disable ACK for final READ */
> -					if (i == data_len - 1)
> -						writel(readl(&i2c->iiccon) &
> -							~I2CCON_ACKGEN,
> -							&i2c->iiccon);
> -					ReadWriteByte(i2c);
> -					result = WaitForXfer(i2c);
> -					data[i] = readl(&i2c->iicds);
> -					i++;
> -				}
> -			} else {
> -				result = I2C_NACK;
> -			}
> +			result = I2C_NACK;
>  		}
>  
>  		/* send STOP */
>  		writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat);
>  		ReadWriteByte(i2c);
>  		break;
> +	}
>  
>  	default:
>  		debug("i2c_transfer: bad call\n");
> 

Thanks,
Minkyu Kang.

  reply	other threads:[~2013-04-01 11:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-25 11:46 [U-Boot] [PATCH] Exynos5: i2c: Fix read NACK handling and remove some redundancy Akshay Saraswat
2013-04-01 11:18 ` Minkyu Kang [this message]
2013-04-09  6:30 ` Hung-ying Tyan
  -- strict thread matches above, loose matches on Subject: below --
2013-04-09  8:08 Akshay Saraswat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51596D16.4020707@samsung.com \
    --to=mk7.kang@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.