Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp775729ybc; Sat, 16 Nov 2019 08:29:01 -0800 (PST) X-Google-Smtp-Source: APXvYqx/5TjU2vjkUFe2FZUf3KYJJjVrkRMkMYnZmGbIARHpYIgQQW4npY4yB0cDvCOnaysG/KJe X-Received: by 2002:a17:906:4098:: with SMTP id u24mr10842236ejj.220.1573921741214; Sat, 16 Nov 2019 08:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921741; cv=none; d=google.com; s=arc-20160816; b=xyn+p2Wk10Tmdf4TO6L7svQ17uermuS7DHSjCV8REKtD36mNHjkuQWrlEfdBb0HIaN 60YOfsizinJjjcR2Bo3daAa1jao+B5zBuDcCb7XjKgnsLtZcW2EnwCpN1PgaWdGTVueJ rt+lviQIO9DSalDAhotQT9P8zDEAbx91jvA9+rjRCBrRKgPyKrWXyz2tlkxUGSeRD76R X56ZPEgHzbGz0eEahOjDT6iSqU28XKS7l0P8S8HyRXccCNGupD5ek4eex8BSjk3VLZQ4 U1gaJsvvkoezIhgzPzcV7Tb5kpcwl/NNZ/uZhEvtTki9x/KMGsVdCHLklLkJvFnToodg S7hg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/ML6a+WMeMeXyjNcBjmsXimYVkZEkmbb8go8/8vGwaU=; b=Y6Z1mEAZ5b8RwLiCR62pZV5HdRbeXZeUktI3Hbr+/gRFiEWEBxbVcCFBCK5kb/gVBR 2I4hcqQrRBOXYid/bGUYhWUdq3dv4rrLqr8wTxu8X8HtAzEeRMP5FP/JZJckuPVJTNiA wRcN0pBoBzbYAK+rfRQHxj9Sq0zEXyzgNr+QtoESX32fXJdrJSRzPR5KjQydqYYYdsPI ssQDAV1th16Md8IL3HoppPZpzhwctcsAZYQ8mzyIqERH98lDd0dviw9TT0rICOpqZ0oJ B3Ep4qyjyRHWDGl162fIksW0Ia1Gg9WfOsNmpErjZOkUUAnhTBgKHmyBrYxMEVh32gUI OamA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gwd16+2b; 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 np1si8124602ejb.370.2019.11.16.08.28.35; Sat, 16 Nov 2019 08:29:01 -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=Gwd16+2b; 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 S1728626AbfKPQ0N (ORCPT + 99 others); Sat, 16 Nov 2019 11:26:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:45374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728075AbfKPPl7 (ORCPT ); Sat, 16 Nov 2019 10:41:59 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (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 175912072D; Sat, 16 Nov 2019 15:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918918; bh=pHdX6CY6Rf7zrpKNhcJf+fkTXPMjxTYy8EVKOPNPvA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gwd16+2bHd1BWQ+74DSeLSEXKMyUtIsthSsHYcJ5kbe2TOvPx6GJgewcxIb9GahSX 8ZDNODitjNnHcn/gh+kspwrDGUW9/I1492yhRlQMVOSFiBLDyRN8fN/iMiWDpzM+O/ gkg3NFv4lEScseiE60tWnhpF6YIo9Y8iO4boaUUk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hans de Goede , Thierry Reding , Sasha Levin , linux-pwm@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 042/237] pwm: lpss: Only set update bit if we are actually changing the settings Date: Sat, 16 Nov 2019 10:37:57 -0500 Message-Id: <20191116154113.7417-42-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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