mtd: maps: sa1100-flash: Add reference counter to set_vpp()

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Mar 26 20:59:16 EDT 2012


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=ee478af8b675908b217198a75cf759d422a81ccb
Commit:     ee478af8b675908b217198a75cf759d422a81ccb
Parent:     7c8d206f219fe52966d970f791246a542718e5ba
Author:     Paul Parsons <lost.distance at yahoo.com>
AuthorDate: Wed Mar 7 14:14:31 2012 +0000
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Tue Mar 27 00:53:02 2012 +0100

    mtd: maps: sa1100-flash: Add reference counter to set_vpp()
    
    This patch is part of a set which fixes unnecessary flash erase and write errors
    resulting from the MTD CFI driver turning off vpp while an erase is in progress.
    This patch allows sa1100_set_vpp() calls to be nested by adding a reference
    counter.
    
    Signed-off-by: Paul Parsons <lost.distance at yahoo.com>
    Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/maps/sa1100-flash.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index cbc3b78..1eaf7b6 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -36,10 +36,22 @@ struct sa_info {
 	struct sa_subdev_info	subdev[0];
 };
 
+static DEFINE_SPINLOCK(sa1100_vpp_lock);
+static int sa1100_vpp_refcnt;
 static void sa1100_set_vpp(struct map_info *map, int on)
 {
 	struct sa_subdev_info *subdev = container_of(map, struct sa_subdev_info, map);
-	subdev->plat->set_vpp(on);
+	unsigned long flags;
+
+	spin_lock_irqsave(&sa1100_vpp_lock, flags);
+	if (on) {
+		if (++sa1100_vpp_refcnt == 1)   /* first nested 'on' */
+			subdev->plat->set_vpp(1);
+	} else {
+		if (--sa1100_vpp_refcnt == 0)   /* last nested 'off' */
+			subdev->plat->set_vpp(0);
+	}
+	spin_unlock_irqrestore(&sa1100_vpp_lock, flags);
 }
 
 static void sa1100_destroy_subdev(struct sa_subdev_info *subdev)



More information about the linux-mtd-cvs mailing list