Skip to contentSkip to conversation

backlight: led_bl: Add support for an "enable" GPIO

PATCH In review Corentin LABBE 2 participants 4 messages Nov 2, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backlight: led_bl: Add support for an "enable" GPIO

From: Jean-Jacques Hiblot <[email protected]>

This patch adds support for an "enable GPIO".

---
 drivers/video/backlight/led_bl.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/video/backlight/led_bl.c +13 -0
index f54d256e2d54..ebd7acc32980 100644
@@ -8,6 +8,7 @@
 
 #include <linux/backlight.h>
 #include <linux/leds.h>
+#include <linux/gpio.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
@@ -15,6 +16,7 @@ struct led_bl_data {
 	struct device		*dev;
 	struct backlight_device	*bl_dev;
 	struct led_classdev	**leds;
+	struct gpio_desc        *enable_gpio;
 	bool			enabled;
 	int			nb_leds;
 	unsigned int		*levels;
@@ -35,6 +37,9 @@ static void led_bl_set_brightness(struct led_bl_data *priv, int level)
 	for (i = 0; i < priv->nb_leds; i++)
 		led_set_brightness(priv->leds[i], bkl_brightness);
 
+	if (!priv->enabled)
+		gpiod_set_value_cansleep(priv->enable_gpio, 1);
+
 	priv->enabled = true;
 }
 
@@ -48,6 +53,9 @@ static void led_bl_power_off(struct led_bl_data *priv)
 	for (i = 0; i < priv->nb_leds; i++)
 		led_set_brightness(priv->leds[i], LED_OFF);
 
+	if (priv->enabled)
+		gpiod_set_value_cansleep(priv->enable_gpio, 0);
+
 	priv->enabled = false;
 }
 
@@ -209,6 +217,11 @@ static int led_bl_probe(struct platform_device *pdev)
 		return PTR_ERR(priv->bl_dev);
 	}
 
+	priv->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
+						    GPIOD_OUT_LOW);
+	if (IS_ERR(priv->enable_gpio))
+		return PTR_ERR(priv->enable_gpio);
+
 	for (i = 0; i < priv->nb_leds; i++)
 		led_sysfs_disable(priv->leds[i]);
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Corentin LABBE

From: Jean-Jacques Hiblot <[email protected]>

This patch adds support for an "enable GPIO".

Before taking this kind of change is there a good reason why backlight should manage the GPIO? I thought that the LED subsystem was a sub system for LEDs (not LED controllers). In other words if you direct that the LED be lit up then isn't it the LED driver's job to manage the GPIO and ensure that it lights up?

Daniel.

Quoted 61 lines
---
 drivers/video/backlight/led_bl.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/video/backlight/led_bl.c +13 -0
index f54d256e2d54..ebd7acc32980 100644
@@ -8,6 +8,7 @@
 
 #include <linux/backlight.h>
 #include <linux/leds.h>
+#include <linux/gpio.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
@@ -15,6 +16,7 @@ struct led_bl_data {
 	struct device		*dev;
 	struct backlight_device	*bl_dev;
 	struct led_classdev	**leds;
+	struct gpio_desc        *enable_gpio;
 	bool			enabled;
 	int			nb_leds;
 	unsigned int		*levels;
@@ -35,6 +37,9 @@ static void led_bl_set_brightness(struct led_bl_data *priv, int level)
 	for (i = 0; i < priv->nb_leds; i++)
 		led_set_brightness(priv->leds[i], bkl_brightness);
 
+	if (!priv->enabled)
+		gpiod_set_value_cansleep(priv->enable_gpio, 1);
+
 	priv->enabled = true;
 }
 
@@ -48,6 +53,9 @@ static void led_bl_power_off(struct led_bl_data *priv)
 	for (i = 0; i < priv->nb_leds; i++)
 		led_set_brightness(priv->leds[i], LED_OFF);
 
+	if (priv->enabled)
+		gpiod_set_value_cansleep(priv->enable_gpio, 0);
+
 	priv->enabled = false;
 }
 
@@ -209,6 +217,11 @@ static int led_bl_probe(struct platform_device *pdev)
 		return PTR_ERR(priv->bl_dev);
 	}
 
+	priv->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
+						    GPIOD_OUT_LOW);
+	if (IS_ERR(priv->enable_gpio))
+		return PTR_ERR(priv->enable_gpio);
+
 	for (i = 0; i < priv->nb_leds; i++)
 		led_sysfs_disable(priv->leds[i]);
 
Signature · 1 line
2.25.1
#2 lore raw
Quoted 10 lines · Daniel Thompson
Quoted 3 lines · Corentin LABBE

From: Jean-Jacques Hiblot <[email protected]>

This patch adds support for an "enable GPIO".

Before taking this kind of change is there a good reason why backlight should manage the GPIO? I thought that the LED subsystem was a sub system for LEDs (not LED controllers). In other words if you direct that the LED be lit up then isn't it the LED driver's job to manage the GPIO and ensure that it lights up?

Sorry... I should have paid more attention to my sense of déjà vu with this patch.

This approach was discussed and rejected when we first introduced the led_bl driver:
https://lore.kernel.org/linux-leds/20190705100851.zn2jkipj4fxq5we6@devuan/

Daniel.

Quoted 61 lines
Quoted 61 lines
---
 drivers/video/backlight/led_bl.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/video/backlight/led_bl.c +13 -0
index f54d256e2d54..ebd7acc32980 100644
@@ -8,6 +8,7 @@
 
 #include <linux/backlight.h>
 #include <linux/leds.h>
+#include <linux/gpio.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
@@ -15,6 +16,7 @@ struct led_bl_data {
 	struct device		*dev;
 	struct backlight_device	*bl_dev;
 	struct led_classdev	**leds;
+	struct gpio_desc        *enable_gpio;
 	bool			enabled;
 	int			nb_leds;
 	unsigned int		*levels;
@@ -35,6 +37,9 @@ static void led_bl_set_brightness(struct led_bl_data *priv, int level)
 	for (i = 0; i < priv->nb_leds; i++)
 		led_set_brightness(priv->leds[i], bkl_brightness);
 
+	if (!priv->enabled)
+		gpiod_set_value_cansleep(priv->enable_gpio, 1);
+
 	priv->enabled = true;
 }
 
@@ -48,6 +53,9 @@ static void led_bl_power_off(struct led_bl_data *priv)
 	for (i = 0; i < priv->nb_leds; i++)
 		led_set_brightness(priv->leds[i], LED_OFF);
 
+	if (priv->enabled)
+		gpiod_set_value_cansleep(priv->enable_gpio, 0);
+
 	priv->enabled = false;
 }
 
@@ -209,6 +217,11 @@ static int led_bl_probe(struct platform_device *pdev)
 		return PTR_ERR(priv->bl_dev);
 	}
 
+	priv->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
+						    GPIOD_OUT_LOW);
+	if (IS_ERR(priv->enable_gpio))
+		return PTR_ERR(priv->enable_gpio);
+
 	for (i = 0; i < priv->nb_leds; i++)
 		led_sysfs_disable(priv->leds[i]);
 
Signature · 1 line
2.25.1
#3 lore raw
Quoted 12 lines · Daniel Thompson
Quoted 10 lines · Daniel Thompson
Quoted 3 lines · Corentin LABBE

From: Jean-Jacques Hiblot <[email protected]>

This patch adds support for an "enable GPIO".

Before taking this kind of change is there a good reason why backlight should manage the GPIO? I thought that the LED subsystem was a sub system for LEDs (not LED controllers). In other words if you direct that the LED be lit up then isn't it the LED driver's job to manage the GPIO and ensure that it lights up?

Quoted 7 lines

Sorry... I should have paid more attention to my sense of déjà vu with this patch.

This approach was discussed and rejected when we first introduced the led_bl driver:
https://lore.kernel.org/linux-leds/20190705100851.zn2jkipj4fxq5we6@devuan/

Hello

I am sorry, I didnt checked if the patch was already submitted or not.

Regards