Skip to content

Commit 45b6f8e

Browse files
Qing Xubroonie
authored andcommitted
regulator: max8925: support dt for regulator
Signed-off-by: Qing Xu <qingx@marvell.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent 3d70f8c commit 45b6f8e

2 files changed

Lines changed: 98 additions & 3 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Max8925 Voltage regulators
2+
3+
max8925 regulator device register is still handled by mfd_add_devices, not by
4+
of_xxx, so, it is not necessary to add compatible name. Also, those reg
5+
offset and id info is stored in mfd_cell(see max8925-core.c), as a result
6+
there is not private properties in dts.
7+
8+
node's name should match with the definition in max8925_regulator_matches
9+
(see max8925-regulator.c)
10+
11+
12+
Optional properties:
13+
- Any optional property defined in bindings/regulator/regulator.txt
14+
15+
16+
Example:
17+
18+
19+
regulators {
20+
SDV1 {
21+
regulator-min-microvolt = <637500>;
22+
regulator-max-microvolt = <1425000>;
23+
regulator-boot-on;
24+
regulator-always-on;
25+
};
26+
27+
...
28+
...
29+
}

‎drivers/regulator/max8925-regulator.c‎

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/regulator/driver.h>
1818
#include <linux/regulator/machine.h>
1919
#include <linux/mfd/max8925.h>
20+
#include <linux/of.h>
21+
#include <linux/regulator/of_regulator.h>
2022

2123
#define SD1_DVM_VMIN 850000
2224
#define SD1_DVM_VMAX 1000000
@@ -187,6 +189,34 @@ static struct regulator_ops max8925_regulator_ldo_ops = {
187189
.enable_reg = MAX8925_LDOCTL##_id, \
188190
}
189191

192+
#ifdef CONFIG_OF
193+
static struct of_regulator_match max8925_regulator_matches[] = {
194+
{ .name = "SDV1",},
195+
{ .name = "SDV2",},
196+
{ .name = "SDV3",},
197+
{ .name = "LDO1",},
198+
{ .name = "LDO2",},
199+
{ .name = "LDO3",},
200+
{ .name = "LDO4",},
201+
{ .name = "LDO5",},
202+
{ .name = "LDO6",},
203+
{ .name = "LDO7",},
204+
{ .name = "LDO8",},
205+
{ .name = "LDO9",},
206+
{ .name = "LDO10",},
207+
{ .name = "LDO11",},
208+
{ .name = "LDO12",},
209+
{ .name = "LDO13",},
210+
{ .name = "LDO14",},
211+
{ .name = "LDO15",},
212+
{ .name = "LDO16",},
213+
{ .name = "LDO17",},
214+
{ .name = "LDO18",},
215+
{ .name = "LDO19",},
216+
{ .name = "LDO20",},
217+
};
218+
#endif
219+
190220
static struct max8925_regulator_info max8925_regulator_info[] = {
191221
MAX8925_SDV(1, 637.5, 1425, 12.5),
192222
MAX8925_SDV(2, 650, 2225, 25),
@@ -214,6 +244,36 @@ static struct max8925_regulator_info max8925_regulator_info[] = {
214244
MAX8925_LDO(20, 750, 3900, 50),
215245
};
216246

247+
#ifdef CONFIG_OF
248+
static int max8925_regulator_dt_init(struct platform_device *pdev,
249+
struct max8925_regulator_info *info,
250+
struct regulator_config *config,
251+
int ridx)
252+
{
253+
struct device_node *nproot, *np;
254+
int rcount;
255+
nproot = pdev->dev.parent->of_node;
256+
if (!nproot)
257+
return -ENODEV;
258+
np = of_find_node_by_name(nproot, "regulators");
259+
if (!np) {
260+
dev_err(&pdev->dev, "failed to find regulators node\n");
261+
return -ENODEV;
262+
}
263+
264+
rcount = of_regulator_match(&pdev->dev, np,
265+
&max8925_regulator_matches[ridx], 1);
266+
if (rcount < 0)
267+
return -ENODEV;
268+
config->init_data = max8925_regulator_matches[ridx].init_data;
269+
config->of_node = max8925_regulator_matches[ridx].of_node;
270+
271+
return 0;
272+
}
273+
#else
274+
#define max8925_regulator_dt_init(w, x, y, z) (-1)
275+
#endif
276+
217277
static int __devinit max8925_regulator_probe(struct platform_device *pdev)
218278
{
219279
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
@@ -222,7 +282,7 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev)
222282
struct max8925_regulator_info *ri;
223283
struct resource *res;
224284
struct regulator_dev *rdev;
225-
int i;
285+
int i, regulator_idx;
226286

227287
res = platform_get_resource(pdev, IORESOURCE_REG, 0);
228288
if (!res) {
@@ -231,9 +291,12 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev)
231291
}
232292
for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
233293
ri = &max8925_regulator_info[i];
234-
if (ri->vol_reg == res->start)
294+
if (ri->vol_reg == res->start) {
295+
regulator_idx = i;
235296
break;
297+
}
236298
}
299+
237300
if (i == ARRAY_SIZE(max8925_regulator_info)) {
238301
dev_err(&pdev->dev, "Failed to find regulator %llu\n",
239302
(unsigned long long)res->start);
@@ -243,9 +306,12 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev)
243306
ri->chip = chip;
244307

245308
config.dev = &pdev->dev;
246-
config.init_data = pdata;
247309
config.driver_data = ri;
248310

311+
if (max8925_regulator_dt_init(pdev, ri, &config, regulator_idx))
312+
if (pdata)
313+
config.init_data = pdata;
314+
249315
rdev = regulator_register(&ri->desc, &config);
250316
if (IS_ERR(rdev)) {
251317
dev_err(&pdev->dev, "failed to register regulator %s\n",

0 commit comments

Comments
 (0)