Skip to content

Commit 7fcd427

Browse files
charleskeepaxbroonie
authored andcommitted
mfd: Allow mapping regulator supplies to MFD device from children
Occasionally, it is useful to map supplies from a child device onto the MFD device. A typical usecase for this would be if the MFD device is represented as a single node in device tree. All supplies will be defined in device tree as existing on the MFD device. When a child depends on frameworks which might have no knowledge of MFD to lookup supplies on its behalf the supply will not be found. This patch adds a list of supplies that should be looked up on the parent rather than the child as part of the mfd_cell structure. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Acked-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent a06ccd9 commit 7fcd427

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎drivers/mfd/mfd-core.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/module.h>
2121
#include <linux/irqdomain.h>
2222
#include <linux/of.h>
23+
#include <linux/regulator/consumer.h>
2324

2425
static struct device_type mfd_dev_type = {
2526
.name = "mfd_device",
@@ -99,6 +100,13 @@ static int mfd_add_device(struct device *parent, int id,
99100
pdev->dev.dma_mask = parent->dma_mask;
100101
pdev->dev.dma_parms = parent->dma_parms;
101102

103+
ret = devm_regulator_bulk_register_supply_alias(
104+
&pdev->dev, cell->parent_supplies,
105+
parent, cell->parent_supplies,
106+
cell->num_parent_supplies);
107+
if (ret < 0)
108+
goto fail_res;
109+
102110
if (parent->of_node && cell->of_compatible) {
103111
for_each_child_of_node(parent->of_node, np) {
104112
if (of_device_is_compatible(np, cell->of_compatible)) {
@@ -112,12 +120,12 @@ static int mfd_add_device(struct device *parent, int id,
112120
ret = platform_device_add_data(pdev,
113121
cell->platform_data, cell->pdata_size);
114122
if (ret)
115-
goto fail_res;
123+
goto fail_alias;
116124
}
117125

118126
ret = mfd_platform_add_cell(pdev, cell);
119127
if (ret)
120-
goto fail_res;
128+
goto fail_alias;
121129

122130
for (r = 0; r < cell->num_resources; r++) {
123131
res[r].name = cell->resources[r].name;
@@ -152,17 +160,17 @@ static int mfd_add_device(struct device *parent, int id,
152160
if (!cell->ignore_resource_conflicts) {
153161
ret = acpi_check_resource_conflict(&res[r]);
154162
if (ret)
155-
goto fail_res;
163+
goto fail_alias;
156164
}
157165
}
158166

159167
ret = platform_device_add_resources(pdev, res, cell->num_resources);
160168
if (ret)
161-
goto fail_res;
169+
goto fail_alias;
162170

163171
ret = platform_device_add(pdev);
164172
if (ret)
165-
goto fail_res;
173+
goto fail_alias;
166174

167175
if (cell->pm_runtime_no_callbacks)
168176
pm_runtime_no_callbacks(&pdev->dev);
@@ -171,6 +179,10 @@ static int mfd_add_device(struct device *parent, int id,
171179

172180
return 0;
173181

182+
fail_alias:
183+
devm_regulator_bulk_unregister_supply_alias(&pdev->dev,
184+
cell->parent_supplies,
185+
cell->num_parent_supplies);
174186
fail_res:
175187
kfree(res);
176188
fail_device:

‎include/linux/mfd/core.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ struct mfd_cell {
5959
* pm_runtime_no_callbacks().
6060
*/
6161
bool pm_runtime_no_callbacks;
62+
63+
/* A list of regulator supplies that should be mapped to the MFD
64+
* device rather than the child device when requested
65+
*/
66+
const char **parent_supplies;
67+
int num_parent_supplies;
6268
};
6369

6470
/*

0 commit comments

Comments
 (0)