Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp178721imd; Wed, 31 Oct 2018 16:54:42 -0700 (PDT) X-Google-Smtp-Source: AJdET5ezzRY4N32UmwXq2+zqboQzkMMCfkpMuaSba2l7TLLkOliwAutWOshV0VD5E7fZQBfwdj+4 X-Received: by 2002:a63:5357:: with SMTP id t23-v6mr5180811pgl.40.1541030082517; Wed, 31 Oct 2018 16:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541030082; cv=none; d=google.com; s=arc-20160816; b=i3vZSZcpfZcws1Lq1y/MM383brbXaUNmLAVEYSVXeUYgE3OLPqEHwrzWTo4oV1Jt5m eGULvC2dlCreWLQkPnu8BG/I1Yq03Ywaru0g7yBM/8UcqN1A6bdGq3xYroFpfMQ51tON IXEvrzr66VFE9otfAYKg355MPmubiJUo0KWHelueigIpMKlkVrgXiC2VpVpAZDoFKfHZ CWG+oNytjmMcTcgN7WXQK0TXca/Y32TFG7gDByuhsZ5SDWrolEfONoJebrmur6+FZkLn UVat86oVrtVT0xwS5L2AeNtBFI3fXYjg8Aj/Rad2KvfZSQ8Co3mN0GwO05Chawv8OR/X jwyg== 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:dkim-signature; bh=l3o7f8DloVDHiFK0QfrIg3/ocWDswI6R2wpdImOaFUI=; b=SSmyg23r2WFVIvj3eZMuZCvpEuhepCl0sySs9fkXixuKkd4JYsvD6BKwepxNMkU9jA PtvTBNAAItVRScWiEqPIoddVc7nQ4Dxlsgo5QGwztw3MS9+EkkYLigmWAHMqqz25Pikn 8lD69N+5qKLA5UdaG3JxfYXGf3B4CSLHp1tDRFlpD4nr3Kgw6va83mPtn10coUe5CmCp XMILZ6DGW7UEJuFCXK+BjlgxmiMWONQ2dZhndHZ4244X9ORWw2fJ9deTTj/y8U7eNU3L 9ZbHH/N9J8GapmP8mymmRe/+iLWVtEPudqPSkVccPxGSr+EABV4N3qq8LHbmXYQqRpNI tl2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0Tpe26hv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g92-v6si29147371plg.354.2018.10.31.16.54.27; Wed, 31 Oct 2018 16:54:42 -0700 (PDT) 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=pass header.i=@kernel.org header.s=default header.b=0Tpe26hv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727503AbeKAIGG (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:52782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727231AbeKAIGF (ORCPT ); Thu, 1 Nov 2018 04:06:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 283502081B; Wed, 31 Oct 2018 23:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027154; bh=ixUZkOVKcxgbGYsuykHXlGnNiMl6OJKGDCgw9JPoNjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Tpe26hvuOmIiJZ2JnUKFBNohqafOIj/neAjBgMfVnz8/7uemFKBwd63tXweQIg/g 17r8SJ/8EdLLCRQ0euLRsEb2rA7fctBPPJiWHWIR+47NjtDr9IStShwmogBZC/UL03 62DElRsy8nmSuwk8tIF1BMvN4vJpDqfP2RNvJYxI= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Thierry Reding , Guenter Roeck , Sasha Levin Subject: [PATCH AUTOSEL 4.19 013/146] hwmon: (pwm-fan) Set fan speed to 0 on suspend Date: Wed, 31 Oct 2018 19:03:28 -0400 Message-Id: <20181031230541.28822-13-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thierry Reding [ Upstream commit 95dcd64bc5a27080beaa344edfe5bdcca3d2e7dc ] Technically this is not required because disabling the PWM should be enough. However, when support for atomic operations was implemented in the PWM subsystem, only actual changes to the PWM channel are applied during pwm_config(), which means that during after resume from suspend the old settings won't be applied. One possible solution is for the PWM driver to implement its own PM operations such that settings from before suspend get applied on resume. This has the disadvantage of completely ignoring any particular ordering requirements that PWM user drivers might have, so it is best to leave it up to the user drivers to apply the settings that they want at the appropriate time. Another way to solve this would be to read back the current state of the PWM at the time of resume. That way, in case the configuration was lost during suspend, applying the old settings in PWM user drivers would actually get them applied because they differ from the current settings. However, not all PWM drivers support reading the hardware state, and not all hardware may support it. The best workaround at this point seems to be to let PWM user drivers tell the PWM subsystem that the PWM is turned off by, in addition to disabling it, also setting the duty cycle to 0. This causes the resume operation to apply a configuration that is different from the current configuration, resulting in the proper state from before suspend getting restored. Signed-off-by: Thierry Reding Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/pwm-fan.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 7838af58f92d..9d611dd268e1 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -290,9 +290,19 @@ static int pwm_fan_remove(struct platform_device *pdev) static int pwm_fan_suspend(struct device *dev) { struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); + struct pwm_args args; + int ret; + + pwm_get_args(ctx->pwm, &args); + + if (ctx->pwm_value) { + ret = pwm_config(ctx->pwm, 0, args.period); + if (ret < 0) + return ret; - if (ctx->pwm_value) pwm_disable(ctx->pwm); + } + return 0; } -- 2.17.1