Skip to content

Commit 222d0f0

Browse files
krzkbroonie
authored andcommitted
regulator: max77693: Let core parse DT and drop board files support
Simplify the driver by removing board file support and letting regulator core to parse DT. The max77693 regulator driver is used only on Exynos based boards which are DT-only. Board files for Exynos are not supported. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c517d83 commit 222d0f0

1 file changed

Lines changed: 9 additions & 84 deletions

File tree

‎drivers/regulator/max77693.c‎

Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ static struct regulator_ops max77693_charger_ops = {
128128
#define regulator_desc_esafeout(_num) { \
129129
.name = "ESAFEOUT"#_num, \
130130
.id = MAX77693_ESAFEOUT##_num, \
131+
.of_match = of_match_ptr("ESAFEOUT"#_num), \
132+
.regulators_node = of_match_ptr("regulators"), \
131133
.n_voltages = 4, \
132134
.ops = &max77693_safeout_ops, \
133135
.type = REGULATOR_VOLTAGE, \
@@ -145,6 +147,8 @@ static const struct regulator_desc regulators[] = {
145147
{
146148
.name = "CHARGER",
147149
.id = MAX77693_CHARGER,
150+
.of_match = of_match_ptr("CHARGER"),
151+
.regulators_node = of_match_ptr("regulators"),
148152
.ops = &max77693_charger_ops,
149153
.type = REGULATOR_CURRENT,
150154
.owner = THIS_MODULE,
@@ -154,102 +158,23 @@ static const struct regulator_desc regulators[] = {
154158
},
155159
};
156160

157-
#ifdef CONFIG_OF
158-
static int max77693_pmic_dt_parse_rdata(struct device *dev,
159-
struct max77693_regulator_data **rdata)
160-
{
161-
struct device_node *np;
162-
struct of_regulator_match *rmatch;
163-
struct max77693_regulator_data *tmp;
164-
int i, matched = 0;
165-
166-
np = of_get_child_by_name(dev->parent->of_node, "regulators");
167-
if (!np)
168-
return -EINVAL;
169-
170-
rmatch = devm_kzalloc(dev,
171-
sizeof(*rmatch) * ARRAY_SIZE(regulators), GFP_KERNEL);
172-
if (!rmatch) {
173-
of_node_put(np);
174-
return -ENOMEM;
175-
}
176-
177-
for (i = 0; i < ARRAY_SIZE(regulators); i++)
178-
rmatch[i].name = regulators[i].name;
179-
180-
matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(regulators));
181-
of_node_put(np);
182-
if (matched <= 0)
183-
return matched;
184-
*rdata = devm_kzalloc(dev, sizeof(**rdata) * matched, GFP_KERNEL);
185-
if (!(*rdata))
186-
return -ENOMEM;
187-
188-
tmp = *rdata;
189-
190-
for (i = 0; i < matched; i++) {
191-
tmp->initdata = rmatch[i].init_data;
192-
tmp->of_node = rmatch[i].of_node;
193-
tmp->id = regulators[i].id;
194-
tmp++;
195-
}
196-
197-
return matched;
198-
}
199-
#else
200-
static int max77693_pmic_dt_parse_rdata(struct device *dev,
201-
struct max77693_regulator_data **rdata)
202-
{
203-
return 0;
204-
}
205-
#endif /* CONFIG_OF */
206-
207-
static int max77693_pmic_init_rdata(struct device *dev,
208-
struct max77693_regulator_data **rdata)
209-
{
210-
struct max77693_platform_data *pdata;
211-
int num_regulators = 0;
212-
213-
pdata = dev_get_platdata(dev->parent);
214-
if (pdata) {
215-
*rdata = pdata->regulators;
216-
num_regulators = pdata->num_regulators;
217-
}
218-
219-
if (!(*rdata) && dev->parent->of_node)
220-
num_regulators = max77693_pmic_dt_parse_rdata(dev, rdata);
221-
222-
return num_regulators;
223-
}
224-
225161
static int max77693_pmic_probe(struct platform_device *pdev)
226162
{
227163
struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
228-
struct max77693_regulator_data *rdata = NULL;
229-
int num_rdata, i;
164+
int i;
230165
struct regulator_config config = { };
231166

232-
num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata);
233-
if (!rdata || num_rdata <= 0) {
234-
dev_err(&pdev->dev, "No init data supplied.\n");
235-
return -ENODEV;
236-
}
237-
238-
config.dev = &pdev->dev;
167+
config.dev = iodev->dev;
239168
config.regmap = iodev->regmap;
240169

241-
for (i = 0; i < num_rdata; i++) {
242-
int id = rdata[i].id;
170+
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
243171
struct regulator_dev *rdev;
244172

245-
config.init_data = rdata[i].initdata;
246-
config.of_node = rdata[i].of_node;
247-
248173
rdev = devm_regulator_register(&pdev->dev,
249-
&regulators[id], &config);
174+
&regulators[i], &config);
250175
if (IS_ERR(rdev)) {
251176
dev_err(&pdev->dev,
252-
"Failed to initialize regulator-%d\n", id);
177+
"Failed to initialize regulator-%d\n", i);
253178
return PTR_ERR(rdev);
254179
}
255180
}

0 commit comments

Comments
 (0)