Commit b05d3946 authored by Bjorn Andersson's avatar Bjorn Andersson Committed by Johan Hovold

leds: qcom-lpg: Fix PWM period limits

The introduction of high resolution PWM support changed the order of the
operations in the calculation of min and max period. The result in both
divisions is in most cases a truncation to 0, which limits the period to
the range of [0, 0].

Both numerators (and denominators) are within 64 bits, so the whole
expression can be put directly into the div64_u64, instead of doing it
partially.

Fixes: b00d2ed3 ("leds: rgb: leds-qcom-lpg: Add support for high resolution PWM")
Reviewed-by: default avatarCaleb Connolly <caleb.connolly@linaro.org>
Tested-by: default avatarSteev Klimaszewski <steev@kali.org>
Signed-off-by: default avatarBjorn Andersson <quic_bjorande@quicinc.com>
Acked-by: default avatarLee Jones <lee@kernel.org>
Tested-by: default avatarJohan Hovold <johan+linaro@kernel.org>
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
Link: https://lore.kernel.org/r/20230515162604.649203-1-quic_bjorande@quicinc.comSigned-off-by: default avatarJohan Hovold <johan@kernel.org>
parent 7877cb91
...@@ -312,14 +312,14 @@ static int lpg_calc_freq(struct lpg_channel *chan, uint64_t period) ...@@ -312,14 +312,14 @@ static int lpg_calc_freq(struct lpg_channel *chan, uint64_t period)
max_res = LPG_RESOLUTION_9BIT; max_res = LPG_RESOLUTION_9BIT;
} }
min_period = (u64)NSEC_PER_SEC * min_period = div64_u64((u64)NSEC_PER_SEC * (1 << pwm_resolution_arr[0]),
div64_u64((1 << pwm_resolution_arr[0]), clk_rate_arr[clk_len - 1]); clk_rate_arr[clk_len - 1]);
if (period <= min_period) if (period <= min_period)
return -EINVAL; return -EINVAL;
/* Limit period to largest possible value, to avoid overflows */ /* Limit period to largest possible value, to avoid overflows */
max_period = (u64)NSEC_PER_SEC * max_res * LPG_MAX_PREDIV * max_period = div64_u64((u64)NSEC_PER_SEC * max_res * LPG_MAX_PREDIV * (1 << LPG_MAX_M),
div64_u64((1 << LPG_MAX_M), 1024); 1024);
if (period > max_period) if (period > max_period)
period = max_period; period = max_period;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment