The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] regulator: Add GPIO enable control to fixed voltage regulator driver
@ 2009-07-31 12:55 Roger Quadros
  2009-07-31 13:10 ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Roger Quadros @ 2009-07-31 12:55 UTC (permalink / raw)
  To: broonie; +Cc: lrg, linux-kernel

From: Roger Quadros <ext-roger.quadros@nokia.com>

Now fixed regulators that have their enable pin connected to a GPIO line
can use the fixed regulator driver. The GPIO number and polarity
information is passed through platform data. GPIO enable control
is acheived using gpiolib.

Signed-off-by: Roger Quadros <ext-roger.quadros@nokia.com>
---
 drivers/regulator/fixed.c       |   60 ++++++++++++++++++++++++++++++++++++++-
 include/linux/regulator/fixed.h |    7 ++++
 2 files changed, 66 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index cdc674f..4ba6a50 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -20,20 +20,51 @@
 #include <linux/platform_device.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/fixed.h>
+#include <linux/gpio.h>
 
 struct fixed_voltage_data {
 	struct regulator_desc desc;
 	struct regulator_dev *dev;
 	int microvolts;
+	int use_gpio_control;
+	int gpio;
+	int enable_high;
+	int is_enabled;
 };
 
 static int fixed_voltage_is_enabled(struct regulator_dev *dev)
 {
-	return 1;
+	struct fixed_voltage_data *data = rdev_get_drvdata(dev);
+
+	if (data->use_gpio_control)
+		return data->is_enabled;
+	else
+		return 1;
 }
 
 static int fixed_voltage_enable(struct regulator_dev *dev)
 {
+	struct fixed_voltage_data *data = rdev_get_drvdata(dev);
+
+	if (data->use_gpio_control) {
+		gpio_set_value(data->gpio,
+				data->enable_high ? 1 : 0);
+		data->is_enabled = 1;
+	}
+
+	return 0;
+}
+
+static int fixed_voltage_disable(struct regulator_dev *dev)
+{
+	struct fixed_voltage_data *data = rdev_get_drvdata(dev);
+
+	if (data->use_gpio_control) {
+		gpio_set_value(data->gpio,
+				data->enable_high ? 0 : 1);
+		data->is_enabled = 0;
+	}
+
 	return 0;
 }
 
@@ -58,6 +89,7 @@ static int fixed_voltage_list_voltage(struct regulator_dev *dev,
 static struct regulator_ops fixed_voltage_ops = {
 	.is_enabled = fixed_voltage_is_enabled,
 	.enable = fixed_voltage_enable,
+	.disable = fixed_voltage_disable,
 	.get_voltage = fixed_voltage_get_voltage,
 	.list_voltage = fixed_voltage_list_voltage,
 };
@@ -85,6 +117,29 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev)
 	drvdata->desc.n_voltages = 1;
 
 	drvdata->microvolts = config->microvolts;
+	drvdata->use_gpio_control = config->use_gpio_control;
+	if (drvdata->use_gpio_control) {
+		drvdata->gpio = config->gpio;
+		drvdata->enable_high = config->enable_high;
+
+		ret = gpio_request(config->gpio,
+					config->supply_name);
+		if (ret) {
+			dev_err(&pdev->dev, "Could not obtain regulator " \
+					"enable GPIO %d\n", config->gpio);
+			goto err_name;
+		} else {
+			ret = gpio_direction_output(config->gpio,
+				config->enable_high ? 0 : 1);
+			if (ret) {
+				dev_err(&pdev->dev, "Could not configure " \
+					"enable GPIO %d direction\n",
+					config->gpio);
+				gpio_free(config->gpio);
+				goto err_name;
+			}
+		}
+	}
 
 	drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
 					  config->init_data, drvdata);
@@ -115,6 +170,9 @@ static int regulator_fixed_voltage_remove(struct platform_device *pdev)
 	kfree(drvdata->desc.name);
 	kfree(drvdata);
 
+	if (drvdata->_use_gpio_control)
+		gpio_free(drvdata->gpio);
+
 	return 0;
 }
 
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h
index 91b4da3..5b963cc 100644
--- a/include/linux/regulator/fixed.h
+++ b/include/linux/regulator/fixed.h
@@ -19,6 +19,13 @@ struct regulator_init_data;
 struct fixed_voltage_config {
 	const char *supply_name;
 	int microvolts;
+	int use_gpio_control;	/* Use GPIO enable control */
+	int gpio;		/* GPIO to use for enable control */
+
+	int enable_high;	/* Polarity of enable GPIO
+				 * 1 = Active High, 0 = Active Low
+				 */
+
 	struct regulator_init_data *init_data;
 };
 
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-07-31 14:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-31 12:55 [PATCH] regulator: Add GPIO enable control to fixed voltage regulator driver Roger Quadros
2009-07-31 13:10 ` Mark Brown
2009-07-31 13:25   ` pHilipp Zabel
2009-07-31 13:34     ` Mark Brown
2009-07-31 13:43       ` Roger Quadros
2009-07-31 13:50         ` Mark Brown
     [not found]           ` <b90c0690907310713w5c8b7fe3l4253f03f78f06491@mail.gmail.com>
     [not found]             ` <20090731141547.GA6505@rakim.wolfsonmicro.main>
2009-07-31 14:22               ` Roger Quadros
2009-07-31 14:34                 ` Roger Quadros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox