pwm: mxs: Fix period divider computation
[firefly-linux-kernel-4.4.55.git] / drivers / pwm / pwm-mxs.c
index f75ecb09d97de3e9a80e7b0fac46f2369fc288b7..b430811e14f582a9ad66e4cad3f86fbe4569a073 100644 (file)
 #define  PERIOD_CDIV(div)      (((div) & 0x7) << 20)
 #define  PERIOD_CDIV_MAX       8
 
+static const unsigned int cdiv[PERIOD_CDIV_MAX] = {
+       1, 2, 4, 8, 16, 64, 256, 1024
+};
+
 struct mxs_pwm_chip {
        struct pwm_chip chip;
        struct clk *clk;
@@ -54,13 +58,13 @@ static int mxs_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 
        rate = clk_get_rate(mxs->clk);
        while (1) {
-               c = rate / (1 << div);
+               c = rate / cdiv[div];
                c = c * period_ns;
                do_div(c, 1000000000);
                if (c < PERIOD_PERIOD_MAX)
                        break;
                div++;
-               if (div > PERIOD_CDIV_MAX)
+               if (div >= PERIOD_CDIV_MAX)
                        return -EINVAL;
        }