mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] video: backlight-pwm: switch to gpiod functions
@ 2024-07-16 12:03 Ahmad Fatoum
  2024-07-17 20:18 ` Ahmad Fatoum
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 12:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Using GPIO descriptors aligns us more with the Linux customs nowadays
and takes care of potential active low handling.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/video/backlight-pwm.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
index 87358ca778ec..d3c81114e006 100644
--- a/drivers/video/backlight-pwm.c
+++ b/drivers/video/backlight-pwm.c
@@ -12,8 +12,7 @@
 #include <linux/err.h>
 #include <of.h>
 #include <regulator.h>
-#include <gpio.h>
-#include <of_gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/math64.h>
 
 struct pwm_backlight {
@@ -22,8 +21,7 @@ struct pwm_backlight {
 	struct regulator *power;
 	uint32_t period;
 	unsigned int *levels;
-	int enable_gpio;
-	int enable_active_high;
+	struct gpio_desc *enable_gpio;
 	int enabled;
 	unsigned int scale;
 };
@@ -41,10 +39,7 @@ static int backlight_pwm_enable(struct pwm_backlight *pwm_backlight)
 
 	regulator_enable(pwm_backlight->power);
 
-	if (gpio_is_valid(pwm_backlight->enable_gpio)) {
-		gpio_direction_output(pwm_backlight->enable_gpio,
-				pwm_backlight->enable_active_high);
-	}
+	gpiod_direction_output(pwm_backlight->enable_gpio, true);
 
 	pwm_backlight->enabled = 1;
 
@@ -53,13 +48,13 @@ static int backlight_pwm_enable(struct pwm_backlight *pwm_backlight)
 
 static int backlight_pwm_disable(struct pwm_backlight *pwm_backlight)
 {
+	int ret;
+
 	if (!pwm_backlight->enabled)
 		return 0;
 
-	if (gpio_is_valid(pwm_backlight->enable_gpio)) {
-		gpio_direction_output(pwm_backlight->enable_gpio,
-				!pwm_backlight->enable_active_high);
-
+	ret = gpiod_direction_output(pwm_backlight->enable_gpio, false);
+	if (!ret) {
 		regulator_disable(pwm_backlight->power);
 
 		/*
@@ -109,7 +104,6 @@ static int pwm_backlight_parse_dt(struct device *dev,
 	int length;
 	u32 value;
 	int ret, i;
-	enum of_gpio_flags flags;
 
 	if (!node)
 		return -ENODEV;
@@ -154,12 +148,7 @@ static int pwm_backlight_parse_dt(struct device *dev,
 		pwm_backlight->backlight.brightness_max = pwm_backlight->scale;
 	}
 
-	pwm_backlight->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0, &flags);
-
-	if (gpio_is_valid(pwm_backlight->enable_gpio)) {
-		if (!(flags & OF_GPIO_ACTIVE_LOW))
-			pwm_backlight->enable_active_high = 1;
-	}
+	pwm_backlight->enable_gpio = gpiod_get_optional(dev, "enable-gpios", 0);
 
 	return 0;
 }
-- 
2.39.2




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

* Re: [PATCH] video: backlight-pwm: switch to gpiod functions
  2024-07-16 12:03 [PATCH] video: backlight-pwm: switch to gpiod functions Ahmad Fatoum
@ 2024-07-17 20:18 ` Ahmad Fatoum
  0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-17 20:18 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On 16.07.24 14:03, Ahmad Fatoum wrote:
> Using GPIO descriptors aligns us more with the Linux customs nowadays
> and takes care of potential active low handling.

Please dismiss. I'll send out a v2 at a later time.

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/video/backlight-pwm.c | 27 ++++++++-------------------
>  1 file changed, 8 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
> index 87358ca778ec..d3c81114e006 100644
> --- a/drivers/video/backlight-pwm.c
> +++ b/drivers/video/backlight-pwm.c
> @@ -12,8 +12,7 @@
>  #include <linux/err.h>
>  #include <of.h>
>  #include <regulator.h>
> -#include <gpio.h>
> -#include <of_gpio.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/math64.h>
>  
>  struct pwm_backlight {
> @@ -22,8 +21,7 @@ struct pwm_backlight {
>  	struct regulator *power;
>  	uint32_t period;
>  	unsigned int *levels;
> -	int enable_gpio;
> -	int enable_active_high;
> +	struct gpio_desc *enable_gpio;
>  	int enabled;
>  	unsigned int scale;
>  };
> @@ -41,10 +39,7 @@ static int backlight_pwm_enable(struct pwm_backlight *pwm_backlight)
>  
>  	regulator_enable(pwm_backlight->power);
>  
> -	if (gpio_is_valid(pwm_backlight->enable_gpio)) {
> -		gpio_direction_output(pwm_backlight->enable_gpio,
> -				pwm_backlight->enable_active_high);
> -	}
> +	gpiod_direction_output(pwm_backlight->enable_gpio, true);
>  
>  	pwm_backlight->enabled = 1;
>  
> @@ -53,13 +48,13 @@ static int backlight_pwm_enable(struct pwm_backlight *pwm_backlight)
>  
>  static int backlight_pwm_disable(struct pwm_backlight *pwm_backlight)
>  {
> +	int ret;
> +
>  	if (!pwm_backlight->enabled)
>  		return 0;
>  
> -	if (gpio_is_valid(pwm_backlight->enable_gpio)) {
> -		gpio_direction_output(pwm_backlight->enable_gpio,
> -				!pwm_backlight->enable_active_high);
> -
> +	ret = gpiod_direction_output(pwm_backlight->enable_gpio, false);
> +	if (!ret) {
>  		regulator_disable(pwm_backlight->power);
>  
>  		/*
> @@ -109,7 +104,6 @@ static int pwm_backlight_parse_dt(struct device *dev,
>  	int length;
>  	u32 value;
>  	int ret, i;
> -	enum of_gpio_flags flags;
>  
>  	if (!node)
>  		return -ENODEV;
> @@ -154,12 +148,7 @@ static int pwm_backlight_parse_dt(struct device *dev,
>  		pwm_backlight->backlight.brightness_max = pwm_backlight->scale;
>  	}
>  
> -	pwm_backlight->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0, &flags);
> -
> -	if (gpio_is_valid(pwm_backlight->enable_gpio)) {
> -		if (!(flags & OF_GPIO_ACTIVE_LOW))
> -			pwm_backlight->enable_active_high = 1;
> -	}
> +	pwm_backlight->enable_gpio = gpiod_get_optional(dev, "enable-gpios", 0);
>  
>  	return 0;
>  }

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




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

end of thread, other threads:[~2024-07-17 20:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-16 12:03 [PATCH] video: backlight-pwm: switch to gpiod functions Ahmad Fatoum
2024-07-17 20:18 ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox