Openbmc archive mirror
 help / color / mirror / Atom feed
From: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
To: patrick@stwcx.xyz, joel@jms.id.au, openbmc@lists.ozlabs.org
Cc: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Subject: [PATCH linux dev-6.5 v4 3/3] hwmon: max31790: add fanN_enable for all fans
Date: Thu,  2 Nov 2023 11:39:02 +0800	[thread overview]
Message-ID: <20231102033902.3884466-4-Delphine_CC_Chiu@wiwynn.com> (raw)
In-Reply-To: <20231102033902.3884466-1-Delphine_CC_Chiu@wiwynn.com>

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@wiwynn.com>
---
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


      parent reply	other threads:[~2023-11-02  3:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02  3:38 [PATCH linux dev-6.5 v4 0/3] hwmon: max31790: support to config PWM as TACH Delphine CC Chiu
2023-11-02  3:39 ` [PATCH linux dev-6.5 v4 1/3] " Delphine CC Chiu
2023-11-02  3:39 ` [PATCH linux dev-6.5 v4 2/3] dt-bindings: hwmon: add MAX31790 Delphine CC Chiu
2023-11-02  3:39 ` Delphine CC Chiu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231102033902.3884466-4-Delphine_CC_Chiu@wiwynn.com \
    --to=delphine_cc_chiu@wiwynn.com \
    --cc=joel@jms.id.au \
    --cc=openbmc@lists.ozlabs.org \
    --cc=patrick@stwcx.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).