[U-Boot] [PATCH v2 5/9] i2c: sh_i2c: enable i2c_probe

Nobuhiro Iwamatsu nobuhiro.iwamatsu.yj at renesas.com
Thu Sep 13 07:15:18 CEST 2012


On Wed, Sep 12, 2012 at 5:46 PM, Tetsuyuki Kobayashi <koba at kmckk.co.jp> wrote:
> Before this patch i2c_probe() always returned 0 and "i2c probe" command did not work properly.
>
> Modify i2c_set_addr() to check TACK when waiting DTE and make i2c_probe() call this function.
>
> Signed-off-by: Tetsuyuki Kobayashi <koba at kmckk.co.jp>
> ---
> Changes for v2:
>  - new
>
>  drivers/i2c/sh_i2c.c |   29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i2c/sh_i2c.c b/drivers/i2c/sh_i2c.c
> index d524619..25dbc43 100644
> --- a/drivers/i2c/sh_i2c.c
> +++ b/drivers/i2c/sh_i2c.c
> @@ -85,6 +85,21 @@ static void irq_dte(struct sh_i2c *base)
>         }
>  }
>
> +static int irq_dte_with_tack(struct sh_i2c *base)
> +{
> +       int i;
> +       int ret = 0;
> +
> +       for (i = 0 ; i < IRQ_WAIT ; i++) {
> +               if (SH_IC_DTE & readb(&base->icsr))
> +                       break;
> +               if (SH_IC_TACK & readb(&base->icsr))
> +                       return -1;
> +               udelay(10);
> +       }
> +       return ret;
> +}
> +
>  static void irq_busy(struct sh_i2c *base)
>  {
>         int i;
> @@ -96,9 +111,9 @@ static void irq_busy(struct sh_i2c *base)
>         }
>  }
>
> -static void i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop)
> +static int i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop)
>  {
> -       u8 icic = 0;
> +       u8 icic = SH_IC_TACK;
>
>         writeb(readb(&base->iccr) & ~SH_I2C_ICCR_ICE, &base->iccr);
>         writeb(readb(&base->iccr) | SH_I2C_ICCR_ICE, &base->iccr);
> @@ -116,14 +131,18 @@ static void i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop)
>         writeb((SH_I2C_ICCR_ICE|SH_I2C_ICCR_RTS|SH_I2C_ICCR_BUSY), &base->iccr);
>         irq_dte(base);
>
> +       writeb(readb(&base->icsr) & ~SH_IC_TACK, &base->icsr);
>         writeb(id << 1, &base->icdr);
> -       irq_dte(base);
> +       if (irq_dte_with_tack(base) != 0)
> +               return -1;
>
>         writeb(reg, &base->icdr);
>         if (stop)
>                 writeb((SH_I2C_ICCR_ICE|SH_I2C_ICCR_RTS), &base->iccr);
>
> -       irq_dte(base);
> +       if (irq_dte_with_tack(base) != 0)
> +               return -1;
> +       return 0;
>  }
>
>  static void i2c_finish(struct sh_i2c *base)
> @@ -321,5 +340,5 @@ int i2c_write(u8 chip, u32 addr, int alen, u8 *buffer, int len)
>   */
>  int i2c_probe(u8 chip)
>  {
> -       return 0;
> +       return i2c_set_addr(base, chip, 0, 1);
>  }
> --
> 1.7.9.5
>
Acked-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj at renesas.com>

Best regards,
  Nobuhiro



-- 
Nobuhiro Iwamatsu


More information about the U-Boot mailing list