Re: [PATCH] leds: rgb: leds-qcom-lpg: Add PWM frequency mode support
From: Konrad Dybcio
Date: Fri Jul 31 2026 - 10:28:01 EST
On 7/29/26 11:48 AM, Fenglin Wu wrote:
> Certain PWM channels on a PMIC (e.g. PM8350C PWM4) support a Frequency
> Mode (FM) that can generate waveforms with more frequency points than
> the standard LPG PWM mode. The trade-off is that the duty cycle can
> only be fixed at 50%. Add the FM support. When the PWM channel is
> requested to set a duty cycle to exactly 50%, use FM mode by default
> as it provides a finer-grained frequency resolution in that case.
>
> Signed-off-by: Fenglin Wu <fenglin.wu@xxxxxxxxxxxxxxxx>
> ---
[...]
> + for (clk = 1; clk < clk_len; clk++) {
> + last_err = U64_MAX;
> +
> + for (exp = 0; exp <= LPG_MAX_M; exp++) {
> + /* Calculate pwm_value_lsb for this (clk, exp) pair */
> + lsb_tmp = period_ns;
> + lsb_tmp = div64_u64(lsb_tmp, clk_period_arr[clk]);
> + lsb_tmp >>= (exp + 1);
> +
> + if (lsb_tmp == 0 || lsb_tmp - 1 > U8_MAX)
> + continue;
> +
> + lsb = lsb_tmp - 1;
> +
> + period_actual = (u64)(lsb + 1);
Did you mean `(u64)(lsb) + 1` here?
[...]
> + /* Calculate actual period for reference */
> + period_actual = (u64)(best_lsb + 1);
And here too?
In general, I think there's nothing that prevents you from
turning all of these variables into u64s
[...]
> regmap_read(lpg->map, chan->base + LPG_SUBTYPE_REG, &chan->subtype);
> + if (data->channels[i].fm_capable) {
> + ret = regmap_read(lpg->map, chan->base + PWM_STATUS1_REG, &status);
> + if (ret < 0)
> + return ret;
> +
> + chan->fm_capable = !!(status & PWM_FM_PRESENT);
Can we read this register blindly by chance and drop the match data?
Konrad