[PATCH RESEND PoC] leds: trigger: netdev: support DT "trigger-sources" property

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

 



From: Rafał Miłecki <rafal@xxxxxxxxxx>

Parse "trigger-sources", find referenced netdev & use it as default
trigger source.

Signed-off-by: Rafał Miłecki <rafal@xxxxxxxxxx>
---
This is a proof on concept, please don't apply this patch. I'll rework
this on top of Ansuel's netdev trigger refactoring once it gets accepted
----
 drivers/leds/trigger/ledtrig-netdev.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index d5e774d83021..c036a3671773 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -20,6 +20,8 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
 #include <linux/spinlock.h>
 #include <linux/timer.h>
 #include "../leds.h"
@@ -389,6 +391,28 @@ static void netdev_trig_work(struct work_struct *work)
 			(atomic_read(&trigger_data->interval)*2));
 }
 
+static void netdev_trig_of_init(struct led_classdev *led_cdev)
+{
+	struct device *dev = led_cdev->dev;
+	struct device_node *np = dev->of_node;
+	struct of_phandle_args args;
+	struct net_device *netdev;
+	int err;
+
+	err = of_parse_phandle_with_args(np, "trigger-sources", "#trigger-source-cells", 0, &args);
+	if (err || WARN_ON(!args.np)) {
+		dev_err(dev, "Failed to get trigger source phandle: %d\n", err);
+		return;
+	}
+
+	netdev = of_find_net_device_by_node(args.np);
+	if (netdev) {
+		device_name_store(dev, NULL, netdev->name, strlen(netdev->name) + 1);
+	}
+
+	of_node_put(args.np);
+}
+
 static int netdev_trig_activate(struct led_classdev *led_cdev)
 {
 	struct led_netdev_data *trigger_data;
@@ -415,6 +439,8 @@ static int netdev_trig_activate(struct led_classdev *led_cdev)
 
 	led_set_trigger_data(led_cdev, trigger_data);
 
+	netdev_trig_of_init(led_cdev);
+
 	rc = register_netdevice_notifier(&trigger_data->notifier);
 	if (rc)
 		kfree(trigger_data);
-- 
2.34.1




[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