Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp156142pxa; Wed, 26 Aug 2020 07:18:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYL+lnnss/P+RM85Z4sfUyoyn/NKzTghp3oaGjudUDR3TB6hTkb7H7jmWvWA0h5kBLGsoW X-Received: by 2002:a17:906:3393:: with SMTP id v19mr16707031eja.135.1598451529938; Wed, 26 Aug 2020 07:18:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598451529; cv=none; d=google.com; s=arc-20160816; b=EUGL1F0eg4g+4naaGm20D55rDZdOqH+R4rhtQCfjT54J8zxmZworWDdDxQis0Jj82u hHWFZbDBEo+hztFOZdkPYrWIILm9DmxxdLAY8F7qlumcDQhJai6YcPUPg+BsmGr7gUd4 GabF2bdTMWQRMCZTYjrc/A3G3LmYC6HDVi6LnZr3t1ZMAtWMjfIgXJVhc1eAwRhMT90o kKAdo1Tira3VNmy91lzEE8xFWxuJsnO8g9fLBR2A0GzUQUmgo0OwCzvF3G5VVuOtpRfa 9RzfwJDg33hYesiQA6LRnA7penqOu241pY5r/vxKboXSKUIK1IgN3xffdXPp5a6TSwNe t1zQ== 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:message-id:date :subject:cc:to:from; bh=GBcPTOa9ObX02vw7oRuCWfBdMcVns9FM+NF4TcOkSmY=; b=lwwCcwBHLeno5m7WPimhFyyhWhMdkjYgjKzweIvsPscIgy68Glez+Z4U2GhATZJOrh kqoMg1PvHj0gpTcXidrlX95jcEPPYPH9hTlR4CS7KOKUeJSZC5HJbC/Om7IhrmLvq/bj ZRNaOPntPYPlWKQ+/V+FsAf4Ojp8Jzg7hVLqXeFzY5INOQxomlLoOmMXXz/GKVnvo/J/ Zq3SORSgek5eSalN9u/8yKeBmORjWk6OYroByASAUZRmYvT8e9Mft2ES+25IIBw56qJi rqwgJj+pBNu8nTBSwhgOeeTFpo4hYmO94+lCmI7JyfLXLxp/djVKX4Q8mKQ/f51hD3aN T0Sg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z26si1647888ejj.133.2020.08.26.07.18.27; Wed, 26 Aug 2020 07:18:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728113AbgHZJpu (ORCPT + 99 others); Wed, 26 Aug 2020 05:45:50 -0400 Received: from mail.thorsis.com ([92.198.35.195]:50826 "EHLO mail.thorsis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727997AbgHZJpu (ORCPT ); Wed, 26 Aug 2020 05:45:50 -0400 X-Greylist: delayed 487 seconds by postgrey-1.27 at vger.kernel.org; Wed, 26 Aug 2020 05:45:50 EDT Received: from localhost (localhost [127.0.0.1]) by mail.thorsis.com (Postfix) with ESMTP id 6C7ED46E1; Wed, 26 Aug 2020 11:37:42 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.thorsis.com Received: from mail.thorsis.com ([127.0.0.1]) by localhost (mail.thorsis.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wtvtf5oFOyjP; Wed, 26 Aug 2020 11:37:42 +0200 (CEST) Received: by mail.thorsis.com (Postfix, from userid 109) id 3E5BE471B; Wed, 26 Aug 2020 11:37:41 +0200 (CEST) X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RELAYS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from adahl by ada.ifak-system.com with local (Exim 4.92) (envelope-from ) id 1kArs9-0007Yb-BO; Wed, 26 Aug 2020 11:37:37 +0200 From: Alexander Dahl To: linux-leds@vger.kernel.org Cc: Pavel Machek , Dan Murphy , linux-kernel@vger.kernel.org, Alexander Dahl Subject: [PATCH] leds: pwm: Allow automatic labels for DT based devices Date: Wed, 26 Aug 2020 11:37:37 +0200 Message-Id: <20200826093737.29008-1-ada@thorsis.com> Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Dahl If LEDs are configured through device tree and the property 'label' is omitted, the label is supposed to be generated from the properties 'function' and 'color' if present. While this works fine for e.g. the 'leds-gpio' driver, it did not for 'leds-pwm'. The reason is, you get this label naming magic only if you add a LED device through 'devm_led_classdev_register_ext()' and pass a pointer to the current device tree node. The approach to fix this was adopted from the 'leds-gpio' driver. For the following node from dts the LED appeared as 'led5' in sysfs before and as 'red:debug' after this change. pwm_leds { compatible = "pwm-leds"; led5 { function = LED_FUNCTION_DEBUG; color = ; pwms = <&pwm0 2 10000000 0>; max-brightness = <127>; linux,default-trigger = "heartbeat"; panic-indicator; }; }; Signed-off-by: Alexander Dahl --- Notes: v1: based on v5.9-rc2, backport on v5.4.59 also works drivers/leds/leds-pwm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index ef7b91bd2064..a27a1d75a3e9 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -65,6 +65,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, struct led_pwm *led, struct fwnode_handle *fwnode) { struct led_pwm_data *led_data = &priv->leds[priv->num_leds]; + struct led_init_data init_data = {}; int ret; led_data->active_low = led->active_low; @@ -90,7 +91,13 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, pwm_init_state(led_data->pwm, &led_data->pwmstate); - ret = devm_led_classdev_register(dev, &led_data->cdev); + if (fwnode) { + init_data.fwnode = fwnode; + ret = devm_led_classdev_register_ext(dev, &led_data->cdev, + &init_data); + } else { + ret = devm_led_classdev_register(dev, &led_data->cdev); + } if (ret) { dev_err(dev, "failed to register PWM led for %s: %d\n", led->name, ret); -- 2.27.0