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

Mason slash.tmp at free.fr
Wed Apr 1 09:40:17 PDT 2015


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.



More information about the linux-mtd mailing list