aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhi Mao <zhi.mao@mediatek.com>2017-06-30 02:05:20 -0400
committerThierry Reding <thierry.reding@gmail.com>2017-08-21 04:39:11 -0400
commit8bdb65dc8575978214785462870852a56b6a21ac (patch)
treefb421e982b77d6e0afae2e3fc8f7217e4af4093c
parent62843a6152e7c19f28c368bb51cac1bbfcdf4249 (diff)
pwm: mediatek: Disable clock on PWM configuration failure
Make sure to disable the PWM clock if the PWM cannot be configured due to the clock divider exceeding the maximum value. While at it, replace the hardcoded maximum clock divider with a defined constant to improve code readability. Signed-off-by: Zhi Mao <zhi.mao@mediatek.com> Acked-by: John Crispin <john@phrozen.org> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
-rw-r--r--drivers/pwm/pwm-mediatek.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
index 637045998318..b52f3afb2ba1 100644
--- a/drivers/pwm/pwm-mediatek.c
+++ b/drivers/pwm/pwm-mediatek.c
@@ -30,6 +30,8 @@
30#define PWMDWIDTH 0x2c 30#define PWMDWIDTH 0x2c
31#define PWMTHRES 0x30 31#define PWMTHRES 0x30
32 32
33#define PWM_CLK_DIV_MAX 7
34
33enum { 35enum {
34 MTK_CLK_MAIN = 0, 36 MTK_CLK_MAIN = 0,
35 MTK_CLK_TOP, 37 MTK_CLK_TOP,
@@ -130,8 +132,11 @@ static int mtk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
130 clkdiv++; 132 clkdiv++;
131 } 133 }
132 134
133 if (clkdiv > 7) 135 if (clkdiv > PWM_CLK_DIV_MAX) {
136 mtk_pwm_clk_disable(chip, pwm);
137 dev_err(chip->dev, "period %d not supported\n", period_ns);
134 return -EINVAL; 138 return -EINVAL;
139 }
135 140
136 mtk_pwm_writel(pc, pwm->hwpwm, PWMCON, BIT(15) | clkdiv); 141 mtk_pwm_writel(pc, pwm->hwpwm, PWMCON, BIT(15) | clkdiv);
137 mtk_pwm_writel(pc, pwm->hwpwm, PWMDWIDTH, period_ns / resolution); 142 mtk_pwm_writel(pc, pwm->hwpwm, PWMDWIDTH, period_ns / resolution);