Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp689202pxk; Wed, 2 Sep 2020 12:08:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxptSCjqMpktHjdW4URDreBjhu9PK4MTt0XemCvMtmVlrQBGALDq7/UacMOF2sz777jyBFw X-Received: by 2002:a05:6402:206d:: with SMTP id bd13mr1560025edb.57.1599073680936; Wed, 02 Sep 2020 12:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599073680; cv=none; d=google.com; s=arc-20160816; b=ibhreUj3CzrCut3WeCwRvaJo4Y+YVa5uhgBryJpflRzAAFMtx1yxba0DyTtOVBt0nA zOf2o4CbD9YVYCItaM6GBqSDt/sorzrGTMbtKKKD43Pm8ffaZriHePZCpTb04jKpWXDh Xt6zrMDxWBa0P6g1pYF6uJebICBZ4+2LJ5IYr5buYRcG7p7zb0QdM4huZvP7LdQjd6SS mDQWSjgIsUnvchCxBySPNY5LgIHvGGrUENYJ75B0Qx3nZdP68XY7LE8FB3ncsqS3wSsL IcwOwFf050UJbtCfOR88+LF6gQ77HngcH+ZhMdyeFIf0goKNWfAuKYNgy23BIyEWdPv0 zrUg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:from:references:cc:to:dkim-signature; bh=UF/XIR74MvxU7fQ8KNSrULOE9J3YgJdlsGJ5K2HXAfw=; b=bM/Rt2dY0Xm66FL+2ESPqtP4VDTukE0bu3ucRHrUM2bzT9x/A3VEA4t8T0HBKEvRQ4 lcBcuMInc75ggEa0jqksFDjb93AMd+HQpiy3JZWaBN7rr71V1vKVj1HatPo5Z8V73GBX Z77nHZV2WBwHdDKzNBON3Sm6MnLzmr2tHPkaemvk+WJQHP8lozbB/kwtJUFZiplVGAaa O6hoCqIdOpCgALs+ySWlxoe+zHl3fUnVWNhv1c5BHKHW7kzpIobaHLqPyQ3rigBOPOGy SF1a0AH92RONKyWH5TlJtBKKOFvU+pxaDdsFv3F+lp0esWG5BHaJVoU6c4KSiCAl0fJG O21w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lebedev-lt.20150623.gappssmtp.com header.s=20150623 header.b=i2ub9Cyd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si83185edr.508.2020.09.02.12.07.36; Wed, 02 Sep 2020 12:08:00 -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=@lebedev-lt.20150623.gappssmtp.com header.s=20150623 header.b=i2ub9Cyd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbgIBTGB (ORCPT + 99 others); Wed, 2 Sep 2020 15:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726567AbgIBTF6 (ORCPT ); Wed, 2 Sep 2020 15:05:58 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F1CAC061244 for ; Wed, 2 Sep 2020 12:05:57 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id r13so512922ljm.0 for ; Wed, 02 Sep 2020 12:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lebedev-lt.20150623.gappssmtp.com; s=20150623; h=to:cc:references:from:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=UF/XIR74MvxU7fQ8KNSrULOE9J3YgJdlsGJ5K2HXAfw=; b=i2ub9Cyd6rAkAYSxJdki3c/ea+689f9BQENqIOXZwzIMffbXKOLoaR/O+rqkZmI0Ke PGctcDMl/R/m0bstTyuzWIFj5NeEPtcg5ggv+61tBKZrY4lhOTqaeAE/Ef4TIF0T2ePH +cKNWzijR14/2kVxNh42JyKVCYGH7tEQ2Ulca4rPHbhOQb5GHAgyQEFEuygPxhDmC163 +nC+a5ElViINkxhoVItF5WVAD1ObixGCppuK8DWVPaeHuQEgA3qs/7z5CkJAq6NQsC8x Uw196KtctH7HDcheDN+klCIoF10qspe109Vy8KAg1/K+Pc18kganDGV/S+FAlb2O14/i ySug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=UF/XIR74MvxU7fQ8KNSrULOE9J3YgJdlsGJ5K2HXAfw=; b=oRXPFd/1Z6165uaYbKUsL5rHI2Jea+BCcq8ZeiIWvHEWjcioP+VIVcNkYi4W9mf0JH CLNFmktAqHZhQqFWWZh/SKeSzSpilt/qeYaLE+3isySJiODW8N4xS1xgHEO1V0lkHydv 0GYECfdhHxFLeFI/0S22WtItTCTr/R/Vn/yAl1pjOzSBiJUU39iVNUyOTfKLiZVHkHJ/ 4mHu/xTBPcbv3usqwvlZDLcFRyfUpd9MzgIELL1K0BIfZxGJhU222geZMVg2RyIRJM/9 EuIi9xAE0b9L184rkNtrn7Iy+byGrIRjFb48Ky9VCVamCtDIMheIOPnmX4GQ5UjVPnt2 c4Pw== X-Gm-Message-State: AOAM532DiWMkaFGNHHKfh402GVYCBjwD6vVuhjrjnpbwOLdIBibDv8du j9GnR1Rtm/3Yl3qk2E1bT4bTfA== X-Received: by 2002:a2e:a0d5:: with SMTP id f21mr4253999ljm.364.1599073555606; Wed, 02 Sep 2020 12:05:55 -0700 (PDT) Received: from [192.168.1.108] ([5.20.204.163]) by smtp.gmail.com with ESMTPSA id z8sm106506ljh.19.2020.09.02.12.05.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Sep 2020 12:05:55 -0700 (PDT) To: Daniel Thompson Cc: Thierry Reding , =?UTF-8?Q?Uwe_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 , Pascal Roeleven References: <20200902095402.pombrirqqjdew34b@holly.lan> From: Andrey Lebedev Autocrypt: addr=andrey@lebedev.lt; keydata= mQINBFNhFoYBEADieS1U4VUTLCgqijeQ3bXGArq7PCasU2OBJ7Bo9vrENOudkIxy3Xhiip5r Rh/agkYp4jQ0ZYnBb6KARVh6DwujVpV4IDbG+QwpoOy/mC9g7CZO0akLW6LtQXrd/kjqQIfq Enf0qT1rcf2XJJ8EKbErB7mHqWsqqWocrk2Bc5PS2+a/43G2jCchy4TnvPvihQ40CpF1XWrP qVzm7brtQ3IyjqD2RLNKVC8/+hn51RJjYggcclyVryS5mb4+8l+LBxsZkqzN9d6r2AW7VEqi Q5EARjLgbzRO1x6rkAL69/eXLJ9SXQFHtBpLny9nE72ThFA9PchT7bhVgTgMrl9tYgmp62io wKfRr8FBdQKSTFa67foL1d2S10IpHbM1z+4+g2KGAzYeYedSnyryptyQUWcYF4kcyk9W9U4f sR/kFAYJ2jj7esSJn7QlqyMB9fr9N9HqewU53gAhlCyagveN8UOEzkBZkCFGd1ECAgoN5jri dNIPJ0sprnLxGPwzU8iAQQY16WIDiJ7fobPU9wlZ6+aGdxC8aP+cT7cpLhkiE5tFDrtE7OqP UI9dXFTKirpKe2SazAdLV75OmNkwJATsLIFWwSRoLZ1qGFS/RQQdZsPd1mFeW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vi6jaJqcqvZlkmBLHwpR66dE3ZrA5cxSdJWmWZQ07QOFdUdAF1m MRt9tMZNfJS8d3ptHvwuaAfaDNiZQwhZa6c3zcq0Ys0tkAbln728R2fyI8EbzUA5fwI71yV8 WWQEZuQZcHGOeuIiFMgP73aAjdBZKVc8qlZ6lwigPK/IuxCOuARyByBjY7RzSdJyzIcjXucs Y2+bgQ/eDza5c2KhK0aiGsoV0yhIhSC66/v/LxLG85QdzM3M0WKQ/z7CYP6/cxJJfDHhknGs c1I= Subject: Re: pwm-sun4i: PWM backlight is not turned off on shutdown Message-ID: <913a5324-a7d2-f1d5-701e-1c28359286f2@lebedev.lt> Date: Wed, 2 Sep 2020 22:05:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200902095402.pombrirqqjdew34b@holly.lan> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/2/20 12:54 PM, Daniel Thompson wrote: > On Thu, Aug 27, 2020 at 10:55:28PM +0300, Andrey Lebedev wrote: >> I think I'm experiencing problem with pwm-sun4i module. I'll describe >> the symptoms first. >> >> I have a device, based on Allwinner A20 (Cubieboard 2) with LVDS display >> that has a PWM-based backlight. The problem is: when linux shuts down, >> the backlight stays on. I expect it to be turned off. This used to work >> as expected on kernel 5.2-rc2, but after upgrade to 5.8 the backlight >> does not turn off anymore (most of the times, see below). >> >> The backlight is configured in the device tree [1]. The brightness can >> be changed by writing to "brightness" file on sysfs. So, linux can >> control the PWM line. Backlight sysfs directory also has a "bl_power" >> file, which can accept "0" to power on or "4" to power off the backlight >> (according to [2]). >> >> Now, writing "4" to bl_power sometimes turns the backlight off and >> sometimes not. I've found that the probability of backlight turning off >> pretty much correlates with the current screen brightness: on 100% >> brightness it will never turn off, on 50% brightness it will turn off on >> about half of the times. When backlight does not turn off, it goes on >> full brightness. It feels like the line, controlled by pwm stays in >> whatever state it was the moment backlight was powered down - either >> full 1 or 0.>> >> The pwm backlight device driver (pwm_bl) requests to set the duty cycle >> to 0 and disable the pwm with the same request [3], but I suspect the >> implementation driver (pwm-sun4i) does not actually set the duty cycle >> to 0 before disabling the pulse width modulation. >> >> Is there anything that can be done to fix this? > > 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. > > I suspect disabling the initial disable would solve your issue... but it > might provoke some new ones! > > Anyhow, try removing the else clause starting at line 299 and see what > happens: > https://elixir.bootlin.com/linux/v5.8/source/drivers/pwm/pwm-sun4i.c#L299 > Thanks Daniel, 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. I'm not completely sure, but this might be a regression after d3817a647059a3e5f8791e9b7225d194985aa75f. So, adding Pascal and Alexandre to the loop. We'll add this as custom patch to our kernel, will let you know if something will go wrong because of this. diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 5c677c563349..4b0b9aed9bb9 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -296,9 +296,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (state->enabled) { ctrl |= BIT_CH(PWM_EN, pwm->hwpwm); - } else { - ctrl &= ~BIT_CH(PWM_EN, pwm->hwpwm); - ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); } sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); -- Andrey Lebedev aka -.- . -.. -.. . .-. Software engineer Homepage: http://lebedev.lt/