aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/pwm-fan.c
diff options
context:
space:
mode:
authorStefan Wahren <stefan.wahren@i2se.com>2019-02-22 08:45:24 -0500
committerGuenter Roeck <linux@roeck-us.net>2019-02-23 12:02:23 -0500
commitb57e1d429397217870595c80219b825d7a6db0c6 (patch)
treeaceb7b2516390f49e45c07bb8c983337830b62b4 /drivers/hwmon/pwm-fan.c
parent29d013ad04010e545f6b51f17b629e3047030105 (diff)
hwmon: (pwm-fan) Add optional regulator support
This adds optional regulator support to the pwm-fan driver. This is necessary for pwm fans which are powered by a switchable supply. Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/pwm-fan.c')
-rw-r--r--drivers/hwmon/pwm-fan.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 2c944825026f..167221c7628a 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -23,6 +23,7 @@
23#include <linux/of.h> 23#include <linux/of.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/pwm.h> 25#include <linux/pwm.h>
26#include <linux/regulator/consumer.h>
26#include <linux/sysfs.h> 27#include <linux/sysfs.h>
27#include <linux/thermal.h> 28#include <linux/thermal.h>
28 29
@@ -31,6 +32,7 @@
31struct pwm_fan_ctx { 32struct pwm_fan_ctx {
32 struct mutex lock; 33 struct mutex lock;
33 struct pwm_device *pwm; 34 struct pwm_device *pwm;
35 struct regulator *reg_en;
34 unsigned int pwm_value; 36 unsigned int pwm_value;
35 unsigned int pwm_fan_state; 37 unsigned int pwm_fan_state;
36 unsigned int pwm_fan_max_state; 38 unsigned int pwm_fan_max_state;
@@ -231,6 +233,21 @@ static int pwm_fan_probe(struct platform_device *pdev)
231 233
232 platform_set_drvdata(pdev, ctx); 234 platform_set_drvdata(pdev, ctx);
233 235
236 ctx->reg_en = devm_regulator_get_optional(&pdev->dev, "fan");
237 if (IS_ERR(ctx->reg_en)) {
238 if (PTR_ERR(ctx->reg_en) != -ENODEV)
239 return PTR_ERR(ctx->reg_en);
240
241 ctx->reg_en = NULL;
242 } else {
243 ret = regulator_enable(ctx->reg_en);
244 if (ret) {
245 dev_err(&pdev->dev,
246 "Failed to enable fan supply: %d\n", ret);
247 return ret;
248 }
249 }
250
234 ctx->pwm_value = MAX_PWM; 251 ctx->pwm_value = MAX_PWM;
235 252
236 /* Set duty cycle to maximum allowed and enable PWM output */ 253 /* Set duty cycle to maximum allowed and enable PWM output */
@@ -241,7 +258,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
241 ret = pwm_apply_state(ctx->pwm, &state); 258 ret = pwm_apply_state(ctx->pwm, &state);
242 if (ret) { 259 if (ret) {
243 dev_err(&pdev->dev, "Failed to configure PWM\n"); 260 dev_err(&pdev->dev, "Failed to configure PWM\n");
244 return ret; 261 goto err_reg_disable;
245 } 262 }
246 263
247 hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan", 264 hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan",
@@ -277,6 +294,10 @@ err_pwm_disable:
277 state.enabled = false; 294 state.enabled = false;
278 pwm_apply_state(ctx->pwm, &state); 295 pwm_apply_state(ctx->pwm, &state);
279 296
297err_reg_disable:
298 if (ctx->reg_en)
299 regulator_disable(ctx->reg_en);
300
280 return ret; 301 return ret;
281} 302}
282 303
@@ -287,6 +308,10 @@ static int pwm_fan_remove(struct platform_device *pdev)
287 thermal_cooling_device_unregister(ctx->cdev); 308 thermal_cooling_device_unregister(ctx->cdev);
288 if (ctx->pwm_value) 309 if (ctx->pwm_value)
289 pwm_disable(ctx->pwm); 310 pwm_disable(ctx->pwm);
311
312 if (ctx->reg_en)
313 regulator_disable(ctx->reg_en);
314
290 return 0; 315 return 0;
291} 316}
292 317
@@ -307,6 +332,14 @@ static int pwm_fan_suspend(struct device *dev)
307 pwm_disable(ctx->pwm); 332 pwm_disable(ctx->pwm);
308 } 333 }
309 334
335 if (ctx->reg_en) {
336 ret = regulator_disable(ctx->reg_en);
337 if (ret) {
338 dev_err(dev, "Failed to disable fan supply: %d\n", ret);
339 return ret;
340 }
341 }
342
310 return 0; 343 return 0;
311} 344}
312 345
@@ -317,6 +350,14 @@ static int pwm_fan_resume(struct device *dev)
317 unsigned long duty; 350 unsigned long duty;
318 int ret; 351 int ret;
319 352
353 if (ctx->reg_en) {
354 ret = regulator_enable(ctx->reg_en);
355 if (ret) {
356 dev_err(dev, "Failed to enable fan supply: %d\n", ret);
357 return ret;
358 }
359 }
360
320 if (ctx->pwm_value == 0) 361 if (ctx->pwm_value == 0)
321 return 0; 362 return 0;
322 363