summaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2022-10-14 19:24:27 +0200
committerSebastian Reichel <sebastian.reichel@collabora.com>2022-10-29 01:40:31 +0200
commit14a3d159abf8f6013d40723856283705253e7e9a (patch)
treefccf1f08f94bc798eb8e24f419c27854572a8a43 /drivers/power
parentpower: supply: bq25890: Add get_voltage support to Vbus regulator (diff)
downloadlinux-14a3d159abf8f6013d40723856283705253e7e9a.tar.xz
linux-14a3d159abf8f6013d40723856283705253e7e9a.zip
power: supply: bq25890: Add Vsys regulator
The chip is capable of reporting Vsys voltage supplied to the system. Add regulator which represents the Vsys supply. This can be used e.g. as a supply for system PMIC input. Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Marek Vasut <marex@denx.de> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/bq25890_charger.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index ad5811304f88..f0362dcb935e 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -1102,6 +1102,20 @@ static int bq25890_vbus_get_voltage(struct regulator_dev *rdev)
return bq25890_get_vbus_voltage(bq);
}
+static int bq25890_vsys_get_voltage(struct regulator_dev *rdev)
+{
+ struct bq25890_device *bq = rdev_get_drvdata(rdev);
+ int ret;
+
+ /* Should be some output voltage ? */
+ ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
+ if (ret < 0)
+ return ret;
+
+ /* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
+ return 2304000 + ret * 20000;
+}
+
static const struct regulator_ops bq25890_vbus_ops = {
.enable = bq25890_vbus_enable,
.disable = bq25890_vbus_disable,
@@ -1117,6 +1131,18 @@ static const struct regulator_desc bq25890_vbus_desc = {
.ops = &bq25890_vbus_ops,
};
+static const struct regulator_ops bq25890_vsys_ops = {
+ .get_voltage = bq25890_vsys_get_voltage,
+};
+
+static const struct regulator_desc bq25890_vsys_desc = {
+ .name = "vsys",
+ .of_match = "vsys",
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .ops = &bq25890_vsys_ops,
+};
+
static int bq25890_register_regulator(struct bq25890_device *bq)
{
struct bq25890_platform_data *pdata = dev_get_platdata(bq->dev);
@@ -1135,6 +1161,12 @@ static int bq25890_register_regulator(struct bq25890_device *bq)
"registering vbus regulator");
}
+ reg = devm_regulator_register(bq->dev, &bq25890_vsys_desc, &cfg);
+ if (IS_ERR(reg)) {
+ return dev_err_probe(bq->dev, PTR_ERR(reg),
+ "registering vsys regulator");
+ }
+
return 0;
}
#else