From 995caae57d3af96faab2342f7f04e528b274e3cb Mon Sep 17 00:00:00 2001 From: SwtcR Date: Sun, 11 Feb 2018 06:15:52 +0900 Subject: [PATCH] pwm-fan: implement enable GPIO --- drivers/hwmon/Kconfig | 2 +- drivers/hwmon/pwm-fan.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index ef23553ff5cb..340cf085fa99 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -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. diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 70cc0d134f3c..c0cf501700b2 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -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)) {