Message ID | 20230912-gpio-led-trigger-dt-v1-1-1b50e3756dda@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp698444vqx; Tue, 12 Sep 2023 14:48:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAMxERsEdAhGXTxrOc2EXNwrjG/991qmlLGchvLDqjbi/VP3zL8pMm/wJIsyXdCP4KaFEG X-Received: by 2002:a05:6a00:1d1a:b0:68b:fc76:7dea with SMTP id a26-20020a056a001d1a00b0068bfc767deamr4992760pfx.12.1694555326579; Tue, 12 Sep 2023 14:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694555326; cv=none; d=google.com; s=arc-20160816; b=M/cslCsZHDyv5P840YBAljDGQlHM+ZWLoTYBUgntEAQfWteGvIVvT07HxmYxn+Tml2 L0Cjpm06zn3DtcYorGQK+H2BQ2LjYsTrkQiadaoj8q4iKXYKIpqMbO2bIxylVjHOdJUt yKrWx/4RZoMBBAQu04HwWToCIDUnKOm0/5v3oPr/oFd7SDO8udzyiGmSjfh+3b4yDKX5 /jb/rJwlumF7/ggpVhFuiggxCawNR70dO2EN860V8O9EoZrmrlaTqhmN9Kal8NTtl7Q+ 0bSljfg5987xRdMHiZCj1WhNvIUwg0Myeoxx0nACCxSrFaI1uackqXM8junur756ibos VFOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=zr1tndUa8GJ+rpTLKAA728oy8bkiMEVH1LyXXvtzocQ=; fh=vOR+f+ec2RFJcjj3G0dAoFd095oyBG31moK1iVhdblk=; b=VDRI7aYrpOMMieCIR/1RckAfBgw//8uK5cGguioiBvi7DsNK+RmtBozuqNoizqnxGc wdkquIO57r8MTV4e4n00zNOvBsf4v6heMc/n0zH0FElDcIn/9WCyR7F1UWiIgmb8UEWC g9t0m9OgqIl46fnBjuFx1EQfQn2o4nvGPdCzl95eZsx9gAWNZmHdOf0EalHT2c6i5c7x jJpQ8UVzjoWzvTp+NTt7ASFPHqHQFTGxaFeTAk1j3tzKv+POPYZcQb7nGv4DLpVfduec fqto1hGOQ4VmOnMn50rqos68oHmoT6QHngJ5P+PlHf2+gg0XiW5scpBj8HNCMbftDkXX k0EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ljM6uTY8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ct5-20020a056a000f8500b0068a692b67b0si8753004pfb.104.2023.09.12.14.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:48:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ljM6uTY8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E93DE81CC851; Tue, 12 Sep 2023 06:45:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235678AbjILNor (ORCPT <rfc822;pwkd43@gmail.com> + 37 others); Tue, 12 Sep 2023 09:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235656AbjILNoi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 12 Sep 2023 09:44:38 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F08E10D9 for <linux-kernel@vger.kernel.org>; Tue, 12 Sep 2023 06:44:34 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-502a25ab777so6352543e87.2 for <linux-kernel@vger.kernel.org>; Tue, 12 Sep 2023 06:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694526272; x=1695131072; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zr1tndUa8GJ+rpTLKAA728oy8bkiMEVH1LyXXvtzocQ=; b=ljM6uTY8TLHrVWuTsqAw98/sjye7NvFIIU3xXeOnql3N4k1SPvpvXiwUf8SON2sqnz ITjEEDogB8bX2WuCiSdq0dKuwwLHq8S07PeW4xPVAYg1XoFCH96oN4ikRQDSvpR+epoe SmgcaxYsEPLlL63QynjdtpmnUwOeMz66roO3HYiFupf7iBO1IRejrDuUWVXc0oWhVVbC FtBgrUiWVOl1ZDetmCXhCNNZzpvaYDvuLG+rBRnKV16KlCPkiNVdI4X0nL7WnPwjYNlB qXSKYM7y1HAsRSYN9P1fkBU3f72cPZyl9RtPFw5akLjhapJQlE8pBEYi32lyFSH1utji HdCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694526272; x=1695131072; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zr1tndUa8GJ+rpTLKAA728oy8bkiMEVH1LyXXvtzocQ=; b=Yoo9bSePcEWkx72y5Td8PrgvyrI9hUZjotWyq/Lb/RZDUZasyG37pPbiL3ALCfI2kz foIZVTjI2IrSVoDsoa/v6DBQpKAPbN6mvPfgIan2BRtlHLkUPhxdRH6nhukKMlYNHQGp Z51V2EuiiClAHQbmfZLyjF2/UGK7S7zZsclj6Daqwnc7Dc4UcTO/xClIHl88sNmXSC4d XHnPm5OdhCh9AQ6W15lu+GtI+1aD9fImfm2xqA2y+6zQhF0/pPmnyV1Bda+iOM6IKtnH 04Nok/0QibXoSPjTIj0l60gLD3OkvsuCBr7Jp6so3s9up0mH+VNf7Oggostc0x5tlvq5 58Qw== X-Gm-Message-State: AOJu0YzlWSXa1WyDfW/lhew8Bqz5c/RDnK6zWGIYT9FeIgwG455BbfS/ aZrleoE5r1wc8tzzluzpWPAuiQ== X-Received: by 2002:a05:6512:3082:b0:501:be3d:8a46 with SMTP id z2-20020a056512308200b00501be3d8a46mr12680112lfd.26.1694526272217; Tue, 12 Sep 2023 06:44:32 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id y6-20020ac255a6000000b00500a2091e30sm1755020lfg.115.2023.09.12.06.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 06:44:31 -0700 (PDT) From: Linus Walleij <linus.walleij@linaro.org> Date: Tue, 12 Sep 2023 15:44:30 +0200 Subject: [PATCH 1/2] dt-bindings: leds: Mention GPIO triggers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230912-gpio-led-trigger-dt-v1-1-1b50e3756dda@linaro.org> References: <20230912-gpio-led-trigger-dt-v1-0-1b50e3756dda@linaro.org> In-Reply-To: <20230912-gpio-led-trigger-dt-v1-0-1b50e3756dda@linaro.org> To: =?utf-8?q?Jan_Kundr=C3=A1t?= <jan.kundrat@cesnet.cz>, Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org> X-Mailer: b4 0.12.3 Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 06:45:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776853064778686805 X-GMAIL-MSGID: 1776870046448239865 |
Series |
Rewrite GPIO LED trigger to use trigger-sources
|
|
Commit Message
Linus Walleij
Sept. 12, 2023, 1:44 p.m. UTC
We reuse the trigger-sources phandle to just point to
GPIOs we may want to use as LED triggers.
Example:
gpio: gpio@0 {
compatible "my-gpio";
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
#trigger-source-cells = <2>;
};
leds {
compatible = "gpio-leds";
led-my-gpio {
label = "device:blue:myled";
gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
default-state = "off";
linux,default-trigger = "gpio";
trigger-sources = <&gpio 1 GPIO_ACTIVE_HIGH>;
};
};
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Documentation/devicetree/bindings/leds/common.yaml | 2 ++
1 file changed, 2 insertions(+)
Comments
On Tue, Sep 12, 2023 at 03:44:30PM +0200, Linus Walleij wrote: > We reuse the trigger-sources phandle to just point to > GPIOs we may want to use as LED triggers. > > Example: > > gpio: gpio@0 { > compatible "my-gpio"; > gpio-controller; > #gpio-cells = <2>; > interrupt-controller; > #interrupt-cells = <2>; > #trigger-source-cells = <2>; BTW, this is not documented for any GPIO binding. If we want to specify the cell size, then it has to be added to every GPIO controller binding. If not, we then need to reference gpio.yaml in every GPIO controller binding (along with unevaluatedProperties). Doesn't have to be done for this patch to go in though. > }; > > leds { > compatible = "gpio-leds"; > led-my-gpio { > label = "device:blue:myled"; > gpios = <&gpio 0 GPIO_ACTIVE_HIGH>; > default-state = "off"; > linux,default-trigger = "gpio"; > trigger-sources = <&gpio 1 GPIO_ACTIVE_HIGH>; > }; > }; > > Signed-off-by: Linus Walleij <linus.walleij@linaro.org> > --- > Documentation/devicetree/bindings/leds/common.yaml | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/Documentation/devicetree/bindings/leds/common.yaml b/Documentation/devicetree/bindings/leds/common.yaml > index 5fb7007f3618..b42950643b9d 100644 > --- a/Documentation/devicetree/bindings/leds/common.yaml > +++ b/Documentation/devicetree/bindings/leds/common.yaml > @@ -191,6 +191,8 @@ properties: > each of them having its own LED assigned (assuming they are not > hardwired). In such cases this property should contain phandle(s) of > related source device(s). > + Another example is a GPIO line that will be monitored and mirror the > + state of the line (with or without inversion flags) to the LED. > In many cases LED can be related to more than one device (e.g. one USB LED > vs. multiple USB ports). Each source should be represented by a node in > the device tree and be referenced by a phandle and a set of phandle > > -- > 2.34.1 >
On Wed, Sep 13, 2023 at 3:34 PM Rob Herring <robh@kernel.org> wrote: > On Tue, Sep 12, 2023 at 03:44:30PM +0200, Linus Walleij wrote: > > We reuse the trigger-sources phandle to just point to > > GPIOs we may want to use as LED triggers. > > > > Example: > > > > gpio: gpio@0 { > > compatible "my-gpio"; > > gpio-controller; > > #gpio-cells = <2>; > > interrupt-controller; > > #interrupt-cells = <2>; > > #trigger-source-cells = <2>; > > BTW, this is not documented for any GPIO binding. If we want to specify > the cell size, then it has to be added to every GPIO controller binding. > If not, we then need to reference gpio.yaml in every GPIO controller > binding (along with unevaluatedProperties). Doesn't have to be done for > this patch to go in though. Yeah I mean this trigger-sources = <...>; one-size-fits-all is a bit weird in a way. My other idea was to simply add trigger-gpios to the normal way and be done with it, but now the trigger binding has this weird thing. Would trigger-gpios be better? Yours, Linus Walleij
On Thu, Sep 14, 2023 at 3:40 AM Linus Walleij <linus.walleij@linaro.org> wrote: > > On Wed, Sep 13, 2023 at 3:34 PM Rob Herring <robh@kernel.org> wrote: > > On Tue, Sep 12, 2023 at 03:44:30PM +0200, Linus Walleij wrote: > > > We reuse the trigger-sources phandle to just point to > > > GPIOs we may want to use as LED triggers. > > > > > > Example: > > > > > > gpio: gpio@0 { > > > compatible "my-gpio"; > > > gpio-controller; > > > #gpio-cells = <2>; > > > interrupt-controller; > > > #interrupt-cells = <2>; > > > #trigger-source-cells = <2>; > > > > BTW, this is not documented for any GPIO binding. If we want to specify > > the cell size, then it has to be added to every GPIO controller binding. > > If not, we then need to reference gpio.yaml in every GPIO controller > > binding (along with unevaluatedProperties). Doesn't have to be done for > > this patch to go in though. > > Yeah I mean this trigger-sources = <...>; one-size-fits-all is a bit > weird in a way. > > My other idea was to simply add trigger-gpios to the normal way > and be done with it, but now the trigger binding has this weird > thing. > > Would trigger-gpios be better? Then GPIOs are different than everyone else. I think we have to think about other bindings too. While we could standardize the naming here with trigger-gpios, that won't work with the foos/foo-names style of bindings. trigger-sources is not widely used as it is just USB ATM and a few platforms. We could come up with something different. "trigger-sources-<cellname>" is the only idea I have. Then the property name gives you the cell name to read. But variable property names have their own challenges. We would need to look at all the current trigger sources (i.e. the linux,default-trigger ones) and see what else might need this. Rob
On Thu, Sep 14, 2023 at 4:27 PM Rob Herring <robh@kernel.org> wrote: > On Thu, Sep 14, 2023 at 3:40 AM Linus Walleij <linus.walleij@linaro.org> wrote: > > On Wed, Sep 13, 2023 at 3:34 PM Rob Herring <robh@kernel.org> wrote: > > > On Tue, Sep 12, 2023 at 03:44:30PM +0200, Linus Walleij wrote: > > > > We reuse the trigger-sources phandle to just point to > > > > GPIOs we may want to use as LED triggers. > > > > > > > > Example: > > > > > > > > gpio: gpio@0 { > > > > compatible "my-gpio"; > > > > gpio-controller; > > > > #gpio-cells = <2>; > > > > interrupt-controller; > > > > #interrupt-cells = <2>; > > > > #trigger-source-cells = <2>; > > > > > > BTW, this is not documented for any GPIO binding. If we want to specify > > > the cell size, then it has to be added to every GPIO controller binding. > > > If not, we then need to reference gpio.yaml in every GPIO controller > > > binding (along with unevaluatedProperties). Doesn't have to be done for > > > this patch to go in though. > > > > Yeah I mean this trigger-sources = <...>; one-size-fits-all is a bit > > weird in a way. > > > > My other idea was to simply add trigger-gpios to the normal way > > and be done with it, but now the trigger binding has this weird > > thing. > > > > Would trigger-gpios be better? > > Then GPIOs are different than everyone else. I think we have to think > about other bindings too. While we could standardize the naming here > with trigger-gpios, that won't work with the foos/foo-names style of > bindings. > > trigger-sources is not widely used as it is just USB ATM and a few > platforms. We could come up with something different. > "trigger-sources-<cellname>" is the only idea I have. Then the > property name gives you the cell name to read. But variable property > names have their own challenges. We would need to look at all the > current trigger sources (i.e. the linux,default-trigger ones) and see > what else might need this. I think it in a way is elegant with the trigger-sources phandle as it is so I would stick with this. I can just add '#trigger-source-cells' to the existing GPIO bindings and it's a bit tedious since we don't have a common file for the GPIO chip stuff, but it's just lots of lines. I guess it would be better to break out gpio-common.yaml and gpio-common-irq.yaml for GPIO controllers with or without interrupt support and then add '#trigger-source-cells' to just those supporting IRQs because I think only that makes sense, polling for a line to change isn't quite a "trigger". Yours, Linus Walleij
On Fri, Sep 15, 2023 at 7:01 AM Linus Walleij <linus.walleij@linaro.org> wrote: > > On Thu, Sep 14, 2023 at 4:27 PM Rob Herring <robh@kernel.org> wrote: > > On Thu, Sep 14, 2023 at 3:40 AM Linus Walleij <linus.walleij@linaro.org> wrote: > > > On Wed, Sep 13, 2023 at 3:34 PM Rob Herring <robh@kernel.org> wrote: > > > > On Tue, Sep 12, 2023 at 03:44:30PM +0200, Linus Walleij wrote: > > > > > We reuse the trigger-sources phandle to just point to > > > > > GPIOs we may want to use as LED triggers. > > > > > > > > > > Example: > > > > > > > > > > gpio: gpio@0 { > > > > > compatible "my-gpio"; > > > > > gpio-controller; > > > > > #gpio-cells = <2>; > > > > > interrupt-controller; > > > > > #interrupt-cells = <2>; > > > > > #trigger-source-cells = <2>; > > > > > > > > BTW, this is not documented for any GPIO binding. If we want to specify > > > > the cell size, then it has to be added to every GPIO controller binding. > > > > If not, we then need to reference gpio.yaml in every GPIO controller > > > > binding (along with unevaluatedProperties). Doesn't have to be done for > > > > this patch to go in though. > > > > > > Yeah I mean this trigger-sources = <...>; one-size-fits-all is a bit > > > weird in a way. > > > > > > My other idea was to simply add trigger-gpios to the normal way > > > and be done with it, but now the trigger binding has this weird > > > thing. > > > > > > Would trigger-gpios be better? > > > > Then GPIOs are different than everyone else. I think we have to think > > about other bindings too. While we could standardize the naming here > > with trigger-gpios, that won't work with the foos/foo-names style of > > bindings. > > > > trigger-sources is not widely used as it is just USB ATM and a few > > platforms. We could come up with something different. > > "trigger-sources-<cellname>" is the only idea I have. Then the > > property name gives you the cell name to read. But variable property > > names have their own challenges. We would need to look at all the > > current trigger sources (i.e. the linux,default-trigger ones) and see > > what else might need this. > > I think it in a way is elegant with the trigger-sources phandle as it > is so I would stick with this. > > I can just add '#trigger-source-cells' to the existing GPIO > bindings and it's a bit tedious since we don't have a common file > for the GPIO chip stuff, but it's just lots of lines. We do, gpio.yaml in dtschema. We just didn't reference it in all controllers because at the time unevaluatedProperties didn't exist/work and you still have to list most properties to define their constraints. In general, we reference the common schema for ones with child nodes, but not ones which are just #foo-cells and other properties. For GPIO, it's evolved to the point that referencing the common schema makes sense mainly because we have the hog nodes now. I said before we still need '#trigger-source-cells' in each schema, but really I suppose if we just set it to 1 or 2 cells in the common schema, that would be good enough. It's so rarely used. I expect (because there's discussions on it) someday jsonschema will support data dependent schemas (i.e. if the value of prop is X, then apply schema). Actually, we can do that already with if/then schemas, but it would be kind of verbose. > I guess it would be better to break out gpio-common.yaml and > gpio-common-irq.yaml for GPIO controllers with or without > interrupt support and then add '#trigger-source-cells' to just > those supporting IRQs because I think only that makes sense, > polling for a line to change isn't quite a "trigger". No need to split them just for that: dependencies: '#trigger-source-cells': interrupt-controller Though maybe a split makes sense anyways. Rob
diff --git a/Documentation/devicetree/bindings/leds/common.yaml b/Documentation/devicetree/bindings/leds/common.yaml index 5fb7007f3618..b42950643b9d 100644 --- a/Documentation/devicetree/bindings/leds/common.yaml +++ b/Documentation/devicetree/bindings/leds/common.yaml @@ -191,6 +191,8 @@ properties: each of them having its own LED assigned (assuming they are not hardwired). In such cases this property should contain phandle(s) of related source device(s). + Another example is a GPIO line that will be monitored and mirror the + state of the line (with or without inversion flags) to the LED. In many cases LED can be related to more than one device (e.g. one USB LED vs. multiple USB ports). Each source should be represented by a node in the device tree and be referenced by a phandle and a set of phandle