Patchwork [1/2] mtd: maps: physmap: Add GPIO VPP control

login
register
mail settings
Submitter Pawel Moll
Date July 12, 2012, 4:38 p.m.
Message ID <1342111121-23161-2-git-send-email-pawel.moll@arm.com>
Download mbox | patch
Permalink /patch/170725/
State New
Headers show

Comments

Pawel Moll - July 12, 2012, 4:38 p.m.
Add GPIO control of the VPP signal:
* platform data fields to specify GPIO number and polarity
* set_vpp implementation setting the GPIO value

Signed-off-by: Pawel Moll <pawel.moll@arm.com>
---
 drivers/mtd/maps/physmap.c  |   22 ++++++++++++++++++++++
 include/linux/mtd/physmap.h |    2 ++
 2 files changed, 24 insertions(+)

Patch

diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index 21b0b71..3ef4e1e 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -20,6 +20,7 @@ 
 #include <linux/mtd/physmap.h>
 #include <linux/mtd/concat.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 
 #define MAX_RESOURCES		4
 
@@ -87,6 +88,14 @@  static void physmap_set_vpp(struct map_info *map, int state)
 	spin_unlock_irqrestore(&info->vpp_lock, flags);
 }
 
+static void physmap_set_gpio_vpp(struct platform_device *pdev, int state)
+{
+	struct physmap_flash_data *physmap_data = pdev->dev.platform_data;
+
+	gpio_set_value(physmap_data->gpio_vpp,
+			!!state ^ !!physmap_data->gpio_vpp_active_low);
+}
+
 static const char *rom_probe_types[] = {
 					"cfi_probe",
 					"jedec_probe",
@@ -123,6 +132,19 @@  static int physmap_flash_probe(struct platform_device *dev)
 			goto err_out;
 	}
 
+	if (!physmap_data->set_vpp && gpio_is_valid(physmap_data->gpio_vpp)) {
+		unsigned long flags = GPIOF_DIR_OUT;
+		if (physmap_data->gpio_vpp_active_low)
+			flags |= GPIOF_INIT_HIGH;
+		else
+			flags |= GPIOF_INIT_LOW;
+		err = devm_gpio_request_one(&dev->dev, physmap_data->gpio_vpp,
+				flags, dev_name(&dev->dev));
+		if (err)
+			goto err_out;
+		physmap_data->set_vpp = physmap_set_gpio_vpp;
+	}
+
 	platform_set_drvdata(dev, info);
 
 	for (i = 0; i < dev->num_resources; i++) {
diff --git a/include/linux/mtd/physmap.h b/include/linux/mtd/physmap.h
index d2887e7..b5c85b6 100644
--- a/include/linux/mtd/physmap.h
+++ b/include/linux/mtd/physmap.h
@@ -26,6 +26,8 @@  struct physmap_flash_data {
 	int			(*init)(struct platform_device *);
 	void			(*exit)(struct platform_device *);
 	void			(*set_vpp)(struct platform_device *, int);
+	int			gpio_vpp;
+	bool			gpio_vpp_active_low;
 	unsigned int		nr_parts;
 	unsigned int		pfow_base;
 	char                    *probe_type;