From: "Guido Günther" <agx@sigxcpu.org>
To: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Pavel Machek <pavel@ucw.cz>, Dan Murphy <dmurphy@ti.com>,
Kate Stewart <kstewart@linuxfoundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Enrico Weigelt <info@metux.net>,
Allison Randal <allison@lohutok.net>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/1] leds: backlight: register with class backlight too
Date: Mon, 25 Nov 2019 15:47:58 +0100 [thread overview]
Message-ID: <4ba4ec252c23ee57ed5c2d6bd68292c95925b647.1574692624.git.agx@sigxcpu.org> (raw)
In-Reply-To: <cover.1574692624.git.agx@sigxcpu.org>
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
next prev parent reply other threads:[~2019-11-25 14:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2019-11-25 18:19 ` Jacek Anaszewski
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=4ba4ec252c23ee57ed5c2d6bd68292c95925b647.1574692624.git.agx@sigxcpu.org \
--to=agx@sigxcpu.org \
--cc=allison@lohutok.net \
--cc=dmurphy@ti.com \
--cc=info@metux.net \
--cc=jacek.anaszewski@gmail.com \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).