From d00bfccedfbd1a79c9bc950e22f9f92a6bf717c0 Mon Sep 17 00:00:00 2001 From: Xing Zheng Date: Fri, 27 Dec 2019 21:31:23 +0800 Subject: [PATCH] clk: fractional-divider: add handle to frac numerator is not to be greater than 4 We know that under the condition of even frequency division, if the numeratoris greater than 4, the duty cycle may not be equal to 50%. In the case, weneed to keep the original numerator(<4) and denominator. Change-Id: I8cd08199df4e3d27d5697ce80370224a6f267e26 Signed-off-by: Xing Zheng --- drivers/clk/clk-fractional-divider.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index f2cd069e4a17..105a677d472d 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -112,9 +112,18 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, * which will lead to a large deviation in the result. * Therefore, it is required that the numerator must * be greater than 4. + * + * Note that there are some exceptions here: + * If there is an even frac div, we need to keep the original + * numerator(<4) and denominator. Otherwise, it may cause the + * issue that the duty ratio is not 50%. */ if (m < 4 && m != 0) { - val = DIV_ROUND_UP(4, m); + if (n % 2 == 0) + val = 1; + else + val = DIV_ROUND_UP(4, m); + n *= val; m *= val; if (n > fd->nmask) {