From patchwork Mon Sep 20 16:41:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 514346 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp2283474jao; Mon, 20 Sep 2021 10:41:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylWQGOzBOzDhlR04p5eYKCwkNEaVYJQ/0REXFmHaitfmyRDtffaIuc9lb3I7LN6BJLodef X-Received: by 2002:a6b:f604:: with SMTP id n4mr11002890ioh.99.1632159716138; Mon, 20 Sep 2021 10:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632159716; cv=none; d=google.com; s=arc-20160816; b=0SbZcs6v4jVGfFKcOCoIuQnpvZ27cysZXzdF8cMj5TTEigskqEVrVnaVp5Cdh3oF8i /tpdHAIy/Ou2ciMEpln4ZU0JmPN6r0UctIYQsqUUbVf4afl9HdbjWUk0sK7piDpB9Ofv xA9CxKj4YmkVywpe8/MvOVPNjzhLCJYiOij/T9mXNBBSsXigIvCEgFEpT4rs3KEbBWdA v1idhH0iR39DJxufVvCQsh7QFtI3hjLnqpahpbDIwfg/eoXdmjTWVgbj3kFgspNiPsUp dw6lfkttnUi01GifMXC9UYIaNmGq8AYPC18Z/cdSxv36HbYDYmZj2G7A0r+zuvf7kRgd cupw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZP5DxhEHnCwahdObDwEC9IrloEq8tk0J72RJRrNl3IA=; b=ltzxZyD5Cksla8IwTuqx4grDsQHc2hmHIf3/HKYjeKcVAD3lkg8YwIdqAP1eAjhj7A 0uIw6XrLP6HfPYA/oK/X4RpA67e7XvzFQ8GJLjJoCfdMO+3PyxsunK4NyIDwshPesSu9 DzVrZJi0Xg6inIMtNAeOlG5XqZBX9wt4od1fGLDrnpQTnQ/GZ91+Yamp6cFfrEvH1j4+ eIm8rWwHKVHYtlNFX0sLHuJX3++KCAqZmWPVknkEvqUSpp82f1jIQ60Z/yDt6pLWaOFH HPDoyZqiQbcOn2e+X7gEt2xwWuVZbe/TXvkbYBhRUEKGNpw5q9NduKcZE/ONwGhx68RV MF5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=whEkZ9pJ; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si14844182ilv.102.2021.09.20.10.41.55; Mon, 20 Sep 2021 10:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@linuxfoundation.org header.s=korg header.b=whEkZ9pJ; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353024AbhITRnU (ORCPT + 11 others); Mon, 20 Sep 2021 13:43:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:48100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348600AbhITRlQ (ORCPT ); Mon, 20 Sep 2021 13:41:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D5A3F617E6; Mon, 20 Sep 2021 17:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157709; bh=+UH3HGxHCFzLXDr38uEq/UrnQqdTMy+u4tvGFugt1EQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=whEkZ9pJiGtp4pBbOTJDTCNKw1Xuyjb8vVtRCVyPWoQFbSYdlzurfsL7Rpqwi+rZf ueZDW5BRIYKfmC8r5Cua5hT39yqKp2h+/nO8owBvE3XqrARbBaBMugIfiYh2om01pk 7I4dRP4KPHfmau/egdcwsZ96tGadK/Uhmgu4zEfU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Vasut , Daniel Thompson , Lee Jones Subject: [PATCH 4.19 116/293] backlight: pwm_bl: Improve bootloader/kernel device handover Date: Mon, 20 Sep 2021 18:41:18 +0200 Message-Id: <20210920163937.232034394@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Thompson commit 79fad92f2e596f5a8dd085788a24f540263ef887 upstream. 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. Cc: stable@vger.kernel.org Reported-by: Marek Vasut Signed-off-by: Daniel Thompson Acked-by: Marek Vasut Tested-by: Marek Vasut Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman --- drivers/video/backlight/pwm_bl.c | 54 ++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-) --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -400,6 +400,33 @@ int pwm_backlight_brightness_default(str 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) @@ -411,20 +438,7 @@ static int pwm_backlight_initial_power_s * 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) @@ -494,18 +508,6 @@ static int pwm_backlight_probe(struct pl pb->enable_gpio = gpio_to_desc(data->enable_gpio); } - /* - * 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);