linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm_backlight: pass correct brightness to callback
@ 2012-07-09  4:21 Alexandre Courbot
  2012-07-09  5:10 ` Thierry Reding
  2012-07-09  5:11 ` [PATCH] " Jingoo Han
  0 siblings, 2 replies; 7+ messages in thread
From: Alexandre Courbot @ 2012-07-09  4:21 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-kernel, linux-fbdev, Alexandre Courbot

pwm_backlight_update_status calls two callbacks before and after
applying the new PWM settings. However, the brightness scale is
completely changed in between if brightness levels are used. This patch
ensures that both callbacks are passed brightness values of the same
meaning.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/video/backlight/pwm_bl.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 057389d..dd4d24d 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -39,6 +39,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
 {
 	struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
 	int brightness = bl->props.brightness;
+	int pwm_brightness;
 	int max = bl->props.max_brightness;
 
 	if (bl->props.power != FB_BLANK_UNBLANK)
@@ -55,13 +56,14 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
 		pwm_disable(pb->pwm);
 	} else {
 		if (pb->levels) {
-			brightness = pb->levels[brightness];
+			pwm_brightness = pb->levels[brightness];
 			max = pb->levels[max];
-		}
+		} else
+			pwm_brightness = brightness;
 
-		brightness = pb->lth_brightness +
-			(brightness * (pb->period - pb->lth_brightness) / max);
-		pwm_config(pb->pwm, brightness, pb->period);
+		pwm_brightness = pb->lth_brightness +
+		     (pwm_brightness * (pb->period - pb->lth_brightness) / max);
+		pwm_config(pb->pwm, pwm_brightness, pb->period);
 		pwm_enable(pb->pwm);
 	}
 
-- 
1.7.11.1


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

* Re: [PATCH] pwm_backlight: pass correct brightness to callback
  2012-07-09  4:21 [PATCH] pwm_backlight: pass correct brightness to callback Alexandre Courbot
@ 2012-07-09  5:10 ` Thierry Reding
  2012-07-09  5:27   ` Alex Courbot
  2012-07-09  5:11 ` [PATCH] " Jingoo Han
  1 sibling, 1 reply; 7+ messages in thread
From: Thierry Reding @ 2012-07-09  5:10 UTC (permalink / raw)
  To: Alexandre Courbot; +Cc: linux-kernel, linux-fbdev

[-- Attachment #1: Type: text/plain, Size: 2141 bytes --]

On Mon, Jul 09, 2012 at 01:21:40PM +0900, Alexandre Courbot wrote:
> pwm_backlight_update_status calls two callbacks before and after
> applying the new PWM settings. However, the brightness scale is
> completely changed in between if brightness levels are used. This patch
> ensures that both callbacks are passed brightness values of the same
> meaning.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
>  drivers/video/backlight/pwm_bl.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)

I had to actually read this patch a number of times and then realized I
was completely missing the context. Looking at the whole function makes
it more obvious what you mean.

However I think it'd be much clearer if we just passed the value of
bl->props.brightness into the callbacks, that way we can avoid the
additional variable.

Thierry

> 
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index 057389d..dd4d24d 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -39,6 +39,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
>  {
>  	struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
>  	int brightness = bl->props.brightness;
> +	int pwm_brightness;
>  	int max = bl->props.max_brightness;
>  
>  	if (bl->props.power != FB_BLANK_UNBLANK)
> @@ -55,13 +56,14 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
>  		pwm_disable(pb->pwm);
>  	} else {
>  		if (pb->levels) {
> -			brightness = pb->levels[brightness];
> +			pwm_brightness = pb->levels[brightness];
>  			max = pb->levels[max];
> -		}
> +		} else
> +			pwm_brightness = brightness;
>  
> -		brightness = pb->lth_brightness +
> -			(brightness * (pb->period - pb->lth_brightness) / max);
> -		pwm_config(pb->pwm, brightness, pb->period);
> +		pwm_brightness = pb->lth_brightness +
> +		     (pwm_brightness * (pb->period - pb->lth_brightness) / max);
> +		pwm_config(pb->pwm, pwm_brightness, pb->period);
>  		pwm_enable(pb->pwm);
>  	}
>  
> -- 
> 1.7.11.1
> 
> 

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

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

* RE: [PATCH] pwm_backlight: pass correct brightness to callback
  2012-07-09  4:21 [PATCH] pwm_backlight: pass correct brightness to callback Alexandre Courbot
  2012-07-09  5:10 ` Thierry Reding
@ 2012-07-09  5:11 ` Jingoo Han
  1 sibling, 0 replies; 7+ messages in thread
From: Jingoo Han @ 2012-07-09  5:11 UTC (permalink / raw)
  To: 'Alexandre Courbot', 'Thierry Reding'
  Cc: linux-kernel, linux-fbdev, 'Jingoo Han'

On Monday, July 09, 2012 1:22 PM, Alexandre Courbot wrote:

> pwm_backlight_update_status calls two callbacks before and after
> applying the new PWM settings. However, the brightness scale is
> completely changed in between if brightness levels are used. This patch
> ensures that both callbacks are passed brightness values of the same
> meaning.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
>  drivers/video/backlight/pwm_bl.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index 057389d..dd4d24d 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -39,6 +39,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
>  {
>  	struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
>  	int brightness = bl->props.brightness;
> +	int pwm_brightness;
>  	int max = bl->props.max_brightness;
> 
>  	if (bl->props.power != FB_BLANK_UNBLANK)
> @@ -55,13 +56,14 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
>  		pwm_disable(pb->pwm);
>  	} else {
>  		if (pb->levels) {
> -			brightness = pb->levels[brightness];
> +			pwm_brightness = pb->levels[brightness];
>  			max = pb->levels[max];
> -		}
> +		} else
> +			pwm_brightness = brightness;

Hi Alexandre Courbot,

Please, use braces to keep the Coding Style.
Refer to Documentation/CodingStyle as follow:

169 This does not apply if only one branch of a conditional statement is a single
170 statement; in the latter case use braces in both branches:
171
172 if (condition) {
173         do_this();
174         do_that();
175 } else {
176         otherwise();
177 }

Best regards,
Jingoo Han

> 
> -		brightness = pb->lth_brightness +
> -			(brightness * (pb->period - pb->lth_brightness) / max);
> -		pwm_config(pb->pwm, brightness, pb->period);
> +		pwm_brightness = pb->lth_brightness +
> +		     (pwm_brightness * (pb->period - pb->lth_brightness) / max);
> +		pwm_config(pb->pwm, pwm_brightness, pb->period);
>  		pwm_enable(pb->pwm);
>  	}
> 
> --
> 1.7.11.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

* Re: [PATCH] pwm_backlight: pass correct brightness to callback
  2012-07-09  5:10 ` Thierry Reding
@ 2012-07-09  5:27   ` Alex Courbot
  2012-07-09  5:36     ` [PATCHv2] " Alexandre Courbot
  2012-07-09  6:04     ` [PATCHv3] " Alexandre Courbot
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Courbot @ 2012-07-09  5:27 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org

On 07/09/2012 02:10 PM, Thierry Reding wrote:
> I had to actually read this patch a number of times and then realized I
> was completely missing the context. Looking at the whole function makes
> it more obvious what you mean.
>
> However I think it'd be much clearer if we just passed the value of
> bl->props.brightness into the callbacks, that way we can avoid the
> additional variable.

This won't work I'm afraid, as brightness can be modified prior to being 
passed to the callback function:

	if (bl->props.power != FB_BLANK_UNBLANK)
		brightness = 0;

	if (bl->props.fb_blank != FB_BLANK_UNBLANK)
		brightness = 0;

	if (pb->notify)
		brightness = pb->notify(pb->dev, brightness);

Alex.

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

* [PATCHv2] pwm_backlight: pass correct brightness to callback
  2012-07-09  5:27   ` Alex Courbot
@ 2012-07-09  5:36     ` Alexandre Courbot
  2012-07-09  6:04     ` [PATCHv3] " Alexandre Courbot
  1 sibling, 0 replies; 7+ messages in thread
From: Alexandre Courbot @ 2012-07-09  5:36 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-kernel, linux-fbdev, Alexandre Courbot

pwm_backlight_update_status calls the notify() and notify_after()
callbacks before and after applying the new PWM settings. However, if
brightness levels are used, the brightness value will be changed from
the index into the levels array to the PWM duty cycle length before
being passed to notify_after(), which results in inconsistent behavior.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/video/backlight/pwm_bl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 057389d..6d1d3ea 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -39,6 +39,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
 {
 	struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
 	int brightness = bl->props.brightness;
+	int pwm_brightness;
 	int max = bl->props.max_brightness;
 
 	if (bl->props.power != FB_BLANK_UNBLANK)
@@ -55,13 +56,15 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
 		pwm_disable(pb->pwm);
 	} else {
 		if (pb->levels) {
-			brightness = pb->levels[brightness];
+			pwm_brightness = pb->levels[brightness];
 			max = pb->levels[max];
+		} else {
+			pwm_brightness = brightness;
 		}
 
-		brightness = pb->lth_brightness +
-			(brightness * (pb->period - pb->lth_brightness) / max);
-		pwm_config(pb->pwm, brightness, pb->period);
+		pwm_brightness = pb->lth_brightness +
+		     (pwm_brightness * (pb->period - pb->lth_brightness) / max);
+		pwm_config(pb->pwm, pwm_brightness, pb->period);
 		pwm_enable(pb->pwm);
 	}
 
-- 
1.7.11.1


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

* [PATCHv3] pwm_backlight: pass correct brightness to callback
  2012-07-09  5:27   ` Alex Courbot
  2012-07-09  5:36     ` [PATCHv2] " Alexandre Courbot
@ 2012-07-09  6:04     ` Alexandre Courbot
  2012-07-09  6:30       ` Thierry Reding
  1 sibling, 1 reply; 7+ messages in thread
From: Alexandre Courbot @ 2012-07-09  6:04 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-kernel, linux-fbdev, Alexandre Courbot

pwm_backlight_update_status calls the notify() and notify_after()
callbacks before and after applying the new PWM settings. However, if
brightness levels are used, the brightness value will be changed from
the index into the levels array to the PWM duty cycle length before
being passed to notify_after(), which results in inconsistent behavior.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/video/backlight/pwm_bl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 057389d..be48517 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -54,14 +54,17 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
 		pwm_config(pb->pwm, 0, pb->period);
 		pwm_disable(pb->pwm);
 	} else {
+		int duty_cycle;
 		if (pb->levels) {
-			brightness = pb->levels[brightness];
+			duty_cycle = pb->levels[brightness];
 			max = pb->levels[max];
+		} else {
+			duty_cycle = brightness;
 		}
 
-		brightness = pb->lth_brightness +
-			(brightness * (pb->period - pb->lth_brightness) / max);
-		pwm_config(pb->pwm, brightness, pb->period);
+		duty_cycle = pb->lth_brightness +
+		     (duty_cycle * (pb->period - pb->lth_brightness) / max);
+		pwm_config(pb->pwm, duty_cycle, pb->period);
 		pwm_enable(pb->pwm);
 	}
 
-- 
1.7.11.1


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

* Re: [PATCHv3] pwm_backlight: pass correct brightness to callback
  2012-07-09  6:04     ` [PATCHv3] " Alexandre Courbot
@ 2012-07-09  6:30       ` Thierry Reding
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2012-07-09  6:30 UTC (permalink / raw)
  To: Alexandre Courbot; +Cc: linux-kernel, linux-fbdev

[-- Attachment #1: Type: text/plain, Size: 1712 bytes --]

On Mon, Jul 09, 2012 at 03:04:23PM +0900, Alexandre Courbot wrote:
> pwm_backlight_update_status calls the notify() and notify_after()
> callbacks before and after applying the new PWM settings. However, if
> brightness levels are used, the brightness value will be changed from
> the index into the levels array to the PWM duty cycle length before
> being passed to notify_after(), which results in inconsistent behavior.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
>  drivers/video/backlight/pwm_bl.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)

Applied, with a minor stylistic fixup adding a blank line after the
duty_cycle variable declaration. Thanks.

Thierry

> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index 057389d..be48517 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -54,14 +54,17 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
>  		pwm_config(pb->pwm, 0, pb->period);
>  		pwm_disable(pb->pwm);
>  	} else {
> +		int duty_cycle;
>  		if (pb->levels) {
> -			brightness = pb->levels[brightness];
> +			duty_cycle = pb->levels[brightness];
>  			max = pb->levels[max];
> +		} else {
> +			duty_cycle = brightness;
>  		}
>  
> -		brightness = pb->lth_brightness +
> -			(brightness * (pb->period - pb->lth_brightness) / max);
> -		pwm_config(pb->pwm, brightness, pb->period);
> +		duty_cycle = pb->lth_brightness +
> +		     (duty_cycle * (pb->period - pb->lth_brightness) / max);
> +		pwm_config(pb->pwm, duty_cycle, pb->period);
>  		pwm_enable(pb->pwm);
>  	}
>  
> -- 
> 1.7.11.1
> 
> 
> 

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2012-07-09  6:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-09  4:21 [PATCH] pwm_backlight: pass correct brightness to callback Alexandre Courbot
2012-07-09  5:10 ` Thierry Reding
2012-07-09  5:27   ` Alex Courbot
2012-07-09  5:36     ` [PATCHv2] " Alexandre Courbot
2012-07-09  6:04     ` [PATCHv3] " Alexandre Courbot
2012-07-09  6:30       ` Thierry Reding
2012-07-09  5:11 ` [PATCH] " Jingoo Han

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).