Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp692222imj; Thu, 7 Feb 2019 10:18:59 -0800 (PST) X-Google-Smtp-Source: AHgI3IZg9rm8v+LXIlPk8uR7hPYVwyDouZtgNR9I73UPps2QJ87P0szpBQtwGLzd2i7SZJhb0wAj X-Received: by 2002:a62:31c1:: with SMTP id x184mr17983978pfx.204.1549563539320; Thu, 07 Feb 2019 10:18:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549563539; cv=none; d=google.com; s=arc-20160816; b=AF9HIhKAtGpLmBvfcGuoMYgj2Hj/NzgTnCtFDbeMuGHy4dV2SCDg+PsiGjwm8e1P3h exPiZEBW+kQQrsucBsZ8SrPdquuUgJEQkd1oz17fdjUJP1/jwPpRrWGz6ekhtdME43x5 myoNGRCtN8gilVeFR5qIU3HcNPqIWvqDFtlDx60CWKSxuZOYe+aOB/vIvcxzEr28rJL+ P4WBmmYUSbydc50wgdtSf6OIWpt527Vnb3cyuPpwsX5YfY9Z/DZZQ43iGpvJSGBplQ6g h9GJPCjhyPw6HAv313WyC4l0dQgZzLRPGePFjJzGtsHNpT76gfWvUr3QkvIfJn2a+O3y 9u5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yqYYiqjS6eJr9g7jLPNaaxd40OapnbzFHmDcUHc4DwQ=; b=lrQfqQryNAMMcwQXCx4JB5Fg7qxU6sUwA0l95JVGGrfmMRdtb2aDs40QwF/HPkD/qx gJXTFudJPfg7h5xlHWrZMJyz3UhSLld4QdqAprlbP6JHIoYcsFPMomkZN3TQi2Yrscdb E166gtg4rZatVGhPT3FaAHy+/Mw2+Q+5CJdR35Gn2uwbuoM9hV7YJmBmqEuUXY0+HcrA FuigHXfDcHkBU/gY+IDC3cWz/NOxp2DKQEERKSQ73OpEz84Czn/Ri4LRi0KYYsPA7pfJ 59pqEJ2WAQXlmi+uy6ktMuAo9uL7B9MdwEP1j1DGdRvHJ3iEQMa0gXsTdxetZ12Yrb+v UUvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aUizLL1D; 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 62si8887473pgb.298.2019.02.07.10.18.43; Thu, 07 Feb 2019 10:18:59 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aUizLL1D; 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 S1727019AbfBGSSa (ORCPT + 99 others); Thu, 7 Feb 2019 13:18:30 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36907 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbfBGSSa (ORCPT ); Thu, 7 Feb 2019 13:18:30 -0500 Received: by mail-pl1-f194.google.com with SMTP id b5so307710plr.4; Thu, 07 Feb 2019 10:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=yqYYiqjS6eJr9g7jLPNaaxd40OapnbzFHmDcUHc4DwQ=; b=aUizLL1DZBI1MpfVhWKXxJjV1SYoMV4WI0FetOUsG4ongauB5cPq+tw0hTHFX7CPJU pGLFEKsvkTnUsILsZVej+C6rr38Ei4Py5ul0c2ewEf/4TuMmAqF3427NfdA0J03gwtAd +czVLV6Ge+/kg2Rhf0PKH8mwtcIUAuwHMhv4NJLpAs2jcET/nuV0gFgw4Wz8/w2PF50M OlvZ0OnDDc1CWZ3SdztnC6ei3FEzgPzYvQ+ZcBAjZ168/nT2/zkM99we1mOpD1OKFFYo ZpPJbueiuRBbD/e/OsdRPlAzU95BUxUdmKIFsP6NVkedfJyGDZ0bnLxWQIiXcKh8UY1G TCuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=yqYYiqjS6eJr9g7jLPNaaxd40OapnbzFHmDcUHc4DwQ=; b=sD78ExLl94M0dl5eKvGfCdG1fl/NPxoEaF0VuDhjqFGvvPWYQSI/bhRwGM/cn381MM 6mkYbaNjfjVGnssHUkbU0xka/FcKG3Xf9tBxBhlrETjdcOQRDC9RYN2vgHkNKDKHGoQB EUYAhSIqliSEPNyFIki7msenYCnutjuEPFZsoMVIHTbjz8xojYEuzrwZ8BO92B13XxaR fA58S1d3fvY22tcspkrfO3YHuWwVeARTUhMt68NsEyYxqnuMM2O4H+gJg8f2d6LHWXm2 H5is7A10JoJpdSVi67uuPD8Ems86lRERvJyZTkK5VNyU1sFQSFFS4WwdlAk5A3Jhwaqz eH1A== X-Gm-Message-State: AHQUAublhTwL+Y80iegZ19aCMNgXybBDXLBbsz2PArHnTb4d43DGFPvH kHuV3Hbxmhk7/8tQaqE/4z8= X-Received: by 2002:a17:902:622:: with SMTP id 31mr17539959plg.171.1549563509093; Thu, 07 Feb 2019 10:18:29 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id f20sm11972086pfn.177.2019.02.07.10.18.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Feb 2019 10:18:27 -0800 (PST) Date: Thu, 7 Feb 2019 10:18:26 -0800 From: Guenter Roeck To: Stefan Wahren Cc: Kamil Debski , Bartlomiej Zolnierkiewicz , Jean Delvare , Rob Herring , Mark Rutland , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2 2/2] hwmon: pwm-fan: Add optional regulator support Message-ID: <20190207181826.GA27492@roeck-us.net> References: <1549557480-14436-1-git-send-email-stefan.wahren@i2se.com> <1549557480-14436-3-git-send-email-stefan.wahren@i2se.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1549557480-14436-3-git-send-email-stefan.wahren@i2se.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 07, 2019 at 05:38:00PM +0100, Stefan Wahren wrote: > 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); if PTR_ERR(ctx->reg_en) != -ENODEV) return PTR_ERR(ctx->reg_en); ctx->reg_en = NULL; would be a bit easier to read and avoid an else. > + } 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); This is a bit weird. The error is returned to the caller, but only if ctx->pwm_value is 0. Otherwise it is ignored. This warrants an explanation (and some selling) if it is on purpose. > + } > + > 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); Does it really make sense here to ignore this error ? After all, the fan will likely not work if that error really happens. Doesn't that count as resume failure ? > + } > + > if (ctx->pwm_value == 0) > return 0; > > -- > 2.7.4 >