Skip to content

Commit bf3a28c

Browse files
Dmitry Baryshkovbroonie
authored andcommitted
regulator: fixed: support using power domain for enable/disable
Adds possibility to choose the compatible "fixed-regulator-domain" for regulators which use power domain for enabling/disabling corresponding regulator. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Link: https://lore.kernel.org/r/20201023131925.334864-3-dmitry.baryshkov@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 01c77ca commit bf3a28c

1 file changed

Lines changed: 57 additions & 6 deletions

File tree

‎drivers/regulator/fixed.c‎

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <linux/mutex.h>
1919
#include <linux/module.h>
2020
#include <linux/platform_device.h>
21+
#include <linux/pm_domain.h>
22+
#include <linux/pm_opp.h>
2123
#include <linux/regulator/driver.h>
2224
#include <linux/regulator/fixed.h>
2325
#include <linux/gpio/consumer.h>
@@ -34,11 +36,13 @@ struct fixed_voltage_data {
3436
struct regulator_dev *dev;
3537

3638
struct clk *enable_clock;
37-
unsigned int clk_enable_counter;
39+
unsigned int enable_counter;
40+
int performance_state;
3841
};
3942

4043
struct fixed_dev_type {
4144
bool has_enable_clock;
45+
bool has_performance_state;
4246
};
4347

4448
static int reg_clock_enable(struct regulator_dev *rdev)
@@ -50,7 +54,7 @@ static int reg_clock_enable(struct regulator_dev *rdev)
5054
if (ret)
5155
return ret;
5256

53-
priv->clk_enable_counter++;
57+
priv->enable_counter++;
5458

5559
return ret;
5660
}
@@ -60,16 +64,41 @@ static int reg_clock_disable(struct regulator_dev *rdev)
6064
struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
6165

6266
clk_disable_unprepare(priv->enable_clock);
63-
priv->clk_enable_counter--;
67+
priv->enable_counter--;
6468

6569
return 0;
6670
}
6771

68-
static int reg_clock_is_enabled(struct regulator_dev *rdev)
72+
static int reg_domain_enable(struct regulator_dev *rdev)
6973
{
7074
struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
75+
struct device *dev = rdev->dev.parent;
76+
int ret;
77+
78+
ret = dev_pm_genpd_set_performance_state(dev, priv->performance_state);
79+
if (ret)
80+
return ret;
7181

72-
return priv->clk_enable_counter > 0;
82+
priv->enable_counter++;
83+
84+
return ret;
85+
}
86+
87+
static int reg_domain_disable(struct regulator_dev *rdev)
88+
{
89+
struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
90+
struct device *dev = rdev->dev.parent;
91+
92+
priv->enable_counter--;
93+
94+
return dev_pm_genpd_set_performance_state(dev, 0);
95+
}
96+
97+
static int reg_is_enabled(struct regulator_dev *rdev)
98+
{
99+
struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
100+
101+
return priv->enable_counter > 0;
73102
}
74103

75104

@@ -129,7 +158,13 @@ static const struct regulator_ops fixed_voltage_ops = {
129158
static const struct regulator_ops fixed_voltage_clkenabled_ops = {
130159
.enable = reg_clock_enable,
131160
.disable = reg_clock_disable,
132-
.is_enabled = reg_clock_is_enabled,
161+
.is_enabled = reg_is_enabled,
162+
};
163+
164+
static const struct regulator_ops fixed_voltage_domain_ops = {
165+
.enable = reg_domain_enable,
166+
.disable = reg_domain_disable,
167+
.is_enabled = reg_is_enabled,
133168
};
134169

135170
static int reg_fixed_voltage_probe(struct platform_device *pdev)
@@ -177,6 +212,14 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
177212
dev_err(dev, "Can't get enable-clock from devicetree\n");
178213
return -ENOENT;
179214
}
215+
} else if (drvtype && drvtype->has_performance_state) {
216+
drvdata->desc.ops = &fixed_voltage_domain_ops;
217+
218+
drvdata->performance_state = of_get_required_opp_performance_state(dev->of_node, 0);
219+
if (drvdata->performance_state < 0) {
220+
dev_err(dev, "Can't get performance state from devicetree\n");
221+
return drvdata->performance_state;
222+
}
180223
} else {
181224
drvdata->desc.ops = &fixed_voltage_ops;
182225
}
@@ -260,6 +303,10 @@ static const struct fixed_dev_type fixed_clkenable_data = {
260303
.has_enable_clock = true,
261304
};
262305

306+
static const struct fixed_dev_type fixed_domain_data = {
307+
.has_performance_state = true,
308+
};
309+
263310
static const struct of_device_id fixed_of_match[] = {
264311
{
265312
.compatible = "regulator-fixed",
@@ -269,6 +316,10 @@ static const struct of_device_id fixed_of_match[] = {
269316
.compatible = "regulator-fixed-clock",
270317
.data = &fixed_clkenable_data,
271318
},
319+
{
320+
.compatible = "regulator-fixed-domain",
321+
.data = &fixed_domain_data,
322+
},
272323
{
273324
},
274325
};

0 commit comments

Comments
 (0)