From: Peter Korsgaard <peter@korsgaard.com>
To: Guenter Roeck <linux@roeck-us.net>,
devicetree@vger.kernel.org, linux-hwmon@vger.kernel.org
Cc: Peter Korsgaard <peter@korsgaard.com>,
Jean Delvare <jdelvare@suse.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v4 2/2] hwmon: (pwm-fan): Make default PWM duty cycle configurable
Date: Fri, 3 Jan 2025 11:14:48 +0100 [thread overview]
Message-ID: <20250103101448.890946-2-peter@korsgaard.com> (raw)
In-Reply-To: <20250103101448.890946-1-peter@korsgaard.com>
The pwm-fan driver uses full PWM (255) duty cycle at startup, which may not
always be desirable because of noise or power consumption peaks, so support
an optional "default-pwm" property (0..255) that can be used to specify the
default PWM duty cycle.
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
Changes since v3:
- Readded validation code from v2, reworded commit message
Changes since v2:
- Recreated/resent
Changes since v1:
- Rename property to default-pwm
- Drop u32 cast
drivers/hwmon/pwm-fan.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 53a1a968d00d..f49b5c2c64a9 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -499,6 +499,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
const struct hwmon_channel_info **channels;
u32 pwm_min_from_stopped = 0;
u32 *fan_channel_config;
+ u32 default_pwm = MAX_PWM;
int channel_count = 1; /* We always have a PWM channel. */
int i;
@@ -545,11 +546,17 @@ static int pwm_fan_probe(struct platform_device *pdev)
ctx->enable_mode = pwm_disable_reg_enable;
+ device_property_read_u32(dev, "default-pwm", &default_pwm);
+ if (default_pwm > MAX_PWM) {
+ dev_err(dev, "Invalid default-pwm: %u > %d\n", default_pwm, MAX_PWM);
+ return -EINVAL;
+ }
+
/*
- * Set duty cycle to maximum allowed and enable PWM output as well as
+ * Set duty cycle to default and enable PWM output as well as
* the regulator. In case of error nothing is changed
*/
- ret = set_pwm(ctx, MAX_PWM);
+ ret = set_pwm(ctx, default_pwm);
if (ret) {
dev_err(dev, "Failed to configure PWM: %d\n", ret);
return ret;
--
2.39.5
next prev parent reply other threads:[~2025-01-03 10:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-03 10:14 [PATCH v4 1/2] dt-bindings: hwmon: pwm-fan: Document default-pwm property Peter Korsgaard
2025-01-03 10:14 ` Peter Korsgaard [this message]
2025-01-03 19:58 ` Rob Herring
2025-01-05 16:10 ` Peter Korsgaard
2025-01-06 17:38 ` Rob Herring
2025-01-06 18:32 ` Guenter Roeck
2025-01-10 20:06 ` Peter Korsgaard
2025-01-11 17:15 ` Guenter Roeck
2025-01-11 18:24 ` Peter Korsgaard
2025-01-11 22:45 ` Guenter Roeck
2025-01-05 16:42 ` Guenter Roeck
2025-01-05 17:22 ` Guenter Roeck
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=20250103101448.890946-2-peter@korsgaard.com \
--to=peter@korsgaard.com \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/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