linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	Pavel Machek <pavel@ucw.cz>, Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Baolin Wang <baolin.wang@linaro.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/5] leds: trigger: Add pattern initialization from Device Tree
Date: Mon, 10 Dec 2018 10:30:01 +0100	[thread overview]
Message-ID: <1544434201-14190-6-git-send-email-krzk@kernel.org> (raw)
In-Reply-To: <1544434201-14190-1-git-send-email-krzk@kernel.org>

Allow initialization of pattern used in pattern trigger from Device Tree
property.

This is especially useful for embedded systems where the pattern trigger
would be used to indicate the process of boot status in a nice,
user-friendly blinking way.  This initialization pattern will be used
till user-space is brought up and sets its own pattern, indicating the
boot status is for example finished.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/leds/trigger/ledtrig-pattern.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/leds/trigger/ledtrig-pattern.c b/drivers/leds/trigger/ledtrig-pattern.c
index 1870cf87afe1..1e7672eba2b8 100644
--- a/drivers/leds/trigger/ledtrig-pattern.c
+++ b/drivers/leds/trigger/ledtrig-pattern.c
@@ -11,6 +11,7 @@
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/slab.h>
 #include <linux/timer.h>
 
@@ -331,6 +332,28 @@ static const struct attribute_group *pattern_trig_groups[] = {
 	NULL,
 };
 
+static void pattern_init(struct led_classdev *led_cdev)
+{
+	struct device_node *np = dev_of_node(led_cdev->dev);
+	const char *pattern;
+	int err;
+
+	if (!np)
+		return;
+
+	if (of_property_read_string(np, "linux,trigger-pattern", &pattern))
+		return;
+
+	if (!strlen(pattern))
+		return;
+
+	err = pattern_trig_store_patterns(led_cdev, pattern, strlen(pattern),
+					  false);
+	if (err)
+		dev_warn(led_cdev->dev,
+			 "Pattern initialization failed with error %d\n", err);
+}
+
 static int pattern_trig_activate(struct led_classdev *led_cdev)
 {
 	struct pattern_trig_data *data;
@@ -354,6 +377,15 @@ static int pattern_trig_activate(struct led_classdev *led_cdev)
 	timer_setup(&data->timer, pattern_trig_timer_function, 0);
 	led_cdev->activated = true;
 
+	if (led_cdev->flags & LED_INIT_DEFAULT_TRIGGER) {
+		pattern_init(led_cdev);
+		/*
+		 * Mark as initialized even on pattern_init() error because
+		 * any consecutive call to it would produce the same error.
+		 */
+		led_cdev->flags &= ~LED_INIT_DEFAULT_TRIGGER;
+	}
+
 	return 0;
 }
 
-- 
2.7.4


  parent reply	other threads:[~2018-12-10  9:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-10  9:29 [PATCH v2 0/5] leds: trigger: Add pattern initialization from Device Tree Krzysztof Kozlowski
2018-12-10  9:29 ` [PATCH v2 1/5] led: triggers: Break the for loop after default trigger is found Krzysztof Kozlowski
2018-12-10  9:29 ` [PATCH v2 2/5] led: triggers: Add LED_INIT_DEFAULT_TRIGGER flag Krzysztof Kozlowski
2018-12-10  9:29 ` [PATCH v2 3/5] led: triggers: Initialize LED_INIT_DEFAULT_TRIGGER if trigger is brought after class Krzysztof Kozlowski
2018-12-10  9:30 ` [PATCH v2 4/5] dt-bindings: leds: Add pattern initialization from Device Tree Krzysztof Kozlowski
2018-12-11 17:23   ` Rob Herring
2018-12-12  8:42     ` Krzysztof Kozlowski
2018-12-10  9:30 ` Krzysztof Kozlowski [this message]
2018-12-10 21:03 ` [PATCH v2 0/5] leds: trigger: " Jacek Anaszewski
2018-12-12 12:16   ` Pavel Machek
2018-12-12 19:18     ` 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=1544434201-14190-6-git-send-email-krzk@kernel.org \
    --to=krzk@kernel.org \
    --cc=baolin.wang@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).