1 |
From 1be6854b63eac6438f5ac5f359ce8bbfd16a3693 Mon Sep 17 00:00:00 2001 |
2 |
From: Thierry Reding <treding@nvidia.com> |
3 |
Date: Fri, 21 Sep 2018 12:10:48 +0200 |
4 |
Subject: [PATCH 013/145] hwmon: (pwm-fan) Set fan speed to 0 on suspend |
5 |
|
6 |
[ Upstream commit 95dcd64bc5a27080beaa344edfe5bdcca3d2e7dc ] |
7 |
|
8 |
Technically this is not required because disabling the PWM should be |
9 |
enough. However, when support for atomic operations was implemented in |
10 |
the PWM subsystem, only actual changes to the PWM channel are applied |
11 |
during pwm_config(), which means that during after resume from suspend |
12 |
the old settings won't be applied. |
13 |
|
14 |
One possible solution is for the PWM driver to implement its own PM |
15 |
operations such that settings from before suspend get applied on resume. |
16 |
This has the disadvantage of completely ignoring any particular ordering |
17 |
requirements that PWM user drivers might have, so it is best to leave it |
18 |
up to the user drivers to apply the settings that they want at the |
19 |
appropriate time. |
20 |
|
21 |
Another way to solve this would be to read back the current state of the |
22 |
PWM at the time of resume. That way, in case the configuration was lost |
23 |
during suspend, applying the old settings in PWM user drivers would |
24 |
actually get them applied because they differ from the current settings. |
25 |
However, not all PWM drivers support reading the hardware state, and not |
26 |
all hardware may support it. |
27 |
|
28 |
The best workaround at this point seems to be to let PWM user drivers |
29 |
tell the PWM subsystem that the PWM is turned off by, in addition to |
30 |
disabling it, also setting the duty cycle to 0. This causes the resume |
31 |
operation to apply a configuration that is different from the current |
32 |
configuration, resulting in the proper state from before suspend getting |
33 |
restored. |
34 |
|
35 |
Signed-off-by: Thierry Reding <treding@nvidia.com> |
36 |
Signed-off-by: Guenter Roeck <linux@roeck-us.net> |
37 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
38 |
--- |
39 |
drivers/hwmon/pwm-fan.c | 12 +++++++++++- |
40 |
1 file changed, 11 insertions(+), 1 deletion(-) |
41 |
|
42 |
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c |
43 |
index 7838af58f92d..9d611dd268e1 100644 |
44 |
--- a/drivers/hwmon/pwm-fan.c |
45 |
+++ b/drivers/hwmon/pwm-fan.c |
46 |
@@ -290,9 +290,19 @@ static int pwm_fan_remove(struct platform_device *pdev) |
47 |
static int pwm_fan_suspend(struct device *dev) |
48 |
{ |
49 |
struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); |
50 |
+ struct pwm_args args; |
51 |
+ int ret; |
52 |
+ |
53 |
+ pwm_get_args(ctx->pwm, &args); |
54 |
+ |
55 |
+ if (ctx->pwm_value) { |
56 |
+ ret = pwm_config(ctx->pwm, 0, args.period); |
57 |
+ if (ret < 0) |
58 |
+ return ret; |
59 |
|
60 |
- if (ctx->pwm_value) |
61 |
pwm_disable(ctx->pwm); |
62 |
+ } |
63 |
+ |
64 |
return 0; |
65 |
} |
66 |
|
67 |
-- |
68 |
2.19.1 |
69 |
|