Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2063imu; Thu, 8 Nov 2018 12:49:06 -0800 (PST) X-Google-Smtp-Source: AJdET5fCgK+vVxf5GnIr4+cgwiXGHeRJZ33cK9FiB25Gt6uLDqEbgkDag1u3oL5CVqDB4WiKwR1E X-Received: by 2002:a17:902:9009:: with SMTP id a9-v6mr6075584plp.134.1541710146175; Thu, 08 Nov 2018 12:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541710146; cv=none; d=google.com; s=arc-20160816; b=MMP957iD1kjFh5jVbNOxZpOJCp0K2LzZA+pK6Xu9QPAXq3xXydJ78U0rzj8eEEX2CL 3cDkdnwfn4yPCoZat5erGH+19GKm1W1PslrT8++59OSIP58X4zv5tkCcM6VHJmIjyEc5 qzcEdAYR2WD4yWagZUD2LeQmat9lcmBrK+peWP51rfC72QoVi/QHXLv2WiVKpRSACH7o sltTEKVimajTUA+sNxCAMTxkJ0QVd7vRowzXrSIGu5XOrYtcPqRf2g4Z1JHsuyHSDzPw iUVkGr0av4tgmQgAMmAaa5TPIYDPl6fWnMmgBjLo3cReWwY61pvXEJCtMBzLFgHNeTvl FfYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=FrFuQ066lwq0JvRLuAtMRDuTVAScn6IiT1n8AcTD11I=; b=ovJ5i0AtCTT/F1k/f/FgT5tUMD4TNYgZLaVd6WtlfT/B+3Rqb1C/E5vC+FI0Y5tgYr EWFb50pDXwY5tg+LRJvZjxH+MtD517G9Jof/gmT6eW3Jtyo/I65pInmIyCurQUPFSH7d EdeGn8u6szTpLRzZpAw9zNtHHzjxPUrHHah+vBn7RivNlnMhfspxIx9XsDqsBuLWd065 7kXauyjgsm2jevoOdcCh2DmM/kCxq2XSfAJ80BgsZ/QQrFeeSzBMM4yMjGVc+iVY/nCj cyNHovZMa3lBQZbRPjEFtGLOmB92E5bTYtHD9IZ34Znlin8bfgZbaLYLQHXPF/PGQces 2mTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PZkuWKEZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a144-v6si5728817pfd.138.2018.11.08.12.48.48; Thu, 08 Nov 2018 12:49:06 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PZkuWKEZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbeKIGZX (ORCPT + 99 others); Fri, 9 Nov 2018 01:25:23 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:35500 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbeKIGZW (ORCPT ); Fri, 9 Nov 2018 01:25:22 -0500 Received: by mail-lf1-f66.google.com with SMTP id d7-v6so15239705lfi.2; Thu, 08 Nov 2018 12:48:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=FrFuQ066lwq0JvRLuAtMRDuTVAScn6IiT1n8AcTD11I=; b=PZkuWKEZLCtg2K85YaqCowb4DExy1EG8aGqioQYAObFHS1rK4+6iAsSjFwFkDBcWYY qgslDz6yr2osWw8B0bxxSA4h9Z+tszdH3tWxhVG8ocsw7iaerZB4YBr5eVn1v3ugYqml x8Ss/gNQVEXYZ1R50ohIZ5fNPPziS0GcCsQoOdDdEJBLW4Tmiev5hqZTXzKwBp2y6fMO zuLrM8EAFw39YRpbaR7cVTfvv+zc79zD3A42u16aMGOSP6yZf4owHV/zjL+VZs3YpFgA LJdrnk0vw3UavxANqL/iZIekRwMLiNBZLgBZ4K+JT7mwM6Ld7/EoqwAP/NFkm830TfUB nQaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FrFuQ066lwq0JvRLuAtMRDuTVAScn6IiT1n8AcTD11I=; b=Uprxfh9gyTquYX0T2HPqzGY1PHF0kzPP0YVI/GWMrF7AOVW3XwLbUkW64Ug6H++4kc SPPh9Rb/oZHpG9/JVoVyei0XPXIlVy4ALl7mLNWna6hNB+GnMDL9rRvYMie5qWWJ12Qt o5wvLL2FB3q07Gt/G9P6CLYBiBkascP3Y2GMSc39uQBTZCfuc3oyhSG+lnA1eNfcTsQU nuHbOBb5i91UpiJuIVVIVoE0WrARNiiXFejo0L0OrMXIsdamP0lUBJbxJ8jalNIzm3qZ 25GID6JSB9qdzmWbEjZRvZ2UqxbS8123xfdydJm2UXYQjOgyybs31BBHzAJYg+g1aOmX nbFQ== X-Gm-Message-State: AGRZ1gKMrvgOL7iaTUE1unTxL9PF5/55EM2a/+3Ixod7plWkMqRqRjCF YfQvYi5Km+KJLOZHmIe5lS6Hu2Gj X-Received: by 2002:a19:9a8c:: with SMTP id c134mr3595705lfe.152.1541710087322; Thu, 08 Nov 2018 12:48:07 -0800 (PST) Received: from [192.168.1.18] (dkl219.neoplus.adsl.tpnet.pl. [83.24.15.219]) by smtp.gmail.com with ESMTPSA id c22sm842341lfd.88.2018.11.08.12.48.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 12:48:06 -0800 (PST) Subject: Re: [PATCH 02/24] leds: core: Add support for composing LED class device names To: Dan Murphy , linux-leds@vger.kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, pavel@ucw.cz, robh@kernel.org, Baolin Wang , Daniel Mack , Linus Walleij , Oleh Kravchenko , Sakari Ailus , Simon Shields , Xiaotong Lu References: <1541542052-10081-1-git-send-email-jacek.anaszewski@gmail.com> <1541542052-10081-3-git-send-email-jacek.anaszewski@gmail.com> <84dd8750-883e-1318-df85-f4c6b46b898f@ti.com> From: Jacek Anaszewski Message-ID: <5e857610-baee-9b4b-7a21-025be1f9670e@gmail.com> Date: Thu, 8 Nov 2018 21:48:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <84dd8750-883e-1318-df85-f4c6b46b898f@ti.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dan, On 11/08/2018 07:06 PM, Dan Murphy wrote: > On 11/06/2018 04:07 PM, Jacek Anaszewski wrote: >> Add public led_compose_name() API for composing LED class device >> name basing on fwnode_handle data. The function composes device name >> according to either a new pattern or the legacy >> pattern. The decision on using the >> particular pattern is made basing on whether fwnode contains new >> "function" and "color" properties, or the legacy "label" proeprty. >> >> Backwards compatibility with in-driver hard-coded LED class device >> names is assured thanks to the default_desc argument. >> >> In case none of the aformentioned properties was found, then, for OF >> nodes, the node name is adopted for LED class device name. >> >> Signed-off-by: Jacek Anaszewski >> Cc: Baolin Wang >> Cc: Daniel Mack >> Cc: Dan Murphy >> Cc: Linus Walleij >> Cc: Oleh Kravchenko >> Cc: Sakari Ailus >> Cc: Simon Shields >> Cc: Xiaotong Lu >> --- >> Documentation/leds/leds-class.txt | 2 +- >> drivers/leds/led-core.c | 71 +++++++++++++++++++++++++++++++++++++++ >> include/linux/leds.h | 32 ++++++++++++++++++ >> 3 files changed, 104 insertions(+), 1 deletion(-) >> >> diff --git a/Documentation/leds/leds-class.txt b/Documentation/leds/leds-class.txt >> index 836cb16..e9009c4 100644 >> --- a/Documentation/leds/leds-class.txt >> +++ b/Documentation/leds/leds-class.txt >> @@ -43,7 +43,7 @@ LED Device Naming >> >> Is currently of the form: >> >> -"devicename:colour:function" >> +"colour:function" >> >> There have been calls for LED properties such as colour to be exported as >> individual led class attributes. As a solution which doesn't incur as much >> diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c >> index ede4fa0..f7371fc 100644 >> --- a/drivers/leds/led-core.c >> +++ b/drivers/leds/led-core.c >> @@ -16,6 +16,8 @@ >> #include >> #include >> #include >> +#include >> +#include >> #include >> #include "leds.h" >> >> @@ -327,3 +329,72 @@ void led_sysfs_enable(struct led_classdev *led_cdev) >> led_cdev->flags &= ~LED_SYSFS_DISABLE; >> } >> EXPORT_SYMBOL_GPL(led_sysfs_enable); >> + >> +static void led_parse_properties(struct fwnode_handle *fwnode, >> + struct led_properties *props) >> +{ >> + int ret; >> + >> + if (!fwnode) >> + return; >> + >> + ret = fwnode_property_read_string(fwnode, "label", &props->label); > > If we have the label do we need to continue to look for the function and color nodes? > > It can be checked and diverted using fwnode_property_present for the "label" property Good catch. I will respin it as proposed. >> + if (!ret) >> + return; >> + >> + ret = fwnode_property_read_string(fwnode, "function", &props->function); >> + if (ret) >> + pr_info("Failed to parse function property\n"); >> + >> + ret = fwnode_property_read_string(fwnode, "color", &props->color); >> + if (ret) >> + pr_info("Failed to parse color property\n"); >> +} >> + >> +int led_compose_name(struct fwnode_handle *fwnode, const char *led_hw_name, >> + const char *default_desc, char *led_classdev_name) >> +{ >> + struct led_properties props = {}; >> + >> + if (!led_classdev_name) >> + return -EINVAL; >> + >> + led_parse_properties(fwnode, &props); >> + >> + if (props.label) { >> + /* >> + * Presence of 'label' DT property implies legacy LED name, >> + * formatted as , with possible >> + * section omission if doesn't apply to given device. >> + * >> + * If no led_hw_name has been passed, then it indicates that >> + * DT label should be used as-is for LED class device name. >> + * Otherwise the label is prepended with led_hw_name to compose >> + * the final LED class device name. >> + */ >> + if (!led_hw_name) { >> + strncpy(led_classdev_name, props.label, >> + LED_MAX_NAME_SIZE); >> + } else { >> + snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s:%s", >> + led_hw_name, props.label); >> + } >> + } else if (props.function || props.color) { >> + snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s:%s", >> + props.color ?: "", props.function ?: ""); >> + } else if (default_desc) { >> + if (!led_hw_name) { >> + pr_err("Legacy LED naming requires devicename segment"); >> + return -EINVAL; >> + } >> + snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s:%s", >> + led_hw_name, default_desc); >> + } else if (is_of_node(fwnode)) { >> + strncpy(led_classdev_name, to_of_node(fwnode)->name, >> + LED_MAX_NAME_SIZE); >> + } else >> + return -EINVAL; >> + >> + return 0; >> +} >> +EXPORT_SYMBOL_GPL(led_compose_name); >> diff --git a/include/linux/leds.h b/include/linux/leds.h >> index 646c49a..ddb4001 100644 >> --- a/include/linux/leds.h >> +++ b/include/linux/leds.h >> @@ -238,6 +238,32 @@ extern void led_sysfs_disable(struct led_classdev *led_cdev); >> extern void led_sysfs_enable(struct led_classdev *led_cdev); >> >> /** >> + * led_compose_name - compose LED class device name >> + * @child: child fwnode_handle describing a LED, >> + * or a group of synchronized LEDs. >> + * @led_hw_name: name of the LED controller, used when falling back to legacy >> + * LED naming; it should be set to NULL in new LED class drivers >> + * @default_desc: default tuple, for backwards compatibility >> + * with in-driver hard-coded LED names used as a fallback when >> + * "label" DT property was absent; it should be set to NULL >> + * in new LED class drivers >> + * @led_classdev_name: composed LED class device name >> + * >> + * Create LED class device name basing on the configuration provided by the >> + * board firmware. The name can have a legacy form , >> + * or a new form . The latter is chosen if at least one of >> + * "color" or "function" properties is present in the fwnode, leaving the >> + * section blank if the related property is absent. The former is applied >> + * when legacy "label" property is present in the fwnode. In case none of the >> + * aformentioned properties was found, then, for OF nodes, the node name > > s/aforementioned > >> + * is adopted for LED class device name. >> + * >> + * Returns: 0 on success or negative error value on failure >> + */ >> +extern int led_compose_name(struct fwnode_handle *child, const char *led_hw_name, >> + const char *default_desc, char *led_classdev_name); >> + >> +/** >> * led_sysfs_is_disabled - check if LED sysfs interface is disabled >> * @led_cdev: the LED to query >> * >> @@ -414,6 +440,12 @@ struct led_platform_data { >> struct led_info *leds; >> }; >> >> +struct led_properties { >> + const char *color; >> + const char *function; >> + const char *label; >> +}; >> + >> struct gpio_desc; >> typedef int (*gpio_blink_set_t)(struct gpio_desc *desc, int state, >> unsigned long *delay_on, >> > > -- Best regards, Jacek Anaszewski