aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-10-24 06:11:32 -0400
committerMark Brown <broonie@linaro.org>2013-10-24 06:11:32 -0400
commit420118d48311e0c4ef4aace5aede35079ecc2412 (patch)
treea4affbc11b9271d786b9c9e5711b1e7dc873d3e8 /drivers/regulator
parent2a2bec6554e9e9d0ae351575ca1f72df1fa0f15f (diff)
parent32dadef2190efd2e06331825b11881daf100d6d9 (diff)
Merge remote-tracking branch 'regulator/topic/alias' into regulator-next
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/88pm8607.c12
-rw-r--r--drivers/regulator/Makefile2
-rw-r--r--drivers/regulator/aat2870-regulator.c11
-rw-r--r--drivers/regulator/ad5398.c19
-rw-r--r--drivers/regulator/anatop-regulator.c3
-rw-r--r--drivers/regulator/arizona-ldo1.c12
-rw-r--r--drivers/regulator/arizona-micsupp.c14
-rw-r--r--drivers/regulator/as3711-regulator.c22
-rw-r--r--drivers/regulator/core.c325
-rw-r--r--drivers/regulator/da903x.c11
-rw-r--r--drivers/regulator/da9052-regulator.c14
-rw-r--r--drivers/regulator/da9055-regulator.c24
-rw-r--r--drivers/regulator/devres.c415
-rw-r--r--drivers/regulator/fan53555.c12
-rw-r--r--drivers/regulator/internal.h38
-rw-r--r--drivers/regulator/isl6271a-regulator.c24
-rw-r--r--drivers/regulator/max1586.c26
-rw-r--r--drivers/regulator/max77686.c23
-rw-r--r--drivers/regulator/max77693.c29
-rw-r--r--drivers/regulator/max8649.c14
-rw-r--r--drivers/regulator/max8660.c30
-rw-r--r--drivers/regulator/max8907-regulator.c23
-rw-r--r--drivers/regulator/max8973-regulator.c11
-rw-r--r--drivers/regulator/max8997.c39
-rw-r--r--drivers/regulator/max8998.c35
-rw-r--r--drivers/regulator/mc13783-regulator.c25
-rw-r--r--drivers/regulator/mc13892-regulator.c22
-rw-r--r--drivers/regulator/palmas-regulator.c42
-rw-r--r--drivers/regulator/rc5t583-regulator.c22
-rw-r--r--drivers/regulator/s2mps11.c23
-rw-r--r--drivers/regulator/s5m8767.c24
-rw-r--r--drivers/regulator/ti-abb-regulator.c79
-rw-r--r--drivers/regulator/tps51632-regulator.c11
-rw-r--r--drivers/regulator/tps62360-regulator.c17
-rw-r--r--drivers/regulator/tps65023-regulator.c22
-rw-r--r--drivers/regulator/tps6507x-regulator.c23
-rw-r--r--drivers/regulator/tps65090-regulator.c35
-rw-r--r--drivers/regulator/tps65217-regulator.c26
-rw-r--r--drivers/regulator/tps6586x-regulator.c31
-rw-r--r--drivers/regulator/tps65910-regulator.c23
-rw-r--r--drivers/regulator/tps65912-regulator.c24
-rw-r--r--drivers/regulator/tps80031-regulator.c30
-rw-r--r--drivers/regulator/wm831x-dcdc.c118
-rw-r--r--drivers/regulator/wm831x-isink.c25
-rw-r--r--drivers/regulator/wm831x-ldo.c63
-rw-r--r--drivers/regulator/wm8350-regulator.c6
-rw-r--r--drivers/regulator/wm8400-regulator.c13
-rw-r--r--drivers/regulator/wm8994-regulator.c14
48 files changed, 824 insertions, 1082 deletions
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 70230974468c..f704d83c93c4 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -391,7 +391,8 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
391 else 391 else
392 config.regmap = chip->regmap_companion; 392 config.regmap = chip->regmap_companion;
393 393
394 info->regulator = regulator_register(&info->desc, &config); 394 info->regulator = devm_regulator_register(&pdev->dev, &info->desc,
395 &config);
395 if (IS_ERR(info->regulator)) { 396 if (IS_ERR(info->regulator)) {
396 dev_err(&pdev->dev, "failed to register regulator %s\n", 397 dev_err(&pdev->dev, "failed to register regulator %s\n",
397 info->desc.name); 398 info->desc.name);
@@ -402,14 +403,6 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
402 return 0; 403 return 0;
403} 404}
404 405
405static int pm8607_regulator_remove(struct platform_device *pdev)
406{
407 struct pm8607_regulator_info *info = platform_get_drvdata(pdev);
408
409 regulator_unregister(info->regulator);
410 return 0;
411}
412
413static struct platform_device_id pm8607_regulator_driver_ids[] = { 406static struct platform_device_id pm8607_regulator_driver_ids[] = {
414 { 407 {
415 .name = "88pm860x-regulator", 408 .name = "88pm860x-regulator",
@@ -428,7 +421,6 @@ static struct platform_driver pm8607_regulator_driver = {
428 .owner = THIS_MODULE, 421 .owner = THIS_MODULE,
429 }, 422 },
430 .probe = pm8607_regulator_probe, 423 .probe = pm8607_regulator_probe,
431 .remove = pm8607_regulator_remove,
432 .id_table = pm8607_regulator_driver_ids, 424 .id_table = pm8607_regulator_driver_ids,
433}; 425};
434 426
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 185cce246022..69db4c8bb5c9 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -3,7 +3,7 @@
3# 3#
4 4
5 5
6obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o 6obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o
7obj-$(CONFIG_OF) += of_regulator.o 7obj-$(CONFIG_OF) += of_regulator.o
8obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o 8obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
9obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 9obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 881159dfcb5e..f70a9bfa5ff2 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -176,7 +176,7 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
176 config.driver_data = ri; 176 config.driver_data = ri;
177 config.init_data = dev_get_platdata(&pdev->dev); 177 config.init_data = dev_get_platdata(&pdev->dev);
178 178
179 rdev = regulator_register(&ri->desc, &config); 179 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
180 if (IS_ERR(rdev)) { 180 if (IS_ERR(rdev)) {
181 dev_err(&pdev->dev, "Failed to register regulator %s\n", 181 dev_err(&pdev->dev, "Failed to register regulator %s\n",
182 ri->desc.name); 182 ri->desc.name);
@@ -187,21 +187,12 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
187 return 0; 187 return 0;
188} 188}
189 189
190static int aat2870_regulator_remove(struct platform_device *pdev)
191{
192 struct regulator_dev *rdev = platform_get_drvdata(pdev);
193
194 regulator_unregister(rdev);
195 return 0;
196}
197
198static struct platform_driver aat2870_regulator_driver = { 190static struct platform_driver aat2870_regulator_driver = {
199 .driver = { 191 .driver = {
200 .name = "aat2870-regulator", 192 .name = "aat2870-regulator",
201 .owner = THIS_MODULE, 193 .owner = THIS_MODULE,
202 }, 194 },
203 .probe = aat2870_regulator_probe, 195 .probe = aat2870_regulator_probe,
204 .remove = aat2870_regulator_remove,
205}; 196};
206 197
207static int __init aat2870_regulator_init(void) 198static int __init aat2870_regulator_init(void)
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index b2b203cb6b2f..48016a050d5f 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -219,7 +219,6 @@ static int ad5398_probe(struct i2c_client *client,
219 struct ad5398_chip_info *chip; 219 struct ad5398_chip_info *chip;
220 const struct ad5398_current_data_format *df = 220 const struct ad5398_current_data_format *df =
221 (struct ad5398_current_data_format *)id->driver_data; 221 (struct ad5398_current_data_format *)id->driver_data;
222 int ret;
223 222
224 if (!init_data) 223 if (!init_data)
225 return -EINVAL; 224 return -EINVAL;
@@ -240,33 +239,21 @@ static int ad5398_probe(struct i2c_client *client,
240 chip->current_offset = df->current_offset; 239 chip->current_offset = df->current_offset;
241 chip->current_mask = (chip->current_level - 1) << chip->current_offset; 240 chip->current_mask = (chip->current_level - 1) << chip->current_offset;
242 241
243 chip->rdev = regulator_register(&ad5398_reg, &config); 242 chip->rdev = devm_regulator_register(&client->dev, &ad5398_reg,
243 &config);
244 if (IS_ERR(chip->rdev)) { 244 if (IS_ERR(chip->rdev)) {
245 ret = PTR_ERR(chip->rdev);
246 dev_err(&client->dev, "failed to register %s %s\n", 245 dev_err(&client->dev, "failed to register %s %s\n",
247 id->name, ad5398_reg.name); 246 id->name, ad5398_reg.name);
248 goto err; 247 return PTR_ERR(chip->rdev);
249 } 248 }
250 249
251 i2c_set_clientdata(client, chip); 250 i2c_set_clientdata(client, chip);
252 dev_dbg(&client->dev, "%s regulator driver is registered.\n", id->name); 251 dev_dbg(&client->dev, "%s regulator driver is registered.\n", id->name);
253 return 0; 252 return 0;
254
255err:
256 return ret;
257}
258
259static int ad5398_remove(struct i2c_client *client)
260{
261 struct ad5398_chip_info *chip = i2c_get_clientdata(client);
262
263 regulator_unregister(chip->rdev);
264 return 0;
265} 253}
266 254
267static struct i2c_driver ad5398_driver = { 255static struct i2c_driver ad5398_driver = {
268 .probe = ad5398_probe, 256 .probe = ad5398_probe,
269 .remove = ad5398_remove,
270 .driver = { 257 .driver = {
271 .name = "ad5398", 258 .name = "ad5398",
272 }, 259 },
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
index 0d4a8ccbb536..e42bfd17562a 100644
--- a/drivers/regulator/anatop-regulator.c
+++ b/drivers/regulator/anatop-regulator.c
@@ -200,7 +200,7 @@ static int anatop_regulator_probe(struct platform_device *pdev)
200 config.regmap = sreg->anatop; 200 config.regmap = sreg->anatop;
201 201
202 /* register regulator */ 202 /* register regulator */
203 rdev = regulator_register(rdesc, &config); 203 rdev = devm_regulator_register(dev, rdesc, &config);
204 if (IS_ERR(rdev)) { 204 if (IS_ERR(rdev)) {
205 dev_err(dev, "failed to register %s\n", 205 dev_err(dev, "failed to register %s\n",
206 rdesc->name); 206 rdesc->name);
@@ -223,7 +223,6 @@ static int anatop_regulator_remove(struct platform_device *pdev)
223 struct anatop_regulator *sreg = rdev_get_drvdata(rdev); 223 struct anatop_regulator *sreg = rdev_get_drvdata(rdev);
224 const char *name = sreg->name; 224 const char *name = sreg->name;
225 225
226 regulator_unregister(rdev);
227 kfree(name); 226 kfree(name);
228 227
229 return 0; 228 return 0;
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index 81d8681c3195..4f6c2055f6b2 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -226,7 +226,7 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
226 else 226 else
227 config.init_data = &ldo1->init_data; 227 config.init_data = &ldo1->init_data;
228 228
229 ldo1->regulator = regulator_register(desc, &config); 229 ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config);
230 if (IS_ERR(ldo1->regulator)) { 230 if (IS_ERR(ldo1->regulator)) {
231 ret = PTR_ERR(ldo1->regulator); 231 ret = PTR_ERR(ldo1->regulator);
232 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n", 232 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n",
@@ -239,18 +239,8 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
239 return 0; 239 return 0;
240} 240}
241 241
242static int arizona_ldo1_remove(struct platform_device *pdev)
243{
244 struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
245
246 regulator_unregister(ldo1->regulator);
247
248 return 0;
249}
250
251static struct platform_driver arizona_ldo1_driver = { 242static struct platform_driver arizona_ldo1_driver = {
252 .probe = arizona_ldo1_probe, 243 .probe = arizona_ldo1_probe,
253 .remove = arizona_ldo1_remove,
254 .driver = { 244 .driver = {
255 .name = "arizona-ldo1", 245 .name = "arizona-ldo1",
256 .owner = THIS_MODULE, 246 .owner = THIS_MODULE,
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index e87536bf0bed..724706a97dc4 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -225,7 +225,9 @@ static int arizona_micsupp_probe(struct platform_device *pdev)
225 regmap_update_bits(arizona->regmap, ARIZONA_MIC_CHARGE_PUMP_1, 225 regmap_update_bits(arizona->regmap, ARIZONA_MIC_CHARGE_PUMP_1,
226 ARIZONA_CPMIC_BYPASS, 0); 226 ARIZONA_CPMIC_BYPASS, 0);
227 227
228 micsupp->regulator = regulator_register(&arizona_micsupp, &config); 228 micsupp->regulator = devm_regulator_register(&pdev->dev,
229 &arizona_micsupp,
230 &config);
229 if (IS_ERR(micsupp->regulator)) { 231 if (IS_ERR(micsupp->regulator)) {
230 ret = PTR_ERR(micsupp->regulator); 232 ret = PTR_ERR(micsupp->regulator);
231 dev_err(arizona->dev, "Failed to register mic supply: %d\n", 233 dev_err(arizona->dev, "Failed to register mic supply: %d\n",
@@ -238,18 +240,8 @@ static int arizona_micsupp_probe(struct platform_device *pdev)
238 return 0; 240 return 0;
239} 241}
240 242
241static int arizona_micsupp_remove(struct platform_device *pdev)
242{
243 struct arizona_micsupp *micsupp = platform_get_drvdata(pdev);
244
245 regulator_unregister(micsupp->regulator);
246
247 return 0;
248}
249
250static struct platform_driver arizona_micsupp_driver = { 243static struct platform_driver arizona_micsupp_driver = {
251 .probe = arizona_micsupp_probe, 244 .probe = arizona_micsupp_probe,
252 .remove = arizona_micsupp_remove,
253 .driver = { 245 .driver = {
254 .name = "arizona-micsupp", 246 .name = "arizona-micsupp",
255 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
diff --git a/drivers/regulator/as3711-regulator.c b/drivers/regulator/as3711-regulator.c
index 8406cd745da2..fb27e6c8887c 100644
--- a/drivers/regulator/as3711-regulator.c
+++ b/drivers/regulator/as3711-regulator.c
@@ -273,33 +273,16 @@ static int as3711_regulator_probe(struct platform_device *pdev)
273 config.regmap = as3711->regmap; 273 config.regmap = as3711->regmap;
274 config.of_node = of_node[id]; 274 config.of_node = of_node[id];
275 275
276 rdev = regulator_register(&ri->desc, &config); 276 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
277 if (IS_ERR(rdev)) { 277 if (IS_ERR(rdev)) {
278 dev_err(&pdev->dev, "Failed to register regulator %s\n", 278 dev_err(&pdev->dev, "Failed to register regulator %s\n",
279 ri->desc.name); 279 ri->desc.name);
280 ret = PTR_ERR(rdev); 280 return PTR_ERR(rdev);
281 goto eregreg;
282 } 281 }
283 reg->rdev = rdev; 282 reg->rdev = rdev;
284 } 283 }
285 platform_set_drvdata(pdev, regs); 284 platform_set_drvdata(pdev, regs);
286 return 0; 285 return 0;
287
288eregreg:
289 while (--id >= 0)
290 regulator_unregister(regs[id].rdev);
291
292 return ret;
293}
294
295static int as3711_regulator_remove(struct platform_device *pdev)
296{
297 struct as3711_regulator *regs = platform_get_drvdata(pdev);
298 int id;
299
300 for (id = 0; id < AS3711_REGULATOR_NUM; ++id)
301 regulator_unregister(regs[id].rdev);
302 return 0;
303} 286}
304 287
305static struct platform_driver as3711_regulator_driver = { 288static struct platform_driver as3711_regulator_driver = {
@@ -308,7 +291,6 @@ static struct platform_driver as3711_regulator_driver = {
308 .owner = THIS_MODULE, 291 .owner = THIS_MODULE,
309 }, 292 },
310 .probe = as3711_regulator_probe, 293 .probe = as3711_regulator_probe,
311 .remove = as3711_regulator_remove,
312}; 294};
313 295
314static int __init as3711_regulator_init(void) 296static int __init as3711_regulator_init(void)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a01b8b3b70ca..16427de56ce8 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -36,6 +36,7 @@
36#include <trace/events/regulator.h> 36#include <trace/events/regulator.h>
37 37
38#include "dummy.h" 38#include "dummy.h"
39#include "internal.h"
39 40
40#define rdev_crit(rdev, fmt, ...) \ 41#define rdev_crit(rdev, fmt, ...) \
41 pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) 42 pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
@@ -52,6 +53,7 @@ static DEFINE_MUTEX(regulator_list_mutex);
52static LIST_HEAD(regulator_list); 53static LIST_HEAD(regulator_list);
53static LIST_HEAD(regulator_map_list); 54static LIST_HEAD(regulator_map_list);
54static LIST_HEAD(regulator_ena_gpio_list); 55static LIST_HEAD(regulator_ena_gpio_list);
56static LIST_HEAD(regulator_supply_alias_list);
55static bool has_full_constraints; 57static bool has_full_constraints;
56static bool board_wants_dummy_regulator; 58static bool board_wants_dummy_regulator;
57 59
@@ -83,22 +85,16 @@ struct regulator_enable_gpio {
83}; 85};
84 86
85/* 87/*
86 * struct regulator 88 * struct regulator_supply_alias
87 * 89 *
88 * One for each consumer device. 90 * Used to map lookups for a supply onto an alternative device.
89 */ 91 */
90struct regulator { 92struct regulator_supply_alias {
91 struct device *dev;
92 struct list_head list; 93 struct list_head list;
93 unsigned int always_on:1; 94 struct device *src_dev;
94 unsigned int bypass:1; 95 const char *src_supply;
95 int uA_load; 96 struct device *alias_dev;
96 int min_uV; 97 const char *alias_supply;
97 int max_uV;
98 char *supply_name;
99 struct device_attribute dev_attr;
100 struct regulator_dev *rdev;
101 struct dentry *debugfs;
102}; 98};
103 99
104static int _regulator_is_enabled(struct regulator_dev *rdev); 100static int _regulator_is_enabled(struct regulator_dev *rdev);
@@ -1191,6 +1187,32 @@ static int _regulator_get_enable_time(struct regulator_dev *rdev)
1191 return rdev->desc->ops->enable_time(rdev); 1187 return rdev->desc->ops->enable_time(rdev);
1192} 1188}
1193 1189
1190static struct regulator_supply_alias *regulator_find_supply_alias(
1191 struct device *dev, const char *supply)
1192{
1193 struct regulator_supply_alias *map;
1194
1195 list_for_each_entry(map, &regulator_supply_alias_list, list)
1196 if (map->src_dev == dev && strcmp(map->src_supply, supply) == 0)
1197 return map;
1198
1199 return NULL;
1200}
1201
1202static void regulator_supply_alias(struct device **dev, const char **supply)
1203{
1204 struct regulator_supply_alias *map;
1205
1206 map = regulator_find_supply_alias(*dev, *supply);
1207 if (map) {
1208 dev_dbg(*dev, "Mapping supply %s to %s,%s\n",
1209 *supply, map->alias_supply,
1210 dev_name(map->alias_dev));
1211 *dev = map->alias_dev;
1212 *supply = map->alias_supply;
1213 }
1214}
1215
1194static struct regulator_dev *regulator_dev_lookup(struct device *dev, 1216static struct regulator_dev *regulator_dev_lookup(struct device *dev,
1195 const char *supply, 1217 const char *supply,
1196 int *ret) 1218 int *ret)
@@ -1200,6 +1222,8 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
1200 struct regulator_map *map; 1222 struct regulator_map *map;
1201 const char *devname = NULL; 1223 const char *devname = NULL;
1202 1224
1225 regulator_supply_alias(&dev, &supply);
1226
1203 /* first do a dt based lookup */ 1227 /* first do a dt based lookup */
1204 if (dev && dev->of_node) { 1228 if (dev && dev->of_node) {
1205 node = of_get_regulator(dev, supply); 1229 node = of_get_regulator(dev, supply);
@@ -1353,40 +1377,6 @@ struct regulator *regulator_get(struct device *dev, const char *id)
1353} 1377}
1354EXPORT_SYMBOL_GPL(regulator_get); 1378EXPORT_SYMBOL_GPL(regulator_get);
1355 1379
1356static void devm_regulator_release(struct device *dev, void *res)
1357{
1358 regulator_put(*(struct regulator **)res);
1359}
1360
1361/**
1362 * devm_regulator_get - Resource managed regulator_get()
1363 * @dev: device for regulator "consumer"
1364 * @id: Supply name or regulator ID.
1365 *
1366 * Managed regulator_get(). Regulators returned from this function are
1367 * automatically regulator_put() on driver detach. See regulator_get() for more
1368 * information.
1369 */
1370struct regulator *devm_regulator_get(struct device *dev, const char *id)
1371{
1372 struct regulator **ptr, *regulator;
1373
1374 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1375 if (!ptr)
1376 return ERR_PTR(-ENOMEM);
1377
1378 regulator = regulator_get(dev, id);
1379 if (!IS_ERR(regulator)) {
1380 *ptr = regulator;
1381 devres_add(dev, ptr);
1382 } else {
1383 devres_free(ptr);
1384 }
1385
1386 return regulator;
1387}
1388EXPORT_SYMBOL_GPL(devm_regulator_get);
1389
1390/** 1380/**
1391 * regulator_get_exclusive - obtain exclusive access to a regulator. 1381 * regulator_get_exclusive - obtain exclusive access to a regulator.
1392 * @dev: device for regulator "consumer" 1382 * @dev: device for regulator "consumer"
@@ -1443,36 +1433,6 @@ struct regulator *regulator_get_optional(struct device *dev, const char *id)
1443} 1433}
1444EXPORT_SYMBOL_GPL(regulator_get_optional); 1434EXPORT_SYMBOL_GPL(regulator_get_optional);
1445 1435
1446/**
1447 * devm_regulator_get_optional - Resource managed regulator_get_optional()
1448 * @dev: device for regulator "consumer"
1449 * @id: Supply name or regulator ID.
1450 *
1451 * Managed regulator_get_optional(). Regulators returned from this
1452 * function are automatically regulator_put() on driver detach. See
1453 * regulator_get_optional() for more information.
1454 */
1455struct regulator *devm_regulator_get_optional(struct device *dev,
1456 const char *id)
1457{
1458 struct regulator **ptr, *regulator;
1459
1460 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1461 if (!ptr)
1462 return ERR_PTR(-ENOMEM);
1463
1464 regulator = regulator_get_optional(dev, id);
1465 if (!IS_ERR(regulator)) {
1466 *ptr = regulator;
1467 devres_add(dev, ptr);
1468 } else {
1469 devres_free(ptr);
1470 }
1471
1472 return regulator;
1473}
1474EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
1475
1476/* Locks held by regulator_put() */ 1436/* Locks held by regulator_put() */
1477static void _regulator_put(struct regulator *regulator) 1437static void _regulator_put(struct regulator *regulator)
1478{ 1438{
@@ -1499,36 +1459,6 @@ static void _regulator_put(struct regulator *regulator)
1499} 1459}
1500 1460
1501/** 1461/**
1502 * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
1503 * @dev: device for regulator "consumer"
1504 * @id: Supply name or regulator ID.
1505 *
1506 * Managed regulator_get_exclusive(). Regulators returned from this function
1507 * are automatically regulator_put() on driver detach. See regulator_get() for
1508 * more information.
1509 */
1510struct regulator *devm_regulator_get_exclusive(struct device *dev,
1511 const char *id)
1512{
1513 struct regulator **ptr, *regulator;
1514
1515 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1516 if (!ptr)
1517 return ERR_PTR(-ENOMEM);
1518
1519 regulator = _regulator_get(dev, id, 1);
1520 if (!IS_ERR(regulator)) {
1521 *ptr = regulator;
1522 devres_add(dev, ptr);
1523 } else {
1524 devres_free(ptr);
1525 }
1526
1527 return regulator;
1528}
1529EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
1530
1531/**
1532 * regulator_put - "free" the regulator source 1462 * regulator_put - "free" the regulator source
1533 * @regulator: regulator source 1463 * @regulator: regulator source
1534 * 1464 *
@@ -1544,34 +1474,133 @@ void regulator_put(struct regulator *regulator)
1544} 1474}
1545EXPORT_SYMBOL_GPL(regulator_put); 1475EXPORT_SYMBOL_GPL(regulator_put);
1546 1476
1547static int devm_regulator_match(struct device *dev, void *res, void *data) 1477/**
1478 * regulator_register_supply_alias - Provide device alias for supply lookup
1479 *
1480 * @dev: device that will be given as the regulator "consumer"
1481 * @id: Supply name or regulator ID
1482 * @alias_dev: device that should be used to lookup the supply
1483 * @alias_id: Supply name or regulator ID that should be used to lookup the
1484 * supply
1485 *
1486 * All lookups for id on dev will instead be conducted for alias_id on
1487 * alias_dev.
1488 */
1489int regulator_register_supply_alias(struct device *dev, const char *id,
1490 struct device *alias_dev,
1491 const char *alias_id)
1548{ 1492{
1549 struct regulator **r = res; 1493 struct regulator_supply_alias *map;
1550 if (!r || !*r) { 1494
1551 WARN_ON(!r || !*r); 1495 map = regulator_find_supply_alias(dev, id);
1552 return 0; 1496 if (map)
1497 return -EEXIST;
1498
1499 map = kzalloc(sizeof(struct regulator_supply_alias), GFP_KERNEL);
1500 if (!map)
1501 return -ENOMEM;
1502
1503 map->src_dev = dev;
1504 map->src_supply = id;
1505 map->alias_dev = alias_dev;
1506 map->alias_supply = alias_id;
1507
1508 list_add(&map->list, &regulator_supply_alias_list);
1509
1510 pr_info("Adding alias for supply %s,%s -> %s,%s\n",
1511 id, dev_name(dev), alias_id, dev_name(alias_dev));
1512
1513 return 0;
1514}
1515EXPORT_SYMBOL_GPL(regulator_register_supply_alias);
1516
1517/**
1518 * regulator_unregister_supply_alias - Remove device alias
1519 *
1520 * @dev: device that will be given as the regulator "consumer"
1521 * @id: Supply name or regulator ID
1522 *
1523 * Remove a lookup alias if one exists for id on dev.
1524 */
1525void regulator_unregister_supply_alias(struct device *dev, const char *id)
1526{
1527 struct regulator_supply_alias *map;
1528
1529 map = regulator_find_supply_alias(dev, id);
1530 if (map) {
1531 list_del(&map->list);
1532 kfree(map);
1533 }
1534}
1535EXPORT_SYMBOL_GPL(regulator_unregister_supply_alias);
1536
1537/**
1538 * regulator_bulk_register_supply_alias - register multiple aliases
1539 *
1540 * @dev: device that will be given as the regulator "consumer"
1541 * @id: List of supply names or regulator IDs
1542 * @alias_dev: device that should be used to lookup the supply
1543 * @alias_id: List of supply names or regulator IDs that should be used to
1544 * lookup the supply
1545 * @num_id: Number of aliases to register
1546 *
1547 * @return 0 on success, an errno on failure.
1548 *
1549 * This helper function allows drivers to register several supply
1550 * aliases in one operation. If any of the aliases cannot be
1551 * registered any aliases that were registered will be removed
1552 * before returning to the caller.
1553 */
1554int regulator_bulk_register_supply_alias(struct device *dev, const char **id,
1555 struct device *alias_dev,
1556 const char **alias_id,
1557 int num_id)
1558{
1559 int i;
1560 int ret;
1561
1562 for (i = 0; i < num_id; ++i) {
1563 ret = regulator_register_supply_alias(dev, id[i], alias_dev,
1564 alias_id[i]);
1565 if (ret < 0)
1566 goto err;
1553 } 1567 }
1554 return *r == data; 1568
1569 return 0;
1570
1571err:
1572 dev_err(dev,
1573 "Failed to create supply alias %s,%s -> %s,%s\n",
1574 id[i], dev_name(dev), alias_id[i], dev_name(alias_dev));
1575
1576 while (--i >= 0)
1577 regulator_unregister_supply_alias(dev, id[i]);
1578
1579 return ret;
1555} 1580}
1581EXPORT_SYMBOL_GPL(regulator_bulk_register_supply_alias);
1556 1582
1557/** 1583/**
1558 * devm_regulator_put - Resource managed regulator_put() 1584 * regulator_bulk_unregister_supply_alias - unregister multiple aliases
1559 * @regulator: regulator to free 1585 *
1586 * @dev: device that will be given as the regulator "consumer"
1587 * @id: List of supply names or regulator IDs
1588 * @num_id: Number of aliases to unregister
1560 * 1589 *
1561 * Deallocate a regulator allocated with devm_regulator_get(). Normally 1590 * This helper function allows drivers to unregister several supply
1562 * this function will not need to be called and the resource management 1591 * aliases in one operation.
1563 * code will ensure that the resource is freed.
1564 */ 1592 */
1565void devm_regulator_put(struct regulator *regulator) 1593void regulator_bulk_unregister_supply_alias(struct device *dev,
1594 const char **id,
1595 int num_id)
1566{ 1596{
1567 int rc; 1597 int i;
1568 1598
1569 rc = devres_release(regulator->dev, devm_regulator_release, 1599 for (i = 0; i < num_id; ++i)
1570 devm_regulator_match, regulator); 1600 regulator_unregister_supply_alias(dev, id[i]);
1571 if (rc != 0)
1572 WARN_ON(rc);
1573} 1601}
1574EXPORT_SYMBOL_GPL(devm_regulator_put); 1602EXPORT_SYMBOL_GPL(regulator_bulk_unregister_supply_alias);
1603
1575 1604
1576/* Manage enable GPIO list. Same GPIO pin can be shared among regulators */ 1605/* Manage enable GPIO list. Same GPIO pin can be shared among regulators */
1577static int regulator_ena_gpio_request(struct regulator_dev *rdev, 1606static int regulator_ena_gpio_request(struct regulator_dev *rdev,
@@ -2912,52 +2941,6 @@ err:
2912} 2941}
2913EXPORT_SYMBOL_GPL(regulator_bulk_get); 2942EXPORT_SYMBOL_GPL(regulator_bulk_get);
2914 2943
2915/**
2916 * devm_regulator_bulk_get - managed get multiple regulator consumers
2917 *
2918 * @dev: Device to supply
2919 * @num_consumers: Number of consumers to register
2920 * @consumers: Configuration of consumers; clients are stored here.
2921 *
2922 * @return 0 on success, an errno on failure.
2923 *
2924 * This helper function allows drivers to get several regulator
2925 * consumers in one operation with management, the regulators will
2926 * automatically be freed when the device is unbound. If any of the
2927 * regulators cannot be acquired then any regulators that were
2928 * allocated will be freed before returning to the caller.
2929 */
2930int devm_regulator_bulk_get(struct device *dev, int num_consumers,
2931 struct regulator_bulk_data *consumers)
2932{
2933 int i;
2934 int ret;
2935
2936 for (i = 0; i < num_consumers; i++)
2937 consumers[i].consumer = NULL;
2938
2939 for (i = 0; i < num_consumers; i++) {
2940 consumers[i].consumer = devm_regulator_get(dev,
2941 consumers[i].supply);
2942 if (IS_ERR(consumers[i].consumer)) {
2943 ret = PTR_ERR(consumers[i].consumer);
2944 dev_err(dev, "Failed to get supply '%s': %d\n",
2945 consumers[i].supply, ret);
2946 consumers[i].consumer = NULL;
2947 goto err;
2948 }
2949 }
2950
2951 return 0;
2952
2953err:
2954 for (i = 0; i < num_consumers && consumers[i].consumer; i++)
2955 devm_regulator_put(consumers[i].consumer);
2956
2957 return ret;
2958}
2959EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);
2960
2961static void regulator_bulk_enable_async(void *data, async_cookie_t cookie) 2944static void regulator_bulk_enable_async(void *data, async_cookie_t cookie)
2962{ 2945{
2963 struct regulator_bulk_data *bulk = data; 2946 struct regulator_bulk_data *bulk = data;
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index f06854cf8cf5..c61d96e9d925 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -463,7 +463,7 @@ static int da903x_regulator_probe(struct platform_device *pdev)
463 config.init_data = dev_get_platdata(&pdev->dev); 463 config.init_data = dev_get_platdata(&pdev->dev);
464 config.driver_data = ri; 464 config.driver_data = ri;
465 465
466 rdev = regulator_register(&ri->desc, &config); 466 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
467 if (IS_ERR(rdev)) { 467 if (IS_ERR(rdev)) {
468 dev_err(&pdev->dev, "failed to register regulator %s\n", 468 dev_err(&pdev->dev, "failed to register regulator %s\n",
469 ri->desc.name); 469 ri->desc.name);
@@ -474,21 +474,12 @@ static int da903x_regulator_probe(struct platform_device *pdev)
474 return 0; 474 return 0;
475} 475}
476 476
477static int da903x_regulator_remove(struct platform_device *pdev)
478{
479 struct regulator_dev *rdev = platform_get_drvdata(pdev);
480
481 regulator_unregister(rdev);
482 return 0;
483}
484
485static struct platform_driver da903x_regulator_driver = { 477static struct platform_driver da903x_regulator_driver = {
486 .driver = { 478 .driver = {
487 .name = "da903x-regulator", 479 .name = "da903x-regulator",
488 .owner = THIS_MODULE, 480 .owner = THIS_MODULE,
489 }, 481 },
490 .probe = da903x_regulator_probe, 482 .probe = da903x_regulator_probe,
491 .remove = da903x_regulator_remove,
492}; 483};
493 484
494static int __init da903x_regulator_init(void) 485static int __init da903x_regulator_init(void)
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 1e4d483f6163..c427e42472e8 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -389,8 +389,9 @@ static int da9052_regulator_probe(struct platform_device *pdev)
389#endif 389#endif
390 } 390 }
391 391
392 regulator->rdev = regulator_register(&regulator->info->reg_desc, 392 regulator->rdev = devm_regulator_register(&pdev->dev,
393 &config); 393 &regulator->info->reg_desc,
394 &config);
394 if (IS_ERR(regulator->rdev)) { 395 if (IS_ERR(regulator->rdev)) {
395 dev_err(&pdev->dev, "failed to register regulator %s\n", 396 dev_err(&pdev->dev, "failed to register regulator %s\n",
396 regulator->info->reg_desc.name); 397 regulator->info->reg_desc.name);
@@ -402,17 +403,8 @@ static int da9052_regulator_probe(struct platform_device *pdev)
402 return 0; 403 return 0;
403} 404}
404 405
405static int da9052_regulator_remove(struct platform_device *pdev)
406{
407 struct da9052_regulator *regulator = platform_get_drvdata(pdev);
408
409 regulator_unregister(regulator->rdev);
410 return 0;
411}
412
413static struct platform_driver da9052_regulator_driver = { 406static struct platform_driver da9052_regulator_driver = {
414 .probe = da9052_regulator_probe, 407 .probe = da9052_regulator_probe,
415 .remove = da9052_regulator_remove,
416 .driver = { 408 .driver = {
417 .name = "da9052-regulator", 409 .name = "da9052-regulator",
418 .owner = THIS_MODULE, 410 .owner = THIS_MODULE,
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index 77b53e5a231c..7f340206d329 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -564,13 +564,13 @@ static int da9055_regulator_probe(struct platform_device *pdev)
564 if (ret < 0) 564 if (ret < 0)
565 return ret; 565 return ret;
566 566
567 regulator->rdev = regulator_register(&regulator->info->reg_desc, 567 regulator->rdev = devm_regulator_register(&pdev->dev,
568 &config); 568 &regulator->info->reg_desc,
569 &config);
569 if (IS_ERR(regulator->rdev)) { 570 if (IS_ERR(regulator->rdev)) {
570 dev_err(&pdev->dev, "Failed to register regulator %s\n", 571 dev_err(&pdev->dev, "Failed to register regulator %s\n",
571 regulator->info->reg_desc.name); 572 regulator->info->reg_desc.name);
572 ret = PTR_ERR(regulator->rdev); 573 return PTR_ERR(regulator->rdev);
573 return ret;
574 } 574 }
575 575
576 /* Only LDO 5 and 6 has got the over current interrupt */ 576 /* Only LDO 5 and 6 has got the over current interrupt */
@@ -588,7 +588,7 @@ static int da9055_regulator_probe(struct platform_device *pdev)
588 dev_err(&pdev->dev, 588 dev_err(&pdev->dev,
589 "Failed to request Regulator IRQ %d: %d\n", 589 "Failed to request Regulator IRQ %d: %d\n",
590 irq, ret); 590 irq, ret);
591 goto err_regulator; 591 return ret;
592 } 592 }
593 } 593 }
594 } 594 }
@@ -596,24 +596,10 @@ static int da9055_regulator_probe(struct platform_device *pdev)
596 platform_set_drvdata(pdev, regulator); 596 platform_set_drvdata(pdev, regulator);
597 597
598 return 0; 598 return 0;
599
600err_regulator:
601 regulator_unregister(regulator->rdev);
602 return ret;
603}
604
605static int da9055_regulator_remove(struct platform_device *pdev)
606{
607 struct da9055_regulator *regulator = platform_get_drvdata(pdev);
608
609 regulator_unregister(regulator->rdev);
610
611 return 0;
612} 599}
613 600
614static struct platform_driver da9055_regulator_driver = { 601static struct platform_driver da9055_regulator_driver = {
615 .probe = da9055_regulator_probe, 602 .probe = da9055_regulator_probe,
616 .remove = da9055_regulator_remove,
617 .driver = { 603 .driver = {
618 .name = "da9055-regulator", 604 .name = "da9055-regulator",
619 .owner = THIS_MODULE, 605 .owner = THIS_MODULE,
diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c
new file mode 100644
index 000000000000..f44818b838dc
--- /dev/null
+++ b/drivers/regulator/devres.c
@@ -0,0 +1,415 @@
1/*
2 * devres.c -- Voltage/Current Regulator framework devres implementation.
3 *
4 * Copyright 2013 Linaro Ltd
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/err.h>
15#include <linux/regmap.h>
16#include <linux/regulator/consumer.h>
17#include <linux/regulator/driver.h>
18#include <linux/module.h>
19
20#include "internal.h"
21
22enum {
23 NORMAL_GET,
24 EXCLUSIVE_GET,
25 OPTIONAL_GET,
26};
27
28static void devm_regulator_release(struct device *dev, void *res)
29{
30 regulator_put(*(struct regulator **)res);
31}
32
33static struct regulator *_devm_regulator_get(struct device *dev, const char *id,
34 int get_type)
35{
36 struct regulator **ptr, *regulator;
37
38 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
39 if (!ptr)
40 return ERR_PTR(-ENOMEM);
41
42 switch (get_type) {
43 case NORMAL_GET:
44 regulator = regulator_get(dev, id);
45 break;
46 case EXCLUSIVE_GET:
47 regulator = regulator_get_exclusive(dev, id);
48 break;
49 case OPTIONAL_GET:
50 regulator = regulator_get_optional(dev, id);
51 break;
52 default:
53 regulator = ERR_PTR(-EINVAL);
54 }
55
56 if (!IS_ERR(regulator)) {
57 *ptr = regulator;
58 devres_add(dev, ptr);
59 } else {
60 devres_free(ptr);
61 }
62
63 return regulator;
64}
65
66/**
67 * devm_regulator_get - Resource managed regulator_get()
68 * @dev: device for regulator "consumer"
69 * @id: Supply name or regulator ID.
70 *
71 * Managed regulator_get(). Regulators returned from this function are
72 * automatically regulator_put() on driver detach. See regulator_get() for more
73 * information.
74 */
75struct regulator *devm_regulator_get(struct device *dev, const char *id)
76{
77 return _devm_regulator_get(dev, id, NORMAL_GET);
78}
79EXPORT_SYMBOL_GPL(devm_regulator_get);
80
81/**
82 * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
83 * @dev: device for regulator "consumer"
84 * @id: Supply name or regulator ID.
85 *
86 * Managed regulator_get_exclusive(). Regulators returned from this function
87 * are automatically regulator_put() on driver detach. See regulator_get() for
88 * more information.
89 */
90struct regulator *devm_regulator_get_exclusive(struct device *dev,
91 const char *id)
92{
93 return _devm_regulator_get(dev, id, EXCLUSIVE_GET);
94}
95EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
96
97/**
98 * devm_regulator_get_optional - Resource managed regulator_get_optional()
99 * @dev: device for regulator "consumer"
100 * @id: Supply name or regulator ID.
101 *
102 * Managed regulator_get_optional(). Regulators returned from this
103 * function are automatically regulator_put() on driver detach. See
104 * regulator_get_optional() for more information.
105 */
106struct regulator *devm_regulator_get_optional(struct device *dev,
107 const char *id)
108{
109 return _devm_regulator_get(dev, id, OPTIONAL_GET);
110}
111EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
112
113static int devm_regulator_match(struct device *dev, void *res, void *data)
114{
115 struct regulator **r = res;
116 if (!r || !*r) {
117 WARN_ON(!r || !*r);
118 return 0;
119 }
120 return *r == data;
121}
122
123/**
124 * devm_regulator_put - Resource managed regulator_put()
125 * @regulator: regulator to free
126 *
127 * Deallocate a regulator allocated with devm_regulator_get(). Normally
128 * this function will not need to be called and the resource management
129 * code will ensure that the resource is freed.
130 */
131void devm_regulator_put(struct regulator *regulator)
132{
133 int rc;
134
135 rc = devres_release(regulator->dev, devm_regulator_release,
136 devm_regulator_match, regulator);
137 if (rc != 0)
138 WARN_ON(rc);
139}
140EXPORT_SYMBOL_GPL(devm_regulator_put);
141
142/**
143 * devm_regulator_bulk_get - managed get multiple regulator consumers
144 *
145 * @dev: Device to supply
146 * @num_consumers: Number of consumers to register
147 * @consumers: Configuration of consumers; clients are stored here.
148 *
149 * @return 0 on success, an errno on failure.
150 *
151 * This helper function allows drivers to get several regulator
152 * consumers in one operation with management, the regulators will
153 * automatically be freed when the device is unbound. If any of the
154 * regulators cannot be acquired then any regulators that were
155 * allocated will be freed before returning to the caller.
156 */
157int devm_regulator_bulk_get(struct device *dev, int num_consumers,
158 struct regulator_bulk_data *consumers)
159{
160 int i;
161 int ret;
162
163 for (i = 0; i < num_consumers; i++)
164 consumers[i].consumer = NULL;
165
166 for (i = 0; i < num_consumers; i++) {
167 consumers[i].consumer = devm_regulator_get(dev,
168 consumers[i].supply);
169 if (IS_ERR(consumers[i].consumer)) {
170 ret = PTR_ERR(consumers[i].consumer);
171 dev_err(dev, "Failed to get supply '%s': %d\n",
172 consumers[i].supply, ret);
173 consumers[i].consumer = NULL;
174 goto err;
175 }
176 }
177
178 return 0;
179
180err:
181 for (i = 0; i < num_consumers && consumers[i].consumer; i++)
182 devm_regulator_put(consumers[i].consumer);
183
184 return ret;
185}
186EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);
187
188static void devm_rdev_release(struct device *dev, void *res)
189{
190 regulator_unregister(*(struct regulator_dev **)res);
191}
192
193/**
194 * devm_regulator_register - Resource managed regulator_register()
195 * @regulator_desc: regulator to register
196 * @config: runtime configuration for regulator
197 *
198 * Called by regulator drivers to register a regulator. Returns a
199 * valid pointer to struct regulator_dev on success or an ERR_PTR() on
200 * error. The regulator will automatically be released when the device
201 * is unbound.
202 */
203struct regulator_dev *devm_regulator_register(struct device *dev,
204 const struct regulator_desc *regulator_desc,
205 const struct regulator_config *config)
206{
207 struct regulator_dev **ptr, *rdev;
208
209 ptr = devres_alloc(devm_rdev_release, sizeof(*ptr),
210 GFP_KERNEL);
211 if (!ptr)
212 return ERR_PTR(-ENOMEM);
213
214 rdev = regulator_register(regulator_desc, config);
215 if (!IS_ERR(rdev)) {
216 *ptr = rdev;
217 devres_add(dev, ptr);
218 } else {
219 devres_free(ptr);
220 }
221
222 return rdev;
223}
224EXPORT_SYMBOL_GPL(devm_regulator_register);
225
226static int devm_rdev_match(struct device *dev, void *res, void *data)
227{
228 struct regulator_dev **r = res;
229 if (!r || !*r) {
230 WARN_ON(!r || !*r);
231 return 0;
232 }
233 return *r == data;
234}
235
236/**
237 * devm_regulator_unregister - Resource managed regulator_unregister()
238 * @regulator: regulator to free
239 *
240 * Unregister a regulator registered with devm_regulator_register().
241 * Normally this function will not need to be called and the resource
242 * management code will ensure that the resource is freed.
243 */
244void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev)
245{
246 int rc;
247
248 rc = devres_release(dev, devm_rdev_release, devm_rdev_match, rdev);
249 if (rc != 0)
250 WARN_ON(rc);
251}
252EXPORT_SYMBOL_GPL(devm_regulator_unregister);
253
254struct regulator_supply_alias_match {
255 struct device *dev;
256 const char *id;
257};
258
259static int devm_regulator_match_supply_alias(struct device *dev, void *res,
260 void *data)
261{
262 struct regulator_supply_alias_match *match = res;
263 struct regulator_supply_alias_match *target = data;
264
265 return match->dev == target->dev && strcmp(match->id, target->id) == 0;
266}
267
268static void devm_regulator_destroy_supply_alias(struct device *dev, void *res)
269{
270 struct regulator_supply_alias_match *match = res;
271
272 regulator_unregister_supply_alias(match->dev, match->id);
273}
274
275/**
276 * devm_regulator_register_supply_alias - Resource managed
277 * regulator_register_supply_alias()
278 *
279 * @dev: device that will be given as the regulator "consumer"
280 * @id: Supply name or regulator ID
281 * @alias_dev: device that should be used to lookup the supply
282 * @alias_id: Supply name or regulator ID that should be used to lookup the
283 * supply
284 *
285 * The supply alias will automatically be unregistered when the source
286 * device is unbound.
287 */
288int devm_regulator_register_supply_alias(struct device *dev, const char *id,
289 struct device *alias_dev,
290 const char *alias_id)
291{
292 struct regulator_supply_alias_match *match;
293 int ret;
294
295 match = devres_alloc(devm_regulator_destroy_supply_alias,
296 sizeof(struct regulator_supply_alias_match),
297 GFP_KERNEL);
298 if (!match)
299 return -ENOMEM;
300
301 match->dev = dev;
302 match->id = id;
303
304 ret = regulator_register_supply_alias(dev, id, alias_dev, alias_id);
305 if (ret < 0) {
306 devres_free(match);
307 return ret;
308 }
309
310 devres_add(dev, match);
311
312 return 0;
313}
314EXPORT_SYMBOL_GPL(devm_regulator_register_supply_alias);
315
316/**
317 * devm_regulator_unregister_supply_alias - Resource managed
318 * regulator_unregister_supply_alias()
319 *
320 * @dev: device that will be given as the regulator "consumer"
321 * @id: Supply name or regulator ID
322 *
323 * Unregister an alias registered with
324 * devm_regulator_register_supply_alias(). Normally this function
325 * will not need to be called and the resource management code
326 * will ensure that the resource is freed.
327 */
328void devm_regulator_unregister_supply_alias(struct device *dev, const char *id)
329{
330 struct regulator_supply_alias_match match;
331 int rc;
332
333 match.dev = dev;
334 match.id = id;
335
336 rc = devres_release(dev, devm_regulator_destroy_supply_alias,
337 devm_regulator_match_supply_alias, &match);
338 if (rc != 0)
339 WARN_ON(rc);
340}
341EXPORT_SYMBOL_GPL(devm_regulator_unregister_supply_alias);
342
343/**
344 * devm_regulator_bulk_register_supply_alias - Managed register
345 * multiple aliases
346 *
347 * @dev: device that will be given as the regulator "consumer"
348 * @id: List of supply names or regulator IDs
349 * @alias_dev: device that should be used to lookup the supply
350 * @alias_id: List of supply names or regulator IDs that should be used to
351 * lookup the supply
352 * @num_id: Number of aliases to register
353 *
354 * @return 0 on success, an errno on failure.
355 *
356 * This helper function allows drivers to register several supply
357 * aliases in one operation, the aliases will be automatically
358 * unregisters when the source device is unbound. If any of the
359 * aliases cannot be registered any aliases that were registered
360 * will be removed before returning to the caller.
361 */
362int devm_regulator_bulk_register_supply_alias(struct device *dev,
363 const char **id,
364 struct device *alias_dev,
365 const char **alias_id,
366 int num_id)
367{
368 int i;
369 int ret;
370
371 for (i = 0; i < num_id; ++i) {
372 ret = devm_regulator_register_supply_alias(dev, id[i],
373 alias_dev,
374 alias_id[i]);
375 if (ret < 0)
376 goto err;
377 }
378
379 return 0;
380
381err:
382 dev_err(dev,
383 "Failed to create supply alias %s,%s -> %s,%s\n",
384 id[i], dev_name(dev), alias_id[i], dev_name(alias_dev));
385
386 while (--i >= 0)
387 devm_regulator_unregister_supply_alias(dev, id[i]);
388
389 return ret;
390}
391EXPORT_SYMBOL_GPL(devm_regulator_bulk_register_supply_alias);
392
393/**
394 * devm_regulator_bulk_unregister_supply_alias - Managed unregister
395 * multiple aliases
396 *
397 * @dev: device that will be given as the regulator "consumer"
398 * @id: List of supply names or regulator IDs
399 * @num_id: Number of aliases to unregister
400 *
401 * Unregister aliases registered with
402 * devm_regulator_bulk_register_supply_alias(). Normally this function
403 * will not need to be called and the resource management code
404 * will ensure that the resource is freed.
405 */
406void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
407 const char **id,
408 int num_id)
409{
410 int i;
411
412 for (i = 0; i < num_id; ++i)
413 devm_regulator_unregister_supply_alias(dev, id[i]);
414}
415EXPORT_SYMBOL_GPL(devm_regulator_bulk_unregister_supply_alias);
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 70b7220c587f..7ca3d9e3b0fe 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -218,9 +218,8 @@ static int fan53555_regulator_register(struct fan53555_device_info *di,
218 rdesc->vsel_mask = VSEL_NSEL_MASK; 218 rdesc->vsel_mask = VSEL_NSEL_MASK;
219 rdesc->owner = THIS_MODULE; 219 rdesc->owner = THIS_MODULE;
220 220
221 di->rdev = regulator_register(&di->desc, config); 221 di->rdev = devm_regulator_register(di->dev, &di->desc, config);
222 return PTR_ERR_OR_ZERO(di->rdev); 222 return PTR_ERR_OR_ZERO(di->rdev);
223
224} 223}
225 224
226static struct regmap_config fan53555_regmap_config = { 225static struct regmap_config fan53555_regmap_config = {
@@ -291,14 +290,6 @@ static int fan53555_regulator_probe(struct i2c_client *client,
291 290
292} 291}
293 292
294static int fan53555_regulator_remove(struct i2c_client *client)
295{
296 struct fan53555_device_info *di = i2c_get_clientdata(client);
297
298 regulator_unregister(di->rdev);
299 return 0;
300}
301
302static const struct i2c_device_id fan53555_id[] = { 293static const struct i2c_device_id fan53555_id[] = {
303 {"fan53555", -1}, 294 {"fan53555", -1},
304 { }, 295 { },
@@ -309,7 +300,6 @@ static struct i2c_driver fan53555_regulator_driver = {
309 .name = "fan53555-regulator", 300 .name = "fan53555-regulator",
310 }, 301 },
311 .probe = fan53555_regulator_probe, 302 .probe = fan53555_regulator_probe,
312 .remove = fan53555_regulator_remove,
313 .id_table = fan53555_id, 303 .id_table = fan53555_id,
314}; 304};
315 305
diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h
new file mode 100644
index 000000000000..84bbda10c396
--- /dev/null
+++ b/drivers/regulator/internal.h
@@ -0,0 +1,38 @@
1/*
2 * internal.h -- Voltage/Current Regulator framework internal code
3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
6 *
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#ifndef __REGULATOR_INTERNAL_H
17#define __REGULATOR_INTERNAL_H
18
19/*
20 * struct regulator
21 *
22 * One for each consumer device.
23 */
24struct regulator {
25 struct device *dev;
26 struct list_head list;
27 unsigned int always_on:1;
28 unsigned int bypass:1;
29 int uA_load;
30 int min_uV;
31 int max_uV;
32 char *supply_name;
33 struct device_attribute dev_attr;
34 struct regulator_dev *rdev;
35 struct dentry *debugfs;
36};
37
38#endif
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index 88c1a3acf563..6e5da95fa025 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -112,7 +112,7 @@ static int isl6271a_probe(struct i2c_client *i2c,
112 struct regulator_config config = { }; 112 struct regulator_config config = { };
113 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev); 113 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev);
114 struct isl_pmic *pmic; 114 struct isl_pmic *pmic;
115 int err, i; 115 int i;
116 116
117 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 117 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
118 return -EIO; 118 return -EIO;
@@ -133,32 +133,17 @@ static int isl6271a_probe(struct i2c_client *i2c,
133 config.init_data = NULL; 133 config.init_data = NULL;
134 config.driver_data = pmic; 134 config.driver_data = pmic;
135 135
136 pmic->rdev[i] = regulator_register(&isl_rd[i], &config); 136 pmic->rdev[i] = devm_regulator_register(&i2c->dev, &isl_rd[i],
137 &config);
137 if (IS_ERR(pmic->rdev[i])) { 138 if (IS_ERR(pmic->rdev[i])) {
138 dev_err(&i2c->dev, "failed to register %s\n", id->name); 139 dev_err(&i2c->dev, "failed to register %s\n", id->name);
139 err = PTR_ERR(pmic->rdev[i]); 140 return PTR_ERR(pmic->rdev[i]);
140 goto error;
141 } 141 }
142 } 142 }
143 143
144 i2c_set_clientdata(i2c, pmic); 144 i2c_set_clientdata(i2c, pmic);
145 145
146 return 0; 146 return 0;
147
148error:
149 while (--i >= 0)
150 regulator_unregister(pmic->rdev[i]);
151 return err;
152}
153
154static int isl6271a_remove(struct i2c_client *i2c)
155{
156 struct isl_pmic *pmic = i2c_get_clientdata(i2c);
157 int i;
158
159 for (i = 0; i < 3; i++)
160 regulator_unregister(pmic->rdev[i]);
161 return 0;
162} 147}
163 148
164static const struct i2c_device_id isl6271a_id[] = { 149static const struct i2c_device_id isl6271a_id[] = {
@@ -174,7 +159,6 @@ static struct i2c_driver isl6271a_i2c_driver = {
174 .owner = THIS_MODULE, 159 .owner = THIS_MODULE,
175 }, 160 },
176 .probe = isl6271a_probe, 161 .probe = isl6271a_probe,
177 .remove = isl6271a_remove,
178 .id_table = isl6271a_id, 162 .id_table = isl6271a_id,
179}; 163};
180 164
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 3a599ee0a456..e242dd316d36 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -166,7 +166,7 @@ static int max1586_pmic_probe(struct i2c_client *client,
166 struct max1586_platform_data *pdata = dev_get_platdata(&client->dev); 166 struct max1586_platform_data *pdata = dev_get_platdata(&client->dev);
167 struct regulator_config config = { }; 167 struct regulator_config config = { };
168 struct max1586_data *max1586; 168 struct max1586_data *max1586;
169 int i, id, ret = -ENOMEM; 169 int i, id;
170 170
171 max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data) + 171 max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data) +
172 sizeof(struct regulator_dev *) * (MAX1586_V6 + 1), 172 sizeof(struct regulator_dev *) * (MAX1586_V6 + 1),
@@ -193,7 +193,7 @@ static int max1586_pmic_probe(struct i2c_client *client,
193 continue; 193 continue;
194 if (id < MAX1586_V3 || id > MAX1586_V6) { 194 if (id < MAX1586_V3 || id > MAX1586_V6) {
195 dev_err(&client->dev, "invalid regulator id %d\n", id); 195 dev_err(&client->dev, "invalid regulator id %d\n", id);
196 goto err; 196 return -EINVAL;
197 } 197 }
198 198
199 if (id == MAX1586_V3) { 199 if (id == MAX1586_V3) {
@@ -207,33 +207,18 @@ static int max1586_pmic_probe(struct i2c_client *client,
207 config.init_data = pdata->subdevs[i].platform_data; 207 config.init_data = pdata->subdevs[i].platform_data;
208 config.driver_data = max1586; 208 config.driver_data = max1586;
209 209
210 rdev[i] = regulator_register(&max1586_reg[id], &config); 210 rdev[i] = devm_regulator_register(&client->dev,
211 &max1586_reg[id], &config);
211 if (IS_ERR(rdev[i])) { 212 if (IS_ERR(rdev[i])) {
212 ret = PTR_ERR(rdev[i]);
213 dev_err(&client->dev, "failed to register %s\n", 213 dev_err(&client->dev, "failed to register %s\n",
214 max1586_reg[id].name); 214 max1586_reg[id].name);
215 goto err; 215 return PTR_ERR(rdev[i]);
216 } 216 }
217 } 217 }
218 218
219 i2c_set_clientdata(client, max1586); 219 i2c_set_clientdata(client, max1586);
220 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n"); 220 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n");
221 return 0; 221 return 0;
222
223err:
224 while (--i >= 0)
225 regulator_unregister(rdev[i]);
226 return ret;
227}
228
229static int max1586_pmic_remove(struct i2c_client *client)
230{
231 struct max1586_data *max1586 = i2c_get_clientdata(client);
232 int i;
233
234 for (i = 0; i <= MAX1586_V6; i++)
235 regulator_unregister(max1586->rdev[i]);
236 return 0;
237} 222}
238 223
239static const struct i2c_device_id max1586_id[] = { 224static const struct i2c_device_id max1586_id[] = {
@@ -244,7 +229,6 @@ MODULE_DEVICE_TABLE(i2c, max1586_id);
244 229
245static struct i2c_driver max1586_pmic_driver = { 230static struct i2c_driver max1586_pmic_driver = {
246 .probe = max1586_pmic_probe, 231 .probe = max1586_pmic_probe,
247 .remove = max1586_pmic_remove,
248 .driver = { 232 .driver = {
249 .name = "max1586", 233 .name = "max1586",
250 .owner = THIS_MODULE, 234 .owner = THIS_MODULE,
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index f563057e5690..ae001ccf26f4 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -478,32 +478,16 @@ static int max77686_pmic_probe(struct platform_device *pdev)
478 config.of_node = pdata->regulators[i].of_node; 478 config.of_node = pdata->regulators[i].of_node;
479 479
480 max77686->opmode[i] = regulators[i].enable_mask; 480 max77686->opmode[i] = regulators[i].enable_mask;
481 max77686->rdev[i] = regulator_register(&regulators[i], &config); 481 max77686->rdev[i] = devm_regulator_register(&pdev->dev,
482 &regulators[i], &config);
482 if (IS_ERR(max77686->rdev[i])) { 483 if (IS_ERR(max77686->rdev[i])) {
483 ret = PTR_ERR(max77686->rdev[i]);
484 dev_err(&pdev->dev, 484 dev_err(&pdev->dev,
485 "regulator init failed for %d\n", i); 485 "regulator init failed for %d\n", i);
486 max77686->rdev[i] = NULL; 486 return PTR_ERR(max77686->rdev[i]);
487 goto err;
488 } 487 }
489 } 488 }
490 489
491 return 0; 490 return 0;
492err:
493 while (--i >= 0)
494 regulator_unregister(max77686->rdev[i]);
495 return ret;
496}
497
498static int max77686_pmic_remove(struct platform_device *pdev)
499{
500 struct max77686_data *max77686 = platform_get_drvdata(pdev);
501 int i;
502
503 for (i = 0; i < MAX77686_REGULATORS; i++)
504 regulator_unregister(max77686->rdev[i]);
505
506 return 0;
507} 491}
508 492
509static const struct platform_device_id max77686_pmic_id[] = { 493static const struct platform_device_id max77686_pmic_id[] = {
@@ -518,7 +502,6 @@ static struct platform_driver max77686_pmic_driver = {
518 .owner = THIS_MODULE, 502 .owner = THIS_MODULE,
519 }, 503 },
520 .probe = max77686_pmic_probe, 504 .probe = max77686_pmic_probe,
521 .remove = max77686_pmic_remove,
522 .id_table = max77686_pmic_id, 505 .id_table = max77686_pmic_id,
523}; 506};
524 507
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c
index ce4b96c15eba..feb20bf4ccab 100644
--- a/drivers/regulator/max77693.c
+++ b/drivers/regulator/max77693.c
@@ -230,7 +230,7 @@ static int max77693_pmic_probe(struct platform_device *pdev)
230 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); 230 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
231 struct max77693_pmic_dev *max77693_pmic; 231 struct max77693_pmic_dev *max77693_pmic;
232 struct max77693_regulator_data *rdata = NULL; 232 struct max77693_regulator_data *rdata = NULL;
233 int num_rdata, i, ret; 233 int num_rdata, i;
234 struct regulator_config config; 234 struct regulator_config config;
235 235
236 num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata); 236 num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata);
@@ -266,36 +266,16 @@ static int max77693_pmic_probe(struct platform_device *pdev)
266 config.init_data = rdata[i].initdata; 266 config.init_data = rdata[i].initdata;
267 config.of_node = rdata[i].of_node; 267 config.of_node = rdata[i].of_node;
268 268
269 max77693_pmic->rdev[i] = regulator_register(&regulators[id], 269 max77693_pmic->rdev[i] = devm_regulator_register(&pdev->dev,
270 &config); 270 &regulators[id], &config);
271 if (IS_ERR(max77693_pmic->rdev[i])) { 271 if (IS_ERR(max77693_pmic->rdev[i])) {
272 ret = PTR_ERR(max77693_pmic->rdev[i]);
273 dev_err(max77693_pmic->dev, 272 dev_err(max77693_pmic->dev,
274 "Failed to initialize regulator-%d\n", id); 273 "Failed to initialize regulator-%d\n", id);
275 max77693_pmic->rdev[i] = NULL; 274 return PTR_ERR(max77693_pmic->rdev[i]);
276 goto err;
277 } 275 }
278 } 276 }
279 277
280 return 0; 278 return 0;
281 err:
282 while (--i >= 0)
283 regulator_unregister(max77693_pmic->rdev[i]);
284
285 return ret;
286}
287
288static int max77693_pmic_remove(struct platform_device *pdev)
289{
290 struct max77693_pmic_dev *max77693_pmic = platform_get_drvdata(pdev);
291 struct regulator_dev **rdev = max77693_pmic->rdev;
292 int i;
293
294 for (i = 0; i < max77693_pmic->num_regulators; i++)
295 if (rdev[i])
296 regulator_unregister(rdev[i]);
297
298 return 0;
299} 279}
300 280
301static const struct platform_device_id max77693_pmic_id[] = { 281static const struct platform_device_id max77693_pmic_id[] = {
@@ -311,7 +291,6 @@ static struct platform_driver max77693_pmic_driver = {
311 .owner = THIS_MODULE, 291 .owner = THIS_MODULE,
312 }, 292 },
313 .probe = max77693_pmic_probe, 293 .probe = max77693_pmic_probe,
314 .remove = max77693_pmic_remove,
315 .id_table = max77693_pmic_id, 294 .id_table = max77693_pmic_id,
316}; 295};
317 296
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
index 19c6f08eafd5..7f049c92ee52 100644
--- a/drivers/regulator/max8649.c
+++ b/drivers/regulator/max8649.c
@@ -234,7 +234,8 @@ static int max8649_regulator_probe(struct i2c_client *client,
234 config.driver_data = info; 234 config.driver_data = info;
235 config.regmap = info->regmap; 235 config.regmap = info->regmap;
236 236
237 info->regulator = regulator_register(&dcdc_desc, &config); 237 info->regulator = devm_regulator_register(&client->dev, &dcdc_desc,
238 &config);
238 if (IS_ERR(info->regulator)) { 239 if (IS_ERR(info->regulator)) {
239 dev_err(info->dev, "failed to register regulator %s\n", 240 dev_err(info->dev, "failed to register regulator %s\n",
240 dcdc_desc.name); 241 dcdc_desc.name);
@@ -244,16 +245,6 @@ static int max8649_regulator_probe(struct i2c_client *client,
244 return 0; 245 return 0;
245} 246}
246 247
247static int max8649_regulator_remove(struct i2c_client *client)
248{
249 struct max8649_regulator_info *info = i2c_get_clientdata(client);
250
251 if (info)
252 regulator_unregister(info->regulator);
253
254 return 0;
255}
256
257static const struct i2c_device_id max8649_id[] = { 248static const struct i2c_device_id max8649_id[] = {
258 { "max8649", 0 }, 249 { "max8649", 0 },
259 { } 250 { }
@@ -262,7 +253,6 @@ MODULE_DEVICE_TABLE(i2c, max8649_id);
262 253
263static struct i2c_driver max8649_driver = { 254static struct i2c_driver max8649_driver = {
264 .probe = max8649_regulator_probe, 255 .probe = max8649_regulator_probe,
265 .remove = max8649_regulator_remove,
266 .driver = { 256 .driver = {
267 .name = "max8649", 257 .name = "max8649",
268 }, 258 },
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index 144bcacd734d..8d94d3d7f97f 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -439,7 +439,7 @@ static int max8660_probe(struct i2c_client *client,
439 for (i = 0; i < pdata->num_subdevs; i++) { 439 for (i = 0; i < pdata->num_subdevs; i++) {
440 440
441 if (!pdata->subdevs[i].platform_data) 441 if (!pdata->subdevs[i].platform_data)
442 goto err_out; 442 return ret;
443 443
444 boot_on = pdata->subdevs[i].platform_data->constraints.boot_on; 444 boot_on = pdata->subdevs[i].platform_data->constraints.boot_on;
445 445
@@ -465,7 +465,7 @@ static int max8660_probe(struct i2c_client *client,
465 case MAX8660_V7: 465 case MAX8660_V7:
466 if (type == MAX8661) { 466 if (type == MAX8661) {
467 dev_err(dev, "Regulator not on this chip!\n"); 467 dev_err(dev, "Regulator not on this chip!\n");
468 goto err_out; 468 return -EINVAL;
469 } 469 }
470 470
471 if (boot_on) 471 if (boot_on)
@@ -475,7 +475,7 @@ static int max8660_probe(struct i2c_client *client,
475 default: 475 default:
476 dev_err(dev, "invalid regulator %s\n", 476 dev_err(dev, "invalid regulator %s\n",
477 pdata->subdevs[i].name); 477 pdata->subdevs[i].name);
478 goto err_out; 478 return ret;
479 } 479 }
480 } 480 }
481 481
@@ -489,33 +489,18 @@ static int max8660_probe(struct i2c_client *client,
489 config.of_node = of_node[i]; 489 config.of_node = of_node[i];
490 config.driver_data = max8660; 490 config.driver_data = max8660;
491 491
492 rdev[i] = regulator_register(&max8660_reg[id], &config); 492 rdev[i] = devm_regulator_register(&client->dev,
493 &max8660_reg[id], &config);
493 if (IS_ERR(rdev[i])) { 494 if (IS_ERR(rdev[i])) {
494 ret = PTR_ERR(rdev[i]); 495 ret = PTR_ERR(rdev[i]);
495 dev_err(dev, "failed to register %s\n", 496 dev_err(&client->dev, "failed to register %s\n",
496 max8660_reg[id].name); 497 max8660_reg[id].name);
497 goto err_unregister; 498 return PTR_ERR(rdev[i]);
498 } 499 }
499 } 500 }
500 501
501 i2c_set_clientdata(client, max8660); 502 i2c_set_clientdata(client, max8660);
502 return 0; 503 return 0;
503
504err_unregister:
505 while (--i >= 0)
506 regulator_unregister(rdev[i]);
507err_out:
508 return ret;
509}
510
511static int max8660_remove(struct i2c_client *client)
512{
513 struct max8660 *max8660 = i2c_get_clientdata(client);
514 int i;
515
516 for (i = 0; i < MAX8660_V_END; i++)
517 regulator_unregister(max8660->rdev[i]);
518 return 0;
519} 504}
520 505
521static const struct i2c_device_id max8660_id[] = { 506static const struct i2c_device_id max8660_id[] = {
@@ -527,7 +512,6 @@ MODULE_DEVICE_TABLE(i2c, max8660_id);
527 512
528static struct i2c_driver max8660_driver = { 513static struct i2c_driver max8660_driver = {
529 .probe = max8660_probe, 514 .probe = max8660_probe,
530 .remove = max8660_remove,
531 .driver = { 515 .driver = {
532 .name = "max8660", 516 .name = "max8660",
533 .owner = THIS_MODULE, 517 .owner = THIS_MODULE,
diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c
index 4568c15fa78d..0c5fe6c6ac26 100644
--- a/drivers/regulator/max8907-regulator.c
+++ b/drivers/regulator/max8907-regulator.c
@@ -350,33 +350,17 @@ static int max8907_regulator_probe(struct platform_device *pdev)
350 pmic->desc[i].ops = &max8907_out5v_hwctl_ops; 350 pmic->desc[i].ops = &max8907_out5v_hwctl_ops;
351 } 351 }
352 352
353 pmic->rdev[i] = regulator_register(&pmic->desc[i], &config); 353 pmic->rdev[i] = devm_regulator_register(&pdev->dev,
354 &pmic->desc[i], &config);
354 if (IS_ERR(pmic->rdev[i])) { 355 if (IS_ERR(pmic->rdev[i])) {
355 dev_err(&pdev->dev, 356 dev_err(&pdev->dev,
356 "failed to register %s regulator\n", 357 "failed to register %s regulator\n",
357 pmic->desc[i].name); 358 pmic->desc[i].name);
358 ret = PTR_ERR(pmic->rdev[i]); 359 return PTR_ERR(pmic->rdev[i]);
359 goto err_unregister_regulator;
360 } 360 }
361 } 361 }
362 362
363 return 0; 363 return 0;
364
365err_unregister_regulator:
366 while (--i >= 0)
367 regulator_unregister(pmic->rdev[i]);
368 return ret;
369}
370
371static int max8907_regulator_remove(struct platform_device *pdev)
372{
373 struct max8907_regulator *pmic = platform_get_drvdata(pdev);
374 int i;
375
376 for (i = 0; i < MAX8907_NUM_REGULATORS; i++)
377 regulator_unregister(pmic->rdev[i]);
378
379 return 0;
380} 364}
381 365
382static struct platform_driver max8907_regulator_driver = { 366static struct platform_driver max8907_regulator_driver = {
@@ -385,7 +369,6 @@ static struct platform_driver max8907_regulator_driver = {
385 .owner = THIS_MODULE, 369 .owner = THIS_MODULE,
386 }, 370 },
387 .probe = max8907_regulator_probe, 371 .probe = max8907_regulator_probe,
388 .remove = max8907_regulator_remove,
389}; 372};
390 373
391static int __init max8907_regulator_init(void) 374static int __init max8907_regulator_init(void)
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index 5b77ab7762e4..892aa1e5b96c 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -467,7 +467,7 @@ static int max8973_probe(struct i2c_client *client,
467 config.regmap = max->regmap; 467 config.regmap = max->regmap;
468 468
469 /* Register the regulators */ 469 /* Register the regulators */
470 rdev = regulator_register(&max->desc, &config); 470 rdev = devm_regulator_register(&client->dev, &max->desc, &config);
471 if (IS_ERR(rdev)) { 471 if (IS_ERR(rdev)) {
472 ret = PTR_ERR(rdev); 472 ret = PTR_ERR(rdev);
473 dev_err(max->dev, "regulator register failed, err %d\n", ret); 473 dev_err(max->dev, "regulator register failed, err %d\n", ret);
@@ -478,14 +478,6 @@ static int max8973_probe(struct i2c_client *client,
478 return 0; 478 return 0;
479} 479}
480 480
481static int max8973_remove(struct i2c_client *client)
482{
483 struct max8973_chip *max = i2c_get_clientdata(client);
484
485 regulator_unregister(max->rdev);
486 return 0;
487}
488
489static const struct i2c_device_id max8973_id[] = { 481static const struct i2c_device_id max8973_id[] = {
490 {.name = "max8973",}, 482 {.name = "max8973",},
491 {}, 483 {},
@@ -499,7 +491,6 @@ static struct i2c_driver max8973_i2c_driver = {
499 .owner = THIS_MODULE, 491 .owner = THIS_MODULE,
500 }, 492 },
501 .probe = max8973_probe, 493 .probe = max8973_probe,
502 .remove = max8973_remove,
503 .id_table = max8973_id, 494 .id_table = max8973_id,
504}; 495};
505 496
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index df20069f0537..bcd2488d1252 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -1081,7 +1081,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1081 pdata->buck1_voltage[i] + 1081 pdata->buck1_voltage[i] +
1082 buck1245_voltage_map_desc.step); 1082 buck1245_voltage_map_desc.step);
1083 if (ret < 0) 1083 if (ret < 0)
1084 goto err_out; 1084 return ret;
1085 1085
1086 max8997->buck2_vol[i] = ret = 1086 max8997->buck2_vol[i] = ret =
1087 max8997_get_voltage_proper_val( 1087 max8997_get_voltage_proper_val(
@@ -1090,7 +1090,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1090 pdata->buck2_voltage[i] + 1090 pdata->buck2_voltage[i] +
1091 buck1245_voltage_map_desc.step); 1091 buck1245_voltage_map_desc.step);
1092 if (ret < 0) 1092 if (ret < 0)
1093 goto err_out; 1093 return ret;
1094 1094
1095 max8997->buck5_vol[i] = ret = 1095 max8997->buck5_vol[i] = ret =
1096 max8997_get_voltage_proper_val( 1096 max8997_get_voltage_proper_val(
@@ -1099,7 +1099,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1099 pdata->buck5_voltage[i] + 1099 pdata->buck5_voltage[i] +
1100 buck1245_voltage_map_desc.step); 1100 buck1245_voltage_map_desc.step);
1101 if (ret < 0) 1101 if (ret < 0)
1102 goto err_out; 1102 return ret;
1103 1103
1104 if (max_buck1 < max8997->buck1_vol[i]) 1104 if (max_buck1 < max8997->buck1_vol[i])
1105 max_buck1 = max8997->buck1_vol[i]; 1105 max_buck1 = max8997->buck1_vol[i];
@@ -1143,24 +1143,23 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1143 !gpio_is_valid(pdata->buck125_gpios[1]) || 1143 !gpio_is_valid(pdata->buck125_gpios[1]) ||
1144 !gpio_is_valid(pdata->buck125_gpios[2])) { 1144 !gpio_is_valid(pdata->buck125_gpios[2])) {
1145 dev_err(&pdev->dev, "GPIO NOT VALID\n"); 1145 dev_err(&pdev->dev, "GPIO NOT VALID\n");
1146 ret = -EINVAL; 1146 return -EINVAL;
1147 goto err_out;
1148 } 1147 }
1149 1148
1150 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0], 1149 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0],
1151 "MAX8997 SET1"); 1150 "MAX8997 SET1");
1152 if (ret) 1151 if (ret)
1153 goto err_out; 1152 return ret;
1154 1153
1155 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1], 1154 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1],
1156 "MAX8997 SET2"); 1155 "MAX8997 SET2");
1157 if (ret) 1156 if (ret)
1158 goto err_out; 1157 return ret;
1159 1158
1160 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2], 1159 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2],
1161 "MAX8997 SET3"); 1160 "MAX8997 SET3");
1162 if (ret) 1161 if (ret)
1163 goto err_out; 1162 return ret;
1164 1163
1165 gpio_direction_output(pdata->buck125_gpios[0], 1164 gpio_direction_output(pdata->buck125_gpios[0],
1166 (max8997->buck125_gpioindex >> 2) 1165 (max8997->buck125_gpioindex >> 2)
@@ -1205,33 +1204,16 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1205 config.driver_data = max8997; 1204 config.driver_data = max8997;
1206 config.of_node = pdata->regulators[i].reg_node; 1205 config.of_node = pdata->regulators[i].reg_node;
1207 1206
1208 rdev[i] = regulator_register(&regulators[id], &config); 1207 rdev[i] = devm_regulator_register(&pdev->dev, &regulators[id],
1208 &config);
1209 if (IS_ERR(rdev[i])) { 1209 if (IS_ERR(rdev[i])) {
1210 ret = PTR_ERR(rdev[i]);
1211 dev_err(max8997->dev, "regulator init failed for %d\n", 1210 dev_err(max8997->dev, "regulator init failed for %d\n",
1212 id); 1211 id);
1213 rdev[i] = NULL; 1212 return PTR_ERR(rdev[i]);
1214 goto err;
1215 } 1213 }
1216 } 1214 }
1217 1215
1218 return 0; 1216 return 0;
1219err:
1220 while (--i >= 0)
1221 regulator_unregister(rdev[i]);
1222err_out:
1223 return ret;
1224}
1225
1226static int max8997_pmic_remove(struct platform_device *pdev)
1227{
1228 struct max8997_data *max8997 = platform_get_drvdata(pdev);
1229 struct regulator_dev **rdev = max8997->rdev;
1230 int i;
1231
1232 for (i = 0; i < max8997->num_regulators; i++)
1233 regulator_unregister(rdev[i]);
1234 return 0;
1235} 1217}
1236 1218
1237static const struct platform_device_id max8997_pmic_id[] = { 1219static const struct platform_device_id max8997_pmic_id[] = {
@@ -1246,7 +1228,6 @@ static struct platform_driver max8997_pmic_driver = {
1246 .owner = THIS_MODULE, 1228 .owner = THIS_MODULE,
1247 }, 1229 },
1248 .probe = max8997_pmic_probe, 1230 .probe = max8997_pmic_probe,
1249 .remove = max8997_pmic_remove,
1250 .id_table = max8997_pmic_id, 1231 .id_table = max8997_pmic_id,
1251}; 1232};
1252 1233
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index a4c53b2d1aaf..ae3f0656feb0 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -790,16 +790,14 @@ static int max8998_pmic_probe(struct platform_device *pdev)
790 dev_err(&pdev->dev, 790 dev_err(&pdev->dev,
791 "MAX8998 SET1 GPIO defined as 0 !\n"); 791 "MAX8998 SET1 GPIO defined as 0 !\n");
792 WARN_ON(!pdata->buck1_set1); 792 WARN_ON(!pdata->buck1_set1);
793 ret = -EIO; 793 return -EIO;
794 goto err_out;
795 } 794 }
796 /* Check if SET2 is not equal to 0 */ 795 /* Check if SET2 is not equal to 0 */
797 if (!pdata->buck1_set2) { 796 if (!pdata->buck1_set2) {
798 dev_err(&pdev->dev, 797 dev_err(&pdev->dev,
799 "MAX8998 SET2 GPIO defined as 0 !\n"); 798 "MAX8998 SET2 GPIO defined as 0 !\n");
800 WARN_ON(!pdata->buck1_set2); 799 WARN_ON(!pdata->buck1_set2);
801 ret = -EIO; 800 return -EIO;
802 goto err_out;
803 } 801 }
804 802
805 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1"); 803 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1");
@@ -823,7 +821,7 @@ static int max8998_pmic_probe(struct platform_device *pdev)
823 ret = max8998_write_reg(i2c, 821 ret = max8998_write_reg(i2c,
824 MAX8998_REG_BUCK1_VOLTAGE1 + v, i); 822 MAX8998_REG_BUCK1_VOLTAGE1 + v, i);
825 if (ret) 823 if (ret)
826 goto err_out; 824 return ret;
827 } 825 }
828 } 826 }
829 827
@@ -833,8 +831,7 @@ static int max8998_pmic_probe(struct platform_device *pdev)
833 dev_err(&pdev->dev, 831 dev_err(&pdev->dev,
834 "MAX8998 SET3 GPIO defined as 0 !\n"); 832 "MAX8998 SET3 GPIO defined as 0 !\n");
835 WARN_ON(!pdata->buck2_set3); 833 WARN_ON(!pdata->buck2_set3);
836 ret = -EIO; 834 return -EIO;
837 goto err_out;
838 } 835 }
839 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3"); 836 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3");
840 gpio_direction_output(pdata->buck2_set3, 837 gpio_direction_output(pdata->buck2_set3,
@@ -852,7 +849,7 @@ static int max8998_pmic_probe(struct platform_device *pdev)
852 ret = max8998_write_reg(i2c, 849 ret = max8998_write_reg(i2c,
853 MAX8998_REG_BUCK2_VOLTAGE1 + v, i); 850 MAX8998_REG_BUCK2_VOLTAGE1 + v, i);
854 if (ret) 851 if (ret)
855 goto err_out; 852 return ret;
856 } 853 }
857 } 854 }
858 855
@@ -875,34 +872,19 @@ static int max8998_pmic_probe(struct platform_device *pdev)
875 config.init_data = pdata->regulators[i].initdata; 872 config.init_data = pdata->regulators[i].initdata;
876 config.driver_data = max8998; 873 config.driver_data = max8998;
877 874
878 rdev[i] = regulator_register(&regulators[index], &config); 875 rdev[i] = devm_regulator_register(&pdev->dev,
876 &regulators[index], &config);
879 if (IS_ERR(rdev[i])) { 877 if (IS_ERR(rdev[i])) {
880 ret = PTR_ERR(rdev[i]); 878 ret = PTR_ERR(rdev[i]);
881 dev_err(max8998->dev, "regulator %s init failed (%d)\n", 879 dev_err(max8998->dev, "regulator %s init failed (%d)\n",
882 regulators[index].name, ret); 880 regulators[index].name, ret);
883 rdev[i] = NULL; 881 rdev[i] = NULL;
884 goto err; 882 return ret;
885 } 883 }
886 } 884 }
887 885
888 886
889 return 0; 887 return 0;
890err:
891 while (--i >= 0)
892 regulator_unregister(rdev[i]);
893err_out:
894 return ret;
895}
896
897static int max8998_pmic_remove(struct platform_device *pdev)
898{
899 struct max8998_data *max8998 = platform_get_drvdata(pdev);
900 struct regulator_dev **rdev = max8998->rdev;
901 int i;
902
903 for (i = 0; i < max8998->num_regulators; i++)
904 regulator_unregister(rdev[i]);
905 return 0;
906} 888}
907 889
908static const struct platform_device_id max8998_pmic_id[] = { 890static const struct platform_device_id max8998_pmic_id[] = {
@@ -918,7 +900,6 @@ static struct platform_driver max8998_pmic_driver = {
918 .owner = THIS_MODULE, 900 .owner = THIS_MODULE,
919 }, 901 },
920 .probe = max8998_pmic_probe, 902 .probe = max8998_pmic_probe,
921 .remove = max8998_pmic_remove,
922 .id_table = max8998_pmic_id, 903 .id_table = max8998_pmic_id,
923}; 904};
924 905
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index 5ff99d2703db..f036b26d4cfc 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -400,7 +400,7 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
400 dev_get_platdata(&pdev->dev); 400 dev_get_platdata(&pdev->dev);
401 struct mc13xxx_regulator_init_data *mc13xxx_data; 401 struct mc13xxx_regulator_init_data *mc13xxx_data;
402 struct regulator_config config = { }; 402 struct regulator_config config = { };
403 int i, ret, num_regulators; 403 int i, num_regulators;
404 404
405 num_regulators = mc13xxx_get_num_regulators_dt(pdev); 405 num_regulators = mc13xxx_get_num_regulators_dt(pdev);
406 406
@@ -444,32 +444,16 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
444 config.driver_data = priv; 444 config.driver_data = priv;
445 config.of_node = node; 445 config.of_node = node;
446 446
447 priv->regulators[i] = regulator_register(desc, &config); 447 priv->regulators[i] = devm_regulator_register(&pdev->dev, desc,
448 &config);
448 if (IS_ERR(priv->regulators[i])) { 449 if (IS_ERR(priv->regulators[i])) {
449 dev_err(&pdev->dev, "failed to register regulator %s\n", 450 dev_err(&pdev->dev, "failed to register regulator %s\n",
450 mc13783_regulators[i].desc.name); 451 mc13783_regulators[i].desc.name);
451 ret = PTR_ERR(priv->regulators[i]); 452 return PTR_ERR(priv->regulators[i]);
452 goto err;
453 } 453 }
454 } 454 }
455 455
456 return 0; 456 return 0;
457err:
458 while (--i >= 0)
459 regulator_unregister(priv->regulators[i]);
460
461 return ret;
462}
463
464static int mc13783_regulator_remove(struct platform_device *pdev)
465{
466 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
467 int i;
468
469 for (i = 0; i < priv->num_regulators; i++)
470 regulator_unregister(priv->regulators[i]);
471
472 return 0;
473} 457}
474 458
475static struct platform_driver mc13783_regulator_driver = { 459static struct platform_driver mc13783_regulator_driver = {
@@ -477,7 +461,6 @@ static struct platform_driver mc13783_regulator_driver = {
477 .name = "mc13783-regulator", 461 .name = "mc13783-regulator",
478 .owner = THIS_MODULE, 462 .owner = THIS_MODULE,
479 }, 463 },
480 .remove = mc13783_regulator_remove,
481 .probe = mc13783_regulator_probe, 464 .probe = mc13783_regulator_probe,
482}; 465};
483 466
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index 1037e07937cf..96c9f80d9550 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -611,43 +611,27 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
611 config.driver_data = priv; 611 config.driver_data = priv;
612 config.of_node = node; 612 config.of_node = node;
613 613
614 priv->regulators[i] = regulator_register(desc, &config); 614 priv->regulators[i] = devm_regulator_register(&pdev->dev, desc,
615 &config);
615 if (IS_ERR(priv->regulators[i])) { 616 if (IS_ERR(priv->regulators[i])) {
616 dev_err(&pdev->dev, "failed to register regulator %s\n", 617 dev_err(&pdev->dev, "failed to register regulator %s\n",
617 mc13892_regulators[i].desc.name); 618 mc13892_regulators[i].desc.name);
618 ret = PTR_ERR(priv->regulators[i]); 619 return PTR_ERR(priv->regulators[i]);
619 goto err;
620 } 620 }
621 } 621 }
622 622
623 return 0; 623 return 0;
624err:
625 while (--i >= 0)
626 regulator_unregister(priv->regulators[i]);
627 return ret;
628 624
629err_unlock: 625err_unlock:
630 mc13xxx_unlock(mc13892); 626 mc13xxx_unlock(mc13892);
631 return ret; 627 return ret;
632} 628}
633 629
634static int mc13892_regulator_remove(struct platform_device *pdev)
635{
636 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
637 int i;
638
639 for (i = 0; i < priv->num_regulators; i++)
640 regulator_unregister(priv->regulators[i]);
641
642 return 0;
643}
644
645static struct platform_driver mc13892_regulator_driver = { 630static struct platform_driver mc13892_regulator_driver = {
646 .driver = { 631 .driver = {
647 .name = "mc13892-regulator", 632 .name = "mc13892-regulator",
648 .owner = THIS_MODULE, 633 .owner = THIS_MODULE,
649 }, 634 },
650 .remove = mc13892_regulator_remove,
651 .probe = mc13892_regulator_probe, 635 .probe = mc13892_regulator_probe,
652}; 636};
653 637
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 7e2b165972e6..4f79c0d61faf 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -856,7 +856,7 @@ static int palmas_regulators_probe(struct platform_device *pdev)
856 if (ret < 0) { 856 if (ret < 0) {
857 dev_err(&pdev->dev, 857 dev_err(&pdev->dev,
858 "reading TSTEP reg failed: %d\n", ret); 858 "reading TSTEP reg failed: %d\n", ret);
859 goto err_unregister_regulator; 859 return ret;
860 } 860 }
861 pmic->desc[id].ramp_delay = 861 pmic->desc[id].ramp_delay =
862 palmas_smps_ramp_delay[reg & 0x3]; 862 palmas_smps_ramp_delay[reg & 0x3];
@@ -868,7 +868,7 @@ static int palmas_regulators_probe(struct platform_device *pdev)
868 reg_init = pdata->reg_init[id]; 868 reg_init = pdata->reg_init[id];
869 ret = palmas_smps_init(palmas, id, reg_init); 869 ret = palmas_smps_init(palmas, id, reg_init);
870 if (ret) 870 if (ret)
871 goto err_unregister_regulator; 871 return ret;
872 } 872 }
873 873
874 /* Register the regulators */ 874 /* Register the regulators */
@@ -909,7 +909,7 @@ static int palmas_regulators_probe(struct platform_device *pdev)
909 909
910 ret = palmas_smps_read(pmic->palmas, addr, &reg); 910 ret = palmas_smps_read(pmic->palmas, addr, &reg);
911 if (ret) 911 if (ret)
912 goto err_unregister_regulator; 912 return ret;
913 if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) 913 if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
914 pmic->range[id] = 1; 914 pmic->range[id] = 1;
915 915
@@ -925,7 +925,7 @@ static int palmas_regulators_probe(struct platform_device *pdev)
925 addr = palmas_regs_info[id].ctrl_addr; 925 addr = palmas_regs_info[id].ctrl_addr;
926 ret = palmas_smps_read(pmic->palmas, addr, &reg); 926 ret = palmas_smps_read(pmic->palmas, addr, &reg);
927 if (ret) 927 if (ret)
928 goto err_unregister_regulator; 928 return ret;
929 pmic->current_reg_mode[id] = reg & 929 pmic->current_reg_mode[id] = reg &
930 PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; 930 PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
931 } 931 }
@@ -941,13 +941,13 @@ static int palmas_regulators_probe(struct platform_device *pdev)
941 pmic->desc[id].supply_name = palmas_regs_info[id].sname; 941 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
942 config.of_node = palmas_matches[id].of_node; 942 config.of_node = palmas_matches[id].of_node;
943 943
944 rdev = regulator_register(&pmic->desc[id], &config); 944 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id],
945 &config);
945 if (IS_ERR(rdev)) { 946 if (IS_ERR(rdev)) {
946 dev_err(&pdev->dev, 947 dev_err(&pdev->dev,
947 "failed to register %s regulator\n", 948 "failed to register %s regulator\n",
948 pdev->name); 949 pdev->name);
949 ret = PTR_ERR(rdev); 950 return PTR_ERR(rdev);
950 goto err_unregister_regulator;
951 } 951 }
952 952
953 /* Save regulator for cleanup */ 953 /* Save regulator for cleanup */
@@ -1015,13 +1015,13 @@ static int palmas_regulators_probe(struct platform_device *pdev)
1015 pmic->desc[id].supply_name = palmas_regs_info[id].sname; 1015 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
1016 config.of_node = palmas_matches[id].of_node; 1016 config.of_node = palmas_matches[id].of_node;
1017 1017
1018 rdev = regulator_register(&pmic->desc[id], &config); 1018 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id],
1019 &config);
1019 if (IS_ERR(rdev)) { 1020 if (IS_ERR(rdev)) {
1020 dev_err(&pdev->dev, 1021 dev_err(&pdev->dev,
1021 "failed to register %s regulator\n", 1022 "failed to register %s regulator\n",
1022 pdev->name); 1023 pdev->name);
1023 ret = PTR_ERR(rdev); 1024 return PTR_ERR(rdev);
1024 goto err_unregister_regulator;
1025 } 1025 }
1026 1026
1027 /* Save regulator for cleanup */ 1027 /* Save regulator for cleanup */
@@ -1037,31 +1037,14 @@ static int palmas_regulators_probe(struct platform_device *pdev)
1037 else 1037 else
1038 ret = palmas_extreg_init(palmas, 1038 ret = palmas_extreg_init(palmas,
1039 id, reg_init); 1039 id, reg_init);
1040 if (ret) { 1040 if (ret)
1041 regulator_unregister(pmic->rdev[id]); 1041 return ret;
1042 goto err_unregister_regulator;
1043 }
1044 } 1042 }
1045 } 1043 }
1046 } 1044 }
1047 1045
1048 1046
1049 return 0; 1047 return 0;
1050
1051err_unregister_regulator:
1052 while (--id >= 0)
1053 regulator_unregister(pmic->rdev[id]);
1054 return ret;
1055}
1056
1057static int palmas_regulators_remove(struct platform_device *pdev)
1058{
1059 struct palmas_pmic *pmic = platform_get_drvdata(pdev);
1060 int id;
1061
1062 for (id = 0; id < PALMAS_NUM_REGS; id++)
1063 regulator_unregister(pmic->rdev[id]);
1064 return 0;
1065} 1048}
1066 1049
1067static struct of_device_id of_palmas_match_tbl[] = { 1050static struct of_device_id of_palmas_match_tbl[] = {
@@ -1083,7 +1066,6 @@ static struct platform_driver palmas_driver = {
1083 .owner = THIS_MODULE, 1066 .owner = THIS_MODULE,
1084 }, 1067 },
1085 .probe = palmas_regulators_probe, 1068 .probe = palmas_regulators_probe,
1086 .remove = palmas_regulators_remove,
1087}; 1069};
1088 1070
1089static int __init palmas_init(void) 1071static int __init palmas_init(void)
diff --git a/drivers/regulator/rc5t583-regulator.c b/drivers/regulator/rc5t583-regulator.c
index 5885b4504596..b58affb33143 100644
--- a/drivers/regulator/rc5t583-regulator.c
+++ b/drivers/regulator/rc5t583-regulator.c
@@ -173,33 +173,16 @@ skip_ext_pwr_config:
173 config.driver_data = reg; 173 config.driver_data = reg;
174 config.regmap = rc5t583->regmap; 174 config.regmap = rc5t583->regmap;
175 175
176 rdev = regulator_register(&ri->desc, &config); 176 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
177 if (IS_ERR(rdev)) { 177 if (IS_ERR(rdev)) {
178 dev_err(&pdev->dev, "Failed to register regulator %s\n", 178 dev_err(&pdev->dev, "Failed to register regulator %s\n",
179 ri->desc.name); 179 ri->desc.name);
180 ret = PTR_ERR(rdev); 180 return PTR_ERR(rdev);
181 goto clean_exit;
182 } 181 }
183 reg->rdev = rdev; 182 reg->rdev = rdev;
184 } 183 }
185 platform_set_drvdata(pdev, regs); 184 platform_set_drvdata(pdev, regs);
186 return 0; 185 return 0;
187
188clean_exit:
189 while (--id >= 0)
190 regulator_unregister(regs[id].rdev);
191
192 return ret;
193}
194
195static int rc5t583_regulator_remove(struct platform_device *pdev)
196{
197 struct rc5t583_regulator *regs = platform_get_drvdata(pdev);
198 int id;
199
200 for (id = 0; id < RC5T583_REGULATOR_MAX; ++id)
201 regulator_unregister(regs[id].rdev);
202 return 0;
203} 186}
204 187
205static struct platform_driver rc5t583_regulator_driver = { 188static struct platform_driver rc5t583_regulator_driver = {
@@ -208,7 +191,6 @@ static struct platform_driver rc5t583_regulator_driver = {
208 .owner = THIS_MODULE, 191 .owner = THIS_MODULE,
209 }, 192 },
210 .probe = rc5t583_regulator_probe, 193 .probe = rc5t583_regulator_probe,
211 .remove = rc5t583_regulator_remove,
212}; 194};
213 195
214static int __init rc5t583_regulator_init(void) 196static int __init rc5t583_regulator_init(void)
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 5eba2ff8c0e8..333677d68d0e 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -448,33 +448,17 @@ common_reg:
448 config.of_node = rdata[i].of_node; 448 config.of_node = rdata[i].of_node;
449 } 449 }
450 450
451 s2mps11->rdev[i] = regulator_register(&regulators[i], &config); 451 s2mps11->rdev[i] = devm_regulator_register(&pdev->dev,
452 &regulators[i], &config);
452 if (IS_ERR(s2mps11->rdev[i])) { 453 if (IS_ERR(s2mps11->rdev[i])) {
453 ret = PTR_ERR(s2mps11->rdev[i]); 454 ret = PTR_ERR(s2mps11->rdev[i]);
454 dev_err(&pdev->dev, "regulator init failed for %d\n", 455 dev_err(&pdev->dev, "regulator init failed for %d\n",
455 i); 456 i);
456 s2mps11->rdev[i] = NULL; 457 return ret;
457 goto err;
458 } 458 }
459 } 459 }
460 460
461 return 0; 461 return 0;
462err:
463 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
464 regulator_unregister(s2mps11->rdev[i]);
465
466 return ret;
467}
468
469static int s2mps11_pmic_remove(struct platform_device *pdev)
470{
471 struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev);
472 int i;
473
474 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
475 regulator_unregister(s2mps11->rdev[i]);
476
477 return 0;
478} 462}
479 463
480static const struct platform_device_id s2mps11_pmic_id[] = { 464static const struct platform_device_id s2mps11_pmic_id[] = {
@@ -489,7 +473,6 @@ static struct platform_driver s2mps11_pmic_driver = {
489 .owner = THIS_MODULE, 473 .owner = THIS_MODULE,
490 }, 474 },
491 .probe = s2mps11_pmic_probe, 475 .probe = s2mps11_pmic_probe,
492 .remove = s2mps11_pmic_remove,
493 .id_table = s2mps11_pmic_id, 476 .id_table = s2mps11_pmic_id,
494}; 477};
495 478
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index c24448bc43cf..2297fdf9ba7e 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -910,34 +910,17 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
910 config.regmap = iodev->regmap; 910 config.regmap = iodev->regmap;
911 config.of_node = pdata->regulators[i].reg_node; 911 config.of_node = pdata->regulators[i].reg_node;
912 912
913 rdev[i] = regulator_register(&regulators[id], &config); 913 rdev[i] = devm_regulator_register(&pdev->dev, &regulators[id],
914 &config);
914 if (IS_ERR(rdev[i])) { 915 if (IS_ERR(rdev[i])) {
915 ret = PTR_ERR(rdev[i]); 916 ret = PTR_ERR(rdev[i]);
916 dev_err(s5m8767->dev, "regulator init failed for %d\n", 917 dev_err(s5m8767->dev, "regulator init failed for %d\n",
917 id); 918 id);
918 rdev[i] = NULL; 919 return ret;
919 goto err;
920 } 920 }
921 } 921 }
922 922
923 return 0; 923 return 0;
924err:
925 for (i = 0; i < s5m8767->num_regulators; i++)
926 regulator_unregister(rdev[i]);
927
928 return ret;
929}
930
931static int s5m8767_pmic_remove(struct platform_device *pdev)
932{
933 struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev);
934 struct regulator_dev **rdev = s5m8767->rdev;
935 int i;
936
937 for (i = 0; i < s5m8767->num_regulators; i++)
938 regulator_unregister(rdev[i]);
939
940 return 0;
941} 924}
942 925
943static const struct platform_device_id s5m8767_pmic_id[] = { 926static const struct platform_device_id s5m8767_pmic_id[] = {
@@ -952,7 +935,6 @@ static struct platform_driver s5m8767_pmic_driver = {
952 .owner = THIS_MODULE, 935 .owner = THIS_MODULE,
953 }, 936 },
954 .probe = s5m8767_pmic_probe, 937 .probe = s5m8767_pmic_probe,
955 .remove = s5m8767_pmic_remove,
956 .id_table = s5m8767_pmic_id, 938 .id_table = s5m8767_pmic_id,
957}; 939};
958 940
diff --git a/drivers/regulator/ti-abb-regulator.c b/drivers/regulator/ti-abb-regulator.c
index b993ec570f66..20aab8f90e08 100644
--- a/drivers/regulator/ti-abb-regulator.c
+++ b/drivers/regulator/ti-abb-regulator.c
@@ -708,39 +708,31 @@ static int ti_abb_probe(struct platform_device *pdev)
708 match = of_match_device(ti_abb_of_match, dev); 708 match = of_match_device(ti_abb_of_match, dev);
709 if (!match) { 709 if (!match) {
710 /* We do not expect this to happen */ 710 /* We do not expect this to happen */
711 ret = -ENODEV;
712 dev_err(dev, "%s: Unable to match device\n", __func__); 711 dev_err(dev, "%s: Unable to match device\n", __func__);
713 goto err; 712 return -ENODEV;
714 } 713 }
715 if (!match->data) { 714 if (!match->data) {
716 ret = -EINVAL;
717 dev_err(dev, "%s: Bad data in match\n", __func__); 715 dev_err(dev, "%s: Bad data in match\n", __func__);
718 goto err; 716 return -EINVAL;
719 } 717 }
720 718
721 abb = devm_kzalloc(dev, sizeof(struct ti_abb), GFP_KERNEL); 719 abb = devm_kzalloc(dev, sizeof(struct ti_abb), GFP_KERNEL);
722 if (!abb) { 720 if (!abb)
723 dev_err(dev, "%s: Unable to allocate ABB struct\n", __func__); 721 return -ENOMEM;
724 ret = -ENOMEM;
725 goto err;
726 }
727 abb->regs = match->data; 722 abb->regs = match->data;
728 723
729 /* Map ABB resources */ 724 /* Map ABB resources */
730 pname = "base-address"; 725 pname = "base-address";
731 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 726 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
732 abb->base = devm_ioremap_resource(dev, res); 727 abb->base = devm_ioremap_resource(dev, res);
733 if (IS_ERR(abb->base)) { 728 if (IS_ERR(abb->base))
734 ret = PTR_ERR(abb->base); 729 return PTR_ERR(abb->base);
735 goto err;
736 }
737 730
738 pname = "int-address"; 731 pname = "int-address";
739 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 732 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
740 if (!res) { 733 if (!res) {
741 dev_err(dev, "Missing '%s' IO resource\n", pname); 734 dev_err(dev, "Missing '%s' IO resource\n", pname);
742 ret = -ENODEV; 735 return -ENODEV;
743 goto err;
744 } 736 }
745 /* 737 /*
746 * We may have shared interrupt register offsets which are 738 * We may have shared interrupt register offsets which are
@@ -750,8 +742,7 @@ static int ti_abb_probe(struct platform_device *pdev)
750 resource_size(res)); 742 resource_size(res));
751 if (!abb->int_base) { 743 if (!abb->int_base) {
752 dev_err(dev, "Unable to map '%s'\n", pname); 744 dev_err(dev, "Unable to map '%s'\n", pname);
753 ret = -ENOMEM; 745 return -ENOMEM;
754 goto err;
755 } 746 }
756 747
757 /* Map Optional resources */ 748 /* Map Optional resources */
@@ -771,17 +762,14 @@ static int ti_abb_probe(struct platform_device *pdev)
771 resource_size(res)); 762 resource_size(res));
772 if (!abb->efuse_base) { 763 if (!abb->efuse_base) {
773 dev_err(dev, "Unable to map '%s'\n", pname); 764 dev_err(dev, "Unable to map '%s'\n", pname);
774 ret = -ENOMEM; 765 return -ENOMEM;
775 goto err;
776 } 766 }
777 767
778 pname = "ldo-address"; 768 pname = "ldo-address";
779 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 769 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
780 abb->ldo_base = devm_ioremap_resource(dev, res); 770 abb->ldo_base = devm_ioremap_resource(dev, res);
781 if (IS_ERR(abb->ldo_base)) { 771 if (IS_ERR(abb->ldo_base))
782 ret = PTR_ERR(abb->ldo_base); 772 return PTR_ERR(abb->ldo_base);
783 goto err;
784 }
785 773
786 /* IF ldo_base is set, the following are mandatory */ 774 /* IF ldo_base is set, the following are mandatory */
787 pname = "ti,ldovbb-override-mask"; 775 pname = "ti,ldovbb-override-mask";
@@ -790,12 +778,11 @@ static int ti_abb_probe(struct platform_device *pdev)
790 &abb->ldovbb_override_mask); 778 &abb->ldovbb_override_mask);
791 if (ret) { 779 if (ret) {
792 dev_err(dev, "Missing '%s' (%d)\n", pname, ret); 780 dev_err(dev, "Missing '%s' (%d)\n", pname, ret);
793 goto err; 781 return ret;
794 } 782 }
795 if (!abb->ldovbb_override_mask) { 783 if (!abb->ldovbb_override_mask) {
796 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname); 784 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname);
797 ret = -EINVAL; 785 return -EINVAL;
798 goto err;
799 } 786 }
800 787
801 pname = "ti,ldovbb-vset-mask"; 788 pname = "ti,ldovbb-vset-mask";
@@ -804,12 +791,11 @@ static int ti_abb_probe(struct platform_device *pdev)
804 &abb->ldovbb_vset_mask); 791 &abb->ldovbb_vset_mask);
805 if (ret) { 792 if (ret) {
806 dev_err(dev, "Missing '%s' (%d)\n", pname, ret); 793 dev_err(dev, "Missing '%s' (%d)\n", pname, ret);
807 goto err; 794 return ret;
808 } 795 }
809 if (!abb->ldovbb_vset_mask) { 796 if (!abb->ldovbb_vset_mask) {
810 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname); 797 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname);
811 ret = -EINVAL; 798 return -EINVAL;
812 goto err;
813 } 799 }
814 800
815skip_opt: 801skip_opt:
@@ -819,31 +805,29 @@ skip_opt:
819 &abb->txdone_mask); 805 &abb->txdone_mask);
820 if (ret) { 806 if (ret) {
821 dev_err(dev, "Missing '%s' (%d)\n", pname, ret); 807 dev_err(dev, "Missing '%s' (%d)\n", pname, ret);
822 goto err; 808 return ret;
823 } 809 }
824 if (!abb->txdone_mask) { 810 if (!abb->txdone_mask) {
825 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname); 811 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname);
826 ret = -EINVAL; 812 return -EINVAL;
827 goto err;
828 } 813 }
829 814
830 initdata = of_get_regulator_init_data(dev, pdev->dev.of_node); 815 initdata = of_get_regulator_init_data(dev, pdev->dev.of_node);
831 if (!initdata) { 816 if (!initdata) {
832 ret = -ENOMEM;
833 dev_err(dev, "%s: Unable to alloc regulator init data\n", 817 dev_err(dev, "%s: Unable to alloc regulator init data\n",
834 __func__); 818 __func__);
835 goto err; 819 return -ENOMEM;
836 } 820 }
837 821
838 /* init ABB opp_sel table */ 822 /* init ABB opp_sel table */
839 ret = ti_abb_init_table(dev, abb, initdata); 823 ret = ti_abb_init_table(dev, abb, initdata);
840 if (ret) 824 if (ret)
841 goto err; 825 return ret;
842 826
843 /* init ABB timing */ 827 /* init ABB timing */
844 ret = ti_abb_init_timings(dev, abb); 828 ret = ti_abb_init_timings(dev, abb);
845 if (ret) 829 if (ret)
846 goto err; 830 return ret;
847 831
848 desc = &abb->rdesc; 832 desc = &abb->rdesc;
849 desc->name = dev_name(dev); 833 desc->name = dev_name(dev);
@@ -861,12 +845,12 @@ skip_opt:
861 config.driver_data = abb; 845 config.driver_data = abb;
862 config.of_node = pdev->dev.of_node; 846 config.of_node = pdev->dev.of_node;
863 847
864 rdev = regulator_register(desc, &config); 848 rdev = devm_regulator_register(dev, desc, &config);
865 if (IS_ERR(rdev)) { 849 if (IS_ERR(rdev)) {
866 ret = PTR_ERR(rdev); 850 ret = PTR_ERR(rdev);
867 dev_err(dev, "%s: failed to register regulator(%d)\n", 851 dev_err(dev, "%s: failed to register regulator(%d)\n",
868 __func__, ret); 852 __func__, ret);
869 goto err; 853 return ret;
870 } 854 }
871 platform_set_drvdata(pdev, rdev); 855 platform_set_drvdata(pdev, rdev);
872 856
@@ -874,31 +858,12 @@ skip_opt:
874 ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->regs->setup_reg, abb->base); 858 ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->regs->setup_reg, abb->base);
875 859
876 return 0; 860 return 0;
877
878err:
879 dev_err(dev, "%s: Failed to initialize(%d)\n", __func__, ret);
880 return ret;
881}
882
883/**
884 * ti_abb_remove() - cleanups
885 * @pdev: ABB platform device
886 *
887 * Return: 0
888 */
889static int ti_abb_remove(struct platform_device *pdev)
890{
891 struct regulator_dev *rdev = platform_get_drvdata(pdev);
892
893 regulator_unregister(rdev);
894 return 0;
895} 861}
896 862
897MODULE_ALIAS("platform:ti_abb"); 863MODULE_ALIAS("platform:ti_abb");
898 864
899static struct platform_driver ti_abb_driver = { 865static struct platform_driver ti_abb_driver = {
900 .probe = ti_abb_probe, 866 .probe = ti_abb_probe,
901 .remove = ti_abb_remove,
902 .driver = { 867 .driver = {
903 .name = "ti_abb", 868 .name = "ti_abb",
904 .owner = THIS_MODULE, 869 .owner = THIS_MODULE,
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c
index 9392a7ca3d2d..b0a3f0917a27 100644
--- a/drivers/regulator/tps51632-regulator.c
+++ b/drivers/regulator/tps51632-regulator.c
@@ -343,7 +343,7 @@ static int tps51632_probe(struct i2c_client *client,
343 config.regmap = tps->regmap; 343 config.regmap = tps->regmap;
344 config.of_node = client->dev.of_node; 344 config.of_node = client->dev.of_node;
345 345
346 rdev = regulator_register(&tps->desc, &config); 346 rdev = devm_regulator_register(&client->dev, &tps->desc, &config);
347 if (IS_ERR(rdev)) { 347 if (IS_ERR(rdev)) {
348 dev_err(tps->dev, "regulator register failed\n"); 348 dev_err(tps->dev, "regulator register failed\n");
349 return PTR_ERR(rdev); 349 return PTR_ERR(rdev);
@@ -353,14 +353,6 @@ static int tps51632_probe(struct i2c_client *client,
353 return 0; 353 return 0;
354} 354}
355 355
356static int tps51632_remove(struct i2c_client *client)
357{
358 struct tps51632_chip *tps = i2c_get_clientdata(client);
359
360 regulator_unregister(tps->rdev);
361 return 0;
362}
363
364static const struct i2c_device_id tps51632_id[] = { 356static const struct i2c_device_id tps51632_id[] = {
365 {.name = "tps51632",}, 357 {.name = "tps51632",},
366 {}, 358 {},
@@ -375,7 +367,6 @@ static struct i2c_driver tps51632_i2c_driver = {
375 .of_match_table = of_match_ptr(tps51632_of_match), 367 .of_match_table = of_match_ptr(tps51632_of_match),
376 }, 368 },
377 .probe = tps51632_probe, 369 .probe = tps51632_probe,
378 .remove = tps51632_remove,
379 .id_table = tps51632_id, 370 .id_table = tps51632_id,
380}; 371};
381 372
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c
index 0b7ebb1ebf85..c2c0185a2dcd 100644
--- a/drivers/regulator/tps62360-regulator.c
+++ b/drivers/regulator/tps62360-regulator.c
@@ -476,7 +476,7 @@ static int tps62360_probe(struct i2c_client *client,
476 config.of_node = client->dev.of_node; 476 config.of_node = client->dev.of_node;
477 477
478 /* Register the regulators */ 478 /* Register the regulators */
479 rdev = regulator_register(&tps->desc, &config); 479 rdev = devm_regulator_register(&client->dev, &tps->desc, &config);
480 if (IS_ERR(rdev)) { 480 if (IS_ERR(rdev)) {
481 dev_err(tps->dev, 481 dev_err(tps->dev,
482 "%s(): regulator register failed with err %s\n", 482 "%s(): regulator register failed with err %s\n",
@@ -488,20 +488,6 @@ static int tps62360_probe(struct i2c_client *client,
488 return 0; 488 return 0;
489} 489}
490 490
491/**
492 * tps62360_remove - tps62360 driver i2c remove handler
493 * @client: i2c driver client device structure
494 *
495 * Unregister TPS driver as an i2c client device driver
496 */
497static int tps62360_remove(struct i2c_client *client)
498{
499 struct tps62360_chip *tps = i2c_get_clientdata(client);
500
501 regulator_unregister(tps->rdev);
502 return 0;
503}
504
505static void tps62360_shutdown(struct i2c_client *client) 491static void tps62360_shutdown(struct i2c_client *client)
506{ 492{
507 struct tps62360_chip *tps = i2c_get_clientdata(client); 493 struct tps62360_chip *tps = i2c_get_clientdata(client);
@@ -535,7 +521,6 @@ static struct i2c_driver tps62360_i2c_driver = {
535 .of_match_table = of_match_ptr(tps62360_of_match), 521 .of_match_table = of_match_ptr(tps62360_of_match),
536 }, 522 },
537 .probe = tps62360_probe, 523 .probe = tps62360_probe,
538 .remove = tps62360_remove,
539 .shutdown = tps62360_shutdown, 524 .shutdown = tps62360_shutdown,
540 .id_table = tps62360_id, 525 .id_table = tps62360_id,
541}; 526};
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index a15263d4bdff..a957579bd98b 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -277,12 +277,12 @@ static int tps_65023_probe(struct i2c_client *client,
277 config.regmap = tps->regmap; 277 config.regmap = tps->regmap;
278 278
279 /* Register the regulators */ 279 /* Register the regulators */
280 rdev = regulator_register(&tps->desc[i], &config); 280 rdev = devm_regulator_register(&client->dev, &tps->desc[i],
281 &config);
281 if (IS_ERR(rdev)) { 282 if (IS_ERR(rdev)) {
282 dev_err(&client->dev, "failed to register %s\n", 283 dev_err(&client->dev, "failed to register %s\n",
283 id->name); 284 id->name);
284 error = PTR_ERR(rdev); 285 return PTR_ERR(rdev);
285 goto fail;
286 } 286 }
287 287
288 /* Save regulator for cleanup */ 288 /* Save regulator for cleanup */
@@ -296,21 +296,6 @@ static int tps_65023_probe(struct i2c_client *client,
296 TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); 296 TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ);
297 297
298 return 0; 298 return 0;
299
300 fail:
301 while (--i >= 0)
302 regulator_unregister(tps->rdev[i]);
303 return error;
304}
305
306static int tps_65023_remove(struct i2c_client *client)
307{
308 struct tps_pmic *tps = i2c_get_clientdata(client);
309 int i;
310
311 for (i = 0; i < TPS65023_NUM_REGULATOR; i++)
312 regulator_unregister(tps->rdev[i]);
313 return 0;
314} 299}
315 300
316static const struct tps_info tps65020_regs[] = { 301static const struct tps_info tps65020_regs[] = {
@@ -430,7 +415,6 @@ static struct i2c_driver tps_65023_i2c_driver = {
430 .owner = THIS_MODULE, 415 .owner = THIS_MODULE,
431 }, 416 },
432 .probe = tps_65023_probe, 417 .probe = tps_65023_probe,
433 .remove = tps_65023_remove,
434 .id_table = tps_65023_id, 418 .id_table = tps_65023_id,
435}; 419};
436 420
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index 4117ff52dba1..162a0fae20b3 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -508,13 +508,13 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
508 config.of_node = tps6507x_reg_matches[i].of_node; 508 config.of_node = tps6507x_reg_matches[i].of_node;
509 } 509 }
510 510
511 rdev = regulator_register(&tps->desc[i], &config); 511 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],
512 &config);
512 if (IS_ERR(rdev)) { 513 if (IS_ERR(rdev)) {
513 dev_err(tps6507x_dev->dev, 514 dev_err(tps6507x_dev->dev,
514 "failed to register %s regulator\n", 515 "failed to register %s regulator\n",
515 pdev->name); 516 pdev->name);
516 error = PTR_ERR(rdev); 517 return PTR_ERR(rdev);
517 goto fail;
518 } 518 }
519 519
520 /* Save regulator for cleanup */ 520 /* Save regulator for cleanup */
@@ -525,22 +525,6 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
525 platform_set_drvdata(pdev, tps6507x_dev); 525 platform_set_drvdata(pdev, tps6507x_dev);
526 526
527 return 0; 527 return 0;
528
529fail:
530 while (--i >= 0)
531 regulator_unregister(tps->rdev[i]);
532 return error;
533}
534
535static int tps6507x_pmic_remove(struct platform_device *pdev)
536{
537 struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
538 struct tps6507x_pmic *tps = tps6507x_dev->pmic;
539 int i;
540
541 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
542 regulator_unregister(tps->rdev[i]);
543 return 0;
544} 528}
545 529
546static struct platform_driver tps6507x_pmic_driver = { 530static struct platform_driver tps6507x_pmic_driver = {
@@ -549,7 +533,6 @@ static struct platform_driver tps6507x_pmic_driver = {
549 .owner = THIS_MODULE, 533 .owner = THIS_MODULE,
550 }, 534 },
551 .probe = tps6507x_pmic_probe, 535 .probe = tps6507x_pmic_probe,
552 .remove = tps6507x_pmic_remove,
553}; 536};
554 537
555static int __init tps6507x_pmic_init(void) 538static int __init tps6507x_pmic_init(void)
diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c
index c8e70451df38..bd611cdf6e1c 100644
--- a/drivers/regulator/tps65090-regulator.c
+++ b/drivers/regulator/tps65090-regulator.c
@@ -279,7 +279,7 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
279 if (ret < 0) { 279 if (ret < 0) {
280 dev_err(&pdev->dev, 280 dev_err(&pdev->dev,
281 "failed disable ext control\n"); 281 "failed disable ext control\n");
282 goto scrub; 282 return ret;
283 } 283 }
284 } 284 }
285 } 285 }
@@ -296,12 +296,11 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
296 else 296 else
297 config.of_node = NULL; 297 config.of_node = NULL;
298 298
299 rdev = regulator_register(ri->desc, &config); 299 rdev = devm_regulator_register(&pdev->dev, ri->desc, &config);
300 if (IS_ERR(rdev)) { 300 if (IS_ERR(rdev)) {
301 dev_err(&pdev->dev, "failed to register regulator %s\n", 301 dev_err(&pdev->dev, "failed to register regulator %s\n",
302 ri->desc->name); 302 ri->desc->name);
303 ret = PTR_ERR(rdev); 303 return PTR_ERR(rdev);
304 goto scrub;
305 } 304 }
306 ri->rdev = rdev; 305 ri->rdev = rdev;
307 306
@@ -309,36 +308,13 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
309 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data && 308 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data &&
310 tps_pdata->enable_ext_control) { 309 tps_pdata->enable_ext_control) {
311 ret = tps65090_config_ext_control(ri, true); 310 ret = tps65090_config_ext_control(ri, true);
312 if (ret < 0) { 311 if (ret < 0)
313 /* Increment num to get unregister rdev */ 312 return ret;
314 num++;
315 goto scrub;
316 }
317 } 313 }
318 } 314 }
319 315
320 platform_set_drvdata(pdev, pmic); 316 platform_set_drvdata(pdev, pmic);
321 return 0; 317 return 0;
322
323scrub:
324 while (--num >= 0) {
325 ri = &pmic[num];
326 regulator_unregister(ri->rdev);
327 }
328 return ret;
329}
330
331static int tps65090_regulator_remove(struct platform_device *pdev)
332{
333 struct tps65090_regulator *pmic = platform_get_drvdata(pdev);
334 struct tps65090_regulator *ri;
335 int num;
336
337 for (num = 0; num < TPS65090_REGULATOR_MAX; ++num) {
338 ri = &pmic[num];
339 regulator_unregister(ri->rdev);
340 }
341 return 0;
342} 318}
343 319
344static struct platform_driver tps65090_regulator_driver = { 320static struct platform_driver tps65090_regulator_driver = {
@@ -347,7 +323,6 @@ static struct platform_driver tps65090_regulator_driver = {
347 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
348 }, 324 },
349 .probe = tps65090_regulator_probe, 325 .probe = tps65090_regulator_probe,
350 .remove = tps65090_regulator_remove,
351}; 326};
352 327
353static int __init tps65090_regulator_init(void) 328static int __init tps65090_regulator_init(void)
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index 90861d68a0b0..8860379fd6be 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -233,7 +233,7 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
233 struct regulator_init_data *reg_data; 233 struct regulator_init_data *reg_data;
234 struct regulator_dev *rdev; 234 struct regulator_dev *rdev;
235 struct regulator_config config = { }; 235 struct regulator_config config = { };
236 int i, ret; 236 int i;
237 237
238 if (tps->dev->of_node) 238 if (tps->dev->of_node)
239 pdata = tps65217_parse_dt(pdev); 239 pdata = tps65217_parse_dt(pdev);
@@ -269,35 +269,18 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
269 if (tps->dev->of_node) 269 if (tps->dev->of_node)
270 config.of_node = pdata->of_node[i]; 270 config.of_node = pdata->of_node[i];
271 271
272 rdev = regulator_register(&regulators[i], &config); 272 rdev = devm_regulator_register(&pdev->dev, &regulators[i],
273 &config);
273 if (IS_ERR(rdev)) { 274 if (IS_ERR(rdev)) {
274 dev_err(tps->dev, "failed to register %s regulator\n", 275 dev_err(tps->dev, "failed to register %s regulator\n",
275 pdev->name); 276 pdev->name);
276 ret = PTR_ERR(rdev); 277 return PTR_ERR(rdev);
277 goto err_unregister_regulator;
278 } 278 }
279 279
280 /* Save regulator for cleanup */ 280 /* Save regulator for cleanup */
281 tps->rdev[i] = rdev; 281 tps->rdev[i] = rdev;
282 } 282 }
283 return 0; 283 return 0;
284
285err_unregister_regulator:
286 while (--i >= 0)
287 regulator_unregister(tps->rdev[i]);
288
289 return ret;
290}
291
292static int tps65217_regulator_remove(struct platform_device *pdev)
293{
294 struct tps65217 *tps = platform_get_drvdata(pdev);
295 unsigned int i;
296
297 for (i = 0; i < TPS65217_NUM_REGULATOR; i++)
298 regulator_unregister(tps->rdev[i]);
299
300 return 0;
301} 284}
302 285
303static struct platform_driver tps65217_regulator_driver = { 286static struct platform_driver tps65217_regulator_driver = {
@@ -305,7 +288,6 @@ static struct platform_driver tps65217_regulator_driver = {
305 .name = "tps65217-pmic", 288 .name = "tps65217-pmic",
306 }, 289 },
307 .probe = tps65217_regulator_probe, 290 .probe = tps65217_regulator_probe,
308 .remove = tps65217_regulator_remove,
309}; 291};
310 292
311static int __init tps65217_regulator_init(void) 293static int __init tps65217_regulator_init(void)
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 2c9155b66f09..45e5d683d3f8 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -379,15 +379,14 @@ static int tps6586x_regulator_probe(struct platform_device *pdev)
379 ri = find_regulator_info(id); 379 ri = find_regulator_info(id);
380 if (!ri) { 380 if (!ri) {
381 dev_err(&pdev->dev, "invalid regulator ID specified\n"); 381 dev_err(&pdev->dev, "invalid regulator ID specified\n");
382 err = -EINVAL; 382 return -EINVAL;
383 goto fail;
384 } 383 }
385 384
386 err = tps6586x_regulator_preinit(pdev->dev.parent, ri); 385 err = tps6586x_regulator_preinit(pdev->dev.parent, ri);
387 if (err) { 386 if (err) {
388 dev_err(&pdev->dev, 387 dev_err(&pdev->dev,
389 "regulator %d preinit failed, e %d\n", id, err); 388 "regulator %d preinit failed, e %d\n", id, err);
390 goto fail; 389 return err;
391 } 390 }
392 391
393 config.dev = pdev->dev.parent; 392 config.dev = pdev->dev.parent;
@@ -397,12 +396,12 @@ static int tps6586x_regulator_probe(struct platform_device *pdev)
397 if (tps6586x_reg_matches) 396 if (tps6586x_reg_matches)
398 config.of_node = tps6586x_reg_matches[id].of_node; 397 config.of_node = tps6586x_reg_matches[id].of_node;
399 398
400 rdev[id] = regulator_register(&ri->desc, &config); 399 rdev[id] = devm_regulator_register(&pdev->dev, &ri->desc,
400 &config);
401 if (IS_ERR(rdev[id])) { 401 if (IS_ERR(rdev[id])) {
402 dev_err(&pdev->dev, "failed to register regulator %s\n", 402 dev_err(&pdev->dev, "failed to register regulator %s\n",
403 ri->desc.name); 403 ri->desc.name);
404 err = PTR_ERR(rdev[id]); 404 return PTR_ERR(rdev[id]);
405 goto fail;
406 } 405 }
407 406
408 if (reg_data) { 407 if (reg_data) {
@@ -411,30 +410,13 @@ static int tps6586x_regulator_probe(struct platform_device *pdev)
411 if (err < 0) { 410 if (err < 0) {
412 dev_err(&pdev->dev, 411 dev_err(&pdev->dev,
413 "Slew rate config failed, e %d\n", err); 412 "Slew rate config failed, e %d\n", err);
414 regulator_unregister(rdev[id]); 413 return err;
415 goto fail;
416 } 414 }
417 } 415 }
418 } 416 }
419 417
420 platform_set_drvdata(pdev, rdev); 418 platform_set_drvdata(pdev, rdev);
421 return 0; 419 return 0;
422
423fail:
424 while (--id >= 0)
425 regulator_unregister(rdev[id]);
426 return err;
427}
428
429static int tps6586x_regulator_remove(struct platform_device *pdev)
430{
431 struct regulator_dev **rdev = platform_get_drvdata(pdev);
432 int id = TPS6586X_ID_MAX_REGULATOR;
433
434 while (--id >= 0)
435 regulator_unregister(rdev[id]);
436
437 return 0;
438} 420}
439 421
440static struct platform_driver tps6586x_regulator_driver = { 422static struct platform_driver tps6586x_regulator_driver = {
@@ -443,7 +425,6 @@ static struct platform_driver tps6586x_regulator_driver = {
443 .owner = THIS_MODULE, 425 .owner = THIS_MODULE,
444 }, 426 },
445 .probe = tps6586x_regulator_probe, 427 .probe = tps6586x_regulator_probe,
446 .remove = tps6586x_regulator_remove,
447}; 428};
448 429
449static int __init tps6586x_regulator_init(void) 430static int __init tps6586x_regulator_init(void)
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 45c16447744b..b8167df71170 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -1177,35 +1177,19 @@ static int tps65910_probe(struct platform_device *pdev)
1177 if (tps65910_reg_matches) 1177 if (tps65910_reg_matches)
1178 config.of_node = tps65910_reg_matches[i].of_node; 1178 config.of_node = tps65910_reg_matches[i].of_node;
1179 1179
1180 rdev = regulator_register(&pmic->desc[i], &config); 1180 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
1181 &config);
1181 if (IS_ERR(rdev)) { 1182 if (IS_ERR(rdev)) {
1182 dev_err(tps65910->dev, 1183 dev_err(tps65910->dev,
1183 "failed to register %s regulator\n", 1184 "failed to register %s regulator\n",
1184 pdev->name); 1185 pdev->name);
1185 err = PTR_ERR(rdev); 1186 return PTR_ERR(rdev);
1186 goto err_unregister_regulator;
1187 } 1187 }
1188 1188
1189 /* Save regulator for cleanup */ 1189 /* Save regulator for cleanup */
1190 pmic->rdev[i] = rdev; 1190 pmic->rdev[i] = rdev;
1191 } 1191 }
1192 return 0; 1192 return 0;
1193
1194err_unregister_regulator:
1195 while (--i >= 0)
1196 regulator_unregister(pmic->rdev[i]);
1197 return err;
1198}
1199
1200static int tps65910_remove(struct platform_device *pdev)
1201{
1202 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1203 int i;
1204
1205 for (i = 0; i < pmic->num_regulators; i++)
1206 regulator_unregister(pmic->rdev[i]);
1207
1208 return 0;
1209} 1193}
1210 1194
1211static void tps65910_shutdown(struct platform_device *pdev) 1195static void tps65910_shutdown(struct platform_device *pdev)
@@ -1244,7 +1228,6 @@ static struct platform_driver tps65910_driver = {
1244 .owner = THIS_MODULE, 1228 .owner = THIS_MODULE,
1245 }, 1229 },
1246 .probe = tps65910_probe, 1230 .probe = tps65910_probe,
1247 .remove = tps65910_remove,
1248 .shutdown = tps65910_shutdown, 1231 .shutdown = tps65910_shutdown,
1249}; 1232};
1250 1233
diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c
index 281e52ac64ba..1ed4d049abfe 100644
--- a/drivers/regulator/tps65912-regulator.c
+++ b/drivers/regulator/tps65912-regulator.c
@@ -461,7 +461,7 @@ static int tps65912_probe(struct platform_device *pdev)
461 struct regulator_dev *rdev; 461 struct regulator_dev *rdev;
462 struct tps65912_reg *pmic; 462 struct tps65912_reg *pmic;
463 struct tps65912_board *pmic_plat_data; 463 struct tps65912_board *pmic_plat_data;
464 int i, err; 464 int i;
465 465
466 pmic_plat_data = dev_get_platdata(tps65912->dev); 466 pmic_plat_data = dev_get_platdata(tps65912->dev);
467 if (!pmic_plat_data) 467 if (!pmic_plat_data)
@@ -504,34 +504,19 @@ static int tps65912_probe(struct platform_device *pdev)
504 config.init_data = reg_data; 504 config.init_data = reg_data;
505 config.driver_data = pmic; 505 config.driver_data = pmic;
506 506
507 rdev = regulator_register(&pmic->desc[i], &config); 507 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
508 &config);
508 if (IS_ERR(rdev)) { 509 if (IS_ERR(rdev)) {
509 dev_err(tps65912->dev, 510 dev_err(tps65912->dev,
510 "failed to register %s regulator\n", 511 "failed to register %s regulator\n",
511 pdev->name); 512 pdev->name);
512 err = PTR_ERR(rdev); 513 return PTR_ERR(rdev);
513 goto err;
514 } 514 }
515 515
516 /* Save regulator for cleanup */ 516 /* Save regulator for cleanup */
517 pmic->rdev[i] = rdev; 517 pmic->rdev[i] = rdev;
518 } 518 }
519 return 0; 519 return 0;
520
521err:
522 while (--i >= 0)
523 regulator_unregister(pmic->rdev[i]);
524 return err;
525}
526
527static int tps65912_remove(struct platform_device *pdev)
528{
529 struct tps65912_reg *tps65912_reg = platform_get_drvdata(pdev);
530 int i;
531
532 for (i = 0; i < TPS65912_NUM_REGULATOR; i++)
533 regulator_unregister(tps65912_reg->rdev[i]);
534 return 0;
535} 520}
536 521
537static struct platform_driver tps65912_driver = { 522static struct platform_driver tps65912_driver = {
@@ -540,7 +525,6 @@ static struct platform_driver tps65912_driver = {
540 .owner = THIS_MODULE, 525 .owner = THIS_MODULE,
541 }, 526 },
542 .probe = tps65912_probe, 527 .probe = tps65912_probe,
543 .remove = tps65912_remove,
544}; 528};
545 529
546static int __init tps65912_init(void) 530static int __init tps65912_init(void)
diff --git a/drivers/regulator/tps80031-regulator.c b/drivers/regulator/tps80031-regulator.c
index 6511d0bfd896..71f457a42623 100644
--- a/drivers/regulator/tps80031-regulator.c
+++ b/drivers/regulator/tps80031-regulator.c
@@ -719,7 +719,7 @@ static int tps80031_regulator_probe(struct platform_device *pdev)
719 if (ret < 0) { 719 if (ret < 0) {
720 dev_err(&pdev->dev, 720 dev_err(&pdev->dev,
721 "regulator config failed, e %d\n", ret); 721 "regulator config failed, e %d\n", ret);
722 goto fail; 722 return ret;
723 } 723 }
724 724
725 ret = tps80031_power_req_config(pdev->dev.parent, 725 ret = tps80031_power_req_config(pdev->dev.parent,
@@ -727,41 +727,22 @@ static int tps80031_regulator_probe(struct platform_device *pdev)
727 if (ret < 0) { 727 if (ret < 0) {
728 dev_err(&pdev->dev, 728 dev_err(&pdev->dev,
729 "pwr_req config failed, err %d\n", ret); 729 "pwr_req config failed, err %d\n", ret);
730 goto fail; 730 return ret;
731 } 731 }
732 } 732 }
733 rdev = regulator_register(&ri->rinfo->desc, &config); 733 rdev = devm_regulator_register(&pdev->dev, &ri->rinfo->desc,
734 &config);
734 if (IS_ERR(rdev)) { 735 if (IS_ERR(rdev)) {
735 dev_err(&pdev->dev, 736 dev_err(&pdev->dev,
736 "register regulator failed %s\n", 737 "register regulator failed %s\n",
737 ri->rinfo->desc.name); 738 ri->rinfo->desc.name);
738 ret = PTR_ERR(rdev); 739 return PTR_ERR(rdev);
739 goto fail;
740 } 740 }
741 ri->rdev = rdev; 741 ri->rdev = rdev;
742 } 742 }
743 743
744 platform_set_drvdata(pdev, pmic); 744 platform_set_drvdata(pdev, pmic);
745 return 0; 745 return 0;
746fail:
747 while (--num >= 0) {
748 ri = &pmic[num];
749 regulator_unregister(ri->rdev);
750 }
751 return ret;
752}
753
754static int tps80031_regulator_remove(struct platform_device *pdev)
755{
756 struct tps80031_regulator *pmic = platform_get_drvdata(pdev);
757 struct tps80031_regulator *ri = NULL;
758 int num;
759
760 for (num = 0; num < TPS80031_REGULATOR_MAX; ++num) {
761 ri = &pmic[num];
762 regulator_unregister(ri->rdev);
763 }
764 return 0;
765} 746}
766 747
767static struct platform_driver tps80031_regulator_driver = { 748static struct platform_driver tps80031_regulator_driver = {
@@ -770,7 +751,6 @@ static struct platform_driver tps80031_regulator_driver = {
770 .owner = THIS_MODULE, 751 .owner = THIS_MODULE,
771 }, 752 },
772 .probe = tps80031_regulator_probe, 753 .probe = tps80031_regulator_probe,
773 .remove = tps80031_regulator_remove,
774}; 754};
775 755
776static int __init tps80031_regulator_init(void) 756static int __init tps80031_regulator_init(void)
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 11861cb861df..6823e6f2b88a 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -387,8 +387,9 @@ static struct regulator_ops wm831x_buckv_ops = {
387 * Set up DVS control. We just log errors since we can still run 387 * Set up DVS control. We just log errors since we can still run
388 * (with reduced performance) if we fail. 388 * (with reduced performance) if we fail.
389 */ 389 */
390static void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc, 390static void wm831x_buckv_dvs_init(struct platform_device *pdev,
391 struct wm831x_buckv_pdata *pdata) 391 struct wm831x_dcdc *dcdc,
392 struct wm831x_buckv_pdata *pdata)
392{ 393{
393 struct wm831x *wm831x = dcdc->wm831x; 394 struct wm831x *wm831x = dcdc->wm831x;
394 int ret; 395 int ret;
@@ -402,9 +403,9 @@ static void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc,
402 */ 403 */
403 dcdc->dvs_gpio_state = pdata->dvs_init_state; 404 dcdc->dvs_gpio_state = pdata->dvs_init_state;
404 405
405 ret = gpio_request_one(pdata->dvs_gpio, 406 ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio,
406 dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, 407 dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0,
407 "DCDC DVS"); 408 "DCDC DVS");
408 if (ret < 0) { 409 if (ret < 0) {
409 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", 410 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n",
410 dcdc->name, ret); 411 dcdc->name, ret);
@@ -513,7 +514,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
513 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK; 514 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK;
514 515
515 if (pdata && pdata->dcdc[id]) 516 if (pdata && pdata->dcdc[id])
516 wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data); 517 wm831x_buckv_dvs_init(pdev, dcdc,
518 pdata->dcdc[id]->driver_data);
517 519
518 config.dev = pdev->dev.parent; 520 config.dev = pdev->dev.parent;
519 if (pdata) 521 if (pdata)
@@ -521,7 +523,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
521 config.driver_data = dcdc; 523 config.driver_data = dcdc;
522 config.regmap = wm831x->regmap; 524 config.regmap = wm831x->regmap;
523 525
524 dcdc->regulator = regulator_register(&dcdc->desc, &config); 526 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
527 &config);
525 if (IS_ERR(dcdc->regulator)) { 528 if (IS_ERR(dcdc->regulator)) {
526 ret = PTR_ERR(dcdc->regulator); 529 ret = PTR_ERR(dcdc->regulator);
527 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 530 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -530,57 +533,35 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
530 } 533 }
531 534
532 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 535 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
533 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, 536 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
534 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 537 wm831x_dcdc_uv_irq,
538 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
535 if (ret != 0) { 539 if (ret != 0) {
536 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 540 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
537 irq, ret); 541 irq, ret);
538 goto err_regulator; 542 goto err;
539 } 543 }
540 544
541 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")); 545 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC"));
542 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_oc_irq, 546 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
543 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 547 wm831x_dcdc_oc_irq,
548 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
544 if (ret != 0) { 549 if (ret != 0) {
545 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n", 550 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n",
546 irq, ret); 551 irq, ret);
547 goto err_uv; 552 goto err;
548 } 553 }
549 554
550 platform_set_drvdata(pdev, dcdc); 555 platform_set_drvdata(pdev, dcdc);
551 556
552 return 0; 557 return 0;
553 558
554err_uv:
555 free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")),
556 dcdc);
557err_regulator:
558 regulator_unregister(dcdc->regulator);
559err: 559err:
560 if (dcdc->dvs_gpio)
561 gpio_free(dcdc->dvs_gpio);
562 return ret; 560 return ret;
563} 561}
564 562
565static int wm831x_buckv_remove(struct platform_device *pdev)
566{
567 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
568 struct wm831x *wm831x = dcdc->wm831x;
569
570 free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")),
571 dcdc);
572 free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")),
573 dcdc);
574 regulator_unregister(dcdc->regulator);
575 if (dcdc->dvs_gpio)
576 gpio_free(dcdc->dvs_gpio);
577
578 return 0;
579}
580
581static struct platform_driver wm831x_buckv_driver = { 563static struct platform_driver wm831x_buckv_driver = {
582 .probe = wm831x_buckv_probe, 564 .probe = wm831x_buckv_probe,
583 .remove = wm831x_buckv_remove,
584 .driver = { 565 .driver = {
585 .name = "wm831x-buckv", 566 .name = "wm831x-buckv",
586 .owner = THIS_MODULE, 567 .owner = THIS_MODULE,
@@ -681,7 +662,8 @@ static int wm831x_buckp_probe(struct platform_device *pdev)
681 config.driver_data = dcdc; 662 config.driver_data = dcdc;
682 config.regmap = wm831x->regmap; 663 config.regmap = wm831x->regmap;
683 664
684 dcdc->regulator = regulator_register(&dcdc->desc, &config); 665 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
666 &config);
685 if (IS_ERR(dcdc->regulator)) { 667 if (IS_ERR(dcdc->regulator)) {
686 ret = PTR_ERR(dcdc->regulator); 668 ret = PTR_ERR(dcdc->regulator);
687 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 669 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -690,38 +672,25 @@ static int wm831x_buckp_probe(struct platform_device *pdev)
690 } 672 }
691 673
692 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 674 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
693 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, 675 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
694 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 676 wm831x_dcdc_uv_irq,
677 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
695 if (ret != 0) { 678 if (ret != 0) {
696 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 679 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
697 irq, ret); 680 irq, ret);
698 goto err_regulator; 681 goto err;
699 } 682 }
700 683
701 platform_set_drvdata(pdev, dcdc); 684 platform_set_drvdata(pdev, dcdc);
702 685
703 return 0; 686 return 0;
704 687
705err_regulator:
706 regulator_unregister(dcdc->regulator);
707err: 688err:
708 return ret; 689 return ret;
709} 690}
710 691
711static int wm831x_buckp_remove(struct platform_device *pdev)
712{
713 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
714
715 free_irq(wm831x_irq(dcdc->wm831x, platform_get_irq_byname(pdev, "UV")),
716 dcdc);
717 regulator_unregister(dcdc->regulator);
718
719 return 0;
720}
721
722static struct platform_driver wm831x_buckp_driver = { 692static struct platform_driver wm831x_buckp_driver = {
723 .probe = wm831x_buckp_probe, 693 .probe = wm831x_buckp_probe,
724 .remove = wm831x_buckp_remove,
725 .driver = { 694 .driver = {
726 .name = "wm831x-buckp", 695 .name = "wm831x-buckp",
727 .owner = THIS_MODULE, 696 .owner = THIS_MODULE,
@@ -813,7 +782,8 @@ static int wm831x_boostp_probe(struct platform_device *pdev)
813 config.driver_data = dcdc; 782 config.driver_data = dcdc;
814 config.regmap = wm831x->regmap; 783 config.regmap = wm831x->regmap;
815 784
816 dcdc->regulator = regulator_register(&dcdc->desc, &config); 785 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
786 &config);
817 if (IS_ERR(dcdc->regulator)) { 787 if (IS_ERR(dcdc->regulator)) {
818 ret = PTR_ERR(dcdc->regulator); 788 ret = PTR_ERR(dcdc->regulator);
819 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 789 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -822,39 +792,26 @@ static int wm831x_boostp_probe(struct platform_device *pdev)
822 } 792 }
823 793
824 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 794 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
825 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, 795 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
826 IRQF_TRIGGER_RISING, dcdc->name, 796 wm831x_dcdc_uv_irq,
827 dcdc); 797 IRQF_TRIGGER_RISING, dcdc->name,
798 dcdc);
828 if (ret != 0) { 799 if (ret != 0) {
829 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 800 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
830 irq, ret); 801 irq, ret);
831 goto err_regulator; 802 goto err;
832 } 803 }
833 804
834 platform_set_drvdata(pdev, dcdc); 805 platform_set_drvdata(pdev, dcdc);
835 806
836 return 0; 807 return 0;
837 808
838err_regulator:
839 regulator_unregister(dcdc->regulator);
840err: 809err:
841 return ret; 810 return ret;
842} 811}
843 812
844static int wm831x_boostp_remove(struct platform_device *pdev)
845{
846 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
847
848 free_irq(wm831x_irq(dcdc->wm831x, platform_get_irq_byname(pdev, "UV")),
849 dcdc);
850 regulator_unregister(dcdc->regulator);
851
852 return 0;
853}
854
855static struct platform_driver wm831x_boostp_driver = { 813static struct platform_driver wm831x_boostp_driver = {
856 .probe = wm831x_boostp_probe, 814 .probe = wm831x_boostp_probe,
857 .remove = wm831x_boostp_remove,
858 .driver = { 815 .driver = {
859 .name = "wm831x-boostp", 816 .name = "wm831x-boostp",
860 .owner = THIS_MODULE, 817 .owner = THIS_MODULE,
@@ -914,7 +871,8 @@ static int wm831x_epe_probe(struct platform_device *pdev)
914 config.driver_data = dcdc; 871 config.driver_data = dcdc;
915 config.regmap = wm831x->regmap; 872 config.regmap = wm831x->regmap;
916 873
917 dcdc->regulator = regulator_register(&dcdc->desc, &config); 874 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
875 &config);
918 if (IS_ERR(dcdc->regulator)) { 876 if (IS_ERR(dcdc->regulator)) {
919 ret = PTR_ERR(dcdc->regulator); 877 ret = PTR_ERR(dcdc->regulator);
920 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n", 878 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n",
@@ -930,18 +888,8 @@ err:
930 return ret; 888 return ret;
931} 889}
932 890
933static int wm831x_epe_remove(struct platform_device *pdev)
934{
935 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
936
937 regulator_unregister(dcdc->regulator);
938
939 return 0;
940}
941
942static struct platform_driver wm831x_epe_driver = { 891static struct platform_driver wm831x_epe_driver = {
943 .probe = wm831x_epe_probe, 892 .probe = wm831x_epe_probe,
944 .remove = wm831x_epe_remove,
945 .driver = { 893 .driver = {
946 .name = "wm831x-epe", 894 .name = "wm831x-epe",
947 .owner = THIS_MODULE, 895 .owner = THIS_MODULE,
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c
index 4eb373de1fac..0339b886df5d 100644
--- a/drivers/regulator/wm831x-isink.c
+++ b/drivers/regulator/wm831x-isink.c
@@ -194,7 +194,8 @@ static int wm831x_isink_probe(struct platform_device *pdev)
194 config.init_data = pdata->isink[id]; 194 config.init_data = pdata->isink[id];
195 config.driver_data = isink; 195 config.driver_data = isink;
196 196
197 isink->regulator = regulator_register(&isink->desc, &config); 197 isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc,
198 &config);
198 if (IS_ERR(isink->regulator)) { 199 if (IS_ERR(isink->regulator)) {
199 ret = PTR_ERR(isink->regulator); 200 ret = PTR_ERR(isink->regulator);
200 dev_err(wm831x->dev, "Failed to register ISINK%d: %d\n", 201 dev_err(wm831x->dev, "Failed to register ISINK%d: %d\n",
@@ -203,38 +204,26 @@ static int wm831x_isink_probe(struct platform_device *pdev)
203 } 204 }
204 205
205 irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0)); 206 irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0));
206 ret = request_threaded_irq(irq, NULL, wm831x_isink_irq, 207 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
207 IRQF_TRIGGER_RISING, isink->name, isink); 208 wm831x_isink_irq,
209 IRQF_TRIGGER_RISING, isink->name,
210 isink);
208 if (ret != 0) { 211 if (ret != 0) {
209 dev_err(&pdev->dev, "Failed to request ISINK IRQ %d: %d\n", 212 dev_err(&pdev->dev, "Failed to request ISINK IRQ %d: %d\n",
210 irq, ret); 213 irq, ret);
211 goto err_regulator; 214 goto err;
212 } 215 }
213 216
214 platform_set_drvdata(pdev, isink); 217 platform_set_drvdata(pdev, isink);
215 218
216 return 0; 219 return 0;
217 220
218err_regulator:
219 regulator_unregister(isink->regulator);
220err: 221err:
221 return ret; 222 return ret;
222} 223}
223 224
224static int wm831x_isink_remove(struct platform_device *pdev)
225{
226 struct wm831x_isink *isink = platform_get_drvdata(pdev);
227
228 free_irq(wm831x_irq(isink->wm831x, platform_get_irq(pdev, 0)), isink);
229
230 regulator_unregister(isink->regulator);
231
232 return 0;
233}
234
235static struct platform_driver wm831x_isink_driver = { 225static struct platform_driver wm831x_isink_driver = {
236 .probe = wm831x_isink_probe, 226 .probe = wm831x_isink_probe,
237 .remove = wm831x_isink_remove,
238 .driver = { 227 .driver = {
239 .name = "wm831x-isink", 228 .name = "wm831x-isink",
240 .owner = THIS_MODULE, 229 .owner = THIS_MODULE,
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 2205fbc2c37b..482ebe8f47aa 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -279,7 +279,8 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev)
279 config.driver_data = ldo; 279 config.driver_data = ldo;
280 config.regmap = wm831x->regmap; 280 config.regmap = wm831x->regmap;
281 281
282 ldo->regulator = regulator_register(&ldo->desc, &config); 282 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
283 &config);
283 if (IS_ERR(ldo->regulator)) { 284 if (IS_ERR(ldo->regulator)) {
284 ret = PTR_ERR(ldo->regulator); 285 ret = PTR_ERR(ldo->regulator);
285 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 286 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
@@ -288,39 +289,26 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev)
288 } 289 }
289 290
290 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 291 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
291 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, 292 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
292 IRQF_TRIGGER_RISING, ldo->name, 293 wm831x_ldo_uv_irq,
293 ldo); 294 IRQF_TRIGGER_RISING, ldo->name,
295 ldo);
294 if (ret != 0) { 296 if (ret != 0) {
295 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 297 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
296 irq, ret); 298 irq, ret);
297 goto err_regulator; 299 goto err;
298 } 300 }
299 301
300 platform_set_drvdata(pdev, ldo); 302 platform_set_drvdata(pdev, ldo);
301 303
302 return 0; 304 return 0;
303 305
304err_regulator:
305 regulator_unregister(ldo->regulator);
306err: 306err:
307 return ret; 307 return ret;
308} 308}
309 309
310static int wm831x_gp_ldo_remove(struct platform_device *pdev)
311{
312 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
313
314 free_irq(wm831x_irq(ldo->wm831x,
315 platform_get_irq_byname(pdev, "UV")), ldo);
316 regulator_unregister(ldo->regulator);
317
318 return 0;
319}
320
321static struct platform_driver wm831x_gp_ldo_driver = { 310static struct platform_driver wm831x_gp_ldo_driver = {
322 .probe = wm831x_gp_ldo_probe, 311 .probe = wm831x_gp_ldo_probe,
323 .remove = wm831x_gp_ldo_remove,
324 .driver = { 312 .driver = {
325 .name = "wm831x-ldo", 313 .name = "wm831x-ldo",
326 .owner = THIS_MODULE, 314 .owner = THIS_MODULE,
@@ -505,7 +493,8 @@ static int wm831x_aldo_probe(struct platform_device *pdev)
505 config.driver_data = ldo; 493 config.driver_data = ldo;
506 config.regmap = wm831x->regmap; 494 config.regmap = wm831x->regmap;
507 495
508 ldo->regulator = regulator_register(&ldo->desc, &config); 496 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
497 &config);
509 if (IS_ERR(ldo->regulator)) { 498 if (IS_ERR(ldo->regulator)) {
510 ret = PTR_ERR(ldo->regulator); 499 ret = PTR_ERR(ldo->regulator);
511 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 500 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
@@ -514,38 +503,25 @@ static int wm831x_aldo_probe(struct platform_device *pdev)
514 } 503 }
515 504
516 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 505 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
517 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, 506 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
518 IRQF_TRIGGER_RISING, ldo->name, ldo); 507 wm831x_ldo_uv_irq,
508 IRQF_TRIGGER_RISING, ldo->name, ldo);
519 if (ret != 0) { 509 if (ret != 0) {
520 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 510 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
521 irq, ret); 511 irq, ret);
522 goto err_regulator; 512 goto err;
523 } 513 }
524 514
525 platform_set_drvdata(pdev, ldo); 515 platform_set_drvdata(pdev, ldo);
526 516
527 return 0; 517 return 0;
528 518
529err_regulator:
530 regulator_unregister(ldo->regulator);
531err: 519err:
532 return ret; 520 return ret;
533} 521}
534 522
535static int wm831x_aldo_remove(struct platform_device *pdev)
536{
537 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
538
539 free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")),
540 ldo);
541 regulator_unregister(ldo->regulator);
542
543 return 0;
544}
545
546static struct platform_driver wm831x_aldo_driver = { 523static struct platform_driver wm831x_aldo_driver = {
547 .probe = wm831x_aldo_probe, 524 .probe = wm831x_aldo_probe,
548 .remove = wm831x_aldo_remove,
549 .driver = { 525 .driver = {
550 .name = "wm831x-aldo", 526 .name = "wm831x-aldo",
551 .owner = THIS_MODULE, 527 .owner = THIS_MODULE,
@@ -663,7 +639,8 @@ static int wm831x_alive_ldo_probe(struct platform_device *pdev)
663 config.driver_data = ldo; 639 config.driver_data = ldo;
664 config.regmap = wm831x->regmap; 640 config.regmap = wm831x->regmap;
665 641
666 ldo->regulator = regulator_register(&ldo->desc, &config); 642 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
643 &config);
667 if (IS_ERR(ldo->regulator)) { 644 if (IS_ERR(ldo->regulator)) {
668 ret = PTR_ERR(ldo->regulator); 645 ret = PTR_ERR(ldo->regulator);
669 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 646 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
@@ -679,18 +656,8 @@ err:
679 return ret; 656 return ret;
680} 657}
681 658
682static int wm831x_alive_ldo_remove(struct platform_device *pdev)
683{
684 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
685
686 regulator_unregister(ldo->regulator);
687
688 return 0;
689}
690
691static struct platform_driver wm831x_alive_ldo_driver = { 659static struct platform_driver wm831x_alive_ldo_driver = {
692 .probe = wm831x_alive_ldo_probe, 660 .probe = wm831x_alive_ldo_probe,
693 .remove = wm831x_alive_ldo_remove,
694 .driver = { 661 .driver = {
695 .name = "wm831x-alive-ldo", 662 .name = "wm831x-alive-ldo",
696 .owner = THIS_MODULE, 663 .owner = THIS_MODULE,
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index 61ca9292a429..017e8695ca71 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -1206,7 +1206,8 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1206 config.regmap = wm8350->regmap; 1206 config.regmap = wm8350->regmap;
1207 1207
1208 /* register regulator */ 1208 /* register regulator */
1209 rdev = regulator_register(&wm8350_reg[pdev->id], &config); 1209 rdev = devm_regulator_register(&pdev->dev, &wm8350_reg[pdev->id],
1210 &config);
1210 if (IS_ERR(rdev)) { 1211 if (IS_ERR(rdev)) {
1211 dev_err(&pdev->dev, "failed to register %s\n", 1212 dev_err(&pdev->dev, "failed to register %s\n",
1212 wm8350_reg[pdev->id].name); 1213 wm8350_reg[pdev->id].name);
@@ -1217,7 +1218,6 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1217 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq, 1218 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq,
1218 pmic_uv_handler, 0, "UV", rdev); 1219 pmic_uv_handler, 0, "UV", rdev);
1219 if (ret < 0) { 1220 if (ret < 0) {
1220 regulator_unregister(rdev);
1221 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n", 1221 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n",
1222 wm8350_reg[pdev->id].name); 1222 wm8350_reg[pdev->id].name);
1223 return ret; 1223 return ret;
@@ -1233,8 +1233,6 @@ static int wm8350_regulator_remove(struct platform_device *pdev)
1233 1233
1234 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq, rdev); 1234 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq, rdev);
1235 1235
1236 regulator_unregister(rdev);
1237
1238 return 0; 1236 return 0;
1239} 1237}
1240 1238
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 58f51bec13f2..870b52f709bc 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -219,7 +219,8 @@ static int wm8400_regulator_probe(struct platform_device *pdev)
219 config.driver_data = wm8400; 219 config.driver_data = wm8400;
220 config.regmap = wm8400->regmap; 220 config.regmap = wm8400->regmap;
221 221
222 rdev = regulator_register(&regulators[pdev->id], &config); 222 rdev = devm_regulator_register(&pdev->dev, &regulators[pdev->id],
223 &config);
223 if (IS_ERR(rdev)) 224 if (IS_ERR(rdev))
224 return PTR_ERR(rdev); 225 return PTR_ERR(rdev);
225 226
@@ -228,21 +229,11 @@ static int wm8400_regulator_probe(struct platform_device *pdev)
228 return 0; 229 return 0;
229} 230}
230 231
231static int wm8400_regulator_remove(struct platform_device *pdev)
232{
233 struct regulator_dev *rdev = platform_get_drvdata(pdev);
234
235 regulator_unregister(rdev);
236
237 return 0;
238}
239
240static struct platform_driver wm8400_regulator_driver = { 232static struct platform_driver wm8400_regulator_driver = {
241 .driver = { 233 .driver = {
242 .name = "wm8400-regulator", 234 .name = "wm8400-regulator",
243 }, 235 },
244 .probe = wm8400_regulator_probe, 236 .probe = wm8400_regulator_probe,
245 .remove = wm8400_regulator_remove,
246}; 237};
247 238
248/** 239/**
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 5ee2a208457c..71c5911f2e71 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -165,7 +165,9 @@ static int wm8994_ldo_probe(struct platform_device *pdev)
165 ldo->init_data = *pdata->ldo[id].init_data; 165 ldo->init_data = *pdata->ldo[id].init_data;
166 } 166 }
167 167
168 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config); 168 ldo->regulator = devm_regulator_register(&pdev->dev,
169 &wm8994_ldo_desc[id],
170 &config);
169 if (IS_ERR(ldo->regulator)) { 171 if (IS_ERR(ldo->regulator)) {
170 ret = PTR_ERR(ldo->regulator); 172 ret = PTR_ERR(ldo->regulator);
171 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", 173 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n",
@@ -181,18 +183,8 @@ err:
181 return ret; 183 return ret;
182} 184}
183 185
184static int wm8994_ldo_remove(struct platform_device *pdev)
185{
186 struct wm8994_ldo *ldo = platform_get_drvdata(pdev);
187
188 regulator_unregister(ldo->regulator);
189
190 return 0;
191}
192
193static struct platform_driver wm8994_ldo_driver = { 186static struct platform_driver wm8994_ldo_driver = {
194 .probe = wm8994_ldo_probe, 187 .probe = wm8994_ldo_probe,
195 .remove = wm8994_ldo_remove,
196 .driver = { 188 .driver = {
197 .name = "wm8994-ldo", 189 .name = "wm8994-ldo",
198 .owner = THIS_MODULE, 190 .owner = THIS_MODULE,