From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Chi-Wen Weng <cwweng.linux@gmail.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
cwweng@nuvoton.com
Subject: Re: [PATCH v5 2/2] pwm: Add Nuvoton MA35D1 PWM controller support
Date: Mon, 14 Sep 2026 10:44:22 +0200 [thread overview]
Message-ID: <aqexDgkF7Nqp-fML@monoceros> (raw)
In-Reply-To: <20260721062308.536947-3-cwweng.linux@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2430 bytes --]
Hello,
On Tue, Jul 21, 2026 at 02:23:08PM +0800, Chi-Wen Weng wrote:
> +static int nuvoton_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> + const struct pwm_state *state)
> +{
> + struct nuvoton_pwm *nvtpwm = nuvoton_pwm_from_chip(chip);
> + unsigned int ch = pwm->hwpwm;
> + u64 duty_cycles, period_cycles;
> + u64 divisor;
> + u32 cmpdat, period, prescale;
> + int ret;
> +
> + if (!state->enabled) {
> + nuvoton_pwm_rmw(nvtpwm, MA35D1_REG_PWM_POEN,
> + MA35D1_PWM_POEN_EN(ch), 0);
Does this mean the output pin goes High-Z on disable?
> + nuvoton_pwm_rmw(nvtpwm, MA35D1_REG_PWM_CNTEN,
> + MA35D1_PWM_CNTEN_EN(ch), 0);
> +
> + return 0;
> + }
> +
> + prescale = nuvoton_pwm_get_prescale(nvtpwm, ch);
> + divisor = (u64)NSEC_PER_SEC * (prescale + 1);
> +
> + period_cycles = mul_u64_u64_div_u64(nvtpwm->clkrate,
> + state->period, divisor);
> + if (!period_cycles)
> + return -EINVAL;
> +
> + if (period_cycles > MA35D1_PWM_MAX_CYCLES)
> + period_cycles = MA35D1_PWM_MAX_CYCLES;
> +
> + duty_cycles = mul_u64_u64_div_u64(nvtpwm->clkrate,
> + state->duty_cycle, divisor);
> + if (duty_cycles > period_cycles)
> + duty_cycles = period_cycles;
> +
> + ret = nuvoton_pwm_config_channel(nvtpwm, ch);
> + if (ret)
> + return ret;
> +
> + if (state->polarity == PWM_POLARITY_NORMAL)
> + nuvoton_pwm_rmw(nvtpwm, MA35D1_REG_PWM_POLCTL,
> + MA35D1_PWM_POLCTL_INV(ch), 0);
> + else
> + nuvoton_pwm_rmw(nvtpwm, MA35D1_REG_PWM_POLCTL,
> + MA35D1_PWM_POLCTL_INV(ch),
> + MA35D1_PWM_POLCTL_INV(ch));
> +
> + /*
> + * In up-counting mode the counter counts from 0 to PERIOD inclusive.
> + * With zero point high and compare-up point low actions:
> + * - CMPDAT = 0 produces 0% duty.
> + * - CMPDAT > PERIOD produces 100% duty.
> + *
> + * period_cycles is limited to 0xffff, so PERIOD is at most 0xfffe
> + * and a 100% duty cycle can be represented by CMPDAT = 0xffff.
> + */
> + period = period_cycles - 1;
> + cmpdat = duty_cycles;
> +
> + nuvoton_pwm_writel(nvtpwm, MA35D1_REG_PWM_PERIOD(ch), period);
> + nuvoton_pwm_writel(nvtpwm, MA35D1_REG_PWM_CMPDAT(ch), cmpdat);
This is racy, right? (i.e. if a period end happens between these two
writes, we see (probably) one period with the new period length and the
old duty_cycle.
The result of the two questions should be a comment describing the
behaviour, otherwise the code looks fine on a quick glance.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2026-09-14 8:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 6:23 [PATCH v5 0/2] pwm: Add Nuvoton MA35D1 PWM controller support Chi-Wen Weng
2026-07-21 6:23 ` [PATCH v5 1/2] dt-bindings: pwm: Add Nuvoton MA35D1 PWM controller Chi-Wen Weng
2026-07-21 6:23 ` [PATCH v5 2/2] pwm: Add Nuvoton MA35D1 PWM controller support Chi-Wen Weng
2026-07-21 6:33 ` sashiko-bot
2026-09-14 8:32 ` Uwe Kleine-König
2026-09-14 8:44 ` Uwe Kleine-König [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=aqexDgkF7Nqp-fML@monoceros \
--to=ukleinek@kernel.org \
--cc=conor+dt@kernel.org \
--cc=cwweng.linux@gmail.com \
--cc=cwweng@nuvoton.com \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox