Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp674741ybm; Wed, 22 May 2019 09:36:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJ0pQVNrKTWn8wzt3FM0LLm86h8qB+kMMjCY0Iwq2koJsmLjHpqHwgRHRL/bv6/v68dEbu X-Received: by 2002:a62:7796:: with SMTP id s144mr39587382pfc.260.1558543010968; Wed, 22 May 2019 09:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558543010; cv=none; d=google.com; s=arc-20160816; b=ufcxI/11JmpbSvfDsuUOPCI0LH10XC0AOITROj3tmWnHP8wMCQM6g8xMXKFwHoMgxD sc9h3cVKsydpekZfKcsAPGP0Ni8Xu4QOzHC2JhAzG6Qqsu6QMslnirE3jFFcFiIIJmk1 PZXxN5h/p7o2LWFKxKs3/Ibp+E+sVfmc/VYOGLPjIj5F9OE6+PR4xvuwnx8Q88xQeorX BJ/bWud5HrPTs8JW4Algv/zkKS/X5Kx/U3sX+gOzQi1i3BnpT3oklYlRuhUCZIMSNrMv 8Pet8LeOib8VukBIgMA32myJR1jT0vTnM6ZkauSyXoo2LlKhSWPEZYznvArUfGJT9Gv7 Wdlg== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=iWtE607ygyephngrXoZlswDjPShkvMXmajkumWA4ytc=; b=J3V1HikLO3tCuN2li8ERBqzYLC+Hu6Tsv81YiPgRKX+w/KBuZkV41gG0NhSnmLUSs9 TaZxYBjOUumPWNi7grBMMP0BJD2IJa1jL2TJymofsHcTRZOfk17pCpjmWwBoUb8//fMH QHNwsK/qq1wLQv6D0e270thmw+4KbiJ3y5hpeUwGGYf1WCn9UJd1ka1S106p8DPRMZeX zJlyeWn7O7VQiT3nNyDz3xjLIQzQainwhzYiHr+QPQj4QOYWYVS6Xx6DhPMDGuOSg1oE bvygdtSG50+xjosL9TnrGWykHngmLwwrLNi/lbf98PAexuAFKuhiNU6S6w3OpPg8gVjk 4e+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=I40kohTa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d23si24442889pgh.448.2019.05.22.09.36.35; Wed, 22 May 2019 09:36:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=I40kohTa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730155AbfEVQef (ORCPT + 99 others); Wed, 22 May 2019 12:34:35 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:41790 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729856AbfEVQef (ORCPT ); Wed, 22 May 2019 12:34:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1558542873; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=iWtE607ygyephngrXoZlswDjPShkvMXmajkumWA4ytc=; b=I40kohTauhNL2B30AT1P9Ug4a/NaE5wADnGZ60YisnxmkGkNfC+9Dx6xCIvOCU1ZyozbLF X3SDY2ErWA4fFl/5/KgUrVVm2XaC1zKRDE5cjfqqod4x0QozBCD4QVE4BO/JnoIjOEY+/f cQ41nk0uQnrt9OnVFl/KdMtCERRL7zc= From: Paul Cercueil To: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Cc: od@zcrc.me, linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH] backlight: pwm_bl: Set pin to sleep state when powered down Date: Wed, 22 May 2019 18:34:28 +0200 Message-Id: <20190522163428.7078-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the driver probes, the PWM pin is automatically configured to its default state, which should be the "pwm" function. However, at this point we don't know the actual level of the pin, which may be active or inactive. As a result, if the driver probes without enabling the backlight, the PWM pin might be active, and the backlight would be lit way before being officially enabled. To work around this, if the probe function doesn't enable the backlight, the pin is set to its sleep state instead of the default one, until the backlight is enabled. When the backlight is disabled, the pin is reset to its sleep state. Signed-off-by: Paul Cercueil --- drivers/video/backlight/pwm_bl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index fb45f866b923..422f7903b382 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb) struct pwm_state state; int err; + pinctrl_pm_select_default_state(pb->dev); + pwm_get_state(pb->pwm, &state); if (pb->enabled) return; @@ -90,6 +93,8 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) regulator_disable(pb->power_supply); pb->enabled = false; + + pinctrl_pm_select_sleep_state(pb->dev); } static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) @@ -626,6 +631,10 @@ static int pwm_backlight_probe(struct platform_device *pdev) backlight_update_status(bl); platform_set_drvdata(pdev, bl); + + if (bl->props.power == FB_BLANK_POWERDOWN) + pinctrl_pm_select_sleep_state(&pdev->dev); + return 0; err_alloc: -- 2.21.0.593.g511ec345e18