|
@@ -76,6 +76,7 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
|
struct tegra_pwm_chip *pc = to_tegra_pwm_chip(chip);
|
|
|
unsigned long long c = duty_ns;
|
|
|
unsigned long rate, hz;
|
|
|
+ unsigned long long ns100 = NSEC_PER_SEC;
|
|
|
u32 val = 0;
|
|
|
int err;
|
|
|
|
|
@@ -94,9 +95,11 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
|
* cycles at the PWM clock rate will take period_ns nanoseconds.
|
|
|
*/
|
|
|
rate = clk_get_rate(pc->clk) >> PWM_DUTY_WIDTH;
|
|
|
- hz = NSEC_PER_SEC / period_ns;
|
|
|
|
|
|
- rate = (rate + (hz / 2)) / hz;
|
|
|
+ /* Consider precision in PWM_SCALE_WIDTH rate calculation */
|
|
|
+ ns100 *= 100;
|
|
|
+ hz = DIV_ROUND_CLOSEST_ULL(ns100, period_ns);
|
|
|
+ rate = DIV_ROUND_CLOSEST(rate * 100, hz);
|
|
|
|
|
|
/*
|
|
|
* Since the actual PWM divider is the register's frequency divider
|