Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp578307imj; Thu, 7 Feb 2019 08:40:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IYJc2rRW2RAZbzpzRYCIth1tn+JnidcEY15u1Ne4nQ/Dp2DJIIANQkFWDf2Dh+hkYcV41GV X-Received: by 2002:a62:5003:: with SMTP id e3mr17456010pfb.23.1549557656730; Thu, 07 Feb 2019 08:40:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549557656; cv=none; d=google.com; s=arc-20160816; b=CnRrqZCRL11WP/bnLId2x/ejSkQVwzEZg2rXfMZJjnKcZ1wV6CjADH/JLPWeVx5Wq8 qivR1TSuvt5GuPevGjf/N6Uvi7/0QJaa25+y+DuSfUgTjJhO6jCiwXyleNVaoZ5+Ajtd ZAJcXB7dTkI2+tuTDvhCpEPsJEifBiLZTlOzIYlBvS5Y9oeAMAw68CS71YXxp3JI/Znz hsSYiQw3rdPJRHudZlfR9FNR//jdBqvmCwBwrBxw0r/8F3hECjn+GdKMOx3DF+S6SbbH bY61v7QVlJt7dcjw+uvm9K+CdwL0u/0XBdXLtIv3Aq+LE9f9o/PJcEuokLT2zbixVkrS Sv5A== 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=OpGp5N1qm0oEL8OdUpFy3/bLXtikkccIMuS+Hb8XUtA=; b=u1k+q7N7wO06g8kFygzc1F7MpdYfjIfJPQTHq5Fpr93fIAaRss1rvbtxbqOegkjvbK YVHdXXPW/rdYqny4AaB2kdRTRU2DUen9kuIRJrw5erl3kBf8g7MVhovn3FZT0gDMzSgP x+AqRWcJssrijOrxp2k+AuXEp3I908O5x5f5uNqf3+kM/23s1HwTSEgGwMcE/tYmdzZA DM5lJJBWUlOoDtFj5P0A5KjNmH+WUxck2PDRj7nRhNINAhQwJvR49l48EUiFMAFLy4w9 DJZFNbtcB31l9DqklK/1T9atxHksDIW8iJuWmWvtanpBTcaalkLLLWtZFSWh1EuPmjHz hnzw== 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 g21si1114031pgl.114.2019.02.07.08.40.40; Thu, 07 Feb 2019 08:40:56 -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 S1726883AbfBGQjN (ORCPT + 99 others); Thu, 7 Feb 2019 11:39:13 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:41551 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726733AbfBGQjL (ORCPT ); Thu, 7 Feb 2019 11:39:11 -0500 Received: from stefan-Vostro-260.fritz.box ([109.104.54.161]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N4Q8u-1hHjLR1Hdu-011Odb; Thu, 07 Feb 2019 17:38:35 +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 V2 2/2] hwmon: pwm-fan: Add optional regulator support Date: Thu, 7 Feb 2019 17:38:00 +0100 Message-Id: <1549557480-14436-3-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549557480-14436-1-git-send-email-stefan.wahren@i2se.com> References: <1549557480-14436-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:527t2r+5wT4Tj26tDEC6KLuXpAa9eMoa/YYhqOJvj0xK4GUIO4p C0+xemkf1AvTeCutx9FhIk/lTXRRr9mMv0X99kDeDMcHxMw3xHfT4xaG5w5l1yOEldn7E8j KwT94kSC3Mcd/Uqtyc7kf/47mjhJkKxOv5cuUzMdVl/0FCvrMc2lHka6BCqexoXJ/naBkhe 418hulCzLlFCFIFo75ttg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:XwBqw9vFi2s=:HoeoWZEaUFk2xfmoSgAQIR oO+FWxVuRoRKWT1OdHFmtBqLHCwPVyzqUGnHcdoG1cPLjpTrg8Xoouoe46h4b5YFh91U0Jbc6 MIzPA8sVG88m/CvRb3m2qA5xKTePKfT8iJsQyLQ4DTa9bkuWA5LisKb3SkecebYIilS067YNP C7VNu5PFJE0CLYeTIAIlUuHfTc2/1S/CFRTYIT+T2tkZeK6Ei9OMxHyjgTrLYtm4fOVYMewU9 GRzLDIGxZ2BB+vCxtmYQi41bl2OaF17SOmEphGJxnMIbHZwqDjRfoB4LJaIWiTkQAoLDafNQh wuA+zY70gfljNhvTQIYajlYpgy1WXCWhGvAeUZ5Bej3zDQATkO1Nu/hrSY0tbra8glem7MJur 2JMgkz02L0qM0P7esFR1wb6seP/ZIuhhtiLX6A7Lr/WEGsxBztsvVXwUTGN++vKYxKVJOcu/p gM2M9jgYDAxQ2fyHFGlnnJSC+f+hN4gkQBJvIFYOA3Qtr1L5i0p9nd6bFGAN7pkHLMSrHr/Kv crBqbVLz6sSKIwZqQwaJ6qYEJveLaQoKH95AJxEXkKyAPZSmlaSRt1UrIGVN7+REw4Kx3cRJL LNivjqNot6B1iJnpbxAqE8FT1cv4VWquA80lzVaO6shc89HBNqT2HJr/5pkX8+AWmRp3Flbou Lk1okqp6igjZ7g5KShiE+Ru6qk5v+P3Cab1AC0/Th54dyyrUjKtnb0kqqgeDkr/30C0NfQpUl UWYhbTavdLkTqdw464mwTR/14srkg8Zf4iOpxAgtsODUWM7NWkTgIPUmR2Y= 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 | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 2c94482..344915c 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) + ctx->reg_en = NULL; + else + return PTR_ERR(ctx->reg_en); + } 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; } @@ -299,6 +324,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 +348,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