Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3439367imu; Sun, 11 Nov 2018 15:07:33 -0800 (PST) X-Google-Smtp-Source: AJdET5eRR5qJbwMcBkY6pvC0Xe9FL4lBEWIz+pdhm553znbdemhcgLTNct/YpsX+NzA7FLu9PBt4 X-Received: by 2002:a62:4502:: with SMTP id s2-v6mr13668352pfa.31.1541977653106; Sun, 11 Nov 2018 15:07:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977653; cv=none; d=google.com; s=arc-20160816; b=KJw7eStGHa52mFHEaaCPfxpP9j/fE3PFuEPJrQcE6b2HKBcYjWQ3MKkns83zxv6BDD 9AwfxnWAqw1QGvtiIpmOpZQEPJVYdA/Jy9JZ8R/S6H+vo9W/bjMmclwZAP6ZKkMEJl+F 4D+iCBJrY8ue9tmqbtZdARNqkAk6TrlxBcMJSSyWFR22yyrpmLvvkr88yqR8t1my7/s8 lv3oSzsEURdtADwhUPJTH9epPt+7UuFPaHRbUwjWFywTO/LaRmwrO1f9dz89+IcRJEN4 c5cyRsVPRH/fp4faIa9zDZgdf41SnJ1iz8P3YiDBd+qBZhnmTX6XDXNqHQWLmHTVLMv9 PwLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MVQgdJ3qJteXOe4ejI17obrl+c/qCc3gA7jKSz0RdnY=; b=rFSugbWJPwKSc9ynEa5FWy4cMLMNz7sNEIvd6ts15i7AG85VKzWfSScbJdGrnH9mS8 UI6TKPeaSl4kvG4sZNox1/gxIX9yewakbVMFrlJdpqAW2G8e/hif/ng95IKoMITRNJeF /r//d3AA83a+Bj0U/cTdNu88kpTLmT5j4FuxGtgKRscR7KdYHjbh/nLQqxkgNm3aaBU2 /UcEgw8dZkzh/GodVf+monGqZawq6hv0k5Ry7g8V8XJf+d1WDC4PxAPgVGrxuALgxn1G U1DwYPPaTtevJVppdEvplzMMSmU3Z6awFuQLC+ZPYqyQkbhhwRJhpNnKYG3dkFlYJkON vCAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YdpuFX7R; 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 u11-v6si14613425pgh.55.2018.11.11.15.07.18; Sun, 11 Nov 2018 15:07:33 -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=pass header.i=@kernel.org header.s=default header.b=YdpuFX7R; 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 S2390360AbeKLIWK (ORCPT + 99 others); Mon, 12 Nov 2018 03:22:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:51248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390325AbeKLIWK (ORCPT ); Mon, 12 Nov 2018 03:22:10 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 52AFF223C8; Sun, 11 Nov 2018 22:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975533; bh=Uz/5FMAHxGQkJPcDKRcfb0fEPFWIO23T/WpPUWiDCZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YdpuFX7R6+4PIThStBO682i115Cddsl31VFtzHDr7Xlu+mvCwg+WZwXN2k2lAHb5t hKGAmc1gIjeA7UfHMWq+POp4vAJD/8x4O6Cdn9aWYQ0W1Hd/9H9+GL44Z67ql8Tjeh YxWiSbi1RYd6d1kVGTTZQV/4lUCjUCqhQCZP5Ixk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thierry Reding , Guenter Roeck , Sasha Levin Subject: [PATCH 4.14 045/222] hwmon: (pwm-fan) Set fan speed to 0 on suspend Date: Sun, 11 Nov 2018 14:22:22 -0800 Message-Id: <20181111221652.188592617@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/pwm-fan.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -290,9 +290,19 @@ static int pwm_fan_remove(struct platfor 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; }