aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/virtual.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/virtual.c')
-rw-r--r--drivers/regulator/virtual.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c
index e7db5664722e..addc032c84bf 100644
--- a/drivers/regulator/virtual.c
+++ b/drivers/regulator/virtual.c
@@ -27,71 +27,81 @@ struct virtual_consumer_data {
27 unsigned int mode; 27 unsigned int mode;
28}; 28};
29 29
30static void update_voltage_constraints(struct virtual_consumer_data *data) 30static void update_voltage_constraints(struct device *dev,
31 struct virtual_consumer_data *data)
31{ 32{
32 int ret; 33 int ret;
33 34
34 if (data->min_uV && data->max_uV 35 if (data->min_uV && data->max_uV
35 && data->min_uV <= data->max_uV) { 36 && data->min_uV <= data->max_uV) {
37 dev_dbg(dev, "Requesting %d-%duV\n",
38 data->min_uV, data->max_uV);
36 ret = regulator_set_voltage(data->regulator, 39 ret = regulator_set_voltage(data->regulator,
37 data->min_uV, data->max_uV); 40 data->min_uV, data->max_uV);
38 if (ret != 0) { 41 if (ret != 0) {
39 printk(KERN_ERR "regulator_set_voltage() failed: %d\n", 42 dev_err(dev,
40 ret); 43 "regulator_set_voltage() failed: %d\n", ret);
41 return; 44 return;
42 } 45 }
43 } 46 }
44 47
45 if (data->min_uV && data->max_uV && !data->enabled) { 48 if (data->min_uV && data->max_uV && !data->enabled) {
49 dev_dbg(dev, "Enabling regulator\n");
46 ret = regulator_enable(data->regulator); 50 ret = regulator_enable(data->regulator);
47 if (ret == 0) 51 if (ret == 0)
48 data->enabled = 1; 52 data->enabled = 1;
49 else 53 else
50 printk(KERN_ERR "regulator_enable() failed: %d\n", 54 dev_err(dev, "regulator_enable() failed: %d\n",
51 ret); 55 ret);
52 } 56 }
53 57
54 if (!(data->min_uV && data->max_uV) && data->enabled) { 58 if (!(data->min_uV && data->max_uV) && data->enabled) {
59 dev_dbg(dev, "Disabling regulator\n");
55 ret = regulator_disable(data->regulator); 60 ret = regulator_disable(data->regulator);
56 if (ret == 0) 61 if (ret == 0)
57 data->enabled = 0; 62 data->enabled = 0;
58 else 63 else
59 printk(KERN_ERR "regulator_disable() failed: %d\n", 64 dev_err(dev, "regulator_disable() failed: %d\n",
60 ret); 65 ret);
61 } 66 }
62} 67}
63 68
64static void update_current_limit_constraints(struct virtual_consumer_data 69static void update_current_limit_constraints(struct device *dev,
65 *data) 70 struct virtual_consumer_data *data)
66{ 71{
67 int ret; 72 int ret;
68 73
69 if (data->max_uA 74 if (data->max_uA
70 && data->min_uA <= data->max_uA) { 75 && data->min_uA <= data->max_uA) {
76 dev_dbg(dev, "Requesting %d-%duA\n",
77 data->min_uA, data->max_uA);
71 ret = regulator_set_current_limit(data->regulator, 78 ret = regulator_set_current_limit(data->regulator,
72 data->min_uA, data->max_uA); 79 data->min_uA, data->max_uA);
73 if (ret != 0) { 80 if (ret != 0) {
74 pr_err("regulator_set_current_limit() failed: %d\n", 81 dev_err(dev,
75 ret); 82 "regulator_set_current_limit() failed: %d\n",
83 ret);
76 return; 84 return;
77 } 85 }
78 } 86 }
79 87
80 if (data->max_uA && !data->enabled) { 88 if (data->max_uA && !data->enabled) {
89 dev_dbg(dev, "Enabling regulator\n");
81 ret = regulator_enable(data->regulator); 90 ret = regulator_enable(data->regulator);
82 if (ret == 0) 91 if (ret == 0)
83 data->enabled = 1; 92 data->enabled = 1;
84 else 93 else
85 printk(KERN_ERR "regulator_enable() failed: %d\n", 94 dev_err(dev, "regulator_enable() failed: %d\n",
86 ret); 95 ret);
87 } 96 }
88 97
89 if (!(data->min_uA && data->max_uA) && data->enabled) { 98 if (!(data->min_uA && data->max_uA) && data->enabled) {
99 dev_dbg(dev, "Disabling regulator\n");
90 ret = regulator_disable(data->regulator); 100 ret = regulator_disable(data->regulator);
91 if (ret == 0) 101 if (ret == 0)
92 data->enabled = 0; 102 data->enabled = 0;
93 else 103 else
94 printk(KERN_ERR "regulator_disable() failed: %d\n", 104 dev_err(dev, "regulator_disable() failed: %d\n",
95 ret); 105 ret);
96 } 106 }
97} 107}
@@ -115,7 +125,7 @@ static ssize_t set_min_uV(struct device *dev, struct device_attribute *attr,
115 mutex_lock(&data->lock); 125 mutex_lock(&data->lock);
116 126
117 data->min_uV = val; 127 data->min_uV = val;
118 update_voltage_constraints(data); 128 update_voltage_constraints(dev, data);
119 129
120 mutex_unlock(&data->lock); 130 mutex_unlock(&data->lock);
121 131
@@ -141,7 +151,7 @@ static ssize_t set_max_uV(struct device *dev, struct device_attribute *attr,
141 mutex_lock(&data->lock); 151 mutex_lock(&data->lock);
142 152
143 data->max_uV = val; 153 data->max_uV = val;
144 update_voltage_constraints(data); 154 update_voltage_constraints(dev, data);
145 155
146 mutex_unlock(&data->lock); 156 mutex_unlock(&data->lock);
147 157
@@ -167,7 +177,7 @@ static ssize_t set_min_uA(struct device *dev, struct device_attribute *attr,
167 mutex_lock(&data->lock); 177 mutex_lock(&data->lock);
168 178
169 data->min_uA = val; 179 data->min_uA = val;
170 update_current_limit_constraints(data); 180 update_current_limit_constraints(dev, data);
171 181
172 mutex_unlock(&data->lock); 182 mutex_unlock(&data->lock);
173 183
@@ -193,7 +203,7 @@ static ssize_t set_max_uA(struct device *dev, struct device_attribute *attr,
193 mutex_lock(&data->lock); 203 mutex_lock(&data->lock);
194 204
195 data->max_uA = val; 205 data->max_uA = val;
196 update_current_limit_constraints(data); 206 update_current_limit_constraints(dev, data);
197 207
198 mutex_unlock(&data->lock); 208 mutex_unlock(&data->lock);
199 209
@@ -276,8 +286,7 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev)
276 286
277 drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); 287 drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL);
278 if (drvdata == NULL) { 288 if (drvdata == NULL) {
279 ret = -ENOMEM; 289 return -ENOMEM;
280 goto err;
281 } 290 }
282 291
283 mutex_init(&drvdata->lock); 292 mutex_init(&drvdata->lock);
@@ -285,13 +294,18 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev)
285 drvdata->regulator = regulator_get(&pdev->dev, reg_id); 294 drvdata->regulator = regulator_get(&pdev->dev, reg_id);
286 if (IS_ERR(drvdata->regulator)) { 295 if (IS_ERR(drvdata->regulator)) {
287 ret = PTR_ERR(drvdata->regulator); 296 ret = PTR_ERR(drvdata->regulator);
297 dev_err(&pdev->dev, "Failed to obtain supply '%s': %d\n",
298 reg_id, ret);
288 goto err; 299 goto err;
289 } 300 }
290 301
291 for (i = 0; i < ARRAY_SIZE(attributes); i++) { 302 for (i = 0; i < ARRAY_SIZE(attributes); i++) {
292 ret = device_create_file(&pdev->dev, attributes[i]); 303 ret = device_create_file(&pdev->dev, attributes[i]);
293 if (ret != 0) 304 if (ret != 0) {
294 goto err; 305 dev_err(&pdev->dev, "Failed to create attr %d: %d\n",
306 i, ret);
307 goto err_regulator;
308 }
295 } 309 }
296 310
297 drvdata->mode = regulator_get_mode(drvdata->regulator); 311 drvdata->mode = regulator_get_mode(drvdata->regulator);
@@ -300,6 +314,8 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev)
300 314
301 return 0; 315 return 0;
302 316
317err_regulator:
318 regulator_put(drvdata->regulator);
303err: 319err:
304 for (i = 0; i < ARRAY_SIZE(attributes); i++) 320 for (i = 0; i < ARRAY_SIZE(attributes); i++)
305 device_remove_file(&pdev->dev, attributes[i]); 321 device_remove_file(&pdev->dev, attributes[i]);