summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2022-11-24 20:36:42 +0100
committerGuenter Roeck <linux@roeck-us.net>2022-12-04 16:45:03 -0800
commitc05f477c4ba36e007c03ff4f834f43bc4e37692b (patch)
tree263a2bfffc13d17eb7e36eeb1aed4176e8633f3f /drivers/hwmon
parent3ca0f12a02582c3dd4029294ab0245ba77c27a77 (diff)
downloadlinux-c05f477c4ba36e007c03ff4f834f43bc4e37692b.tar.bz2
hwmon: (pmbus/core) Implement regulator get_status
Add get_status for pmbus_regulator_ops. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com> Link: https://lore.kernel.org/r/20221124193642.4081054-1-Naresh.Solanki@9elements.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 20ca26e19db7..95e95783972a 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2855,6 +2855,49 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
return 0;
}
+static int pmbus_regulator_get_status(struct regulator_dev *rdev)
+{
+ struct device *dev = rdev_get_dev(rdev);
+ struct i2c_client *client = to_i2c_client(dev->parent);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ u8 page = rdev_get_id(rdev);
+ int status, ret;
+
+ mutex_lock(&data->update_lock);
+ status = pmbus_get_status(client, page, PMBUS_STATUS_WORD);
+ if (status < 0) {
+ ret = status;
+ goto unlock;
+ }
+
+ if (status & PB_STATUS_OFF) {
+ ret = REGULATOR_STATUS_OFF;
+ goto unlock;
+ }
+
+ /* If regulator is ON & reports power good then return ON */
+ if (!(status & PB_STATUS_POWER_GOOD_N)) {
+ ret = REGULATOR_STATUS_ON;
+ goto unlock;
+ }
+
+ ret = pmbus_regulator_get_error_flags(rdev, &status);
+ if (ret)
+ goto unlock;
+
+ if (status & (REGULATOR_ERROR_UNDER_VOLTAGE | REGULATOR_ERROR_OVER_CURRENT |
+ REGULATOR_ERROR_REGULATION_OUT | REGULATOR_ERROR_FAIL | REGULATOR_ERROR_OVER_TEMP)) {
+ ret = REGULATOR_STATUS_ERROR;
+ goto unlock;
+ }
+
+ ret = REGULATOR_STATUS_UNDEFINED;
+
+unlock:
+ mutex_unlock(&data->update_lock);
+ return ret;
+}
+
static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page)
{
struct pmbus_data *data = i2c_get_clientdata(client);
@@ -2995,6 +3038,7 @@ const struct regulator_ops pmbus_regulator_ops = {
.disable = pmbus_regulator_disable,
.is_enabled = pmbus_regulator_is_enabled,
.get_error_flags = pmbus_regulator_get_error_flags,
+ .get_status = pmbus_regulator_get_status,
.get_voltage = pmbus_regulator_get_voltage,
.set_voltage = pmbus_regulator_set_voltage,
.list_voltage = pmbus_regulator_list_voltage,