[PATCH v2 1/2] mtd: maps: physmap: Add VPP regulator control

Pawel Moll pawel.moll at arm.com
Wed Jul 18 09:22:00 EDT 2012


Add an optional regulator control of the VPP line.
"vpp" supply must be provided by the board description.

Signed-off-by: Pawel Moll <pawel.moll at arm.com>
---
 drivers/mtd/maps/physmap.c |   24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index 21b0b71..57d79ea 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -20,6 +20,8 @@
 #include <linux/mtd/physmap.h>
 #include <linux/mtd/concat.h>
 #include <linux/io.h>
+#include <linux/err.h>
+#include <linux/regulator/consumer.h>
 
 #define MAX_RESOURCES		4
 
@@ -29,6 +31,7 @@ struct physmap_flash_info {
 	struct map_info		map[MAX_RESOURCES];
 	spinlock_t		vpp_lock;
 	int			vpp_refcnt;
+	struct regulator	*vpp_regulator;
 };
 
 static int physmap_flash_remove(struct platform_device *dev)
@@ -70,19 +73,22 @@ static void physmap_set_vpp(struct map_info *map, int state)
 
 	pdev = (struct platform_device *)map->map_priv_1;
 	physmap_data = pdev->dev.platform_data;
+	info = platform_get_drvdata(pdev);
 
-	if (!physmap_data->set_vpp)
+	if (!physmap_data->set_vpp && !info->vpp_regulator)
 		return;
 
-	info = platform_get_drvdata(pdev);
-
 	spin_lock_irqsave(&info->vpp_lock, flags);
-	if (state) {
-		if (++info->vpp_refcnt == 1)    /* first nested 'on' */
+	if (state && ++info->vpp_refcnt == 1) { /* first nested 'on' */
+		if (physmap_data->set_vpp)
 			physmap_data->set_vpp(pdev, 1);
-	} else {
-		if (--info->vpp_refcnt == 0)    /* last nested 'off' */
+		else
+			regulator_enable(info->vpp_regulator);
+	} else if (!state && --info->vpp_refcnt == 0) { /* last nested 'off' */
+		if (physmap_data->set_vpp)
 			physmap_data->set_vpp(pdev, 0);
+		else
+			regulator_disable(info->vpp_regulator);
 	}
 	spin_unlock_irqrestore(&info->vpp_lock, flags);
 }
@@ -123,6 +129,10 @@ static int physmap_flash_probe(struct platform_device *dev)
 			goto err_out;
 	}
 
+	info->vpp_regulator = devm_regulator_get(&dev->dev, "vpp");
+	if (IS_ERR(info->vpp_regulator))
+		info->vpp_regulator = NULL;
+
 	platform_set_drvdata(dev, info);
 
 	for (i = 0; i < dev->num_resources; i++) {
-- 
1.7.9.5





More information about the linux-mtd mailing list