From patchwork Mon Apr 4 20:35:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 556124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DED8C43219 for ; Mon, 4 Apr 2022 21:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379611AbiDDVUK (ORCPT ); Mon, 4 Apr 2022 17:20:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380593AbiDDUjY (ORCPT ); Mon, 4 Apr 2022 16:39:24 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B74026AC8 for ; Mon, 4 Apr 2022 13:37:27 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id bn33so14506440ljb.6 for ; Mon, 04 Apr 2022 13:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8EWmhxYeescuoCv2qecY489ZApW2YrepMt4Bje0oQts=; b=XtRO6Fx/fmKs2i6b1ODuN/x3OlLed4vBIORJcGplwAGpxWw1rTqHE8UGCgrUN6hJWf DCEaidi9c2pAkn5SVhtyfdipWkxcmjvxYAVykmNvQDF4t+dcl86bCqT4ihxGyflR7vVh wiUyBLZL4hn6C+hm4UE/lSH2UYTmhBKe/+3Q2vsraTDfwC7wIXbfKRa/xRPxcMxI2Q9Y gat4fx2S4J7ToOZI01e9+EDDozAzFFA3pfcZ2UvnVjaAXUnr2wslwNx+2LHwQnPlblq3 QYwu0Xb2X2/k/kawMBA0Qui59ToLuOkunJj2DOxlXE7GAi9SuekrgVjD2ibAdq74hjqK B3jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8EWmhxYeescuoCv2qecY489ZApW2YrepMt4Bje0oQts=; b=jT4MiEXscByWgNEJYwkBg2HpvERUR6qSDWVSsfbD2EEf1+25fdwzq0KFJIH0IMVFG+ bVo6F8fV//Ly/Y3XiEwAdJZO4u+xuAvYYuanuOpkAaN0wCVcNuZS+HcMvrtHWiP5jy29 hSyMmA9WAQgd77JSFAFU0H47pNcsZ5Ixtiv5tzb//M6T2FvmoUqtHPBgzkkZcmA+OktI 559w824rWYfmKuRgafNLcex/f3lwlyomkD5LHooCq3sWvQkQDgRxW4y7NgiAzHfTdvJQ Upr4ZKBtLSBF54wObpg9Ykwhk2RMqKRWLPdyfCx4sQ6YOoPJFyLQcO3uRdOEvLtGqdsN pgMw== X-Gm-Message-State: AOAM532xrTBpEvayF1iB3pb3inrlnuxK0QR5sjqTqxFeRv3CafrrprU1 8V65MYZ49PJZitJ8eS0w4KgdWn6eu1dsjA== X-Google-Smtp-Source: ABdhPJzKHkHsEZI8v4wcxTfaqUyEuS0DxyKN3vdpdKdh60ERXh+ofmvpzf8iLoQyxkGPpsmsri1Z5g== X-Received: by 2002:a2e:a408:0:b0:246:35dd:c242 with SMTP id p8-20020a2ea408000000b0024635ddc242mr842848ljn.197.1649104645175; Mon, 04 Apr 2022 13:37:25 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m14-20020a2eb6ce000000b0024afbbbb0c3sm1154650ljo.70.2022.04.04.13.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 13:37:24 -0700 (PDT) From: Linus Walleij To: Pavel Machek Cc: linux-leds@vger.kernel.org, Linus Walleij , devicetree@vger.kernel.org, Antonio Ospite , Rob Herring Subject: [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Date: Mon, 4 Apr 2022 22:35:20 +0200 Message-Id: <20220404203522.2068071-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org The regulator is a LED connected directly to a regulator and with its brightness controlled by the voltage of the regulator. Cc: devicetree@vger.kernel.org Cc: Antonio Ospite Reviewed-by: Rob Herring Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Collect Rob's ACK - Rebase on v5.18-rc1 --- .../bindings/leds/regulator-led.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/regulator-led.yaml diff --git a/Documentation/devicetree/bindings/leds/regulator-led.yaml b/Documentation/devicetree/bindings/leds/regulator-led.yaml new file mode 100644 index 000000000000..3e020d700c00 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/regulator-led.yaml @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/regulator-led.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Device Tree Bindings for Regulator LEDs + +maintainers: + - Linus Walleij + +description: | + Regulator LEDs are powered by a single regulator such that they can + be turned on or off by enabling or disabling the regulator. The available + brightness settings will be inferred from the available voltages on the + regulator, and any constraints on the voltage or current will need to be + specified on the regulator. + +allOf: + - $ref: common.yaml# + +properties: + $nodename: + pattern: '^led.*$' + + compatible: + const: regulator-led + + vled-supply: + description: + The regulator controlling the current to the LED. + + function: true + color: true + linux,default-trigger: true + default-state: true + +required: + - compatible + - vled-supply + +additionalProperties: false + +examples: + - | + #include + + led-heartbeat { + compatible = "regulator-led"; + vled-supply = <®ulator>; + function = LED_FUNCTION_STATUS; + color = ; + linux,default-trigger = "heartbeat"; + }; +... From patchwork Mon Apr 4 20:35:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 556123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 692FDC4707A for ; Mon, 4 Apr 2022 21:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379630AbiDDVUM (ORCPT ); Mon, 4 Apr 2022 17:20:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380595AbiDDUjs (ORCPT ); Mon, 4 Apr 2022 16:39:48 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F1C25EB8 for ; Mon, 4 Apr 2022 13:37:51 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id e16so19454448lfc.13 for ; Mon, 04 Apr 2022 13:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GfUQJ+5ZKTsh5/P7HOu/fecB4P8HYcIT9EAtiQi9qYw=; b=owtX2OX5gEMDhOb2tI+OzblKDVHGdBTAT1HkXZK1b72EyMRhul0SGChncwQK1t+VId /cweVmES4uGM2ef/Hudrik0yBYhHrUaH2ry/O6jCd4Toea2WsiLD1XMn3N7SO2b9EOt5 0PBwKGXDJqS0XxfD4ipbh2kQP09evohJ8d4b8H69AFUlke9NN5csxPrgLl/fezk6y3fw F1CIjxdpXq3PIIfKdZG3g4R4SWncVp70WbfJzAaZejJPWtsAx2LPA22ahbd7GRLFvEd5 1uXCjh3IxofKT0BwXmuOQojVKXRmxDvLtYrepMIqXeTPEf3Lt2KNQGh0EA/LXvKeOOHQ WIjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GfUQJ+5ZKTsh5/P7HOu/fecB4P8HYcIT9EAtiQi9qYw=; b=OFWEY8fPwr7w0PxNpAk/+v+BIpFTfkJpmApJ9yYms520kpgXLsO3+5dcQd/vP09qOC 1p7CfugKPDSO3fD0STBEhRCEZQpb0liLl0xck8O4PqFHNTUbh1tSsnRnO77E/L1jbdiv FP994HDVlOD0ZK2ABTfcIKzccltdEv3Iw5vq8doFS9KiX9a98rGJN+W23DStDhefkeru F8TZ2p8y/bYLsAu02CxfGh0xpf4EJJv4CtvK6lBVwM8d3dy93vXZuHNkjxUQ9bjUEYuJ XIGaKuRn/K7pXRzmF9hiPs0W2ogldisV6oH/c59F2gRVYIxH4a1mZdxv64ImxBlmOY2S AA7g== X-Gm-Message-State: AOAM533P47FB150DZiknCk6ZSSZGA5OgiE8fAMp7GrESLMh/uH5098e+ getWtzLjZnhxLhlcKFc5/JasaQ== X-Google-Smtp-Source: ABdhPJy2t36zV7CHqwT5f+UGlpEXXWpKqFtSwQEtnEk1Ku8aucozAFx7D4XB6DrdimvodqzGmbEfzA== X-Received: by 2002:a05:6512:e8f:b0:44a:bf22:89c8 with SMTP id bi15-20020a0565120e8f00b0044abf2289c8mr77975lfb.323.1649104669783; Mon, 04 Apr 2022 13:37:49 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m14-20020a2eb6ce000000b0024afbbbb0c3sm1154650ljo.70.2022.04.04.13.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 13:37:49 -0700 (PDT) From: Linus Walleij To: Pavel Machek Cc: linux-leds@vger.kernel.org, Linus Walleij , Antonio Ospite Subject: [PATCH 2/3] leds: regulator: Add dev helper variable Date: Mon, 4 Apr 2022 22:35:21 +0200 Message-Id: <20220404203522.2068071-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220404203522.2068071-1-linus.walleij@linaro.org> References: <20220404203522.2068071-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Instead of repeating the hard to read &pdev->dev just create a local struct device *dev in probe(). Cc: Antonio Ospite Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on v5.18-rc1 --- drivers/leds/leds-regulator.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/leds/leds-regulator.c b/drivers/leds/leds-regulator.c index 208c98918433..87b9f46e572b 100644 --- a/drivers/leds/leds-regulator.c +++ b/drivers/leds/leds-regulator.c @@ -123,28 +123,29 @@ static int regulator_led_probe(struct platform_device *pdev) { struct led_regulator_platform_data *pdata = dev_get_platdata(&pdev->dev); + struct device *dev = &pdev->dev; struct regulator_led *led; struct regulator *vcc; int ret = 0; if (pdata == NULL) { - dev_err(&pdev->dev, "no platform data\n"); + dev_err(dev, "no platform data\n"); return -ENODEV; } - vcc = devm_regulator_get_exclusive(&pdev->dev, "vled"); + vcc = devm_regulator_get_exclusive(dev, "vled"); if (IS_ERR(vcc)) { - dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name); + dev_err(dev, "Cannot get vcc for %s\n", pdata->name); return PTR_ERR(vcc); } - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); if (led == NULL) return -ENOMEM; led->cdev.max_brightness = led_regulator_get_max_brightness(vcc); if (pdata->brightness > led->cdev.max_brightness) { - dev_err(&pdev->dev, "Invalid default brightness %d\n", + dev_err(dev, "Invalid default brightness %d\n", pdata->brightness); return -EINVAL; } @@ -162,7 +163,7 @@ static int regulator_led_probe(struct platform_device *pdev) platform_set_drvdata(pdev, led); - ret = led_classdev_register(&pdev->dev, &led->cdev); + ret = led_classdev_register(dev, &led->cdev); if (ret < 0) return ret; From patchwork Mon Apr 4 20:35:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 558438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29AA0C4332F for ; Mon, 4 Apr 2022 21:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379624AbiDDVUL (ORCPT ); Mon, 4 Apr 2022 17:20:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380596AbiDDUjt (ORCPT ); Mon, 4 Apr 2022 16:39:49 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFF4326AC8 for ; Mon, 4 Apr 2022 13:37:52 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id e16so19454522lfc.13 for ; Mon, 04 Apr 2022 13:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wXd7MQ3R8DlS2U8G/UUEE/J7wGJYvs66gXT9b6R666M=; b=fwh9rj1x7brhDKaZe8B5oHVYo7ESn21APvI36bPJ7mjFgRl+dHEcLU4PjmJB9y70UM rzJucCAyaYdqox89TZXZZlnV9QCg/CsWGShpzImA4czpIdRiDBFDlIW9u+6ht9H3lrfu wvJ5Ut7LlzfYBmwHmMF023ZEA9Ifek6gwF+kUPM8FsL53+oWanfyNiA+xiIuE+kz7ep4 cgECpRfgxCIGgWnqYIb29aWAN67MzJxL+g5VSLjU6KvuzlGbflyodbVrfJhpJX5ZhUcu n+9++2Vvo2JrM1nMfKD2enpsZ9DSNeT9hLhScc5FaY/7OaEsKLeb/ZIZ083Sl7kigNSi WITQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wXd7MQ3R8DlS2U8G/UUEE/J7wGJYvs66gXT9b6R666M=; b=Hav0uSIDdkXGALbqh+Zf+p7ncqdBhFbiBqg5s5oW0oXvljwJB6BsHy6LCwr0vZmCuQ MGCkLAOnf6G2nAqKNWh+kGGseU7NIW6ynSWTGH0oW04fzQo1RyHX0qyeFGGrojV7Uuhz Lbzi0WVfx9a477Isx9CeYrZR85o+iQm+d6Lu9MOCoBD+kPd4Rn8G+p8/7bZvZR5ReXoQ Du90t1oz33TmnYif9Rduw9jqjbmMyqfJrDsiU0fIyDcOvhMLS9ZWqU+MtZGdrt46yCU1 qXOrBnErR10PS7N3XWuVSeHybMeTmY64wvdCeywzuvhrzXI7WU8FP018ygMkU/96XE8t I6uw== X-Gm-Message-State: AOAM530+mDQ4xQg2cuKijTBEI4rpuxuCGegwIs2cZ4xAQeFkduTMtc4Z 6gLZP22Ew6GGoDJrA4pkMiup7g== X-Google-Smtp-Source: ABdhPJw06dmp/qmd75CMJumrWUv0O2dps6JG3ldN1OucoEa9qv8bMtetnpiMLAgL3Yy2QleMdJkKLg== X-Received: by 2002:a05:6512:3d0f:b0:44a:d8a5:9c38 with SMTP id d15-20020a0565123d0f00b0044ad8a59c38mr112725lfv.84.1649104671153; Mon, 04 Apr 2022 13:37:51 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m14-20020a2eb6ce000000b0024afbbbb0c3sm1154650ljo.70.2022.04.04.13.37.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 13:37:50 -0700 (PDT) From: Linus Walleij To: Pavel Machek Cc: linux-leds@vger.kernel.org, Linus Walleij , Antonio Ospite Subject: [PATCH 3/3] leds: regulator: Make probeable from device tree Date: Mon, 4 Apr 2022 22:35:22 +0200 Message-Id: <20220404203522.2068071-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220404203522.2068071-1-linus.walleij@linaro.org> References: <20220404203522.2068071-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org The regulator LED can easily be adapted to probe from the device tree. We switch led_classdev_register() to led_classdev_register_ext() passing some struct led_init_data init_data that we leave NULL save the fwnode if platform data isn't present so that it will be populated from the device tree. If we have platform data we set up the name from the platform data but using init_data instead. Cc: Antonio Ospite Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on v5.18-rc1 --- drivers/leds/leds-regulator.c | 42 +++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/drivers/leds/leds-regulator.c b/drivers/leds/leds-regulator.c index 87b9f46e572b..8a8b73b4e358 100644 --- a/drivers/leds/leds-regulator.c +++ b/drivers/leds/leds-regulator.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -124,18 +125,14 @@ static int regulator_led_probe(struct platform_device *pdev) struct led_regulator_platform_data *pdata = dev_get_platdata(&pdev->dev); struct device *dev = &pdev->dev; + struct led_init_data init_data = {}; struct regulator_led *led; struct regulator *vcc; int ret = 0; - if (pdata == NULL) { - dev_err(dev, "no platform data\n"); - return -ENODEV; - } - vcc = devm_regulator_get_exclusive(dev, "vled"); if (IS_ERR(vcc)) { - dev_err(dev, "Cannot get vcc for %s\n", pdata->name); + dev_err(dev, "Cannot get vcc\n"); return PTR_ERR(vcc); } @@ -143,15 +140,21 @@ static int regulator_led_probe(struct platform_device *pdev) if (led == NULL) return -ENOMEM; + init_data.fwnode = dev->fwnode; + led->cdev.max_brightness = led_regulator_get_max_brightness(vcc); - if (pdata->brightness > led->cdev.max_brightness) { - dev_err(dev, "Invalid default brightness %d\n", + /* Legacy platform data label assignment */ + if (pdata) { + if (pdata->brightness > led->cdev.max_brightness) { + dev_err(dev, "Invalid default brightness %d\n", pdata->brightness); - return -EINVAL; + return -EINVAL; + } + led->cdev.brightness = pdata->brightness; + init_data.default_label = pdata->name; } led->cdev.brightness_set_blocking = regulator_led_brightness_set; - led->cdev.name = pdata->name; led->cdev.flags |= LED_CORE_SUSPENDRESUME; led->vcc = vcc; @@ -163,16 +166,10 @@ static int regulator_led_probe(struct platform_device *pdev) platform_set_drvdata(pdev, led); - ret = led_classdev_register(dev, &led->cdev); + ret = led_classdev_register_ext(dev, &led->cdev, &init_data); if (ret < 0) return ret; - /* to expose the default value to userspace */ - led->cdev.brightness = pdata->brightness; - - /* Set the default led status */ - regulator_led_brightness_set(&led->cdev, led->cdev.brightness); - return 0; } @@ -185,10 +182,17 @@ static int regulator_led_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id regulator_led_of_match[] = { + { .compatible = "regulator-led", }, + {} +}; +MODULE_DEVICE_TABLE(of, regulator_led_of_match); + static struct platform_driver regulator_led_driver = { .driver = { - .name = "leds-regulator", - }, + .name = "leds-regulator", + .of_match_table = regulator_led_of_match, + }, .probe = regulator_led_probe, .remove = regulator_led_remove, };