]>
Commit | Line | Data |
---|---|---|
36e3f504 SL |
1 | From a1b958551a9e326ba93e6d6c15db3992ee09f9db Mon Sep 17 00:00:00 2001 |
2 | From: Jonathan Bakker <xc-racer2@live.ca> | |
3 | Date: Mon, 28 Jan 2019 11:13:01 -0800 | |
4 | Subject: Input: pwm-vibra - prevent unbalanced regulator | |
5 | MIME-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | [ Upstream commit 3ca232df9921f083c3b37ba5fbc76f4d9046268b ] | |
10 | ||
11 | pwm_vibrator_stop disables the regulator, but it can be called from | |
12 | multiple places, even when the regulator is already disabled. Fix this | |
13 | by using regulator_is_enabled check when starting and stopping device. | |
14 | ||
15 | Signed-off-by: Jonathan Bakker <xc-racer2@live.ca> | |
16 | Signed-off-by: Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com> | |
17 | Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> | |
18 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
19 | --- | |
20 | drivers/input/misc/pwm-vibra.c | 17 ++++++++++++----- | |
21 | 1 file changed, 12 insertions(+), 5 deletions(-) | |
22 | ||
23 | diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c | |
24 | index 55da191ae550..9df87431d7d4 100644 | |
25 | --- a/drivers/input/misc/pwm-vibra.c | |
26 | +++ b/drivers/input/misc/pwm-vibra.c | |
27 | @@ -34,6 +34,7 @@ struct pwm_vibrator { | |
28 | struct work_struct play_work; | |
29 | u16 level; | |
30 | u32 direction_duty_cycle; | |
31 | + bool vcc_on; | |
32 | }; | |
33 | ||
34 | static int pwm_vibrator_start(struct pwm_vibrator *vibrator) | |
35 | @@ -42,10 +43,13 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator) | |
36 | struct pwm_state state; | |
37 | int err; | |
38 | ||
39 | - err = regulator_enable(vibrator->vcc); | |
40 | - if (err) { | |
41 | - dev_err(pdev, "failed to enable regulator: %d", err); | |
42 | - return err; | |
43 | + if (!vibrator->vcc_on) { | |
44 | + err = regulator_enable(vibrator->vcc); | |
45 | + if (err) { | |
46 | + dev_err(pdev, "failed to enable regulator: %d", err); | |
47 | + return err; | |
48 | + } | |
49 | + vibrator->vcc_on = true; | |
50 | } | |
51 | ||
52 | pwm_get_state(vibrator->pwm, &state); | |
53 | @@ -76,7 +80,10 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator) | |
54 | ||
55 | static void pwm_vibrator_stop(struct pwm_vibrator *vibrator) | |
56 | { | |
57 | - regulator_disable(vibrator->vcc); | |
58 | + if (vibrator->vcc_on) { | |
59 | + regulator_disable(vibrator->vcc); | |
60 | + vibrator->vcc_on = false; | |
61 | + } | |
62 | ||
63 | if (vibrator->pwm_dir) | |
64 | pwm_disable(vibrator->pwm_dir); | |
65 | -- | |
66 | 2.19.1 | |
67 |