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-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 11 Mar 2024 18:13:46 +0700
From: Chanh Nguyen <chanh@...amperecomputing.com>
To: Jean Delvare <jdelvare@...e.com>,
	Guenter Roeck <linux@...ck-us.net>,
	Rob Herring <robh+dt@...nel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
	Conor Dooley <conor+dt@...nel.org>,
	Justin Ledford <justinledford@...gle.com>,
	devicetree@...r.kernel.org,
	linux-hwmon@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	OpenBMC Maillist <openbmc@...ts.ozlabs.org>,
	Open Source Submission <patches@...erecomputing.com>
Cc: Phong Vo <phong@...amperecomputing.com>,
	Thang Nguyen <thang@...amperecomputing.com>,
	Quan Nguyen <quan@...amperecomputing.com>,
	Chanh Nguyen <chanh@...amperecomputing.com>
Subject: [PATCH 2/3] hwmon: (max31790): Support config PWM output becomes TACH

PWMOUT pins on MAX31790 can be configured as a tachometer input pin by
setting bit[0] in the Configuration Register. When the bit[0] of a channel
is set, the PWMOUT pin becomes the tach input pin for the channel plus six.

This commit allows the kernel to set those pins when necessary if the
pwmout-pin-as-tach-input DT property exists.

Signed-off-by: Chanh Nguyen <chanh@...amperecomputing.com>
---
 drivers/hwmon/max31790.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
index 3dc95196b229..33ca8d1721c0 100644
--- a/drivers/hwmon/max31790.c
+++ b/drivers/hwmon/max31790.c
@@ -12,6 +12,7 @@
 #include <linux/init.h>
 #include <linux/jiffies.h>
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 
 /* MAX31790 registers */
@@ -506,9 +507,12 @@ static int max31790_probe(struct i2c_client *client)
 {
 	struct i2c_adapter *adapter = client->adapter;
 	struct device *dev = &client->dev;
+	u8 pwmout_to_tach[NR_CHANNEL];
 	struct max31790_data *data;
 	struct device *hwmon_dev;
 	int err;
+	u8 tmp;
+	int i;
 
 	if (!i2c_check_functionality(adapter,
 			I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
@@ -528,6 +532,33 @@ static int max31790_probe(struct i2c_client *client)
 	if (err)
 		return err;
 
+	if (device_property_present(dev, "pwmout-pin-as-tach-input")) {
+		err = device_property_read_u8_array(dev, "pwmout-pin-as-tach-input",
+						    pwmout_to_tach, NR_CHANNEL);
+		if (err) {
+			/* The pwmout-pin-as-tach-input is an array of six values */
+			dev_warn(dev, "The pwmout-pin-as-tach-input property exist but malform");
+		} else {
+			for (i = 0; i < NR_CHANNEL; i++) {
+				tmp = data->fan_config[i];
+				if (pwmout_to_tach[i])
+					data->fan_config[i] |= MAX31790_FAN_CFG_TACH_INPUT;
+				else
+					data->fan_config[i] &= ~(MAX31790_FAN_CFG_TACH_INPUT);
+
+				if (tmp != data->fan_config[i]) {
+					err = i2c_smbus_write_byte_data(client,
+									MAX31790_REG_FAN_CONFIG(i),
+									data->fan_config[i]);
+					if (err < 0)
+						dev_warn(dev,
+							 "Fail to apply fan configuration at channel %d",
+							 i);
+				}
+			}
+		}
+	}
+
 	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
 							 data,
 							 &max31790_chip_info,
-- 
2.17.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ