Re: [PATCH v3 01/22] i2c: tegra: Make tegra_i2c_flush_fifos() usable in atomic transfer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 3, 2020 at 3:53 AM Dmitry Osipenko <digetx@xxxxxxxxx> wrote:
>
> The tegra_i2c_flush_fifos() shouldn't sleep in atomic transfer and jiffies
> are not updating if interrupts are disabled. Hence let's use proper delay
> functions and use ktime API in order not to hang atomic transfer. Note
> that this patch doesn't fix any known problem because normally FIFO is
> flushed at the time of starting a new transfer.

> +       /*
> +        * ktime_get() may take up to couple milliseconds in a worst case
> +        * and normally FIFOs are flushed, hence let's check the state before
> +        * proceeding to polling.
> +        */

Everything, including above can be done by using macros from iopoll.h. Why not?

> +       if (!(i2c_readl(i2c_dev, offset) & mask))
> +               return 0;
> +
> +       ktime = ktime_get();
> +       ktimeout = ktime_add_ms(ktime, 1000);
> +
>         while (i2c_readl(i2c_dev, offset) & mask) {
> -               if (time_after(jiffies, timeout)) {
> -                       dev_warn(i2c_dev->dev, "timeout waiting for fifo flush\n");
> -                       return -ETIMEDOUT;
> -               }
> -               usleep_range(1000, 2000);
> +               if (ktime_after(ktime, ktimeout))
> +                       goto err_timeout;
> +
> +               if (i2c_dev->is_curr_atomic_xfer)
> +                       mdelay(1);
> +               else
> +                       fsleep(1000);
> +
> +               ktime = ktime_get();
>         }
>         return 0;
> +
> +err_timeout:
> +       dev_err(i2c_dev->dev, "FIFO flushing timed out\n");
> +
> +       return -ETIMEDOUT;
>  }


-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux