linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm-backlight: Avoid backlight flicker when probed from DT
@ 2015-10-29 15:51 Philipp Zabel
  2015-10-30 18:21 ` Lee Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Philipp Zabel @ 2015-10-29 15:51 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Jingoo Han, Lee Jones, Ajay Kumar, YH Huang, Christian Gmeiner,
	linux-pwm, linux-fbdev, linux-kernel, linux-arm-kernel, kernel,
	Philipp Zabel

If the driver is probed from the device tree, and there is a phandle
property set on it, and the enable GPIO is already configured as output,
and the backlight is currently disabled, keep it disabled.
If all these conditions are met, assume there will be some other driver
that can enable the backlight at the appropriate time.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
---
Changes since v2:
 - Leave GPIO configuration as is (GPIOD_ASIS) when requesting,
   so we can actually check the initial state.
---
 drivers/video/backlight/pwm_bl.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index ae3c6b6..8e9c261 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -199,6 +199,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 	struct backlight_properties props;
 	struct backlight_device *bl;
 	struct pwm_bl_data *pb;
+	int initial_blank = FB_BLANK_UNBLANK;
+	bool phandle;
 	int ret;
 
 	if (!data) {
@@ -242,7 +244,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 	pb->enabled = false;
 
 	pb->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
-						  GPIOD_OUT_HIGH);
+						  GPIOD_ASIS);
 	if (IS_ERR(pb->enable_gpio)) {
 		ret = PTR_ERR(pb->enable_gpio);
 		goto err_alloc;
@@ -264,12 +266,32 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 		pb->enable_gpio = gpio_to_desc(data->enable_gpio);
 	}
 
+	phandle = of_find_property(pdev->dev.of_node, "phandle", NULL) != NULL;
+
+	if (pb->enable_gpio) {
+		/*
+		 * If the driver is probed from the device tree and there is a
+		 * phandle link pointing to the backlight node, it is safe to
+		 * assume that another driver will enable the backlight at the
+		 * appropriate time. Therefore, if it is disabled, keep it so.
+		 */
+		if (phandle &&
+		    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT &&
+		    gpiod_get_value(pb->enable_gpio) == 0)
+			initial_blank = FB_BLANK_POWERDOWN;
+		else
+			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);
 		goto err_alloc;
 	}
 
+	if (phandle && !regulator_is_enabled(pb->power_supply))
+		initial_blank = FB_BLANK_POWERDOWN;
+
 	pb->pwm = devm_pwm_get(&pdev->dev, NULL);
 	if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER
 	    && !pdev->dev.of_node) {
@@ -320,6 +342,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 	}
 
 	bl->props.brightness = data->dft_brightness;
+	bl->props.power = initial_blank;
 	backlight_update_status(bl);
 
 	platform_set_drvdata(pdev, bl);
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] pwm-backlight: Avoid backlight flicker when probed from DT
  2015-10-29 15:51 [PATCH] pwm-backlight: Avoid backlight flicker when probed from DT Philipp Zabel
@ 2015-10-30 18:21 ` Lee Jones
  2015-11-02 16:30   ` Philipp Zabel
  0 siblings, 1 reply; 5+ messages in thread
From: Lee Jones @ 2015-10-30 18:21 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Thierry Reding, Jingoo Han, Ajay Kumar, YH Huang,
	Christian Gmeiner, linux-pwm, linux-fbdev, linux-kernel,
	linux-arm-kernel, kernel

On Thu, 29 Oct 2015, Philipp Zabel wrote:

> If the driver is probed from the device tree, and there is a phandle
> property set on it, and the enable GPIO is already configured as output,
> and the backlight is currently disabled, keep it disabled.
> If all these conditions are met, assume there will be some other driver
> that can enable the backlight at the appropriate time.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> ---
> Changes since v2:
>  - Leave GPIO configuration as is (GPIOD_ASIS) when requesting,
>    so we can actually check the initial state.
> ---
>  drivers/video/backlight/pwm_bl.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index ae3c6b6..8e9c261 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -199,6 +199,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	struct backlight_properties props;
>  	struct backlight_device *bl;
>  	struct pwm_bl_data *pb;
> +	int initial_blank = FB_BLANK_UNBLANK;
> +	bool phandle;
>  	int ret;
>  
>  	if (!data) {
> @@ -242,7 +244,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	pb->enabled = false;
>  
>  	pb->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
> -						  GPIOD_OUT_HIGH);
> +						  GPIOD_ASIS);
>  	if (IS_ERR(pb->enable_gpio)) {
>  		ret = PTR_ERR(pb->enable_gpio);
>  		goto err_alloc;
> @@ -264,12 +266,32 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  		pb->enable_gpio = gpio_to_desc(data->enable_gpio);
>  	}
>  
> +	phandle = of_find_property(pdev->dev.of_node, "phandle", NULL) != NULL;

This is a little ugly.

If this is the only way to identify the probedness of a device then
you probably want to neaten it up a little.  I suggest something along
the lines of:

if (of_find_property(pdev->dev.of_node, "phandle", NULL))
	already_probed = true;

Also, do you also want to check for "linux,phandle", as this is always
catered for in drivers/of/*

> +	if (pb->enable_gpio) {
> +		/*
> +		 * If the driver is probed from the device tree and there is a
> +		 * phandle link pointing to the backlight node, it is safe to
> +		 * assume that another driver will enable the backlight at the
> +		 * appropriate time. Therefore, if it is disabled, keep it so.
> +		 */
> +		if (phandle &&
> +		    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT &&
> +		    gpiod_get_value(pb->enable_gpio) == 0)
> +			initial_blank = FB_BLANK_POWERDOWN;
> +		else
> +			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);
>  		goto err_alloc;
>  	}
>  
> +	if (phandle && !regulator_is_enabled(pb->power_supply))
> +		initial_blank = FB_BLANK_POWERDOWN;
> +
>  	pb->pwm = devm_pwm_get(&pdev->dev, NULL);
>  	if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER
>  	    && !pdev->dev.of_node) {
> @@ -320,6 +342,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	}
>  
>  	bl->props.brightness = data->dft_brightness;
> +	bl->props.power = initial_blank;
>  	backlight_update_status(bl);
>  
>  	platform_set_drvdata(pdev, bl);

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pwm-backlight: Avoid backlight flicker when probed from DT
  2015-10-30 18:21 ` Lee Jones
@ 2015-11-02 16:30   ` Philipp Zabel
  0 siblings, 0 replies; 5+ messages in thread
From: Philipp Zabel @ 2015-11-02 16:30 UTC (permalink / raw)
  To: Lee Jones
  Cc: Thierry Reding, Jingoo Han, Ajay Kumar, YH Huang,
	Christian Gmeiner, linux-pwm, linux-fbdev, linux-kernel,
	linux-arm-kernel, kernel

Hi Lee,

Am Freitag, den 30.10.2015, 18:21 +0000 schrieb Lee Jones:
> > @@ -264,12 +266,32 @@ static int pwm_backlight_probe(struct platform_device *pdev)
> >  		pb->enable_gpio = gpio_to_desc(data->enable_gpio);
> >  	}
> >  
> > +	phandle = of_find_property(pdev->dev.of_node, "phandle", NULL) != NULL;
> 
> This is a little ugly.
> 
> If this is the only way to identify the probedness of a device then
> you probably want to neaten it up a little.  I suggest something along
> the lines of:
>
> if (of_find_property(pdev->dev.of_node, "phandle", NULL))
> 	already_probed = true;
> 
> Also, do you also want to check for "linux,phandle", as this is always
> catered for in drivers/of/*

Thanks for pointing this out. I suppose I should just check
pdev->dev.of_node->phandle != 0 instead. That will already be
initialized by unflatten_dt_node if either property was found.

regards
Philipp


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pwm-backlight: Avoid backlight flicker when probed from DT
  2015-06-12 16:26 Philipp Zabel
@ 2015-07-13  9:40 ` Philipp Zabel
  0 siblings, 0 replies; 5+ messages in thread
From: Philipp Zabel @ 2015-07-13  9:40 UTC (permalink / raw)
  To: Thierry Reding, Lee Jones, Jingoo Han, Ajay Kumar
  Cc: linux-pwm, linux-fbdev, linux-kernel, kernel

Hi,

Am Freitag, den 12.06.2015, 18:26 +0200 schrieb Philipp Zabel:
> If the driver is probed from the device tree, and there is a phandle
> property set on it, and the enable GPIO is already configured as output,
> and the backlight is currently disabled, keep it disabled.
> If all these conditions are met, assume there will be some other driver
> that can enable the backlight at the appropriate time.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
> I have seen the thread at https://lkml.org/lkml/2014/7/31/259, but I'm not
> sure if it has come to a resolution. This is what I think could be useful
> to keep the current default behaviour of enabling the backlight while at the
> same time allowing to keep it disabled if we are absolutely certain that the
> backlight is currently off, and we think there is some other driver that will
> control it:

do you have any comments on this? Would the conditions mentioned above
be sufficient for your use cases?

best regards
Philipp

> ---
>  drivers/video/backlight/pwm_bl.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index 6897f1c..dcb6bfb 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -199,6 +199,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	struct backlight_properties props;
>  	struct backlight_device *bl;
>  	struct pwm_bl_data *pb;
> +	int initial_blank = FB_BLANK_UNBLANK;
>  	int ret;
>  
>  	if (!data) {
> @@ -263,8 +264,21 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  		pb->enable_gpio = gpio_to_desc(data->enable_gpio);
>  	}
>  
> -	if (pb->enable_gpio)
> -		gpiod_direction_output(pb->enable_gpio, 1);
> +	if (pb->enable_gpio) {
> +		/*
> +		 * If the driver is probed from the device tree and there is a
> +		 * phandle link pointing to the backlight node, it is safe to
> +		 * assume that another driver will enable the backlight at the
> +		 * appropriate time. Therefore, if it is disabled, keep it so.
> +		 */
> +		if (of_find_property(pdev->dev.of_node, "phandle", NULL) &&
> +		    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT &&
> +		    gpiod_get_value(pb->enable_gpio) == 0) {
> +			initial_blank = FB_BLANK_POWERDOWN;
> +		} else {
> +			gpiod_direction_output(pb->enable_gpio, 1);
> +		}
> +	}
>  
>  	pb->power_supply = devm_regulator_get(&pdev->dev, "power");
>  	if (IS_ERR(pb->power_supply)) {
> @@ -323,6 +337,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	}
>  
>  	bl->props.brightness = data->dft_brightness;
> +	bl->props.power = initial_blank;
>  	backlight_update_status(bl);
>  
>  	platform_set_drvdata(pdev, bl);



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] pwm-backlight: Avoid backlight flicker when probed from DT
@ 2015-06-12 16:26 Philipp Zabel
  2015-07-13  9:40 ` Philipp Zabel
  0 siblings, 1 reply; 5+ messages in thread
From: Philipp Zabel @ 2015-06-12 16:26 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Jingoo Han, Lee Jones, Ajay Kumar, linux-pwm, linux-fbdev,
	linux-kernel, kernel, Philipp Zabel

If the driver is probed from the device tree, and there is a phandle
property set on it, and the enable GPIO is already configured as output,
and the backlight is currently disabled, keep it disabled.
If all these conditions are met, assume there will be some other driver
that can enable the backlight at the appropriate time.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
I have seen the thread at https://lkml.org/lkml/2014/7/31/259, but I'm not
sure if it has come to a resolution. This is what I think could be useful
to keep the current default behaviour of enabling the backlight while at the
same time allowing to keep it disabled if we are absolutely certain that the
backlight is currently off, and we think there is some other driver that will
control it:
---
 drivers/video/backlight/pwm_bl.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 6897f1c..dcb6bfb 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -199,6 +199,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 	struct backlight_properties props;
 	struct backlight_device *bl;
 	struct pwm_bl_data *pb;
+	int initial_blank = FB_BLANK_UNBLANK;
 	int ret;
 
 	if (!data) {
@@ -263,8 +264,21 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 		pb->enable_gpio = gpio_to_desc(data->enable_gpio);
 	}
 
-	if (pb->enable_gpio)
-		gpiod_direction_output(pb->enable_gpio, 1);
+	if (pb->enable_gpio) {
+		/*
+		 * If the driver is probed from the device tree and there is a
+		 * phandle link pointing to the backlight node, it is safe to
+		 * assume that another driver will enable the backlight at the
+		 * appropriate time. Therefore, if it is disabled, keep it so.
+		 */
+		if (of_find_property(pdev->dev.of_node, "phandle", NULL) &&
+		    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT &&
+		    gpiod_get_value(pb->enable_gpio) == 0) {
+			initial_blank = FB_BLANK_POWERDOWN;
+		} else {
+			gpiod_direction_output(pb->enable_gpio, 1);
+		}
+	}
 
 	pb->power_supply = devm_regulator_get(&pdev->dev, "power");
 	if (IS_ERR(pb->power_supply)) {
@@ -323,6 +337,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 	}
 
 	bl->props.brightness = data->dft_brightness;
+	bl->props.power = initial_blank;
 	backlight_update_status(bl);
 
 	platform_set_drvdata(pdev, bl);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-02 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-29 15:51 [PATCH] pwm-backlight: Avoid backlight flicker when probed from DT Philipp Zabel
2015-10-30 18:21 ` Lee Jones
2015-11-02 16:30   ` Philipp Zabel
  -- strict thread matches above, loose matches on Subject: below --
2015-06-12 16:26 Philipp Zabel
2015-07-13  9:40 ` Philipp Zabel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).