aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm
diff options
context:
space:
mode:
authorDan O'Donovan <dan@emutex.com>2016-06-01 10:31:12 -0400
committerThierry Reding <thierry.reding@gmail.com>2016-07-11 06:07:23 -0400
commite5ca42458b6278b7d5866e08dae7c45349af2157 (patch)
treed9fe091c919e771fb56f11647c8b8bc743a2f4bf /drivers/pwm
parentcc37655e6bbf83ded1e4d1d7ffd977786a845a67 (diff)
pwm: lpss: Fix base_unit calculation for PWM frequency
The base_unit calculation applies an offset of 0x2 which adds significant error for lower frequencies and doesn't appear to be warranted - rounding the division result gives a correct value. Also, the upper limit check for base_unit is off-by-one; the upper nibble of base_unit is invalid if >=128 according to the Table 88 in the Z8000 Processor Series Datasheet Volume 1 (Rev. 2). Verified on UP Board (Cherry Trail) and Minnowboard Max (Bay Trail). Signed-off-by: Dan O'Donovan <dan@emutex.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/pwm-lpss.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
index 295b963dbddb..98dc8b80b79d 100644
--- a/drivers/pwm/pwm-lpss.c
+++ b/drivers/pwm/pwm-lpss.c
@@ -27,7 +27,6 @@
27#define PWM_SW_UPDATE BIT(30) 27#define PWM_SW_UPDATE BIT(30)
28#define PWM_BASE_UNIT_SHIFT 8 28#define PWM_BASE_UNIT_SHIFT 8
29#define PWM_ON_TIME_DIV_MASK 0x000000ff 29#define PWM_ON_TIME_DIV_MASK 0x000000ff
30#define PWM_DIVISION_CORRECTION 0x2
31 30
32/* Size of each PWM register space if multiple */ 31/* Size of each PWM register space if multiple */
33#define PWM_SIZE 0x400 32#define PWM_SIZE 0x400
@@ -101,17 +100,16 @@ static int pwm_lpss_config(struct pwm_chip *chip, struct pwm_device *pwm,
101 100
102 /* 101 /*
103 * The equation is: 102 * The equation is:
104 * base_unit = ((freq / c) * base_unit_range) + correction 103 * base_unit = round(base_unit_range * freq / c)
105 */ 104 */
106 base_unit_range = BIT(lpwm->info->base_unit_bits); 105 base_unit_range = BIT(lpwm->info->base_unit_bits);
107 base_unit = freq * base_unit_range; 106 freq *= base_unit_range;
108 107
109 c = lpwm->info->clk_rate; 108 c = lpwm->info->clk_rate;
110 if (!c) 109 if (!c)
111 return -EINVAL; 110 return -EINVAL;
112 111
113 do_div(base_unit, c); 112 base_unit = DIV_ROUND_CLOSEST_ULL(freq, c);
114 base_unit += PWM_DIVISION_CORRECTION;
115 113
116 if (duty_ns <= 0) 114 if (duty_ns <= 0)
117 duty_ns = 1; 115 duty_ns = 1;