From patchwork Fri Feb 22 13:45:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 10826011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1B8E1823 for ; Fri, 22 Feb 2019 13:46:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF67A3276D for ; Fri, 22 Feb 2019 13:46:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B383C32771; Fri, 22 Feb 2019 13:46:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4CFB3276E for ; Fri, 22 Feb 2019 13:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726737AbfBVNqi (ORCPT ); Fri, 22 Feb 2019 08:46:38 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:56607 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726352AbfBVNqh (ORCPT ); Fri, 22 Feb 2019 08:46:37 -0500 Received: from stefan-Vostro-260.fritz.box ([109.104.42.136]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mf0Jg-1hXrk41Kx8-00ga7M; Fri, 22 Feb 2019 14:46:06 +0100 From: Stefan Wahren To: Kamil Debski , Bartlomiej Zolnierkiewicz , Jean Delvare , Guenter Roeck , Rob Herring , Mark Rutland Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Wahren Subject: [PATCH V3 1/2] dt-bindings: hwmon: Add optional regulator support to pwm-fan Date: Fri, 22 Feb 2019 14:45:23 +0100 Message-Id: <1550843124-10992-2-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550843124-10992-1-git-send-email-stefan.wahren@i2se.com> References: <1550843124-10992-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:8sNvvteVhASqzHNQ09B0UGT5Fzlm4HOrt4iUbWxSNJsvuv+CYVs 1PLP3q9ddTYVVrcCYQUw/9ajTVv7fxilVuxEo50PY6NxrL5s/7QPduQc/dHN7+gq2k1JPLd SYWqVoG265N9Qvsq+yK2587rQk7rXMefmym43sm3mDD8LeioBbxqqB+DCt/VBBCVYT7HMIE 19dZzT4JS5kjG/Qv9Wc1A== X-UI-Out-Filterresults: notjunk:1;V03:K0:DxeKGqHloeE=:FOgaO9BRlNdIYU6uVfayzl KqpzRa8F9Slu4e3ssoVOHnsOd9sOJwXIH1wf6YOQpuAy1TYlhYmEri3IZQDIRjEWHRDcenkVB AQVLWiz/4aqK8hS7goawO4J8aqDOwo6x7q6f1IIrTTG4+Zkw/khRotoIQc43klRGs+FxtUWuT iiOAsDGovMT040f847HgGgp7DRaDbCSE56yaVKKo8+oUi+hbqVvfPmb30WQbIfrJ0DFekuLjE ZnIOnOv+i97X4nZSOCrzrYe9S/rl7o9E2rKwlyZE5g7yk6V+Qw0AfsUaV04hV9+jxPUFi+VzB l5g9lhQf8DACO5GGn8d169wkm2ofBrzBmdNVDo2E7LvPNmZbc1pHMUQ8M5AGhw8hqm9eAkQ3u fEGuvsJoIWc96PUlFPjcTBxs9ASckHzkEINzIzStBXdlhZ2oTLuE48zqCa6kUtMr7NDTZXw82 mOt3TWikQUbze5/ORXYyC35Fhja2qT1nzM8ejgpP9vnSLlrGPAYfqM/ujcm8j03BbVj2BdTQO T2lCuX4XFX+Su0k40jqfK7MeoFYvywLkDnfUNxTnSutPUh2IBZPt9NTb1ciB+2oIyYw87aJLo c7DtX7dH6LtSIQ5Cb93V48o7p4/goIDyarRBfw9M7VCfOXo1m5FRPtgfviUdclQmcxRYENTSV chmmCUopmb6iKsp63Wknc/GGKu1jBF8PHcACAKPWq48D5rv3xGxTgO0+G5EceYaBIqayfLT+D QfhS/2BDAWW0uK4zEbrghEr9vI/dbceO4A6N1ZtSC7qzR9HeaBePencil0Q= Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds an optional regulator support (e.g. switchable supply) to the pwm fan binding. Signed-off-by: Stefan Wahren Reviewed-by: Rob Herring --- Documentation/devicetree/bindings/hwmon/pwm-fan.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/pwm-fan.txt b/Documentation/devicetree/bindings/hwmon/pwm-fan.txt index c6d5332..49ca5d8 100644 --- a/Documentation/devicetree/bindings/hwmon/pwm-fan.txt +++ b/Documentation/devicetree/bindings/hwmon/pwm-fan.txt @@ -6,6 +6,9 @@ Required properties: - cooling-levels : PWM duty cycle values in a range from 0 to 255 which correspond to thermal cooling states +Optional properties: +- fan-supply : phandle to the regulator that provides power to the fan + Example: fan0: pwm-fan { compatible = "pwm-fan"; From patchwork Fri Feb 22 13:45:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 10826009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2443413B5 for ; Fri, 22 Feb 2019 13:46:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1193F3276D for ; Fri, 22 Feb 2019 13:46:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 043A332777; Fri, 22 Feb 2019 13:46:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83EE63276D for ; Fri, 22 Feb 2019 13:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbfBVNqn (ORCPT ); Fri, 22 Feb 2019 08:46:43 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:54349 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726352AbfBVNqm (ORCPT ); Fri, 22 Feb 2019 08:46:42 -0500 Received: from stefan-Vostro-260.fritz.box ([109.104.42.136]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M6DSo-1gzLwE2WRU-006h8U; Fri, 22 Feb 2019 14:46:06 +0100 From: Stefan Wahren To: Kamil Debski , Bartlomiej Zolnierkiewicz , Jean Delvare , Guenter Roeck , Rob Herring , Mark Rutland Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Wahren Subject: [PATCH V3 2/2] hwmon: pwm-fan: Add optional regulator support Date: Fri, 22 Feb 2019 14:45:24 +0100 Message-Id: <1550843124-10992-3-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550843124-10992-1-git-send-email-stefan.wahren@i2se.com> References: <1550843124-10992-1-git-send-email-stefan.wahren@i2se.com> X-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le5lVaSRt3wSQ/6SfoD7mEI= Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/hwmon/pwm-fan.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 2c94482..167221c 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ struct pwm_fan_ctx { struct mutex lock; struct pwm_device *pwm; + struct regulator *reg_en; unsigned int pwm_value; unsigned int pwm_fan_state; unsigned int pwm_fan_max_state; @@ -231,6 +233,21 @@ static int pwm_fan_probe(struct platform_device *pdev) platform_set_drvdata(pdev, ctx); + ctx->reg_en = devm_regulator_get_optional(&pdev->dev, "fan"); + if (IS_ERR(ctx->reg_en)) { + if (PTR_ERR(ctx->reg_en) != -ENODEV) + return PTR_ERR(ctx->reg_en); + + ctx->reg_en = NULL; + } else { + ret = regulator_enable(ctx->reg_en); + if (ret) { + dev_err(&pdev->dev, + "Failed to enable fan supply: %d\n", ret); + return ret; + } + } + ctx->pwm_value = MAX_PWM; /* Set duty cycle to maximum allowed and enable PWM output */ @@ -241,7 +258,7 @@ static int pwm_fan_probe(struct platform_device *pdev) ret = pwm_apply_state(ctx->pwm, &state); if (ret) { dev_err(&pdev->dev, "Failed to configure PWM\n"); - return ret; + goto err_reg_disable; } hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan", @@ -277,6 +294,10 @@ static int pwm_fan_probe(struct platform_device *pdev) state.enabled = false; pwm_apply_state(ctx->pwm, &state); +err_reg_disable: + if (ctx->reg_en) + regulator_disable(ctx->reg_en); + return ret; } @@ -287,6 +308,10 @@ static int pwm_fan_remove(struct platform_device *pdev) thermal_cooling_device_unregister(ctx->cdev); if (ctx->pwm_value) pwm_disable(ctx->pwm); + + if (ctx->reg_en) + regulator_disable(ctx->reg_en); + return 0; } @@ -307,6 +332,14 @@ static int pwm_fan_suspend(struct device *dev) pwm_disable(ctx->pwm); } + if (ctx->reg_en) { + ret = regulator_disable(ctx->reg_en); + if (ret) { + dev_err(dev, "Failed to disable fan supply: %d\n", ret); + return ret; + } + } + return 0; } @@ -317,6 +350,14 @@ static int pwm_fan_resume(struct device *dev) unsigned long duty; int ret; + if (ctx->reg_en) { + ret = regulator_enable(ctx->reg_en); + if (ret) { + dev_err(dev, "Failed to enable fan supply: %d\n", ret); + return ret; + } + } + if (ctx->pwm_value == 0) return 0;