Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6029139ybc; Wed, 27 Nov 2019 13:41:36 -0800 (PST) X-Google-Smtp-Source: APXvYqw0FUgGrHx9NJs47DPT2mvDtJ9GvgiHz+Gc2IiY5/YZZwebSmbeqKoZnfWj6KQT+xe5IDpZ X-Received: by 2002:a17:906:2508:: with SMTP id i8mr38278019ejb.323.1574890896039; Wed, 27 Nov 2019 13:41:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890896; cv=none; d=google.com; s=arc-20160816; b=cjDKuxpndhAf/HDncZzCeQH7ClaDHeOB5nKb/vG7NSCHfCz23btqtFpl/3GHVsf6kp 1fnyeHFEcImDcgIyuLy25+ErPTkUNHyEMkR0kTa1oy4Be0o8SejeQFtg9dLckOzRLUtX lPFvNgWqtRnegaESR6u89NlcigtAWaf4nwDAOABvU5sKr4s8MCMIdzI0Rzb5jllTNWdq nVOkal8FV1hP5WIG3VOrzk1UmN33H6oH6+tjhEJQsh3ALv0Tdv4sSXYk7YGYgroKEY8j FLzDHxr6RW7ZkYSw07sc1MflgBKeE01XOA7rEC2rkfxWSkGF+VZrijSPA/6IVzgx/VRF aSJA== 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=/ML6a+WMeMeXyjNcBjmsXimYVkZEkmbb8go8/8vGwaU=; b=WvOsfVliy45EGyqpcrlfRlyPBRYhmfZS7MG//XkWg5OW44zFp7W812MkwxEdZ/FuuS XBu6i0Rqqgkpk6jxMABgAOSp0txkwf786yuqaQQ+00EtajLlm9NFo9zH66NX1ld9kxRU hhY3gU+T/3TywRsv8n5PVUxP6XgtSFZq0vSZvTzo3RnuvZe+TNeCFDg5Y29s/MOBRpwp rFbzFnFek9ljmpDALpFyF0SEQtKLjeonViiEquZzx1YpXdISjZ8wBo3r/HsJuQlSSmse SVU50Pr4thIUcZDFqRE/YlHGsJ1AzQDqhCRcX6IzF6ehqdHlFfT5o2hBnKi4lM+si10U /t9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m4sI+P3Y; 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 a18si10313943ejj.100.2019.11.27.13.41.12; Wed, 27 Nov 2019 13:41:36 -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=m4sI+P3Y; 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 S1730013AbfK0Ure (ORCPT + 99 others); Wed, 27 Nov 2019 15:47:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:60412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729995AbfK0Urb (ORCPT ); Wed, 27 Nov 2019 15:47:31 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 E512B217C3; Wed, 27 Nov 2019 20:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887650; bh=pHdX6CY6Rf7zrpKNhcJf+fkTXPMjxTYy8EVKOPNPvA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4sI+P3YmDi9KdUKQA04RZma9oI18Qik8dE0q/fzcveLsVeA8sgIde2oOJlDhLPW+ sy9FX1zciYwsq+EjvwPs5fPkIM6N2TE964GlZvmWmpwvbJfVQEMUpSIiZj6a50lrAN HFsSAgdhzq3iB6hP0HOcIRgzX2utmBPCYX7o0ztM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Thierry Reding , Sasha Levin Subject: [PATCH 4.14 040/211] pwm: lpss: Only set update bit if we are actually changing the settings Date: Wed, 27 Nov 2019 21:29:33 +0100 Message-Id: <20191127203056.021797006@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Hans de Goede [ Upstream commit 2153bbc12f77fb2203276befc0f0dddbfb023bb1 ] According to the datasheet the update bit must be set if the on-time-div or the base-unit changes. Now that we properly order device resume on Cherry Trail so that the GFX0 _PS0 method no longer exits with an error, we end up with a sequence of events where we are writing the same values twice in a row. First the _PS0 method restores the duty cycle of 0% the GPU driver set on suspend and then the GPU driver first updates just the enabled bit in the pwm_state from 0 to 1, causing us to write the same values again, before restoring the pre-suspend duty-cycle in a separate pwm_apply call. When writing the update bit the second time, without changing any of the values the update bit clears immediately / instantly, instead of staying 1 for a while as usual. After this the next setting of the update bit seems to be ignored, causing the restoring of the pre-suspend duty-cycle to not get applied. This makes the backlight come up with a 0% dutycycle after suspend/resume. Any further brightness changes after this do work. This commit moves the setting of the update bit into pwm_lpss_prepare() and only sets the bit if we have actually changed any of the values. This avoids the setting of the update bit the second time we configure the PWM to 0% dutycycle, this fixes the backlight coming up with 0% duty-cycle after a suspend/resume. Signed-off-by: Hans de Goede Signed-off-by: Thierry Reding Signed-off-by: Sasha Levin --- drivers/pwm/pwm-lpss.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c index 4721a264bac25..1e69c1c9ec096 100644 --- a/drivers/pwm/pwm-lpss.c +++ b/drivers/pwm/pwm-lpss.c @@ -97,7 +97,7 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm, unsigned long long on_time_div; unsigned long c = lpwm->info->clk_rate, base_unit_range; unsigned long long base_unit, freq = NSEC_PER_SEC; - u32 ctrl; + u32 orig_ctrl, ctrl; do_div(freq, period_ns); @@ -114,13 +114,17 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm, do_div(on_time_div, period_ns); on_time_div = 255ULL - on_time_div; - ctrl = pwm_lpss_read(pwm); + orig_ctrl = ctrl = pwm_lpss_read(pwm); ctrl &= ~PWM_ON_TIME_DIV_MASK; ctrl &= ~(base_unit_range << PWM_BASE_UNIT_SHIFT); base_unit &= base_unit_range; ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT; ctrl |= on_time_div; - pwm_lpss_write(pwm, ctrl); + + if (orig_ctrl != ctrl) { + pwm_lpss_write(pwm, ctrl); + pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE); + } } static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond) @@ -144,7 +148,6 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, return ret; } pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); - pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE); pwm_lpss_cond_enable(pwm, lpwm->info->bypass == false); ret = pwm_lpss_wait_for_update(pwm); if (ret) { @@ -157,7 +160,6 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (ret) return ret; pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); - pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE); return pwm_lpss_wait_for_update(pwm); } } else if (pwm_is_enabled(pwm)) { -- 2.20.1