From: Guenter Roeck <linux@roeck-us.net>
To: linux-hwmon@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Farouk Bouabid <farouk.bouabid@cherry.de>,
Quentin Schulz <quentin.schulz@cherry.de>,
Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH v3 11/11] hwmon: (amc6821) Add support for pwm1_mode attribute
Date: Thu, 4 Jul 2024 10:52:07 -0700 [thread overview]
Message-ID: <20240704175207.2684012-12-linux@roeck-us.net> (raw)
In-Reply-To: <20240704175207.2684012-1-linux@roeck-us.net>
AMC6821 supports configuring if a fan is DC or PWM controlled.
Add support for the pwm1_mode attribute to make it runtime configurable.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3: Fix wrong register used when writing the attribute
v2: New patch
Documentation/hwmon/amc6821.rst | 1 +
drivers/hwmon/amc6821.c | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Documentation/hwmon/amc6821.rst b/Documentation/hwmon/amc6821.rst
index 96e604c5ea8e..dbd544cd1160 100644
--- a/Documentation/hwmon/amc6821.rst
+++ b/Documentation/hwmon/amc6821.rst
@@ -58,6 +58,7 @@ pwm1_enable rw regulator mode, 1=open loop, 2=fan controlled
remote-sensor temperature,
4=fan controlled by target rpm set with
fan1_target attribute.
+pwm1_mode rw Fan duty control mode (0=DC, 1=PWM)
pwm1_auto_channels_temp ro 1 if pwm_enable==2, 3 if pwm_enable==3
pwm1_auto_point1_pwm ro Hardwired to 0, shared for both
temperature channels.
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index be3e590aba3d..4e3f8a6e8354 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -308,6 +308,12 @@ static int amc6821_pwm_read(struct device *dev, u32 attr, long *val)
break;
}
return 0;
+ case hwmon_pwm_mode:
+ err = regmap_read(regmap, AMC6821_REG_CONF2, ®val);
+ if (err)
+ return err;
+ *val = !!(regval & AMC6821_CONF2_TACH_MODE);
+ return 0;
case hwmon_pwm_auto_channels_temp:
err = regmap_read(regmap, AMC6821_REG_CONF1, ®val);
if (err)
@@ -363,6 +369,13 @@ static int amc6821_pwm_write(struct device *dev, u32 attr, long val)
return regmap_update_bits(regmap, AMC6821_REG_CONF1,
AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1,
mode);
+ case hwmon_pwm_mode:
+ if (val < 0 || val > 1)
+ return -EINVAL;
+ return regmap_update_bits(regmap, AMC6821_REG_CONF2,
+ AMC6821_CONF2_TACH_MODE,
+ val ? AMC6821_CONF2_TACH_MODE : 0);
+ break;
case hwmon_pwm_input:
if (val < 0 || val > 255)
return -EINVAL;
@@ -741,6 +754,7 @@ static umode_t amc6821_is_visible(const void *data,
}
case hwmon_pwm:
switch (attr) {
+ case hwmon_pwm_mode:
case hwmon_pwm_enable:
case hwmon_pwm_input:
return 0644;
@@ -767,7 +781,7 @@ static const struct hwmon_channel_info * const amc6821_info[] = {
HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_MAX |
HWMON_F_TARGET | HWMON_F_PULSES | HWMON_F_FAULT),
HWMON_CHANNEL_INFO(pwm,
- HWMON_PWM_INPUT | HWMON_PWM_ENABLE |
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE |
HWMON_PWM_AUTO_CHANNELS_TEMP),
NULL
};
--
2.39.2
next prev parent reply other threads:[~2024-07-04 17:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-04 17:51 [PATCH v3 00/11] hwmon: (amc6821) Various improvements Guenter Roeck
2024-07-04 17:51 ` [PATCH v3 01/11] hwmon: (amc6821) Stop accepting invalid pwm values Guenter Roeck
2024-07-04 17:51 ` [PATCH v3 02/11] hwmon: (amc6821) Make reading and writing fan speed limits consistent Guenter Roeck
2024-07-04 17:51 ` [PATCH v3 03/11] hwmon: (amc6821) Rename fan1_div to fan1_pulses Guenter Roeck
2024-07-04 17:52 ` [PATCH v3 04/11] hwmon: (amc6821) Add support for fan1_target and pwm1_enable mode 4 Guenter Roeck
2024-07-04 17:52 ` [PATCH v3 05/11] hwmon: (amc2821) Reorder include files, drop unnecessary ones Guenter Roeck
2024-07-04 17:52 ` [PATCH v3 06/11] hwmon: (amc6821) Use tabs for column alignment in defines Guenter Roeck
2024-07-04 17:52 ` [PATCH v3 07/11] hwmon: (amc2821) Use BIT() and GENMASK() Guenter Roeck
2024-07-04 17:52 ` [PATCH v3 08/11] hwmon: (amc6821) Drop unnecessary enum chips Guenter Roeck
2024-07-04 17:52 ` [PATCH v3 09/11] hwmon: (amc6821) Convert to use regmap Guenter Roeck
2024-07-05 10:59 ` Quentin Schulz
2024-07-05 14:28 ` Guenter Roeck
2024-07-08 10:37 ` Quentin Schulz
2024-07-04 17:52 ` [PATCH v3 10/11] hwmon: (amc6821) Convert to with_info API Guenter Roeck
2024-07-04 17:52 ` Guenter Roeck [this message]
2024-07-05 11:00 ` [PATCH v3 11/11] hwmon: (amc6821) Add support for pwm1_mode attribute Quentin Schulz
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=20240704175207.2684012-12-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=farouk.bouabid@cherry.de \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quentin.schulz@cherry.de \
/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