All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] leds: backlight: Register with class backlight
@ 2019-11-25 14:47 Guido Günther
  2019-11-25 14:47 ` [RFC PATCH 1/1] leds: backlight: register with class backlight too Guido Günther
  2019-11-25 18:19 ` [RFC PATCH 0/1] leds: backlight: Register with class backlight Jacek Anaszewski
  0 siblings, 2 replies; 3+ messages in thread
From: Guido Günther @ 2019-11-25 14:47 UTC (permalink / raw)
  To: Jacek Anaszewski, Pavel Machek, Dan Murphy, Kate Stewart,
	Thomas Gleixner, Enrico Weigelt, Allison Randal, linux-leds,
	linux-kernel

When using current LCD drivers as ledtrig backlight they're
not registered with the backlight device class. This has
two problems: they're usually not found by userspace since
these tools usually look in /sys/class/backlight and they
can't be used as backlight phandles in device tree for
e.g. LCD panels.

This is an RFC if this is worthwhile at all? A current problem
is that changing the LED brightness does currently not notify
the class backlight so they can get out of sync but i could
look into that if the approach makes sense.


Guido Günther (1):
  leds: backlight: register with class backlight too

 drivers/leds/trigger/ledtrig-backlight.c | 54 ++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

-- 
2.23.0


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

* [RFC PATCH 1/1] leds: backlight: register with class backlight too
  2019-11-25 14:47 [RFC PATCH 0/1] leds: backlight: Register with class backlight Guido Günther
@ 2019-11-25 14:47 ` Guido Günther
  2019-11-25 18:19 ` [RFC PATCH 0/1] leds: backlight: Register with class backlight Jacek Anaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Guido Günther @ 2019-11-25 14:47 UTC (permalink / raw)
  To: Jacek Anaszewski, Pavel Machek, Dan Murphy, Kate Stewart,
	Thomas Gleixner, Enrico Weigelt, Allison Randal, linux-leds,
	linux-kernel

This allows it to be used as backlight device in device tree (e.g. to
link it to a LCD panel) and helps userspace since it shows up in
/sys/class/backlight then.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
---
 drivers/leds/trigger/ledtrig-backlight.c | 54 ++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/leds/trigger/ledtrig-backlight.c b/drivers/leds/trigger/ledtrig-backlight.c
index 487577d22cfc..3967f7014b9a 100644
--- a/drivers/leds/trigger/ledtrig-backlight.c
+++ b/drivers/leds/trigger/ledtrig-backlight.c
@@ -22,6 +22,9 @@ struct bl_trig_notifier {
 	int brightness;
 	int old_status;
 	struct notifier_block notifier;
+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
+	struct backlight_device *backlight_device;
+#endif
 	unsigned invert;
 };
 
@@ -98,11 +101,40 @@ static struct attribute *bl_trig_attrs[] = {
 };
 ATTRIBUTE_GROUPS(bl_trig);
 
+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
+static int bl_get_brightness(struct backlight_device *b)
+{
+	struct led_classdev *led = bl_get_data(b);
+
+	return led_get_brightness(led);
+}
+
+static int bl_update_status(struct backlight_device *b)
+{
+	struct led_classdev *led = bl_get_data(b);
+
+	if (b->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
+		led_set_brightness_nosleep(led, 0);
+	else
+		led_set_brightness_nosleep(led, b->props.brightness);
+
+	return 0;
+}
+
+static const struct backlight_ops backlight_ops = {
+	.get_brightness = bl_get_brightness,
+	.update_status	= bl_update_status,
+};
+#endif
+
 static int bl_trig_activate(struct led_classdev *led)
 {
 	int ret;
 
 	struct bl_trig_notifier *n;
+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
+	struct backlight_properties props;
+#endif
 
 	n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
 	if (!n)
@@ -118,13 +150,35 @@ static int bl_trig_activate(struct led_classdev *led)
 	if (ret)
 		dev_err(led->dev, "unable to register backlight trigger\n");
 
+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
+	memset(&props, 0, sizeof(struct backlight_properties));
+	props.type = BACKLIGHT_PLATFORM;
+	props.max_brightness = LED_FULL;
+	props.brightness = led->brightness;
+	n->backlight_device = backlight_device_register(led->name,
+							led->dev,
+							led,
+							&backlight_ops,
+							&props);
+	if (IS_ERR(n->backlight_device)) {
+		ret = IS_ERR(n->backlight_device);
+		goto out;
+	}
+#endif
+
 	return 0;
+out:
+	fb_unregister_client(&n->notifier);
+	return ret;
 }
 
 static void bl_trig_deactivate(struct led_classdev *led)
 {
 	struct bl_trig_notifier *n = led_get_trigger_data(led);
 
+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
+	backlight_device_unregister(n->backlight_device);
+#endif
 	fb_unregister_client(&n->notifier);
 	kfree(n);
 }
-- 
2.23.0


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

* Re: [RFC PATCH 0/1] leds: backlight: Register with class backlight
  2019-11-25 14:47 [RFC PATCH 0/1] leds: backlight: Register with class backlight Guido Günther
  2019-11-25 14:47 ` [RFC PATCH 1/1] leds: backlight: register with class backlight too Guido Günther
@ 2019-11-25 18:19 ` Jacek Anaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Jacek Anaszewski @ 2019-11-25 18:19 UTC (permalink / raw)
  To: Guido Günther, Pavel Machek, Dan Murphy, Kate Stewart,
	Thomas Gleixner, Enrico Weigelt, Allison Randal, linux-leds,
	linux-kernel

Hi Guido,

You might want to check the pending patch set [0].

On 11/25/19 3:47 PM, Guido Günther wrote:
> When using current LCD drivers as ledtrig backlight they're
> not registered with the backlight device class. This has
> two problems: they're usually not found by userspace since
> these tools usually look in /sys/class/backlight and they
> can't be used as backlight phandles in device tree for
> e.g. LCD panels.
> 
> This is an RFC if this is worthwhile at all? A current problem
> is that changing the LED brightness does currently not notify
> the class backlight so they can get out of sync but i could
> look into that if the approach makes sense.
> 
> 
> Guido Günther (1):
>   leds: backlight: register with class backlight too
> 
>  drivers/leds/trigger/ledtrig-backlight.c | 54 ++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
> 

[0]
https://lore.kernel.org/linux-leds/20191007124437.20367-1-jjhiblot@ti.com/

-- 
Best regards,
Jacek Anaszewski

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

end of thread, other threads:[~2019-11-25 18:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-25 14:47 [RFC PATCH 0/1] leds: backlight: Register with class backlight Guido Günther
2019-11-25 14:47 ` [RFC PATCH 1/1] leds: backlight: register with class backlight too Guido Günther
2019-11-25 18:19 ` [RFC PATCH 0/1] leds: backlight: Register with class backlight Jacek Anaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.