From patchwork Sat Feb 19 23:56:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 544157 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 8E550C433EF for ; Sat, 19 Feb 2022 23:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiBSX6j (ORCPT ); Sat, 19 Feb 2022 18:58:39 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbiBSX6i (ORCPT ); Sat, 19 Feb 2022 18:58:38 -0500 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D6738A5 for ; Sat, 19 Feb 2022 15:58:18 -0800 (PST) Received: by mail-lj1-x22c.google.com with SMTP id e8so1520606ljj.2 for ; Sat, 19 Feb 2022 15:58:18 -0800 (PST) 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=davTlAz72/o8PzH0gfbXYTV3qnPMMT+uYMyKepr6G5I=; b=gpIzCawQ7726/hWrK4YYTMqxVQSQ+isU4ZSHdyFlx9TkwfZokyi796JG+kQp7csEtL iyeCjl9TlHFyuauhIpMANmAcGt/wNX+YNM8mr3A2NKiinY1gGYRmcIXwH+tjg0C7Zzc+ MbB6xGg/bWmyN57/OdGmbJ2q+WCdkq5+Gnpnetp1Frlvj+hxJSpEZTKm2Yo5wbjdUhjv bAP4M8+FImn/IbXBT/2pQaAbxnr9RXIBS+QZmKhvDwwovyTZYvj04DNpsekP63NlQ0Ip iV3w8xhQs4OWGlIx6fTA4T+ULsylCnBleh7tNYm47hRfY+D7Qg+Yfa/zoYairLKOO95s 6VPg== 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=davTlAz72/o8PzH0gfbXYTV3qnPMMT+uYMyKepr6G5I=; b=UVoRi3yTq2vbH+VOmhJ4ZreV3vqFtdDAcBgM+VJpuNJSGCDMHIqYwB596WQhChsRf4 KbPn78dyHLrYdiY1YrxkPG9fcnF99inS/pYNPjVZZQA9U9dZzNOZBZEpto2Ue8lRLIwO Y4XlEiMN23LB4y4KqT4dGaBPUZrrMV5oxn45goFGBNZ7xsf8UW7ubpbx5osxwIrikDeP yUeH8HwgVkJCZADvKotQzDhtgTy9aPEqP5NVyiET85Sm5Gl4HjKk1W84LyLfmkuUbqqe XMzhSkKVc6JqAZ30UFq6xhkHlTVKPGxC5zhMNYVk8KWOpLB1E68QKDU+CbZhvKjU/btB obbw== X-Gm-Message-State: AOAM533spAtHtxbHxbxnz4QXDlywH+wPHzap0jYZQav47J20TXAF+RzP TTdG4TCwaPLutR7GyzFe/B1WNw== X-Google-Smtp-Source: ABdhPJyQFOkTeWyLkS8fTh2/rw4kF64sCDC5TAs3PjIg8YLy+/XN839nIdoHfVIaCJyc1OHZtauocg== X-Received: by 2002:a05:651c:198f:b0:244:4deb:70d6 with SMTP id bx15-20020a05651c198f00b002444deb70d6mr9980225ljb.167.1645315096519; Sat, 19 Feb 2022 15:58:16 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id q34sm814106lje.121.2022.02.19.15.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 15:58:16 -0800 (PST) From: Linus Walleij To: Pavel Machek Cc: linux-leds@vger.kernel.org, Linus Walleij , devicetree@vger.kernel.org, Antonio Ospite Subject: [PATCH 1/3] dt-bindings: leds: Add regulator-led binding Date: Sun, 20 Feb 2022 00:56:05 +0100 Message-Id: <20220219235607.1613686-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.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 Signed-off-by: Linus Walleij Reviewed-by: Rob Herring --- .../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 Sat Feb 19 23:56:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 544546 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 79ECDC433FE for ; Sat, 19 Feb 2022 23:58:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229821AbiBSX6l (ORCPT ); Sat, 19 Feb 2022 18:58:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbiBSX6k (ORCPT ); Sat, 19 Feb 2022 18:58:40 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A30C138A5 for ; Sat, 19 Feb 2022 15:58:20 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id u20so12008317lff.2 for ; Sat, 19 Feb 2022 15:58:20 -0800 (PST) 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=LFss8ysMBD8Jhg8w3hi8+xycCjjqs7KkMfVxCv6AFTg=; b=mzkDVYMEJwSJQtBKnmCc/3FCnxmQlEcEJPqGV5R4hIsbAoj/ulqprlug2yvn3Cea7k MFK2YZTafG5l2uH1sR5IEOngFJwfSNVXax/XL5fSfIMeplpn5vkmsJ0rA4niCpyVZXcs 6nTgavnEC3mqcQ7JbcDrfdMsmcHl9mi0NgDz1q5OfO7wL9YFWmRNoF+Xr/WBTft/Bto+ 06Gz/yArg0FuDjgesVwPggAcX72ldlj9LDZ+yRwsmOoDwI27YYu79+dGHOseN2nAnU59 JxTuSTi9PSqmhe3piHlTAJecTCkxtfPJV4SSzTrD8cDyI3BgDrIdFnq3Nf4WylLzvYsy lS+A== 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=LFss8ysMBD8Jhg8w3hi8+xycCjjqs7KkMfVxCv6AFTg=; b=0OPVmtAqlWT8xGxLlqk9KGctoJ6anIQiHqHXm5E2fMSSUCuZYaXuo9aCdWuAaPO+8y nf4eTfF+WtNMFhptccUQJCoUQyz6oLoaX40mhta6z3jzBj4VNlKEQJqZk/+JrzDrTks1 UEKUYGT+Rwat9auovC6zHnxTPk/in3RUepAZeAUDjeI9KzK5lCBkjPU0gAGtZ5IpiYX1 qCyOG7NIFUtofyoBpRmybw2usTlAZX4O9fwdkv464/nWz7TRPwJCg06oFQum/2A3VpUm LYdMIM4MpWYPL4czJBhBQZ6r9B92dQs/hav49VK7RugxTJ+/AOva5aJtJgeoIz392zd/ x0Nw== X-Gm-Message-State: AOAM532jpq2SSgYgkfI0U1DKK7O2uOEsRXJ97EBiLqmGU4LAeJ9Euvds 0f5m2O9gXpaT+MLuQlsNx2zXhIaJ+k8MdVYQ X-Google-Smtp-Source: ABdhPJz8C+mfWF1daTKkDozHPHt7cCFObh94mOi4OXTjC+gs1K8PKbQ2hciGVcchs4Ticzh/yr6Xdg== X-Received: by 2002:ac2:5de4:0:b0:443:5b80:d4c4 with SMTP id z4-20020ac25de4000000b004435b80d4c4mr9749259lfq.373.1645315099007; Sat, 19 Feb 2022 15:58:19 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id q34sm814106lje.121.2022.02.19.15.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 15:58:18 -0800 (PST) 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: Sun, 20 Feb 2022 00:56:06 +0100 Message-Id: <20220219235607.1613686-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220219235607.1613686-1-linus.walleij@linaro.org> References: <20220219235607.1613686-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 --- 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 Sat Feb 19 23:56:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 544156 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 53E05C433F5 for ; Sat, 19 Feb 2022 23:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229677AbiBSX6m (ORCPT ); Sat, 19 Feb 2022 18:58:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232156AbiBSX6l (ORCPT ); Sat, 19 Feb 2022 18:58:41 -0500 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 D76CCBCA7 for ; Sat, 19 Feb 2022 15:58:21 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id o2so12043602lfd.1 for ; Sat, 19 Feb 2022 15:58:21 -0800 (PST) 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=j1lBYqoMVGMcb0CHyreIzMQuBYPA3qOgCje3bJMw18w=; b=CpDMcp/LRwZ9CBzdxvkyGVUb8uvbpzJRN8tuo1/TxDZEAnmqAMpAsgfXfvoDekhQhA zfa6R09Y0rAIO2SueeS9M3nE2IHfnREPzNQ4q3xo4WQSa1IJ1MgfIXVX1p/xSh4ZlBUz o7mk2Q9JOMbm0wOgNWGuEWEDk3QJzZI7x3/WfutsLY7HCPhC8IhsKsR5mAyr27E7LR/y OUV0hcqn8HsKn/yrJuG0xfXztxV7aByMY8YpfdsHrtsE3gSmlSJQCugqURE0roqxBz3+ q61OZlyzegegc6J6S9QPe3qgNkmyQUYxntQRFov43m/KlRM3KUP7pkdj4zzcYCMnWxD8 OMoQ== 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=j1lBYqoMVGMcb0CHyreIzMQuBYPA3qOgCje3bJMw18w=; b=MBaocXM1wyHuhJpMwgXq51wXw/VAnDviFPlxcZTDi8Pq5waVkbHTCsDakGXKFka9as toZv1mw523dKo9Myyzd76sN1s8n6s3/zVBbTbXGumskQSb3kH7AVZ5CoPsI88MMr3WFE VtVdli10gtQ5hFdSdgsaZz2oqsnVXWQSxirp7yKC22vZuSWZ4xT59NP3wHBfTe5CsqEq j6yyMbnxvYXKut+4A1QK2gnGmktctQ+z1/vn6wr/D9k91acfh6Uilf/xkXhm3j6KIUou QrumaSieAo/7fj1xHiGytegG9/neYs+2LT5fU5aulOs88wMFuxapTc8njGlwWZTd70nW uCDQ== X-Gm-Message-State: AOAM531UxJosA8Qqnox/QnQoIxg650337dvP/ox/0dCpcplr0UFTUWeY ayOFuxmOx2/0w6xg5dIJPr/REa9rzB0H5rZi X-Google-Smtp-Source: ABdhPJxhuN32JrosZXRaED14ICyv+FqDGMU4gQGz0hchZWiMaKwi75zf+qgOMA4sImwkWafDqIbuWA== X-Received: by 2002:a19:f00f:0:b0:443:ae5c:47d0 with SMTP id p15-20020a19f00f000000b00443ae5c47d0mr8277091lfc.332.1645315100226; Sat, 19 Feb 2022 15:58:20 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id q34sm814106lje.121.2022.02.19.15.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 15:58:19 -0800 (PST) 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: Sun, 20 Feb 2022 00:56:07 +0100 Message-Id: <20220219235607.1613686-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220219235607.1613686-1-linus.walleij@linaro.org> References: <20220219235607.1613686-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 --- 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, };