Tiny delays in drivers/mtd/nand/nand_base.c

Richard Weinberger richard.weinberger at gmail.com
Wed Apr 1 13:52:29 PDT 2015


On Wed, Apr 1, 2015 at 6:40 PM, Mason <slash.tmp at free.fr> wrote:
> Hello everyone,
>
> In drivers/mtd/nand/nand_base.c there are several instances of
> the following code:
>
>         /*
>          * Apply this short delay always to ensure that we do wait tWB in
>          * any case on any machine.
>          */
>         ndelay(100);
>
>
> Is the intent to spin for 100 nanoseconds?

Yes. tWB is 100ns.

> It seems that, for most platforms, ndelay is defined as:
> udelay(DIV_ROUND_UP(x, 1000))
>
> So it will resolve to udelay(1) if I understand correctly?

If your kernel has the above definition, yes.

> (I suppose sleeping longer is not a problem.)

That covers my knowledge.

> However the comment implies that 100 ns are sufficient, right?

Spec wants tWB to be at least 100ns.

> So if I override ndelay with a function that sleeps *exactly*
> the amount requested, everything should keep working?

Yes.

> The reason I ask is because someone added this comment in my
> source tree:
>
> #ifdef CONFIG_TANGOX
>         udelay(1); /* needs to make it much longer than tWB */
> #else
>         ndelay(100);
> #endif

Looks fishy. Maybe this papers over a BSP bug.

> Also I have to figure out why the build is not picking up this
> definition for ndelay (from include/asm-generic/delay.h)

Not all archs use generic delay.h

HTH,
//richard



More information about the linux-mtd mailing list