summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>2026-04-15 17:50:13 +0300
committerUwe Kleine-König <ukleinek@kernel.org>2026-05-26 08:50:42 +0300
commit35ce15049ea6ee5d5a59549039698d6029718efc (patch)
tree869369dd73e04fa9cc7f2cc3db6508a97373d70a
parent5ac9b13e3fce7fc43bfdbc309dc0871650404023 (diff)
downloadlinux-35ce15049ea6ee5d5a59549039698d6029718efc.tar.xz
pwm: stm32: Make use of mul_u64_u64_div_u64_roundup()
When the driver was converted to the waveform API the need for this function arised but at that time this function didn't exist yet. In the meantime it's available, so switch to the global function and drop the driver specific implementation. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://patch.msgid.link/788319f0fff963feca4df3c5fcdd471dcf70ccdf.1776264104.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
-rw-r--r--drivers/pwm/pwm-stm32.c27
1 files changed, 5 insertions, 22 deletions
diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
index 935257a890b0..c708e4a7ad70 100644
--- a/drivers/pwm/pwm-stm32.c
+++ b/drivers/pwm/pwm-stm32.c
@@ -193,22 +193,6 @@ out:
return ret;
}
-/*
- * This should be moved to lib/math/div64.c. Currently there are some changes
- * pending to mul_u64_u64_div_u64. Uwe will care for that when the dust settles.
- */
-static u64 stm32_pwm_mul_u64_u64_div_u64_roundup(u64 a, u64 b, u64 c)
-{
- u64 res = mul_u64_u64_div_u64(a, b, c);
- /* Those multiplications might overflow but it doesn't matter */
- u64 rem = a * b - c * res;
-
- if (rem)
- res += 1;
-
- return res;
-}
-
static int stm32_pwm_round_waveform_fromhw(struct pwm_chip *chip,
struct pwm_device *pwm,
const void *_wfhw,
@@ -223,16 +207,15 @@ static int stm32_pwm_round_waveform_fromhw(struct pwm_chip *chip,
u64 ccr_ns;
/* The result doesn't overflow for rate >= 15259 */
- wf->period_length_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1),
- NSEC_PER_SEC, rate);
+ wf->period_length_ns = mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1),
+ NSEC_PER_SEC, rate);
- ccr_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * wfhw->ccr,
- NSEC_PER_SEC, rate);
+ ccr_ns = mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * wfhw->ccr, NSEC_PER_SEC, rate);
if (wfhw->ccer & TIM_CCER_CCxP(ch + 1)) {
wf->duty_length_ns =
- stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1 - wfhw->ccr),
- NSEC_PER_SEC, rate);
+ mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1 - wfhw->ccr),
+ NSEC_PER_SEC, rate);
wf->duty_offset_ns = ccr_ns;
} else {