* [PATCH] docs: dt-bindings: add DTS Coding Style document
@ 2023-11-16 18:12 Krzysztof Kozlowski
2023-11-16 19:26 ` Heiko Stuebner
` (5 more replies)
0 siblings, 6 replies; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-16 18:12 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel
Cc: Krzysztof Kozlowski, AngeloGioacchino Del Regno, Arnd Bergmann,
Bjorn Andersson, Geert Uytterhoeven, Heiko Stuebner,
Konrad Dybcio, Matthias Brugger, Michal Simek, Neil Armstrong,
Nishanth Menon, Olof Johansson
Document preferred coding style for Devicetree sources (DTS and DTSI),
to bring consistency among all (sub)architectures and ease in reviews.
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Andersson <andersson@kernel.org>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Michal Simek <michal.simek@amd.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Nishanth Menon <nm@ti.com>
Cc: Olof Johansson <olof@lixom.net>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Merging idea: Rob/DT bindings
---
Documentation/devicetree/bindings/index.rst | 1 +
.../devicetree/bindings/writing-dts.rst | 137 ++++++++++++++++++
2 files changed, 138 insertions(+)
create mode 100644 Documentation/devicetree/bindings/writing-dts.rst
diff --git a/Documentation/devicetree/bindings/index.rst b/Documentation/devicetree/bindings/index.rst
index d9002a3a0abb..975449be4862 100644
--- a/Documentation/devicetree/bindings/index.rst
+++ b/Documentation/devicetree/bindings/index.rst
@@ -5,5 +5,6 @@
ABI
writing-bindings
+ writing-dts
writing-schema
submitting-patches
diff --git a/Documentation/devicetree/bindings/writing-dts.rst b/Documentation/devicetree/bindings/writing-dts.rst
new file mode 100644
index 000000000000..10c477ec1eed
--- /dev/null
+++ b/Documentation/devicetree/bindings/writing-dts.rst
@@ -0,0 +1,137 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. _writingdts:
+
+===================================================
+Writing Devicetree Sources (DTS) - DTS Coding Style
+===================================================
+
+When writing Devicetree Sources (DTS) please observe below guidelines. They
+should be considered complementary to any rules expressed already in Devicetree
+Specification and dtc compiler (including W=1 and W=2 builds).
+
+Individual architectures and sub-architectures can add additional rules, making
+the style stricter.
+
+Naming and Valid Characters
+---------------------------
+
+1. Node and property names are allowed to use only:
+
+ * lowercase characters:: [a-z]
+ * digits:: [0-9]
+ * dash:: -
+
+2. Labels are allowed to use only:
+
+ * lowercase characters:: [a-z]
+ * digits:: [0-9]
+ * underscore:: _
+
+3. Unit addresses should use lowercase hex, without leading zeros (padding).
+
+4. Hex values in properties, e.g. "reg", should use lowercase hex. Any address
+ part can be padded with leading zeros.
+
+Example::
+
+ gpi_dma2: dma-controller@800000 {
+ compatible = "qcom,sm8550-gpi-dma", "qcom,sm6350-gpi-dma";
+ reg = <0x0 0x00800000 0x0 0x60000>;
+ }
+
+Order of Nodes
+--------------
+
+1. Nodes within any bus, thus using unit addresses for children, shall be
+ ordered incrementally by unit address.
+
+2. Nodes without unit addresses should be ordered alpha-numerically.
+
+3. When extending nodes in board DTS via &label, the entries should be ordered
+ alpha-numerically.
+
+Example::
+
+ // SoC DTSI
+
+ \ {
+ cpus {
+ // ...
+ };
+
+ psci {
+ // ...
+ };
+
+ soc@ {
+ dma: dma-controller@10000 {
+ // ...
+ };
+
+ clk: clock-controller@80000 {
+ // ...
+ };
+ };
+ };
+
+ // Board DTS
+
+ &clk {
+ // ...
+ };
+
+ &dma {
+ // ...
+ };
+
+
+Order of Properties in Device Node
+----------------------------------
+
+Following order of properties in device nodes is preferred:
+
+1. compatible
+2. reg
+3. ranges
+4. All properties with values
+5. Boolean properties
+6. status (if applicable)
+7. Child nodes
+
+The "status" property is by default "okay", thus it can be omitted.
+
+Example::
+
+ // SoC DTSI
+
+ usb_1_hsphy: phy@88e3000 {
+ compatible = "qcom,sm8550-snps-eusb2-phy";
+ reg = <0x0 0x088e3000 0x0 0x154>;
+ #phy-cells = <0>;
+ resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>;
+ status = "disabled";
+ };
+
+ // Board DTS
+
+ &usb_1_hsphy {
+ clocks = <&tcsr TCSR_USB2_CLKREF_EN>;
+ clock-names = "ref";
+ status = "okay";
+ };
+
+
+Indentation
+-----------
+
+1. Use indentation according to :ref:`codingstyle`.
+2. For arrays spanning across lines, preferred is to align the continued
+ entries with opening < from first line.
+
+Example::
+
+ thermal-sensor@c271000 {
+ compatible = "qcom,sm8550-tsens", "qcom,tsens-v2";
+ reg = <0x0 0x0c271000 0x0 0x1000>,
+ <0x0 0x0c222000 0x0 0x1000>;
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 18:12 [PATCH] docs: dt-bindings: add DTS Coding Style document Krzysztof Kozlowski
@ 2023-11-16 19:26 ` Heiko Stuebner
2023-11-16 19:51 ` Krzysztof Kozlowski
2023-11-16 20:44 ` Rob Herring
` (4 subsequent siblings)
5 siblings, 1 reply; 22+ messages in thread
From: Heiko Stuebner @ 2023-11-16 19:26 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, Krzysztof Kozlowski
Cc: Krzysztof Kozlowski, AngeloGioacchino Del Regno, Arnd Bergmann,
Bjorn Andersson, Geert Uytterhoeven, Konrad Dybcio,
Matthias Brugger, Michal Simek, Neil Armstrong, Nishanth Menon,
Olof Johansson
Hi Krzysztof,
Am Donnerstag, 16. November 2023, 19:12:18 CET schrieb Krzysztof Kozlowski:
> Document preferred coding style for Devicetree sources (DTS and DTSI),
> to bring consistency among all (sub)architectures and ease in reviews.
>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Michal Simek <michal.simek@amd.com>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Nishanth Menon <nm@ti.com>
> Cc: Olof Johansson <olof@lixom.net>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> +Order of Properties in Device Node
> +----------------------------------
> +
> +Following order of properties in device nodes is preferred:
> +
> +1. compatible
> +2. reg
> +3. ranges
> +4. All properties with values
> +5. Boolean properties
I guess the only thing I do have questions about is the part
> +4. All properties with values
> +5. Boolean properties
Is there a rationale for it? Because with it things like regulator-*
properties then end up in two different blocks.
For all the rest I fully agree :-)
Thanks
Heiko
> +6. status (if applicable)
> +7. Child nodes
> +
> +The "status" property is by default "okay", thus it can be omitted.
> +
> +Example::
> +
> + // SoC DTSI
> +
> + usb_1_hsphy: phy@88e3000 {
> + compatible = "qcom,sm8550-snps-eusb2-phy";
> + reg = <0x0 0x088e3000 0x0 0x154>;
> + #phy-cells = <0>;
> + resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>;
> + status = "disabled";
> + };
> +
> + // Board DTS
> +
> + &usb_1_hsphy {
> + clocks = <&tcsr TCSR_USB2_CLKREF_EN>;
> + clock-names = "ref";
> + status = "okay";
> + };
> +
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 19:26 ` Heiko Stuebner
@ 2023-11-16 19:51 ` Krzysztof Kozlowski
2023-11-16 20:03 ` Heiko Stuebner
0 siblings, 1 reply; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-16 19:51 UTC (permalink / raw)
To: Heiko Stuebner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
On 16/11/2023 20:26, Heiko Stuebner wrote:
> Hi Krzysztof,
> Am Donnerstag, 16. November 2023, 19:12:18 CET schrieb Krzysztof Kozlowski:
>> Document preferred coding style for Devicetree sources (DTS and DTSI),
>> to bring consistency among all (sub)architectures and ease in reviews.
>>
>> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> Cc: Arnd Bergmann <arnd@arndb.de>
>> Cc: Bjorn Andersson <andersson@kernel.org>
>> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
>> Cc: Heiko Stuebner <heiko@sntech.de>
>> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
>> Cc: Matthias Brugger <matthias.bgg@gmail.com>
>> Cc: Michal Simek <michal.simek@amd.com>
>> Cc: Neil Armstrong <neil.armstrong@linaro.org>
>> Cc: Nishanth Menon <nm@ti.com>
>> Cc: Olof Johansson <olof@lixom.net>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>
>
>> +Order of Properties in Device Node
>> +----------------------------------
>> +
>> +Following order of properties in device nodes is preferred:
>> +
>> +1. compatible
>> +2. reg
>> +3. ranges
>> +4. All properties with values
>> +5. Boolean properties
>
> I guess the only thing I do have questions about is the part
>
>> +4. All properties with values
>> +5. Boolean properties
>
> Is there a rationale for it? Because with it things like regulator-*
> properties then end up in two different blocks.
Good point. It is only a matter of style that this:
foo {
compatible = "foo";
reg = <0x1>;
clocks = <&clk>;
wakeup-source;
key-autorepeat;
}
looks better to me than:
foo {
compatible = "foo";
reg = <0x1>;
key-autorepeat;
wakeup-source;
clocks = <&clk>;
}
But you have good point that similar properties should be usually
grouped together.
About which regulator properties are you thinking now? You mean the
supplies or the provider?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 19:51 ` Krzysztof Kozlowski
@ 2023-11-16 20:03 ` Heiko Stuebner
2023-11-16 20:23 ` Krzysztof Kozlowski
0 siblings, 1 reply; 22+ messages in thread
From: Heiko Stuebner @ 2023-11-16 20:03 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, Krzysztof Kozlowski
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
Am Donnerstag, 16. November 2023, 20:51:24 CET schrieb Krzysztof Kozlowski:
> On 16/11/2023 20:26, Heiko Stuebner wrote:
> > Hi Krzysztof,
> > Am Donnerstag, 16. November 2023, 19:12:18 CET schrieb Krzysztof Kozlowski:
> >> Document preferred coding style for Devicetree sources (DTS and DTSI),
> >> to bring consistency among all (sub)architectures and ease in reviews.
> >>
> >> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> >> Cc: Arnd Bergmann <arnd@arndb.de>
> >> Cc: Bjorn Andersson <andersson@kernel.org>
> >> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> >> Cc: Heiko Stuebner <heiko@sntech.de>
> >> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> >> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> >> Cc: Michal Simek <michal.simek@amd.com>
> >> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> >> Cc: Nishanth Menon <nm@ti.com>
> >> Cc: Olof Johansson <olof@lixom.net>
> >> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >>
> >
> >> +Order of Properties in Device Node
> >> +----------------------------------
> >> +
> >> +Following order of properties in device nodes is preferred:
> >> +
> >> +1. compatible
> >> +2. reg
> >> +3. ranges
> >> +4. All properties with values
> >> +5. Boolean properties
> >
> > I guess the only thing I do have questions about is the part
> >
> >> +4. All properties with values
> >> +5. Boolean properties
> >
> > Is there a rationale for it? Because with it things like regulator-*
> > properties then end up in two different blocks.
>
> Good point. It is only a matter of style that this:
>
> foo {
> compatible = "foo";
> reg = <0x1>;
> clocks = <&clk>;
> wakeup-source;
> key-autorepeat;
> }
>
> looks better to me than:
>
>
> foo {
> compatible = "foo";
> reg = <0x1>;
> key-autorepeat;
> wakeup-source;
> clocks = <&clk>;
> }
>
> But you have good point that similar properties should be usually
> grouped together.
>
> About which regulator properties are you thinking now? You mean the
> supplies or the provider?
I was thinking about the provider. There are
regulator-min-microvolt = <>;
and friends, but also
regulator-boot-on;
I guess I would just go with
1. compatible
2. reg
3. ranges
4. All other properties
5. status (if applicable)
6. Child nodes
aka grouping the old 4+5 together. The difference is probably minimal
but doesn't create corner cases and you don't need to know if a property
has a value or is boolean when looking for it.
Heiko
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 20:03 ` Heiko Stuebner
@ 2023-11-16 20:23 ` Krzysztof Kozlowski
2023-11-16 20:33 ` Heiko Stuebner
0 siblings, 1 reply; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-16 20:23 UTC (permalink / raw)
To: Heiko Stuebner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
On 16/11/2023 21:03, Heiko Stuebner wrote:
>>> I guess the only thing I do have questions about is the part
>>>
>>>> +4. All properties with values
>>>> +5. Boolean properties
>>>
>>> Is there a rationale for it? Because with it things like regulator-*
>>> properties then end up in two different blocks.
>>
>> Good point. It is only a matter of style that this:
>>
>> foo {
>> compatible = "foo";
>> reg = <0x1>;
>> clocks = <&clk>;
>> wakeup-source;
>> key-autorepeat;
>> }
>>
>> looks better to me than:
>>
>>
>> foo {
>> compatible = "foo";
>> reg = <0x1>;
>> key-autorepeat;
>> wakeup-source;
>> clocks = <&clk>;
>> }
>>
>> But you have good point that similar properties should be usually
>> grouped together.
>>
>> About which regulator properties are you thinking now? You mean the
>> supplies or the provider?
>
> I was thinking about the provider. There are
> regulator-min-microvolt = <>;
> and friends, but also
> regulator-boot-on;
These are in regulator provider nodes and above guideline would keep
logical order:
regulator-name = "vdd_kfc";
regulator-min-microvolt = <800000>;
regulator-max-microvolt = <1500000>;
regulator-always-on;
regulator-boot-on;
regulator-state-mem {
regulator-off-in-suspend;
};
What exactly would be here misordered?
>
>
> I guess I would just go with
>
> 1. compatible
> 2. reg
> 3. ranges
> 4. All other properties
> 5. status (if applicable)
> 6. Child nodes
>
> aka grouping the old 4+5 together. The difference is probably minimal
> but doesn't create corner cases and you don't need to know if a property
> has a value or is boolean when looking for it.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 20:23 ` Krzysztof Kozlowski
@ 2023-11-16 20:33 ` Heiko Stuebner
2023-11-17 14:03 ` Andrew Davis
2023-11-20 7:12 ` Krzysztof Kozlowski
0 siblings, 2 replies; 22+ messages in thread
From: Heiko Stuebner @ 2023-11-16 20:33 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, Krzysztof Kozlowski
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
Am Donnerstag, 16. November 2023, 21:23:20 CET schrieb Krzysztof Kozlowski:
> On 16/11/2023 21:03, Heiko Stuebner wrote:
>
> >>> I guess the only thing I do have questions about is the part
> >>>
> >>>> +4. All properties with values
> >>>> +5. Boolean properties
> >>>
> >>> Is there a rationale for it? Because with it things like regulator-*
> >>> properties then end up in two different blocks.
> >>
> >> Good point. It is only a matter of style that this:
> >>
> >> foo {
> >> compatible = "foo";
> >> reg = <0x1>;
> >> clocks = <&clk>;
> >> wakeup-source;
> >> key-autorepeat;
> >> }
> >>
> >> looks better to me than:
> >>
> >>
> >> foo {
> >> compatible = "foo";
> >> reg = <0x1>;
> >> key-autorepeat;
> >> wakeup-source;
> >> clocks = <&clk>;
> >> }
> >>
> >> But you have good point that similar properties should be usually
> >> grouped together.
> >>
> >> About which regulator properties are you thinking now? You mean the
> >> supplies or the provider?
> >
> > I was thinking about the provider. There are
> > regulator-min-microvolt = <>;
> > and friends, but also
> > regulator-boot-on;
>
> These are in regulator provider nodes and above guideline would keep
> logical order:
>
> regulator-name = "vdd_kfc";
> regulator-min-microvolt = <800000>;
> regulator-max-microvolt = <1500000>;
> regulator-always-on;
> regulator-boot-on;
>
> regulator-state-mem {
> regulator-off-in-suspend;
> };
>
> What exactly would be here misordered?
going with the vcc5v0_host regulator of the rk3588-quartzpro64 and
+1. compatible
+2. reg
+3. ranges
+4. All properties with values
+5. Boolean properties
+6. status (if applicable)
+7. Child nodes
we'd end up with
vcc5v0_host: vcc5v0-host-regulator {
/* 1. */ compatible = "regulator-fixed";
/* 4. */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
pinctrl-names = "default";
pinctrl-0 = <&vcc5v0_host_en>;
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
regulator-name = "vcc5v0_host";
vin-supply = <&vcc5v0_usb>;
/* 5. */ enable-active-high;
regulator-always-on;
regulator-boot-on;
};
which I find somewhat counter-intuitive ;-) .
Heiko
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 18:12 [PATCH] docs: dt-bindings: add DTS Coding Style document Krzysztof Kozlowski
2023-11-16 19:26 ` Heiko Stuebner
@ 2023-11-16 20:44 ` Rob Herring
2023-11-17 23:55 ` Konrad Dybcio
2023-11-20 7:19 ` Krzysztof Kozlowski
2023-11-16 21:27 ` Conor Dooley
` (3 subsequent siblings)
5 siblings, 2 replies; 22+ messages in thread
From: Rob Herring @ 2023-11-16 20:44 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Krzysztof Kozlowski, Conor Dooley, devicetree, linux-kernel,
AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Heiko Stuebner, Konrad Dybcio,
Matthias Brugger, Michal Simek, Neil Armstrong, Nishanth Menon,
Olof Johansson
On Thu, Nov 16, 2023 at 12:12 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> Document preferred coding style for Devicetree sources (DTS and DTSI),
> to bring consistency among all (sub)architectures and ease in reviews.
Thanks for doing this.
>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Michal Simek <michal.simek@amd.com>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Nishanth Menon <nm@ti.com>
> Cc: Olof Johansson <olof@lixom.net>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
>
> Merging idea: Rob/DT bindings
> ---
> Documentation/devicetree/bindings/index.rst | 1 +
> .../devicetree/bindings/writing-dts.rst | 137 ++++++++++++++++++
> 2 files changed, 138 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/writing-dts.rst
Perhaps dts-coding-style.rst
After adding writing-schema, I realized the difference between
writing-schema and writing-bindings isn't all that clear. I never got
around to renaming things.
>
> diff --git a/Documentation/devicetree/bindings/index.rst b/Documentation/devicetree/bindings/index.rst
> index d9002a3a0abb..975449be4862 100644
> --- a/Documentation/devicetree/bindings/index.rst
> +++ b/Documentation/devicetree/bindings/index.rst
> @@ -5,5 +5,6 @@
>
> ABI
> writing-bindings
> + writing-dts
> writing-schema
> submitting-patches
> diff --git a/Documentation/devicetree/bindings/writing-dts.rst b/Documentation/devicetree/bindings/writing-dts.rst
> new file mode 100644
> index 000000000000..10c477ec1eed
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/writing-dts.rst
> @@ -0,0 +1,137 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +.. _writingdts:
> +
> +===================================================
> +Writing Devicetree Sources (DTS) - DTS Coding Style
> +===================================================
> +
> +When writing Devicetree Sources (DTS) please observe below guidelines. They
> +should be considered complementary to any rules expressed already in Devicetree
> +Specification and dtc compiler (including W=1 and W=2 builds).
> +
> +Individual architectures and sub-architectures can add additional rules, making
> +the style stricter.
> +
> +Naming and Valid Characters
> +---------------------------
> +
> +1. Node and property names are allowed to use only:
> +
> + * lowercase characters:: [a-z]
> + * digits:: [0-9]
> + * dash:: -
> +
> +2. Labels are allowed to use only:
> +
> + * lowercase characters:: [a-z]
> + * digits:: [0-9]
> + * underscore:: _
> +
> +3. Unit addresses should use lowercase hex, without leading zeros (padding).
Strictly speaking, the unit-address is whatever a bus defines, but
yes, by default, that is the format.
> +
> +4. Hex values in properties, e.g. "reg", should use lowercase hex. Any address
> + part can be padded with leading zeros.
> +
> +Example::
> +
> + gpi_dma2: dma-controller@800000 {
> + compatible = "qcom,sm8550-gpi-dma", "qcom,sm6350-gpi-dma";
> + reg = <0x0 0x00800000 0x0 0x60000>;
> + }
> +
> +Order of Nodes
> +--------------
> +
> +1. Nodes within any bus, thus using unit addresses for children, shall be
> + ordered incrementally by unit address.
> +
> +2. Nodes without unit addresses should be ordered alpha-numerically.
> +
> +3. When extending nodes in board DTS via &label, the entries should be ordered
> + alpha-numerically.
Or matching the original node definition order?
> +
> +Example::
> +
> + // SoC DTSI
> +
> + \ {
/ {
> + cpus {
> + // ...
> + };
> +
> + psci {
> + // ...
> + };
> +
> + soc@ {
> + dma: dma-controller@10000 {
> + // ...
> + };
> +
> + clk: clock-controller@80000 {
> + // ...
> + };
> + };
> + };
> +
> + // Board DTS
> +
> + &clk {
> + // ...
> + };
> +
> + &dma {
> + // ...
> + };
> +
> +
> +Order of Properties in Device Node
> +----------------------------------
> +
> +Following order of properties in device nodes is preferred:
> +
> +1. compatible
> +2. reg
> +3. ranges
> +4. All properties with values
> +5. Boolean properties
I make this like schemas, standard/common properties first, then
vendor specific properties.
> +6. status (if applicable)
> +7. Child nodes
> +
> +The "status" property is by default "okay", thus it can be omitted.
> +
> +Example::
> +
> + // SoC DTSI
> +
> + usb_1_hsphy: phy@88e3000 {
> + compatible = "qcom,sm8550-snps-eusb2-phy";
> + reg = <0x0 0x088e3000 0x0 0x154>;
> + #phy-cells = <0>;
> + resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>;
> + status = "disabled";
> + };
> +
> + // Board DTS
> +
> + &usb_1_hsphy {
> + clocks = <&tcsr TCSR_USB2_CLKREF_EN>;
> + clock-names = "ref";
> + status = "okay";
> + };
> +
> +
> +Indentation
> +-----------
> +
> +1. Use indentation according to :ref:`codingstyle`.
> +2. For arrays spanning across lines, preferred is to align the continued
> + entries with opening < from first line.
> +
> +Example::
> +
> + thermal-sensor@c271000 {
> + compatible = "qcom,sm8550-tsens", "qcom,tsens-v2";
> + reg = <0x0 0x0c271000 0x0 0x1000>,
> + <0x0 0x0c222000 0x0 0x1000>;
You should cover the <> style too, meaning <> around each logical entry.
> + };
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 18:12 [PATCH] docs: dt-bindings: add DTS Coding Style document Krzysztof Kozlowski
2023-11-16 19:26 ` Heiko Stuebner
2023-11-16 20:44 ` Rob Herring
@ 2023-11-16 21:27 ` Conor Dooley
2023-11-20 7:14 ` Krzysztof Kozlowski
2023-11-16 21:32 ` Geert Uytterhoeven
` (2 subsequent siblings)
5 siblings, 1 reply; 22+ messages in thread
From: Conor Dooley @ 2023-11-16 21:27 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, AngeloGioacchino Del Regno, Arnd Bergmann,
Bjorn Andersson, Geert Uytterhoeven, Heiko Stuebner,
Konrad Dybcio, Matthias Brugger, Michal Simek, Neil Armstrong,
Nishanth Menon, Olof Johansson
[-- Attachment #1: Type: text/plain, Size: 5568 bytes --]
On Thu, Nov 16, 2023 at 07:12:18PM +0100, Krzysztof Kozlowski wrote:
> Document preferred coding style for Devicetree sources (DTS and DTSI),
> to bring consistency among all (sub)architectures and ease in reviews.
This is a good idea IMO, thanks for writing it.
Should we also mention in this about the expected breakdown of things
between $soc.dtsi and $soc-$board.dtsi? There's commonly confusion about
things like oscillators and where they belong - particularly when the
SoC mandates that these oscillators be of a single frequency.
It may seem obvious to us what goes where, but certainly contributors
frequently get this wrong.
Cheers,
Conor.
>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Michal Simek <michal.simek@amd.com>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Nishanth Menon <nm@ti.com>
> Cc: Olof Johansson <olof@lixom.net>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
>
> Merging idea: Rob/DT bindings
> ---
> Documentation/devicetree/bindings/index.rst | 1 +
> .../devicetree/bindings/writing-dts.rst | 137 ++++++++++++++++++
> 2 files changed, 138 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/writing-dts.rst
>
> diff --git a/Documentation/devicetree/bindings/index.rst b/Documentation/devicetree/bindings/index.rst
> index d9002a3a0abb..975449be4862 100644
> --- a/Documentation/devicetree/bindings/index.rst
> +++ b/Documentation/devicetree/bindings/index.rst
> @@ -5,5 +5,6 @@
>
> ABI
> writing-bindings
> + writing-dts
> writing-schema
> submitting-patches
> diff --git a/Documentation/devicetree/bindings/writing-dts.rst b/Documentation/devicetree/bindings/writing-dts.rst
> new file mode 100644
> index 000000000000..10c477ec1eed
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/writing-dts.rst
> @@ -0,0 +1,137 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +.. _writingdts:
> +
> +===================================================
> +Writing Devicetree Sources (DTS) - DTS Coding Style
> +===================================================
> +
> +When writing Devicetree Sources (DTS) please observe below guidelines. They
> +should be considered complementary to any rules expressed already in Devicetree
> +Specification and dtc compiler (including W=1 and W=2 builds).
> +
> +Individual architectures and sub-architectures can add additional rules, making
> +the style stricter.
> +
> +Naming and Valid Characters
> +---------------------------
> +
> +1. Node and property names are allowed to use only:
> +
> + * lowercase characters:: [a-z]
> + * digits:: [0-9]
> + * dash:: -
> +
> +2. Labels are allowed to use only:
> +
> + * lowercase characters:: [a-z]
> + * digits:: [0-9]
> + * underscore:: _
> +
> +3. Unit addresses should use lowercase hex, without leading zeros (padding).
> +
> +4. Hex values in properties, e.g. "reg", should use lowercase hex. Any address
> + part can be padded with leading zeros.
> +
> +Example::
> +
> + gpi_dma2: dma-controller@800000 {
> + compatible = "qcom,sm8550-gpi-dma", "qcom,sm6350-gpi-dma";
> + reg = <0x0 0x00800000 0x0 0x60000>;
> + }
> +
> +Order of Nodes
> +--------------
> +
> +1. Nodes within any bus, thus using unit addresses for children, shall be
> + ordered incrementally by unit address.
> +
> +2. Nodes without unit addresses should be ordered alpha-numerically.
> +
> +3. When extending nodes in board DTS via &label, the entries should be ordered
> + alpha-numerically.
> +
> +Example::
> +
> + // SoC DTSI
> +
> + \ {
> + cpus {
> + // ...
> + };
> +
> + psci {
> + // ...
> + };
> +
> + soc@ {
> + dma: dma-controller@10000 {
> + // ...
> + };
> +
> + clk: clock-controller@80000 {
> + // ...
> + };
> + };
> + };
> +
> + // Board DTS
> +
> + &clk {
> + // ...
> + };
> +
> + &dma {
> + // ...
> + };
> +
> +
> +Order of Properties in Device Node
> +----------------------------------
> +
> +Following order of properties in device nodes is preferred:
> +
> +1. compatible
> +2. reg
> +3. ranges
> +4. All properties with values
> +5. Boolean properties
> +6. status (if applicable)
> +7. Child nodes
> +
> +The "status" property is by default "okay", thus it can be omitted.
> +
> +Example::
> +
> + // SoC DTSI
> +
> + usb_1_hsphy: phy@88e3000 {
> + compatible = "qcom,sm8550-snps-eusb2-phy";
> + reg = <0x0 0x088e3000 0x0 0x154>;
> + #phy-cells = <0>;
> + resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>;
> + status = "disabled";
> + };
> +
> + // Board DTS
> +
> + &usb_1_hsphy {
> + clocks = <&tcsr TCSR_USB2_CLKREF_EN>;
> + clock-names = "ref";
> + status = "okay";
> + };
> +
> +
> +Indentation
> +-----------
> +
> +1. Use indentation according to :ref:`codingstyle`.
> +2. For arrays spanning across lines, preferred is to align the continued
> + entries with opening < from first line.
> +
> +Example::
> +
> + thermal-sensor@c271000 {
> + compatible = "qcom,sm8550-tsens", "qcom,tsens-v2";
> + reg = <0x0 0x0c271000 0x0 0x1000>,
> + <0x0 0x0c222000 0x0 0x1000>;
> + };
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 18:12 [PATCH] docs: dt-bindings: add DTS Coding Style document Krzysztof Kozlowski
` (2 preceding siblings ...)
2023-11-16 21:27 ` Conor Dooley
@ 2023-11-16 21:32 ` Geert Uytterhoeven
2023-11-20 7:16 ` Krzysztof Kozlowski
2023-11-17 23:53 ` Konrad Dybcio
2023-11-17 23:58 ` Konrad Dybcio
5 siblings, 1 reply; 22+ messages in thread
From: Geert Uytterhoeven @ 2023-11-16 21:32 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, AngeloGioacchino Del Regno, Arnd Bergmann,
Bjorn Andersson, Heiko Stuebner, Konrad Dybcio, Matthias Brugger,
Michal Simek, Neil Armstrong, Nishanth Menon, Olof Johansson
Hi Krzysztof,
On Thu, Nov 16, 2023 at 7:12 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote>
> Document preferred coding style for Devicetree sources (DTS and DTSI),
> to bring consistency among all (sub)architectures and ease in reviews.
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Thanks for your patch!
> --- a/Documentation/devicetree/bindings/index.rst
> +++ b/Documentation/devicetree/bindings/index.rst
> +Order of Nodes
> +--------------
> +
> +1. Nodes within any bus, thus using unit addresses for children, shall be
> + ordered incrementally by unit address.
In Renesas DTS files, we have an (unwritten) additional rule: when there
are multiple nodes of the same type, they do not follow the global
ordering by unit-address, but are grouped together.
E.g. the second and any subsequent serial ports are always listed
immediately after the first serial port.
> +2. Nodes without unit addresses should be ordered alpha-numerically.
> +
> +3. When extending nodes in board DTS via &label, the entries should be ordered
> + alpha-numerically.
> +Order of Properties in Device Node
> +----------------------------------
> +
> +Following order of properties in device nodes is preferred:
> +
> +1. compatible
> +2. reg
> +3. ranges
> +4. All properties with values
> +5. Boolean properties
> +6. status (if applicable)
There must be a lank line between properties and child nodes?
And once we have a documented coding style, the next long-standing item
from our wishlist would be a script to sort the contents of a DTS file
according to the rules ;-)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 20:33 ` Heiko Stuebner
@ 2023-11-17 14:03 ` Andrew Davis
2023-11-17 19:38 ` Heiko Stübner
2023-11-20 7:12 ` Krzysztof Kozlowski
1 sibling, 1 reply; 22+ messages in thread
From: Andrew Davis @ 2023-11-17 14:03 UTC (permalink / raw)
To: Heiko Stuebner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel, Krzysztof Kozlowski
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
On 11/16/23 2:33 PM, Heiko Stuebner wrote:
> Am Donnerstag, 16. November 2023, 21:23:20 CET schrieb Krzysztof Kozlowski:
>> On 16/11/2023 21:03, Heiko Stuebner wrote:
>>
>>>>> I guess the only thing I do have questions about is the part
>>>>>
>>>>>> +4. All properties with values
>>>>>> +5. Boolean properties
>>>>>
>>>>> Is there a rationale for it? Because with it things like regulator-*
>>>>> properties then end up in two different blocks.
>>>>
>>>> Good point. It is only a matter of style that this:
>>>>
>>>> foo {
>>>> compatible = "foo";
>>>> reg = <0x1>;
>>>> clocks = <&clk>;
>>>> wakeup-source;
>>>> key-autorepeat;
>>>> }
>>>>
>>>> looks better to me than:
>>>>
>>>>
>>>> foo {
>>>> compatible = "foo";
>>>> reg = <0x1>;
>>>> key-autorepeat;
>>>> wakeup-source;
>>>> clocks = <&clk>;
>>>> }
>>>>
>>>> But you have good point that similar properties should be usually
>>>> grouped together.
>>>>
>>>> About which regulator properties are you thinking now? You mean the
>>>> supplies or the provider?
>>>
>>> I was thinking about the provider. There are
>>> regulator-min-microvolt = <>;
>>> and friends, but also
>>> regulator-boot-on;
>>
>> These are in regulator provider nodes and above guideline would keep
>> logical order:
>>
>> regulator-name = "vdd_kfc";
>> regulator-min-microvolt = <800000>;
>> regulator-max-microvolt = <1500000>;
>> regulator-always-on;
>> regulator-boot-on;
>>
>> regulator-state-mem {
>> regulator-off-in-suspend;
>> };
>>
>> What exactly would be here misordered?
>
> going with the vcc5v0_host regulator of the rk3588-quartzpro64 and
>
> +1. compatible
> +2. reg
> +3. ranges
> +4. All properties with values
> +5. Boolean properties
> +6. status (if applicable)
> +7. Child nodes
>
> we'd end up with
>
> vcc5v0_host: vcc5v0-host-regulator {
> /* 1. */ compatible = "regulator-fixed";
> /* 4. */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> pinctrl-names = "default";
> pinctrl-0 = <&vcc5v0_host_en>;
> regulator-min-microvolt = <5000000>;
> regulator-max-microvolt = <5000000>;
> regulator-name = "vcc5v0_host";
> vin-supply = <&vcc5v0_usb>;
> /* 5. */ enable-active-high;
> regulator-always-on;
> regulator-boot-on;
> };
>
How about grouping like properties (defined in the same schema),
then sorting within that group. Would also allow for defining
where to add spacing.
1. compatible
2. reg
3. ranges
4. All property groups
4.1 Properties with values
4.2 Boolean properties
4.3 Separating space
6. status (if applicable)
7. Child nodes
Your node then would look like we expect:
vcc5v0_host: vcc5v0-host-regulator {
/* 1 */ compatible = "regulator-fixed";
/* 4.1 */ pinctrl-names = "default";
/* 4.1 */ pinctrl-0 = <&vcc5v0_host_en>;
/* 4.3 */
/* 4.1 */ regulator-min-microvolt = <5000000>;
/* 4.1 */ regulator-max-microvolt = <5000000>;
/* 4.1 */ regulator-name = "vcc5v0_host";
/* 4.2 */ regulator-always-on;
/* 4.2 */ regulator-boot-on;
/* 4.2 */ enable-active-high;
/* 4.3 */
/* 4.1 */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
...
};
Andrew
> which I find somewhat counter-intuitive ;-) .
>
>
> Heiko
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-17 14:03 ` Andrew Davis
@ 2023-11-17 19:38 ` Heiko Stübner
2023-11-17 19:54 ` Andrew Davis
2023-11-18 11:25 ` Geert Uytterhoeven
0 siblings, 2 replies; 22+ messages in thread
From: Heiko Stübner @ 2023-11-17 19:38 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, Krzysztof Kozlowski, Andrew Davis
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
Am Freitag, 17. November 2023, 15:03:38 CET schrieb Andrew Davis:
> On 11/16/23 2:33 PM, Heiko Stuebner wrote:
> > Am Donnerstag, 16. November 2023, 21:23:20 CET schrieb Krzysztof Kozlowski:
> >> On 16/11/2023 21:03, Heiko Stuebner wrote:
> > going with the vcc5v0_host regulator of the rk3588-quartzpro64 and
> >
> > +1. compatible
> > +2. reg
> > +3. ranges
> > +4. All properties with values
> > +5. Boolean properties
> > +6. status (if applicable)
> > +7. Child nodes
> >
> > we'd end up with
> >
> > vcc5v0_host: vcc5v0-host-regulator {
> > /* 1. */ compatible = "regulator-fixed";
> > /* 4. */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> > pinctrl-names = "default";
> > pinctrl-0 = <&vcc5v0_host_en>;
> > regulator-min-microvolt = <5000000>;
> > regulator-max-microvolt = <5000000>;
> > regulator-name = "vcc5v0_host";
> > vin-supply = <&vcc5v0_usb>;
> > /* 5. */ enable-active-high;
> > regulator-always-on;
> > regulator-boot-on;
> > };
> >
>
> How about grouping like properties (defined in the same schema),
> then sorting within that group. Would also allow for defining
> where to add spacing.
>
> 1. compatible
> 2. reg
> 3. ranges
> 4. All property groups
> 4.1 Properties with values
> 4.2 Boolean properties
> 4.3 Separating space
> 6. status (if applicable)
> 7. Child nodes
>
> Your node then would look like we expect:
>
> vcc5v0_host: vcc5v0-host-regulator {
> /* 1 */ compatible = "regulator-fixed";
>
> /* 4.1 */ pinctrl-names = "default";
> /* 4.1 */ pinctrl-0 = <&vcc5v0_host_en>;
> /* 4.3 */
> /* 4.1 */ regulator-min-microvolt = <5000000>;
> /* 4.1 */ regulator-max-microvolt = <5000000>;
> /* 4.1 */ regulator-name = "vcc5v0_host";
> /* 4.2 */ regulator-always-on;
> /* 4.2 */ regulator-boot-on;
> /* 4.2 */ enable-active-high;
> /* 4.3 */
> /* 4.1 */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> ...
> };
I'm really not sure about adding big sets of rules.
In the above example you'd also need to define which schema has a higher
priority? ;-)
When I started with Rockchip stuff, I also had some fancy way of sorting
elements in mind that was really intuitive to myself :-) .
Over time I realized that it was quite complex - especially when I had to
explain it to people.
There are definite advantages for having compatible + reg + status in
fixed positions, as it helps going over a whole dt to spot the huge
mistakes (accidentially disabled, wrong address), but for the rest a
simple alphabetical sorting is easiest to explain to people :-) .
And alphabetic elements are also easier on my eyes.
I just think having a short clean set of rules like Krzysztof proposed,
is easier to follow and "enforce" and also most likely doesn't deter
people from contributing, if mainline work is not their main occupation.
Heiko
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-17 19:38 ` Heiko Stübner
@ 2023-11-17 19:54 ` Andrew Davis
2023-11-17 20:04 ` Heiko Stübner
2023-11-18 11:25 ` Geert Uytterhoeven
1 sibling, 1 reply; 22+ messages in thread
From: Andrew Davis @ 2023-11-17 19:54 UTC (permalink / raw)
To: Heiko Stübner, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, devicetree, linux-kernel, Krzysztof Kozlowski
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
On 11/17/23 1:38 PM, Heiko Stübner wrote:
> Am Freitag, 17. November 2023, 15:03:38 CET schrieb Andrew Davis:
>> On 11/16/23 2:33 PM, Heiko Stuebner wrote:
>>> Am Donnerstag, 16. November 2023, 21:23:20 CET schrieb Krzysztof Kozlowski:
>>>> On 16/11/2023 21:03, Heiko Stuebner wrote:
>>> going with the vcc5v0_host regulator of the rk3588-quartzpro64 and
>>>
>>> +1. compatible
>>> +2. reg
>>> +3. ranges
>>> +4. All properties with values
>>> +5. Boolean properties
>>> +6. status (if applicable)
>>> +7. Child nodes
>>>
>>> we'd end up with
>>>
>>> vcc5v0_host: vcc5v0-host-regulator {
>>> /* 1. */ compatible = "regulator-fixed";
>>> /* 4. */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
>>> pinctrl-names = "default";
>>> pinctrl-0 = <&vcc5v0_host_en>;
>>> regulator-min-microvolt = <5000000>;
>>> regulator-max-microvolt = <5000000>;
>>> regulator-name = "vcc5v0_host";
>>> vin-supply = <&vcc5v0_usb>;
>>> /* 5. */ enable-active-high;
>>> regulator-always-on;
>>> regulator-boot-on;
>>> };
>>>
>>
>> How about grouping like properties (defined in the same schema),
>> then sorting within that group. Would also allow for defining
>> where to add spacing.
>>
>> 1. compatible
>> 2. reg
>> 3. ranges
>> 4. All property groups
>> 4.1 Properties with values
>> 4.2 Boolean properties
>> 4.3 Separating space
>> 6. status (if applicable)
>> 7. Child nodes
>>
>> Your node then would look like we expect:
>>
>> vcc5v0_host: vcc5v0-host-regulator {
>> /* 1 */ compatible = "regulator-fixed";
>>
>> /* 4.1 */ pinctrl-names = "default";
>> /* 4.1 */ pinctrl-0 = <&vcc5v0_host_en>;
>> /* 4.3 */
>> /* 4.1 */ regulator-min-microvolt = <5000000>;
>> /* 4.1 */ regulator-max-microvolt = <5000000>;
>> /* 4.1 */ regulator-name = "vcc5v0_host";
>> /* 4.2 */ regulator-always-on;
>> /* 4.2 */ regulator-boot-on;
>> /* 4.2 */ enable-active-high;
>> /* 4.3 */
>> /* 4.1 */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
>> ...
>> };
>
> I'm really not sure about adding big sets of rules.
> In the above example you'd also need to define which schema has a higher
> priority? ;-)
>
>
> When I started with Rockchip stuff, I also had some fancy way of sorting
> elements in mind that was really intuitive to myself :-) .
> Over time I realized that it was quite complex - especially when I had to
> explain it to people.
>
> There are definite advantages for having compatible + reg + status in
> fixed positions, as it helps going over a whole dt to spot the huge
> mistakes (accidentially disabled, wrong address), but for the rest a
> simple alphabetical sorting is easiest to explain to people :-) .
>
> And alphabetic elements are also easier on my eyes.
>
+1 for starting with compatible/reg/status that we would like to see
in the same spot in each node.
Not so sure on plain alphabetical. That has the same issue you pointed out
with splitting value vs boolean properties, related properties would end up
not grouped. Some like regulator- with the same prefix will, but think -gpios
that is a postfix, they would be scattered about.
How about just enforcing ordering on the couple common property we care about
seeing and everything else left free-hand as it today?
Andrew
>
> I just think having a short clean set of rules like Krzysztof proposed,
> is easier to follow and "enforce" and also most likely doesn't deter
> people from contributing, if mainline work is not their main occupation.
>
>
> Heiko
>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-17 19:54 ` Andrew Davis
@ 2023-11-17 20:04 ` Heiko Stübner
0 siblings, 0 replies; 22+ messages in thread
From: Heiko Stübner @ 2023-11-17 20:04 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, Krzysztof Kozlowski, Andrew Davis
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
Am Freitag, 17. November 2023, 20:54:05 CET schrieb Andrew Davis:
> On 11/17/23 1:38 PM, Heiko Stübner wrote:
> > Am Freitag, 17. November 2023, 15:03:38 CET schrieb Andrew Davis:
> >> On 11/16/23 2:33 PM, Heiko Stuebner wrote:
> >>> Am Donnerstag, 16. November 2023, 21:23:20 CET schrieb Krzysztof Kozlowski:
> >>>> On 16/11/2023 21:03, Heiko Stuebner wrote:
> >>> going with the vcc5v0_host regulator of the rk3588-quartzpro64 and
> >>>
> >>> +1. compatible
> >>> +2. reg
> >>> +3. ranges
> >>> +4. All properties with values
> >>> +5. Boolean properties
> >>> +6. status (if applicable)
> >>> +7. Child nodes
> >>>
> >>> we'd end up with
> >>>
> >>> vcc5v0_host: vcc5v0-host-regulator {
> >>> /* 1. */ compatible = "regulator-fixed";
> >>> /* 4. */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> >>> pinctrl-names = "default";
> >>> pinctrl-0 = <&vcc5v0_host_en>;
> >>> regulator-min-microvolt = <5000000>;
> >>> regulator-max-microvolt = <5000000>;
> >>> regulator-name = "vcc5v0_host";
> >>> vin-supply = <&vcc5v0_usb>;
> >>> /* 5. */ enable-active-high;
> >>> regulator-always-on;
> >>> regulator-boot-on;
> >>> };
> >>>
> >>
> >> How about grouping like properties (defined in the same schema),
> >> then sorting within that group. Would also allow for defining
> >> where to add spacing.
> >>
> >> 1. compatible
> >> 2. reg
> >> 3. ranges
> >> 4. All property groups
> >> 4.1 Properties with values
> >> 4.2 Boolean properties
> >> 4.3 Separating space
> >> 6. status (if applicable)
> >> 7. Child nodes
> >>
> >> Your node then would look like we expect:
> >>
> >> vcc5v0_host: vcc5v0-host-regulator {
> >> /* 1 */ compatible = "regulator-fixed";
> >>
> >> /* 4.1 */ pinctrl-names = "default";
> >> /* 4.1 */ pinctrl-0 = <&vcc5v0_host_en>;
> >> /* 4.3 */
> >> /* 4.1 */ regulator-min-microvolt = <5000000>;
> >> /* 4.1 */ regulator-max-microvolt = <5000000>;
> >> /* 4.1 */ regulator-name = "vcc5v0_host";
> >> /* 4.2 */ regulator-always-on;
> >> /* 4.2 */ regulator-boot-on;
> >> /* 4.2 */ enable-active-high;
> >> /* 4.3 */
> >> /* 4.1 */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> >> ...
> >> };
> >
> > I'm really not sure about adding big sets of rules.
> > In the above example you'd also need to define which schema has a higher
> > priority? ;-)
> >
> >
> > When I started with Rockchip stuff, I also had some fancy way of sorting
> > elements in mind that was really intuitive to myself :-) .
> > Over time I realized that it was quite complex - especially when I had to
> > explain it to people.
> >
> > There are definite advantages for having compatible + reg + status in
> > fixed positions, as it helps going over a whole dt to spot the huge
> > mistakes (accidentially disabled, wrong address), but for the rest a
> > simple alphabetical sorting is easiest to explain to people :-) .
> >
> > And alphabetic elements are also easier on my eyes.
> >
>
> +1 for starting with compatible/reg/status that we would like to see
> in the same spot in each node.
>
> Not so sure on plain alphabetical. That has the same issue you pointed out
> with splitting value vs boolean properties, related properties would end up
> not grouped. Some like regulator- with the same prefix will, but think -gpios
> that is a postfix, they would be scattered about.
>
> How about just enforcing ordering on the couple common property we care about
> seeing and everything else left free-hand as it today?
Sounds like a very sensible idea :-) .
Especially as the sorting of individual properties is just a tiny part of
Krzysztof's document, and all the other parts in it are way more
important anyway.
Heiko
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 18:12 [PATCH] docs: dt-bindings: add DTS Coding Style document Krzysztof Kozlowski
` (3 preceding siblings ...)
2023-11-16 21:32 ` Geert Uytterhoeven
@ 2023-11-17 23:53 ` Konrad Dybcio
2023-11-20 7:15 ` Krzysztof Kozlowski
2023-11-17 23:58 ` Konrad Dybcio
5 siblings, 1 reply; 22+ messages in thread
From: Konrad Dybcio @ 2023-11-17 23:53 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, devicetree, linux-kernel
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Heiko Stuebner, Matthias Brugger,
Michal Simek, Neil Armstrong, Nishanth Menon, Olof Johansson
On 16.11.2023 19:12, Krzysztof Kozlowski wrote:
> Document preferred coding style for Devicetree sources (DTS and DTSI),
> to bring consistency among all (sub)architectures and ease in reviews.
>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Michal Simek <michal.simek@amd.com>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Nishanth Menon <nm@ti.com>
> Cc: Olof Johansson <olof@lixom.net>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
[...]
> +Order of Nodes
> +--------------
> +
> +1. Nodes within any bus, thus using unit addresses for children, shall be
> + ordered incrementally by unit address.
> +
> +2. Nodes without unit addresses should be ordered alpha-numerically.
I largely agree with all this given our fight for some level of
tidyness across linux-msm, but there's one specific case where I think
it would make sense to break this ordering, and that's GPIO states:
&pinctrl {
xyz-active-state {
pins ="gpio0";
...
};
abc-active-state {
pins ="gpio1";
...
};
qwe-active-state {
pins ="gpio2";
...
};
};
looks so much more readable to me than
&pinctrl {
abc-active-state {
pins ="gpio1";
...
};
qwe-active-state {
pins ="gpio2";
...
};
xyz-active-state {
pins ="gpio0";
...
};
};
Konrad
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 20:44 ` Rob Herring
@ 2023-11-17 23:55 ` Konrad Dybcio
2023-11-20 7:19 ` Krzysztof Kozlowski
1 sibling, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2023-11-17 23:55 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski
Cc: Krzysztof Kozlowski, Conor Dooley, devicetree, linux-kernel,
AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Heiko Stuebner, Matthias Brugger,
Michal Simek, Neil Armstrong, Nishanth Menon, Olof Johansson
On 16.11.2023 21:44, Rob Herring wrote:
> On Thu, Nov 16, 2023 at 12:12 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>>
>> Document preferred coding style for Devicetree sources (DTS and DTSI),
>> to bring consistency among all (sub)architectures and ease in reviews.
>
> Thanks for doing this.
>
>>
>> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> Cc: Arnd Bergmann <arnd@arndb.de>
>> Cc: Bjorn Andersson <andersson@kernel.org>
>> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
>> Cc: Heiko Stuebner <heiko@sntech.de>
>> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
>> Cc: Matthias Brugger <matthias.bgg@gmail.com>
>> Cc: Michal Simek <michal.simek@amd.com>
>> Cc: Neil Armstrong <neil.armstrong@linaro.org>
>> Cc: Nishanth Menon <nm@ti.com>
>> Cc: Olof Johansson <olof@lixom.net>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>
>> ---
[...]
>> +Example::
>> +
>> + thermal-sensor@c271000 {
>> + compatible = "qcom,sm8550-tsens", "qcom,tsens-v2";
>> + reg = <0x0 0x0c271000 0x0 0x1000>,
>> + <0x0 0x0c222000 0x0 0x1000>;
>
> You should cover the <> style too, meaning <> around each logical entry.
FWIW this matters because e.g.
https://github.com/devicetree-org/devicetree-specification/issues/66
Konrad
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 18:12 [PATCH] docs: dt-bindings: add DTS Coding Style document Krzysztof Kozlowski
` (4 preceding siblings ...)
2023-11-17 23:53 ` Konrad Dybcio
@ 2023-11-17 23:58 ` Konrad Dybcio
5 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2023-11-17 23:58 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, devicetree, linux-kernel
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Heiko Stuebner, Matthias Brugger,
Michal Simek, Neil Armstrong, Nishanth Menon, Olof Johansson
On 16.11.2023 19:12, Krzysztof Kozlowski wrote:
> Document preferred coding style for Devicetree sources (DTS and DTSI),
> to bring consistency among all (sub)architectures and ease in reviews.
>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Michal Simek <michal.simek@amd.com>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Nishanth Menon <nm@ti.com>
> Cc: Olof Johansson <olof@lixom.net>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
Another thing that was suggested by at least one person to me is that
with a formalized ordering system in place AND using dt-bindings,
devicetrees could largely be reduced to a set of structs thrown into
some sort of an ASLC-alike (meaning: you fill out structs with the
necessary data, like reg, name etc. and the computer infers the rest
and creates a nice & stylish output for you).
Konrad
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-17 19:38 ` Heiko Stübner
2023-11-17 19:54 ` Andrew Davis
@ 2023-11-18 11:25 ` Geert Uytterhoeven
1 sibling, 0 replies; 22+ messages in thread
From: Geert Uytterhoeven @ 2023-11-18 11:25 UTC (permalink / raw)
To: Heiko Stübner
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, Krzysztof Kozlowski, Andrew Davis,
AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
Hi Heiko,
On Fri, Nov 17, 2023 at 8:38 PM Heiko Stübner <heiko@sntech.de> wrote:
> Am Freitag, 17. November 2023, 15:03:38 CET schrieb Andrew Davis:
> > On 11/16/23 2:33 PM, Heiko Stuebner wrote:
> > > Am Donnerstag, 16. November 2023, 21:23:20 CET schrieb Krzysztof Kozlowski:
> > >> On 16/11/2023 21:03, Heiko Stuebner wrote:
> > > going with the vcc5v0_host regulator of the rk3588-quartzpro64 and
> > >
> > > +1. compatible
> > > +2. reg
> > > +3. ranges
> > > +4. All properties with values
> > > +5. Boolean properties
> > > +6. status (if applicable)
> > > +7. Child nodes
> > >
> > > we'd end up with
> > >
> > > vcc5v0_host: vcc5v0-host-regulator {
> > > /* 1. */ compatible = "regulator-fixed";
> > > /* 4. */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> > > pinctrl-names = "default";
> > > pinctrl-0 = <&vcc5v0_host_en>;
> > > regulator-min-microvolt = <5000000>;
> > > regulator-max-microvolt = <5000000>;
> > > regulator-name = "vcc5v0_host";
> > > vin-supply = <&vcc5v0_usb>;
> > > /* 5. */ enable-active-high;
> > > regulator-always-on;
> > > regulator-boot-on;
> > > };
> > >
> >
> > How about grouping like properties (defined in the same schema),
> > then sorting within that group. Would also allow for defining
> > where to add spacing.
> >
> > 1. compatible
> > 2. reg
> > 3. ranges
> > 4. All property groups
> > 4.1 Properties with values
> > 4.2 Boolean properties
> > 4.3 Separating space
> > 6. status (if applicable)
> > 7. Child nodes
> >
> > Your node then would look like we expect:
> >
> > vcc5v0_host: vcc5v0-host-regulator {
> > /* 1 */ compatible = "regulator-fixed";
> >
> > /* 4.1 */ pinctrl-names = "default";
> > /* 4.1 */ pinctrl-0 = <&vcc5v0_host_en>;
> > /* 4.3 */
> > /* 4.1 */ regulator-min-microvolt = <5000000>;
> > /* 4.1 */ regulator-max-microvolt = <5000000>;
> > /* 4.1 */ regulator-name = "vcc5v0_host";
> > /* 4.2 */ regulator-always-on;
> > /* 4.2 */ regulator-boot-on;
> > /* 4.2 */ enable-active-high;
> > /* 4.3 */
> > /* 4.1 */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> > ...
> > };
>
> I'm really not sure about adding big sets of rules.
> In the above example you'd also need to define which schema has a higher
> priority? ;-)
>
>
> When I started with Rockchip stuff, I also had some fancy way of sorting
> elements in mind that was really intuitive to myself :-) .
> Over time I realized that it was quite complex - especially when I had to
> explain it to people.
Feel familiar.
> There are definite advantages for having compatible + reg + status in
> fixed positions, as it helps going over a whole dt to spot the huge
> mistakes (accidentially disabled, wrong address), but for the rest a
> simple alphabetical sorting is easiest to explain to people :-) .
>
> And alphabetic elements are also easier on my eyes.
Alphabetical does break logical ordering and grouping.
Apart from compatible/reg order, on Renesas SoCs we usually
also have the clocks/resets/power-domains block.
> I just think having a short clean set of rules like Krzysztof proposed,
> is easier to follow and "enforce" and also most likely doesn't deter
> people from contributing, if mainline work is not their main occupation.
And in reality, most of this is created by copy-and-corrupt^Wmodify...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 20:33 ` Heiko Stuebner
2023-11-17 14:03 ` Andrew Davis
@ 2023-11-20 7:12 ` Krzysztof Kozlowski
1 sibling, 0 replies; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-20 7:12 UTC (permalink / raw)
To: Heiko Stuebner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Konrad Dybcio, Matthias Brugger, Michal Simek,
Neil Armstrong, Nishanth Menon, Olof Johansson
On 16/11/2023 21:33, Heiko Stuebner wrote:
>> regulator-state-mem {
>> regulator-off-in-suspend;
>> };
>>
>> What exactly would be here misordered?
>
> going with the vcc5v0_host regulator of the rk3588-quartzpro64 and
>
> +1. compatible
> +2. reg
> +3. ranges
> +4. All properties with values
> +5. Boolean properties
> +6. status (if applicable)
> +7. Child nodes
>
> we'd end up with
>
> vcc5v0_host: vcc5v0-host-regulator {
> /* 1. */ compatible = "regulator-fixed";
> /* 4. */ gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
> pinctrl-names = "default";
> pinctrl-0 = <&vcc5v0_host_en>;
> regulator-min-microvolt = <5000000>;
> regulator-max-microvolt = <5000000>;
> regulator-name = "vcc5v0_host";
> vin-supply = <&vcc5v0_usb>;
> /* 5. */ enable-active-high;
> regulator-always-on;
> regulator-boot-on;
> };
>
> which I find somewhat counter-intuitive ;-) .
Yes, good point.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 21:27 ` Conor Dooley
@ 2023-11-20 7:14 ` Krzysztof Kozlowski
0 siblings, 0 replies; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-20 7:14 UTC (permalink / raw)
To: Conor Dooley
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, AngeloGioacchino Del Regno, Arnd Bergmann,
Bjorn Andersson, Geert Uytterhoeven, Heiko Stuebner,
Konrad Dybcio, Matthias Brugger, Michal Simek, Neil Armstrong,
Nishanth Menon, Olof Johansson
On 16/11/2023 22:27, Conor Dooley wrote:
> On Thu, Nov 16, 2023 at 07:12:18PM +0100, Krzysztof Kozlowski wrote:
>> Document preferred coding style for Devicetree sources (DTS and DTSI),
>> to bring consistency among all (sub)architectures and ease in reviews.
>
> This is a good idea IMO, thanks for writing it.
>
> Should we also mention in this about the expected breakdown of things
> between $soc.dtsi and $soc-$board.dtsi? There's commonly confusion about
> things like oscillators and where they belong - particularly when the
> SoC mandates that these oscillators be of a single frequency.
> It may seem obvious to us what goes where, but certainly contributors
> frequently get this wrong.
Sure, I can add a chapter about DTS/DTSI split.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-17 23:53 ` Konrad Dybcio
@ 2023-11-20 7:15 ` Krzysztof Kozlowski
0 siblings, 0 replies; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-20 7:15 UTC (permalink / raw)
To: Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
devicetree, linux-kernel
Cc: AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Heiko Stuebner, Matthias Brugger,
Michal Simek, Neil Armstrong, Nishanth Menon, Olof Johansson
On 18/11/2023 00:53, Konrad Dybcio wrote:
> On 16.11.2023 19:12, Krzysztof Kozlowski wrote:
>> Document preferred coding style for Devicetree sources (DTS and DTSI),
>> to bring consistency among all (sub)architectures and ease in reviews.
>>
>> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> Cc: Arnd Bergmann <arnd@arndb.de>
>> Cc: Bjorn Andersson <andersson@kernel.org>
>> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
>> Cc: Heiko Stuebner <heiko@sntech.de>
>> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
>> Cc: Matthias Brugger <matthias.bgg@gmail.com>
>> Cc: Michal Simek <michal.simek@amd.com>
>> Cc: Neil Armstrong <neil.armstrong@linaro.org>
>> Cc: Nishanth Menon <nm@ti.com>
>> Cc: Olof Johansson <olof@lixom.net>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>
>> ---
> [...]
>
>> +Order of Nodes
>> +--------------
>> +
>> +1. Nodes within any bus, thus using unit addresses for children, shall be
>> + ordered incrementally by unit address.
>> +
>> +2. Nodes without unit addresses should be ordered alpha-numerically.
> I largely agree with all this given our fight for some level of
> tidyness across linux-msm, but there's one specific case where I think
> it would make sense to break this ordering, and that's GPIO states:
>
>
> &pinctrl {
> xyz-active-state {
> pins ="gpio0";
> ...
> };
>
> abc-active-state {
> pins ="gpio1";
> ...
> };
>
> qwe-active-state {
> pins ="gpio2";
> ...
> };
> };
>
> looks so much more readable to me than
True. I'll mention exception for this and Renesas.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 21:32 ` Geert Uytterhoeven
@ 2023-11-20 7:16 ` Krzysztof Kozlowski
0 siblings, 0 replies; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-20 7:16 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
linux-kernel, AngeloGioacchino Del Regno, Arnd Bergmann,
Bjorn Andersson, Heiko Stuebner, Konrad Dybcio, Matthias Brugger,
Michal Simek, Neil Armstrong, Nishanth Menon, Olof Johansson
On 16/11/2023 22:32, Geert Uytterhoeven wrote:
> Hi Krzysztof,
>
> On Thu, Nov 16, 2023 at 7:12 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote>
>> Document preferred coding style for Devicetree sources (DTS and DTSI),
>> to bring consistency among all (sub)architectures and ease in reviews.
>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> Thanks for your patch!
>
>> --- a/Documentation/devicetree/bindings/index.rst
>> +++ b/Documentation/devicetree/bindings/index.rst
>
>> +Order of Nodes
>> +--------------
>> +
>> +1. Nodes within any bus, thus using unit addresses for children, shall be
>> + ordered incrementally by unit address.
>
> In Renesas DTS files, we have an (unwritten) additional rule: when there
> are multiple nodes of the same type, they do not follow the global
> ordering by unit-address, but are grouped together.
> E.g. the second and any subsequent serial ports are always listed
> immediately after the first serial port.
OK, I'll add here some exception paragraph. pin-state nodes also need one.
>
>> +2. Nodes without unit addresses should be ordered alpha-numerically.
>> +
>> +3. When extending nodes in board DTS via &label, the entries should be ordered
>> + alpha-numerically.
>
>
>> +Order of Properties in Device Node
>> +----------------------------------
>> +
>> +Following order of properties in device nodes is preferred:
>> +
>> +1. compatible
>> +2. reg
>> +3. ranges
>> +4. All properties with values
>> +5. Boolean properties
>> +6. status (if applicable)
>
> There must be a lank line between properties and child nodes?
+1
>
> And once we have a documented coding style, the next long-standing item
> from our wishlist would be a script to sort the contents of a DTS file
> according to the rules ;-)
Yeah...
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH] docs: dt-bindings: add DTS Coding Style document
2023-11-16 20:44 ` Rob Herring
2023-11-17 23:55 ` Konrad Dybcio
@ 2023-11-20 7:19 ` Krzysztof Kozlowski
1 sibling, 0 replies; 22+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-20 7:19 UTC (permalink / raw)
To: Rob Herring
Cc: Krzysztof Kozlowski, Conor Dooley, devicetree, linux-kernel,
AngeloGioacchino Del Regno, Arnd Bergmann, Bjorn Andersson,
Geert Uytterhoeven, Heiko Stuebner, Konrad Dybcio,
Matthias Brugger, Michal Simek, Neil Armstrong, Nishanth Menon,
Olof Johansson
On 16/11/2023 21:44, Rob Herring wrote:
>>
>> Merging idea: Rob/DT bindings
>> ---
>> Documentation/devicetree/bindings/index.rst | 1 +
>> .../devicetree/bindings/writing-dts.rst | 137 ++++++++++++++++++
>> 2 files changed, 138 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/writing-dts.rst
>
> Perhaps dts-coding-style.rst
Ack
>
> After adding writing-schema, I realized the difference between
> writing-schema and writing-bindings isn't all that clear. I never got
> around to renaming things.
>
>>
>> diff --git a/Documentation/devicetree/bindings/index.rst b/Documentation/devicetree/bindings/index.rst
>> index d9002a3a0abb..975449be4862 100644
>> --- a/Documentation/devicetree/bindings/index.rst
>> +++ b/Documentation/devicetree/bindings/index.rst
>> @@ -5,5 +5,6 @@
>>
>> ABI
>> writing-bindings
>> + writing-dts
>> writing-schema
>> submitting-patches
>> diff --git a/Documentation/devicetree/bindings/writing-dts.rst b/Documentation/devicetree/bindings/writing-dts.rst
>> new file mode 100644
>> index 000000000000..10c477ec1eed
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/writing-dts.rst
>> @@ -0,0 +1,137 @@
>> +.. SPDX-License-Identifier: GPL-2.0
>> +.. _writingdts:
>> +
>> +===================================================
>> +Writing Devicetree Sources (DTS) - DTS Coding Style
>> +===================================================
>> +
>> +When writing Devicetree Sources (DTS) please observe below guidelines. They
>> +should be considered complementary to any rules expressed already in Devicetree
>> +Specification and dtc compiler (including W=1 and W=2 builds).
>> +
>> +Individual architectures and sub-architectures can add additional rules, making
>> +the style stricter.
>> +
>> +Naming and Valid Characters
>> +---------------------------
>> +
>> +1. Node and property names are allowed to use only:
>> +
>> + * lowercase characters:: [a-z]
>> + * digits:: [0-9]
>> + * dash:: -
>> +
>> +2. Labels are allowed to use only:
>> +
>> + * lowercase characters:: [a-z]
>> + * digits:: [0-9]
>> + * underscore:: _
>> +
>> +3. Unit addresses should use lowercase hex, without leading zeros (padding).
>
> Strictly speaking, the unit-address is whatever a bus defines, but
> yes, by default, that is the format.
>
>> +
>> +4. Hex values in properties, e.g. "reg", should use lowercase hex. Any address
>> + part can be padded with leading zeros.
>> +
>> +Example::
>> +
>> + gpi_dma2: dma-controller@800000 {
>> + compatible = "qcom,sm8550-gpi-dma", "qcom,sm6350-gpi-dma";
>> + reg = <0x0 0x00800000 0x0 0x60000>;
>> + }
>> +
>> +Order of Nodes
>> +--------------
>> +
>> +1. Nodes within any bus, thus using unit addresses for children, shall be
>> + ordered incrementally by unit address.
>> +
>> +2. Nodes without unit addresses should be ordered alpha-numerically.
>> +
>> +3. When extending nodes in board DTS via &label, the entries should be ordered
>> + alpha-numerically.
>
> Or matching the original node definition order?
If there is any sub-arch using such style, then sure, why not. Otherwise
if we do not have such examples, I find that a bit tricky to implement:
for patches adding new board, one needs to check the original DTSI for
order.
>
>> +
>> +Example::
>> +
>> + // SoC DTSI
>> +
>> + \ {
>
> / {
>
>> + cpus {
>> + // ...
>> + };
>> +
>> + psci {
>> + // ...
>> + };
>> +
>> + soc@ {
>> + dma: dma-controller@10000 {
>> + // ...
>> + };
>> +
>> + clk: clock-controller@80000 {
>> + // ...
>> + };
>> + };
>> + };
>> +
>> + // Board DTS
>> +
>> + &clk {
>> + // ...
>> + };
>> +
>> + &dma {
>> + // ...
>> + };
>> +
>> +
>> +Order of Properties in Device Node
>> +----------------------------------
>> +
>> +Following order of properties in device nodes is preferred:
>> +
>> +1. compatible
>> +2. reg
>> +3. ranges
>
>> +4. All properties with values
>> +5. Boolean properties
>
> I make this like schemas, standard/common properties first, then
> vendor specific properties.
Sure.
>
>> +6. status (if applicable)
>> +7. Child nodes
>> +
>> +The "status" property is by default "okay", thus it can be omitted.
>> +
>> +Example::
>> +
>> + // SoC DTSI
>> +
>> + usb_1_hsphy: phy@88e3000 {
>> + compatible = "qcom,sm8550-snps-eusb2-phy";
>> + reg = <0x0 0x088e3000 0x0 0x154>;
>> + #phy-cells = <0>;
>> + resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>;
>> + status = "disabled";
>> + };
>> +
>> + // Board DTS
>> +
>> + &usb_1_hsphy {
>> + clocks = <&tcsr TCSR_USB2_CLKREF_EN>;
>> + clock-names = "ref";
>> + status = "okay";
>> + };
>> +
>> +
>> +Indentation
>> +-----------
>> +
>> +1. Use indentation according to :ref:`codingstyle`.
>> +2. For arrays spanning across lines, preferred is to align the continued
>> + entries with opening < from first line.
>> +
>> +Example::
>> +
>> + thermal-sensor@c271000 {
>> + compatible = "qcom,sm8550-tsens", "qcom,tsens-v2";
>> + reg = <0x0 0x0c271000 0x0 0x1000>,
>> + <0x0 0x0c222000 0x0 0x1000>;
>
> You should cover the <> style too, meaning <> around each logical entry.
Ack.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2023-11-20 7:19 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 18:12 [PATCH] docs: dt-bindings: add DTS Coding Style document Krzysztof Kozlowski
2023-11-16 19:26 ` Heiko Stuebner
2023-11-16 19:51 ` Krzysztof Kozlowski
2023-11-16 20:03 ` Heiko Stuebner
2023-11-16 20:23 ` Krzysztof Kozlowski
2023-11-16 20:33 ` Heiko Stuebner
2023-11-17 14:03 ` Andrew Davis
2023-11-17 19:38 ` Heiko Stübner
2023-11-17 19:54 ` Andrew Davis
2023-11-17 20:04 ` Heiko Stübner
2023-11-18 11:25 ` Geert Uytterhoeven
2023-11-20 7:12 ` Krzysztof Kozlowski
2023-11-16 20:44 ` Rob Herring
2023-11-17 23:55 ` Konrad Dybcio
2023-11-20 7:19 ` Krzysztof Kozlowski
2023-11-16 21:27 ` Conor Dooley
2023-11-20 7:14 ` Krzysztof Kozlowski
2023-11-16 21:32 ` Geert Uytterhoeven
2023-11-20 7:16 ` Krzysztof Kozlowski
2023-11-17 23:53 ` Konrad Dybcio
2023-11-20 7:15 ` Krzysztof Kozlowski
2023-11-17 23:58 ` Konrad Dybcio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).