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: <20240514092242.2739662-1-Delphine_CC_Chiu@wiwynn.com>
Date: Tue, 14 May 2024 17:22:40 +0800
From: Delphine CC Chiu <Delphine_CC_Chiu@...ynn.com>
To: patrick@...cx.xyz
Cc: Delphine CC Chiu <Delphine_CC_Chiu@...ynn.com>,
	Jean Delvare <jdelvare@...e.com>,
	Guenter Roeck <linux@...ck-us.net>,
	linux-hwmon@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH v2] hwmon: Add support for ina233

Support ina233 with vshunt

Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@...ynn.com>
---
 drivers/hwmon/pmbus/ina233.c | 37 +++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/ina233.c b/drivers/hwmon/pmbus/ina233.c
index d5c7d7408ac3..33736e5049a9 100644
--- a/drivers/hwmon/pmbus/ina233.c
+++ b/drivers/hwmon/pmbus/ina233.c
@@ -11,9 +11,43 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/hwmon-sysfs.h>
 #include "pmbus.h"
 
 #define MFR_CALIBRATION	0xd4
+#define MFR_READ_VSHUNT 0xd1
+
+#define HIGHEST_BIT 15
+
+static ssize_t ina233_vshunt_show(struct device *dev,
+				  struct device_attribute *devattr, char *buf)
+{
+	int shunt_volt;
+	struct i2c_client *client = to_i2c_client(dev->parent);
+
+	shunt_volt = i2c_smbus_read_word_data(client, MFR_READ_VSHUNT);
+	if (shunt_volt < 0)
+		return shunt_volt;
+
+	// Is negative
+	if (shunt_volt & (1 << HIGHEST_BIT))
+		shunt_volt = ~(shunt_volt & ~(1 << HIGHEST_BIT)) + 1;
+
+	// This unit is mV.
+	// LSB 2.5 μV is reference from spec 7.6.3.2 MFR_READ_VSHUNT
+	int val = DIV_ROUND_UP(shunt_volt * 25, 10000);
+
+	return sysfs_emit(buf, "%d\n", val);
+}
+
+static SENSOR_DEVICE_ATTR_RO(vshunt, ina233_vshunt, 1);
+
+static struct attribute *ina233_attrs[] = {
+	&sensor_dev_attr_vshunt.dev_attr.attr,
+	NULL,
+};
+
+ATTRIBUTE_GROUPS(ina233);
 
 struct pmbus_driver_info ina233_info = {
 	.pages = 1,
@@ -29,6 +63,7 @@ struct pmbus_driver_info ina233_info = {
 	.m[PSC_VOLTAGE_OUT] = 8,
 	.R[PSC_VOLTAGE_IN] = 2,
 	.R[PSC_VOLTAGE_OUT] = 2,
+	.groups = ina233_groups,
 };
 
 static int ina233_probe(struct i2c_client *client)
@@ -82,7 +117,7 @@ static struct i2c_driver ina233_driver = {
 
 module_i2c_driver(ina233_driver);
 
-MODULE_AUTHOR("Eli Huang <eli_huang@...ynn.com>");
+MODULE_AUTHOR("Delphine_CC_Chiu <Delphine_CC_Chiu@...ynn.com>");
 MODULE_DESCRIPTION("PMBus driver for Texas Instruments INA233 and compatible chips");
 MODULE_LICENSE("GPL");
 MODULE_IMPORT_NS(PMBUS);
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ