All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Richard Weinberger <richard@nod.at>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	linux-pwm@vger.kernel.org,
	 linux-hwmon <linux-hwmon@vger.kernel.org>,
	Guenter Roeck <linux@roeck-us.net>,
	 julian friedrich <julian.friedrich@frequentis.com>
Subject: Re: [PATCH] [RFC] hwmon: nct6775: Register fan PWMs as PWM chip
Date: Fri, 27 Feb 2026 20:57:16 +0100	[thread overview]
Message-ID: <aaH1g7Bi_rJkN_aG@monoceros> (raw)
In-Reply-To: <1212284023.1388.1772131004601.JavaMail.zimbra@nod.at>

[-- Attachment #1: Type: text/plain, Size: 2106 bytes --]

Hello Richard,

On Thu, Feb 26, 2026 at 07:36:44PM +0100, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
> > Von: "Uwe Kleine-König" <ukleinek@kernel.org>
> >> +	struct nct6775_data *data = pwmchip_get_drvdata(chip);
> >> +	const u8 *wfhw = _wfhw;
> >> +
> >> +	if (get_pwm_period(data, pwm->hwpwm, &wf->period_length_ns))
> >> +		return 1;
> > 
> > That looks wrong. In principle nct6775_pwm_round_waveform_fromhw()
> > doesn't depend on hardware state. It's supposed to just convert the
> > settings stored in _wfhw to wf. If you know that some things are
> > constant during the lifetime of the PWM and you read those from
> > hardware, return a proper error code, not 1.
> 
> I see. Since the frequency is never changed by the driver we could
> read it while probing and use here the cached value.

I don't care much why the period length is constant. With the idiom from
this patch a comment would be nice, reading once is also fine.

> > Rounding down wf->period_length_ns is fine, so this must be:
> > 
> >	if (wf->period_length_ns < cur_period)
> >		return 1;
> 
> But then the period is no longer fixed and something larger than supported
> can get configured. Smaller values get caught, though.

that's wrong. The period is still fixed.

> e.g.
> root@fedora:/sys/class/pwm/pwmchip0/pwm2# cat period 
> 43243
> root@fedora:/sys/class/pwm/pwmchip0/pwm2# echo 43200 > period 
> bash: echo: write error: Invalid argument
> root@fedora:/sys/class/pwm/pwmchip0/pwm2# echo 50000 > period 
> root@fedora:/sys/class/pwm/pwmchip0/pwm2# echo $?
> 0

Yes, you can request 50000, but the driver will round that down to
43243. If you have commit aa12c7e70319c9746e55e5b00a215119ba838dad, a
look into /sys/kernel/debug/pwm should confirm that.

(That's a weakness of the sysfs API, you cannot get feedback about how
far the driver has to modify your request to adapt it to the hardware.
Did I mention that you should better use libpwm tools for such tests?
pwm_round will tell you what the driver does with a certain request.)

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-02-27 19:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 12:51 [PATCH] [RFC] hwmon: nct6775: Register fan PWMs as PWM chip Richard Weinberger
2026-02-26 17:54 ` Uwe Kleine-König
2026-02-26 18:36   ` Richard Weinberger
2026-02-27 19:57     ` Uwe Kleine-König [this message]
2026-02-26 22:38 ` Guenter Roeck
2026-02-27  7:46   ` Richard Weinberger
2026-02-27  8:17     ` Guenter Roeck
2026-02-27 20:02       ` Uwe Kleine-König
2026-02-27 20:59         ` Guenter Roeck
2026-04-14  9:48   ` Uwe Kleine-König

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=aaH1g7Bi_rJkN_aG@monoceros \
    --to=ukleinek@kernel.org \
    --cc=julian.friedrich@frequentis.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=richard@nod.at \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.