aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/regulator/max1586.c15
-rw-r--r--drivers/regulator/max77686.c15
-rw-r--r--drivers/regulator/max77693.c44
-rw-r--r--drivers/regulator/max8649.c8
-rw-r--r--drivers/regulator/max8660.c35
-rw-r--r--drivers/regulator/max8907-regulator.c16
-rw-r--r--drivers/regulator/max8925-regulator.c8
-rw-r--r--drivers/regulator/max8952.c26
8 files changed, 70 insertions, 97 deletions
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index e242dd316d36..d23d0577754b 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -46,8 +46,6 @@ struct max1586_data {
46 46
47 unsigned int v3_curr_sel; 47 unsigned int v3_curr_sel;
48 unsigned int v6_curr_sel; 48 unsigned int v6_curr_sel;
49
50 struct regulator_dev *rdev[0];
51}; 49};
52 50
53/* 51/*
@@ -162,14 +160,12 @@ static struct regulator_desc max1586_reg[] = {
162static int max1586_pmic_probe(struct i2c_client *client, 160static int max1586_pmic_probe(struct i2c_client *client,
163 const struct i2c_device_id *i2c_id) 161 const struct i2c_device_id *i2c_id)
164{ 162{
165 struct regulator_dev **rdev;
166 struct max1586_platform_data *pdata = dev_get_platdata(&client->dev); 163 struct max1586_platform_data *pdata = dev_get_platdata(&client->dev);
167 struct regulator_config config = { }; 164 struct regulator_config config = { };
168 struct max1586_data *max1586; 165 struct max1586_data *max1586;
169 int i, id; 166 int i, id;
170 167
171 max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data) + 168 max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data),
172 sizeof(struct regulator_dev *) * (MAX1586_V6 + 1),
173 GFP_KERNEL); 169 GFP_KERNEL);
174 if (!max1586) 170 if (!max1586)
175 return -ENOMEM; 171 return -ENOMEM;
@@ -186,8 +182,9 @@ static int max1586_pmic_probe(struct i2c_client *client,
186 max1586->v3_curr_sel = 24; /* 1.3V */ 182 max1586->v3_curr_sel = 24; /* 1.3V */
187 max1586->v6_curr_sel = 0; 183 max1586->v6_curr_sel = 0;
188 184
189 rdev = max1586->rdev;
190 for (i = 0; i < pdata->num_subdevs && i <= MAX1586_V6; i++) { 185 for (i = 0; i < pdata->num_subdevs && i <= MAX1586_V6; i++) {
186 struct regulator_dev *rdev;
187
191 id = pdata->subdevs[i].id; 188 id = pdata->subdevs[i].id;
192 if (!pdata->subdevs[i].platform_data) 189 if (!pdata->subdevs[i].platform_data)
193 continue; 190 continue;
@@ -207,12 +204,12 @@ static int max1586_pmic_probe(struct i2c_client *client,
207 config.init_data = pdata->subdevs[i].platform_data; 204 config.init_data = pdata->subdevs[i].platform_data;
208 config.driver_data = max1586; 205 config.driver_data = max1586;
209 206
210 rdev[i] = devm_regulator_register(&client->dev, 207 rdev = devm_regulator_register(&client->dev,
211 &max1586_reg[id], &config); 208 &max1586_reg[id], &config);
212 if (IS_ERR(rdev[i])) { 209 if (IS_ERR(rdev)) {
213 dev_err(&client->dev, "failed to register %s\n", 210 dev_err(&client->dev, "failed to register %s\n",
214 max1586_reg[id].name); 211 max1586_reg[id].name);
215 return PTR_ERR(rdev[i]); 212 return PTR_ERR(rdev);
216 } 213 }
217 } 214 }
218 215
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index ae001ccf26f4..ef1af2debbd2 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -65,7 +65,6 @@ enum max77686_ramp_rate {
65}; 65};
66 66
67struct max77686_data { 67struct max77686_data {
68 struct regulator_dev *rdev[MAX77686_REGULATORS];
69 unsigned int opmode[MAX77686_REGULATORS]; 68 unsigned int opmode[MAX77686_REGULATORS];
70}; 69};
71 70
@@ -400,7 +399,7 @@ static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
400 unsigned int i; 399 unsigned int i;
401 400
402 pmic_np = iodev->dev->of_node; 401 pmic_np = iodev->dev->of_node;
403 regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators"); 402 regulators_np = of_get_child_by_name(pmic_np, "voltage-regulators");
404 if (!regulators_np) { 403 if (!regulators_np) {
405 dev_err(&pdev->dev, "could not find regulators sub-node\n"); 404 dev_err(&pdev->dev, "could not find regulators sub-node\n");
406 return -EINVAL; 405 return -EINVAL;
@@ -410,8 +409,7 @@ static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
410 rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) * 409 rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
411 pdata->num_regulators, GFP_KERNEL); 410 pdata->num_regulators, GFP_KERNEL);
412 if (!rdata) { 411 if (!rdata) {
413 dev_err(&pdev->dev, 412 of_node_put(regulators_np);
414 "could not allocate memory for regulator data\n");
415 return -ENOMEM; 413 return -ENOMEM;
416 } 414 }
417 415
@@ -425,6 +423,7 @@ static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
425 } 423 }
426 424
427 pdata->regulators = rdata; 425 pdata->regulators = rdata;
426 of_node_put(regulators_np);
428 427
429 return 0; 428 return 0;
430} 429}
@@ -474,16 +473,18 @@ static int max77686_pmic_probe(struct platform_device *pdev)
474 platform_set_drvdata(pdev, max77686); 473 platform_set_drvdata(pdev, max77686);
475 474
476 for (i = 0; i < MAX77686_REGULATORS; i++) { 475 for (i = 0; i < MAX77686_REGULATORS; i++) {
476 struct regulator_dev *rdev;
477
477 config.init_data = pdata->regulators[i].initdata; 478 config.init_data = pdata->regulators[i].initdata;
478 config.of_node = pdata->regulators[i].of_node; 479 config.of_node = pdata->regulators[i].of_node;
479 480
480 max77686->opmode[i] = regulators[i].enable_mask; 481 max77686->opmode[i] = regulators[i].enable_mask;
481 max77686->rdev[i] = devm_regulator_register(&pdev->dev, 482 rdev = devm_regulator_register(&pdev->dev,
482 &regulators[i], &config); 483 &regulators[i], &config);
483 if (IS_ERR(max77686->rdev[i])) { 484 if (IS_ERR(rdev)) {
484 dev_err(&pdev->dev, 485 dev_err(&pdev->dev,
485 "regulator init failed for %d\n", i); 486 "regulator init failed for %d\n", i);
486 return PTR_ERR(max77686->rdev[i]); 487 return PTR_ERR(rdev);
487 } 488 }
488 } 489 }
489 490
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c
index 5fb899f461d0..653a58b49cdf 100644
--- a/drivers/regulator/max77693.c
+++ b/drivers/regulator/max77693.c
@@ -34,13 +34,6 @@
34 34
35#define CHGIN_ILIM_STEP_20mA 20000 35#define CHGIN_ILIM_STEP_20mA 20000
36 36
37struct max77693_pmic_dev {
38 struct device *dev;
39 struct max77693_dev *iodev;
40 int num_regulators;
41 struct regulator_dev **rdev;
42};
43
44/* CHARGER regulator ops */ 37/* CHARGER regulator ops */
45/* CHARGER regulator uses two bits for enabling */ 38/* CHARGER regulator uses two bits for enabling */
46static int max77693_chg_is_enabled(struct regulator_dev *rdev) 39static int max77693_chg_is_enabled(struct regulator_dev *rdev)
@@ -170,19 +163,22 @@ static int max77693_pmic_dt_parse_rdata(struct device *dev,
170 struct max77693_regulator_data *tmp; 163 struct max77693_regulator_data *tmp;
171 int i, matched = 0; 164 int i, matched = 0;
172 165
173 np = of_find_node_by_name(dev->parent->of_node, "regulators"); 166 np = of_get_child_by_name(dev->parent->of_node, "regulators");
174 if (!np) 167 if (!np)
175 return -EINVAL; 168 return -EINVAL;
176 169
177 rmatch = devm_kzalloc(dev, 170 rmatch = devm_kzalloc(dev,
178 sizeof(*rmatch) * ARRAY_SIZE(regulators), GFP_KERNEL); 171 sizeof(*rmatch) * ARRAY_SIZE(regulators), GFP_KERNEL);
179 if (!rmatch) 172 if (!rmatch) {
173 of_node_put(np);
180 return -ENOMEM; 174 return -ENOMEM;
175 }
181 176
182 for (i = 0; i < ARRAY_SIZE(regulators); i++) 177 for (i = 0; i < ARRAY_SIZE(regulators); i++)
183 rmatch[i].name = regulators[i].name; 178 rmatch[i].name = regulators[i].name;
184 179
185 matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(regulators)); 180 matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(regulators));
181 of_node_put(np);
186 if (matched <= 0) 182 if (matched <= 0)
187 return matched; 183 return matched;
188 *rdata = devm_kzalloc(dev, sizeof(**rdata) * matched, GFP_KERNEL); 184 *rdata = devm_kzalloc(dev, sizeof(**rdata) * matched, GFP_KERNEL);
@@ -229,7 +225,6 @@ static int max77693_pmic_init_rdata(struct device *dev,
229static int max77693_pmic_probe(struct platform_device *pdev) 225static int max77693_pmic_probe(struct platform_device *pdev)
230{ 226{
231 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); 227 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
232 struct max77693_pmic_dev *max77693_pmic;
233 struct max77693_regulator_data *rdata = NULL; 228 struct max77693_regulator_data *rdata = NULL;
234 int num_rdata, i; 229 int num_rdata, i;
235 struct regulator_config config; 230 struct regulator_config config;
@@ -240,39 +235,22 @@ static int max77693_pmic_probe(struct platform_device *pdev)
240 return -ENODEV; 235 return -ENODEV;
241 } 236 }
242 237
243 max77693_pmic = devm_kzalloc(&pdev->dev,
244 sizeof(struct max77693_pmic_dev),
245 GFP_KERNEL);
246 if (!max77693_pmic)
247 return -ENOMEM;
248
249 max77693_pmic->rdev = devm_kzalloc(&pdev->dev,
250 sizeof(struct regulator_dev *) * num_rdata,
251 GFP_KERNEL);
252 if (!max77693_pmic->rdev)
253 return -ENOMEM;
254
255 max77693_pmic->dev = &pdev->dev;
256 max77693_pmic->iodev = iodev;
257 max77693_pmic->num_regulators = num_rdata;
258
259 config.dev = &pdev->dev; 238 config.dev = &pdev->dev;
260 config.regmap = iodev->regmap; 239 config.regmap = iodev->regmap;
261 config.driver_data = max77693_pmic;
262 platform_set_drvdata(pdev, max77693_pmic);
263 240
264 for (i = 0; i < max77693_pmic->num_regulators; i++) { 241 for (i = 0; i < num_rdata; i++) {
265 int id = rdata[i].id; 242 int id = rdata[i].id;
243 struct regulator_dev *rdev;
266 244
267 config.init_data = rdata[i].initdata; 245 config.init_data = rdata[i].initdata;
268 config.of_node = rdata[i].of_node; 246 config.of_node = rdata[i].of_node;
269 247
270 max77693_pmic->rdev[i] = devm_regulator_register(&pdev->dev, 248 rdev = devm_regulator_register(&pdev->dev,
271 &regulators[id], &config); 249 &regulators[id], &config);
272 if (IS_ERR(max77693_pmic->rdev[i])) { 250 if (IS_ERR(rdev)) {
273 dev_err(max77693_pmic->dev, 251 dev_err(&pdev->dev,
274 "Failed to initialize regulator-%d\n", id); 252 "Failed to initialize regulator-%d\n", id);
275 return PTR_ERR(max77693_pmic->rdev[i]); 253 return PTR_ERR(rdev);
276 } 254 }
277 } 255 }
278 256
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
index 7f049c92ee52..3172da847d24 100644
--- a/drivers/regulator/max8649.c
+++ b/drivers/regulator/max8649.c
@@ -49,7 +49,6 @@
49#define MAX8649_RAMP_DOWN (1 << 1) 49#define MAX8649_RAMP_DOWN (1 << 1)
50 50
51struct max8649_regulator_info { 51struct max8649_regulator_info {
52 struct regulator_dev *regulator;
53 struct device *dev; 52 struct device *dev;
54 struct regmap *regmap; 53 struct regmap *regmap;
55 54
@@ -154,6 +153,7 @@ static int max8649_regulator_probe(struct i2c_client *client,
154{ 153{
155 struct max8649_platform_data *pdata = dev_get_platdata(&client->dev); 154 struct max8649_platform_data *pdata = dev_get_platdata(&client->dev);
156 struct max8649_regulator_info *info = NULL; 155 struct max8649_regulator_info *info = NULL;
156 struct regulator_dev *regulator;
157 struct regulator_config config = { }; 157 struct regulator_config config = { };
158 unsigned int val; 158 unsigned int val;
159 unsigned char data; 159 unsigned char data;
@@ -234,12 +234,12 @@ 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 = devm_regulator_register(&client->dev, &dcdc_desc, 237 regulator = devm_regulator_register(&client->dev, &dcdc_desc,
238 &config); 238 &config);
239 if (IS_ERR(info->regulator)) { 239 if (IS_ERR(regulator)) {
240 dev_err(info->dev, "failed to register regulator %s\n", 240 dev_err(info->dev, "failed to register regulator %s\n",
241 dcdc_desc.name); 241 dcdc_desc.name);
242 return PTR_ERR(info->regulator); 242 return PTR_ERR(regulator);
243 } 243 }
244 244
245 return 0; 245 return 0;
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index 8d94d3d7f97f..2fc411188794 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -81,16 +81,17 @@ enum {
81struct max8660 { 81struct max8660 {
82 struct i2c_client *client; 82 struct i2c_client *client;
83 u8 shadow_regs[MAX8660_N_REGS]; /* as chip is write only */ 83 u8 shadow_regs[MAX8660_N_REGS]; /* as chip is write only */
84 struct regulator_dev *rdev[];
85}; 84};
86 85
87static int max8660_write(struct max8660 *max8660, u8 reg, u8 mask, u8 val) 86static int max8660_write(struct max8660 *max8660, u8 reg, u8 mask, u8 val)
88{ 87{
89 static const u8 max8660_addresses[MAX8660_N_REGS] = 88 static const u8 max8660_addresses[MAX8660_N_REGS] = {
90 { 0x10, 0x12, 0x20, 0x23, 0x24, 0x29, 0x2a, 0x32, 0x33, 0x39, 0x80 }; 89 0x10, 0x12, 0x20, 0x23, 0x24, 0x29, 0x2a, 0x32, 0x33, 0x39, 0x80
90 };
91 91
92 int ret; 92 int ret;
93 u8 reg_val = (max8660->shadow_regs[reg] & mask) | val; 93 u8 reg_val = (max8660->shadow_regs[reg] & mask) | val;
94
94 dev_vdbg(&max8660->client->dev, "Writing reg %02x with %02x\n", 95 dev_vdbg(&max8660->client->dev, "Writing reg %02x with %02x\n",
95 max8660_addresses[reg], reg_val); 96 max8660_addresses[reg], reg_val);
96 97
@@ -112,6 +113,7 @@ static int max8660_dcdc_is_enabled(struct regulator_dev *rdev)
112 struct max8660 *max8660 = rdev_get_drvdata(rdev); 113 struct max8660 *max8660 = rdev_get_drvdata(rdev);
113 u8 val = max8660->shadow_regs[MAX8660_OVER1]; 114 u8 val = max8660->shadow_regs[MAX8660_OVER1];
114 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4; 115 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4;
116
115 return !!(val & mask); 117 return !!(val & mask);
116} 118}
117 119
@@ -119,6 +121,7 @@ static int max8660_dcdc_enable(struct regulator_dev *rdev)
119{ 121{
120 struct max8660 *max8660 = rdev_get_drvdata(rdev); 122 struct max8660 *max8660 = rdev_get_drvdata(rdev);
121 u8 bit = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4; 123 u8 bit = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4;
124
122 return max8660_write(max8660, MAX8660_OVER1, 0xff, bit); 125 return max8660_write(max8660, MAX8660_OVER1, 0xff, bit);
123} 126}
124 127
@@ -126,15 +129,16 @@ static int max8660_dcdc_disable(struct regulator_dev *rdev)
126{ 129{
127 struct max8660 *max8660 = rdev_get_drvdata(rdev); 130 struct max8660 *max8660 = rdev_get_drvdata(rdev);
128 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? ~1 : ~4; 131 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? ~1 : ~4;
132
129 return max8660_write(max8660, MAX8660_OVER1, mask, 0); 133 return max8660_write(max8660, MAX8660_OVER1, mask, 0);
130} 134}
131 135
132static int max8660_dcdc_get_voltage_sel(struct regulator_dev *rdev) 136static int max8660_dcdc_get_voltage_sel(struct regulator_dev *rdev)
133{ 137{
134 struct max8660 *max8660 = rdev_get_drvdata(rdev); 138 struct max8660 *max8660 = rdev_get_drvdata(rdev);
135
136 u8 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; 139 u8 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2;
137 u8 selector = max8660->shadow_regs[reg]; 140 u8 selector = max8660->shadow_regs[reg];
141
138 return selector; 142 return selector;
139} 143}
140 144
@@ -207,6 +211,7 @@ static int max8660_ldo67_is_enabled(struct regulator_dev *rdev)
207 struct max8660 *max8660 = rdev_get_drvdata(rdev); 211 struct max8660 *max8660 = rdev_get_drvdata(rdev);
208 u8 val = max8660->shadow_regs[MAX8660_OVER2]; 212 u8 val = max8660->shadow_regs[MAX8660_OVER2];
209 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4; 213 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4;
214
210 return !!(val & mask); 215 return !!(val & mask);
211} 216}
212 217
@@ -214,6 +219,7 @@ static int max8660_ldo67_enable(struct regulator_dev *rdev)
214{ 219{
215 struct max8660 *max8660 = rdev_get_drvdata(rdev); 220 struct max8660 *max8660 = rdev_get_drvdata(rdev);
216 u8 bit = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4; 221 u8 bit = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4;
222
217 return max8660_write(max8660, MAX8660_OVER2, 0xff, bit); 223 return max8660_write(max8660, MAX8660_OVER2, 0xff, bit);
218} 224}
219 225
@@ -221,15 +227,16 @@ static int max8660_ldo67_disable(struct regulator_dev *rdev)
221{ 227{
222 struct max8660 *max8660 = rdev_get_drvdata(rdev); 228 struct max8660 *max8660 = rdev_get_drvdata(rdev);
223 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? ~2 : ~4; 229 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? ~2 : ~4;
230
224 return max8660_write(max8660, MAX8660_OVER2, mask, 0); 231 return max8660_write(max8660, MAX8660_OVER2, mask, 0);
225} 232}
226 233
227static int max8660_ldo67_get_voltage_sel(struct regulator_dev *rdev) 234static int max8660_ldo67_get_voltage_sel(struct regulator_dev *rdev)
228{ 235{
229 struct max8660 *max8660 = rdev_get_drvdata(rdev); 236 struct max8660 *max8660 = rdev_get_drvdata(rdev);
230
231 u8 shift = (rdev_get_id(rdev) == MAX8660_V6) ? 0 : 4; 237 u8 shift = (rdev_get_id(rdev) == MAX8660_V6) ? 0 : 4;
232 u8 selector = (max8660->shadow_regs[MAX8660_L12VCR] >> shift) & 0xf; 238 u8 selector = (max8660->shadow_regs[MAX8660_L12VCR] >> shift) & 0xf;
239
233 return selector; 240 return selector;
234} 241}
235 242
@@ -330,7 +337,7 @@ static int max8660_pdata_from_dt(struct device *dev,
330 struct max8660_subdev_data *sub; 337 struct max8660_subdev_data *sub;
331 struct of_regulator_match rmatch[ARRAY_SIZE(max8660_reg)]; 338 struct of_regulator_match rmatch[ARRAY_SIZE(max8660_reg)];
332 339
333 np = of_find_node_by_name(dev->of_node, "regulators"); 340 np = of_get_child_by_name(dev->of_node, "regulators");
334 if (!np) { 341 if (!np) {
335 dev_err(dev, "missing 'regulators' subnode in DT\n"); 342 dev_err(dev, "missing 'regulators' subnode in DT\n");
336 return -EINVAL; 343 return -EINVAL;
@@ -340,6 +347,7 @@ static int max8660_pdata_from_dt(struct device *dev,
340 rmatch[i].name = max8660_reg[i].name; 347 rmatch[i].name = max8660_reg[i].name;
341 348
342 matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(rmatch)); 349 matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(rmatch));
350 of_node_put(np);
343 if (matched <= 0) 351 if (matched <= 0)
344 return matched; 352 return matched;
345 353
@@ -373,7 +381,6 @@ static inline int max8660_pdata_from_dt(struct device *dev,
373static int max8660_probe(struct i2c_client *client, 381static int max8660_probe(struct i2c_client *client,
374 const struct i2c_device_id *i2c_id) 382 const struct i2c_device_id *i2c_id)
375{ 383{
376 struct regulator_dev **rdev;
377 struct device *dev = &client->dev; 384 struct device *dev = &client->dev;
378 struct max8660_platform_data *pdata = dev_get_platdata(dev); 385 struct max8660_platform_data *pdata = dev_get_platdata(dev);
379 struct regulator_config config = { }; 386 struct regulator_config config = { };
@@ -406,14 +413,11 @@ static int max8660_probe(struct i2c_client *client,
406 return -EINVAL; 413 return -EINVAL;
407 } 414 }
408 415
409 max8660 = devm_kzalloc(dev, sizeof(struct max8660) + 416 max8660 = devm_kzalloc(dev, sizeof(struct max8660), GFP_KERNEL);
410 sizeof(struct regulator_dev *) * MAX8660_V_END,
411 GFP_KERNEL);
412 if (!max8660) 417 if (!max8660)
413 return -ENOMEM; 418 return -ENOMEM;
414 419
415 max8660->client = client; 420 max8660->client = client;
416 rdev = max8660->rdev;
417 421
418 if (pdata->en34_is_high) { 422 if (pdata->en34_is_high) {
419 /* Simulate always on */ 423 /* Simulate always on */
@@ -481,6 +485,7 @@ static int max8660_probe(struct i2c_client *client,
481 485
482 /* Finally register devices */ 486 /* Finally register devices */
483 for (i = 0; i < pdata->num_subdevs; i++) { 487 for (i = 0; i < pdata->num_subdevs; i++) {
488 struct regulator_dev *rdev;
484 489
485 id = pdata->subdevs[i].id; 490 id = pdata->subdevs[i].id;
486 491
@@ -489,13 +494,13 @@ static int max8660_probe(struct i2c_client *client,
489 config.of_node = of_node[i]; 494 config.of_node = of_node[i];
490 config.driver_data = max8660; 495 config.driver_data = max8660;
491 496
492 rdev[i] = devm_regulator_register(&client->dev, 497 rdev = devm_regulator_register(&client->dev,
493 &max8660_reg[id], &config); 498 &max8660_reg[id], &config);
494 if (IS_ERR(rdev[i])) { 499 if (IS_ERR(rdev)) {
495 ret = PTR_ERR(rdev[i]); 500 ret = PTR_ERR(rdev);
496 dev_err(&client->dev, "failed to register %s\n", 501 dev_err(&client->dev, "failed to register %s\n",
497 max8660_reg[id].name); 502 max8660_reg[id].name);
498 return PTR_ERR(rdev[i]); 503 return PTR_ERR(rdev);
499 } 504 }
500 } 505 }
501 506
diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c
index 0c5fe6c6ac26..9623e9e290bf 100644
--- a/drivers/regulator/max8907-regulator.c
+++ b/drivers/regulator/max8907-regulator.c
@@ -34,7 +34,6 @@
34 34
35struct max8907_regulator { 35struct max8907_regulator {
36 struct regulator_desc desc[MAX8907_NUM_REGULATORS]; 36 struct regulator_desc desc[MAX8907_NUM_REGULATORS];
37 struct regulator_dev *rdev[MAX8907_NUM_REGULATORS];
38}; 37};
39 38
40#define REG_MBATT() \ 39#define REG_MBATT() \
@@ -231,7 +230,7 @@ static int max8907_regulator_parse_dt(struct platform_device *pdev)
231 if (!np) 230 if (!np)
232 return 0; 231 return 0;
233 232
234 regulators = of_find_node_by_name(np, "regulators"); 233 regulators = of_get_child_by_name(np, "regulators");
235 if (!regulators) { 234 if (!regulators) {
236 dev_err(&pdev->dev, "regulators node not found\n"); 235 dev_err(&pdev->dev, "regulators node not found\n");
237 return -EINVAL; 236 return -EINVAL;
@@ -292,10 +291,9 @@ static int max8907_regulator_probe(struct platform_device *pdev)
292 return ret; 291 return ret;
293 292
294 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); 293 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
295 if (!pmic) { 294 if (!pmic)
296 dev_err(&pdev->dev, "Failed to alloc pmic\n");
297 return -ENOMEM; 295 return -ENOMEM;
298 } 296
299 platform_set_drvdata(pdev, pmic); 297 platform_set_drvdata(pdev, pmic);
300 298
301 memcpy(pmic->desc, max8907_regulators, sizeof(pmic->desc)); 299 memcpy(pmic->desc, max8907_regulators, sizeof(pmic->desc));
@@ -311,6 +309,8 @@ static int max8907_regulator_probe(struct platform_device *pdev)
311 } 309 }
312 310
313 for (i = 0; i < MAX8907_NUM_REGULATORS; i++) { 311 for (i = 0; i < MAX8907_NUM_REGULATORS; i++) {
312 struct regulator_dev *rdev;
313
314 config.dev = pdev->dev.parent; 314 config.dev = pdev->dev.parent;
315 if (pdata) 315 if (pdata)
316 idata = pdata->init_data[i]; 316 idata = pdata->init_data[i];
@@ -350,13 +350,13 @@ 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] = devm_regulator_register(&pdev->dev, 353 rdev = devm_regulator_register(&pdev->dev,
354 &pmic->desc[i], &config); 354 &pmic->desc[i], &config);
355 if (IS_ERR(pmic->rdev[i])) { 355 if (IS_ERR(rdev)) {
356 dev_err(&pdev->dev, 356 dev_err(&pdev->dev,
357 "failed to register %s regulator\n", 357 "failed to register %s regulator\n",
358 pmic->desc[i].name); 358 pmic->desc[i].name);
359 return PTR_ERR(pmic->rdev[i]); 359 return PTR_ERR(rdev);
360 } 360 }
361 } 361 }
362 362
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index 759510789e71..dad2bcd14e96 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -36,9 +36,7 @@
36 36
37struct max8925_regulator_info { 37struct max8925_regulator_info {
38 struct regulator_desc desc; 38 struct regulator_desc desc;
39 struct regulator_dev *regulator;
40 struct i2c_client *i2c; 39 struct i2c_client *i2c;
41 struct max8925_chip *chip;
42 40
43 int vol_reg; 41 int vol_reg;
44 int enable_reg; 42 int enable_reg;
@@ -251,10 +249,11 @@ static int max8925_regulator_dt_init(struct platform_device *pdev,
251{ 249{
252 struct device_node *nproot, *np; 250 struct device_node *nproot, *np;
253 int rcount; 251 int rcount;
252
254 nproot = of_node_get(pdev->dev.parent->of_node); 253 nproot = of_node_get(pdev->dev.parent->of_node);
255 if (!nproot) 254 if (!nproot)
256 return -ENODEV; 255 return -ENODEV;
257 np = of_find_node_by_name(nproot, "regulators"); 256 np = of_get_child_by_name(nproot, "regulators");
258 if (!np) { 257 if (!np) {
259 dev_err(&pdev->dev, "failed to find regulators node\n"); 258 dev_err(&pdev->dev, "failed to find regulators node\n");
260 return -ENODEV; 259 return -ENODEV;
@@ -264,7 +263,7 @@ static int max8925_regulator_dt_init(struct platform_device *pdev,
264 &max8925_regulator_matches[ridx], 1); 263 &max8925_regulator_matches[ridx], 1);
265 of_node_put(np); 264 of_node_put(np);
266 if (rcount < 0) 265 if (rcount < 0)
267 return -ENODEV; 266 return rcount;
268 config->init_data = max8925_regulator_matches[ridx].init_data; 267 config->init_data = max8925_regulator_matches[ridx].init_data;
269 config->of_node = max8925_regulator_matches[ridx].of_node; 268 config->of_node = max8925_regulator_matches[ridx].of_node;
270 269
@@ -303,7 +302,6 @@ static int max8925_regulator_probe(struct platform_device *pdev)
303 return -EINVAL; 302 return -EINVAL;
304 } 303 }
305 ri->i2c = chip->i2c; 304 ri->i2c = chip->i2c;
306 ri->chip = chip;
307 305
308 config.dev = &pdev->dev; 306 config.dev = &pdev->dev;
309 config.driver_data = ri; 307 config.driver_data = ri;
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index 788e5ae2af1b..d920f5a32ec8 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -48,9 +48,7 @@ enum {
48 48
49struct max8952_data { 49struct max8952_data {
50 struct i2c_client *client; 50 struct i2c_client *client;
51 struct device *dev;
52 struct max8952_platform_data *pdata; 51 struct max8952_platform_data *pdata;
53 struct regulator_dev *rdev;
54 52
55 bool vid0; 53 bool vid0;
56 bool vid1; 54 bool vid1;
@@ -59,6 +57,7 @@ struct max8952_data {
59static int max8952_read_reg(struct max8952_data *max8952, u8 reg) 57static int max8952_read_reg(struct max8952_data *max8952, u8 reg)
60{ 58{
61 int ret = i2c_smbus_read_byte_data(max8952->client, reg); 59 int ret = i2c_smbus_read_byte_data(max8952->client, reg);
60
62 if (ret > 0) 61 if (ret > 0)
63 ret &= 0xff; 62 ret &= 0xff;
64 63
@@ -144,10 +143,8 @@ static struct max8952_platform_data *max8952_parse_dt(struct device *dev)
144 int i; 143 int i;
145 144
146 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); 145 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
147 if (!pd) { 146 if (!pd)
148 dev_err(dev, "Failed to allocate platform data\n");
149 return NULL; 147 return NULL;
150 }
151 148
152 pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0); 149 pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0);
153 pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1); 150 pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1);
@@ -199,6 +196,7 @@ static int max8952_pmic_probe(struct i2c_client *client,
199 struct max8952_platform_data *pdata = dev_get_platdata(&client->dev); 196 struct max8952_platform_data *pdata = dev_get_platdata(&client->dev);
200 struct regulator_config config = { }; 197 struct regulator_config config = { };
201 struct max8952_data *max8952; 198 struct max8952_data *max8952;
199 struct regulator_dev *rdev;
202 200
203 int ret = 0, err = 0; 201 int ret = 0, err = 0;
204 202
@@ -219,10 +217,9 @@ static int max8952_pmic_probe(struct i2c_client *client,
219 return -ENOMEM; 217 return -ENOMEM;
220 218
221 max8952->client = client; 219 max8952->client = client;
222 max8952->dev = &client->dev;
223 max8952->pdata = pdata; 220 max8952->pdata = pdata;
224 221
225 config.dev = max8952->dev; 222 config.dev = &client->dev;
226 config.init_data = pdata->reg_data; 223 config.init_data = pdata->reg_data;
227 config.driver_data = max8952; 224 config.driver_data = max8952;
228 config.of_node = client->dev.of_node; 225 config.of_node = client->dev.of_node;
@@ -231,11 +228,11 @@ static int max8952_pmic_probe(struct i2c_client *client,
231 if (pdata->reg_data->constraints.boot_on) 228 if (pdata->reg_data->constraints.boot_on)
232 config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; 229 config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
233 230
234 max8952->rdev = regulator_register(&regulator, &config); 231 rdev = devm_regulator_register(&client->dev, &regulator, &config);
235 232
236 if (IS_ERR(max8952->rdev)) { 233 if (IS_ERR(rdev)) {
237 ret = PTR_ERR(max8952->rdev); 234 ret = PTR_ERR(rdev);
238 dev_err(max8952->dev, "regulator init failed (%d)\n", ret); 235 dev_err(&client->dev, "regulator init failed (%d)\n", ret);
239 return ret; 236 return ret;
240 } 237 }
241 238
@@ -263,7 +260,7 @@ static int max8952_pmic_probe(struct i2c_client *client,
263 err = 3; 260 err = 3;
264 261
265 if (err) { 262 if (err) {
266 dev_warn(max8952->dev, "VID0/1 gpio invalid: " 263 dev_warn(&client->dev, "VID0/1 gpio invalid: "
267 "DVS not available.\n"); 264 "DVS not available.\n");
268 max8952->vid0 = 0; 265 max8952->vid0 = 0;
269 max8952->vid1 = 0; 266 max8952->vid1 = 0;
@@ -274,7 +271,7 @@ static int max8952_pmic_probe(struct i2c_client *client,
274 /* Disable Pulldown of EN only */ 271 /* Disable Pulldown of EN only */
275 max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60); 272 max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60);
276 273
277 dev_err(max8952->dev, "DVS modes disabled because VID0 and VID1" 274 dev_err(&client->dev, "DVS modes disabled because VID0 and VID1"
278 " do not have proper controls.\n"); 275 " do not have proper controls.\n");
279 } else { 276 } else {
280 /* 277 /*
@@ -321,9 +318,6 @@ static int max8952_pmic_remove(struct i2c_client *client)
321{ 318{
322 struct max8952_data *max8952 = i2c_get_clientdata(client); 319 struct max8952_data *max8952 = i2c_get_clientdata(client);
323 struct max8952_platform_data *pdata = max8952->pdata; 320 struct max8952_platform_data *pdata = max8952->pdata;
324 struct regulator_dev *rdev = max8952->rdev;
325
326 regulator_unregister(rdev);
327 321
328 gpio_free(pdata->gpio_vid0); 322 gpio_free(pdata->gpio_vid0);
329 gpio_free(pdata->gpio_vid1); 323 gpio_free(pdata->gpio_vid1);