Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp617179pxk; Thu, 3 Sep 2020 08:20:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLx4vp2nhvVR2o4pJWA+Go62oM9dZ+4CpvmY5hA6FOBfxxbZkHiIe42HGJcdQqZ3PiMZFT X-Received: by 2002:a05:6402:1694:: with SMTP id a20mr3518820edv.286.1599146438573; Thu, 03 Sep 2020 08:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599146438; cv=none; d=google.com; s=arc-20160816; b=ckjrDU+I+jryEgqZJQIcljMsW5rgakc3RfL6d/5c8gfhoFv5kid5/fpoEvv3yAtnXo XfAL8HuVNn6/zwGiE6b1jACP6ZhfWAjmk1j7v8nMJnXVFXL2/0lERqHs/G5jhEk9bPC4 csV2ZW+plIdLWl8vEMx9sAN3W/IfeYdizzh80A/5/vwjl1k4kRp/DQOIuvwTS5CzAI0F yEyw7jc78ZdqUYBiVKysA3/ka0i8SX2IdwKEitxwx/DrHgRC46nHpQItoX8nRkQh6N3b NR3Bjqjiecg69pXf4ZxZNzKV9ewYefHSxrHADDmDOvGxd1vpaA2SLj5W62bUUBTqsPaT g/0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=CQ15tirZpKA58Rq11JF7jkdfBFgYHMCtFMxo14MKJgM=; b=dGkKnpQ9OdXLQ77BiER2u4fjo3ZR4kXxDHyavbj1B4RkDE5Mcp0m3qtA1h+0CAOHLu xk/97m5rKd9SsGnmhOrSCYyB63f5BHhOtkwaUshbqJFAX9HcUrl24fT6BJ8pJv67zNvo nVqazvHDUYV4IJqKcfAvFzMqMpl3rtUgUzVHKisJxTeA7L/rgsfunEadQeAYRfcrqHV+ ZpXWmaoXf3ZUhKAzl60hybpztTC9a3Jzjejl9FBkcXhXUVuoJkotYG9+ygsJPClVpOwT rcDBQ/hkTgMK3DMAjB9dhacM5wPJUg8pt2K6KRxm7zRpebAkfpDSW5W7atfQ+YKy5l6p 0QJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yAdaap5P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nr20si1978930ejb.483.2020.09.03.08.20.14; Thu, 03 Sep 2020 08:20:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yAdaap5P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728646AbgICPT1 (ORCPT + 99 others); Thu, 3 Sep 2020 11:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728557AbgICL1b (ORCPT ); Thu, 3 Sep 2020 07:27:31 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FB47C061247 for ; Thu, 3 Sep 2020 04:18:45 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id e16so2811231wrm.2 for ; Thu, 03 Sep 2020 04:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=CQ15tirZpKA58Rq11JF7jkdfBFgYHMCtFMxo14MKJgM=; b=yAdaap5PB+hSEk2DOwQJho56yttfPUEvELhdmmRyS1aWA6/G07iA1d7B1Aiag5yyRb HBGOzpOR+7eQ1duXllObstGDJ2QrVCfgjTKWh/B5vovtTRM8OkuIkQUL9AhBTOrjZa+k pHHXVEAAZgVR65CNlQhE3F4r74LGaJi72lU8XEOKQ+t+i/pI85BoWmmvEPFkjWMSoLYw Y0zToNSt3UUvWnoGvHkaTgDQDdqPmMhmbOWHsrcJMzCrxqwLEpy6tjCD/6Qvz2ccy9K2 zUijigOpVuxEOqKwN7rrTA89Q0657lSLVrciP+dal70DXma2u0aUNkHoQd9jyF+xtZjs bM1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=CQ15tirZpKA58Rq11JF7jkdfBFgYHMCtFMxo14MKJgM=; b=c0UDi7bT6XWrJaU3qEfP9QZp0gs0CcikY98r6z0PnD94/MGkfcfpjwMchE4Bo7tpgG BwQYl7PLvYfXwIPSWizGHfRdZQqIdjX2hkxAdDGjkWysCc8XnlqFlhQPUeNQYTXgw8ud E3d5NuImr+qzZ2g6MnXd2SPD4H+KPeEGO74gUGLID0It6Kmsy6CrC0mMbN+WSmxGJLLT EX+1drNpg+hdZeOwg0CidWb5VouVc8c/+W3V1PnCfPfyt4O5ORZpc+C1hF1yYFvQfkec 6dJTUuSdGQ2M0Eq2obVZiJO52QkqpcrxL/bvEAMl5w2AJ3wK/t/E25HOOCWLL0B3i1Uy bkCQ== X-Gm-Message-State: AOAM531DPGys0il6IXpK8H/vuEnEB1Rs/Z79C8OXgj7C0ChWlvvy+wES JpaeYHaS1ZrFmd+1FYovccEzYg== X-Received: by 2002:adf:e7ca:: with SMTP id e10mr1860353wrn.236.1599131923615; Thu, 03 Sep 2020 04:18:43 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id z14sm3706113wrh.14.2020.09.03.04.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 04:18:42 -0700 (PDT) Date: Thu, 3 Sep 2020 12:18:40 +0100 From: Daniel Thompson To: Pascal Roeleven Cc: Andrey Lebedev , Thierry Reding , Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , Lee Jones , Maxime Ripard , Chen-Yu Tsai , Philipp Zabel , "open list:PWM SUBSYSTEM" , "moderated list:ARM/Allwinner sunXi SoC support" , open list , Alexandre Belloni , Emil Lenngren Subject: Re: pwm-sun4i: PWM backlight is not turned off on shutdown Message-ID: <20200903111840.vkjevwmwarx2txhe@holly.lan> References: <20200902095402.pombrirqqjdew34b@holly.lan> <913a5324-a7d2-f1d5-701e-1c28359286f2@lebedev.lt> <5302741318a28e39239db08a1f05ecb7@pascalroeleven.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5302741318a28e39239db08a1f05ecb7@pascalroeleven.nl> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 02, 2020 at 09:42:49PM +0200, Pascal Roeleven wrote: > Thank you for adding me. Emil (also added now) and I spent a while on trying > to figure out how to solve this. The Allwinner PWM controller has some > quirks. > > Unfortunately I never got around to perform some more tests and fix it > indefinitely. It's still on my todo list.. > > > On 9/2/20 12:54 PM, Daniel Thompson wrote: > > > There's some rather odd logic in sun4i_pwm_apply() that results in the > > > PWM being disabled twice... once when it applies the initial config > > > and again after waiting for a duty_cycle. > > That's true. To properly turn off the controller you have to turn the > controller off first and keep the gate on for at least two full clock > cycles. Then the gate must be turned off. Otherwise it might get stuck. > That's probably what is trying to be done here. > > On 2020-09-02 21:05, Andrey Lebedev wrote: > > Indeed, this fixes the issue for me. The display goes dark reliably on > > writing 4 to "/sys/.../bl_power" as well as when system is halted. I did > > not notice any negative side effects so far. > > Problems start to arise when combining bl_power and brightness setting in a > particular order or at the same time (with for example a backlight driver > which sets both bl_power and brightness). I can't recall exactly what caused > problems and when, but one thing I was sure of is that timing was of the > essence. Once I added some delays here and there it started to work. > > If this patch works for you then that's great, but unfortunately it isn't a > complete solution. Forgive my poking but it does look to me like Andrey may have a point about d3817a647059 ("pwm: sun4i: Remove redundant needs_delay"). I've not got this hardware so I can't comment on whether the current code is correct or not. However, after reviewing d3817a647059, it is certainly looks like the patch does not actually implement what the patch description says it does. In fact, by activating previously unreachable code, it appears to introduces exactly the regression described by Andrey. > From d3817a647059a3e5f8791e9b7225d194985aa75f Mon Sep 17 00:00:00 2001 > From: Pascal Roeleven > Date: Tue, 17 Mar 2020 16:59:03 +0100 > Subject: [PATCH] pwm: sun4i: Remove redundant needs_delay > > 'needs_delay' does now always evaluate to true, so remove all > occurrences. In other words, all paths that test !needs_delay[pwm->hwpwm] are unreachable... > Signed-off-by: Pascal Roeleven > Signed-off-by: Thierry Reding > --- > drivers/pwm/pwm-sun4i.c | 13 ++----------- > 1 file changed, 2 insertions(+), 11 deletions(-) > > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c > index 3e3efa6c768f..5c677c563349 100644 > --- a/drivers/pwm/pwm-sun4i.c > +++ b/drivers/pwm/pwm-sun4i.c > @@ -90,7 +90,6 @@ struct sun4i_pwm_chip { > spinlock_t ctrl_lock; > const struct sun4i_pwm_data *data; > unsigned long next_period[2]; > - bool needs_delay[2]; > }; > > static inline struct sun4i_pwm_chip *to_sun4i_pwm_chip(struct pwm_chip *chip) > @@ -287,7 +286,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > sun4i_pwm_writel(sun4i_pwm, val, PWM_CH_PRD(pwm->hwpwm)); > sun4i_pwm->next_period[pwm->hwpwm] = jiffies + > usecs_to_jiffies(cstate.period / 1000 + 1); > - sun4i_pwm->needs_delay[pwm->hwpwm] = true; > > if (state->polarity != PWM_POLARITY_NORMAL) > ctrl &= ~BIT_CH(PWM_ACT_STATE, pwm->hwpwm); > @@ -298,7 +296,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > > if (state->enabled) { > ctrl |= BIT_CH(PWM_EN, pwm->hwpwm); > - } else if (!sun4i_pwm->needs_delay[pwm->hwpwm]) { > + } else { ... but this previously unreachable path will now be executed if state->enabled is false. > ctrl &= ~BIT_CH(PWM_EN, pwm->hwpwm); > ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); > } > @@ -310,15 +308,9 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > if (state->enabled) > return 0; > > - if (!sun4i_pwm->needs_delay[pwm->hwpwm]) { > - clk_disable_unprepare(sun4i_pwm->clk); > - return 0; > - } > - This unreachable path is correctly removed. > /* We need a full period to elapse before disabling the channel. */ > now = jiffies; > - if (sun4i_pwm->needs_delay[pwm->hwpwm] && This unconditionally true expression is also correctly removed. In short this patch changes behaviour in a manner that could not be predicted from the patch description. Daniel. > - time_before(now, sun4i_pwm->next_period[pwm->hwpwm])) { > + if (time_before(now, sun4i_pwm->next_period[pwm->hwpwm])) { > delay_us = jiffies_to_usecs(sun4i_pwm->next_period[pwm->hwpwm] - > now); > if ((delay_us / 500) > MAX_UDELAY_MS) > @@ -326,7 +318,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > else > usleep_range(delay_us, delay_us * 2); > } > - sun4i_pwm->needs_delay[pwm->hwpwm] = false; > > spin_lock(&sun4i_pwm->ctrl_lock); > ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);