From 9defda9cd258620710e76d6aa0d5f789b88bc47c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AE=B8=E7=9B=9B=E9=A3=9E?= Date: Tue, 11 Feb 2014 11:19:03 +0800 Subject: [PATCH] pwm: solve the bug sleeping function called from invalid context at kernel/mutex.c:413 --- drivers/pwm/pwm-rockchip.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c index 5ca87e134eb0..ecb6255df6c4 100644 --- a/drivers/pwm/pwm-rockchip.c +++ b/drivers/pwm/pwm-rockchip.c @@ -227,9 +227,8 @@ static inline void rk_pwm_writel(struct rk_pwm_chip *chip, } - #if 1 -static int __rk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, +static int rk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns) { struct rk_pwm_chip *pc = to_rk_pwm_chip(chip); @@ -238,6 +237,10 @@ static int __rk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, int ret; u32 off, on; int conf=0; + unsigned long flags; + spinlock_t *lock; + + lock = &pwm_lock[pwm->hwpwm]; off = PWM_RESET; on = PWM_ENABLE | PWM_TIMER_EN; @@ -293,6 +296,7 @@ static int __rk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, if (ret) return ret; #endif + spin_lock_irqsave(lock, flags); barrier(); rk_pwm_writel(pc, pwm->hwpwm, PWM_REG_CTRL,off); @@ -304,6 +308,7 @@ static int __rk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, dsb(); rk_pwm_writel(pc, pwm->hwpwm, PWM_REG_CTRL,on|conf); dsb(); + spin_unlock_irqrestore(lock, flags); #if PWM_CLK clk_disable(pc->clk); @@ -312,18 +317,6 @@ static int __rk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } #endif -static int rk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, - int duty_ns, int period_ns) -{ - unsigned long flags; - spinlock_t *lock; - - lock = &pwm_lock[pwm->hwpwm]; - spin_lock_irqsave(lock, flags); - __rk_pwm_config(chip, pwm, duty_ns, period_ns); - spin_unlock_irqrestore(lock, flags); - return 0; -} static int rk_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) { -- 2.34.1