Skip to contentSkip to conversation

mtd: SST25L (non JEDEC) SPI Flash driver

PATCH Applied [email protected] 3 participants 6 messages Sep 18, 2009 – Sep 21, 2009 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 2/13 mtd: SST25L (non JEDEC) SPI Flash driver

From: Ryan Mallon <[email protected]>

Add support for the non JEDEC SST25L SPI Flash devices.

---

 drivers/mtd/devices/Kconfig  |   10 
 drivers/mtd/devices/Makefile |    1 
 drivers/mtd/devices/sst25l.c |  510 +++++++++++++++++++++++++++++++++
 3 files changed, 521 insertions(+)
drivers/mtd/devices/Kconfig renamed from drivers/mtd/devices/Kconfig~mtd-sst25l-non-jedec-spi-flash-driver +10 -0
diff -puN drivers/mtd/devices/Kconfig~mtd-sst25l-non-jedec-spi-flash-driver drivers/mtd/devices/Kconfig
@@ -104,6 +104,16 @@ config M25PXX_USE_FAST_READ
 	help
 	  This option enables FAST_READ access supported by ST M25Pxx.
 
+config MTD_SST25L
+	tristate "Support SST25L (non JEDEC) SPI Flash chips"
+	depends on SPI_MASTER
+	help
+	  This enables access to the non JEDEC SST25L SPI flash chips, used
+	  for program and data storage.
+
+	  Set up your spi devices with the right board-specific platform data,
+	  if you want to specify device partitioning.
+
 config MTD_SLRAM
 	tristate "Uncached system RAM"
 	help
drivers/mtd/devices/Makefile renamed from drivers/mtd/devices/Makefile~mtd-sst25l-non-jedec-spi-flash-driver +1 -0
diff -puN drivers/mtd/devices/Makefile~mtd-sst25l-non-jedec-spi-flash-driver drivers/mtd/devices/Makefile
@@ -16,3 +16,4 @@ obj-$(CONFIG_MTD_LART)		+= lart.o
 obj-$(CONFIG_MTD_BLOCK2MTD)	+= block2mtd.o
 obj-$(CONFIG_MTD_DATAFLASH)	+= mtd_dataflash.o
 obj-$(CONFIG_MTD_M25P80)	+= m25p80.o
+obj-$(CONFIG_MTD_SST25L)	+= sst25l.o
drivers/mtd/devices/sst25l.c new file +510 -0

510 lines not on this page · raw message

_

#1 lore raw
Quoted 9 lines · On Fri, 2009-09-18 at 12:51 -0700, [email protected] wrote:
drivers/mtd/devices/sst25l.c new file +8 -0
+static int sst25l_wait_till_ready(struct sst25l_flash *flash)
+{
+       unsigned long deadline;
+       int status, err;
+
+       deadline = jiffies + MAX_READY_WAIT_JIFFIES;
+       do {
+               err = sst25l_status(flash, &status);

drivers/mtd/devices/sst25l.c line 135

Quoted 10 lines
drivers/mtd/devices/sst25l.c new file +10 -0
+               if (err)
+                       return err;
+               if (!(status & SST25L_STATUS_BUSY))
+                       return 0;
+
+               cond_resched();
+       } while (!time_after_eq(jiffies, deadline));
+
+       return -ETIMEDOUT;
+}

If your system is busy and you end up relinquishing the CPU for a long period of time during that cond_resched(), you could hit the timeout condition even though the hardware _is_ actually reporting 'ready' status by the time you get back on the CPU.

It's unlikely, admittedly, but it's good practice to make sure it can't happen like that. Something like

 while (busy) {
    if (timed_out) return -ETIMEDOUT;
    cond_resched();

}

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#2 lore raw
Quoted 25 lines · David Woodhouse
Quoted 8 lines · On Fri, 2009-09-18 at 12:51 -0700, [email protected] wrote:
drivers/mtd/devices/sst25l.c new file +8 -0
+static int sst25l_wait_till_ready(struct sst25l_flash *flash)
+{
+       unsigned long deadline;
+       int status, err;
+
+       deadline = jiffies + MAX_READY_WAIT_JIFFIES;
+       do {
+               err = sst25l_status(flash, &status);

drivers/mtd/devices/sst25l.c line 135

Quoted 10 lines
drivers/mtd/devices/sst25l.c new file +10 -0
+               if (err)
+                       return err;
+               if (!(status & SST25L_STATUS_BUSY))
+                       return 0;
+
+               cond_resched();
+       } while (!time_after_eq(jiffies, deadline));
+
+       return -ETIMEDOUT;
+}

If your system is busy and you end up relinquishing the CPU for a long period of time during that cond_resched(), you could hit the timeout condition even though the hardware _is_ actually reporting 'ready' status by the time you get back on the CPU.

Quoted 8 lines

It's unlikely, admittedly, but it's good practice to make sure it can't happen like that. Something like

 while (busy) {
    if (timed_out) return -ETIMEDOUT;
    cond_resched();

}

Okay, makes sense. I'm a bit busy at the moment, but I'll try and post a fix in the next couple of days. Is the patch still going to be merged as is, or are you waiting on a fix for this?

The function above is based on the one of the same name from drivers/mtd/devices/m25p80.c, so that should also be changed? There are possibly other mtd drivers which also have this construct.

~Ryan

Signature · 8 lines
Bluewater Systems Ltd - ARM Technology Solution Centre

       Ryan Mallon                              Unit 5, Amuri Park
       Phone: +64 3 3779127                     404 Barbadoes St
       Fax:   +64 3 3779135                     PO Box 13 889
       Email: [email protected]             Christchurch, 8013
       Web:   http://www.bluewatersys.com       New Zealand
       Freecall Australia  1800 148 751         USA 1800 261 2934
#3 lore raw
Quoted 11 lines · Ryan Mallon
Quoted 6 lines · David Woodhouse
 while (busy) {
    if (timed_out) return -ETIMEDOUT;
    cond_resched();

}

Okay, makes sense. I'm a bit busy at the moment, but I'll try and post a fix in the next couple of days. Is the patch still going to be merged as is, or are you waiting on a fix for this?

I've merged it already; a few days for a fix is fine. Thanks.

Quoted 3 lines

The function above is based on the one of the same name from drivers/mtd/devices/m25p80.c, so that should also be changed? There are possibly other mtd drivers which also have this construct.

Hm, yes. I try to look out for this stuff but sometimes I miss it.

Signature · 1 line
dwmw2
#4 lore raw
In reply to David Woodhouse
Quoted 25 lines · David Woodhouse
Quoted 8 lines · On Fri, 2009-09-18 at 12:51 -0700, [email protected] wrote:
drivers/mtd/devices/sst25l.c new file +8 -0
+static int sst25l_wait_till_ready(struct sst25l_flash *flash)
+{
+       unsigned long deadline;
+       int status, err;
+
+       deadline = jiffies + MAX_READY_WAIT_JIFFIES;
+       do {
+               err = sst25l_status(flash, &status);

drivers/mtd/devices/sst25l.c line 135

Quoted 10 lines
drivers/mtd/devices/sst25l.c new file +10 -0
+               if (err)
+                       return err;
+               if (!(status & SST25L_STATUS_BUSY))
+                       return 0;
+
+               cond_resched();
+       } while (!time_after_eq(jiffies, deadline));
+
+       return -ETIMEDOUT;
+}

If your system is busy and you end up relinquishing the CPU for a long period of time during that cond_resched(), you could hit the timeout condition even though the hardware _is_ actually reporting 'ready' status by the time you get back on the CPU.

Quoted 8 lines

It's unlikely, admittedly, but it's good practice to make sure it can't happen like that. Something like

 while (busy) {
    if (timed_out) return -ETIMEDOUT;
    cond_resched();

}

Just thinking about this a bit more. We don't want to call cond_resched if the device is ready immediately, and we want to do the check _after_ cond_resched each time through the loop. There are probably enough places that this sort of thing gets used that it may be worth having a generic function like this (untested):

int cond_resched_wait_timeout(unsigned long timeout_jiffies,
int (*cond_check)(void *cookie), void *data)

{
	unsigned long deadline;
	int ret;

	ret = cond_check(data);
	if (ret == 1)
		return 0;
	if (ret < 0)
		return ret;
	deadline = jiffies + timeout_jiffies;
	while (1) {
		cond_resched();
		ret = cond_check(data);
		if (ret == 1)
			return 0;
		if (ret < 0)
			return ret;

		if (time_after_eq(jiffies, deadline))
			return -ETIMEDOUT;
	}

	/* Not reached */
	return 0;
}

Not sure if the name is entirely appropriate, or where it should go as a generic function. Thoughts?

~Ryan

Signature · 8 lines
Bluewater Systems Ltd - ARM Technology Solution Centre

       Ryan Mallon                              Unit 5, Amuri Park
       Phone: +64 3 3779127                     404 Barbadoes St
       Fax:   +64 3 3779135                     PO Box 13 889
       Email: [email protected]             Christchurch, 8013
       Web:   http://www.bluewatersys.com       New Zealand
       Freecall Australia  1800 148 751         USA 1800 261 2934
#5 lore raw
Quoted 9 lines · Ryan Mallon
Quoted 5 lines
 while (busy) {
    if (timed_out) return -ETIMEDOUT;
    cond_resched();

}

Just thinking about this a bit more. We don't want to call cond_resched if the device is ready immediately, and we want to do the check _after_ cond_resched each time through the loop.

Right, absolutely.

And that's exactly what the loop above was doing, isn't it? If you unroll the loop, it goes...

if (busy) {
if (timed_out) return -ETIMEDOUT;
cond_resched();

  if (busy) {
    if (timed_out) return -ETIMEDOUT;
    cond_resched();
    if (busy) {
      if (timed_out) return -ETIMEDOUT;
      cond_resched();
      if (busy) {
        ...

It _isn't_ calling cond_resched() if the device is ready immediately, and it _is_ doing the check _after_ cond_resched() each time. Yes?

Quoted 6 lines

There are probably enough places that this sort of thing gets used that it may be worth having a generic function like this (untested):

int cond_resched_wait_timeout(unsigned long timeout_jiffies,
int (*cond_check)(void *cookie), void *data)

Yes, it's probably a good idea. Maybe better off as a macro, rather than having a function call to evaluate the condition. Much like wait_event?

Signature · 1 line
dwmw2