lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221117194352.1904264-1-Naresh.Solanki@9elements.com>
Date:   Thu, 17 Nov 2022 20:43:51 +0100
From:   Naresh Solanki <naresh.solanki@...ements.com>
To:     Guenter Roeck <linux@...ck-us.net>, linux-hwmon@...r.kernel.org,
        Jean Delvare <jdelvare@...e.com>
Cc:     Patrick Rudolph <patrick.rudolph@...ements.com>,
        Naresh Solanki <Naresh.Solanki@...ements.com>,
        linux-kernel@...r.kernel.org
Subject: [PATCH] hwmon: pm_bus: core: Implement regulator get_status

From: Patrick Rudolph <patrick.rudolph@...ements.com>

Add get_status for pmbus_regulator_ops.

Signed-off-by: Patrick Rudolph <patrick.rudolph@...ements.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@...ements.com>
---
 drivers/hwmon/pmbus/pmbus_core.c | 78 ++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 7ec04934747e..d5e2b0662da5 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2851,6 +2851,83 @@ 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, status2;
+
+	mutex_lock(&data->update_lock);
+	status = pmbus_get_status(client, page, PMBUS_STATUS_WORD);
+	mutex_unlock(&data->update_lock);
+	if (status < 0)
+		 return status;
+
+	if (status & PB_STATUS_VIN_UV ||
+	    status & PB_STATUS_IOUT_OC ||
+	    status & PB_STATUS_VOUT_OV ||
+	    status & PB_STATUS_UNKNOWN)
+		 return REGULATOR_STATUS_ERROR;
+
+	if (status & PB_STATUS_VOUT_OV &&
+	    data->info->func[page] & PMBUS_HAVE_STATUS_VOUT) {
+		 mutex_lock(&data->update_lock);
+		 status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_VOUT);
+		 mutex_unlock(&data->update_lock);
+		 if (status2 < 0)
+			  return status2;
+		 if (status2 & PB_VOLTAGE_OV_FAULT ||
+		     status2 & PB_VOLTAGE_UV_FAULT)
+			  return REGULATOR_STATUS_ERROR;
+	}
+	if (status & PB_STATUS_IOUT_OC &&
+	    data->info->func[page] & PMBUS_HAVE_STATUS_IOUT) {
+		 mutex_lock(&data->update_lock);
+		 status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT);
+		 mutex_unlock(&data->update_lock);
+		 if (status2 < 0)
+			  return status2;
+		 if (status2 & PB_POUT_OP_FAULT ||
+		     status2 & PB_IOUT_UC_FAULT ||
+		     status2 & PB_IOUT_OC_LV_FAULT ||
+		     status2 & PB_IOUT_OC_FAULT)
+			  return REGULATOR_STATUS_ERROR;
+	}
+	if (status & PB_STATUS_VIN_UV &&
+	    data->info->func[page] & PMBUS_HAVE_STATUS_INPUT) {
+		 mutex_lock(&data->update_lock);
+		 status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_INPUT);
+		 mutex_unlock(&data->update_lock);
+		 if (status2 < 0)
+			  return status2;
+		 if (status2 & PB_IIN_OC_FAULT ||
+		     status2 & PB_VOLTAGE_OV_FAULT ||
+		     status2 & PB_VOLTAGE_UV_FAULT)
+			  return REGULATOR_STATUS_ERROR;
+	}
+	if (status & PB_STATUS_TEMPERATURE &&
+	    data->info->func[page] & PMBUS_HAVE_STATUS_TEMP) {
+		 mutex_lock(&data->update_lock);
+		 status2 = _pmbus_read_byte_data(client, page, PMBUS_STATUS_TEMPERATURE);
+		 mutex_unlock(&data->update_lock);
+		 if (status2 < 0)
+			  return status2;
+		 if (status2 & PB_TEMP_UT_FAULT ||
+		     status2 & PB_TEMP_OT_FAULT)
+			  return REGULATOR_STATUS_ERROR;
+	}
+
+	if (status & PB_STATUS_OFF)
+		 return REGULATOR_STATUS_OFF;
+
+	if (status & PB_STATUS_POWER_GOOD_N)
+		 return REGULATOR_STATUS_OFF;
+
+	return REGULATOR_STATUS_ON;
+}
+
 static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page)
 {
 	struct pmbus_data *data = i2c_get_clientdata(client);
@@ -2991,6 +3068,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,

base-commit: 27fea302952d8c90cafbdbee96bafeca03544401
-- 
2.37.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ