Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4889529imu; Tue, 29 Jan 2019 09:10:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN7w0X1b4a2DZ8zDAGDZe7ytXE8qmttbmijyDxdaBATXb1A1KgHWTUoua0SCAhXlJtlLRS7Q X-Received: by 2002:a63:334a:: with SMTP id z71mr24618902pgz.400.1548781826824; Tue, 29 Jan 2019 09:10:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548781826; cv=none; d=google.com; s=arc-20160816; b=OcZBGCLP3r+cQN1toTVnbVdt1QZGL0xXtbnVN6Nj4yrNm0+56fv0pa4LSs52PlTeHc RyUJVUJDlbvG6fNjemEejQE3eCT1zzrGVMv3bxks8HIgzQCiIs60gQ9rkn/VKxaelH2B UGCE4VjUAm8RmkB29uNgtMSBlFA0RiEgXTiCzmCgKKOJ0ar+bMLiqCzUtrK8TMuzdPXl acCsNht5lZPJqueAV1nZC6FRLVSQwSYoibfvL6clKiN1iKP/Pp11yDwcL+x0FU4gEiCL Vytzu9CAWCwGt9yIyU7eRxSkNk71/0h/to9/daGac5CgWieGF715EUA5z7Ehu7Fv5jTk v3bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=OSQ+tnkN6RG1bQj0gNec2iZeg8ZrNOYCn4C73vhEpUA=; b=aFMxu0jFxecouVuSKFPcdMG5YeNCplaIHdFsQ9LzWlrpFohOsMEoo86nlDx9KqNVqL jE8dNQHlPSRDwsO7mA5OTFi9nVraUkQ/6XghI6LFi5s178Madyvf3mcXq5cyYcQwoRfa Sa8qxHqhOLIewBceKvzMJp21ZlDi5pygmTQsNV8Mj5xewhmNmJ4vpLA4snXIntXTQJnn D20Cnyk1PX3yZhRHIsfw30oJ7dVetiL0dqfC7x+fZNuHPZOd3Sepb1o3OvXtsIqKRjKI j+oNbAq+WfAwwOjyIySGbIKo/0m0i05wpj9JqRRSNXIQ4eqhJyjIRX9SnKDpiJYeSpnv /O7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si5549425ple.281.2019.01.29.09.10.11; Tue, 29 Jan 2019 09:10:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728791AbfA2RIU (ORCPT + 99 others); Tue, 29 Jan 2019 12:08:20 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:55109 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727499AbfA2RIQ (ORCPT ); Tue, 29 Jan 2019 12:08:16 -0500 Received: from stefan-Vostro-260.fritz.box ([109.104.39.36]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N4h7p-1hGpFw2Ii7-011fhB; Tue, 29 Jan 2019 18:07:43 +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 2/2] hwmon: pwm-fan: Add optional regulator support Date: Tue, 29 Jan 2019 18:07:11 +0100 Message-Id: <1548781631-5736-2-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548781631-5736-1-git-send-email-stefan.wahren@i2se.com> References: <1548781631-5736-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:jtwELjB805zwxqlcR6KebkiceUBiO0fSX6J2nGv0aL+sLxhIYJx oN2dI/J/CdLZIDZc/kcMDfhUlEaIYCChiaiQc9TcDIz0nmgPv0mOQVUKafnuX0e04HyBWPD VLR1JqsDHzSamsLLr3UaM08IURRIC0X2eq6hSGym4NAPuiwZz+JojmUkYd2thCaHKnbDmL6 WsYARiQQwcoWV8RXpRPag== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:sieGw/6SFdw=:QMBajiXet03YKU6cgp/CMn BUh8SyL4rtW5nESaQGiS3W3wExw8+WgjPw5OqyGMiolEziNjiSbihVG4mwoDHaenuOQAM3m9w Rl1wMvd+u85wG8cqEKfVYmkmRit9yoIe8QiD5KQKv8MYGAFRJaoQA06TKVYbBEjrUe1mS/RhY H5W3FGiuOE7Wq013yKu0nyKK28xjmUXkjvC2uKVq4d2uLw2J3aAI+TRcnAL47F/R9vodGsmnF dP2Zj8l1Z27F2HpC+LEtQE9lX2Abn9MUoI+ouUNrMkNNLQXktg3R4uaASb/o62sB+tILpkdmf iNYv7einDGojWYb9usKJihNjkjzV4+eZQ6vNuwmWsVaQtDlBYG9/vTpo5n27AmKIcKmO1Z+lj qQnMFXkgGXMj+P/aSq5oZcWc0Jk6g5bwpd1r0eLJPAiDpjtsWnGS1VcsWdx9loYZnsa0T3aLh f5Co7xAIam7+G6TY8fXu63AUfRmi58q8yFiWZpWG6WjeKyFWZXec96STiPX/HiI6SBeHuUFkC +3r/p5SJPXzQoEZJ9E7KcuQk2rUL0qlgoORliC1pNug6YsbhE2lbEquoyVm56TEV8vfJIy+eR O/YmyVEiKnX7bm0i1A8/1uTsmPkZfM6DMX1X8ITEB3Aeb7vSWSg1R0lawF5xdMF8uRlihrJst NzPKJm6mRsWQcPxESEAKIm5enpDs4Ga7g2TMPBYQdWdoVTjJp0EXgwUhjZWvMMZlbWYhJm7Q7 NNF3bjCtJb8dlmg0B+3DI7gkI0rQGehDd/8CaVFqCHHmtB8TEtQaNEtLJvk= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 2c94482..9e0591e 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; @@ -244,6 +246,23 @@ static int pwm_fan_probe(struct platform_device *pdev) return ret; } + ctx->reg_en = devm_regulator_get_optional(&pdev->dev, "fan"); + if (!IS_ERR(ctx->reg_en)) { + ret = regulator_enable(ctx->reg_en); + if (ret) + dev_err(&pdev->dev, + "Failed to enable fan supply: %d\n", ret); + } else { + switch (PTR_ERR(ctx->reg_en)) { + case -ENODEV: + case -ENOSYS: + ctx->reg_en = NULL; + break; + default: + return PTR_ERR(ctx->reg_en); + } + } + hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan", ctx, pwm_fan_groups); if (IS_ERR(hwmon)) { @@ -287,6 +306,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; } @@ -299,6 +322,12 @@ static int pwm_fan_suspend(struct device *dev) pwm_get_args(ctx->pwm, &args); + if (ctx->reg_en) { + ret = regulator_disable(ctx->reg_en); + if (ret) + dev_err(dev, "Failed to disable fan supply: %d\n", ret); + } + if (ctx->pwm_value) { ret = pwm_config(ctx->pwm, 0, args.period); if (ret < 0) @@ -317,6 +346,12 @@ 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); + } + if (ctx->pwm_value == 0) return 0; -- 2.7.4