@@ -51,16 +51,17 @@ static int mxs_pwm_config(struct pwm_chip *chip,
struct pwm_device *pwm,
unsigned int period_cycles, duty_cycles;
unsigned long rate;
unsigned long long c;
+ unsigned const int cdiv[PERIOD_CDIV_MAX] = {1, 2, 4, 8, 16, 64,
256, 1024};
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;