From patchwork Fri Dec 1 16:56:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 120358 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1382903qgn; Fri, 1 Dec 2017 08:56:53 -0800 (PST) X-Google-Smtp-Source: AGs4zMZyuVKWQahA/HYCNMXuB1HcHjZTYg2AJgIQiowDdwo1iP+gNgUwCM3d9MpN5e3sVuKGjRhw X-Received: by 10.98.49.130 with SMTP id x124mr10980768pfx.149.1512147413030; Fri, 01 Dec 2017 08:56:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512147413; cv=none; d=google.com; s=arc-20160816; b=X0WKsES/YJkfhra/BKRAdc8ojnsJwH3ZGv9zm/Xrnn/qqAAGCQaCVEkJ+dNrL9Btn8 ZdZe9CHe6vtpD2BbbG3saC9R4lEQ6sNXSN1DoTjMdCZDCK7iwiXJ7vJWRts3bXym/E3t D5oWloVqETzQoQqQ9/ZL1dulc5rtGuWgWrl++HDg0aVd7CnobioNKXUH5oNXeHJCwbys 3bvLJzyx0LIiezHmCxe5Fy3mRq1yU0K7fRACWncL968qHIj/gYlk9uTvB2wGastNTP6E ah2/WXhgKzDApSE7BSykTwJLYVlVC1NXXVJPx+OFQAiTl/X7hxZthAk52NiBQjSSGKl8 xlUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=cV0NDzZSAVtWML0gD1lQ+zXhXLkA9W0oVnw7jQgjaFA=; b=ZKx1KqiKeBKJ8rrRfWEPR1dkE+oq6TeNjOdNSAO9WO3nOWjxGJxRVx91oClH+2eZka 0RZUXHAplCXrPhY6jYggcICIG3lfC1OrVyK+IVdWLFWONBv5OxvyBmyXqk45Cs4zOlpT t9lEvqu3CL32rL2daS9OP1oiIxLQwAtllHyBc7nYIivHR5oJIoSDntgBb/Z5adrVSEh8 Eqztd6spsUnJrQpOcEdAVhqPpJLCqMqWYkkZJnvaA42dscR8n25Q49l29jK43unMq245 P+yGe7KCUN6N7rEI9rsYdWtR9AlCV9icmJTcG/nkpCfwOscAyapshFkoIE3AX8TPO5+P uEDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=oWBNnZEx; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si5116816pgu.56.2017.12.01.08.56.52; Fri, 01 Dec 2017 08:56:53 -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=@ti.com header.s=ti-com-17Q1 header.b=oWBNnZEx; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751573AbdLAQ4u (ORCPT + 28 others); Fri, 1 Dec 2017 11:56:50 -0500 Received: from fllnx210.ext.ti.com ([198.47.19.17]:25816 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750988AbdLAQ4o (ORCPT ); Fri, 1 Dec 2017 11:56:44 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id vB1GuOc7015274; Fri, 1 Dec 2017 10:56:24 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1512147384; bh=LKWcK7CY837YXgVN9ftVBrzEoTtr4y57uV2TqeMP4mk=; h=From:To:CC:Subject:Date; b=oWBNnZExnDVCw/WmSIj/Lpovd6zodKmeaWorgyuAee29ek3Pf0Xiwf3A0rkuKuqkL SYZvs63FKHp9saRwgnDDycWqXZ82dEA9xoYaWYujPyQ0qXrS2BYZzisaf4VGbsHMJY me1QC9Ih76A7GCAkGRgTUOHch2cmr04k6s6C42vk= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id vB1GuOJt013889; Fri, 1 Dec 2017 10:56:24 -0600 Received: from DLEE111.ent.ti.com (157.170.170.22) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34; Fri, 1 Dec 2017 10:56:23 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend Transport; Fri, 1 Dec 2017 10:56:23 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id vB1GuNOs030492; Fri, 1 Dec 2017 10:56:23 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.70.55]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id vB1GuN303169; Fri, 1 Dec 2017 10:56:23 -0600 (CST) From: Dan Murphy To: , , CC: , , Dan Murphy Subject: [PATCH v6 1/6] leds: Add new API to derive a LED name Date: Fri, 1 Dec 2017 10:56:08 -0600 Message-ID: <20171201165613.10358-1-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create an API that is called to derive the LED name from either the DT label in the child node or if that does not exist from the parent node name and an alternate label that is passed in. Signed-off-by: Dan Murphy --- v6 - New patch to add the api to generate a LED label drivers/leds/led-class.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/leds.h | 6 ++++++ 2 files changed, 40 insertions(+) -- 2.15.0.124.g7668cbc60 diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index b0e2d55acbd6..d3e035488737 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -243,6 +244,39 @@ static int led_classdev_next_name(const char *init_name, char *name, return i; } +/** + * of_led_compose_name - derive the LED name based on DT or alternate name. + * + * @parent: parent of LED device + * @child: child node of LED device + * @alt_name: an alternate name if the label node is not found + * @len: length of the alt_name + * @led_name: derived name from either DT label or alt_name + */ +void of_led_compose_name(struct device_node *parent, + struct device_node *child, + const char *alt_name, + size_t len, + char *led_name) +{ + int ret; + int length; + const char *name; + + if (len == 0 || alt_name == NULL) + return; + + ret = of_property_read_string(child, "label", &name); + if (!ret) { + strlcpy(led_name, name, sizeof(led_name)); + } else { + length = len + strlen(parent->name) + 1; + snprintf(led_name, len, "%s:%s", parent->name, alt_name); + } + +} +EXPORT_SYMBOL_GPL(of_led_compose_name); + /** * of_led_classdev_register - register a new object of led_classdev class. * diff --git a/include/linux/leds.h b/include/linux/leds.h index 5579c64c8fd6..9e18dbe196e2 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -123,6 +123,12 @@ struct led_classdev { struct mutex led_access; }; +extern void of_led_compose_name(struct device_node *parent, + struct device_node *child, + const char *alt_name, + size_t len, + char *led_name); + extern int of_led_classdev_register(struct device *parent, struct device_node *np, struct led_classdev *led_cdev);