From: "Marek Behún" <kabel@kernel.org>
To: Lee Jones <lee@kernel.org>
Cc: "Pavel Machek" <pavel@ucw.cz>,
linux-leds@vger.kernel.org, "Arnd Bergmann" <arnd@arndb.de>,
soc@kernel.org, "Gregory CLEMENT" <gregory.clement@bootlin.com>,
arm@kernel.org, "Andy Shevchenko" <andy@kernel.org>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Andrew Lunn" <andrew@lunn.ch>,
"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
"Marek Behún" <kabel@kernel.org>
Subject: [PATCH leds 5/8] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change
Date: Mon, 2 Sep 2024 14:41:01 +0200 [thread overview]
Message-ID: <20240902124104.14297-6-kabel@kernel.org> (raw)
In-Reply-To: <20240902124104.14297-1-kabel@kernel.org>
Recall that on Turris Omnia, the LED controller has a global brightness
property, which allows the user to make the front LED panel dimmer.
There is also a button on the front panel, which by default is
configured so that pressing it changes the global brightness to a lower
value (unless it is at 0%, in which case pressing the button changes the
global brightness to 100%).
Newer versions of the MCU firmware support informing the SOC that the
brightness was changed by button press event via an interrupt.
Now that we have the turris-omnia-mcu driver, which adds support for MCU
interrupts, add the ability to inform the userspace (via a sysfs
notification) that the global brightness was changed.
Signed-off-by: Marek Behún <kabel@kernel.org>
---
drivers/leds/leds-turris-omnia.c | 67 ++++++++++++++++++++++++++++++--
1 file changed, 64 insertions(+), 3 deletions(-)
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index 14e8fbb5bb69..bf8635cec72e 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -357,7 +357,57 @@ static struct attribute *omnia_led_controller_attrs[] = {
&dev_attr_gamma_correction.attr,
NULL,
};
-ATTRIBUTE_GROUPS(omnia_led_controller);
+
+static const struct attribute_group omnia_led_controller_group = {
+ .attrs = omnia_led_controller_attrs,
+};
+
+static irqreturn_t omnia_brightness_changed_handler(int irq, void *dev_id)
+{
+ struct kernfs_node *brightness_kn = dev_id;
+
+ sysfs_notify_dirent(brightness_kn);
+
+ return IRQ_HANDLED;
+}
+
+static void brightness_kn_release(struct device *dev, void *res)
+{
+ struct kernfs_node **brightness_kn = res;
+
+ sysfs_put(*brightness_kn);
+}
+
+static int omnia_probe_brightness_interrupt(struct i2c_client *client)
+{
+ struct kernfs_node **brightness_kn;
+ struct device *dev = &client->dev;
+ int ret;
+
+ brightness_kn = devres_alloc(brightness_kn_release,
+ sizeof(*brightness_kn), GFP_KERNEL);
+ if (!brightness_kn)
+ return -ENOMEM;
+
+ *brightness_kn = sysfs_get_dirent(dev->kobj.sd, "brightness");
+ if (!*brightness_kn) {
+ devres_free(brightness_kn);
+ return -EIO;
+ }
+
+ devres_add(dev, brightness_kn);
+
+ ret = devm_request_any_context_irq(dev, client->irq,
+ omnia_brightness_changed_handler,
+ IRQF_ONESHOT, "leds-turris-omnia",
+ *brightness_kn);
+ if (ret < 0) {
+ dev_err(dev, "Cannot request IRQ: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
static int omnia_mcu_get_features(const struct i2c_client *client)
{
@@ -387,6 +437,7 @@ static int omnia_leds_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
struct device_node *np = dev_of_node(dev);
+ bool has_brightness_interrupt;
struct omnia_leds *leds;
struct omnia_led *led;
int ret, count;
@@ -414,6 +465,8 @@ static int omnia_leds_probe(struct i2c_client *client)
return ret;
}
+ has_brightness_interrupt = ret & OMNIA_FEAT_BRIGHTNESS_INT;
+
leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION;
if (!leds->has_gamma_correction) {
dev_info(dev,
@@ -439,7 +492,16 @@ static int omnia_leds_probe(struct i2c_client *client)
led += ret;
}
- return 0;
+ ret = devm_device_add_group(dev, &omnia_led_controller_group);
+ if (ret < 0) {
+ dev_err(dev, "Cannot add sysfs attribute group: %d\n", ret);
+ return ret;
+ }
+
+ if (has_brightness_interrupt)
+ ret = omnia_probe_brightness_interrupt(client);
+
+ return ret;
}
static void omnia_leds_remove(struct i2c_client *client)
@@ -479,7 +541,6 @@ static struct i2c_driver omnia_leds_driver = {
.driver = {
.name = "leds-turris-omnia",
.of_match_table = of_omnia_leds_match,
- .dev_groups = omnia_led_controller_groups,
},
};
--
2.44.2
next prev parent reply other threads:[~2024-09-02 12:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 12:40 [PATCH leds 0/8] Turris Omnia LED driver changes Marek Behún
2024-09-02 12:40 ` [PATCH leds 1/8] turris-omnia-mcu-interface.h: Move command execution function to global header Marek Behún
2024-09-02 12:55 ` Andy Shevchenko
2024-09-02 12:59 ` Marek Behún
2024-09-02 13:23 ` Andy Shevchenko
2024-09-02 12:40 ` [PATCH leds 2/8] leds: turris-omnia: Use command execution functions from the MCU driver Marek Behún
2024-09-02 12:40 ` [PATCH leds 3/8] turris-omnia-mcu-interface.h: Add LED commands related definitions to global header Marek Behún
2024-09-02 12:41 ` [PATCH leds 4/8] leds: turris-omnia: Use global header for MCU command definitions Marek Behún
2024-09-02 12:41 ` Marek Behún [this message]
2024-09-02 13:17 ` [PATCH leds 5/8] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change Andy Shevchenko
2024-09-02 14:36 ` Marek Behún
2024-09-02 12:41 ` [PATCH leds 6/8] platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature Marek Behún
2024-09-02 12:41 ` [PATCH leds 7/8] leds: turris-omnia: Inform about missing LED gamma correction feature in the MCU driver Marek Behún
2024-09-02 12:41 ` [PATCH leds 8/8] ARM: dts: turris-omnia: Add global LED brightness change interrupt Marek Behún
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=20240902124104.14297-6-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=andrew@lunn.ch \
--cc=andy@kernel.org \
--cc=arm@kernel.org \
--cc=arnd@arndb.de \
--cc=gregory.clement@bootlin.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=sebastian.hesselbarth@gmail.com \
--cc=soc@kernel.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