Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3490323imu; Sun, 11 Nov 2018 16:16:47 -0800 (PST) X-Google-Smtp-Source: AJdET5dii6ElTe2HpFVcjvCX9jpeQ8+48iMmwvBn4yqVqWk3OiW0cHw39V8v12syMX+9Wp9FSYtx X-Received: by 2002:a17:902:142:: with SMTP id 60-v6mr4999127plb.108.1541981807066; Sun, 11 Nov 2018 16:16:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981807; cv=none; d=google.com; s=arc-20160816; b=oSrqDhH6FF6w0/XLVnLzy1Qu9ES/Sa8KChx96/zpMeZyl0gEU7a/EwvuP+brY2MLj4 BsR1bH28ITqoWWgXPjAn2n+aGaVCMNmrGiArOlEw1ShGDs5h5iKPW4L3nxzBc16CT73Z EjC+B4+TyU3axqcidXHnjQAyWPwYrJWSCnSGzaHPxqKx/YM2ZaEqn17b6Nl+XmW7ahL1 vFT/D0f/WoiYq9iWdSJialrb6PGrsAz7Vtyk7eYSg91p6I2EzxJ4WvtEhbuB7DA+faHM AryWKfsxMDKVTaRre6xytuobpVUWVn0hVoME/g/urvbWB3JE68S64CPy8Y/xh0wg8SHn 9UhQ== 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=44IaT0SFV0MV/om5Q12cu/XsrMvrokRmhZNrpoSDoWg=; b=W8BMuyHVlnOSyqMUGoxTi90DvKDl4AHPTyOVhgcRDQ8WZWG/UrHBjh6mkyxlplugQf xZNF9TVL3JMmxmMeCDow1uqAcDd8ZBzzGjw5uyHtPjJ+/5VBp8Q7uBImJbATi3NP5dk7 magTfo5ugePeONpCPCgy/MSi5DFUwXp2cMHEO1mMxFuT4nz/gcsoy3VPoby/nBIH5QTi IbsNGLfhZ13dh6BqlPyxDwK1HKiczYSOBsLg79ltiBKnBP5Yta0/O+hMsSxC6gbx8BuL EC1hK7JI9cPxDX2KnC0qGgShuUab3rc/MzUk9BEkKhDjsuOCsboCBwF+H73zrwpIlVns hYvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SyLRd+X5; 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 k8-v6si9527971plt.144.2018.11.11.16.16.32; Sun, 11 Nov 2018 16:16:47 -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=SyLRd+X5; 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 S1730217AbeKLIRI (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:59760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730202AbeKLIRI (ORCPT ); Mon, 12 Nov 2018 03:17:08 -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 6620E223CA; Sun, 11 Nov 2018 22:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975232; bh=kY+9To193i7Jbj/kpP/H6SN/r6UMDnxAQAY6H1wI6VU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SyLRd+X5QHEKUB1WVYI8dtXuZI7MNBk5UTISFGxsYcPaHT2plu58fWA3bA9R0esyk Tkp1dOrtU0h3cdBjTPBLpuPsH5KuItURniuEWWIBo6Ie8OiybSI4dHngUqStgKP8c8 YksTO3UntabGY/z5GEyw2QgZCI3dbfwXpwSpAVPk= 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.19 059/361] hwmon: (pwm-fan) Set fan speed to 0 on suspend Date: Sun, 11 Nov 2018 14:16:46 -0800 Message-Id: <20181111221628.253067614@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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; }