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 v6 6/9] leds: multicolor: Introduce a multicolor class definition
Date: Wed, 18 Sep 2019 23:27:57 +0200	[thread overview]
Message-ID: <ff1d2ede-6bdf-8f73-9e89-0e990cce09a7@gmail.com> (raw)
In-Reply-To: <20190917175937.13872-6-dmurphy@ti.com>

Hi Dan,

I think Greg's guidance clarified everything nicely -
we will avoid <color> sub-dirs in favour of prefixes
to *intensity and *max_intensity.

Before you will send an update I have some improvement
ideas regarding the remnants after the previous approach,
where single color intensity update resulted in updating
hardware state. Now the update will happen only on write to
brightness file, so we will not need color_set/color_get ops
anymore.

On 9/17/19 7:59 PM, Dan Murphy wrote:
> Introduce a multicolor class that groups colored LEDs
> within a LED node.
> 
> The framework allows for dynamically setting individual LEDs
> or setting brightness levels of LEDs and updating them virtually
> simultaneously.
> 
> Signed-off-by: Dan Murphy <dmurphy@ti.com>
> ---
> 
> v6 removed color_id and color_mix files, used sysfs_create_groups instead of
> kobject call for LED color directory, kept kobject_create for the "colors" directory,
> removed the calculate function, updated the export for the intensity calculations.
> 
> 
>  drivers/leds/Kconfig                 |  10 +
>  drivers/leds/Makefile                |   1 +
>  drivers/leds/led-class-multicolor.c  | 306 +++++++++++++++++++++++++++
>  include/linux/led-class-multicolor.h |  90 ++++++++
>  4 files changed, 407 insertions(+)
>  create mode 100644 drivers/leds/led-class-multicolor.c
>  create mode 100644 include/linux/led-class-multicolor.h
> 
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 1988de1d64c0..71e7fd4f6f15 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -30,6 +30,16 @@ config LEDS_CLASS_FLASH
>  	  for the flash related features of a LED device. It can be built
>  	  as a module.
>  
> +config LEDS_CLASS_MULTI_COLOR
> +	tristate "LED Mulit Color LED Class Support"
> +	depends on LEDS_CLASS
> +	help
> +	  This option enables the multicolor LED sysfs class in /sys/class/leds.
> +	  It wraps LED class and adds multicolor LED specific sysfs attributes
> +	  and kernel internal API to it. You'll need this to provide support
> +	  for multicolor LEDs that are grouped together. This class is not
> +	  intended for single color LEDs. It can be built as a module.
> +
>  config LEDS_BRIGHTNESS_HW_CHANGED
>  	bool "LED Class brightness_hw_changed attribute support"
>  	depends on LEDS_CLASS
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 41fb073a39c1..897b810257dd 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -4,6 +4,7 @@
>  obj-$(CONFIG_NEW_LEDS)			+= led-core.o
>  obj-$(CONFIG_LEDS_CLASS)		+= led-class.o
>  obj-$(CONFIG_LEDS_CLASS_FLASH)		+= led-class-flash.o
> +obj-$(CONFIG_LEDS_CLASS_MULTI_COLOR)	+= led-class-multicolor.o
>  obj-$(CONFIG_LEDS_TRIGGERS)		+= led-triggers.o
>  
>  # LED Platform Drivers
> diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c
> new file mode 100644
> index 000000000000..d43bd344ed4c
> --- /dev/null
> +++ b/drivers/leds/led-class-multicolor.c
> @@ -0,0 +1,306 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// LED Multi Color class interface
> +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
> +
> +#include <linux/device.h>
> +#include <linux/init.h>
> +#include <linux/led-class-multicolor.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/uaccess.h>
> +
> +#include "leds.h"
> +
> +struct led_mc_color_entry {
> +	struct led_classdev_mc *mcled_cdev;
> +
> +	struct device_attribute max_intensity_attr;
> +	struct device_attribute intensity_attr;
> +
> +	enum led_brightness max_intensity;
> +	enum led_brightness intensity;
> +
> +	struct list_head list;
> +
> +	int led_color_id;
> +};
> +
> +void led_mc_calc_brightness(struct led_classdev_mc *mcled_cdev,
> +			    enum led_brightness brightness,
> +			    int brightness_val[])
> +{
> +	struct led_classdev_mc_data *data = mcled_cdev->data;
> +	struct led_mc_color_entry *priv;
> +	int i = 0;
> +
> +	list_for_each_entry(priv, &data->color_list, list) {
> +		brightness_val[i] = brightness *
> +				    priv->intensity / priv->max_intensity;
> +		i++;
> +	}
> +}
> +EXPORT_SYMBOL_GPL(led_mc_calc_brightness);
> +
> +static ssize_t intensity_store(struct device *dev,
> +				struct device_attribute *intensity_attr,
> +				const char *buf, size_t size)
> +{
> +	struct led_mc_color_entry *priv = container_of(intensity_attr,
> +						    struct led_mc_color_entry,
> +						      intensity_attr);
> +	struct led_classdev_mc_data *data = priv->mcled_cdev->data;
> +	struct led_classdev_mc *mcled_cdev = data->mcled_cdev;
> +	struct led_classdev *led_cdev = priv->mcled_cdev->led_cdev;
> +	unsigned long value;
> +	ssize_t ret;
> +
> +	mutex_lock(&led_cdev->led_access);
> +
> +	ret = kstrtoul(buf, 10, &value);
> +	if (ret)
> +		goto unlock;
> +
> +	if (value > priv->max_intensity) {
> +		ret = -EINVAL;
> +		goto unlock;
> +	}
> +
> +	priv->intensity = value;
> +
> +	if (mcled_cdev->ops) {
> +		ret = mcled_cdev->ops->set_color_brightness(mcled_cdev,
> +							    priv->led_color_id,
> +							    priv->intensity);

I don't think this is a good idea to update hw here now.
As I proposed before - let's do the write only in brightness set.
Otherwise any change of hue requiring alteration of more than one color
component will be non-atomic w.r.t. hw state change. Just cache the
intensity in the entry here.

[...]

-- 
Best regards,
Jacek Anaszewski

  parent reply	other threads:[~2019-09-18 21:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17 17:59 [PATCH v6 1/9] leds: multicolor: Add sysfs interface definition Dan Murphy
2019-09-17 17:59 ` [PATCH v6 2/9] documention: leds: Add multicolor class documentation Dan Murphy
2019-09-17 17:59 ` [PATCH v6 3/9] dt: bindings: Add multicolor class dt bindings documention Dan Murphy
2019-09-17 17:59 ` [PATCH v6 4/9] dt-bindings: leds: Add multicolor ID to the color ID list Dan Murphy
2019-09-17 17:59 ` [PATCH v6 5/9] " Dan Murphy
2019-09-17 17:59 ` [PATCH v6 6/9] leds: multicolor: Introduce a multicolor class definition Dan Murphy
2019-09-18 17:09   ` Dan Murphy
2019-09-18 19:56     ` Greg KH
2019-09-18 21:27   ` Jacek Anaszewski [this message]
2019-09-19  1:07     ` Dan Murphy
2019-09-19 21:32       ` Jacek Anaszewski
2019-09-20 12:31         ` Dan Murphy
2019-09-17 17:59 ` [PATCH v6 7/9] dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers Dan Murphy
2019-09-17 17:59 ` [PATCH v6 8/9] leds: lp50xx: Add the LP50XX family of the RGB LED driver Dan Murphy
2019-09-17 17:59 ` [PATCH v6 9/9] leds: Update the lp55xx to use the multi color framework 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=ff1d2ede-6bdf-8f73-9e89-0e990cce09a7@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).