aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/fixed.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/fixed.c')
-rw-r--r--drivers/regulator/fixed.c91
1 files changed, 89 insertions, 2 deletions
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index cdc674fb46c3..f8b295700d7d 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -5,6 +5,9 @@
5 * 5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 * 7 *
8 * Copyright (c) 2009 Nokia Corporation
9 * Roger Quadros <ext-roger.quadros@nokia.com>
10 *
8 * This program is free software; you can redistribute it and/or 11 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 12 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the 13 * published by the Free Software Foundation; either version 2 of the
@@ -20,20 +23,45 @@
20#include <linux/platform_device.h> 23#include <linux/platform_device.h>
21#include <linux/regulator/driver.h> 24#include <linux/regulator/driver.h>
22#include <linux/regulator/fixed.h> 25#include <linux/regulator/fixed.h>
26#include <linux/gpio.h>
23 27
24struct fixed_voltage_data { 28struct fixed_voltage_data {
25 struct regulator_desc desc; 29 struct regulator_desc desc;
26 struct regulator_dev *dev; 30 struct regulator_dev *dev;
27 int microvolts; 31 int microvolts;
32 int gpio;
33 unsigned enable_high:1;
34 unsigned is_enabled:1;
28}; 35};
29 36
30static int fixed_voltage_is_enabled(struct regulator_dev *dev) 37static int fixed_voltage_is_enabled(struct regulator_dev *dev)
31{ 38{
32 return 1; 39 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
40
41 return data->is_enabled;
33} 42}
34 43
35static int fixed_voltage_enable(struct regulator_dev *dev) 44static int fixed_voltage_enable(struct regulator_dev *dev)
36{ 45{
46 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
47
48 if (gpio_is_valid(data->gpio)) {
49 gpio_set_value_cansleep(data->gpio, data->enable_high);
50 data->is_enabled = 1;
51 }
52
53 return 0;
54}
55
56static int fixed_voltage_disable(struct regulator_dev *dev)
57{
58 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
59
60 if (gpio_is_valid(data->gpio)) {
61 gpio_set_value_cansleep(data->gpio, !data->enable_high);
62 data->is_enabled = 0;
63 }
64
37 return 0; 65 return 0;
38} 66}
39 67
@@ -58,6 +86,7 @@ static int fixed_voltage_list_voltage(struct regulator_dev *dev,
58static struct regulator_ops fixed_voltage_ops = { 86static struct regulator_ops fixed_voltage_ops = {
59 .is_enabled = fixed_voltage_is_enabled, 87 .is_enabled = fixed_voltage_is_enabled,
60 .enable = fixed_voltage_enable, 88 .enable = fixed_voltage_enable,
89 .disable = fixed_voltage_disable,
61 .get_voltage = fixed_voltage_get_voltage, 90 .get_voltage = fixed_voltage_get_voltage,
62 .list_voltage = fixed_voltage_list_voltage, 91 .list_voltage = fixed_voltage_list_voltage,
63}; 92};
@@ -70,12 +99,14 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev)
70 99
71 drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); 100 drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
72 if (drvdata == NULL) { 101 if (drvdata == NULL) {
102 dev_err(&pdev->dev, "Failed to allocate device data\n");
73 ret = -ENOMEM; 103 ret = -ENOMEM;
74 goto err; 104 goto err;
75 } 105 }
76 106
77 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); 107 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
78 if (drvdata->desc.name == NULL) { 108 if (drvdata->desc.name == NULL) {
109 dev_err(&pdev->dev, "Failed to allocate supply name\n");
79 ret = -ENOMEM; 110 ret = -ENOMEM;
80 goto err; 111 goto err;
81 } 112 }
@@ -85,12 +116,62 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev)
85 drvdata->desc.n_voltages = 1; 116 drvdata->desc.n_voltages = 1;
86 117
87 drvdata->microvolts = config->microvolts; 118 drvdata->microvolts = config->microvolts;
119 drvdata->gpio = config->gpio;
120
121 if (gpio_is_valid(config->gpio)) {
122 drvdata->enable_high = config->enable_high;
123
124 /* FIXME: Remove below print warning
125 *
126 * config->gpio must be set to -EINVAL by platform code if
127 * GPIO control is not required. However, early adopters
128 * not requiring GPIO control may forget to initialize
129 * config->gpio to -EINVAL. This will cause GPIO 0 to be used
130 * for GPIO control.
131 *
132 * This warning will be removed once there are a couple of users
133 * for this driver.
134 */
135 if (!config->gpio)
136 dev_warn(&pdev->dev,
137 "using GPIO 0 for regulator enable control\n");
138
139 ret = gpio_request(config->gpio, config->supply_name);
140 if (ret) {
141 dev_err(&pdev->dev,
142 "Could not obtain regulator enable GPIO %d: %d\n",
143 config->gpio, ret);
144 goto err_name;
145 }
146
147 /* set output direction without changing state
148 * to prevent glitch
149 */
150 drvdata->is_enabled = config->enabled_at_boot;
151 ret = drvdata->is_enabled ?
152 config->enable_high : !config->enable_high;
153
154 ret = gpio_direction_output(config->gpio, ret);
155 if (ret) {
156 dev_err(&pdev->dev,
157 "Could not configure regulator enable GPIO %d direction: %d\n",
158 config->gpio, ret);
159 goto err_gpio;
160 }
161
162 } else {
163 /* Regulator without GPIO control is considered
164 * always enabled
165 */
166 drvdata->is_enabled = 1;
167 }
88 168
89 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, 169 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
90 config->init_data, drvdata); 170 config->init_data, drvdata);
91 if (IS_ERR(drvdata->dev)) { 171 if (IS_ERR(drvdata->dev)) {
92 ret = PTR_ERR(drvdata->dev); 172 ret = PTR_ERR(drvdata->dev);
93 goto err_name; 173 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
174 goto err_gpio;
94 } 175 }
95 176
96 platform_set_drvdata(pdev, drvdata); 177 platform_set_drvdata(pdev, drvdata);
@@ -100,6 +181,9 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev)
100 181
101 return 0; 182 return 0;
102 183
184err_gpio:
185 if (gpio_is_valid(config->gpio))
186 gpio_free(config->gpio);
103err_name: 187err_name:
104 kfree(drvdata->desc.name); 188 kfree(drvdata->desc.name);
105err: 189err:
@@ -115,6 +199,9 @@ static int regulator_fixed_voltage_remove(struct platform_device *pdev)
115 kfree(drvdata->desc.name); 199 kfree(drvdata->desc.name);
116 kfree(drvdata); 200 kfree(drvdata);
117 201
202 if (gpio_is_valid(drvdata->gpio))
203 gpio_free(drvdata->gpio);
204
118 return 0; 205 return 0;
119} 206}
120 207