Skip to content

Commit 2730fd8

Browse files
committed
Merge remote-tracking branch 'regulator/topic/tps65090' into regulator-next
2 parents da3522f + 09a228e commit 2730fd8

1 file changed

Lines changed: 101 additions & 5 deletions

File tree

‎drivers/regulator/tps65090-regulator.c‎

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
#include <linux/module.h>
2020
#include <linux/init.h>
2121
#include <linux/gpio.h>
22+
#include <linux/of_gpio.h>
2223
#include <linux/slab.h>
2324
#include <linux/err.h>
2425
#include <linux/platform_device.h>
2526
#include <linux/regulator/driver.h>
2627
#include <linux/regulator/machine.h>
28+
#include <linux/regulator/of_regulator.h>
2729
#include <linux/mfd/tps65090.h>
2830

2931
struct tps65090_regulator {
@@ -67,8 +69,8 @@ static struct regulator_desc tps65090_regulator_desc[] = {
6769
tps65090_REG_DESC(FET5, "infet5", 0x13, tps65090_reg_contol_ops),
6870
tps65090_REG_DESC(FET6, "infet6", 0x14, tps65090_reg_contol_ops),
6971
tps65090_REG_DESC(FET7, "infet7", 0x15, tps65090_reg_contol_ops),
70-
tps65090_REG_DESC(LDO1, "vsys_l1", 0, tps65090_ldo_ops),
71-
tps65090_REG_DESC(LDO2, "vsys_l2", 0, tps65090_ldo_ops),
72+
tps65090_REG_DESC(LDO1, "vsys-l1", 0, tps65090_ldo_ops),
73+
tps65090_REG_DESC(LDO2, "vsys-l2", 0, tps65090_ldo_ops),
7274
};
7375

7476
static inline bool is_dcdc(int id)
@@ -138,6 +140,92 @@ static void tps65090_configure_regulator_config(
138140
}
139141
}
140142

143+
#ifdef CONFIG_OF
144+
static struct of_regulator_match tps65090_matches[] = {
145+
{ .name = "dcdc1", },
146+
{ .name = "dcdc2", },
147+
{ .name = "dcdc3", },
148+
{ .name = "fet1", },
149+
{ .name = "fet2", },
150+
{ .name = "fet3", },
151+
{ .name = "fet4", },
152+
{ .name = "fet5", },
153+
{ .name = "fet6", },
154+
{ .name = "fet7", },
155+
{ .name = "ldo1", },
156+
{ .name = "ldo2", },
157+
};
158+
159+
static struct tps65090_platform_data *tps65090_parse_dt_reg_data(
160+
struct platform_device *pdev,
161+
struct of_regulator_match **tps65090_reg_matches)
162+
{
163+
struct tps65090_platform_data *tps65090_pdata;
164+
struct device_node *np = pdev->dev.parent->of_node;
165+
struct device_node *regulators;
166+
int idx = 0, ret;
167+
struct tps65090_regulator_plat_data *reg_pdata;
168+
169+
tps65090_pdata = devm_kzalloc(&pdev->dev, sizeof(*tps65090_pdata),
170+
GFP_KERNEL);
171+
if (!tps65090_pdata) {
172+
dev_err(&pdev->dev, "Memory alloc for tps65090_pdata failed\n");
173+
return ERR_PTR(-ENOMEM);
174+
}
175+
176+
reg_pdata = devm_kzalloc(&pdev->dev, TPS65090_REGULATOR_MAX *
177+
sizeof(*reg_pdata), GFP_KERNEL);
178+
if (!reg_pdata) {
179+
dev_err(&pdev->dev, "Memory alloc for reg_pdata failed\n");
180+
return ERR_PTR(-ENOMEM);
181+
}
182+
183+
regulators = of_find_node_by_name(np, "regulators");
184+
if (!regulators) {
185+
dev_err(&pdev->dev, "regulator node not found\n");
186+
return ERR_PTR(-ENODEV);
187+
}
188+
189+
ret = of_regulator_match(&pdev->dev, regulators, tps65090_matches,
190+
ARRAY_SIZE(tps65090_matches));
191+
if (ret < 0) {
192+
dev_err(&pdev->dev,
193+
"Error parsing regulator init data: %d\n", ret);
194+
return ERR_PTR(ret);
195+
}
196+
197+
*tps65090_reg_matches = tps65090_matches;
198+
for (idx = 0; idx < ARRAY_SIZE(tps65090_matches); idx++) {
199+
struct regulator_init_data *ri_data;
200+
struct tps65090_regulator_plat_data *rpdata;
201+
202+
rpdata = &reg_pdata[idx];
203+
ri_data = tps65090_matches[idx].init_data;
204+
if (!ri_data || !tps65090_matches[idx].of_node)
205+
continue;
206+
207+
rpdata->reg_init_data = ri_data;
208+
rpdata->enable_ext_control = of_property_read_bool(
209+
tps65090_matches[idx].of_node,
210+
"ti,enable-ext-control");
211+
if (rpdata->enable_ext_control)
212+
rpdata->gpio = of_get_named_gpio(np,
213+
"dcdc-ext-control-gpios", 0);
214+
215+
tps65090_pdata->reg_pdata[idx] = rpdata;
216+
}
217+
return tps65090_pdata;
218+
}
219+
#else
220+
static inline struct tps65090_platform_data *tps65090_parse_dt_reg_data(
221+
struct platform_device *pdev,
222+
struct of_regulator_match **tps65090_reg_matches)
223+
{
224+
*tps65090_reg_matches = NULL;
225+
return NULL;
226+
}
227+
#endif
228+
141229
static int tps65090_regulator_probe(struct platform_device *pdev)
142230
{
143231
struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
@@ -147,15 +235,19 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
147235
struct tps65090_regulator_plat_data *tps_pdata;
148236
struct tps65090_regulator *pmic;
149237
struct tps65090_platform_data *tps65090_pdata;
238+
struct of_regulator_match *tps65090_reg_matches = NULL;
150239
int num;
151240
int ret;
152241

153242
dev_dbg(&pdev->dev, "Probing regulator\n");
154243

155244
tps65090_pdata = dev_get_platdata(pdev->dev.parent);
156-
if (!tps65090_pdata) {
245+
if (!tps65090_pdata && tps65090_mfd->dev->of_node)
246+
tps65090_pdata = tps65090_parse_dt_reg_data(pdev,
247+
&tps65090_reg_matches);
248+
if (IS_ERR_OR_NULL(tps65090_pdata)) {
157249
dev_err(&pdev->dev, "Platform data missing\n");
158-
return -EINVAL;
250+
return tps65090_pdata ? PTR_ERR(tps65090_pdata) : -EINVAL;
159251
}
160252

161253
pmic = devm_kzalloc(&pdev->dev, TPS65090_REGULATOR_MAX * sizeof(*pmic),
@@ -192,13 +284,17 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
192284
}
193285
}
194286

195-
config.dev = &pdev->dev;
287+
config.dev = pdev->dev.parent;
196288
config.driver_data = ri;
197289
config.regmap = tps65090_mfd->rmap;
198290
if (tps_pdata)
199291
config.init_data = tps_pdata->reg_init_data;
200292
else
201293
config.init_data = NULL;
294+
if (tps65090_reg_matches)
295+
config.of_node = tps65090_reg_matches[num].of_node;
296+
else
297+
config.of_node = NULL;
202298

203299
rdev = regulator_register(ri->desc, &config);
204300
if (IS_ERR(rdev)) {

0 commit comments

Comments
 (0)