From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] video: backlight-pwm: switch to gpiod functions
Date: Tue, 16 Jul 2024 14:03:55 +0200 [thread overview]
Message-ID: <20240716120355.1988646-1-a.fatoum@pengutronix.de> (raw)
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
next reply other threads:[~2024-07-16 12:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 12:03 Ahmad Fatoum [this message]
2024-07-17 20:18 ` Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240716120355.1988646-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox