Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3673642imc; Thu, 14 Mar 2019 02:37:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqywc2Sh2hMd43jpIe2H4LGnMIejL9LaZlrl51OlqNyW1MmzFjfLBdOuZM3nCazTZjHZTVXJ X-Received: by 2002:a63:1318:: with SMTP id i24mr31920370pgl.163.1552556278942; Thu, 14 Mar 2019 02:37:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552556278; cv=none; d=google.com; s=arc-20160816; b=Gu34IJoH4Z1yw292KQBN68F7cHvasLF/wDJQF9HNJzSHRkZj+kvDakWuUHCHlSkNrc 8ahvyB7amslZslXGPnMF4yc6GPaqzUz1/cxPkSFO/XoNtyEU22GstkQxl5ROiC2ke0jb 6qhp//zd5S1bsJxSlLuNlFt+MxxhZaMBkts0cqZ+b1djYb/Tc3Ryo4bj0v3gq+pok7TN Xu8oUy1nmGce3aoV3RqDDa71VIJ/P2Ue8pYbAhkdhw636iON+VhFHx7LHxIAK3kKE4EU DEiCG/qq75TmQH/9Oqdk8SnQLpPlK3G7T1AWNY0q84IbecomSgGKMTcukASwDHXY/4Xc zoig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=sAaAs6FCPxRmGbRhWVRfL9ls3IMXPhdJLVoZGgkFznA=; b=RvPxfu2j02jYnX2NpwQf9qA9MjWmmG474n2zlwHHCB80SGgMMb+UIP80ET9QOhnyMo Aq9jlJrVpuUFVqZNrA/yd03uPvJvYZ/kf7sOsYC1MfI8pc/XW1ZjBlVbtd7iedBe1WCn ohWwjk2if0n9aOkbQJ8uIMYyS9+P7OPEas4viEG/bQ2uzUl4UOgJp3S6Ag3FoPgSZ02t Ojnn/PyR4Oh6YIDYWZGIo5RVF0oovWn/ZEJfsdPfhHcIQxSRcjDDaElbI+RD0RCXJjNX IZOUExILSYpHbCLjeDHv1iJOlO2HhjIqTbchJjGEkVChkqLDrAvlRxgL05hAYVU84RiF 5wLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si14364229plc.190.2019.03.14.02.37.44; Thu, 14 Mar 2019 02:37:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726777AbfCNJhD (ORCPT + 99 others); Thu, 14 Mar 2019 05:37:03 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:59811 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726284AbfCNJhC (ORCPT ); Thu, 14 Mar 2019 05:37:02 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1h4MnL-0003zx-NK; Thu, 14 Mar 2019 10:36:59 +0100 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1h4MnL-0001ca-Ea; Thu, 14 Mar 2019 10:36:59 +0100 Date: Thu, 14 Mar 2019 10:36:59 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Rasmus Villemoes Cc: Pavel Machek , Jacek Anaszewski , LKML , 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 Message-ID: <20190314093659.srtlgqljcasbawva@pengutronix.de> References: <20190311144227.GA4404@amd> <20190313202615.22883-1-linux@rasmusvillemoes.dk> <20190313202615.22883-5-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190313202615.22883-5-linux@rasmusvillemoes.dk> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Wed, Mar 13, 2019 at 09:26:15PM +0100, 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. Well, you'd do this in an udev rule instead of an init script. > 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 > --- > .../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"; Maybe make this: device = <&can0>; ? > + }; > + > + can be used to replace 'linux,default-trigger = > + "can0-rxtx"' that relies on the deprecated > + CONFIG_CAN_LEDS. Mentioning "CONFIG_CAN_LEDS" is wrong for a binding document that is supposed to be independent from the kernel. > - 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 > #include > #include > +#include > #include > #include > #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); if set_device contained the length check you'd have it in only one place. > + } > + 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); > > 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--- This hunk can better live in the patch adding to Documentation/devicetree/bindings/leds/common.txt or a separate patch. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |