linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Doug Zobel <dougdev334@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Rob Herring <robh+dt@kernel.org>,
	Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Doug Zobel <dougdev334@gmail.com>
Subject: [PATCH 1/2] leds: lp55xx: support predefined pattern in Device Tree
Date: Tue, 11 May 2021 15:48:33 -0500	[thread overview]
Message-ID: <20210511204834.2675271-2-dougdev334@gmail.com> (raw)
In-Reply-To: <20210511204834.2675271-1-dougdev334@gmail.com>

The predefined LED pattern supported by the lp5562 can only
be passed via the antiquated platform data structure.  This
patch allows the patterns to be defined in the Device Tree.

Signed-off-by: Doug Zobel <dougdev334@gmail.com>
---
 drivers/leds/leds-lp55xx-common.c | 94 +++++++++++++++++++++++++++----
 1 file changed, 84 insertions(+), 10 deletions(-)

diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 81de1346bf5d..227577ab4a16 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -659,15 +659,25 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
 	struct device_node *child;
 	struct lp55xx_platform_data *pdata;
 	struct lp55xx_led_config *cfg;
-	int num_channels;
-	int i = 0;
+	struct lp55xx_predef_pattern *pat = NULL;
+	int num_channels = 0;
+	int cfg_num = 0;
+	int num_patterns = 0;
+	int pat_num = 0;
+	int pat_size;
 	int ret;
 
 	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return ERR_PTR(-ENOMEM);
 
-	num_channels = of_get_available_child_count(np);
+	for_each_available_child_of_node(np, child) {
+		if (of_property_read_bool(child, "chan-name"))
+			num_channels++;
+		else if (of_property_read_bool(child, "pat-name"))
+			num_patterns++;
+	}
+
 	if (num_channels == 0) {
 		dev_err(dev, "no LED channels\n");
 		return ERR_PTR(-EINVAL);
@@ -677,19 +687,83 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
 	if (!cfg)
 		return ERR_PTR(-ENOMEM);
 
-	pdata->led_config = &cfg[0];
-	pdata->num_channels = num_channels;
+	if (num_patterns) {
+		pat = devm_kcalloc(dev, num_patterns, sizeof(*pat), GFP_KERNEL);
+		if (!pat)
+			return ERR_PTR(-ENOMEM);
+	}
+
 	cfg->max_channel = chip->cfg->max_channel;
 
 	for_each_available_child_of_node(np, child) {
-		ret = lp55xx_parse_logical_led(child, cfg, i);
-		if (ret) {
-			of_node_put(child);
-			return ERR_PTR(-EINVAL);
+		if (of_property_read_bool(child, "chan-name")) {
+			ret = lp55xx_parse_logical_led(child, cfg, cfg_num);
+			if (ret) {
+				of_node_put(child);
+				return ERR_PTR(-EINVAL);
+			}
+			cfg_num++;
+		} else if (of_property_read_bool(child, "pat-name")) {
+			pat_size = of_property_count_elems_of_size(child,
+								   "pat-r",
+						sizeof((*pat[pat_num].r)));
+			if (pat_size <= 0) {
+				pat[pat_num].size_r = 0;
+			} else {
+				char *program = devm_kcalloc(dev, pat_size,
+					sizeof(*(pat[pat_num].r)), GFP_KERNEL);
+				if (!program)
+					return ERR_PTR(-ENOMEM);
+				of_property_read_u8_array(child, "pat-r",
+							  program,
+							  pat_size);
+				pat[pat_num].r = program;
+				pat[pat_num].size_r = pat_size;
+			}
+
+			pat_size = of_property_count_elems_of_size(child,
+								   "pat-g",
+						sizeof((*pat[pat_num].g)));
+			if (pat_size <= 0) {
+				pat[pat_num].size_g = 0;
+			} else {
+				char *program = devm_kcalloc(dev, pat_size,
+					sizeof(*(pat[pat_num].g)), GFP_KERNEL);
+				if (!program)
+					return ERR_PTR(-ENOMEM);
+				of_property_read_u8_array(child, "pat-g",
+							  program,
+							  pat_size);
+				pat[pat_num].g = program;
+				pat[pat_num].size_g = pat_size;
+			}
+
+			pat_size = of_property_count_elems_of_size(child,
+								   "pat-b",
+						sizeof((*pat[pat_num].b)));
+			if (pat_size <= 0) {
+				pat[pat_num].size_b = 0;
+			} else {
+				char *program = devm_kcalloc(dev, pat_size,
+					sizeof(*(pat[pat_num].b)), GFP_KERNEL);
+				if (!program)
+					return ERR_PTR(-ENOMEM);
+				of_property_read_u8_array(child, "pat-b",
+							  program,
+							  pat_size);
+				pat[pat_num].b = program;
+				pat[pat_num].size_b = pat_size;
+			}
+
+			pat_num++;
 		}
-		i++;
 	}
 
+	pdata->led_config = &cfg[0];
+	pdata->num_channels = num_channels;
+	pdata->patterns = &pat[0];
+	pdata->num_patterns = num_patterns;
+
 	of_property_read_string(np, "label", &pdata->label);
 	of_property_read_u8(np, "clock-mode", &pdata->clock_mode);
 
-- 
2.20.1


  reply	other threads:[~2021-05-11 20:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 20:48 [PATCH 0/2] Device Tree support for LP5562 predefined patterns Doug Zobel
2021-05-11 20:48 ` Doug Zobel [this message]
2021-05-11 20:48 ` [PATCH 2/2] dt: bindings: lp55xx: Add predefined LED pattern Doug Zobel
2021-05-12 18:35   ` Rob Herring
2021-05-13  2:20   ` Rob Herring
2021-05-13 20:47     ` Doug Zobel
2021-05-16 18:31       ` Pavel Machek
2021-05-17 20:07         ` Doug Zobel
2021-05-16 18:22   ` Pavel Machek

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=20210511204834.2675271-2-dougdev334@gmail.com \
    --to=dougdev334@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --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).