From e7089b40b70f966bb574d1a4fa24a203e6f0779e Mon Sep 17 00:00:00 2001 From: max_chen Date: Mon, 21 Jul 2025 20:15:09 +0800 Subject: [PATCH] pwm: atmel-hlcdc: Fix frequency output being half of expected The atmel-hlcdc PWM driver generates an output frequency that is exactly half of the value requested in the device tree. For example, a request for 1000 Hz results in a 500 Hz output. This is caused by an incorrect prescaler calculation. The driver's formula for the clock divider did not match the hardware, which uses a division factor of 2^(pres + 1). The driver was missing the "+1", causing the output period to be doubled. This patch corrects the calculation to `2^(pres + 1)`, aligning it with the hardware's behavior and ensuring the generated frequency is correct. --- drivers/pwm/pwm-atmel-hlcdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-atmel-hlcdc.c b/drivers/pwm/pwm-atmel-hlcdc.c index 5553efa4634a40..fb2bdb520868d4 100644 --- a/drivers/pwm/pwm-atmel-hlcdc.c +++ b/drivers/pwm/pwm-atmel-hlcdc.c @@ -89,7 +89,7 @@ static int atmel_hlcdc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, atmel->errata->div1_clk_erratum) continue; - if ((clk_period_ns << pres) >= state->period) + if ((clk_period_ns << (pres + 1)) >= state->period) break; }