linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: "Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Pavel Machek" <pavel@ucw.cz>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-can@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH 4/4] leds: netdev trigger: allow setting initial values in device tree
Date: Thu, 14 Mar 2019 11:32:17 +0100	[thread overview]
Message-ID: <98fda0ee-555d-86a5-a4f1-1774271e4b6d@gmail.com> (raw)
In-Reply-To: <20190313202615.22883-5-linux@rasmusvillemoes.dk>

Hi Rasmus,

Thank you for the patch set.

I have one comment below.

On 3/13/19 9:26 PM, Rasmus Villemoes wrote:
> It can be quite convenient to initialize a netdev-triggered LED with a
> device name and setting the rx,tx,link properties from device tree,
> instead of having to do that in an init script in userspace.
> 
> My main motivation for this is to be able to switch away from the
> deprecated CONFIG_CAN_LEDS, so add an example based on that and add a
> pointer in the net/can/Kconfig file.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>   .../devicetree/bindings/leds/common.txt       | 17 ++++++++++
>   drivers/leds/trigger/ledtrig-netdev.c         | 31 +++++++++++++++++++
>   drivers/net/can/Kconfig                       |  3 +-
>   3 files changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/leds/common.txt b/Documentation/devicetree/bindings/leds/common.txt
> index 7cb88460a47c..4f3a97e73417 100644
> --- a/Documentation/devicetree/bindings/leds/common.txt
> +++ b/Documentation/devicetree/bindings/leds/common.txt
> @@ -43,6 +43,23 @@ Optional properties for child nodes:
>                   Documentation/ABI/testing/sysfs-class-led-trigger-netdev)
>                   to reflect the state and activity of a net device.
>   
> +                The optional child node netdev can be used to
> +                configure initial values for the link, rx, tx and
> +                device_name properties. For example, setting
> +                linux,default-trigger = "netdev" and adding the child
> +                node
> +
> +                netdev {
> +                    rx;
> +                    tx;
> +                    link;
> +                    device-name = "can0";
> +                };
> +
> +                can be used to replace 'linux,default-trigger =
> +                "can0-rxtx"' that relies on the deprecated
> +                CONFIG_CAN_LEDS.
> +
>   - led-pattern : Array of integers with default pattern for certain triggers.
>                   Each trigger may parse this property differently:
>                   - one-shot : two numbers specifying delay on and delay off (in ms),
> diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
> index 55153a7e8433..1f7c86df1e91 100644
> --- a/drivers/leds/trigger/ledtrig-netdev.c
> +++ b/drivers/leds/trigger/ledtrig-netdev.c
> @@ -20,6 +20,7 @@
>   #include <linux/list.h>
>   #include <linux/module.h>
>   #include <linux/netdevice.h>
> +#include <linux/of.h>
>   #include <linux/spinlock.h>
>   #include <linux/timer.h>
>   #include "../leds.h"
> @@ -395,6 +396,35 @@ static void netdev_trig_work(struct work_struct *work)
>   			(atomic_read(&trigger_data->interval)*2));
>   }
>   
> +static void netdev_trig_of_init(struct led_classdev *led_cdev,
> +				struct led_netdev_data *trigger_data)
> +{
> +	struct device_node *np = led_cdev->dev->of_node;
> +	const char *device_name;
> +
> +	if (!np)
> +		return;
> +	np = of_get_child_by_name(np, "netdev");
> +	if (!np)
> +		return;
> +
> +	if (of_property_read_bool(np, "link"))
> +		__set_bit(NETDEV_LED_LINK, &trigger_data->mode);
> +	if (of_property_read_bool(np, "tx"))
> +		__set_bit(NETDEV_LED_TX, &trigger_data->mode);
> +	if (of_property_read_bool(np, "rx"))
> +		__set_bit(NETDEV_LED_RX, &trigger_data->mode);
> +	if (!of_property_read_string(np, "device-name", &device_name)) {
> +		unsigned len = strlen(device_name);
> +
> +		if (len < IFNAMSIZ)
> +			set_device(trigger_data, device_name, len);
> +	}
> +	set_baseline_state(trigger_data);
> +
> +	of_node_put(np);
> +}
> +
>   static int netdev_trig_activate(struct led_classdev *led_cdev)
>   {
>   	struct led_netdev_data *trigger_data;
> @@ -418,6 +448,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev)
>   	trigger_data->mode = 0;
>   	atomic_set(&trigger_data->interval, msecs_to_jiffies(50));
>   	trigger_data->last_activity = 0;
> +	netdev_trig_of_init(led_cdev, trigger_data);

You want to execute this only if recently introduced flag
LED_INIT_DEFAULT_TRIGGER is set. Please compare how
drivers/leds/trigger/ledtrig-pattern.c uses it.

>   
>   	led_set_trigger_data(led_cdev, trigger_data);
>   
> diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
> index e0f0ad7a550a..91703a96b636 100644
> --- a/drivers/net/can/Kconfig
> +++ b/drivers/net/can/Kconfig
> @@ -77,7 +77,8 @@ config CAN_LEDS
>   	# everything that this driver is doing. This is marked as broken
>   	# because it uses stuff that is intended to be changed or removed.
>   	# Please consider switching to the netdev trigger and confirm it
> -	# fulfills your needs instead of fixing this driver.
> +	# fulfills your needs instead of fixing this driver. See e.g.
> +	# Documentation/devicetree/bindings/leds/common.txt
>   	depends on BROKEN
>   	select LEDS_TRIGGERS
>   	---help---
> 

-- 
Best regards,
Jacek Anaszewski

  parent reply	other threads:[~2019-03-14 10:32 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-11 10:59 replacement for CAN_LEDS Rasmus Villemoes
2019-03-11 14:42 ` Pavel Machek
2019-03-13 20:26   ` [PATCH 0/4] leds: netdev trigger: allow setting initial values in device tree Rasmus Villemoes
2019-03-13 20:26     ` [PATCH 1/4] leds: netdev trigger: use memcpy in device_name_store Rasmus Villemoes
2019-03-14  9:29       ` Uwe Kleine-König
2019-03-14  9:57         ` Rasmus Villemoes
2019-03-14 10:04           ` Uwe Kleine-König
2019-03-14 10:14       ` Pavel Machek
2019-03-14 10:54         ` Rasmus Villemoes
2019-03-14 12:16           ` Pavel Machek
2019-03-13 20:26     ` [PATCH 2/4] leds: netdev trigger: factor out middle part of device_name_store Rasmus Villemoes
2019-03-14  9:31       ` Uwe Kleine-König
2019-03-14  9:57         ` Rasmus Villemoes
2019-03-14 10:15         ` Pavel Machek
2019-03-14 10:20           ` Uwe Kleine-König
2019-03-13 20:26     ` [PATCH 3/4] leds: netdev trigger: add documentation to leds/common.txt Rasmus Villemoes
2019-03-13 20:26     ` [PATCH 4/4] leds: netdev trigger: allow setting initial values in device tree Rasmus Villemoes
2019-03-14  9:36       ` Uwe Kleine-König
2019-03-14 10:28         ` Rasmus Villemoes
2019-03-14 10:29       ` Pavel Machek
2019-03-14 11:26         ` Rasmus Villemoes
2019-03-14 12:00           ` Pavel Machek
2019-03-14 13:19             ` Rasmus Villemoes
2019-03-17 19:11               ` Pavel Machek
2019-03-24 20:39                 ` Rasmus Villemoes
2019-03-14 10:32       ` Jacek Anaszewski [this message]
2019-03-14 14:06     ` [PATCH v2 0/6] " Rasmus Villemoes
2019-03-14 14:06       ` [PATCH v2 1/6] leds: netdev trigger: use memcpy in device_name_store Rasmus Villemoes
2019-03-18 11:20         ` Pavel Machek
2019-03-26 19:53         ` Jacek Anaszewski
2019-03-27 15:26           ` Rasmus Villemoes
2019-03-27 21:20             ` Jacek Anaszewski
2019-03-27 21:31               ` Rasmus Villemoes
2019-03-27 21:45                 ` Jacek Anaszewski
2019-03-14 14:06       ` [PATCH v2 2/6] leds: netdev trigger: factor out middle part of device_name_store Rasmus Villemoes
2019-03-18 11:24         ` Pavel Machek
2019-03-14 14:06       ` [PATCH v2 3/6] leds: netdev trigger: move newline handling back to device_name_store Rasmus Villemoes
2019-03-18 11:25         ` Pavel Machek
2019-03-14 14:06       ` [PATCH v2 4/6] leds: netdev trigger: move name length checking to netdev_trig_set_device Rasmus Villemoes
2019-03-18 11:26         ` Pavel Machek
2019-03-14 14:06       ` [PATCH v2 5/6] leds: netdev trigger: add documentation to leds/common.txt Rasmus Villemoes
2019-03-14 14:06       ` [PATCH v2 6/6] leds: netdev trigger: allow setting initial values in device tree Rasmus Villemoes
2019-03-14 14:24         ` Jacek Anaszewski
2019-03-14 15:05           ` Rasmus Villemoes
2019-03-14 15:36             ` Jacek Anaszewski
2019-03-18 11:54         ` Pavel Machek
2019-03-28 16:28         ` Rob Herring

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=98fda0ee-555d-86a5-a4f1-1774271e4b6d@gmail.com \
    --to=jacek.anaszewski@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=netdev@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).