linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Dan Murphy <dmurphy@ti.com>, pavel@ucw.cz
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v13 04/18] leds: multicolor: Introduce a multicolor class definition
Date: Sat, 19 Oct 2019 20:33:10 +0200	[thread overview]
Message-ID: <141a58aa-654e-6edf-b84c-b451b7b2d96b@gmail.com> (raw)
In-Reply-To: <20191016155954.29044-5-dmurphy@ti.com>

[-- Attachment #1: Type: text/plain, Size: 3130 bytes --]

Dan,

On 10/16/19 5:59 PM, Dan Murphy wrote:
> Introduce a multicolor class that groups colored LEDs
> within a LED node.
> 
> The multi color class groups monochrome LEDs and allows controlling two
> aspects of the final combined color: hue and lightness. The former is
> controlled via <color>_intensity files and the latter is controlled
> via brightness file.
> 
> Signed-off-by: Dan Murphy <dmurphy@ti.com>
> ---
[...]
> +static int led_multicolor_init_color(struct led_classdev_mc *mcled_cdev,
> +				     int color_id)
> +{
> +	struct led_classdev *led_cdev = mcled_cdev->led_cdev;
> +	struct led_mc_color_entry *mc_priv;
> +	char *intensity_file_name;
> +	char *max_intensity_file_name;
> +	size_t len;
> +	int ret;
> +
> +	mc_priv = devm_kzalloc(led_cdev->dev, sizeof(*mc_priv), GFP_KERNEL);
> +	if (!mc_priv)
> +		return -ENOMEM;
> +
> +	mc_priv->led_color_id = color_id;
> +	mc_priv->mcled_cdev = mcled_cdev;
> +
> +	sysfs_attr_init(&mc_priv->intensity_attr.attr);
> +	len = strlen(led_colors[color_id]) + strlen(INTENSITY_NAME) + 1;
> +	intensity_file_name = kzalloc(len, GFP_KERNEL);
> +	if (!intensity_file_name)
> +		return -ENOMEM;
> +
> +	snprintf(intensity_file_name, len, "%s%s",
> +		 led_colors[color_id], INTENSITY_NAME);
> +	mc_priv->intensity_attr.attr.name = intensity_file_name;
> +	mc_priv->intensity_attr.attr.mode = 0644;
> +	mc_priv->intensity_attr.store = intensity_store;
> +	mc_priv->intensity_attr.show = intensity_show;
> +	ret = sysfs_add_file_to_group(&led_cdev->dev->kobj,
> +				      &mc_priv->intensity_attr.attr,
> +				      led_color_group.name);
> +	if (ret)
> +		goto intensity_err_out;
> +
> +	sysfs_attr_init(&mc_priv->max_intensity_attr.attr);
> +	len = strlen(led_colors[color_id]) + strlen(MAX_INTENSITY_NAME) + 1;
> +	max_intensity_file_name = kzalloc(len, GFP_KERNEL);
> +	if (!max_intensity_file_name) {
> +		ret = -ENOMEM;
> +		goto intensity_err_out;
> +	}
> +
> +	snprintf(max_intensity_file_name, len, "%s%s",
> +		 led_colors[color_id], MAX_INTENSITY_NAME);
> +	mc_priv->max_intensity_attr.attr.name = max_intensity_file_name;
> +	mc_priv->max_intensity_attr.attr.mode = 0444;
> +	mc_priv->max_intensity_attr.show = max_intensity_show;
> +	ret = sysfs_add_file_to_group(&led_cdev->dev->kobj,
> +				      &mc_priv->max_intensity_attr.attr,
> +				      led_color_group.name);
> +	if (ret)
> +		goto max_intensity_err_out;
> +
> +	mc_priv->max_intensity = LED_FULL;
> +	list_add_tail(&mc_priv->list, &mcled_cdev->color_list);

We don't need the list here since our collection of color LEDs will
be fixed. Instead of the list we can do with a dynamically allocated
array of a size depending on available color LEDs.

It will allow also to get rid of lp55xx_map_channel() since random
access to array elements will be possible via lookup tables mapping
colors to array element id.

And regarding my amendments to the DT parser - attached is the
patch for your patch, that is compile-tested.

> +
> +max_intensity_err_out:
> +	kfree(max_intensity_file_name);
> +intensity_err_out:
> +	kfree(intensity_file_name);
> +	return ret;
> +}
> +
>
-- 
Best regards,
Jacek Anaszewski

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-DT-parser-amendments.patch --]
[-- Type: text/x-patch; name="0001-DT-parser-amendments.patch", Size: 5558 bytes --]

From fb0ce79b97acf6ee68ec4a2a9e24d56080826766 Mon Sep 17 00:00:00 2001
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Date: Sat, 19 Oct 2019 19:45:18 +0200
Subject: [PATCH] DT parser amendments

---
 drivers/leds/leds-lp55xx-common.c         | 109 ++++++++++++++++--------------
 include/linux/platform_data/leds-lp55xx.h |   1 +
 2 files changed, 61 insertions(+), 49 deletions(-)

diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 0764520bc4a8..0244ec9bad8d 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -590,82 +590,93 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip)
 }
 EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs);
 
-static int lp5xx_parse_common_child(struct device_node *np,
-				    struct lp55xx_led_config *cfg,
-				    int chan_num, bool is_multicolor,
-				    int color_num)
+static int lp55xx_parse_common_child(struct device_node *np,
+				     struct lp55xx_led_config *cfg,
+				     int led_number, int *chan_nr)
 {
-	u32 led_number;
 	int ret;
 
 	of_property_read_string(np, "chan-name",
-				&cfg[chan_num].name);
+				&cfg[led_number].name);
 	of_property_read_u8(np, "led-cur",
-			    &cfg[chan_num].led_current);
+			    &cfg[led_number].led_current);
 	of_property_read_u8(np, "max-cur",
-			    &cfg[chan_num].max_current);
+			    &cfg[led_number].max_current);
 
-	ret = of_property_read_u32(np, "reg", &led_number);
+	ret = of_property_read_u32(np, "reg", chan_nr);
 	if (ret)
 		return ret;
 
-	if (led_number < 0 || led_number > 6)
+	if (chan_nr < 0 || chan_nr > cfg->max_channel)
 		return -EINVAL;
 
-	if (is_multicolor)
-		cfg[chan_num].color_components[color_num].output_num =
-								led_number;
-	else
-		cfg[chan_num].chan_nr = led_number;
-
 	return 0;
 }
 
-static int lp5xx_parse_channel_child(struct device_node *np,
-				     struct lp55xx_led_config *cfg,
-				     int child_number)
+static int lp55xx_parse_mutli_led_child(struct device_node *child,
+					 struct lp55xx_led_config *cfg,
+					 int child_number, int color_number)
 {
-	struct device_node *child;
-	int channel_color;
-	int num_colors = 0;
-	u32 color_id;
-	int ret;
-
-	cfg[child_number].default_trigger =
-			of_get_property(np, "linux,default-trigger", NULL);
+	int chan_nr, color_id, ret;
 
-	ret = of_property_read_u32(np, "color", &channel_color);
+	ret = lp55xx_parse_common_child(child, cfg, child_number, &chan_nr);
 	if (ret)
-		channel_color = ret;
+		return ret;
 
+	ret = of_property_read_u32(child, "color", &color_id);
+	if (ret)
+	       return ret;
 
-	if (channel_color == LED_COLOR_ID_MULTI) {
-		for_each_child_of_node(np, child) {
-			ret = lp5xx_parse_common_child(child, cfg,
-						       child_number, true,
-						       num_colors);
-			if (ret)
-				return ret;
+	cfg[child_number].color_components[color_number].color_id = color_id;
+	cfg[child_number].color_components[color_number].output_num = chan_nr;
+	set_bit(color_id, &cfg[child_number].available_colors);
 
-			ret = of_property_read_u32(child, "color", &color_id);
-			if (ret)
-				return ret;
+	return 0;
+}
 
-			cfg[child_number].color_components[num_colors].color_id =
-						color_id;
-			set_bit(color_id, &cfg[child_number].available_colors);
-			num_colors++;
-		}
+static int lp55xx_parse_mutli_led(struct device_node *np,
+				  struct lp55xx_led_config *cfg,
+				  int child_number)
+{
+	struct device_node *child;
+	int num_colors = 0, ret;
 
-		cfg[child_number].num_colors = num_colors;
-	} else {
-		return lp5xx_parse_common_child(np, cfg, child_number, false,
-						num_colors);
+	for_each_child_of_node(np, child) {
+		ret = lp55xx_parse_mutli_led_child(child, cfg, child_number,
+						   num_colors);
+		if (ret)
+			return ret;
+		num_colors++;
 	}
 
 	return 0;
 }
 
+static int lp55xx_parse_logical_led(struct device_node *np,
+				   struct lp55xx_led_config *cfg,
+				   int child_number)
+{
+	int led_color, ret;
+
+	cfg[child_number].default_trigger =
+		of_get_property(np, "linux,default-trigger", NULL);
+
+	ret = of_property_read_u32(np, "color", &led_color);
+
+	if (ret) {
+		int chan_nr;
+		ret =  lp55xx_parse_common_child(np, cfg, child_number,
+						 &chan_nr);
+		if (ret < 0)
+		       return ret;
+		cfg[child_number].chan_nr = chan_nr;
+	} else if (led_color == LED_COLOR_ID_MULTI) {
+		return lp55xx_parse_mutli_led(np, cfg, child_number);
+	}
+
+	return ret;
+}
+
 struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
 						      struct device_node *np)
 {
@@ -694,7 +705,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
 	pdata->num_channels = num_channels;
 
 	for_each_child_of_node(np, child) {
-		ret = lp5xx_parse_channel_child(child, cfg, i);
+		ret = lp55xx_parse_logical_led(child, cfg, i);
 		if (ret)
 			return ERR_PTR(-EINVAL);
 		i++;
diff --git a/include/linux/platform_data/leds-lp55xx.h b/include/linux/platform_data/leds-lp55xx.h
index ead9d145de0d..dca21b19a283 100644
--- a/include/linux/platform_data/leds-lp55xx.h
+++ b/include/linux/platform_data/leds-lp55xx.h
@@ -28,6 +28,7 @@ struct lp55xx_led_config {
 	u8 led_current; /* mA x10, 0 if led is not connected */
 	u8 max_current;
 	int num_colors;
+	unsigned int max_channel;
 	unsigned long available_colors;
 	struct led_mc_color_conversion color_components[LP55XX_MAX_GROUPED_CHAN];
 };
-- 
2.11.0


  reply	other threads:[~2019-10-19 18:33 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 15:59 [PATCH v13 00/18] Multicolor Framework v13 Dan Murphy
2019-10-16 15:59 ` [PATCH v13 01/18] dt: bindings: Add multicolor class dt bindings documention Dan Murphy
2019-10-16 15:59 ` [PATCH v13 02/18] dt-bindings: leds: Add multicolor ID to the color ID list Dan Murphy
2019-10-16 15:59 ` [PATCH v13 03/18] " Dan Murphy
2019-10-16 15:59 ` [PATCH v13 04/18] leds: multicolor: Introduce a multicolor class definition Dan Murphy
2019-10-19 18:33   ` Jacek Anaszewski [this message]
2019-10-16 15:59 ` [PATCH v13 05/18] dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers Dan Murphy
2019-10-16 15:59 ` [PATCH v13 06/18] leds: lp50xx: Add the LP50XX family of the RGB LED driver Dan Murphy
2019-10-16 15:59 ` [PATCH v13 07/18] dt: bindings: lp55xx: Be consistent in the document with LED acronym Dan Murphy
2019-10-16 15:59 ` [PATCH v13 08/18] dt: bindings: lp55xx: Update binding for Multicolor Framework Dan Murphy
2019-10-16 15:59 ` [PATCH v13 09/18] ARM: dts: n900: Add reg property to the LP5523 channel node Dan Murphy
2019-10-17 16:10   ` Tony Lindgren
2019-10-16 15:59 ` [PATCH v13 10/18] ARM: dts: imx6dl-yapp4: Add reg property to the lp5562 " Dan Murphy
2019-10-28  2:55   ` Shawn Guo
2019-10-16 15:59 ` [PATCH v13 11/18] ARM: dts: ste-href: Add reg property to the LP5521 channel nodes Dan Murphy
2019-10-16 15:59 ` [PATCH v13 12/18] leds: lp55xx: Convert LED class registration to devm_* Dan Murphy
2019-10-16 15:59 ` [PATCH v13 13/18] leds: lp55xx: Add multicolor framework support to lp55xx Dan Murphy
2019-10-16 20:44   ` Jacek Anaszewski
2019-10-16 21:09     ` Jacek Anaszewski
2019-10-16 15:59 ` [PATCH v13 14/18] leds: lp5523: Update the lp5523 code to add multicolor brightness function Dan Murphy
2019-10-16 15:59 ` [PATCH v13 15/18] leds: lp5521: Add multicolor framework multicolor brightness support Dan Murphy
2019-10-16 15:59 ` [PATCH v13 16/18] leds: lp55xx: Fix checkpatch file permissions issues Dan Murphy
2019-10-16 15:59 ` [PATCH v13 17/18] leds: lp5523: Fix checkpatch issues in the code Dan Murphy
2019-10-16 15:59 ` [PATCH v13 18/18] dt: bindings: Update lp55xx binding to recommended LED naming Dan Murphy

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=141a58aa-654e-6edf-b84c-b451b7b2d96b@gmail.com \
    --to=jacek.anaszewski@gmail.com \
    --cc=dmurphy@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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).