From patchwork Thu Oct 26 12:49:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lothar_Wa=C3=9Fmann?= X-Patchwork-Id: 830631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yN6nc1YNZz9t5x for ; Fri, 27 Oct 2017 00:10:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932327AbdJZNKm (ORCPT ); Thu, 26 Oct 2017 09:10:42 -0400 Received: from smtprelay09.ispgateway.de ([134.119.228.113]:61936 "EHLO smtprelay09.ispgateway.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932273AbdJZNKk (ORCPT ); Thu, 26 Oct 2017 09:10:40 -0400 X-Greylist: delayed 1243 seconds by postgrey-1.27 at vger.kernel.org; Thu, 26 Oct 2017 09:10:39 EDT Received: from [89.1.81.74] (helo=ipc1.ka-ro) by smtprelay09.ispgateway.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1e7hbb-0005gS-M6; Thu, 26 Oct 2017 14:49:51 +0200 Received: from lothar by ipc1.ka-ro with local (Exim 4.84_2 #2 (Debian)) id 1e7hbZ-00057S-6O; Thu, 26 Oct 2017 14:49:49 +0200 From: =?utf-8?q?Lothar_Wa=C3=9Fmann?= To: Bartlomiej Zolnierkiewicz , Daniel Thompson , Jacek Anaszewski , Jingoo Han , Lee Jones , Mark Rutland , Pavel Machek , Richard Purdie , Rob Herring , Thierry Reding , devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, linux-pwm@vger.kernel.org Cc: =?utf-8?q?Lothar_Wa=C3=9Fmann?= Subject: [PATCH 1/2] backlight: pwm_bl: Enable PWM before switching regulator on Date: Thu, 26 Oct 2017 14:49:45 +0200 Message-Id: <1509022186-19636-3-git-send-email-LW@KARO-electronics.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1509022186-19636-1-git-send-email-LW@KARO-electronics.de> References: <1509022186-19636-1-git-send-email-LW@KARO-electronics.de> MIME-Version: 1.0 X-Df-Sender: bHdAa2Fyby1lbGVjdHJvbmljcy5kZQ== Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org When the PWM is re-enabled after being switched off, the backlight may flicker due to the backlight power being switched on while the PWM is still unconfigured. This is especially true if the PWM output is active low (assuming that the PWM output is low when the PWM is not enabled). Configure the PWM before switching backlight power on to prevent this. Signed-off-by: Lothar Waßmann --- drivers/video/backlight/pwm_bl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 002f1ce..921f322 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -50,6 +50,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) if (pb->enabled) return; + pwm_enable(pb->pwm); + err = regulator_enable(pb->power_supply); if (err < 0) dev_err(pb->dev, "failed to enable power supply\n"); @@ -57,7 +59,6 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) if (pb->enable_gpio) gpiod_set_value_cansleep(pb->enable_gpio, 1); - pwm_enable(pb->pwm); pb->enabled = true; } From patchwork Thu Oct 26 12:49:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lothar_Wa=C3=9Fmann?= X-Patchwork-Id: 830627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yN6jn2RCNz9t5b for ; Fri, 27 Oct 2017 00:07:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932246AbdJZNHY (ORCPT ); Thu, 26 Oct 2017 09:07:24 -0400 Received: from smtprelay04.ispgateway.de ([80.67.31.27]:61687 "EHLO smtprelay04.ispgateway.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932198AbdJZNHX (ORCPT ); Thu, 26 Oct 2017 09:07:23 -0400 Received: from [89.1.81.74] (helo=ipc1.ka-ro) by smtprelay04.ispgateway.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1e7hbb-0000et-R6; Thu, 26 Oct 2017 14:49:51 +0200 Received: from lothar by ipc1.ka-ro with local (Exim 4.84_2 #2 (Debian)) id 1e7hbZ-00057X-KL; Thu, 26 Oct 2017 14:49:49 +0200 From: =?utf-8?q?Lothar_Wa=C3=9Fmann?= To: Bartlomiej Zolnierkiewicz , Daniel Thompson , Jacek Anaszewski , Jingoo Han , Lee Jones , Mark Rutland , Pavel Machek , Richard Purdie , Rob Herring , Thierry Reding , devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, linux-pwm@vger.kernel.org Cc: =?utf-8?q?Lothar_Wa=C3=9Fmann?= Subject: [PATCH 2/2] backlight: pwm_bl: add configurable delay between re-enabling PWM and switching backlight power on Date: Thu, 26 Oct 2017 14:49:46 +0200 Message-Id: <1509022186-19636-4-git-send-email-LW@KARO-electronics.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1509022186-19636-1-git-send-email-LW@KARO-electronics.de> References: <1509022186-19636-1-git-send-email-LW@KARO-electronics.de> MIME-Version: 1.0 X-Df-Sender: bHdAa2Fyby1lbGVjdHJvbmljcy5kZQ== Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org When switching the backlight on, the LCD may need some time to adjust to the configured PWM duty cycle. Add a configurable delay between configuring the PWM and enabling the backlight regulator to account for this. Signed-off-by: Lothar Waßmann --- .../bindings/leds/backlight/pwm-backlight.txt | 4 ++++ drivers/video/backlight/pwm_bl.c | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt b/Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt index 764db86..95594c3 100644 --- a/Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt +++ b/Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt @@ -17,6 +17,10 @@ Optional properties: "pwms" property (see PWM binding[0]) - enable-gpios: contains a single GPIO specifier for the GPIO which enables and disables the backlight (see GPIO binding[1]) + - turn-on-delay-ms: delay in milliseconds between configuring the PWM + and switching PWM on. This may be required to eliminate + flicker when switching the PWM on after it has been + disabled. [0]: Documentation/devicetree/bindings/pwm/pwm.txt [1]: Documentation/devicetree/bindings/gpio/gpio.txt diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 921f322..9578f65 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -23,6 +23,7 @@ #include #include #include +#include struct pwm_bl_data { struct pwm_device *pwm; @@ -35,6 +36,7 @@ struct pwm_bl_data { struct gpio_desc *enable_gpio; unsigned int scale; bool legacy; + int turn_on_delay_ms; int (*notify)(struct device *, int brightness); void (*notify_after)(struct device *, @@ -52,6 +54,17 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) pwm_enable(pb->pwm); + if (pb->turn_on_delay_ms > 0) { + dev_dbg(pb->dev, "Sleeping %u..%uµs\n", + pb->turn_on_delay_ms * 1000, + pb->turn_on_delay_ms * 1100); + if (pb->turn_on_delay_ms > 20) + msleep(pb->turn_on_delay_ms); + else + usleep_range(pb->turn_on_delay_ms * 1000, + pb->turn_on_delay_ms * 1100); + } + err = regulator_enable(pb->power_supply); if (err < 0) dev_err(pb->dev, "failed to enable power supply\n"); @@ -108,8 +121,9 @@ static int pwm_backlight_update_status(struct backlight_device *bl) duty_cycle = compute_duty_cycle(pb, brightness); pwm_config(pb->pwm, duty_cycle, pb->period); pwm_backlight_power_on(pb, brightness); - } else + } else { pwm_backlight_power_off(pb); + } if (pb->notify_after) pb->notify_after(pb->dev, brightness); @@ -264,9 +278,9 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->scale = data->levels[i]; pb->levels = data->levels; - } else + } else { pb->scale = data->max_brightness; - + } pb->notify = data->notify; pb->notify_after = data->notify_after; pb->check_fb = data->check_fb; @@ -329,6 +343,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) goto err_alloc; } + of_property_read_u32(node, "turn-on-delay-ms", &pb->turn_on_delay_ms); + dev_dbg(&pdev->dev, "got pwm for backlight\n"); /*