lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4ba4ec252c23ee57ed5c2d6bd68292c95925b647.1574692624.git.agx@sigxcpu.org>
Date:   Mon, 25 Nov 2019 15:47:58 +0100
From:   Guido Günther <agx@...xcpu.org>
To:     Jacek Anaszewski <jacek.anaszewski@...il.com>,
        Pavel Machek <pavel@....cz>, Dan Murphy <dmurphy@...com>,
        Kate Stewart <kstewart@...uxfoundation.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Enrico Weigelt <info@...ux.net>,
        Allison Randal <allison@...utok.net>,
        linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [RFC PATCH 1/1] leds: backlight: register with class backlight too

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@...xcpu.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ