aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/max77693.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/max77693.c')
-rw-r--r--drivers/regulator/max77693.c44
1 files changed, 11 insertions, 33 deletions
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