linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups
@ 2013-10-23  9:55 Johan Hovold
  2013-10-23  9:55 ` [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
                   ` (9 more replies)
  0 siblings, 10 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

These patches fix a few issues and clean up the atmel-pwm-bl driver
somewhat.

Resend with added ack from Jingo Han.

Johan

Johan Hovold (9):
  backlight: atmel-pwm-bl: fix reported brightness
  backlight: atmel-pwm-bl: fix gpio polarity in remove
  backlight: atmel-pwm-bl: fix module autoload
  backlight: atmel-pwm-bl: clean up probe error handling
  backlight: atmel-pwm-bl: clean up get_intensity
  backlight: atmel-pwm-bl: remove unused include
  backlight: atmel-pwm-bl: use gpio_is_valid
  backlight: atmel-pwm-bl: refactor gpio_on handling
  backlight: atmel-pwm-bl: use gpio_request_one

 drivers/video/backlight/atmel-pwm-bl.c | 86 ++++++++++++++++------------------
 1 file changed, 40 insertions(+), 46 deletions(-)

-- 
1.8.4


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

* [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-25 11:08   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-23  9:55 ` [PATCH 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold, stable

The driver supports 16-bit brightness values, but the value returned
from get_brightness was truncated to eight bits.

Cc: stable@vger.kernel.org
Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 66885fb..8aac273 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -70,7 +70,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
-	u8 intensity;
+	u32 intensity;
 
 	if (pwmbl->pdata->pwm_active_low) {
 		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
@@ -80,7 +80,7 @@ static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
 	}
 
-	return intensity;
+	return (u16)intensity;
 }
 
 static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
-- 
1.8.4


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

* [PATCH 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  2013-10-23  9:55 ` [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-25 11:09   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-23  9:55 ` [PATCH 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold, stable

Make sure to honour gpio polarity also at remove so that the backlight
is actually disabled on boards with active-low enable pin.

Cc: stable@vger.kernel.org
Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 8aac273..3cb0094 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -205,8 +205,10 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (pwmbl->gpio_on != -1)
-		gpio_set_value(pwmbl->gpio_on, 0);
+	if (pwmbl->gpio_on != -1) {
+		gpio_set_value(pwmbl->gpio_on,
+					0 ^ pwmbl->pdata->on_active_low);
+	}
 	pwm_channel_disable(&pwmbl->pwmc);
 	pwm_channel_free(&pwmbl->pwmc);
 
-- 
1.8.4


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

* [PATCH 3/9] backlight: atmel-pwm-bl: fix module autoload
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  2013-10-23  9:55 ` [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
  2013-10-23  9:55 ` [PATCH 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-23  9:55 ` [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Add missing module alias which is needed for module autoloading.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 3cb0094..cc5a5ed 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -229,3 +229,4 @@ module_platform_driver(atmel_pwm_bl_driver);
 MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
 MODULE_DESCRIPTION("Atmel PWM backlight driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:atmel-pwm-bl");
-- 
1.8.4


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

* [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                   ` (2 preceding siblings ...)
  2013-10-23  9:55 ` [PATCH 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-25 11:11   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-23  9:55 ` [PATCH 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Clean up probe error handling by checking parameters before any
allocations and removing an obsolete error label. Also remove
unnecessary reset of private gpio number.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index cc5a5ed..52a8134 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -126,40 +126,33 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	struct atmel_pwm_bl *pwmbl;
 	int retval;
 
+	pdata = dev_get_platdata(&pdev->dev);
+	if (!pdata)
+		return -ENODEV;
+
+	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
+			pdata->pwm_duty_min > pdata->pwm_duty_max ||
+			pdata->pwm_frequency == 0)
+		return -EINVAL;
+
 	pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
 				GFP_KERNEL);
 	if (!pwmbl)
 		return -ENOMEM;
 
 	pwmbl->pdev = pdev;
-
-	pdata = dev_get_platdata(&pdev->dev);
-	if (!pdata) {
-		retval = -ENODEV;
-		goto err_free_mem;
-	}
-
-	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
-			pdata->pwm_duty_min > pdata->pwm_duty_max ||
-			pdata->pwm_frequency == 0) {
-		retval = -EINVAL;
-		goto err_free_mem;
-	}
-
 	pwmbl->pdata = pdata;
 	pwmbl->gpio_on = pdata->gpio_on;
 
 	retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
 	if (retval)
-		goto err_free_mem;
+		return retval;
 
 	if (pwmbl->gpio_on != -1) {
 		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
 					"gpio_atmel_pwm_bl");
-		if (retval) {
-			pwmbl->gpio_on = -1;
+		if (retval)
 			goto err_free_pwm;
-		}
 
 		/* Turn display off by default. */
 		retval = gpio_direction_output(pwmbl->gpio_on,
@@ -197,7 +190,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 
 err_free_pwm:
 	pwm_channel_free(&pwmbl->pwmc);
-err_free_mem:
+
 	return retval;
 }
 
-- 
1.8.4


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

* [PATCH 5/9] backlight: atmel-pwm-bl: clean up get_intensity
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                   ` (3 preceding siblings ...)
  2013-10-23  9:55 ` [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-25 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-23  9:55 ` [PATCH 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Clean up get_intensity to increase readability.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 52a8134..504061c 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -70,15 +70,14 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
+	u32 cdty;
 	u32 intensity;
 
-	if (pwmbl->pdata->pwm_active_low) {
-		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
-			pwmbl->pdata->pwm_duty_min;
-	} else {
-		intensity = pwmbl->pdata->pwm_duty_max -
-			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
-	}
+	cdty = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
+	if (pwmbl->pdata->pwm_active_low)
+		intensity = cdty - pwmbl->pdata->pwm_duty_min;
+	else
+		intensity = pwmbl->pdata->pwm_duty_max - cdty;
 
 	return (u16)intensity;
 }
-- 
1.8.4


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

* [PATCH 6/9] backlight: atmel-pwm-bl: remove unused include
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                   ` (4 preceding siblings ...)
  2013-10-23  9:55 ` [PATCH 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-23  9:55 ` [PATCH 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Remove unused include of clk.h.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 504061c..db68cab 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -12,7 +12,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/fb.h>
-#include <linux/clk.h>
 #include <linux/gpio.h>
 #include <linux/backlight.h>
 #include <linux/atmel_pwm.h>
-- 
1.8.4


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

* [PATCH 7/9] backlight: atmel-pwm-bl: use gpio_is_valid
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                   ` (5 preceding siblings ...)
  2013-10-23  9:55 ` [PATCH 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-23  9:55 ` [PATCH 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Use gpio_is_valid rather than open coding the more restrictive != -1
test.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index db68cab..ffc30d2 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -48,7 +48,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 		pwm_duty = pwmbl->pdata->pwm_duty_min;
 
 	if (!intensity) {
-		if (pwmbl->gpio_on != -1) {
+		if (gpio_is_valid(pwmbl->gpio_on)) {
 			gpio_set_value(pwmbl->gpio_on,
 					0 ^ pwmbl->pdata->on_active_low);
 		}
@@ -57,7 +57,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 	} else {
 		pwm_channel_enable(&pwmbl->pwmc);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
-		if (pwmbl->gpio_on != -1) {
+		if (gpio_is_valid(pwmbl->gpio_on)) {
 			gpio_set_value(pwmbl->gpio_on,
 					1 ^ pwmbl->pdata->on_active_low);
 		}
@@ -146,7 +146,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	if (retval)
 		return retval;
 
-	if (pwmbl->gpio_on != -1) {
+	if (gpio_is_valid(pwmbl->gpio_on)) {
 		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
 					"gpio_atmel_pwm_bl");
 		if (retval)
@@ -196,7 +196,7 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (pwmbl->gpio_on != -1) {
+	if (gpio_is_valid(pwmbl->gpio_on)) {
 		gpio_set_value(pwmbl->gpio_on,
 					0 ^ pwmbl->pdata->on_active_low);
 	}
-- 
1.8.4


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

* [PATCH 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                   ` (6 preceding siblings ...)
  2013-10-23  9:55 ` [PATCH 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-25 11:13   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-23  9:55 ` [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  9 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Add helper function to control the gpio_on signal.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index ffc30d2..1277e0c 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -26,6 +26,14 @@ struct atmel_pwm_bl {
 	int					gpio_on;
 };
 
+static void atmel_pwm_bl_set_gpio_on(struct atmel_pwm_bl *pwmbl, int on)
+{
+	if (!gpio_is_valid(pwmbl->gpio_on))
+		return;
+
+	gpio_set_value(pwmbl->gpio_on, on ^ pwmbl->pdata->on_active_low);
+}
+
 static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
@@ -48,19 +56,13 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 		pwm_duty = pwmbl->pdata->pwm_duty_min;
 
 	if (!intensity) {
-		if (gpio_is_valid(pwmbl->gpio_on)) {
-			gpio_set_value(pwmbl->gpio_on,
-					0 ^ pwmbl->pdata->on_active_low);
-		}
+		atmel_pwm_bl_set_gpio_on(pwmbl, 0);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
 		pwm_channel_disable(&pwmbl->pwmc);
 	} else {
 		pwm_channel_enable(&pwmbl->pwmc);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
-		if (gpio_is_valid(pwmbl->gpio_on)) {
-			gpio_set_value(pwmbl->gpio_on,
-					1 ^ pwmbl->pdata->on_active_low);
-		}
+		atmel_pwm_bl_set_gpio_on(pwmbl, 1);
 	}
 
 	return 0;
@@ -196,10 +198,7 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (gpio_is_valid(pwmbl->gpio_on)) {
-		gpio_set_value(pwmbl->gpio_on,
-					0 ^ pwmbl->pdata->on_active_low);
-	}
+	atmel_pwm_bl_set_gpio_on(pwmbl, 0);
 	pwm_channel_disable(&pwmbl->pwmc);
 	pwm_channel_free(&pwmbl->pwmc);
 
-- 
1.8.4


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

* [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                   ` (7 preceding siblings ...)
  2013-10-23  9:55 ` [PATCH 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
@ 2013-10-23  9:55 ` Johan Hovold
  2013-10-25 11:15   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  9 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-23  9:55 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Use devm_gpio_request_one rather than requesting and setting direction
in two calls.

Acked-by: Jingoo Han <jg1.han@samsung.com>:w
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 1277e0c..5ea2517 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -124,6 +124,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	const struct atmel_pwm_bl_platform_data *pdata;
 	struct backlight_device *bldev;
 	struct atmel_pwm_bl *pwmbl;
+	int flags;
 	int retval;
 
 	pdata = dev_get_platdata(&pdev->dev);
@@ -149,14 +150,14 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 		return retval;
 
 	if (gpio_is_valid(pwmbl->gpio_on)) {
-		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
-					"gpio_atmel_pwm_bl");
-		if (retval)
-			goto err_free_pwm;
-
 		/* Turn display off by default. */
-		retval = gpio_direction_output(pwmbl->gpio_on,
-				0 ^ pdata->on_active_low);
+		if (pdata->on_active_low)
+			flags = GPIOF_OUT_INIT_HIGH;
+		else
+			flags = GPIOF_OUT_INIT_LOW;
+
+		retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
+						flags, "gpio_atmel_pwm_bl");
 		if (retval)
 			goto err_free_pwm;
 	}
-- 
1.8.4


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

* Re: [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness
  2013-10-23  9:55 ` [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
@ 2013-10-25 11:08   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-29 13:32     ` Johan Hovold
  0 siblings, 1 reply; 43+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-25 11:08 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Richard Purdie, Jingoo Han, Nicolas Ferre, Tomi Valkeinen,
	Andrew Morton, linux-fbdev, linux-kernel, stable

On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> The driver supports 16-bit brightness values, but the value returned
> from get_brightness was truncated to eight bits.
> 
> Cc: stable@vger.kernel.org
> Acked-by: Jingoo Han <jg1.han@samsung.com>
> Signed-off-by: Johan Hovold <jhovold@gmail.com>
> ---
>  drivers/video/backlight/atmel-pwm-bl.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> index 66885fb..8aac273 100644
> --- a/drivers/video/backlight/atmel-pwm-bl.c
> +++ b/drivers/video/backlight/atmel-pwm-bl.c
> @@ -70,7 +70,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
>  static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
>  {
>  	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
> -	u8 intensity;
> +	u32 intensity;
>  
>  	if (pwmbl->pdata->pwm_active_low) {
>  		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
> @@ -80,7 +80,7 @@ static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
>  			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
>  	}
>  
> -	return intensity;
> +	return (u16)intensity;
no cast mask it
>  }
>  
>  static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
> -- 
> 1.8.4
> 

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

* Re: [PATCH 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove
  2013-10-23  9:55 ` [PATCH 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
@ 2013-10-25 11:09   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-29 13:08     ` Johan Hovold
  0 siblings, 1 reply; 43+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-25 11:09 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Richard Purdie, Jingoo Han, Nicolas Ferre, Tomi Valkeinen,
	Andrew Morton, linux-fbdev, linux-kernel, stable

On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> Make sure to honour gpio polarity also at remove so that the backlight
> is actually disabled on boards with active-low enable pin.
> 
> Cc: stable@vger.kernel.org
> Acked-by: Jingoo Han <jg1.han@samsung.com>
> Signed-off-by: Johan Hovold <jhovold@gmail.com>
> ---
>  drivers/video/backlight/atmel-pwm-bl.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> index 8aac273..3cb0094 100644
> --- a/drivers/video/backlight/atmel-pwm-bl.c
> +++ b/drivers/video/backlight/atmel-pwm-bl.c
> @@ -205,8 +205,10 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
>  {
>  	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
>  
> -	if (pwmbl->gpio_on != -1)
> -		gpio_set_value(pwmbl->gpio_on, 0);
> +	if (pwmbl->gpio_on != -1) {
here we need to use gpio_is_valid
> +		gpio_set_value(pwmbl->gpio_on,
> +					0 ^ pwmbl->pdata->on_active_low);
> +	}
>  	pwm_channel_disable(&pwmbl->pwmc);
>  	pwm_channel_free(&pwmbl->pwmc);
>  
> -- 
> 1.8.4
> 

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

* Re: [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling
  2013-10-23  9:55 ` [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
@ 2013-10-25 11:11   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-29 13:09     ` Johan Hovold
  0 siblings, 1 reply; 43+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-25 11:11 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Richard Purdie, Jingoo Han, Nicolas Ferre, Tomi Valkeinen,
	Andrew Morton, linux-fbdev, linux-kernel

On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> Clean up probe error handling by checking parameters before any
> allocations and removing an obsolete error label. Also remove
> unnecessary reset of private gpio number.
> 
> Acked-by: Jingoo Han <jg1.han@samsung.com>
> Signed-off-by: Johan Hovold <jhovold@gmail.com>
> ---
>  drivers/video/backlight/atmel-pwm-bl.c | 31 ++++++++++++-------------------
>  1 file changed, 12 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> index cc5a5ed..52a8134 100644
> --- a/drivers/video/backlight/atmel-pwm-bl.c
> +++ b/drivers/video/backlight/atmel-pwm-bl.c
> @@ -126,40 +126,33 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
>  	struct atmel_pwm_bl *pwmbl;
>  	int retval;
>  
> +	pdata = dev_get_platdata(&pdev->dev);
> +	if (!pdata)
> +		return -ENODEV;
> +
> +	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
> +			pdata->pwm_duty_min > pdata->pwm_duty_max ||
> +			pdata->pwm_frequency == 0)
> +		return -EINVAL;
> +
>  	pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
>  				GFP_KERNEL);
>  	if (!pwmbl)
>  		return -ENOMEM;
>  
>  	pwmbl->pdev = pdev;
> -
> -	pdata = dev_get_platdata(&pdev->dev);
> -	if (!pdata) {
> -		retval = -ENODEV;
> -		goto err_free_mem;
> -	}
> -
> -	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
> -			pdata->pwm_duty_min > pdata->pwm_duty_max ||
> -			pdata->pwm_frequency == 0) {
> -		retval = -EINVAL;
> -		goto err_free_mem;
> -	}
> -
>  	pwmbl->pdata = pdata;
>  	pwmbl->gpio_on = pdata->gpio_on;
>  
>  	retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
>  	if (retval)
> -		goto err_free_mem;
> +		return retval;
>  
>  	if (pwmbl->gpio_on != -1) {
gpio_is_valid here
>  		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
>  					"gpio_atmel_pwm_bl");
> -		if (retval) {
> -			pwmbl->gpio_on = -1;
> +		if (retval)
>  			goto err_free_pwm;
> -		}
>  
>  		/* Turn display off by default. */
>  		retval = gpio_direction_output(pwmbl->gpio_on,
> @@ -197,7 +190,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
>  
>  err_free_pwm:
>  	pwm_channel_free(&pwmbl->pwmc);
> -err_free_mem:
> +
>  	return retval;
>  }
>  
> -- 
> 1.8.4
> 

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

* Re: [PATCH 5/9] backlight: atmel-pwm-bl: clean up get_intensity
  2013-10-23  9:55 ` [PATCH 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
@ 2013-10-25 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 43+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-25 11:12 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Richard Purdie, Jingoo Han, Nicolas Ferre, Tomi Valkeinen,
	Andrew Morton, linux-fbdev, linux-kernel

On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> Clean up get_intensity to increase readability.
> 
> Acked-by: Jingoo Han <jg1.han@samsung.com>
> Signed-off-by: Johan Hovold <jhovold@gmail.com>

this ok
> ---
>  drivers/video/backlight/atmel-pwm-bl.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> index 52a8134..504061c 100644
> --- a/drivers/video/backlight/atmel-pwm-bl.c
> +++ b/drivers/video/backlight/atmel-pwm-bl.c
> @@ -70,15 +70,14 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
>  static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
>  {
>  	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
> +	u32 cdty;
>  	u32 intensity;
>  
> -	if (pwmbl->pdata->pwm_active_low) {
> -		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
> -			pwmbl->pdata->pwm_duty_min;
> -	} else {
> -		intensity = pwmbl->pdata->pwm_duty_max -
> -			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
> -	}
> +	cdty = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
> +	if (pwmbl->pdata->pwm_active_low)
> +		intensity = cdty - pwmbl->pdata->pwm_duty_min;
> +	else
> +		intensity = pwmbl->pdata->pwm_duty_max - cdty;
>  
>  	return (u16)intensity;
>  }
> -- 
> 1.8.4
> 

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

* Re: [PATCH 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling
  2013-10-23  9:55 ` [PATCH 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
@ 2013-10-25 11:13   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 43+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-25 11:13 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Richard Purdie, Jingoo Han, Nicolas Ferre, Tomi Valkeinen,
	Andrew Morton, linux-fbdev, linux-kernel

On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> Add helper function to control the gpio_on signal.
> 
> Acked-by: Jingoo Han <jg1.han@samsung.com>
> Signed-off-by: Johan Hovold <jhovold@gmail.com>

ok
> ---
>  drivers/video/backlight/atmel-pwm-bl.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> index ffc30d2..1277e0c 100644
> --- a/drivers/video/backlight/atmel-pwm-bl.c
> +++ b/drivers/video/backlight/atmel-pwm-bl.c
> @@ -26,6 +26,14 @@ struct atmel_pwm_bl {
>  	int					gpio_on;
>  };
>  
> +static void atmel_pwm_bl_set_gpio_on(struct atmel_pwm_bl *pwmbl, int on)
> +{
> +	if (!gpio_is_valid(pwmbl->gpio_on))
> +		return;
> +
> +	gpio_set_value(pwmbl->gpio_on, on ^ pwmbl->pdata->on_active_low);
> +}
> +
>  static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
>  {
>  	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
> @@ -48,19 +56,13 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
>  		pwm_duty = pwmbl->pdata->pwm_duty_min;
>  
>  	if (!intensity) {
> -		if (gpio_is_valid(pwmbl->gpio_on)) {
> -			gpio_set_value(pwmbl->gpio_on,
> -					0 ^ pwmbl->pdata->on_active_low);
> -		}
> +		atmel_pwm_bl_set_gpio_on(pwmbl, 0);
>  		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
>  		pwm_channel_disable(&pwmbl->pwmc);
>  	} else {
>  		pwm_channel_enable(&pwmbl->pwmc);
>  		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
> -		if (gpio_is_valid(pwmbl->gpio_on)) {
> -			gpio_set_value(pwmbl->gpio_on,
> -					1 ^ pwmbl->pdata->on_active_low);
> -		}
> +		atmel_pwm_bl_set_gpio_on(pwmbl, 1);
>  	}
>  
>  	return 0;
> @@ -196,10 +198,7 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
>  {
>  	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
>  
> -	if (gpio_is_valid(pwmbl->gpio_on)) {
> -		gpio_set_value(pwmbl->gpio_on,
> -					0 ^ pwmbl->pdata->on_active_low);
> -	}
> +	atmel_pwm_bl_set_gpio_on(pwmbl, 0);
>  	pwm_channel_disable(&pwmbl->pwmc);
>  	pwm_channel_free(&pwmbl->pwmc);
>  
> -- 
> 1.8.4
> 

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

* Re: [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one
  2013-10-23  9:55 ` [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
@ 2013-10-25 11:15   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-29 13:20     ` Johan Hovold
  0 siblings, 1 reply; 43+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-25 11:15 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Richard Purdie, Jingoo Han, Nicolas Ferre, Tomi Valkeinen,
	Andrew Morton, linux-fbdev, linux-kernel

On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> Use devm_gpio_request_one rather than requesting and setting direction
> in two calls.

this is the same I do not see any advantage

and as I said for ather backligth It's wrong to enable or disable it at probe
as the bootloader might have already enable it for splash screen

Best Regards,
J.
> 
> Acked-by: Jingoo Han <jg1.han@samsung.com>:w
> Signed-off-by: Johan Hovold <jhovold@gmail.com>
> ---
>  drivers/video/backlight/atmel-pwm-bl.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> index 1277e0c..5ea2517 100644
> --- a/drivers/video/backlight/atmel-pwm-bl.c
> +++ b/drivers/video/backlight/atmel-pwm-bl.c
> @@ -124,6 +124,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
>  	const struct atmel_pwm_bl_platform_data *pdata;
>  	struct backlight_device *bldev;
>  	struct atmel_pwm_bl *pwmbl;
> +	int flags;
>  	int retval;
>  
>  	pdata = dev_get_platdata(&pdev->dev);
> @@ -149,14 +150,14 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
>  		return retval;
>  
>  	if (gpio_is_valid(pwmbl->gpio_on)) {
> -		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
> -					"gpio_atmel_pwm_bl");
> -		if (retval)
> -			goto err_free_pwm;
> -
>  		/* Turn display off by default. */
> -		retval = gpio_direction_output(pwmbl->gpio_on,
> -				0 ^ pdata->on_active_low);
> +		if (pdata->on_active_low)
> +			flags = GPIOF_OUT_INIT_HIGH;
> +		else
> +			flags = GPIOF_OUT_INIT_LOW;
> +
> +		retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
> +						flags, "gpio_atmel_pwm_bl");
>  		if (retval)
>  			goto err_free_pwm;
>  	}
> -- 
> 1.8.4
> 

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

* Re: [PATCH 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove
  2013-10-25 11:09   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-29 13:08     ` Johan Hovold
  0 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 13:08 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: Johan Hovold, Richard Purdie, Jingoo Han, Nicolas Ferre,
	Tomi Valkeinen, Andrew Morton, linux-fbdev, linux-kernel, stable

On Fri, Oct 25, 2013 at 01:09:28PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> > Make sure to honour gpio polarity also at remove so that the backlight
> > is actually disabled on boards with active-low enable pin.
> > 
> > Cc: stable@vger.kernel.org
> > Acked-by: Jingoo Han <jg1.han@samsung.com>
> > Signed-off-by: Johan Hovold <jhovold@gmail.com>
> > ---
> >  drivers/video/backlight/atmel-pwm-bl.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> > index 8aac273..3cb0094 100644
> > --- a/drivers/video/backlight/atmel-pwm-bl.c
> > +++ b/drivers/video/backlight/atmel-pwm-bl.c
> > @@ -205,8 +205,10 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
> >  {
> >  	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
> >  
> > -	if (pwmbl->gpio_on != -1)
> > -		gpio_set_value(pwmbl->gpio_on, 0);
> > +	if (pwmbl->gpio_on != -1) {
> here we need to use gpio_is_valid

That is a different issue which is fixed by patch 7/9. It doesn't make
sense to only change one of the gpio-validity tests.

Johan

> > +		gpio_set_value(pwmbl->gpio_on,
> > +					0 ^ pwmbl->pdata->on_active_low);
> > +	}
> >  	pwm_channel_disable(&pwmbl->pwmc);
> >  	pwm_channel_free(&pwmbl->pwmc);
> >  
> > -- 
> > 1.8.4
> > 

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

* Re: [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling
  2013-10-25 11:11   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-29 13:09     ` Johan Hovold
  0 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 13:09 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: Johan Hovold, Richard Purdie, Jingoo Han, Nicolas Ferre,
	Tomi Valkeinen, Andrew Morton, linux-fbdev, linux-kernel

On Fri, Oct 25, 2013 at 01:11:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> > Clean up probe error handling by checking parameters before any
> > allocations and removing an obsolete error label. Also remove
> > unnecessary reset of private gpio number.
> > 
> > Acked-by: Jingoo Han <jg1.han@samsung.com>
> > Signed-off-by: Johan Hovold <jhovold@gmail.com>
> > ---
> >  drivers/video/backlight/atmel-pwm-bl.c | 31 ++++++++++++-------------------
> >  1 file changed, 12 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> > index cc5a5ed..52a8134 100644
> > --- a/drivers/video/backlight/atmel-pwm-bl.c
> > +++ b/drivers/video/backlight/atmel-pwm-bl.c
> > @@ -126,40 +126,33 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
> >  	struct atmel_pwm_bl *pwmbl;
> >  	int retval;
> >  
> > +	pdata = dev_get_platdata(&pdev->dev);
> > +	if (!pdata)
> > +		return -ENODEV;
> > +
> > +	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
> > +			pdata->pwm_duty_min > pdata->pwm_duty_max ||
> > +			pdata->pwm_frequency == 0)
> > +		return -EINVAL;
> > +
> >  	pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
> >  				GFP_KERNEL);
> >  	if (!pwmbl)
> >  		return -ENOMEM;
> >  
> >  	pwmbl->pdev = pdev;
> > -
> > -	pdata = dev_get_platdata(&pdev->dev);
> > -	if (!pdata) {
> > -		retval = -ENODEV;
> > -		goto err_free_mem;
> > -	}
> > -
> > -	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
> > -			pdata->pwm_duty_min > pdata->pwm_duty_max ||
> > -			pdata->pwm_frequency == 0) {
> > -		retval = -EINVAL;
> > -		goto err_free_mem;
> > -	}
> > -
> >  	pwmbl->pdata = pdata;
> >  	pwmbl->gpio_on = pdata->gpio_on;
> >  
> >  	retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
> >  	if (retval)
> > -		goto err_free_mem;
> > +		return retval;
> >  
> >  	if (pwmbl->gpio_on != -1) {
> gpio_is_valid here

Again, this is unrelated to this patch and is fixed separately in patch
7/9.

Johan

> >  		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
> >  					"gpio_atmel_pwm_bl");
> > -		if (retval) {
> > -			pwmbl->gpio_on = -1;
> > +		if (retval)
> >  			goto err_free_pwm;
> > -		}
> >  
> >  		/* Turn display off by default. */
> >  		retval = gpio_direction_output(pwmbl->gpio_on,
> > @@ -197,7 +190,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
> >  
> >  err_free_pwm:
> >  	pwm_channel_free(&pwmbl->pwmc);
> > -err_free_mem:
> > +
> >  	return retval;
> >  }
> >  
> > -- 
> > 1.8.4
> > 

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

* Re: [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one
  2013-10-25 11:15   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-29 13:20     ` Johan Hovold
  2013-10-30 19:30       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 13:20 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: Johan Hovold, Richard Purdie, Jingoo Han, Nicolas Ferre,
	Tomi Valkeinen, Andrew Morton, linux-fbdev, linux-kernel

On Fri, Oct 25, 2013 at 01:15:43PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> > Use devm_gpio_request_one rather than requesting and setting direction
> > in two calls.
> 
> this is the same I do not see any advantage

It removes one error path.

> and as I said for ather backligth It's wrong to enable or disable it at probe
> as the bootloader might have already enable it for splash screen

I agree with you on that, and it's actually the reason for the below
clean up. I use a second patch:

        if (gpio_is_valid(pwmbl->gpio_on)) {
-               /* Turn display off by default. */
-               if (pdata->on_active_low)
+               /* Turn display off unless already enabled. */
+               if (pdata->gpio_on_enabled ^ pdata->on_active_low)
                        flags = GPIOF_OUT_INIT_HIGH;
                else
                        flags = GPIOF_OUT_INIT_LOW;

to make sure the driver does not temporarily disable the backlight at
probe.

Decided not to submit it as part of this series when I realised that
several other backlight drivers did the same, but perhaps I should?

Thanks,
Johan

> > 
> > Acked-by: Jingoo Han <jg1.han@samsung.com>:w
> > Signed-off-by: Johan Hovold <jhovold@gmail.com>
> > ---
> >  drivers/video/backlight/atmel-pwm-bl.c | 15 ++++++++-------
> >  1 file changed, 8 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> > index 1277e0c..5ea2517 100644
> > --- a/drivers/video/backlight/atmel-pwm-bl.c
> > +++ b/drivers/video/backlight/atmel-pwm-bl.c
> > @@ -124,6 +124,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
> >  	const struct atmel_pwm_bl_platform_data *pdata;
> >  	struct backlight_device *bldev;
> >  	struct atmel_pwm_bl *pwmbl;
> > +	int flags;
> >  	int retval;
> >  
> >  	pdata = dev_get_platdata(&pdev->dev);
> > @@ -149,14 +150,14 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
> >  		return retval;
> >  
> >  	if (gpio_is_valid(pwmbl->gpio_on)) {
> > -		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
> > -					"gpio_atmel_pwm_bl");
> > -		if (retval)
> > -			goto err_free_pwm;
> > -
> >  		/* Turn display off by default. */
> > -		retval = gpio_direction_output(pwmbl->gpio_on,
> > -				0 ^ pdata->on_active_low);
> > +		if (pdata->on_active_low)
> > +			flags = GPIOF_OUT_INIT_HIGH;
> > +		else
> > +			flags = GPIOF_OUT_INIT_LOW;
> > +
> > +		retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
> > +						flags, "gpio_atmel_pwm_bl");
> >  		if (retval)
> >  			goto err_free_pwm;
> >  	}
> > -- 
> > 1.8.4
> > 

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

* Re: [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness
  2013-10-25 11:08   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-29 13:32     ` Johan Hovold
  0 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 13:32 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: Johan Hovold, Richard Purdie, Jingoo Han, Nicolas Ferre,
	Tomi Valkeinen, Andrew Morton, linux-fbdev, linux-kernel, stable

On Fri, Oct 25, 2013 at 01:08:36PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> > The driver supports 16-bit brightness values, but the value returned
> > from get_brightness was truncated to eight bits.
> > 
> > Cc: stable@vger.kernel.org
> > Acked-by: Jingoo Han <jg1.han@samsung.com>
> > Signed-off-by: Johan Hovold <jhovold@gmail.com>
> > ---
> >  drivers/video/backlight/atmel-pwm-bl.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> > index 66885fb..8aac273 100644
> > --- a/drivers/video/backlight/atmel-pwm-bl.c
> > +++ b/drivers/video/backlight/atmel-pwm-bl.c
> > @@ -70,7 +70,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
> >  static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
> >  {
> >  	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
> > -	u8 intensity;
> > +	u32 intensity;
> >  
> >  	if (pwmbl->pdata->pwm_active_low) {
> >  		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
> > @@ -80,7 +80,7 @@ static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
> >  			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
> >  	}
> >  
> > -	return intensity;
> > +	return (u16)intensity;
> no cast mask it

Yeah, perhaps that is better. I discussed this a bit with Jingoo Han in
the thread of the original post. I'll respin.

Thanks,
Johan

> >  }
> >  
> >  static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
> > -- 
> > 1.8.4
> > 

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

* [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups
  2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                   ` (8 preceding siblings ...)
  2013-10-23  9:55 ` [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
@ 2013-10-29 16:27 ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
                     ` (9 more replies)
  9 siblings, 10 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

These patches fix a few issues and clean up the atmel-pwm-bl driver
somewhat.

Acks from Jingoo Han retained on all patches but the slightly modified
first patch.

Johan

v2:
 - mask returned brightness rather than cast it to u16 (patch 1/9)


Johan Hovold (9):
  backlight: atmel-pwm-bl: fix reported brightness
  backlight: atmel-pwm-bl: fix gpio polarity in remove
  backlight: atmel-pwm-bl: fix module autoload
  backlight: atmel-pwm-bl: clean up probe error handling
  backlight: atmel-pwm-bl: clean up get_intensity
  backlight: atmel-pwm-bl: remove unused include
  backlight: atmel-pwm-bl: use gpio_is_valid
  backlight: atmel-pwm-bl: refactor gpio_on handling
  backlight: atmel-pwm-bl: use gpio_request_one

 drivers/video/backlight/atmel-pwm-bl.c | 86 ++++++++++++++++------------------
 1 file changed, 40 insertions(+), 46 deletions(-)

-- 
1.8.4.2


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

* [PATCH v2 1/9] backlight: atmel-pwm-bl: fix reported brightness
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold, stable

The driver supports 16-bit brightness values, but the value returned
from get_brightness was truncated to eight bits.

Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 66885fb..0971a8e 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -70,7 +70,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
-	u8 intensity;
+	u32 intensity;
 
 	if (pwmbl->pdata->pwm_active_low) {
 		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
@@ -80,7 +80,7 @@ static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
 	}
 
-	return intensity;
+	return intensity & 0xffff;
 }
 
 static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
-- 
1.8.4.2


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

* [PATCH v2 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold, stable

Make sure to honour gpio polarity also at remove so that the backlight
is actually disabled on boards with active-low enable pin.

Cc: stable@vger.kernel.org
Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 0971a8e..e21beb6 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -205,8 +205,10 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (pwmbl->gpio_on != -1)
-		gpio_set_value(pwmbl->gpio_on, 0);
+	if (pwmbl->gpio_on != -1) {
+		gpio_set_value(pwmbl->gpio_on,
+					0 ^ pwmbl->pdata->on_active_low);
+	}
 	pwm_channel_disable(&pwmbl->pwmc);
 	pwm_channel_free(&pwmbl->pwmc);
 
-- 
1.8.4.2


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

* [PATCH v2 3/9] backlight: atmel-pwm-bl: fix module autoload
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
                     ` (6 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Add missing module alias which is needed for module autoloading.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index e21beb6..4886028 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -229,3 +229,4 @@ module_platform_driver(atmel_pwm_bl_driver);
 MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
 MODULE_DESCRIPTION("Atmel PWM backlight driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:atmel-pwm-bl");
-- 
1.8.4.2


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

* [PATCH v2 4/9] backlight: atmel-pwm-bl: clean up probe error handling
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                     ` (2 preceding siblings ...)
  2013-10-29 16:27   ` [PATCH v2 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Clean up probe error handling by checking parameters before any
allocations and removing an obsolete error label. Also remove
unnecessary reset of private gpio number.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 4886028..01af5c2 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -126,40 +126,33 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	struct atmel_pwm_bl *pwmbl;
 	int retval;
 
+	pdata = dev_get_platdata(&pdev->dev);
+	if (!pdata)
+		return -ENODEV;
+
+	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
+			pdata->pwm_duty_min > pdata->pwm_duty_max ||
+			pdata->pwm_frequency == 0)
+		return -EINVAL;
+
 	pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
 				GFP_KERNEL);
 	if (!pwmbl)
 		return -ENOMEM;
 
 	pwmbl->pdev = pdev;
-
-	pdata = dev_get_platdata(&pdev->dev);
-	if (!pdata) {
-		retval = -ENODEV;
-		goto err_free_mem;
-	}
-
-	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
-			pdata->pwm_duty_min > pdata->pwm_duty_max ||
-			pdata->pwm_frequency == 0) {
-		retval = -EINVAL;
-		goto err_free_mem;
-	}
-
 	pwmbl->pdata = pdata;
 	pwmbl->gpio_on = pdata->gpio_on;
 
 	retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
 	if (retval)
-		goto err_free_mem;
+		return retval;
 
 	if (pwmbl->gpio_on != -1) {
 		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
 					"gpio_atmel_pwm_bl");
-		if (retval) {
-			pwmbl->gpio_on = -1;
+		if (retval)
 			goto err_free_pwm;
-		}
 
 		/* Turn display off by default. */
 		retval = gpio_direction_output(pwmbl->gpio_on,
@@ -197,7 +190,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 
 err_free_pwm:
 	pwm_channel_free(&pwmbl->pwmc);
-err_free_mem:
+
 	return retval;
 }
 
-- 
1.8.4.2


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

* [PATCH v2 5/9] backlight: atmel-pwm-bl: clean up get_intensity
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                     ` (3 preceding siblings ...)
  2013-10-29 16:27   ` [PATCH v2 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Clean up get_intensity to increase readability.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 01af5c2..abfaada 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -70,15 +70,14 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
+	u32 cdty;
 	u32 intensity;
 
-	if (pwmbl->pdata->pwm_active_low) {
-		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
-			pwmbl->pdata->pwm_duty_min;
-	} else {
-		intensity = pwmbl->pdata->pwm_duty_max -
-			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
-	}
+	cdty = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
+	if (pwmbl->pdata->pwm_active_low)
+		intensity = cdty - pwmbl->pdata->pwm_duty_min;
+	else
+		intensity = pwmbl->pdata->pwm_duty_max - cdty;
 
 	return intensity & 0xffff;
 }
-- 
1.8.4.2


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

* [PATCH v2 6/9] backlight: atmel-pwm-bl: remove unused include
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                     ` (4 preceding siblings ...)
  2013-10-29 16:27   ` [PATCH v2 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Remove unused include of clk.h.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index abfaada..bfd6a96 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -12,7 +12,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/fb.h>
-#include <linux/clk.h>
 #include <linux/gpio.h>
 #include <linux/backlight.h>
 #include <linux/atmel_pwm.h>
-- 
1.8.4.2


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

* [PATCH v2 7/9] backlight: atmel-pwm-bl: use gpio_is_valid
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                     ` (5 preceding siblings ...)
  2013-10-29 16:27   ` [PATCH v2 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Use gpio_is_valid rather than open coding the more restrictive != -1
test.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index bfd6a96..c254209 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -48,7 +48,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 		pwm_duty = pwmbl->pdata->pwm_duty_min;
 
 	if (!intensity) {
-		if (pwmbl->gpio_on != -1) {
+		if (gpio_is_valid(pwmbl->gpio_on)) {
 			gpio_set_value(pwmbl->gpio_on,
 					0 ^ pwmbl->pdata->on_active_low);
 		}
@@ -57,7 +57,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 	} else {
 		pwm_channel_enable(&pwmbl->pwmc);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
-		if (pwmbl->gpio_on != -1) {
+		if (gpio_is_valid(pwmbl->gpio_on)) {
 			gpio_set_value(pwmbl->gpio_on,
 					1 ^ pwmbl->pdata->on_active_low);
 		}
@@ -146,7 +146,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	if (retval)
 		return retval;
 
-	if (pwmbl->gpio_on != -1) {
+	if (gpio_is_valid(pwmbl->gpio_on)) {
 		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
 					"gpio_atmel_pwm_bl");
 		if (retval)
@@ -196,7 +196,7 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (pwmbl->gpio_on != -1) {
+	if (gpio_is_valid(pwmbl->gpio_on)) {
 		gpio_set_value(pwmbl->gpio_on,
 					0 ^ pwmbl->pdata->on_active_low);
 	}
-- 
1.8.4.2


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

* [PATCH v2 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                     ` (6 preceding siblings ...)
  2013-10-29 16:27   ` [PATCH v2 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-29 16:27   ` [PATCH v2 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Add helper function to control the gpio_on signal.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index c254209..bd1ed34 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -26,6 +26,14 @@ struct atmel_pwm_bl {
 	int					gpio_on;
 };
 
+static void atmel_pwm_bl_set_gpio_on(struct atmel_pwm_bl *pwmbl, int on)
+{
+	if (!gpio_is_valid(pwmbl->gpio_on))
+		return;
+
+	gpio_set_value(pwmbl->gpio_on, on ^ pwmbl->pdata->on_active_low);
+}
+
 static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
@@ -48,19 +56,13 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 		pwm_duty = pwmbl->pdata->pwm_duty_min;
 
 	if (!intensity) {
-		if (gpio_is_valid(pwmbl->gpio_on)) {
-			gpio_set_value(pwmbl->gpio_on,
-					0 ^ pwmbl->pdata->on_active_low);
-		}
+		atmel_pwm_bl_set_gpio_on(pwmbl, 0);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
 		pwm_channel_disable(&pwmbl->pwmc);
 	} else {
 		pwm_channel_enable(&pwmbl->pwmc);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
-		if (gpio_is_valid(pwmbl->gpio_on)) {
-			gpio_set_value(pwmbl->gpio_on,
-					1 ^ pwmbl->pdata->on_active_low);
-		}
+		atmel_pwm_bl_set_gpio_on(pwmbl, 1);
 	}
 
 	return 0;
@@ -196,10 +198,7 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (gpio_is_valid(pwmbl->gpio_on)) {
-		gpio_set_value(pwmbl->gpio_on,
-					0 ^ pwmbl->pdata->on_active_low);
-	}
+	atmel_pwm_bl_set_gpio_on(pwmbl, 0);
 	pwm_channel_disable(&pwmbl->pwmc);
 	pwm_channel_free(&pwmbl->pwmc);
 
-- 
1.8.4.2


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

* [PATCH v2 9/9] backlight: atmel-pwm-bl: use gpio_request_one
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                     ` (7 preceding siblings ...)
  2013-10-29 16:27   ` [PATCH v2 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
@ 2013-10-29 16:27   ` Johan Hovold
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  9 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-29 16:27 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Use devm_gpio_request_one rather than requesting and setting direction
in two calls.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index bd1ed34..03b5f3b 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -124,6 +124,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	const struct atmel_pwm_bl_platform_data *pdata;
 	struct backlight_device *bldev;
 	struct atmel_pwm_bl *pwmbl;
+	int flags;
 	int retval;
 
 	pdata = dev_get_platdata(&pdev->dev);
@@ -149,14 +150,14 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 		return retval;
 
 	if (gpio_is_valid(pwmbl->gpio_on)) {
-		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
-					"gpio_atmel_pwm_bl");
-		if (retval)
-			goto err_free_pwm;
-
 		/* Turn display off by default. */
-		retval = gpio_direction_output(pwmbl->gpio_on,
-				0 ^ pdata->on_active_low);
+		if (pdata->on_active_low)
+			flags = GPIOF_OUT_INIT_HIGH;
+		else
+			flags = GPIOF_OUT_INIT_LOW;
+
+		retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
+						flags, "gpio_atmel_pwm_bl");
 		if (retval)
 			goto err_free_pwm;
 	}
-- 
1.8.4.2


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

* Re: [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one
  2013-10-29 13:20     ` Johan Hovold
@ 2013-10-30 19:30       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 43+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-30 19:30 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Richard Purdie, Jingoo Han, Nicolas Ferre, Tomi Valkeinen,
	Andrew Morton, linux-fbdev, linux-kernel

On 14:20 Tue 29 Oct     , Johan Hovold wrote:
> On Fri, Oct 25, 2013 at 01:15:43PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 11:55 Wed 23 Oct     , Johan Hovold wrote:
> > > Use devm_gpio_request_one rather than requesting and setting direction
> > > in two calls.
> > 
> > this is the same I do not see any advantage
> 
> It removes one error path.
> 
> > and as I said for ather backligth It's wrong to enable or disable it at probe
> > as the bootloader might have already enable it for splash screen
> 
> I agree with you on that, and it's actually the reason for the below
> clean up. I use a second patch:
> 
>         if (gpio_is_valid(pwmbl->gpio_on)) {
> -               /* Turn display off by default. */
> -               if (pdata->on_active_low)
> +               /* Turn display off unless already enabled. */
> +               if (pdata->gpio_on_enabled ^ pdata->on_active_low)
>                         flags = GPIOF_OUT_INIT_HIGH;
>                 else
>                         flags = GPIOF_OUT_INIT_LOW;
> 
> to make sure the driver does not temporarily disable the backlight at
> probe.
> 
> Decided not to submit it as part of this series when I realised that
> several other backlight drivers did the same, but perhaps I should?

I'm not happy with this idea to play with enable at probe time

we need to detect the current status if possible and only enable or disable
when requiered

Best Regards,
J.
> 
> Thanks,
> Johan
> 
> > > 
> > > Acked-by: Jingoo Han <jg1.han@samsung.com>:w
> > > Signed-off-by: Johan Hovold <jhovold@gmail.com>
> > > ---
> > >  drivers/video/backlight/atmel-pwm-bl.c | 15 ++++++++-------
> > >  1 file changed, 8 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
> > > index 1277e0c..5ea2517 100644
> > > --- a/drivers/video/backlight/atmel-pwm-bl.c
> > > +++ b/drivers/video/backlight/atmel-pwm-bl.c
> > > @@ -124,6 +124,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
> > >  	const struct atmel_pwm_bl_platform_data *pdata;
> > >  	struct backlight_device *bldev;
> > >  	struct atmel_pwm_bl *pwmbl;
> > > +	int flags;
> > >  	int retval;
> > >  
> > >  	pdata = dev_get_platdata(&pdev->dev);
> > > @@ -149,14 +150,14 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
> > >  		return retval;
> > >  
> > >  	if (gpio_is_valid(pwmbl->gpio_on)) {
> > > -		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
> > > -					"gpio_atmel_pwm_bl");
> > > -		if (retval)
> > > -			goto err_free_pwm;
> > > -
> > >  		/* Turn display off by default. */
> > > -		retval = gpio_direction_output(pwmbl->gpio_on,
> > > -				0 ^ pdata->on_active_low);
> > > +		if (pdata->on_active_low)
> > > +			flags = GPIOF_OUT_INIT_HIGH;
> > > +		else
> > > +			flags = GPIOF_OUT_INIT_LOW;
> > > +
> > > +		retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
> > > +						flags, "gpio_atmel_pwm_bl");
> > >  		if (retval)
> > >  			goto err_free_pwm;
> > >  	}
> > > -- 
> > > 1.8.4
> > > 

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

* [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups
  2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                     ` (8 preceding siblings ...)
  2013-10-29 16:27   ` [PATCH v2 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
@ 2013-10-31 17:57   ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
                       ` (8 more replies)
  9 siblings, 9 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

These patches fix a few issues and clean up the atmel-pwm-bl driver
somewhat.

Acks from Jingoo Han retained on all patches but the slightly modified
first and final patch.

Johan

v2:
 - mask returned brightness rather than cast it to u16 (patch 1/9)
v3
 - use unsigned long for gpio flags (patch 9/9)

Johan Hovold (9):
  backlight: atmel-pwm-bl: fix reported brightness
  backlight: atmel-pwm-bl: fix gpio polarity in remove
  backlight: atmel-pwm-bl: fix module autoload
  backlight: atmel-pwm-bl: clean up probe error handling
  backlight: atmel-pwm-bl: clean up get_intensity
  backlight: atmel-pwm-bl: remove unused include
  backlight: atmel-pwm-bl: use gpio_is_valid
  backlight: atmel-pwm-bl: refactor gpio_on handling
  backlight: atmel-pwm-bl: use gpio_request_one

 drivers/video/backlight/atmel-pwm-bl.c | 86 ++++++++++++++++------------------
 1 file changed, 40 insertions(+), 46 deletions(-)

-- 
1.8.4.2


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

* [PATCH v3 1/9] backlight: atmel-pwm-bl: fix reported brightness
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
                       ` (7 subsequent siblings)
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold, stable

The driver supports 16-bit brightness values, but the value returned
from get_brightness was truncated to eight bits.

Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 66885fb..0971a8e 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -70,7 +70,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
-	u8 intensity;
+	u32 intensity;
 
 	if (pwmbl->pdata->pwm_active_low) {
 		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
@@ -80,7 +80,7 @@ static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
 	}
 
-	return intensity;
+	return intensity & 0xffff;
 }
 
 static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
-- 
1.8.4.2


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

* [PATCH v3 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
                       ` (6 subsequent siblings)
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold, stable

Make sure to honour gpio polarity also at remove so that the backlight
is actually disabled on boards with active-low enable pin.

Cc: stable@vger.kernel.org
Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 0971a8e..e21beb6 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -205,8 +205,10 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (pwmbl->gpio_on != -1)
-		gpio_set_value(pwmbl->gpio_on, 0);
+	if (pwmbl->gpio_on != -1) {
+		gpio_set_value(pwmbl->gpio_on,
+					0 ^ pwmbl->pdata->on_active_low);
+	}
 	pwm_channel_disable(&pwmbl->pwmc);
 	pwm_channel_free(&pwmbl->pwmc);
 
-- 
1.8.4.2


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

* [PATCH v3 3/9] backlight: atmel-pwm-bl: fix module autoload
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
                       ` (5 subsequent siblings)
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Add missing module alias which is needed for module autoloading.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index e21beb6..4886028 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -229,3 +229,4 @@ module_platform_driver(atmel_pwm_bl_driver);
 MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
 MODULE_DESCRIPTION("Atmel PWM backlight driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:atmel-pwm-bl");
-- 
1.8.4.2


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

* [PATCH v3 4/9] backlight: atmel-pwm-bl: clean up probe error handling
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                       ` (2 preceding siblings ...)
  2013-10-31 17:57     ` [PATCH v3 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
                       ` (4 subsequent siblings)
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Clean up probe error handling by checking parameters before any
allocations and removing an obsolete error label. Also remove
unnecessary reset of private gpio number.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 4886028..01af5c2 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -126,40 +126,33 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	struct atmel_pwm_bl *pwmbl;
 	int retval;
 
+	pdata = dev_get_platdata(&pdev->dev);
+	if (!pdata)
+		return -ENODEV;
+
+	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
+			pdata->pwm_duty_min > pdata->pwm_duty_max ||
+			pdata->pwm_frequency == 0)
+		return -EINVAL;
+
 	pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
 				GFP_KERNEL);
 	if (!pwmbl)
 		return -ENOMEM;
 
 	pwmbl->pdev = pdev;
-
-	pdata = dev_get_platdata(&pdev->dev);
-	if (!pdata) {
-		retval = -ENODEV;
-		goto err_free_mem;
-	}
-
-	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
-			pdata->pwm_duty_min > pdata->pwm_duty_max ||
-			pdata->pwm_frequency == 0) {
-		retval = -EINVAL;
-		goto err_free_mem;
-	}
-
 	pwmbl->pdata = pdata;
 	pwmbl->gpio_on = pdata->gpio_on;
 
 	retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
 	if (retval)
-		goto err_free_mem;
+		return retval;
 
 	if (pwmbl->gpio_on != -1) {
 		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
 					"gpio_atmel_pwm_bl");
-		if (retval) {
-			pwmbl->gpio_on = -1;
+		if (retval)
 			goto err_free_pwm;
-		}
 
 		/* Turn display off by default. */
 		retval = gpio_direction_output(pwmbl->gpio_on,
@@ -197,7 +190,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 
 err_free_pwm:
 	pwm_channel_free(&pwmbl->pwmc);
-err_free_mem:
+
 	return retval;
 }
 
-- 
1.8.4.2


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

* [PATCH v3 5/9] backlight: atmel-pwm-bl: clean up get_intensity
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                       ` (3 preceding siblings ...)
  2013-10-31 17:57     ` [PATCH v3 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
                       ` (3 subsequent siblings)
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Clean up get_intensity to increase readability.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index 01af5c2..abfaada 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -70,15 +70,14 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
+	u32 cdty;
 	u32 intensity;
 
-	if (pwmbl->pdata->pwm_active_low) {
-		intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
-			pwmbl->pdata->pwm_duty_min;
-	} else {
-		intensity = pwmbl->pdata->pwm_duty_max -
-			pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
-	}
+	cdty = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
+	if (pwmbl->pdata->pwm_active_low)
+		intensity = cdty - pwmbl->pdata->pwm_duty_min;
+	else
+		intensity = pwmbl->pdata->pwm_duty_max - cdty;
 
 	return intensity & 0xffff;
 }
-- 
1.8.4.2


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

* [PATCH v3 6/9] backlight: atmel-pwm-bl: remove unused include
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                       ` (4 preceding siblings ...)
  2013-10-31 17:57     ` [PATCH v3 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
                       ` (2 subsequent siblings)
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Remove unused include of clk.h.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index abfaada..bfd6a96 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -12,7 +12,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/fb.h>
-#include <linux/clk.h>
 #include <linux/gpio.h>
 #include <linux/backlight.h>
 #include <linux/atmel_pwm.h>
-- 
1.8.4.2


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

* [PATCH v3 7/9] backlight: atmel-pwm-bl: use gpio_is_valid
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                       ` (5 preceding siblings ...)
  2013-10-31 17:57     ` [PATCH v3 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Use gpio_is_valid rather than open coding the more restrictive != -1
test.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index bfd6a96..c254209 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -48,7 +48,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 		pwm_duty = pwmbl->pdata->pwm_duty_min;
 
 	if (!intensity) {
-		if (pwmbl->gpio_on != -1) {
+		if (gpio_is_valid(pwmbl->gpio_on)) {
 			gpio_set_value(pwmbl->gpio_on,
 					0 ^ pwmbl->pdata->on_active_low);
 		}
@@ -57,7 +57,7 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 	} else {
 		pwm_channel_enable(&pwmbl->pwmc);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
-		if (pwmbl->gpio_on != -1) {
+		if (gpio_is_valid(pwmbl->gpio_on)) {
 			gpio_set_value(pwmbl->gpio_on,
 					1 ^ pwmbl->pdata->on_active_low);
 		}
@@ -146,7 +146,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	if (retval)
 		return retval;
 
-	if (pwmbl->gpio_on != -1) {
+	if (gpio_is_valid(pwmbl->gpio_on)) {
 		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
 					"gpio_atmel_pwm_bl");
 		if (retval)
@@ -196,7 +196,7 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (pwmbl->gpio_on != -1) {
+	if (gpio_is_valid(pwmbl->gpio_on)) {
 		gpio_set_value(pwmbl->gpio_on,
 					0 ^ pwmbl->pdata->on_active_low);
 	}
-- 
1.8.4.2


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

* [PATCH v3 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                       ` (6 preceding siblings ...)
  2013-10-31 17:57     ` [PATCH v3 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  2013-10-31 17:57     ` [PATCH v3 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Add helper function to control the gpio_on signal.

Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index c254209..bd1ed34 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -26,6 +26,14 @@ struct atmel_pwm_bl {
 	int					gpio_on;
 };
 
+static void atmel_pwm_bl_set_gpio_on(struct atmel_pwm_bl *pwmbl, int on)
+{
+	if (!gpio_is_valid(pwmbl->gpio_on))
+		return;
+
+	gpio_set_value(pwmbl->gpio_on, on ^ pwmbl->pdata->on_active_low);
+}
+
 static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 {
 	struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
@@ -48,19 +56,13 @@ static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
 		pwm_duty = pwmbl->pdata->pwm_duty_min;
 
 	if (!intensity) {
-		if (gpio_is_valid(pwmbl->gpio_on)) {
-			gpio_set_value(pwmbl->gpio_on,
-					0 ^ pwmbl->pdata->on_active_low);
-		}
+		atmel_pwm_bl_set_gpio_on(pwmbl, 0);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
 		pwm_channel_disable(&pwmbl->pwmc);
 	} else {
 		pwm_channel_enable(&pwmbl->pwmc);
 		pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
-		if (gpio_is_valid(pwmbl->gpio_on)) {
-			gpio_set_value(pwmbl->gpio_on,
-					1 ^ pwmbl->pdata->on_active_low);
-		}
+		atmel_pwm_bl_set_gpio_on(pwmbl, 1);
 	}
 
 	return 0;
@@ -196,10 +198,7 @@ static int atmel_pwm_bl_remove(struct platform_device *pdev)
 {
 	struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
 
-	if (gpio_is_valid(pwmbl->gpio_on)) {
-		gpio_set_value(pwmbl->gpio_on,
-					0 ^ pwmbl->pdata->on_active_low);
-	}
+	atmel_pwm_bl_set_gpio_on(pwmbl, 0);
 	pwm_channel_disable(&pwmbl->pwmc);
 	pwm_channel_free(&pwmbl->pwmc);
 
-- 
1.8.4.2


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

* [PATCH v3 9/9] backlight: atmel-pwm-bl: use gpio_request_one
  2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
                       ` (7 preceding siblings ...)
  2013-10-31 17:57     ` [PATCH v3 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
@ 2013-10-31 17:57     ` Johan Hovold
  8 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2013-10-31 17:57 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, Tomi Valkeinen, Jean-Christophe Plagniol-Villard,
	Andrew Morton, linux-fbdev, linux-kernel, Johan Hovold

Use devm_gpio_request_one rather than requesting and setting direction
in two calls.

Cc: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index bd1ed34..261b1a4 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -124,6 +124,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	const struct atmel_pwm_bl_platform_data *pdata;
 	struct backlight_device *bldev;
 	struct atmel_pwm_bl *pwmbl;
+	unsigned long flags;
 	int retval;
 
 	pdata = dev_get_platdata(&pdev->dev);
@@ -149,14 +150,14 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 		return retval;
 
 	if (gpio_is_valid(pwmbl->gpio_on)) {
-		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
-					"gpio_atmel_pwm_bl");
-		if (retval)
-			goto err_free_pwm;
-
 		/* Turn display off by default. */
-		retval = gpio_direction_output(pwmbl->gpio_on,
-				0 ^ pdata->on_active_low);
+		if (pdata->on_active_low)
+			flags = GPIOF_OUT_INIT_HIGH;
+		else
+			flags = GPIOF_OUT_INIT_LOW;
+
+		retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
+						flags, "gpio_atmel_pwm_bl");
 		if (retval)
 			goto err_free_pwm;
 	}
-- 
1.8.4.2


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

* Re: [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling
  2013-10-22 17:26 ` [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
@ 2013-10-23  1:50   ` Jingoo Han
  0 siblings, 0 replies; 43+ messages in thread
From: Jingoo Han @ 2013-10-23  1:50 UTC (permalink / raw)
  To: 'Johan Hovold'
  Cc: 'Richard Purdie', 'Nicolas Ferre',
	linux-fbdev, linux-kernel, 'Jingoo Han'

On Wednesday, October 23, 2013 2:27 AM, Johan Hovold wrote:
> 
> Clean up probe error handling by checking parameters before any
> allocations and removing an obsolete error label. Also remove
> unnecessary reset of private gpio number.
> 
> Signed-off-by: Johan Hovold <jhovold@gmail.com>

Acked-by: Jingoo Han <jg1.han@samsung.com>

Best regards,
Jingoo Han

> ---
>  drivers/video/backlight/atmel-pwm-bl.c | 31 ++++++++++++-------------------
>  1 file changed, 12 insertions(+), 19 deletions(-)


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

* [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling
  2013-10-22 17:26 [PATCH 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
@ 2013-10-22 17:26 ` Johan Hovold
  2013-10-23  1:50   ` Jingoo Han
  0 siblings, 1 reply; 43+ messages in thread
From: Johan Hovold @ 2013-10-22 17:26 UTC (permalink / raw)
  To: Richard Purdie, Jingoo Han
  Cc: Nicolas Ferre, linux-fbdev, linux-kernel, Johan Hovold

Clean up probe error handling by checking parameters before any
allocations and removing an obsolete error label. Also remove
unnecessary reset of private gpio number.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
 drivers/video/backlight/atmel-pwm-bl.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index cc5a5ed..52a8134 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -126,40 +126,33 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 	struct atmel_pwm_bl *pwmbl;
 	int retval;
 
+	pdata = dev_get_platdata(&pdev->dev);
+	if (!pdata)
+		return -ENODEV;
+
+	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
+			pdata->pwm_duty_min > pdata->pwm_duty_max ||
+			pdata->pwm_frequency == 0)
+		return -EINVAL;
+
 	pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
 				GFP_KERNEL);
 	if (!pwmbl)
 		return -ENOMEM;
 
 	pwmbl->pdev = pdev;
-
-	pdata = dev_get_platdata(&pdev->dev);
-	if (!pdata) {
-		retval = -ENODEV;
-		goto err_free_mem;
-	}
-
-	if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
-			pdata->pwm_duty_min > pdata->pwm_duty_max ||
-			pdata->pwm_frequency == 0) {
-		retval = -EINVAL;
-		goto err_free_mem;
-	}
-
 	pwmbl->pdata = pdata;
 	pwmbl->gpio_on = pdata->gpio_on;
 
 	retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
 	if (retval)
-		goto err_free_mem;
+		return retval;
 
 	if (pwmbl->gpio_on != -1) {
 		retval = devm_gpio_request(&pdev->dev, pwmbl->gpio_on,
 					"gpio_atmel_pwm_bl");
-		if (retval) {
-			pwmbl->gpio_on = -1;
+		if (retval)
 			goto err_free_pwm;
-		}
 
 		/* Turn display off by default. */
 		retval = gpio_direction_output(pwmbl->gpio_on,
@@ -197,7 +190,7 @@ static int atmel_pwm_bl_probe(struct platform_device *pdev)
 
 err_free_pwm:
 	pwm_channel_free(&pwmbl->pwmc);
-err_free_mem:
+
 	return retval;
 }
 
-- 
1.8.4


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

end of thread, other threads:[~2013-10-31 18:00 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-23  9:55 [PATCH RESEND 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
2013-10-23  9:55 ` [PATCH 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
2013-10-25 11:08   ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-29 13:32     ` Johan Hovold
2013-10-23  9:55 ` [PATCH 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
2013-10-25 11:09   ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-29 13:08     ` Johan Hovold
2013-10-23  9:55 ` [PATCH 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
2013-10-23  9:55 ` [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
2013-10-25 11:11   ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-29 13:09     ` Johan Hovold
2013-10-23  9:55 ` [PATCH 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
2013-10-25 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-23  9:55 ` [PATCH 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
2013-10-23  9:55 ` [PATCH 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
2013-10-23  9:55 ` [PATCH 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
2013-10-25 11:13   ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-23  9:55 ` [PATCH 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
2013-10-25 11:15   ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-29 13:20     ` Johan Hovold
2013-10-30 19:30       ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-29 16:27 ` [PATCH v2 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
2013-10-29 16:27   ` [PATCH v2 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
2013-10-29 16:27   ` [PATCH v2 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
2013-10-29 16:27   ` [PATCH v2 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
2013-10-29 16:27   ` [PATCH v2 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
2013-10-29 16:27   ` [PATCH v2 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
2013-10-29 16:27   ` [PATCH v2 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
2013-10-29 16:27   ` [PATCH v2 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
2013-10-29 16:27   ` [PATCH v2 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
2013-10-29 16:27   ` [PATCH v2 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
2013-10-31 17:57   ` [PATCH v3 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
2013-10-31 17:57     ` [PATCH v3 1/9] backlight: atmel-pwm-bl: fix reported brightness Johan Hovold
2013-10-31 17:57     ` [PATCH v3 2/9] backlight: atmel-pwm-bl: fix gpio polarity in remove Johan Hovold
2013-10-31 17:57     ` [PATCH v3 3/9] backlight: atmel-pwm-bl: fix module autoload Johan Hovold
2013-10-31 17:57     ` [PATCH v3 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
2013-10-31 17:57     ` [PATCH v3 5/9] backlight: atmel-pwm-bl: clean up get_intensity Johan Hovold
2013-10-31 17:57     ` [PATCH v3 6/9] backlight: atmel-pwm-bl: remove unused include Johan Hovold
2013-10-31 17:57     ` [PATCH v3 7/9] backlight: atmel-pwm-bl: use gpio_is_valid Johan Hovold
2013-10-31 17:57     ` [PATCH v3 8/9] backlight: atmel-pwm-bl: refactor gpio_on handling Johan Hovold
2013-10-31 17:57     ` [PATCH v3 9/9] backlight: atmel-pwm-bl: use gpio_request_one Johan Hovold
  -- strict thread matches above, loose matches on Subject: below --
2013-10-22 17:26 [PATCH 0/9] backlight: atmel-pwm-bl: fixes and clean ups Johan Hovold
2013-10-22 17:26 ` [PATCH 4/9] backlight: atmel-pwm-bl: clean up probe error handling Johan Hovold
2013-10-23  1:50   ` 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).