[RFC PATCH 3/3] Add panic_write function to the onenand driver

Richard Purdie rpurdie at rpsys.net
Thu Jan 31 05:03:34 EST 2008


On Thu, 2008-01-31 at 11:05 +0900, Kyungmin Park wrote:
> > +static void onenand_panic_wait(struct mtd_info *mtd)
> > +{
> > +	struct onenand_chip *this = mtd->priv;
> > +	unsigned int interrupt;
> > +	int i;
> > +
> > +	for (i = 0; i < 20; i++) {
> > +		interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
> > +		if (interrupt & ONENAND_INT_MASTER)
> > +			break;
> > +		udelay(1000);
> > +	}
> > +}
> 
> Umm it's waiting with maximum 20msec. how about the increase the index to 20*1000 and use udelay(1).
> If we use the busy-waiting, it uses the max 3msec in case of erase.

I'm ok with changing it to use udelay(10). This function is going to be
rarely called so efficiency isn't a primary concern... 

> Anyway I think you don't use the onenand_wait since it has
> cond_resched(). It's better to use the existing function in case of
> panic_write.
> Okay try to think what's the better way.

Yes, I'm avoiding onenand_wait since we can't schedule in this context.
Other ideas welcome :)

> > + */
> > +static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
> > +			 size_t *retlen, const u_char *buf)
> > +{
> > +	struct onenand_chip *this = mtd->priv;
> > +	int column, subpage;
> > +	int written = 0;
> > +	int ret = 0;
> > +
> > +	if (this->state == FL_PM_SUSPENDED)
> > +		return -EBUSY;
> > +
> > +	/* Wait for any existing operation to clear */
> > +	onenand_panic_wait(mtd);
> 
> Reasonable!
> 
> > +
> > +		this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize);
> > +		this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
> > +
> > +		this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize);
> > +
> > +		onenand_panic_wait(mtd);
> 
> It has to check the return value and update the bufferram. If not, we can read the wrong data later.

The key point with panic_write is there is unlikely to be any "later". I
don't mind putting the bufferram update calls back if you're happier
with that though.

Cheers,

Richard





More information about the linux-mtd mailing list