summaryrefslogtreecommitdiff
path: root/drivers/regulator/rt4801-regulator.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2022-05-25 01:09:47 +0300
committerLinus Torvalds <torvalds@linux-foundation.org>2022-05-25 01:09:47 +0300
commit9b18d07ba3ae75fcb7a191fafe4e2954f07271be (patch)
treeb3f3d995a9a8a746fd66fb769154c016dbc8c19e /drivers/regulator/rt4801-regulator.c
parent5d23bb5f25ed9cbf530b99640f4f17f59b79de9e (diff)
parenta5b8e4a5ceec0ab6453176bc7f5eceafa78bf8a9 (diff)
downloadlinux-9b18d07ba3ae75fcb7a191fafe4e2954f07271be.tar.xz
Merge tag 'regulator-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown: "This is mostly a drivers update including a couple of new drivers but we do have some fixes and improvements to the core as well. - Make sure we don't log spuriously about uncontrollable regulators. - Don't use delays when we should use sleeps for regulators with larger ramp times. - Support for MediaTek MT6358 and MT6366, Richtek RT5759 and Silicon Mitus SM5703" * tag 'regulator-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (36 commits) regulator: scmi: Fix refcount leak in scmi_regulator_probe regulator: pfuze100: Fix refcount leak in pfuze_parse_regulators_dt regulator: qcom_smd: Fix up PM8950 regulator configuration regulator: core: Fix enable_count imbalance with EXCLUSIVE_GET regulator: core: Add error flags to sysfs attributes regulator: dt-bindings: qcom,rpmh: document vdd-l7-bob-supply on PMR735A regulator: dt-bindings: qcom,rpmh: document supplies per variant regulator: dt-bindings: qcom,rpmh: update maintainers regulator: mt6315: Enforce regulator-compatible, not name regulator: pca9450: Enable DVS control via PMIC_STBY_REQ regulator: pca9450: Make warm reset on WDOG_B assertion regulator: Add property for WDOG_B warm reset regulator: pca9450: Make I2C Level Translator configurable regulator: Add property for I2C level shifter regulator: sm5703: Correct reference to the common regulator schema regulator: sm5703-regulator: Add regulators support for SM5703 MFD dt-bindings: regulator: Add bindings for Silicon Mitus SM5703 regulators regulator: richtek,rt4801: parse GPIOs per regulator regulator: dt-bindings: richtek,rt4801: use existing ena_gpiod feature regulator: core: Sleep (not delay) in set_voltage() ...
Diffstat (limited to 'drivers/regulator/rt4801-regulator.c')
-rw-r--r--drivers/regulator/rt4801-regulator.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt4801-regulator.c
index 7a87788d3f09..563d79196fdd 100644
--- a/drivers/regulator/rt4801-regulator.c
+++ b/drivers/regulator/rt4801-regulator.c
@@ -29,11 +29,33 @@
struct rt4801_priv {
struct device *dev;
- struct gpio_descs *enable_gpios;
+ struct gpio_desc *enable_gpios[DSV_OUT_MAX];
unsigned int enable_flag;
unsigned int volt_sel[DSV_OUT_MAX];
};
+static int rt4801_of_parse_cb(struct device_node *np,
+ const struct regulator_desc *desc,
+ struct regulator_config *config)
+{
+ struct rt4801_priv *priv = config->driver_data;
+ int id = desc->id;
+
+ if (priv->enable_gpios[id]) {
+ dev_warn(priv->dev, "duplicated enable-gpios property\n");
+ return 0;
+ }
+ priv->enable_gpios[id] = devm_fwnode_gpiod_get_index(priv->dev,
+ of_fwnode_handle(np),
+ "enable", 0,
+ GPIOD_OUT_HIGH,
+ "rt4801");
+ if (IS_ERR(priv->enable_gpios[id]))
+ priv->enable_gpios[id] = NULL;
+
+ return 0;
+}
+
static int rt4801_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector)
{
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
@@ -63,15 +85,14 @@ static int rt4801_get_voltage_sel(struct regulator_dev *rdev)
static int rt4801_enable(struct regulator_dev *rdev)
{
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
- struct gpio_descs *gpios = priv->enable_gpios;
int id = rdev_get_id(rdev), ret;
- if (!gpios || gpios->ndescs <= id) {
+ if (!priv->enable_gpios[id]) {
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
goto bypass_gpio;
}
- gpiod_set_value(gpios->desc[id], 1);
+ gpiod_set_value(priv->enable_gpios[id], 1);
bypass_gpio:
ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, priv->volt_sel[id]);
@@ -85,15 +106,14 @@ bypass_gpio:
static int rt4801_disable(struct regulator_dev *rdev)
{
struct rt4801_priv *priv = rdev_get_drvdata(rdev);
- struct gpio_descs *gpios = priv->enable_gpios;
int id = rdev_get_id(rdev);
- if (!gpios || gpios->ndescs <= id) {
+ if (!priv->enable_gpios[id]) {
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
goto bypass_gpio;
}
- gpiod_set_value(gpios->desc[id], 0);
+ gpiod_set_value(priv->enable_gpios[id], 0);
bypass_gpio:
priv->enable_flag &= ~BIT(id);
@@ -122,6 +142,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
.name = "DSVP",
.ops = &rt4801_regulator_ops,
.of_match = of_match_ptr("DSVP"),
+ .of_parse_cb = rt4801_of_parse_cb,
.type = REGULATOR_VOLTAGE,
.id = DSV_OUT_POS,
.min_uV = MIN_UV,
@@ -135,6 +156,7 @@ static const struct regulator_desc rt4801_regulator_descs[] = {
.name = "DSVN",
.ops = &rt4801_regulator_ops,
.of_match = of_match_ptr("DSVN"),
+ .of_parse_cb = rt4801_of_parse_cb,
.type = REGULATOR_VOLTAGE,
.id = DSV_OUT_NEG,
.min_uV = MIN_UV,
@@ -172,10 +194,15 @@ static int rt4801_probe(struct i2c_client *i2c)
return PTR_ERR(regmap);
}
- priv->enable_gpios = devm_gpiod_get_array_optional(&i2c->dev, "enable", GPIOD_OUT_HIGH);
- if (IS_ERR(priv->enable_gpios)) {
- dev_err(&i2c->dev, "Failed to get gpios\n");
- return PTR_ERR(priv->enable_gpios);
+ for (i = 0; i < DSV_OUT_MAX; i++) {
+ priv->enable_gpios[i] = devm_gpiod_get_index_optional(&i2c->dev,
+ "enable",
+ i,
+ GPIOD_OUT_HIGH);
+ if (IS_ERR(priv->enable_gpios[i])) {
+ dev_err(&i2c->dev, "Failed to get gpios\n");
+ return PTR_ERR(priv->enable_gpios[i]);
+ }
}
for (i = 0; i < DSV_OUT_MAX; i++) {