Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1850935pxb; Mon, 13 Sep 2021 06:55:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY+WR1ADilS3H57uOPc8bG4x+yPO+3GWmdjR8DDNw3nqCRiHT3HLG/nWDlymOUITdV3SHf X-Received: by 2002:a1c:23cb:: with SMTP id j194mr11290325wmj.1.1631541359200; Mon, 13 Sep 2021 06:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631541359; cv=none; d=google.com; s=arc-20160816; b=JD5roeN3wQL5/BrEeIgY/u/Ldx/lPcn2fWAzv/5WRDRGRXso4EdTncO5tHjUohU9q/ Ll8/Y2unhNnlPAMkSmwH3BIX2wGhHHmO7dleVpfP9PXOhRaVWpJTBhPW1X0f5NOxgNUi B2r62+/gmLEa1CFC7vdo/ntoRXB17X9NGJaxk4I9+x+wlZpPjHSlbEFt5FWJuRdxK8xA 0UmNwecM3U/4pi8U9I4kzgSps90ydUVWLfobTsbUrV+OjGkBqVyG414Z4taHaTsW3AGV IMqfXmPTV7XF+TpBoaf02xBfHGs6i/YdEvV8XQRYN+wKwHhdNZG5ZkKTh5ukrslljqEA 7wow== 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=B/ZsiAqlKYI+NNDVmazRyFp53SMEvA0tzjpgy/DNtIE=; b=KxWl7slccm4twNEH4jFEtq3qE6s0os73fo8XRyCsIZj4Kc1IdAdlcsDB9LhHqnQF3x dQ9cRVLIdQ4Xvcu3umZQBwJD1bHzhqYIIQCaGz/HEPnGZZmepSeRAMABbdPW/Xb0qW1k 1JkkhwwCED+8xFUCwcJND1hBPN3D35LWkwMmea2EaGrkN447m4evAqX7xdedkQ6A9sbz SdJCOID08sKM/9V76PLxlDNnNz0MgIb19gR0RJKMui9OgwHLlnYibDZpH8G9oENw5Tz4 e6UpZYHqTJetU6ouzY8oGd5ASacnMNK0UxPopcPIMwZHRjB78xLgc0K5nrbasRaTx1CH gX3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zw4Ri2kC; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si8088301edj.313.2021.09.13.06.55.33; Mon, 13 Sep 2021 06:55:59 -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=@linuxfoundation.org header.s=korg header.b=Zw4Ri2kC; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245090AbhIMNx7 (ORCPT + 99 others); Mon, 13 Sep 2021 09:53:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:51790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243557AbhIMNsx (ORCPT ); Mon, 13 Sep 2021 09:48:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 01C9B61362; Mon, 13 Sep 2021 13:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539975; bh=FjbNyhkjshMTjpHvOOTXE5FEYk5XhcKQcm1pRFXJuGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zw4Ri2kCVxC6RiqJMwN1ZIvpr4NCNZzIKXKhHYgYdAXaNpjzcNSoR1BS90MyUbJHD hw8+nYtR/irJljcukIrMf+IJDKTeQP9GAi7ZCtsuRiFfeX6g2iK2wgfjHL5xT1GxCD VBxEBHFPxLQ5WgT8zZyfS5oUukq4g6rqpB2NEYVY= 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 5.10 235/236] backlight: pwm_bl: Improve bootloader/kernel device handover Date: Mon, 13 Sep 2021 15:15:40 +0200 Message-Id: <20210913131108.334287330@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -417,6 +417,33 @@ static bool pwm_backlight_is_linear(stru 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) @@ -428,20 +455,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 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);