All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V3 05/11] I2C: mxc_i2c: address failure with mx35 processor
Date: Fri, 21 Jan 2011 07:36:27 +0100	[thread overview]
Message-ID: <4D39296B.7020907@denx.de> (raw)
In-Reply-To: <1295545891-12574-1-git-send-email-sbabic@denx.de>

Hello Stefano,

just a question ...

Stefano Babic wrote:
> There is sporadic failures when more as one I2C slave
> is on the bus and the processor tries to communicate
> with more as one slave.
> The problem was seen on a mx35pdk (two I2C slaves,
> PMIC controller and CAN/RTC chip).
> 
> The current driver uses the IIF bit in the status register
> to check if the bus is busy or not. According to the manual,
> this is not correct, because the IIB bit should be checked.
> Not only, to check if a transfer is finished must be checked
> the ICF bit, and this is not tested at all.
> 
> This patch comes from analyse with a corresponding driver
> provided by Freescale as part of the LTIB tool. Comparing
> the two drivers, it appears that the current u-boot driver checks
> the wrong bits, and depending on race condition, the transfer
> can be successful or not.
> 
> The patch gets rid also of own debug function (DPRINTF),
> replaced with the general debug().
> 
> Tested on Freescale mx35pdk.
> 
> Signed-off-by: Stefano Babic <sbabic@denx.de>
> CC: Heiko Schocher <hs@denx.de>
> ---
> Changes:
> 
> Wolfgang Denk:
> 	- change commit message explaining the problem
> 	and the changes
> 	- describe in commit message the drop of DPRINTF
> 
>  drivers/i2c/mxc_i2c.c |   86 ++++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 68 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
> index fd6db18..c5ec486 100755
> --- a/drivers/i2c/mxc_i2c.c
> +++ b/drivers/i2c/mxc_i2c.c
[...]
> @@ -116,31 +113,61 @@ void i2c_init(int speed, int unused)
>  	i2c_reset();
>  }
>  
> +static int wait_idle(void)
> +{
> +	int timeout = I2C_MAX_TIMEOUT;
> +
> +	while ((readw(I2C_BASE + I2SR) & I2SR_IBB) && --timeout) {
> +		writew(0, I2C_BASE + I2SR);
> +		udelay(1);
> +	}
> +	return timeout ? timeout : (!(readw(I2C_BASE + I2SR) & I2SR_IBB));
> +}
> +
>  static int wait_busy(void)
>  {
> -	int timeout = 10000;
> +	int timeout = I2C_MAX_TIMEOUT;
>  
> -	while (!(readw(I2C_BASE + I2SR) & I2SR_IIF) && --timeout)
> +	while (!(readw(I2C_BASE + I2SR) & I2SR_IBB) && --timeout)
>  		udelay(1);
>  	writew(0, I2C_BASE + I2SR); /* clear interrupt */
>  
>  	return timeout;
>  }
>  
> +static int wait_complete(void)
> +{
> +	int timeout = I2C_MAX_TIMEOUT;
> +
> +	while ((!(readw(I2C_BASE + I2SR) & I2SR_ICF)) && (--timeout)) {
> +		writew(0, I2C_BASE + I2SR);
> +		udelay(1);
> +	}
> +	udelay(200);

Why is this delay necessary? Why exactly 200? Is this documented
somewhere in the doc?

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  reply	other threads:[~2011-01-21  6:36 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-20  8:46 [U-Boot] Adding support for MX35 Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 01/11] Add support for MX35 processor Stefano Babic
2011-01-20  9:25   ` Wolfgang Denk
2011-01-20 10:19     ` Stefano Babic
2011-01-20 11:52       ` Wolfgang Denk
2011-01-20 17:49   ` [U-Boot] [PATCH V3 " Stefano Babic
2011-02-01 17:50     ` Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 02/11] serial_mxc: add support for Freescale's i.MX35 processor Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 03/11] mxc_i2c: Add support for the " Stefano Babic
2011-01-21  6:28   ` Heiko Schocher
2011-01-20  8:46 ` [U-Boot] [PATCH V2 04/11] I2C: mxc_i2c: get rid of __REG access Stefano Babic
2011-01-20  9:27   ` Wolfgang Denk
2011-01-20 10:23     ` Stefano Babic
2011-01-20 17:50   ` [U-Boot] [PATCH V3 " Stefano Babic
2011-01-21  6:30     ` Heiko Schocher
2011-01-20  8:46 ` [U-Boot] [PATCH V2 05/11] I2C: mxc_i2c: address failure with mx35 processor Stefano Babic
2011-01-20  9:30   ` Wolfgang Denk
2011-01-20 10:27     ` Stefano Babic
2011-01-20 17:51   ` [U-Boot] [PATCH V3 " Stefano Babic
2011-01-21  6:36     ` Heiko Schocher [this message]
2011-01-21  9:08       ` Stefano Babic
2011-01-21  9:21         ` Heiko Schocher
2011-01-20  8:46 ` [U-Boot] [PATCH V2 06/11] Add basic support for Freescale's mc9sdz60 Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 07/11] SPI: mxc_spi: add support for i.MX35 processor Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 08/11] SPI: mxc_spi: fix swapping bug and add missing swapping in unaligned rx case Stefano Babic
2011-01-20  9:32   ` Wolfgang Denk
2011-01-20 10:29     ` Stefano Babic
2011-01-20 11:59       ` Wolfgang Denk
2011-01-20 17:53   ` [U-Boot] [PATCH V3 " Stefano Babic
2011-02-01 17:53     ` Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 09/11] SPI: mxc_spi: add SPI clock calculation and setup to the driver Stefano Babic
2011-02-01 17:58   ` Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 10/11] SPI: mxc_spi: replace fixed offsets with structures Stefano Babic
2011-01-20  9:33   ` Wolfgang Denk
2011-01-20 10:30     ` Stefano Babic
2011-01-20  8:46 ` [U-Boot] [PATCH V2 11/11] Add support for Freescale's mx35pdk board Stefano Babic
2011-01-20  9:41   ` Wolfgang Denk
2011-01-20 10:45     ` Stefano Babic
2011-01-20 12:03       ` Wolfgang Denk
2011-01-20 17:53   ` [U-Boot] [PATCH V3 " Stefano Babic
2011-01-20 18:05     ` [U-Boot] [PATCH V4 " Stefano Babic
2011-02-01 17:51       ` Stefano Babic
2011-02-01 17:51     ` [U-Boot] [PATCH V3 " Stefano Babic
2011-01-20  9:52 ` [U-Boot] Adding support for MX35 Wolfgang Denk
2011-01-20 10:50   ` Stefano Babic
2011-01-20 12:04     ` Wolfgang Denk

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=4D39296B.7020907@denx.de \
    --to=hs@denx.de \
    --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.