[PATCH v4 3/3] hwmon: max31790: add fanN_enable for all fans

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The fanN_enable will be set in dbus-sensors service according to the
index of TACH that filled in the configuration of entity-manager.
Add fanN_enable for all fans to prevent dbus-sensors service
couldn't find the corresponding fanN_enable for fanN_input.

Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@xxxxxxxxxx>
---
Changelog:
v4 - Add fanN_enable for all fans.
---
 Documentation/hwmon/max31790.rst |  2 +-
 drivers/hwmon/max31790.c         | 57 +++++++++++++++++---------------
 2 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst
index 33c5c7330efc..510d5691b18b 100644
--- a/Documentation/hwmon/max31790.rst
+++ b/Documentation/hwmon/max31790.rst
@@ -38,7 +38,7 @@ Sysfs entries
 fan[1-12]_input    RO  fan tachometer speed in RPM
 fan[1-12]_fault    RO  fan experienced fault
 fan[1-6]_target    RW  desired fan speed in RPM
-fan[1-6]_enable    RW  enable or disable the tachometer input
+fan[1-12]_enable   RW  enable or disable the tachometer input
 pwm[1-6]_enable    RW  regulator mode, 0=disabled (duty cycle=0%), 1=manual mode, 2=rpm mode
 pwm[1-6]           RW  read: current pwm duty cycle,
                        write: target pwm duty cycle (0-255)
diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
index 378ff32c7c1e..fa31e108c7ce 100644
--- a/drivers/hwmon/max31790.c
+++ b/drivers/hwmon/max31790.c
@@ -203,7 +203,8 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel,
 		mutex_unlock(&data->update_lock);
 		return 0;
 	case hwmon_fan_enable:
-		*val = !!(data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT_EN);
+		*val = !!(data->fan_config[channel % NR_CHANNEL] &
+			  MAX31790_FAN_CFG_TACH_INPUT_EN);
 		return 0;
 	default:
 		return -EOPNOTSUPP;
@@ -242,12 +243,12 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel,
 
 		data->target_count[channel] = target_count << 5;
 
-		err = i2c_smbus_write_word_swapped(client,
-					MAX31790_REG_TARGET_COUNT(channel),
-					data->target_count[channel]);
+		err = i2c_smbus_write_word_swapped(
+			client, MAX31790_REG_TARGET_COUNT(channel),
+			data->target_count[channel]);
 		break;
 	case hwmon_fan_enable:
-		fan_config = data->fan_config[channel];
+		fan_config = data->fan_config[channel % NR_CHANNEL];
 		if (val == 0) {
 			fan_config &= ~MAX31790_FAN_CFG_TACH_INPUT_EN;
 		} else if (val == 1) {
@@ -256,11 +257,14 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel,
 			err = -EINVAL;
 			break;
 		}
-		if (fan_config != data->fan_config[channel]) {
-			err = i2c_smbus_write_byte_data(client, MAX31790_REG_FAN_CONFIG(channel),
-							fan_config);
+		if (fan_config != data->fan_config[channel % NR_CHANNEL]) {
+			err = i2c_smbus_write_byte_data(
+				client,
+				MAX31790_REG_FAN_CONFIG(channel % NR_CHANNEL),
+				fan_config);
 			if (!err)
-				data->fan_config[channel] = fan_config;
+				data->fan_config[channel % NR_CHANNEL] =
+					fan_config;
 		}
 		break;
 	default:
@@ -291,7 +295,8 @@ static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel)
 			return 0644;
 		return 0;
 	case hwmon_fan_enable:
-		if (channel < NR_CHANNEL)
+		if (channel < NR_CHANNEL ||
+		    (fan_config & MAX31790_FAN_CFG_TACH_INPUT))
 			return 0644;
 		return 0;
 	default:
@@ -445,22 +450,22 @@ static umode_t max31790_is_visible(const void *data,
 	}
 }
 
-static const struct hwmon_channel_info * const max31790_info[] = {
-	HWMON_CHANNEL_INFO(fan,
-			   HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
-			   HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
-			   HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
-			   HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
-			   HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
-			   HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
-			   HWMON_F_INPUT | HWMON_F_FAULT,
-			   HWMON_F_INPUT | HWMON_F_FAULT,
-			   HWMON_F_INPUT | HWMON_F_FAULT,
-			   HWMON_F_INPUT | HWMON_F_FAULT,
-			   HWMON_F_INPUT | HWMON_F_FAULT,
-			   HWMON_F_INPUT | HWMON_F_FAULT),
-	HWMON_CHANNEL_INFO(pwm,
-			   HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+static const struct hwmon_channel_info *const max31790_info[] = {
+	HWMON_CHANNEL_INFO(
+		fan,
+		HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+		HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE),
+	HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
 			   HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
 			   HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
 			   HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
-- 
2.25.1





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux