diff options
Diffstat (limited to 'drivers/regulator/virtual.c')
-rw-r--r-- | drivers/regulator/virtual.c | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c index addc032c84bf..d96cecaac73d 100644 --- a/drivers/regulator/virtual.c +++ b/drivers/regulator/virtual.c | |||
@@ -19,7 +19,7 @@ | |||
19 | struct virtual_consumer_data { | 19 | struct virtual_consumer_data { |
20 | struct mutex lock; | 20 | struct mutex lock; |
21 | struct regulator *regulator; | 21 | struct regulator *regulator; |
22 | int enabled; | 22 | bool enabled; |
23 | int min_uV; | 23 | int min_uV; |
24 | int max_uV; | 24 | int max_uV; |
25 | int min_uA; | 25 | int min_uA; |
@@ -49,7 +49,7 @@ static void update_voltage_constraints(struct device *dev, | |||
49 | dev_dbg(dev, "Enabling regulator\n"); | 49 | dev_dbg(dev, "Enabling regulator\n"); |
50 | ret = regulator_enable(data->regulator); | 50 | ret = regulator_enable(data->regulator); |
51 | if (ret == 0) | 51 | if (ret == 0) |
52 | data->enabled = 1; | 52 | data->enabled = true; |
53 | else | 53 | else |
54 | dev_err(dev, "regulator_enable() failed: %d\n", | 54 | dev_err(dev, "regulator_enable() failed: %d\n", |
55 | ret); | 55 | ret); |
@@ -59,7 +59,7 @@ static void update_voltage_constraints(struct device *dev, | |||
59 | dev_dbg(dev, "Disabling regulator\n"); | 59 | dev_dbg(dev, "Disabling regulator\n"); |
60 | ret = regulator_disable(data->regulator); | 60 | ret = regulator_disable(data->regulator); |
61 | if (ret == 0) | 61 | if (ret == 0) |
62 | data->enabled = 0; | 62 | data->enabled = false; |
63 | else | 63 | else |
64 | dev_err(dev, "regulator_disable() failed: %d\n", | 64 | dev_err(dev, "regulator_disable() failed: %d\n", |
65 | ret); | 65 | ret); |
@@ -89,7 +89,7 @@ static void update_current_limit_constraints(struct device *dev, | |||
89 | dev_dbg(dev, "Enabling regulator\n"); | 89 | dev_dbg(dev, "Enabling regulator\n"); |
90 | ret = regulator_enable(data->regulator); | 90 | ret = regulator_enable(data->regulator); |
91 | if (ret == 0) | 91 | if (ret == 0) |
92 | data->enabled = 1; | 92 | data->enabled = true; |
93 | else | 93 | else |
94 | dev_err(dev, "regulator_enable() failed: %d\n", | 94 | dev_err(dev, "regulator_enable() failed: %d\n", |
95 | ret); | 95 | ret); |
@@ -99,7 +99,7 @@ static void update_current_limit_constraints(struct device *dev, | |||
99 | dev_dbg(dev, "Disabling regulator\n"); | 99 | dev_dbg(dev, "Disabling regulator\n"); |
100 | ret = regulator_disable(data->regulator); | 100 | ret = regulator_disable(data->regulator); |
101 | if (ret == 0) | 101 | if (ret == 0) |
102 | data->enabled = 0; | 102 | data->enabled = false; |
103 | else | 103 | else |
104 | dev_err(dev, "regulator_disable() failed: %d\n", | 104 | dev_err(dev, "regulator_disable() failed: %d\n", |
105 | ret); | 105 | ret); |
@@ -270,24 +270,28 @@ static DEVICE_ATTR(min_microamps, 0666, show_min_uA, set_min_uA); | |||
270 | static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); | 270 | static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); |
271 | static DEVICE_ATTR(mode, 0666, show_mode, set_mode); | 271 | static DEVICE_ATTR(mode, 0666, show_mode, set_mode); |
272 | 272 | ||
273 | static struct device_attribute *attributes[] = { | 273 | static struct attribute *regulator_virtual_attributes[] = { |
274 | &dev_attr_min_microvolts, | 274 | &dev_attr_min_microvolts.attr, |
275 | &dev_attr_max_microvolts, | 275 | &dev_attr_max_microvolts.attr, |
276 | &dev_attr_min_microamps, | 276 | &dev_attr_min_microamps.attr, |
277 | &dev_attr_max_microamps, | 277 | &dev_attr_max_microamps.attr, |
278 | &dev_attr_mode, | 278 | &dev_attr_mode.attr, |
279 | NULL | ||
279 | }; | 280 | }; |
280 | 281 | ||
281 | static int regulator_virtual_consumer_probe(struct platform_device *pdev) | 282 | static const struct attribute_group regulator_virtual_attr_group = { |
283 | .attrs = regulator_virtual_attributes, | ||
284 | }; | ||
285 | |||
286 | static int __devinit regulator_virtual_probe(struct platform_device *pdev) | ||
282 | { | 287 | { |
283 | char *reg_id = pdev->dev.platform_data; | 288 | char *reg_id = pdev->dev.platform_data; |
284 | struct virtual_consumer_data *drvdata; | 289 | struct virtual_consumer_data *drvdata; |
285 | int ret, i; | 290 | int ret; |
286 | 291 | ||
287 | drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); | 292 | drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); |
288 | if (drvdata == NULL) { | 293 | if (drvdata == NULL) |
289 | return -ENOMEM; | 294 | return -ENOMEM; |
290 | } | ||
291 | 295 | ||
292 | mutex_init(&drvdata->lock); | 296 | mutex_init(&drvdata->lock); |
293 | 297 | ||
@@ -299,13 +303,12 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev) | |||
299 | goto err; | 303 | goto err; |
300 | } | 304 | } |
301 | 305 | ||
302 | for (i = 0; i < ARRAY_SIZE(attributes); i++) { | 306 | ret = sysfs_create_group(&pdev->dev.kobj, |
303 | ret = device_create_file(&pdev->dev, attributes[i]); | 307 | ®ulator_virtual_attr_group); |
304 | if (ret != 0) { | 308 | if (ret != 0) { |
305 | dev_err(&pdev->dev, "Failed to create attr %d: %d\n", | 309 | dev_err(&pdev->dev, |
306 | i, ret); | 310 | "Failed to create attribute group: %d\n", ret); |
307 | goto err_regulator; | 311 | goto err_regulator; |
308 | } | ||
309 | } | 312 | } |
310 | 313 | ||
311 | drvdata->mode = regulator_get_mode(drvdata->regulator); | 314 | drvdata->mode = regulator_get_mode(drvdata->regulator); |
@@ -317,37 +320,36 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev) | |||
317 | err_regulator: | 320 | err_regulator: |
318 | regulator_put(drvdata->regulator); | 321 | regulator_put(drvdata->regulator); |
319 | err: | 322 | err: |
320 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | ||
321 | device_remove_file(&pdev->dev, attributes[i]); | ||
322 | kfree(drvdata); | 323 | kfree(drvdata); |
323 | return ret; | 324 | return ret; |
324 | } | 325 | } |
325 | 326 | ||
326 | static int regulator_virtual_consumer_remove(struct platform_device *pdev) | 327 | static int __devexit regulator_virtual_remove(struct platform_device *pdev) |
327 | { | 328 | { |
328 | struct virtual_consumer_data *drvdata = platform_get_drvdata(pdev); | 329 | struct virtual_consumer_data *drvdata = platform_get_drvdata(pdev); |
329 | int i; | ||
330 | 330 | ||
331 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | 331 | sysfs_remove_group(&pdev->dev.kobj, ®ulator_virtual_attr_group); |
332 | device_remove_file(&pdev->dev, attributes[i]); | 332 | |
333 | if (drvdata->enabled) | 333 | if (drvdata->enabled) |
334 | regulator_disable(drvdata->regulator); | 334 | regulator_disable(drvdata->regulator); |
335 | regulator_put(drvdata->regulator); | 335 | regulator_put(drvdata->regulator); |
336 | 336 | ||
337 | kfree(drvdata); | 337 | kfree(drvdata); |
338 | 338 | ||
339 | platform_set_drvdata(pdev, NULL); | ||
340 | |||
339 | return 0; | 341 | return 0; |
340 | } | 342 | } |
341 | 343 | ||
342 | static struct platform_driver regulator_virtual_consumer_driver = { | 344 | static struct platform_driver regulator_virtual_consumer_driver = { |
343 | .probe = regulator_virtual_consumer_probe, | 345 | .probe = regulator_virtual_probe, |
344 | .remove = regulator_virtual_consumer_remove, | 346 | .remove = __devexit_p(regulator_virtual_remove), |
345 | .driver = { | 347 | .driver = { |
346 | .name = "reg-virt-consumer", | 348 | .name = "reg-virt-consumer", |
349 | .owner = THIS_MODULE, | ||
347 | }, | 350 | }, |
348 | }; | 351 | }; |
349 | 352 | ||
350 | |||
351 | static int __init regulator_virtual_consumer_init(void) | 353 | static int __init regulator_virtual_consumer_init(void) |
352 | { | 354 | { |
353 | return platform_driver_register(®ulator_virtual_consumer_driver); | 355 | return platform_driver_register(®ulator_virtual_consumer_driver); |