Re: [PATCH v14] pwm: airoha: Add support for EN7581 SoC

From: Uwe Kleine-König
Date: Mon Jun 23 2025 - 05:54:54 EST


Hello Christian,

On Mon, Jun 16, 2025 at 10:15:24PM +0200, Christian Marangi wrote:
> +static int airoha_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> + const struct pwm_state *state)
> +{
> + struct airoha_pwm *pc = pwmchip_get_drvdata(chip);
> + u64 duty_ns = state->duty_cycle;
> + u64 period_ns = state->period;
> +
> + if (!state->enabled) {
> + airoha_pwm_disable(pc, pwm);
> + return 0;
> + }
> +
> + /* Only normal polarity is supported */
> + if (state->polarity == PWM_POLARITY_INVERSED)
> + return -EINVAL;
> +
> + /* Exit early if period is less than minimum supported */
> + if (period_ns < AIROHA_PWM_PERIOD_TICK_NS)
> + return -EINVAL;
> +
> + /*
> + * Period goes at 4ns step, normalize it to check if we can
> + * share a generator.
> + */
> + period_ns = rounddown(period_ns, AIROHA_PWM_PERIOD_TICK_NS);

I guess this is the one that triggered the exception on m68k (though I
couldn't reproduce it). If you do the clamping first, period_ns can be
an unsigned int and the issue should be fixed.

> + /*
> + * Duty goes at 255 step, normalize it to check if we can
> + * share a generator.
> + */
> + duty_ns = DIV_U64_ROUND_UP(duty_ns * AIROHA_PWM_DUTY_FULL,
> + AIROHA_PWM_DUTY_FULL);
> +
> + /* Clamp period to MAX supported value */
> + if (period_ns > AIROHA_PWM_PERIOD_MAX_NS) {
> + period_ns = AIROHA_PWM_PERIOD_MAX_NS;
> +
> + if (duty_ns > period_ns)
> + duty_ns = period_ns;
> + }
> +
> + return airoha_pwm_config(pc, pwm, duty_ns, period_ns);
> +}
> [...]
> +static struct platform_driver airoha_pwm_driver = {
> + .driver = {
> + .name = "pwm-airoha",

Given that there must be another revision anyhow, please add

.probe_type = PROBE_PREFER_ASYNCHRONOUS,

here.

> + .of_match_table = airoha_pwm_of_match,
> + },
> + .probe = airoha_pwm_probe,
> +};
> +module_platform_driver(airoha_pwm_driver);

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature