Skip to content

Commit 0042c88

Browse files
andredbroonie
authored andcommitted
regulator: s2mps11: refactor handling of external rail control
Refactor s2mps14_pmic_enable_ext_control() and s2mps11_of_parse_cb() slightly as a preparation for adding S2MPG10 and S2MPG11 support, as both of those PMICs also support control of rails via GPIOs. This also includes the following to avoid further updates in follow-up commits: * On S2MPG10 and S2MPG11, external rail control can be via GPIO or via non-GPIO signals, hence passing a GPIO is allowed to be optional. This avoids inappropriate verbose driver messages. * Prepare to allow use of standard DT property name 'enable-gpios' for newer platforms instead of vendor-specific 'samsung,ext-control'. Signed-off-by: André Draszik <andre.draszik@linaro.org> Link: https://patch.msgid.link/20260122-s2mpg1x-regulators-v7-15-3b1f9831fffd@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 5b3c957 commit 0042c88

1 file changed

Lines changed: 67 additions & 33 deletions

File tree

drivers/regulator/s2mps11.c

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -328,29 +328,15 @@ static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
328328
rdev->desc->enable_mask, state);
329329
}
330330

331-
static int s2mps11_of_parse_cb(struct device_node *np,
332-
const struct regulator_desc *desc,
333-
struct regulator_config *config)
331+
static int s2mps11_of_parse_gpiod(struct device_node *np,
332+
const char *con_id, bool optional,
333+
const struct regulator_desc *desc,
334+
struct regulator_config *config)
334335
{
335-
const struct s2mps11_info *s2mps11 = config->driver_data;
336336
struct gpio_desc *ena_gpiod;
337337
int ret;
338338

339-
if (s2mps11->dev_type == S2MPS14X)
340-
switch (desc->id) {
341-
case S2MPS14_LDO10:
342-
case S2MPS14_LDO11:
343-
case S2MPS14_LDO12:
344-
break;
345-
346-
default:
347-
return 0;
348-
}
349-
else
350-
return 0;
351-
352-
ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np),
353-
"samsung,ext-control", 0,
339+
ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np), con_id, 0,
354340
GPIOD_OUT_HIGH |
355341
GPIOD_FLAGS_BIT_NONEXCLUSIVE,
356342
"s2mps11-regulator");
@@ -361,14 +347,19 @@ static int s2mps11_of_parse_cb(struct device_node *np,
361347
if (ret == -EPROBE_DEFER)
362348
return ret;
363349

364-
if (ret == -ENOENT)
350+
if (ret == -ENOENT) {
351+
if (optional)
352+
return 0;
353+
365354
dev_info(config->dev,
366355
"No entry for control GPIO for %d/%s in node %pOF\n",
367356
desc->id, desc->name, np);
368-
else
357+
} else {
369358
dev_warn_probe(config->dev, ret,
370359
"Failed to get control GPIO for %d/%s in node %pOF\n",
371360
desc->id, desc->name, np);
361+
}
362+
372363
return 0;
373364
}
374365

@@ -380,6 +371,29 @@ static int s2mps11_of_parse_cb(struct device_node *np,
380371
return 0;
381372
}
382373

374+
static int s2mps11_of_parse_cb(struct device_node *np,
375+
const struct regulator_desc *desc,
376+
struct regulator_config *config)
377+
{
378+
const struct s2mps11_info *s2mps11 = config->driver_data;
379+
380+
if (s2mps11->dev_type == S2MPS14X)
381+
switch (desc->id) {
382+
case S2MPS14_LDO10:
383+
case S2MPS14_LDO11:
384+
case S2MPS14_LDO12:
385+
break;
386+
387+
default:
388+
return 0;
389+
}
390+
else
391+
return 0;
392+
393+
return s2mps11_of_parse_gpiod(np, "samsung,ext-control", false, desc,
394+
config);
395+
}
396+
383397
static const struct regulator_ops s2mps11_ldo_ops = {
384398
.list_voltage = regulator_list_voltage_linear,
385399
.map_voltage = regulator_map_voltage_linear,
@@ -903,10 +917,16 @@ static const struct regulator_desc s2mps15_regulators[] = {
903917
};
904918

905919
static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
906-
struct regulator_dev *rdev)
920+
struct regulator_dev *rdev)
907921
{
908-
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
909-
rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
922+
int ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
923+
rdev->desc->enable_mask,
924+
S2MPS14_ENABLE_EXT_CONTROL);
925+
if (ret < 0)
926+
return dev_err_probe(rdev_get_dev(rdev), ret,
927+
"failed to enable GPIO control over %d/%s\n",
928+
rdev->desc->id, rdev->desc->name);
929+
return 0;
910930
}
911931

912932
static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
@@ -1244,6 +1264,26 @@ static const struct regulator_desc s2mpu05_regulators[] = {
12441264
regulator_desc_s2mpu05_buck45(5),
12451265
};
12461266

1267+
static int s2mps11_handle_ext_control(struct s2mps11_info *s2mps11,
1268+
struct regulator_dev *rdev)
1269+
{
1270+
int ret;
1271+
1272+
switch (s2mps11->dev_type) {
1273+
case S2MPS14X:
1274+
if (!rdev->ena_pin)
1275+
return 0;
1276+
1277+
ret = s2mps14_pmic_enable_ext_control(s2mps11, rdev);
1278+
break;
1279+
1280+
default:
1281+
return 0;
1282+
}
1283+
1284+
return ret;
1285+
}
1286+
12471287
static int s2mps11_pmic_probe(struct platform_device *pdev)
12481288
{
12491289
struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -1314,15 +1354,9 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
13141354
regulators[i].id,
13151355
regulators[i].name);
13161356

1317-
if (regulator->ena_pin) {
1318-
ret = s2mps14_pmic_enable_ext_control(s2mps11,
1319-
regulator);
1320-
if (ret < 0)
1321-
return dev_err_probe(&pdev->dev, ret,
1322-
"failed to enable GPIO control over %d/%s\n",
1323-
regulator->desc->id,
1324-
regulator->desc->name);
1325-
}
1357+
ret = s2mps11_handle_ext_control(s2mps11, regulator);
1358+
if (ret < 0)
1359+
return ret;
13261360
}
13271361

13281362
return 0;

0 commit comments

Comments
 (0)