pwm-fan: implement enable GPIO

This commit is contained in:
SwtcR 2018-02-11 06:15:52 +09:00
parent 1a0c6c9b58
commit 995caae57d
2 changed files with 14 additions and 1 deletions

View file

@ -1278,7 +1278,7 @@ source drivers/hwmon/pmbus/Kconfig
config SENSORS_PWM_FAN
tristate "PWM fan"
depends on (PWM && OF) || COMPILE_TEST
depends on (PWM && OF && GPIOLIB && OF_GPIO) || COMPILE_TEST
depends on THERMAL || THERMAL=n
help
If you say yes here you get support for fans connected to PWM lines.

View file

@ -18,6 +18,7 @@
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
@ -31,6 +32,7 @@
struct pwm_fan_ctx {
struct mutex lock;
struct pwm_device *pwm;
struct gpio_desc *enable_gpio;
unsigned int pwm_value;
unsigned int pwm_fan_state;
unsigned int pwm_fan_max_state;
@ -56,6 +58,10 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
ret = pwm_apply_state(ctx->pwm, &state);
if (!ret)
ctx->pwm_value = pwm;
if (ctx->enable_gpio)
gpiod_set_value(ctx->enable_gpio, !!pwm);
exit_set_pwm_err:
mutex_unlock(&ctx->lock);
return ret;
@ -240,6 +246,13 @@ static int pwm_fan_probe(struct platform_device *pdev)
return ret;
}
ctx->enable_gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_HIGH);
if (IS_ERR(ctx->enable_gpio)) {
ctx->enable_gpio = NULL;
} else {
gpiod_set_value(ctx->enable_gpio, 1);
}
hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan",
ctx, pwm_fan_groups);
if (IS_ERR(hwmon)) {