From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Chris Packham <chris.packham@alliedtelesis.co.nz>,
Andrew Morton <akpm@linux-foundation.org>,
"Darrick J. Wong" <djwong@us.ibm.com>,
linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH v2 5/6] hwmon: (adt7470) Register as a PWM provider
Date: Sun, 19 Jul 2026 19:04:24 +0200 [thread overview]
Message-ID: <al0CHPmBmvCd5DW0@monoceros> (raw)
In-Reply-To: <20260717-adt7470_thermalzone-v2-5-a55147958fad@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2008 bytes --]
Hello,
On Fri, Jul 17, 2026 at 05:59:18PM -0300, Luiz Angelo Daros de Luca wrote:
> @@ -864,6 +865,57 @@ static int adt7470_pwm_write(struct device *dev, u32 attr, int channel, long val
> return err;
> }
>
> +static int adt7470_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> + const struct pwm_state *state)
> +{
> + struct adt7470_data *data = pwmchip_get_drvdata(chip);
> + unsigned int pwm_auto_reg_mask;
> + int err;
> + u8 val;
> +
> + if (pwm->hwpwm % 2)
> + pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
> + else
> + pwm_auto_reg_mask = ADT7470_PWM1_AUTO_MASK;
> +
> + if (state->enabled && state->period > 0)
> + val = DIV_ROUND_CLOSEST_ULL(state->duty_cycle * 255, state->period);
rounding a division using closest is wrong in the context of PWM.
Also state->duty_cycle * 255 might overflow and you have to use the
actual period in the calculation of val instead of the requested value.
> + else
> + val = 0;
> +
> + mutex_lock(&data->lock);
If you use guard(), the control flow simplifies and using goto becomes
unnecessary.
> + if (data->pwm[pwm->hwpwm] == val &&
> + data->pwm_automatic[pwm->hwpwm] == 0) {
> + mutex_unlock(&data->lock);
> + return 0;
> + }
> +
> + /* Put the PWM channel in manual mode before updating it. */
> + err = regmap_update_bits(data->regmap,
> + ADT7470_REG_PWM_CFG(pwm->hwpwm),
> + pwm_auto_reg_mask, 0);
> + if (err < 0)
> + goto out;
> +
> + data->pwm_automatic[pwm->hwpwm] = 0;
> +
> + err = regmap_write(data->regmap,
> + ADT7470_REG_PWM(pwm->hwpwm), val);
> + if (err < 0)
> + goto out;
> +
> + data->pwm[pwm->hwpwm] = val;
> +out:
> + mutex_unlock(&data->lock);
> +
> + return err;
> +}
> +
> +static const struct pwm_ops adt7470_pwm_ops = {
> + .apply = adt7470_pwm_apply,
For new drivers please implement .round_waveform_tohw(),
.round_waveform_fromhw(), .write_waveform() and ideally so
.read_waveform().
> +};
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-07-19 17:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 20:59 [PATCH v2 0/6] hwmon: (adt7470) Add thermal zone and PWM provider support Luiz Angelo Daros de Luca
2026-07-17 20:59 ` [PATCH v2 1/6] dt-bindings: hwmon: add binding for adi,adt7470 Luiz Angelo Daros de Luca
2026-07-17 21:04 ` sashiko-bot
2026-07-20 3:23 ` Luiz Angelo Daros de Luca
2026-07-20 6:47 ` Krzysztof Kozlowski
2026-07-20 14:24 ` Guenter Roeck
2026-07-21 2:12 ` Luiz Angelo Daros de Luca
2026-07-20 10:03 ` Uwe Kleine-König
2026-07-17 20:59 ` [PATCH v2 2/6] hwmon: (adt7470) Fix fans stuck in manual mode on I2C errors Luiz Angelo Daros de Luca
2026-07-17 21:10 ` sashiko-bot
2026-07-17 20:59 ` [PATCH v2 3/6] hwmon: (adt7470) Fix busy-loop and I2C flooding in update thread Luiz Angelo Daros de Luca
2026-07-17 21:12 ` sashiko-bot
2026-07-17 20:59 ` [PATCH v2 4/6] hwmon: (adt7470) Add ADT7470_PWM_MAX macro Luiz Angelo Daros de Luca
2026-07-17 21:05 ` sashiko-bot
2026-07-17 20:59 ` [PATCH v2 5/6] hwmon: (adt7470) Register as a PWM provider Luiz Angelo Daros de Luca
2026-07-17 21:17 ` sashiko-bot
2026-07-19 14:49 ` Guenter Roeck
2026-07-19 17:04 ` Uwe Kleine-König [this message]
2026-07-17 20:59 ` [PATCH v2 6/6] hwmon: (adt7470) Add thermal zone sensor support Luiz Angelo Daros de Luca
2026-07-17 21:09 ` sashiko-bot
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=al0CHPmBmvCd5DW0@monoceros \
--to=ukleinek@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chris.packham@alliedtelesis.co.nz \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=djwong@us.ibm.com \
--cc=krzk+dt@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=luizluca@gmail.com \
--cc=robh@kernel.org \
/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.