From patchwork Fri May 17 15:05:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 10948095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0ADA713AD for ; Fri, 17 May 2019 15:06:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE92627F2B for ; Fri, 17 May 2019 15:06:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E252E27F9F; Fri, 17 May 2019 15:06:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C4FD28346 for ; Fri, 17 May 2019 15:06:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F3C6898B7; Fri, 17 May 2019 15:06:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 741A9898B7 for ; Fri, 17 May 2019 15:06:04 +0000 (UTC) X-Originating-IP: 90.88.22.185 Received: from localhost.localdomain (aaubervilliers-681-1-80-185.w90-88.abo.wanadoo.fr [90.88.22.185]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 17FCF24000F; Fri, 17 May 2019 15:05:57 +0000 (UTC) From: Paul Kocialkowski To: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] backlight: gpio-backlight: Set power state instead of brightness at probe Date: Fri, 17 May 2019 17:05:46 +0200 Message-Id: <20190517150546.4508-1-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Thompson , Bartlomiej Zolnierkiewicz , Jingoo Han , Paul Kocialkowski , Laurent Pinchart , Thomas Petazzoni , Lee Jones Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP On a trivial gpio-backlight setup with a panel using the backlight but no boot software to enable it beforehand, we fall in a case where the backlight is disabled (not just blanked) and thus remains disabled when the panel gets enabled. Setting gbl->def_value via the device-tree prop allows enabling the backlight in this situation, but it will be unblanked straight away, in compliance with the binding. This does not work well when there was no boot software to display something before, since we really need to unblank by the time the panel is enabled, not before. Resolve the situation by setting the brightness to 1 at probe and managing the power state accordingly, a bit like it's done in pwm-backlight. Fixes: 8b770e3c9824 ("backlight: Add GPIO-based backlight driver") Signed-off-by: Paul Kocialkowski --- drivers/video/backlight/gpio_backlight.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index e470da95d806..c9cb97fa13d0 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -57,6 +57,21 @@ static const struct backlight_ops gpio_backlight_ops = { .check_fb = gpio_backlight_check_fb, }; +static int gpio_backlight_initial_power_state(struct gpio_backlight *gbl) +{ + struct device_node *node = gbl->dev->of_node; + + /* If we absolutely want the backlight enabled at boot. */ + if (gbl->def_value) + return FB_BLANK_UNBLANK; + + /* If there's no panel to unblank the backlight later. */ + if (!node || !node->phandle) + return FB_BLANK_UNBLANK; + + return FB_BLANK_POWERDOWN; +} + static int gpio_backlight_probe_dt(struct platform_device *pdev, struct gpio_backlight *gbl) { @@ -142,7 +157,9 @@ static int gpio_backlight_probe(struct platform_device *pdev) return PTR_ERR(bl); } - bl->props.brightness = gbl->def_value; + bl->props.brightness = 1; + bl->props.power = gpio_backlight_initial_power_state(gbl); + backlight_update_status(bl); platform_set_drvdata(pdev, bl);