devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Richard Purdie <rpurdie@rpsys.net>,
	Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	linux-leds@vger.kernel.org
Cc: "Rob Herring" <robh+dt@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, "Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH 2/4] leds: triggers: add early support for trigger-type DT property
Date: Tue, 28 Feb 2017 13:04:50 +0100	[thread overview]
Message-ID: <20170228120452.10043-2-zajec5@gmail.com> (raw)
In-Reply-To: <20170228120452.10043-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

This adds support for getting DT node pointed in "triggers" property
and reading its "trigger-type". This will allow:
1) Activating proper trigger as specified in DT
2) Accessing DT info in specific triggers

Please note there is a validation of specified trigger type. This
requires documenting every supported value instead of blindly mapping
them into Linux triggers.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/leds/led-triggers.c | 41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/leds.h        |  1 +
 2 files changed, 42 insertions(+)

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 572ede298d68..83897e0d6b76 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -16,6 +16,7 @@
 #include <linux/list.h>
 #include <linux/spinlock.h>
 #include <linux/device.h>
+#include <linux/of.h>
 #include <linux/timer.h>
 #include <linux/rwsem.h>
 #include <linux/leds.h>
@@ -157,11 +158,48 @@ void led_trigger_remove(struct led_classdev *led_cdev)
 }
 EXPORT_SYMBOL_GPL(led_trigger_remove);
 
+static void led_trigger_of_read_trigger(struct led_classdev *led_cdev)
+{
+	struct device *dev = led_cdev->dev;
+	struct device_node *led_np = dev_of_node(dev);
+	struct of_phandle_args args;
+	const char *trigger_type;
+	int err;
+
+	if (!led_np)
+		return;
+
+	/* Currently we support only 1 trigger at a time */
+	err = of_parse_phandle_with_args(led_np, "triggers", NULL, 0, &args);
+	if (err)
+		return;
+
+	err = of_property_read_string(args.np, "trigger-type", &trigger_type);
+	if (err) {
+		dev_err(dev, "Failed to read trigger type\n");
+		goto err_node_put;
+	}
+
+	/* Check if trigger specified in DT is supported */
+	if (1) /* TODO */
+		goto err_node_put;
+
+	led_cdev->default_trigger = trigger_type;
+	led_cdev->trigger_node = args.np;
+
+	return;
+
+err_node_put:
+	of_node_put(args.np);
+}
+
 int led_trigger_set_default(struct led_classdev *led_cdev)
 {
 	struct led_trigger *trig;
 	int ret = -EPROBE_DEFER;
 
+	led_trigger_of_read_trigger(led_cdev);
+
 	if (!led_cdev->default_trigger)
 		return 0;
 
@@ -252,6 +290,9 @@ void led_trigger_unregister(struct led_trigger *trig)
 		up_write(&led_cdev->trigger_lock);
 	}
 	up_read(&leds_list_lock);
+
+	if (led_cdev->trigger_node)
+		of_node_put(led_cdev->trigger_node);
 }
 EXPORT_SYMBOL_GPL(led_trigger_unregister);
 
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 97ff66e3e8c4..bb6dcb9da4a9 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -106,6 +106,7 @@ struct led_classdev {
 
 	struct led_trigger	*trigger;
 	struct list_head	 trig_list;
+	struct device_node	*trigger_node;
 	void			*trigger_data;
 	/* true if activated - deactivate routine uses it to do cleanup */
 	bool			activated;
-- 
2.11.0

  reply	other threads:[~2017-02-28 12:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 12:04 [PATCH 1/4] dt-bindings: leds: document property for LED triggers Rafał Miłecki
2017-02-28 12:04 ` Rafał Miłecki [this message]
2017-02-28 12:04 ` [PATCH 3/4] dt-bindings: leds: document binding for LED timer trigger Rafał Miłecki
     [not found] ` <20170228120452.10043-1-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-28 12:04   ` [PATCH 4/4] leds: triggers: support timer trigger DT bindings Rafał Miłecki
2017-02-28 21:38   ` [PATCH 1/4] dt-bindings: leds: document property for LED triggers Jacek Anaszewski
2017-02-28 21:51     ` Rafał Miłecki
2017-02-28 22:12       ` Rob Herring
2017-03-01 21:04         ` Jacek Anaszewski
2017-03-01 22:55           ` Rob Herring
     [not found]           ` <386c5b7b-0bc0-d286-6cbb-745a5adbc1e9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-06  6:06             ` Rafał Miłecki
2017-03-12 11:44               ` Rob Herring
     [not found]       ` <290ed068-2518-50ef-4d02-394bef8b7ee9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-01 21:04         ` Jacek Anaszewski
2017-03-06  6:16           ` Rafał Miłecki
2017-03-06 19:59             ` 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=20170228120452.10043-2-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux-leds@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    --cc=rpurdie@rpsys.net \
    /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).