From: sashiko-bot@kernel.org
To: "Petar Stepanovic" <pstepanovic@axiado.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver
Date: Wed, 18 Nov 2026 13:00:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-220959@kernel.org> (raw)
In-Reply-To: <20261118-axiado-ax3000-pwm-v7-2-bbd21a8cf861@axiado.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] pwm: axiado: report AXIADO_PWM_PERIOD_MIN for constant-low
waveform
- [Low] pwm: axiado: missing clock rate upper bound check in
axiado_pwm_probe()
- [Low] pwm: axiado: enabled state with zero period misreported as
disabled
--
commit 7728e28931a7e60a27c5a0287f72bca3566ff745
Author: Petar Stepanovic <pstepanovic@axiado.com>
pwm: add Axiado AX3000 PWM driver
This commit adds a PWM driver for the single-channel PWM controller on
Axiado AX3000 and AX3005 SoCs using the waveform callbacks.
> diff --git a/drivers/pwm/pwm-axiado.c b/drivers/pwm/pwm-axiado.c
> new file mode 100644
> index 0000000000000..08ae3d8ed4bb1
> --- /dev/null
> +++ b/drivers/pwm/pwm-axiado.c
[ ... ]
> +static int
> +axiado_pwm_round_waveform_tohw(struct pwm_chip *chip,
> + struct pwm_device *pwm,
> + const struct pwm_waveform *wf,
> + void *_wfhw)
> +{
[ ... ]
> + if (!duty) {
> + /*
> + * A zero high time makes the hardware emit a constant high
> + * output, so use the constant low period encoding for a 0%
> + * duty cycle. The high time must stay non-zero because it
> + * takes precedence over that encoding. The requested period
> + * is lost, .round_waveform_fromhw() reports a single clock
> + * cycle instead.
> + */
> + *wfhw = (struct axiado_pwm_waveform) {
> + .period = AXIADO_PWM_PERIOD_CONST_LOW,
> + .duty = AXIADO_PWM_DUTY_MIN,
> + .enabled = true,
> + };
> +
> + /* That single cycle is longer than a sub-cycle request. */
> + return period ? 0 : 1;
> + }
> +
> + if (period < AXIADO_PWM_PERIOD_MIN) {
> + period = AXIADO_PWM_PERIOD_MIN;
> + ret = 1;
[Severity: Medium]
Should the constant-low encoding use AXIADO_PWM_PERIOD_MIN (2 clock cycles)
instead of 1 clock cycle as its minimum and reported period?
When duty is 0, axiado_pwm_round_waveform_tohw() accepts a 1-cycle period
with return value 0 and axiado_pwm_round_waveform_fromhw() reports
AXIADO_PWM_PERIOD_CONST_LOW as period = 1, whereas any non-zero duty cycle
requires period >= AXIADO_PWM_PERIOD_MIN (2) and rounds a 1-cycle period up
with return value 1.
When CONFIG_PWM_PROVIDE_GPIO is enabled, pwm_gpio_set() probes the minimum
period with period_length_ns = 1 and duty_length_ns = 0, which rounds to 1
clock cycle. Driving the GPIO high then sets duty_length_ns =
period_length_ns (1 clock cycle) and calls pwm_set_waveform_might_sleep()
with exact = true, which rounds the period up to 2 clock cycles and fails
with -EDOM:
drivers/pwm/core.c:pwm_gpio_set() {
struct pwm_waveform wf = {
.period_length_ns = 1,
};
...
ret = pwm_round_waveform_might_sleep(pwm, &wf);
if (ret < 0)
return ret;
if (value)
wf.duty_length_ns = wf.period_length_ns;
else
wf.duty_length_ns = 0;
return pwm_set_waveform_might_sleep(pwm, &wf, true);
}
Reporting AXIADO_PWM_PERIOD_MIN for AXIADO_PWM_PERIOD_CONST_LOW in
axiado_pwm_round_waveform_fromhw() and returning period <
AXIADO_PWM_PERIOD_MIN ? 1 : 0 when !duty in
axiado_pwm_round_waveform_tohw() keeps the minimum period consistent across
all duty cycles.
[ ... ]
> +static int
> +axiado_pwm_round_waveform_fromhw(struct pwm_chip *chip,
> + struct pwm_device *pwm,
> + const void *_wfhw,
> + struct pwm_waveform *wf)
> +{
[ ... ]
> + /*
> + * The constant low encoding doesn't hold a period. Report the
> + * shortest one, the output is low for all of it either way.
> + */
> + if (!duty) {
> + if (period == AXIADO_PWM_PERIOD_CONST_LOW)
> + period = AXIADO_PWM_PERIOD_MAX;
> +
> + duty = period;
> + } else if (period == AXIADO_PWM_PERIOD_CONST_LOW) {
> + period = 1;
> + duty = 0;
> + } else if (duty > period) {
> + duty = period;
> + }
> +
> + *wf = (struct pwm_waveform) {
> + .period_length_ns =
> + mul_u64_u64_div_u64_roundup(period, NSEC_PER_SEC,
> + axpwm->rate),
> + .duty_length_ns =
> + mul_u64_u64_div_u64_roundup(duty, NSEC_PER_SEC,
> + axpwm->rate),
> + .duty_offset_ns = 0,
> + };
[Severity: Low]
Can axiado_pwm_round_waveform_fromhw() report a disabled waveform when the
hardware is enabled with AXIADO_PWM_PERIOD_REG == 0?
If pre-kernel firmware leaves the controller enabled with period == 0 (for
instance with duty == 0, where a zero high time still drives the output
constant high), period and duty both remain 0 and wf->period_length_ns is
computed as 0. Because period_length_ns == 0 encodes a disabled waveform,
pwm_get_state_hw() records pwm->state.enabled = false, and a subsequent
pwm_apply_might_sleep() call to disable the channel returns early in
__pwm_apply() without clearing AXIADO_PWM_CTRL_ENABLE.
[ ... ]
> +static int axiado_pwm_probe(struct platform_device *pdev)
> +{
[ ... ]
> + axpwm->rate = clk_get_rate(clk);
> + if (!axpwm->rate)
> + return dev_err_probe(dev, -EINVAL,
> + "Failed to get clock rate\n");
[Severity: Low]
Should axiado_pwm_probe() also reject axpwm->rate > NSEC_PER_SEC?
If clk_get_rate() exceeds NSEC_PER_SEC, a single clock cycle is shorter
than 1 ns, breaking nanosecond-to-cycle rounding idempotency and sub-cycle
detection in axiado_pwm_round_waveform_tohw(), and allowing
mul_u64_u64_div_u64() to overflow a 64-bit quotient for large
wf->period_length_ns values.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-axiado-ax3000-pwm-v7-0-bbd21a8cf861@axiado.com?part=2
prev parent reply other threads:[~2026-11-18 13:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 12:42 [PATCH v7 0/2] pwm: add Axiado AX3000 PWM support Petar Stepanovic
2026-11-18 12:42 ` [PATCH v7 1/2] dt-bindings: pwm: add Axiado AX3000 PWM Petar Stepanovic
2026-11-18 12:42 ` [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver Petar Stepanovic
2026-11-18 13:00 ` sashiko-bot [this message]
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=sashiko-outbox-220959@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=pstepanovic@axiado.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.