[PATCH 6/6] mtd: maps: sa1100-flash: Add reference counter to set_vpp()
Paul Parsons
lost.distance at yahoo.com
Wed Mar 7 09:14:31 EST 2012
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>
---
diff -uprN clean-3.3-rc6/drivers/mtd/maps/sa1100-flash.c linux-3.3-rc6/drivers/mtd/maps/sa1100-flash.c
--- clean-3.3-rc6/drivers/mtd/maps/sa1100-flash.c 2012-03-04 01:08:09.000000000 +0000
+++ linux-3.3-rc6/drivers/mtd/maps/sa1100-flash.c 2012-03-06 16:38:29.795134347 +0000
@@ -136,10 +136,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
mailing list