Re: [PATCH] i2c: vt8500: Add support for I2C bus on WondermediaSoCs
From: Russell King - ARM Linux
Date: Mon Jun 10 2013 - 19:31:35 EST
On Mon, Jun 10, 2013 at 06:03:29PM +0200, Wolfram Sang wrote:
> Hi Tony,
>
> > +static int wmt_i2c_wait_bus_not_busy(struct wmt_i2c_dev *i2c_dev)
> > diff --git a/drivers/i2c/busses/i2c-wmt.c b/drivers/i2c/busses/i2c-wmt.c
> > new file mode 100644
> > index 0000000..5cebb29
> > --- /dev/null
> > +++ b/drivers/i2c/busses/i2c-wmt.c
>
> ...
>
> > +{
> > + u16 val;
> > + int i;
> > + int ret = 0;
> > +
> > + for (i = 0; i < 100000; i++) {
> > + val = readw(i2c_dev->base + REG_CSR);
> > + if (val & CSR_READY_MASK)
> > + break;
> > +
> > + udelay(1);
> > + }
> > + if (i >= 9999999)
> > + ret = -EBUSY;
>
> What about using time_after and usleep_range?
And in any case this is not the correct way to check for success or
failure.
Failure is defined by readw(i2c_dev->base + REG_CSR) & CSR_READY_MASK
being false. The above does not check it after the final 1us delay.
You might as well not wait for that final 1us because it's literally
just wasting time the way you've coded it.
Or fix it to re-check for success after the loop completes.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/