public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* Tiny delays in drivers/mtd/nand/nand_base.c
@ 2015-04-01 16:40 Mason
  2015-04-01 20:52 ` Richard Weinberger
  0 siblings, 1 reply; 2+ messages in thread
From: Mason @ 2015-04-01 16:40 UTC (permalink / raw)
  To: linux-mtd; +Cc: Brian Norris, David Woodhouse

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?

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?
(I suppose sleeping longer is not a problem.)

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

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

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

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

/* 0x5 is 2**32 / 1000000000 (rounded up) */
#define ndelay(n)							\
	({								\
		if (__builtin_constant_p(n)) {				\
			if ((n) / 20000 >= 1)				\
				__bad_ndelay();				\
			else						\
				__const_udelay((n) * 5ul);		\
		} else {						\
			__ndelay(n);					\
		}							\
	})

Although it seems it should take HZ into account, as the argument
is then multiplied by ticks_per_jiffy (which is FREQ/HZ).

Regards.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Tiny delays in drivers/mtd/nand/nand_base.c
  2015-04-01 16:40 Tiny delays in drivers/mtd/nand/nand_base.c Mason
@ 2015-04-01 20:52 ` Richard Weinberger
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Weinberger @ 2015-04-01 20:52 UTC (permalink / raw)
  To: Mason; +Cc: David Woodhouse, Brian Norris, linux-mtd@lists.infradead.org

On Wed, Apr 1, 2015 at 6:40 PM, Mason <slash.tmp@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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-01 20:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-01 16:40 Tiny delays in drivers/mtd/nand/nand_base.c Mason
2015-04-01 20:52 ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox