[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2oyfx2i7bsadqmlqtmqhc2ee6vn4r7knfyq5kizgdjx3zpov6c@isiflqgza2gc>
Date: Fri, 12 Jul 2024 07:24:47 +0200
From: Uwe Kleine-König <u.kleine-koenig@...libre.com>
To: Guenter Roeck <linux@...ck-us.net>
Cc: Chris Packham <chris.packham@...iedtelesis.co.nz>, jdelvare@...e.com,
robh@...nel.org, krzk+dt@...nel.org, conor+dt@...nel.org,
linux-hwmon@...r.kernel.org, devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-pwm@...r.kernel.org
Subject: Re: [PATCH v5 3/3] hwmon: (adt7475) Add support for configuring
initial PWM state
On Thu, Jul 11, 2024 at 09:37:29PM -0700, Guenter Roeck wrote:
> On 7/11/24 16:46, Chris Packham wrote:
> > By default the PWM duty cycle in hardware is 100%. On some systems this
> > can cause unwanted fan noise. Add the ability to specify the fan
> > connections and initial state of the PWMs via device properties.
> >
> > Signed-off-by: Chris Packham <chris.packham@...iedtelesis.co.nz>
> > ---
> ...
> > +static int adt7475_pwm_properties_parse_reference_args(struct fwnode_handle *fwnode,
> > + struct adt7475_pwm_config *cfg)
> > +{
> > + int ret;
> > + struct fwnode_reference_args args = {};
> > + int freq_hz;
> > + int duty;
> > +
> > + ret = fwnode_property_get_reference_args(fwnode, "pwms", "#pwm-cells", 0, 0, &args);
> > + if (ret)
> > + return ret;
> > +
> > + if (args.nargs != 4) {
> > + fwnode_handle_put(args.fwnode);
> > + return -EINVAL;
> > + }
> > +
> > + freq_hz = 1000000000UL / args.args[1];
> > + duty = 255 / (args.args[1] / args.args[3]);
> > +
> You'll need to validate args.args[1] and args.args[3] to ensure that there are no
> divide by 0 errors.
>
> On a side note,
> a = b / (c / d) == b / c * d (at least for d != 0)
> Since the result is defined for d == 0, you'd only have to make sure
> that args.args[1] > 0 and that the result for the duty cycle is <= 255.
On a side side note: Depending on the actual values it might be
beneficial to use
b * d / c
instead. b * d might overflow, but in other cases (e.g. b = 7, c = 8, d
= 8) the resulting precision is much better.
Best regards
Uwe
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists