Skip to content

Commit 6963569

Browse files
krzkbroonie
authored andcommitted
regulator: richtek,rt4801: parse GPIOs per regulator
Having one enable-gpios property for all regulators is discouraged and instead, similarly to regulator core ena_gpiod feature, each GPIO should be present in each regulator node. Add support for parsing such GPIOs, keeping backwards compatibility. Signed-off-by: Krzysztof Kozlowski <[email protected]> Tested-by: ChiYuan Huang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent a498db6 commit 6963569

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

drivers/regulator/rt4801-regulator.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,33 @@
2929

3030
struct rt4801_priv {
3131
struct device *dev;
32-
struct gpio_descs *enable_gpios;
32+
struct gpio_desc *enable_gpios[DSV_OUT_MAX];
3333
unsigned int enable_flag;
3434
unsigned int volt_sel[DSV_OUT_MAX];
3535
};
3636

37+
static int rt4801_of_parse_cb(struct device_node *np,
38+
const struct regulator_desc *desc,
39+
struct regulator_config *config)
40+
{
41+
struct rt4801_priv *priv = config->driver_data;
42+
int id = desc->id;
43+
44+
if (priv->enable_gpios[id]) {
45+
dev_warn(priv->dev, "duplicated enable-gpios property\n");
46+
return 0;
47+
}
48+
priv->enable_gpios[id] = devm_fwnode_gpiod_get_index(priv->dev,
49+
of_fwnode_handle(np),
50+
"enable", 0,
51+
GPIOD_OUT_HIGH,
52+
"rt4801");
53+
if (IS_ERR(priv->enable_gpios[id]))
54+
priv->enable_gpios[id] = NULL;
55+
56+
return 0;
57+
}
58+
3759
static int rt4801_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector)
3860
{
3961
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
@@ -63,15 +85,14 @@ static int rt4801_get_voltage_sel(struct regulator_dev *rdev)
6385
static int rt4801_enable(struct regulator_dev *rdev)
6486
{
6587
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
66-
struct gpio_descs *gpios = priv->enable_gpios;
6788
int id = rdev_get_id(rdev), ret;
6889

69-
if (!gpios || gpios->ndescs <= id) {
90+
if (!priv->enable_gpios[id]) {
7091
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
7192
goto bypass_gpio;
7293
}
7394

74-
gpiod_set_value(gpios->desc[id], 1);
95+
gpiod_set_value(priv->enable_gpios[id], 1);
7596

7697
bypass_gpio:
7798
ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, priv->volt_sel[id]);
@@ -85,15 +106,14 @@ static int rt4801_enable(struct regulator_dev *rdev)
85106
static int rt4801_disable(struct regulator_dev *rdev)
86107
{
87108
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
88-
struct gpio_descs *gpios = priv->enable_gpios;
89109
int id = rdev_get_id(rdev);
90110

91-
if (!gpios || gpios->ndescs <= id) {
111+
if (!priv->enable_gpios[id]) {
92112
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
93113
goto bypass_gpio;
94114
}
95115

96-
gpiod_set_value(gpios->desc[id], 0);
116+
gpiod_set_value(priv->enable_gpios[id], 0);
97117

98118
bypass_gpio:
99119
priv->enable_flag &= ~BIT(id);
@@ -122,6 +142,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
122142
.name = "DSVP",
123143
.ops = &rt4801_regulator_ops,
124144
.of_match = of_match_ptr("DSVP"),
145+
.of_parse_cb = rt4801_of_parse_cb,
125146
.type = REGULATOR_VOLTAGE,
126147
.id = DSV_OUT_POS,
127148
.min_uV = MIN_UV,
@@ -135,6 +156,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
135156
.name = "DSVN",
136157
.ops = &rt4801_regulator_ops,
137158
.of_match = of_match_ptr("DSVN"),
159+
.of_parse_cb = rt4801_of_parse_cb,
138160
.type = REGULATOR_VOLTAGE,
139161
.id = DSV_OUT_NEG,
140162
.min_uV = MIN_UV,
@@ -172,10 +194,15 @@ static int rt4801_probe(struct i2c_client *i2c)
172194
return PTR_ERR(regmap);
173195
}
174196

175-
priv->enable_gpios = devm_gpiod_get_array_optional(&i2c->dev, "enable", GPIOD_OUT_HIGH);
176-
if (IS_ERR(priv->enable_gpios)) {
177-
dev_err(&i2c->dev, "Failed to get gpios\n");
178-
return PTR_ERR(priv->enable_gpios);
197+
for (i = 0; i < DSV_OUT_MAX; i++) {
198+
priv->enable_gpios[i] = devm_gpiod_get_index_optional(&i2c->dev,
199+
"enable",
200+
i,
201+
GPIOD_OUT_HIGH);
202+
if (IS_ERR(priv->enable_gpios[i])) {
203+
dev_err(&i2c->dev, "Failed to get gpios\n");
204+
return PTR_ERR(priv->enable_gpios[i]);
205+
}
179206
}
180207

181208
for (i = 0; i < DSV_OUT_MAX; i++) {

0 commit comments

Comments
 (0)