[PATCH leds 5/8] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux