From patchwork Thu Jul 22 14:46:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 483908 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp425771jao; Thu, 22 Jul 2021 07:46:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxle6LP/Icg2SkI1KIPDHB0hbjS1pm8/BTeyMBccEQ/eBLyWEB6JY6mEQp6qx5bbg4YeFU X-Received: by 2002:a17:906:5e04:: with SMTP id n4mr235210eju.277.1626965219727; Thu, 22 Jul 2021 07:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626965219; cv=none; d=google.com; s=arc-20160816; b=mNGYiIutwaMS/9KFxWqil0Bqa5hufoqcTTvI3q4YSUetuUucJNncwEAhDigMFlVfvG jk8+Qs3NjAmuuAZczrmq3uNlhkbaiSV1kDstX+tOBKEAajwtL7/NgdJ1wX4bbhyxgRvF 1rISgRHCaBa9XagHcIgmWC2t1GpDKfNVeRSjmGRbO96fkP/yEz6aJqMUgb0znJWm9zr+ qubVoqLQuc2sYvitdj4eKx2LKUMMYwLc6EGUo+SRTPj77IBgoHcD+J7IsvjDoP8hzeYg CF6E72tN0oRCmuIs/DrCsQcRzw5CslNjEEHTJWfltWJOIVoihVIrVBWcqOgIVMymHybs bcsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DnmHNNXEi+D67CdXt2sdtRiYmXnF0UzDAK5d1qxhJYo=; b=c3Cr4msoDgL+efFXGrkDxytguM5RA5iBhGaQ88fjH7JMrXnI3TFljv1lcqohfqCTwM N1gvmqPhW6fjRZUfoVmnZjTXFMa78aTo7Zueo92j7Npwp1MKtzP8Xse/tgDzrEJ9NKxB H2Ra3FO0iMVXs29usMgAE4Jo6UNCck2UM9D5WonXfn+hPR1ByfSvJ3VHGg+qQT4xaQLl rvtIyTVs0thCbv/n+ZhmXnk48S6qc33QKn+1BP7WAlckrXlEpqqmAu4D8WmFzCwGmOzE 5p2vZizpvR7FWfcXvl8591QqSuYQV/jfn0OyByinXZinMbacMibmwXHk3SCT+mWrORMs 3vBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sh8hlv9d; spf=pass (google.com: domain of linux-fbdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-fbdev-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 gg4si24809217ejb.695.2021.07.22.07.46.59 for ; Thu, 22 Jul 2021 07:46:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-fbdev-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=sh8hlv9d; spf=pass (google.com: domain of linux-fbdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-fbdev-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 S232447AbhGVOGX (ORCPT ); Thu, 22 Jul 2021 10:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232414AbhGVOGX (ORCPT ); Thu, 22 Jul 2021 10:06:23 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00145C061757 for ; Thu, 22 Jul 2021 07:46:57 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id p15-20020a05600c358fb0290245467f26a4so3135204wmq.0 for ; Thu, 22 Jul 2021 07:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DnmHNNXEi+D67CdXt2sdtRiYmXnF0UzDAK5d1qxhJYo=; b=sh8hlv9dg7eFqGZTlCBS2fKOrpDKfSZK3zJeZAxqFqqhfvCmEK+p2ojCMdRWL4QTY1 qHojFkfGdIg6xnOeJsgldaeFwrZXI+0iVQAYPS3CL4l1xCGYemJTMcW38fTnJoXCdl/x t/bhlRsTtobXIZx9KJPjblZFuuHKoNbtUftrzqGxFV6GnOBEyLkgCOHKzm89LzDkfnpy bo1lPduqlKiYJzUzLcbCGTFOQ5vPoPyPxk+9Bdj6CZ1itgw5tz7j/fFh6Fu4QFmrkKG+ 8qS9w+idYQf/1f/QWfl6Bc6iw2Hp3K25vaDVrlWaCKyoCu2YX52X2iXDrh+XKwdT25hL SBbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DnmHNNXEi+D67CdXt2sdtRiYmXnF0UzDAK5d1qxhJYo=; b=hklhnFqZOdkoPiwHBvze+VZxEBxJ1fZvGAxvf5q0jjJ4BZM46ogupbzdbbEMXqBsgs bun6H4Kk4aSjLdpkTMxDCRqHUn+ZG+frlCU6BFto5L/97R0q1W2rvWWSWSsbVPYPmHZO baPi/oEx993CUxThOnzoZ+uyo6pcYLB33bq+Yj9rODyn9ERFCgoaI11TUJiGhEA+Jcdu OR4/M33JGRUGjjSs5QitJgLIqQFLouVz+bWTsTrEbiB09xsSMHZN9jlYFR/VFs7XZbRB DRoklc1OHGCRwIaDkGI2lJdlxzvsBpiPwyW9uv9PDrFS0Q7g48Sv23+LwfFkrEd+CrKX qZrQ== X-Gm-Message-State: AOAM530sVJlvfX8dUQaQdUrBzyc5hZkeF020NJEeJ299mL8B+Dy9SGio 1HQ7QPZw2dIpOB5bBeyfyvphOQ== X-Received: by 2002:a7b:c7cb:: with SMTP id z11mr9558960wmk.102.1626965216396; Thu, 22 Jul 2021 07:46:56 -0700 (PDT) Received: from maple.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id z2sm10167362wma.45.2021.07.22.07.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 07:46:55 -0700 (PDT) From: Daniel Thompson To: Lee Jones , Jingoo Han Cc: Daniel Thompson , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Marek Vasut , stable@vger.kernel.org Subject: [PATCH] backlight: pwm_bl: Improve bootloader/kernel device handover Date: Thu, 22 Jul 2021 15:46:23 +0100 Message-Id: <20210722144623.1572816-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Currently there are (at least) two problems in the way pwm_bl starts managing the enable_gpio pin. Both occur when the backlight is initially off and the driver finds the pin not already in output mode and, as a result, unconditionally switches it to output-mode and asserts the signal. Problem 1: This could cause the backlight to flicker since, at this stage in driver initialisation, we have no idea what the PWM and regulator are doing (an unconfigured PWM could easily "rest" at 100% duty cycle). Problem 2: This will cause us not to correctly honour the post_pwm_on_delay (which also risks flickers). Fix this by moving the code to configure the GPIO output mode until after we have examines the handover state. That allows us to initialize enable_gpio to off if the backlight is currently off and on if the backlight is on. Reported-by: Marek Vasut Signed-off-by: Daniel Thompson Cc: stable@vger.kernel.org Acked-by: Marek Vasut Tested-by: Marek Vasut --- drivers/video/backlight/pwm_bl.c | 54 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) base-commit: 2734d6c1b1a089fb593ef6a23d4b70903526fe0c -- 2.30.2 diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index e48fded3e414..8d8959a70e44 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -409,6 +409,33 @@ static bool pwm_backlight_is_linear(struct platform_pwm_backlight_data *data) static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) { struct device_node *node = pb->dev->of_node; + bool active = true; + + /* + * If the enable GPIO is present, observable (either as input + * or output) and off then the backlight is not currently active. + * */ + if (pb->enable_gpio && gpiod_get_value_cansleep(pb->enable_gpio) == 0) + active = false; + + if (!regulator_is_enabled(pb->power_supply)) + active = false; + + if (!pwm_is_enabled(pb->pwm)) + active = false; + + /* + * Synchronize the enable_gpio with the observed state of the + * hardware. + */ + if (pb->enable_gpio) + gpiod_direction_output(pb->enable_gpio, active); + + /* + * Do not change pb->enabled here! pb->enabled essentially + * tells us if we own one of the regulator's use counts and + * right now we do not. + */ /* Not booted with device tree or no phandle link to the node */ if (!node || !node->phandle) @@ -420,20 +447,7 @@ static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) * assume that another driver will enable the backlight at the * appropriate time. Therefore, if it is disabled, keep it so. */ - - /* if the enable GPIO is disabled, do not enable the backlight */ - if (pb->enable_gpio && gpiod_get_value_cansleep(pb->enable_gpio) == 0) - return FB_BLANK_POWERDOWN; - - /* The regulator is disabled, do not enable the backlight */ - if (!regulator_is_enabled(pb->power_supply)) - return FB_BLANK_POWERDOWN; - - /* The PWM is disabled, keep it like this */ - if (!pwm_is_enabled(pb->pwm)) - return FB_BLANK_POWERDOWN; - - return FB_BLANK_UNBLANK; + return active ? FB_BLANK_UNBLANK: FB_BLANK_POWERDOWN; } static int pwm_backlight_probe(struct platform_device *pdev) @@ -486,18 +500,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) goto err_alloc; } - /* - * If the GPIO is not known to be already configured as output, that - * is, if gpiod_get_direction returns either 1 or -EINVAL, change the - * direction to output and set the GPIO as active. - * Do not force the GPIO to active when it was already output as it - * could cause backlight flickering or we would enable the backlight too - * early. Leave the decision of the initial backlight state for later. - */ - if (pb->enable_gpio && - gpiod_get_direction(pb->enable_gpio) != 0) - gpiod_direction_output(pb->enable_gpio, 1); - pb->power_supply = devm_regulator_get(&pdev->dev, "power"); if (IS_ERR(pb->power_supply)) { ret = PTR_ERR(pb->power_supply);